4

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

  1. 获取on_cpu结构中的字段task_struct
  2. 获取cpustruct中的字段thread_info

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

[ 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

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

4

1 回答 1

1

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

The on_cpu flag in task_struct is actually a lock when context switching and wanting to have interrupts enabled during a context switch in order to avoid high latency by having an unlocked runqueue. Basically when it's 0 then the task can be moved to a different cpu.

于 2012-11-22T14:30:01.930 回答