您的位置:首页 > 运维架构 > Linux

Linux: hrtimer 用法

2016-06-07 13:54 405 查看
hrtimer = high res timer

内核为高精度定时器重新设计了一套软件架构,它可以为我们提供纳秒级的定时精度,以满足对精确时间有迫切需求的应用程序或内核驱动,例如多媒体应用,音频设备的驱动程序等等。以下的讨论用hrtimer(high
resolution timer)表示高精度定时器。

#include <linux/hrtimer.h>

static struct hrtimer hrtimer;

//init

hrtimer_init(&hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);

hrtimer.function = timer_hr_interrupt;

//

static enum hrtimer_restart timer_hr_interrupt(struct hrtimer *timer)

{

do_something();

return HRTIMER_NORESTART;

}

void start_timer(void)

{

hrtimer_start(&hrtimer, ktime_set(0, first_time* NSEC_PER_USEC), HRTIMER_MODE_REL);

}

static void do_something(void)

{

// do something

...

//start next timer

hrtimer_start(&hrtimer, ktime_set(0, next_time* NSEC_PER_USEC), HRTIMER_MODE_REL);

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: