sched: don't allow rt_runtime_us to be zero for groups having rt tasks
PATCH 1/1 sched: don't allow rt_runtime_us to be zero for groups having rt tasks
This patch checks if we can set the rt_runtime_us to 0. If there is a realtime task in the group, we don't want to set the rt_runtime_us to 0 otherwise bad things will happen.
--- kernel/sched.c | 19 +++++++++++++++++++ 1 files changed, 19 insertions(+)
kernel/sched.c +19 -0
@@ -7960,6 +7960,17 @@ static int __rt_schedulable(struct task_return total +to_ratio (period, runtime) < global_ratio; } +/* Must be called with tasklist_lock held */ +static inline int tg_has_rt_tasks (struct task_group *tg) +{ +struct task_struct *p; +for_each_process (p) { +if (rt_task (p) &&rt_rq_of_se (&p->rt)->tg == tg) +return 1 ; + } +return 0 ; +} +int sched_group_set_rt_runtime (struct task_group *tg,long rt_runtime_us) {u64 rt_runtime, rt_period;
@@ -7971,6 +7982,13 @@ int sched_group_set_rt_runtime(struct ta rt_runtime = rt_period;mutex_lock (&rt_constraints_mutex); +read_lock (&tasklist_lock); +if (rt_runtime_us ==0 ) { +if (tg_has_rt_tasks (tg)) { + err = -EINVAL ; + goto unlock; + } + }if (!__rt_schedulable (tg, rt_period, rt_runtime)) { err = -EINVAL ; goto unlock;
@@ -7979,6 +7997,7 @@ int sched_group_set_rt_runtime(struct ta rt_runtime =RUNTIME_INF ; tg->rt_runtime = rt_runtime; unlock: +read_unlock (&tasklist_lock);mutex_unlock (&rt_constraints_mutex);return err;
Signature · 2 lines
regards, Dhaval
Quoted 3 lines · Dhaval Giani
This patch checks if we can set the
rt_runtime_usto 0. If there is a realtime task in the group, we don't want to set thert_runtime_usto 0 otherwise bad things will happen.
I had considered this a: don't do that then, thing. But sure, helping the admin seems like a valid option.
Quoted 28 lines
Signed-off-by Dhaval Giani <[email protected]>--- kernel/sched.c | 19 +++++++++++++++++++ 1 files changed, 19 insertions(+)Index:
linux-2.6.25-rc3/kernel/sched.c
===================================================================kernel/sched.c +11
-0@@ -7960,6 +7960,17 @@ static int __rt_schedulable(struct task_return total +to_ratio (period, runtime) < global_ratio; } +/* Must be called with tasklist_lock held */ +static inline int tg_has_rt_tasks (struct task_group *tg) +{ +struct task_struct *p; +for_each_process (p) { +if (rt_task (p) &&rt_rq_of_se (&p->rt)->tg == tg) +return 1 ; + } +return 0 ; +} +int sched_group_set_rt_runtime (struct task_group *tg,long rt_runtime_us) {u64 rt_runtime, rt_period;
kernel/sched.c int sched_group_set_rt_runtime(struct ta · line 7987
Quoted 6 lines
kernel/sched.c +3
-0@@ -7971,6 +7982,13 @@ int sched_group_set_rt_runtime(struct ta rt_runtime = rt_period;mutex_lock (&rt_constraints_mutex); +read_lock (&tasklist_lock); +if (rt_runtime_us ==0 ) { +if (tg_has_rt_tasks (tg)) {
&&
kernel/sched.c int sched_group_set_rt_runtime(struct ta · line 7988
Quoted 1 line
kernel/sched.c +1
-0+ err = -EINVAL ;
-EBUSY perhaps?
Quoted 14 lines
kernel/sched.c +4
-0+ goto unlock; + } + }if (!__rt_schedulable (tg, rt_period, rt_runtime)) { err = -EINVAL ; goto unlock;@@ -7979,6 +7997,7 @@ int sched_group_set_rt_runtime(struct ta rt_runtime =RUNTIME_INF ; tg->rt_runtime = rt_runtime; unlock: +read_unlock (&tasklist_lock);mutex_unlock (&rt_constraints_mutex);return err;
Quoted 9 lines · Peter Zijlstra
Quoted 3 lines · Dhaval Giani
This patch checks if we can set the
rt_runtime_usto 0. If there is a realtime task in the group, we don't want to set thert_runtime_usto 0 otherwise bad things will happen.I had considered this a: don't do that then, thing. But sure, helping the admin seems like a valid option.
Well, if it can be done, it shall be done :)
<snip>
Quoted 5 lines
Review
Quoted 2 lines
(quoted diff) +1
-0+ err = -EINVAL;
-EBUSYperhaps?
Well, the group is certainly not busy. I will go with invalid as it is definitly an invalid value when the groups have rt tasks. But if someone disagrees, I have no issue with it being something else.
Corrected patch as follows,
--
This patch checks if we can set the rt_runtime_us to 0. If there is a realtime task in the group, we don't want to set the rt_runtime_us as 0 or bad things will happen.
--- kernel/sched.c | 17 +++++++++++++++++ 1 files changed, 17 insertions(+)
kernel/sched.c +17 -0
@@ -7960,6 +7960,17 @@ static int __rt_schedulable(struct task_return total +to_ratio (period, runtime) < global_ratio; } +/* Must be called with tasklist_lock held */ +static inline int tg_has_rt_tasks (struct task_group *tg) +{ +struct task_struct *p; +for_each_process (p) { +if (rt_task (p) &&rt_rq_of_se (&p->rt)->tg == tg) +return 1 ; + } +return 0 ; +} +int sched_group_set_rt_runtime (struct task_group *tg,long rt_runtime_us) {u64 rt_runtime, rt_period;
@@ -7971,6 +7982,11 @@ int sched_group_set_rt_runtime(struct ta rt_runtime = rt_period;mutex_lock (&rt_constraints_mutex); +read_lock (&tasklist_lock); +if (rt_runtime_us ==0 &&tg_has_rt_tasks (tg)) { + err = -EINVAL ; + goto unlock; + }if (!__rt_schedulable (tg, rt_period, rt_runtime)) { err = -EINVAL ; goto unlock;
@@ -7979,6 +7995,7 @@ int sched_group_set_rt_runtime(struct ta rt_runtime =RUNTIME_INF ; tg->rt_runtime = rt_runtime; unlock: +read_unlock (&tasklist_lock);mutex_unlock (&rt_constraints_mutex);return err;
Signature · 2 lines
regards, Dhaval
Quoted 1 line · Dhaval Giani
Well, if it can be done, it shall be done :)
May I suggest: rm -rf /
/me runs
Peter Zijlstra
Acked-byQuoted 5 lines · Dhaval Giani
This patch checks if we can set the
rt_runtime_usto 0. If there is a realtime task in the group, we don't want to set thert_runtime_usas 0 or bad things will happen.Signed-off-by Dhaval Giani <[email protected]>
Quoted 46 lines
--- kernel/sched.c | 17 +++++++++++++++++ 1 files changed, 17 insertions(+)Index:
linux-2.6.25-rc3/kernel/sched.c
===================================================================kernel/sched.c +17
-0@@ -7960,6 +7960,17 @@ static int __rt_schedulable(struct task_return total +to_ratio (period, runtime) < global_ratio; } +/* Must be called with tasklist_lock held */ +static inline int tg_has_rt_tasks (struct task_group *tg) +{ +struct task_struct *p; +for_each_process (p) { +if (rt_task (p) &&rt_rq_of_se (&p->rt)->tg == tg) +return 1 ; + } +return 0 ; +} +int sched_group_set_rt_runtime (struct task_group *tg,long rt_runtime_us) {u64 rt_runtime, rt_period;@@ -7971,6 +7982,11 @@ int sched_group_set_rt_runtime(struct ta rt_runtime = rt_period;mutex_lock (&rt_constraints_mutex); +read_lock (&tasklist_lock); +if (rt_runtime_us ==0 &&tg_has_rt_tasks (tg)) { + err = -EINVAL ; + goto unlock; + }if (!__rt_schedulable (tg, rt_period, rt_runtime)) { err = -EINVAL ; goto unlock;@@ -7979,6 +7995,7 @@ int sched_group_set_rt_runtime(struct ta rt_runtime =RUNTIME_INF ; tg->rt_runtime = rt_runtime; unlock: +read_unlock (&tasklist_lock);mutex_unlock (&rt_constraints_mutex);return err;
Quoted 10 lines · Peter Zijlstra
Quoted 5 lines · Dhaval Giani
This patch checks if we can set the
rt_runtime_usto 0. If there is a realtime task in the group, we don't want to set thert_runtime_usas 0 or bad things will happen.Signed-off-by Dhaval Giani <[email protected]>Acked-by Peter Zijlstra <[email protected]>
doesnt apply to sched-devel.git - what's the plan here?
Ingo
Quoted 9 lines · Ingo Molnar
Quoted 7 lines · Peter Zijlstra
Quoted 4 lines · Dhaval Giani
This patch checks if we can set the
rt_runtime_usto 0. If there is a realtime task in the group, we don't want to set thert_runtime_usas 0 or bad things will happen.
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
Signed-off-by Dhaval Giani <[email protected]>Acked-by Peter Zijlstra <[email protected]>doesnt apply to sched-devel.git - what's the plan here?
stick in front, drop the other two sched-rt-group patches for which I'll send you an update somewhere today.
These two patches would be candidates to push to linus..
Quoted 10 lines · Ingo Molnar
Quoted 7 lines · Peter Zijlstra
Quoted 4 lines · Dhaval Giani
This patch checks if we can set the
rt_runtime_usto 0. If there is a realtime task in the group, we don't want to set thert_runtime_usas 0 or bad things will happen.
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Signed-off-by Dhaval Giani <[email protected]>Acked-by Peter Zijlstra <[email protected]>doesnt apply to sched-devel.git - what's the plan here?
Belongs to mainline.
Signature · 2 lines
regards, Dhaval
Quoted 15 lines · Dhaval Giani
This patch checks if we can set the
rt_runtime_usto 0. If there is a realtime task in the group, we don't want to set thert_runtime_usas 0 or bad things will happen.Signed-off-by Dhaval Giani <[email protected]>--- kernel/sched.c | 17 +++++++++++++++++ 1 files changed, 17 insertions(+)Index:
linux-2.6.25-rc3/kernel/sched.c
===================================================================kernel/sched.c +0
-0@@ -7960,6 +7960,17 @@ static int __rt_schedulable(struct task_return total +to_ratio (period, runtime) < global_ratio;
kernel/sched.c static int __rt_schedulable(struct task_ · line 7970
Quoted 10 lines
kernel/sched.c +8
-0} +/* Must be called with tasklist_lock held */ +static inline int tg_has_rt_tasks (struct task_group *tg) +{ +struct task_struct *p; +for_each_process (p) { +if (rt_task (p) &&rt_rq_of_se (&p->rt)->tg == tg) +return 1 ; + }
This should be a do_each_thread() { } while_each_thread(); iteration loop;
cgroups are thread oriented, not task.
Sorry for missing this earlier.
Quoted 26 lines
kernel/sched.c +9
-0+return 0 ; +} +int sched_group_set_rt_runtime (struct task_group *tg,long rt_runtime_us) {u64 rt_runtime, rt_period;@@ -7971,6 +7982,11 @@ int sched_group_set_rt_runtime(struct ta rt_runtime = rt_period;mutex_lock (&rt_constraints_mutex); +read_lock (&tasklist_lock); +if (rt_runtime_us ==0 &&tg_has_rt_tasks (tg)) { + err = -EINVAL ; + goto unlock; + }if (!__rt_schedulable (tg, rt_period, rt_runtime)) { err = -EINVAL ; goto unlock;@@ -7979,6 +7995,7 @@ int sched_group_set_rt_runtime(struct ta rt_runtime =RUNTIME_INF ; tg->rt_runtime = rt_runtime; unlock: +read_unlock (&tasklist_lock);mutex_unlock (&rt_constraints_mutex);return err;
Quoted 11 lines · Peter Zijlstra
Review
Quoted 5 lines · Dhaval Giani
(quoted diff) +5
-0+ struct task_struct *p; + for_each_process(p) { + if (rt_task(p) && rt_rq_of_se(&p->rt)->tg == tg) + return 1; + }This should be a
do_each_thread(){ }while_each_thread(); iteration loop;
Quoted 4 lines
cgroups are thread oriented, not task.
Sorry for missing this earlier.
Nice catch! Sorry for the mistake, corrected patch follows.
---
This patch checks if we can set the rt_runtime_us to 0. If there is a realtime task in the group, we don't want to set the rt_runtime_us as 0 or bad things will happen.
--- kernel/sched.c | 17 +++++++++++++++++ 1 files changed, 17 insertions(+)
kernel/sched.c +17 -0
@@ -7960,6 +7960,17 @@ static int __rt_schedulable(struct task_return total +to_ratio (period, runtime) < global_ratio; } +/* Must be called with tasklist_lock held */ +static inline int tg_has_rt_tasks (struct task_group *tg) +{ +struct task_struct *g, *p; + do_each_thread(g, p) { +if (rt_task (p) &&rt_rq_of_se (&p->rt)->tg == tg) +return 1 ; + }while_each_thread (g, p); +return 0 ; +} +int sched_group_set_rt_runtime (struct task_group *tg,long rt_runtime_us) {u64 rt_runtime, rt_period;
@@ -7971,6 +7982,11 @@ int sched_group_set_rt_runtime(struct ta rt_runtime = rt_period;mutex_lock (&rt_constraints_mutex); +read_lock (&tasklist_lock); +if (rt_runtime_us ==0 &&tg_has_rt_tasks (tg)) { + err = -EINVAL ; + goto unlock; + }if (!__rt_schedulable (tg, rt_period, rt_runtime)) { err = -EINVAL ; goto unlock;
@@ -7979,6 +7995,7 @@ int sched_group_set_rt_runtime(struct ta rt_runtime =RUNTIME_INF ; tg->rt_runtime = rt_runtime; unlock: +read_unlock (&tasklist_lock);mutex_unlock (&rt_constraints_mutex);return err;
Signature · 2 lines
regards, Dhaval