From: "Satyam Sharma" <satyam.sharma@gmail.com>
To: "Johannes Stezenbach" <js@linuxtv.org>
Cc: "Jonathan Corbet" <corbet@lwn.net>,
"Randy Dunlap" <randy.dunlap@oracle.com>,
"Paul Sokolovsky" <pmiscml@gmail.com>,
linux-kernel@vger.kernel.org,
"Andrew Morton" <akpm@linux-foundation.org>
Subject: Re: [RFC/PATCH] doc: volatile considered evil
Date: Thu, 10 May 2007 01:04:41 +0530 [thread overview]
Message-ID: <a781481a0705091234w613f7e59ud3968a7143ed62ac@mail.gmail.com> (raw)
In-Reply-To: <20070509094305.GC28774@linuxtv.org>
On 5/9/07, Johannes Stezenbach <js@linuxtv.org> wrote:
> On Tue, May 08, 2007, Jonathan Corbet wrote:
> >
> > I just took a shot at turning this into something more like a normal
> > document:
> >
> > http://lwn.net/Articles/233479/
>
> I think the "jiffies variable is special" part misses the
> "for stupid legacy reasons" explanation.
>
> According to the other volatile rules one should use
> something like that:
>
> extern unsigned long __jiffies;
> static inline unsigned long read_ulong(unsigned long *addr)
> {
> return *(volatile unsigned long *)addr;
> }
> static inline unsigned long get_jiffies(void)
> {
> return read_ulong(&__jiffies);
> }
>
> But of course changing all references to jiffies in the kernel would
> be insane, thus jiffies is special "for stupid legacy reasons".
>
> Right?
Right. jiffies comes with no locking protection by default (and adding
one today in a patch that is not invasive / disruptive could be
difficult). If it had a spinlock or something for itself then the
above discussion would have been void, everybody would've just grabbed
the lock before accessing jiffies, and the spinlock implementation
would have done the Right Thing by itself (using barriers, obviously,
and so "volatile" would've been unnecessary even then).
Anyway, as things stand, jiffies comes without locks for itself. But
using a volatile "access cast" to read jiffies whenever you might need
it is _still_ not what I would personally prefer. IMO, it's *much*
better to use something like barrier() if / where you're sitting in a
tight loop comparing jiffies to whatever (a timeout expiry for
example).
So, if you _really_ need / want to do something of this sort, I'd much
rather see:
while (time_before(jiffies, expiry))
barrier();
in code instead of:
while (time_before((*(volatile unsigned long *)&jiffies), expiry))
;
But of course,
while (time_before(jiffies, expiry))
cpu_relax();
would be better still.
A last word from Linus himself here would be obviously best, but I'm
not so sure it makes sense to allow the "volatile" type qualifier
_even_ for the jiffies case.
prev parent reply other threads:[~2007-05-09 19:34 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-05-01 5:08 [RFC, PATCH 2/4] SoC base drivers: ASIC3 SoC hardware definitions Paul Sokolovsky
2007-05-01 6:56 ` Andrew Morton
2007-05-01 10:27 ` Alan Cox
2007-05-01 12:04 ` Paul Sokolovsky
2007-05-01 12:21 ` Jamey Hicks
2007-05-08 19:14 ` [RFC/PATCH] doc: volatile considered evil Randy Dunlap
2007-05-08 19:18 ` David Rientjes
2007-05-08 20:00 ` Krzysztof Halasa
2007-05-08 20:20 ` David Rientjes
2007-05-08 23:13 ` Randy Dunlap
2007-05-08 23:54 ` David Rientjes
2007-05-09 0:00 ` Randy Dunlap
2007-05-08 21:05 ` Jeremy Fitzhardinge
2007-05-08 21:10 ` Krzysztof Halasa
2007-05-08 21:16 ` Jeff Garzik
2007-05-08 21:26 ` Randy Dunlap
2007-05-08 21:25 ` Jeff Garzik
2007-05-08 21:20 ` Jeremy Fitzhardinge
2007-05-08 21:27 ` David Rientjes
2007-05-08 21:37 ` Jeremy Fitzhardinge
2007-05-08 21:59 ` David Rientjes
2007-05-08 22:04 ` Jeremy Fitzhardinge
2007-05-08 22:19 ` David Rientjes
2007-05-08 22:29 ` Jeremy Fitzhardinge
2007-05-08 22:35 ` David Rientjes
2007-05-08 23:09 ` Randy Dunlap
2007-05-08 21:29 ` Randy Dunlap
2007-05-08 20:07 ` Satyam Sharma
2007-05-08 23:34 ` [PATCH] " Randy Dunlap
2007-05-09 0:06 ` David Rientjes
2007-05-09 2:08 ` Randy Dunlap
2007-05-09 2:38 ` David Rientjes
2007-05-09 3:15 ` Randy Dunlap
2007-05-09 9:21 ` Alan Cox
2007-05-09 9:26 ` Nick Piggin
2007-05-09 13:31 ` Alan Cox
2007-05-09 10:25 ` David Rientjes
2007-05-09 13:36 ` Alan Cox
2007-05-09 18:41 ` David Rientjes
2007-05-09 20:23 ` Alan Cox
2007-05-09 20:25 ` David Rientjes
2007-05-09 22:47 ` Rob Landley
2007-05-09 8:50 ` Stefan Richter
2007-05-09 15:52 ` Randy Dunlap
2007-05-09 19:04 ` Satyam Sharma
2007-05-09 1:47 ` [RFC/PATCH] " Jonathan Corbet
2007-05-09 9:43 ` Johannes Stezenbach
2007-05-09 19:34 ` Satyam Sharma [this message]
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=a781481a0705091234w613f7e59ud3968a7143ed62ac@mail.gmail.com \
--to=satyam.sharma@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=corbet@lwn.net \
--cc=js@linuxtv.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pmiscml@gmail.com \
--cc=randy.dunlap@oracle.com \
/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
all inboxes | Powered by JetHome®