From patchwork Mon Jun 18 10:19:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 138888 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp3772173lji; Mon, 18 Jun 2018 03:22:04 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLWXHmYN07mV5ilp13Mitd21OYNjyewkeqBd39R2EyoFwRp2fni8KyrGwgoRDDB+y1bpZT1 X-Received: by 2002:a63:a44a:: with SMTP id c10-v6mr10315159pgp.198.1529317324013; Mon, 18 Jun 2018 03:22:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529317324; cv=none; d=google.com; s=arc-20160816; b=z+XalDOTVn9S7t9IE6XakK6qBbY/rPdZ5GM2etwvmPLKGOtUTSzJQnFS181U4sAAMX ZSoV1zmyuvshQeDomvqpjlZ+0T2RgFVkHDFEbS2HZ8XzBNHPV4VczEH+9qz7p4s02tu1 0/CQc4s1buBfvqaKjF9Lt8i/GL4bIzN4D8wTAMg0VxW5KP5dRAlb1fhdWkKLLVzmpCEx s63CShCnW89Lgo+ZduFk2kEpGmu5aI97ySaBl0G2O/X8lm6KrqhheSmDu1l12zolcARu UfM6iDXRKY0mCi2rYj2DV6ytXgTNOXXUVdI6m6BlxtFVKX2G7aaA/QHogR7a2zSXAYc/ B3wQ== 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=8J8sfhmB0wS/O4wy4nIaGb8WuUXp3cf3A5h3bLjoIzY=; b=GoqbX36dgm08cd4SYDhviGz2tiiVkhLAsvPHqLc1N5tYJSQAuAwcHwPY+wVFc4aGPW j6IgNBBcxzGIT9SdgkWOpjt2P6z0VcRe/cuI3cH+yvOS/1U64PnS1c3vL7nr/9J/QF/b 9pgWxOqqRb2JlveCyTOIU02ZRn/Qu5sI7MJlJ2IoeTlhSx7CxYk3NG77zm2sfjuSA+I6 JIttAW8CQs7lgHBwzGwnI+vL5WknKHMx6zjUQyAzCVdC6CZxjXZ6ckAapI0jOMyADOeI Prys7umHNuKgW5JY/d6f07v+amBO7jcDGT/feajMjFHCQryJBYKEBH5sfQVMxzqkIapK bAzw== 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 m6-v6si12373667pgt.636.2018.06.18.03.22.03; Mon, 18 Jun 2018 03:22:03 -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 S965757AbeFRKWC (ORCPT + 30 others); Mon, 18 Jun 2018 06:22:02 -0400 Received: from foss.arm.com ([217.140.101.70]:59454 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S936991AbeFRKTx (ORCPT ); Mon, 18 Jun 2018 06:19:53 -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 6831215BE; Mon, 18 Jun 2018 03:19:53 -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 13ECD3F25D; Mon, 18 Jun 2018 03:19:51 -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 , Vineet Gupta Subject: [PATCHv3 10/18] atomics/arc: define atomic64_fetch_add_unless() Date: Mon, 18 Jun 2018 11:19:11 +0100 Message-Id: <20180618101919.51973-11-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/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 Acked-by: Peter Zijlstra (Intel) Cc: Boqun Feng 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..4917ffa61579 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, if 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))