0
votes

Currently, I am reading about Schedulers and scheduling algorithms.

I am really confused with short-term scheduler and dispatcher.

At some places, it is written that they are same. At some places, it is written that their jobs are different.

From whatever I read I concluded that - "Scheduling" of the scheduler is caused by the code associated with a hardware interrupt, or code associated with a system call. With this a mode switch from user mode to kernel mode took place. Then short-term scheduler selects a process from a queue of the available process to give it control of the CPU. The task of short-term scheduler ends here.

Now dispatcher comes into play. The dispatcher is the module that gives control of the CPU to the process selected by the short-term scheduler. This function involves the following: -Switching context -Switching to user mode -Jumping to the proper location in the user program to restart that program.

  1. Is my understanding correct?

  2. Suppose Process A is preempted and process B is scheduled next. What happened during the context switch ? How context data of Process A, scheduler, dispatcher, Process B is saved and restored?

1

1 Answers

0
votes

The various divisions of the process switching steps are system dependent. Operating system books like to make these steps complicated and divide the into multiple steps.

There are really only two steps: 1. pick a the new process. 2. Switch to the new process.

That last step is very simple; so simple that it is probably not worthy of being called a separate step.

Most CPUs define a structure that is usually called the Process Context Block (PBC). The PCB has a slot for every register that defines the state of the process. Switching processes can be as simple as:

SAVEPCTX pcb_address_of_current_process ; Save the state of the running process
LOADPCTX pcb_address_of_new_process ; Load the state of the other process.
REI

Some processors require more steps, like having to save floating point registers separately.