[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1474649375-28056-2-git-send-email-jdesfossez@efficios.com>
Date: Fri, 23 Sep 2016 12:49:31 -0400
From: Julien Desfossez <jdesfossez@...icios.com>
To: peterz@...radead.org, tglx@...utronix.de, rostedt@...dmis.org,
mingo@...hat.com, daolivei@...hat.com
Cc: mathieu.desnoyers@...icios.com, linux-kernel@...r.kernel.org,
Julien Desfossez <jdesfossez@...icios.com>
Subject: [RFC PATCH v2 1/5] sched: get effective policy and rt_prio
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 <peterz@...radead.org>
Cc: Steven Rostedt (Red Hat) <rostedt@...dmis.org>
Cc: Thomas Gleixner <tglx@...utronix.de>
Cc: Ingo Molnar <mingo@...hat.com>
Reviewed-by: Mathieu Desnoyers <mathieu.desnoyers@...icios.com>
Signed-off-by: Julien Desfossez <jdesfossez@...icios.com>
---
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
Powered by blists - more mailing lists