Linux芯片级移植与底层驱动(基于3.7.4内核) –SMP多核启动以及CPU热插拔驱动

宋宝华 Barry Song <21cnbao@gmail.com>

新浪微博: @宋宝华Barry

在Linux系统中,对于多核的ARM芯片而言,Bootrom代码中,CPU0会率先起来,引导Bootloader和Linux内核执行,而其他的核则在上电时Bootrom一般将自身置于WFI或者WFE状态,并等待CPU0给其发CPU核间中断(IPI)或事件(一般透过SEV指令)唤醒之。一个典型的启动过程如下图:

被CPU0唤醒的CPUn可以在运行过程中进行热插拔。譬如运行如下命令即可卸载CPU1并且将CPU1上的任务全部迁移到其他CPU:

# echo 0 > /sys/devices/system/cpu/cpu1/online

同样地,运行如下命令可以再次启动CPU1:

# echo 1 > /sys/devices/system/cpu/cpu1/online

之后CPU1会主动参与系统中各个CPU之间要运行任务的负载均衡工作。

CPU0唤醒其他 CPU的动作在内核中被封装为一个smp_operations的结构体,该结构体的成员如下:

83struct smp_operations {

84#ifdef CONFIG_SMP

85 /*

86 * Setup the set of possible CPUs (via set_cpu_possible)

87 */

88 void (*smp_init_cpus)(void);

89 /*

90 * Initialize cpu_possible map, and enable coherency

91 */

92 void (*smp_prepare_cpus)(unsigned int max_cpus);

93

94 /*

95 * Perform platform specific initialisation of the specified CPU.

96 */

97 void (*smp_secondary_init)(unsigned int cpu);

98 /*

99 * Boot a secondary CPU, and assign it the specified idle task.

100 * This also gives us the initial stack to use for this CPU.

101 */

102 int (*smp_boot_secondary)(unsigned int cpu, struct task_struct *idle);

103#ifdef CONFIG_HOTPLUG_CPU

104 int (*cpu_kill)(unsigned int cpu);

105 void (*cpu_die)(unsigned int cpu);

106 int (*cpu_disable)(unsigned int cpu);

107#endif

108#endif

109};

我们从arch/arm/mach-vexpress/v2m.c看到VEXPRESS电路板用到的smp_ops为vexpress_smp_ops:

666DT_MACHINE_START(VEXPRESS_DT, "ARM-Versatile Express")

667 .dt_compat = v2m_dt_match,

自己打败自己的远远多于比别人打败的。

Linux芯片级移植与底层驱动(基于3.7.4内核) –SMP多核启动以及CPU热插拔驱动

相关文章:

你感兴趣的文章:

标签云: