以内核中/arch/arm64/kvm/arm.c为例,在内核初始化时注册了一个
CPU 低功耗事件发生时的接收通知器,用于处理 CPU 低功耗事件:
1 2 3 4 5 6
//file: arm.c staticvoid __init hyp_cpu_pm_init(void) { if (!is_protected_kvm_enabled()) cpu_pm_register_notifier(&hyp_init_cpu_pm_nb); }
上述通知器中,cpu_pm_register_notifier函数是 LPI
模块在cpu_pm.c中定义的一个通知链函数,hyp_cpu_pm_init通过调用该函数,可以实现将
hyp_init_cpu_pm_nb回调结构体注册到 CPU 低功耗通知链中,使
KVM 模块也能作为 CPU 低功耗事件发生时的一个观察者。
//file: cpu_pm.c /** * cpu_pm_register_notifier - register a driver with cpu_pm * @nb: notifier block to register * * Add a driver to a list of drivers that are notified about * CPU and CPU cluster low power entry and exit. * * This function has the same return conditions as raw_notifier_chain_register. */ intcpu_pm_register_notifier(struct notifier_block *nb) { unsignedlong flags; int ret;
//file: cpu_pm.c staticintcpu_pm_notify(enum cpu_pm_event event) { int ret;
rcu_read_lock(); ret = raw_notifier_call_chain(&cpu_pm_notifier.chain, event, NULL); rcu_read_unlock();
return notifier_to_errno(ret); }
/** * cpu_pm_exit - CPU low power exit notifier * * Notifies listeners that a single CPU is exiting a low power state that may * have caused some blocks in the same power domain as the cpu to reset. * * Notified drivers can include VFP co-processor, interrupt controller * and its PM extensions, local CPU timers context save/restore which * shouldn't be interrupted. Hence it must be called with interrupts disabled. * * Return conditions are same as __raw_notifier_call_chain. */ intcpu_pm_exit(void) { return cpu_pm_notify(CPU_PM_EXIT); } EXPORT_SYMBOL_GPL(cpu_pm_exit);