Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

cgroup/rstat: Fix forceidle time in cpu.stat

The commit b824766504e4 ("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: b824766504e4 ("cgroup/rstat: add force idle show helper")
Signed-off-by: Abel Wu <wuyun.abel@bytedance.com>
Signed-off-by: Tejun Heo <tj@kernel.org>

authored by

Abel Wu and committed by
Tejun Heo
c4af66a9 ad6c08d8

+13 -16
+13 -16
kernel/cgroup/rstat.c
··· 613 613 void cgroup_base_stat_cputime_show(struct seq_file *seq) 614 614 { 615 615 struct cgroup *cgrp = seq_css(seq)->cgroup; 616 - u64 usage, utime, stime, ntime; 616 + struct cgroup_base_stat bstat; 617 617 618 618 if (cgroup_parent(cgrp)) { 619 619 cgroup_rstat_flush_hold(cgrp); 620 - usage = cgrp->bstat.cputime.sum_exec_runtime; 620 + bstat = cgrp->bstat; 621 621 cputime_adjust(&cgrp->bstat.cputime, &cgrp->prev_cputime, 622 - &utime, &stime); 623 - ntime = cgrp->bstat.ntime; 622 + &bstat.cputime.utime, &bstat.cputime.stime); 624 623 cgroup_rstat_flush_release(cgrp); 625 624 } 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); 632 626 } 633 627 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); 638 632 639 633 seq_printf(seq, "usage_usec %llu\n" 640 634 "user_usec %llu\n" 641 635 "system_usec %llu\n" 642 636 "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); 644 641 645 - cgroup_force_idle_show(seq, &cgrp->bstat); 642 + cgroup_force_idle_show(seq, &bstat); 646 643 } 647 644 648 645 /* Add bpf kfuncs for cgroup_rstat_updated() and cgroup_rstat_flush() */