lkml.org 
[lkml]   [2022]   [Jun]   [29]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRE: [PATCH V7 1/5] asm-generic: ticket-lock: Remove unnecessary atomic_read
Date
From: guoren@kernel.org
> Sent: 28 June 2022 09:17
>
> From: Guo Ren <guoren@linux.alibaba.com>
>
> Remove unnecessary atomic_read in arch_spin_value_unlocked(lock),
> because the value has been in lock. This patch could prevent
> arch_spin_value_unlocked contend spin_lock data again.

I'm confused (as usual).
Isn't atomic_read() pretty much free?

..
> diff --git a/include/asm-generic/spinlock.h b/include/asm-generic/spinlock.h
> index fdfebcb050f4..f1e4fa100f5a 100644
> --- a/include/asm-generic/spinlock.h
> +++ b/include/asm-generic/spinlock.h
> @@ -84,7 +84,9 @@ static __always_inline int arch_spin_is_contended(arch_spinlock_t *lock)
>
> static __always_inline int arch_spin_value_unlocked(arch_spinlock_t lock)
> {
> - return !arch_spin_is_locked(&lock);
> + u32 val = lock.counter;
> +
> + return ((val >> 16) == (val & 0xffff));

That almost certainly needs a READ_ONCE().

The result is also inherently stale.
So the uses must be pretty limited.

David

> }
>
> #include <asm/qrwlock.h>
> --
> 2.36.1

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

\
 
 \ /
  Last update: 2022-06-29 10:29    [W:0.249 / U:0.048 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site