smp_setup_processor_id - cpu_logical_map my_cpu_offset

 

linux/arch/arm64/kernel/setup.c

 

  85void __init smp_setup_processor_id(void)
  86{
  87        u64 mpidr = read_cpuid_mpidr() & MPIDR_HWID_BITMASK;
  88        set_cpu_logical_map(0, mpidr);
  89
  90        /*
  91         * clear __my_cpu_offset on boot CPU to avoid hang caused by
  92         * using percpu variable early, for example, lockdep will
  93         * access percpu variable inside lock_release
  94         */
  95        set_my_cpu_offset(0);
  96        pr_info("Booting Linux on physical CPU 0x%010lx [0x%08x]\n",
  97                (unsigned long)mpidr, read_cpuid_id());
  98}
  99

 

87 ~ 88 行,cpu_logical_map 的 index 0  里面填入  启动 cpu 的 mpidr 寄存器里面取得的信息。

95  行 - 启动cpu的 tpidr_el1/ tpid_el2 寄存器里面写入 0. 【表示 这个 cpu 编号是0,访问percpu 变量时,访问第0号cpu的变量副本】

 

1、mpidr_el1 相关信息 寄存器表示-亲和性-也具有唯一性,所以可以填入logical_map里面

https://developer.arm.com/documentation/ddi0595/2021-12/AArch64-Registers/MPIDR-EL1--Multiprocessor-Affinity-Register?lang=en 

[63:40]:Reserved, RES0.
[39:32]:Affinity level 3。有关更多信息,请参阅Aff0的描述。
[31]:Reserved, RES1.
[30]:U。表示一个单处理器系统,与多处理器系统中的pe0不同。这个位的可能值是:
0b0 :处理器是多处理器系统的一部分。
0b1 :处理器是单处理器系统的一部分。
[29:25]:Reserved, RES0.
[24]:MT。指示关联的最低级别是否由使用多线程类型方法实现的逻辑PEs组成。这个位的值可能是:
0b0 当PEs的性能关联级别最低,或者使用MPIDR_EL1.MT的PEs被设置为1时,级别0的不同值或者级别1的相同值或更高级别,是相互独立的
0b1 当PEs的性能关联级别最低,或者使用MPIDR_EL1.MT的PEs被设置为1时,级别0的不同值或者级别1的相同值或更高级别的相关性非常高
[23:16] Affinity level 2.
[15:8] Affinity level 1.
[7:0] Affinity level 0. 这个Affinity等级对于确定PE行为最为重要。更高级别的affinity 等级的重要性越低。
————————————————
版权声明:本文为CSDN博主「qijiuliushisan」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qijiuliushisan/article/details/108580158

 

The assigned value of the MPIDR.{Aff2, Aff1, Aff0} or MPIDR_EL1.{Aff3, Aff2, Aff1, Aff0} set of fields of each PE must be unique within the system as a whole.

 

arch/arm64/include/asm/cputype.h

 197static inline u32 __attribute_const__ read_cpuid_id(void)
 198{
 199        return read_cpuid(MIDR_EL1);
 200}
 201
 202static inline u64 __attribute_const__ read_cpuid_mpidr(void)
 203{
 204        return read_cpuid(MPIDR_EL1);
 205}

 

midr main id register 信息在这儿 - midr_el1 里面的内容不保证唯一性,仅仅表示 CPU的厂商,架构,版本号等内容。类似于商品信息-条形码。

https://developer.arm.com/documentation/ddi0595/2021-12/AArch32-Registers/MIDR--Main-ID-Register?lang=en

 

arch/arm64/include/asm/cputype.h

10#define MPIDR_UP_BITMASK        (0x1 << 30)
  11#define MPIDR_MT_BITMASK        (0x1 << 24)
  12#define MPIDR_HWID_BITMASK      UL(0xff00ffffff)   //       ff 00 ff ff ff

 

95 行- set_my_cpu_offset(0)

1、这个和 percpu 变量相关 , 参考  https://www.cnblogs.com/zhangzhiwei122/p/16054079.html

2、使用了cpu 上面的 tpidr_el1 寄存器。这个寄存器里面可以写入/读取 自定义的一份数据。

 

TPIDR_EL1, EL1 Software Thread ID Register

Provides a location where software executing at EL1 can store thread identifying information, for OS management purposes.

 

https://developer.arm.com/documentation/ddi0595/2021-12/AArch64-Registers/TPIDR-EL1--EL1-Software-Thread-ID-Register?lang=en

 

posted @ 2022-03-24 20:25  张志伟122  阅读(399)  评论(0编辑  收藏  举报