Re: [PATCH 06/16] sched: SCHED_DEADLINE push and pull logic

From: Hillf Danton
Date: Fri Apr 06 2012 - 09:39:46 EST


Hello

On Fri, Apr 6, 2012 at 3:14 PM, Juri Lelli <juri.lelli@xxxxxxxxx> wrote:
> Add dynamic migrations to SCHED_DEADLINE, so that tasks can
> be moved among CPUs when necessary. It is also possible to bind a
> task to a (set of) CPU(s), thus restricting its capability of
> migrating, or forbidding migrations at all.
>
> The very same approach used in sched_rt is utilised:
> Â- -deadline tasks are kept into CPU-specific runqueues,
> Â- -deadline tasks are migrated among runqueues to achieve the
> Â following:
> Â Â* on an M-CPU system the M earliest deadline ready tasks
> Â Â Âare always running;
> Â Â* affinity/cpusets settings of all the -deadline tasks is
> Â Â Âalways respected.
>
> Therefore, this very special form of "load balancing" is done with
> an active method, i.e., the scheduler pushes or pulls tasks between
> runqueues when they are woken up and/or (de)scheduled.
> IOW, every time a preemption occurs, the descheduled task might be sent
> to some other CPU (depending on its deadline) to continue executing
> (push). On the other hand, every time a CPU becomes idle, it might pull
> the second earliest deadline ready task from some other CPU.
>
> To enforce this, a pull operation is always attempted before taking any
> scheduling decision (pre_schedule()), as well as a push one after each
> scheduling decision (post_schedule()). In addition, when a task arrives
> or wakes up, the best CPU where to resume it is selected taking into
> account its affinity mask, the system topology, but also its deadline.
> E.g., from the scheduling point of view, the best CPU where to wake
> up (and also where to push) a task is the one which is running the task
> with the latest deadline among the M executing ones.
>
> In order to facilitate these decisions, per-runqueue "caching" of the
> deadlines of the currently running and of the first ready task is used.
> Queued but not running tasks are also parked in another rb-tree to
> speed-up pushes.
>
> Signed-off-by: Juri Lelli <juri.lelli@xxxxxxxxx>
> Signed-off-by: Dario Faggioli <raistlin@xxxxxxxx>
> ---
> Âkernel/sched_dl.c | Â912 +++++++++++++++++++++++++++++++++++++++++++++++++++--
> Âkernel/sched_rt.c | Â Â2 +-
> Â2 files changed, 889 insertions(+), 25 deletions(-)
>
> diff --git a/kernel/sched_dl.c b/kernel/sched_dl.c
> index 604e2bc..38edefa 100644
> --- a/kernel/sched_dl.c
> +++ b/kernel/sched_dl.c
> @@ -10,6 +10,7 @@
> Â* miss some of their deadlines), and won't affect any other task.
> Â*
> Â* Copyright (C) 2010 Dario Faggioli <raistlin@xxxxxxxx>,
> + * Â Â Â Â Â Â Â Â Â ÂJuri Lelli <juri.lelli@xxxxxxxxx>,
> Â* Â Â Â Â Â Â Â Â Â ÂMichael Trimarchi <michael@xxxxxxxxxxxxxxxxxxxx>,
> Â* Â Â Â Â Â Â Â Â Â ÂFabio Checconi <fabio@xxxxxxxxxxxxxxxx>
> Â*/
> @@ -20,6 +21,15 @@ static inline int dl_time_before(u64 a, u64 b)
> Â Â Â Âreturn (s64)(a - b) < 0;
> Â}
>
> +/*
> + * Tells if entity @a should preempt entity @b.
> + */
> +static inline
> +int dl_entity_preempt(struct sched_dl_entity *a, struct sched_dl_entity *b)
> +{
> + Â Â Â return dl_time_before(a->deadline, b->deadline);
> +}
> +
> Âstatic inline struct task_struct *dl_task_of(struct sched_dl_entity *dl_se)
> Â{
> Â Â Â Âreturn container_of(dl_se, struct task_struct, dl);
> @@ -50,6 +60,153 @@ static inline int is_leftmost(struct task_struct *p, struct dl_rq *dl_rq)
> Â Â Â Âreturn dl_rq->rb_leftmost == &dl_se->rb_node;
> Â}
>
> +#ifdef CONFIG_SMP
> +
> +static inline int dl_overloaded(struct rq *rq)
> +{
> + Â Â Â return atomic_read(&rq->rd->dlo_count);
> +}
> +
> +static inline void dl_set_overload(struct rq *rq)
> +{
> + Â Â Â if (!rq->online)
> + Â Â Â Â Â Â Â return;
> +
> + Â Â Â cpumask_set_cpu(rq->cpu, rq->rd->dlo_mask);
> + Â Â Â /*
> + Â Â Â Â* Must be visible before the overload count is
> + Â Â Â Â* set (as in sched_rt.c).
> + Â Â Â Â*/
> + Â Â Â wmb();
> + Â Â Â atomic_inc(&rq->rd->dlo_count);
> +}
> +
> +static inline void dl_clear_overload(struct rq *rq)
> +{
> + Â Â Â if (!rq->online)
> + Â Â Â Â Â Â Â return;
> +
> + Â Â Â atomic_dec(&rq->rd->dlo_count);
> + Â Â Â cpumask_clear_cpu(rq->cpu, rq->rd->dlo_mask);
> +}
> +
> +static void update_dl_migration(struct dl_rq *dl_rq)
> +{
> + Â Â Â if (dl_rq->dl_nr_migratory && dl_rq->dl_nr_total > 1) {
> + Â Â Â Â Â Â Â if (!dl_rq->overloaded) {
> + Â Â Â Â Â Â Â Â Â Â Â dl_set_overload(rq_of_dl_rq(dl_rq));
> + Â Â Â Â Â Â Â Â Â Â Â dl_rq->overloaded = 1;
> + Â Â Â Â Â Â Â }
> + Â Â Â } else if (dl_rq->overloaded) {
> + Â Â Â Â Â Â Â dl_clear_overload(rq_of_dl_rq(dl_rq));
> + Â Â Â Â Â Â Â dl_rq->overloaded = 0;
> + Â Â Â }
> +}
> +
> +static void inc_dl_migration(struct sched_dl_entity *dl_se, struct dl_rq *dl_rq)
> +{
> + Â Â Â dl_rq = &rq_of_dl_rq(dl_rq)->dl;
> +
> + Â Â Â dl_rq->dl_nr_total++;
> + Â Â Â if (dl_se->nr_cpus_allowed > 1)
> + Â Â Â Â Â Â Â dl_rq->dl_nr_migratory++;
> +
> + Â Â Â update_dl_migration(dl_rq);

if (dl_se->nr_cpus_allowed > 1) {
dl_rq->dl_nr_migratory++;
/* No change in migratory, no update of migration */
update_dl_migration(dl_rq);
}

> +}
> +
> +static void dec_dl_migration(struct sched_dl_entity *dl_se, struct dl_rq *dl_rq)
> +{
> + Â Â Â dl_rq = &rq_of_dl_rq(dl_rq)->dl;
> +
> + Â Â Â dl_rq->dl_nr_total--;
> + Â Â Â if (dl_se->nr_cpus_allowed > 1)
> + Â Â Â Â Â Â Â dl_rq->dl_nr_migratory--;
> +
> + Â Â Â update_dl_migration(dl_rq);

ditto

> +}
> +
> +/*
> + * The list of pushable -deadline task is not a plist, like in
> + * sched_rt.c, it is an rb-tree with tasks ordered by deadline.
> + */
> +static void enqueue_pushable_dl_task(struct rq *rq, struct task_struct *p)
> +{
> + Â Â Â struct dl_rq *dl_rq = &rq->dl;
> + Â Â Â struct rb_node **link = &dl_rq->pushable_dl_tasks_root.rb_node;
> + Â Â Â struct rb_node *parent = NULL;
> + Â Â Â struct task_struct *entry;
> + Â Â Â int leftmost = 1;
> +
> + Â Â Â BUG_ON(!RB_EMPTY_NODE(&p->pushable_dl_tasks));
> +
> + Â Â Â while (*link) {
> + Â Â Â Â Â Â Â parent = *link;
> + Â Â Â Â Â Â Â entry = rb_entry(parent, struct task_struct,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âpushable_dl_tasks);
> + Â Â Â Â Â Â Â if (!dl_entity_preempt(&entry->dl, &p->dl))

if (dl_entity_preempt(&p->dl, &entry->dl))

> + Â Â Â Â Â Â Â Â Â Â Â link = &parent->rb_left;
> + Â Â Â Â Â Â Â else {
> + Â Â Â Â Â Â Â Â Â Â Â link = &parent->rb_right;
> + Â Â Â Â Â Â Â Â Â Â Â leftmost = 0;
> + Â Â Â Â Â Â Â }
> + Â Â Â }
> +
> + Â Â Â if (leftmost)
> + Â Â Â Â Â Â Â dl_rq->pushable_dl_tasks_leftmost = &p->pushable_dl_tasks;
> +
> + Â Â Â rb_link_node(&p->pushable_dl_tasks, parent, link);
> + Â Â Â rb_insert_color(&p->pushable_dl_tasks, &dl_rq->pushable_dl_tasks_root);
> +}
> +
> +static void dequeue_pushable_dl_task(struct rq *rq, struct task_struct *p)
> +{
> + Â Â Â struct dl_rq *dl_rq = &rq->dl;
> +
> + Â Â Â if (RB_EMPTY_NODE(&p->pushable_dl_tasks))
> + Â Â Â Â Â Â Â return;
> +
> + Â Â Â if (dl_rq->pushable_dl_tasks_leftmost == &p->pushable_dl_tasks) {
> + Â Â Â Â Â Â Â struct rb_node *next_node;
> +
> + Â Â Â Â Â Â Â next_node = rb_next(&p->pushable_dl_tasks);
> + Â Â Â Â Â Â Â dl_rq->pushable_dl_tasks_leftmost = next_node;

dl_rq->pushable_dl_tasks_leftmost =
rb_next(&p->pushable_dl_tasks);

> + Â Â Â }
> +
> + Â Â Â rb_erase(&p->pushable_dl_tasks, &dl_rq->pushable_dl_tasks_root);
> + Â Â Â RB_CLEAR_NODE(&p->pushable_dl_tasks);
> +}
> +
> +static inline int has_pushable_dl_tasks(struct rq *rq)
> +{
> + Â Â Â return !RB_EMPTY_ROOT(&rq->dl.pushable_dl_tasks_root);

return rq->dl.pushable_dl_tasks_leftmost != NULL;
> +}
> +
> +static int push_dl_task(struct rq *rq);
> +
> +#else
> +
> +static inline
> +void enqueue_pushable_dl_task(struct rq *rq, struct task_struct *p)
> +{
> +}
> +
> +static inline
> +void dequeue_pushable_dl_task(struct rq *rq, struct task_struct *p)
> +{
> +}
> +
> +static inline
> +void inc_dl_migration(struct sched_dl_entity *dl_se, struct dl_rq *dl_rq)
> +{
> +}
> +
> +static inline
> +void dec_dl_migration(struct sched_dl_entity *dl_se, struct dl_rq *dl_rq)
> +{
> +}
> +
> +#endif /* CONFIG_SMP */
> +
> Âstatic void enqueue_task_dl(struct rq *rq, struct task_struct *p, int flags);
> Âstatic void __dequeue_task_dl(struct rq *rq, struct task_struct *p, int flags);
> Âstatic void check_preempt_curr_dl(struct rq *rq, struct task_struct *p,
> @@ -276,6 +433,14 @@ static enum hrtimer_restart dl_task_timer(struct hrtimer *timer)
> Â Â Â Â Â Â Â Â Â Â Â Âcheck_preempt_curr_dl(rq, p, 0);
> Â Â Â Â Â Â Â Âelse
> Â Â Â Â Â Â Â Â Â Â Â Âresched_task(rq->curr);
> +#ifdef CONFIG_SMP
> + Â Â Â Â Â Â Â /*
> + Â Â Â Â Â Â Â Â* Queueing this task back might have overloaded rq,
> + Â Â Â Â Â Â Â Â* check if we need to kick someone away.
> + Â Â Â Â Â Â Â Â*/
> + Â Â Â Â Â Â Â if (rq->dl.overloaded)
if (has_pushable_dl_tasks(rq))

> + Â Â Â Â Â Â Â Â Â Â Â push_dl_task(rq);
> +#endif
> Â Â Â Â}
> Âunlock:
> Â Â Â Âtask_rq_unlock(rq, p, &flags);
> @@ -359,6 +524,100 @@ static void update_curr_dl(struct rq *rq)
> Â Â Â Â}
> Â}
>
> +#ifdef CONFIG_SMP
> +
> +static struct task_struct *pick_next_earliest_dl_task(struct rq *rq, int cpu);
> +
> +static inline int next_deadline(struct rq *rq)
static inline typeof(next->dl.deadline) next_deadline(struct rq *rq) ?

