2022-07-04 14:54:03

by Nicholas Piggin

[permalink] [raw]
Subject: [PATCH 11/13] locking/qspinlock: Use queued_spin_trylock in pv_hybrid_queued_unfair_trylock

Rather than open-code it as necessitated by the old function-renaming
code generation that rendered queued_spin_trylock unavailable to use
here.

Signed-off-by: Nicholas Piggin <[email protected]>
---
kernel/locking/qspinlock.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/locking/qspinlock.c b/kernel/locking/qspinlock.c
index cef0ca7d94e1..9db168753124 100644
--- a/kernel/locking/qspinlock.c
+++ b/kernel/locking/qspinlock.c
@@ -357,7 +357,7 @@ static inline bool pv_hybrid_queued_unfair_trylock(struct qspinlock *lock)
int val = atomic_read(&lock->val);

if (!(val & _Q_LOCKED_PENDING_MASK) &&
- (cmpxchg_acquire(&lock->locked, 0, _Q_LOCKED_VAL) == 0)) {
+ queued_spin_trylock(lock)) {
lockevent_inc(pv_lock_stealing);
return true;
}
--
2.35.1


2022-07-05 18:02:24

by Peter Zijlstra

[permalink] [raw]
Subject: Re: [PATCH 11/13] locking/qspinlock: Use queued_spin_trylock in pv_hybrid_queued_unfair_trylock

On Tue, Jul 05, 2022 at 12:38:18AM +1000, Nicholas Piggin wrote:
> Rather than open-code it as necessitated by the old function-renaming
> code generation that rendered queued_spin_trylock unavailable to use
> here.
>
> Signed-off-by: Nicholas Piggin <[email protected]>
> ---
> kernel/locking/qspinlock.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/kernel/locking/qspinlock.c b/kernel/locking/qspinlock.c
> index cef0ca7d94e1..9db168753124 100644
> --- a/kernel/locking/qspinlock.c
> +++ b/kernel/locking/qspinlock.c
> @@ -357,7 +357,7 @@ static inline bool pv_hybrid_queued_unfair_trylock(struct qspinlock *lock)
> int val = atomic_read(&lock->val);
>
> if (!(val & _Q_LOCKED_PENDING_MASK) &&
> - (cmpxchg_acquire(&lock->locked, 0, _Q_LOCKED_VAL) == 0)) {
> + queued_spin_trylock(lock)) {

Indenting went wild here; please use cino=(0:0 (if you're a vim user; I
seem to have misplaced the emacs equivalent).

2022-07-05 20:48:47

by Waiman Long

[permalink] [raw]
Subject: Re: [PATCH 11/13] locking/qspinlock: Use queued_spin_trylock in pv_hybrid_queued_unfair_trylock

On 7/4/22 10:38, Nicholas Piggin wrote:
> Rather than open-code it as necessitated by the old function-renaming
> code generation that rendered queued_spin_trylock unavailable to use
> here.
>
> Signed-off-by: Nicholas Piggin <[email protected]>
> ---
> kernel/locking/qspinlock.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/kernel/locking/qspinlock.c b/kernel/locking/qspinlock.c
> index cef0ca7d94e1..9db168753124 100644
> --- a/kernel/locking/qspinlock.c
> +++ b/kernel/locking/qspinlock.c
> @@ -357,7 +357,7 @@ static inline bool pv_hybrid_queued_unfair_trylock(struct qspinlock *lock)
> int val = atomic_read(&lock->val);
>
> if (!(val & _Q_LOCKED_PENDING_MASK) &&
> - (cmpxchg_acquire(&lock->locked, 0, _Q_LOCKED_VAL) == 0)) {
> + queued_spin_trylock(lock)) {
> lockevent_inc(pv_lock_stealing);
> return true;
> }

I am not sure if the compiler will eliminate the duplicated
atomic_read() in queued_spin_trylock(). So unless it can generate the
same code, I would prefer to leave this alone.

Cheers,
Longman


2022-07-12 00:58:39

by Nicholas Piggin

[permalink] [raw]
Subject: Re: [PATCH 11/13] locking/qspinlock: Use queued_spin_trylock in pv_hybrid_queued_unfair_trylock

Excerpts from Waiman Long's message of July 6, 2022 6:15 am:
> On 7/4/22 10:38, Nicholas Piggin wrote:
>> Rather than open-code it as necessitated by the old function-renaming
>> code generation that rendered queued_spin_trylock unavailable to use
>> here.
>>
>> Signed-off-by: Nicholas Piggin <[email protected]>
>> ---
>> kernel/locking/qspinlock.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/kernel/locking/qspinlock.c b/kernel/locking/qspinlock.c
>> index cef0ca7d94e1..9db168753124 100644
>> --- a/kernel/locking/qspinlock.c
>> +++ b/kernel/locking/qspinlock.c
>> @@ -357,7 +357,7 @@ static inline bool pv_hybrid_queued_unfair_trylock(struct qspinlock *lock)
>> int val = atomic_read(&lock->val);
>>
>> if (!(val & _Q_LOCKED_PENDING_MASK) &&
>> - (cmpxchg_acquire(&lock->locked, 0, _Q_LOCKED_VAL) == 0)) {
>> + queued_spin_trylock(lock)) {
>> lockevent_inc(pv_lock_stealing);
>> return true;
>> }
>
> I am not sure if the compiler will eliminate the duplicated
> atomic_read() in queued_spin_trylock(). So unless it can generate the
> same code, I would prefer to leave this alone.

Ah you're right, I had that read removed in my tree but then dropped
that change before submitting. This should have been dropped as well.

Thanks,
Nick