From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753034AbbIRIst (ORCPT ); Fri, 18 Sep 2015 04:48:49 -0400 Received: from terminus.zytor.com ([198.137.202.10]:44713 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752986AbbIRIsp (ORCPT ); Fri, 18 Sep 2015 04:48:45 -0400 Date: Fri, 18 Sep 2015 01:48:10 -0700 From: tip-bot for Henrik Austad Message-ID: Cc: henrik@austad.us, linux-kernel@vger.kernel.org, hpa@zytor.com, peterz@infradead.org, mingo@kernel.org, tglx@linutronix.de, torvalds@linux-foundation.org Reply-To: hpa@zytor.com, peterz@infradead.org, linux-kernel@vger.kernel.org, henrik@austad.us, torvalds@linux-foundation.org, tglx@linutronix.de, mingo@kernel.org In-Reply-To: <1441810841-4756-1-git-send-email-henrik@austad.us> References: <1441810841-4756-1-git-send-email-henrik@austad.us> To: linux-tip-commits@vger.kernel.org Subject: [tip:sched/core] sched/core: Make policy-testing consistent Git-Commit-ID: 20f9cd2acb1d74a8bf4b4087267f586e6ecdbc03 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 20f9cd2acb1d74a8bf4b4087267f586e6ecdbc03 Gitweb: http://git.kernel.org/tip/20f9cd2acb1d74a8bf4b4087267f586e6ecdbc03 Author: Henrik Austad AuthorDate: Wed, 9 Sep 2015 17:00:41 +0200 Committer: Ingo Molnar CommitDate: Fri, 18 Sep 2015 09:23:13 +0200 sched/core: Make policy-testing consistent Most of the policy-tests are done via the _policy() helpers with the notable exception of idle. A new wrapper for valid_policy() has also been added to improve readability in set_load_weight(). This commit does not change the logical behavior of the scheduler core. Signed-off-by: Henrik Austad Signed-off-by: Peter Zijlstra (Intel) Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: linux-kernel@vger.kernel.org Link: http://lkml.kernel.org/r/1441810841-4756-1-git-send-email-henrik@austad.us Signed-off-by: Ingo Molnar --- kernel/sched/core.c | 9 +++------ kernel/sched/sched.h | 9 +++++++++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 6ab415a..1b30b5b 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -817,7 +817,7 @@ static void set_load_weight(struct task_struct *p) /* * SCHED_IDLE tasks get minimal weight: */ - if (p->policy == SCHED_IDLE) { + if (idle_policy(p->policy)) { load->weight = scale_load(WEIGHT_IDLEPRIO); load->inv_weight = WMULT_IDLEPRIO; return; @@ -3733,10 +3733,7 @@ recheck: } else { reset_on_fork = !!(attr->sched_flags & SCHED_FLAG_RESET_ON_FORK); - if (policy != SCHED_DEADLINE && - policy != SCHED_FIFO && policy != SCHED_RR && - policy != SCHED_NORMAL && policy != SCHED_BATCH && - policy != SCHED_IDLE) + if (!valid_policy(policy)) return -EINVAL; } @@ -3792,7 +3789,7 @@ recheck: * Treat SCHED_IDLE as nice 20. Only allow a switch to * SCHED_NORMAL if the RLIMIT_NICE would normally permit it. */ - if (p->policy == SCHED_IDLE && policy != SCHED_IDLE) { + if (idle_policy(p->policy) && !idle_policy(policy)) { if (!can_nice(p, task_nice(p))) return -EPERM; } diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index 167ab48..3845a71 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -84,6 +84,10 @@ static inline void update_cpu_load_active(struct rq *this_rq) { } */ #define RUNTIME_INF ((u64)~0ULL) +static inline int idle_policy(int policy) +{ + return policy == SCHED_IDLE; +} static inline int fair_policy(int policy) { return policy == SCHED_NORMAL || policy == SCHED_BATCH; @@ -98,6 +102,11 @@ static inline int dl_policy(int policy) { return policy == SCHED_DEADLINE; } +static inline bool valid_policy(int policy) +{ + return idle_policy(policy) || fair_policy(policy) || + rt_policy(policy) || dl_policy(policy); +} static inline int task_has_rt_policy(struct task_struct *p) {