linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Waiman Long <llong@redhat.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>, Will Deacon <will@kernel.org>,
	Boqun Feng <boqun.feng@gmail.com>,
	linux-kernel@vger.kernel.org, Borislav Petkov <bp@suse.de>,
	Ali Saidi <alisaidi@amazon.com>,
	Steve Capper <steve.capper@arm.com>
Subject: Re: [PATCH] locking/qrwlock: queued_write_lock_slowpath() cleanup
Date: Mon, 26 Apr 2021 10:54:41 -0400	[thread overview]
Message-ID: <d8b2bc8a-3788-6cba-ffa9-2985d7a278d4@redhat.com> (raw)
In-Reply-To: <YIZ0+hNh0SMQoOkh@hirez.programming.kicks-ass.net>

On 4/26/21 4:08 AM, Peter Zijlstra wrote:
> On Sun, Apr 25, 2021 at 04:06:37PM -0400, Waiman Long wrote:
>
>>   void queued_write_lock_slowpath(struct qrwlock *lock)
>>   {
>> -	int cnts;
>> +	int cnts = 0;
>>   
>>   	/* Put the writer into the wait queue */
>>   	arch_spin_lock(&lock->wait_lock);
>>   
>>   	/* Try to acquire the lock directly if no reader is present */
>>   	if (!atomic_read(&lock->cnts) &&
>> -	    (atomic_cmpxchg_acquire(&lock->cnts, 0, _QW_LOCKED) == 0))
>> +	    atomic_try_cmpxchg_acquire(&lock->cnts, &cnts, _QW_LOCKED))
>>   		goto unlock;
> Would not something like:
>
> 	if (!(cnts = atomic_read(&lock->cnts)) &&
> 	    atomic_try_cmpxchg_acquire(&lock->cnts, &cnts, _QW_LOCKED)
> 		goto unlock;
>
> Be clearer?
That works for me too. It is equivalent anyway.
>
>>   
>> -	/* Set the waiting flag to notify readers that a writer is pending */
>> -	atomic_add(_QW_WAITING, &lock->cnts);
>> +	/*
>> +	 * Set the waiting flag to notify readers that a writer is pending
>> +	 *
>> +	 * As only one writer who is the wait_lock owner can set the waiting
>> +	 * flag which will be cleared later on when acquiring the write lock,
>> +	 * we can easily replace atomic_or() by an atomic_add() if there is
>> +	 * an architecture where an atomic_add() performs better than an
>> +	 * atomic_or().
> That might be a little overboard on the comment, but sure :-) I don't
> think there's any arch that doesn't have atomic_or(), like I wrote
> elsewhere, the one that's often an issue is atomic_fetch_or().
>
I was not sure as I didn't look at other archs that hadn't used qrwlock 
yet. Given what you said, I will remove the comment.

Cheers,
Longman


  reply	other threads:[~2021-04-26 14:54 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-25 20:06 [PATCH] locking/qrwlock: queued_write_lock_slowpath() cleanup Waiman Long
2021-04-26  8:08 ` Peter Zijlstra
2021-04-26 14:54   ` Waiman Long [this message]
2021-04-26 18:50 Waiman Long
2021-04-26 18:51 ` Waiman Long
2021-04-27  7:56 ` Will Deacon
2021-05-04  9:19   ` Peter Zijlstra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d8b2bc8a-3788-6cba-ffa9-2985d7a278d4@redhat.com \
    --to=llong@redhat.com \
    --cc=alisaidi@amazon.com \
    --cc=boqun.feng@gmail.com \
    --cc=bp@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=steve.capper@arm.com \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).