Coresight - ARM 上的硬件辅助追踪

作者:

Mathieu Poirier <mathieu.poirier@linaro.org>

日期:

2014 年 9 月 11 日

介绍

Coresight 是用于调试基于 ARM 的 SoC 的技术的集合。它包括 JTAG 和硬件辅助追踪的解决方案。本文档关注后者。

当处理具有许多 SoC 和其他组件(如 GPU 和 DMA 引擎)的系统时,硬件辅助追踪正变得越来越有用。ARM 已经开发了一种硬件辅助追踪解决方案,通过不同的组件,每个组件在综合时被添加到设计中以满足特定的追踪需求。组件通常被分类为源、链接和接收器,并且(通常)使用 AMBA 总线发现。

“源”生成一个压缩流,表示基于用户配置的追踪场景的处理器指令路径。从那里,流通过 Coresight 系统(通过 ATB 总线)使用链接,这些链接将发出的源连接到接收器。接收器用作 Coresight 实现的端点,或者将压缩流存储在内存缓冲区中,或者创建一个到外部世界的接口,在该接口中,数据可以传输到主机,而不必担心填满板载 Coresight 内存缓冲区。

一个典型的 Coresight 系统如下所示

 *****************************************************************
**************************** AMBA AXI  ****************************===||
 *****************************************************************    ||
       ^                    ^                            |            ||
       |                    |                            *            **
    0000000    :::::     0000000    :::::    :::::    @@@@@@@    ||||||||||||
    0 CPU 0<-->: C :     0 CPU 0<-->: C :    : C :    @ STM @    || System ||
 |->0000000    : T :  |->0000000    : T :    : T :<--->@@@@@     || Memory ||
 |  #######<-->: I :  |  #######<-->: I :    : I :      @@@<-|   ||||||||||||
 |  # ETM #    :::::  |  # PTM #    :::::    :::::       @   |
 |   #####      ^ ^   |   #####      ^ !      ^ !        .   |   |||||||||
 | |->###       | !   | |->###       | !      | !        .   |   || DAP ||
 | |   #        | !   | |   #        | !      | !        .   |   |||||||||
 | |   .        | !   | |   .        | !      | !        .   |      |  |
 | |   .        | !   | |   .        | !      | !        .   |      |  *
 | |   .        | !   | |   .        | !      | !        .   |      | SWD/
 | |   .        | !   | |   .        | !      | !        .   |      | JTAG
 *****************************************************************<-|
*************************** AMBA Debug APB ************************
 *****************************************************************
  |    .          !         .          !        !        .    |
  |    .          *         .          *        *        .    |
 *****************************************************************
******************** Cross Trigger Matrix (CTM) *******************
 *****************************************************************
  |    .     ^              .                            .    |
  |    *     !              *                            *    |
 *****************************************************************
****************** AMBA Advanced Trace Bus (ATB) ******************
 *****************************************************************
  |          !                        ===============         |
  |          *                         ===== F =====<---------|
  |   :::::::::                         ==== U ====
  |-->:: CTI ::<!!                       === N ===
  |   :::::::::  !                        == N ==
  |    ^         *                        == E ==
  |    !  &&&&&&&&&       IIIIIII         == L ==
  |------>&& ETB &&<......II     I        =======
  |    !  &&&&&&&&&       II     I           .
  |    !                    I     I          .
  |    !                    I REP I<..........
  |    !                    I     I
  |    !!>&&&&&&&&&       II     I           *Source: ARM ltd.
  |------>& TPIU  &<......II    I            DAP = Debug Access Port
          &&&&&&&&&       IIIIIII            ETM = Embedded Trace Macrocell
              ;                              PTM = Program Trace Macrocell
              ;                              CTI = Cross Trigger Interface
              *                              ETB = Embedded Trace Buffer
         To trace port                       TPIU= Trace Port Interface Unit
                                             SWD = Serial Wire Debug

虽然组件的目标配置是通过 APB 总线完成的,但所有追踪数据都在 ATB 总线上带外传输。CTM 提供了一种聚合和分配 CoreSight 组件之间信号的方法。

Coresight 框架提供了一个中心点来表示、配置和管理平台上的 Coresight 设备。第一个实现集中在基本追踪功能上,启用组件如 ETM/PTM、funnel、replicator、TMC、TPIU 和 ETB。未来的工作将启用更复杂的 IP 块,如 STM 和 CTI。

缩略语和分类

缩略语

PTM

程序追踪宏单元

ETM

嵌入式追踪宏单元

STM

系统追踪宏单元

ETB

嵌入式追踪缓冲区

ITM

仪器追踪宏单元

TPIU

追踪端口接口单元

TMC-ETR

追踪内存控制器,配置为嵌入式追踪路由器

TMC-ETF

追踪内存控制器,配置为嵌入式追踪 FIFO

CTI

交叉触发接口

分类

ETMv3.x ETMv4, PTMv1.0, PTMv1.1, STM, STM500, ITM

链接

Funnel, replicator (智能或非智能), TMC-ETR

接收器

ETBv1.0, ETB1.1, TPIU, TMC-ETF

其他

CTI

设备树绑定

有关详细信息,请参阅 Documentation/devicetree/bindings/arm/arm,coresight-*.yaml

在撰写本文时,不提供 ITM、STM 和 CTI 的驱动程序,但预计会随着解决方案的成熟而添加。

框架和实现

Coresight 框架提供了一个中心点来表示、配置和管理平台上的 Coresight 设备。任何符合 Coresight 规范的设备只要使用正确的 API 就可以向该框架注册

struct coresight_device *coresight_register(struct coresight_desc *desc);
void coresight_unregister(struct coresight_device *csdev);

注册函数接受一个 struct coresight_desc *desc 并将设备注册到核心框架。取消注册函数接受对注册时获得的 struct coresight_device *csdev 的引用。

如果注册过程一切顺利,新设备将显示在 /sys/bus/coresight/devices 下,如下所示,用于 TC2 平台

root:~# ls /sys/bus/coresight/devices/
replicator  20030000.tpiu    2201c000.ptm  2203c000.etm  2203e000.etm
20010000.etb         20040000.funnel  2201d000.ptm  2203d000.etm
root:~#

这些函数接受一个 struct coresight_device,如下所示

struct coresight_desc {
        enum coresight_dev_type type;
        struct coresight_dev_subtype subtype;
        const struct coresight_ops *ops;
        struct coresight_platform_data *pdata;
        struct device *dev;
        const struct attribute_group **groups;
};

“coresight_dev_type” 标识设备是什么类型,即源链接或接收器,而 “coresight_dev_subtype” 将进一步描述该类型。

struct coresight_ops 是必需的,它将告诉框架如何执行与组件相关的基本操作,每个组件都有不同的要求。为此,提供了 struct coresight_ops_sinkstruct coresight_ops_linkstruct coresight_ops_source

下一个字段 struct coresight_platform_data *pdata 是通过调用 of_get_coresight_platform_data() 获取的,作为驱动程序 _probe 例程的一部分,struct device *dev 获取嵌入在 amba_device 中的设备引用

static int etm_probe(struct amba_device *adev, const struct amba_id *id)
{
 ...
 ...
 drvdata->dev = &adev->dev;
 ...
}

特定类别的设备(源、链接或接收器)可以对它们执行通用操作(参见 struct coresight_ops)。**groups 是与仅特定于该组件的操作相关的 sysfs 条目的列表。“实现定义的”自定义预计将使用这些条目进行访问和控制。

设备命名方案

出现在“coresight”总线上的设备与其父设备同名,即出现在 AMBA 总线或平台总线上的真实设备。因此,名称基于 Linux Open Firmware 层命名约定,该约定遵循设备的基本物理地址,后跟设备类型。例如

root:~# ls /sys/bus/coresight/devices/
 20010000.etf  20040000.funnel      20100000.stm     22040000.etm
 22140000.etm  230c0000.funnel      23240000.etm     20030000.tpiu
 20070000.etr  20120000.replicator  220c0000.funnel
 23040000.etm  23140000.etm         23340000.etm

