Re: [PATCH] sched: check and preempt the current task at right place

From: Hillf Danton
Date: Sun Jun 05 2011 - 06:54:52 EST


On Wed, Jun 1, 2011 at 4:31 AM, Steven Rostedt <rostedt@xxxxxxxxxxx> wrote:
> On Tue, 2011-05-31 at 21:04 +0800, Hillf Danton wrote:
>> When switching a task to RT, it is the right place to preempt the current
>> running task if the task is not running. Same scenario also rises when the
>> priority of task has changed.
>>
>> Signed-off-by: Hillf Danton <dhillf@xxxxxxxxx>
>> ---
>> Âkernel/sched_rt.c | Â 19 +++----------------
>> Â1 files changed, 3 insertions(+), 16 deletions(-)
>>
>> diff --git a/kernel/sched_rt.c b/kernel/sched_rt.c
>> index 88725c9..4a9553e 100644
>> --- a/kernel/sched_rt.c
>> +++ b/kernel/sched_rt.c
>> @@ -1671,25 +1671,13 @@ static inline void init_sched_rt_class(void)
>> Â */
>> Âstatic void switched_to_rt(struct rq *rq, struct task_struct *p)
>> Â{
>> - Â Â int check_resched = 1;
>> -
>> Â Â Â /*
>> Â Â Â Â* If we are already running, then there's nothing
>> Â Â Â Â* that needs to be done. But if we are not running
>> Â Â Â Â* we may need to preempt the current running task.
>> - Â Â Â* If that current running task is also an RT task
>> - Â Â Â* then see if we can move to another run queue.
>> Â Â Â Â*/
>> - Â Â if (p->on_rq && rq->curr != p) {
>> -#ifdef CONFIG_SMP
>> - Â Â Â Â Â Â if (rq->rt.overloaded && push_rt_task(rq) &&
>> - Â Â Â Â Â Â Â Â /* Don't resched if we changed runqueues */
>> - Â Â Â Â Â Â Â Â rq != task_rq(p))
>> - Â Â Â Â Â Â Â Â Â Â check_resched = 0;
>> -#endif /* CONFIG_SMP */
>> - Â Â Â Â Â Â if (check_resched && p->prio < rq->curr->prio)
>> - Â Â Â Â Â Â Â Â Â Â resched_task(rq->curr);
>> - Â Â }
>> + Â Â if (p->on_rq && rq->curr != p)
>> + Â Â Â Â Â Â check_preempt_curr_rt(rq, p, 0);
>
>
> Note, although it works now, there's no guarantee that
> check_preempt_curr_rt() will work with something other than an rt task
> on the runqueue.
>

If check_preempt_curr_rt has solid shortage to do its work, we could do more
for it later.

> Also, this code removes the push_rt_task(rq) entirely, which means that
> if we don't preempt current, and p is an RT task (as it is), we wont
> push it off to another rq even if one is available for it to run on.
>

If it is concerned that we fail to preempt the current task with a RT task, why
is preempt checked after pushing?

If we really fail to preempt, it is not too late to push the starved
tasks, though
starvation is eligible as you taught a while ago.

thanks
Hillf

>> Â}
>>
>> Â/*
>> @@ -1729,8 +1717,7 @@ prio_changed_rt(struct rq *rq, struct
>> task_struct *p, int oldprio)
>> Â Â Â Â Â Â Â Â* greater than the current running task
>> Â Â Â Â Â Â Â Â* then reschedule.
>> Â Â Â Â Â Â Â Â*/
>> - Â Â Â Â Â Â if (p->prio < rq->curr->prio)
>> - Â Â Â Â Â Â Â Â Â Â resched_task(rq->curr);
>> + Â Â Â Â Â Â check_preempt_curr_rt(rq, p, 0);
>> Â Â Â }
>> Â}
>
>
>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/