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