aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/sched.h
diff options
context:
space:
mode:
authorPeter Zijlstra <a.p.zijlstra@chello.nl>2009-02-05 06:24:16 -0500
committerIngo Molnar <mingo@elte.hu>2009-02-05 07:04:33 -0500
commit4cd4c1b40d40447fb5e7ba80746c6d7ba91d7a53 (patch)
treeb1e580d5284648d6884e951d995509094a92cca4 /include/linux/sched.h
parent32bd671d6cbeda60dc73be77fa2b9037d9a9bfa0 (diff)
timers: split process wide cpu clocks/timers
Change the process wide cpu timers/clocks so that we: 1) don't mess up the kernel with too many threads, 2) don't have a per-cpu allocation for each process, 3) have no impact when not used. In order to accomplish this we're going to split it into two parts: - clocks; which can take all the time they want since they run from user context -- ie. sys_clock_gettime(CLOCK_PROCESS_CPUTIME_ID) - timers; which need constant time sampling but since they're explicity used, the user can pay the overhead. The clock readout will go back to a full sum of the thread group, while the timers will run of a global 'clock' that only runs when needed, so only programs that make use of the facility pay the price. Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl> Reviewed-by: Ingo Molnar <mingo@elte.hu> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'include/linux/sched.h')
-rw-r--r--include/linux/sched.h54
1 files changed, 31 insertions, 23 deletions
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 2e0646a30314..082d7619b3a1 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 */
472struct thread_group_cputime { 479struct 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;
@@ -2191,27 +2200,26 @@ static inline int spin_needbreak(spinlock_t *lock)
2191/* 2200/*
2192 * Thread group CPU time accounting. 2201 * Thread group CPU time accounting.
2193 */ 2202 */
2203void thread_group_cputime(struct task_struct *tsk, struct task_cputime *times);
2194 2204
2195static inline 2205static inline
2196void thread_group_cputime(struct task_struct *tsk, struct task_cputime *times) 2206void thread_group_cputimer(struct task_struct *tsk, struct task_cputime *times)
2197{ 2207{
2198 struct task_cputime *totals = &tsk->signal->cputime.totals; 2208 struct thread_group_cputimer *cputimer = &tsk->signal->cputimer;
2199 unsigned long flags; 2209 unsigned long flags;
2200 2210
2201 spin_lock_irqsave(&totals->lock, flags); 2211 WARN_ON(!cputimer->running);
2202 *times = *totals; 2212
2203 spin_unlock_irqrestore(&totals->lock, flags); 2213 spin_lock_irqsave(&cputimer->lock, flags);
2214 *times = cputimer->cputime;
2215 spin_unlock_irqrestore(&cputimer->lock, flags);
2204} 2216}
2205 2217
2206static inline void thread_group_cputime_init(struct signal_struct *sig) 2218static inline void thread_group_cputime_init(struct signal_struct *sig)
2207{ 2219{
2208 sig->cputime.totals = (struct task_cputime){ 2220 sig->cputimer.cputime = INIT_CPUTIME;
2209 .utime = cputime_zero, 2221 spin_lock_init(&sig->cputimer.lock);
2210 .stime = cputime_zero, 2222 sig->cputimer.running = 0;
2211 .sum_exec_runtime = 0,
2212 };
2213
2214 spin_lock_init(&sig->cputime.totals.lock);
2215} 2223}
2216 2224
2217static inline void thread_group_cputime_free(struct signal_struct *sig) 2225static inline void thread_group_cputime_free(struct signal_struct *sig)