All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ARM: locks: remove opencoded #16 for ticket shift
@ 2013-07-15 13:27 Will Deacon
  2013-07-16 16:35 ` Dave Martin
  2013-07-17 13:56 ` Nicolas Pitre
  0 siblings, 2 replies; 6+ messages in thread
From: Will Deacon @ 2013-07-15 13:27 UTC (permalink / raw)
  To: linux-arm-kernel

The ticket width of our spinlocks is defined by TICKET_SHIFT, so remove
the opencoded #16 from the trylock implementation.

Signed-off-by: Will Deacon <will.deacon@arm.com>
---
 arch/arm/include/asm/spinlock.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/arm/include/asm/spinlock.h b/arch/arm/include/asm/spinlock.h
index f8b8965..fa3ccce 100644
--- a/arch/arm/include/asm/spinlock.h
+++ b/arch/arm/include/asm/spinlock.h
@@ -104,11 +104,11 @@ static inline int arch_spin_trylock(arch_spinlock_t *lock)
 		__asm__ __volatile__(
 		"	ldrex	%0, [%3]\n"
 		"	mov	%2, #0\n"
-		"	subs	%1, %0, %0, ror #16\n"
-		"	addeq	%0, %0, %4\n"
+		"	subs	%1, %0, %0, ror %4\n"
+		"	addeq	%0, %0, %5\n"
 		"	strexeq	%2, %0, [%3]"
 		: "=&r" (slock), "=&r" (contended), "=r" (res)
-		: "r" (&lock->slock), "I" (1 << TICKET_SHIFT)
+		: "r" (&lock->slock), "I" (TICKET_SHIFT), "I" (1 << TICKET_SHIFT)
 		: "cc");
 	} while (res);
 
-- 
1.8.2.2

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH] ARM: locks: remove opencoded #16 for ticket shift
  2013-07-15 13:27 [PATCH] ARM: locks: remove opencoded #16 for ticket shift Will Deacon
@ 2013-07-16 16:35 ` Dave Martin
  2013-07-17 13:56 ` Nicolas Pitre
  1 sibling, 0 replies; 6+ messages in thread
From: Dave Martin @ 2013-07-16 16:35 UTC (permalink / raw)
  To: linux-arm-kernel

On Mon, Jul 15, 2013 at 02:27:59PM +0100, Will Deacon wrote:
> The ticket width of our spinlocks is defined by TICKET_SHIFT, so remove
> the opencoded #16 from the trylock implementation.
> 
> Signed-off-by: Will Deacon <will.deacon@arm.com>
> ---
>  arch/arm/include/asm/spinlock.h | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/arm/include/asm/spinlock.h b/arch/arm/include/asm/spinlock.h
> index f8b8965..fa3ccce 100644
> --- a/arch/arm/include/asm/spinlock.h
> +++ b/arch/arm/include/asm/spinlock.h
> @@ -104,11 +104,11 @@ static inline int arch_spin_trylock(arch_spinlock_t *lock)
>  		__asm__ __volatile__(
>  		"	ldrex	%0, [%3]\n"
>  		"	mov	%2, #0\n"
> -		"	subs	%1, %0, %0, ror #16\n"
> -		"	addeq	%0, %0, %4\n"
> +		"	subs	%1, %0, %0, ror %4\n"
> +		"	addeq	%0, %0, %5\n"

%5!  Argh.

>  		"	strexeq	%2, %0, [%3]"
>  		: "=&r" (slock), "=&r" (contended), "=r" (res)
> -		: "r" (&lock->slock), "I" (1 << TICKET_SHIFT)
> +		: "r" (&lock->slock), "I" (TICKET_SHIFT), "I" (1 << TICKET_SHIFT)

I guess that should work.

Strictly speaking, "M" is the right constraint to use for explicit shift
counts, though it won't make much difference in practice.

(Unless it ICEs the compiler for you ... seems to work on the 4.6.3
GCC I have here.)

Cheers
---Dave

>  		: "cc");
>  	} while (res);
>  
> -- 
> 1.8.2.2
> 
> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH] ARM: locks: remove opencoded #16 for ticket shift
  2013-07-15 13:27 [PATCH] ARM: locks: remove opencoded #16 for ticket shift Will Deacon
  2013-07-16 16:35 ` Dave Martin
@ 2013-07-17 13:56 ` Nicolas Pitre
  2013-07-18 17:21   ` Will Deacon
  1 sibling, 1 reply; 6+ messages in thread
From: Nicolas Pitre @ 2013-07-17 13:56 UTC (permalink / raw)
  To: linux-arm-kernel

On Mon, 15 Jul 2013, Will Deacon wrote:

> The ticket width of our spinlocks is defined by TICKET_SHIFT, so remove
> the opencoded #16 from the trylock implementation.
> 
> Signed-off-by: Will Deacon <will.deacon@arm.com>

This is pointless.

>  		"	ldrex	%0, [%3]\n"
>  		"	mov	%2, #0\n"
> -		"	subs	%1, %0, %0, ror #16\n"

Any value other than 16 would break that code.  You'd rather ensure it 
never gets defined to anything else.


Nicolas

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH] ARM: locks: remove opencoded #16 for ticket shift
  2013-07-17 13:56 ` Nicolas Pitre
