Hi, I have a question. I have searching for a lot of hours in internet but I did not find an answer.
When a preemptive scheduler is working in the OS, it choices a process to run, but how the control returns to the scheduler at the specified time?
Thanks for your answers, sorry for my poor english.
How does the scheduler preemption works?
- thepowersgang
- Member
- Posts: 734
- Joined: Tue Dec 25, 2007 6:03 am
- Libera.chat IRC: thePowersGang
- Location: Perth, Western Australia
- Contact:
Re: How does the scheduler preemption works?
Short answer: the timer interrupt fires.
Long answer: When the task is started, you schedule an interrupt for t+some time (e.g. 10ms) and if the task does not yield the processor in that time, the timer will fire, forcing the task switch. Otherwise, the timer is reset for the next task.
Long answer: When the task is started, you schedule an interrupt for t+some time (e.g. 10ms) and if the task does not yield the processor in that time, the timer will fire, forcing the task switch. Otherwise, the timer is reset for the next task.
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
Re: How does the scheduler preemption works?
Thanks. But, who checks the timer? i.e.: the processor is running a process (or thread), so, in what moment checks the timer to fire it? My knowledges about the architecture of the processor are basics for now, maybe there is something that I forgotten.
Re: How does the scheduler preemption works?
The basics of it all: You set up the timer interrupt in your kernel code, so when it fires (how often this happens depends on your clock setting) you'll be back in the kernel and can change the stack to another tasks. Making the iret jump to that new task instead.
Re: How does the scheduler preemption works?
It sounds like you need to read about interrupts. The timer fires an interrupt after the specified length of time.luxianos wrote:Thanks. But, who checks the timer? i.e.: the processor is running a process (or thread), so, in what moment checks the timer to fire it? My knowledges about the architecture of the processor are basics for now, maybe there is something that I forgotten.
Re: How does the scheduler preemption works?
You can also force a reschedule on some API ( like blocking IO or IPC signals ). It's up to the design of proper code path.
-
- Member
- Posts: 510
- Joined: Wed Mar 09, 2011 3:55 am
Re: How does the scheduler preemption works?
The timer itself fires the interrupt. The processor doesn't check anything at all. It's like an alarm clock: you set it and go do something else (like working or sleeping) while you wait for it to go off. You don't need to check it 'cause you'll hear it when it rings. Likewise, the processor tells the timer to interrupt it after a specified amount of time, and can then go and do anything without needing to check the timer: The timer will send it a signal when the arranged time comes.luxianos wrote:Thanks. But, who checks the timer? i.e.: the processor is running a process (or thread), so, in what moment checks the timer to fire it? My knowledges about the architecture of the processor are basics for now, maybe there is something that I forgotten.
Re: How does the scheduler preemption works?
Thanks!! I am understanding now.