Does there have to be a mode switch for something to qualify as a context switch?
Does there have to be a mode switch ie. from user to ke开发者_C百科rnel mode in order for the action to be called a context switch?
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.
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.
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".
精彩评论