gpt4 book ai didi

c++ - 逻辑 CPU 计数返回 16 而不是 4

转载 作者:太空狗 更新时间:2023-10-29 23:51:05 24 4
gpt4 key购买 nike

我有一个 Intel Core i5-2450m(2 个物理处理器和 4 个逻辑处理器),我想找到一种方法来计算 AMD 和 Intel CPU 上的逻辑和物理内核。但是,经过一些搜索,我发现了一些奇怪的事情。我的代码没有返回 4 个逻辑单元,而是返回 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 .

因此 16 与您的逻辑 CPU 的实际数量无关。在我的机器上 CPUID.1:EBX[23:16] 也返回 16,尽管它有 8 个逻辑 CPU。

用于计算实际逻辑 CPU 的示例代码也可以在链接的白皮书中找到。

关于c++ - 逻辑 CPU 计数返回 16 而不是 4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24088837/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com