简体   繁体   English

操作系统如何调用用户计划的任务来执行?

[英]How does operating system invoke user-scheduled task that to execute when its time comes to?

I'm not sure how to phrase this question, but i'll try my best.我不知道如何表达这个问题,但我会尽力而为。 When we schedule some abstract task in a real-time, how is it invoked on time (task can be anything that has been scheduled to happen at some point in time, like alarm that wakes you up in the morning)?当我们实时安排一些抽象任务时,它是如何按时调用的(任务可以是任何已安排在某个时间点发生的事情,例如早上叫醒你的闹钟)? What happens at the lowest level of software?在软件的最低层会发生什么? For example in .NET WaitHandle.WaitOne(1000), how is it implemented?例如在.NET WaitHandle.WaitOne(1000)中,它是如何实现的? Is there some operating system scheduler (i'm not talking about time slicing between threads) that every software platform uses to schedule its task?是否有每个软件平台用来调度其任务的操作系统调度程序(我不是在谈论线程之间的时间切片)? When system clock goes one tick, does it say somehow to operating system "hey, one tick elapsed, increase your system time!".当系统时钟走一滴答时,它是否以某种方式向操作系统说“嘿,一滴答过去了,增加你的系统时间!”。 And then operating system increases its time and tells its scheduler to check if there are some events scheduled to occur at this new time?然后操作系统增加它的时间并告诉它的调度程序检查是否有一些事件安排在这个新时间发生? Or scheduler runs on separate thread in infinite loop, check system time in each iteration and see if it has something scheduled to invoke?或者调度程序在无限循环中在单独的线程上运行,在每次迭代中检查系统时间并查看它是否有安排要调用的东西? Or there is no scheduler and each component runs infinite loops on its own?或者没有调度程序,每个组件都自己无限循环? I assume that idea is the same on every operating system, but if its not, i'm interested specifically in what happens on Windows OS and .NET.我认为这个想法在每个操作系统上都是一样的,但如果不是,我对 Windows 操作系统和 .NET 上发生的事情特别感兴趣。

Kind regards,亲切的问候,

The state of a process is defined by a set of registers called the process context.进程的状态由一组称为进程上下文的寄存器定义。 This set of registers includes the values of the general registers and system registers that are only accessible in kernel mode.这组寄存器包括只能在内核模式下访问的通用寄存器和系统寄存器的值。

Most processors define a data structure called the Process Context Block (PCB).大多数处理器定义了一个称为进程上下文块 (PCB) 的数据结构。 The PCB has a slot for each of the registers. PCB 有一个插槽用于每个寄存器。

To make a context switch from one process to another, the operating system causes the registers of the current process to be saved in its PCB then loads the registers from the PCB of the new process.为了进行从一个进程到另一个进程的上下文切换,操作系统使当前进程的寄存器保存在其 PCB 中,然后从新进程的 PCB 加载寄存器。

Most processors have load process context and save process context instructions to this can be done all at once.大多数处理器都有加载进程上下文和保存进程上下文指令,这可以一次性完成。 A number of incompetently designed processors in widespread use can require multiple instructions to do these tasks.许多广泛使用的设计不当的处理器可能需要多条指令来完成这些任务。

There is something called Programmable Interval Timer.有一种叫做可编程间隔定时器的东西。 It can be programmed to count number of ticks and then send signal to os.它可以被编程为计算滴答数,然后将信号发送到 os。 The os will then wake up the process.然后操作系统将唤醒该进程。 To read more about PIT, refer to osdev要阅读有关 PIT 的更多信息,请参阅osdev

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM