如何在Linux内核空间中睡眠? [英] How to sleep in the Linux kernel space?

查看:536
本文介绍了如何在Linux内核空间中睡眠?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个内核线程,该线程在具有FIFO和最高优先级的特定CPU上分配.该线程会不时休眠,但是时间间隔必须尽可能精确.因此,考虑到这一点,在内核空间中最准确的睡眠方式是什么?

I have a kernel thread which is assigned on a specific CPU with FIFO and highest priority. This thread sleeps from time to time but the time interval must be as precise as possible. So with this in mind what would be the most precise way to sleep in the kernel space?

推荐答案

以下是

非原子上下文:

您应该使用*sleep[_range]系列功能. 这里还有更多选择,而其中任何一个都可能 正常工作,使用正确的"睡眠功能将 帮助调度程序,电源管理,并使您的 驱动程序更好:)

NON-ATOMIC CONTEXT:

You should use the *sleep[_range] family of functions. There are a few more options here, while any of them may work correctly, using the "right" sleep function will help the scheduler, power management, and just make your driver better :)

  • 由busy-wait循环支持:
    udelay(unsigned long usecs)
  • 由hrtimers支持:
    usleep_range(unsigned long min, unsigned long max)
  • 由jiffies/legacy_timers提供支持
    msleep(unsigned long msecs)
    msleep_interruptible(unsigned long msecs)
  • Backed by busy-wait loop:
    udelay(unsigned long usecs)
  • Backed by hrtimers:
    usleep_range(unsigned long min, unsigned long max)
  • Backed by jiffies / legacy_timers
    msleep(unsigned long msecs)
    msleep_interruptible(unsigned long msecs)

*delay系列不同,其潜在机制 这些呼叫的驱动方式各不相同,因此有 您应该注意的怪癖.

Unlike the *delay family, the underlying mechanism driving each of these calls varies, thus there are quirks you should be aware of.

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