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