Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760385AbXIJPMK (ORCPT ); Mon, 10 Sep 2007 11:12:10 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1759462AbXIJPLx (ORCPT ); Mon, 10 Sep 2007 11:11:53 -0400 Received: from smtp2.linux-foundation.org ([207.189.120.14]:34514 "EHLO smtp2.linux-foundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758697AbXIJPLv (ORCPT ); Mon, 10 Sep 2007 11:11:51 -0400 Date: Mon, 10 Sep 2007 08:09:08 -0700 (PDT) From: Linus Torvalds To: Denys Vlasenko cc: Kyle Moffett , Arjan van de Ven , Nick Piggin , Satyam Sharma , Herbert Xu , Paul Mackerras , Christoph Lameter , Chris Snook , Ilpo Jarvinen , "Paul E. McKenney" , Stefan Richter , Linux Kernel Mailing List , linux-arch@vger.kernel.org, Netdev , Andrew Morton , ak@suse.de, heiko.carstens@de.ibm.com, David Miller , schwidefsky@de.ibm.com, wensong@linux-vs.org, horms@verge.net.au, wjiang@resilience.com, cfriesen@nortel.com, zlynx@acm.org, rpjday@mindspring.com, jesper.juhl@gmail.com, segher@kernel.crashing.org Subject: Re: [PATCH 0/24] make atomic_read() behave consistently across all architectures In-Reply-To: <200709101516.03234.vda.linux@googlemail.com> Message-ID: References: <18115.52863.638655.658466@cargo.ozlabs.ibm.com> <6370BBDF-0C79-41EB-BD2A-02AA0D216924@mac.com> <200709101438.36710.vda.linux@googlemail.com> <200709101516.03234.vda.linux@googlemail.com> 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 Content-Length: 2114 Lines: 52 On Mon, 10 Sep 2007, Denys Vlasenko wrote: > > static inline int > qla2x00_wait_for_loop_ready(scsi_qla_host_t *ha) > { > int return_status = QLA_SUCCESS; > unsigned long loop_timeout ; > scsi_qla_host_t *pha = to_qla_parent(ha); > > /* wait for 5 min at the max for loop to be ready */ > loop_timeout = jiffies + (MAX_LOOP_TIMEOUT * HZ); > > while ((!atomic_read(&pha->loop_down_timer) && > atomic_read(&pha->loop_state) == LOOP_DOWN) || > atomic_read(&pha->loop_state) != LOOP_READY) { > if (atomic_read(&pha->loop_state) == LOOP_DEAD) { ... > Is above correct or buggy? Correct, because msleep is a barrier. > Is it obvious? No. It's *buggy*. But it has nothing to do with any msleep() in the loop, or anything else. And more importantly, it would be equally buggy even *with* a "volatile" atomic_read(). Why is this so hard for people to understand? You're all acting like morons. The reason it is buggy has absolutely nothing to do with whether the read is done or not, it has to do with the fact that the CPU may re-order the reads *regardless* of whether the read is done in some specific order by the compiler ot not! In effect, there is zero ordering between all those three reads, and if you don't have memory barriers (or a lock or other serialization), that code is buggy. So stop this idiotic discussion thread already. The above kind of code needs memory barriers to be non-buggy. The whole "volatile or not" discussion is totally idiotic, and pointless, and anybody who doesn't understand that by now needs to just shut up and think about it more, rather than make this discussion drag out even further. The fact is, "volatile" *only* makes things worse. It generates worse code, and never fixes any real bugs. This is a *fact*. Linus - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/