diff options
Diffstat (limited to 'kernel/posix-cpu-timers.c')
-rw-r--r-- | kernel/posix-cpu-timers.c | 95 |
1 files changed, 91 insertions, 4 deletions
diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c index fa07da94d7be..db107c9bbc05 100644 --- a/kernel/posix-cpu-timers.c +++ b/kernel/posix-cpu-timers.c | |||
@@ -230,6 +230,37 @@ 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 | |||
233 | /* | 264 | /* |
234 | * Sample a process (thread group) clock for the given group_leader task. | 265 | * Sample a process (thread group) clock for the given group_leader task. |
235 | * Must be called with tasklist_lock held for reading. | 266 | * Must be called with tasklist_lock held for reading. |
@@ -476,6 +507,29 @@ static void clear_dead_task(struct k_itimer *timer, union cpu_time_count now) | |||
476 | } | 507 | } |
477 | 508 | ||
478 | /* | 509 | /* |
510 | * Enable the process wide cpu timer accounting. | ||
511 | * | ||
512 | * serialized using ->sighand->siglock | ||
513 | */ | ||
514 | static void start_process_timers(struct task_struct *tsk) | ||
515 | { | ||
516 | tsk->signal->cputimer.running = 1; | ||
517 | barrier(); | ||
518 | } | ||
519 | |||
520 | /* | ||
521 | * Release the process wide timer accounting -- timer stops ticking when | ||
522 | * nobody cares about it. | ||
523 | * | ||
524 | * serialized using ->sighand->siglock | ||
525 | */ | ||
526 | static void stop_process_timers(struct task_struct *tsk) | ||
527 | { | ||
528 | tsk->signal->cputimer.running = 0; | ||
529 | barrier(); | ||
530 | } | ||
531 | |||
532 | /* | ||
479 | * Insert the timer on the appropriate list before any timers that | 533 | * Insert the timer on the appropriate list before any timers that |
480 | * expire later. This must be called with the tasklist_lock held | 534 | * expire later. This must be called with the tasklist_lock held |
481 | * for reading, and interrupts disabled. | 535 | * for reading, and interrupts disabled. |
@@ -495,6 +549,9 @@ static void arm_timer(struct k_itimer *timer, union cpu_time_count now) | |||
495 | BUG_ON(!irqs_disabled()); | 549 | BUG_ON(!irqs_disabled()); |
496 | spin_lock(&p->sighand->siglock); | 550 | spin_lock(&p->sighand->siglock); |
497 | 551 | ||
552 | if (!CPUCLOCK_PERTHREAD(timer->it_clock)) | ||
553 | start_process_timers(p); | ||
554 | |||
498 | listpos = head; | 555 | listpos = head; |
499 | if (CPUCLOCK_WHICH(timer->it_clock) == CPUCLOCK_SCHED) { | 556 | if (CPUCLOCK_WHICH(timer->it_clock) == CPUCLOCK_SCHED) { |
500 | list_for_each_entry(next, head, entry) { | 557 | list_for_each_entry(next, head, entry) { |
@@ -987,13 +1044,15 @@ static void check_process_timers(struct task_struct *tsk, | |||
987 | sig->rlim[RLIMIT_CPU].rlim_cur == RLIM_INFINITY && | 1044 | sig->rlim[RLIMIT_CPU].rlim_cur == RLIM_INFINITY && |
988 | list_empty(&timers[CPUCLOCK_VIRT]) && | 1045 | list_empty(&timers[CPUCLOCK_VIRT]) && |
989 | cputime_eq(sig->it_virt_expires, cputime_zero) && | 1046 | cputime_eq(sig->it_virt_expires, cputime_zero) && |
990 | list_empty(&timers[CPUCLOCK_SCHED])) | 1047 | list_empty(&timers[CPUCLOCK_SCHED])) { |
1048 | stop_process_timers(tsk); | ||
991 | return; | 1049 | return; |
1050 | } | ||
992 | 1051 | ||
993 | /* | 1052 | /* |
994 | * Collect the current process totals. | 1053 | * Collect the current process totals. |
995 | */ | 1054 | */ |
996 | thread_group_cputime(tsk, &cputime); | 1055 | thread_group_cputimer(tsk, &cputime); |
997 | utime = cputime.utime; | 1056 | utime = cputime.utime; |
998 | ptime = cputime_add(utime, cputime.stime); | 1057 | ptime = cputime_add(utime, cputime.stime); |
999 | sum_sched_runtime = cputime.sum_exec_runtime; | 1058 | sum_sched_runtime = cputime.sum_exec_runtime; |
@@ -1259,7 +1318,7 @@ static inline int fastpath_timer_check(struct task_struct *tsk) | |||
1259 | if (!task_cputime_zero(&sig->cputime_expires)) { | 1318 | if (!task_cputime_zero(&sig->cputime_expires)) { |
1260 | struct task_cputime group_sample; | 1319 | struct task_cputime group_sample; |
1261 | 1320 | ||
1262 | thread_group_cputime(tsk, &group_sample); | 1321 | thread_group_cputimer(tsk, &group_sample); |
1263 | if (task_cputime_expired(&group_sample, &sig->cputime_expires)) | 1322 | if (task_cputime_expired(&group_sample, &sig->cputime_expires)) |
1264 | return 1; | 1323 | return 1; |
1265 | } | 1324 | } |
@@ -1329,6 +1388,33 @@ void run_posix_cpu_timers(struct task_struct *tsk) | |||
1329 | } | 1388 | } |
1330 | 1389 | ||
1331 | /* | 1390 | /* |
1391 | * Sample a process (thread group) timer for the given group_leader task. | ||
1392 | * Must be called with tasklist_lock held for reading. | ||
1393 | */ | ||
1394 | static int cpu_timer_sample_group(const clockid_t which_clock, | ||
1395 | struct task_struct *p, | ||
1396 | union cpu_time_count *cpu) | ||
1397 | { | ||
1398 | struct task_cputime cputime; | ||
1399 | |||
1400 | thread_group_cputimer(p, &cputime); | ||
1401 | switch (CPUCLOCK_WHICH(which_clock)) { | ||
1402 | default: | ||
1403 | return -EINVAL; | ||
1404 | case CPUCLOCK_PROF: | ||
1405 | cpu->cpu = cputime_add(cputime.utime, cputime.stime); | ||
1406 | break; | ||
1407 | case CPUCLOCK_VIRT: | ||
1408 | cpu->cpu = cputime.utime; | ||
1409 | break; | ||
1410 | case CPUCLOCK_SCHED: | ||
1411 | cpu->sched = cputime.sum_exec_runtime + task_delta_exec(p); | ||
1412 | break; | ||
1413 | } | ||
1414 | return 0; | ||
1415 | } | ||
1416 | |||
1417 | /* | ||
1332 | * Set one of the process-wide special case CPU timers. | 1418 | * Set one of the process-wide special case CPU timers. |
1333 | * The tsk->sighand->siglock must be held by the caller. | 1419 | * The tsk->sighand->siglock must be held by the caller. |
1334 | * The *newval argument is relative and we update it to be absolute, *oldval | 1420 | * The *newval argument is relative and we update it to be absolute, *oldval |
@@ -1341,7 +1427,8 @@ void set_process_cpu_timer(struct task_struct *tsk, unsigned int clock_idx, | |||
1341 | struct list_head *head; | 1427 | struct list_head *head; |
1342 | 1428 | ||
1343 | BUG_ON(clock_idx == CPUCLOCK_SCHED); | 1429 | BUG_ON(clock_idx == CPUCLOCK_SCHED); |
1344 | cpu_clock_sample_group(clock_idx, tsk, &now); | 1430 | start_process_timers(tsk); |
1431 | cpu_timer_sample_group(clock_idx, tsk, &now); | ||
1345 | 1432 | ||
1346 | if (oldval) { | 1433 | if (oldval) { |
1347 | if (!cputime_eq(*oldval, cputime_zero)) { | 1434 | if (!cputime_eq(*oldval, cputime_zero)) { |