operating-systemtaskcpu-architecturemultitaskingpreemptive

To implement OS for 'preemptive' tasks, what hardware feature should cpu support?


For example, to implement an operating system that's like unix or NT, which supports different tasks switching based on time slices, what kind of hardware support should cpu have?

Does intel 80286 begin to support implementation of 'preemptive' tasks, with clock interruption? What else hardware features are needed to achieve this goal?


Solution

  • For an OS to implement Preemptive multitasking effectively the hardware must have support for two features:

    1. A way to get the OS back in control after it handed execution to a task.
      This is usually achieved with a timer interrupt and during system calls.
      Upon a system call the OS is back in control and can suspend the current task in favour of others (specially for IO bounded system calls).
      The timer is needed too, otherwise a thigh spinning task that makes no system call would never give control back to the OS.

    2. A way to prevent the disabling of the feature above.
      If the running task cannot be sand-boxed just enough to keep the preemptive mechanism active, then it could simply disable it and run forever.

    The 286 was the first processor of the x86 family to support protected mode, a mode necessary to implement feature 2.
    Feature 1 was available in the IBM PC since the beginning (the CPU was 8086) through the use of the PIT 8254.

    Feature 1 is a feature of the platform hardware, not of the CPU (though it can be included in the CPU).
    Feature 2 is a feature of the CPU.

    Note that there are other possible ways to achieve 1 and 2.
    For example, a system with two CPUs where one can control the execution of the other (but not the other way around) qualifies for both features.