Does there have to be a mode switch ie. from user to kernel mode in order for the action to be called a context switch?
-
2They're not directly related. A "mode switch" happens inside one process. A context switch involves more than one process (or thread, or whatever). A context switch doesn't imply a mode switch (could be done by the hardware alone). A mode switch does not require a context switch either. – Mat Oct 02 '11 at 12:51
3 Answers
context switch happens only in kernel mode. If context switching happens between two user mode processes, first cpu has to change to kernel mode, perform context switch, return back to user mode and so on. So there has to be a mode switch associated with a context switch.

- 71
- 1
- 1
No. Not all processors even have privilege levels.
A context switch usually means restoring an execution state from a Process Control Block. However, the notion of a context is implementation-defined. From Wikipedia:
What constitutes the context is determined by the processor and the operating system.
...
When a transition between user mode and kernel mode is required in an operating system, a context switch is not necessary; a mode transition is not by itself a context switch. However, depending on the operating system, a context switch may also take place at this time.

- 6,438
- 3
- 40
- 58
-
'When a transition between user mode and kernel mode is required in an operating system, a context switch is not necessary.' What if it's the other way round? I mean does context switch require mode switch? – Palak Jain Feb 15 '18 at 04:52
Mode Switch - When a single process mode is switched from user-level to kernel-level or the other way around. It happens through the system calls. When a process call the system call, the process mode will change to kernel-mode and the kernel will start acting on behalf of the user process. And once the system call returns the process mode will change from kernel-mode to user-mode. "Mode" is a property associated with the process. So, a mode switch is switch of the mode of a single process.
Context Switch - It is when the running process current state is stored some place and a new process is chosen for running and its already stored state is loaded in the CPU registers. And now the new process starts running. This whole "context switch" procedure is done by the "Process Scheduler".

- 1,571
- 1
- 19
- 31