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]