Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how dispatcher works?

I have recently started my OS course. As far as i know the work of dispatcher is to save the context of current process and load context of process to be run next. But how does it do that? When a process is preempted then as soon as dispatcher will be loaded and executed ( as it is also a program ) the context of previous process in registers, PSW etc will be lost. How is it going to save the context before loading itself ?

like image 828
Terminal Avatar asked Jan 24 '11 13:01

Terminal


People also ask

What do you know about dispatcher?

Dispatchers are generally responsible for coordinating with the customers regarding the delivery status of the products and providing precise logistics and the fastest transportation routes to the professional drivers to ensure smooth and timely deliveries.

What is the role of dispatch assistant?

The primary responsibility of the Dispatch Assistant is to ensure safe, accurate, timely and efficient delivery of all orders while facilitating and supporting drivers and dispatchers as they perform their duties.


2 Answers

The simple answer is that modern processors offer architectural extensions providing for several banks of registers that can be swapped in hardware, so up to X tasks get to retain their full set of registers.

The more complex answer is that the dispatcher, when triggered by an interrupt, receives the full register set of the program that was running at the time of interrupt (with the exception of the program counter, which is presumably propagated through a mutually-agreed-upon 'volatile' register or some such). Thus, the dispatcher must be carefully written to store the current state of register banks as its first operation upon being triggered. In short, the dispatcher itself has no immediate context and thus doesn't suffer from the same problem.

Here is an attempt at a simple description of what goes on during the dispatcher call:

  1. The program that currently has context is running on the processor. Registers, program counter, flags, stack base, etc are all appropriate for this program; with the possible exception of an operating-system-native "reserved register" or some such, nothing about the program knows anything about the dispatcher.
  2. The timed interrupt for dispatcher function is triggered. The only thing that happens at this point (in the vanilla architecture case) is that the program counter jumps immediately to whatever the PC address in the BIOS interrupt is listed as. This begins execution of the dispatcher's "dispatch" subroutine; everything else is left untouched, so the dispatcher sees the registers, stack, etc of the program that was previously executing.
  3. The dispatcher (like all programs) has a set of instructions that operate on the current register set. These instructions are written in such a way that they know that the previously executing application has left all of its state behind. The first few instructions in the dispatcher will store this state in memory somewhere.
  4. The dispatcher determines what the next program to have the cpu should be, takes all of its previously stored state and fills registers with it.
  5. The dispatcher jumps to the appropriate PC counter as listed in the task that now has its full context established on the cpu.

To (over)simplify in summary; the dispatcher doesn't need registers, all it does is write the current cpu state to a predetermined memory location, load another processes' cpu state from a predetermined memory location, and jumps to where that process left off.

Does that make it any clearer?

like image 111
Mark McKenna Avatar answered Oct 21 '22 14:10

Mark McKenna


It doesn't generally get loaded in such a way that you lose the information on the current process.

Often, it's an interrupt that happens in the context of the current process.

So the dispatcher (or scheduler) can save all relevant information in a task control block of some sort before loading up that information for the next process.

This includes the register contents, stack pointer and so on.

It's worth noting that the context of the next process includes its state of being in the dispatcher interrupt itself so that, when it returns from the interrupt, it's to a totally different process.

like image 40
paxdiablo Avatar answered Oct 21 '22 14:10

paxdiablo