grttimeofday和xtime的定時精度

2021-08-25 13:02:15 字數 3008 閱讀 6628

客戶反映,gettimeofday獲取的時間us部分總是零。

自己修改測試**有如下結果:

./lpc3250test 1 0 50000

divsor is 1 sec is 0 usec is 50000 ***

current time: sec = 1289836976 usec = 390000 ***

current time: sec = 1289836976 usec = 390000 ***

current time: sec = 1289836976 usec = 390000 ***

current time: sec = 1289836976 usec = 450000 cnt = 1 ***

current time: sec = 1289836976 usec = 450000 cnt = 1 ***

current time: sec = 1289836976 usec = 500000 cnt = 2 ***

current time: sec = 1289836976 usec = 500000 cnt = 2 ***

current time: sec = 1289836976 usec = 550000 cnt = 3 ***

current time: sec = 1289836976 usec = 550000 cnt = 3 ***

current time: sec = 1289836976 usec = 600000 cnt = 4 ***

current time: sec = 1289836976 usec = 600000 cnt = 4 ***

current time: sec = 1289836976 usec = 650000 cnt = 5 ***

current time: sec = 1289836976 usec = 650000 cnt = 5 ***

current time: sec = 1289836976 usec = 700000 cnt = 6 ***

current time: sec = 1289836976 usec = 700000 cnt = 6 ***

current time: sec = 1289836976 usec = 750000 cnt = 7 ***

current time: sec = 1289836976 usec = 750000 cnt = 7 ***

current time: sec = 1289836976 usec = 800000 cnt = 8 ***

current time: sec = 1289836976 usec = 800000 cnt = 8 ***

current time: sec = 1289836976 usec = 850000 cnt = 9 ***

可以發現gettimeofday的us後四位總為零,只能精確到10ms.

呼叫關係:gettimeofday->sys_gettimeofday->do_gettimeofday.

do_gettimeofday的**在核心**的kernel/time/timekeeping.c

函式定義在114行,do_gettimeofday又呼叫了同一檔案中的getnstimeofday。

void getnstimeofday(struct timespec *ts)

while (read_seqretry(&xtime_lock, seq));

timespec_add_ns(ts, nsecs);

}可見getnstimeofday直接使用了xtime。

現在問題轉化為xtime的精度到底如何。

在驅動模組中列印current_kernel_time(void)讀取的xtime如下:

isoinit, sec:1289833417, ns:950000000

isoinit, sec:1289833417, ns:950000000

isoinit, sec:1289833417, ns:960000000

isoinit, sec:1289833417, ns:960000000

isoinit, sec:1289833417, ns:960000000

isoinit, sec:1289833417, ns:970000000

isoinit, sec:1289833417, ns:970000000

isoinit, sec:1289833425, ns:780000000

isoinit, sec:1289833425, ns:780000000

isoinit, sec:1289833425, ns:790000000

isoinit, sec:1289833425, ns:790000000

isoinit, sec:1289833425, ns:790000000

isoinit, sec:1289833425, ns:800000000

isoinit, sec:1289833425, ns:800000000

多次試驗的結果都是最後七位總為零。所以xtime的精度不會超過10ms。

現在可以看到gettimeofday和xtime的精度同為10ms。與系統時鐘的精度相同(hz=100).

xtime是乙個全域性變數。

kernel/time/timekeeping.c中更新xtime的函式為update_wall_time(void)

/*** update_wall_time - uses the current clocksource to increment the wall time

** called from the timer interrupt, must hold a write on xtime_lock.

*/void update_wall_time(void)

由於此函式是由系統定時中斷呼叫的,所以xtime精度和系統時鐘精度相同也就不足為怪了。

總結:getrimeofday和xtime的精度和系統節拍有關,我的系統hz=100,因此只能精確到10ms。(核心2.6.27.8)

grttimeofday和xtime的定時精度

客戶反映,gettimeofday獲取的時間us部分總是零。自己修改測試 有如下結果 lpc3250test 1 0 50000 divsor is 1 sec is 0 usec is 50000 current time sec 1289836976 usec 390000 current ti...

XT800內建軟體的更換和刪除

注意 此貼的基礎是 韌體 2.0.1,軟體 15.10.1 俺入手xt800幾天了,在這裡學到了不少東西,自己也鑽研了一下xt800如何更換和刪除 系統 內建的軟體,下面開講。一 首先要取得xt800的root 3.同時按三個鍵 搜尋鍵 拍照鍵 電源開關鍵,開機 4.當你看見recovery 模式2...

2060 super和5700xt哪個值得買?

首先拋開光線追蹤和dlss的話,5700xt的效能比2060super是強一些的,總體大約10 左右,在2k解析度下擁有更好的幀數表現,尤其是在一些a卡的優勢遊戲專案裡甚至能達到2070super的效能,而且 還比2060super便宜好幾百,比2070super更是便宜1000多元,價效比非常高。...