Linux内核中获取纳秒时间戳的方法

  • 1 方法1:使用getnstimeofday64方法
  • 2 方法2:使用ktime_get_real_ns方法

1 方法1:使用getnstimeofday64方法

此处以获取内核中mm/page_alloc.c__alloc_pages_direct_reclaim函数中的__perform_reclaim函数的执行之间为例(内核版本4.14.216),代码如下:

/* The really slow allocator path where we enter direct reclaim */
static inline struct page *
__alloc_pages_direct_reclaim(gfp_t gfp_mask, unsigned int order,unsigned int alloc_flags, const struct alloc_context *ac,unsigned long *did_some_progress)
{struct page *page = NULL;bool drained = false;struct timespec64 start, end;getnstimeofday64(&start);*did_some_progress = __perform_reclaim(gfp_mask, order, ac);getnstimeofday64(&end);printk("func : %s-> %s, time spent = %ld s, %ld ns\n", \__func__, "__perform_reclaim", (end.tv_sec - start.tv_sec),\(end.tv_nsec - start.tv_nsec));//... the rest of the code
}

2 方法2:使用ktime_get_real_ns方法

此处仍是以获取内核中mm/page_alloc.c__alloc_pages_direct_reclaim函数中的__perform_reclaim函数的执行之间为例(内核版本4.14.216),代码如下:

/* The really slow allocator path where we enter direct reclaim */
static inline struct page *
__alloc_pages_direct_reclaim(gfp_t gfp_mask, unsigned int order,unsigned int alloc_flags, const struct alloc_context *ac,unsigned long *did_some_progress)
{struct page *page = NULL;bool drained = false;u64 start_time, end_time;start_time = ktime_get_real_ns();*did_some_progress = __perform_reclaim(gfp_mask, order, ac);end_time = ktime_get_real_ns();printk("func : %s-> %s, time spent = %ld ns\n", \__func__, "__perform_reclaim", (end_time - start_time));//... the rest of the code
}

相关参考:
Linux latest timekeeping

Linux内核中获取纳秒时间戳的方法相关推荐

  1. 从Linux内核中获取真随机数【转】

    转自:http://www.cnblogs.com/bigship/archive/2010/04/04/1704228.html 内核随机数产生器 Linux内核实现了一个随机数产生器,从理论上说这 ...

  2. 【Elasticsearch】在Elasticsearch中支持纳秒时间戳

    1.概述 翻译:The journey to support nanosecond timestamps in Elasticsearch 以纳秒分辨率存储日期的能力需要在Elasticsearch代 ...

  3. linux内核中获取虚拟地址api,Linux内核-系统调用

    Linux内核-系统调用 1.与内核通信 #系统调用在用户空间进程和硬件设备之间添加了一个中间层 作用:1.为用户空间提供了一种硬件的抽象接口 2.系统调用保证了系统的稳定和安全 3.出于每一个进程都 ...

  4. linux内核中测量时间的方法,Linux内核中获取时间函数do_gettimeofday

    内核代码能一直获取一个当前时间的表示, 通过查看 jifies 的值. 常常地, 这个值只代表从最后一次启动以来的时间, 这个事实对驱动来说无关, 因为它的生命周期受限于系统的 uptime. 如所示 ...

  5. linux ps le hrtime,前端Tips#4 - 用 process.hrtime 获取纳秒级的计时精度

    视频讲解 文字讲解 如果去测试代码运行的时长,你会选择哪个时间函数? 一般第一时间想到的函数是 Date.now 或 Date.getTime. 1.先讲结论 之所以这么选,是基于 精度 和 时钟同步 ...

  6. 论文中文翻译——Double-Fetch情况如何演变为Double-Fetch漏洞:Linux内核中的双重获取研究

    本论文相关内容 论文下载地址--Web Of Science 论文中文翻译--How Double-Fetch Situations turn into Double-Fetch Vulnerabil ...

  7. linux 内核 遍历文件夹,Linux内核中通过文件描述符获取绝对路径

    背景 在Linux内核中,已知一个进程的pid和其打开文件的文件描述符fd,如何获取该文件的绝对路径?基本思路是先获取该文件在内核中的file结构体,再通过d_path()获取到整个文件的绝对路径. ...

  8. javascript 获取毫秒、纳秒时间戳

    var date = Date.now() console.log(date)//毫秒时间戳 console.log(date) console.log(date)const start = proc ...

  9. python时间函数纳秒_python – 获取纳秒级精度的文件修改时间

    我需要为遍历文件系统树的Python 2程序中的每个文件获取完整的纳秒精度修改时间戳.我想在Python本身中这样做,因为为每个文件生成一个新的子进程会很慢. 通过查看stat结果的st_mtime_ ...

最新文章

  1. 多台Linux服务器SSH相互访问无需密码--转
  2. 设计模式 代理模式和装饰模式的区别
  3. 小米屏下摄像头专利曝光!或为小米mix4准备?
  4. 设计类导航,为设计师提供最简单便捷的设计网址
  5. 字符串校验器 ExcelValidator.java
  6. 【算法学习笔记】81.动态规划 分类讨论 SJTU OJ 1075 括号匹配升级
  7. 捷联惯导算法与组合导航原理讲义捷联惯导基础知识剖析目录
  8. PLC数据采集解决方案及数采网关
  9. 【C51单片机】数码管实现99秒倒计时
  10. 索尼手机更新android10,索尼XPERIA 10 II终于收到了ANDROID 11更新
  11. TCP网络编程(基于UDP的网络聊天室)
  12. js进阶之天猫弹性导航
  13. 计算机及应用课程实验,计算机网络及应用课程实验指导书
  14. dede mysql x_mysql 插入数据时中文变x87xE7xA7x91xE7x82这种?
  15. mac 安装win7 攻略
  16. Carsim-问题Failed to start Solver: PATH_ID_OBJ(X) was set to Y; no corresponding value of XXXXX?
  17. android怎么装windows系统,普通电脑怎么装Windows和安卓的双系统?
  18. 迅时MX8(FXO)8口语音网关连接Elastix+服务器配置
  19. C语言实现用户输入数字输出输入的为几时几分几秒
  20. Oracle之常用内置函数

热门文章

  1. 驻极体式MIC电路设计
  2. Android 炫酷自定义 View - 剑气加载
  3. Android_openCV图片处理
  4. 三星S7edge从8.0降到6.0.1,只为流畅的飞一般的感觉
  5. 有没有测试牙齿需不需要修正的软件,三步图测法,就能知道自己牙齿是否需要矫正...
  6. 十余款新品惊艳亮相,华为春季旗舰新品发布会看点满满
  7. 上海市土木工程人才需求暴涨
  8. [歪谈]拽一个贵人出来给你当炮架子
  9. <一>Android Audio音频框架
  10. 该战斗的时候战斗,该转身的时候转身,但请保持优雅