Re: [PATCH v2 2/4] powerpc/spinlock: support vcpu preempted check

From: Balbir Singh
Date: Wed Jul 06 2016 - 06:54:08 EST


On Tue, 2016-06-28 at 10:43 -0400, Pan Xinhui wrote:
> This is to fix some lock holder preemption issues. Some other locks
> implementation do a spin loop before acquiring the lock itself. Currently
> kernel has an interface of bool vcpu_is_preempted(int cpu). It take the cpu
^^ takes
> as parameter and return true if the cpu is preempted. Then kernel can break
> the spin loops upon on the retval of vcpu_is_preempted.
>Â
> As kernel has used this interface, So lets support it.
>Â
> Only pSeries need supoort it. And the fact is powerNV are built into same
ÂÂÂ^^ support
> kernel image with pSeries. So we need return false if we are runnig as
> powerNV. The another fact is that lppaca->yiled_count keeps zero on
ÂÂ^^ yield
> powerNV. So we can just skip the machine type.
>Â
> Suggested-by: Boqun Feng <boqun.feng@xxxxxxxxx>
> Suggested-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>
> Signed-off-by: Pan Xinhui <xinhui.pan@xxxxxxxxxxxxxxxxxx>
> ---
> Âarch/powerpc/include/asm/spinlock.h | 18 ++++++++++++++++++
> Â1 file changed, 18 insertions(+)
>Â
> diff --git a/arch/powerpc/include/asm/spinlock.h b/arch/powerpc/include/asm/spinlock.h
> index 523673d..3ac9fcb 100644
> --- a/arch/powerpc/include/asm/spinlock.h
> +++ b/arch/powerpc/include/asm/spinlock.h
> @@ -52,6 +52,24 @@
> Â#define SYNC_IO
> Â#endif
> Â
> +/*
> + * This support kernel to check if one cpu is preempted or not.
> + * Then we can fix some lock holder preemption issue.
> + */
> +#ifdef CONFIG_PPC_PSERIES
> +#define vcpu_is_preempted vcpu_is_preempted
> +static inline bool vcpu_is_preempted(int cpu)
> +{
> + /*
> + Â* pSeries and powerNV can be built into same kernel image. In
> + Â* principle we need return false directly if we are running as
> + Â* powerNV. However the yield_count is always zero on powerNV, So
> + Â* skip such machine type check

Or you could use the ppc_md interface callbacks if required, but your
solution works as well

> + Â*/
> + return !!(be32_to_cpu(lppaca_of(cpu).yield_count) & 1);
> +}
> +#endif
> +
> Âstatic __always_inline int arch_spin_value_unlocked(arch_spinlock_t lock)
> Â{
> Â return lock.slock == 0;


Balbir Singh.