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