public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: David Howells <dhowells@redhat.com>
Cc: linux-arch@vger.kernel.org, x86@kernel.org, will.deacon@arm.com,
	linux-kernel@vger.kernel.org, ramana.radhakrishnan@arm.com,
	paulmck@linux.vnet.ibm.com, dwmw2@infradead.org
Subject: Re: [RFC PATCH 13/15] x86: Improve spinlocks using ISO C++11 intrinsic atomics
Date: Wed, 18 May 2016 19:37:20 +0200	[thread overview]
Message-ID: <20160518173720.GG3206@twins.programming.kicks-ass.net> (raw)
In-Reply-To: <146358433517.8596.492761570975545534.stgit@warthog.procyon.org.uk>

On Wed, May 18, 2016 at 04:12:15PM +0100, David Howells wrote:
> diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
> index be0a05913b91..1cbddef2b3f3 100644
> --- a/arch/x86/include/asm/spinlock.h
> +++ b/arch/x86/include/asm/spinlock.h
> @@ -81,7 +81,7 @@ static inline void __ticket_check_and_clear_slowpath(arch_spinlock_t *lock,
>  		new.tickets.tail = old.tickets.tail;
>  
>  		/* try to clear slowpath flag when there are no contenders */
> -		cmpxchg(&lock->head_tail, old.head_tail, new.head_tail);
> +		try_cmpxchg_acquire(&lock->head_tail, old.head_tail, new.head_tail);
>  	}
>  }
>  
> @@ -107,7 +107,7 @@ static __always_inline void arch_spin_lock(arch_spinlock_t *lock)
>  {
>  	register struct __raw_tickets inc = { .tail = TICKET_LOCK_INC };
>  
> -	inc = xadd(&lock->tickets, inc);
> +	inc = xadd_acquire(&lock->tickets, inc);
>  	if (likely(inc.head == inc.tail))
>  		goto out;
>  
> @@ -128,19 +128,21 @@ out:
>  	barrier();	/* make sure nothing creeps before the lock is taken */
>  }
>  
> -static __always_inline int arch_spin_trylock(arch_spinlock_t *lock)
> +static __always_inline bool arch_spin_trylock(arch_spinlock_t *lock)
>  {
>  	arch_spinlock_t old, new;
>  
>  	old.tickets = READ_ONCE(lock->tickets);
>  	if (!__tickets_equal(old.tickets.head, old.tickets.tail))
> -		return 0;
> +		return false;
>  
>  	new.head_tail = old.head_tail + (TICKET_LOCK_INC << TICKET_SHIFT);
>  	new.head_tail &= ~TICKET_SLOWPATH_FLAG;
>  
> -	/* cmpxchg is a full barrier, so nothing can move before it */
> -	return cmpxchg(&lock->head_tail, old.head_tail, new.head_tail) == old.head_tail;
> +	/* Insert an acquire barrier with the cmpxchg so that nothing
> +	 * can move before it.
> +	 */
> +	return try_cmpxchg_acquire(&lock->head_tail, old.head_tail, new.head_tail);
>  }
>  
>  static __always_inline void arch_spin_unlock(arch_spinlock_t *lock)
> @@ -151,14 +153,14 @@ static __always_inline void arch_spin_unlock(arch_spinlock_t *lock)
>  
>  		BUILD_BUG_ON(((__ticket_t)NR_CPUS) != NR_CPUS);
>  
> -		head = xadd(&lock->tickets.head, TICKET_LOCK_INC);
> +		head = xadd_release(&lock->tickets.head, TICKET_LOCK_INC);
>  
>  		if (unlikely(head & TICKET_SLOWPATH_FLAG)) {
>  			head &= ~TICKET_SLOWPATH_FLAG;
>  			__ticket_unlock_kick(lock, (head + TICKET_LOCK_INC));
>  		}
>  	} else
> -		__add(&lock->tickets.head, TICKET_LOCK_INC, UNLOCK_LOCK_PREFIX);
> +		add_release(&lock->tickets.head, TICKET_LOCK_INC, UNLOCK_LOCK_PREFIX);
>  }
>  
>  static inline int arch_spin_is_locked(arch_spinlock_t *lock)
> 

