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

Commit b464fe7

Browse files
Abel-WYCarlos Llamas
authored andcommitted
UPSTREAM: cgroup/rstat: Fix forceidle time in cpu.stat
[ Upstream commit c4af66a ] 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") Change-Id: Idfe355016afe579d853c8c62dcc632ff3101f28d Signed-off-by: Abel Wu <wuyun.abel@bytedance.com> Signed-off-by: Tejun Heo <tj@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org> (cherry picked from commit 3501677) Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
1 parent 0dcd826 commit b464fe7

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
@@ -612,36 +612,33 @@ static void cgroup_force_idle_show(struct seq_file *seq, struct cgroup_base_stat
612612
void cgroup_base_stat_cputime_show(struct seq_file *seq)
613613
{
614614
struct cgroup *cgrp = seq_css(seq)->cgroup;
615-
u64 usage, utime, stime, ntime;
615+
struct cgroup_base_stat bstat;
616616

617617
if (cgroup_parent(cgrp)) {
618618
cgroup_rstat_flush_hold(cgrp);
619-
usage = cgrp->bstat.cputime.sum_exec_runtime;
619+
bstat = cgrp->bstat;
620620
cputime_adjust(&cgrp->bstat.cputime, &cgrp->prev_cputime,
621-
&utime, &stime);
622-
ntime = cgrp->bstat.ntime;
621+
&bstat.cputime.utime, &bstat.cputime.stime);
623622
cgroup_rstat_flush_release(cgrp);
624623
} else {
625-
/* cgrp->bstat of root is not actually used, reuse it */
626-
root_cgroup_cputime(&cgrp->bstat);
627-
usage = cgrp->bstat.cputime.sum_exec_runtime;
628-
utime = cgrp->bstat.cputime.utime;
629-
stime = cgrp->bstat.cputime.stime;
630-
ntime = cgrp->bstat.ntime;
624+
root_cgroup_cputime(&bstat);
631625
}
632626

633-
do_div(usage, NSEC_PER_USEC);
634-
do_div(utime, NSEC_PER_USEC);
635-
do_div(stime, NSEC_PER_USEC);
636-
do_div(ntime, NSEC_PER_USEC);
627+
do_div(bstat.cputime.sum_exec_runtime, NSEC_PER_USEC);
628+
do_div(bstat.cputime.utime, NSEC_PER_USEC);
629+
do_div(bstat.cputime.stime, NSEC_PER_USEC);
630+
do_div(bstat.ntime, NSEC_PER_USEC);
637631

638632
seq_printf(seq, "usage_usec %llu\n"
639633
"user_usec %llu\n"
640634
"system_usec %llu\n"
641635
"nice_usec %llu\n",
642-
usage, utime, stime, ntime);
636+
bstat.cputime.sum_exec_runtime,
637+
bstat.cputime.utime,
638+
bstat.cputime.stime,
639+
bstat.ntime);
643640

644-
cgroup_force_idle_show(seq, &cgrp->bstat);
641+
cgroup_force_idle_show(seq, &bstat);
645642
}
646643

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

0 commit comments

Comments
 (0)