Re: [PATCH] smp: force all cpu to boot once under maxcpus option

From: Pingfan Liu
Date: Wed Jul 24 2019 - 04:39:50 EST


On Mon, Jul 22, 2019 at 11:41:29AM +0200, Thomas Gleixner wrote:
> On Wed, 10 Jul 2019, Pingfan Liu wrote:
> >
> > +static inline bool maxcpus_allowed(unsigned int cpu)
> > +{
> > + /* maxcpus only takes effect during system bootup */
> > + if (smp_boot_done)
> > + return true;
> > + if (num_online_cpus() < setup_max_cpus)
> > + return true;
> > + /*
> > + * maxcpus should allow cpu to set CR4.MCE asap, otherwise the set may
> > + * be deferred indefinitely.
> > + */
> > + if (!per_cpu(cpuhp_state, cpu).booted_once)
> > + return true;
>
> As this is a x86 only issue, you cannot inflict this magic on every
> architecture.
OK.
In my developing patch which fixes nr_cpus issue, I takes the following way:
(I am diverted to other things, have not finished test yet, hope to
turn back soon.)
diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
index 362dd89..c009169 100644
--- a/arch/x86/kernel/smpboot.c
+++ b/arch/x86/kernel/smpboot.c
@@ -956,6 +956,87 @@ int common_cpu_up(unsigned int cpu, struct task_struct *idle)
return 0;
}

+void __init bring_capped_cpu_steady(void)
+{
[...]
+}
+
/*
* NOTE - on most systems this is a PHYSICAL apic ID, but on multiquad
* (ie clustered apic addressing mode), this is a LOGICAL apic ID.
diff --git a/kernel/smp.c b/kernel/smp.c
index d155374..b04961c 100644
--- a/kernel/smp.c
+++ b/kernel/smp.c
@@ -560,6 +560,10 @@ void __init setup_nr_cpu_ids(void)
nr_cpu_ids = find_last_bit(cpumask_bits(cpu_possible_mask),NR_CPUS) + 1;
}

+void __weak bring_capped_cpu_steady(void)
+{
+}
+
/* Called by boot processor to activate the rest. */
void __init smp_init(void)
{
@@ -579,6 +583,8 @@ void __init smp_init(void)
cpu_up(cpu);
}

+ /* force cpus capped by nr_cpus option into steady state */
+ bring_capped_cpu_steady();
num_nodes = num_online_nodes();


The initial motivation is to step around percpu area required by cpu hotplug
framework. But it also provide the abstraction of archs.

What do you think about resolving maxcpus by the similar abstraction?

>
> Aside of that this does not solve the problem at all because smp_init()
> still does:
>
> for_each_present_cpu(cpu) {
> if (num_online_cpus() >= setup_max_cpus)
> break;
Yes, this logic should be removed, then maxcpus_allowed() can take effect. But
now, it may take a quite different way to resolve it.

Thanks for your kindly review.

Regards,
Pingfan
> if (!cpu_online(cpu))
> cpu_up(cpu);
> }
>
> So the remaining CPUs are not onlined at all.
>
> Thanks,
>
> tglx