From patchwork Mon Jun 18 10:19:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 138879 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp3770194lji; Mon, 18 Jun 2018 03:19:56 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKx3b4+7HzCmfi78K6Y4gz2WSQbEcuQ2P2If5oApnEbettR9MXHVuoWggR/CL+uZtivh5Fr X-Received: by 2002:a62:494f:: with SMTP id w76-v6mr12759470pfa.152.1529317196153; Mon, 18 Jun 2018 03:19:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529317196; cv=none; d=google.com; s=arc-20160816; b=WYaQX6uRr5gou5helqDdxybgXXlpej2mFVs02WHcxXqZbL35V+rpqgO2Z70jqOa5rS xO6DAuN/61IfV9f7vZGIwQWGPg+ht0iIL5kFBcPl4YGNsS4QRLNGegjG0jAhq/O+emXs V407IvaVZ6yZLimqpLnZeKXua3xT2XDCYJ5m+6Ame/CPTmUtXZeTciBV1HlGsYxLI69W LVPMRHum73i7TqRB0++AGKBo9RN5ceVMZDKOKJwvOJNkVE0P+C/etH35pYNDKybEgv6k PP2c2Dcfx+JBDR5bA2GdIvz8L4K0zv64Of/6NQqx4pb7wS+pXZGTX87p1+4z+j5lavV+ xozA== 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=mvnZaW+9DU6Q8s7XclYHZv8MXUruZYwECFgresxVNjE=; b=da9Nt/ON2combz7ydcEzt2aQ/TtJEUfiiEeUhdGEePg+3A405MGr6wdbdBX+ZBy85D TwlNBouv1W7w6iyiqUVt5zNnduImhFNsX9I/5FM0F5q6YLJWqy7djJYTes4n3LMOuzMe e4ERcPhY3Bo/9ncbwsz3upV6uwUuhKgXSEp12huourTI32KAVvD/1iotRkRMe0i45dHq SRQNzfbHv0OKf7RHTdnVIZ0MjyNhWxmFKrzKq303gf4SKXKsztj2FCAUD+YUi9H8gyue NN+F3ZCFOd+k7nKB8CrcX7J0AZGZhdBHZ1rxks4U9AzhrJ78bozaYCq/t+FeI+OwgBNU sZ/A== 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 f5-v6si16138841pln.414.2018.06.18.03.19.55; Mon, 18 Jun 2018 03:19:56 -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 S936997AbeFRKTy (ORCPT + 30 others); Mon, 18 Jun 2018 06:19:54 -0400 Received: from foss.arm.com ([217.140.101.70]:59440 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S936958AbeFRKTv (ORCPT ); Mon, 18 Jun 2018 06:19:51 -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 4939A15B2; Mon, 18 Jun 2018 03:19:51 -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 A28043F25D; Mon, 18 Jun 2018 03:19:49 -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 , Richard Henderson , Ivan Kokshaysky , Matt Turner Subject: [PATCHv3 09/18] atomics/alpha: define atomic64_fetch_add_unless() Date: Mon, 18 Jun 2018 11:19:10 +0100 Message-Id: <20180618101919.51973-10-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/alpha 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: Richard Henderson Cc: Ivan Kokshaysky Cc: Matt Turner --- arch/alpha/include/asm/atomic.h | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) -- 2.11.0 diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h index 4a800a3424a3..dcb7bbeeae02 100644 --- a/arch/alpha/include/asm/atomic.h +++ b/arch/alpha/include/asm/atomic.h @@ -238,35 +238,36 @@ static __inline__ int atomic_fetch_add_unless(atomic_t *v, int a, int u) #define atomic_fetch_add_unless atomic_fetch_add_unless /** - * 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. * * Atomically adds @a to @v, so long as it was not @u. - * Returns true iff @v was not @u. + * Returns the old value of @v. */ -static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u) +static __inline__ int atomic64_fetch_add_unless(atomic64_t *v, long a, long u) { - long c, tmp; + long c, new, old; smp_mb(); __asm__ __volatile__( - "1: ldq_l %[tmp],%[mem]\n" - " cmpeq %[tmp],%[u],%[c]\n" - " addq %[tmp],%[a],%[tmp]\n" + "1: ldq_l %[old],%[mem]\n" + " cmpeq %[old],%[u],%[c]\n" + " addq %[old],%[a],%[new]\n" " bne %[c],2f\n" - " stq_c %[tmp],%[mem]\n" - " beq %[tmp],3f\n" + " stq_c %[new],%[mem]\n" + " beq %[new],3f\n" "2:\n" ".subsection 2\n" "3: br 1b\n" ".previous" - : [tmp] "=&r"(tmp), [c] "=&r"(c) + : [old] "=&r"(old), [new] "=&r"(new), [c] "=&r"(c) : [mem] "m"(*v), [a] "rI"(a), [u] "rI"(u) : "memory"); smp_mb(); - return !c; + return old; } +#define atomic64_fetch_add_unless atomic64_fetch_add_unless /* * atomic64_dec_if_positive - decrement by 1 if old value positive