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

==============================================

本文系本站原创,欢迎转载!转载请注明出处:

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


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值