From patchwork Thu Jun 21 12:13:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 139527 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp1991342lji; Thu, 21 Jun 2018 05:13:44 -0700 (PDT) X-Google-Smtp-Source: ADUXVKK8+f2V8WJfAvKqPwSrdqViaESPeareTh6zT9waTGoVHAx0fu1X9OyURQ8w7RjPWE43tTAp X-Received: by 2002:a17:902:8a4:: with SMTP id 33-v6mr27851740pll.343.1529583224622; Thu, 21 Jun 2018 05:13:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529583224; cv=none; d=google.com; s=arc-20160816; b=LgQCI1E61VYW3KSSANfw0e8dsTp/3WArrq1kJai3Ds9nwRM5R/9LssRxyU8IkRL9Gc TdMzwg/P7NTKtaO3RXHYaIj99FgRNh83WDfSAJcPZf2kcUpvK0VF9flgSkVgAWaY7ruj LyYr/3qh6ELiS+N/CgYDTtG89LIMyLhtRHFFx8GNDYYxWeP+YO+KkOGzwOHo0EjRw1Yi 9SGc7rw6b+G8iDnuiAlOaVBwpt/Gw4IPEWu7D9zwnr7xfH1SCY2cT+/9FbqcVly/ZxMV nQABdbo59SZE+HnDtW922Rnk14lPI0wT/Lgst51RIma6tJuJdiBnUkAb3AFopBo8xRn9 URNg== 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=rLO42Cck+Eo2h07U7rEBszan+6F55MX19chGbNHQ4J4=; b=o8Gg4LwLUZfCakEohWI/TklnRkiSDwInU2kJO7YUSWTSoIQjenIYC9lItDWD7mA728 ZU21AyH+Rc5IqHWdWJeWrHVltEuZj279M1QpEpYlM0vWXy6fI9whIXeHWkim7ZvhnZTL upm8t0VLNdeS8fNBdFkFx93FBKdGcZUbz8DFgcanpPb7VRVQ4jpBOmnxiYaFb83ZMUZl KJqvwqWJgYPwB/LWdh2j3UpA7wuhZyK+Oct2Ey2SsZHaZpxLVk0S9LYNfSBplZnmZL3z 9/7t8pCtQaDDZyP31SU5PHL5ZuqUiy+jjOZZF2pNKELCw2ME/wYmQZHleItNZumWGnZF nCAg== 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.44; Thu, 21 Jun 2018 05:13:44 -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 S933556AbeFUMNm (ORCPT + 30 others); Thu, 21 Jun 2018 08:13:42 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:49266 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932763AbeFUMNi (ORCPT ); Thu, 21 Jun 2018 08:13:38 -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 C18C915BE; Thu, 21 Jun 2018 05:13:37 -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 90AAA3F578; Thu, 21 Jun 2018 05:13:36 -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 Subject: [PATCHv4 03/18] atomics/treewide: remove atomic_inc_not_zero_hint() Date: Thu, 21 Jun 2018 13:13:06 +0100 Message-Id: <20180621121321.4761-4-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 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) Reviewed-by: Will Deacon Cc: Boqun Feng --- 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; /*