rtla-timerlat-top

测量操作系统定时器延迟

手册章节:

1

概要

rtla timerlat top [选项] ...

描述

rtla timerlat 工具是 timerlat 跟踪器的一个接口。 timerlat 跟踪器为每个 CPU 调度一个内核线程。这些线程设置一个周期性定时器来唤醒自己,然后再次进入睡眠。唤醒后,它们收集并生成有用的信息,用于调试操作系统定时器延迟。

timerlat 跟踪器以两种方式输出信息。它会周期性地打印定时器 IRQ 处理程序和 Thread 处理程序处的定时器延迟。它还通过 osnoise: 跟踪点启用最相关信息的跟踪。

rtla timerlat 工具设置 timerlat 跟踪器的选项,并收集和显示结果摘要。默认情况下,数据收集是通过附加到 timerlat 跟踪器的专用 BPF 程序在内核空间同步完成的。如果 BPF 或其所附加的 osnoise:timerlat_sample 跟踪点不可用,则 rtla timerlat 工具会回退到使用 tracefs 在用户空间异步处理数据。

rtla timerlat top 显示 timerlat 跟踪器周期性输出的摘要。它还通过 osnoise: 跟踪点为每个操作系统噪声提供信息,这些信息可以通过 -T 选项查看。

选项

-a, --auto 微秒

设置自动跟踪模式。此模式在调试系统时设置一些常用选项。它等同于使用 -T 微秒 -s 微秒 -t。默认情况下,timerlat 跟踪器对 timerlat 线程使用 FIFO:95,因此等同于 -P f:95

-p, --period 微秒

设置 timerlat 跟踪器周期,单位为微秒。

-i, --irq 微秒

如果 IRQ 延迟高于参数值(单位:微秒),则停止跟踪。

-T, --thread 微秒

如果 Thread 延迟高于参数值(单位:微秒),则停止跟踪。

-s, --stack 微秒

如果 Thread 延迟高于参数值(单位:微秒),则在 IRQ 处保存堆栈跟踪。

-t, --trace [文件]

将停止的跟踪保存到 [文件|timerlat_trace.txt]。

--dma-latency 微秒

将 /dev/cpu_dma_latency 设置为 微秒,旨在限制退出空闲状态的延迟。 cyclictest 默认将此值设置为 0,使用 --dma-latency 0 可获得类似结果。

--deepest-idle-state n

禁用运行 timerlat 线程的 CPU 上高于 n 的空闲状态,以减少退出空闲状态的延迟。如果 n 为 -1,则禁用所有空闲状态。退出 timerlat 时,空闲状态设置将恢复到运行 timerlat 之前的原始状态。

要求 rtla 使用 libcpupower 构建。

-k, --kernel-threads

使用 timerlat 内核空间线程,与 -u 相反。

-u, --user-threads

设置 timerlat 在没有工作负载的情况下运行,然后调度用户空间工作负载在 timerlat_fd 上等待。一旦工作负载被唤醒,它会再次进入睡眠,从而将内核到用户和用户到内核的测量结果添加到跟踪器输出中。除非用户指定 -k,否则将使用 --user-threads

-U, --user-load

设置 timerlat 在没有工作负载的情况下运行,等待用户调度一个每个 CPU 的任务,该任务在 tracing/osnoise/per_cpu/cpu$ID/timerlat_fd 上等待新的周期。有关用户负载代码示例,请参阅 linux/tools/rtla/sample/timerlat_load.py。

-q, --quiet

仅在会话结束时打印摘要。

-c, --cpus cpu-列表

设置 osnoise 跟踪器在 cpu-列表 中运行示例线程。

-H, --house-keeping cpu-列表

仅在给定的 cpu-列表 上运行 rtla 控制线程。

-d, --duration 时间[秒|分|小时|天]

设置会话持续时间。

-D, --debug

打印调试信息。

-e, --event 系统:事件

在跟踪 (-t) 会话中启用一个事件。参数可以是特定事件,例如 -e sched:sched_switch,或系统组的所有事件,例如 -e sched。允许多个 -e。仅当设置了 -t-a 时才激活。

--filter <过滤器>

使用 <过滤器> 过滤上一个 -e 系统:事件 事件。有关事件过滤的更多信息,请参阅 https://linuxkernel.org.cn/doc/html/latest/trace/events.html#event-filtering

--trigger <触发器>

为上一个 -e 系统:事件 启用跟踪事件触发器。如果 hist: 触发器被激活,输出直方图将自动保存到名为 system_event_hist.txt 的文件中。例如,命令

rtla <command> <mode> -t -e osnoise:irq_noise --trigger=”hist:key=desc,duration/1000:sort=desc,duration/1000:vals=hitcount”

将自动保存与 osnoise:irq_noise 事件关联的直方图内容到 osnoise_irq_noise_hist.txt

有关事件触发器的更多信息,请参阅 https://linuxkernel.org.cn/doc/html/latest/trace/events.html#event-triggers

-P, --priority o:优先级|r:优先级|f:优先级|d:运行时:周期

设置 osnoise 跟踪器线程的调度参数,设置优先级的格式为

  • o:优先级 - 使用 SCHED_OTHER 和 优先级;

  • r:优先级 - 使用 SCHED_RR 和 优先级;

  • f:优先级 - 使用 SCHED_FIFO 和 优先级;

  • d:运行时[微秒|毫秒|秒]:周期[微秒|毫秒|秒] - 使用 SCHED_DEADLINE 和纳秒单位的 运行时周期

-C, --cgroup[=cgroup]

为跟踪器的线程设置一个 cgroup。如果 -C 选项不带参数,跟踪器的线程将继承 rtlacgroup。否则,线程将被放置在传递给该选项的 cgroup 上。

