Re: [PATCH 1/3] cgroup/rstat: Fix forceidle time in cpu.stat

From: Abel Wu
Date: Fri Jan 24 2025 - 04:58:48 EST




On 1/24/25 5:22 PM, Michal Koutný Wrote:
Hello.

On Fri, Jan 24, 2025 at 01:47:01AM +0800, Abel Wu <wuyun.abel@xxxxxxxxxxxxx> wrote:
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.

Sorry, I'm blind, where's the change moving wrt cgroup_rstat_lock?
(I only see unuse of root cgroup's bstat and a few renames).

Hi Michal,

The following hunk deleted the snapshot of cgrp->bstat.forceidle_sum:

if (cgroup_parent(cgrp)) {
cgroup_rstat_flush_hold(cgrp);
usage = cgrp->bstat.cputime.sum_exec_runtime;
cputime_adjust(&cgrp->bstat.cputime, &cgrp->prev_cputime,
&utime, &stime);
-#ifdef CONFIG_SCHED_CORE
- forceidle_time = cgrp->bstat.forceidle_sum;
-#endif
cgroup_rstat_flush_release(cgrp);
} else {

and then read forceidle_sum from @cgrp directly outside of the lock,
but its value can be changed in this window, so...
-#ifdef CONFIG_SCHED_CORE
- seq_printf(seq, "core_sched.force_idle_usec %llu\n", forceidle_time);
-#endif
+ cgroup_force_idle_show(seq, &cgrp->bstat);
}
result in the inconsistence between forceidle and other cputimes.

Best Regards,
Abel