2
votes

I'm confused of user/kernel thread and mode/context switch (Platform: Linux)
I have two linked questions.

(1) Is the below sentence right?

If I make a system call, then mode switch (user mode to kernel mode) will occur and eventually switching from user thread to kernel thread happens.

Since system call can only be executed in kernel thread, I think mode switch must occur the switching from the user thread to kernel thread.

(2) Then, what we call the overhead of mode switching is that switching overhead of user thread to kernel thread? What kinds of overhead will there be?


As of I know,
1) Context switching is the switching of the CPU from one process or thread to another and only happens in kernel mode.
2) The reason for calling mode switch (instead of context switching) is that the currently executing process does NOT change during a mode switch.
3) Process context switching costs more than Thread context switching.


1
One more...What is big difference between mode switch (user thread to kernel thread) and thread context switch (kernel thread to kernel thread)? Assuming that sentence is question (1) is right.. - Sooyoung Jang
You should save user regs on kernel stack and restore them after syscall is handled. This is the overhead. - Alex Hoppus
The entire process is different, one is exception and another is just piece of OS code which changes reg set (not only) - Alex Hoppus
Thanks, Alex :) Great Help! - Sooyoung Jang

1 Answers

2
votes

(1) Is the below sentence right?

If I make a system call, then mode switch (user mode to kernel mode) will occur and eventually switching from user thread to kernel thread happens.

Yes

(2) Then, what we call the overhead of mode switching is that switching overhead of user thread to kernel thread? What kinds of overhead will there be?

Saving registers, changing segment selectors, etc. Good answer to this question

What is big difference between mode switch (user thread to kernel thread) and thread context switch (kernel thread to kernel thread)?

I think that segment selectors are the same in case of switching kernel thread to kernel thread, maybe some registers too. It's architecture dependent