逻辑CPU数回报16而不是4 [英] Logical CPU count return 16 instead of 4

查看:323
本文介绍了逻辑CPU数回报16而不是4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个英特尔酷睿i5-2450M(2个物理处理器和4个逻辑处理器),我想找到一种方法,依靠AMD和英特尔CPU的逻辑和物理内核。
但是,一些搜索后,我发现了一些奇怪的。而不是返回4个逻辑单元,我的code给我16。

 静态LogicalProcCount中int8_t(无效)
{
    如果(!超线程)
        返回1;    uint32_t的未使用的,EBX;
    CPUID(1,未使用的,EBX,未使用的,未使用的);    返回(中int8_t)((EBX>> 16)及为0xFF);
}


解决方案

  

CPUID.1:EBX [23:16] 重新presents的的最大数量的可寻址的ID(初始APIC ID)的可以分配给逻辑处理器在物理包


<一个href=\"https://software.intel.com/en-us/articles/intel-64-architecture-processor-topology-enumeration\">Source.

所以16无关,与你的逻辑CPU的实际数量。在我的机器 CPUID.1:EBX [23:16] 也返回16,虽然它有8个逻辑CPU

样code来算实际的逻辑CPU可以在链接whire纸上还发现了。

I have a Intel Core i5-2450m (2 physical processors and 4 logical processors) and I want to find a way to count logical and physical cores on AMD and Intel CPUs. But, after some searches I noticed something strange. Instead of returning 4 logical units, my code give me 16.

static int8_t LogicalProcCount(void)
{
    if ( !Hyperthreading )
        return 1;

    uint32_t unused, ebx;
    CPUID(1, unused, ebx, unused, unused);

    return (int8_t) ( (ebx >> 16 ) & 0xFF );
}

解决方案

CPUID.1:EBX[23:16] represents the maximum number of addressable IDs (initial APIC ID) that can be assigned to logical processors in a physical package.

Source.

So 16 has nothing to do with the actual number of your logical CPUs. On my machine CPUID.1:EBX[23:16] also returns 16, though it has 8 logical CPUs.

Sample code to count actual logical CPUs can be also found in the linked whire paper.

这篇关于逻辑CPU数回报16而不是4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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