#include<linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include<linux/fs.h>
#include<linux/slab.h>
#include<linux/timer.h>
#include <linux/sched.h>
#include <linux/list.h>
MODULE_AUTHOR("Tan xujia");
MODULE_LICENSE("Dual BSD/GPL");
struct timertest {
struct timer_list mytimer;
int count;
int delay;
}ttest;
void
timer_callback(struct timer_list *t)
{
printk("timer_callback\n");
struct timertest *p = container_of(t, struct timertest, mytimer);
if(--(p->count)) {
mod_timer(t, jiffies+p->delay);
}
else {
printk("timer_callback del\n");
del_timer(t);
}
return;
}
static
int __init hello_init (void)
{
printk("hello_init\n");
ttest.count = 10;
ttest.delay = 100;
timer_setup(&ttest.mytimer, &timer_callback, 0);
mod_timer(&ttest.mytimer, jiffies+ttest.delay);
return 0;
}
static
void __exit hello_exit (void)
{
printk("hello_exit\n");
}
module_init(hello_init);
module_exit(hello_exit);
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
obj-m :=timer.o
all:
make -C $(KERNELDIR) M=$(PWD) modules
clean:
rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.* .tmp_versions *.mod *.order *.symvers *.dwo