#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/delay.h>
#include <linux/interrupt.h>
static void time_get(ktime_t *start);
static void time_get(ktime_t *start)
{
*start = ktime_get();
}
static int time_print(const char *name, ktime_t starttime)
{
ktime_t rettime;
s64 usecs64;
int usecs;
unsigned long my_s, my_us;
rettime = ktime_get();
usecs64 = ktime_to_us(ktime_sub(rettime, starttime));
usecs = usecs64;
my_s = usecs / USEC_PER_MSEC;
my_us = usecs % USEC_PER_MSEC;
if (usecs == 0)
usecs = 1;
printk("time: %ld.%03ld \r\n", my_s, my_us);
return 0;
}
static int hello_init(void)
{
ktime_t my_time;
printk(KERN_ALERT "Hello, world ver=%s\n", "1.0");
time_get(&my_time);
time_print(NULL, my_time);
mdelay(100);
time_print(NULL, my_time);
return 0;
}
static void hello_exit(void)
{
printk(KERN_ALERT "Goodbye, cruel world\n");
}
module_init(hello_init);
module_exit(hello_exit);
MODULE_LICENSE("Dual BSD/GPL");
[80492.470000] Hello, world ver=1.0
[80492.480000] time: 0.000
[80492.580000] time: 102.299
本文转自张昺华-sky博客园博客,原文链接:http://www.cnblogs.com/sky-heaven/p/5387395.html,如需转载请自行联系原作者