Commit 12f1a0f9 authored by Peter Zijlstra's avatar Peter Zijlstra Committed by Willy Tarreau

locking/static_keys: Add static_key_{en,dis}able() helpers

commit e33886b3 upstream.

Add two helpers to make it easier to treat the refcount as boolean.

[js] do not involve WARN_ON_ONCE as it causes build failures
Suggested-by: default avatarJason Baron <jasonbaron0@gmail.com>
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
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: linux-kernel@vger.kernel.org
Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
Signed-off-by: default avatarJiri Slaby <jslaby@suse.cz>
[wt: only backported for use in next fix ;
     s/static_key_count(key)/atomic_read(&key->enabled)/]
Signed-off-by: default avatarWilly Tarreau <w@1wt.eu>
parent 7c72e851
......@@ -208,4 +208,20 @@ static inline bool static_key_enabled(struct static_key *key)
return (atomic_read(&key->enabled) > 0);
}
static inline void static_key_enable(struct static_key *key)
{
int count = atomic_read(&key->enabled);
if (!count)
static_key_slow_inc(key);
}
static inline void static_key_disable(struct static_key *key)
{
int count = atomic_read(&key->enabled);
if (count)
static_key_slow_dec(key);
}
#endif /* _LINUX_JUMP_LABEL_H */
......@@ -179,14 +179,12 @@ struct static_key sched_feat_keys[__SCHED_FEAT_NR] = {
static void sched_feat_disable(int i)
{
if (static_key_enabled(&sched_feat_keys[i]))
static_key_slow_dec(&sched_feat_keys[i]);
static_key_disable(&sched_feat_keys[i]);
}
static void sched_feat_enable(int i)
{
if (!static_key_enabled(&sched_feat_keys[i]))
static_key_slow_inc(&sched_feat_keys[i]);
static_key_enable(&sched_feat_keys[i]);
}
#else
static void sched_feat_disable(int i) { };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment