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 */
48 u32 freepages_count; /* total count of memory reclaim */
49 u32 thrashing_count; /* total count of thrash waits */
50 u32 compact_count; /* total count of memory compact */
54 #include <linux/sched.h>
55 #include <linux/slab.h>
56 #include <linux/jump_label.h>
58 #ifdef CONFIG_TASK_DELAY_ACCT
59 DECLARE_STATIC_KEY_FALSE(delayacct_key);
60 extern int delayacct_on; /* Delay accounting turned on/off */
61 extern struct kmem_cache *delayacct_cache;
62 extern void delayacct_init(void);
64 extern int sysctl_delayacct(struct ctl_table *table, int write, void *buffer,
65 size_t *lenp, loff_t *ppos);
67 extern void __delayacct_tsk_init(struct task_struct *);
68 extern void __delayacct_tsk_exit(struct task_struct *);
69 extern void __delayacct_blkio_start(void);
70 extern void __delayacct_blkio_end(struct task_struct *);
71 extern int delayacct_add_tsk(struct taskstats *, struct task_struct *);
72 extern __u64 __delayacct_blkio_ticks(struct task_struct *);
73 extern void __delayacct_freepages_start(void);
74 extern void __delayacct_freepages_end(void);
75 extern void __delayacct_thrashing_start(void);
76 extern void __delayacct_thrashing_end(void);
77 extern void __delayacct_swapin_start(void);
78 extern void __delayacct_swapin_end(void);
79 extern void __delayacct_compact_start(void);
80 extern void __delayacct_compact_end(void);
82 static inline void delayacct_tsk_init(struct task_struct *tsk)
84 /* reinitialize in case parent's non-null pointer was dup'ed*/
87 __delayacct_tsk_init(tsk);
90 /* Free tsk->delays. Called from bad fork and __put_task_struct
91 * where there's no risk of tsk->delays being accessed elsewhere
93 static inline void delayacct_tsk_free(struct task_struct *tsk)
96 kmem_cache_free(delayacct_cache, tsk->delays);
100 static inline void delayacct_blkio_start(void)
102 if (!static_branch_unlikely(&delayacct_key))
106 __delayacct_blkio_start();
109 static inline void delayacct_blkio_end(struct task_struct *p)
111 if (!static_branch_unlikely(&delayacct_key))
115 __delayacct_blkio_end(p);
118 static inline __u64 delayacct_blkio_ticks(struct task_struct *tsk)
121 return __delayacct_blkio_ticks(tsk);
125 static inline void delayacct_freepages_start(void)
127 if (!static_branch_unlikely(&delayacct_key))
131 __delayacct_freepages_start();
134 static inline void delayacct_freepages_end(void)
136 if (!static_branch_unlikely(&delayacct_key))
140 __delayacct_freepages_end();
143 static inline void delayacct_thrashing_start(void)
145 if (!static_branch_unlikely(&delayacct_key))
149 __delayacct_thrashing_start();
152 static inline void delayacct_thrashing_end(void)
154 if (!static_branch_unlikely(&delayacct_key))
158 __delayacct_thrashing_end();
161 static inline void delayacct_swapin_start(void)
163 if (!static_branch_unlikely(&delayacct_key))
167 __delayacct_swapin_start();
170 static inline void delayacct_swapin_end(void)
172 if (!static_branch_unlikely(&delayacct_key))
176 __delayacct_swapin_end();
179 static inline void delayacct_compact_start(void)
181 if (!static_branch_unlikely(&delayacct_key))
185 __delayacct_compact_start();
188 static inline void delayacct_compact_end(void)
190 if (!static_branch_unlikely(&delayacct_key))
194 __delayacct_compact_end();
198 static inline void delayacct_init(void)
200 static inline void delayacct_tsk_init(struct task_struct *tsk)
202 static inline void delayacct_tsk_free(struct task_struct *tsk)
204 static inline void delayacct_blkio_start(void)
206 static inline void delayacct_blkio_end(struct task_struct *p)
208 static inline int delayacct_add_tsk(struct taskstats *d,
209 struct task_struct *tsk)
211 static inline __u64 delayacct_blkio_ticks(struct task_struct *tsk)
213 static inline int delayacct_is_task_waiting_on_io(struct task_struct *p)
215 static inline void delayacct_freepages_start(void)
217 static inline void delayacct_freepages_end(void)
219 static inline void delayacct_thrashing_start(void)
221 static inline void delayacct_thrashing_end(void)
223 static inline void delayacct_swapin_start(void)
225 static inline void delayacct_swapin_end(void)
227 static inline void delayacct_compact_start(void)
229 static inline void delayacct_compact_end(void)
232 #endif /* CONFIG_TASK_DELAY_ACCT */