Received: by 10.213.65.68 with SMTP id h4csp742615imn; Fri, 6 Apr 2018 08:09:36 -0700 (PDT) X-Google-Smtp-Source: AIpwx49/xBE7k6YIFJ0UvWwzEb4yYM90Ju1/GKkQGaWNetGka9rmHgT7s43r/4ubovXA8UJMEQ4c X-Received: by 10.99.119.79 with SMTP id s76mr17637107pgc.291.1523027376302; Fri, 06 Apr 2018 08:09:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523027376; cv=none; d=google.com; s=arc-20160816; b=ETqQT87mlcUD5mCw+knWl4lmm1U2V1BJi9LPVG0QnOwoCzX/nd0xYeOGAghj8oyxOE 7VsIeLBbe0YYBFDv0XQsyTufIpG9RamxNd7+0uMMlExSY+nqz5z/xwlkKAeHa7h8jTVP 05CMclHAqKwYQmAxRIrdmSgDqMJBF5uev0X0DUitsU/9GCKHPeFNB8Pd8UktTbOnxpCY 0tkT0pM6ckuH/fh8HCHLLRpm2HfwXzw+XESa+w0XMbzTmSDQpm/ERcOkiyrM9iIJKas/ aP8Iqg9/M6shoWVZ3UyGkulXlqa1b+1AvZT1FnzH2jZpEkhqHgFfYX/tinZ2K255/+OA QGqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=4+r1u2XgwBsqbFp9CMjWtIe7OjMaiE2WVbEjmRDH1/M=; b=0uaeE6dPC+bLRwz6/uroyteHWTp6Y8lgSPBwpJOldlBiaDPWwRpe82EDxIO8T9lxlI lY08WLIBBBO0mFbksSsPqU2WtMM9LX6+xdC+3vH+O1w6pWelrErjbcZrCFgqYzOttubK 7iw29K/whlCJho1IlqZLnI0vXb39xa8KKLVcICu+9sU9jsEj0TadDvQPHxm3bRgCTL1H iuLRGmpBAON6OnGYilmxcF3fRF50LwIdNLNAk6zmlLrxlJWFaOneY/UHJ4gizfK8CTDQ Hy9aAnUoIogN2bP2ZOShm+L+MyIxcCsTSAWViKgUDUnTZJ82sV2nSDMkTDBMGVBkGqyT uaKQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k9si7329007pgc.327.2018.04.06.08.09.22; Fri, 06 Apr 2018 08:09:36 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751089AbeDFPIA (ORCPT + 99 others); Fri, 6 Apr 2018 11:08:00 -0400 Received: from foss.arm.com ([217.140.101.70]:38386 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752938AbeDFPH5 (ORCPT ); Fri, 6 Apr 2018 11:07:57 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 51ACC1529; Fri, 6 Apr 2018 08:07:57 -0700 (PDT) Received: from edgewater-inn.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 223F93F587; Fri, 6 Apr 2018 08:07:57 -0700 (PDT) Received: by edgewater-inn.cambridge.arm.com (Postfix, from userid 1000) id 14ED31AE55CC; Fri, 6 Apr 2018 16:08:11 +0100 (BST) Date: Fri, 6 Apr 2018 16:08:11 +0100 From: Will Deacon To: Peter Zijlstra Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, mingo@kernel.org, boqun.feng@gmail.com, paulmck@linux.vnet.ibm.com, catalin.marinas@arm.com, Waiman Long Subject: Re: [PATCH 02/10] locking/qspinlock: Remove unbounded cmpxchg loop from locking slowpath Message-ID: <20180406150810.GA10528@arm.com> References: <1522947547-24081-1-git-send-email-will.deacon@arm.com> <1522947547-24081-3-git-send-email-will.deacon@arm.com> <20180405170706.GC4082@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180405170706.GC4082@hirez.programming.kicks-ass.net> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 05, 2018 at 07:07:06PM +0200, Peter Zijlstra wrote: > On Thu, Apr 05, 2018 at 05:58:59PM +0100, Will Deacon wrote: > > The qspinlock locking slowpath utilises a "pending" bit as a simple form > > of an embedded test-and-set lock that can avoid the overhead of explicit > > queuing in cases where the lock is held but uncontended. This bit is > > managed using a cmpxchg loop which tries to transition the uncontended > > lock word from (0,0,0) -> (0,0,1) or (0,0,1) -> (0,1,1). > > > > Unfortunately, the cmpxchg loop is unbounded and lockers can be starved > > indefinitely if the lock word is seen to oscillate between unlocked > > (0,0,0) and locked (0,0,1). This could happen if concurrent lockers are > > able to take the lock in the cmpxchg loop without queuing and pass it > > around amongst themselves. > > > > This patch fixes the problem by unconditionally setting _Q_PENDING_VAL > > using atomic_fetch_or, > > Of course, LL/SC or cmpxchg implementations of fetch_or do not in fact > get anything from this ;-) Whilst it's true that they would still be unfair, the window is at least reduced and moves a lot more of the fairness burden onto hardware itself. ARMv8.1 has an instruction for atomic_fetch_or, so we can make good use of it here. Will