> +{
> + Â Â Â struct task_struct *next = pick_next_earliest_dl_task(rq, rq->cpu);
> +
> + Â Â Â if (next && dl_prio(next->prio))
> + Â Â Â Â Â Â Â return next->dl.deadline;
> + Â Â Â else
> + Â Â Â Â Â Â Â return 0;
> +}
> +
> +static void inc_dl_deadline(struct dl_rq *dl_rq, u64 deadline)
> +{
> + Â Â Â struct rq *rq = rq_of_dl_rq(dl_rq);
> +
> + Â Â Â if (dl_rq->earliest_dl.curr == 0 ||
> + Â Â Â Â Â dl_time_before(deadline, dl_rq->earliest_dl.curr)) {
> + Â Â Â Â Â Â Â /*
> + Â Â Â Â Â Â Â Â* If the dl_rq had no -deadline tasks, or if the new task
> + Â Â Â Â Â Â Â Â* has shorter deadline than the current one on dl_rq, we
> + Â Â Â Â Â Â Â Â* know that the previous earliest becomes our next earliest,
> + Â Â Â Â Â Â Â Â* as the new task becomes the earliest itself.
> + Â Â Â Â Â Â Â Â*/
> + Â Â Â Â Â Â Â dl_rq->earliest_dl.next = dl_rq->earliest_dl.curr;
> + Â Â Â Â Â Â Â dl_rq->earliest_dl.curr = deadline;
> + Â Â Â } else if (dl_rq->earliest_dl.next == 0 ||
> + Â Â Â Â Â Â Â Â Âdl_time_before(deadline, dl_rq->earliest_dl.next)) {
> + Â Â Â Â Â Â Â /*
> + Â Â Â Â Â Â Â Â* On the other hand, if the new -deadline task has a
> + Â Â Â Â Â Â Â Â* a later deadline than the earliest one on dl_rq, but
> + Â Â Â Â Â Â Â Â* it is earlier than the next (if any), we must
> + Â Â Â Â Â Â Â Â* recompute the next-earliest.
> + Â Â Â Â Â Â Â Â*/
> + Â Â Â Â Â Â Â dl_rq->earliest_dl.next = next_deadline(rq);
> + Â Â Â }
> +}
> +
> +static void dec_dl_deadline(struct dl_rq *dl_rq, u64 deadline)
> +{
> + Â Â Â struct rq *rq = rq_of_dl_rq(dl_rq);
> +
> + Â Â Â /*
> + Â Â Â Â* Since we may have removed our earliest (and/or next earliest)
> + Â Â Â Â* task we must recompute them.
> + Â Â Â Â*/
> + Â Â Â if (!dl_rq->dl_nr_running) {
> + Â Â Â Â Â Â Â dl_rq->earliest_dl.curr = 0;
> + Â Â Â Â Â Â Â dl_rq->earliest_dl.next = 0;
> + Â Â Â } else {
> + Â Â Â Â Â Â Â struct rb_node *leftmost = dl_rq->rb_leftmost;
> + Â Â Â Â Â Â Â struct sched_dl_entity *entry;
> +
> + Â Â Â Â Â Â Â entry = rb_entry(leftmost, struct sched_dl_entity, rb_node);
> + Â Â Â Â Â Â Â dl_rq->earliest_dl.curr = entry->deadline;
> + Â Â Â Â Â Â Â dl_rq->earliest_dl.next = next_deadline(rq);
> + Â Â Â }
> +}
> +
> +#else
> +
> +static inline void inc_dl_deadline(struct dl_rq *dl_rq, u64 deadline) {}
> +static inline void dec_dl_deadline(struct dl_rq *dl_rq, u64 deadline) {}
> +
> +#endif /* CONFIG_SMP */
> +
> +static inline
> +void inc_dl_tasks(struct sched_dl_entity *dl_se, struct dl_rq *dl_rq)
void inc_dl_task(struct sched_dl_entity *dl_se, struct dl_rq *dl_rq)

