我使用perf sched record -p 8827
来记录特定程序的调度程序活动。但是,当我生成延迟报告时,它显示只有一个上下文切换,而要求它转储原始事件则显示了许多切换(摘录如下(。这怎么可能有意义呢?我想我是在误解什么?切换到kworker不算在内吗?
perf sched latency
输出:
-----------------------------------------------------------------------------------------------------------------
Task | Runtime ms | Switches | Average delay ms | Maximum delay ms | Maximum delay at |
-----------------------------------------------------------------------------------------------------------------
:4320:4320 | 0.000 ms | 1 | avg: 0.000 ms | max: 0.000 ms | max at: 0.000000 s
-----------------------------------------------------------------------------------------------------------------
TOTAL: | 0.000 ms | 1 |
---------------------------------------------------
perf sched script
输出:
test_program 8827 [008] 1727201.302534: sched:sched_switch: test_program:8827 [100] R ==> kworker/8:0:4320 [120]
test_program 8827 [008] 1727201.303524: sched:sched_stat_runtime: comm=test_program pid=8827 runtime=954318 [ns] vruntime=30559299144
test_program 8827 [008] 1727202.303521: sched:sched_stat_runtime: comm=test_program pid=8827 runtime=999997430 [ns] vruntime=30559414
test_program 8827 [008] 1727202.303528: sched:sched_stat_runtime: comm=test_program pid=8827 runtime=6419 [ns] vruntime=3055941451126
test_program 8827 [008] 1727202.303529: sched:sched_wakeup: kworker/8:0:4320 [120] success=1 CPU:008
test_program 8827 [008] 1727202.303532: sched:sched_switch: test_program:8827 [100] R ==> kworker/8:0:4320 [120]
test_program 8827 [008] 1727202.303738: sched:sched_stat_runtime: comm=test_program pid=8827 runtime=192062 [ns] vruntime=30559414533
test_program 8827 [008] 1727202.303739: sched:sched_stat_runtime: comm=test_program pid=8827 runtime=908 [ns] vruntime=3055941453351
test_program 8827 [008] 1727202.304471: sched:sched_stat_runtime: comm=test_program pid=8827 runtime=731656 [ns] vruntime=30559414617
test_program 8827 [008] 1727203.304469: sched:sched_stat_runtime: comm=test_program pid=8827 runtime=999997968 [ns] vruntime=30559529
test_program 8827 [008] 1727203.304531: sched:sched_stat_runtime: comm=test_program pid=8827 runtime=62107 [ns] vruntime=305595299908
test_program 8827 [008] 1727203.304532: sched:sched_stat_runtime: comm=test_program pid=8827 runtime=1006 [ns] vruntime=3055952999092
test_program 8827 [008] 1727204.302373: sched:sched_switch: test_program:8827 [100] R ==> kworker/8:0:4320 [120]
test_program 8827 [008] 1727204.303365: sched:sched_stat_runtime: comm=test_program pid=8827 runtime=979718 [ns] vruntime=30559645220
test_program 8827 [008] 1727205.303363: sched:sched_stat_runtime: comm=test_program pid=8827 runtime=999997445 [ns] vruntime=30559760
test_program 8827 [008] 1727205.303368: sched:sched_stat_runtime: comm=test_program pid=8827 runtime=5898 [ns] vruntime=3055976058680
test_program 8827 [008] 1727205.303370: sched:sched_wakeup: kworker/8:0:4320 [120] success=1 CPU:008
test_program 8827 [008] 1727205.303372: sched:sched_switch: test_program:8827 [100] R ==> kworker/8:0:4320 [120]
perf sched latency
"开关"列仅包含非自愿/非自愿上下文开关。而perf sched script
列出了所有上下文切换(即自愿和非自愿切换(。
您可以将此数字与例如GNU时间进行交叉检查。例如:
perf sched record /usr/bin/time -v yourtestprogram
或者通过其他方式监控/proc/$pid/status
中上下文开关的数量(每种(。
另请参阅perf sched latency
是如何计数的(即nb_atoms
是"开关"值,例如从源文件中的该函数进行回溯(。