Logical CPU count return 16 instead of 4

前端 未结 2 1889
走了就别回头了
走了就别回头了 2021-01-15 03:40

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

相关标签:
2条回答
  • 2021-01-15 03:46

    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.

    0 讨论(0)
  • 2021-01-15 04:05

    A more complete answer would be that for Intel processors made before 2010 that kind code was usually okay. (I'd like to hear about counter-examples though!) That kind of counting routine was even given in an older Intel presentation dating to 2007(?) or so https://software.intel.com/en-us/articles/hyper-threading-technology-and-multi-core-processor-detection (Don't let the posting date the fool you; when that presentation was made the Intel Core wasn't yet public and the Pentium Extreme Edition was Intel's top offering.) Rather shamefully, that algorithm is still given in the MSDN page about __cpuid, even for their 2013 edition! (http://msdn.microsoft.com/en-us/library/hskdteyh.aspx) The MSDN sample code hasn't been updated since 2008...

    In early 2010 Intel put out Westmere processors that have gaps in their APIC id space. So these and later processors need a more refined method of counting their cores. These processors all have x2APIC and support leaf 0xB of cpuid as well... which can tell you about the gaps in the APIC id space, via EAX[4:0] and exactly how many logical processors are present at each level (package/core) via EBX. The link provided by n.m. is the authoritative one, albeit rather dry. Basically all you have to do is call cpuid with EAX=0xB, ECX=1 and you'll have the correct number of logical processors per package returned in EBX.

    Also, the part of question about AMD was not answered. AMD has a different methodology because they don't support the same cpuid leaves as Intel. The most up to date info I could find about AMD (from 2013) is at http://developer.amd.com/resources/documentation-articles/articles-whitepapers/processor-and-core-enumeration-using-cpuid/

    I dug up all this info while updating the Wikipedia page on CPUID today, by the way.

    0 讨论(0)
提交回复
热议问题