From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932340AbWGGWGb (ORCPT ); Fri, 7 Jul 2006 18:06:31 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S932343AbWGGWGa (ORCPT ); Fri, 7 Jul 2006 18:06:30 -0400 Received: from smtp.osdl.org ([65.172.181.4]:27549 "EHLO smtp.osdl.org") by vger.kernel.org with ESMTP id S932340AbWGGWGa (ORCPT ); Fri, 7 Jul 2006 18:06:30 -0400 Date: Fri, 7 Jul 2006 15:06:10 -0700 (PDT) From: Linus Torvalds To: "linux-os (Dick Johnson)" cc: Krzysztof Halasa , Ingo Molnar , Andrew Morton , Linux kernel , arjan@infradead.org Subject: Re: [patch] spinlocks: remove 'volatile' In-Reply-To: Message-ID: References: <20060705114630.GA3134@elte.hu><20060705101059.66a762bf.akpm@osdl.org><20060705193551.GA13070@elte.hu><20060705131824.52fa20ec.akpm@osdl.org><20060705204727.GA16615@elte.hu><20060705214502.GA27597@elte.hu><20060706081639.GA24179@elte.hu> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 7 Jul 2006, Linus Torvalds wrote: > > It still makes a difference for code generation, OF COURSE. But it's the > wrong thing to use. And if you don't realize that my argument wasn't "bait-and-switch", it's exactly the same thing. You pointed out a place where "volatile" would make the code "work". AND I POINTED OUT THAT EVEN IN YOUR TRIVIAL EXAMPLE, VOLATILE WAS ACTUALLY THE WRONG THING TO DO. And that's _exactly_ because the language environment (in this case the CPU itself) has evolved past the point it was 30 years ago. And my point is that this is _always_ true. There are basically no valid uses where you can use "volatile" today, where there isn't some reason why you _should_ have done it another way entirely. Either you should have used proper locking, or you should have used the proper IO accessor functions, or you should have used something like "cpu_relax()", OR ANY NUMBER OF OTHER MECHANISMS. (I did give a few examples of where "volatile" can be valid, but they are very limited) Yes, "volatile" is convenient - at the cost of making the compiler generate crap code even when it shouldn't need to. Yes, "volatile" sometimes allows you to be lazy and not do the proper thing. Yes, "volatile" can hide bugs when you _tried_ to do the proper thing but screwed up. But can't you see that _none_ of those 'Yes, "volatile" ...' actually means that you should _use_ "volatile". Linus