但是,随着 ACPI 支持的引入,真实设备的名称有点神秘且不明显。因此,引入了一种新的命名方案,以使用基于设备类型的更通用的名称。以下规则适用

1) Devices that are bound to CPUs, are named based on the CPU logical
   number.

   e.g, ETM bound to CPU0 is named "etm0"

2) All other devices follow a pattern, "<device_type_prefix>N", where :

      <device_type_prefix>    - A prefix specific to the type of the device
      N                       - a sequential number assigned based on the order
                                of probing.

      e.g, tmc_etf0, tmc_etr0, funnel0, funnel1

因此,使用新方案,设备可能显示为

root:~# ls /sys/bus/coresight/devices/
 etm0     etm1     etm2         etm3  etm4      etm5      funnel0
 funnel1  funnel2  replicator0  stm0  tmc_etf0  tmc_etr0  tpiu0

以下一些示例可能指的是旧的命名方案,而另一些则指的是较新的方案,以确认您在系统上看到的内容不是意外的。必须使用系统上指定位置下显示的“名称”。

拓扑表示

每个 CoreSight 组件都有一个 connections 目录,其中包含指向其他 CoreSight 组件的链接。这允许用户探索追踪拓扑,对于较大的系统,确定给定源最合适的接收器。连接信息还可用于确定哪些 CTI 设备连接到给定组件。此目录包含一个 nr_links 属性,详细说明目录中的链接数。

对于 ETM 源,在本例中是 Juno 平台上的 etm0,一个典型的安排将是

linaro-developer:~# ls - l /sys/bus/coresight/devices/etm0/connections
<file details>  cti_cpu0 -> ../../../23020000.cti/cti_cpu0
<file details>  nr_links
<file details>  out:0 -> ../../../230c0000.funnel/funnel2

跟随输出端口到 funnel2

linaro-developer:~# ls -l /sys/bus/coresight/devices/funnel2/connections
<file details> in:0 -> ../../../23040000.etm/etm0
<file details> in:1 -> ../../../23140000.etm/etm3
<file details> in:2 -> ../../../23240000.etm/etm4
<file details> in:3 -> ../../../23340000.etm/etm5
<file details> nr_links
<file details> out:0 -> ../../../20040000.funnel/funnel0

再次到 funnel0

linaro-developer:~# ls -l /sys/bus/coresight/devices/funnel0/connections
<file details> in:0 -> ../../../220c0000.funnel/funnel1
<file details> in:1 -> ../../../230c0000.funnel/funnel2
<file details> nr_links
<file details> out:0 -> ../../../20010000.etf/tmc_etf0

找到第一个接收器 tmc_etf0。这可以用作收集数据的接收器,或者作为进一步沿链传播的链接

linaro-developer:~# ls -l /sys/bus/coresight/devices/tmc_etf0/connections
<file details> cti_sys0 -> ../../../20020000.cti/cti_sys0
<file details> in:0 -> ../../../20040000.funnel/funnel0
<file details> nr_links
<file details> out:0 -> ../../../20150000.funnel/funnel4

通过 funnel4

linaro-developer:~# ls -l /sys/bus/coresight/devices/funnel4/connections
<file details> in:0 -> ../../../20010000.etf/tmc_etf0
<file details> in:1 -> ../../../20140000.etf/tmc_etf1
<file details> nr_links
<file details> out:0 -> ../../../20120000.replicator/replicator0

和一个 replicator0

linaro-developer:~# ls -l /sys/bus/coresight/devices/replicator0/connections
<file details> in:0 -> ../../../20150000.funnel/funnel4
<file details> nr_links
<file details> out:0 -> ../../../20030000.tpiu/tpiu0
<file details> out:1 -> ../../../20070000.etr/tmc_etr0

到达链中的最终接收器,tmc_etr0

linaro-developer:~# ls -l /sys/bus/coresight/devices/tmc_etr0/connections
<file details> cti_sys0 -> ../../../20020000.cti/cti_sys0
<file details> in:0 -> ../../../20120000.replicator/replicator0
<file details> nr_links

