Received: by 2002:a25:5b86:0:0:0:0:0 with SMTP id p128csp2032249ybb; Fri, 29 Mar 2019 17:10:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqxEHL5KiPeT8eUyJ4OBpgAuDiTBWXAu0ALzm2rIKJYozq98Ik4NvnIVQjdvmVNwOcpSplJR X-Received: by 2002:a63:da4e:: with SMTP id l14mr8256380pgj.96.1553904652704; Fri, 29 Mar 2019 17:10:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553904652; cv=none; d=google.com; s=arc-20160816; b=iWoKkqvjpyGK18swTj7hI83hDQ1NRa9jgFfGTpn6Zh1DEhH1JbGDWKsw43bK7QijdF BWcF+tbngkcm4PWNgBG83z6m4p01bLRnWjYrcQj1ZkalFr/q5whUqbBucuYFFLH17xGH W4Nur4IEV9BIeZHljJe1fweh9X0Ubzy/nBfkLyjPhiUU4jk8y2ZECPSh7vVyy8ra5uiG hfRC8me5dK9hh8ipx0RQcD3wOFv6J35iBVCT7WHLmw5j533crUxVCfjpZzWxqA5khAMT ZAQHZXZWFAtFkzqm/Q0iKLVUKXiSlnzSeMd4TERHCFnYzQIBrMg2gZEu7ku5aZKctvK1 ml6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=gFPF0xdLu5V+0kEHHrdxm8rWiz86XO06lZiBRioAcRI=; b=JT7lq9yOoKOQ8bXA8CRmBwHQn/+ovt1JzpuYE8VU9eQX6Dg7QKYhzJv56DBE5ZvsrK aLjFQRZaVG0HGJ4qTK3WFjtmWWdFE+wlWVk7KoP767OHLqeA6TSbNs04MWZtzW4/KUX/ LPbBfvNCtKtzcL45u+P97HDVegvlJE4WupoV3lXMnKKUgMQQw7BLlzvm8hAPDJgd/T5q VY3Pw6uJl/dBzBtzT3IZ/7YIqwy4Y50xDNoHFTdrHXyz7+FOemt2rtI1K1RBX9nbtSRZ fML9REsB/B+iEQY7S+/Z13dc736+nFZpIPig+D0F7hF9GUDIuU1VPWjqQnEB4V61qKQ9 lBnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@netronome-com.20150623.gappssmtp.com header.s=20150623 header.b=M6+qONH+; 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 65si3107991plf.288.2019.03.29.17.10.37; Fri, 29 Mar 2019 17:10:52 -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; dkim=pass header.i=@netronome-com.20150623.gappssmtp.com header.s=20150623 header.b=M6+qONH+; 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 S1730446AbfC3AJ0 (ORCPT + 99 others); Fri, 29 Mar 2019 20:09:26 -0400 Received: from mail-qt1-f196.google.com ([209.85.160.196]:35987 "EHLO mail-qt1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730391AbfC3AJL (ORCPT ); Fri, 29 Mar 2019 20:09:11 -0400 Received: by mail-qt1-f196.google.com with SMTP id s15so4694169qtn.3 for ; Fri, 29 Mar 2019 17:09:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netronome-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gFPF0xdLu5V+0kEHHrdxm8rWiz86XO06lZiBRioAcRI=; b=M6+qONH+QmteVwe5RMrKW8JP1cwszZ9jGlNEPDwUU74o9h9+G9R7P7fYlR1aZ3Ni78 xR58IiBkgPlV4+xX8RpfX/E8jB/z6bcNB6FPylKn+vrliUpbNCKMCfbP7iHPfCnsI6uP tzxOCfibwE6yQrW/FxGCPGhOxscjdi/pFI6w5hFX+XlBE71NzAW5UvCG5krNonY0uk8k 3mI2dvd+zt5R2u/Uru0lh7yyS/9ckd7ojW4NvkA7Zze5g3LmVNUCVwj77Q6pMUNOND+n HodpADLdydgdszggckNXsViG/zTC9fSobw6WTSCCeNFMw4cWa12x9jor34keTIm5tJol Ja5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gFPF0xdLu5V+0kEHHrdxm8rWiz86XO06lZiBRioAcRI=; b=AhBJdzmJ2++nCCSeFf+I+mlJ/yq5oADNFprkDTmfggu6ADKLAeMR51zUjdtIiTMlZF VmsHqWsMZK2pyCZrPpPmWjksUyctdkx1IQO26VUi7UuckYyNv//ifjnqqJLG9E2H04v6 FemDf7ydV0S/c3xU8JDGmTgXYHF3m/GvOlrNt6a0K8SkjipcUZStgui9WDENeVagaVRt d08iXzuC199tgTW4Z4/JvRbl+GU73jRVaky+zs/bVYkcGuV9SLQ53l4v/ivRLul7MC5m iL3bWd0wbCK18qHL8szX3JLC12orP9Z4hSoLGmztXfoKKnLlySK1/cxjkEpqShomQOfa Cfyg== X-Gm-Message-State: APjAAAVWWAkuCUnFz1r1U7fEKIKGzI+SFdL/4XC+QEGM4zjWhLj+Gnqp xuePfcJOYh92Lzq9ykpKnnkzsw== X-Received: by 2002:ac8:30a1:: with SMTP id v30mr42338564qta.176.1553904550069; Fri, 29 Mar 2019 17:09:10 -0700 (PDT) Received: from jkicinski-Precision-T1700.netronome.com ([66.60.152.14]) by smtp.gmail.com with ESMTPSA id i63sm1996757qkd.82.2019.03.29.17.09.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 29 Mar 2019 17:09:09 -0700 (PDT) From: Jakub Kicinski To: peterz@infradead.org, tglx@linutronix.de Cc: ard.biesheuvel@linaro.org, yamada.masahiro@socionext.com, mingo@kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, oss-drivers@netronome.com, alexei.starovoitov@gmail.com, Jakub Kicinski , Simon Horman Subject: [PATCH 2/3] locking/static_key: factor out the fast path of static_key_slow_dec() Date: Fri, 29 Mar 2019 17:08:53 -0700 Message-Id: <20190330000854.30142-3-jakub.kicinski@netronome.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190330000854.30142-1-jakub.kicinski@netronome.com> References: <20190330000854.30142-1-jakub.kicinski@netronome.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org static_key_slow_dec() checks if the atomic enable count is larger than 1, and if so there decrements it before taking the jump_label_lock. Move this logic into a helper for reuse in rate limitted keys. Signed-off-by: Jakub Kicinski Reviewed-by: Simon Horman --- kernel/jump_label.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/kernel/jump_label.c b/kernel/jump_label.c index 73bbbaddbd9c..02c3d11264dd 100644 --- a/kernel/jump_label.c +++ b/kernel/jump_label.c @@ -202,13 +202,13 @@ void static_key_disable(struct static_key *key) } EXPORT_SYMBOL_GPL(static_key_disable); -static void __static_key_slow_dec_cpuslocked(struct static_key *key, - unsigned long rate_limit, - struct delayed_work *work) +static bool static_key_slow_try_dec(struct static_key *key) { int val; - lockdep_assert_cpus_held(); + val = atomic_fetch_add_unless(&key->enabled, -1, 1); + if (val == 1) + return false; /* * The negative count check is valid even when a negative @@ -217,11 +217,18 @@ static void __static_key_slow_dec_cpuslocked(struct static_key *key, * returns is unbalanced, because all other static_key_slow_inc() * instances block while the update is in progress. */ - val = atomic_fetch_add_unless(&key->enabled, -1, 1); - if (val != 1) { - WARN(val < 0, "jump label: negative count!\n"); + WARN(val < 0, "jump label: negative count!\n"); + return true; +} + +static void __static_key_slow_dec_cpuslocked(struct static_key *key, + unsigned long rate_limit, + struct delayed_work *work) +{ + lockdep_assert_cpus_held(); + + if (static_key_slow_try_dec(key)) return; - } jump_label_lock(); if (atomic_dec_and_test(&key->enabled)) { -- 2.21.0