flat assembler
Message board for the users of flat assembler.
Index
> Main > How to get number of physical cores? |
Author |
|
revolution 06 Apr 2016, 07:16
It might be more fruitful to call the OS API to get the number of available cores for the program. The number physical and available cores are not always the same.
And to ignore HT you need to map from the OSes available cores to the physically implemented threads. And to make things more interesting different OSes map these in different orders. The only really sure way to ensure that you are not sharing a core with two threads is to disable HT in the BIOS. For that you need to convince the user to check and/or alter BIOS settings which might be difficult depending upon the exact usage situation. |
|||
06 Apr 2016, 07:16 |
|
Feryno 06 Apr 2016, 11:11
Hi SergeASM, as revolution pointed you, e.g. ms win OS may start with /singlecpu boot switch and in that case CPUID reports something else than running OS is using.
64-ia-32-architectures-software-developer-vol-2a-manual.pdf The CPUID leaf 04H also reports data that can be used to derive the topology of processor cores in a physical package. This information is constant for all valid index values. Software can query the raw data reported by executing CPUID with EAX=04H and ECX=0 and use it as part of the topology enumeration algorithm described in Chapter 8, “Multiple-Processor Management,” in the Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 3A. 64-ia-32-architectures-software-developer-system-programming-manual-325384.pdf 8.6 DETECTING HARDWARE MULTI-THREADING SUPPORT AND TOPOLOGY Use the CPUID instruction to detect the presence of hardware multi-threading support in a physical processor. Hardware multi-threading can support several varieties of multigrade and/or Intel Hyper-Threading Technology. CPUID instruction provides several sets of parameter information to aid software enumerating topology information. The relevant topology enumeration parameters provided by CPUID include: • Hardware Multi-Threading feature flag (CPUID.1:EDX[28] = 1) — Indicates when set that the physical package is capable of supporting Intel Hyper-Threading Technology and/or multiple cores. • Processor topology enumeration parameters for 8-bit APIC ID: — Addressable IDs for Logical processors in the same Package (CPUID.1:EBX[23:16]) — Indicates the maximum number of addressable ID for logical processors in a physical package. Within a physical package, there may be addressable IDs that are not occupied by any logical processors. This parameter does not represents the hardware capability of the physical processor. Addressable IDs for processor cores in the same Package6 (CPUID.(EAX=4, ECX=07):EAX[31:26] + 1 = Y) — Indicates the maximum number of addressable IDs attributable to processor cores (Y) in the physical package. • Extended Processor Topology Enumeration parameters for 32-bit APIC ID: Intel 64 processors supporting CPUID leaf 0BH will assign unique APIC IDs to each logical processor in the system. CPUID leaf 0BH reports the 32-bit APIC ID and provide topology enumeration parameters. See CPUID instruction reference pages in Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 2A. The CPUID feature flag may indicate support for hardware multi-threading when only one logical processor available in the package. In this case, the decimal value represented by bits 16 through 23 in the EBX register will have a value of 1. Software should note that the number of logical processors enabled by system software may be less than the value of “Addressable IDs for Logical processors”. Similarly, the number of cores enabled by system software may be less than the value of “Addressable IDs for processor cores”. Software can detect the availability of the CPUID extended topology enumeration leaf (0BH) by performing two steps: • Check maximum input value for basic CPUID information by executing CPUID with EAX= 0. If CPUID.0H:EAX is greater than or equal or 11 (0BH), then proceed to next step, • Check CPUID.EAX=0BH, ECX=0H:EBX is non-zero. If both of the above conditions are true, extended topology enumeration leaf is available. Note the presence of CPUID leaf 0BH in a processor does not guarantee support that the local APIC supports x2APIC. If CPUID.(EAX=0BH, ECX=0H):EBX returns zero and maximum input value for basic CPUID information is greater than 0BH, then CPUID.0BH leaf is not supported on that processor. |
|||
06 Apr 2016, 11:11 |
|
SergeASM 06 Apr 2016, 12:29
Thanks to all, but I think, some programmers already solve this hard
mind-breaker? May be WIN API GetSystemInfo, GetLogicalProcessorInformationEx will help? |
|||
06 Apr 2016, 12:29 |
|
revolution 06 Apr 2016, 14:28
Since you now say you are using windows then look at GetProcessAffinityMask. However that won't tell you anything about HT.
|
|||
06 Apr 2016, 14:28 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.