加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

linux – struct task_struct中字段’on_cpu’和struct thread_i

发布时间:2020-12-13 23:23:34 所属栏目:Linux 来源:网络整理
导读:我想知道 Linux系统中当前进程正在运行哪个cpu, 我有两个选择 – 在struct task_struct或中获取字段on_cpu 在struct thread_info中获取字段cpu. 我编写了一个内核模块编程来探测这两个字段,然后得到 结果如下: [ 3991.419185] the field 'on_cpu' in task_s
我想知道 Linux系统中当前进程正在运行哪个cpu,
我有两个选择 –

>在struct task_struct或中获取字段on_cpu
>在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_info中的cpu字段指定执行进程的CPU的编号.这就是你要搜索的内容.

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读