From: Nick Piggin <nickpiggin@yahoo.com.au>
To: Satyam Sharma <ssatyam@cse.iitk.ac.in>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
David Howells <dhowells@redhat.com>, Andi Kleen <ak@suse.de>,
Andrew Morton <akpm@linux-foundation.org>,
Linus Torvalds <torvalds@linux-foundation.org>,
Jeremy Fitzhardinge <jeremy@goop.org>
Subject: Re: [PATCH 6/8] i386: bitops: Don't mark memory as clobbered unnecessarily
Date: Tue, 24 Jul 2007 18:39:15 +1000 [thread overview]
Message-ID: <46A5BAB3.2030503@yahoo.com.au> (raw)
In-Reply-To: <Pine.LNX.4.64.0707241304410.1433@cselinux1.cse.iitk.ac.in>
Satyam Sharma wrote:
> On Tue, 24 Jul 2007, Nick Piggin wrote:
>
>
>>>>[...]
>>>>
>>>>__test_and_change_bit is one that you could remove the memory clobber
>>>>from.
>>>
>>>Yes, for the atomic versions we don't care if we're asking gcc to
>>>generate trashy code (even though I'd have wanted to only disallow
>>>problematic optimizations -- ones involving the passed bit-string
>>>address -- there, and allow other memory references to be optimized
>>>as and how the compiler feels like it) because the atomic variants
>>>are slow anyway and we probably want to be extra-safe there.
>>>
>>>But for the non-atomic variants, it does make sense to remove the
>>>memory clobber (and the unneeded __asm__ __volatile__ that another
>>>patch did -- for the non-atomic variants, again).
>>
>>No. It has nothing to do with atomicity and all to do with ordering.
>
>
> The memory clobber, or the volatile asm? There's more than one variable
> here ... but still, I don't think either affects _ordering_ in any
> _direct_ way.
The clobber which you remove with this patch.
>>For example test_bit, clear_bit, set_bit, etc are all atomic but none
>>place any restrictions on ordering.
>
>
> In that case we need to update comments in include/asm-i386/bitops.h
Hmm... yeah it looks like they could be reordered. I think?
>>__test_and_change_bit has no restriction on ordering, so as long as
>>the correct operands are clobbered, a "memory" clobber to enforce a
>>compiler barrier is not needed.
>
>
> But why even for the other operations? Consider (current code of)
> test_and_set_bit():
>
> static inline int test_and_set_bit(int nr, volatile unsigned long * addr)
> {
> int oldbit;
> __asm__ __volatile__( LOCK_PREFIX
> "btsl %2,%1\n\tsbbl %0,%0"
> :"=r" (oldbit),"+m" (ADDR)
> :"Ir" (nr) : "memory");
>
> return oldbit;
> }
>
> The only memory reference in there is to the passed address, it will
> be modified, yes, but that's been made obvious to gcc in the asm
> already. So why are we marking all of memory as clobbered, is the
> question. (I just read Jeremy's latest reply, but I don't see how
> or why the memory clobber helps that case either -- does a memory
> clobber affect how gcc would order / reorder code?)
Of course, because then the compiler can't assume anything about
the contents of memory after the operation.
#define barrier() __asm__ __volatile__("": : :"memory")
A memory clobber is equivalent to a compiler barrier.
--
SUSE Labs, Novell Inc.
next prev parent reply other threads:[~2007-07-24 8:39 UTC|newest]
Thread overview: 92+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-07-23 16:05 [PATCH 0/8] i386: bitops: Cleanup, sanitize, optimize Satyam Sharma
2007-07-23 16:05 ` [PATCH 1/8] i386: bitops: Update/correct comments Satyam Sharma
2007-07-23 16:05 ` [PATCH 2/8] i386: bitops: Rectify bogus "Ir" constraints Satyam Sharma
2007-07-23 16:10 ` Andi Kleen
2007-07-23 16:21 ` Satyam Sharma
2007-07-23 16:30 ` Andi Kleen
2007-07-23 16:36 ` Jan Hubicka
2007-07-23 18:05 ` H. Peter Anvin
2007-07-23 18:28 ` H. Peter Anvin
2007-07-23 17:57 ` Linus Torvalds
2007-07-23 18:14 ` Satyam Sharma
2007-07-23 18:32 ` Andi Kleen
2007-07-23 18:39 ` H. Peter Anvin
2007-07-23 18:52 ` Satyam Sharma
2007-07-23 16:05 ` [PATCH 3/8] i386: bitops: Rectify bogus "+m" constraints Satyam Sharma
2007-07-23 16:37 ` Andi Kleen
2007-07-23 17:15 ` Satyam Sharma
2007-07-23 17:46 ` Linus Torvalds
2007-07-24 9:22 ` David Howells
2007-07-23 16:05 ` [PATCH 4/8] i386: bitops: Kill volatile-casting of memory addresses Satyam Sharma
2007-07-23 17:52 ` Linus Torvalds
2007-07-24 4:19 ` Nick Piggin
2007-07-24 6:23 ` Satyam Sharma
2007-07-24 7:16 ` Nick Piggin
2007-07-24 9:49 ` Benjamin Herrenschmidt
2007-07-24 17:20 ` Linus Torvalds
2007-07-24 17:39 ` Jeff Garzik
2007-07-25 4:54 ` Nick Piggin
2007-07-23 16:05 ` [PATCH 5/8] i386: bitops: Contain warnings fallout from the death of volatiles Satyam Sharma
2007-07-23 16:05 ` [PATCH 6/8] i386: bitops: Don't mark memory as clobbered unnecessarily Satyam Sharma
2007-07-23 16:13 ` Andi Kleen
2007-07-23 16:26 ` Satyam Sharma
2007-07-23 16:33 ` Andi Kleen
2007-07-23 17:12 ` Satyam Sharma
2007-07-23 17:49 ` Jeremy Fitzhardinge
2007-07-23 17:55 ` Linus Torvalds
2007-07-24 9:52 ` Benjamin Herrenschmidt
2007-07-24 17:24 ` Linus Torvalds
2007-07-24 17:42 ` Trond Myklebust
2007-07-24 18:13 ` Linus Torvalds
2007-07-24 18:28 ` Trond Myklebust
2007-07-24 21:37 ` Benjamin Herrenschmidt
2007-07-24 21:55 ` Trond Myklebust
2007-07-24 22:32 ` Benjamin Herrenschmidt
2007-07-25 4:10 ` Nick Piggin
2007-07-24 21:36 ` Benjamin Herrenschmidt
2007-07-24 3:57 ` Nick Piggin
2007-07-24 6:38 ` Satyam Sharma
2007-07-24 7:24 ` Nick Piggin
2007-07-24 8:29 ` Satyam Sharma
2007-07-24 8:39 ` Nick Piggin [this message]
2007-07-24 8:38 ` Trent Piepho
2007-07-24 19:39 ` Linus Torvalds
2007-07-24 20:37 ` Andi Kleen
2007-07-24 20:08 ` Linus Torvalds
2007-07-24 21:31 ` Jeremy Fitzhardinge
2007-07-24 21:46 ` Linus Torvalds
2007-07-26 1:07 ` Trent Piepho
2007-07-26 1:18 ` Linus Torvalds
2007-07-26 1:22 ` Linus Torvalds
2007-07-24 9:44 ` David Howells
2007-07-24 10:02 ` Satyam Sharma
2007-07-23 16:06 ` [PATCH 7/8] i386: bitops: Kill needless usage of __asm__ __volatile__ Satyam Sharma
2007-07-23 16:18 ` Andi Kleen
2007-07-23 16:22 ` [PATCH 7/8] i386: bitops: Kill needless usage of __asm__ __volatile__ II Andi Kleen
2007-07-23 16:32 ` [PATCH 7/8] i386: bitops: Kill needless usage of __asm__ __volatile__ Satyam Sharma
2007-07-23 16:23 ` Jeremy Fitzhardinge
2007-07-23 16:43 ` Satyam Sharma
2007-07-23 17:39 ` Jeremy Fitzhardinge
2007-07-23 18:07 ` Satyam Sharma
2007-07-23 18:28 ` Jeremy Fitzhardinge
2007-07-23 20:29 ` Trent Piepho
2007-07-23 20:40 ` Jeremy Fitzhardinge
2007-07-23 21:06 ` Trent Piepho
2007-07-23 21:30 ` Andi Kleen
2007-07-23 21:48 ` Nicholas Miell
2007-07-23 16:06 ` [PATCH 8/8] i386: bitops: smp_mb__{before, after}_clear_bit() definitions Satyam Sharma
2007-07-24 3:53 ` Nick Piggin
2007-07-24 7:34 ` Satyam Sharma
2007-07-24 7:48 ` Jeremy Fitzhardinge
2007-07-24 8:31 ` Nick Piggin
2007-07-24 8:20 ` Nick Piggin
2007-07-24 9:21 ` Satyam Sharma
2007-07-24 10:25 ` Nick Piggin
2007-07-24 11:10 ` Satyam Sharma
2007-07-24 11:32 ` Nick Piggin
2007-07-24 11:45 ` Satyam Sharma
2007-07-24 12:01 ` Nick Piggin
2007-07-24 17:12 ` Linus Torvalds
2007-07-24 19:01 ` Satyam Sharma
2007-07-30 17:57 ` [PATCH 0/8] i386: bitops: Cleanup, sanitize, optimize Denis Vlasenko
2007-07-31 1:07 ` Satyam Sharma
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=46A5BAB3.2030503@yahoo.com.au \
--to=nickpiggin@yahoo.com.au \
--cc=ak@suse.de \
--cc=akpm@linux-foundation.org \
--cc=dhowells@redhat.com \
--cc=jeremy@goop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ssatyam@cse.iitk.ac.in \
--cc=torvalds@linux-foundation.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