Skip to content

Commit aefa398

Browse files
joshuahahnhtejun
authored andcommitted
cgroup/rstat: Tracking cgroup-level niced CPU time
Cgroup-level CPU statistics currently include time spent on user/system processes, but do not include niced CPU time (despite already being tracked). This patch exposes niced CPU time to the userspace, allowing users to get a better understanding of their hardware limits and can facilitate more informed workload distribution. A new field 'ntime' is added to struct cgroup_base_stat as opposed to struct task_cputime to minimize footprint. Signed-off-by: Joshua Hahn <joshua.hahnjy@gmail.com> Signed-off-by: Tejun Heo <tj@kernel.org>
1 parent 95a616d commit aefa398

2 files changed

Lines changed: 15 additions & 5 deletions

File tree

include/linux/cgroup-defs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ struct cgroup_base_stat {
327327
#ifdef CONFIG_SCHED_CORE
328328
u64 forceidle_sum;
329329
#endif
330+
u64 ntime;
330331
};
331332

332333
/*

kernel/cgroup/rstat.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ static void cgroup_base_stat_add(struct cgroup_base_stat *dst_bstat,
444444
#ifdef CONFIG_SCHED_CORE
445445
dst_bstat->forceidle_sum += src_bstat->forceidle_sum;
446446
#endif
447+
dst_bstat->ntime += src_bstat->ntime;
447448
}
448449

449450
static void cgroup_base_stat_sub(struct cgroup_base_stat *dst_bstat,
@@ -455,6 +456,7 @@ static void cgroup_base_stat_sub(struct cgroup_base_stat *dst_bstat,
455456
#ifdef CONFIG_SCHED_CORE
456457
dst_bstat->forceidle_sum -= src_bstat->forceidle_sum;
457458
#endif
459+
dst_bstat->ntime -= src_bstat->ntime;
458460
}
459461

460462
static void cgroup_base_stat_flush(struct cgroup *cgrp, int cpu)
@@ -534,8 +536,10 @@ void __cgroup_account_cputime_field(struct cgroup *cgrp,
534536
rstatc = cgroup_base_stat_cputime_account_begin(cgrp, &flags);
535537

536538
switch (index) {
537-
case CPUTIME_USER:
538539
case CPUTIME_NICE:
540+
rstatc->bstat.ntime += delta_exec;
541+
fallthrough;
542+
case CPUTIME_USER:
539543
rstatc->bstat.cputime.utime += delta_exec;
540544
break;
541545
case CPUTIME_SYSTEM:
@@ -591,6 +595,7 @@ static void root_cgroup_cputime(struct cgroup_base_stat *bstat)
591595
#ifdef CONFIG_SCHED_CORE
592596
bstat->forceidle_sum += cpustat[CPUTIME_FORCEIDLE];
593597
#endif
598+
bstat->ntime += cpustat[CPUTIME_NICE];
594599
}
595600
}
596601

@@ -608,30 +613,34 @@ static void cgroup_force_idle_show(struct seq_file *seq, struct cgroup_base_stat
608613
void cgroup_base_stat_cputime_show(struct seq_file *seq)
609614
{
610615
struct cgroup *cgrp = seq_css(seq)->cgroup;
611-
u64 usage, utime, stime;
616+
u64 usage, utime, stime, ntime;
612617

613618
if (cgroup_parent(cgrp)) {
614619
cgroup_rstat_flush_hold(cgrp);
615620
usage = cgrp->bstat.cputime.sum_exec_runtime;
616621
cputime_adjust(&cgrp->bstat.cputime, &cgrp->prev_cputime,
617622
&utime, &stime);
623+
ntime = cgrp->bstat.ntime;
618624
cgroup_rstat_flush_release(cgrp);
619625
} else {
620626
/* cgrp->bstat of root is not actually used, reuse it */
621627
root_cgroup_cputime(&cgrp->bstat);
622628
usage = cgrp->bstat.cputime.sum_exec_runtime;
623629
utime = cgrp->bstat.cputime.utime;
624630
stime = cgrp->bstat.cputime.stime;
631+
ntime = cgrp->bstat.ntime;
625632
}
626633

627634
do_div(usage, NSEC_PER_USEC);
628635
do_div(utime, NSEC_PER_USEC);
629636
do_div(stime, NSEC_PER_USEC);
637+
do_div(ntime, NSEC_PER_USEC);
630638

631639
seq_printf(seq, "usage_usec %llu\n"
632-
"user_usec %llu\n"
633-
"system_usec %llu\n",
634-
usage, utime, stime);
640+
"user_usec %llu\n"
641+
"system_usec %llu\n"
642+
"nice_usec %llu\n",
643+
usage, utime, stime, ntime);
635644

636645
cgroup_force_idle_show(seq, &cgrp->bstat);
637646
}

0 commit comments

Comments
 (0)