Re: [PATCH] sched/cpuacct: show only present CPUs to userspace
From: Jonathan Cameron
Date: Mon Oct 28 2024 - 07:19:16 EST
On Fri, 25 Oct 2024 17:35:56 +0200
Aleksandr Mikhalitsyn <aleksandr.mikhalitsyn@xxxxxxxxxxxxx> wrote:
> Gentle ping.
>
> On Thu, Oct 17, 2024 at 12:22 PM Alexander Mikhalitsyn
> <aleksandr.mikhalitsyn@xxxxxxxxxxxxx> wrote:
> >
> > After commit b0c69e1214bc ("drivers: base: Use present CPUs in GENERIC_CPU_DEVICES")
> > changed which CPUs are shown in /sys/devices/system/cpu/ (only "present" ones)
> > it also makes sense to change cpuacct cgroupv1 code not to report CPUs
> > which are not present in the system as it confuses userspace.
> > Let's make it consistent.
> >
> > A configuration when #(present CPUs) < #(possible CPUs) is easy to get with:
> > qemu-system-x86_64
> > -smp 3,maxcpus=12 \
> > ...
> >
On a general basis, we definitely want these to line up, but I'm not familiar
enough with this code to give more specific review.
Other than that, I'm curious as to what userspace is tripping over this?
Jonathan
> > Cc: James Morse <james.morse@xxxxxxx>
> > Cc: Jonathan Cameron <Jonathan.Cameron@xxxxxxxxxx>
> > Cc: Gavin Shan <gshan@xxxxxxxxxx>
> > Cc: "Russell King (Oracle)" <rmk+kernel@xxxxxxxxxxxxxxx>
> > Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
> > Reported-by: Simon Deziel <simon.deziel@xxxxxxxxxxxxx>
> > Closes: https://github.com/canonical/lxd/issues/13324
> > Co-developed-by: Simon Deziel <simon.deziel@xxxxxxxxxxxxx>
> > Signed-off-by: Simon Deziel <simon.deziel@xxxxxxxxxxxxx>
> > Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@xxxxxxxxxxxxx>
> > ---
> > kernel/sched/cpuacct.c | 4 ++--
> > 1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/kernel/sched/cpuacct.c b/kernel/sched/cpuacct.c
> > index 0de9dda09949..0f07fbfdb20e 100644
> > --- a/kernel/sched/cpuacct.c
> > +++ b/kernel/sched/cpuacct.c
> > @@ -213,7 +213,7 @@ static int __cpuacct_percpu_seq_show(struct seq_file *m,
> > u64 percpu;
> > int i;
> >
> > - for_each_possible_cpu(i) {
> > + for_each_present_cpu(i) {
> > percpu = cpuacct_cpuusage_read(ca, i, index);
> > seq_printf(m, "%llu ", (unsigned long long) percpu);
> > }
> > @@ -247,7 +247,7 @@ static int cpuacct_all_seq_show(struct seq_file *m, void *V)
> > seq_printf(m, " %s", cpuacct_stat_desc[index]);
> > seq_puts(m, "\n");
> >
> > - for_each_possible_cpu(cpu) {
> > + for_each_present_cpu(cpu) {
> > seq_printf(m, "%d", cpu);
> > for (index = 0; index < CPUACCT_STAT_NSTATS; index++)
> > seq_printf(m, " %llu",
> > --
> > 2.34.1
> >