linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jakub Kicinski <jakub.kicinski@netronome.com>
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 <jakub.kicinski@netronome.com>,
	Simon Horman <simon.horman@netronome.com>
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	[thread overview]
Message-ID: <20190330000854.30142-3-jakub.kicinski@netronome.com> (raw)
In-Reply-To: <20190330000854.30142-1-jakub.kicinski@netronome.com>

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 <jakub.kicinski@netronome.com>
Reviewed-by: Simon Horman <simon.horman@netronome.com>
---
 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


  parent reply	other threads:[~2019-03-30  0:09 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-30  0:08 [PATCH 0/3] locking/static_key: improve rate limited labels Jakub Kicinski
2019-03-30  0:08 ` [PATCH 1/3] locking/static_key: add support for deferred static branches Jakub Kicinski
2019-04-29  6:40   ` [tip:locking/core] locking/static_key: Add " tip-bot for Jakub Kicinski
2019-03-30  0:08 ` Jakub Kicinski [this message]
2019-04-29  6:41   ` [tip:locking/core] locking/static_key: Factor out the fast path of static_key_slow_dec() tip-bot for Jakub Kicinski
2019-03-30  0:08 ` [PATCH 3/3] locking/static_key: don't take sleeping locks in __static_key_slow_dec_deferred() Jakub Kicinski
2019-04-29  6:41   ` [tip:locking/core] locking/static_key: Don't " tip-bot for Jakub Kicinski
2019-04-01 18:21 ` [PATCH 0/3] locking/static_key: improve rate limited labels Jakub Kicinski
2019-04-02  7:03   ` Peter Zijlstra
2019-04-04 10:29   ` Peter Zijlstra
2019-04-16 16:33     ` Jakub Kicinski
2019-04-16 17:38       ` Peter Zijlstra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190330000854.30142-3-jakub.kicinski@netronome.com \
    --to=jakub.kicinski@netronome.com \
    --cc=alexei.starovoitov@gmail.com \
    --cc=ard.biesheuvel@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=oss-drivers@netronome.com \
    --cc=peterz@infradead.org \
    --cc=simon.horman@netronome.com \
    --cc=tglx@linutronix.de \
    --cc=yamada.masahiro@socionext.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).