Re: [tip:core/locking] locking, x86: Slightly shorten __ticket_spin_trylock()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On Wed, 2 Dec 2009, Jan Beulich wrote:

> >>> Ingo Molnar <mingo@xxxxxxx> 02.12.09 15:21 >>>
> 792a99a9 <_raw_spin_lock>:
> ...
> >792a99f3:	89 d8                	mov    %ebx,%eax
> >792a99f5:	ff 15 d0 6c f2 79    	call   *0x79f26cd0
> >792a99fb:	85 c0                	test   %eax,%eax
> ...
> >792a9a2e:	89 f8                	mov    %edi,%eax
> >792a9a30:	ff 15 d0 6c f2 79    	call   *0x79f26cd0
> >792a9a36:	85 c0                	test   %eax,%eax
> 
> Assuming that these are the calls to __raw_spin_trylock, it is clear that
> the generated code isn't what we want: It should be test %al, %al in
> both cases.

See my previous email.  Using 'bool' was a mistake. It's _always_ a 
mistake. 

'bool' basically says that the compiler can assume magic things, and 
compile the thing to be anything it wants that is convenient for it. 
Put another way, 'bool' has a magic API. For all you know, the rule might 
even be that a 'bool' return value is always returned in a flag register 
(ok, on x86 that would be _very_ inconvenient, but it's _possible_). 

So the calling convention could have been

	call <bool-returning-function>
	jne ..	// jump if it returned non-zero

because the rule about bool is that it is just one bit of information, 
but exactly _how_ that bit is done is totally up to the compiler ABI.

In this case, the rule gcc implements on x86 is probably just "we pass it 
around as an 'int' that contains 0 or 1". So the code would work if you 
had left in the 'movzbl'.

End result: don't use bool.

			Linus
--
To unsubscribe from this list: send the line "unsubscribe linux-tip-commits" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Stable Commits]     [Linux Stable Kernel]     [Linux Kernel]     [Linux USB Devel]     [Linux Video &Media]     [Linux Audio Users]     [Yosemite News]     [Linux SCSI]

  Powered by Linux