我想知道Linux系统中当前进程运行在哪个cpu上, 我有两个选择 —
- 获取struct
task_struct
或 中的字段 - 获取结构
thread_info
中的字段cpu
。
on_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/