hrtimer高精度定时器的简单使用【学习笔记】

 1 #include <linux/module.h>
 2 
 3 #include <linux/kernel.h>
 4 #include <linux/hrtimer.h>
 5 #include <linux/jiffies.h>
 6 
 7 
 8 static struct hrtimer timer;
 9 ktime_t kt;
10 
11 static enum hrtimer_restart        hrtimer_hander(struct hrtimer *timer)
12 {
13     printk("zbzhuang:I am in hrtimer hander\r\n");
14 
15     hrtimer_forward(timer,timer->base->get_time(),kt);
16 
17     return HRTIMER_RESTART;
18         
19 
20 }
21 
22 static int __init test_init(void)
23 {
24     printk("zbzhuang:---------%s-----------\r\n",__func__);
25 
26     kt = ktime_set(1,10);
27     hrtimer_init(&timer,CLOCK_MONOTONIC,HRTIMER_MODE_REL);
28     hrtimer_start(&timer,kt,HRTIMER_MODE_REL);
29     timer.function = hrtimer_hander;
30 
31     return 0;
32 }
33 
34 static void __exit test_exit(void)
35 {
36     hrtimer_cancel(&timer);
37     printk("zbzhuang------------test over---------------\r\n");
38 }
39 
40 
41 module_init(test_init);
42 module_exit(test_exit);
43 MODULE_LICENSE("GPL");
44 MODULE_AUTHOR("zbzhuang@qq.com");

 

转载于:https://www.cnblogs.com/zzb-Dream-90Time/p/7084916.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值