Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 0dcd826

Browse files
joshuahahnCarlos Llamas
authored andcommitted
UPSTREAM: cgroup/rstat: Tracking cgroup-level niced CPU time
[ Upstream commit aefa398 ] 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. Change-Id: Iabd26afcedb83d5342ad7e583a2eda01a077044c Signed-off-by: Joshua Hahn <joshua.hahnjy@gmail.com> Signed-off-by: Tejun Heo <tj@kernel.org> Stable-dep-of: c4af66a ("cgroup/rstat: Fix forceidle time in cpu.stat") Signed-off-by: Sasha Levin <sashal@kernel.org> (cherry picked from commit 39bc148) Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
1 parent 871ecf0 commit 0dcd826

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

include/linux/cgroup-defs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ struct cgroup_base_stat {
324324
#ifdef CONFIG_SCHED_CORE
325325
u64 forceidle_sum;
326326
#endif
327+
u64 ntime;
327328
};
328329

329330
/*

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:
@@ -590,6 +594,7 @@ static void root_cgroup_cputime(struct cgroup_base_stat *bstat)
590594
#ifdef CONFIG_SCHED_CORE
591595
bstat->forceidle_sum += cpustat[CPUTIME_FORCEIDLE];
592596
#endif
597+
bstat->ntime += cpustat[CPUTIME_NICE];
593598
}
594599
}
595600

@@ -607,30 +612,34 @@ static void cgroup_force_idle_show(struct seq_file *seq, struct cgroup_base_stat
607612
void cgroup_base_stat_cputime_show(struct seq_file *seq)
608613
{
609614
struct cgroup *cgrp = seq_css(seq)->cgroup;
610-
u64 usage, utime, stime;
615+
u64 usage, utime, stime, ntime;
611616

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

626633
do_div(usage, NSEC_PER_USEC);
627634
do_div(utime, NSEC_PER_USEC);
628635
do_div(stime, NSEC_PER_USEC);
636+
do_div(ntime, NSEC_PER_USEC);
629637

630638
seq_printf(seq, "usage_usec %llu\n"
631-
"user_usec %llu\n"
632-
"system_usec %llu\n",
633-
usage, utime, stime);
639+
"user_usec %llu\n"
640+
"system_usec %llu\n"
641+
"nice_usec %llu\n",
642+
usage, utime, stime, ntime);
634643

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

0 commit comments

Comments
 (0)