【问题标题】:Assembly instructions to find how many threads are enabled in a multi-core system查找多核系统中启用了多少线程的汇编指令
【发布时间】:2010-10-21 21:34:46
【问题描述】:

我正在开发一个准系统,我需要在启动后的某个时间确定启用了多少内核和线程,以便我可以向它们发送 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

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

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

【问题讨论】:

    标签: assembly x86 multicore


    【解决方案1】:

    我研究了一下,得出了这些事实。 cpuideax = 01hEBX[31:24] 中返回 APIC ID,在 EDX[28] 中启用 HT。

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

        ; 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:
    

    【讨论】:

      猜你喜欢
      • 2016-06-17
      • 2023-04-02
      • 1970-01-01
      • 1970-01-01
      • 2011-04-08
      • 1970-01-01
      • 2016-12-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多