From patchwork Tue May 29 15:43:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 137186 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp4212858lji; Tue, 29 May 2018 08:44:47 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoQdmq+XzTVIkRIWV7DZTKxRqwHU6XeyUYiTMu7CleED7vEGWVv3/cMHxM8/opTCRBzd+S4 X-Received: by 2002:a63:7986:: with SMTP id u128-v6mr14191104pgc.127.1527608687180; Tue, 29 May 2018 08:44:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527608687; cv=none; d=google.com; s=arc-20160816; b=ZD3un1XGaJeDE6FvK7PF/7xxuDPo87UWtHb6mu13JmKqTIqP5bxgwby3dCslamYF5d mFf9E63iSZzFOdRF733Eh5itMgE/y8SgO9rU8pU8TYQrwVZ+NC9PyuphHoaG906cuJD6 8mAbDZ8iceZz0kPfJq1sl1rFbfQ0Z4ysJjzK7sHu7RfipSjIhKyhlwe1I4UWAR+n0fgT ARq2NoyxZI4ys9U1Jsz/Zijuy1G+tuWjKHquj+qQUHh+kOYz8eg3oWnFHjWA74cFRCLv Zq4GL1fPCAacenS86/cLTtyM/O0ehkZzbDsUvSm3HbC8fR7M2B7WQCpq3w7DElvNzh8b eTRA== 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=cncY8u0TCAY8f7xv9sX3u6+G4D5dqDsC+rnv8SR6Z4M=; b=IdkfiDlyVrgjqb/Uj+LLZsZCjZYsEEK/VlptKGr6F+42R5/bjLJxy9/Bq+Ww1A754t pCpk9D0BsqTkh+onIfVV6PxJv4DSiPWoA3ErXv19qIGoVLwF/cPLIb46WVbcYJMohvTn JfU7E1m2LShPE/7WavpzaFkGESzF+Mft92gPx6WunaUSF+M5MAznC8SX5yvxdW7ho9Ee BJ/ycvembFmKFvuT73KnYIiv3UaIDjLI/j+JsjVRlfjEAj1EhUpKIBeUmK8vVzZ4EVDB 8WC8eltRxtMl/FV5wjaK0h6zyaqVQc5X4kLvV/TWlPSgC72QrjujXuIEVt7DuQVZWQVf Etfw== 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 k12-v6si8736967pll.319.2018.05.29.08.44.46; Tue, 29 May 2018 08:44:47 -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 S935287AbeE2Pom (ORCPT + 30 others); Tue, 29 May 2018 11:44:42 -0400 Received: from foss.arm.com ([217.140.101.70]:43464 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964814AbeE2PoV (ORCPT ); Tue, 29 May 2018 11:44:21 -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 E2EDA15BE; Tue, 29 May 2018 08:44:20 -0700 (PDT) Received: from lakrids.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 D593C3F25D; Tue, 29 May 2018 08:44:19 -0700 (PDT) From: Mark Rutland To: linux-kernel@vger.kernel.org Cc: Mark Rutland , Boqun Feng , Will Deacon , Russell King Subject: [PATCHv2 09/16] atomics/arm: define atomic64_fetch_add_unless() Date: Tue, 29 May 2018 16:43:39 +0100 Message-Id: <20180529154346.3168-10-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180529154346.3168-1-mark.rutland@arm.com> References: <20180529154346.3168-1-mark.rutland@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org As a step towards unifying the atomic/atomic64/atomic_long APIs, this patch converts the arch/arm implementation of atomic64_add_unless() into an implementation of atomic64_fetch_add_unless(). A wrapper in will build atomic_add_unless() atop of this, provided it is given a preprocessor definition. No functional change is intended as a result of this patch. Signed-off-by: Mark Rutland Acked-by: Peter Zijlstra (Intel) Cc: Boqun Feng Cc: Will Deacon Cc: Russell King --- arch/arm/include/asm/atomic.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) -- 2.11.0 diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h index 74460aa00fa0..852e1fee72b0 100644 --- a/arch/arm/include/asm/atomic.h +++ b/arch/arm/include/asm/atomic.h @@ -486,11 +486,11 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v) return result; } -static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u) +static inline long long atomic64_fetch_add_unless(atomic64_t *v, long long a, + long long u) { - long long val; + long long oldval, newval; unsigned long tmp; - int ret = 1; smp_mb(); prefetchw(&v->counter); @@ -499,23 +499,23 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u) "1: ldrexd %0, %H0, [%4]\n" " teq %0, %5\n" " teqeq %H0, %H5\n" -" moveq %1, #0\n" " beq 2f\n" -" adds %Q0, %Q0, %Q6\n" -" adc %R0, %R0, %R6\n" -" strexd %2, %0, %H0, [%4]\n" +" adds %Q1, %Q0, %Q6\n" +" adc %R1, %R0, %R6\n" +" strexd %2, %1, %H1, [%4]\n" " teq %2, #0\n" " bne 1b\n" "2:" - : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter) + : "=&r" (oldval), "=&r" (newval), "=&r" (tmp), "+Qo" (v->counter) : "r" (&v->counter), "r" (u), "r" (a) : "cc"); - if (ret) + if (oldval != u) smp_mb(); - return ret; + return oldval; } +#define atomic64_fetch_add_unless atomic64_fetch_add_unless #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0) #define atomic64_inc(v) atomic64_add(1LL, (v))