this is my first post here, so -> hello

i want to replace my round'n'robin-algo with priority-scheduling... but i can't find any informations about it

can you tell me where i can find informations about priority-scheduling?
thx
mblock
Reason is simple. Every task was set to priority 0 by default. The Workbench GUI (including the event handling) ran at priority 5, so GUI events preempted whatever task was running ATM.beyond infinity wrote:
Look at your own holy grail: AmigaOS - responsive as hell regardless of workload spinning around the cpu in form of Number Crunchers.
Code: Select all
class PriorityScheduler {
const int k;
bits notempty:k;
Queue queues[k];
void insert(Task task) {
int priority=task.priority()
queues[priority].insert(task);
if (!notempty[priority]) {
int previous = notempty&masks_all_tasks_with_lower_priority
previous=find_lowest_bit_set_in(previous);
queues[priority].next=queues[previous].next;
queues[previous].next=priority;
notempty[priority]=true;
}
}
Task get() {
priority=curr_priority;
Task t=queues[priority].get();
if (queues[priority].isempty()) {
notempty[priority]=false;
curr_priority=queues[priority].next;
}
}
}
IMHO ageing is worse. Tasks that use a constant amount of CPU time still end up with a priority of 255 or 0, it just takes longer before they get there. Also consider a task used to create video for a 3D game - when nothing is moving the video doesn't change, the task does nothing and the task's priority becomes 255. When the user starts moving around in the game the task starts using 98% of CPU time. Eventually the scheduler reduces the task's priority back to 0, but other tasks that need high priority may end up with overflowed buffers and things first.mblock wrote: i implemented priority-based-scheduling with static priorities... but how can i prevent the "starvation" of "low-priority-tasks" if a "high-priority-task" is in a endless-loop.... the solution is easy: i must modify the priorities
but how?
i could use aging... but i don't know wheather this is sooo good... what do you think?
Code: Select all
findNextTask {
if(readyPolicy0tasks != 0) findNextPolicy0task;
else if(readyPolicy1tasks != 0) findNextPolicy1task;
else if(readyPolicy2tasks != 0) findNextPolicy2task;
else findNextPolicy3task;
}
findNextPolicy0task {
//Note: tasks sorted in order of priority when put in stack
task = task from top of policy 0 stack
switchTasks(task, policy0qTime)
}
findNextPolicy1task {
task = nextPolicy1task
lowestCount = 255
bestTask = -1
do {
task.count--
if(task.count == 0) {
task.count == task.priority
switchTasks(task, 10)
return
}
if(task.count < lowestCount) lowestCount = task.count
task = task + 1
} while task != nextPolicy1task
do {
task.count = task.count - lowestCount
if( (task.count == 0) && (bestTask == -1) ) bestTask = task
task = task + 1
} while task != nextPolicy1task
task.count == task.priority
switchTasks(bestTask, 10)
}
findNextPolicy2task {
//Note: tasks put on end of queue
task = task from start of policy 2 stack
switchTasks(task, 255-task.priority)
}
findNextPolicy3task {
//Note: tasks put on end of queue
task = task from start of policy 2 stack
switchTasks(task, 255-task.priority)
}
That's a matter of access control, not of scheduling.How to prevent starvation ?