Linux實時性能測試工具之cyclictest使用詳解
cyclictest 是 Linux 系統(tǒng)中 rt-tests 下的用于測試內(nèi)核實時性能的常用工具,通過創(chuàng)建高精度定時線程并測量其喚醒延遲,評估系統(tǒng)的中斷響應(yīng)、調(diào)度延遲等實時特性。
cyclictest 安裝
下面是 cyclictest 的安裝方法,供參考:
# 下載cyclictest原碼 git clone git://git.kernel.org/pub/scm/utils/rt-tests/rt-tests.git # 切換branch stable/v1.0 git checkout stable/v1.0 # 編譯 make
cyclictest 計算延時原理
cyclictest計算延時的原理是通過記錄進程睡眠的開始時間、實際睡眠時間以及真正喚醒并運行的時間,用實際喚醒時間減去實際睡眠時間和睡眠開始時間來得出延時。
- 程序會記錄進程睡眠的開始時間 t1
- 進程實際睡眠時間 t2
- 進程 真正喚醒并運行的時間為 t3
- 延時結(jié)果即為 t3 - t2 - t1
cyclictest 運行
編譯完成后可以在運行cyclictest, 例如:
sudo ./cyclictest -m -n -p95 -d0 -a 1-17 -t 17
查看參數(shù)可以使用:
./cyclictest -h
./cyclictest: option requires an argument -- 'h'
cyclictest V 1.00
Usage:
cyclictest <options>
-a [CPUSET] --affinity Run thread #N on processor #N, if possible, or if CPUSET
given, pin threads to that set of processors in round-
robin order. E.g. -a 2 pins all threads to CPU 2,
but -a 3-5,0 -t 5 will run the first and fifth
threads on CPU (0),thread #2 on CPU 3, thread #3
on CPU 4, and thread #5 on CPU 5.
-A USEC --aligned=USEC align thread wakeups to a specific offset
-b USEC --breaktrace=USEC send break trace command when latency > USEC
-B --preemptirqs both preempt and irqsoff tracing (used with -b)
-c CLOCK --clock=CLOCK select clock
0 = CLOCK_MONOTONIC (default)
1 = CLOCK_REALTIME
-C --context context switch tracing (used with -b)
-d DIST --distance=DIST distance of thread intervals in us, default=500
-D --duration=TIME specify a length for the test run.
Append 'm', 'h', or 'd' to specify minutes, hours or days.
--latency=PM_QOS write PM_QOS to /dev/cpu_dma_latency
-E --event event tracing (used with -b)
-f --ftrace function trace (when -b is active)
-F --fifo=<path> create a named pipe at path and write stats to it
-h --histogram=US dump a latency histogram to stdout after the run
US is the max latency time to be be tracked in microseconds
This option runs all threads at the same priority.
-H --histofall=US same as -h except with an additional summary column
--histfile=<path> dump the latency histogram to <path> instead of stdout
-i INTV --interval=INTV base interval of thread in us default=1000
-I --irqsoff Irqsoff tracing (used with -b)
-l LOOPS --loops=LOOPS number of loops: default=0(endless)
--laptop Save battery when running cyclictest
This will give you poorer realtime results
but will not drain your battery so quickly
-m --mlockall lock current and future memory allocations
-M --refresh_on_max delay updating the screen until a new max
latency is hit. Userful for low bandwidth.
-n --nanosleep use clock_nanosleep
--notrace suppress tracing
-N --nsecs print results in ns instead of us (default us)
-o RED --oscope=RED oscilloscope mode, reduce verbose output by RED
-O TOPT --traceopt=TOPT trace option
-p PRIO --priority=PRIO priority of highest prio thread
-P --preemptoff Preempt off tracing (used with -b)
--policy=NAME policy of measurement thread, where NAME may be one
of: other, normal, batch, idle, fifo or rr.
--priospread spread priority levels starting at specified value
-q --quiet print a summary only on exit
-r --relative use relative timer instead of absolute
-R --resolution check clock resolution, calling clock_gettime() many
times. List of clock_gettime() values will be
reported with -X
--secaligned [USEC] align thread wakeups to the next full second
and apply the optional offset
-s --system use sys_nanosleep and sys_setitimer
-S --smp Standard SMP testing: options -a -t -n and
same priority of all threads
--spike=<trigger> record all spikes > trigger
--spike-nodes=[num of nodes]
These are the maximum number of spikes we can record.
The default is 1024 if not specified
--smi Enable SMI counting
-t --threads one thread per available processor
-t [NUM] --threads=NUM number of threads:
without NUM, threads = max_cpus
without -t default = 1
--tracemark write a trace mark when -b latency is exceeded
-T TRACE --tracer=TRACER set tracing function
configured tracers: none
-u --unbuffered force unbuffered output for live processing
-U --numa Standard NUMA testing (similar to SMP option)
thread data structures allocated from local node
-v --verbose output values on stdout for statistics
format: n:c:v n=tasknum c=count v=value in us
-w --wakeup task wakeup tracing (used with -b)
-W --wakeuprt rt task wakeup tracing (used with -b)
--dbg_cyclictest print info useful for debugging cyclictest
簡單介紹下一些參數(shù):
- -m 鎖定進程內(nèi)存,防止頁交換影響實時性,高精度測試時避免內(nèi)存抖動。
- -n 使用 clock_nanosleep 替代 nanosleep,提高時間精度。
- -p 設(shè)置線程優(yōu)先級(需 root 權(quán)限)。(Linux 中 SCHED_FIFO 優(yōu)先級范圍通常為 1-99)
- d0 CPU上有多個實時線程時,每個線程喚醒時間的間隔增量。當設(shè)置為0時,意味著所有線程將在同一時間被喚醒。
- -a 綁定線程到指定 CPU 核心,例如1-17 綁定到 CPU 1 到 17。
- -t 指定測試線程數(shù)量。
總結(jié)
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
Linux安裝yum時出現(xiàn)apt-get?install?E:?無法定位軟件包問題解決
這篇文章主要介紹了Linux安裝yum時出現(xiàn)apt-get?install?E:?無法定位軟件包問題解決的相關(guān)資料,文中通過圖文介紹的非常詳細,對大家的學習或者工作具有一定的參考借鑒價值,需要的朋友可以參考下2024-12-12
Linux服務(wù)器升級GLIBC失敗導(dǎo)致shell命令不可用的情況怎么處理
在某些linux系統(tǒng)里面本身自帶的glibc版本過低,如果你直接更新系統(tǒng)的glibc版本會導(dǎo)致系統(tǒng)崩潰,shell中的大部分命令(ls,cat,rm,cp,ln,scp,vi,yum等)都執(zhí)行報錯,嘗試新的ssh連接時提示拒絕連接,筆者最近不幸遇到了這個問題2024-11-11
VPS CentOS-6 下 LNMP HTTP web服務(wù)器的搭建步驟
雖然現(xiàn)在很多朋友比較喜歡使用軍哥的lnmp一鍵安裝包,但手工配置方法也要會,否則容易技術(shù)退步2014-06-06
利用.htaccess的Rewrite規(guī)則實現(xiàn)Discuz論壇的偽靜態(tài)鏈接
重新開放了Minidx幫助論壇,雖然目前沒什么內(nèi)容,不過順便想SEO一下,實現(xiàn)偽靜態(tài)鏈接。2010-12-12
Linux定時任務(wù)Crontab命令使用詳解與總結(jié)
本為大家介紹了Linux定時任務(wù)Crontab命令使用詳解并總結(jié)Crontab命令的一些使用技巧以及工作中遇到的一些問題解決方法2018-10-10