--warm-up

启动工作负载后,让其运行 秒,然后才开始收集数据,以允许系统预热。预热期间生成的统计数据将被丢弃。

--trace-buffer-size KB

设置每个 CPU 的跟踪缓冲区大小(单位:KB),用于跟踪输出。

-h, --help

打印帮助菜单。

--dump-tasks

如果满足停止条件,打印所有 CPU 上运行的任务(取决于 !--no-aa)

--no-aa

禁用自动分析,减少 rtla timerlat 的 CPU 使用。

--aa-only 微秒

设置停止跟踪条件并运行,而不收集和显示统计数据。如果系统达到停止跟踪条件,则打印自动分析结果。此选项有助于减少 rtla timerlat 的 CPU 使用,从而在没有收集统计数据开销的情况下启用调试。

示例

在下面的示例中,timerlat 跟踪器在自动跟踪模式下被分派到 CPU 1-23,指示跟踪器在发现 40 微秒 或更高的延迟时停止。

# timerlat -a 40 -c 1-23 -q
                                   Timer Latency
  0 00:00:12   |          IRQ Timer Latency (us)        |         Thread Timer Latency (us)
CPU COUNT      |      cur       min       avg       max |      cur       min       avg       max
  1 #12322     |        0         0         1        15 |       10         3         9        31
  2 #12322     |        3         0         1        12 |       10         3         9        23
  3 #12322     |        1         0         1        21 |        8         2         8        34
  4 #12322     |        1         0         1        17 |       10         2        11        33
  5 #12322     |        0         0         1        12 |        8         3         8        25
  6 #12322     |        1         0         1        14 |       16         3        11        35
  7 #12322     |        0         0         1        14 |        9         2         8        29
  8 #12322     |        1         0         1        22 |        9         3         9        34
  9 #12322     |        0         0         1        14 |        8         2         8        24
 10 #12322     |        1         0         0        12 |        9         3         8        24
 11 #12322     |        0         0         0        15 |        6         2         7        29
 12 #12321     |        1         0         0        13 |        5         3         8        23
 13 #12319     |        0         0         1        14 |        9         3         9        26
 14 #12321     |        1         0         0        13 |        6         2         8        24
 15 #12321     |        1         0         1        15 |       12         3        11        27
 16 #12318     |        0         0         1        13 |        7         3        10        24
 17 #12319     |        0         0         1        13 |       11         3         9        25
 18 #12318     |        0         0         0        12 |        8         2         8        20
 19 #12319     |        0         0         1        18 |       10         2         9        28
 20 #12317     |        0         0         0        20 |        9         3         8        34
 21 #12318     |        0         0         0        13 |        8         3         8        28
 22 #12319     |        0         0         1        11 |        8         3        10        22
 23 #12320     |       28         0         1        28 |       41         3        11        41
rtla timerlat hit stop tracing
## CPU 23 hit stop tracing, analyzing it ##
IRQ handler delay:                                        27.49 us (65.52 %)
IRQ latency:                                              28.13 us
Timerlat IRQ duration:                                     9.59 us (22.85 %)
Blocking thread:                                           3.79 us (9.03 %)
                       objtool:49256                       3.79 us
  Blocking thread stacktrace
              -> timerlat_irq
              -> __hrtimer_run_queues
              -> hrtimer_interrupt
              -> __sysvec_apic_timer_interrupt
              -> sysvec_apic_timer_interrupt
              -> asm_sysvec_apic_timer_interrupt
              -> _raw_spin_unlock_irqrestore
              -> cgroup_rstat_flush_locked
              -> cgroup_rstat_flush_irqsafe
              -> mem_cgroup_flush_stats
              -> mem_cgroup_wb_stats
              -> balance_dirty_pages
              -> balance_dirty_pages_ratelimited_flags
              -> btrfs_buffered_write
              -> btrfs_do_write_iter
              -> vfs_write
              -> __x64_sys_pwrite64
              -> do_syscall_64
              -> entry_SYSCALL_64_after_hwframe
------------------------------------------------------------------------
  Thread latency:                                          41.96 us (100%)

The system has exit from idle latency!
  Max timerlat IRQ latency from idle: 17.48 us in cpu 4
Saving trace to timerlat_trace.txt

在这种情况下,主要因素是处理 timerlat 唤醒的 IRQ 处理程序 所遭受的延迟:65.52%。这可能是由当前线程屏蔽中断引起的,这可以在阻塞线程的堆栈跟踪中看到:当前线程 (objtool:49256) 在 mem cgroup 内部通过 raw spin lock 操作禁用了中断,同时在 btrfs 文件系统中执行写系统调用。

原始跟踪保存到 timerlat_trace.txt 文件中以供进一步分析。

请注意,rtla timerlat 在调度时没有更改 timerlat 跟踪器线程的优先级。这通常不是必需的,因为这些线程默认具有 FIFO:95 的优先级,这是实时内核开发人员用于分析调度延迟的常用优先级。

另请参阅

rtla-timerlat(1), rtla-timerlat-hist(1)

timerlat 跟踪器文档:<https://linuxkernel.org.cn/doc/html/latest/trace/timerlat-tracer.html>

作者

由 Daniel Bristot de Oliveira 撰写 <bristot@kernel.org>

报告错误

向 <linux-kernel@vger.kernel.org> 和 <linux-trace-devel@vger.kernel.org> 报告错误

许可证

rtla 是根据 GNU GPLv2 许可的自由软件

版权

版权所有 (C) 2021 Red Hat, Inc. 依据 GNU 通用公共许可证 (GPL) 的条款,授予本软件的自由使用权。