SCHED_DEADLINE fix AC and SMP scheduling
cover SCHED_DEADLINE fix AC and SMP scheduling
Hello everyone,
This patchset fixes admission control, bandwidth management and (clustered) SMP scheduling for SCHED_DEADLINE tasks.
Patch 1/3 properly clears things up when a task leaves SCHED_DEADLINE, without dying (and it is a different solution for the problem spotted by Daniel, http://marc.info/?l=linux-kernel&m=140974782707197&w=2);
patch 2/3 fixes how cpusets bandwidth is checked and updated; patch 3/3 fixes SMP (clustered) scheduling.
Best Regards,
- Juri
Juri Lelli (3):
sched/deadline: clear dl_entity params when setscheduling to different
class
sched/deadline: fix bandwidth check/update when migrating tasks
between exclusive cpusets
sched/deadline: fix inter- exclusive cpusets migrations
include/linux/sched.h | 2 ++ kernel/cpuset.c | 13 ++----- kernel/sched/core.c | 89 ++++++++++++++++++++++++++++++++++------------ kernel/sched/cpudeadline.c | 4 +-- kernel/sched/deadline.c | 34 ++++++++++++++++-- kernel/sched/sched.h | 22 ++++++++++++ 6 files changed, 125 insertions(+), 39 deletions(-)
Signature · 1 line
2.1.0
PATCH 1/3 sched/deadline: clear dl_entity params when setscheduling to different class
When a task is using SCHED_DEADLINE and the user setschedules it to a different class its sched_dl_entity static parameters are not cleaned up. This causes a bug if the user sets it back to SCHED_DEADLINE with the same parameters again. The problem resides in the check we perform at the very beginning of dl_overflow():
if (new_bw == p->dl.dl_bw) return 0;
This condition is met in the case depicted above, so the function returns and dl_b->total_bw is not updated (the p->dl.dl_bw is not added to it). After this, admission control is broken.
This patch fixes the thing, properly clearing static parameters for a task that ceases to use SCHED_DEADLINE.
--- kernel/sched/core.c | 19 +++++++++++++++---- kernel/sched/deadline.c | 2 ++ kernel/sched/sched.h | 3 +++ 3 files changed, 20 insertions(+), 4 deletions(-)
kernel/sched/core.c +15 -4
@@ -1776,6 +1776,20 @@ int wake_up_state(struct task_struct *p, unsigned int state) }/* +* This function clears the sched_dl_entity static params. +*/ +void __dl_clear_params (struct task_struct *p) +{ +struct sched_dl_entity *dl_se = &p->dl; + + dl_se->dl_runtime =0 ; + dl_se->dl_deadline =0 ; + dl_se->dl_period =0 ; + dl_se->flags =0 ; + dl_se->dl_bw =0 ; +} + +/* * Perform scheduler related setup for a newly forked process p. * p is forked by current. *
@@ -1799,10 +1813,7 @@ static void __sched_fork(unsigned long clone_flags, struct task_struct *p)RB_CLEAR_NODE (&p->dl.rb_node);hrtimer_init (&p->dl.dl_timer,CLOCK_MONOTONIC ,HRTIMER_MODE_REL ); - p->dl.dl_runtime = p->dl.runtime =0 ; - p->dl.dl_deadline = p->dl.deadline =0 ; - p->dl.dl_period =0 ; - p->dl.flags =0 ; +__dl_clear_params (p);INIT_LIST_HEAD (&p->rt.run_list);
kernel/sched/deadline.c +2 -0
@@ -1569,6 +1569,8 @@ static void switched_from_dl(struct rq *rq, struct task_struct *p)if (hrtimer_active (&p->dl.dl_timer) && !dl_policy (p->policy))hrtimer_try_to_cancel (&p->dl.dl_timer); +__dl_clear_params (p); +#ifdef CONFIG_SMP /* * Since this might be the only -deadline task on the rq,
kernel/sched/sched.h +3 -0
@@ -126,6 +126,9 @@ struct rt_bandwidth {u64 rt_runtime;struct hrtimer rt_period_timer; }; + +void __dl_clear_params (struct task_struct *p); +/* * To keep the bandwidth of -deadline tasks and groups under control * we need some place where:
Signature · 1 line
2.1.0
Re: [PATCH 1/3] sched/deadline: clear dl_entity params when setscheduling to different class
Hi,
Quoted 13 lines · Juri Lelli
When a task is using
SCHED_DEADLINEand the user setschedules it to a different class itssched_dl_entitystatic parameters are not cleaned up. This causes a bug if the user sets it back toSCHED_DEADLINEwith the same parameters again. The problem resides in the check we perform at the very beginning ofdl_overflow():if (new_bw == p->dl.dl_bw) return 0;This condition is met in the case depicted above, so the function returns and
dl_b->total_bwis not updated (thep->dl.dl_bwis not added to it). After this, admission control is broken.
Quoted 5 lines
This patch fixes the thing, properly clearing static parameters for a task that ceases to use
SCHED_DEADLINE.Reported-by Daniele Alessandrelli <[email protected]>Reported-by Daniel Wagner <[email protected]>
Fixes my problem.
Thanks,
Daniel
Re: [PATCH 1/3] sched/deadline: clear dl_entity params when setscheduling to different class
Hi Daniel,
Quoted 19 lines · Daniel Wagner
Hi,
Quoted 16 lines · Juri Lelli
When a task is using
SCHED_DEADLINEand the user setschedules it to a different class itssched_dl_entitystatic parameters are not cleaned up. This causes a bug if the user sets it back toSCHED_DEADLINEwith the same parameters again. The problem resides in the check we perform at the very beginning ofdl_overflow():if (new_bw == p->dl.dl_bw) return 0;This condition is met in the case depicted above, so the function returns and
dl_b->total_bwis not updated (thep->dl.dl_bwis not added to it). After this, admission control is broken.This patch fixes the thing, properly clearing static parameters for a task that ceases to use
SCHED_DEADLINE.
Quoted 7 lines
Quoted 2 lines
Reported-by Daniele Alessandrelli <[email protected]>Reported-by Daniel Wagner <[email protected]>Tested-by Daniel Wagner <[email protected]>Fixes my problem.
Great! Thanks for testing it.
Best,
- Juri
Re: [PATCH 1/3] sched/deadline: clear dl_entity params when setscheduling to different class
In reply to Juri LelliHello,
Quoted 9 lines · Juri Lelli
When a task is using
SCHED_DEADLINEand the user setschedules it to a different class itssched_dl_entitystatic parameters are not cleaned up. This causes a bug if the user sets it back toSCHED_DEADLINEwith the same parameters again. The problem resides in the check we perform at the very beginning ofdl_overflow():if (new_bw == p->dl.dl_bw) return 0;
Quoted 6 lines
This condition is met in the case depicted above, so the function returns and
dl_b->total_bwis not updated (thep->dl.dl_bwis not added to it). After this, admission control is broken.This patch fixes the thing, properly clearing static parameters for a task that ceases to use
SCHED_DEADLINE.
Thanks, this fixes the issue I had:
Thanks,
Vincent
tip-bot for Juri Lelli
merge bot[tip:sched/core] sched/deadline: Clear dl_entity params when setscheduling to different class
In reply to Juri Lellisched/deadline: Clear dl_entity params when setscheduling to different class
Commit-ID: a5e7be3b28a235108c59561bea55eea1072b23b0 Gitweb: http://git.kernel.org/tip/a5e7be3b28a235108c59561bea55eea1072b23b0 Author: Juri Lelli <[email protected]> AuthorDate: Fri, 19 Sep 2014 10:22:39 +0100 Committer: Ingo Molnar <[email protected]> CommitDate: Wed, 24 Sep 2014 14:46:56 +0200
sched/deadline: Clear dl_entity params when setscheduling to different class
When a task is using SCHED_DEADLINE and the user setschedules it to a different class its sched_dl_entity static parameters are not cleaned up. This causes a bug if the user sets it back to SCHED_DEADLINE with the same parameters again. The problem resides in the check we perform at the very beginning of dl_overflow():
if (new_bw == p->dl.dl_bw) return 0;
This condition is met in the case depicted above, so the function returns and dl_b->total_bw is not updated (the p->dl.dl_bw is not added to it). After this, admission control is broken.
This patch fixes the thing, properly clearing static parameters for a task that ceases to use SCHED_DEADLINE.
--- kernel/sched/core.c | 19 +++++++++++++++---- kernel/sched/deadline.c | 2 ++ kernel/sched/sched.h | 3 +++ 3 files changed, 20 insertions(+), 4 deletions(-)
kernel/sched/core.c +15 -4
@@ -1809,6 +1809,20 @@ int wake_up_state(struct task_struct *p, unsigned int state) }/* +* This function clears the sched_dl_entity static params. +*/ +void __dl_clear_params (struct task_struct *p) +{ +struct sched_dl_entity *dl_se = &p->dl; + + dl_se->dl_runtime =0 ; + dl_se->dl_deadline =0 ; + dl_se->dl_period =0 ; + dl_se->flags =0 ; + dl_se->dl_bw =0 ; +} + +/* * Perform scheduler related setup for a newly forked process p. * p is forked by current. *
@@ -1832,10 +1846,7 @@ static void __sched_fork(unsigned long clone_flags, struct task_struct *p)RB_CLEAR_NODE (&p->dl.rb_node);hrtimer_init (&p->dl.dl_timer,CLOCK_MONOTONIC ,HRTIMER_MODE_REL ); - p->dl.dl_runtime = p->dl.runtime =0 ; - p->dl.dl_deadline = p->dl.deadline =0 ; - p->dl.dl_period =0 ; - p->dl.flags =0 ; +__dl_clear_params (p);INIT_LIST_HEAD (&p->rt.run_list);
kernel/sched/deadline.c +2 -0
@@ -1565,6 +1565,8 @@ static void switched_from_dl(struct rq *rq, struct task_struct *p)if (hrtimer_active (&p->dl.dl_timer) && !dl_policy (p->policy))hrtimer_try_to_cancel (&p->dl.dl_timer); +__dl_clear_params (p); +#ifdef CONFIG_SMP /* * Since this might be the only -deadline task on the rq,
kernel/sched/sched.h +3 -0
@@ -130,6 +130,9 @@ struct rt_bandwidth {u64 rt_runtime;struct hrtimer rt_period_timer; }; + +void __dl_clear_params (struct task_struct *p); +/* * To keep the bandwidth of -deadline tasks and groups under control * we need some place where:
Re: [PATCH 1/3] sched/deadline: clear dl_entity params when setscheduling to different class
In reply to Juri LelliHi Juri,
Quoted 11 lines · Juri Lelli
When a task is using
SCHED_DEADLINEand the user setschedules it to a different class itssched_dl_entitystatic parameters are not cleaned up. This causes a bug if the user sets it back toSCHED_DEADLINEwith the same parameters again. The problem resides in the check we perform at the very beginning ofdl_overflow():if (new_bw == p->dl.dl_bw) return 0;This condition is met in the case depicted above, so the function returns and
dl_b->total_bwis not updated (thep->dl.dl_bwis not added to it). After this,
As you know there is no static parameter clear before this patch, so if p->dl.dl_bw will decrease from dl_b->total_bw when the user setschedules to a different class instead of dl?
Regards,
Wanpeng Li
Quoted 87 lines
admission control is broken.
This patch fixes the thing, properly clearing static parameters for a task that ceases to use
SCHED_DEADLINE.Reported-by Daniele Alessandrelli <[email protected]>Reported-by Daniel Wagner <[email protected]>Reported-by Vincent Legout <[email protected]>Tested-by Luca Abeni <[email protected]>Signed-off-by Juri Lelli <[email protected]>Cc Ingo Molnar <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Juri Lelli <[email protected]>Cc Dario Faggioli <[email protected]>Cc Michael Trimarchi <[email protected]>Cc Fabio Checconi <[email protected]>--- kernel/sched/core.c | 19 +++++++++++++++---- kernel/sched/deadline.c | 2 ++ kernel/sched/sched.h | 3 +++ 3 files changed, 20 insertions(+), 4 deletions(-)kernel/sched/core.c +15
-4@@ -1776,6 +1776,20 @@ int wake_up_state(struct task_struct *p, unsigned int state) }/* +* This function clears the sched_dl_entity static params. +*/ +void __dl_clear_params (struct task_struct *p) +{ +struct sched_dl_entity *dl_se = &p->dl; + + dl_se->dl_runtime =0 ; + dl_se->dl_deadline =0 ; + dl_se->dl_period =0 ; + dl_se->flags =0 ; + dl_se->dl_bw =0 ; +} + +/* * Perform scheduler related setup for a newly forked process p. * p is forked by current. * @@ -1799,10 +1813,7 @@ static void __sched_fork(unsigned long clone_flags, struct task_struct *p)RB_CLEAR_NODE (&p->dl.rb_node);hrtimer_init (&p->dl.dl_timer,CLOCK_MONOTONIC ,HRTIMER_MODE_REL ); - p->dl.dl_runtime = p->dl.runtime =0 ; - p->dl.dl_deadline = p->dl.deadline =0 ; - p->dl.dl_period =0 ; - p->dl.flags =0 ; +__dl_clear_params (p);INIT_LIST_HEAD (&p->rt.run_list);kernel/sched/deadline.c +2
-0@@ -1569,6 +1569,8 @@ static void switched_from_dl(struct rq *rq, struct task_struct *p)if (hrtimer_active (&p->dl.dl_timer) && !dl_policy (p->policy))hrtimer_try_to_cancel (&p->dl.dl_timer); +__dl_clear_params (p); +#ifdef CONFIG_SMP /* * Since this might be the only -deadline task on the rq, kernel/sched/sched.h +3
-0@@ -126,6 +126,9 @@ struct rt_bandwidth {u64 rt_runtime;struct hrtimer rt_period_timer; }; + +void __dl_clear_params (struct task_struct *p); +/* * To keep the bandwidth of -deadline tasks and groups under control * we need some place where:
Re: [PATCH 1/3] sched/deadline: clear dl_entity params when setscheduling to different class
ping,
Quoted 106 lines · Wanpeng Li
Hi Juri,
Quoted 11 lines · Juri Lelli
When a task is using
SCHED_DEADLINEand the user setschedules it to a different class itssched_dl_entitystatic parameters are not cleaned up. This causes a bug if the user sets it back toSCHED_DEADLINEwith the same parameters again. The problem resides in the check we perform at the very beginning ofdl_overflow():if (new_bw == p->dl.dl_bw) return 0;This condition is met in the case depicted above, so the function returns and
dl_b->total_bwis not updated (thep->dl.dl_bwis not added to it). After this,As you know there is no static parameter clear before this patch, so if
p->dl.dl_bwwill decrease fromdl_b->total_bwwhen the user setschedules to a different class instead of dl?Regards,
Wanpeng LiQuoted 85 lines
admission control is broken.
This patch fixes the thing, properly clearing static parameters for a task that ceases to use
SCHED_DEADLINE.Reported-by Daniele Alessandrelli <[email protected]>Reported-by Daniel Wagner <[email protected]>Reported-by Vincent Legout <[email protected]>Tested-by Luca Abeni <[email protected]>Signed-off-by Juri Lelli <[email protected]>Cc Ingo Molnar <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Juri Lelli <[email protected]>Cc Dario Faggioli <[email protected]>Cc Michael Trimarchi <[email protected]>Cc Fabio Checconi <[email protected]>--- kernel/sched/core.c | 19 +++++++++++++++---- kernel/sched/deadline.c | 2 ++ kernel/sched/sched.h | 3 +++ 3 files changed, 20 insertions(+), 4 deletions(-)kernel/sched/core.c +15
-4@@ -1776,6 +1776,20 @@ int wake_up_state(struct task_struct *p, unsigned int state) }/* +* This function clears the sched_dl_entity static params. +*/ +void __dl_clear_params (struct task_struct *p) +{ +struct sched_dl_entity *dl_se = &p->dl; + + dl_se->dl_runtime =0 ; + dl_se->dl_deadline =0 ; + dl_se->dl_period =0 ; + dl_se->flags =0 ; + dl_se->dl_bw =0 ; +} + +/* * Perform scheduler related setup for a newly forked process p. * p is forked by current. * @@ -1799,10 +1813,7 @@ static void __sched_fork(unsigned long clone_flags, struct task_struct *p)RB_CLEAR_NODE (&p->dl.rb_node);hrtimer_init (&p->dl.dl_timer,CLOCK_MONOTONIC ,HRTIMER_MODE_REL ); - p->dl.dl_runtime = p->dl.runtime =0 ; - p->dl.dl_deadline = p->dl.deadline =0 ; - p->dl.dl_period =0 ; - p->dl.flags =0 ; +__dl_clear_params (p);INIT_LIST_HEAD (&p->rt.run_list); diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.cindex 255ce13..4a51b14 100644
kernel/sched/deadline.c +1
-0@@ -1569,6 +1569,8 @@ static void switched_from_dl(struct rq *rq, struct task_struct *p)if (hrtimer_active (&p->dl.dl_timer) && !dl_policy (p->policy))hrtimer_try_to_cancel (&p->dl.dl_timer); +__dl_clear_params (p); +#ifdef CONFIG_SMP /* * Since this might be the only -deadline task on the rq, kernel/sched/sched.h +3
-0@@ -126,6 +126,9 @@ struct rt_bandwidth {u64 rt_runtime;struct hrtimer rt_period_timer; }; + +void __dl_clear_params (struct task_struct *p); +/* * To keep the bandwidth of -deadline tasks and groups under control * we need some place where:
Re: [PATCH 1/3] sched/deadline: clear dl_entity params when setscheduling to different class
Hi,
Quoted 27 lines · Wanpeng Li
ping,
Quoted 24 lines · Wanpeng Li
Hi Juri,
Quoted 9 lines · Juri Lelli
When a task is using
SCHED_DEADLINEand the user setschedules it to a different
class itssched_dl_entitystatic parameters are not cleaned up. This causes a
bug if the user sets it back toSCHED_DEADLINEwith the same parameters again.
The problem resides in the check we perform at the very beginning ofdl_overflow():Quoted 7 lines
if (new_bw == p->dl.dl_bw) return 0;This condition is met in the case depicted above, so the function returns and
dl_b->total_bwis not updated (thep->dl.dl_bwis not added to it). After this,As you know there is no static parameter clear before this patch, so if
p->dl.dl_bwwill decrease fromdl_b->total_bwwhen the user setschedules to a different class instead of dl?
We remove p->dl.dl_bw from dl_b->total_bw in dl_overflow(). Then this patch introduces the clearing of p->dl params.
Thanks,
- Juri
Quoted 92 lines
Quoted 90 lines
Regards,
Wanpeng LiQuoted 86 lines
admission control is broken.
This patch fixes the thing, properly clearing static parameters for a task
that ceases to useSCHED_DEADLINE.Reported-by Daniele Alessandrelli <[email protected]>Reported-by Daniel Wagner <[email protected]>Reported-by Vincent Legout <[email protected]>Tested-by Luca Abeni <[email protected]>Signed-off-by Juri Lelli <[email protected]>Cc Ingo Molnar <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Juri Lelli <[email protected]>Cc Dario Faggioli <[email protected]>Cc Michael Trimarchi <[email protected]>Cc Fabio Checconi <[email protected]>--- kernel/sched/core.c | 19 +++++++++++++++---- kernel/sched/deadline.c | 2 ++ kernel/sched/sched.h | 3 +++ 3 files changed, 20 insertions(+), 4 deletions(-)kernel/sched/core.c +15
-4@@ -1776,6 +1776,20 @@ int wake_up_state(struct task_struct *p, unsigned int state) }/* +* This function clears the sched_dl_entity static params. +*/ +void __dl_clear_params (struct task_struct *p) +{ +struct sched_dl_entity *dl_se = &p->dl; + + dl_se->dl_runtime =0 ; + dl_se->dl_deadline =0 ; + dl_se->dl_period =0 ; + dl_se->flags =0 ; + dl_se->dl_bw =0 ; +} + +/* * Perform scheduler related setup for a newly forked process p. * p is forked by current. * @@ -1799,10 +1813,7 @@ static void __sched_fork(unsigned long clone_flags, struct task_struct *p)RB_CLEAR_NODE (&p->dl.rb_node);hrtimer_init (&p->dl.dl_timer,CLOCK_MONOTONIC ,HRTIMER_MODE_REL ); - p->dl.dl_runtime = p->dl.runtime =0 ; - p->dl.dl_deadline = p->dl.deadline =0 ; - p->dl.dl_period =0 ; - p->dl.flags =0 ; +__dl_clear_params (p);INIT_LIST_HEAD (&p->rt.run_list); diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.cindex 255ce13..4a51b14 100644
kernel/sched/deadline.c +1
-0@@ -1569,6 +1569,8 @@ static void switched_from_dl(struct rq *rq, struct task_struct *p)if (hrtimer_active (&p->dl.dl_timer) && !dl_policy (p->policy))hrtimer_try_to_cancel (&p->dl.dl_timer); +__dl_clear_params (p); +#ifdef CONFIG_SMP /* * Since this might be the only -deadline task on the rq, kernel/sched/sched.h +3
-0@@ -126,6 +126,9 @@ struct rt_bandwidth {u64 rt_runtime;struct hrtimer rt_period_timer; }; + +void __dl_clear_params (struct task_struct *p); +/* * To keep the bandwidth of -deadline tasks and groups under control * we need some place where:
PATCH 2/3 sched/deadline: fix bandwidth check/update when migrating tasks between exclusive cpusets
In reply to Juri LelliExclusive cpusets are the only way users can restrict SCHED_DEADLINE tasks affinity (performing what is commonly called clustered scheduling). Unfortunately, such thing is currently broken for two reasons:
- No check is performed when the user tries to attach a task to an exlusive cpuset (recall that exclusive cpusets have an associated maximum allowed bandwidth).
- Bandwidths of source and destination cpusets are not correctly updated after a task is migrated between them.
This patch fixes both things at once, as they are opposite faces of the same coin.
The check is performed in cpuset_can_attach(), as there aren't any points of failure after that function. The updated is split in two halves. We first reserve bandwidth in the destination cpuset, after we pass the check in cpuset_can_attach(). And we then release bandwidth from the source cpuset when the task's affinity is actually changed. Even if there can be time windows when sched_setattr() may erroneously fail in the source cpuset, we are fine with it, as we can't perfom an atomic update of both cpusets at once.
--- include/linux/sched.h | 2 ++ kernel/cpuset.c | 13 ++------- kernel/sched/core.c | 70 +++++++++++++++++++++++++++++++++++-------------- kernel/sched/deadline.c | 25 ++++++++++++++++-- kernel/sched/sched.h | 19 ++++++++++++++ 5 files changed, 97 insertions(+), 32 deletions(-)
include/linux/sched.h +2 -0
@@ -2029,6 +2029,8 @@ static inline void tsk_restore_flags(struct task_struct *task, task->flags |= orig_flags & flags; } +extern int task_can_attach (struct task_struct *p, +const struct cpumask *cs_cpus_allowed);#ifdef CONFIG_SMP extern void do_set_cpus_allowed (struct task_struct *p,const struct cpumask *new_mask);
kernel/cpuset.c +2 -11
@@ -1428,17 +1428,8 @@ static int cpuset_can_attach(struct cgroup_subsys_state *css, goto out_unlock;cgroup_taskset_for_each (task, tset) { -/* -* Kthreads which disallow setaffinity shouldn't be moved -* to a new cpuset; we don't want to change their cpu -* affinity and isolating such threads by their set of -* allowed nodes is unnecessary. Thus, cpusets are not -* applicable for such threads. This prevents checking for -* success of set_cpus_allowed_ptr() on all attached tasks -* before cpus_allowed may be changed. -*/ - ret = -EINVAL ; -if (task->flags &PF_NO_SETAFFINITY ) + ret =task_can_attach (task, cs->cpus_allowed); +if (ret) goto out_unlock; ret =security_task_setscheduler (task);if (ret)
kernel/sched/core.c +51 -19
82 lines not on this page · raw message
kernel/sched/deadline.c +23 -2
@@ -1495,10 +1495,33 @@ static void set_cpus_allowed_dl(struct task_struct *p, const struct cpumask *new_mask) {struct rq *rq; +struct root_domain *src_rd;int weight;BUG_ON (!dl_task (p)); + rq =task_rq (p); + src_rd = rq->rd; +/* +* Migrating a SCHED_DEADLINE task between exclusive +* cpusets (different root_domains) entails a bandwidth +* update. We already made space for us in the destination +* domain (see cpuset_can_attach()). +*/ +if (!cpumask_intersects (src_rd->span, new_mask)) { +struct dl_bw *src_dl_b; + + src_dl_b =dl_bw_of (cpu_of (rq)); +/* +* We now free resources of the root_domain we are migrating +* off. In the worst case, sched_setattr() may temporary fail +* until we complete the update. +*/ +raw_spin_lock (&src_dl_b->lock); +__dl_clear (src_dl_b, p->dl.dl_bw); +raw_spin_unlock (&src_dl_b->lock); + } +/* * Update only if the task is actually running (i.e., * it is on the rq AND it is not throttled).
@@ -1515,8 +1538,6 @@ static void set_cpus_allowed_dl(struct task_struct *p,if ((p->nr_cpus_allowed >1 ) == (weight >1 ))return ; - rq =task_rq (p); -/* * The process used to be able to migrate OR it can now migrate */
kernel/sched/sched.h +19 -0
@@ -171,6 +171,25 @@ struct dl_bw {u64 bw, total_bw; }; +static inline +void __dl_clear (struct dl_bw *dl_b,u64 tsk_bw) +{ + dl_b->total_bw -= tsk_bw; +} + +static inline +void __dl_add (struct dl_bw *dl_b,u64 tsk_bw) +{ + dl_b->total_bw += tsk_bw; +} + +static inline +bool __dl_overflow (struct dl_bw *dl_b,int cpus,u64 old_bw,u64 new_bw) +{ +return dl_b->bw !=-1 && + dl_b->bw * cpus < dl_b->total_bw - old_bw + new_bw; +} +extern struct mutex sched_domains_mutex;#ifdef CONFIG_CGROUP_SCHED
Signature · 1 line
2.1.0
Re: [PATCH 2/3] sched/deadline: fix bandwidth check/update when migrating tasks between exclusive cpusets
Hi,
Quoted 23 lines · Juri Lelli
Exclusive cpusets are the only way users can restrict
SCHED_DEADLINEtasks affinity (performing what is commonly called clustered scheduling). Unfortunately, such thing is currently broken for two reasons:- No check is performed when the user tries to attach a task to an exlusive cpuset (recall that exclusive cpusets have an associated maximum allowed bandwidth).
- Bandwidths of source and destination cpusets are not correctly updated after a task is migrated between them.
This patch fixes both things at once, as they are opposite faces of the same coin.
The check is performed in
cpuset_can_attach(), as there aren't any points of failure after that function. The updated is split in two halves. We first reserve bandwidth in the destination cpuset, after we pass the check incpuset_can_attach(). And we then release bandwidth from the source cpuset when the task's affinity is actually changed. Even if there can be time windows whensched_setattr()may erroneously fail in the source cpuset, we are fine with it, as we can't perfom an atomic update of both cpusets at once.
Quoted 1 line
Reported-by Daniel Wagner <[email protected]>
Ack
I have no special test for this, I just let my test running which was fixed by patch #1. Works fine though. I'll plan to write some test for this.
Thanks,
Daniel
Re: [PATCH 2/3] sched/deadline: fix bandwidth check/update when migrating tasks between exclusive cpusets
Hi Daniel,
Quoted 26 lines · Daniel Wagner
Hi,
Quoted 23 lines · Juri Lelli
Exclusive cpusets are the only way users can restrict
SCHED_DEADLINEtasks affinity (performing what is commonly called clustered scheduling). Unfortunately, such thing is currently broken for two reasons:- No check is performed when the user tries to attach a task to an exlusive cpuset (recall that exclusive cpusets have an associated maximum allowed bandwidth).
- Bandwidths of source and destination cpusets are not correctly updated after a task is migrated between them.
This patch fixes both things at once, as they are opposite faces of the same coin.
The check is performed in
cpuset_can_attach(), as there aren't any points of failure after that function. The updated is split in two halves. We first reserve bandwidth in the destination cpuset, after we pass the check incpuset_can_attach(). And we then release bandwidth from the source cpuset when the task's affinity is actually changed. Even if there can be time windows whensched_setattr()may erroneously fail in the source cpuset, we are fine with it, as we can't perfom an atomic update of both cpusets at once.
Quoted 7 lines
Quoted 1 line
Reported-by Daniel Wagner <[email protected]>Ack
I have no special test for this, I just let my test running which was fixed by patch #1. Works fine though. I'll plan to write some test for this.
Ok, thanks. Just mind that the problem fixed by patch 3/3 may sometime affect this too. I should have definitely put 3/3 on top of the patchset :/.
Thanks,
- Juri
Peter Zijlstra
maintainerRe: [PATCH 2/3] sched/deadline: fix bandwidth check/update when migrating tasks between exclusive cpusets
In reply to Juri LelliQuoted 14 lines · Juri Lelli
Exclusive cpusets are the only way users can restrict
SCHED_DEADLINEtasks affinity (performing what is commonly called clustered scheduling). Unfortunately, such thing is currently broken for two reasons:- No check is performed when the user tries to attach a task to an exlusive cpuset (recall that exclusive cpusets have an associated maximum allowed bandwidth).
- Bandwidths of source and destination cpusets are not correctly updated after a task is migrated between them.
This patch fixes both things at once, as they are opposite faces of the same coin.
Quoted 8 lines
The check is performed in
cpuset_can_attach(), as there aren't any points of failure after that function. The updated is split in two halves. We first reserve bandwidth in the destination cpuset, after we pass the check incpuset_can_attach(). And we then release bandwidth from the source cpuset when the task's affinity is actually changed. Even if there can be time windows whensched_setattr()may erroneously fail in the source cpuset, we are fine with it, as we can't perfom an atomic update of both cpusets at once.
The thing I cannot find is if we correctly deal with updates to the cpuset. Say we first setup 2 (exclusive) sets A:cpu0 B:cpu1-3. Then assign tasks and then update the cpu masks like: B:cpu2,3, A:cpu1,2.
Re: [PATCH 2/3] sched/deadline: fix bandwidth check/update when migrating tasks between exclusive cpusets
Hi Peter,
Quoted 24 lines · Peter Zijlstra
Quoted 14 lines · Juri Lelli
Exclusive cpusets are the only way users can restrict
SCHED_DEADLINEtasks affinity (performing what is commonly called clustered scheduling). Unfortunately, such thing is currently broken for two reasons:- No check is performed when the user tries to attach a task to an exlusive cpuset (recall that exclusive cpusets have an associated maximum allowed bandwidth).
- Bandwidths of source and destination cpusets are not correctly updated after a task is migrated between them.
This patch fixes both things at once, as they are opposite faces of the same coin.
Quoted 8 lines
The check is performed in
cpuset_can_attach(), as there aren't any points of failure after that function. The updated is split in two halves. We first reserve bandwidth in the destination cpuset, after we pass the check incpuset_can_attach(). And we then release bandwidth from the source cpuset when the task's affinity is actually changed. Even if there can be time windows whensched_setattr()may erroneously fail in the source cpuset, we are fine with it, as we can't perfom an atomic update of both cpusets at once.
Quoted 4 lines
The thing I cannot find is if we correctly deal with updates to the cpuset. Say we first setup 2 (exclusive) sets A:cpu0 B:cpu1-3. Then assign tasks and then update the cpu masks like: B:cpu2,3, A:cpu1,2.
Right, next week I should be able to properly test this.
Thanks a lot,
- Juri
Re: [PATCH 2/3] sched/deadline: fix bandwidth check/update when migrating tasks between exclusive cpusets
In reply to Peter ZijlstraHi Peter,
Quoted 24 lines · Peter Zijlstra
Quoted 14 lines · Juri Lelli
Exclusive cpusets are the only way users can restrict
SCHED_DEADLINEtasks affinity (performing what is commonly called clustered scheduling). Unfortunately, such thing is currently broken for two reasons:- No check is performed when the user tries to attach a task to an exlusive cpuset (recall that exclusive cpusets have an associated maximum allowed bandwidth).
- Bandwidths of source and destination cpusets are not correctly updated after a task is migrated between them.
This patch fixes both things at once, as they are opposite faces of the same coin.
Quoted 8 lines
The check is performed in
cpuset_can_attach(), as there aren't any points of failure after that function. The updated is split in two halves. We first reserve bandwidth in the destination cpuset, after we pass the check incpuset_can_attach(). And we then release bandwidth from the source cpuset when the task's affinity is actually changed. Even if there can be time windows whensched_setattr()may erroneously fail in the source cpuset, we are fine with it, as we can't perfom an atomic update of both cpusets at once.
Quoted 4 lines
The thing I cannot find is if we correctly deal with updates to the cpuset. Say we first setup 2 (exclusive) sets A:cpu0 B:cpu1-3. Then assign tasks and then update the cpu masks like: B:cpu2,3, A:cpu1,2.
So, what follows should address the problem you describe.
Assuming you intended that we try to update masks as A:cpu0,3 and B:cpu1,2, with what below we are able to check that removing cpu3 from B doesn't break guarantees. After that cpu3 can be put in A.
Does it make any sense?
Thanks,
- Juri
Quoted 1 line
From
0e52c2211879eec92cd435e7717ab628f3b3084bMon Sep 17 00:00:00 2001
From: Juri Lelli <[email protected]>
Date: Tue, 7 Oct 2014 09:52:11 +0100
Subject: [PATCH] sched/deadline: ensure that updates to exclusive cpusets
don't break AC
--- include/linux/sched.h | 2 ++ kernel/cpuset.c | 10 ++++++++++ kernel/sched/core.c | 19 +++++++++++++++++++ 3 files changed, 31 insertions(+)
include/linux/sched.h +2 -0
@@ -2041,6 +2041,8 @@ static inline void tsk_restore_flags(struct task_struct *task, task->flags |= orig_flags & flags; } +extern int cpuset_cpumask_can_shrink (const struct cpumask *cur, +const struct cpumask *trial);extern int task_can_attach (struct task_struct *p,const struct cpumask *cs_cpus_allowed);#ifdef CONFIG_SMP
kernel/cpuset.c +10 -0
@@ -506,6 +506,16 @@ static int validate_change(struct cpuset *cur, struct cpuset *trial) goto out; } +/* +* We can't shrink if we won't have enough room for SCHED_DEADLINE +* tasks. +*/ + ret = -EBUSY ; +if (is_cpu_exclusive (cur) && + !cpuset_cpumask_can_shrink (cur->cpus_allowed, + trial->cpus_allowed)) + goto out; + ret =0 ; out:rcu_read_unlock ();
kernel/sched/core.c +19 -0
@@ -4587,6 +4587,25 @@ void init_idle(struct task_struct *idle, int cpu)#endif } +int cpuset_cpumask_can_shrink (const struct cpumask *cur, +const struct cpumask *trial) +{ +int ret =1 , trial_cpus; +struct dl_bw *cur_dl_b; +unsigned long flags; + + cur_dl_b =dl_bw_of (cpumask_any (cur)); + trial_cpus =cpumask_weight (trial); + +raw_spin_lock_irqsave (&cur_dl_b->lock, flags); +if (cur_dl_b->bw !=-1 && + cur_dl_b->bw * trial_cpus < cur_dl_b->total_bw) + ret =0 ; +raw_spin_unlock_irqrestore (&cur_dl_b->lock, flags); + +return ret; +} +int task_can_attach (struct task_struct *p,const struct cpumask *cs_cpus_allowed) {
Signature · 1 line
2.1.0
Peter Zijlstra
maintainerRe: [PATCH 2/3] sched/deadline: fix bandwidth check/update when migrating tasks between exclusive cpusets
Quoted 32 lines · Juri Lelli
Hi Peter,
Quoted 24 lines · Peter Zijlstra
Quoted 14 lines · Juri Lelli
Exclusive cpusets are the only way users can restrict
SCHED_DEADLINEtasks affinity (performing what is commonly called clustered scheduling). Unfortunately, such thing is currently broken for two reasons:- No check is performed when the user tries to attach a task to an exlusive cpuset (recall that exclusive cpusets have an associated maximum allowed bandwidth).
- Bandwidths of source and destination cpusets are not correctly updated after a task is migrated between them.
This patch fixes both things at once, as they are opposite faces of the same coin.
Quoted 8 lines
The check is performed in
cpuset_can_attach(), as there aren't any points of failure after that function. The updated is split in two halves. We first reserve bandwidth in the destination cpuset, after we pass the check incpuset_can_attach(). And we then release bandwidth from the source cpuset when the task's affinity is actually changed. Even if there can be time windows whensched_setattr()may erroneously fail in the source cpuset, we are fine with it, as we can't perfom an atomic update of both cpusets at once.Quoted 4 lines
The thing I cannot find is if we correctly deal with updates to the cpuset. Say we first setup 2 (exclusive) sets A:cpu0 B:cpu1-3. Then assign tasks and then update the cpu masks like: B:cpu2,3, A:cpu1,2.
Quoted 7 lines
So, what follows should address the problem you describe.
Assuming you intended that we try to update masks as A:cpu0,3 and B:cpu1,2, with what below we are able to check that removing cpu3 from B doesn't break guarantees. After that cpu3 can be put in A.
Does it make any sense?
Yeah, I think that about covers is. Could you write a changelog with it?
The reason I hadn't applied your patch #2 yet is because I thought it triggered the splat reported in this thread. But later emails seem to suggest this is a separate/pre-existing issue?
Re: [PATCH 2/3] sched/deadline: fix bandwidth check/update when migrating tasks between exclusive cpusets
Hi Peter,
Quoted 35 lines · Peter Zijlstra
Quoted 34 lines · Juri Lelli
Hi Peter,
Quoted 24 lines · Peter Zijlstra
Quoted 14 lines · Juri Lelli
Exclusive cpusets are the only way users can restrict
SCHED_DEADLINEtasks affinity (performing what is commonly called clustered scheduling). Unfortunately, such thing is currently broken for two reasons:- No check is performed when the user tries to attach a task to an exlusive cpuset (recall that exclusive cpusets have an associated maximum allowed bandwidth).
- Bandwidths of source and destination cpusets are not correctly updated after a task is migrated between them.
This patch fixes both things at once, as they are opposite faces of the same coin.
Quoted 8 lines
The check is performed in
cpuset_can_attach(), as there aren't any points of failure after that function. The updated is split in two halves. We first reserve bandwidth in the destination cpuset, after we pass the check incpuset_can_attach(). And we then release bandwidth from the source cpuset when the task's affinity is actually changed. Even if there can be time windows whensched_setattr()may erroneously fail in the source cpuset, we are fine with it, as we can't perfom an atomic update of both cpusets at once.Quoted 4 lines
The thing I cannot find is if we correctly deal with updates to the cpuset. Say we first setup 2 (exclusive) sets A:cpu0 B:cpu1-3. Then assign tasks and then update the cpu masks like: B:cpu2,3, A:cpu1,2.
So, what follows should address the problem you describe.
Quoted 8 lines
Quoted 5 lines
Assuming you intended that we try to update masks as A:cpu0,3 and B:cpu1,2, with what below we are able to check that removing cpu3 from B doesn't break guarantees. After that cpu3 can be put in A.
Does it make any sense?
Yeah, I think that about covers is. Could you write a changelog with it?
Sure. Didn't write it in the first instance because I though to squash it in 2/3. But it is actually fixing a different issue, so please find it below.
Quoted 4 lines
The reason I hadn't applied your patch #2 yet is because I thought it triggered the splat reported in this thread. But later emails seem to suggest this is a separate/pre-existing issue?
Right. I think that is a separate (PI related) issue. But we could also wait for that to be nailed down and then apply all the fixes at once. As you think is better.
Thanks,
- Juri
Quoted 1 line
From
af75e5f56c9eafacfddad79485149e2e2cb889b9Mon Sep 17 00:00:00 2001
From: Juri Lelli <[email protected]>
Date: Tue, 7 Oct 2014 09:52:11 +0100
Subject: [PATCH] sched/deadline: ensure that updates to exclusive cpusets
don't break AC
How we deal with updates to exclusive cpusets is currently broken. As an example, suppose we have an exclusive cpuset composed of two cpus: A[cpu0,cpu1]. We can assign SCHED_DEADLINE task to it up to the allowed bandwidth. If we want now to modify cpusetA's cpumask, we have to check that removing a cpu's amount of bandwidth doesn't break AC guarantees. This thing isn't checked in the current code.
This patch fixes the problem above, denying an update if the new cpumask won't have enough bandwidth for SCHED_DEADLINE tasks that are currently active.
--- include/linux/sched.h | 2 ++ kernel/cpuset.c | 10 ++++++++++ kernel/sched/core.c | 19 +++++++++++++++++++ 3 files changed, 31 insertions(+)
include/linux/sched.h +2 -0
@@ -2041,6 +2041,8 @@ static inline void tsk_restore_flags(struct task_struct *task, task->flags |= orig_flags & flags; } +extern int cpuset_cpumask_can_shrink (const struct cpumask *cur, +const struct cpumask *trial);extern int task_can_attach (struct task_struct *p,const struct cpumask *cs_cpus_allowed);#ifdef CONFIG_SMP
kernel/cpuset.c +10 -0
@@ -506,6 +506,16 @@ static int validate_change(struct cpuset *cur, struct cpuset *trial) goto out; } +/* +* We can't shrink if we won't have enough room for SCHED_DEADLINE +* tasks. +*/ + ret = -EBUSY ; +if (is_cpu_exclusive (cur) && + !cpuset_cpumask_can_shrink (cur->cpus_allowed, + trial->cpus_allowed)) + goto out; + ret =0 ; out:rcu_read_unlock ();
kernel/sched/core.c +19 -0
@@ -4587,6 +4587,25 @@ void init_idle(struct task_struct *idle, int cpu)#endif } +int cpuset_cpumask_can_shrink (const struct cpumask *cur, +const struct cpumask *trial) +{ +int ret =1 , trial_cpus; +struct dl_bw *cur_dl_b; +unsigned long flags; + + cur_dl_b =dl_bw_of (cpumask_any (cur)); + trial_cpus =cpumask_weight (trial); + +raw_spin_lock_irqsave (&cur_dl_b->lock, flags); +if (cur_dl_b->bw !=-1 && + cur_dl_b->bw * trial_cpus < cur_dl_b->total_bw) + ret =0 ; +raw_spin_unlock_irqrestore (&cur_dl_b->lock, flags); + +return ret; +} +int task_can_attach (struct task_struct *p,const struct cpumask *cs_cpus_allowed) {
Signature · 1 line
2.1.0
tip-bot for Juri Lelli
merge bot[tip:sched/core] sched/deadline: Ensure that updates to exclusive cpusets don't break AC
sched/deadline: Ensure that updates to exclusive cpusets don't break AC
Commit-ID: f82f80426f7afcf55953924e71555984a4bd6ce6 Gitweb: http://git.kernel.org/tip/f82f80426f7afcf55953924e71555984a4bd6ce6 Author: Juri Lelli <[email protected]> AuthorDate: Tue, 7 Oct 2014 09:52:11 +0100 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 28 Oct 2014 10:48:00 +0100
sched/deadline: Ensure that updates to exclusive cpusets don't break AC
How we deal with updates to exclusive cpusets is currently broken. As an example, suppose we have an exclusive cpuset composed of two cpus: A[cpu0,cpu1]. We can assign SCHED_DEADLINE task to it up to the allowed bandwidth. If we want now to modify cpusetA's cpumask, we have to check that removing a cpu's amount of bandwidth doesn't break AC guarantees. This thing isn't checked in the current code.
This patch fixes the problem above, denying an update if the new cpumask won't have enough bandwidth for SCHED_DEADLINE tasks that are currently active.
--- include/linux/sched.h | 2 ++ kernel/cpuset.c | 10 ++++++++++ kernel/sched/core.c | 19 +++++++++++++++++++ 3 files changed, 31 insertions(+)
include/linux/sched.h +2 -0
@@ -2052,6 +2052,8 @@ static inline void tsk_restore_flags(struct task_struct *task, task->flags |= orig_flags & flags; } +extern int cpuset_cpumask_can_shrink (const struct cpumask *cur, +const struct cpumask *trial);extern int task_can_attach (struct task_struct *p,const struct cpumask *cs_cpus_allowed);#ifdef CONFIG_SMP
kernel/cpuset.c +10 -0
@@ -506,6 +506,16 @@ static int validate_change(struct cpuset *cur, struct cpuset *trial) goto out; } +/* +* We can't shrink if we won't have enough room for SCHED_DEADLINE +* tasks. +*/ + ret = -EBUSY ; +if (is_cpu_exclusive (cur) && + !cpuset_cpumask_can_shrink (cur->cpus_allowed, + trial->cpus_allowed)) + goto out; + ret =0 ; out:rcu_read_unlock ();
kernel/sched/core.c +19 -0
@@ -4650,6 +4650,25 @@ void init_idle(struct task_struct *idle, int cpu)#endif } +int cpuset_cpumask_can_shrink (const struct cpumask *cur, +const struct cpumask *trial) +{ +int ret =1 , trial_cpus; +struct dl_bw *cur_dl_b; +unsigned long flags; + + cur_dl_b =dl_bw_of (cpumask_any (cur)); + trial_cpus =cpumask_weight (trial); + +raw_spin_lock_irqsave (&cur_dl_b->lock, flags); +if (cur_dl_b->bw !=-1 && + cur_dl_b->bw * trial_cpus < cur_dl_b->total_bw) + ret =0 ; +raw_spin_unlock_irqrestore (&cur_dl_b->lock, flags); + +return ret; +} +int task_can_attach (struct task_struct *p,const struct cpumask *cs_cpus_allowed) {
Re: [PATCH 2/3] sched/deadline: fix bandwidth check/update when migrating tasks between exclusive cpusets
In reply to Juri LelliHello,
Quoted 14 lines · Juri Lelli
Exclusive cpusets are the only way users can restrict
SCHED_DEADLINEtasks affinity (performing what is commonly called clustered scheduling). Unfortunately, such thing is currently broken for two reasons:- No check is performed when the user tries to attach a task to an exlusive cpuset (recall that exclusive cpusets have an associated maximum allowed bandwidth).
- Bandwidths of source and destination cpusets are not correctly updated after a task is migrated between them.
This patch fixes both things at once, as they are opposite faces of the same coin.
Quoted 8 lines
The check is performed in
cpuset_can_attach(), as there aren't any points of failure after that function. The updated is split in two halves. We first reserve bandwidth in the destination cpuset, after we pass the check incpuset_can_attach(). And we then release bandwidth from the source cpuset when the task's affinity is actually changed. Even if there can be time windows whensched_setattr()may erroneously fail in the source cpuset, we are fine with it, as we can't perfom an atomic update of both cpusets at once.
Thanks, this seems to fix the other problem I had. However, this bug, which I never had before, now happens randomly (with or without patch 3/3):
Sep 19 09:54:37 starbuck kernel: [ 1309.728678] ------------[ cut here ]------------ Sep 19 09:54:37 starbuck kernel: [ 1309.728699] kernel BUG at kernel/sched/deadline.c:819! Sep 19 09:54:37 starbuck kernel: [ 1309.728719] invalid opcode: 0000 [#1] PREEMPT SMP Sep 19 09:54:37 starbuck kernel: [ 1309.728744] Modules linked in: nfsv3 rpcsec_gss_krb5 nfsv4 dm_crypt nfsd auth_rpcgss oid_registry exportfs nfs_acl nfs lockd sunrpc bridge stp llc lp coretemp kvm_intel kvm ppdev ioatdma microcode ipmi_si parport_pc lpc_ich dca mfd_core parport ipmi_msghandler joydev serio_raw hid_generic usbhid hid crc32c_intel psmouse e1000e ptp pps_core Sep 19 09:54:37 starbuck kernel: [ 1309.728928] CPU: 5 PID: 0 Comm: swapper/5 Not tainted 3.16.0+ #20 Sep 19 09:54:37 starbuck kernel: [ 1309.728950] Hardware name: empty empty/S7002, BIOS 'V1.10.B10 ' 05/03/2011 Sep 19 09:54:37 starbuck kernel: [ 1309.728977] task: ffff88023691c920 ti: ffff88023692c000 task.ti: ffff88023692c000 Sep 19 09:54:37 starbuck kernel: [ 1309.729003] RIP: 0010:[<ffffffff810a543e>] [<ffffffff810a543e>] enqueue_task_dl+0x44e/0x450 Sep 19 09:54:37 starbuck kernel: [ 1309.729041] RSP: 0018:ffff88043fc23e68 EFLAGS: 00010082 Sep 19 09:54:37 starbuck kernel: [ 1309.729060] RAX: 0000000000000000 RBX: ffff880434edb0c0 RCX: ffff880434edb2f8 Sep 19 09:54:37 starbuck kernel: [ 1309.729086] RDX: 0000000000000008 RSI: ffff880434edb0c0 RDI: 0000000000000000 Sep 19 09:54:37 starbuck kernel: [ 1309.729140] RBP: ffff88043fc23ea8 R08: 0000000000000001 R09: 000002cb4aebb39d Sep 19 09:54:37 starbuck kernel: [ 1309.729193] R10: 13955a8129438cf2 R11: 0000000000000202 R12: 0000000000000008 Sep 19 09:54:37 starbuck kernel: [ 1309.729247] R13: ffff88043fc33f00 R14: ffff88043fc2e0e0 R15: ffff880434edb2f8 Sep 19 09:54:37 starbuck kernel: [ 1309.729301] FS: 0000000000000000(0000) GS:ffff88043fc20000(0000) knlGS:0000000000000000 Sep 19 09:54:37 starbuck kernel: [ 1309.729383] CS: 0010 DS: 0000 ES: 0000 CR0: 000000008005003b Sep 19 09:54:37 starbuck kernel: [ 1309.729436] CR2: 0000000000000000 CR3: 0000000435a07000 CR4: 00000000000027e0
My script launches 6 processes and schedules them on 2 cpusets where each cpuset contains only one cpu. It moves processes from one cpuset to another and also updates their runtime. I can investigate more and try to provide a short script to reproduce if needed.
Thanks,
Vincent
Re: [PATCH 2/3] sched/deadline: fix bandwidth check/update when migrating tasks between exclusive cpusets
Hi Vincent,
Quoted 40 lines · Vincent Legout
Hello,
Quoted 14 lines · Juri Lelli
Exclusive cpusets are the only way users can restrict
SCHED_DEADLINEtasks affinity (performing what is commonly called clustered scheduling). Unfortunately, such thing is currently broken for two reasons:- No check is performed when the user tries to attach a task to an exlusive cpuset (recall that exclusive cpusets have an associated maximum allowed bandwidth).
- Bandwidths of source and destination cpusets are not correctly updated after a task is migrated between them.
This patch fixes both things at once, as they are opposite faces of the same coin.
Quoted 8 lines
The check is performed in
cpuset_can_attach(), as there aren't any points of failure after that function. The updated is split in two halves. We first reserve bandwidth in the destination cpuset, after we pass the check incpuset_can_attach(). And we then release bandwidth from the source cpuset when the task's affinity is actually changed. Even if there can be time windows whensched_setattr()may erroneously fail in the source cpuset, we are fine with it, as we can't perfom an atomic update of both cpusets at once.Thanks, this seems to fix the other problem I had. However, this bug, which I never had before, now happens randomly (with or without patch 3/3):
Sep 19 09:54:37 starbuck kernel: [ 1309.728678] ------------[ cut here ]------------ Sep 19 09:54:37 starbuck kernel: [ 1309.728699] kernel BUG at kernel/sched/deadline.c:819! Sep 19 09:54:37 starbuck kernel: [ 1309.728719] invalid opcode: 0000 [#1] PREEMPT SMP Sep 19 09:54:37 starbuck kernel: [ 1309.728744] Modules linked in: nfsv3 rpcsec_gss_krb5 nfsv4 dm_crypt nfsd auth_rpcgss oid_registry exportfs nfs_acl nfs lockd sunrpc bridge stp llc lp coretemp kvm_intel kvm ppdev ioatdma microcode ipmi_si parport_pc lpc_ich dca mfd_core parport ipmi_msghandler joydev serio_raw hid_generic usbhid hid crc32c_intel psmouse e1000e ptp pps_core Sep 19 09:54:37 starbuck kernel: [ 1309.728928] CPU: 5 PID: 0 Comm: swapper/5 Not tainted 3.16.0+ #20 Sep 19 09:54:37 starbuck kernel: [ 1309.728950] Hardware name: empty empty/S7002, BIOS 'V1.10.B10 ' 05/03/2011 Sep 19 09:54:37 starbuck kernel: [ 1309.728977] task: ffff88023691c920 ti: ffff88023692c000 task.ti: ffff88023692c000 Sep 19 09:54:37 starbuck kernel: [ 1309.729003] RIP: 0010:[<ffffffff810a543e>] [<ffffffff810a543e>] enqueue_task_dl+0x44e/0x450 Sep 19 09:54:37 starbuck kernel: [ 1309.729041] RSP: 0018:ffff88043fc23e68 EFLAGS: 00010082
Quoted 9 lines
Sep 19 09:54:37 starbuck kernel: [ 1309.729060] RAX: 0000000000000000 RBX: ffff880434edb0c0 RCX: ffff880434edb2f8 Sep 19 09:54:37 starbuck kernel: [ 1309.729086] RDX: 0000000000000008 RSI: ffff880434edb0c0 RDI: 0000000000000000 Sep 19 09:54:37 starbuck kernel: [ 1309.729140] RBP: ffff88043fc23ea8 R08: 0000000000000001 R09: 000002cb4aebb39d Sep 19 09:54:37 starbuck kernel: [ 1309.729193] R10: 13955a8129438cf2 R11: 0000000000000202 R12: 0000000000000008 Sep 19 09:54:37 starbuck kernel: [ 1309.729247] R13: ffff88043fc33f00 R14: ffff88043fc2e0e0 R15: ffff880434edb2f8 Sep 19 09:54:37 starbuck kernel: [ 1309.729301] FS: 0000000000000000(0000) GS:ffff88043fc20000(0000) knlGS:0000000000000000 Sep 19 09:54:37 starbuck kernel: [ 1309.729383] CS: 0010 DS: 0000 ES: 0000 CR0: 000000008005003b Sep 19 09:54:37 starbuck kernel: [ 1309.729436] CR2: 0000000000000000 CR3: 0000000435a07000 CR4: 00000000000027e0
This can be related to the problems Daniel is also experiencing.
Quoted 5 lines
My script launches 6 processes and schedules them on 2 cpusets where each cpuset contains only one cpu. It moves processes from one cpuset to another and also updates their runtime. I can investigate more and try to provide a short script to reproduce if needed.
I should be able to dig into this next week. But yes, in the meantime a script would be useful to reproduce the problem.
Thanks,
- Juri
Re: [PATCH 2/3] sched/deadline: fix bandwidth check/update when migrating tasks between exclusive cpusets
Hi,
Quoted 19 lines · Juri Lelli
Quoted 9 lines
Sep 19 09:54:37 starbuck kernel: [ 1309.728678] ------------[ cut here ]------------ Sep 19 09:54:37 starbuck kernel: [ 1309.728699] kernel BUG at kernel/sched/deadline.c:819! Sep 19 09:54:37 starbuck kernel: [ 1309.728719] invalid opcode: 0000 [#1] PREEMPT SMP Sep 19 09:54:37 starbuck kernel: [ 1309.728744] Modules linked in: nfsv3 rpcsec_gss_krb5 nfsv4 dm_crypt nfsd auth_rpcgss oid_registry exportfs nfs_acl nfs lockd sunrpc bridge stp llc lp coretemp kvm_intel kvm ppdev ioatdma microcode ipmi_si parport_pc lpc_ich dca mfd_core parport ipmi_msghandler joydev serio_raw hid_generic usbhid hid crc32c_intel psmouse e1000e ptp pps_core Sep 19 09:54:37 starbuck kernel: [ 1309.728928] CPU: 5 PID: 0 Comm: swapper/5 Not tainted 3.16.0+ #20 Sep 19 09:54:37 starbuck kernel: [ 1309.728950] Hardware name: empty empty/S7002, BIOS 'V1.10.B10 ' 05/03/2011 Sep 19 09:54:37 starbuck kernel: [ 1309.728977] task: ffff88023691c920 ti: ffff88023692c000 task.ti: ffff88023692c000 Sep 19 09:54:37 starbuck kernel: [ 1309.729003] RIP: 0010:[<ffffffff810a543e>] [<ffffffff810a543e>] enqueue_task_dl+0x44e/0x450 Sep 19 09:54:37 starbuck kernel: [ 1309.729041] RSP: 0018:ffff88043fc23e68 EFLAGS: 00010082Quoted 9 lines
Sep 19 09:54:37 starbuck kernel: [ 1309.729060] RAX: 0000000000000000 RBX: ffff880434edb0c0 RCX: ffff880434edb2f8 Sep 19 09:54:37 starbuck kernel: [ 1309.729086] RDX: 0000000000000008 RSI: ffff880434edb0c0 RDI: 0000000000000000 Sep 19 09:54:37 starbuck kernel: [ 1309.729140] RBP: ffff88043fc23ea8 R08: 0000000000000001 R09: 000002cb4aebb39d Sep 19 09:54:37 starbuck kernel: [ 1309.729193] R10: 13955a8129438cf2 R11: 0000000000000202 R12: 0000000000000008 Sep 19 09:54:37 starbuck kernel: [ 1309.729247] R13: ffff88043fc33f00 R14: ffff88043fc2e0e0 R15: ffff880434edb2f8 Sep 19 09:54:37 starbuck kernel: [ 1309.729301] FS: 0000000000000000(0000) GS:ffff88043fc20000(0000) knlGS:0000000000000000 Sep 19 09:54:37 starbuck kernel: [ 1309.729383] CS: 0010 DS: 0000 ES: 0000 CR0: 000000008005003b Sep 19 09:54:37 starbuck kernel: [ 1309.729436] CR2: 0000000000000000 CR3: 0000000435a07000 CR4: 00000000000027e0
Quoted 1 line
This can be related to the problems Daniel is also experiencing.
I nailed my problem down to mutex with PI inheritance. This will trigger
kernel BUG at kernel/sched/deadline.c:819!
reliable.
cheers,
daniel
tip-bot for Juri Lelli
merge bot[tip:sched/core] sched/deadline: Fix bandwidth check/ update when migrating tasks between exclusive cpusets
In reply to Juri Lellisched/deadline: Fix bandwidth check/update when migrating tasks between exclusive cpusets
Commit-ID: 7f51412a415d87ea8598d14722fb31e4f5701257 Gitweb: http://git.kernel.org/tip/7f51412a415d87ea8598d14722fb31e4f5701257 Author: Juri Lelli <[email protected]> AuthorDate: Fri, 19 Sep 2014 10:22:40 +0100 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 28 Oct 2014 10:47:58 +0100
sched/deadline: Fix bandwidth check/update when migrating tasks between exclusive cpusets
Exclusive cpusets are the only way users can restrict SCHED_DEADLINE tasks affinity (performing what is commonly called clustered scheduling). Unfortunately, such thing is currently broken for two reasons:
- No check is performed when the user tries to attach a task to an exlusive cpuset (recall that exclusive cpusets have an associated maximum allowed bandwidth).
- Bandwidths of source and destination cpusets are not correctly updated after a task is migrated between them.
This patch fixes both things at once, as they are opposite faces of the same coin.
The check is performed in cpuset_can_attach(), as there aren't any points of failure after that function. The updated is split in two halves. We first reserve bandwidth in the destination cpuset, after we pass the check in cpuset_can_attach(). And we then release bandwidth from the source cpuset when the task's affinity is actually changed. Even if there can be time windows when sched_setattr() may erroneously fail in the source cpuset, we are fine with it, as we can't perfom an atomic update of both cpusets at once.
--- include/linux/sched.h | 2 ++ kernel/cpuset.c | 13 ++------- kernel/sched/core.c | 70 +++++++++++++++++++++++++++++++++++-------------- kernel/sched/deadline.c | 25 ++++++++++++++++-- kernel/sched/sched.h | 19 ++++++++++++++ 5 files changed, 97 insertions(+), 32 deletions(-)
include/linux/sched.h +2 -0
@@ -2052,6 +2052,8 @@ static inline void tsk_restore_flags(struct task_struct *task, task->flags |= orig_flags & flags; } +extern int task_can_attach (struct task_struct *p, +const struct cpumask *cs_cpus_allowed);#ifdef CONFIG_SMP extern void do_set_cpus_allowed (struct task_struct *p,const struct cpumask *new_mask);
kernel/cpuset.c +2 -11
@@ -1429,17 +1429,8 @@ static int cpuset_can_attach(struct cgroup_subsys_state *css, goto out_unlock;cgroup_taskset_for_each (task, tset) { -/* -* Kthreads which disallow setaffinity shouldn't be moved -* to a new cpuset; we don't want to change their cpu -* affinity and isolating such threads by their set of -* allowed nodes is unnecessary. Thus, cpusets are not -* applicable for such threads. This prevents checking for -* success of set_cpus_allowed_ptr() on all attached tasks -* before cpus_allowed may be changed. -*/ - ret = -EINVAL ; -if (task->flags &PF_NO_SETAFFINITY ) + ret =task_can_attach (task, cs->cpus_allowed); +if (ret) goto out_unlock; ret =security_task_setscheduler (task);if (ret)
kernel/sched/core.c +51 -19
82 lines not on this page · raw message
kernel/sched/deadline.c +23 -2
@@ -1517,10 +1517,33 @@ static void set_cpus_allowed_dl(struct task_struct *p, const struct cpumask *new_mask) {struct rq *rq; +struct root_domain *src_rd;int weight;BUG_ON (!dl_task (p)); + rq =task_rq (p); + src_rd = rq->rd; +/* +* Migrating a SCHED_DEADLINE task between exclusive +* cpusets (different root_domains) entails a bandwidth +* update. We already made space for us in the destination +* domain (see cpuset_can_attach()). +*/ +if (!cpumask_intersects (src_rd->span, new_mask)) { +struct dl_bw *src_dl_b; + + src_dl_b =dl_bw_of (cpu_of (rq)); +/* +* We now free resources of the root_domain we are migrating +* off. In the worst case, sched_setattr() may temporary fail +* until we complete the update. +*/ +raw_spin_lock (&src_dl_b->lock); +__dl_clear (src_dl_b, p->dl.dl_bw); +raw_spin_unlock (&src_dl_b->lock); + } +/* * Update only if the task is actually running (i.e., * it is on the rq AND it is not throttled).
@@ -1537,8 +1560,6 @@ static void set_cpus_allowed_dl(struct task_struct *p,if ((p->nr_cpus_allowed >1 ) == (weight >1 ))return ; - rq =task_rq (p); -/* * The process used to be able to migrate OR it can now migrate */
kernel/sched/sched.h +19 -0
@@ -176,6 +176,25 @@ struct dl_bw {u64 bw, total_bw; }; +static inline +void __dl_clear (struct dl_bw *dl_b,u64 tsk_bw) +{ + dl_b->total_bw -= tsk_bw; +} + +static inline +void __dl_add (struct dl_bw *dl_b,u64 tsk_bw) +{ + dl_b->total_bw += tsk_bw; +} + +static inline +bool __dl_overflow (struct dl_bw *dl_b,int cpus,u64 old_bw,u64 new_bw) +{ +return dl_b->bw !=-1 && + dl_b->bw * cpus < dl_b->total_bw - old_bw + new_bw; +} +extern struct mutex sched_domains_mutex;#ifdef CONFIG_CGROUP_SCHED
PATCH 3/3 sched/deadline: fix inter- exclusive cpusets migrations
In reply to Juri LelliUsers can perform clustered scheduling using the cpuset facility. After an exclusive cpuset is created, task migrations happen only between CPUs belonging to the same cpuset. Inter- cpuset migrations can only happen when the user requires so, moving a task between different cpusets. This behaviour is broken in SCHED_DEADLINE, as currently spurious inter- cpuset migration may happen without user intervention.
This patch fix the problem (and shuffles the code a bit to improve clarity).
--- kernel/sched/cpudeadline.c | 4 +--- kernel/sched/deadline.c | 7 +++++++ 2 files changed, 8 insertions(+), 3 deletions(-)
kernel/sched/cpudeadline.c +1 -3
@@ -107,9 +107,7 @@ int cpudl_find(struct cpudl *cp, struct task_struct *p,int best_cpu =-1 ;const struct sched_dl_entity *dl_se = &p->dl; -if (later_mask &&cpumask_and (later_mask, cp->free_cpus, - &p->cpus_allowed) &&cpumask_and (later_mask, - later_mask, cpu_active_mask)) { +if (later_mask &&cpumask_and (later_mask, later_mask, cp->free_cpus)) { best_cpu =cpumask_any (later_mask); goto out; } else if (cpumask_test_cpu(cpudl_maximum(cp), &p->cpus_allowed) &&
kernel/sched/deadline.c +7 -0
@@ -1169,6 +1169,13 @@ static int find_later_rq(struct task_struct *task)if (task->nr_cpus_allowed ==1 )return -1 ; +/* +* We have to consider system topology and task affinity +* first, then we can look for a suitable cpu. +*/ +cpumask_copy (later_mask,task_rq (task)->rd->span); +cpumask_and (later_mask, later_mask, cpu_active_mask); +cpumask_and (later_mask, later_mask, &task->cpus_allowed); best_cpu =cpudl_find (&task_rq (task)->rd->cpudl, task, later_mask);if (best_cpu ==-1 )
Signature · 1 line
2.1.0
tip-bot for Juri Lelli
merge bot[tip:sched/core] sched/deadline: Fix inter- exclusive cpusets migrations
sched/deadline: Fix inter- exclusive cpusets migrations
Commit-ID: 91ec6778ec4f963fcb2c2793610919b572f633b0 Gitweb: http://git.kernel.org/tip/91ec6778ec4f963fcb2c2793610919b572f633b0 Author: Juri Lelli <[email protected]> AuthorDate: Fri, 19 Sep 2014 10:22:41 +0100 Committer: Ingo Molnar <[email protected]> CommitDate: Wed, 24 Sep 2014 14:46:57 +0200
sched/deadline: Fix inter- exclusive cpusets migrations
Users can perform clustered scheduling using the cpuset facility. After an exclusive cpuset is created, task migrations happen only between CPUs belonging to the same cpuset. Inter- cpuset migrations can only happen when the user requires so, moving a task between different cpusets. This behaviour is broken in SCHED_DEADLINE, as currently spurious inter- cpuset migration may happen without user intervention.
This patch fix the problem (and shuffles the code a bit to improve clarity).
--- kernel/sched/cpudeadline.c | 4 +--- kernel/sched/deadline.c | 7 +++++++ 2 files changed, 8 insertions(+), 3 deletions(-)
kernel/sched/cpudeadline.c +1 -3
@@ -107,9 +107,7 @@ int cpudl_find(struct cpudl *cp, struct task_struct *p,int best_cpu =-1 ;const struct sched_dl_entity *dl_se = &p->dl; -if (later_mask &&cpumask_and (later_mask, cp->free_cpus, - &p->cpus_allowed) &&cpumask_and (later_mask, - later_mask, cpu_active_mask)) { +if (later_mask &&cpumask_and (later_mask, later_mask, cp->free_cpus)) { best_cpu =cpumask_any (later_mask); goto out; } else if (cpumask_test_cpu(cpudl_maximum(cp), &p->cpus_allowed) &&
kernel/sched/deadline.c +7 -0
@@ -1164,6 +1164,13 @@ static int find_later_rq(struct task_struct *task)if (task->nr_cpus_allowed ==1 )return -1 ; +/* +* We have to consider system topology and task affinity +* first, then we can look for a suitable cpu. +*/ +cpumask_copy (later_mask,task_rq (task)->rd->span); +cpumask_and (later_mask, later_mask, cpu_active_mask); +cpumask_and (later_mask, later_mask, &task->cpus_allowed); best_cpu =cpudl_find (&task_rq (task)->rd->cpudl, task, later_mask);if (best_cpu ==-1 )