码迷,mamicode.com
首页 > 其他好文 > 详细

ktime使用例子【原创】

时间:2016-04-13 15:54:42      阅读:344      评论:0      收藏:0      [点我收藏+]

标签:

#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

 

ktime使用例子【原创】

标签:

原文地址:http://www.cnblogs.com/sky-heaven/p/5387395.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!