schedule_timeout与mdelay

schedule_timeout  该方法相当于设置一个timer,然后schedule,timer到期后process_timeout会调用wake_up_process唤醒进程。不会修改进程状

schedule_timeout  该方法相当于设置一个timer,然后schedule,timer到期后process_timeout会调用wake_up_process唤醒进程。不会修改进程状态,依然为TASK_RUNNING,不会把这个task从runqueue中移出去。那么当系统进行调度的时候这个进程仍然会被调度进来,因此一般调用前要set_current_state(TASK_INTERRUPTIBLE);然后让需要延迟的任务睡眠到指定的延时时间耗尽后在重新运行。

schedule_timeout有可能被signal打断,导致delay的时间小于预期

mdelay可以确保等待的时间大于等于参数设置的时间,在一些hardware驱动当中使用的delay,安全起见,一般推荐使用mdelay或者usleep_range函数。

msleep函数不会导致cpu忙等,时间不如mdelay精确,一般会大于设置的时间。底层实现是调用schedule_timeout

msleep_interruptible有可能会在延迟到一半时被信号打断退出

用户态的msleep底层会调用hrtimer_nanosleep来实现

推荐调用

Schedule_timeout_interruptible

Schedule_timeout_uninterruptible

Schedule_timeout_killable

这几个函数都会在调用schedule_timeout之前调用set_current_state,来把进程的状态设置为非TASK_RUNNING得状态。

其中msleep就是调用schedule_timeout_uninterruptible,ps查看进程为“D”状态

发布者:admin,转转请注明出处:http://www.yc00.com/web/1755001333a5225547.html

相关推荐

  • schedule_timeout与mdelay

    schedule_timeout  该方法相当于设置一个timer,然后schedule,timer到期后process_timeout会调用wake_up_process唤醒进程。不会修改进程状

    1月前
    160

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信