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

commit e33886b38cc82a9fc3b2d655dfc7f50467594138 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: Jason Baron <jasonbaron0@gmail.com>
Signed-off-by: Peter 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: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
[wt: only backported for use in next fix ;
     s/static_key_count(key)/atomic_read(&key->enabled)/]

Signed-off-by: Willy Tarreau <w@1wt.eu>
This commit is contained in:
Peter Zijlstra 2015-07-24 15:03:40 +02:00 committed by syphyr
parent ac94c9a4cb
commit 6ec33b5e8f
2 changed files with 18 additions and 4 deletions

View File

@ -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 */

View File

@ -281,14 +281,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) { };