diff options
| author | Linus Torvalds <torvalds@linux-foundation.org> | 2009-02-11 11:24:32 -0500 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-02-11 11:24:32 -0500 |
| commit | 94dba895333a4321f27360e42b807260ae36bda4 (patch) | |
| tree | 7b6381da7ea9fc176001dda0714725c3a1dd6cc7 | |
| parent | 9ce04f9238cafcfd09a502f2bc8c13b5f44ec590 (diff) | |
| parent | 4da94d49b2ecb0a26e716a8811c3ecc542c2a65d (diff) | |
Merge branch 'timers-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip
* 'timers-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip:
timers: fix TIMER_ABSTIME for process wide cpu timers
timers: split process wide cpu clocks/timers, fix
x86: clean up hpet timer reinit
timers: split process wide cpu clocks/timers, remove spurious warning
timers: split process wide cpu clocks/timers
signal: re-add dead task accumulation stats.
x86: fix hpet timer reinit for x86_64
sched: fix nohz load balancer on cpu offline
| -rw-r--r-- | arch/x86/kernel/hpet.c | 12 | ||||
| -rw-r--r-- | include/linux/init_task.h | 11 | ||||
| -rw-r--r-- | include/linux/sched.h | 64 | ||||
| -rw-r--r-- | kernel/exit.c | 3 | ||||
| -rw-r--r-- | kernel/fork.c | 3 | ||||
| -rw-r--r-- | kernel/itimer.c | 4 | ||||
| -rw-r--r-- | kernel/posix-cpu-timers.c | 117 | ||||
| -rw-r--r-- | kernel/sched.c | 17 | ||||
| -rw-r--r-- | kernel/sched_stats.h | 45 | ||||
| -rw-r--r-- | kernel/signal.c | 8 |
10 files changed, 209 insertions, 75 deletions
diff --git a/arch/x86/kernel/hpet.c b/arch/x86/kernel/hpet.c index 64d5ad0b8add..388254f69a2a 100644 --- a/arch/x86/kernel/hpet.c +++ b/arch/x86/kernel/hpet.c | |||
| @@ -897,7 +897,7 @@ static unsigned long hpet_rtc_flags; | |||
| 897 | static int hpet_prev_update_sec; | 897 | static int hpet_prev_update_sec; |
| 898 | static struct rtc_time hpet_alarm_time; | 898 | static struct rtc_time hpet_alarm_time; |
| 899 | static unsigned long hpet_pie_count; | 899 | static unsigned long hpet_pie_count; |
| 900 | static unsigned long hpet_t1_cmp; | 900 | static u32 hpet_t1_cmp; |
| 901 | static unsigned long hpet_default_delta; | 901 | static unsigned long hpet_default_delta; |
| 902 | static unsigned long hpet_pie_delta; | 902 | static unsigned long hpet_pie_delta; |
| 903 | static unsigned long hpet_pie_limit; | 903 | static unsigned long hpet_pie_limit; |
| @@ -905,6 +905,14 @@ static unsigned long hpet_pie_limit; | |||
| 905 | static rtc_irq_handler irq_handler; | 905 | static rtc_irq_handler irq_handler; |
| 906 | 906 | ||
| 907 | /* | 907 | /* |
| 908 | * Check that the hpet counter c1 is ahead of the c2 | ||
| 909 | */ | ||
| 910 | static inline int hpet_cnt_ahead(u32 c1, u32 c2) | ||
| 911 | { | ||
| 912 | return (s32)(c2 - c1) < 0; | ||
| 913 | } | ||
| 914 | |||
| 915 | /* | ||
| 908 | * Registers a IRQ handler. | 916 | * Registers a IRQ handler. |
| 909 | */ | 917 | */ |
| 910 | int hpet_register_irq_handler(rtc_irq_handler handler) | 918 | int hpet_register_irq_handler(rtc_irq_handler handler) |
| @@ -1075,7 +1083,7 @@ static void hpet_rtc_timer_reinit(void) | |||
| 1075 | hpet_t1_cmp += delta; | 1083 | hpet_t1_cmp += delta; |
| 1076 | hpet_writel(hpet_t1_cmp, HPET_T1_CMP); | 1084 | hpet_writel(hpet_t1_cmp, HPET_T1_CMP); |
| 1077 | lost_ints++; | 1085 | lost_ints++; |
| 1078 | } while ((long)(hpet_readl(HPET_COUNTER) - hpet_t1_cmp) > 0); | 1086 | } while (!hpet_cnt_ahead(hpet_t1_cmp, hpet_readl(HPET_COUNTER))); |
| 1079 | 1087 | ||
| 1080 | if (lost_ints) { | 1088 | if (lost_ints) { |
| 1081 | if (hpet_rtc_flags & RTC_PIE) | 1089 | if (hpet_rtc_flags & RTC_PIE) |
diff --git a/include/linux/init_task.h b/include/linux/init_task.h index ea0ea1a4c36f..e752d973fa21 100644 --- a/include/linux/init_task.h +++ b/include/linux/init_task.h | |||
| @@ -48,12 +48,11 @@ extern struct fs_struct init_fs; | |||
| 48 | .posix_timers = LIST_HEAD_INIT(sig.posix_timers), \ | 48 | .posix_timers = LIST_HEAD_INIT(sig.posix_timers), \ |
| 49 | .cpu_timers = INIT_CPU_TIMERS(sig.cpu_timers), \ | 49 | .cpu_timers = INIT_CPU_TIMERS(sig.cpu_timers), \ |
| 50 | .rlim = INIT_RLIMITS, \ | 50 | .rlim = INIT_RLIMITS, \ |
| 51 | .cputime = { .totals = { \ | 51 | .cputimer = { \ |
| 52 | .utime = cputime_zero, \ | 52 | .cputime = INIT_CPUTIME, \ |
| 53 | .stime = cputime_zero, \ | 53 | .running = 0, \ |
| 54 | .sum_exec_runtime = 0, \ | 54 | .lock = __SPIN_LOCK_UNLOCKED(sig.cputimer.lock), \ |
| 55 | .lock = __SPIN_LOCK_UNLOCKED(sig.cputime.totals.lock), \ | 55 | }, \ |
| 56 | }, }, \ | ||
| 57 | } | 56 | } |
| 58 | 57 | ||
| 59 | extern struct nsproxy init_nsproxy; | 58 | extern struct nsproxy init_nsproxy; |
diff --git a/include/linux/sched.h b/include/linux/sched.h index 2127e959e0f4..8981e52c714f 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h | |||
| @@ -443,7 +443,6 @@ struct pacct_struct { | |||
| 443 | * @utime: time spent in user mode, in &cputime_t units | 443 | * @utime: time spent in user mode, in &cputime_t units |
| 444 | * @stime: time spent in kernel mode, in &cputime_t units | 444 | * @stime: time spent in kernel mode, in &cputime_t units |
| 445 | * @sum_exec_runtime: total time spent on the CPU, in nanoseconds | 445 | * @sum_exec_runtime: total time spent on the CPU, in nanoseconds |
| 446 | * @lock: lock for fields in this struct | ||
| 447 | * | 446 | * |
| 448 | * This structure groups together three kinds of CPU time that are | 447 | * This structure groups together three kinds of CPU time that are |
| 449 | * tracked for threads and thread groups. Most things considering | 448 | * tracked for threads and thread groups. Most things considering |
| @@ -454,23 +453,33 @@ struct task_cputime { | |||
| 454 | cputime_t utime; | 453 | cputime_t utime; |
| 455 | cputime_t stime; | 454 | cputime_t stime; |
| 456 | unsigned long long sum_exec_runtime; | 455 | unsigned long long sum_exec_runtime; |
| 457 | spinlock_t lock; | ||
| 458 | }; | 456 | }; |
| 459 | /* Alternate field names when used to cache expirations. */ | 457 | /* Alternate field names when used to cache expirations. */ |
| 460 | #define prof_exp stime | 458 | #define prof_exp stime |
| 461 | #define virt_exp utime | 459 | #define virt_exp utime |
| 462 | #define sched_exp sum_exec_runtime | 460 | #define sched_exp sum_exec_runtime |
| 463 | 461 | ||
| 462 | #define INIT_CPUTIME \ | ||
| 463 | (struct task_cputime) { \ | ||
| 464 | .utime = cputime_zero, \ | ||
| 465 | .stime = cputime_zero, \ | ||
| 466 | .sum_exec_runtime = 0, \ | ||
| 467 | } | ||
| 468 | |||
| 464 | /** | 469 | /** |
| 465 | * struct thread_group_cputime - thread group interval timer counts | 470 | * struct thread_group_cputimer - thread group interval timer counts |
| 466 | * @totals: thread group interval timers; substructure for | 471 | * @cputime: thread group interval timers. |
| 467 | * uniprocessor kernel, per-cpu for SMP kernel. | 472 | * @running: non-zero when there are timers running and |
| 473 | * @cputime receives updates. | ||
| 474 | * @lock: lock for fields in this struct. | ||
| 468 | * | 475 | * |
| 469 | * This structure contains the version of task_cputime, above, that is | 476 | * This structure contains the version of task_cputime, above, that is |
| 470 | * used for thread group CPU clock calculations. | 477 | * used for thread group CPU timer calculations. |
| 471 | */ | 478 | */ |
| 472 | struct thread_group_cputime { | 479 | struct thread_group_cputimer { |
| 473 | struct task_cputime totals; | 480 | struct task_cputime cputime; |
| 481 | int running; | ||
| 482 | spinlock_t lock; | ||
| 474 | }; | 483 | }; |
| 475 | 484 | ||
| 476 | /* | 485 | /* |
| @@ -519,10 +528,10 @@ struct signal_struct { | |||
| 519 | cputime_t it_prof_incr, it_virt_incr; | 528 | cputime_t it_prof_incr, it_virt_incr; |
| 520 | 529 | ||
| 521 | /* | 530 | /* |
| 522 | * Thread group totals for process CPU clocks. | 531 | * Thread group totals for process CPU timers. |
| 523 | * See thread_group_cputime(), et al, for details. | 532 | * See thread_group_cputimer(), et al, for details. |
| 524 | */ | 533 | */ |
| 525 | struct thread_group_cputime cputime; | 534 | struct thread_group_cputimer cputimer; |
| 526 | 535 | ||
| 527 | /* Earliest-expiration cache. */ | 536 | /* Earliest-expiration cache. */ |
| 528 | struct task_cputime cputime_expires; | 537 | struct task_cputime cputime_expires; |
| @@ -559,7 +568,7 @@ struct signal_struct { | |||
| 559 | * Live threads maintain their own counters and add to these | 568 | * Live threads maintain their own counters and add to these |
| 560 | * in __exit_signal, except for the group leader. | 569 | * in __exit_signal, except for the group leader. |
| 561 | */ | 570 | */ |
| 562 | cputime_t cutime, cstime; | 571 | cputime_t utime, stime, cutime, cstime; |
| 563 | cputime_t gtime; | 572 | cputime_t gtime; |
| 564 | cputime_t cgtime; | 573 | cputime_t cgtime; |
| 565 | unsigned long nvcsw, nivcsw, cnvcsw, cnivcsw; | 574 | unsigned long nvcsw, nivcsw, cnvcsw, cnivcsw; |
| @@ -568,6 +577,14 @@ struct signal_struct { | |||
| 568 | struct task_io_accounting ioac; | 577 | struct task_io_accounting ioac; |
| 569 | 578 | ||
| 570 | /* | 579 | /* |
| 580 | * Cumulative ns of schedule CPU time fo dead threads in the | ||
| 581 | * group, not including a zombie group leader, (This only differs | ||
| 582 | * from jiffies_to_ns(utime + stime) if sched_clock uses something | ||
| 583 | * other than jiffies.) | ||
| 584 | */ | ||
| 585 | unsigned long long sum_sched_runtime; | ||
| 586 | |||
| 587 | /* | ||
| 571 | * We don't bother to synchronize most readers of this at all, | 588 | * We don't bother to synchronize most readers of this at all, |
| 572 | * because there is no reader checking a limit that actually needs | 589 | * because there is no reader checking a limit that actually needs |
| 573 | * to get both rlim_cur and rlim_max atomically, and either one | 590 | * to get both rlim_cur and rlim_max atomically, and either one |
| @@ -2183,27 +2200,14 @@ static inline int spin_needbreak(spinlock_t *lock) | |||
| 2183 | /* | 2200 | /* |
| 2184 | * Thread group CPU time accounting. | 2201 | * Thread group CPU time accounting. |
| 2185 | */ | 2202 | */ |
| 2186 | 2203 | void thread_group_cputime(struct task_struct *tsk, struct task_cputime *times); | |
| 2187 | static inline | 2204 | void thread_group_cputimer(struct task_struct *tsk, struct task_cputime *times); |
| 2188 | void thread_group_cputime(struct task_struct *tsk, struct task_cputime *times) | ||
| 2189 | { | ||
| 2190 | struct task_cputime *totals = &tsk->signal->cputime.totals; | ||
| 2191 | unsigned long flags; | ||
| 2192 | |||
| 2193 | spin_lock_irqsave(&totals->lock, flags); | ||
| 2194 | *times = *totals; | ||
| 2195 | spin_unlock_irqrestore(&totals->lock, flags); | ||
| 2196 | } | ||
| 2197 | 2205 | ||
| 2198 | static inline void thread_group_cputime_init(struct signal_struct *sig) | 2206 | static inline void thread_group_cputime_init(struct signal_struct *sig) |
| 2199 | { | 2207 | { |
| 2200 | sig->cputime.totals = (struct task_cputime){ | 2208 | sig->cputimer.cputime = INIT_CPUTIME; |
| 2201 | .utime = cputime_zero, | 2209 | spin_lock_init(&sig->cputimer.lock); |
| 2202 | .stime = cputime_zero, | 2210 | sig->cputimer.running = 0; |
| 2203 | .sum_exec_runtime = 0, | ||
| 2204 | }; | ||
| 2205 | |||
| 2206 | spin_lock_init(&sig->cputime.totals.lock); | ||
| 2207 | } | 2211 | } |
| 2208 | 2212 | ||
| 2209 | static inline void thread_group_cputime_free(struct signal_struct *sig) | 2213 | static inline void thread_group_cputime_free(struct signal_struct *sig) |
diff --git a/kernel/exit.c b/kernel/exit.c index f80dec3f1875..efd30ccf3858 100644 --- a/kernel/exit.c +++ b/kernel/exit.c | |||
| @@ -118,6 +118,8 @@ static void __exit_signal(struct task_struct *tsk) | |||
| 118 | * We won't ever get here for the group leader, since it | 118 | * We won't ever get here for the group leader, since it |
| 119 | * will have been the last reference on the signal_struct. | 119 | * will have been the last reference on the signal_struct. |
| 120 | */ | 120 | */ |
| 121 | sig->utime = cputime_add(sig->utime, task_utime(tsk)); | ||
| 122 | sig->stime = cputime_add(sig->stime, task_stime(tsk)); | ||
| 121 | sig->gtime = cputime_add(sig->gtime, task_gtime(tsk)); | 123 | sig->gtime = cputime_add(sig->gtime, task_gtime(tsk)); |
| 122 | sig->min_flt += tsk->min_flt; | 124 | sig->min_flt += tsk->min_flt; |
| 123 | sig->maj_flt += tsk->maj_flt; | 125 | sig->maj_flt += tsk->maj_flt; |
| @@ -126,6 +128,7 @@ static void __exit_signal(struct task_struct *tsk) | |||
| 126 | sig->inblock += task_io_get_inblock(tsk); | 128 | sig->inblock += task_io_get_inblock(tsk); |
| 127 | sig->oublock += task_io_get_oublock(tsk); | 129 | sig->oublock += task_io_get_oublock(tsk); |
| 128 | task_io_accounting_add(&sig->ioac, &tsk->ioac); | 130 | task_io_accounting_add(&sig->ioac, &tsk->ioac); |
| 131 | sig->sum_sched_runtime += tsk->se.sum_exec_runtime; | ||
| 129 | sig = NULL; /* Marker for below. */ | 132 | sig = NULL; /* Marker for below. */ |
| 130 | } | 133 | } |
| 131 | 134 | ||
diff --git a/kernel/fork.c b/kernel/fork.c index d624d50f7729..a66fbde20715 100644 --- a/kernel/fork.c +++ b/kernel/fork.c | |||
| @@ -851,13 +851,14 @@ static int copy_signal(unsigned long clone_flags, struct task_struct *tsk) | |||
| 851 | sig->tty_old_pgrp = NULL; | 851 | sig->tty_old_pgrp = NULL; |
| 852 | sig->tty = NULL; | 852 | sig->tty = NULL; |
| 853 | 853 | ||
| 854 | sig->cutime = sig->cstime = cputime_zero; | 854 | sig->utime = sig->stime = sig->cutime = sig->cstime = cputime_zero; |
| 855 | sig->gtime = cputime_zero; | 855 | sig->gtime = cputime_zero; |
| 856 | sig->cgtime = cputime_zero; | 856 | sig->cgtime = cputime_zero; |
| 857 | sig->nvcsw = sig->nivcsw = sig->cnvcsw = sig->cnivcsw = 0; | 857 | sig->nvcsw = sig->nivcsw = sig->cnvcsw = sig->cnivcsw = 0; |
| 858 | sig->min_flt = sig->maj_flt = sig->cmin_flt = sig->cmaj_flt = 0; | 858 | sig->min_flt = sig->maj_flt = sig->cmin_flt = sig->cmaj_flt = 0; |
| 859 | sig->inblock = sig->oublock = sig->cinblock = sig->coublock = 0; | 859 | sig->inblock = sig->oublock = sig->cinblock = sig->coublock = 0; |
| 860 | task_io_accounting_init(&sig->ioac); | 860 | task_io_accounting_init(&sig->ioac); |
| 861 | sig->sum_sched_runtime = 0; | ||
| 861 | taskstats_tgid_init(sig); | 862 | taskstats_tgid_init(sig); |
| 862 | 863 | ||
| 863 | task_lock(current->group_leader); | 864 | task_lock(current->group_leader); |
diff --git a/kernel/itimer.c b/kernel/itimer.c index 6a5fe93dd8bd..58762f7077ec 100644 --- a/kernel/itimer.c +++ b/kernel/itimer.c | |||
| @@ -62,7 +62,7 @@ int do_getitimer(int which, struct itimerval *value) | |||
| 62 | struct task_cputime cputime; | 62 | struct task_cputime cputime; |
| 63 | cputime_t utime; | 63 | cputime_t utime; |
| 64 | 64 | ||
| 65 | thread_group_cputime(tsk, &cputime); | 65 | thread_group_cputimer(tsk, &cputime); |
| 66 | utime = cputime.utime; | 66 | utime = cputime.utime; |
| 67 | if (cputime_le(cval, utime)) { /* about to fire */ | 67 | if (cputime_le(cval, utime)) { /* about to fire */ |
| 68 | cval = jiffies_to_cputime(1); | 68 | cval = jiffies_to_cputime(1); |
| @@ -82,7 +82,7 @@ int do_getitimer(int which, struct itimerval *value) | |||
| 82 | struct task_cputime times; | 82 | struct task_cputime times; |
| 83 | cputime_t ptime; | 83 | cputime_t ptime; |
| 84 | 84 | ||
| 85 | thread_group_cputime(tsk, ×); | 85 | thread_group_cputimer(tsk, ×); |
| 86 | ptime = cputime_add(times.utime, times.stime); | 86 | ptime = cputime_add(times.utime, times.stime); |
| 87 | if (cputime_le(cval, ptime)) { /* about to fire */ | 87 | if (cputime_le(cval, ptime)) { /* about to fire */ |
| 88 | cval = jiffies_to_cputime(1); | 88 | cval = jiffies_to_cputime(1); |
diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c index fa07da94d7be..2313a4cc14ea 100644 --- a/kernel/posix-cpu-timers.c +++ b/kernel/posix-cpu-timers.c | |||
| @@ -230,6 +230,71 @@ static int cpu_clock_sample(const clockid_t which_clock, struct task_struct *p, | |||
| 230 | return 0; | 230 | return 0; |
| 231 | } | 231 | } |
| 232 | 232 | ||
| 233 | void thread_group_cputime(struct task_struct *tsk, struct task_cputime *times) | ||
| 234 | { | ||
| 235 | struct sighand_struct *sighand; | ||
| 236 | struct signal_struct *sig; | ||
| 237 | struct task_struct *t; | ||
| 238 | |||
| 239 | *times = INIT_CPUTIME; | ||
| 240 | |||
| 241 | rcu_read_lock(); | ||
| 242 | sighand = rcu_dereference(tsk->sighand); | ||
| 243 | if (!sighand) | ||
| 244 | goto out; | ||
| 245 | |||
| 246 | sig = tsk->signal; | ||
| 247 | |||
| 248 | t = tsk; | ||
| 249 | do { | ||
| 250 | times->utime = cputime_add(times->utime, t->utime); | ||
| 251 | times->stime = cputime_add(times->stime, t->stime); | ||
| 252 | times->sum_exec_runtime += t->se.sum_exec_runtime; | ||
| 253 | |||
| 254 | t = next_thread(t); | ||
| 255 | } while (t != tsk); | ||
| 256 | |||
| 257 | times->utime = cputime_add(times->utime, sig->utime); | ||
| 258 | times->stime = cputime_add(times->stime, sig->stime); | ||
| 259 | times->sum_exec_runtime += sig->sum_sched_runtime; | ||
| 260 | out: | ||
| 261 | rcu_read_unlock(); | ||
| 262 | } | ||
| 263 | |||
| 264 | static void update_gt_cputime(struct task_cputime *a, struct task_cputime *b) | ||
| 265 | { | ||
| 266 | if (cputime_gt(b->utime, a->utime)) | ||
| 267 | a->utime = b->utime; | ||
| 268 | |||
| 269 | if (cputime_gt(b->stime, a->stime)) | ||
| 270 | a->stime = b->stime; | ||
| 271 | |||
| 272 | if (b->sum_exec_runtime > a->sum_exec_runtime) | ||
| 273 | a->sum_exec_runtime = b->sum_exec_runtime; | ||
| 274 | } | ||
| 275 | |||
| 276 | void thread_group_cputimer(struct task_struct *tsk, struct task_cputime *times) | ||
| 277 | { | ||
| 278 | struct thread_group_cputimer *cputimer = &tsk->signal->cputimer; | ||
| 279 | struct task_cputime sum; | ||
| 280 | unsigned long flags; | ||
| 281 | |||
| 282 | spin_lock_irqsave(&cputimer->lock, flags); | ||
| 283 | if (!cputimer->running) { | ||
| 284 | cputimer->running = 1; | ||
| 285 | /* | ||
| 286 | * The POSIX timer interface allows for absolute time expiry | ||
| 287 | * values through the TIMER_ABSTIME flag, therefore we have | ||
| 288 | * to synchronize the timer to the clock every time we start | ||
| 289 | * it. | ||
| 290 | */ | ||
| 291 | thread_group_cputime(tsk, &sum); | ||
| 292 | update_gt_cputime(&cputimer->cputime, &sum); | ||
| 293 | } | ||
| 294 | *times = cputimer->cputime; | ||
| 295 | spin_unlock_irqrestore(&cputimer->lock, flags); | ||
| 296 | } | ||
| 297 | |||
| 233 | /* | 298 | /* |
| 234 | * Sample a process (thread group) clock for the given group_leader task. | 299 | * Sample a process (thread group) clock for the given group_leader task. |
| 235 | * Must be called with tasklist_lock held for reading. | 300 | * Must be called with tasklist_lock held for reading. |
| @@ -457,7 +522,7 @@ void posix_cpu_timers_exit_group(struct task_struct *tsk) | |||
| 457 | { | 522 | { |
| 458 | struct task_cputime cputime; | 523 | struct task_cputime cputime; |
| 459 | 524 | ||
| 460 | thread_group_cputime(tsk, &cputime); | 525 | thread_group_cputimer(tsk, &cputime); |
| 461 | cleanup_timers(tsk->signal->cpu_timers, | 526 | cleanup_timers(tsk->signal->cpu_timers, |
| 462 | cputime.utime, cputime.stime, cputime.sum_exec_runtime); | 527 | cputime.utime, cputime.stime, cputime.sum_exec_runtime); |
| 463 | } | 528 | } |
| @@ -964,6 +1029,19 @@ static void check_thread_timers(struct task_struct *tsk, | |||
| 964 | } | 1029 | } |
| 965 | } | 1030 | } |
| 966 | 1031 | ||
| 1032 | static void stop_process_timers(struct task_struct *tsk) | ||
| 1033 | { | ||
| 1034 | struct thread_group_cputimer *cputimer = &tsk->signal->cputimer; | ||
| 1035 | unsigned long flags; | ||
| 1036 | |||
| 1037 | if (!cputimer->running) | ||
| 1038 | return; | ||
| 1039 | |||
| 1040 | spin_lock_irqsave(&cputimer->lock, flags); | ||
| 1041 | cputimer->running = 0; | ||
| 1042 | spin_unlock_irqrestore(&cputimer->lock, flags); | ||
| 1043 | } | ||
| 1044 | |||
| 967 | /* | 1045 | /* |
| 968 | * Check for any per-thread CPU timers that have fired and move them | 1046 | * Check for any per-thread CPU timers that have fired and move them |
| 969 | * off the tsk->*_timers list onto the firing list. Per-thread timers | 1047 | * off the tsk->*_timers list onto the firing list. Per-thread timers |
| @@ -987,13 +1065,15 @@ static void check_process_timers(struct task_struct *tsk, | |||
| 987 | sig->rlim[RLIMIT_CPU].rlim_cur == RLIM_INFINITY && | 1065 | sig->rlim[RLIMIT_CPU].rlim_cur == RLIM_INFINITY && |
| 988 | list_empty(&timers[CPUCLOCK_VIRT]) && | 1066 | list_empty(&timers[CPUCLOCK_VIRT]) && |
| 989 | cputime_eq(sig->it_virt_expires, cputime_zero) && | 1067 | cputime_eq(sig->it_virt_expires, cputime_zero) && |
| 990 | list_empty(&timers[CPUCLOCK_SCHED])) | 1068 | list_empty(&timers[CPUCLOCK_SCHED])) { |
| 1069 | stop_process_timers(tsk); | ||
| 991 | return; | 1070 | return; |
| 1071 | } | ||
| 992 | 1072 | ||
| 993 | /* | 1073 | /* |
| 994 | * Collect the current process totals. | 1074 | * Collect the current process totals. |
| 995 | */ | 1075 | */ |
| 996 | thread_group_cputime(tsk, &cputime); | 1076 | thread_group_cputimer(tsk, &cputime); |
| 997 | utime = cputime.utime; | 1077 | utime = cputime.utime; |
| 998 | ptime = cputime_add(utime, cputime.stime); | 1078 | ptime = cputime_add(utime, cputime.stime); |
| 999 | sum_sched_runtime = cputime.sum_exec_runtime; | 1079 | sum_sched_runtime = cputime.sum_exec_runtime; |
| @@ -1259,7 +1339,7 @@ static inline int fastpath_timer_check(struct task_struct *tsk) | |||
| 1259 | if (!task_cputime_zero(&sig->cputime_expires)) { | 1339 | if (!task_cputime_zero(&sig->cputime_expires)) { |
| 1260 | struct task_cputime group_sample; | 1340 | struct task_cputime group_sample; |
| 1261 | 1341 | ||
| 1262 | thread_group_cputime(tsk, &group_sample); | 1342 | thread_group_cputimer(tsk, &group_sample); |
| 1263 | if (task_cputime_expired(&group_sample, &sig->cputime_expires)) | 1343 | if (task_cputime_expired(&group_sample, &sig->cputime_expires)) |
| 1264 | return 1; | 1344 | return 1; |
| 1265 | } | 1345 | } |
| @@ -1329,6 +1409,33 @@ void run_posix_cpu_timers(struct task_struct *tsk) | |||
| 1329 | } | 1409 | } |
| 1330 | 1410 | ||
| 1331 | /* | 1411 | /* |
| 1412 | * Sample a process (thread group) timer for the given group_leader task. | ||
| 1413 | * Must be called with tasklist_lock held for reading. | ||
| 1414 | */ | ||
| 1415 | static int cpu_timer_sample_group(const clockid_t which_clock, | ||
| 1416 | struct task_struct *p, | ||
| 1417 | union cpu_time_count *cpu) | ||
| 1418 | { | ||
| 1419 | struct task_cputime cputime; | ||
| 1420 | |||
| 1421 | thread_group_cputimer(p, &cputime); | ||
| 1422 | switch (CPUCLOCK_WHICH(which_clock)) { | ||
| 1423 | default: | ||
| 1424 | return -EINVAL; | ||
| 1425 | case CPUCLOCK_PROF: | ||
| 1426 | cpu->cpu = cputime_add(cputime.utime, cputime.stime); | ||
| 1427 | break; | ||
| 1428 | case CPUCLOCK_VIRT: | ||
| 1429 | cpu->cpu = cputime.utime; | ||
| 1430 | break; | ||
| 1431 | case CPUCLOCK_SCHED: | ||
| 1432 | cpu->sched = cputime.sum_exec_runtime + task_delta_exec(p); | ||
| 1433 | break; | ||
| 1434 | } | ||
| 1435 | return 0; | ||
| 1436 | } | ||
| 1437 | |||
| 1438 | /* | ||
| 1332 | * Set one of the process-wide special case CPU timers. | 1439 | * Set one of the process-wide special case CPU timers. |
| 1333 | * The tsk->sighand->siglock must be held by the caller. | 1440 | * The tsk->sighand->siglock must be held by the caller. |
| 1334 | * The *newval argument is relative and we update it to be absolute, *oldval | 1441 | * The *newval argument is relative and we update it to be absolute, *oldval |
| @@ -1341,7 +1448,7 @@ void set_process_cpu_timer(struct task_struct *tsk, unsigned int clock_idx, | |||
| 1341 | struct list_head *head; | 1448 | struct list_head *head; |
| 1342 | 1449 | ||
| 1343 | BUG_ON(clock_idx == CPUCLOCK_SCHED); | 1450 | BUG_ON(clock_idx == CPUCLOCK_SCHED); |
| 1344 | cpu_clock_sample_group(clock_idx, tsk, &now); | 1451 | cpu_timer_sample_group(clock_idx, tsk, &now); |
| 1345 | 1452 | ||
| 1346 | if (oldval) { | 1453 | if (oldval) { |
| 1347 | if (!cputime_eq(*oldval, cputime_zero)) { | 1454 | if (!cputime_eq(*oldval, cputime_zero)) { |
diff --git a/kernel/sched.c b/kernel/sched.c index 8ee437a5ec1d..e72485033c48 100644 --- a/kernel/sched.c +++ b/kernel/sched.c | |||
| @@ -3890,19 +3890,24 @@ int select_nohz_load_balancer(int stop_tick) | |||
| 3890 | int cpu = smp_processor_id(); | 3890 | int cpu = smp_processor_id(); |
| 3891 | 3891 | ||
| 3892 | if (stop_tick) { | 3892 | if (stop_tick) { |
| 3893 | cpumask_set_cpu(cpu, nohz.cpu_mask); | ||
| 3894 | cpu_rq(cpu)->in_nohz_recently = 1; | 3893 | cpu_rq(cpu)->in_nohz_recently = 1; |
| 3895 | 3894 | ||
| 3896 | /* | 3895 | if (!cpu_active(cpu)) { |
| 3897 | * If we are going offline and still the leader, give up! | 3896 | if (atomic_read(&nohz.load_balancer) != cpu) |
| 3898 | */ | 3897 | return 0; |
| 3899 | if (!cpu_active(cpu) && | 3898 | |
| 3900 | atomic_read(&nohz.load_balancer) == cpu) { | 3899 | /* |
| 3900 | * If we are going offline and still the leader, | ||
| 3901 | * give up! | ||
| 3902 | */ | ||
| 3901 | if (atomic_cmpxchg(&nohz.load_balancer, cpu, -1) != cpu) | 3903 | if (atomic_cmpxchg(&nohz.load_balancer, cpu, -1) != cpu) |
| 3902 | BUG(); | 3904 | BUG(); |
| 3905 | |||
| 3903 | return 0; | 3906 | return 0; |
| 3904 | } | 3907 | } |
| 3905 | 3908 | ||
| 3909 | cpumask_set_cpu(cpu, nohz.cpu_mask); | ||
| 3910 | |||
| 3906 | /* time for ilb owner also to sleep */ | 3911 | /* time for ilb owner also to sleep */ |
| 3907 | if (cpumask_weight(nohz.cpu_mask) == num_online_cpus()) { | 3912 | if (cpumask_weight(nohz.cpu_mask) == num_online_cpus()) { |
| 3908 | if (atomic_read(&nohz.load_balancer) == cpu) | 3913 | if (atomic_read(&nohz.load_balancer) == cpu) |
diff --git a/kernel/sched_stats.h b/kernel/sched_stats.h index 8ab0cef8ecab..a8f93dd374e1 100644 --- a/kernel/sched_stats.h +++ b/kernel/sched_stats.h | |||
| @@ -296,19 +296,21 @@ sched_info_switch(struct task_struct *prev, struct task_struct *next) | |||
| 296 | static inline void account_group_user_time(struct task_struct *tsk, | 296 | static inline void account_group_user_time(struct task_struct *tsk, |
| 297 | cputime_t cputime) | 297 | cputime_t cputime) |
| 298 | { | 298 | { |
| 299 | struct task_cputime *times; | 299 | struct thread_group_cputimer *cputimer; |
| 300 | struct signal_struct *sig; | ||
| 301 | 300 | ||
| 302 | /* tsk == current, ensure it is safe to use ->signal */ | 301 | /* tsk == current, ensure it is safe to use ->signal */ |
| 303 | if (unlikely(tsk->exit_state)) | 302 | if (unlikely(tsk->exit_state)) |
| 304 | return; | 303 | return; |
| 305 | 304 | ||
| 306 | sig = tsk->signal; | 305 | cputimer = &tsk->signal->cputimer; |
| 307 | times = &sig->cputime.totals; | ||
| 308 | 306 | ||
| 309 | spin_lock(×->lock); | 307 | if (!cputimer->running) |
| 310 | times->utime = cputime_add(times->utime, cputime); | 308 | return; |
| 311 | spin_unlock(×->lock); | 309 | |
| 310 | spin_lock(&cputimer->lock); | ||
| 311 | cputimer->cputime.utime = | ||
| 312 | cputime_add(cputimer->cputime.utime, cputime); | ||
| 313 | spin_unlock(&cputimer->lock); | ||
| 312 | } | 314 | } |
| 313 | 315 | ||
| 314 | /** | 316 | /** |
| @@ -324,19 +326,21 @@ static inline void account_group_user_time(struct task_struct *tsk, | |||
| 324 | static inline void account_group_system_time(struct task_struct *tsk, | 326 | static inline void account_group_system_time(struct task_struct *tsk, |
| 325 | cputime_t cputime) | 327 | cputime_t cputime) |
| 326 | { | 328 | { |
| 327 | struct task_cputime *times; | 329 | struct thread_group_cputimer *cputimer; |
| 328 | struct signal_struct *sig; | ||
| 329 | 330 | ||
| 330 | /* tsk == current, ensure it is safe to use ->signal */ | 331 | /* tsk == current, ensure it is safe to use ->signal */ |
| 331 | if (unlikely(tsk->exit_state)) | 332 | if (unlikely(tsk->exit_state)) |
| 332 | return; | 333 | return; |
| 333 | 334 | ||
| 334 | sig = tsk->signal; | 335 | cputimer = &tsk->signal->cputimer; |
| 335 | times = &sig->cputime.totals; | 336 | |
| 337 | if (!cputimer->running) | ||
| 338 | return; | ||
| 336 | 339 | ||
| 337 | spin_lock(×->lock); | 340 | spin_lock(&cputimer->lock); |
| 338 | times->stime = cputime_add(times->stime, cputime); | 341 | cputimer->cputime.stime = |
| 339 | spin_unlock(×->lock); | 342 | cputime_add(cputimer->cputime.stime, cputime); |
| 343 | spin_unlock(&cputimer->lock); | ||
| 340 | } | 344 | } |
| 341 | 345 | ||
| 342 | /** | 346 | /** |
| @@ -352,7 +356,7 @@ static inline void account_group_system_time(struct task_struct *tsk, | |||
| 352 | static inline void account_group_exec_runtime(struct task_struct *tsk, | 356 | static inline void account_group_exec_runtime(struct task_struct *tsk, |
| 353 | unsigned long long ns) | 357 | unsigned long long ns) |
| 354 | { | 358 | { |
| 355 | struct task_cputime *times; | 359 | struct thread_group_cputimer *cputimer; |
| 356 | struct signal_struct *sig; | 360 | struct signal_struct *sig; |
| 357 | 361 | ||
| 358 | sig = tsk->signal; | 362 | sig = tsk->signal; |
| @@ -361,9 +365,12 @@ static inline void account_group_exec_runtime(struct task_struct *tsk, | |||
| 361 | if (unlikely(!sig)) | 365 | if (unlikely(!sig)) |
| 362 | return; | 366 | return; |
| 363 | 367 | ||
| 364 | times = &sig->cputime.totals; | 368 | cputimer = &sig->cputimer; |
| 369 | |||
| 370 | if (!cputimer->running) | ||
| 371 | return; | ||
| 365 | 372 | ||
| 366 | spin_lock(×->lock); | 373 | spin_lock(&cputimer->lock); |
| 367 | times->sum_exec_runtime += ns; | 374 | cputimer->cputime.sum_exec_runtime += ns; |
| 368 | spin_unlock(×->lock); | 375 | spin_unlock(&cputimer->lock); |
| 369 | } | 376 | } |
diff --git a/kernel/signal.c b/kernel/signal.c index b6b36768b758..2a74fe87c0dd 100644 --- a/kernel/signal.c +++ b/kernel/signal.c | |||
| @@ -1367,7 +1367,6 @@ int do_notify_parent(struct task_struct *tsk, int sig) | |||
| 1367 | struct siginfo info; | 1367 | struct siginfo info; |
| 1368 | unsigned long flags; | 1368 | unsigned long flags; |
| 1369 | struct sighand_struct *psig; | 1369 | struct sighand_struct *psig; |
| 1370 | struct task_cputime cputime; | ||
| 1371 | int ret = sig; | 1370 | int ret = sig; |
| 1372 | 1371 | ||
| 1373 | BUG_ON(sig == -1); | 1372 | BUG_ON(sig == -1); |
| @@ -1397,9 +1396,10 @@ int do_notify_parent(struct task_struct *tsk, int sig) | |||
| 1397 | info.si_uid = __task_cred(tsk)->uid; | 1396 | info.si_uid = __task_cred(tsk)->uid; |
| 1398 | rcu_read_unlock(); | 1397 | rcu_read_unlock(); |
| 1399 | 1398 | ||
| 1400 | thread_group_cputime(tsk, &cputime); | 1399 | info.si_utime = cputime_to_clock_t(cputime_add(tsk->utime, |
| 1401 | info.si_utime = cputime_to_jiffies(cputime.utime); | 1400 | tsk->signal->utime)); |
| 1402 | info.si_stime = cputime_to_jiffies(cputime.stime); | 1401 | info.si_stime = cputime_to_clock_t(cputime_add(tsk->stime, |
| 1402 | tsk->signal->stime)); | ||
| 1403 | 1403 | ||
| 1404 | info.si_status = tsk->exit_code & 0x7f; | 1404 | info.si_status = tsk->exit_code & 0x7f; |
| 1405 | if (tsk->exit_code & 0x80) | 1405 | if (tsk->exit_code & 0x80) |
