Commit | Line | Data |
---|---|---|
c942fddf | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
ca74e92b SN |
2 | /* delayacct.h - per-task delay accounting |
3 | * | |
4 | * Copyright (C) Shailabh Nagar, IBM Corp. 2006 | |
ca74e92b SN |
5 | */ |
6 | ||
7 | #ifndef _LINUX_DELAYACCT_H | |
8 | #define _LINUX_DELAYACCT_H | |
9 | ||
4025819d | 10 | #include <uapi/linux/taskstats.h> |
ca74e92b SN |
11 | |
12 | #ifdef CONFIG_TASK_DELAY_ACCT | |
47913d4e | 13 | struct task_delay_info { |
02acc80d | 14 | raw_spinlock_t lock; |
ca74e92b | 15 | |
47913d4e IM |
16 | /* For each stat XXX, add following, aligned appropriately |
17 | * | |
18 | * struct timespec XXX_start, XXX_end; | |
19 | * u64 XXX_delay; | |
20 | * u32 XXX_count; | |
21 | * | |
22 | * Atomicity of updates to XXX_delay, XXX_count protected by | |
23 | * single lock above (split into XXX_lock if contention is an issue). | |
24 | */ | |
25 | ||
26 | /* | |
27 | * XXX_count is incremented on every XXX operation, the delay | |
28 | * associated with the operation is added to XXX_delay. | |
29 | * XXX_delay contains the accumulated delay time in nanoseconds. | |
30 | */ | |
a3d5dc90 | 31 | u64 blkio_start; |
47913d4e | 32 | u64 blkio_delay; /* wait for sync block io completion */ |
a3d5dc90 YY |
33 | u64 swapin_start; |
34 | u64 swapin_delay; /* wait for swapin */ | |
47913d4e IM |
35 | u32 blkio_count; /* total count of the number of sync block */ |
36 | /* io operations performed */ | |
a3d5dc90 | 37 | u32 swapin_count; /* total count of swapin */ |
47913d4e IM |
38 | |
39 | u64 freepages_start; | |
40 | u64 freepages_delay; /* wait for memory reclaim */ | |
b1d29ba8 JW |
41 | |
42 | u64 thrashing_start; | |
43 | u64 thrashing_delay; /* wait for thrashing page */ | |
44 | ||
5bf18281 | 45 | u64 compact_start; |
46 | u64 compact_delay; /* wait for memory compact */ | |
47 | ||
662ce1dc YY |
48 | u64 wpcopy_start; |
49 | u64 wpcopy_delay; /* wait for write-protect copy */ | |
50 | ||
47913d4e | 51 | u32 freepages_count; /* total count of memory reclaim */ |
b1d29ba8 | 52 | u32 thrashing_count; /* total count of thrash waits */ |
5bf18281 | 53 | u32 compact_count; /* total count of memory compact */ |
662ce1dc | 54 | u32 wpcopy_count; /* total count of write-protect copy */ |
47913d4e IM |
55 | }; |
56 | #endif | |
57 | ||
58 | #include <linux/sched.h> | |
59 | #include <linux/slab.h> | |
eee4d9fe | 60 | #include <linux/jump_label.h> |
47913d4e IM |
61 | |
62 | #ifdef CONFIG_TASK_DELAY_ACCT | |
e4042ad4 | 63 | DECLARE_STATIC_KEY_FALSE(delayacct_key); |
ca74e92b | 64 | extern int delayacct_on; /* Delay accounting turned on/off */ |
e18b890b | 65 | extern struct kmem_cache *delayacct_cache; |
ca74e92b | 66 | extern void delayacct_init(void); |
0cd7c741 | 67 | |
ca74e92b SN |
68 | extern void __delayacct_tsk_init(struct task_struct *); |
69 | extern void __delayacct_tsk_exit(struct task_struct *); | |
0ff92245 | 70 | extern void __delayacct_blkio_start(void); |
c96f5471 | 71 | extern void __delayacct_blkio_end(struct task_struct *); |
e4042ad4 | 72 | extern int delayacct_add_tsk(struct taskstats *, struct task_struct *); |
25890454 | 73 | extern __u64 __delayacct_blkio_ticks(struct task_struct *); |
873b4771 KK |
74 | extern void __delayacct_freepages_start(void); |
75 | extern void __delayacct_freepages_end(void); | |
aa1cf99b YY |
76 | extern void __delayacct_thrashing_start(bool *in_thrashing); |
77 | extern void __delayacct_thrashing_end(bool *in_thrashing); | |
a3d5dc90 YY |
78 | extern void __delayacct_swapin_start(void); |
79 | extern void __delayacct_swapin_end(void); | |
5bf18281 | 80 | extern void __delayacct_compact_start(void); |
81 | extern void __delayacct_compact_end(void); | |
662ce1dc YY |
82 | extern void __delayacct_wpcopy_start(void); |
83 | extern void __delayacct_wpcopy_end(void); | |
846c7bb0 | 84 | |
ca74e92b SN |
85 | static inline void delayacct_tsk_init(struct task_struct *tsk) |
86 | { | |
87 | /* reinitialize in case parent's non-null pointer was dup'ed*/ | |
88 | tsk->delays = NULL; | |
163ecdff | 89 | if (delayacct_on) |
ca74e92b SN |
90 | __delayacct_tsk_init(tsk); |
91 | } | |
92 | ||
35df17c5 SN |
93 | /* Free tsk->delays. Called from bad fork and __put_task_struct |
94 | * where there's no risk of tsk->delays being accessed elsewhere | |
95 | */ | |
96 | static inline void delayacct_tsk_free(struct task_struct *tsk) | |
ca74e92b SN |
97 | { |
98 | if (tsk->delays) | |
35df17c5 SN |
99 | kmem_cache_free(delayacct_cache, tsk->delays); |
100 | tsk->delays = NULL; | |
ca74e92b SN |
101 | } |
102 | ||
0ff92245 SN |
103 | static inline void delayacct_blkio_start(void) |
104 | { | |
e4042ad4 | 105 | if (!static_branch_unlikely(&delayacct_key)) |
eee4d9fe PZ |
106 | return; |
107 | ||
0ff92245 SN |
108 | if (current->delays) |
109 | __delayacct_blkio_start(); | |
110 | } | |
111 | ||
c96f5471 | 112 | static inline void delayacct_blkio_end(struct task_struct *p) |
0ff92245 | 113 | { |
e4042ad4 | 114 | if (!static_branch_unlikely(&delayacct_key)) |
eee4d9fe PZ |
115 | return; |
116 | ||
b512719f | 117 | if (p->delays) |
c96f5471 | 118 | __delayacct_blkio_end(p); |
0ff92245 SN |
119 | } |
120 | ||
25890454 SN |
121 | static inline __u64 delayacct_blkio_ticks(struct task_struct *tsk) |
122 | { | |
123 | if (tsk->delays) | |
124 | return __delayacct_blkio_ticks(tsk); | |
125 | return 0; | |
126 | } | |
127 | ||
873b4771 KK |
128 | static inline void delayacct_freepages_start(void) |
129 | { | |
82065b72 YY |
130 | if (!static_branch_unlikely(&delayacct_key)) |
131 | return; | |
132 | ||
873b4771 KK |
133 | if (current->delays) |
134 | __delayacct_freepages_start(); | |
135 | } | |
136 | ||
137 | static inline void delayacct_freepages_end(void) | |
138 | { | |
82065b72 YY |
139 | if (!static_branch_unlikely(&delayacct_key)) |
140 | return; | |
141 | ||
873b4771 KK |
142 | if (current->delays) |
143 | __delayacct_freepages_end(); | |
144 | } | |
145 | ||
aa1cf99b | 146 | static inline void delayacct_thrashing_start(bool *in_thrashing) |
b1d29ba8 | 147 | { |
82065b72 YY |
148 | if (!static_branch_unlikely(&delayacct_key)) |
149 | return; | |
150 | ||
b1d29ba8 | 151 | if (current->delays) |
aa1cf99b | 152 | __delayacct_thrashing_start(in_thrashing); |
b1d29ba8 JW |
153 | } |
154 | ||
aa1cf99b | 155 | static inline void delayacct_thrashing_end(bool *in_thrashing) |
b1d29ba8 | 156 | { |
82065b72 YY |
157 | if (!static_branch_unlikely(&delayacct_key)) |
158 | return; | |
159 | ||
b1d29ba8 | 160 | if (current->delays) |
aa1cf99b | 161 | __delayacct_thrashing_end(in_thrashing); |
b1d29ba8 JW |
162 | } |
163 | ||
a3d5dc90 YY |
164 | static inline void delayacct_swapin_start(void) |
165 | { | |
82065b72 YY |
166 | if (!static_branch_unlikely(&delayacct_key)) |
167 | return; | |
168 | ||
a3d5dc90 YY |
169 | if (current->delays) |
170 | __delayacct_swapin_start(); | |
171 | } | |
172 | ||
173 | static inline void delayacct_swapin_end(void) | |
174 | { | |
82065b72 YY |
175 | if (!static_branch_unlikely(&delayacct_key)) |
176 | return; | |
177 | ||
a3d5dc90 YY |
178 | if (current->delays) |
179 | __delayacct_swapin_end(); | |
180 | } | |
181 | ||
5bf18281 | 182 | static inline void delayacct_compact_start(void) |
183 | { | |
184 | if (!static_branch_unlikely(&delayacct_key)) | |
185 | return; | |
186 | ||
187 | if (current->delays) | |
188 | __delayacct_compact_start(); | |
189 | } | |
190 | ||
191 | static inline void delayacct_compact_end(void) | |
192 | { | |
193 | if (!static_branch_unlikely(&delayacct_key)) | |
194 | return; | |
195 | ||
196 | if (current->delays) | |
197 | __delayacct_compact_end(); | |
198 | } | |
199 | ||
662ce1dc YY |
200 | static inline void delayacct_wpcopy_start(void) |
201 | { | |
202 | if (!static_branch_unlikely(&delayacct_key)) | |
203 | return; | |
204 | ||
205 | if (current->delays) | |
206 | __delayacct_wpcopy_start(); | |
207 | } | |
208 | ||
209 | static inline void delayacct_wpcopy_end(void) | |
210 | { | |
211 | if (!static_branch_unlikely(&delayacct_key)) | |
212 | return; | |
213 | ||
214 | if (current->delays) | |
215 | __delayacct_wpcopy_end(); | |
216 | } | |
217 | ||
ca74e92b | 218 | #else |
ca74e92b SN |
219 | static inline void delayacct_init(void) |
220 | {} | |
221 | static inline void delayacct_tsk_init(struct task_struct *tsk) | |
222 | {} | |
35df17c5 | 223 | static inline void delayacct_tsk_free(struct task_struct *tsk) |
ca74e92b | 224 | {} |
0ff92245 SN |
225 | static inline void delayacct_blkio_start(void) |
226 | {} | |
c96f5471 | 227 | static inline void delayacct_blkio_end(struct task_struct *p) |
0ff92245 | 228 | {} |
6f44993f SN |
229 | static inline int delayacct_add_tsk(struct taskstats *d, |
230 | struct task_struct *tsk) | |
231 | { return 0; } | |
25890454 SN |
232 | static inline __u64 delayacct_blkio_ticks(struct task_struct *tsk) |
233 | { return 0; } | |
846c7bb0 BS |
234 | static inline int delayacct_is_task_waiting_on_io(struct task_struct *p) |
235 | { return 0; } | |
873b4771 KK |
236 | static inline void delayacct_freepages_start(void) |
237 | {} | |
238 | static inline void delayacct_freepages_end(void) | |
239 | {} | |
aa1cf99b | 240 | static inline void delayacct_thrashing_start(bool *in_thrashing) |
b1d29ba8 | 241 | {} |
aa1cf99b | 242 | static inline void delayacct_thrashing_end(bool *in_thrashing) |
b1d29ba8 | 243 | {} |
a3d5dc90 YY |
244 | static inline void delayacct_swapin_start(void) |
245 | {} | |
246 | static inline void delayacct_swapin_end(void) | |
247 | {} | |
5bf18281 | 248 | static inline void delayacct_compact_start(void) |
249 | {} | |
250 | static inline void delayacct_compact_end(void) | |
251 | {} | |
662ce1dc YY |
252 | static inline void delayacct_wpcopy_start(void) |
253 | {} | |
254 | static inline void delayacct_wpcopy_end(void) | |
255 | {} | |
873b4771 | 256 | |
ca74e92b SN |
257 | #endif /* CONFIG_TASK_DELAY_ACCT */ |
258 | ||
259 | #endif |