| 1 |
|
| 2 | |
| 3 | *
|
| 4 | * Copyright (C) Shailabh Nagar, IBM Corp. 2006
|
| 5 |
|
| 6 |
|
| 7 | #ifndef _LINUX_DELAYACCT_H
|
| 8 | #define _LINUX_DELAYACCT_H
|
| 9 |
|
| 10 | #include <uapi/linux/taskstats.h>
|
| 11 |
|
| 12 | #ifdef CONFIG_TASK_DELAY_ACCT
|
| 13 | struct task_delay_info {
|
| 14 | raw_spinlock_t lock;
|
| 15 |
|
| 16 | |
| 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 |
|
| 31 | u64 blkio_start;
|
| 32 | u64 blkio_delay_max;
|
| 33 | u64 blkio_delay_min;
|
| 34 | u64 blkio_delay;
|
| 35 | u64 swapin_start;
|
| 36 | u64 swapin_delay_max;
|
| 37 | u64 swapin_delay_min;
|
| 38 | u64 swapin_delay;
|
| 39 | u32 blkio_count;
|
| 40 |
|
| 41 | u32 swapin_count;
|
| 42 |
|
| 43 | u64 freepages_start;
|
| 44 | u64 freepages_delay_max;
|
| 45 | u64 freepages_delay_min;
|
| 46 | u64 freepages_delay;
|
| 47 |
|
| 48 | u64 thrashing_start;
|
| 49 | u64 thrashing_delay_max;
|
| 50 | u64 thrashing_delay_min;
|
| 51 | u64 thrashing_delay;
|
| 52 |
|
| 53 | u64 compact_start;
|
| 54 | u64 compact_delay_max;
|
| 55 | u64 compact_delay_min;
|
| 56 | u64 compact_delay;
|
| 57 |
|
| 58 | u64 wpcopy_start;
|
| 59 | u64 wpcopy_delay_max;
|
| 60 | u64 wpcopy_delay_min;
|
| 61 | u64 wpcopy_delay;
|
| 62 |
|
| 63 | u64 irq_delay_max;
|
| 64 | u64 irq_delay_min;
|
| 65 | u64 irq_delay;
|
| 66 |
|
| 67 | u32 freepages_count;
|
| 68 | u32 thrashing_count;
|
| 69 | u32 compact_count;
|
| 70 | u32 wpcopy_count;
|
| 71 | u32 irq_count;
|
| 72 |
|
| 73 | struct timespec64 blkio_delay_max_ts;
|
| 74 | struct timespec64 swapin_delay_max_ts;
|
| 75 | struct timespec64 freepages_delay_max_ts;
|
| 76 | struct timespec64 thrashing_delay_max_ts;
|
| 77 | struct timespec64 compact_delay_max_ts;
|
| 78 | struct timespec64 wpcopy_delay_max_ts;
|
| 79 | struct timespec64 irq_delay_max_ts;
|
| 80 | };
|
| 81 | #endif
|
| 82 |
|
| 83 | #include <linux/sched.h>
|
| 84 | #include <linux/slab.h>
|
| 85 | #include <linux/jump_label.h>
|
| 86 |
|
| 87 | #ifdef CONFIG_TASK_DELAY_ACCT
|
| 88 | DECLARE_STATIC_KEY_FALSE(delayacct_key);
|
| 89 | extern int delayacct_on;
|
| 90 | extern struct kmem_cache *delayacct_cache;
|
| 91 | extern void delayacct_init(void);
|
| 92 |
|
| 93 | extern void __delayacct_tsk_init(struct task_struct *);
|
| 94 | extern void __delayacct_tsk_exit(struct task_struct *);
|
| 95 | extern void __delayacct_blkio_start(void);
|
| 96 | extern void __delayacct_blkio_end(struct task_struct *);
|
| 97 | extern int delayacct_add_tsk(struct taskstats *, struct task_struct *);
|
| 98 | extern __u64 __delayacct_blkio_ticks(struct task_struct *);
|
| 99 | extern void __delayacct_freepages_start(void);
|
| 100 | extern void __delayacct_freepages_end(void);
|
| 101 | extern void __delayacct_thrashing_start(bool *in_thrashing);
|
| 102 | extern void __delayacct_thrashing_end(bool *in_thrashing);
|
| 103 | extern void __delayacct_swapin_start(void);
|
| 104 | extern void __delayacct_swapin_end(void);
|
| 105 | extern void __delayacct_compact_start(void);
|
| 106 | extern void __delayacct_compact_end(void);
|
| 107 | extern void __delayacct_wpcopy_start(void);
|
| 108 | extern void __delayacct_wpcopy_end(void);
|
| 109 | extern void __delayacct_irq(struct task_struct *task, u32 delta);
|
| 110 |
|
| 111 | static inline void delayacct_tsk_init(struct task_struct *tsk)
|
| 112 | {
|
| 113 |
|
| 114 | tsk->delays = NULL;
|
| 115 | if (delayacct_on)
|
| 116 | __delayacct_tsk_init(tsk);
|
| 117 | }
|
| 118 |
|
| 119 | |
| 120 | * where there's no risk of tsk->delays being accessed elsewhere
|
| 121 |
|
| 122 | static inline void delayacct_tsk_free(struct task_struct *tsk)
|
| 123 | {
|
| 124 | if (tsk->delays)
|
| 125 | kmem_cache_free(delayacct_cache, tsk->delays);
|
| 126 | tsk->delays = NULL;
|
| 127 | }
|
| 128 |
|
| 129 | static inline void delayacct_blkio_start(void)
|
| 130 | {
|
| 131 | if (!static_branch_unlikely(&delayacct_key))
|
| 132 | return;
|
| 133 |
|
| 134 | if (current->delays)
|
| 135 | __delayacct_blkio_start();
|
| 136 | }
|
| 137 |
|
| 138 | static inline void delayacct_blkio_end(struct task_struct *p)
|
| 139 | {
|
| 140 | if (!static_branch_unlikely(&delayacct_key))
|
| 141 | return;
|
| 142 |
|
| 143 | if (p->delays)
|
| 144 | __delayacct_blkio_end(p);
|
| 145 | }
|
| 146 |
|
| 147 | static inline __u64 delayacct_blkio_ticks(struct task_struct *tsk)
|
| 148 | {
|
| 149 | if (tsk->delays)
|
| 150 | return __delayacct_blkio_ticks(tsk);
|
| 151 | return 0;
|
| 152 | }
|
| 153 |
|
| 154 | static inline void delayacct_freepages_start(void)
|
| 155 | {
|
| 156 | if (!static_branch_unlikely(&delayacct_key))
|
| 157 | return;
|
| 158 |
|
| 159 | if (current->delays)
|
| 160 | __delayacct_freepages_start();
|
| 161 | }
|
| 162 |
|
| 163 | static inline void delayacct_freepages_end(void)
|
| 164 | {
|
| 165 | if (!static_branch_unlikely(&delayacct_key))
|
| 166 | return;
|
| 167 |
|
| 168 | if (current->delays)
|
| 169 | __delayacct_freepages_end();
|
| 170 | }
|
| 171 |
|
| 172 | static inline void delayacct_thrashing_start(bool *in_thrashing)
|
| 173 | {
|
| 174 | if (!static_branch_unlikely(&delayacct_key))
|
| 175 | return;
|
| 176 |
|
| 177 | if (current->delays)
|
| 178 | __delayacct_thrashing_start(in_thrashing);
|
| 179 | }
|
| 180 |
|
| 181 | static inline void delayacct_thrashing_end(bool *in_thrashing)
|
| 182 | {
|
| 183 | if (!static_branch_unlikely(&delayacct_key))
|
| 184 | return;
|
| 185 |
|
| 186 | if (current->delays)
|
| 187 | __delayacct_thrashing_end(in_thrashing);
|
| 188 | }
|
| 189 |
|
| 190 | static inline void delayacct_swapin_start(void)
|
| 191 | {
|
| 192 | if (!static_branch_unlikely(&delayacct_key))
|
| 193 | return;
|
| 194 |
|
| 195 | if (current->delays)
|
| 196 | __delayacct_swapin_start();
|
| 197 | }
|
| 198 |
|
| 199 | static inline void delayacct_swapin_end(void)
|
| 200 | {
|
| 201 | if (!static_branch_unlikely(&delayacct_key))
|
| 202 | return;
|
| 203 |
|
| 204 | if (current->delays)
|
| 205 | __delayacct_swapin_end();
|
| 206 | }
|
| 207 |
|
| 208 | static inline void delayacct_compact_start(void)
|
| 209 | {
|
| 210 | if (!static_branch_unlikely(&delayacct_key))
|
| 211 | return;
|
| 212 |
|
| 213 | if (current->delays)
|
| 214 | __delayacct_compact_start();
|
| 215 | }
|
| 216 |
|
| 217 | static inline void delayacct_compact_end(void)
|
| 218 | {
|
| 219 | if (!static_branch_unlikely(&delayacct_key))
|
| 220 | return;
|
| 221 |
|
| 222 | if (current->delays)
|
| 223 | __delayacct_compact_end();
|
| 224 | }
|
| 225 |
|
| 226 | static inline void delayacct_wpcopy_start(void)
|
| 227 | {
|
| 228 | if (!static_branch_unlikely(&delayacct_key))
|
| 229 | return;
|
| 230 |
|
| 231 | if (current->delays)
|
| 232 | __delayacct_wpcopy_start();
|
| 233 | }
|
| 234 |
|
| 235 | static inline void delayacct_wpcopy_end(void)
|
| 236 | {
|
| 237 | if (!static_branch_unlikely(&delayacct_key))
|
| 238 | return;
|
| 239 |
|
| 240 | if (current->delays)
|
| 241 | __delayacct_wpcopy_end();
|
| 242 | }
|
| 243 |
|
| 244 | static inline void delayacct_irq(struct task_struct *task, u32 delta)
|
| 245 | {
|
| 246 | if (!static_branch_unlikely(&delayacct_key))
|
| 247 | return;
|
| 248 |
|
| 249 | if (task->delays)
|
| 250 | __delayacct_irq(task, delta);
|
| 251 | }
|
| 252 |
|
| 253 | #else
|
| 254 | static inline void delayacct_init(void)
|
| 255 | {}
|
| 256 | static inline void delayacct_tsk_init(struct task_struct *tsk)
|
| 257 | {}
|
| 258 | static inline void delayacct_tsk_free(struct task_struct *tsk)
|
| 259 | {}
|
| 260 | static inline void delayacct_blkio_start(void)
|
| 261 | {}
|
| 262 | static inline void delayacct_blkio_end(struct task_struct *p)
|
| 263 | {}
|
| 264 | static inline int delayacct_add_tsk(struct taskstats *d,
|
| 265 | struct task_struct *tsk)
|
| 266 | { return 0; }
|
| 267 | static inline __u64 delayacct_blkio_ticks(struct task_struct *tsk)
|
| 268 | { return 0; }
|
| 269 | static inline int delayacct_is_task_waiting_on_io(struct task_struct *p)
|
| 270 | { return 0; }
|
| 271 | static inline void delayacct_freepages_start(void)
|
| 272 | {}
|
| 273 | static inline void delayacct_freepages_end(void)
|
| 274 | {}
|
| 275 | static inline void delayacct_thrashing_start(bool *in_thrashing)
|
| 276 | {}
|
| 277 | static inline void delayacct_thrashing_end(bool *in_thrashing)
|
| 278 | {}
|
| 279 | static inline void delayacct_swapin_start(void)
|
| 280 | {}
|
| 281 | static inline void delayacct_swapin_end(void)
|
| 282 | {}
|
| 283 | static inline void delayacct_compact_start(void)
|
| 284 | {}
|
| 285 | static inline void delayacct_compact_end(void)
|
| 286 | {}
|
| 287 | static inline void delayacct_wpcopy_start(void)
|
| 288 | {}
|
| 289 | static inline void delayacct_wpcopy_end(void)
|
| 290 | {}
|
| 291 | static inline void delayacct_irq(struct task_struct *task, u32 delta)
|
| 292 | {}
|
| 293 |
|
| 294 | #endif
|
| 295 |
|
| 296 | #endif
|