aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Zijlstra <peterz@infradead.org>2015-07-24 09:03:40 -0400
committerIngo Molnar <mingo@kernel.org>2015-08-03 05:34:14 -0400
commite33886b38cc82a9fc3b2d655dfc7f50467594138 (patch)
treef28d2cdfd09a3220231ffaf085abfad85d92f45a
parent7dcfd915bae51571bcc339d8e3dda027287880e5 (diff)
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: 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>
-rw-r--r--include/linux/jump_label.h20
-rw-r--r--kernel/sched/core.c6
2 files changed, 22 insertions, 4 deletions
diff --git a/include/linux/jump_label.h b/include/linux/jump_label.h
index 0ddb208b8449..65f0ebac63cf 100644
--- a/include/linux/jump_label.h
+++ b/include/linux/jump_label.h
@@ -198,6 +198,26 @@ static inline bool static_key_enabled(struct static_key *key)
198 return static_key_count(key) > 0; 198 return static_key_count(key) > 0;
199} 199}
200 200
201static inline void static_key_enable(struct static_key *key)
202{
203 int count = static_key_count(key);
204
205 WARN_ON_ONCE(count < 0 || count > 1);
206
207 if (!count)
208 static_key_slow_inc(key);
209}
210
211static inline void static_key_disable(struct static_key *key)
212{
213 int count = static_key_count(key);
214
215 WARN_ON_ONCE(count < 0 || count > 1);
216
217 if (count)
218 static_key_slow_dec(key);
219}
220
201#endif /* _LINUX_JUMP_LABEL_H */ 221#endif /* _LINUX_JUMP_LABEL_H */
202 222
203#endif /* __ASSEMBLY__ */ 223#endif /* __ASSEMBLY__ */
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 78b4bad10081..66ae8baf42fe 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -164,14 +164,12 @@ struct static_key sched_feat_keys[__SCHED_FEAT_NR] = {
164 164
165static void sched_feat_disable(int i) 165static void sched_feat_disable(int i)
166{ 166{
167 if (static_key_enabled(&sched_feat_keys[i])) 167 static_key_disable(&sched_feat_keys[i]);
168 static_key_slow_dec(&sched_feat_keys[i]);
169} 168}
170 169
171static void sched_feat_enable(int i) 170static void sched_feat_enable(int i)
172{ 171{
173 if (!static_key_enabled(&sched_feat_keys[i])) 172 static_key_enable(&sched_feat_keys[i]);
174 static_key_slow_inc(&sched_feat_keys[i]);
175} 173}
176#else 174#else
177static void sched_feat_disable(int i) { }; 175static void sched_feat_disable(int i) { };