HTM(硬件跟踪宏)¶
Athira Rajeev, 2 Mar 2025
基本概述¶
H_HTM 用作执行硬件跟踪宏(HTM)功能的接口,包括 HTM 数据的设置、配置、控制和转储。要使用 HTM,需要设置 HTM 缓冲区,HTM 操作可以通过 H_HTM hcall 进行控制。hcall 可以在分区内部为系统的任何核心/芯片调用。要使用此功能,/sys/kernel/debug/powerpc 下有一个名为“htmdump”的 debugfs 文件夹。
HTM debugfs 使用示例¶
# ls /sys/kernel/debug/powerpc/htmdump/
coreindexonchip htmcaps htmconfigure htmflags htminfo htmsetup
htmstart htmstatus htmtype nodalchipindex nodeindex trace
每个文件的详细信息
nodeindex、nodalchipindex、coreindexonchip 指定为哪个分区配置 HTM。
htmtype:指定 HTM 的类型。支持的目标是 hardwareTarget。
trace:用于读取 HTM 数据。
htmconfigure:配置/取消配置 HTM。向文件写入 1 将配置跟踪,写入 0 将取消配置。
htmstart:启动/停止 HTM。向文件写入 1 将启动跟踪,写入 0 将停止跟踪。
htmstatus:获取 HTM 的状态。这对于理解每次操作后 HTM 的状态是必需的。
htmsetup:设置 HTM 缓冲区大小。HTM 缓冲区大小为 2 的幂。
htminfo:提供系统处理器配置详情。这对于理解 nodeindex、nodalchipindex、coreindexonchip 的合适值是必需的。
htmcaps:提供 HTM 功能,例如最小/最大缓冲区大小、HTM 支持的跟踪类型等。
htmflags:允许向 hcall 传递标志。目前支持控制 HTM 缓冲区的环绕。
查看系统处理器配置详情
# cat /sys/kernel/debug/powerpc/htmdump/htminfo > htminfo_file
结果可以使用 hexdump 进行解释。
为 nodeindex 为零、nodalchipindex 为 1、coreindexonchip 为 12 的分区收集 HTM 跟踪
# cd /sys/kernel/debug/powerpc/htmdump/
# echo 2 > htmtype
# echo 33 > htmsetup ( sets 8GB memory for HTM buffer, number is size in power of 2 )
这需要重新启动 CEC 以分配 HTM 缓冲区。
# cd /sys/kernel/debug/powerpc/htmdump/
# echo 2 > htmtype
# echo 0 > nodeindex
# echo 1 > nodalchipindex
# echo 12 > coreindexonchip
# echo 1 > htmflags # to set noWrap for HTM buffers
# echo 1 > htmconfigure # Configure the HTM
# echo 1 > htmstart # Start the HTM
# echo 0 > htmstart # Stop the HTM
# echo 0 > htmconfigure # Deconfigure the HTM
# cat htmstatus # Dump the status of HTM entries as data
以上将设置 htmtype 和核心详情,然后执行相应的 HTM 操作。
读取 HTM 跟踪数据¶
启动跟踪收集后,运行感兴趣的工作负载。在所需时间段后停止跟踪收集,并读取跟踪文件。
# cat /sys/kernel/debug/powerpc/htmdump/trace > trace_file
此跟踪文件将包含在工作负载执行期间收集到的相关指令跟踪。并且可以作为跟踪解码器的输入文件以理解数据。
使用 HTM debugfs 接口的优势¶
现在可以从系统的任何分区中收集特定核心/芯片的跟踪并对其进行解码。通过此功能,可以将一个小型分区专用于收集跟踪数据并进行分析,从而为性能分析、软件调优或硬件调试提供重要信息。