【问题标题】:What are the best to ways measure latencies from user space to kernel space?测量从用户空间到内核空间的延迟的最佳方法是什么?
【发布时间】:2017-07-25 14:25:41
【问题描述】:

我必须测量用户空间程序与其交互的驱动程序之间的延迟。我基本上是通过这个应用程序发送一个数据包。 latecny 在用户空间中的write 到内核中对应的write 函数之间

我在用户空间中使用了clock_gettimeCLOCK_MONOTONIC,并且 getrawmonotonic 在内核(驱动程序)中,当我看到差异时,它是巨大的(大约 4 毫秒)。所以我肯定使用了错误的方法。

那么,最好的方法是什么?

【问题讨论】:

  • 什么和什么之间的延迟?
  • @EugeneSh。更新了问题
  • perf 是一个很棒的工具。参见例如perf.wiki.kernel.org/index.php/Main_Page
  • valgrind 是一个相当知名的 linux 分析器
  • perf 和 valgrind 是优秀的工具,正如其他人已经提到的那样。 strace -T 也可能有帮助。

标签: c linux performance timer linux-kernel


【解决方案1】:

要仅测量从用户空间到内核空间的单个上下文切换,请尝试使用 TSC(时间戳计数器)。它适用于 x86 和 ARM、用户和内核空间。

维基百科上有关 TSC 的更多信息:https://en.wikipedia.org/wiki/Time_Stamp_Counter

针对 x86 的 BSD 许可实现 could be found herefor 64-bit ARM here.

此外,正如 cmets 建议的那样,考虑使用任何可用的标准工具来测量往返延迟,即使用到内核和返回。

【讨论】:

    【解决方案2】:

    如果我这样做,我会使用 ftrace,它是 linux 内核提供的性能工具。

    它几乎可以追踪内核中的所有功能。

    它首先将信息记录到内存中的一个环形缓冲区中,所以它很少滑行。

    linux内核源码中有一个很好的文档“Documentation/trace/ftrace.txt”,你也可以找到here

    1.prepare the environment, configure ftrace.
    2.run the application.
    3.0.In the application, bind cpu, and give the application priority。
    3.1.In the application, write something to the trace_marker, 
    3.2.In the application, call the function which you want to test.
    4.get the log from the ring buffer.
    5.calculate the latency.
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-10-22
      • 2016-06-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-18
      • 1970-01-01
      相关资源
      最近更新 更多