This is all very dead code, I should do a patch removing it.

  reply	other threads:[~2016-05-18 17:37 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-18 15:10 [RFC PATCH 00/15] Provide atomics and bitops implemented with ISO C++11 atomics David Howells
2016-05-18 15:10 ` [RFC PATCH 01/15] cmpxchg_local() is not signed-value safe, so fix generic atomics David Howells
2016-05-18 15:29   ` Arnd Bergmann
2016-05-18 15:10 ` [RFC PATCH 02/15] tty: ldsem_cmpxchg() should use cmpxchg() not atomic_long_cmpxchg() David Howells
2016-05-18 15:10 ` [RFC PATCH 03/15] Provide atomic_t functions implemented with ISO-C++11 atomics David Howells
2016-05-18 17:31   ` Peter Zijlstra
2016-05-18 17:32   ` Peter Zijlstra
2016-05-19  7:36     ` David Woodhouse
2016-05-19  7:45       ` Peter Zijlstra
2016-05-19  9:52     ` David Howells
2016-05-19 10:50       ` Peter Zijlstra
2016-05-19 11:31         ` Peter Zijlstra
2016-05-19 11:33           ` Peter Zijlstra
2016-05-19 14:22         ` Paul E. McKenney
2016-05-19 14:41           ` Peter Zijlstra
2016-05-19 15:00             ` Paul E. McKenney
2016-05-20  9:32               ` Michael Ellerman
2016-05-23 18:39                 ` Paul E. McKenney
2016-06-01 14:16       ` Will Deacon
2016-05-18 17:33   ` Peter Zijlstra
2016-05-18 15:11 ` [RFC PATCH 04/15] Convert 32-bit ISO atomics into a template David Howells
2016-05-18 15:11 ` [RFC PATCH 05/15] Provide atomic64_t and atomic_long_t using ISO atomics David Howells
2016-05-18 15:11 ` [RFC PATCH 06/15] Provide 16-bit " David Howells
2016-05-18 17:28   ` Peter Zijlstra
2016-05-18 15:11 ` [RFC PATCH 07/15] Provide cmpxchg(), xchg(), xadd() and __add() based on ISO C++11 intrinsics David Howells
2016-05-18 15:11 ` [RFC PATCH 08/15] Provide an implementation of bitops using C++11 atomics David Howells
2016-05-18 15:11 ` [RFC PATCH 09/15] Make the ISO bitops use 32-bit values internally David Howells
2016-05-18 15:11 ` [RFC PATCH 10/15] x86: Use ISO atomics David Howells
2016-05-18 15:12 ` [RFC PATCH 11/15] x86: Use ISO bitops David Howells
2016-05-18 15:12 ` [RFC PATCH 12/15] x86: Use ISO xchg(), cmpxchg() and friends David Howells
2016-05-18 15:12 ` [RFC PATCH 13/15] x86: Improve spinlocks using ISO C++11 intrinsic atomics David Howells
2016-05-18 17:37   ` Peter Zijlstra [this message]
2016-05-18 15:12 ` [RFC PATCH 14/15] x86: Make the mutex implementation use ISO atomic ops David Howells
2016-05-18 15:12 ` [RFC PATCH 15/15] x86: Fix misc cmpxchg() and atomic_cmpxchg() calls to use try/return variants David Howells
2016-05-18 17:22 ` [RFC PATCH 00/15] Provide atomics and bitops implemented with ISO C++11 atomics Peter Zijlstra
2016-05-18 17:45 ` Peter Zijlstra
2016-05-18 18:05 ` Peter Zijlstra
2016-05-19  0:23 ` Paul E. McKenney
2016-06-01 14:45 ` Will Deacon
2016-06-08 20:01   ` Paul E. McKenney

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=20160518173720.GG3206@twins.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=dhowells@redhat.com \
    --cc=dwmw2@infradead.org \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=ramana.radhakrishnan@arm.com \
    --cc=will.deacon@arm.com \
    --cc=x86@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