From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752487AbbASToi (ORCPT ); Mon, 19 Jan 2015 14:44:38 -0500 Received: from pandora.arm.linux.org.uk ([78.32.30.218]:39257 "EHLO pandora.arm.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751462AbbASTog (ORCPT ); Mon, 19 Jan 2015 14:44:36 -0500 Date: Mon, 19 Jan 2015 19:44:20 +0000 From: Russell King - ARM Linux To: Ray Jui Cc: Wolfram Sang , Uwe =?iso-8859-1?Q?Kleine-K=F6nig?= , Arend van Spriel , Rob Herring , Pawel Moll , Mark Rutland , Ian Campbell , Kumar Gala , Grant Likely , Christian Daudt , Matt Porter , Florian Fainelli , Scott Branden , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, bcm-kernel-feedback-list@broadcom.com, devicetree@vger.kernel.org Subject: Re: [PATCH v6 2/3] i2c: iproc: Add Broadcom iProc I2C Driver Message-ID: <20150119194420.GG26493@n2100.arm.linux.org.uk> References: <1421695428-19102-1-git-send-email-rjui@broadcom.com> <1421695428-19102-3-git-send-email-rjui@broadcom.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1421695428-19102-3-git-send-email-rjui@broadcom.com> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org To see why atomic_t is pure obfuscation: typedef struct { int counter; } atomic_t; So, counter is a plain int. On Mon, Jan 19, 2015 at 11:23:47AM -0800, Ray Jui wrote: > +static irqreturn_t bcm_iproc_i2c_isr(int irq, void *data) > +{ > + struct bcm_iproc_i2c_dev *iproc_i2c = data; > + u32 status = readl(iproc_i2c->base + IS_OFFSET); > + > + status &= ISR_MASK; > + > + if (!status) > + return IRQ_NONE; > + > + writel(status, iproc_i2c->base + IS_OFFSET); > + atomic_set(&iproc_i2c->xfer_is_done, 1); #define atomic_set(v,i) (((v)->counter) = (i)) So, this is the same as doing: iproc_i2c->xfer_is_done.counter = 1; which is merely setting the 'int' to 1. > + time_left = wait_for_completion_timeout(&iproc_i2c->done, time_left); > + > + /* disable all interrupts */ > + writel(0, iproc_i2c->base + IE_OFFSET); > + > + if (!time_left && !atomic_read(&iproc_i2c->xfer_is_done)) { #define atomic_read(v) ACCESS_ONCE((v)->counter) This is practically the same as: if (!time_left && !iproc_i2c->xfer_is_done.counter) { except that this access will be guaranteed to happen just once at this location (see ACCESS_ONCE() in include/linux/compiler.h). However, complete()..wait_for_completion() ensures that there are barriers in the way: complete takes a spinlock on the waiter, so the write to iproc_i2c->xfer_is_done.counter will be visible by the time wait_for_completion() returns, and wait_for_completion() also does. The same spinlock is also manipulated by wait_for_completion(), which means there's barriers there as well, so it can't cache the value of "counter" across that call. So, the "volatile" access guaranteed by ACCESS_ONCE() isn't even needed here. (It would be needed if you were spinning in a loop, calling no other functions - but then you're supposed to use cpu_relax() in that circumstance, which has a compiler barrier in it, which ensures that it will re-read such a variable each time.) -- FTTC broadband for 0.8mile line: currently at 10.5Mbps down 400kbps up according to speedtest.net.