Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752227AbdDJQM6 (ORCPT ); Mon, 10 Apr 2017 12:12:58 -0400 Received: from mx2.suse.de ([195.135.220.15]:37766 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754111AbdDJPd7 (ORCPT ); Mon, 10 Apr 2017 11:33:59 -0400 X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" From: Jiri Slaby To: stable@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Andrew Morton , Linus Torvalds , "Paul E . McKenney" , Thomas Gleixner , Ingo Molnar , Jiri Slaby Subject: [PATCH 3.12 024/142] locking/static_keys: Add static_key_{en,dis}able() helpers Date: Mon, 10 Apr 2017 17:31:45 +0200 Message-Id: <7511dee587205498e3d71234ee89ce9c81ae17e9.1491838390.git.jslaby@suse.cz> X-Mailer: git-send-email 2.12.2 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2225 Lines: 75 From: Peter Zijlstra 3.12-stable review patch. If anyone has any objections, please let me know. =============== 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 Signed-off-by: Peter Zijlstra (Intel) Cc: Andrew Morton Cc: Linus Torvalds Cc: Paul E. McKenney Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: linux-kernel@vger.kernel.org Signed-off-by: Ingo Molnar Signed-off-by: Jiri Slaby --- include/linux/jump_label.h | 16 ++++++++++++++++ kernel/sched/core.c | 6 ++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/include/linux/jump_label.h b/include/linux/jump_label.h index 9216e465289a..6fdea8105f45 100644 --- a/include/linux/jump_label.h +++ b/include/linux/jump_label.h @@ -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 */ diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 426193802b1f..602b6c08c47d 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -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) { }; -- 2.12.2