==============================================
本文系本站原创,欢迎转载!转载请注明出处:
http://blog.csdn.net/gdt_a20/article/details/7220389
==============================================
进入init/main.c
start_kernel
asmlinkage void __init start_kernel(void){
char * command_line;
extern const struct kernel_param __start___param[], __stop___param[];
smp_setup_processor_id();
/*
* Need to run as early as possible, to initialize the
* lockdep hash:
*/
lockdep_init();
debug_objects_early_init();
/*
* Set up the the initial canary ASAP:
*/
boot_init_stack_canary();
cgroup_init_early();
================
第一个函数smp_setup_processor_id();
arch/arm/smp.c
================int __cpu_logical_map[NR_CPUS];
void __init smp_setup_processor_id(void)
{
int i;
u32 cpu = is_smp() ? read_cpuid_mpidr() & 0xff : 0; //判断是否是smp系统,如果是读取当前cpuid,否则为0
//存在多cpu,判断哪个cpu是当前cpu
cpu_logical_map(0) = cpu; //当前cpu赋值给cpu第一个表项
for (i = 1; i < NR_CPUS; ++i)
cpu_logical_map(i) = i == cpu ? 0 : i; //当前cpu如果不是0,那么会把他安排到数组第一项,则原来位置要用0填充
printk(KERN_INFO "Booting Linux on physical CPU %d\n", cpu);
}
================
arch/arm/include/asm/smp_plat.h
/*
* Return true if we are running on a SMP platform
*/
static inline bool is_smp(void)
{
#ifndef CONFIG_SMP
return false;
#elif defined(CONFIG_SMP_ON_UP)
extern unsigned int smp_on_up;
return !!smp_on_up;
#else
return true;
#endif
}
===============
可以配置是否为smp
===============
static inline unsigned int __attribute_const__ read_cpuid_mpidr(void)
{
return read_cpuid(CPUID_MPIDR);
}
arch/arm/include/asm/cputype.h
===============
#define read_cpuid(reg) \
({ \
unsigned int __val; \
asm("mrc p15, 0, %0, c0, c0, " __stringify(reg) \
: "=r" (__val) \
: \
: "cc"); \
__val; \
})
===============
1 /*
2 * Logical CPU mapping.
3 */
4 extern int __cpu_logical_map[NR_CPUS];
5 #define cpu_logical_map(cpu) __cpu_logical_map[cpu]
Thanks