mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Linus Torvalds <torvalds@linux-foundation.org>
To: Jan Beulich <JBeulich@novell.com>
Cc: Ingo Molnar <mingo@elte.hu>,
	a.p.zijlstra@chello.nl, Jeremy Fitzhardinge <jeremy@goop.org>,
	tglx@linutronix.de, mingo@redhat.com, npiggin@suse.de,
	linux-kernel@vger.kernel.org, linux-tip-commits@vger.kernel.org,
	hpa@zytor.com
Subject: Re: [tip:core/locking] locking, x86: Slightly shorten  __ticket_spin_trylock()
Date: Wed, 2 Dec 2009 07:33:25 -0800 (PST)	[thread overview]
Message-ID: <alpine.LFD.2.00.0912020727410.2872@localhost.localdomain> (raw)
In-Reply-To: <4B168E7702000078000230C5@vpn.id2.novell.com>



On Wed, 2 Dec 2009, Jan Beulich wrote:

> >>> Ingo Molnar <mingo@elte.hu> 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

  reply	other threads:[~2009-12-02 15:34 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-27 15:09 [PATCH] x86: slightly " Jan Beulich
2009-12-02 10:45 ` [tip:core/locking] locking, x86: Slightly " tip-bot for Jan Beulich
2009-12-02 13:29   ` Ingo Molnar
2009-12-02 14:06     ` Jan Beulich
2009-12-02 14:12       ` Avi Kivity
2009-12-02 14:25         ` Jan Beulich
2009-12-02 14:36           ` Avi Kivity
2009-12-02 14:59             ` Jan Beulich
2009-12-02 14:21       ` Ingo Molnar
2009-12-02 14:57         ` Jan Beulich
2009-12-02 15:33           ` Linus Torvalds [this message]
2009-12-02 15:26   ` Linus Torvalds
2009-12-02 16:24     ` Jan Beulich
2009-12-02 16:56       ` Linus Torvalds
2009-12-02 17:05         ` Linus Torvalds
2009-12-02 17:23           ` H. Peter Anvin
2009-12-02 17:48             ` Linus Torvalds
2009-12-02 17:58               ` H. Peter Anvin

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=alpine.LFD.2.00.0912020727410.2872@localhost.localdomain \
    --to=torvalds@linux-foundation.org \
    --cc=JBeulich@novell.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=hpa@zytor.com \
    --cc=jeremy@goop.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=mingo@redhat.com \
    --cc=npiggin@suse.de \
    --cc=tglx@linutronix.de \
    /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

Powered by JetHome