【原创】Linux cpu hotplug
背景 Read the fucking source code! --By 鲁迅 A picture is worth a thousand words. --By 高尔基 说明: Kernel版本:4.14 ARM64处理器 使用工具:Source Insight 3.5, Visio 1. 介绍 Linux CPU热插拔,支持在系统启动后,关闭任意一个 secondary cpu (在ARM架构中,CPU0为 boot cpu ,不能被关闭),并在需要时重新打开它。 CPU-hotplug 的一个用处是,支持SMP的 Suspend 和 Resume ,这个也是我看 CPU-hotplug 的原因。 代码路径: include/linux/cpuhotplug.h kernel/cpu.c kernel/smpboot.c arch/arm64/kernel/smp.c 2. 数据结构 关键的数据结构有三种,如下图所示: struct cpuhp_cpu_state :用来存储hotplug的状态; enum cpuhp_state :枚举各种状态,这个会对应到全局数组中的某一项,而该项中会定义回调函数。当然,也可以通过函数接口来设置回调函数。 struct cpuhp_step :Hotplug state machine step,主要定义了函数指针