大会说明找到多少线程在多核心系统启用 [英] Assembly instructions to find how many threads are enabled in a multi-core system
问题描述
我工作一个最基本的系统,我需要启动后的某个确定有多少核心和线程被启用,这样我就可以送他们SIPI事件上。我也希望每个线程知道它是哪个线程。
I'm working on a bare-bones system in which I need to determine sometime after boot how many cores and threads are enabled, so that I can send them SIPI events. I also want each thread to know which thread it is.
例如,在HT单核配置中启用,我们有(例如,英特尔凌动):
For instance, in a single-core configuration with HT enabled, we have (for instance, Intel Atom):
thread 0 --> core 0 thread 0
thread 1 --> core 0 thread 1
虽然没有HT我们有一个双核的配置(例如,酷睿2):
While in a dual-core configuration with no HT we have (for instance, Core 2 Duo):
thread 0 --> core 0 thread 0
thread 1 --> core 1 thread 0
什么是确定最好的方法?
What's the best way to determine this?
编辑:我发现每个线程如何能找到是哪个线程。我还没有找到如何确定多少个核心也有。
I found how each thread can find which thread it is. I still haven't found how to determine how many cores there are.
推荐答案
我研究了一下,这些事实走了过来。 CPUID
与 EAX = 01H
返回的APIC ID EBX [31:24]
和 EDX HT能[28]
。
I researched it a bit and came up with these facts. cpuid
with eax = 01h
returns the APIC ID in EBX[31:24]
and HT enable in EDX[28]
.
这code应该做的工作:
This code should do the work:
; this code will put the thread id into ecx
; and the core id into ebx
mov eax, 01h
cpuid
; get APIC ID from EBX[31:24]
shr ebx, 24
and ebx, 0ffh; not really necessary but makes the code nice
; get HT enable bit from EDX[28]
test edx, 010000000h
jz ht_off
; HT is on
; bit 0 of EBX is the thread
; bits 7:1 are the core
mov ecx, ebx
and ecx, 01h
shr ebx, 1
jmp done
ht_off:
; the thread is always 0
xor ecx, ecx
done:
这篇关于大会说明找到多少线程在多核心系统启用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!