Re: [PATCH] sched: remove starvation in check_preempt_equal_prio()
From: Hillf Danton
Date: Tue May 24 2011 - 10:12:05 EST
On Tue, May 24, 2011 at 9:45 PM, Steven Rostedt <rostedt@xxxxxxxxxxx> wrote:
> On Tue, 2011-05-24 at 21:34 +0800, Hillf Danton wrote:
>> If there are pushable tasks and they are high enough in priority, in which
>> case task p is covered, the current could keep holding its CPU.
>>
>> Even if current task has to release its CPU, requeuing task p could result in
>> starvation of tasks that are of same priority and have been waiting on RQ for
>> a couple of hours:/
>
> Can you explain this better? Sounds like you are describing the
> definition of FIFO. You are *not* suppose to preempt a FIFO task just
I dont want to redefine FIFO, but starvation needs attention, since
the woken task is already off RQ, and its position on RQ is reshuffled.
thanks
Hillf
> because another task of equal priority woke up on its run queue.
>
> Yes, if you queue two FIFO tasks of the same priority on the same run
> queue, and one runs for hours without calling schedule. The other one
> will have to wait.
>
> -- Steve
>
>
>>
>> Signed-off-by: Hillf Danton <dhillf@xxxxxxxxx>
>> ---
>>
>> --- tip-git/kernel/sched_rt.c Sun May 22 20:12:01 2011
>> +++ sched_rt.c    ÂTue May 24 21:01:51 2011
>> @@ -1028,24 +1028,23 @@ select_task_rq_rt(struct task_struct *p,
>> Â Â Â return cpu;
>> Â}
>>
>> +static struct task_struct *pick_next_pushable_task(struct rq *);
>> +
>> Âstatic void check_preempt_equal_prio(struct rq *rq, struct task_struct *p)
>> Â{
>> - Â Â if (rq->curr->rt.nr_cpus_allowed == 1)
>> - Â Â Â Â Â Â return;
>> -
>> - Â Â if (p->rt.nr_cpus_allowed != 1
>> - Â Â Â Â && cpupri_find(&rq->rd->cpupri, p, NULL))
>> + Â Â if (rq->curr->rt.nr_cpus_allowed > 1) {
>> + Â Â Â Â Â Â struct task_struct *push = pick_next_pushable_task(rq);
>> + Â Â Â Â Â Â /*
>> + Â Â Â Â Â Â Â* Though curr is pushable, if there are other pushable tasks,
>> + Â Â Â Â Â Â Â* we keep curr busy.
>> + Â Â Â Â Â Â Â*/
>> + Â Â Â Â Â Â if (push && !(push->prio > p->prio))
>> + Â Â Â Â Â Â Â Â Â Â return;
>> + Â Â } else
>> Â Â Â Â Â Â Â return;
>>
>> - Â Â if (!cpupri_find(&rq->rd->cpupri, rq->curr, NULL))
>> - Â Â Â Â Â Â return;
>> -
>> - Â Â /*
>> - Â Â Â* There appears to be other cpus that can accept
>> - Â Â Â* current and none to run 'p', so lets reschedule
>> - Â Â Â* to try and push current away:
>> - Â Â Â*/
>> - Â Â requeue_task_rt(rq, p, 1);
>> + Â Â /* yield curr */
>> + Â Â requeue_task_rt(rq, rq->curr, 0);
>> Â Â Â resched_task(rq->curr);
>> Â}
>>
>> @@ -1091,7 +1090,7 @@ static struct sched_rt_entity *pick_next
>> Â Â Â BUG_ON(idx >= MAX_RT_PRIO);
>>
>> Â Â Â queue = array->queue + idx;
>> - Â Â next = list_entry(queue->next, struct sched_rt_entity, run_list);
>> + Â Â next = list_first_entry(queue, struct sched_rt_entity, run_list);
>>
>> Â Â Â return next;
>> Â}
>
>
>
--
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/