]>
git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/blob - include/linux/delayacct.h
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>
13 * Per-task flags relevant to delay accounting
14 * maintained privately to avoid exhausting similar flags in sched.h:PF_*
15 * Used to set current->delays->flags
17 #define DELAYACCT_PF_SWAPIN 0x00000001 /* I am doing a swapin */
18 #define DELAYACCT_PF_BLKIO 0x00000002 /* I am waiting on IO */
20 #ifdef CONFIG_TASK_DELAY_ACCT
21 struct task_delay_info
{
23 unsigned int flags
; /* Private per-task flags */
25 /* For each stat XXX, add following, aligned appropriately
27 * struct timespec XXX_start, XXX_end;
31 * Atomicity of updates to XXX_delay, XXX_count protected by
32 * single lock above (split into XXX_lock if contention is an issue).
36 * XXX_count is incremented on every XXX operation, the delay
37 * associated with the operation is added to XXX_delay.
38 * XXX_delay contains the accumulated delay time in nanoseconds.
40 u64 blkio_start
; /* Shared by blkio, swapin */
41 u64 blkio_delay
; /* wait for sync block io completion */
42 u64 swapin_delay
; /* wait for swapin block io completion */
43 u32 blkio_count
; /* total count of the number of sync block */
44 /* io operations performed */
45 u32 swapin_count
; /* total count of the number of swapin block */
46 /* io operations performed */
49 u64 freepages_delay
; /* wait for memory reclaim */
52 u64 thrashing_delay
; /* wait for thrashing page */
54 u32 freepages_count
; /* total count of memory reclaim */
55 u32 thrashing_count
; /* total count of thrash waits */
59 #include <linux/sched.h>
60 #include <linux/slab.h>
62 #ifdef CONFIG_TASK_DELAY_ACCT
63 extern int delayacct_on
; /* Delay accounting turned on/off */
64 extern struct kmem_cache
*delayacct_cache
;
65 extern void delayacct_init(void);
66 extern void __delayacct_tsk_init(struct task_struct
*);
67 extern void __delayacct_tsk_exit(struct task_struct
*);
68 extern void __delayacct_blkio_start(void);
69 extern void __delayacct_blkio_end(struct task_struct
*);
70 extern int __delayacct_add_tsk(struct taskstats
*, struct task_struct
*);
71 extern __u64
__delayacct_blkio_ticks(struct task_struct
*);
72 extern void __delayacct_freepages_start(void);
73 extern void __delayacct_freepages_end(void);
74 extern void __delayacct_thrashing_start(void);
75 extern void __delayacct_thrashing_end(void);
77 static inline int delayacct_is_task_waiting_on_io(struct task_struct
*p
)
80 return (p
->delays
->flags
& DELAYACCT_PF_BLKIO
);
85 static inline void delayacct_set_flag(int flag
)
88 current
->delays
->flags
|= flag
;
91 static inline void delayacct_clear_flag(int flag
)
94 current
->delays
->flags
&= ~flag
;
97 static inline void delayacct_tsk_init(struct task_struct
*tsk
)
99 /* reinitialize in case parent's non-null pointer was dup'ed*/
102 __delayacct_tsk_init(tsk
);
105 /* Free tsk->delays. Called from bad fork and __put_task_struct
106 * where there's no risk of tsk->delays being accessed elsewhere
108 static inline void delayacct_tsk_free(struct task_struct
*tsk
)
111 kmem_cache_free(delayacct_cache
, tsk
->delays
);
115 static inline void delayacct_blkio_start(void)
117 delayacct_set_flag(DELAYACCT_PF_BLKIO
);
119 __delayacct_blkio_start();
122 static inline void delayacct_blkio_end(struct task_struct
*p
)
125 __delayacct_blkio_end(p
);
126 delayacct_clear_flag(DELAYACCT_PF_BLKIO
);
129 static inline int delayacct_add_tsk(struct taskstats
*d
,
130 struct task_struct
*tsk
)
132 if (!delayacct_on
|| !tsk
->delays
)
134 return __delayacct_add_tsk(d
, tsk
);
137 static inline __u64
delayacct_blkio_ticks(struct task_struct
*tsk
)
140 return __delayacct_blkio_ticks(tsk
);
144 static inline void delayacct_freepages_start(void)
147 __delayacct_freepages_start();
150 static inline void delayacct_freepages_end(void)
153 __delayacct_freepages_end();
156 static inline void delayacct_thrashing_start(void)
159 __delayacct_thrashing_start();
162 static inline void delayacct_thrashing_end(void)
165 __delayacct_thrashing_end();
169 static inline void delayacct_set_flag(int flag
)
171 static inline void delayacct_clear_flag(int flag
)
173 static inline void delayacct_init(void)
175 static inline void delayacct_tsk_init(struct task_struct
*tsk
)
177 static inline void delayacct_tsk_free(struct task_struct
*tsk
)
179 static inline void delayacct_blkio_start(void)
181 static inline void delayacct_blkio_end(struct task_struct
*p
)
183 static inline int delayacct_add_tsk(struct taskstats
*d
,
184 struct task_struct
*tsk
)
186 static inline __u64
delayacct_blkio_ticks(struct task_struct
*tsk
)
188 static inline int delayacct_is_task_waiting_on_io(struct task_struct
*p
)
190 static inline void delayacct_freepages_start(void)
192 static inline void delayacct_freepages_end(void)
194 static inline void delayacct_thrashing_start(void)
196 static inline void delayacct_thrashing_end(void)
199 #endif /* CONFIG_TASK_DELAY_ACCT */