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.
32 u64 blkio_delay; /* wait for sync block io completion */
34 u64 swapin_delay; /* wait for swapin */
35 u32 blkio_count; /* total count of the number of sync block */
36 /* io operations performed */
37 u32 swapin_count; /* total count of swapin */
40 u64 freepages_delay; /* wait for memory reclaim */
43 u64 thrashing_delay; /* wait for thrashing page */
46 u64 compact_delay; /* wait for memory compact */
49 u64 wpcopy_delay; /* wait for write-protect copy */
51 u32 freepages_count; /* total count of memory reclaim */
52 u32 thrashing_count; /* total count of thrash waits */
53 u32 compact_count; /* total count of memory compact */
54 u32 wpcopy_count; /* total count of write-protect copy */
58 #include <linux/sched.h>
59 #include <linux/slab.h>
60 #include <linux/jump_label.h>
62 #ifdef CONFIG_TASK_DELAY_ACCT
63 DECLARE_STATIC_KEY_FALSE(delayacct_key);
64 extern int delayacct_on; /* Delay accounting turned on/off */
65 extern struct kmem_cache *delayacct_cache;
66 extern void delayacct_init(void);
68 extern void __delayacct_tsk_init(struct task_struct *);
69 extern void __delayacct_tsk_exit(struct task_struct *);
70 extern void __delayacct_blkio_start(void);
71 extern void __delayacct_blkio_end(struct task_struct *);
72 extern int delayacct_add_tsk(struct taskstats *, struct task_struct *);
73 extern __u64 __delayacct_blkio_ticks(struct task_struct *);
74 extern void __delayacct_freepages_start(void);
75 extern void __delayacct_freepages_end(void);
76 extern void __delayacct_thrashing_start(bool *in_thrashing);
77 extern void __delayacct_thrashing_end(bool *in_thrashing);
78 extern void __delayacct_swapin_start(void);
79 extern void __delayacct_swapin_end(void);
80 extern void __delayacct_compact_start(void);
81 extern void __delayacct_compact_end(void);
82 extern void __delayacct_wpcopy_start(void);
83 extern void __delayacct_wpcopy_end(void);
85 static inline void delayacct_tsk_init(struct task_struct *tsk)
87 /* reinitialize in case parent's non-null pointer was dup'ed*/
90 __delayacct_tsk_init(tsk);
93 /* Free tsk->delays. Called from bad fork and __put_task_struct
94 * where there's no risk of tsk->delays being accessed elsewhere
96 static inline void delayacct_tsk_free(struct task_struct *tsk)
99 kmem_cache_free(delayacct_cache, tsk->delays);
103 static inline void delayacct_blkio_start(void)
105 if (!static_branch_unlikely(&delayacct_key))
109 __delayacct_blkio_start();
112 static inline void delayacct_blkio_end(struct task_struct *p)
114 if (!static_branch_unlikely(&delayacct_key))
118 __delayacct_blkio_end(p);
121 static inline __u64 delayacct_blkio_ticks(struct task_struct *tsk)
124 return __delayacct_blkio_ticks(tsk);
128 static inline void delayacct_freepages_start(void)
130 if (!static_branch_unlikely(&delayacct_key))
134 __delayacct_freepages_start();
137 static inline void delayacct_freepages_end(void)
139 if (!static_branch_unlikely(&delayacct_key))
143 __delayacct_freepages_end();
146 static inline void delayacct_thrashing_start(bool *in_thrashing)
148 if (!static_branch_unlikely(&delayacct_key))
152 __delayacct_thrashing_start(in_thrashing);
155 static inline void delayacct_thrashing_end(bool *in_thrashing)
157 if (!static_branch_unlikely(&delayacct_key))
161 __delayacct_thrashing_end(in_thrashing);
164 static inline void delayacct_swapin_start(void)
166 if (!static_branch_unlikely(&delayacct_key))
170 __delayacct_swapin_start();
173 static inline void delayacct_swapin_end(void)
175 if (!static_branch_unlikely(&delayacct_key))
179 __delayacct_swapin_end();
182 static inline void delayacct_compact_start(void)
184 if (!static_branch_unlikely(&delayacct_key))
188 __delayacct_compact_start();
191 static inline void delayacct_compact_end(void)
193 if (!static_branch_unlikely(&delayacct_key))
197 __delayacct_compact_end();
200 static inline void delayacct_wpcopy_start(void)
202 if (!static_branch_unlikely(&delayacct_key))
206 __delayacct_wpcopy_start();
209 static inline void delayacct_wpcopy_end(void)
211 if (!static_branch_unlikely(&delayacct_key))
215 __delayacct_wpcopy_end();
219 static inline void delayacct_init(void)
221 static inline void delayacct_tsk_init(struct task_struct *tsk)
223 static inline void delayacct_tsk_free(struct task_struct *tsk)
225 static inline void delayacct_blkio_start(void)
227 static inline void delayacct_blkio_end(struct task_struct *p)
229 static inline int delayacct_add_tsk(struct taskstats *d,
230 struct task_struct *tsk)
232 static inline __u64 delayacct_blkio_ticks(struct task_struct *tsk)
234 static inline int delayacct_is_task_waiting_on_io(struct task_struct *p)
236 static inline void delayacct_freepages_start(void)
238 static inline void delayacct_freepages_end(void)
240 static inline void delayacct_thrashing_start(bool *in_thrashing)
242 static inline void delayacct_thrashing_end(bool *in_thrashing)
244 static inline void delayacct_swapin_start(void)
246 static inline void delayacct_swapin_end(void)
248 static inline void delayacct_compact_start(void)
250 static inline void delayacct_compact_end(void)
252 static inline void delayacct_wpcopy_start(void)
254 static inline void delayacct_wpcopy_end(void)
257 #endif /* CONFIG_TASK_DELAY_ACCT */