From patchwork Thu Oct 5 12:54:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 114937 Delivered-To: patch@linaro.org Received: by 10.80.163.170 with SMTP id s39csp194446edb; Thu, 5 Oct 2017 05:56:20 -0700 (PDT) X-Google-Smtp-Source: AOwi7QCD+G1Lco3+Hf67ZpBeTrlZf2nzQdl3MSZpihCD1cRx1UVLkT8rB9A9A9Gbin+R1DKucnd0 X-Received: by 10.99.176.14 with SMTP id h14mr21482833pgf.358.1507208180523; Thu, 05 Oct 2017 05:56:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507208180; cv=none; d=google.com; s=arc-20160816; b=bKucdNhTCE7FYPiv5cUbJCp8Qwg+SFczvm0ydeWsLxcN/VKfktsKxXvkwOfAOS9ILW hdHNB4AhqHvIcA11JgkFZhjtmTUhsUW69tlopQixX4wlbKVUeZnKjTgB31w8aDrltM0y Uw0NHfxDVr61t6bSyq1W8ItjyXgBdQYGlmr5LoRqyCDOlqVh1rBc+hWUuVXAaCyLAOss UUkiBfbp6qXQBJs6vxtaj5LjC6PPlwSLcZYc66bveye+n19MQColuRTh4NG/OsVpBk56 I40Cn+vVGkyEhIOyYTb11ObrQK2SlWp/eGZkK85rFfYJe6q94bpGJ6qVGBKJo3mnYFZT JEbQ== 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=BQuvjM4CDAt4fOd4Ge/ciUpvvElTL+vA/u0M85KpLh3RM2dS+KDAXMGqI11ECOJFqB 41h7f1Ugh+O26P9CfKuJMYGBSnPfKhqsSDeKdbqBJ2ONaNYUk4P4z0gIeQoUSBD7LhnK jcm6V4zc+I/X0v7aexKTTEswwQ5tPIhM1DfoWRh1/J00gjlOA2q14Sqv0jnn8sJDE3++ wjzYKC627WfNF5woy3fJKFIHvEqjqgiPo38fa+JQmhO4iPldNh+H0dnQU7YrxhzbBh0w pD6K7tvqjJ68mky3ASAoKqfDk8E8mejKZEbTrU0KDHlIjB+Bng1JFnyRcLWcxVkNtVm/ 4vNg== 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 q14si13757542pll.260.2017.10.05.05.56.20; Thu, 05 Oct 2017 05:56:20 -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 S1751917AbdJEM4R (ORCPT + 26 others); Thu, 5 Oct 2017 08:56:17 -0400 Received: from foss.arm.com ([217.140.101.70]:44982 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751318AbdJEMy5 (ORCPT ); Thu, 5 Oct 2017 08:54: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 A771915AD; Thu, 5 Oct 2017 05:54: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 78BB53F5CA; Thu, 5 Oct 2017 05:54:57 -0700 (PDT) Received: by edgewater-inn.cambridge.arm.com (Postfix, from userid 1000) id BF08B1AE2E09; Thu, 5 Oct 2017 13:54:58 +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 2/6] locking/atomic: Add atomic_cond_read_acquire Date: Thu, 5 Oct 2017 13:54:53 +0100 Message-Id: <1507208097-825-3-git-send-email-will.deacon@arm.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1507208097-825-1-git-send-email-will.deacon@arm.com> References: <1507208097-825-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 */