我想知道Linux系统中当前进程正在运行哪个cpu, 我有两个选择 -
on_cpu
或task_struct
cpu
中获取字段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
我不知道这两个字段的正确含义。
答案 0 :(得分:1)
cpu
中的thread_info
字段指定执行进程的CPU的编号。这就是你要找的东西。
on_cpu
中的task_struct
标志实际上是上下文切换时的锁定,并且希望在上下文切换期间启用中断,以避免因解锁的runqueue而导致高延迟。基本上当它为0时,任务可以移动到不同的cpu。