[問題] clock_nanosleep() 還是不準的問題...
我不確定這問題要發在linux板或C_and_CPP板比較好,
目前我打算用嵌入式開發板 beaglebone black 上安裝Debian, kernel 3.15,
因為某些需要,所以時間精度要求要在 1us 以下,所以我打算用clock_nanosleep()實現
但我給 1s 的delay,他實際睡眠時間卻是 1s 又 120us,我是在clock_nanosleep()前後
加上clock_gettime(),然後把兩個時間相減得到的數字.. 總是會睡過頭。
另外我有用linuxPTP(某種利用PTP校正系統時間(CLOCK_REALTIME)的軟體),並且將示波器
接上GPIO看1PPS的準確度,delay也是多了100us左右...
請問有辦法讓系統達到至少 1us 以下的時間精度嗎? 譬如我設delay 1s,實際delay是
1s 又 200ns 之類的,用realtime OS有幫助嗎? 或者這是kernel counter的問題(但我對
linux的時間設計並不是很了解,只知道作業系統的計時跟counter有關)?
希望能獲前輩指教,謝謝。
下面是我其中的三組數據:
da 69033 dan 946956445
db 69034 dbn 947070913
da 69035 dan 947355036
db 69036 dbn 947490079
da 69037 dan 947738536
db 69038 dbn 947863215
左邊是秒(絕對時間),右邊是奈秒(絕對時間),故上下兩組相減可看到多了快100us...
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 111.240.26.199
※ 文章網址: http://www.ptt.cc/bbs/Linux/M.1405605295.A.D9D.html
推
07/18 09:53, , 1F
07/18 09:53, 1F
→
07/18 13:10, , 2F
07/18 13:10, 2F
→
07/18 13:11, , 3F
07/18 13:11, 3F
→
07/18 14:44, , 4F
07/18 14:44, 4F
推
07/18 15:01, , 5F
07/18 15:01, 5F
我查到的clock_nanosleep的呼叫流程是:
clock_nanosleep() -->nsleep --> common_nsleep() -->hrtimer_nanosleep()
-->do_nanosleep()
資料:http://ppt.cc/wK3E
內文:do_nanosleep() will simply put the current task in INTERRUPTIBLE state, will
wait for the timer to expire(which is 1 ns) and then set the current task in
RUNNING state again. You see, there are lot of factors involved now, mainly
when your kernel thread (and hence the user space process) will be scheduled
again. Depending on your OS, you will always face some latency when your
doing a context-switch and this is what we observe with the average values.
若nanosleep的概念是用task的方式處理, 故我在想用realtime OS有沒有幫助..?
→
07/18 15:03, , 6F
07/18 15:03, 6F
這部份我不清楚switch的範圍誤差是多少, 但影響會到1us嗎?
→
07/18 15:04, , 7F
07/18 15:04, 7F
我用過renice但還沒試過chrt, 我renice bash 和 sudo 似乎沒有影響.
謝謝!
※ 編輯: user48625 (140.112.20.199), 07/18/2014 18:02:46
→
07/19 12:58, , 8F
07/19 12:58, 8F
→
07/19 12:59, , 9F
07/19 12:59, 9F
→
07/19 13:00, , 10F
07/19 13:00, 10F
→
07/19 19:31, , 11F
07/19 19:31, 11F
推
07/20 00:51, , 12F
07/20 00:51, 12F
→
07/20 00:56, , 13F
07/20 00:56, 13F
→
07/20 00:59, , 14F
07/20 00:59, 14F
→
07/20 01:00, , 15F
07/20 01:00, 15F
推
07/20 01:04, , 16F
07/20 01:04, 16F
推
07/23 00:49, , 17F
07/23 00:49, 17F
→
07/23 00:50, , 18F
07/23 00:50, 18F
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 2 篇):