ktime使用例子【原创】

简介:

#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,如需转载请自行联系原作者

相关文章
|
存储 编译器 程序员
⭐️ 关键字深度剖析 ⭐️第六章(关键字void\return\const)
本章主要讲解: 深入关键字void 深入关键字return 深入关键字const
⭐️ 关键字深度剖析 ⭐️第六章(关键字void\return\const)
|
前端开发 JavaScript
uniapp真机调试文件查找失败:‘./pages/index/index.nvue?mpType=page‘; Error: Cannot find module ‘pages/ ———————————————— 版权声明:本文为CSDN博主「前端老实人」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。 原文链接:https://blog.csdn.net/weixin_52691965/article/details/119241451
uniapp真机调试文件查找失败:‘./pages/index/index.nvue?mpType=page‘; Error: Cannot find module ‘pages/ ———————————————— 版权声明:本文为CSDN博主「前端老实人」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。 原文链接:https://blog.csdn.net/weixin_52691965/article/details/119241451
|
算法 SEO 搜索推荐
如何写好高质量的原创文章?
随着百度算法的不断升级,百度越来越重视原创文章了,但是原创文章可不单单是用工具查询的相似度为0的文章,更多的应当是可以解决用户需求,能够引发用户阅读兴趣的文章,即看了这篇文章还想下次再来你的网站进行学习。
1220 0
|
Python 数据安全/隐私保护 搜索推荐
Python标准库(待续)
相识一场,记得顶我 集合操作 并集 >>> a = set([1,2,3]) >>> b = set([2,3,4]) >>> a.union(b) {1, 2, 3, 4} >>> a|b {1, 2, 3, 4} 交集 >>> a = set([1,2,3]) >>> b = set([2,3,4]) >>> a.
1073 0
|
搜索推荐 SEO
如何写出高质量的原创文章
一个网站的好坏,能否有好的排名,跟网站的内容的好坏是有直接的关系的,正所谓“内容为王,外链为皇”,SEO的排名是以页面为单位的,需要足够的内容来支撑,有高质量的内容的页面才会被百度收录,能被百度收录对应的页面关键词才会有排名,关键词有排名网站才会产生流量。
644 0