sched: Fix rt_task to work properly
PATCH 1/1 sched: Fix rt_task to work properly
Hi,
I am a graduate student of System Software Lab. at Konkuk University
We found that the rt_task() function returns true even if the task is a deadline task scheduled by SCHED_DEADLINE, because the function simply checks whether the priority of the task is smaller than 100. As the priority of deadline tasks is smaller than 0, the rt_task() function returns true for deadline tasks. However, there exists a separate function (i.e., dl_task()) to check if a task is a deadline task. That is, we believe that rt_task() has to return true only if the task is an rt task scheduled by SCHED_FIFO or SCHED_RR, while giving false for deadline tasks.
This ambiguity of rt_task() is causing a strange problem in cgroup. More precisely, we found that -EBUSY was always returned when we tried to run a task group that consisted of rt tasks together with a deadline task. This happened regardless of how much CPU resources were reserved by cgroups and
deadline tasks. It turns out that tg_rt_schedulable() returns ?EBUSY by the following conditional statement for deadline tasks:
if (rt_bandwidth_enabled() && !runtime && tg_has_rt_tasks(tg)) return -EBUSY;
For deadline tasks, tg_has_rt_tasks() in the above statement has to return false. However, the current implementation of rt_task() called by tg_has_rt_tasks() only checks whether the priority of tasks are smaller than 100; thus, it returns true even for deadline tasks that have a minus number.
Our patch is to fix this problem by checking the priority of tasks more precisely (i.e., 0 < priority < 100) in rt_task().
---
include/linux/sched/deadline.h | 8 +------- include/linux/sched/prio.h | 8 ++++++++ include/linux/sched/rt.h | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-)
include/linux/sched/deadline.h +0 -0
@@ -1,13 +1,7 @@
#ifndef _SCHED_DEADLINE_H
#define _SCHED_DEADLINE_H
-/*
- * SCHED_DEADLINE tasks has negative priorities, reflecting
- * the fact that any of them has higher prio than RT and
- * NORMAL/BATCH tasks.
- */
-
-#define MAX_DL_PRIO 0
+#include <linux/sched/prio.h>
static inline int dl_prio(int prio)
{
include/linux/sched/prio.h +0 -0
@@ -25,6 +25,14 @@
#define DEFAULT_PRIO (MAX_RT_PRIO + NICE_WIDTH / 2)
/*
+ * SCHED_DEADLINE tasks has negative priorities, reflecting
+ * the fact that any of them has higher prio than RT and
+ * NORMAL/BATCH tasks.
+ */
+
+#define MAX_DL_PRIO 0
+
+/*
* Convert user-nice values [ -20 ... 0 ... 19 ]
* to static priority [ MAX_RT_PRIO..MAX_PRIO-1 ],
* and back.
include/linux/sched/rt.h +0 -0
@@ -5,7 +5,7 @@
static inline int rt_prio(int prio)
{
- if (unlikely(prio < MAX_RT_PRIO))
+ if (unlikely(prio < MAX_RT_PRIO && prio > MAX_DL_PRIO)) return 1;
return 0;
}