Skip to content

Commit c4af66a

Browse files
Abel-WYhtejun
authored andcommitted
cgroup/rstat: Fix forceidle time in cpu.stat
The commit b824766 ("cgroup/rstat: add force idle show helper") retrieves forceidle_time outside cgroup_rstat_lock for non-root cgroups which can be potentially inconsistent with other stats. Rather than reverting that commit, fix it in a way that retains the effort of cleaning up the ifdef-messes. Fixes: b824766 ("cgroup/rstat: add force idle show helper") Signed-off-by: Abel Wu <[email protected]> Signed-off-by: Tejun Heo <[email protected]>
1 parent ad6c08d commit c4af66a

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

kernel/cgroup/rstat.c

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -613,36 +613,33 @@ static void cgroup_force_idle_show(struct seq_file *seq, struct cgroup_base_stat
613613
void cgroup_base_stat_cputime_show(struct seq_file *seq)
614614
{
615615
struct cgroup *cgrp = seq_css(seq)->cgroup;
616-
u64 usage, utime, stime, ntime;
616+
struct cgroup_base_stat bstat;
617617

618618
if (cgroup_parent(cgrp)) {
619619
cgroup_rstat_flush_hold(cgrp);
620-
usage = cgrp->bstat.cputime.sum_exec_runtime;
620+
bstat = cgrp->bstat;
621621
cputime_adjust(&cgrp->bstat.cputime, &cgrp->prev_cputime,
622-
&utime, &stime);
623-
ntime = cgrp->bstat.ntime;
622+
&bstat.cputime.utime, &bstat.cputime.stime);
624623
cgroup_rstat_flush_release(cgrp);
625624
} else {
626-
/* cgrp->bstat of root is not actually used, reuse it */
627-
root_cgroup_cputime(&cgrp->bstat);
628-
usage = cgrp->bstat.cputime.sum_exec_runtime;
629-
utime = cgrp->bstat.cputime.utime;
630-
stime = cgrp->bstat.cputime.stime;
631-
ntime = cgrp->bstat.ntime;
625+
root_cgroup_cputime(&bstat);
632626
}
633627

634-
do_div(usage, NSEC_PER_USEC);
635-
do_div(utime, NSEC_PER_USEC);
636-
do_div(stime, NSEC_PER_USEC);
637-
do_div(ntime, NSEC_PER_USEC);
628+
do_div(bstat.cputime.sum_exec_runtime, NSEC_PER_USEC);
629+
do_div(bstat.cputime.utime, NSEC_PER_USEC);
630+
do_div(bstat.cputime.stime, NSEC_PER_USEC);
631+
do_div(bstat.ntime, NSEC_PER_USEC);
638632

639633
seq_printf(seq, "usage_usec %llu\n"
640634
"user_usec %llu\n"
641635
"system_usec %llu\n"
642636
"nice_usec %llu\n",
643-
usage, utime, stime, ntime);
637+
bstat.cputime.sum_exec_runtime,
638+
bstat.cputime.utime,
639+
bstat.cputime.stime,
640+
bstat.ntime);
644641

645-
cgroup_force_idle_show(seq, &cgrp->bstat);
642+
cgroup_force_idle_show(seq, &bstat);
646643
}
647644

648645
/* Add bpf kfuncs for cgroup_rstat_updated() and cgroup_rstat_flush() */

0 commit comments

Comments
 (0)