如下所述,当使用 sysfs 时,只需启用接收器和源即可成功追踪。框架将根据需要正确启用所有中间链接。

注意: cti_sys0 出现在上面的两个连接列表中。CTI 可以连接到多个设备,并通过 CTM 以星形拓扑排列。有关更多详细信息,请参见 (CoreSight 嵌入式交叉触发器 (CTI & CTM)。) [4]。查看此设备,我们看到 4 个连接

linaro-developer:~# ls -l /sys/bus/coresight/devices/cti_sys0/connections
<file details> nr_links
<file details> stm0 -> ../../../20100000.stm/stm0
<file details> tmc_etf0 -> ../../../20010000.etf/tmc_etf0
<file details> tmc_etr0 -> ../../../20070000.etr/tmc_etr0
<file details> tpiu0 -> ../../../20030000.tpiu/tpiu0

如何使用追踪器模块

有两种方法可以使用 Coresight 框架

  1. 使用 perf 命令行工具。

  2. 使用 sysFS 接口直接与 Coresight 设备交互。

优先考虑前者,因为使用 sysFS 接口需要对 Coresight HW 有深入的了解。以下部分提供了有关使用这两种方法的详细信息。

使用 sysFS 接口

在追踪收集开始之前,需要识别 Coresight 接收器。可以随时启用任意数量的接收器(和源)。作为通用操作,属于接收器类的所有设备在 sysfs 中都有一个“active”条目

root:/sys/bus/coresight/devices# ls
replicator  20030000.tpiu    2201c000.ptm  2203c000.etm  2203e000.etm
20010000.etb         20040000.funnel  2201d000.ptm  2203d000.etm
root:/sys/bus/coresight/devices# ls 20010000.etb
enable_sink  status  trigger_cntr
root:/sys/bus/coresight/devices# echo 1 > 20010000.etb/enable_sink
root:/sys/bus/coresight/devices# cat 20010000.etb/enable_sink
1
root:/sys/bus/coresight/devices#

在启动时,当前的 etm3x 驱动程序将使用 “_stext” 和 “_etext” 配置第一个地址比较器,本质上是追踪落在该范围内的任何指令。因此,“启用”源将立即触发追踪捕获

root:/sys/bus/coresight/devices# echo 1 > 2201c000.ptm/enable_source
root:/sys/bus/coresight/devices# cat 2201c000.ptm/enable_source
1
root:/sys/bus/coresight/devices# cat 20010000.etb/status
Depth:          0x2000
Status:         0x1
RAM read ptr:   0x0
RAM wrt ptr:    0x19d3   <----- The write pointer is moving
Trigger cnt:    0x0
Control:        0x1
Flush status:   0x0
Flush ctrl:     0x2001
root:/sys/bus/coresight/devices#

追踪收集以相同的方式停止

root:/sys/bus/coresight/devices# echo 0 > 2201c000.ptm/enable_source
root:/sys/bus/coresight/devices#

ETB 缓冲区的内容可以直接从 /dev 中获取

root:/sys/bus/coresight/devices# dd if=/dev/20010000.etb \
of=~/cstrace.bin
64+0 records in
64+0 records out
32768 bytes (33 kB) copied, 0.00125258 s, 26.2 MB/s
root:/sys/bus/coresight/devices#

可以使用 “ptm2human”、DS-5 或 Trace32 解压缩文件 cstrace.bin。

以下是使用 DS-5 输出的实验循环,该循环将变量递增到一定值。该示例很简单,但提供了 Coresight 提供的丰富可能性的概览。

