How to sleep in the Linux kernel space?

后端 未结 2 638
执念已碎
执念已碎 2021-02-06 09:09

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 possi

2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-06 09:23

    I've used combination of hrtimer and waitqueue to implement periodical task using kernel thread:

    1. create waitqueue and periodic hrtimer
    2. block kernel thread on waitqueue using wait_event()/wait_event_timeout()
    3. in the hrtimer callback call wake_up()/wake_up_all()

    Also, just found, you can implement sleep using hrtimer_init_sleeper() and schedule(), see __wait_event_hrtimeout() or do_nanosleep(). But I nether tried that.

提交回复
热议问题