From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753401AbcEMPIH (ORCPT ); Fri, 13 May 2016 11:08:07 -0400 Received: from merlin.infradead.org ([205.233.59.134]:33450 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753271AbcEMPIG (ORCPT ); Fri, 13 May 2016 11:08:06 -0400 Date: Fri, 13 May 2016 17:07:49 +0200 From: Peter Zijlstra To: Peter Hurley Cc: Waiman Long , Ingo Molnar , linux-kernel@vger.kernel.org, Davidlohr Bueso , Jason Low , Dave Chinner , Scott J Norton , Douglas Hatch Subject: Re: [PATCH v2] locking/rwsem: Add reader-owned state to the owner field Message-ID: <20160513150749.GT3192@twins.programming.kicks-ass.net> References: <1462580424-40333-1-git-send-email-Waiman.Long@hpe.com> <5733AC64.6020306@hurleysoftware.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5733AC64.6020306@hurleysoftware.com> User-Agent: Mutt/1.5.21 (2012-12-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 11, 2016 at 03:04:20PM -0700, Peter Hurley wrote: > > + return !rwsem_is_reader_owned(READ_ONCE(sem->owner)); > > It doesn't make sense to force reload sem->owner here; if sem->owner > is not being reloaded then the loop above will execute forever. > > Arguably, this check should be bumped out to the optimistic spin and > reload/check the owner there? > Note that barrier() and READ_ONCE() have overlapping but not identical results and the combined use actually makes sense here. Yes, a barrier() anywhere in the loop will force a reload of the variable, _however_ it doesn't force that reload to not suffer from load tearing. Using volatile also forces a reload, but also ensures the load cannot be torn IFF it is of machine word side and naturally aligned. So while the READ_ONCE() here is pointless for forcing the reload; that's already ensured, we still need to make sure the load isn't torn.