日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) >

linux 内核 hrtimer,hrtimer在Linux内核中重复任务

發(fā)布時(shí)間:2023/12/10 57 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux 内核 hrtimer,hrtimer在Linux内核中重复任务 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

我的目標(biāo)是使用hrtimer結(jié)構(gòu)在

linux內(nèi)核中創(chuàng)建一個(gè)定期任務(wù).我希望它每500毫秒重復(fù)一次.

但是,我對(duì)hrtimer在linux內(nèi)核中的工作方式有點(diǎn)困惑(參見(jiàn)linux / hrtimer.h).我知道時(shí)間是指定的,回調(diào)應(yīng)該返回HRTIMER_RESTART或HRTIMER_NORESTART.我在網(wǎng)上找到了一些資料,說(shuō)明需要使用hrtimer_forward方法在回調(diào)中重置計(jì)時(shí)器.然而,我所看到的消息來(lái)源對(duì)于如何增加時(shí)間有點(diǎn)不清楚.這是我到目前為止的代碼:

static struct hrtimer timer;

static enum hrtimer_restart timer_callback(struct hrtimer *timer)

{

printk(KERN_ERR "Callback\n");

//I know something needs to go here to reset the timer

return HRTIMER_RESTART;

}

static int init_timer(void)

{

ktime_t ktime;

unsigned long delay_in_ms = 500L;

printk(KERN_ERR "Timer being set up\n");

ktime = ktime_set(0,delay_in_ms*1E6L);

hrtimer_init(&timer,CLOCK_MONOTONIC,HRTIMER_MODE_REL);

timer.function = &timer_callback;

printk(KERN_ERR "Timer starting to fire\n");

printk(KERN_ERR "in %ldms %ld\n",delay_in_ms,jiffies);

hrtimer_start(&timer,ktime,HRTIMER_MODE_REL);

return 0;

}

static void clean_load_balancing_timer(void)

{

int cancelled = hrtimer_cancel(&timer);

if (cancelled)

printk(KERN_ERR "Timer still running\n");

else

printk(KERN_ERR "Timer cancelled\n");

}

有人能解釋一下重置計(jì)時(shí)器在回調(diào)函數(shù)中的作用嗎?謝謝!

總結(jié)

以上是生活随笔為你收集整理的linux 内核 hrtimer,hrtimer在Linux内核中重复任务的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。