From patchwork Tue May 29 15:43:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 137189 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp4214586lji; Tue, 29 May 2018 08:46:21 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoDARDbhh44VN2Llf24E1qWIALz2oBZgH1rInC3yJoJ/nsPCzmbp9969A8JV9RQiRZhkY3l X-Received: by 2002:a17:902:8f8b:: with SMTP id z11-v6mr18027585plo.203.1527608781803; Tue, 29 May 2018 08:46:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527608781; cv=none; d=google.com; s=arc-20160816; b=HICCt2YLDXdQftKnywVESlw4XDgy2QR3FGTg2PpNHrxUH7c00gKBWaZCdZ7qL7Pi+c 7Yl0r++Qk4gHHPAmvxgV0p9GM6L8iLX/3woMFWZkjZqK+UC1u78Z07Ac2VF/c0Ql/iqE cYAeiE1k+RwOKvjfZJb4qxJlO+mZs/VuWjbOVr6p9z2IaPEl5PZlYQiYU9K8B75cLIHV blSRmAfnjyDoCUq+Nr/L3RvvO901kmWqQJzgBsdts2adaV68gkPxM4vpP5PfTg2HLPuN RtqybrK4XCJ6bd6Ct4AC4VwwVE9gXOop0d9rPV2K9s3aNyQlre1K2eGEUzUwxZrXHDe3 R8+A== 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=+Y9bMEEcT8FREn6Fvd+7h2yYj8wu8sblN3dn8WWJe5s=; b=YDBF52suYXNdTnRNXqleRtjygcR01t9yLWtRi85y38/HQHL3Tq3VYFf/KIpxDuVuxh +EO0daG9DJwnDYvZLFU6EL9vvy8wid/rA9S4iVLGX056kU3LiUITSzD8pH6eKSjP8rm7 ns/Cr+U1zItpRXxlQDOuWZYAd4RIBstree2+IOAvrlLQZpZhnyzg/9gB4XufL3plJq5r WXIBhBUIreIut1B0SW4GEU33kdT4tZSvFbekgMi4OKumWT4RyneQNa8ApG9irulKL5uO RE1QXpAB+NqdV50IolhCKvJ6XpLhCJOM/+DZVqAaRMAFAWf958cmkoPWrMmnH+Dptl1A oVWQ== 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 v38-v6si33618368plg.283.2018.05.29.08.46.21; Tue, 29 May 2018 08:46:21 -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 S965082AbeE2PqU (ORCPT + 30 others); Tue, 29 May 2018 11:46:20 -0400 Received: from foss.arm.com ([217.140.101.70]:43512 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S936866AbeE2Poa (ORCPT ); Tue, 29 May 2018 11:44:30 -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 C19C815AD; Tue, 29 May 2018 08:44:29 -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 B460B3F25D; Tue, 29 May 2018 08:44:28 -0700 (PDT) From: Mark Rutland To: linux-kernel@vger.kernel.org Cc: Mark Rutland , Boqun Feng , Peter Zijlstra , Will Deacon Subject: [PATCHv2 14/16] atomics/treewide: remove atomic_inc_not_zero_hint() Date: Tue, 29 May 2018 16:43:44 +0100 Message-Id: <20180529154346.3168-15-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180529154346.3168-1-mark.rutland@arm.com> References: <20180529154346.3168-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 Cc: Boqun Feng Cc: Peter Zijlstra 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 7d41b6fffab6..8ec4d120b264 100644 --- a/include/linux/atomic.h +++ b/include/linux/atomic.h @@ -656,38 +656,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; /*