5

我正在开发一个准系统,我需要在启动后的某个时间确定启用了多少内核和线程,以便我可以向它们发送 SIPI 事件。我还希望每个线程都知道它是哪个线程。

例如,在启用了 HT 的单核配置中,我们有(例如,Intel Atom):

thread 0 --> core 0 thread 0
thread 1 --> core 0 thread 1

在没有 HT 的双核配置中(例如,Core 2 Duo):

thread 0 --> core 0 thread 0
thread 1 --> core 1 thread 0

确定这一点的最佳方法是什么?

编辑: 我发现每个线程如何找到它是哪个线程。我还没有找到如何确定有多少核心。

4

1 回答 1

7

我研究了一下,得出了这些事实。 cpuidwitheax = 01h返回 APIC ID inEBX[31:24]和 HT enable in EDX[28]

这段代码应该可以完成工作:

    ; 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:
于 2009-04-26T12:28:20.480 回答