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

时间:2012-11-22 07:43:42

标签: linux kernel

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

  1. 在结构on_cpu
  2. 中获取字段task_struct
  3. 在结构cpu中获取字段thread_info
  4. 我编写了一个内核模块编程来探测这两个字段,然后得到 结果如下:

    [ 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
    

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

1 个答案:

答案 0 :(得分:1)

cpu中的thread_info字段指定执行进程的CPU的编号。这就是你要找的东西。

on_cpu中的task_struct标志实际上是上下文切换时的锁定,并且希望在上下文切换期间启用中断,以避免因解锁的runqueue而导致高延迟。基本上当它为0时,任务可以移动到不同的cpu。

相关问题