public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Will Deacon <will.deacon@arm.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Waiman Long <waiman.long@hpe.com>, Ingo Molnar <mingo@redhat.com>,
	linux-kernel@vger.kernel.org,
	Scott J Norton <scott.norton@hpe.com>,
	Douglas Hatch <doug.hatch@hpe.com>
Subject: Re: [PATCH] locking/qrwlock: Allow multiple spinning readers
Date: Fri, 1 Apr 2016 17:47:43 +0100	[thread overview]
Message-ID: <20160401164742.GD3991@arm.com> (raw)
In-Reply-To: <20160401114303.GA24771@twins.programming.kicks-ass.net>

On Fri, Apr 01, 2016 at 01:43:03PM +0200, Peter Zijlstra wrote:
> > Ah, yes, I forgot about that. Lemme go find that discussions and see
> > what I can do there.
> 
> Completely untested..
> 
> ---
> include/linux/compiler.h   | 20 ++++++++++++++------
> kernel/locking/qspinlock.c | 12 ++++++------
> kernel/sched/core.c        |  9 +++++----
> kernel/sched/sched.h       |  2 +-
> kernel/smp.c               |  2 +-
> 5 files changed, 27 insertions(+), 18 deletions(-)
> 
> diff --git a/include/linux/compiler.h b/include/linux/compiler.h
> index b5ff9881bef8..c64f5897664f 100644
> --- a/include/linux/compiler.h
> +++ b/include/linux/compiler.h
> @@ -305,7 +305,8 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s
> })
> 
> /**
> - * smp_cond_acquire() - Spin wait for cond with ACQUIRE ordering
> + * smp_cond_load_acquire() - Spin wait for cond with ACQUIRE ordering
> + * @ptr:  pointer to the variable wait on
>  * @cond: boolean expression to wait for
>  *
>  * Equivalent to using smp_load_acquire() on the condition variable but employs
> @@ -315,11 +316,18 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s
>  * provides LOAD->LOAD order, together they provide LOAD->{LOAD,STORE} order,
>  * aka. ACQUIRE.
>  */
> -#define smp_cond_acquire(cond)	do {		\
> -	while (!(cond))				\
> -		cpu_relax();			\
> -	smp_rmb(); /* ctrl + rmb := acquire */	\
> -} while (0)
> +#define smp_cond_load_acquire(ptr, cond_expr)	({		\
> +	typeof(ptr) __PTR = (ptr);				\
> +	typeof(*ptr) VAL;					\

It's a bit grim having a magic variable name, but I have no better
suggestion.

> +	for (;;) {						\
> +		VAL = READ_ONCE(*__PTR);			\
> +		if (cond_expr)					\
> +			break;					\
> +		cpu_relax();					\
> +	}							\
> +	smp_rmb(); /* ctrl + rmb := acquire */			\
> +	VAL;							\
> +})

Can you stick some #ifndef guards around this, please? That way I can do
my ldxr/wfe-based version for ARM that makes the spinning tolerable. Also,
wouldn't this be better suited to barrier.h?

Otherwise, I really like this idea. Thanks!

Will

  reply	other threads:[~2016-04-01 16:47 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-20  3:21 [PATCH] locking/qrwlock: Allow multiple spinning readers Waiman Long
2016-03-20 10:43 ` Peter Zijlstra
2016-03-22  2:21   ` Waiman Long
2016-03-29 20:20 ` Peter Zijlstra
2016-03-31 22:12   ` Waiman Long
2016-04-01 10:29     ` Peter Zijlstra
2016-04-01 10:31     ` Peter Zijlstra
2016-04-01 10:41       ` Will Deacon
2016-04-01 10:54         ` Peter Zijlstra
2016-04-01 11:43           ` Peter Zijlstra
2016-04-01 16:47             ` Will Deacon [this message]
2016-04-01 19:53               ` 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=20160401164742.GD3991@arm.com \
    --to=will.deacon@arm.com \
    --cc=doug.hatch@hpe.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=scott.norton@hpe.com \
    --cc=waiman.long@hpe.com \
    /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