第20章 Linux芯片级移植及底层驱动之SMP多核启动以及CPU热插拔驱动

20.4 SMP多核启动以及CPU热插拔驱动

    在Linux系统中,对于多核的ARM芯片,在Bootrom代码中,每个CPU都会识别自身ID,如果ID是0,则引导Bootloader和Linux内核执行,如果ID不是0,则Bootrom一般在上电时将自身置于WFI(WaitFortInerrupt)或者WFE(WaitForEvent)状态,并等待CPU0给其发CPU核间中断或事件(一般通过SEV指令)以唤醒它。一个典型的多核Linux启动过程如图20.6所示。


图20.6 一个典型的多核Linux启动过程

    被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的结构体,对于ARM而言,定义于

arch/arm/include/asm/smp.h中。该结构体的成员函数如代码清单20.8所示。

    代码清单20.8 smp_operations结构体

struct smp_operations {
#ifdef CONFIG_SMP
        /*
         * Setup the set of possible CPUs (via set_cpu_possible)
         */
        void (*smp_init_cpus)(void);
        /*
         * Initialize cpu_possible map, and enable coherency
         */
        void (*smp_prepare_cpus)(unsigned int max_cpus);


        /*
         * Perform platform specific initialisation of the specified CPU.
         */
        void (*smp_secondary_init)(unsigned int cpu);
        /*
         * Boot a secondary CPU, and assign it the specified idle task.
         * This also gives us the initial stack to use for this CPU.
         */
        int  (*smp_boot_secondary)(unsigned int cpu, struct task_struct *idle);
#ifdef CONFIG_HOTPLUG_CPU
        int  (*cpu_kill)(unsigned int cpu);
        void (*cpu_die)(unsigned int cpu);
        bool  (*cpu_can_disable)(unsigned int cpu);
        int  (*cpu_disable)(unsigned int cpu);
#endif
#endif

}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值