[PATCH v2 29/45] kvm/vmx: Use get/put_online_cpus_atomic() to prevent CPU offline
Srivatsa S. Bhat
srivatsa.bhat at linux.vnet.ibm.com
Wed Jun 26 18:06:46 EST 2013
On 06/26/2013 01:16 PM, Paolo Bonzini wrote:
> Il 25/06/2013 22:30, Srivatsa S. Bhat ha scritto:
>> - cpu = get_cpu();
>> + cpu = get_online_cpus_atomic();
>> vmx_vcpu_load(&vmx->vcpu, cpu);
>> vmx->vcpu.cpu = cpu;
>> err = vmx_vcpu_setup(vmx);
>> vmx_vcpu_put(&vmx->vcpu);
>> - put_cpu();
>> + put_online_cpus_atomic();
>
> The new API has a weird name. Why are you adding new functions instead
> of just modifying get/put_cpu?
>
Because the purpose of those two functions are distinctly different
from each other.
get/put_cpu() is used to disable preemption on the local CPU. (Which
also disables offlining the local CPU during that critical section).
What this patchset deals with is synchronizing with offline of *any*
CPU. Typically, we use get_online_cpus()/put_online_cpus() for that
purpose. But they can't be used in atomic context, because they take
mutex locks and hence can sleep.
So the code that executes in atomic context and which wants to prevent
*any* CPU from going offline, used to disable preemption around its
critical section. Disabling preemption prevents stop_machine(), and
CPU offline (of *any* CPU) was done via stop_machine(). So disabling
preemption disabled any CPU from going offline, as a *side-effect*.
And this patchset prepares the ground for getting rid of stop_machine()
in the CPU offline path. Which means, disabling preemption only prevents
the *local* CPU from going offline. So if code in atomic context wants
to prevent any CPU from going offline, we need a new set of APIs, like
get/put_online_cpus(), but which can be invoked from atomic context.
That's why I named it as get/put_online_cpus_atomic().
One of the key points here is that we want to preserve get/put_cpu()
as it is, since its purpose is different - disable preemption and
offline of the local CPU. There is no reason to change that API, its
useful as it is.
Regards,
Srivatsa S. Bhat
More information about the Linuxppc-dev
mailing list