I am unable to understand How Linux Scheduler knows that process has run for defined time slice. Does timer interrupt keep on coming during process execution ?
我无法理解Linux调度器是如何知道进程已经为定义的时间片运行的。在进程执行过程中,计时器中断是否持续?
Lets take a scenario, HZ is 100, so there will be a tick in every 10 milliseconds. Now assume there are only process with same priority, so both should get equal chance, so if time slice is 4 ms, both process will run for that much time. My doubt is how scheduler will know that process has consumed its 4 ms ?
假设HZ是100,所以每10毫秒就会有一个滴答声。现在假设只有具有相同优先级的进程,所以两个进程都应该有相同的机会,所以如果时间片是4ms,两个进程都会运行那么多时间。我的怀疑是调度程序如何知道进程已经消耗了它的4毫秒?
1 个解决方案
#1
2
The kernel timer is always running and interrupting processes. As part of its management duties the kernel keeps track of how many full (and partial) time slices a process consumes. Now, there are many things which will cause a process to give up part of a time slice. These are generically referred to as blocking events (though not all blocking events give up the remainder of a time slice and return control to the kernel). Whenever you call sleep
, or wait for user input or for disk or network I/O, the kernel doesn't just spin in a loop consuming the rest of your time slice before switching to the next task. Instead it adds the amount of time from the partially consumed slice to your processes information store and goes on to the process in its list. Then, when the event on which you were waiting occurs, your process is queued up to become active at the next opportunity and given a new full time slice. This continues until the process terminates by any means.
内核计时器总是在运行和中断进程。作为其管理职责的一部分,内核跟踪进程所消耗的完整(和部分)时间片的数量。现在,有很多事情会导致进程放弃一部分时间片。这些通常被称为阻塞事件(尽管并非所有阻塞事件都放弃时间片的剩余部分并将控制权返回给内核)。无论何时调用sleep,或等待用户输入,或等待磁盘或网络I/O,内核都不会在切换到下一个任务之前,在循环中消耗掉剩余的时间片。相反,它会将部分被消耗的部分添加到流程信息存储中,并继续到其列表中的流程。然后,当您正在等待的事件发生时,您的进程将排队以便在下一次机会时成为活动的,并给出一个新的完整时间片。这将继续下去,直到进程以任何方式终止。
#1
2
The kernel timer is always running and interrupting processes. As part of its management duties the kernel keeps track of how many full (and partial) time slices a process consumes. Now, there are many things which will cause a process to give up part of a time slice. These are generically referred to as blocking events (though not all blocking events give up the remainder of a time slice and return control to the kernel). Whenever you call sleep
, or wait for user input or for disk or network I/O, the kernel doesn't just spin in a loop consuming the rest of your time slice before switching to the next task. Instead it adds the amount of time from the partially consumed slice to your processes information store and goes on to the process in its list. Then, when the event on which you were waiting occurs, your process is queued up to become active at the next opportunity and given a new full time slice. This continues until the process terminates by any means.
内核计时器总是在运行和中断进程。作为其管理职责的一部分,内核跟踪进程所消耗的完整(和部分)时间片的数量。现在,有很多事情会导致进程放弃一部分时间片。这些通常被称为阻塞事件(尽管并非所有阻塞事件都放弃时间片的剩余部分并将控制权返回给内核)。无论何时调用sleep,或等待用户输入,或等待磁盘或网络I/O,内核都不会在切换到下一个任务之前,在循环中消耗掉剩余的时间片。相反,它会将部分被消耗的部分添加到流程信息存储中,并继续到其列表中的流程。然后,当您正在等待的事件发生时,您的进程将排队以便在下一次机会时成为活动的,并给出一个新的完整时间片。这将继续下去,直到进程以任何方式终止。