From patchwork Mon Jun 18 10:19:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 138891 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp3773553lji; Mon, 18 Jun 2018 03:23:37 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJkzcQOjahK54dO0yBZRoGwSwqc+RDCjNA4628aA/QNxJyyWsVaA8juV1BS6cktbYsufPCb X-Received: by 2002:a17:902:2702:: with SMTP id c2-v6mr13303442plb.297.1529317417823; Mon, 18 Jun 2018 03:23:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529317417; cv=none; d=google.com; s=arc-20160816; b=jas3kI+9xRh48B2NGw/4/rZo/ODrj4TUqABFNDZyw0vmp9dMPAh1wqbMVNlQgC6Z1d zFMHuqrznhRxZS+T9Xu4yiaWpc4WP/mpb3SIy81vJZb5EbTKWO7KoWPbmhyH460toqaN kMpVWRzyWkvCsN/By4/SKYd6j0R7bGoFLYuKlSIymKX/2cakpkKIOMY309JPIcGBUoG7 H+YSg/dya6AIeWAVDwPV/0v6SLPeKrtYE+UrK/HL8KqGJ8XioNxn1/ZPXjKb9Cc9N/gn r//sxavNClJ2DeecspAZhGwqvTYsaN/cokAIf+Uda3NNv6q1RM1Uff0RpbPc0zY48/fb SOqg== 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=wq00ozMzgj+1VnE+IiPGEQC+JW7AoQ9wZM3oVrADEF4=; b=AQESNvPx02/jGTKrBCrMZ1RiG2wqvRGUQujAUCzIm7GndnnQzYi6LhPwOtfFErMpB0 iMSSxDeAv36UNaJQLZqFUMuxederRaGerm+sfXplmB4t9tWTmhYJtqcY+IVE7qqSJMhD a0ahvsET/zDWb9okT2ZG6yZl/LQaKYUaxlH3MBSyw+q6e6K7F0LFH7G53tRn0WukKNpj e2W40XBqmEJautewALoDATkN89mYR2hPDmzA2eRVQeaSCl0usoOrjmSXNb6adzgZ2nkb yfafKDAk+ma05k3SJFWrBcOIwGuc/sZ5vL8SCpjvwcbk0s/LvS8wa+T4itu5OgXhRnxC Xc4A== 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 5-v6si14856763plx.517.2018.06.18.03.23.37; Mon, 18 Jun 2018 03:23:37 -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 S937102AbeFRKXf (ORCPT + 30 others); Mon, 18 Jun 2018 06:23:35 -0400 Received: from foss.arm.com ([217.140.101.70]:59352 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S936900AbeFRKTg (ORCPT ); Mon, 18 Jun 2018 06:19:36 -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 23DB815BE; Mon, 18 Jun 2018 03:19:36 -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 E6E323F25D; Mon, 18 Jun 2018 03:19:34 -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 Subject: [PATCHv3 03/18] atomics/treewide: remove atomic_inc_not_zero_hint() Date: Mon, 18 Jun 2018 11:19:04 +0100 Message-Id: <20180618101919.51973-4-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 While documentation suggests atomic_inc_not_zero_hint() will perform better than atomic_inc_not_zero(), this is unlikely to be the case. No architectures implement atomic_inc_not_zero_hint() directly, and thus it either falls back to atomic_inc_not_zero(), or a loop using atomic_cmpxchg(). Whenever the hint does not match the value in memory, the repeated use of atomic_cmpxchg() will be more expensive than the read that atomic_inc_not_zero_hint() attempts to avoid. For architectures with LL/SC atomics, a read cannot be avoided, and it would always be better to use atomic_inc_not_zero() directly. For other architectures, their own atomic_inc_not_zero() is likely to be more optimal than an atomic_cmpxchg() loop regardless. Generally, atomic_inc_not_zero_hint() is liable to perform worse than atomic_inc_not_zero(). Further, atomic_inc_not_zero_hint() only exists for atomic_t, and not atomic64_t or atomic_long_t, and there is only one user in the kernel tree. Given all this, let's remove atomic_inc_not_zero_hint(), and migrate the existing user over to atomic_inc_not_zero(). There should be no functional change as a result of this patch. Signed-off-by: Mark Rutland Acked-by: Peter Zijlstra (Intel) Cc: Boqun Feng Cc: Will Deacon --- include/linux/atomic.h | 32 -------------------------------- net/atm/pppoatm.c | 2 +- 2 files changed, 1 insertion(+), 33 deletions(-) -- 2.11.0 diff --git a/include/linux/atomic.h b/include/linux/atomic.h index 9cc982936675..5c5620ae5a35 100644 --- a/include/linux/atomic.h +++ b/include/linux/atomic.h @@ -571,38 +571,6 @@ static inline int atomic_fetch_andnot_release(int i, atomic_t *v) } #endif -/** - * atomic_inc_not_zero_hint - increment if not null - * @v: pointer of type atomic_t - * @hint: probable value of the atomic before the increment - * - * This version of atomic_inc_not_zero() gives a hint of probable - * value of the atomic. This helps processor to not read the memory - * before doing the atomic read/modify/write cycle, lowering - * number of bus transactions on some arches. - * - * Returns: 0 if increment was not done, 1 otherwise. - */ -#ifndef atomic_inc_not_zero_hint -static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint) -{ - int val, c = hint; - - /* sanity test, should be removed by compiler if hint is a constant */ - if (!hint) - return atomic_inc_not_zero(v); - - do { - val = atomic_cmpxchg(v, c, c + 1); - if (val == c) - return 1; - c = val; - } while (c); - - return 0; -} -#endif - #ifndef atomic_inc_unless_negative static inline int atomic_inc_unless_negative(atomic_t *p) { diff --git a/net/atm/pppoatm.c b/net/atm/pppoatm.c index 21d9d341a619..a4d82afd4586 100644 --- a/net/atm/pppoatm.c +++ b/net/atm/pppoatm.c @@ -244,7 +244,7 @@ static int pppoatm_may_send(struct pppoatm_vcc *pvcc, int size) * the packet count limit, so... */ if (atm_may_send(pvcc->atmvcc, size) && - atomic_inc_not_zero_hint(&pvcc->inflight, NONE_INFLIGHT)) + atomic_inc_not_zero(&pvcc->inflight)) return 1; /*