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

标签 c++ c intel cpuid

我有一个 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/

相关文章:

c++ - 编译 private.hpp OpenCV 3.0.0-rc1 时出错

c++ - 为什么它是指向 void 声明符的指针而不是指向成员函数的指针?

C++ 谷歌测试 (gtest) : how to create custom asserts and expects?

c - netlink_kernel_create 函数出错

计算最佳定时器间隔 (timer_settime)

c++ - Mac 上的段错误 11,C++ unsigned int 声明

c - 根据另一个数组的大小分配 C 数组

assembly - 有什么方法可以编写 Intel CPU 直接核对核通信代码吗?

linux - 你如何在 Linux 中组装、链接和运行 .s 文件?

assembly - 我可以在每个内核的基础上编写汇编代码吗?