From: Chris Snook <csnook@redhat.com>
To: Herbert Xu <herbert.xu@redhat.com>
Cc: akpm@linux-foundation.org, torvalds@linux-foundation.org,
ak@suse.de, heiko.carstens@de.ibm.com, davem@davemloft.net,
linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
schwidefsky@de.ibm.com, wensong@linux-vs.org, horms@verge.net.au,
wjiang@resilience.com, cfriesen@nortel.com, zlynx@acm.org
Subject: Re: [PATCH] make atomic_t volatile on all architectures
Date: Thu, 09 Aug 2007 07:44:08 -0400 [thread overview]
Message-ID: <46BAFE08.5070906@redhat.com> (raw)
In-Reply-To: <20070809083055.GA19048@gondor.apana.org.au>
Herbert Xu wrote:
> On Thu, Aug 09, 2007 at 03:47:57AM -0400, Chris Snook wrote:
>> If they're not doing anything, sure. Plenty of loops actually do some sort
>> of real work while waiting for their halt condition, possibly even work
>> which is necessary for their halt condition to occur, and you definitely
>> don't want to be doing cpu_relax() in this case. On register-rich
>> architectures you can do quite a lot of work without needing to reuse the
>> register containing the result of the atomic_read(). Those are precisely
>> the architectures where barrier() hurts the most.
>
> I have a problem with this argument. The same loop could be
> using a non-atomic as long as the updaters are serialised. Would
> you suggest that we turn such non-atomics into volatiles too?
No. I'm simply saying that when people call atomic_read, they expect a read to
occur. When this doesn't happen, people get confused. Merely referencing a
variable doesn't carry the same connotation.
Anyway, I'm taking Linus's advice and putting the cast in atomic_read(), rather
than the counter declaration itself. Everything else uses __asm__ __volatile__,
or calls atomic_read() with interrupts disabled. This ensures that
atomic_read() works as expected across all architectures, without the cruft the
compiler generates when you declare the variable itself volatile.
> Any loop that's waiting for an external halt condition either
> has to schedule away (which is a barrier) or you'd be busy
> waiting in which case you should use cpu_relax.
Not necessarily. Some code uses atomic_t for a sort of lightweight semaphore.
If your loop is actually doing real work, perhaps in a softirq handler
negotiating shared resources with a hard irq handler, you're not busy-waiting.
> Do you have an example where this isn't the case?
a) No, and that's sort of the point. We shouldn't have to audit the whole
kernel to find cases where a misleadingly-named function is doing what its users
are not expecting. If we can make it always do the right thing without any
substantial drawbacks, we should.
b) Loops are just one case, which came to mind because of the IPVS bug recently
discussed. I recall seeing some scheduler code recently which does an
atomic_read() twice on the same variable, with a barrier in between. It's in a
very hot path, so if we can remove that barrier, we save a bunch of register
loads. When you're context switching every microsecond in SCHED_RR, that really
matters.
-- Chris
next prev parent reply other threads:[~2007-08-09 11:44 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-08-08 23:07 [PATCH] make atomic_t volatile on all architectures Chris Snook
2007-08-08 23:18 ` Jesper Juhl
2007-08-08 23:31 ` Chris Snook
2007-08-08 23:51 ` Jesper Juhl
2007-08-08 23:25 ` Lennert Buytenhek
2007-08-08 23:35 ` Chris Snook
2007-08-09 1:03 ` Herbert Xu
2007-08-09 1:48 ` David Miller
2007-08-09 3:47 ` Paul E. McKenney
2007-08-09 7:47 ` Chris Snook
2007-08-09 8:30 ` Herbert Xu
2007-08-09 11:44 ` Chris Snook [this message]
2007-08-09 4:18 ` Linus Torvalds
2007-08-09 4:59 ` Jerry Jiang
2007-08-09 7:31 ` Chris Snook
2007-08-09 8:14 ` Heiko Carstens
2007-08-09 17:36 ` Chuck Ebbert
2007-08-09 17:55 ` Linus Torvalds
2007-08-09 18:20 ` Martin Schwidefsky
2007-08-12 5:53 ` Segher Boessenkool
2007-08-12 6:09 ` Linus Torvalds
2007-08-12 9:48 ` Martin Schwidefsky
2007-08-12 9:54 ` Linus Torvalds
2007-08-12 16:30 ` Segher Boessenkool
2007-08-12 18:11 ` Linus Torvalds
2007-08-12 19:13 ` Segher Boessenkool
2007-08-12 10:27 ` Segher Boessenkool
2007-08-12 17:59 ` Linus Torvalds
2007-08-12 9:47 ` Martin Schwidefsky
2007-08-12 10:35 ` Segher Boessenkool
2007-08-09 17:57 ` Martin Schwidefsky
[not found] <8Q2Pg-8uV-23@gated-at.bofh.it>
[not found] ` <8Q7Fa-7rJ-1@gated-at.bofh.it>
[not found] ` <8Q8rD-hh-7@gated-at.bofh.it>
2007-08-09 9:10 ` Bodo Eggert
2007-08-09 9:18 ` Jerry Jiang
2007-08-09 15:00 ` 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=46BAFE08.5070906@redhat.com \
--to=csnook@redhat.com \
--cc=ak@suse.de \
--cc=akpm@linux-foundation.org \
--cc=cfriesen@nortel.com \
--cc=davem@davemloft.net \
--cc=heiko.carstens@de.ibm.com \
--cc=herbert.xu@redhat.com \
--cc=horms@verge.net.au \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=schwidefsky@de.ibm.com \
--cc=torvalds@linux-foundation.org \
--cc=wensong@linux-vs.org \
--cc=wjiang@resilience.com \
--cc=zlynx@acm.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;
as well as URLs for NNTP newsgroup(s).