struct task_struct中的“on_cpu”字段和struct thread_info中的“cpu”字段的含义是什么?

我想知道当前进程在Linux系统上运行的CPU,我有两个select –

  1. 在struct task_struct获取字段on_cpu
  2. 在struct 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_infocpu字段指定正在执行进程的CPU的编号。 这是你正在寻找的。

task_structon_cpu标志实际上是上下文切换时的锁,并且希望在上下文切换期间启用中断,以便通过解锁runqueue来避免高延迟。 基本上当它是0时,任务可以被移动到不同的CPU。