delayacct.c (0ff922452df86f3e9a2c6f705c4588ec62d096a7) | delayacct.c (6f44993fe1d7b2b097f6ac60cd5835c6f5ca0874) |
---|---|
1/* delayacct.c - per-task delay accounting 2 * 3 * Copyright (C) Shailabh Nagar, IBM Corp. 2006 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. --- 27 unchanged lines hidden (view full) --- 36 0, 37 SLAB_PANIC, 38 NULL, NULL); 39 delayacct_tsk_init(&init_task); 40} 41 42void __delayacct_tsk_init(struct task_struct *tsk) 43{ | 1/* delayacct.c - per-task delay accounting 2 * 3 * Copyright (C) Shailabh Nagar, IBM Corp. 2006 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. --- 27 unchanged lines hidden (view full) --- 36 0, 37 SLAB_PANIC, 38 NULL, NULL); 39 delayacct_tsk_init(&init_task); 40} 41 42void __delayacct_tsk_init(struct task_struct *tsk) 43{ |
44 spin_lock_init(&tsk->delays_lock); 45 /* No need to acquire tsk->delays_lock for allocation here unless 46 __delayacct_tsk_init called after tsk is attached to tasklist 47 */ |
|
44 tsk->delays = kmem_cache_zalloc(delayacct_cache, SLAB_KERNEL); 45 if (tsk->delays) 46 spin_lock_init(&tsk->delays->lock); 47} 48 49void __delayacct_tsk_exit(struct task_struct *tsk) 50{ | 48 tsk->delays = kmem_cache_zalloc(delayacct_cache, SLAB_KERNEL); 49 if (tsk->delays) 50 spin_lock_init(&tsk->delays->lock); 51} 52 53void __delayacct_tsk_exit(struct task_struct *tsk) 54{ |
51 kmem_cache_free(delayacct_cache, tsk->delays); | 55 struct task_delay_info *delays = tsk->delays; 56 spin_lock(&tsk->delays_lock); |
52 tsk->delays = NULL; | 57 tsk->delays = NULL; |
58 spin_unlock(&tsk->delays_lock); 59 kmem_cache_free(delayacct_cache, delays); |
|
53} 54 55/* 56 * Start accounting for a delay statistic using 57 * its starting timestamp (@start) 58 */ 59 60static inline void delayacct_start(struct timespec *start) --- 38 unchanged lines hidden (view full) --- 99 ¤t->delays->swapin_delay, 100 ¤t->delays->swapin_count); 101 else /* Other block I/O */ 102 delayacct_end(¤t->delays->blkio_start, 103 ¤t->delays->blkio_end, 104 ¤t->delays->blkio_delay, 105 ¤t->delays->blkio_count); 106} | 60} 61 62/* 63 * Start accounting for a delay statistic using 64 * its starting timestamp (@start) 65 */ 66 67static inline void delayacct_start(struct timespec *start) --- 38 unchanged lines hidden (view full) --- 106 ¤t->delays->swapin_delay, 107 ¤t->delays->swapin_count); 108 else /* Other block I/O */ 109 delayacct_end(¤t->delays->blkio_start, 110 ¤t->delays->blkio_end, 111 ¤t->delays->blkio_delay, 112 ¤t->delays->blkio_count); 113} |
114 115int __delayacct_add_tsk(struct taskstats *d, struct task_struct *tsk) 116{ 117 s64 tmp; 118 struct timespec ts; 119 unsigned long t1,t2,t3; 120 121 spin_lock(&tsk->delays_lock); 122 123 /* Though tsk->delays accessed later, early exit avoids 124 * unnecessary returning of other data 125 */ 126 if (!tsk->delays) 127 goto done; 128 129 tmp = (s64)d->cpu_run_real_total; 130 cputime_to_timespec(tsk->utime + tsk->stime, &ts); 131 tmp += timespec_to_ns(&ts); 132 d->cpu_run_real_total = (tmp < (s64)d->cpu_run_real_total) ? 0 : tmp; 133 134 /* 135 * No locking available for sched_info (and too expensive to add one) 136 * Mitigate by taking snapshot of values 137 */ 138 t1 = tsk->sched_info.pcnt; 139 t2 = tsk->sched_info.run_delay; 140 t3 = tsk->sched_info.cpu_time; 141 142 d->cpu_count += t1; 143 144 jiffies_to_timespec(t2, &ts); 145 tmp = (s64)d->cpu_delay_total + timespec_to_ns(&ts); 146 d->cpu_delay_total = (tmp < (s64)d->cpu_delay_total) ? 0 : tmp; 147 148 tmp = (s64)d->cpu_run_virtual_total + (s64)jiffies_to_usecs(t3) * 1000; 149 d->cpu_run_virtual_total = 150 (tmp < (s64)d->cpu_run_virtual_total) ? 0 : tmp; 151 152 /* zero XXX_total, non-zero XXX_count implies XXX stat overflowed */ 153 154 spin_lock(&tsk->delays->lock); 155 tmp = d->blkio_delay_total + tsk->delays->blkio_delay; 156 d->blkio_delay_total = (tmp < d->blkio_delay_total) ? 0 : tmp; 157 tmp = d->swapin_delay_total + tsk->delays->swapin_delay; 158 d->swapin_delay_total = (tmp < d->swapin_delay_total) ? 0 : tmp; 159 d->blkio_count += tsk->delays->blkio_count; 160 d->swapin_count += tsk->delays->swapin_count; 161 spin_unlock(&tsk->delays->lock); 162 163done: 164 spin_unlock(&tsk->delays_lock); 165 return 0; 166} |
|