linux - struct task_struct中的字段 'on_cpu'和struct thread_info中的字段 'cpu'是什么意思?

标签 linux kernel

我想知道Linux系统中当前进程运行在哪个cpu上, 我有两个选择 —

  1. 获取struct task_struct
  2. 中的字段on_cpu
  3. 获取结构thread_info中的字段cpu

我写了一个内核模块程序来探测这两个字段,并得到 结果如下:

[ 3991.419185] the field 'on_cpu' in task_struct is :1
[ 3991.419187] the field 'cpu' in thread_info is :0
[ 3991.419199] the field 'on_cpu' in task_struct is :1
[ 3991.419200] the field 'cpu' in thread_info is :0
[ 3991.419264] the field 'on_cpu' in task_struct is :1
[ 3991.419266] the field 'cpu' in thread_info is :1
[ 3991.419293] the field 'on_cpu' in task_struct is :1
[ 3991.419294] the field 'cpu' in thread_info is :1
[ 3991.419314] the field 'on_cpu' in task_struct is :1
[ 3991.419315] the field 'cpu' in thread_info is :1
[ 3991.419494] the field 'on_cpu' in task_struct is :1
[ 3991.419495] the field 'cpu' in thread_info is :0
[ 3991.419506] the field 'on_cpu' in task_struct is :1
[ 3991.419507] the field 'cpu' in thread_info is :1

而且我不知道这两个字段的正确含义。

最佳答案

thread_info 中的cpu 字段指定进程正在执行的 CPU 编号。这就是您要搜索的内容。

task_struct 中的 on_cpu 标志实际上是上下文切换时的锁,并且希望在上下文切换期间启用中断以避免通过解锁运行队列来避免高延迟.基本上当它为 0 时,任务可以移动到不同的 cpu。

关于linux - struct task_struct中的字段 'on_cpu'和struct thread_info中的字段 'cpu'是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13507927/

相关文章:

linux - 集中式和分布式版本控制团队的优缺点

linux - 远程设置环境变量?

linux - 为什么根据 LDD3 device->kobj->parent 等于 &device->parent->kobj?

linux - 如何初始化semaphore.h?

c - 多管道不起作用

linux - 如何为我的 Linux 游戏禁用 gnome 窗口管理器键盘快捷键?

linux - 进程因内存过多而被杀死?

c - 如何迭代 kmem_caches?

c - 如何在内核模式下使用 ZwQuerySystemInformation() 获取线程 ID?

linux - 操作系统如何知道缺失页面的磁盘地址?