如何在内核模块中查找物理和逻辑核心号? [英] How to find physical and logical core number in a kernel module?

查看:79
本文介绍了如何在内核模块中查找物理和逻辑核心号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Linux中是否有内核函数会返回物理内核的编号和 内核模块在其上运行的逻辑核心(在超线程的情况下)?

Are there kernel functions in Linux that would return the number of the physical core and logical core (in case of Hyperthreading) on which a kernel module is running ?

推荐答案

看看include/linux/smp.h的结尾:smp_processor_id() 为您提供当前正在执行的CPU的编号. get_cpu()可以 一样,并且还会禁用抢占,这样您就可以继续 直到put_cpu()被调用为止.

Have a look at the end of include/linux/smp.h: smp_processor_id() gives you the number of the current executing CPU. get_cpu() will do the same and will also disable preemption so that you will stay on that CPU until put_cpu() is called.

在用户空间中,您可以使用sched_getcpu()getcpu()来获取相同的信息.

From user-space, you can use sched_getcpu() or getcpu() to obtain the same information.

这篇关于如何在内核模块中查找物理和逻辑核心号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