From patchwork Thu Jun 21 12:13: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: 139531 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp1991649lji; Thu, 21 Jun 2018 05:14:00 -0700 (PDT) X-Google-Smtp-Source: ADUXVKI8etArBdbSQ8ZKI9ctn4ijrrtwYiuHzVLlfCLUJYQOul1MjcF96z2o4oKBiVn7Owt4Eqfh X-Received: by 2002:a65:53cc:: with SMTP id z12-v6mr22420187pgr.350.1529583240241; Thu, 21 Jun 2018 05:14:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529583240; cv=none; d=google.com; s=arc-20160816; b=O+Z0xnGoRvfghZFEM/oA0si9Pw10+/NXzrOsb0XRBosGHTTjRPATQ8sKGgCxIsylhQ A+m7n6o99d3CTioha2iaOqVZfLISxlZ4TvBxxvzblbcFjYmODopA8eSmYFhPPW1K3dMS G8eZqgJfdc/eL52yx63Viz9v2mpM84E6bPcNoADc3VPX5x39S1YjJI8SzzuwAYGUGXqp eQSDe2NZwhgryhk3NbYi8rbhj2eJanCKOevsVCh5TFqq3gnby/SW/BcMkhyPXqgl7B9h /wB2TMsCnwgLUDe1326+kTfEgKEldV93rID9yIgMXZthX3PpQdPr+9ax76WOud310dLT nZOg== 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=X6ruuXQktb3uQVTrnPQxSk0fMI1iqxBzPijtyRyb96c=; b=zFUPtuqBS4+Iv34fWnY5TGRG5AAoW7+SM8MYvzZ/vXjw3HmjFjz8qEcU4A2OxkcBqr bbRhT+gdvltAwISA+8436q2ucnaB5CY9rVWFmC+HCaQz6EqHxaSE/+dkjtFqjDRV8Z9u 2XTdq/3Ig6Oqf5/sqJHcEy9296cF0JXUhk9g8vV3ttd/xIroI3f09p0yB+eE6VRlOQUi VqLTR12MADwyts3u7InJUTifkNTW6o/QWg140Lyluf4rex0KKipxYt95Vln2tGI28vdP X/23wnxHGPEbPQTIPhqGoR2fW0RUqJvoE3j/EB5fOB2ujSi6N9EFKthY388ZSub690FE xxxA== 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 f90-v6si4668924pfe.291.2018.06.21.05.13.59; Thu, 21 Jun 2018 05:14:00 -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 S933686AbeFUMN5 (ORCPT + 30 others); Thu, 21 Jun 2018 08:13:57 -0400 Received: from foss.arm.com ([217.140.101.70]:49354 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933258AbeFUMNw (ORCPT ); Thu, 21 Jun 2018 08:13:52 -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 B63D41529; Thu, 21 Jun 2018 05:13: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 1B7483F578; Thu, 21 Jun 2018 05:13:49 -0700 (PDT) From: Mark Rutland To: mingo@kernel.org, will.deacon@arm.com, peterz@infradead.org, linux-kernel@vger.kernel.org Cc: Mark Rutland , Boqun Feng , Richard Henderson , Ivan Kokshaysky , Matt Turner Subject: [PATCHv4 09/18] atomics/alpha: define atomic64_fetch_add_unless() Date: Thu, 21 Jun 2018 13:13:12 +0100 Message-Id: <20180621121321.4761-10-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180621121321.4761-1-mark.rutland@arm.com> References: <20180621121321.4761-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) Reviewed-by: Will Deacon Cc: Boqun Feng 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..cc486dbb3837 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__ long 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