1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /* delayacct.h - per-task delay accounting
4 * Copyright (C) Shailabh Nagar, IBM Corp. 2006
7 #ifndef _LINUX_DELAYACCT_H
8 #define _LINUX_DELAYACCT_H
10 #include <uapi/linux/taskstats.h>
12 #ifdef CONFIG_TASK_DELAY_ACCT
13 struct task_delay_info {
16 /* For each stat XXX, add following, aligned appropriately
18 * struct timespec XXX_start, XXX_end;
22 * Atomicity of updates to XXX_delay, XXX_count protected by
23 * single lock above (split into XXX_lock if contention is an issue).
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.
34 u64 blkio_delay; /* wait for sync block io completion */
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 */
44 u64 freepages_delay_max;
45 u64 freepages_delay_min;
46 u64 freepages_delay; /* wait for memory reclaim */
49 u64 thrashing_delay_max;
50 u64 thrashing_delay_min;
51 u64 thrashing_delay; /* wait for thrashing page */
54 u64 compact_delay_max;
55 u64 compact_delay_min;
56 u64 compact_delay; /* wait for memory compact */
61 u64 wpcopy_delay; /* wait for write-protect copy */
65 u64 irq_delay; /* wait for IRQ/SOFTIRQ */
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 */
75 #include <linux/sched.h>
76 #include <linux/slab.h>
77 #include <linux/jump_label.h>
79 #ifdef CONFIG_TASK_DELAY_ACCT
80 DECLARE_STATIC_KEY_FALSE(delayacct_key);
81 extern int delayacct_on; /* Delay accounting turned on/off */
82 extern struct kmem_cache *delayacct_cache;
83 extern void delayacct_init(void);
85 extern void __delayacct_tsk_init(struct task_struct *);
86 extern void __delayacct_tsk_exit(struct task_struct *);
87 extern void __delayacct_blkio_start(void);
88 extern void __delayacct_blkio_end(struct task_struct *);
89 extern int delayacct_add_tsk(struct taskstats *, struct task_struct *);
90 extern __u64 __delayacct_blkio_ticks(struct task_struct *);
91 extern void __delayacct_freepages_start(void);
92 extern void __delayacct_freepages_end(void);
93 extern void __delayacct_thrashing_start(bool *in_thrashing);
94 extern void __delayacct_thrashing_end(bool *in_thrashing);
95 extern void __delayacct_swapin_start(void);
96 extern void __delayacct_swapin_end(void);
97 extern void __delayacct_compact_start(void);
98 extern void __delayacct_compact_end(void);
99 extern void __delayacct_wpcopy_start(void);
100 extern void __delayacct_wpcopy_end(void);
101 extern void __delayacct_irq(struct task_struct *task, u32 delta);
103 static inline void delayacct_tsk_init(struct task_struct *tsk)
105 /* reinitialize in case parent's non-null pointer was dup'ed*/
108 __delayacct_tsk_init(tsk);
111 /* Free tsk->delays. Called from bad fork and __put_task_struct
112 * where there's no risk of tsk->delays being accessed elsewhere
114 static inline void delayacct_tsk_free(struct task_struct *tsk)
117 kmem_cache_free(delayacct_cache, tsk->delays);
121 static inline void delayacct_blkio_start(void)
123 if (!static_branch_unlikely(&delayacct_key))
127 __delayacct_blkio_start();
130 static inline void delayacct_blkio_end(struct task_struct *p)
132 if (!static_branch_unlikely(&delayacct_key))
136 __delayacct_blkio_end(p);
139 static inline __u64 delayacct_blkio_ticks(struct task_struct *tsk)
142 return __delayacct_blkio_ticks(tsk);
146 static inline void delayacct_freepages_start(void)
148 if (!static_branch_unlikely(&delayacct_key))
152 __delayacct_freepages_start();
155 static inline void delayacct_freepages_end(void)
157 if (!static_branch_unlikely(&delayacct_key))
161 __delayacct_freepages_end();
164 static inline void delayacct_thrashing_start(bool *in_thrashing)
166 if (!static_branch_unlikely(&delayacct_key))
170 __delayacct_thrashing_start(in_thrashing);
173 static inline void delayacct_thrashing_end(bool *in_thrashing)
175 if (!static_branch_unlikely(&delayacct_key))
179 __delayacct_thrashing_end(in_thrashing);
182 static inline void delayacct_swapin_start(void)
184 if (!static_branch_unlikely(&delayacct_key))
188 __delayacct_swapin_start();
191 static inline void delayacct_swapin_end(void)
193 if (!static_branch_unlikely(&delayacct_key))
197 __delayacct_swapin_end();
200 static inline void delayacct_compact_start(void)
202 if (!static_branch_unlikely(&delayacct_key))
206 __delayacct_compact_start();
209 static inline void delayacct_compact_end(void)
211 if (!static_branch_unlikely(&delayacct_key))
215 __delayacct_compact_end();
218 static inline void delayacct_wpcopy_start(void)
220 if (!static_branch_unlikely(&delayacct_key))
224 __delayacct_wpcopy_start();
227 static inline void delayacct_wpcopy_end(void)
229 if (!static_branch_unlikely(&delayacct_key))
233 __delayacct_wpcopy_end();
236 static inline void delayacct_irq(struct task_struct *task, u32 delta)
238 if (!static_branch_unlikely(&delayacct_key))
242 __delayacct_irq(task, delta);
246 static inline void delayacct_init(void)
248 static inline void delayacct_tsk_init(struct task_struct *tsk)
250 static inline void delayacct_tsk_free(struct task_struct *tsk)
252 static inline void delayacct_blkio_start(void)
254 static inline void delayacct_blkio_end(struct task_struct *p)
256 static inline int delayacct_add_tsk(struct taskstats *d,
257 struct task_struct *tsk)
259 static inline __u64 delayacct_blkio_ticks(struct task_struct *tsk)
261 static inline int delayacct_is_task_waiting_on_io(struct task_struct *p)
263 static inline void delayacct_freepages_start(void)
265 static inline void delayacct_freepages_end(void)
267 static inline void delayacct_thrashing_start(bool *in_thrashing)
269 static inline void delayacct_thrashing_end(bool *in_thrashing)
271 static inline void delayacct_swapin_start(void)
273 static inline void delayacct_swapin_end(void)
275 static inline void delayacct_compact_start(void)
277 static inline void delayacct_compact_end(void)
279 static inline void delayacct_wpcopy_start(void)
281 static inline void delayacct_wpcopy_end(void)
283 static inline void delayacct_irq(struct task_struct *task, u32 delta)
286 #endif /* CONFIG_TASK_DELAY_ACCT */