1 #ifndef _LINUX_PSI_TYPES_H
2 #define _LINUX_PSI_TYPES_H
3
4 #include <linux/kthread.h>
5 #include <linux/seqlock.h>
6 #include <linux/types.h>
7 #include <linux/kref.h>
8 #include <linux/wait.h>
9
10 #ifdef CONFIG_PSI
11
12
13 enum psi_task_count {
14 NR_IOWAIT,
15 NR_MEMSTALL,
16 NR_RUNNING,
17 NR_PSI_TASK_COUNTS = 3,
18 };
19
20
21 #define TSK_IOWAIT (1 << NR_IOWAIT)
22 #define TSK_MEMSTALL (1 << NR_MEMSTALL)
23 #define TSK_RUNNING (1 << NR_RUNNING)
24
25
26 enum psi_res {
27 PSI_IO,
28 PSI_MEM,
29 PSI_CPU,
30 NR_PSI_RESOURCES = 3,
31 };
32
33
34
35
36
37
38
39 enum psi_states {
40 PSI_IO_SOME,
41 PSI_IO_FULL,
42 PSI_MEM_SOME,
43 PSI_MEM_FULL,
44 PSI_CPU_SOME,
45
46 PSI_NONIDLE,
47 NR_PSI_STATES = 6,
48 };
49
50 enum psi_aggregators {
51 PSI_AVGS = 0,
52 PSI_POLL,
53 NR_PSI_AGGREGATORS,
54 };
55
56 struct psi_group_cpu {
57
58
59
60 seqcount_t seq ____cacheline_aligned_in_smp;
61
62
63 unsigned int tasks[NR_PSI_TASK_COUNTS];
64
65
66 u32 state_mask;
67
68
69 u32 times[NR_PSI_STATES];
70
71
72 u64 state_start;
73
74
75
76
77 u32 times_prev[NR_PSI_AGGREGATORS][NR_PSI_STATES]
78 ____cacheline_aligned_in_smp;
79 };
80
81
82 struct psi_window {
83
84 u64 size;
85
86
87 u64 start_time;
88
89
90 u64 start_value;
91
92
93 u64 prev_growth;
94 };
95
96 struct psi_trigger {
97
98 enum psi_states state;
99
100
101 u64 threshold;
102
103
104 struct list_head node;
105
106
107 struct psi_group *group;
108
109
110 wait_queue_head_t event_wait;
111
112
113 int event;
114
115
116 struct psi_window win;
117
118
119
120
121
122 u64 last_event_time;
123
124
125 struct kref refcount;
126 };
127
128 struct psi_group {
129
130 struct mutex avgs_lock;
131
132
133 struct psi_group_cpu __percpu *pcpu;
134
135
136 u64 avg_total[NR_PSI_STATES - 1];
137 u64 avg_last_update;
138 u64 avg_next_update;
139
140
141 struct delayed_work avgs_work;
142
143
144 u64 total[NR_PSI_AGGREGATORS][NR_PSI_STATES - 1];
145 unsigned long avg[NR_PSI_STATES - 1][3];
146
147
148 atomic_t poll_scheduled;
149 struct kthread_worker __rcu *poll_kworker;
150 struct kthread_delayed_work poll_work;
151
152
153 struct mutex trigger_lock;
154
155
156 struct list_head triggers;
157 u32 nr_triggers[NR_PSI_STATES - 1];
158 u32 poll_states;
159 u64 poll_min_period;
160
161
162 u64 polling_total[NR_PSI_STATES - 1];
163 u64 polling_next_update;
164 u64 polling_until;
165 };
166
167 #else
168
169 struct psi_group { };
170
171 #endif
172
173 #endif