日期:2014-05-16 浏览次数:20869 次
#include <linux/kernel.h> #include <linux/init.h> #include <linux/module.h> #include <linux/fs.h> #include <linux/netdevice.h> #include <linux/pci.h> #include <linux/device.h> #include <linux/time.h> #include <linux/skbuff.h> #include <linux/jiffies.h> #include <linux/interrupt.h> #include <linux/hrtimer.h> #include <linux/ktime.h> #include <asm/irq.h> MODULE_DESCRIPTION("Just for hrtimer test"); MODULE_AUTHOR("summon (*********@163.com)"); MODULE_LICENSE("GPL"); #define DyS_HRTIMER_US_TO_NS(x) (x)*1000 static struct hrtimer hrtimer_for_test; unsigned long g_hr_times = 0; enum hrtimer_restart hrtimer_callback_func(struct hrtimer *p_timer) { g_hr_times++; if (net_ratelimit()) { printk(KERN_DEBUG "The function hrtimer_callback_func, times is %d\n", g_hr_times); } return HRTIMER_RESTART; } static int hrtimer_init_module(void) { printk( KERN_DEBUG "Module hrtimer_init_module init\n" ); ktime_t ktime; unsigned long delay_in_ns = DyS_HRTIMER_US_TO_NS(250); ktime = ktime_set(1,delay_in_ns); hrtimer_init(&hrtimer_for_test,CLOCK_MONOTONIC,HRTIMER_MODE_REL); hrtimer_for_test.function = hrtimer_callback_func; hrtimer_start(&hrtimer_for_test,ktime,HRTIMER_MODE_REL); return 0; } static void hrtimer_exit_module(void) { printk( KERN_DEBUG "Module hrtimer_exit_module exit\n" ); } module_init(hrtimer_init_module); module_exit(hrtimer_exit_module);