内核线程在什么情况下运行在 Linux 中?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9389688/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 04:43:59  来源:igfitidea点击:

In what context Kernel Thread runs in Linux?

linuxlinux-kernelkernel

提问by user405369

I am newbie to Linux Kernel.
I know that there are two context
1. Process Context, running in user space or in Kernel Space (for ex: as part of System call)
2. Interrupt Context

我是 Linux 内核的新手。
我知道有两个上下文
1. 进程上下文,在用户空间或内核空间中运行(例如:作为系统调用的一部分)
2. 中断上下文

In what context Kernel Thread (not related to any User Thread, for ex:flush task) runs ?

内核线程(与任何用户线程无关,例如:flush 任务)在什么上下文中运行?

Is there any other context other than Process and Interrupt context in Linux Kernel ?

Linux 内核中除了进程和中断上下文之外还有其他上下文吗?

采纳答案by Pavan Manjunath

Kernel threads run in process contexts in kernel space. Though there are some kernel threads which handle interrupts too. They are called threaded interrupt handlers. But they still run in process context!

内核线程在内核空间的进程上下文中运行。虽然有一些内核线程也处理中断。它们被称为线程中断处理程序。但它们仍然在进程上下文中运行!

Hereis an excellent explanation of the vital difference between the 2 contexts!

是对 2 个上下文之间重要区别的极好解释!

Here is one which'll help you gain more understanding!

这里有一个可以帮助您获得更多理解!

What context does the scheduler code run in?

调度程序代码在什么上下文中运行?

As far as I know, process and interrupt are the only 2 contexts.

据我所知,进程和中断是仅有的两个上下文。

回答by Gargi Srinivas

Well there are certain tasks that are neither called via a system call or when handling interrupts. Such are handled as pure kernel contexts, for instance the swapper, the INIT_TASk etc which do not have corresponding code running in the user space.

好吧,有些任务既不会通过系统调用调用,也不会在处理中断时调用。这些作为纯内核上下文处理,例如交换器、INIT_TASk 等,它们没有在用户空间中运行的相应代码。

回答by j?rgensen

There is a handful of states—some may be specializations of others. Also see http://www.kernel.org/doc/htmldocs/kernel-hacking.html.

有几个州——有些可能是其他州的专业化。另请参阅http://www.kernel.org/doc/htmldocs/kernel-hacking.html

  • NMI context (in_nmi())
  • hard interrupt context (in_irq())
  • soft interrupt context (in_softirq())
  • (tasklet, timer, and workqueue contexts)
  • atomic context (in_atomic()). Possibly entryways are, among others, spin_lock.
  • RCU context, enter with rcu_read_lockfor example
  • user context
  • NMI 上下文 ( in_nmi())
  • 硬中断上下文 ( in_irq())
  • 软中断上下文 ( in_softirq())
  • (小任务、计时器和工作队列上下文)
  • 原子上下文 ( in_atomic())。可能的入口有,等等spin_lock
  • RCU 上下文,rcu_read_lock例如输入
  • 用户上下文