Skip to content

Commit

Permalink
locking/static_key: Factor out the fast path of static_key_slow_dec()
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
Reviewed-by: Simon Horman <[email protected]>
Cc: Andrew Morton <[email protected]>
Cc: Linus Torvalds <[email protected]>
Cc: Paul E. McKenney <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Will Deacon <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Link: https://lkml.kernel.org/r/[email protected]
Signed-off-by: Ingo Molnar <[email protected]>
  • Loading branch information
Jakub Kicinski authored and Ingo Molnar committed Apr 29, 2019
1 parent ad282a8 commit b92e793
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions kernel/jump_label.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)) {
Expand Down

0 comments on commit b92e793

Please sign in to comment.