blob: 414acdd3d2d5eadf1c8ba554077c0e3702390c9d [file] [log] [blame]
Austin Schuh2ec71fd2022-12-30 14:48:59 -08001#ifndef AOS_STARTER_IRQ_AFFINITY_LIB_H_
2#define AOS_STARTER_IRQ_AFFINITY_LIB_H_
3
Stephan Pleinesf581a072024-05-23 20:59:27 -07004#include <stddef.h>
Austin Schuh2ec71fd2022-12-30 14:48:59 -08005
Stephan Pleinesf581a072024-05-23 20:59:27 -07006#include <string>
7#include <string_view>
8#include <vector>
Austin Schuh2ec71fd2022-12-30 14:48:59 -08009
10namespace aos {
11
12// Class to parse /proc/interrupts.
13class InterruptsStatus {
14 public:
15 InterruptsStatus();
16
17 // Updates the interrupt state.
18 void Update();
19
20 // Updates the interrupt state from the contents of /proc/interrupts.
21 //
22 // This should only be used for testing.
23 void Update(std::string_view contents);
24
25 // Information about each interrupt.
26 struct InterruptState {
27 // IRQ number. -1 if this doesn't have a number.
28 int interrupt_number;
29 // Name of the interrupt. Only populated when number == -1
30 std::string interrupt_name;
31 // IRQs triggered per core, where the vector index is the core.
32 std::vector<unsigned int> count;
33
34 // The name of the irq chip controller.
35 std::string chip_name;
36
37 // Description of the IRQ if it doesn't have an interrupt number.
38 std::string description;
39
40 // Hardware IRQ "number".
41 std::string hwirq;
42
43 // List of actions. An action is something which gets triggered on an
44 // interrupt. This is the IRQ "name", and is a vector to cover shared IRQs.
45 std::vector<std::string> actions;
46 };
47
48 // Information about all IRQs.
49 const std::vector<InterruptState> &states() const { return states_; }
50
51 private:
Austin Schuh2ec71fd2022-12-30 14:48:59 -080052 // Buffer to hold the contents of /proc/interrupts to avoid re-allocating
53 // continually.
54 std::vector<char> interrupts_content_;
55
56 size_t cpus_ = 0;
57
58 std::vector<InterruptState> states_;
59};
60
61} // namespace aos
62
63#endif // AOS_STARTER_IRQ_AFFINITY_LIB_H_