- 1
-
2 #include <linux/module.h>
-
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_handler(struct hrtimer *timer)
-
12 {
-
13 //kt = ktime_set(1, 10);
-
14 printk(" ------ I am in hrtimer -----\n");
-
15 hrtimer_forward(timer, timer->base->get_time(), kt);
-
16 return HRTIMER_RESTART;
-
17 }
-
18
-
19 static int __init test_init(void)
-
20 {
-
21
-
22 pr_info("timer resolution: %lu\n", TICK_NSEC);
-
23 kt = ktime_set(1, 10); /* 1 sec, 10 nsec */
-
24 hrtimer_init(&timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
-
25 //hrtimer_set_expires(&timer, kt);
-
26 hrtimer_start(&timer, kt, HRTIMER_MODE_REL);
-
27 timer.function = hrtimer_handler;
-
28
-
29 printk("\n-------- test start ---------\n");
-
30 return 0;
-
31 }
-
32
-
33 static void __exit test_exit(void)
-
34 {
-
35 hrtimer_cancel(&timer);
-
36 printk("-------- test over ----------\n");
-
37 return;
-
38 }
-
39
-
40 MODULE_LICENSE("GPL");
-
41
-
42 module_init(test_init);
-
43 module_exit(test_exit);
-
~
编译:
2 name = test.o
3 #name ?= jprobe.o
4 obj-m := $(name)
5
6 KERNELDIR := /home/tangyt/tmp/linux-2.6-cloud.p1020/
7
8 ARCH = powerpc
9 CROSS_COMPILE = /home/tangyt/toolchain/powerpc-linux-gnu-
10 export ARCH CROSS_COMPILE
11 #export CC
12
13 default:
14 make -C $(KERNELDIR) M=$(shell pwd) modules
15
16
17 clean:
18 make -C $(KERNELDIR) M=$(shell pwd) clean
说明:
1.
40 MODULE_LICENSE("GPL");不可少,否则找不到相应的函数
2. 为了测试需要设置了1秒10纳秒延时,此处完全可以设置纳秒级的延时
阅读(11918) | 评论(0) | 转发(0) |