gdt-A20

导航

linux启动流程导读(arm为例)<二>

进入init/main.c

start_kernel

 1 asmlinkage void __init start_kernel(void)
2 {
3 char * command_line;
4 extern const struct kernel_param __start___param[], __stop___param[];
5
6 smp_setup_processor_id();
7
8 /*
9 * Need to run as early as possible, to initialize the
10 * lockdep hash:
11 */
12 lockdep_init();
13 debug_objects_early_init();
14
15 /*
16 * Set up the the initial canary ASAP:
17 */
18 boot_init_stack_canary();
19
20 cgroup_init_early();
...
...
...

第一个函数smp_setup_processor_id();

arch/arm/smp.c

 1 int __cpu_logical_map[NR_CPUS];
2
3 void __init smp_setup_processor_id(void)
4 {
5 int i;
6 u32 cpu = is_smp() ? read_cpuid_mpidr() & 0xff : 0; //判断是否是smp系统,如果是读取当前cpuid,否则为0
7 //存在多cpu,判断哪个cpu是当前cpu
8 cpu_logical_map(0) = cpu; //当前cpu赋值给cpu第一个表项
9 for (i = 1; i < NR_CPUS; ++i)
10 cpu_logical_map(i) = i == cpu ? 0 : i; //当前cpu如果不是0,那么会把他安排到数组第一项,则原来位置要用0填充
11
12 printk(KERN_INFO "Booting Linux on physical CPU %d\n", cpu);
13 }

arch/arm/include/asm/smp_plat.h

 1 /*
2 * Return true if we are running on a SMP platform
3 */
4 static inline bool is_smp(void)
5 {
6 #ifndef CONFIG_SMP
7 return false;
8 #elif defined(CONFIG_SMP_ON_UP)
9 extern unsigned int smp_on_up;
10 return !!smp_on_up;
11 #else
12 return true;
13 #endif
14 }

 可以配置是否为smp   。

1 static inline unsigned int __attribute_const__ read_cpuid_mpidr(void)
2 {
3 return read_cpuid(CPUID_MPIDR);
4 }

 

 arch/arm/include/asm/cputype.h

1 #define read_cpuid(reg)                            \
2 ({ \
3 unsigned int __val; \
4 asm("mrc p15, 0, %0, c0, c0, " __stringify(reg) \
5 : "=r" (__val) \
6 : \
7 : "cc"); \
8 __val; \
9 })

 

1 /*
2 * Logical CPU mapping.
3 */
4 extern int __cpu_logical_map[NR_CPUS];
5 #define cpu_logical_map(cpu) __cpu_logical_map[cpu]






posted on 2012-01-15 22:57  gdt-A20  阅读(1146)  评论(0编辑  收藏  举报