Skip to content

Commit 9fbc42e

Browse files
committed
cputime: Dynamically scale cputime for full dynticks accounting
The full dynticks cputime accounting is able to account either using the tick or the context tracking subsystem. This way the housekeeping CPU can keep the low overhead tick based solution. This latter mode has a low jiffies resolution granularity and need to be scaled against CFS precise runtime accounting to improve its result. We are doing this for CONFIG_TICK_CPU_ACCOUNTING, now we also need to expand it to full dynticks accounting dynamic off-case as well. Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com> Cc: Li Zhong <zhong@linux.vnet.ibm.com> Cc: Kevin Hilman <khilman@linaro.org> Cc: Mats Liljegren <mats.liljegren@enea.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Ingo Molnar <mingo@kernel.org> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Namhyung Kim <namhyung.kim@lge.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
1 parent b22366c commit 9fbc42e

3 files changed

Lines changed: 83 additions & 77 deletions

File tree

‎include/linux/sched.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ struct signal_struct {
570570
cputime_t utime, stime, cutime, cstime;
571571
cputime_t gtime;
572572
cputime_t cgtime;
573-
#ifndef CONFIG_VIRT_CPU_ACCOUNTING
573+
#ifndef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
574574
struct cputime prev_cputime;
575575
#endif
576576
unsigned long nvcsw, nivcsw, cnvcsw, cnivcsw;
@@ -1327,7 +1327,7 @@ struct task_struct {
13271327

13281328
cputime_t utime, stime, utimescaled, stimescaled;
13291329
cputime_t gtime;
1330-
#ifndef CONFIG_VIRT_CPU_ACCOUNTING
1330+
#ifndef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
13311331
struct cputime prev_cputime;
13321332
#endif
13331333
#ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN

‎kernel/fork.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1230,7 +1230,7 @@ static struct task_struct *copy_process(unsigned long clone_flags,
12301230

12311231
p->utime = p->stime = p->gtime = 0;
12321232
p->utimescaled = p->stimescaled = 0;
1233-
#ifndef CONFIG_VIRT_CPU_ACCOUNTING
1233+
#ifndef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
12341234
p->prev_cputime.utime = p->prev_cputime.stime = 0;
12351235
#endif
12361236
#ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN

‎kernel/sched/cputime.c‎

Lines changed: 80 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -388,82 +388,10 @@ static inline void irqtime_account_process_tick(struct task_struct *p, int user_
388388
struct rq *rq) {}
389389
#endif /* CONFIG_IRQ_TIME_ACCOUNTING */
390390

391-
#ifndef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
392-
/*
393-
* Account a single tick of cpu time.
394-
* @p: the process that the cpu time gets accounted to
395-
* @user_tick: indicates if the tick is a user or a system tick
396-
*/
397-
void account_process_tick(struct task_struct *p, int user_tick)
398-
{
399-
cputime_t one_jiffy_scaled = cputime_to_scaled(cputime_one_jiffy);
400-
struct rq *rq = this_rq();
401-
402-
if (vtime_accounting_enabled())
403-
return;
404-
405-
if (sched_clock_irqtime) {
406-
irqtime_account_process_tick(p, user_tick, rq);
407-
return;
408-
}
409-
410-
if (steal_account_process_tick())
411-
return;
412-
413-
if (user_tick)
414-
account_user_time(p, cputime_one_jiffy, one_jiffy_scaled);
415-
else if ((p != rq->idle) || (irq_count() != HARDIRQ_OFFSET))
416-
account_system_time(p, HARDIRQ_OFFSET, cputime_one_jiffy,
417-
one_jiffy_scaled);
418-
else
419-
account_idle_time(cputime_one_jiffy);
420-
}
421-
422-
/*
423-
* Account multiple ticks of steal time.
424-
* @p: the process from which the cpu time has been stolen
425-
* @ticks: number of stolen ticks
426-
*/
427-
void account_steal_ticks(unsigned long ticks)
428-
{
429-
account_steal_time(jiffies_to_cputime(ticks));
430-
}
431-
432-
/*
433-
* Account multiple ticks of idle time.
434-
* @ticks: number of stolen ticks
435-
*/
436-
void account_idle_ticks(unsigned long ticks)
437-
{
438-
439-
if (sched_clock_irqtime) {
440-
irqtime_account_idle_ticks(ticks);
441-
return;
442-
}
443-
444-
account_idle_time(jiffies_to_cputime(ticks));
445-
}
446-
#endif /* !CONFIG_VIRT_CPU_ACCOUNTING_NATIVE */
447-
448391
/*
449392
* Use precise platform statistics if available:
450393
*/
451394
#ifdef CONFIG_VIRT_CPU_ACCOUNTING
452-
void task_cputime_adjusted(struct task_struct *p, cputime_t *ut, cputime_t *st)
453-
{
454-
*ut = p->utime;
455-
*st = p->stime;
456-
}
457-
458-
void thread_group_cputime_adjusted(struct task_struct *p, cputime_t *ut, cputime_t *st)
459-
{
460-
struct task_cputime cputime;
461-
462-
thread_group_cputime(p, &cputime);
463-
464-
*ut = cputime.utime;
465-
*st = cputime.stime;
466-
}
467395

468396
#ifndef __ARCH_HAS_VTIME_TASK_SWITCH
469397
void vtime_task_switch(struct task_struct *prev)
@@ -518,8 +446,80 @@ void vtime_account_irq_enter(struct task_struct *tsk)
518446
}
519447
EXPORT_SYMBOL_GPL(vtime_account_irq_enter);
520448
#endif /* __ARCH_HAS_VTIME_ACCOUNT */
449+
#endif /* CONFIG_VIRT_CPU_ACCOUNTING */
450+
451+
452+
#ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
453+
void task_cputime_adjusted(struct task_struct *p, cputime_t *ut, cputime_t *st)
454+
{
455+
*ut = p->utime;
456+
*st = p->stime;
457+
}
521458

522-
#else /* !CONFIG_VIRT_CPU_ACCOUNTING */
459+
void thread_group_cputime_adjusted(struct task_struct *p, cputime_t *ut, cputime_t *st)
460+
{
461+
struct task_cputime cputime;
462+
463+
thread_group_cputime(p, &cputime);
464+
465+
*ut = cputime.utime;
466+
*st = cputime.stime;
467+
}
468+
#else /* !CONFIG_VIRT_CPU_ACCOUNTING_NATIVE */
469+
/*
470+
* Account a single tick of cpu time.
471+
* @p: the process that the cpu time gets accounted to
472+
* @user_tick: indicates if the tick is a user or a system tick
473+
*/
474+
void account_process_tick(struct task_struct *p, int user_tick)
475+
{
476+
cputime_t one_jiffy_scaled = cputime_to_scaled(cputime_one_jiffy);
477+
struct rq *rq = this_rq();
478+
479+
if (vtime_accounting_enabled())
480+
return;
481+
482+
if (sched_clock_irqtime) {
483+
irqtime_account_process_tick(p, user_tick, rq);
484+
return;
485+
}
486+
487+
if (steal_account_process_tick())
488+
return;
489+
490+
if (user_tick)
491+
account_user_time(p, cputime_one_jiffy, one_jiffy_scaled);
492+
else if ((p != rq->idle) || (irq_count() != HARDIRQ_OFFSET))
493+
account_system_time(p, HARDIRQ_OFFSET, cputime_one_jiffy,
494+
one_jiffy_scaled);
495+
else
496+
account_idle_time(cputime_one_jiffy);
497+
}
498+
499+
/*
500+
* Account multiple ticks of steal time.
501+
* @p: the process from which the cpu time has been stolen
502+
* @ticks: number of stolen ticks
503+
*/
504+
void account_steal_ticks(unsigned long ticks)
505+
{
506+
account_steal_time(jiffies_to_cputime(ticks));
507+
}
508+
509+
/*
510+
* Account multiple ticks of idle time.
511+
* @ticks: number of stolen ticks
512+
*/
513+
void account_idle_ticks(unsigned long ticks)
514+
{
515+
516+
if (sched_clock_irqtime) {
517+
irqtime_account_idle_ticks(ticks);
518+
return;
519+
}
520+
521+
account_idle_time(jiffies_to_cputime(ticks));
522+
}
523523

524524
static cputime_t scale_stime(cputime_t stime, cputime_t rtime, cputime_t total)
525525
{
@@ -545,6 +545,12 @@ static void cputime_adjust(struct task_cputime *curr,
545545
{
546546
cputime_t rtime, stime, total;
547547

548+
if (vtime_accounting_enabled()) {
549+
*ut = curr->utime;
550+
*st = curr->stime;
551+
return;
552+
}
553+
548554
stime = curr->stime;
549555
total = stime + curr->utime;
550556

@@ -597,7 +603,7 @@ void thread_group_cputime_adjusted(struct task_struct *p, cputime_t *ut, cputime
597603
thread_group_cputime(p, &cputime);
598604
cputime_adjust(&cputime, &p->signal->prev_cputime, ut, st);
599605
}
600-
#endif /* !CONFIG_VIRT_CPU_ACCOUNTING */
606+
#endif /* !CONFIG_VIRT_CPU_ACCOUNTING_NATIVE */
601607

602608
#ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
603609
static unsigned long long vtime_delta(struct task_struct *tsk)

0 commit comments

Comments
 (0)