Monday, February 18, 2013

how to measure the time spent in a context switch

A context switch is the time spent switching between two processes (e.g. bringing a waiting process into execution and sending an executing process into waiting/terminated state). This happens in multitasking. The operating system must bring the state information of waiting processes into memory and save the state information of the running process.

In order to solve the problem, we would like to record timestamps of the last and first instruction of the swapping processes. The context switching time would be the difference in the timestamps between the two processes.

The problem is: how do we know when this swapping occurs? swapping is governed by the scheduling algorithm of the OS. We cannot, of course, record the timestamp of every instruction in the process.

If the total time of execution of all the processes was T, then the context switch time = T - (SUM for all processes (waiting time + execution time)).


No comments:

Post a Comment