Info                                    Tracing enabled
Instruction     106378866       0x8026B53C      E52DE004        false   PUSH     {lr}
Instruction     0       0x8026B540      E24DD00C        false   SUB      sp,sp,#0xc
Instruction     0       0x8026B544      E3A03000        false   MOV      r3,#0
Instruction     0       0x8026B548      E58D3004        false   STR      r3,[sp,#4]
Instruction     0       0x8026B54C      E59D3004        false   LDR      r3,[sp,#4]
Instruction     0       0x8026B550      E3530004        false   CMP      r3,#4
Instruction     0       0x8026B554      E2833001        false   ADD      r3,r3,#1
Instruction     0       0x8026B558      E58D3004        false   STR      r3,[sp,#4]
Instruction     0       0x8026B55C      DAFFFFFA        true    BLE      {pc}-0x10 ; 0x8026b54c
Timestamp                                       Timestamp: 17106715833
Instruction     319     0x8026B54C      E59D3004        false   LDR      r3,[sp,#4]
Instruction     0       0x8026B550      E3530004        false   CMP      r3,#4
Instruction     0       0x8026B554      E2833001        false   ADD      r3,r3,#1
Instruction     0       0x8026B558      E58D3004        false   STR      r3,[sp,#4]
Instruction     0       0x8026B55C      DAFFFFFA        true    BLE      {pc}-0x10 ; 0x8026b54c
Instruction     9       0x8026B54C      E59D3004        false   LDR      r3,[sp,#4]
Instruction     0       0x8026B550      E3530004        false   CMP      r3,#4
Instruction     0       0x8026B554      E2833001        false   ADD      r3,r3,#1
Instruction     0       0x8026B558      E58D3004        false   STR      r3,[sp,#4]
Instruction     0       0x8026B55C      DAFFFFFA        true    BLE      {pc}-0x10 ; 0x8026b54c
Instruction     7       0x8026B54C      E59D3004        false   LDR      r3,[sp,#4]
Instruction     0       0x8026B550      E3530004        false   CMP      r3,#4
Instruction     0       0x8026B554      E2833001        false   ADD      r3,r3,#1
Instruction     0       0x8026B558      E58D3004        false   STR      r3,[sp,#4]
Instruction     0       0x8026B55C      DAFFFFFA        true    BLE      {pc}-0x10 ; 0x8026b54c
Instruction     7       0x8026B54C      E59D3004        false   LDR      r3,[sp,#4]
Instruction     0       0x8026B550      E3530004        false   CMP      r3,#4
Instruction     0       0x8026B554      E2833001        false   ADD      r3,r3,#1
Instruction     0       0x8026B558      E58D3004        false   STR      r3,[sp,#4]
Instruction     0       0x8026B55C      DAFFFFFA        true    BLE      {pc}-0x10 ; 0x8026b54c
Instruction     10      0x8026B54C      E59D3004        false   LDR      r3,[sp,#4]
Instruction     0       0x8026B550      E3530004        false   CMP      r3,#4
Instruction     0       0x8026B554      E2833001        false   ADD      r3,r3,#1
Instruction     0       0x8026B558      E58D3004        false   STR      r3,[sp,#4]
Instruction     0       0x8026B55C      DAFFFFFA        true    BLE      {pc}-0x10 ; 0x8026b54c
Instruction     6       0x8026B560      EE1D3F30        false   MRC      p15,#0x0,r3,c13,c0,#1
Instruction     0       0x8026B564      E1A0100D        false   MOV      r1,sp
Instruction     0       0x8026B568      E3C12D7F        false   BIC      r2,r1,#0x1fc0
Instruction     0       0x8026B56C      E3C2203F        false   BIC      r2,r2,#0x3f
Instruction     0       0x8026B570      E59D1004        false   LDR      r1,[sp,#4]
Instruction     0       0x8026B574      E59F0010        false   LDR      r0,[pc,#16] ; [0x8026B58C] = 0x80550368
Instruction     0       0x8026B578      E592200C        false   LDR      r2,[r2,#0xc]
Instruction     0       0x8026B57C      E59221D0        false   LDR      r2,[r2,#0x1d0]
Instruction     0       0x8026B580      EB07A4CF        true    BL       {pc}+0x1e9344 ; 0x804548c4
Info                                    Tracing enabled
Instruction     13570831        0x8026B584      E28DD00C        false   ADD      sp,sp,#0xc
Instruction     0       0x8026B588      E8BD8000        true    LDM      sp!,{pc}
Timestamp                                       Timestamp: 17107041535

使用 perf 框架

Coresight 追踪器使用 Perf 框架的性能监视单元 (PMU) 抽象来表示。因此,perf 框架负责控制何时根据何时调度感兴趣的进程来启用追踪。在系统中配置时,当被 perf 命令行工具查询时,将列出 Coresight PMU

linaro@linaro-nano:~$ ./perf list pmu

预定义事件列表(用于 -e)

cs_etm// [内核 PMU 事件]

无论系统中可用的追踪器数量(通常等于处理器核心数量)如何,“cs_etm” PMU 都只会列出一次。

Coresight PMU 的工作方式与任何其他 PMU 相同,即 PMU 的名称与正斜杠 '/' 内的配置选项一起提供(请参见 配置选项格式)。

高级 Perf 框架用法

接收器选择

将自动选择合适的接收器与 Perf 一起使用,但由于通常会有多个接收器,因此要使用的接收器的名称可以指定为带有 ‘@’ 前缀的特殊配置选项。

可用的接收器在 sysFS 的 ($SYSFS)/bus/event_source/devices/cs_etm/sinks/ 下列出。

root@localhost:/sys/bus/event_source/devices/cs_etm/sinks# ls
tmc_etf0  tmc_etr0  tpiu0

root@linaro-nano:~# perf record -e cs_etm/@tmc_etr0/u --per-thread program

有关上述内容以及如何在 perf 工具中使用 Coresight 的其他示例的更多信息,可以在 openCSD gitHub 存储库的 “HOWTO.md” 文件中找到 [3]

使用 perf 工具的 AutoFDO 分析

perf 可用于记录和分析程序的追踪。

可以使用带有 cs_etm 事件的 ‘perf record’ 记录执行,指定要记录到的接收器的名称,例如

perf record -e cs_etm//u --per-thread

‘perf report’ 和 ‘perf script’ 命令可用于分析执行,从指令追踪合成指令和分支事件。‘perf inject’ 可用于将追踪数据替换为合成事件。--itrace 选项控制合成事件的类型和频率(请参见 perf 文档)。

请注意,目前仅支持 64 位程序 - 需要进一步的工作来支持 32 位 Arm 程序的指令解码。

追踪 PID

可以构建内核以将 PID 值写入 PE ContextID 寄存器。对于在 EL1 运行的内核,PID 存储在 CONTEXTIDR_EL1 中。PE 可以实现 Arm 虚拟化主机扩展 (VHE),内核可以在 EL2 上作为虚拟化主机运行;在这种情况下,PID 值存储在 CONTEXTIDR_EL2 中。

perf 提供 PMU 格式,该格式对 ETM 进行编程以将这些值插入到追踪数据中;PMU 格式定义如下

“contextid1”: 在 EL1 内核和 EL2 内核上都可用。当

内核在 EL1 上运行时,“contextid1” 启用 PID 追踪;当内核在 EL2 上运行时,这将启用追踪来宾应用程序的 PID。

“contextid2”: 仅在内核在 EL2 上运行时可用。当

选择时,启用 EL2 内核上的 PID 追踪。

“contextid”: 将是启用 PID 的选项的别名

追踪。即,在 EL1 内核上,contextid == contextid1。在 EL2 内核上,contextid == contextid2。

perf 将始终在相关的 EL 上启用 PID 追踪,这是通过自动启用 “contextid” 配置来实现的 - 但是对于 EL2,可以使用配置 “contextid1” 和 “contextid2” 进行特定的调整,例如,如果用户想要追踪主机和来宾的 PID,则可以同时设置两个配置 “contextid1” 和 “contextid2”

perf record -e cs_etm/contextid1,contextid2/u -- vm

为反馈定向优化生成覆盖率文件: AutoFDO

“perf inject” 接受 --itrace 选项,在这种情况下,跟踪数据会被移除并替换为合成事件。例如:

perf inject --itrace --strip -i perf.data -o perf.data.new

以下是使用 ARM ETM 进行 autoFDO 的示例。它需要 autofdo (https://github.com/google/autofdo) 和 gcc 版本 5。气泡排序示例来自 AutoFDO 教程 (https://gcc.gnu.org/wiki/AutoFDO/Tutorial)。

$ gcc-5 -O3 sort.c -o sort
$ taskset -c 2 ./sort
Bubble sorting array of 30000 elements
5910 ms

$ perf record -e cs_etm//u --per-thread taskset -c 2 ./sort
Bubble sorting array of 30000 elements
12543 ms
[ perf record: Woken up 35 times to write data ]
[ perf record: Captured and wrote 69.640 MB perf.data ]

$ perf inject -i perf.data -o inj.data --itrace=il64 --strip
$ create_gcov --binary=./sort --profile=inj.data --gcov=sort.gcov -gcov_version=1
$ gcc-5 -O3 -fauto-profile=sort.gcov sort.c -o sort_autofdo
$ taskset -c 2 ./sort_autofdo
Bubble sorting array of 30000 elements
5806 ms

配置选项格式

可以在 perf 命令行上的 // 之间提供以下字符串以启用各种选项。它们也列在文件夹 /sys/bus/event_source/devices/cs_etm/format/ 中

选项

描述

branch_broadcast

系统范围设置的会话本地版本: ETM_MODE_BB

contextid

参见 追踪 PID

contextid1

参见 追踪 PID

contextid2

参见 追踪 PID

configid

自定义配置的选择。这是一个实现细节,不直接使用,请参见 在 perf 中使用配置

preset

自定义配置中的参数的覆盖,请参见 在 perf 中使用配置

sinkid

用于选择接收器的字符串的哈希版本,在使用 @ 表示法时自动设置。这是一个内部实现细节,不直接使用,请参见 使用 perf 框架

cycacc

系统范围设置的会话本地版本: ETMv4_MODE_CYCACC

retstack

系统范围设置的会话本地版本: ETM_MODE_RETURNSTACK

timestamp

系统范围设置的会话本地版本: ETMv4_MODE_TIMESTAMP

cc_threshold

周期计数阈值。如果此处未提供任何内容或提供的值为 0,则将使用默认值,即 0x100。如果提供的值小于最小周期阈值,如 TRCIDR3.CCITMIN 所示,则将使用最小值。

如何使用 STM 模块

使用系统追踪宏单元模块与使用追踪器相同 - 唯一的区别是客户端驱动追踪捕获,而不是通过代码的程序流程。

与任何其他 CoreSight 组件一样,有关 STM 追踪器的具体信息可以在 sysfs 中找到,有关每个条目的更多信息可以在 [1] 中找到

root@genericarmv8:~# ls /sys/bus/coresight/devices/stm0
enable_source   hwevent_select  port_enable     subsystem       uevent
hwevent_enable  mgmt            port_select     traceid
root@genericarmv8:~#

与任何其他源一样,在使用之前需要识别接收器并启用 STM

root@genericarmv8:~# echo 1 > /sys/bus/coresight/devices/tmc_etf0/enable_sink
root@genericarmv8:~# echo 1 > /sys/bus/coresight/devices/stm0/enable_source

从那里,用户空间应用程序可以使用通用 STM API 为此目的提供的 devfs 接口请求和使用通道

root@genericarmv8:~# ls -l /dev/stm0
crw-------    1 root     root       10,  61 Jan  3 18:11 /dev/stm0
root@genericarmv8:~#

有关如何使用通用 STM API 的详细信息,请参见此处: - 系统追踪模块 [2]

CTI & CTM 模块

CTI(交叉触发接口)在各个 CTI 和组件之间提供一组触发信号,并且可以通过 CTM(交叉触发矩阵)上的通道在所有 CTI 之间传播这些信号。

提供了一个单独的文档文件来解释这些设备的使用。(CoreSight 嵌入式交叉触发器 (CTI & CTM)。[4]

CoreSight 系统配置

CoreSight 组件可以是具有许多编程选项的复杂设备。此外,可以对组件进行编程以在整个系统中相互交互。

提供了一个 CoreSight 系统配置管理器,以允许从 perf 和 sysfs 轻松选择和使用这些复杂的编程配置。

有关更多信息,请参见单独的文档。(CoreSight 系统配置管理器[5]