From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1761393AbcIWQtm (ORCPT ); Fri, 23 Sep 2016 12:49:42 -0400 Received: from albert.ini-tech.com ([192.99.4.57]:47114 "EHLO smtp.ini-tech.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1761342AbcIWQti (ORCPT ); Fri, 23 Sep 2016 12:49:38 -0400 From: Julien Desfossez To: peterz@infradead.org, tglx@linutronix.de, rostedt@goodmis.org, mingo@redhat.com, daolivei@redhat.com Cc: mathieu.desnoyers@efficios.com, linux-kernel@vger.kernel.org, Julien Desfossez Subject: [RFC PATCH v2 1/5] sched: get effective policy and rt_prio Date: Fri, 23 Sep 2016 12:49:31 -0400 Message-Id: <1474649375-28056-2-git-send-email-jdesfossez@efficios.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1474649375-28056-1-git-send-email-jdesfossez@efficios.com> References: <1474649375-28056-1-git-send-email-jdesfossez@efficios.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Helper functions to get the effective policy and rt_priority from the prio and policy values. This is useful in PI situations because these fields are not updated in the task, only the sched_class is temporarily modified. Cc: Peter Zijlstra Cc: Steven Rostedt (Red Hat) Cc: Thomas Gleixner Cc: Ingo Molnar Reviewed-by: Mathieu Desnoyers Signed-off-by: Julien Desfossez --- include/linux/sched.h | 2 ++ kernel/sched/core.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/include/linux/sched.h b/include/linux/sched.h index af39baf..0c03595 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -2594,6 +2594,8 @@ static inline bool is_idle_task(const struct task_struct *p) struct thread_info thread_info; unsigned long stack[THREAD_SIZE/sizeof(long)]; }; +extern int effective_policy(int policy, int prio); +extern int effective_rt_prio(int prio); #ifndef __HAVE_ARCH_KSTACK_END static inline int kstack_end(void *addr) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index f5f7b3c..f3817b5 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -916,6 +916,42 @@ static int effective_prio(struct task_struct *p) return p->prio; } +/* + * Get the effective policy based on the current prio value. + */ +int effective_policy(int policy, int prio) +{ + if (dl_prio(prio)) + return SCHED_DEADLINE; + + /* With RT, the default class is SCHED_FIFO. */ + if (rt_prio(prio)) { + if (policy == SCHED_RR) + return SCHED_RR; + return SCHED_FIFO; + } + + /* With fair, the default class is SCHED_NORMAL. */ + switch (policy) { + case SCHED_NORMAL: + case SCHED_IDLE: + case SCHED_BATCH: + return policy; + } + return SCHED_NORMAL; +} + +/* + * Get the effective rt priority based on the current prio value. + */ +int effective_rt_prio(int prio) +{ + if (!rt_prio(prio)) + return 0; + + return MAX_RT_PRIO - 1 - prio; +} + /** * task_curr - is this task currently executing on a CPU? * @p: the task in question. -- 1.9.1