* Re: [PATCH] Export current_is_keventd() for libphy [not found] ` <Pine.LNX.4.64.0612060955380.3542@woody.osdl.org> @ 2006-12-06 18:33 ` Linus Torvalds 2006-12-06 18:37 ` Linus Torvalds 2006-12-06 18:43 ` David Howells 0 siblings, 2 replies; 4+ messages in thread From: Linus Torvalds @ 2006-12-06 18:33 UTC (permalink / raw) To: David Howells Cc: Andrew Morton, Maciej W. Rozycki, Roland Dreier, Andy Fleming, Ben Collins, Linux Kernel Mailing List, Jeff Garzik, linux-arch On Wed, 6 Dec 2006, Linus Torvalds wrote: > > Sadly, gcc doesn't do it in this case. Still, I'd rather keep the source > clean, and hope that the compiler improves eventually, than to make the > code uglier. Actually, it's our own damn fault. We've long had our arguments "const volatile" to test_bit(), which basically means that gcc can't do the optimization. Damn. And they need to be "volatile" not because we _want_ the thing to be volaile, but because these things are occationally used on volatile objects (so if the function doesn't take a volatile pointer, it would warn). That's why so many of these helper functions use "const volatile" pointers, which on the face of it would seem strange if you don't realize that it's more about a C type issue than about the _actual_ type being either "const" or "volatile". Sad. I guess we could remove the "const volatile" from the _cast_, but the thing is, if the underlying object we're actually looking at really _is_ volatile, we shouldn't do that. GAAH. Really sad. I doubt any of the callers actually want the "volatile" access at all. Things like <linux/page-flags.h> definitely _don't_ want it. I suspect we should just face up to the fact that (a) "volatile" on kernel data is basically always a bug, and you should use locking. "volatile" doesn't help anything at all with memory ordering and friends, so it's insane to think it "solves" anything on its own. (b) on "iomem" pointers it does make sense, but those need special accessor functions _anyway_, so things like test_bit() wouldn't work on them. (c) if you spin on a value changing, you should use "cpu_relax()" or "barrier()" anyway, which will force gcc to re-load any values from memory over the loop. and remove the "volatile" from all the bitop accessor functions. Or at least from "test_bit()". It's not like it's synchronous _anyway_ (there's no memory barriers etc). Hmm? Comments? linux-arch added to Cc, just in case people care (this particular thing is in <asm-*/bitops.h>, so it _is_ architecture- specific, but we should probably all agree on it first) Linus ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Export current_is_keventd() for libphy 2006-12-06 18:33 ` [PATCH] Export current_is_keventd() for libphy Linus Torvalds @ 2006-12-06 18:37 ` Linus Torvalds 2006-12-06 18:43 ` David Howells 1 sibling, 0 replies; 4+ messages in thread From: Linus Torvalds @ 2006-12-06 18:37 UTC (permalink / raw) To: David Howells Cc: Andrew Morton, Maciej W. Rozycki, Roland Dreier, Andy Fleming, Ben Collins, Linux Kernel Mailing List, Jeff Garzik, linux-arch On Wed, 6 Dec 2006, Linus Torvalds wrote: > > and remove the "volatile" from all the bitop accessor functions. It might also be interesting to see if this would change code-size at all. There's a number of things that check different bits in the same word right now, and they just reload the word unnecessarily and do multiple tests. Some of the page flags functions obviously already work around this by doing horrible things by hand instead, eg: (page->flags & ( 1 << PG_lru | 1 << PG_private | 1 << PG_locked | 1 << PG_active | 1 << PG_reclaim | 1 << PG_slab | 1 << PG_swapcache | 1 << PG_writeback | 1 << PG_reserved | 1 << PG_buddy )) in the free_pages_check() thing. It may make sense there, but we really _should_ allow gcc to just do things like this for us, and just use the proper functions to test bits. Linus ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Export current_is_keventd() for libphy 2006-12-06 18:33 ` [PATCH] Export current_is_keventd() for libphy Linus Torvalds 2006-12-06 18:37 ` Linus Torvalds @ 2006-12-06 18:43 ` David Howells 2006-12-06 19:02 ` Linus Torvalds 1 sibling, 1 reply; 4+ messages in thread From: David Howells @ 2006-12-06 18:43 UTC (permalink / raw) To: Linus Torvalds Cc: David Howells, Andrew Morton, Maciej W. Rozycki, Roland Dreier, Andy Fleming, Ben Collins, Linux Kernel Mailing List, Jeff Garzik, linux-arch Linus Torvalds <torvalds@osdl.org> wrote: > (a) "volatile" on kernel data is basically always a bug, and you should > use locking. But what about when you're building a lock? Actually, I suspect correct usage of asm constraints and memory barriers trumps volatile anyway even there. David ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Export current_is_keventd() for libphy 2006-12-06 18:43 ` David Howells @ 2006-12-06 19:02 ` Linus Torvalds 0 siblings, 0 replies; 4+ messages in thread From: Linus Torvalds @ 2006-12-06 19:02 UTC (permalink / raw) To: David Howells Cc: Andrew Morton, Maciej W. Rozycki, Roland Dreier, Andy Fleming, Ben Collins, Linux Kernel Mailing List, Jeff Garzik, linux-arch On Wed, 6 Dec 2006, David Howells wrote: > > Linus Torvalds <torvalds@osdl.org> wrote: > > > (a) "volatile" on kernel data is basically always a bug, and you should > > use locking. > > But what about when you're building a lock? Actually, I suspect correct usage > of asm constraints and memory barriers trumps volatile anyway even there. The word you look for is not "suspect". You _cannot_ build a lock using "volatile", unless your CPU is strictly in-order and has an in-order memory subsystem too (so, for example, while all ia64 implementations today are in-order, they do /not/ have an in-order memory subsystem). Only then could you do locking with volatile and some crazy Peterson's algorithm. I don't think any such CPU actually exists. Anyway, we've had this discussion before on linux-kernel, it really boils down to that "volatile" is basically never correct with the exception of flags that don't have any meaning and that you don't actually _care_ about the exact value (the low word of "jiffies" being the canonical example of something where "volatile" is actually fine, and where - as long as you can load it atomically - "volatile" really does make sense). Linus ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2006-12-06 19:03 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <Pine.LNX.4.64.0612060822260.3542@woody.osdl.org>
[not found] ` <1165125055.5320.14.camel@gullible>
[not found] ` <20061203011625.60268114.akpm@osdl.org>
[not found] ` <Pine.LNX.4.64N.0612051642001.7108@blysk.ds.pg.gda.pl>
[not found] ` <20061205123958.497a7bd6.akpm@osdl.org>
[not found] ` <6FD5FD7A-4CC2-481A-BC87-B869F045B347@freescale.com>
[not found] ` <20061205132643.d16db23b.akpm@osdl.org>
[not found] ` <adaac22c9cu.fsf@cisco.com>
[not found] ` <20061205135753.9c3844f8.akpm@osdl.org>
[not found] ` <Pine.LNX.4.64N.0612061506460.29000@blysk.ds.pg.gda.pl>
[not found] ` <20061206075729.b2b6aa52.akpm@osdl.org>
[not found] ` <21690.1165426993@redhat.com>
[not found] ` <Pine.LNX.4.64.0612060951150.3542@woody.osdl.org>
[not found] ` <Pine.LNX.4.64.0612060955380.3542@woody.osdl.org>
2006-12-06 18:33 ` [PATCH] Export current_is_keventd() for libphy Linus Torvalds
2006-12-06 18:37 ` Linus Torvalds
2006-12-06 18:43 ` David Howells
2006-12-06 19:02 ` Linus Torvalds
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox