blob: ccb7d032e769b29d0ee28c7413c9565352fe678f [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
4#include <string>
5#include <vector>
6
7#include "glog/logging.h"
8
9namespace aos {
10
11// Class to parse /proc/interrupts.
12class InterruptsStatus {
13 public:
14 InterruptsStatus();
15
16 // Updates the interrupt state.
17 void Update();
18
19 // Updates the interrupt state from the contents of /proc/interrupts.
20 //
21 // This should only be used for testing.
22 void Update(std::string_view contents);
23
24 // Information about each interrupt.
25 struct InterruptState {
26 // IRQ number. -1 if this doesn't have a number.
27 int interrupt_number;
28 // Name of the interrupt. Only populated when number == -1
29 std::string interrupt_name;
30 // IRQs triggered per core, where the vector index is the core.
31 std::vector<unsigned int> count;
32
33 // The name of the irq chip controller.
34 std::string chip_name;
35
36 // Description of the IRQ if it doesn't have an interrupt number.
37 std::string description;
38
39 // Hardware IRQ "number".
40 std::string hwirq;
41
42 // List of actions. An action is something which gets triggered on an
43 // interrupt. This is the IRQ "name", and is a vector to cover shared IRQs.
44 std::vector<std::string> actions;
45 };
46
47 // Information about all IRQs.
48 const std::vector<InterruptState> &states() const { return states_; }
49
50 private:
51
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_