From patchwork Thu Jun 21 12:13: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: 139541 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp1994284lji; Thu, 21 Jun 2018 05:16:16 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIkGiL5ZglJCiQ0UNZuTp75/zZxThZOH0htM3Np4orzS8S9MlODRDY57VJBFJ+3zMJGAyqv X-Received: by 2002:a62:e310:: with SMTP id g16-v6mr27302388pfh.25.1529583375887; Thu, 21 Jun 2018 05:16:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529583375; cv=none; d=google.com; s=arc-20160816; b=ATUaRVp64VDuW2AjoZbnZyY4gNvDNEmGwdVAjRNDu+769rLAPm5npvJmMK4iGtRR5e gNNOWkEgycUUt8+8zF4aYuNeSSefzsQwSqg97xkBVbHfhoUozReLkYOymKRpd6AVTXr1 39B8BWcBcli2Y3kWbTV9+RL0EKLjckgC7UsLILXho4LyuAdsazM0/ptgjIEgzebjIEVC M68dfa8PAO3X79gRSMQy23DoSI+NsDrqTS8omVW7HhbYnHmAy/CfYENPN5J2cB5UO64r UGgpFiY1QVJ3K/H4x5f90cvvLCxRawOB+gnZSBoYCStsclAT+kBJ8qDt8c1OOWRfQp+v ch1Q== 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=xoL7QGksXeuua9EI+61fXXeQA0aR46YVwpISxhWeHQM=; b=NwQ8kCivlKz8WgyfUsYLuHCOIrG9Q1snbyr6d+AZqu5nrJdA8ldkxznC2X1wCxnfI4 6+msT8b/NoJ9+FSeWLgVhx56GhYV4OybDPCmKDYi7teasV4raIqatLkPCmLOU/nDw3LT PjOYFkvO39VqsngehKUPEPe3nA+5TIkBhrgxdpiNT13RQnemtmXXwmpOU2gwCsOymn0z 1dc4cqpw5VgrUbGJcjYDHIvmP/+0cWZg3h+1ZryiCdvh2nEWBV1pHV/Scn7kKaQZmqK1 HvagEVs5/vHJRQTegF/knZdDtvr4jrbbrDx7WLJs/kxky7exJQ3RKz4MHuYx/eYCXyd8 gWuQ== 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 e11-v6si5291113pln.161.2018.06.21.05.16.15; Thu, 21 Jun 2018 05:16:15 -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 S933795AbeFUMQN (ORCPT + 30 others); Thu, 21 Jun 2018 08:16:13 -0400 Received: from foss.arm.com ([217.140.101.70]:49342 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933460AbeFUMNt (ORCPT ); Thu, 21 Jun 2018 08:13:49 -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 543FC1435; Thu, 21 Jun 2018 05:13:49 -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 001863F578; Thu, 21 Jun 2018 05:13:47 -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 , Arnd Bergmann Subject: [PATCHv4 08/18] atomics/generic: define atomic64_fetch_add_unless() Date: Thu, 21 Jun 2018 13:13:11 +0100 Message-Id: <20180621121321.4761-9-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 generic implementation of atomic64_add_unless() into a generic 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: Arnd Bergmann --- include/asm-generic/atomic64.h | 3 ++- lib/atomic64.c | 12 ++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) -- 2.11.0 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h index 5105275ac825..49460107b29a 100644 --- a/include/asm-generic/atomic64.h +++ b/include/asm-generic/atomic64.h @@ -53,7 +53,8 @@ ATOMIC64_OPS(xor) extern long long atomic64_dec_if_positive(atomic64_t *v); extern long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n); extern long long atomic64_xchg(atomic64_t *v, long long new); -extern bool atomic64_add_unless(atomic64_t *v, long long a, long long u); +extern long long atomic64_fetch_add_unless(atomic64_t *v, long long a, long long u); +#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)) diff --git a/lib/atomic64.c b/lib/atomic64.c index 4230f4b8906c..16ac13113c8e 100644 --- a/lib/atomic64.c +++ b/lib/atomic64.c @@ -178,18 +178,18 @@ long long atomic64_xchg(atomic64_t *v, long long new) } EXPORT_SYMBOL(atomic64_xchg); -bool atomic64_add_unless(atomic64_t *v, long long a, long long u) +long long atomic64_fetch_add_unless(atomic64_t *v, long long a, long long u) { unsigned long flags; raw_spinlock_t *lock = lock_addr(v); - bool ret = false; + long long val; raw_spin_lock_irqsave(lock, flags); - if (v->counter != u) { + val = v->counter; + if (val != u) v->counter += a; - ret = true; } raw_spin_unlock_irqrestore(lock, flags); - return ret; + return val; } -EXPORT_SYMBOL(atomic64_add_unless); +EXPORT_SYMBOL(atomic64_fetch_add_unless);