转自:http://www.xuebuyuan.com/877633.html

目前项目需要,需要对时间进行基准,基准的精度在微秒。下午老刘给我说不能用do_gettimeofday因为他的精度虽然可以到微秒但是是依靠jiffies的精度(在linux 2.6.27内核中这个jiffies的单位是1毫秒)来更新这个时间值的,晚上回来就试试。结果呵呵,原来是可以精确到微秒并且不是靠jiffies的精度来更新的。

代码如下了。

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/time.h>
MODULE_LICENSE("GPL");
MODULE_AUTHOR("silence1214");
// gloable variable declare
/// time struct
struct timeval tl;
//function declare
void time_frequent_test(void);
// initialize the kernel module
int init_module(void)
{
printk(KERN_INFO "enter into the kernel.../n");
time_frequent_test();
return 0;
}
// clean up the kernel module
void cleanup_module(void)
{
printk(KERN_INFO "away from the kernel .../n");
}
void time_frequent_test(void)
{
do_gettimeofday(&tl);
printk(KERN_INFO "jiffies=%lu, sec=%lu, usec=%lu/n", jiffies, tl.tv_sec, tl.tv_usec);
do_gettimeofday(&tl);
printk(KERN_INFO "jiffies=%lu, sec=%lu, usec=%lu/n", jiffies, tl.tv_sec, tl.tv_usec);
do_gettimeofday(&tl);
printk(KERN_INFO "jiffies=%lu, sec=%lu, usec=%lu/n", jiffies, tl.tv_sec, tl.tv_usec);
}

linux中时间精度的获取问题【转】的更多相关文章

  1. Linux中执行脚本参数获取

    Linux中变量$[#,@,0,1,2,*,$,?]含义 $# 是传给脚本的参数个数 $0 是脚本本身的名字 $1 是传递给该shell脚本的第一个参数 $2 是传递给该shell脚本的第二个参数 $ ...

  2. 【Linux】linux中通过date命令获取昨天或明天时间的方法

    date +"%F" 输出格式:2011-12-31 date +"%F %H:%M:%S" 输出格式:2011-12-31 16:29:50 这都是打印出系统 ...

  3. linux中通过date命令获取昨天或明天时间的方法

    date命令可以获取当前的时间,通过man,可以看到date有很多参数可以用,很容易做到格式化 # 获取当前日期 date +"%F" 或者 date +"%Y-%m-% ...

  4. linux中时间函数

    linux下常用时间类型有四种: time_t . struct   tm. struct  timeval .    struct   timespec 1.time_t   时间函数 time_t ...

  5. linux中时间的更改

    # tzselectPlease identify a location so that time zone rules can be set correctly.Please select a co ...

  6. linux中时间命令详解

    DATE hling@hling:~$ date2018年 04月 11日 星期三 19:43:04 CSThling@hling:~$ date +%Y%M%d20184311hling@hling ...

  7. Linux中表示“时间”的结构体和相关函数

    转载于:http://blog.chinaunix.net/uid-25909722-id-2827364.html      Linux中表示“时间”的结构体和相关函数 2011-09-13 17: ...

  8. 浅析 Linux 中的时间编程和实现原理一—— Linux 应用层的时间编程【转】

    本文转载自:http://www.cnblogs.com/qingchen1984/p/7007631.html 本篇文章主要介绍了"浅析 Linux 中的时间编程和实现原理一—— Linu ...

  9. 关于linux中的时间 时区问题

    本文部分来源于:  http://hi.baidu.com/peruke/blog/item/b8de06ec6a04583b27979132.html 系统是fedora: glibc实现了从RTC ...

随机推荐

  1. 【数据库】各种主流 SQLServer 迁移到 MySQL 工具对比

    在部署前期,首要任务就是考虑如何快速把基于 SQL Server 数据库的应用程序移植到阿里云的 MySQL 数据库.由于程序是基于 O/R mapping 编写,并且数据库中没有使用存储过程.用户函 ...

  2. matlab 中try/catch语句

    try的作用是让Matlab尝试执行一些语句,执行过程中如果出错,则执行catch部分的语句,其语法: try (command1)组命令1总被执行,错误时跳出此结构 catch (command2) ...

  3. A表数据插入到B表(表结构不一致)

    D_A  有E\F\H 3字段 D_B 有 A\B\C\D\E\ID 字段 将 D_B 个别字段插入到D_A  表 INSERT INTO  D_A(E,F,H) select B,A,ID from ...

  4. HDU 4417 离线+树状数组

    Super Mario Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  5. openstack安装问题

    KeyStone NoHandlers Errorroot@openstack-dev-r910:/home/brent/openstack# ./keystone_data.shNo handler ...

  6. XMind 8 破解补丁 XMindCrack.jar注册机激活教程

    XMind 8 破解补丁 XMindCrack.jar注册机激活教程 Xmind 8 update7破解版(附破解教程|激活补丁|序列号) 思维导图 XMind 8 Update 7 Pro 破解版 ...

  7. Android 一些系统参数的获取

    //获取网络类型 2G/3G/WIFI public String getNetworkType(){ String mNetWorkType = ""; Connectivity ...

  8. [LeetCode] 3. Longest Substring Without Repeating Characters ☆☆☆

    Given a string, find the length of the longest substring without repeating characters. Examples: Giv ...

  9. SpringMVC+MyBatis 返回时间格式转换的解决方案

    Spring MVC 4.X ResponseBody 日期类型Json 处理 摘自http://tramp-zzy.iteye.com/blog/2090330  2014-07-10 方法一:全局 ...

  10. 【JSP EL】EL表达式获取当前时间(两种方式)

    第一种方式: //先在代码段定义<% long date = new Date().getTime(); request.setAttribute("date", date) ...