0

Consider a very old single-core CPU that does not support hardware interrupts, and let's say I want to write a multi-tasked operating system. Using a hardware timer, one can poll an IRQ line in order to determine whether the timer has elapsed, and if so then switch threads/processes.

However, in order to be able to poll, the kernel has to have execution attention by the CPU. For a CPU that supports hardware interrupts, an ISR is called upon an interrupt and (correct me if I'm wrong) if the interrupt is by the context-switch timer, the appropriate ISR calls the kernel code that handles context switching.

If a CPU does not support hardware interrupts (again, correct me if I'm wrong), then the kernel has to repeatedly check for interrupts and the appropriate ISR is called in kernel space.

But, if a user thread is currently in execution on this hypothetical processor, the thread has to manually yield execution to the kernel for it to be able check whether the context-switch is due according to the timer through the appropriate IRQ line. This can be done by calling an appropriate kernel function.

Is there a way to implement non-cooperative multithreading on a single-core processor that only supports software interrupts? Are my thoughts correct, or am I missing something?

4

1 回答 1

2

好吧,您通常是正确的,内核在获得对 CPU 的控制之前不能进行多任务处理。这通过中断或用户代码进行系统调用时发生。

特别是定时器中断用于抢占式时间分片。我认为很难找到一个不支持定时器中断的完整 CPU,您不必使用穿孔卡或开关进行编程。中断比多核或虚拟内存或 DMA 或任何花哨的东西都要古老得多。

一些 SoC 具有具有这种限制的实时子组件(例如 Beaglebone),如果您在 FPGA 或其他东西中编写小型 CPU,它可能会出现。

没有中断,你必须等待系统调用,这基本上变成了协作多任务。

于 2017-02-03T13:52:00.250 回答