Re: [PATCH] cpu/hotplug: dont offline the last non-isolated CPU

From: Thomas Gleixner
Date: Wed Oct 11 2023 - 08:56:55 EST


On Sat, Sep 16 2023 at 10:37, yang wrote:
> @@ -1502,6 +1502,7 @@ static long __cpu_down_maps_locked(void *arg)
> static int cpu_down_maps_locked(unsigned int cpu, enum cpuhp_state target)
> {
> struct cpu_down_work work = { .cpu = cpu, .target = target, };
> + struct cpumask tmp_mask;

Allocating a cpumask on stack is not really a good idea as it takes up
to 1K stack space.

> /*
> * If the platform does not support hotplug, report it explicitly to
> @@ -1512,11 +1513,16 @@ static int cpu_down_maps_locked(unsigned int cpu, enum cpuhp_state target)
> if (cpu_hotplug_disabled)
> return -EBUSY;
>
> + /*
> + * Ensure the last non-isolated CPU is not offlined.
> + */
> + cpumask_and(&tmp_mask, cpu_online_mask, housekeeping_cpumask(HK_TYPE_DOMAIN));

You can spare that excercise. See below.

> /*
> * Ensure that the control task does not run on the to be offlined
> * CPU to prevent a deadlock against cfs_b->period_timer.
> */
> - cpu = cpumask_any_but(cpu_online_mask, cpu);
> + cpu = cpumask_any_but(&tmp_mask, cpu);

Just open code it this way:

for_each_cpu_and(cpu, cpu_online_mask, housekeeping_cpumask(HK_TYPE_DOMAIN)) {
if (cpu != work.cpu)
return work_on_cpu(cpu, __cpu_down_maps_locked, &work);
}
return -EBUSY;

Hmm?

Thanks,

tglx