Reputation: 513
The text book for Operating System by Galvin reads "If there are n processes in the ready queue and the time quantum is q, then each process gets 1/n of the CPU time in chunks of at most q time units. Each process must wait no longer than (n — 1) x q time units until its next time quantum. For example, with five processes and a time quantum of 20 milliseconds, each process will get up to 20 milliseconds every 100 milliseconds."
Is it correct? What happens if interrupt occurs while CPU is executing these processes. A process might have to wait for longer time then Or I am missing something obvious?
Upvotes: 1
Views: 347
Reputation: 24907
It depends on whether the interrupt changes the set of ready threads, the scheduling algorithm in use, the availability of cores and other stuff.
Or I am missing something obvious?
Possibly that modern preemptively-scheduled OS manage CPU execution on a core as a resource to be given only to threads that can use it. Interrupts, (syscalls and hardware interrupts), are the events that can change the set of ready threads. The timer interrupt is only one of them.
Fixating on the terms like 'quanta' is likely to lead to misunderstanding of how a premptive scheduler handles CPU execution on a core as a resource.
What happens if interrupt occurs while CPU is executing these processes. A process might have to wait for longer time
Yes, it may. If an interrupt, (syscall or hardware interrupt via a driver), changes the set of ready threads, the scheduling algorithm will run and may decide to preempt one of the threads that was running before the interrupt in favour of a thread that has just become ready. Obviously, the preempted thread cannot make forward progress afterwards until it is made running again by another interrupt so, yes, a process might have to wait for longer time.
Upvotes: 1
Reputation: 25663
It depends on your scheduler policy you have selected and it depends on the kernel you use. If you use the RT patch ( real time patch ) the things are quite different from the standard kernel. And you have to know on how many cpu cores your system is running. The scheduler itself runs as a part of one of the timer irqs and needs time itself. I have no idea if scheduling takes place every 20 milliseconds or (20 - irqtime ) milliseconds. And you also have to know how many processes are on the system in which priority. Take also into account that there are some worker processes which have a high priority. They are mainly used to handle the "slow part" of the irqs.
Maybe you take a look at:
http://man7.org/linux/man-pages/man2/sched_setscheduler.2.html
Upvotes: 0