Is mode switch occur switching from user thread to kernel thread?

五迷三道 提交于 2021-02-08 06:09:21

问题


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:


(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



来源:https://stackoverflow.com/questions/39031259/is-mode-switch-occur-switching-from-user-thread-to-kernel-thread

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!