> +{
> + Â Â Â int prio = dl_task_of(dl_se)->prio;
> + Â Â Â u64 deadline = dl_se->deadline;
> +
> + Â Â Â WARN_ON(!dl_prio(prio));
> + Â Â Â dl_rq->dl_nr_running++;
> +
> + Â Â Â inc_dl_deadline(dl_rq, deadline);
> + Â Â Â inc_dl_migration(dl_se, dl_rq);
> +}
> +
> +static inline
> +void dec_dl_tasks(struct sched_dl_entity *dl_se, struct dl_rq *dl_rq)
void dec_dl_task(struct sched_dl_entity *dl_se, struct dl_rq *dl_rq)

> +{
> + Â Â Â int prio = dl_task_of(dl_se)->prio;
> +
> + Â Â Â WARN_ON(!dl_prio(prio));
> + Â Â Â WARN_ON(!dl_rq->dl_nr_running);
> + Â Â Â dl_rq->dl_nr_running--;
> +
> + Â Â Â dec_dl_deadline(dl_rq, dl_se->deadline);
> + Â Â Â dec_dl_migration(dl_se, dl_rq);
> +}
> +
> Âstatic void __enqueue_dl_entity(struct sched_dl_entity *dl_se)
> Â{
> Â Â Â Âstruct dl_rq *dl_rq = dl_rq_of_se(dl_se);
> @@ -386,7 +645,7 @@ static void __enqueue_dl_entity(struct sched_dl_entity *dl_se)
> Â Â Â Ârb_link_node(&dl_se->rb_node, parent, link);
> Â Â Â Ârb_insert_color(&dl_se->rb_node, &dl_rq->rb_root);
>
> - Â Â Â dl_rq->dl_nr_running++;
> + Â Â Â inc_dl_tasks(dl_se, dl_rq);
> Â}
>
> Âstatic void __dequeue_dl_entity(struct sched_dl_entity *dl_se)
> @@ -406,7 +665,7 @@ static void __dequeue_dl_entity(struct sched_dl_entity *dl_se)
> Â Â Â Ârb_erase(&dl_se->rb_node, &dl_rq->rb_root);
> Â Â Â ÂRB_CLEAR_NODE(&dl_se->rb_node);
>
> - Â Â Â dl_rq->dl_nr_running--;
> + Â Â Â dec_dl_tasks(dl_se, dl_rq);
> Â}
>
> Âstatic void
> @@ -444,11 +703,15 @@ static void enqueue_task_dl(struct rq *rq, struct task_struct *p, int flags)
> Â Â Â Â Â Â Â Âreturn;
>
> Â Â Â Âenqueue_dl_entity(&p->dl, flags);
> +
> + Â Â Â if (!task_current(rq, p) && p->dl.nr_cpus_allowed > 1)
> + Â Â Â Â Â Â Â enqueue_pushable_dl_task(rq, p);
> Â}
>
> Âstatic void __dequeue_task_dl(struct rq *rq, struct task_struct *p, int flags)
> Â{
> Â Â Â Âdequeue_dl_entity(&p->dl);
> + Â Â Â dequeue_pushable_dl_task(rq, p);
> Â}
>
> Âstatic void dequeue_task_dl(struct rq *rq, struct task_struct *p, int flags)
> @@ -480,6 +743,75 @@ static void yield_task_dl(struct rq *rq)
> Â Â Â Âupdate_curr_dl(rq);
> Â}
>
> +#ifdef CONFIG_SMP
> +
> +static int find_later_rq(struct task_struct *task);
> +static int latest_cpu_find(struct cpumask *span,
> + Â Â Â Â Â Â Â Â Â Â Â Â Âstruct task_struct *task,
> + Â Â Â Â Â Â Â Â Â Â Â Â Âstruct cpumask *later_mask);
> +
> +static int
> +select_task_rq_dl(struct task_struct *p, int sd_flag, int flags)
> +{
> + Â Â Â struct task_struct *curr;
> + Â Â Â struct rq *rq;
> + Â Â Â int cpu;
> +
> + Â Â Â if (sd_flag != SD_BALANCE_WAKE)
why is task_cpu(p) not eligible?

> + Â Â Â Â Â Â Â return smp_processor_id();
> +
> + Â Â Â cpu = task_cpu(p);
> + Â Â Â rq = cpu_rq(cpu);
> +
> + Â Â Â rcu_read_lock();
> + Â Â Â curr = ACCESS_ONCE(rq->curr); /* unlocked access */
> +
> + Â Â Â /*
> + Â Â Â Â* If we are dealing with a -deadline task, we must
> + Â Â Â Â* decide where to wake it up.
> + Â Â Â Â* If it has a later deadline and the current task
> + Â Â Â Â* on this rq can't move (provided the waking task
> + Â Â Â Â* can!) we prefer to send it somewhere else. On the
> + Â Â Â Â* other hand, if it has a shorter deadline, we
> + Â Â Â Â* try to make it stay here, it might be important.
> + Â Â Â Â*/
> + Â Â Â if (unlikely(dl_task(rq->curr)) &&
the above ACCESS_ONCE for what?
> + Â Â Â Â Â (rq->curr->dl.nr_cpus_allowed < 2 ||
> + Â Â Â Â Â Âdl_entity_preempt(&rq->curr->dl, &p->dl)) &&
!dl_entity_preempt(&p->dl, &rq->curr->dl)) &&
> + Â Â Â Â Â (p->dl.nr_cpus_allowed > 1)) {
> + Â Â Â Â Â Â Â int target = find_later_rq(p);
> +
> + Â Â Â Â Â Â Â if (target != -1)
> + Â Â Â Â Â Â Â Â Â Â Â cpu = target;
> + Â Â Â }
> + Â Â Â rcu_read_unlock();
> +
> + Â Â Â return cpu;
> +}
> +
> +static void check_preempt_equal_dl(struct rq *rq, struct task_struct *p)
> +{
> + Â Â Â /*
> + Â Â Â Â* Current can't be migrated, useles to reschedule,
> + Â Â Â Â* let's hope p can move out.
> + Â Â Â Â*/
> + Â Â Â if (rq->curr->dl.nr_cpus_allowed == 1 ||
> + Â Â Â Â Â latest_cpu_find(rq->rd->span, rq->curr, NULL) == -1)
> + Â Â Â Â Â Â Â return;
> +
> + Â Â Â /*
> + Â Â Â Â* p is migratable, so let's not schedule it and
> + Â Â Â Â* see if it is pushed or pulled somewhere else.
> + Â Â Â Â*/
> + Â Â Â if (p->dl.nr_cpus_allowed != 1 &&
> + Â Â Â Â Â latest_cpu_find(rq->rd->span, p, NULL) != -1)
> + Â Â Â Â Â Â Â return;
> +
> + Â Â Â resched_task(rq->curr);
> +}
> +
> +#endif /* CONFIG_SMP */
> +
> Â/*
> Â* Only called when both the current and waking task are -deadline
> Â* tasks.
> @@ -487,8 +819,20 @@ static void yield_task_dl(struct rq *rq)
> Âstatic void check_preempt_curr_dl(struct rq *rq, struct task_struct *p,
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âint flags)
> Â{
> - Â Â Â if (dl_time_before(p->dl.deadline, rq->curr->dl.deadline))
> + Â Â Â if (dl_time_before(p->dl.deadline, rq->curr->dl.deadline)) {
if (dl_entity_preempt(&p->dl, &rq->curr->dl))
> Â Â Â Â Â Â Â Âresched_task(rq->curr);
> + Â Â Â Â Â Â Â return;
> + Â Â Â }
> +
> +#ifdef CONFIG_SMP
> + Â Â Â /*
> + Â Â Â Â* In the unlikely case current and p have the same deadline
> + Â Â Â Â* let us try to decide what's the best thing to do...
> + Â Â Â Â*/
> + Â Â Â if ((s64)(p->dl.deadline - rq->curr->dl.deadline) == 0 &&
> + Â Â Â Â Â !need_resched())
please recheck !need_resched(), say rq->curr need reschedule?
> + Â Â Â Â Â Â Â check_preempt_equal_dl(rq, p);
> +#endif /* CONFIG_SMP */
> Â}
>
> Â#ifdef CONFIG_SCHED_HRTICK
> @@ -532,10 +876,20 @@ struct task_struct *pick_next_task_dl(struct rq *rq)
>
> Â Â Â Âp = dl_task_of(dl_se);
> Â Â Â Âp->se.exec_start = rq->clock;
> +
> + Â Â Â /* Running task will never be pushed. */
> + Â Â Â if (p)
> + Â Â Â Â Â Â Â dequeue_pushable_dl_task(rq, p);
> +
> Â#ifdef CONFIG_SCHED_HRTICK
> Â Â Â Âif (hrtick_enabled(rq))
> Â Â Â Â Â Â Â Âstart_hrtick_dl(rq, p);
need to check p is valid?
> Â#endif
> +
> +#ifdef CONFIG_SMP
> + Â Â Â rq->post_schedule = has_pushable_dl_tasks(rq);
> +#endif /* CONFIG_SMP */
> +
> Â Â Â Âreturn p;
> Â}
>
> @@ -543,6 +897,9 @@ static void put_prev_task_dl(struct rq *rq, struct task_struct *p)
> Â{
> Â Â Â Âupdate_curr_dl(rq);
> Â Â Â Âp->se.exec_start = 0;
why seset exec_start?
> +
> + Â Â Â if (on_dl_rq(&p->dl) && p->dl.nr_cpus_allowed > 1)
> + Â Â Â Â Â Â Â enqueue_pushable_dl_task(rq, p);
> Â}
>
> Âstatic void task_tick_dl(struct rq *rq, struct task_struct *p, int queued)
> @@ -576,43 +933,410 @@ static void set_curr_task_dl(struct rq *rq)
> Â Â Â Âstruct task_struct *p = rq->curr;
>
> Â Â Â Âp->se.exec_start = rq->clock;
> +
> + Â Â Â /* You can't push away the running task */
> + Â Â Â dequeue_pushable_dl_task(rq, p);
> Â}
>
> -static void switched_from_dl(struct rq *rq, struct task_struct *p)
> +#ifdef CONFIG_SMP
> +
> +/* Only try algorithms three times */
> +#define DL_MAX_TRIES 3
> +
> +static int pick_dl_task(struct rq *rq, struct task_struct *p, int cpu)
> Â{
> - Â Â Â if (hrtimer_active(&p->dl.dl_timer))
> - Â Â Â Â Â Â Â hrtimer_try_to_cancel(&p->dl.dl_timer);
> + Â Â Â if (!task_running(rq, p) &&
> + Â Â Â Â Â (cpu < 0 || cpumask_test_cpu(cpu, &p->cpus_allowed)) &&
> + Â Â Â Â Â (p->dl.nr_cpus_allowed > 1))
> + Â Â Â Â Â Â Â return 1;
> +
> + Â Â Â return 0;

if (task_running(rq, p))
return 0;
return cpumask_test_cpu(cpu, &p->cpus_allowed);
that is all:)
> Â}
>
> -static void switched_to_dl(struct rq *rq, struct task_struct *p)
> +/* Returns the second earliest -deadline task, NULL otherwise */
> +static struct task_struct *pick_next_earliest_dl_task(struct rq *rq, int cpu)
> +{
> + Â Â Â struct rb_node *next_node = rq->dl.rb_leftmost;
> + Â Â Â struct sched_dl_entity *dl_se;
> + Â Â Â struct task_struct *p = NULL;
> +
> +next_node:
> + Â Â Â next_node = rb_next(next_node);
> + Â Â Â if (next_node) {
> + Â Â Â Â Â Â Â dl_se = rb_entry(next_node, struct sched_dl_entity, rb_node);
> + Â Â Â Â Â Â Â p = dl_task_of(dl_se);
> +
> + Â Â Â Â Â Â Â if (pick_dl_task(rq, p, cpu))
> + Â Â Â Â Â Â Â Â Â Â Â return p;
> +
> + Â Â Â Â Â Â Â goto next_node;
> + Â Â Â }
> +
> + Â Â Â return NULL;
> +}
> +
> +static int latest_cpu_find(struct cpumask *span,
> + Â Â Â Â Â Â Â Â Â Â Â Â Âstruct task_struct *task,
> + Â Â Â Â Â Â Â Â Â Â Â Â Âstruct cpumask *later_mask)
> Â{
> + Â Â Â const struct sched_dl_entity *dl_se = &task->dl;
> + Â Â Â int cpu, found = -1, best = 0;
> + Â Â Â u64 max_dl = 0;
> +
> + Â Â Â for_each_cpu(cpu, span) {
for_each_cpu_and(cpu, span, &task->cpus_allowed) {
> + Â Â Â Â Â Â Â struct rq *rq = cpu_rq(cpu);
> + Â Â Â Â Â Â Â struct dl_rq *dl_rq = &rq->dl;
> +
> + Â Â Â Â Â Â Â if (cpumask_test_cpu(cpu, &task->cpus_allowed) &&
> + Â Â Â Â Â Â Â Â Â (!dl_rq->dl_nr_running || dl_time_before(dl_se->deadline,
> + Â Â Â Â Â Â Â Â Â Âdl_rq->earliest_dl.curr))) {
please use dl_entity_preempt()
> + Â Â Â Â Â Â Â Â Â Â Â if (later_mask)
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â cpumask_set_cpu(cpu, later_mask);
> + Â Â Â Â Â Â Â Â Â Â Â if (!best && !dl_rq->dl_nr_running) {
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â best = 1;
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â found = cpu;
> + Â Â Â Â Â Â Â Â Â Â Â } else if (!best &&
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âdl_time_before(max_dl,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â dl_rq->earliest_dl.curr)) {
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â max_dl = dl_rq->earliest_dl.curr;
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â found = cpu;
> + Â Â Â Â Â Â Â Â Â Â Â }
> + Â Â Â Â Â Â Â } else if (later_mask)
> + Â Â Â Â Â Â Â Â Â Â Â cpumask_clear_cpu(cpu, later_mask);
> + Â Â Â }
> +
> + Â Â Â return found;
> +}
> +
> +static DEFINE_PER_CPU(cpumask_var_t, local_cpu_mask_dl);
> +
> +static int find_later_rq(struct task_struct *task)
> +{
> + Â Â Â struct sched_domain *sd;
> + Â Â Â struct cpumask *later_mask = __get_cpu_var(local_cpu_mask_dl);
please check is local_cpu_mask_dl valid

> + Â Â Â int this_cpu = smp_processor_id();
> + Â Â Â int best_cpu, cpu = task_cpu(task);
> +
> + Â Â Â if (task->dl.nr_cpus_allowed == 1)
> + Â Â Â Â Â Â Â return -1;
> +
> + Â Â Â best_cpu = latest_cpu_find(task_rq(task)->rd->span, task, later_mask);
> + Â Â Â if (best_cpu == -1)
> + Â Â Â Â Â Â Â return -1;
> +
> Â Â Â Â/*
> - Â Â Â Â* If p is throttled, don't consider the possibility
> - Â Â Â Â* of preempting rq->curr, the check will be done right
> - Â Â Â Â* after its runtime will get replenished.
> + Â Â Â Â* If we are here, some target has been found,
> + Â Â Â Â* the most suitable of which is cached in best_cpu.
> + Â Â Â Â* This is, among the runqueues where the current tasks
> + Â Â Â Â* have later deadlines than the task's one, the rq
> + Â Â Â Â* with the latest possible one.
> + Â Â Â Â*
> + Â Â Â Â* Now we check how well this matches with task's
> + Â Â Â Â* affinity and system topology.
> + Â Â Â Â*
> + Â Â Â Â* The last cpu where the task run is our first
> + Â Â Â Â* guess, since it is most likely cache-hot there.
> Â Â Â Â */
> - Â Â Â if (unlikely(p->dl.dl_throttled))
> - Â Â Â Â Â Â Â return;
> + Â Â Â if (cpumask_test_cpu(cpu, later_mask))
> + Â Â Â Â Â Â Â return cpu;
> + Â Â Â /*
> + Â Â Â Â* Check if this_cpu is to be skipped (i.e., it is
> + Â Â Â Â* not in the mask) or not.
> + Â Â Â Â*/
> + Â Â Â if (!cpumask_test_cpu(this_cpu, later_mask))
> + Â Â Â Â Â Â Â this_cpu = -1;
> +
> + Â Â Â rcu_read_lock();
> + Â Â Â for_each_domain(cpu, sd) {
> + Â Â Â Â Â Â Â if (sd->flags & SD_WAKE_AFFINE) {
> +
> + Â Â Â Â Â Â Â Â Â Â Â /*
> + Â Â Â Â Â Â Â Â Â Â Â Â* If possible, preempting this_cpu is
> + Â Â Â Â Â Â Â Â Â Â Â Â* cheaper than migrating.
> + Â Â Â Â Â Â Â Â Â Â Â Â*/
> + Â Â Â Â Â Â Â Â Â Â Â if (this_cpu != -1 &&
> + Â Â Â Â Â Â Â Â Â Â Â Â Â cpumask_test_cpu(this_cpu, sched_domain_span(sd)))
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â return this_cpu;
> +
> + Â Â Â Â Â Â Â Â Â Â Â /*
> + Â Â Â Â Â Â Â Â Â Â Â Â* Last chance: if best_cpu is valid and is
> + Â Â Â Â Â Â Â Â Â Â Â Â* in the mask, that becomes our choice.
> + Â Â Â Â Â Â Â Â Â Â Â Â*/
> + Â Â Â Â Â Â Â Â Â Â Â if (best_cpu < nr_cpu_ids &&
> + Â Â Â Â Â Â Â Â Â Â Â Â Â cpumask_test_cpu(best_cpu, sched_domain_span(sd)))
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â return best_cpu;
> + Â Â Â Â Â Â Â }
> + Â Â Â }
> + Â Â Â rcu_read_unlock();
>
> - Â Â Â if (!p->on_rq || rq->curr != p) {
> - Â Â Â Â Â Â Â if (task_has_dl_policy(rq->curr))
> - Â Â Â Â Â Â Â Â Â Â Â check_preempt_curr_dl(rq, p, 0);
> - Â Â Â Â Â Â Â else
> - Â Â Â Â Â Â Â Â Â Â Â resched_task(rq->curr);
> + Â Â Â /*
> + Â Â Â Â* At this point, all our guesses failed, we just return
> + Â Â Â Â* 'something', and let the caller sort the things out.
> + Â Â Â Â*/
> + Â Â Â if (this_cpu != -1)
> + Â Â Â Â Â Â Â return this_cpu;
> +
> + Â Â Â cpu = cpumask_any(later_mask);
> + Â Â Â if (cpu < nr_cpu_ids)
> + Â Â Â Â Â Â Â return cpu;
> +
> + Â Â Â return -1;
> +}
> +
> +/* Locks the rq it finds */
> +static struct rq *find_lock_later_rq(struct task_struct *task, struct rq *rq)
> +{
> + Â Â Â struct rq *later_rq = NULL;
> + Â Â Â int tries;
> + Â Â Â int cpu;
> +
> + Â Â Â for (tries = 0; tries < DL_MAX_TRIES; tries++) {
> + Â Â Â Â Â Â Â cpu = find_later_rq(task);
> +
> + Â Â Â Â Â Â Â if ((cpu == -1) || (cpu == rq->cpu))
> + Â Â Â Â Â Â Â Â Â Â Â break;
> +
> + Â Â Â Â Â Â Â later_rq = cpu_rq(cpu);
> +
> + Â Â Â Â Â Â Â /* Retry if something changed. */
> + Â Â Â Â Â Â Â if (double_lock_balance(rq, later_rq)) {
> + Â Â Â Â Â Â Â Â Â Â Â if (unlikely(task_rq(task) != rq ||
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â!cpumask_test_cpu(later_rq->cpu,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â&task->cpus_allowed) ||
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âtask_running(rq, task) ||
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â!task->se.on_rq)) {
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â raw_spin_unlock(&later_rq->lock);
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â later_rq = NULL;
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â break;
> + Â Â Â Â Â Â Â Â Â Â Â }
> + Â Â Â Â Â Â Â }
> +
> + Â Â Â Â Â Â Â /*
> + Â Â Â Â Â Â Â Â* If the rq we found has no -deadline task, or
> + Â Â Â Â Â Â Â Â* its earliest one has a later deadline than our
> + Â Â Â Â Â Â Â Â* task, the rq is a good one.
> + Â Â Â Â Â Â Â Â*/
> + Â Â Â Â Â Â Â if (!later_rq->dl.dl_nr_running ||
> + Â Â Â Â Â Â Â Â Â dl_time_before(task->dl.deadline,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âlater_rq->dl.earliest_dl.curr))
> + Â Â Â Â Â Â Â Â Â Â Â break;
> +
> + Â Â Â Â Â Â Â /* Otherwise we try again. */
> + Â Â Â Â Â Â Â double_unlock_balance(rq, later_rq);
> + Â Â Â Â Â Â Â later_rq = NULL;
> Â Â Â Â}
> +
> + Â Â Â return later_rq;
> Â}
>
> -static void prio_changed_dl(struct rq *rq, struct task_struct *p,
> - Â Â Â Â Â Â Â Â Â Â Â Â Â int oldprio)
> +static struct task_struct *pick_next_pushable_dl_task(struct rq *rq)
> Â{
> - Â Â Â switched_to_dl(rq, p);
> + Â Â Â struct task_struct *p;
> +
> + Â Â Â if (!has_pushable_dl_tasks(rq))
> + Â Â Â Â Â Â Â return NULL;
> +
> + Â Â Â p = rb_entry(rq->dl.pushable_dl_tasks_leftmost,
> + Â Â Â Â Â Â Â Â Â Âstruct task_struct, pushable_dl_tasks);
> +
> + Â Â Â BUG_ON(rq->cpu != task_cpu(p));
> + Â Â Â BUG_ON(task_current(rq, p));
> + Â Â Â BUG_ON(p->dl.nr_cpus_allowed <= 1);
> +
> + Â Â Â BUG_ON(!p->se.on_rq);
> + Â Â Â BUG_ON(!dl_task(p));
> +
> + Â Â Â return p;
> Â}
>
> -#ifdef CONFIG_SMP
> -static int
> -select_task_rq_dl(struct task_struct *p, int sd_flag, int flags)
> +/*
> + * See if the non running -deadline tasks on this rq
> + * can be sent to some other CPU where they can preempt
> + * and start executing.
> + */
> +static int push_dl_task(struct rq *rq)
> Â{
> - Â Â Â return task_cpu(p);
> + Â Â Â struct task_struct *next_task;
> + Â Â Â struct rq *later_rq;
> +
> + Â Â Â if (!rq->dl.overloaded)
> + Â Â Â Â Â Â Â return 0;
> +
> + Â Â Â next_task = pick_next_pushable_dl_task(rq);
> + Â Â Â if (!next_task)
> + Â Â Â Â Â Â Â return 0;
> +
> +retry:
> + Â Â Â if (unlikely(next_task == rq->curr)) {
> + Â Â Â Â Â Â Â WARN_ON(1);
> + Â Â Â Â Â Â Â return 0;
> + Â Â Â }
> +
> + Â Â Â /*
> + Â Â Â Â* If next_task preempts rq->curr, and rq->curr
> + Â Â Â Â* can move away, it makes sense to just reschedule
> + Â Â Â Â* without going further in pushing next_task.
> + Â Â Â Â*/
> + Â Â Â if (dl_task(rq->curr) &&
> + Â Â Â Â Â dl_time_before(next_task->dl.deadline, rq->curr->dl.deadline) &&
> + Â Â Â Â Â rq->curr->dl.nr_cpus_allowed > 1) {
> + Â Â Â Â Â Â Â resched_task(rq->curr);
> + Â Â Â Â Â Â Â return 0;
> + Â Â Â }
> +
> + Â Â Â /* We might release rq lock */
> + Â Â Â get_task_struct(next_task);
> +
> + Â Â Â /* Will lock the rq it'll find */
> + Â Â Â later_rq = find_lock_later_rq(next_task, rq);
> + Â Â Â if (!later_rq) {
> + Â Â Â Â Â Â Â struct task_struct *task;
> +
> + Â Â Â Â Â Â Â /*
> + Â Â Â Â Â Â Â Â* We must check all this again, since
> + Â Â Â Â Â Â Â Â* find_lock_later_rq releases rq->lock and it is
> + Â Â Â Â Â Â Â Â* then possible that next_task has migrated.
> + Â Â Â Â Â Â Â Â*/
> + Â Â Â Â Â Â Â task = pick_next_pushable_dl_task(rq);
> + Â Â Â Â Â Â Â if (task_cpu(next_task) == rq->cpu && task == next_task) {
> + Â Â Â Â Â Â Â Â Â Â Â /*
> + Â Â Â Â Â Â Â Â Â Â Â Â* The task is still there. We don't try
> + Â Â Â Â Â Â Â Â Â Â Â Â* again, some other cpu will pull it when ready.
> + Â Â Â Â Â Â Â Â Â Â Â Â*/
> + Â Â Â Â Â Â Â Â Â Â Â dequeue_pushable_dl_task(rq, next_task);
> + Â Â Â Â Â Â Â Â Â Â Â goto out;
> + Â Â Â Â Â Â Â }
> +
> + Â Â Â Â Â Â Â if (!task)
> + Â Â Â Â Â Â Â Â Â Â Â /* No more tasks */
> + Â Â Â Â Â Â Â Â Â Â Â goto out;
> +
> + Â Â Â Â Â Â Â put_task_struct(next_task);
> + Â Â Â Â Â Â Â next_task = task;
> + Â Â Â Â Â Â Â goto retry;
> + Â Â Â }
> +
> + Â Â Â deactivate_task(rq, next_task, 0);
> + Â Â Â set_task_cpu(next_task, later_rq->cpu);
> + Â Â Â activate_task(later_rq, next_task, 0);
> +
> + Â Â Â resched_task(later_rq->curr);
> +
> + Â Â Â double_unlock_balance(rq, later_rq);
> +
> +out:
> + Â Â Â put_task_struct(next_task);
> +
> + Â Â Â return 1;
> +}
> +
> +static void push_dl_tasks(struct rq *rq)
> +{
> + Â Â Â /* Terminates as it moves a -deadline task */
> + Â Â Â while (push_dl_task(rq))
> + Â Â Â Â Â Â Â ;
> +}
> +
> +static int pull_dl_task(struct rq *this_rq)
> +{
> + Â Â Â int this_cpu = this_rq->cpu, ret = 0, cpu;
> + Â Â Â struct task_struct *p;
> + Â Â Â struct rq *src_rq;
> + Â Â Â u64 dmin = LONG_MAX;
> +
> + Â Â Â if (likely(!dl_overloaded(this_rq)))
> + Â Â Â Â Â Â Â return 0;
> +
> + Â Â Â for_each_cpu(cpu, this_rq->rd->dlo_mask) {
> + Â Â Â Â Â Â Â if (this_cpu == cpu)
> + Â Â Â Â Â Â Â Â Â Â Â continue;
> +
> + Â Â Â Â Â Â Â src_rq = cpu_rq(cpu);
> +
> + Â Â Â Â Â Â Â /*
> + Â Â Â Â Â Â Â Â* It looks racy, abd it is! However, as in sched_rt.c,
> + Â Â Â Â Â Â Â Â* we are fine with this.
> + Â Â Â Â Â Â Â Â*/
> + Â Â Â Â Â Â Â if (this_rq->dl.dl_nr_running &&
> + Â Â Â Â Â Â Â Â Â dl_time_before(this_rq->dl.earliest_dl.curr,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âsrc_rq->dl.earliest_dl.next))
> + Â Â Â Â Â Â Â Â Â Â Â continue;
> +
> + Â Â Â Â Â Â Â /* Might drop this_rq->lock */
> + Â Â Â Â Â Â Â double_lock_balance(this_rq, src_rq);
> +
> + Â Â Â Â Â Â Â /*
> + Â Â Â Â Â Â Â Â* If there are no more pullable tasks on the
> + Â Â Â Â Â Â Â Â* rq, we're done with it.
> + Â Â Â Â Â Â Â Â*/
> + Â Â Â Â Â Â Â if (src_rq->dl.dl_nr_running <= 1)
> + Â Â Â Â Â Â Â Â Â Â Â goto skip;
> +
> + Â Â Â Â Â Â Â p = pick_next_earliest_dl_task(src_rq, this_cpu);
> +
> + Â Â Â Â Â Â Â /*
> + Â Â Â Â Â Â Â Â* We found a task to be pulled if:
> + Â Â Â Â Â Â Â Â* Â- it preempts our current (if there's one),
> + Â Â Â Â Â Â Â Â* Â- it will preempt the last one we pulled (if any).
> + Â Â Â Â Â Â Â Â*/
> + Â Â Â Â Â Â Â if (p && dl_time_before(p->dl.deadline, dmin) &&
> + Â Â Â Â Â Â Â Â Â (!this_rq->dl.dl_nr_running ||
> + Â Â Â Â Â Â Â Â Â Âdl_time_before(p->dl.deadline,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â this_rq->dl.earliest_dl.curr))) {
> + Â Â Â Â Â Â Â Â Â Â Â WARN_ON(p == src_rq->curr);
> + Â Â Â Â Â Â Â Â Â Â Â WARN_ON(!p->se.on_rq);
> +
> + Â Â Â Â Â Â Â Â Â Â Â /*
> + Â Â Â Â Â Â Â Â Â Â Â Â* Then we pull iff p has actually an earlier
> + Â Â Â Â Â Â Â Â Â Â Â Â* deadline than the current task of its runqueue.
> + Â Â Â Â Â Â Â Â Â Â Â Â*/
> + Â Â Â Â Â Â Â Â Â Â Â if (dl_time_before(p->dl.deadline,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âsrc_rq->curr->dl.deadline))
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â goto skip;
> +
> + Â Â Â Â Â Â Â Â Â Â Â ret = 1;
> +
> + Â Â Â Â Â Â Â Â Â Â Â deactivate_task(src_rq, p, 0);
> + Â Â Â Â Â Â Â Â Â Â Â set_task_cpu(p, this_cpu);
> + Â Â Â Â Â Â Â Â Â Â Â activate_task(this_rq, p, 0);
> + Â Â Â Â Â Â Â Â Â Â Â dmin = p->dl.deadline;
> +
> + Â Â Â Â Â Â Â Â Â Â Â /* Is there any other task even earlier? */
> + Â Â Â Â Â Â Â }
> +skip:
> + Â Â Â Â Â Â Â double_unlock_balance(this_rq, src_rq);
> + Â Â Â }
> +
> + Â Â Â return ret;
> +}
> +
> +static void pre_schedule_dl(struct rq *rq, struct task_struct *prev)
> +{
> + Â Â Â /* Try to pull other tasks here */
> + Â Â Â if (dl_task(prev))
> + Â Â Â Â Â Â Â pull_dl_task(rq);
> +}
> +
> +static void post_schedule_dl(struct rq *rq)
> +{
> + Â Â Â push_dl_tasks(rq);
> +}
> +
> +/*
> + * Since the task is not running and a reschedule is not going to happen
> + * anytime soon on its runqueue, we try pushing it away now.
> + */
> +static void task_woken_dl(struct rq *rq, struct task_struct *p)
> +{
> + Â Â Â if (!task_running(rq, p) &&
> + Â Â Â Â Â !test_tsk_need_resched(rq->curr) &&
> + Â Â Â Â Â has_pushable_dl_tasks(rq) &&
> + Â Â Â Â Â p->dl.nr_cpus_allowed > 1 &&
> + Â Â Â Â Â dl_task(rq->curr) &&
> + Â Â Â Â Â (rq->curr->dl.nr_cpus_allowed < 2 ||
> + Â Â Â Â Â Âdl_entity_preempt(&rq->curr->dl, &p->dl))) {
> + Â Â Â Â Â Â Â push_dl_tasks(rq);
> + Â Â Â }
> Â}
>
> Âstatic void set_cpus_allowed_dl(struct task_struct *p,
> @@ -622,10 +1346,145 @@ static void set_cpus_allowed_dl(struct task_struct *p,
>
> Â Â Â ÂBUG_ON(!dl_task(p));
>
> + Â Â Â /*
> + Â Â Â Â* Update only if the task is actually running (i.e.,
> + Â Â Â Â* it is on the rq AND it is not throttled).
> + Â Â Â Â*/
> + Â Â Â if (on_dl_rq(&p->dl) && (weight != p->dl.nr_cpus_allowed)) {
> + Â Â Â Â Â Â Â struct rq *rq = task_rq(p);
> +
> + Â Â Â Â Â Â Â if (!task_current(rq, p)) {
> + Â Â Â Â Â Â Â Â Â Â Â /*
> + Â Â Â Â Â Â Â Â Â Â Â Â* If the task was on the pushable list,
> + Â Â Â Â Â Â Â Â Â Â Â Â* make sure it stays there only if the new
> + Â Â Â Â Â Â Â Â Â Â Â Â* mask allows that.
> + Â Â Â Â Â Â Â Â Â Â Â Â*/
> + Â Â Â Â Â Â Â Â Â Â Â if (p->dl.nr_cpus_allowed > 1)
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â dequeue_pushable_dl_task(rq, p);
> +
> + Â Â Â Â Â Â Â Â Â Â Â if (weight > 1)
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â enqueue_pushable_dl_task(rq, p);
> + Â Â Â Â Â Â Â }
> +
> + Â Â Â Â Â Â Â if ((p->dl.nr_cpus_allowed <= 1) && (weight > 1)) {
> + Â Â Â Â Â Â Â Â Â Â Â rq->dl.dl_nr_migratory++;
> + Â Â Â Â Â Â Â } else if ((p->dl.nr_cpus_allowed > 1) && (weight <= 1)) {
> + Â Â Â Â Â Â Â Â Â Â Â BUG_ON(!rq->dl.dl_nr_migratory);
> + Â Â Â Â Â Â Â Â Â Â Â rq->dl.dl_nr_migratory--;
> + Â Â Â Â Â Â Â }
> +
> + Â Â Â Â Â Â Â update_dl_migration(&rq->dl);
> + Â Â Â }
> +
> Â Â Â Âcpumask_copy(&p->cpus_allowed, new_mask);
> Â Â Â Âp->dl.nr_cpus_allowed = weight;
> Â}
> +
> +/* Assumes rq->lock is held */
> +static void rq_online_dl(struct rq *rq)
> +{
> + Â Â Â if (rq->dl.overloaded)
> + Â Â Â Â Â Â Â dl_set_overload(rq);
> +}
> +
> +/* Assumes rq->lock is held */
> +static void rq_offline_dl(struct rq *rq)
> +{
> + Â Â Â if (rq->dl.overloaded)
> + Â Â Â Â Â Â Â dl_clear_overload(rq);
> +}
> +
> +static inline void init_sched_dl_class(void)
> +{
> + Â Â Â unsigned int i;
> +
> + Â Â Â for_each_possible_cpu(i)
> + Â Â Â Â Â Â Â zalloc_cpumask_var_node(&per_cpu(local_cpu_mask_dl, i),
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â GFP_KERNEL, cpu_to_node(i));
> +}
> +
> +#endif /* CONFIG_SMP */
> +
> +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);
> +
> +#ifdef CONFIG_SMP
> + Â Â Â /*
> + Â Â Â Â* Since this might be the only -deadline task on the rq,
> + Â Â Â Â* this is the right place to try to pull some other one
> + Â Â Â Â* from an overloaded cpu, if any.
> + Â Â Â Â*/
> + Â Â Â if (!rq->dl.dl_nr_running)
> + Â Â Â Â Â Â Â pull_dl_task(rq);
> Â#endif
> +}
> +
> +/*
> + * When switching to -deadline, we may overload the rq, then
> + * we try to push someone off, if possible.
> + */
> +static void switched_to_dl(struct rq *rq, struct task_struct *p)
> +{
> + Â Â Â int check_resched = 1;
> +
> + Â Â Â /*
> + Â Â Â Â* If p is throttled, don't consider the possibility
> + Â Â Â Â* of preempting rq->curr, the check will be done right
> + Â Â Â Â* after its runtime will get replenished.
> + Â Â Â Â*/
> + Â Â Â if (unlikely(p->dl.dl_throttled))
> + Â Â Â Â Â Â Â return;
> +
> + Â Â Â if (!p->on_rq || rq->curr != p) {
> +#ifdef CONFIG_SMP
> + Â Â Â Â Â Â Â if (rq->dl.overloaded && push_dl_task(rq) && rq != task_rq(p))
> + Â Â Â Â Â Â Â Â Â Â Â /* Only reschedule if pushing failed */
> + Â Â Â Â Â Â Â Â Â Â Â check_resched = 0;
> +#endif /* CONFIG_SMP */
> + Â Â Â Â Â Â Â if (check_resched && task_has_dl_policy(rq->curr))
> + Â Â Â Â Â Â Â Â Â Â Â check_preempt_curr_dl(rq, p, 0);
> + Â Â Â }
> +}
> +
> +/*
> + * If the scheduling parameters of a -deadline task changed,
> + * a push or pull operation might be needed.
> + */
> +static void prio_changed_dl(struct rq *rq, struct task_struct *p,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â int oldprio)
> +{
> + Â Â Â if (p->on_rq || rq->curr == p) {
> +#ifdef CONFIG_SMP
> + Â Â Â Â Â Â Â /*
> + Â Â Â Â Â Â Â Â* This might be too much, but unfortunately
> + Â Â Â Â Â Â Â Â* we don't have the old deadline value, and
> + Â Â Â Â Â Â Â Â* we can't argue if the task is increasing
> + Â Â Â Â Â Â Â Â* or lowering its prio, so...
> + Â Â Â Â Â Â Â Â*/
> + Â Â Â Â Â Â Â if (!rq->dl.overloaded)
> + Â Â Â Â Â Â Â Â Â Â Â pull_dl_task(rq);
> +
> + Â Â Â Â Â Â Â /*
> + Â Â Â Â Â Â Â Â* If we now have a earlier deadline task than p,
> + Â Â Â Â Â Â Â Â* then reschedule, provided p is still on this
> + Â Â Â Â Â Â Â Â* runqueue.
> + Â Â Â Â Â Â Â Â*/
> + Â Â Â Â Â Â Â if (dl_time_before(rq->dl.earliest_dl.curr, p->dl.deadline) &&
> + Â Â Â Â Â Â Â Â Â rq->curr == p)
> + Â Â Â Â Â Â Â Â Â Â Â resched_task(p);
> +#else
> + Â Â Â Â Â Â Â /*
> + Â Â Â Â Â Â Â Â* Again, we don't know if p has a earlier
> + Â Â Â Â Â Â Â Â* or later deadline, so let's blindly set a
> + Â Â Â Â Â Â Â Â* (maybe not needed) rescheduling point.
> + Â Â Â Â Â Â Â Â*/
> + Â Â Â Â Â Â Â resched_task(p);
> +#endif /* CONFIG_SMP */
> + Â Â Â } else
> + Â Â Â Â Â Â Â switched_to_dl(rq, p);
> +}
>
> Âstatic const struct sched_class dl_sched_class = {
>    Â.next          = &rt_sched_class,
> @@ -642,6 +1501,11 @@ static const struct sched_class dl_sched_class = {
>    Â.select_task_rq     = select_task_rq_dl,
>
>    Â.set_cpus_allowed    = set_cpus_allowed_dl,
> +    .rq_online       Â= rq_online_dl,
> +    .rq_offline       = rq_offline_dl,
> +    .pre_schedule      = pre_schedule_dl,
> +    .post_schedule     Â= post_schedule_dl,
> +    .task_woken       = task_woken_dl,
> Â#endif
>
>    Â.set_curr_task     Â= set_curr_task_dl,
> diff --git a/kernel/sched_rt.c b/kernel/sched_rt.c
> index 4b09704..7b609bc 100644
> --- a/kernel/sched_rt.c
> +++ b/kernel/sched_rt.c
> @@ -1590,7 +1590,7 @@ static void task_woken_rt(struct rq *rq, struct task_struct *p)
> Â Â Â Â Â Â!test_tsk_need_resched(rq->curr) &&
> Â Â Â Â Â Âhas_pushable_tasks(rq) &&
> Â Â Â Â Â Âp->rt.nr_cpus_allowed > 1 &&
> - Â Â Â Â Â rt_task(rq->curr) &&
> + Â Â Â Â Â (dl_task(rq->curr) || rt_task(rq->curr)) &&
> Â Â Â Â Â Â(rq->curr->rt.nr_cpus_allowed < 2 ||
> Â Â Â Â Â Â rq->curr->prio <= p->prio))
> Â Â Â Â Â Â Â Âpush_rt_tasks(rq);
> --
> 1.7.5.4
>

Would you please mail me, in attachment, a monolithic patch of this work?

Thanks
-hd
¢éì®&Þ~º&¶¬–+-±éÝ¥Šw®žË±Êâmébžìdz¹Þ)í…æèw*jg¬±¨¶‰šŽŠÝj/êäz¹ÞŠà2ŠÞ¨è­Ú&¢)ß«a¶Úþø®G«éh®æj:+v‰¨Šwè†Ù>Wš±êÞiÛaxPjØm¶Ÿÿà -»+ƒùdš_