mirror of
https://github.com/FEX-Emu/linux.git
synced 2025-01-10 03:20:49 +00:00
locking/static_key: Factor out the fast path of static_key_slow_dec()
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> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Simon Horman <simon.horman@netronome.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Will Deacon <will.deacon@arm.com> Cc: alexei.starovoitov@gmail.com Cc: ard.biesheuvel@linaro.org Cc: oss-drivers@netronome.com Cc: yamada.masahiro@socionext.com Link: https://lkml.kernel.org/r/20190330000854.30142-3-jakub.kicinski@netronome.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
This commit is contained in:
parent
ad282a8117
commit
b92e793bbe
@ -202,13 +202,13 @@ void static_key_disable(struct static_key *key)
|
|||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(static_key_disable);
|
EXPORT_SYMBOL_GPL(static_key_disable);
|
||||||
|
|
||||||
static void __static_key_slow_dec_cpuslocked(struct static_key *key,
|
static bool static_key_slow_try_dec(struct static_key *key)
|
||||||
unsigned long rate_limit,
|
|
||||||
struct delayed_work *work)
|
|
||||||
{
|
{
|
||||||
int val;
|
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
|
* The negative count check is valid even when a negative
|
||||||
@ -217,12 +217,19 @@ static void __static_key_slow_dec_cpuslocked(struct static_key *key,
|
|||||||
* returns is unbalanced, because all other static_key_slow_inc()
|
* returns is unbalanced, because all other static_key_slow_inc()
|
||||||
* instances block while the update is in progress.
|
* 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;
|
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();
|
jump_label_lock();
|
||||||
if (atomic_dec_and_test(&key->enabled)) {
|
if (atomic_dec_and_test(&key->enabled)) {
|
||||||
if (rate_limit) {
|
if (rate_limit) {
|
||||||
|
Loading…
Reference in New Issue
Block a user