linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Waiman Long <longman@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>, Arnd Bergmann <arnd@arndb.de>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] locking/qrwlock: Reduce cacheline contention for rwlocks used in interrupt context
Date: Wed, 11 May 2022 12:00:33 -0400	[thread overview]
Message-ID: <b64b39ab-58a0-8046-026a-8d635f3f762b@redhat.com> (raw)
In-Reply-To: <20220511133459.GZ76023@worktop.programming.kicks-ass.net>

On 5/11/22 09:34, Peter Zijlstra wrote:
> On Wed, May 11, 2022 at 08:44:55AM -0400, Waiman Long wrote:
>
>>> I'm confused; prior to this change:
>>>
>>> 	CPU0			CPU1
>>>
>>> 	write_lock_irq(&l)
>>> 				read_lock(&l)
>>> 				<INRQ>
>>> 				  read_lock(&l)
>>> 				  ...
>>>
>>> was not deadlock, but now it would AFAICT.
>> Oh you are right. I missed that scenario in my analysis. My bad.
> No worries; I suppose we can also still do something like:
>
> void queued_read_lock_slowpath(struct qrwlock *lock, int cnts)
> {
> 	/*
> 	 * the big comment
> 	 */
> 	if (unlikely(in_interrupt())) {
> 		/*
> 		 * If not write-locked, insta-grant the reader
> 		 */
> 		if (!(cnts & _QW_LOCKED))
> 			return;
>
> 		/*
> 		 * otherwise, wait for the writer to go away.
> 		 */
> 		atomic_cond_read_acquire(&lock->cnts, !(VAL & _QW_LOCKED));
> 		return;
> 	}
>
> 	...
> }
>
> Which saves one load in some cases... not sure it's worth it though.

Yes, it is a micro-optimization that can be done. The gain, if any, 
should be minor though.

Cheers,
Longman


  reply	other threads:[~2022-05-11 16:00 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-10 19:21 [PATCH 1/2] locking/qrwlock: Change "queue rwlock" to "queued rwlock" Waiman Long
2022-05-10 19:21 ` [PATCH 2/2] locking/qrwlock: Reduce cacheline contention for rwlocks used in interrupt context Waiman Long
2022-05-11  7:20   ` Arnd Bergmann
2022-05-11 12:01     ` Waiman Long
2022-05-11  8:30   ` Peter Zijlstra
2022-05-11 12:44     ` Waiman Long
2022-05-11 13:34       ` Peter Zijlstra
2022-05-11 16:00         ` Waiman Long [this message]
2022-05-11 19:39 ` [tip: locking/core] locking/qrwlock: Change "queue rwlock" to "queued rwlock" tip-bot2 for Waiman Long

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=b64b39ab-58a0-8046-026a-8d635f3f762b@redhat.com \
    --to=longman@redhat.com \
    --cc=arnd@arndb.de \
    --cc=boqun.feng@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --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).