Linux 用户-space 关机或重启时安排

Linux user-space scheduling while shutdown or reboot

 68 void kernel_restart_prepare(char *cmd)
 69 {
 70         blocking_notifier_call_chain(&reboot_notifier_list, SYS_RESTART, cmd);
 71         system_state = SYSTEM_RESTART;
 72         usermodehelper_disable();
 73         device_shutdown();
 74 }

我正在检查 linux 内核源代码 linux/kernel/reboot.c。 在重新启动调用时,将调用上面定义的函数。 我的问题与系统重启有关。由于我们在驱动程序中安装了重启通知程序,因此我们希望确保在重启过程中我们的 user-space 进程不会被调用。

  1. 如果调用reboot,user-space进程是否仍然是运行?
  2. 是否保证如果调用reboot notifier,user-space进程仍然可以运行或调度?
  3. SMP 上的行为是否也得到保证,如果调用 reboot,user-space 不会执行?
  4. 这个调用可以被抢占吗?
  5. 如果驱动注册到reboot-notifier 列表是否满足要求,即user-space 应用程序不在这个notifier 被调用?
  6. 是否可以在驱动程序中为device_shutdown添加一个钩子?

kernel_restart_prepare 作为 reboot 系统调用的一部分被调用,描述 explicitely says:

reboot doesn't sync: do that yourself before calling this.

因此无法保证 user-space 进程会在那一刻完成,并且不会阻止新的 user-space 进程启动。

该函数在标准内核环境下是运行,所以可以像往常一样被抢占。

根据device_shutdown implementation,它不提供钩子机制。它只是为每个驱动程序调用 shutdown 方法。