Austin Schuh | 2ec71fd | 2022-12-30 14:48:59 -0800 | [diff] [blame] | 1 | #ifndef AOS_STARTER_IRQ_AFFINITY_LIB_H_ |
| 2 | #define AOS_STARTER_IRQ_AFFINITY_LIB_H_ |
| 3 | |
Stephan Pleines | f581a07 | 2024-05-23 20:59:27 -0700 | [diff] [blame] | 4 | #include <stddef.h> |
Austin Schuh | 2ec71fd | 2022-12-30 14:48:59 -0800 | [diff] [blame] | 5 | |
Stephan Pleines | f581a07 | 2024-05-23 20:59:27 -0700 | [diff] [blame] | 6 | #include <string> |
| 7 | #include <string_view> |
| 8 | #include <vector> |
Austin Schuh | 2ec71fd | 2022-12-30 14:48:59 -0800 | [diff] [blame] | 9 | |
| 10 | namespace aos { |
| 11 | |
| 12 | // Class to parse /proc/interrupts. |
| 13 | class 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 Schuh | 2ec71fd | 2022-12-30 14:48:59 -0800 | [diff] [blame] | 52 | // 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_ |