转自: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. 【Python】Python SQLAlchemy基本操作和常用技巧

    首先说下,由于最新的 0.8 版还是开发版本,因此我使用的是 0.79 版,API 也许会有些不同.因为我是搭配 MySQL InnoDB 使用,所以使用其他数据库的也不能完全照搬本文. 接着就从安装 ...

  2. matlab中nargin函数的用法

    nargin是用来判断输入变量个数的函数,这样就可以针对不同的情况执行不同的功能. 通常可以用他来设定一些默认值,如下面的函数. 例子,函数test1的功能是输出a和b的和.如果只输入一个变量,则认为 ...

  3. bzoj3864-hdu4899-Hero meet devil

    题目 给出一个由AGTC组成的字符串\(S\),长度为\(n\),对于每个\(i\in [0,n]\),问有多少个长度为\(m\),仅含有AGTC的字符串\(T\)使得\(S\)与\(T\)的最长公共 ...

  4. Python文件对象的访问模式

  5. 透彻掌握Promise的使用,读这篇就够了

    透彻掌握Promise的使用,读这篇就够了 Promise的重要性我认为我没有必要多讲,概括起来说就是必须得掌握,而且还要掌握透彻.这篇文章的开头,主要跟大家分析一下,为什么会有Promise出现. ...

  6. 【基础】ASP.net MVC 文件下载的几种方法(欢迎讨论)

    在ASP.net MVC 中有几种下载文件的方法 前提:要下载的文件必须是在服务器目录中的,至于不在web项目server目录中的文件下载我不知道,但是还挺想了解的. 第一种:最简单的超链接方法,&l ...

  7. BZOJ4942 & UOJ314:[NOI2017]整数——题解

    https://www.lydsy.com/JudgeOnline/problem.php?id=4942 http://uoj.ac/problem/314 https://www.luogu.or ...

  8. Kubernetes - Getting Started With Kubeadm

    In this scenario you'll learn how to bootstrap a Kubernetes cluster using Kubeadm. Kubeadm solves th ...

  9. JAVA--未明确定义列

    原因:列明重复 可以加前缀或区别名以区分

  10. springboot线程池@Async的使用和扩展

    我们常用ThreadPoolExecutor提供的线程池服务,springboot框架提供了@Async注解,帮助我们更方便的将业务逻辑提交到线程池中异步执行,今天我们就来实战体验这个线程池服务: 本 ...