[Author: Bo Shen <[email protected]>]
[Linux kernel: git: 0c0bd34]
<init/main.c>
470 void __init smp_setup_processor_id(void) 471 { 472 int i; 473 u32 mpidr = is_smp() ? read_cpuid_mpidr() & MPIDR_HWID_BITMASK : 0; 474 u32 cpu = MPIDR_AFFINITY_LEVEL(mpidr, 0); 475 476 cpu_logical_map(0) = cpu; 477 for (i = 1; i < nr_cpu_ids; ++i) 478 cpu_logical_map(i) = i == cpu ? 0 : i; 479 480 /* 481 * clear __my_cpu_offset on boot CPU to avoid hang caused by 482 * using percpu variable early, for example, lockdep will 483 * access percpu variable inside lock_release 484 */ 485 set_my_cpu_offset(0); 486 487 pr_info("Booting Linux on physical CPU 0x%x\n", mpidr); 488 }
474: cpu = 0
476: 数组0元素赋值。
477: nr_cpu_ids的值是由NR_CPUS决定的。 if NR_CPUS == 1 那么nr_cpu_ids = 1。NR_CPUS是CONFIG_NR_CPUS决定。对单核SOC来说,没有定义CONFIG_NR_CPUS, 所以CONFIG_NR_CPUS = 1, 最后nr_cpu_ids = 1. 所以477, 488不执行。
485:<arch/arm/include/asm/percpu.h>,因为没有定义CONFIG_SMP所以为空函数。do { } while(0)