ktime_get() and do_gettimeofday() APIs use
来源:互联网 发布:淘宝上的xbox360手柄 编辑:程序博客网 时间:2024/05/16 17:37
We have some APIs to measure time taken for a function or a piece of code in the driver.
1. do_gettimeofday()
2. ktime_get()
These APIs are used to measure the time (absolute timestamp) in the kernel.
do_gettimeofday() gives microsecond precision.
ktime_get() return ktime_t object, which has nano second precision.
Here is abstract code to show how ktime_get() API will be used in our driver to measure time taken for a function.
The prototype for ktime_get is:
#include <linux/ktime.h>
ktime_t ktime_get(void);
Sample-code:
--------------
ktime_t start, end;
s64 actual_time;
start = ktime_get();
function();
/* or piece of code */
....
....
end = ktime_get();
actual_time = ktime_to_ns(ktime_sub(end, start));
printk(KERN_INFO, "Time taken for function() execution: %lld\n",
(long long)actual_time);
/* Use below code for millisec precision */
actual_time = ktime_to_ms(ktime_sub(end, start));
printk(KERN_INFO, "Time taken for function() execution: %u\n",
(unsigned int)actual_time);
Here is abstract code to show how do_gettimeofday API will be used in our driver to measure time taken for a function.
The prototype for do_gettimeofday is:
#include <linux/time.h>
void do_gettimeofday(struct timeval *tv);
When this function called, it fills the timestamp data in struct timeval.
Using struct timeval members, we can extract seconds and microseconds info.
Sample code:
-------------
do_gettimeofday(&tstart);
/* Function or code to measure time bound */
do_gettimeofday(&tend);
printk("time taken: %ld millisec\n",
1000 * (tend.tv_sec - tstart.tv_sec) +
(tend.tv_usec - tstart.tv_usec) / 1000);
1. do_gettimeofday()
2. ktime_get()
These APIs are used to measure the time (absolute timestamp) in the kernel.
do_gettimeofday() gives microsecond precision.
ktime_get() return ktime_t object, which has nano second precision.
ktime_get:
===========Here is abstract code to show how ktime_get() API will be used in our driver to measure time taken for a function.
The prototype for ktime_get is:
#include <linux/ktime.h>
ktime_t ktime_get(void);
Sample-code:
--------------
ktime_t start, end;
s64 actual_time;
start = ktime_get();
function();
/* or piece of code */
....
....
end = ktime_get();
actual_time = ktime_to_ns(ktime_sub(end, start));
printk(KERN_INFO, "Time taken for function() execution: %lld\n",
(long long)actual_time);
/* Use below code for millisec precision */
actual_time = ktime_to_ms(ktime_sub(end, start));
printk(KERN_INFO, "Time taken for function() execution: %u\n",
(unsigned int)actual_time);
do_gettimeofday():
==================Here is abstract code to show how do_gettimeofday API will be used in our driver to measure time taken for a function.
The prototype for do_gettimeofday is:
#include <linux/time.h>
void do_gettimeofday(struct timeval *tv);
When this function called, it fills the timestamp data in struct timeval.
Using struct timeval members, we can extract seconds and microseconds info.
Sample code:
-------------
do_gettimeofday(&tstart);
/* Function or code to measure time bound */
do_gettimeofday(&tend);
printk("time taken: %ld millisec\n",
1000 * (tend.tv_sec - tstart.tv_sec) +
(tend.tv_usec - tstart.tv_usec) / 1000);
0 0
- ktime_get() and do_gettimeofday() APIs use
- [Deprecated( "please use panBy and panTo APIs" )]
- Microsoft APIs and frameworks
- Location and Sensors APIs
- use WinRT APIs from desktop applications
- Elevation and process creation APIs
- Netty and Java NIO APIs
- Concurrent Programming: APIs and Challenges
- freecodecamp json APIs and Ajax
- APIs
- Use ALSA lib apis to set the Mic Capture Volume
- Compressing and Decompressing Data using JavaTM APIs
- Other Java APIs And Products @ JDJ
- Common HTTP and FTP WinInet APIs
- Quartz frameworks and their APIs(用途)
- Linux Driver APIs - interrupt and irq
- Building Faster APIs with NodeJs and Redis
- Android API Guides---Location and Sensors APIs and Maps
- linux下编译ffmpeg-2.7.2
- C语言编程基础-03变量与数据类型
- 国内直播-节目源
- C语言编程基础-04占位符与内存结构及sizeof
- Android 事件
- ktime_get() and do_gettimeofday() APIs use
- 老股民警示:抢反弹如果不这样做你会死的很惨
- length length() size()
- 云计算特点
- C语言编程基础-05操作符位操作与运算符优先级
- 浅谈互联网页面价值
- 如何捅破python编程的那层纸之二
- C语言编程基础-06三目操作类型转换分支循环
- 黑马程序员——第一篇_面向对象