A REFINEMENT TO REDUCE THE COST OF A CONTEXT SWITCH

In the target system there are eight 80-bit floating point registers that must be saved and restored as 96-bits each. Doing so for every context switch is obviously expensive, especially as many processes will never make use of the floating point registers. It thus makes sense to avoid saving and restoring the floating point registers when possible.

Clearly, a simple flag in the PCB can be used to distinguish ``floating point'' processes from ``ordinary'' processes. The floating point registers can then be saved/restored only when the registers of a floating point process is saved/restored.

However, if there is only one active floating point process, there is no need to save or restore the floating point registers at all. Given the fact that the implementation targets a multi-processor, as well as the fact that floating point processes can be statically distributed among these processors, it can be quite likely for a processor to have but one active floating point process at a time. It thus makes sense to formulate the mechanism so that such situations can be exploited, especially since it can be done at the cost of a few instructions per context switch.

The floating point refinement basically works like this: Keep a pointer to the PCB of the process ``owning'' the floating point registers in a scheduler variable. When no real floating point process exists, the dummy ``idle'' process is designated the owner.

When saving the registers of the current process, do not save the floating point registers. Instead, modify the SRD to end as follows:

  IF action queue is empty THEN
    IF context switch requested THEN
      IF not blocked THEN
        add current PCB to end of appropriate ready queue
      ENDIF
      choose a new current process
    ENDIF
    IF the current process uses floating point registers
    AND it is not the owner of the floating point registers THEN
      save the floating point registers in the PCB of the owner
      make the new current process the new owner
      restore the floating point registers from the PCB
        of the new owner
    ENDIF
    restore the other registers of the current process
    resume the execution of the current process
  ENDIF


next up previous

Prof Herman Venter
Fri Apr 26 09:15:11 GMT 1996