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


發佈了33 篇原創文章 · 獲贊 77 · 訪問量 19萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章