Hello,
I am making a scheduler. It is currently a simple round robin that just increments a task pointer. My previous ones were terrible, so I am going to slower and doing it the right way. I was wondering if a task switch should occur every tick, or every 3 ticks or so. Brokenthorn, and fair amount of OSes on this community give each task one tick and move to the next. It is simple, but is it any good?
Thanks,
nexos
Should a scheduler give timeslices?
-
- Member
- Posts: 148
- Joined: Sun Aug 23, 2020 4:35 pm
Re: Should a scheduler give timeslices?
Define tick. 100us? 1ms? 10ms?
For a pure round-robin, all tasks would get an equal amount of timespace.
From what I can tell, generally it is preferred to at least have some sort of priority system.
For example, you can set the priority level to be the amount of ticks the process gets before it switches.
I haven't work on my scheduler that much for a while, but my task switch routine is called once every millisecond.
I doubt that's a good way to do it, but as I said, I haven't worked on it for a while.
(I also neglected to write any way to have kernel multitasking, which I should fix soon)
Additionally, any task can call a "yield" syscall and prematurely give up their timeslice.
This is very helpful for polling processes, such as my shell, which is constantly checking for keyboard input.
For a pure round-robin, all tasks would get an equal amount of timespace.
From what I can tell, generally it is preferred to at least have some sort of priority system.
For example, you can set the priority level to be the amount of ticks the process gets before it switches.
I haven't work on my scheduler that much for a while, but my task switch routine is called once every millisecond.
I doubt that's a good way to do it, but as I said, I haven't worked on it for a while.
(I also neglected to write any way to have kernel multitasking, which I should fix soon)
Additionally, any task can call a "yield" syscall and prematurely give up their timeslice.
This is very helpful for polling processes, such as my shell, which is constantly checking for keyboard input.
My OS: TritiumOS
https://github.com/foliagecanine/tritium-os
void warranty(laptop_t laptop) { if (laptop.broken) return laptop; }
I don't get it: Why's the warranty void?
https://github.com/foliagecanine/tritium-os
void warranty(laptop_t laptop) { if (laptop.broken) return laptop; }
I don't get it: Why's the warranty void?
Re: Should a scheduler give timeslices?
Normally, priority means you do some things before other things. Which in its purest form means that it's preemptive w.r.t. priority levels, i.e. that unless there's nothing to do at priority level N, you can't execute anything from lower priority levels N+1, N+2, etc (assuming lower Ns mean higher priority and higher Ns mean lower priority) and that if a higher priority task becomes runnable, you have to preempt all others and run it.foliagecanine wrote:generally it is preferred to at least have some sort of priority system.
For example, you can set the priority level to be the amount of ticks the process gets before it switches.
This purest/strictest form has disadvantages. For example, low priority tasks may starve if there's always something at higher priority levels, for which reason they may be given a chance to run once in a while anyway (e.g. in Windows). Also, it may lead to worse UX in UI and such, for which reason it's common to temporarily increase/boost the priority of the tasks whose UI controls are being manipulated by the user (also in Windows). See also priority inversion.
-
- Member
- Posts: 426
- Joined: Tue Apr 03, 2018 2:44 am
Re: Should a scheduler give timeslices?
Why not it a variable in the task control block, indicating how many timeslice ticks the scheduler has given it?nexos wrote:Hello,
I am making a scheduler. It is currently a simple round robin that just increments a task pointer. My previous ones were terrible, so I am going to slower and doing it the right way. I was wondering if a task switch should occur every tick, or every 3 ticks or so. Brokenthorn, and fair amount of OSes on this community give each task one tick and move to the next. It is simple, but is it any good?
Thanks,
nexos
Then, each tick, decrement the variable in the current task, and reschedule when it reaches 0.
That way, you can separate the mechanism of timeslice length handling from the policy of setting the timeslice length.