mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Linus Torvalds <torvalds@linux-foundation.org>
To: "H. Peter Anvin" <hpa@zytor.com>
Cc: George Spelvin <linux@horizon.com>,
	linux-kernel@vger.kernel.org, schwab@linux-m68k.org
Subject: Re: x86-32: clean up rwsem inline asm statements
Date: Wed, 13 Jan 2010 17:05:33 -0800 (PST)	[thread overview]
Message-ID: <alpine.LFD.2.00.1001131654580.13231@localhost.localdomain> (raw)
In-Reply-To: <4B4E3549.7060405@zytor.com>



On Wed, 13 Jan 2010, H. Peter Anvin wrote:
> 
> There are a number of things that can be done better... for one thing,
> "+m" (sem->count) and "a" (sem) is just bloody wrong.  The right thing
> would be "a" (&sem->count) for proper robustness.

Actually, no.

Strictly speaking, we should use "a" (sem), and then use '%0' (pointing to 
the "+m" (sem->count)) for the actual memory access in the inline asm, 
rather than '(%1)'.

We do need %eax to contain the pointer to the semaphore, because _that_ is 
what we pass in as an argument (and return as a value!) to the rwsem slow 
paths.

So "a" (sem) is absolutely the right thing to do.

The reason we use "(%1)" rather than "%0" is - if I recall correctly - 
that back when we inlined it, gcc would often stupidly use the original 
value of the semaphore address rather than %eax (which obviously also 
contained it), and it generated larger code with big constants etc.

Now, since we only inline it in one place anyway, and the semaphore is 
always an argument to that inlining site anyway, I don't think it matters 
(it's never going to be some global pointer), and we probably could/should 
just do this right. So instead of

	LOCK_PREFIX "  inc%z0      (%1)\n\t"

we'd probably be better off with just

	LOCK_PREFIX "  inc%z0 %0\n\t"

instead, letting gcc generate the memory pointer to "sem->count" itself.

		Linus

  parent reply	other threads:[~2010-01-14  1:05 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-13 19:58 George Spelvin
2010-01-13 21:04 ` H. Peter Anvin
2010-01-14  0:27   ` George Spelvin
2010-01-14  0:39     ` H. Peter Anvin
2010-01-14  1:05   ` Linus Torvalds [this message]
  -- strict thread matches above, loose matches on Subject: below --
2010-01-13  0:21 Linus Torvalds
2010-01-13  0:45 ` Andreas Schwab
2010-01-13  1:26   ` Linus Torvalds
2010-01-13  0:48 ` H. Peter Anvin
2010-01-13  0:59   ` Linus Torvalds

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.1001131654580.13231@localhost.localdomain \
    --to=torvalds@linux-foundation.org \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@horizon.com \
    --cc=schwab@linux-m68k.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

Powered by JetHome