From patchwork Mon Jun 18 10:19:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 138889 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp3772575lji; Mon, 18 Jun 2018 03:22:29 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJuAlRd/TnN51HoOlandI0RQ4pj0EgRrM82c9H1tPQbLaEJyo+/HcxH+KoqfZjAfv/2xwlW X-Received: by 2002:a62:2281:: with SMTP id p1-v6mr12918129pfj.53.1529317349432; Mon, 18 Jun 2018 03:22:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529317349; cv=none; d=google.com; s=arc-20160816; b=xGjhdFZIjMtTEG4NGPFDTZOWTYFM8pvPi4sRSV3w/Lbl++VVDASaBXKsenFDlNX0BF Wx4JAarIHeF9gVArGv5jAVNL7h7KgfDD/laqEUrkurc1M4mZzyM8o4k8bFTAK2eKfm6Y PDG2EXNAF6+K3+l0TNf2t3SuNb2MDQJZi1xJqFkonApjB2SE62iquE9HG+VUPfnr8cvx kmi612UKVZEzPFzGtRsoq542jfeDvekzzJH0lqZ0wb+aq9Lv5Ag51SxQd0CqrXXTdH7C EQUGAmDFxU4iiq2lZgC671TGU/Oajpg3TMGlScC5qekOpB2mqkL8DYrJJwTGypnZBMX2 /P9g== 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=du8A9LhK3dGKfUwdcfbjjWgcDOh0TYqK6/JjZ+iEXm0=; b=wv5+azkVOFrnBxuAhA0YZKbnBKMog7eNmEeYd2JTk0mMGUaPFWF7K48+tzGSeJcchM U3B8BerZIf2XIKs2i3sqOwjWpWRlJB2UyWliZletWMwuod5JugcBoKfEOjYyVSvDV+bT OzKJtmJZQjv4qWGMslu8nX1JcI+gI2WjvkUjMs8wk/dpg3WQWlMU5gKrGwKlg1y2aNTa 0X0Yo5zDrA3d7lyemgzjXwi2LjXrffB4FvLWcgrNLEyOrRknxsnRmuQ0T/jE3GDMZ5Yd MhKbTA5K5nb52vaAgUqAg6qgQrB+c7GJeCeCmznao5Z/UtfKTtb7J6gWeDav+Pv6omBW 6kyA== 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.29; Mon, 18 Jun 2018 03:22:29 -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 S936992AbeFRKW1 (ORCPT + 30 others); Mon, 18 Jun 2018 06:22:27 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:59428 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S936978AbeFRKTt (ORCPT ); Mon, 18 Jun 2018 06:19: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 C57081596; Mon, 18 Jun 2018 03:19:48 -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 6FBB73F25D; Mon, 18 Jun 2018 03:19:47 -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 , Arnd Bergmann Subject: [PATCHv3 08/18] atomics/generic: define atomic64_fetch_add_unless() Date: Mon, 18 Jun 2018 11:19:09 +0100 Message-Id: <20180618101919.51973-9-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 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) Cc: Boqun Feng Cc: Will Deacon 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);