![](/img/trans.png)
[英]What is the best way to communicate a kernel module with a user space program?
[英]What are the best to ways measure latencies from user space to kernel space?
我必須測量用戶空間程序與其交互的驅動程序之間的等待時間。 我基本上是通過此應用程序發送數據包的。 所述latecny之間write
到相應於用戶空間write
在內核函數
我用clock_gettime
與CLOCK_MONOTONIC
在用戶空間和getrawmonotonic
內核(驅動器),當我看到了差距,這是巨大的(約4毫秒)。 因此,我肯定使用了錯誤的方法。
那么,什么是最好的方法呢?
要僅測量從用戶空間到內核空間的單個上下文切換,請嘗試使用TSC(時間戳計數器)。 它在x86和ARM,用戶空間和內核空間上可用。
有關Wikipedia上TSC的更多信息: https : //en.wikipedia.org/wiki/Time_Stamp_Counter
x86的BSD許可實現可以在此處找到 ,64位ARM的可以在此處找到。
同樣,如評論所建議,考慮使用任何可用的標准工具來測量往返延遲,即使用內核和返回。
如果這樣做,我將使用ftrace,它是linux內核提供的性能工具。
它可以跟蹤內核中幾乎所有的功能。
它首先將信息記錄到內存中的環形緩沖區中,因此它的慣性很小。
linux內核源代碼“ Documentation / trace / ftrace.txt”中有一個非常好的文檔,您也可以在這里找到它。
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.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.