提交 e33886b3 编写于 作者: P Peter Zijlstra 提交者: Ingo Molnar

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

Add two helpers to make it easier to treat the refcount as boolean.
Suggested-by: NJason Baron <jasonbaron0@gmail.com>
Signed-off-by: NPeter 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: NIngo Molnar <mingo@kernel.org>
上级 7dcfd915
...@@ -198,6 +198,26 @@ static inline bool static_key_enabled(struct static_key *key) ...@@ -198,6 +198,26 @@ static inline bool static_key_enabled(struct static_key *key)
return static_key_count(key) > 0; return static_key_count(key) > 0;
} }
static inline void static_key_enable(struct static_key *key)
{
int count = static_key_count(key);
WARN_ON_ONCE(count < 0 || count > 1);
if (!count)
static_key_slow_inc(key);
}
static inline void static_key_disable(struct static_key *key)
{
int count = static_key_count(key);
WARN_ON_ONCE(count < 0 || count > 1);
if (count)
static_key_slow_dec(key);
}
#endif /* _LINUX_JUMP_LABEL_H */ #endif /* _LINUX_JUMP_LABEL_H */
#endif /* __ASSEMBLY__ */ #endif /* __ASSEMBLY__ */
...@@ -164,14 +164,12 @@ struct static_key sched_feat_keys[__SCHED_FEAT_NR] = { ...@@ -164,14 +164,12 @@ struct static_key sched_feat_keys[__SCHED_FEAT_NR] = {
static void sched_feat_disable(int i) static void sched_feat_disable(int i)
{ {
if (static_key_enabled(&sched_feat_keys[i])) static_key_disable(&sched_feat_keys[i]);
static_key_slow_dec(&sched_feat_keys[i]);
} }
static void sched_feat_enable(int i) static void sched_feat_enable(int i)
{ {
if (!static_key_enabled(&sched_feat_keys[i])) static_key_enable(&sched_feat_keys[i]);
static_key_slow_inc(&sched_feat_keys[i]);
} }
#else #else
static void sched_feat_disable(int i) { }; static void sched_feat_disable(int i) { };
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册