sched: get effective policy and rt_prio
authorJulien Desfossez <jdesfossez@efficios.com>
Fri, 16 Sep 2016 19:22:17 +0000 (15:22 -0400)
committerJulien Desfossez <jdesfossez@efficios.com>
Fri, 16 Sep 2016 21:01:58 +0000 (17:01 -0400)
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@infradead.org>
Cc: Steven Rostedt (Red Hat) <rostedt@goodmis.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Julien Desfossez <jdesfossez@efficios.com>
include/linux/sched/rt.h
kernel/locking/rtmutex.c

index a30b172df6e1a760905f83c2136ac35f4611320f..42b37ce434021c29dd1b712c35842950762fa59d 100644 (file)
@@ -25,6 +25,8 @@ static inline bool tsk_is_pi_blocked(struct task_struct *tsk)
 {
        return tsk->pi_blocked_on != NULL;
 }
+extern int rt_mutex_get_effective_policy(int policy, int prio);
+extern int rt_mutex_get_effective_rt_prio(int prio);
 #else
 static inline int rt_mutex_getprio(struct task_struct *p)
 {
@@ -46,6 +48,14 @@ static inline bool tsk_is_pi_blocked(struct task_struct *tsk)
 {
        return false;
 }
+static inline int rt_mutex_get_effective_policy(int policy, int prio);
+{
+       return policy;
+}
+static inline int rt_mutex_get_effective_rt_prio(int prio)
+{
+       return task->rt_priority;
+}
 #endif
 
 extern void normalize_rt_tasks(void);
index 1ec0f48962b33dce424d4d3f491c6a1fd76ba13d..b66954f7595374cc4d9ba7dc848ead39df957b97 100644 (file)
@@ -293,6 +293,42 @@ int rt_mutex_get_effective_prio(struct task_struct *task, int newprio)
        return newprio;
 }
 
+/*
+ * Get the effective policy based on the current prio value.
+ */
+int rt_mutex_get_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 rt_mutex_get_effective_rt_prio(int prio)
+{
+       if (!rt_prio(prio))
+               return 0;
+
+       return MAX_RT_PRIO - 1 - prio;
+}
+
 /*
  * Adjust the priority of a task, after its pi_waiters got modified.
  *
This page took 0.026024 seconds and 5 git commands to generate.