Recently, I'm studying about CPU cores, threads, scheduling and and their relations. Apart from definitions of CPU, thread, scheduling, context switch, protection ring, CPU mode, and thread context, this article was very helpful in understanding what is going on under the hood, in case of windows.
I thought CPU mode switch was included in thread context so that CPU sets its mode to either kernel or user mode whenever thread context switch occurs and CPU executes a thread, precisely a thread's code or instructions.
However, from Context switch
"When the system transitions between user mode and kernel mode, 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."
Does this mean thread context switch does not include CPU mode transition?
What happens to CPU mode if CPU time slice expires during CPU mode switch?
For example, a thread began execution in user mode and switches to kernel mode, due to such as system call. The thread time slice expires. CPU mode left as kernel mode. Doesn't this lead to CPU executing next thread in kernel mode?