]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
locking/static_keys: Add static_key_{en,dis}able() helpers
authorPeter Zijlstra <peterz@infradead.org>
Fri, 24 Jul 2015 13:03:40 +0000 (15:03 +0200)
committerJiri Slaby <jslaby@suse.cz>
Tue, 28 Mar 2017 13:49:18 +0000 (15:49 +0200)
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>
include/linux/jump_label.h
kernel/sched/core.c

index 9216e465289a2394c05981ab5285cf3dad8b0b81..6fdea8105f4559132fabe53136317da775d07a5c 100644 (file)
@@ -188,4 +188,20 @@ 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);
+
+       if (!count)
+               static_key_slow_inc(key);
+}
+
+static inline void static_key_disable(struct static_key *key)
+{
+       int count = static_key_count(key);
+
+       if (count)
+               static_key_slow_dec(key);
+}
+
 #endif /* _LINUX_JUMP_LABEL_H */
index 426193802b1feddd03730e75ea48b84e23d40bdb..602b6c08c47d217972d9583d1a37be0b6b0f69f2 100644 (file)
@@ -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) { };