Re: cooperative multitasking scheme

From: Sergio Masci (sergio_at_NO.SPAM.xcprod.com)
Date: 09/19/04


Date: Sun, 19 Sep 2004 13:23:31 GMT


Marco Bleekrode <bleek004@hotmail.com> wrote in message
news:414d5239$0$76505$b83b6cc0@news.wanadoo.nl...
> Hi y'all
>
> Quick but not so easy question (it may spawn a considerable thread...)
> We need to develop a cooperative multitasking kernel for various
> embedded platforms (See the implications and the complications?).
> One requirement is that c-functions should serve as "tasks". (Notably,
> these tasks perform very simple functions, e.g. polling push buttons,
> occasionally updating a display, polling an adc, and a whole slew of
> other things that are definitely not time critical.)
> The question is, how should cpu time be distributed, given the following:
> Task 1: Priority 1
> Task 2: Priority 1
> Task 3: Priority 1
> Task 4: Priority 1
> Task 5: Priority 4
> Task 6: Priority 8
> Should it be:
> T6 T6 T6 T6 T6 T6 T6 T6 T5 T5 T5 T5 T1 T2 T3 T4... ad infinitum
> or:
> T6 T5 T6 T5 T6 T5 T6 T5 T6 T1 T6 T2 T6 T3 T6 T4... ad infinitum
> or perhaps another scheme that does the assigned priorities right?
> A pointer would be very nice too, apart from an interesting discussion.
> None of us has a formal education in these matters... We are at a
> moderate loss...
>
> Thanks in advance
>
> Waldemar

You must first define what you want priority to mean.

Should all priority 1 task run in preference to any priority 2 tasks, should
all priority 2 tasks run in preference to any priority 3 tasks etc.

Are you just trying to give a bias toward higher priority tasks such that
each level has certain percentage of the CPU time. Maybe all priority 1
tasks form a group that has 50% of the CPU time, all priority 2 tasks have
25% of the CPU time, all priority 3 tasks have 10% etc

Are you trying to improve the way tasks use CPU time based on how long they
sleep (maybe increasing the priority of tasks if they are not ready to run
so that they receive quicker attention when they are ready to run).

You really need to know what you want the priority system to achive before
you look at ways of implementing your schedular. In some systems I have
found it adiquate to use simple round robin with no prority, others have
required just 2 levels and others 16. Sometimes trying to be too clever is
really counter productive and you end up with a lot of wasted CPU time as
the schedular does a lot of work just to return to the same task that last
active.

Try writing a simulation to get a better feel for how the tasks interact
withing the priority system.

If in doubt keep it simple!

Regards
Sergio Masci

http://www.xcprod.com