From patchwork Wed May 23 13:35:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 136662 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp909963lji; Wed, 23 May 2018 06:38:46 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqsM1pC5Xl2NXptERHROZT4iLq3nQBs33zQwVDFTmG5yw/NpAvRPkT8RoqcJ/U7ulfQNLAB X-Received: by 2002:a17:902:7008:: with SMTP id y8-v6mr2995418plk.141.1527082726858; Wed, 23 May 2018 06:38:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527082726; cv=none; d=google.com; s=arc-20160816; b=t2UB9e7Y9+k8BNVByB7R0jDuYpJjyVK/cvNLvPcpAbv1mepa+oSX3o7mSfXAH5B69e 5HoyZS28PsBcJvE8Z29d4+TaGlVEBc3xFF3vb5tYSDf8iXzYeAvvpI28IT2fk8mkfdHG CkRXaimM5akVgS/Ifh2Y4LHQVB6W4N4Njj2nGP09wZaGsS5QENJ8VVBcQCtjbVG8AjsF DTGRM9STan0FUH7XafX6zxPBrwXazmhLzN/obZ/5vuoQnigd8nVVcksFhKuMdb5eziNS sYBJCGcdNO59POCwYEzKBcvdQQkMvBSZJotrcWDZFbjrblHi4T7DnOwArCo/k93LeqQz UTYA== 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=uRKsiXrukDzaSGg4FgLSXqqwmgQG+pVHCUIdZoYZvXs=; b=jU2NWQWDmjvlBWrWFDI0zPDgTTUGjrQ3x6ORFVIPOWvaVanlgYDyux8f5xs/MeFI9e Xq4s9CaTvSo+mRhGHBxwetBPrkXSkf8fI8i0pygyfCPxK4RKxxOjP9AwJyLzQGJo78lI ZSoQd4lUZkqY95jDiPJey1vDxzTFKm0VUaLccwWAekNDSZA7a3DHeWkOUmU3UvhPFjzY K7Wsn49wDkcSHnswPBGsESBqEzG08Y2F+Ubu5FMP4dQvCqkV22/OGf9v/Xb1Jl5n8152 s5FmUDA1Jxh8fPf14UVbst6f6BM7DtvPe6eQdzFbRw2rBLdl0/bKavUuzGtpG2TVqyFH l8Dw== 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 f1-v6si19276670plf.453.2018.05.23.06.38.46; Wed, 23 May 2018 06:38:46 -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 S933215AbeEWNip (ORCPT + 30 others); Wed, 23 May 2018 09:38:45 -0400 Received: from foss.arm.com ([217.140.101.70]:55400 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933142AbeEWNgW (ORCPT ); Wed, 23 May 2018 09:36:22 -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 7B12280D; Wed, 23 May 2018 06:36:22 -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 4A4CC3F24A; Wed, 23 May 2018 06:36:21 -0700 (PDT) From: Mark Rutland To: linux-kernel@vger.kernel.org Cc: Mark Rutland , Boqun Feng , Peter Zijlstra , Will Deacon , Vineet Gupta Subject: [PATCH 08/13] atomics/arc: define atomic64_fetch_add_unless() Date: Wed, 23 May 2018 14:35:28 +0100 Message-Id: <20180523133533.1076-9-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180523133533.1076-1-mark.rutland@arm.com> References: <20180523133533.1076-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/arc 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 Cc: Boqun Feng Cc: Peter Zijlstra Cc: Will Deacon Cc: Vineet Gupta --- arch/arc/include/asm/atomic.h | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) -- 2.11.0 diff --git a/arch/arc/include/asm/atomic.h b/arch/arc/include/asm/atomic.h index 60da80481c5d..335ddc21ed03 100644 --- a/arch/arc/include/asm/atomic.h +++ b/arch/arc/include/asm/atomic.h @@ -531,41 +531,40 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v) } /** - * atomic64_add_unless - add unless the number is a given value + * atomic64_fetch_add_unless - add unless the number is a given value * @v: pointer of type atomic64_t * @a: the amount to add to v... * @u: ...unless v is equal to u. * - * if (v != u) { v += a; ret = 1} else {ret = 0} - * Returns 1 iff @v was not @u (i.e. if add actually happened) + * Atomically adds @a to @v, so long as it was not @u. + * Returns the old value of @v */ -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; - int op_done; + long long old, temp; smp_mb(); __asm__ __volatile__( "1: llockd %0, [%2] \n" - " mov %1, 1 \n" " brne %L0, %L4, 2f # continue to add since v != u \n" " breq.d %H0, %H4, 3f # return since v == u \n" - " mov %1, 0 \n" "2: \n" - " add.f %L0, %L0, %L3 \n" - " adc %H0, %H0, %H3 \n" - " scondd %0, [%2] \n" + " add.f %L1, %L0, %L3 \n" + " adc %H1, %H0, %H3 \n" + " scondd %1, [%2] \n" " bnz 1b \n" "3: \n" - : "=&r"(val), "=&r" (op_done) + : "=&r"(old), "=&r" (temp) : "r"(&v->counter), "r"(a), "r"(u) : "cc"); /* memory clobber comes from smp_mb() */ smp_mb(); - return op_done; + return old; } +#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))