Commit | Line | Data |
---|---|---|
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 | 13 | struct 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; |
47913d4e | 32 | u64 blkio_delay; /* wait for sync block io completion */ |
a3d5dc90 YY |
33 | u64 swapin_start; |
34 | u64 swapin_delay; /* wait for swapin */ | |
47913d4e IM |
35 | u32 blkio_count; /* total count of the number of sync block */ |
36 | /* io operations performed */ | |
a3d5dc90 | 37 | u32 swapin_count; /* total count of swapin */ |
47913d4e IM |
38 | |
39 | u64 freepages_start; | |
40 | u64 freepages_delay; /* wait for memory reclaim */ | |
b1d29ba8 JW |
41 | |
42 | u64 thrashing_start; | |
43 | u64 thrashing_delay; /* wait for thrashing page */ | |
44 | ||
47913d4e | 45 | u32 freepages_count; /* total count of memory reclaim */ |
b1d29ba8 | 46 | u32 thrashing_count; /* total count of thrash waits */ |
47913d4e IM |
47 | }; |
48 | #endif | |
49 | ||
50 | #include <linux/sched.h> | |
51 | #include <linux/slab.h> | |
eee4d9fe | 52 | #include <linux/jump_label.h> |
47913d4e IM |
53 | |
54 | #ifdef CONFIG_TASK_DELAY_ACCT | |
e4042ad4 | 55 | DECLARE_STATIC_KEY_FALSE(delayacct_key); |
ca74e92b | 56 | extern int delayacct_on; /* Delay accounting turned on/off */ |
e18b890b | 57 | extern struct kmem_cache *delayacct_cache; |
ca74e92b | 58 | extern void delayacct_init(void); |
0cd7c741 PZ |
59 | |
60 | extern int sysctl_delayacct(struct ctl_table *table, int write, void *buffer, | |
61 | size_t *lenp, loff_t *ppos); | |
62 | ||
ca74e92b SN |
63 | extern void __delayacct_tsk_init(struct task_struct *); |
64 | extern void __delayacct_tsk_exit(struct task_struct *); | |
0ff92245 | 65 | extern void __delayacct_blkio_start(void); |
c96f5471 | 66 | extern void __delayacct_blkio_end(struct task_struct *); |
e4042ad4 | 67 | extern int delayacct_add_tsk(struct taskstats *, struct task_struct *); |
25890454 | 68 | extern __u64 __delayacct_blkio_ticks(struct task_struct *); |
873b4771 KK |
69 | extern void __delayacct_freepages_start(void); |
70 | extern void __delayacct_freepages_end(void); | |
b1d29ba8 JW |
71 | extern void __delayacct_thrashing_start(void); |
72 | extern void __delayacct_thrashing_end(void); | |
a3d5dc90 YY |
73 | extern void __delayacct_swapin_start(void); |
74 | extern void __delayacct_swapin_end(void); | |
846c7bb0 | 75 | |
ca74e92b SN |
76 | static inline void delayacct_tsk_init(struct task_struct *tsk) |
77 | { | |
78 | /* reinitialize in case parent's non-null pointer was dup'ed*/ | |
79 | tsk->delays = NULL; | |
163ecdff | 80 | if (delayacct_on) |
ca74e92b SN |
81 | __delayacct_tsk_init(tsk); |
82 | } | |
83 | ||
35df17c5 SN |
84 | /* Free tsk->delays. Called from bad fork and __put_task_struct |
85 | * where there's no risk of tsk->delays being accessed elsewhere | |
86 | */ | |
87 | static inline void delayacct_tsk_free(struct task_struct *tsk) | |
ca74e92b SN |
88 | { |
89 | if (tsk->delays) | |
35df17c5 SN |
90 | kmem_cache_free(delayacct_cache, tsk->delays); |
91 | tsk->delays = NULL; | |
ca74e92b SN |
92 | } |
93 | ||
0ff92245 SN |
94 | static inline void delayacct_blkio_start(void) |
95 | { | |
e4042ad4 | 96 | if (!static_branch_unlikely(&delayacct_key)) |
eee4d9fe PZ |
97 | return; |
98 | ||
0ff92245 SN |
99 | if (current->delays) |
100 | __delayacct_blkio_start(); | |
101 | } | |
102 | ||
c96f5471 | 103 | static inline void delayacct_blkio_end(struct task_struct *p) |
0ff92245 | 104 | { |
e4042ad4 | 105 | if (!static_branch_unlikely(&delayacct_key)) |
eee4d9fe PZ |
106 | return; |
107 | ||
b512719f | 108 | if (p->delays) |
c96f5471 | 109 | __delayacct_blkio_end(p); |
0ff92245 SN |
110 | } |
111 | ||
25890454 SN |
112 | static inline __u64 delayacct_blkio_ticks(struct task_struct *tsk) |
113 | { | |
114 | if (tsk->delays) | |
115 | return __delayacct_blkio_ticks(tsk); | |
116 | return 0; | |
117 | } | |
118 | ||
873b4771 KK |
119 | static inline void delayacct_freepages_start(void) |
120 | { | |
82065b72 YY |
121 | if (!static_branch_unlikely(&delayacct_key)) |
122 | return; | |
123 | ||
873b4771 KK |
124 | if (current->delays) |
125 | __delayacct_freepages_start(); | |
126 | } | |
127 | ||
128 | static inline void delayacct_freepages_end(void) | |
129 | { | |
82065b72 YY |
130 | if (!static_branch_unlikely(&delayacct_key)) |
131 | return; | |
132 | ||
873b4771 KK |
133 | if (current->delays) |
134 | __delayacct_freepages_end(); | |
135 | } | |
136 | ||
b1d29ba8 JW |
137 | static inline void delayacct_thrashing_start(void) |
138 | { | |
82065b72 YY |
139 | if (!static_branch_unlikely(&delayacct_key)) |
140 | return; | |
141 | ||
b1d29ba8 JW |
142 | if (current->delays) |
143 | __delayacct_thrashing_start(); | |
144 | } | |
145 | ||
146 | static inline void delayacct_thrashing_end(void) | |
147 | { | |
82065b72 YY |
148 | if (!static_branch_unlikely(&delayacct_key)) |
149 | return; | |
150 | ||
b1d29ba8 JW |
151 | if (current->delays) |
152 | __delayacct_thrashing_end(); | |
153 | } | |
154 | ||
a3d5dc90 YY |
155 | static inline void delayacct_swapin_start(void) |
156 | { | |
82065b72 YY |
157 | if (!static_branch_unlikely(&delayacct_key)) |
158 | return; | |
159 | ||
a3d5dc90 YY |
160 | if (current->delays) |
161 | __delayacct_swapin_start(); | |
162 | } | |
163 | ||
164 | static inline void delayacct_swapin_end(void) | |
165 | { | |
82065b72 YY |
166 | if (!static_branch_unlikely(&delayacct_key)) |
167 | return; | |
168 | ||
a3d5dc90 YY |
169 | if (current->delays) |
170 | __delayacct_swapin_end(); | |
171 | } | |
172 | ||
ca74e92b | 173 | #else |
ca74e92b SN |
174 | static inline void delayacct_init(void) |
175 | {} | |
176 | static inline void delayacct_tsk_init(struct task_struct *tsk) | |
177 | {} | |
35df17c5 | 178 | static inline void delayacct_tsk_free(struct task_struct *tsk) |
ca74e92b | 179 | {} |
0ff92245 SN |
180 | static inline void delayacct_blkio_start(void) |
181 | {} | |
c96f5471 | 182 | static inline void delayacct_blkio_end(struct task_struct *p) |
0ff92245 | 183 | {} |
6f44993f SN |
184 | static inline int delayacct_add_tsk(struct taskstats *d, |
185 | struct task_struct *tsk) | |
186 | { return 0; } | |
25890454 SN |
187 | static inline __u64 delayacct_blkio_ticks(struct task_struct *tsk) |
188 | { return 0; } | |
846c7bb0 BS |
189 | static inline int delayacct_is_task_waiting_on_io(struct task_struct *p) |
190 | { return 0; } | |
873b4771 KK |
191 | static inline void delayacct_freepages_start(void) |
192 | {} | |
193 | static inline void delayacct_freepages_end(void) | |
194 | {} | |
b1d29ba8 JW |
195 | static inline void delayacct_thrashing_start(void) |
196 | {} | |
197 | static inline void delayacct_thrashing_end(void) | |
198 | {} | |
a3d5dc90 YY |
199 | static inline void delayacct_swapin_start(void) |
200 | {} | |
201 | static inline void delayacct_swapin_end(void) | |
202 | {} | |
873b4771 | 203 | |
ca74e92b SN |
204 | #endif /* CONFIG_TASK_DELAY_ACCT */ |
205 | ||
206 | #endif |