Compare context switch time

nishabasia

Distinguished
Aug 31, 2011
10
0
18,510
which one of the greater and why?
context switch time between user and kernel mode or context switch time between two processes in a system.
 
Hi, did you mean to put this append somewhere else? Can you post some background? Context switch means different things to people in different layers of the stack (hw guys switch context, so do operating system guys, middleware guys and english majors, but they are not the same)

Guessing: Getting from user to kernel mode is faster than un-dispatching a process which is part of context switch between two processes. However there are user mode thread implementations that might be faster still because they do not use kernal services at all (e.g. GNU Portable Threads)

This stuff is also processor architecture dependent. For example an SVC to get from problem to supervisor state on a mainframe takes only a few cycles and is faster than any context switch that involves saving user state info.
 
hello.....thanx 4 the above answer

I jst needed 2 know the funda of why in multiprogramming systems , the time taken for switching from 1 process control block to another is greater than that of switching between user and kernel modes.

ain't saving states of user mode nd switching to supervisor mode is equivalent to saving state of a process.....where the difference arise?
 
OK,

The steps to context switch from one user to another are
(1) you start in user mode running the first process
(2) you switch to kernal mode via timer interrupt or IO interrupt or some action taken by the running process like yielding control on a lock.
(3) the operating system decides to un-dispatch the current process and dispatch a new process
(4) state for the current process is saved (registers, control registers, security context, stack if any, etc.)
(5) accounting is done for chargeback accounting, performance monitoring, etc.
(6) new process is selected
(7) accounting is setup for the new process
(8) state for the new process is loaded
(9) the new process is dispatched and the system switches back to user mode from kernal mode

The reason "the time taken for switching from 1 process control block to another is greater than that of switching between user and kernel modes." is that switching from user to kernal mode is a small part of the process of switching from one process to another.

Note this can be made into a trick question. Intel Hyperthreading and other forms of SMT (see wikipedia for SMT) run two processes at the same time in the same CPU with the hardware doing the process switch under the covers at no externally visible cost.... Its not really the same but meets the criteria in your question.