3

On a dual quad-core GetProcessAffinityMask (or the dialog from "Set affinity" in taskman.exe) will report eight logical processors. How do I find out which logical processor is on which physical processor? Especially: which logical processors are on the same physical processor?

EDIT: If it is not possible to do this programmatically, do anyone just know what the normal mapping is? Are the first four on the first processor and the second four on the second or are the odd numbered on the first and the even numbered on the second?

Rasmus Faber
  • 48,631
  • 24
  • 141
  • 189
  • All I know is that it is possible because SQL Server 2008 does this, in order to try to parallelize things by putting things that could benefit from fast shared cache on the same physical processor, which involves less cross-processor communication. – Lasse V. Karlsen Jan 08 '09 at 10:12
  • Afaik the scheduler himself does this. I'd be amazed if the SQL-Server-Code does this. – Ronny Brendel Jan 08 '09 at 10:37
  • hydroes, SQL Server does much of its thread and memory management tasks itself as it's a very specialized environment with specialized needs. If had seen raw partitions in SQL, you shouldn't have been that amazed. – Mehrdad Afshari Jan 08 '09 at 10:53
  • @Rasmus, did you look at GetLogicalProcessorInformation API? It IS possible programmatically. Is there anything you need that is not satisfied by that API? – Mehrdad Afshari Jan 08 '09 at 10:53

3 Answers3

7

You can use Win32_Processor WMI class to query the number of cores, number of logical processors, architecture, cache memory and other information about the CPUs on the system.

To query information about the relationship between the logical processors in a system, you can use GetLogicalProcessorInformation API function.

Mehrdad Afshari
  • 414,610
  • 91
  • 852
  • 789
  • I can see how that allows me to detect that I am on a dual quad-core, but I do not see how it allows me to identify whether logical processor 1 is on the same physical processor as logical processor 2. I am missing something? – Rasmus Faber Jan 08 '09 at 10:22
  • I think this API function better suits your specific need. – Mehrdad Afshari Jan 08 '09 at 10:27
  • Thanks, I did not see your edit. GetLogicalProcessorInformation is exactly what I need. – Rasmus Faber Jan 08 '09 at 11:00
2

In case you don't want to write the code yourself, SysInternal's handy coreinfo utility comes closest to answering your questions. It implements GetLogicalProcessorInformation as Mehrdad recommends. For a Xeon E5640 (quad core, 8 threads), you get from coreinfo:

c:\App\SysInternals>Coreinfo.exe -c

Coreinfo v3.0 - Dump information on system CPU and memory topology
Copyright (C) 2008-2011 Mark Russinovich
Sysinternals - www.sysinternals.com

Logical to Physical Processor Map:
**------  Physical Processor 0 (Hyperthreaded)
--**----  Physical Processor 1 (Hyperthreaded)
----**--  Physical Processor 2 (Hyperthreaded)
------**  Physical Processor 3 (Hyperthreaded)

There are 8 * for the 8 hyperthreads, two per core, as expected for this chip. What's not clear, though, is how the arrangement of * matches up with the list of logical processors as Windows presents them. For instance, Task Manager gives me a dialog for assigning the processor affinity, labeled CPU 0 through CPU 7, for any process. It's fair (but not necessary) to assume that you can take coreinfo's output and number the logical processors left-to-right. So "CPU 5" would be the second hyperthread running on physical processor 2.

Sandy Soil
  • 31
  • 3
  • From the `*` output by the command, you could get the impression that "Physical Processor 1" (not 0) corresponds to "logical"/OS processors "CPU 2" and "CPU 3". So I think it is confusing. As you said in your answer, "Physical Processor 1" corresponds to OS's "CPU 1" and "CPU 5". For a hyperthreaded system with physical cores `0, 1, 2, …, N-1` and logical CPUs `0, 1, 2, …, 2N-1`, the physical core with number `j` is mapped to the logical CPUs with numbers `j` and `j+N`. In you example (quad core, 8 hyperthreads), `N=4`. – Jeppe Stig Nielsen May 03 '20 at 11:45
1

The numbering is done in a sequential manner: first all physical cores followed by the logical cores [1] .

[1] CPU Numbering on a hypertheading enabled system

Community
  • 1
  • 1
Jay D
  • 3,263
  • 4
  • 32
  • 48