From patchwork Fri Oct 6 13:34:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 115063 Delivered-To: patch@linaro.org Received: by 10.80.163.170 with SMTP id s39csp1375852edb; Fri, 6 Oct 2017 06:34:50 -0700 (PDT) X-Google-Smtp-Source: AOwi7QCrxbp1495IruUIXhfHXtPtY0CAjutAf0ipYj7IMSx/LiUZROHqQLl6ok3/uAUGVQMtH3Cp X-Received: by 10.98.35.75 with SMTP id j72mr2223675pfj.82.1507296890079; Fri, 06 Oct 2017 06:34:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507296890; cv=none; d=google.com; s=arc-20160816; b=gLHpmuIEukHJ4YwnryPqimdOW55DpXKUtb6k30ToIt7CezGmMqnSjkJCbR94JdmItS wG1Uaar0RAueCAp0dpVKvEQ05cijACji/q4RIsmryz4v5Jj+FN9PVMDppovGjuWh8iua RNSmisiD5SAHLSt/eukqvicD8aXd7P2tu1hs9saR56fitiqLLgfSE62nuEMkuTuG6DRJ kRMTn6ie1HBKedeFyU37hGyLOovKIpPSBDtOW8/KmdWXDFTFWdAYjBf0SqsMDvDIgz/Q CeK8Dn0hNdzsIiOin9S2AjTy9YGCjJ2nsCeCDEzAfyiW6FvlO+BrGieatzzExNAAeM6E nHUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=Lsbu1jjDUivTkhhOKC6THwxDtyqrfTUgDs8peL1zrsc=; b=rc2KT8W9PhSxN+1M6z4tQvALhh/KTuvR+JD2RjgsjaxnhdS8IB0uPe528dHyaJH6ql Qqu53Vthg/Mfl4ToV8fHN3cNRUITWi+nr+u9QC6KHtt8vLpIiPq2zmjLfSFEqioVfhJ6 P06SGXFhNjcVpfFYGivrbWSCx+YiLWZHJ6lzTF2VqsTqUb3SC2ycV4QSwAsLrOLQNpRw Jr8a9EzxmikQPZOU276w9KH82kTXbM2DbRxVT4KdIT1C8bg3JgN5FOaxZG47Rcwdnh+k KyNv2JibOYqQ6IEatBnRFWWS+Z1zNguOx8nn5xZL0PVCOaO40jASrkZAtp6KzlDzVZrY AfdQ== 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 t24si84665pfj.580.2017.10.06.06.34.49; Fri, 06 Oct 2017 06:34:50 -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 S1752614AbdJFNer (ORCPT + 26 others); Fri, 6 Oct 2017 09:34:47 -0400 Received: from foss.arm.com ([217.140.101.70]:33586 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752410AbdJFNem (ORCPT ); Fri, 6 Oct 2017 09:34:42 -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 E4CCD15BF; Fri, 6 Oct 2017 06:34:41 -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 B39343F7B9; Fri, 6 Oct 2017 06:34:41 -0700 (PDT) Received: by edgewater-inn.cambridge.arm.com (Postfix, from userid 1000) id 5BFDC1AE2E09; Fri, 6 Oct 2017 14:34:43 +0100 (BST) From: Will Deacon To: linux-kernel@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, Jeremy.Linton@arm.com, peterz@infradead.org, mingo@redhat.com, longman@redhat.com, boqun.feng@gmail.com, paulmck@linux.vnet.ibm.com, Will Deacon Subject: [PATCH v2 2/5] locking/atomic: Add atomic_cond_read_acquire Date: Fri, 6 Oct 2017 14:34:39 +0100 Message-Id: <1507296882-18721-3-git-send-email-will.deacon@arm.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1507296882-18721-1-git-send-email-will.deacon@arm.com> References: <1507296882-18721-1-git-send-email-will.deacon@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org smp_cond_load_acquire provides a way to spin on a variable with acquire semantics until some conditional expression involing the variable is satisfied. Architectures such as arm64 can potentially enter a low-power state, waking up only when the value of the variable changes, which reduces the system impact of tight polling loops. This patch makes the same interface available to users of atomic_t, atomic64_t and atomic_long_t, rather than require messy accesses to the structure internals. Cc: Peter Zijlstra Cc: Ingo Molnar Cc: Waiman Long Cc: Boqun Feng Cc: "Paul E. McKenney" Signed-off-by: Will Deacon --- include/asm-generic/atomic-long.h | 3 +++ include/linux/atomic.h | 4 ++++ 2 files changed, 7 insertions(+) -- 2.1.4 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h index 288cc9e96395..f2d97b782031 100644 --- a/include/asm-generic/atomic-long.h +++ b/include/asm-generic/atomic-long.h @@ -243,4 +243,7 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u) #define atomic_long_inc_not_zero(l) \ ATOMIC_LONG_PFX(_inc_not_zero)((ATOMIC_LONG_PFX(_t) *)(l)) +#define atomic_long_cond_read_acquire(v, c) \ + ATOMIC_LONG_PFX(_cond_read_acquire)((ATOMIC_LONG_PFX(_t) *)(v), (c)) + #endif /* _ASM_GENERIC_ATOMIC_LONG_H */ diff --git a/include/linux/atomic.h b/include/linux/atomic.h index 40d6bfec0e0d..0aeb2b3f4578 100644 --- a/include/linux/atomic.h +++ b/include/linux/atomic.h @@ -653,6 +653,8 @@ static inline int atomic_dec_if_positive(atomic_t *v) } #endif +#define atomic_cond_read_acquire(v, c) smp_cond_load_acquire(&(v)->counter, (c)) + #ifdef CONFIG_GENERIC_ATOMIC64 #include #endif @@ -1072,6 +1074,8 @@ static inline long long atomic64_fetch_andnot_release(long long i, atomic64_t *v } #endif +#define atomic64_cond_read_acquire(v, c) smp_cond_load_acquire(&(v)->counter, (c)) + #include #endif /* _LINUX_ATOMIC_H */