Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1/* SPDX-License-Identifier: GPL-2.0-or-later */
2/* delayacct.h - per-task delay accounting
3 *
4 * Copyright (C) Shailabh Nagar, IBM Corp. 2006
5 */
6
7#ifndef _LINUX_DELAYACCT_H
8#define _LINUX_DELAYACCT_H
9
10#include <uapi/linux/taskstats.h>
11
12#ifdef CONFIG_TASK_DELAY_ACCT
13struct task_delay_info {
14 raw_spinlock_t lock;
15
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 */
31 u64 blkio_start;
32 u64 blkio_delay_max;
33 u64 blkio_delay_min;
34 u64 blkio_delay; /* wait for sync block io completion */
35 u64 swapin_start;
36 u64 swapin_delay_max;
37 u64 swapin_delay_min;
38 u64 swapin_delay; /* wait for swapin */
39 u32 blkio_count; /* total count of the number of sync block */
40 /* io operations performed */
41 u32 swapin_count; /* total count of swapin */
42
43 u64 freepages_start;
44 u64 freepages_delay_max;
45 u64 freepages_delay_min;
46 u64 freepages_delay; /* wait for memory reclaim */
47
48 u64 thrashing_start;
49 u64 thrashing_delay_max;
50 u64 thrashing_delay_min;
51 u64 thrashing_delay; /* wait for thrashing page */
52
53 u64 compact_start;
54 u64 compact_delay_max;
55 u64 compact_delay_min;
56 u64 compact_delay; /* wait for memory compact */
57
58 u64 wpcopy_start;
59 u64 wpcopy_delay_max;
60 u64 wpcopy_delay_min;
61 u64 wpcopy_delay; /* wait for write-protect copy */
62
63 u64 irq_delay_max;
64 u64 irq_delay_min;
65 u64 irq_delay; /* wait for IRQ/SOFTIRQ */
66
67 u32 freepages_count; /* total count of memory reclaim */
68 u32 thrashing_count; /* total count of thrash waits */
69 u32 compact_count; /* total count of memory compact */
70 u32 wpcopy_count; /* total count of write-protect copy */
71 u32 irq_count; /* total count of IRQ/SOFTIRQ */
72
73 struct timespec64 blkio_delay_max_ts;
74 struct timespec64 swapin_delay_max_ts;
75 struct timespec64 freepages_delay_max_ts;
76 struct timespec64 thrashing_delay_max_ts;
77 struct timespec64 compact_delay_max_ts;
78 struct timespec64 wpcopy_delay_max_ts;
79 struct timespec64 irq_delay_max_ts;
80};
81#endif
82
83#include <linux/sched.h>
84#include <linux/slab.h>
85#include <linux/jump_label.h>
86
87#ifdef CONFIG_TASK_DELAY_ACCT
88DECLARE_STATIC_KEY_FALSE(delayacct_key);
89extern int delayacct_on; /* Delay accounting turned on/off */
90extern struct kmem_cache *delayacct_cache;
91extern void delayacct_init(void);
92
93extern void __delayacct_tsk_init(struct task_struct *);
94extern void __delayacct_tsk_exit(struct task_struct *);
95extern void __delayacct_blkio_start(void);
96extern void __delayacct_blkio_end(struct task_struct *);
97extern int delayacct_add_tsk(struct taskstats *, struct task_struct *);
98extern __u64 __delayacct_blkio_ticks(struct task_struct *);
99extern void __delayacct_freepages_start(void);
100extern void __delayacct_freepages_end(void);
101extern void __delayacct_thrashing_start(bool *in_thrashing);
102extern void __delayacct_thrashing_end(bool *in_thrashing);
103extern void __delayacct_swapin_start(void);
104extern void __delayacct_swapin_end(void);
105extern void __delayacct_compact_start(void);
106extern void __delayacct_compact_end(void);
107extern void __delayacct_wpcopy_start(void);
108extern void __delayacct_wpcopy_end(void);
109extern void __delayacct_irq(struct task_struct *task, u32 delta);
110
111static inline void delayacct_tsk_init(struct task_struct *tsk)
112{
113 /* reinitialize in case parent's non-null pointer was dup'ed*/
114 tsk->delays = NULL;
115 if (delayacct_on)
116 __delayacct_tsk_init(tsk);
117}
118
119/* Free tsk->delays. Called from bad fork and __put_task_struct
120 * where there's no risk of tsk->delays being accessed elsewhere
121 */
122static inline void delayacct_tsk_free(struct task_struct *tsk)
123{
124 if (tsk->delays)
125 kmem_cache_free(delayacct_cache, tsk->delays);
126 tsk->delays = NULL;
127}
128
129static inline void delayacct_blkio_start(void)
130{
131 if (!static_branch_unlikely(&delayacct_key))
132 return;
133
134 if (current->delays)
135 __delayacct_blkio_start();
136}
137
138static inline void delayacct_blkio_end(struct task_struct *p)
139{
140 if (!static_branch_unlikely(&delayacct_key))
141 return;
142
143 if (p->delays)
144 __delayacct_blkio_end(p);
145}
146
147static inline __u64 delayacct_blkio_ticks(struct task_struct *tsk)
148{
149 if (tsk->delays)
150 return __delayacct_blkio_ticks(tsk);
151 return 0;
152}
153
154static inline void delayacct_freepages_start(void)
155{
156 if (!static_branch_unlikely(&delayacct_key))
157 return;
158
159 if (current->delays)
160 __delayacct_freepages_start();
161}
162
163static inline void delayacct_freepages_end(void)
164{
165 if (!static_branch_unlikely(&delayacct_key))
166 return;
167
168 if (current->delays)
169 __delayacct_freepages_end();
170}
171
172static inline void delayacct_thrashing_start(bool *in_thrashing)
173{
174 if (!static_branch_unlikely(&delayacct_key))
175 return;
176
177 if (current->delays)
178 __delayacct_thrashing_start(in_thrashing);
179}
180
181static inline void delayacct_thrashing_end(bool *in_thrashing)
182{
183 if (!static_branch_unlikely(&delayacct_key))
184 return;
185
186 if (current->delays)
187 __delayacct_thrashing_end(in_thrashing);
188}
189
190static inline void delayacct_swapin_start(void)
191{
192 if (!static_branch_unlikely(&delayacct_key))
193 return;
194
195 if (current->delays)
196 __delayacct_swapin_start();
197}
198
199static inline void delayacct_swapin_end(void)
200{
201 if (!static_branch_unlikely(&delayacct_key))
202 return;
203
204 if (current->delays)
205 __delayacct_swapin_end();
206}
207
208static inline void delayacct_compact_start(void)
209{
210 if (!static_branch_unlikely(&delayacct_key))
211 return;
212
213 if (current->delays)
214 __delayacct_compact_start();
215}
216
217static inline void delayacct_compact_end(void)
218{
219 if (!static_branch_unlikely(&delayacct_key))
220 return;
221
222 if (current->delays)
223 __delayacct_compact_end();
224}
225
226static inline void delayacct_wpcopy_start(void)
227{
228 if (!static_branch_unlikely(&delayacct_key))
229 return;
230
231 if (current->delays)
232 __delayacct_wpcopy_start();
233}
234
235static inline void delayacct_wpcopy_end(void)
236{
237 if (!static_branch_unlikely(&delayacct_key))
238 return;
239
240 if (current->delays)
241 __delayacct_wpcopy_end();
242}
243
244static inline void delayacct_irq(struct task_struct *task, u32 delta)
245{
246 if (!static_branch_unlikely(&delayacct_key))
247 return;
248
249 if (task->delays)
250 __delayacct_irq(task, delta);
251}
252
253#else
254static inline void delayacct_init(void)
255{}
256static inline void delayacct_tsk_init(struct task_struct *tsk)
257{}
258static inline void delayacct_tsk_free(struct task_struct *tsk)
259{}
260static inline void delayacct_blkio_start(void)
261{}
262static inline void delayacct_blkio_end(struct task_struct *p)
263{}
264static inline int delayacct_add_tsk(struct taskstats *d,
265 struct task_struct *tsk)
266{ return 0; }
267static inline __u64 delayacct_blkio_ticks(struct task_struct *tsk)
268{ return 0; }
269static inline int delayacct_is_task_waiting_on_io(struct task_struct *p)
270{ return 0; }
271static inline void delayacct_freepages_start(void)
272{}
273static inline void delayacct_freepages_end(void)
274{}
275static inline void delayacct_thrashing_start(bool *in_thrashing)
276{}
277static inline void delayacct_thrashing_end(bool *in_thrashing)
278{}
279static inline void delayacct_swapin_start(void)
280{}
281static inline void delayacct_swapin_end(void)
282{}
283static inline void delayacct_compact_start(void)
284{}
285static inline void delayacct_compact_end(void)
286{}
287static inline void delayacct_wpcopy_start(void)
288{}
289static inline void delayacct_wpcopy_end(void)
290{}
291static inline void delayacct_irq(struct task_struct *task, u32 delta)
292{}
293
294#endif /* CONFIG_TASK_DELAY_ACCT */
295
296#endif