linux ktime set函数,ktime使用例子【原创】

#include

#include

#include

#include

#include

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

", my_s, my_us);

return 0;

}

static int hello_init(void)

{

ktime_t my_time;

printk(KERN_ALERT "Hello, world ver=%s

", "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

");

}

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值