当前位置: 首页 > 工具软件 > cpuid > 使用案例 >

cpuid

裘嘉树
2023-12-01

摘录一些东西,备忘

arch\x86\kernel\head_32.s

    /* get vendor info */
    xorl %eax,%eax            # call CPUID with 0 -> return vendor ID
    cpuid
    movl %eax,X86_CPUID        # save CPUID level
    movl %ebx,X86_VENDOR_ID        # lo 4 chars
    movl %edx,X86_VENDOR_ID+4    # next 4 chars
    movl %ecx,X86_VENDOR_ID+8    # last 4 chars

 

\arch\x86\kernel\cpu\intel.c

static int __cpuinit intel_num_cpu_cores(struct cpuinfo_x86 *c)
{
    unsigned int eax, ebx, ecx, edx;

    if (c->cpuid_level < 4)
        return 1;

    /* Intel has a non-standard dependency on %ecx for this CPUID level. */
    cpuid_count(4, 0, &eax, &ebx, &ecx, &edx);
    if (eax & 0x1f)
        return (eax >> 26) + 1;
    else
        return 1;
}

超线程 ,维基连接

https://en.wikipedia.org/wiki/Hyper-threading

\arch\x86\include\asm\Cpufeature.h

#define X86_FEATURE_HT        (0*32+28) /* Hyper-Threading */

\arch\x86\kernel\cpu\Common.c


void __cpuinit detect_ht(struct cpuinfo_x86 *c)
{
#ifdef CONFIG_X86_HT
    u32 eax, ebx, ecx, edx;
    int index_msb, core_bits;
    static bool printed;

    if (!cpu_has(c, X86_FEATURE_HT))
        return;

    if (cpu_has(c, X86_FEATURE_CMP_LEGACY))
        goto out;

    if (cpu_has(c, X86_FEATURE_XTOPOLOGY))
        return;

    cpuid(1, &eax, &ebx, &ecx, &edx);

    smp_num_siblings = (ebx & 0xff0000) >> 16;

    if (smp_num_siblings == 1) {
        printk_once(KERN_INFO "CPU0: Hyper-Threading is disabled\n");
        goto out;
    }

    if (smp_num_siblings <= 1)
        goto out;

    index_msb = get_count_order(smp_num_siblings);
    c->phys_proc_id = apic->phys_pkg_id(c->initial_apicid, index_msb);

    smp_num_siblings = smp_num_siblings / c->x86_max_cores;

    index_msb = get_count_order(smp_num_siblings);

    core_bits = get_count_order(c->x86_max_cores);

    c->cpu_core_id = apic->phys_pkg_id(c->initial_apicid, index_msb) &
                       ((1 << core_bits) - 1);

out:
    if (!printed && (c->x86_max_cores * smp_num_siblings) > 1) {
        printk(KERN_INFO  "CPU: Physical Processor ID: %d\n",
               c->phys_proc_id);
        printk(KERN_INFO  "CPU: Processor Core ID: %d\n",
               c->cpu_core_id);
        printed = 1;
    }
#endif
}

 

\arch\x86\kenel\cpu

static void __cpuinit init_intel(struct cpuinfo_x86 *c)

里面会detect_ht

\arch\x86\kernel\cpu\Common.c

static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)

里面会调用detect_ht

#ifdef CONFIG_X86_64

#ifdef CONFIG_X86_HT

------------------疲劳的分割线,明天再看--------------------

 类似资料:

相关阅读

相关文章

相关问答