From patchwork Mon Jun 18 10:19:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 138880 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp3770239lji; Mon, 18 Jun 2018 03:19:59 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKqBMQ0o2T1A6r5rSLv8pr3AomfbrB6ppRfpvk/iSOvBSe6AaXcpGuuLiR9rY0sCVAqDXzU X-Received: by 2002:a17:902:74cc:: with SMTP id f12-v6mr13496383plt.7.1529317199406; Mon, 18 Jun 2018 03:19:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529317199; cv=none; d=google.com; s=arc-20160816; b=rikmIT0qSClSCBgBocqfCpmUYJFL3/f/UBR7tqN4z0B9VfILZBDcSUFP2s38EcKYHW V2XmDYEqluUKKO7zaYJomQBVGSTUJYYqVMfIELJrWiFDmrQi/eqTwR0e7YyGvRXNGFR3 Ee2XqYPYpEFMHrukSLWXYaAxWPCfxAv8qmuMbU1z56P018c4fK2SbPJwgulI3lx9gGJj PkrYJ9mQ+1G05Y3NlussRLC/g3/uaX8Xhwfq3TI0vIEjm35rHq/2/pqRW3grVXaLCf09 wJ+m+JYgimaTJjGBcE7lTxTA4FY0x0W0/E8YkwTstLQgYapZY57s3igF8ZC0owvApyZd gfGQ== 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=Lzvboy/dVIJPG4S3le8hERVJuF/RwF6VRWWgKt4vI1SWsJcFh6SMc6wekyTApIVWY5 R6xGgTWgyKro2mt1GHR0hX5gRWvWSMVGPV+44bYsgyjF9ojAOs199oKKCzhru/t+pJ8X dTghVRWZlGc7jkCCElGyY1QVc2+s2WHrykoHYdOeDUeNH4xzwFzKs9Ip8ZD/p9LANZzz w8MMuEJolr9DQ2cNKXz90b9oSn+P8fUN7WqvzgqKHZQZc2kevbdvXlzyjv69srLl3kyk zBthoxLmx8BxdcYfH0BL+lyLz9rsbZ4O3GtjNqMncjWuuQ4ZzKcDj8X1PGfBUs6B3kQW j+fA== 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 f184-v6si14775115pfb.314.2018.06.18.03.19.59; Mon, 18 Jun 2018 03:19:59 -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 S937009AbeFRKT5 (ORCPT + 30 others); Mon, 18 Jun 2018 06:19:57 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:59470 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933946AbeFRKTz (ORCPT ); Mon, 18 Jun 2018 06:19:55 -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 7F5FF15BF; Mon, 18 Jun 2018 03:19:55 -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 2B57D3F25D; Mon, 18 Jun 2018 03:19:54 -0700 (PDT) From: Mark Rutland To: linux-kernel@vger.kernel.org, will.deacon@arm.com, peterz@infradead.org, boqun.feng@gmail.com Cc: mingo@kernel.org, Mark Rutland , Russell King Subject: [PATCHv3 11/18] atomics/arm: define atomic64_fetch_add_unless() Date: Mon, 18 Jun 2018 11:19:12 +0100 Message-Id: <20180618101919.51973-12-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180618101919.51973-1-mark.rutland@arm.com> References: <20180618101919.51973-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))