Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /* delayacct.h - per-task delay accounting
0003  *
0004  * Copyright (C) Shailabh Nagar, IBM Corp. 2006
0005  */
0006 
0007 #ifndef _LINUX_DELAYACCT_H
0008 #define _LINUX_DELAYACCT_H
0009 
0010 #include <uapi/linux/taskstats.h>
0011 
0012 #ifdef CONFIG_TASK_DELAY_ACCT
0013 struct task_delay_info {
0014     raw_spinlock_t  lock;
0015 
0016     /* For each stat XXX, add following, aligned appropriately
0017      *
0018      * struct timespec XXX_start, XXX_end;
0019      * u64 XXX_delay;
0020      * u32 XXX_count;
0021      *
0022      * Atomicity of updates to XXX_delay, XXX_count protected by
0023      * single lock above (split into XXX_lock if contention is an issue).
0024      */
0025 
0026     /*
0027      * XXX_count is incremented on every XXX operation, the delay
0028      * associated with the operation is added to XXX_delay.
0029      * XXX_delay contains the accumulated delay time in nanoseconds.
0030      */
0031     u64 blkio_start;
0032     u64 blkio_delay;    /* wait for sync block io completion */
0033     u64 swapin_start;
0034     u64 swapin_delay;   /* wait for swapin */
0035     u32 blkio_count;    /* total count of the number of sync block */
0036                 /* io operations performed */
0037     u32 swapin_count;   /* total count of swapin */
0038 
0039     u64 freepages_start;
0040     u64 freepages_delay;    /* wait for memory reclaim */
0041 
0042     u64 thrashing_start;
0043     u64 thrashing_delay;    /* wait for thrashing page */
0044 
0045     u64 compact_start;
0046     u64 compact_delay;  /* wait for memory compact */
0047 
0048     u64 wpcopy_start;
0049     u64 wpcopy_delay;   /* wait for write-protect copy */
0050 
0051     u32 freepages_count;    /* total count of memory reclaim */
0052     u32 thrashing_count;    /* total count of thrash waits */
0053     u32 compact_count;  /* total count of memory compact */
0054     u32 wpcopy_count;   /* total count of write-protect copy */
0055 };
0056 #endif
0057 
0058 #include <linux/sched.h>
0059 #include <linux/slab.h>
0060 #include <linux/jump_label.h>
0061 
0062 #ifdef CONFIG_TASK_DELAY_ACCT
0063 DECLARE_STATIC_KEY_FALSE(delayacct_key);
0064 extern int delayacct_on;    /* Delay accounting turned on/off */
0065 extern struct kmem_cache *delayacct_cache;
0066 extern void delayacct_init(void);
0067 
0068 extern void __delayacct_tsk_init(struct task_struct *);
0069 extern void __delayacct_tsk_exit(struct task_struct *);
0070 extern void __delayacct_blkio_start(void);
0071 extern void __delayacct_blkio_end(struct task_struct *);
0072 extern int delayacct_add_tsk(struct taskstats *, struct task_struct *);
0073 extern __u64 __delayacct_blkio_ticks(struct task_struct *);
0074 extern void __delayacct_freepages_start(void);
0075 extern void __delayacct_freepages_end(void);
0076 extern void __delayacct_thrashing_start(void);
0077 extern void __delayacct_thrashing_end(void);
0078 extern void __delayacct_swapin_start(void);
0079 extern void __delayacct_swapin_end(void);
0080 extern void __delayacct_compact_start(void);
0081 extern void __delayacct_compact_end(void);
0082 extern void __delayacct_wpcopy_start(void);
0083 extern void __delayacct_wpcopy_end(void);
0084 
0085 static inline void delayacct_tsk_init(struct task_struct *tsk)
0086 {
0087     /* reinitialize in case parent's non-null pointer was dup'ed*/
0088     tsk->delays = NULL;
0089     if (delayacct_on)
0090         __delayacct_tsk_init(tsk);
0091 }
0092 
0093 /* Free tsk->delays. Called from bad fork and __put_task_struct
0094  * where there's no risk of tsk->delays being accessed elsewhere
0095  */
0096 static inline void delayacct_tsk_free(struct task_struct *tsk)
0097 {
0098     if (tsk->delays)
0099         kmem_cache_free(delayacct_cache, tsk->delays);
0100     tsk->delays = NULL;
0101 }
0102 
0103 static inline void delayacct_blkio_start(void)
0104 {
0105     if (!static_branch_unlikely(&delayacct_key))
0106         return;
0107 
0108     if (current->delays)
0109         __delayacct_blkio_start();
0110 }
0111 
0112 static inline void delayacct_blkio_end(struct task_struct *p)
0113 {
0114     if (!static_branch_unlikely(&delayacct_key))
0115         return;
0116 
0117     if (p->delays)
0118         __delayacct_blkio_end(p);
0119 }
0120 
0121 static inline __u64 delayacct_blkio_ticks(struct task_struct *tsk)
0122 {
0123     if (tsk->delays)
0124         return __delayacct_blkio_ticks(tsk);
0125     return 0;
0126 }
0127 
0128 static inline void delayacct_freepages_start(void)
0129 {
0130     if (!static_branch_unlikely(&delayacct_key))
0131         return;
0132 
0133     if (current->delays)
0134         __delayacct_freepages_start();
0135 }
0136 
0137 static inline void delayacct_freepages_end(void)
0138 {
0139     if (!static_branch_unlikely(&delayacct_key))
0140         return;
0141 
0142     if (current->delays)
0143         __delayacct_freepages_end();
0144 }
0145 
0146 static inline void delayacct_thrashing_start(void)
0147 {
0148     if (!static_branch_unlikely(&delayacct_key))
0149         return;
0150 
0151     if (current->delays)
0152         __delayacct_thrashing_start();
0153 }
0154 
0155 static inline void delayacct_thrashing_end(void)
0156 {
0157     if (!static_branch_unlikely(&delayacct_key))
0158         return;
0159 
0160     if (current->delays)
0161         __delayacct_thrashing_end();
0162 }
0163 
0164 static inline void delayacct_swapin_start(void)
0165 {
0166     if (!static_branch_unlikely(&delayacct_key))
0167         return;
0168 
0169     if (current->delays)
0170         __delayacct_swapin_start();
0171 }
0172 
0173 static inline void delayacct_swapin_end(void)
0174 {
0175     if (!static_branch_unlikely(&delayacct_key))
0176         return;
0177 
0178     if (current->delays)
0179         __delayacct_swapin_end();
0180 }
0181 
0182 static inline void delayacct_compact_start(void)
0183 {
0184     if (!static_branch_unlikely(&delayacct_key))
0185         return;
0186 
0187     if (current->delays)
0188         __delayacct_compact_start();
0189 }
0190 
0191 static inline void delayacct_compact_end(void)
0192 {
0193     if (!static_branch_unlikely(&delayacct_key))
0194         return;
0195 
0196     if (current->delays)
0197         __delayacct_compact_end();
0198 }
0199 
0200 static inline void delayacct_wpcopy_start(void)
0201 {
0202     if (!static_branch_unlikely(&delayacct_key))
0203         return;
0204 
0205     if (current->delays)
0206         __delayacct_wpcopy_start();
0207 }
0208 
0209 static inline void delayacct_wpcopy_end(void)
0210 {
0211     if (!static_branch_unlikely(&delayacct_key))
0212         return;
0213 
0214     if (current->delays)
0215         __delayacct_wpcopy_end();
0216 }
0217 
0218 #else
0219 static inline void delayacct_init(void)
0220 {}
0221 static inline void delayacct_tsk_init(struct task_struct *tsk)
0222 {}
0223 static inline void delayacct_tsk_free(struct task_struct *tsk)
0224 {}
0225 static inline void delayacct_blkio_start(void)
0226 {}
0227 static inline void delayacct_blkio_end(struct task_struct *p)
0228 {}
0229 static inline int delayacct_add_tsk(struct taskstats *d,
0230                     struct task_struct *tsk)
0231 { return 0; }
0232 static inline __u64 delayacct_blkio_ticks(struct task_struct *tsk)
0233 { return 0; }
0234 static inline int delayacct_is_task_waiting_on_io(struct task_struct *p)
0235 { return 0; }
0236 static inline void delayacct_freepages_start(void)
0237 {}
0238 static inline void delayacct_freepages_end(void)
0239 {}
0240 static inline void delayacct_thrashing_start(void)
0241 {}
0242 static inline void delayacct_thrashing_end(void)
0243 {}
0244 static inline void delayacct_swapin_start(void)
0245 {}
0246 static inline void delayacct_swapin_end(void)
0247 {}
0248 static inline void delayacct_compact_start(void)
0249 {}
0250 static inline void delayacct_compact_end(void)
0251 {}
0252 static inline void delayacct_wpcopy_start(void)
0253 {}
0254 static inline void delayacct_wpcopy_end(void)
0255 {}
0256 
0257 #endif /* CONFIG_TASK_DELAY_ACCT */
0258 
0259 #endif