@ 2013-07-18 17:21   ` Will Deacon
  2013-07-18 17:53     ` Nicolas Pitre
  0 siblings, 1 reply; 6+ messages in thread
From: Will Deacon @ 2013-07-18 17:21 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, Jul 17, 2013 at 02:56:59PM +0100, Nicolas Pitre wrote:
> On Mon, 15 Jul 2013, Will Deacon wrote:
> 
> > The ticket width of our spinlocks is defined by TICKET_SHIFT, so remove
> > the opencoded #16 from the trylock implementation.
> > 
> > Signed-off-by: Will Deacon <will.deacon@arm.com>
> 
> This is pointless.

I disagree (see below).

> >  		"	ldrex	%0, [%3]\n"
> >  		"	mov	%2, #0\n"
> > -		"	subs	%1, %0, %0, ror #16\n"
> 
> Any value other than 16 would break that code.  You'd rather ensure it 
> never gets defined to anything else.

There are two aspects to the ticket lock:

  1. The size of each ticket
  2. The location of the next ticket within the 32-bit lock word

TICKET_SHIFT actually defines (2) and could be 0 or 16, hence why I was
making this small cosmetic change. I admit that the naming isn't very good
and I should change the commit message to reflect what's actually going on.

Cheers,

Will

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH] ARM: locks: remove opencoded #16 for ticket shift
  2013-07-18 17:21   ` Will Deacon
@ 2013-07-18 17:53     ` Nicolas Pitre
  2013-07-19  9:05       ` Will Deacon
  0 siblings, 1 reply; 6+ messages in thread
From: Nicolas Pitre @ 2013-07-18 17:53 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, 18 Jul 2013, Will Deacon wrote:

> On Wed, Jul 17, 2013 at 02:56:59PM +0100, Nicolas Pitre wrote:
> > On Mon, 15 Jul 2013, Will Deacon wrote:
> > 
> > > The ticket width of our spinlocks is defined by TICKET_SHIFT, so remove
> > > the opencoded #16 from the trylock implementation.
> > > 
> > > Signed-off-by: Will Deacon <will.deacon@arm.com>
> > 
> > This is pointless.
> 
> I disagree (see below).
> 
> > >  		"	ldrex	%0, [%3]\n"
> > >  		"	mov	%2, #0\n"
> > > -		"	subs	%1, %0, %0, ror #16\n"
> > 
> > Any value other than 16 would break that code.  You'd rather ensure it 
> > never gets defined to anything else.
> 
> There are two aspects to the ticket lock:
> 
>   1. The size of each ticket
>   2. The location of the next ticket within the 32-bit lock word
> 
> TICKET_SHIFT actually defines (2) and could be 0 or 16, hence why I was
> making this small cosmetic change.

Doesn't matter where the location of the next ticket is.  Whether it is 
0 or 16, for the above code to work, it *must* always perform a ror #16.  
Hence tying the ror constant with TICKET_SHIFT is wrong.


Nicolas

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH] ARM: locks: remove opencoded #16 for ticket shift
  2013-07-18 17:53     ` Nicolas Pitre
@ 2013-07-19  9:05       ` Will Deacon
  0 siblings, 0 replies; 6+ messages in thread
From: Will Deacon @ 2013-07-19  9:05 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, Jul 18, 2013 at 06:53:06PM +0100, Nicolas Pitre wrote:
> On Thu, 18 Jul 2013, Will Deacon wrote:
> > There are two aspects to the ticket lock:
> > 
> >   1. The size of each ticket
> >   2. The location of the next ticket within the 32-bit lock word
> > 
> > TICKET_SHIFT actually defines (2) and could be 0 or 16, hence why I was
> > making this small cosmetic change.
> 
> Doesn't matter where the location of the next ticket is.  Whether it is 
> 0 or 16, for the above code to work, it *must* always perform a ror #16.  
> Hence tying the ror constant with TICKET_SHIFT is wrong.

You're right; we always need to refer to the higher ticket, rather than
`owner' or `next'. Patch dropped.

Cheers,

Will

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2013-07-19  9:05 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-07-15 13:27 [PATCH] ARM: locks: remove opencoded #16 for ticket shift Will Deacon
2013-07-16 16:35 ` Dave Martin
2013-07-17 13:56 ` Nicolas Pitre
2013-07-18 17:21   ` Will Deacon
2013-07-18 17:53     ` Nicolas Pitre
2013-07-19  9:05       ` Will Deacon

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.