C / C ++ /汇编编程方式检测是否超线程活跃在Windows,Mac和Linux [英] C/C++/Assembly Programatically detect if hyper-threading is active on Windows, Mac and Linux

查看:126
本文介绍了C / C ++ /汇编编程方式检测是否超线程活跃在Windows,Mac和Linux的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经可以正确地检测正确的逻辑处理器的数量在所有这三个平台。

I can already correctly detect the number of logical processors correctly on all three of these platforms.

要能够检测物理处理器/核心的数量正确我必须检测是否超线程支持和主动(或启用如果preFER),如果是这样除以2,逻辑处理器的数量确定物理处理器的数目。

To be able to detect the number of physical processors/cores correctly I'll have to detect if hyperthreading is supported AND active (or enabled if you prefer) and if so divide the number of logical processors by 2 to determine the number of physical processors.

Perphaps我应该提供一个例子:

Perphaps I should provide an example:

一个四核Intel的CPU与超线程有4个物理核心,然而8个逻辑处理器(超线程创建4个逻辑处理器)。所以,我目前的功能将检测8,而不是预期的4。

A quad core Intel CPU's with hyperthreading enabled has 4 physical cores, yet 8 logical processors (hyperthreading creates 4 more logical processors). So my current function would detect 8 instead of the desired 4.

因此​​,我的问题是,如果有一种方法来检测是否超线程支持和启用?

My question therefore is if there is a way to detect whether hyperthreading is supported AND ENABLED?

推荐答案

在Windows 2003 Server和Windows XP SP3或更高版本,你可以决定使用的 GetLogicalProcessorInformation 系统调用。

On Windows 2003 Server and Windows XP SP3 and later, you can determine this information using the GetLogicalProcessorInformation system call.

这篇关于C / C ++ /汇编编程方式检测是否超线程活跃在Windows,Mac和Linux的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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