how ‘sleep’ happens

sleep 的实现过程

sleep –> sys_nanosleep
{

  • 为当前进程注册一个 timer 及超时回调函数 process_timeout;
  • 将进程置为 TASK_INTERRUPTIBLE;
  • 将 timer 挂到每 CPU 链 tvec_bases;
  • schedule() 让出 CPU;
  • 时钟软中断 TIMER_SOFTIRQ 函数 run_timer_softirq 检查 tvec_bases 是否有 timer 超时;
  • 超时则回调 process_timeout 进而 wake_up_process 唤醒进程到 TASK_RUNNING,等待时间片调度。

}