Skip to content

Commit

Permalink
locking/static_keys: Add static_key_{en,dis}able() helpers
Browse files Browse the repository at this point in the history
Add two helpers to make it easier to treat the refcount as boolean.

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>
  • Loading branch information
Peter Zijlstra authored and Ingo Molnar committed Aug 3, 2015
1 parent 7dcfd91 commit e33886b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
20 changes: 20 additions & 0 deletions include/linux/jump_label.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,26 @@ static inline bool static_key_enabled(struct static_key *key)
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 /* __ASSEMBLY__ */
6 changes: 2 additions & 4 deletions kernel/sched/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,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) { };
Expand Down

0 comments on commit e33886b

Please sign in to comment.