gtrace: RISC-V Hardware Trace Heads for Mainline Linux With 14-Patch v6 Series
On 1 October 2026, Mayuresh Chitale posted v6 of [PATCH v6 00/14] Linux RISC-V trace framework and drivers to the Linux kernel mailing list. The series introduces gtrace — an architecture-neutral hardware-trace framework whose first backend is the ratified RISC-V E-trace specification. Patch authorship is split evenly between Anup Patel (7 patches) and Chitale (7 patches). If it merges, RISC-V silicon with E-trace IP gains what Arm systems have had for years through CoreSight: instruction-level hardware tracing visible in perf.
rv-etrace branch) — the series names no shipping silicon with E-trace. The archive snapshot also shows no review replies yet.What gtrace Is
gtrace (Generic Trace) lives in drivers/hwtracing/gtrace/ and provides the minimal shared plumbing every hardware-trace implementation needs:
- Component registration — trace sources (encoders), links and sinks register into a graph.
- Path creation and destruction — a trace "path" is the ordered chain of components from source to sink.
- Path start/stop — with v6 adding a
start_countplus a lock to serialize start/stop/aux-copy operations. - perf AUX buffer integration — trace data lands in the standard perf AUX area, exposed as
PERF_RECORD_AUXTRACErecords.
The design is deliberately not RISC-V-only. The cover letter states the framework is architecture-neutral and that the required Arm components could be adapted onto the same framework in the future — a notable claim, because it positions gtrace as a possible long-term successor-or-sibling to drivers/hwtracing/coresight/ rather than a one-ISA bolt-on. In v5 the authors made exactly that pivot: the earlier RISC-V-only rvtrace core was rebuilt as gtrace, and all drivers moved under the new directory.
The Specification Foundation Is Ratified
Unlike many RISC-V kernel features that track draft specs, this series sits on ratified documents:
| Specification | Status | Role in the series |
|---|---|---|
RISC-V E-trace v1.0 (encoder + encapsulation, riscv-non-isa/e-trace-encap) | Ratified (v1.0.0-ratified tag) | First trace protocol backend |
RISC-V Nexus trace (riscv-non-isa/tg-nexus-trace) | Ratified (1.0_Ratified tag) | Second supported protocol |
The drivers are designed to be agnostic to the underlying trace protocol: both E-trace and N-trace should work, and discovery of protocol parameters is deliberately left to the user-space trace decoder. In v6 the trace format (E-Trace vs N-Trace) is selected through the platform driver's compatible string and recorded into both the hardware configuration and the perf data header.
The 14 Patches
| Author | Patches | What they do |
|---|---|---|
| Anup Patel (7) | dt-bindings; gtrace core; RISC-V platform driver; path create/destroy; AUX copy helper; DMA_RESTRICTED_POOL defconfig; MAINTAINERS | The framework itself plus the DT plumbing: a new riscv,trace-component.yaml binding, the 858-line gtrace-core.c, and enabling DMA restricted pools so implementations with RAM-sink address restrictions can be handled |
| Mayuresh Chitale (7) | path start/stop; encoder driver; perf AUX flag; RAM-sink driver; perf driver; perf-tools PMU record; gtrace decoder | The functional stack on top: RISC-V trace encoder and RAM-sink drivers, gtrace-perf.c (390 lines), the gtrace PMU, and initial tools/perf support including a stub decoder |
The total diffstat: 24 files, 3,160 insertions. Notable new files beyond the core: rvtrace-ramsink.c (357 lines — the on-chip RAM sink, default buffer 1 MB), rvtrace-encoder.c (236), rvtrace-platform.c (186), gtrace-of.c (126 — DT connection parsing, promoted into the core in v6), and tools/perf/arch/riscv/util/auxtrace.c (221).
What Changed in v6
The version history tells the maturation story — v2 was rebased on Linux 6.18-rc3, v3 on 7.0-rc1, v4 on 7.1-rc1:
- v5: the architectural pivot — RISC-V-only
rvtracecore became the architecture-neutralgtrace; PMU renamed fromrvtracetogtrace; newPERF_AUX_FLAG_GTRACE_FORMAT_ETRACEflag so sink drivers report the AUX data format. - v6 (this posting): DT connection parsing moved into the core as
gtrace-of.c;start_count+ lock added to serialize start/stop/aux-copy; partially enabled paths now disable all enabled components; cycle detection when walking the trace component graph; trace source ID configuration in the encoder; E-Trace/N-Trace format selection via the compatible string; the RAM-sink setup now reads backtrRamStart/trRamLimitregisters and programs sync frequency, memory format and stop-on-wrap at start time; improved error handling plus a path owner in the perf driver; several issues from the sashiko-bot review fixed.
How to Test It Today
The series is testable on QEMU's virt machine with trace support from Daniel Henrique Barboza's rv-etrace branch, against Chitale's riscv_trace_support_v6 kernel branch:
$ qemu-system-riscv64 -nographic -M virt -smp 2 -bios fw_dynamic.bin \
-kernel Image -append "root=/dev/vda rw console=ttyS0 earlycon=sbi" \
-drive file=rootfs.img,id=disk1,if=none,format=raw \
-device virtio-blk-device,drive=disk1
# capture gtrace data with perf
$ perf record --all-cpus -e gtrace/event=0x1/ <command>
# inspect: perf.data carries PERF_RECORD_AUXTRACE records
$ perf report -D
The perf.data output contains PERF_RECORD_AUXTRACE sections pointing at the raw gtrace data offsets; full packet decoding is future work — the in-tree decoder today is a 95-line stub, with protocol-parameter discovery explicitly left to user space.
Stated Roadmap
The cover letter lists follow-up series: sysfs support, ACPI support, more trace drivers (funnel, ATB and friends), support for the upcoming self-hosted trace specification, and — the strategically interesting one — Arm component support under the gtrace framework.
Builder Takeaways
- RISC-V debugging infrastructure is catching up to Arm's. E-trace silicon plus a mainline gtrace stack gives RISC-V the "where exactly did my firmware/OS go wrong" tool that profiles and printk cannot answer.
- The perf-first design matters. Trace data arrives through the standard perf AUX path and the
gtracePMU, so existing tooling and automation consume it without new daemons. - SoC vendors with E-trace IP now have a kernel target to validate against. The QEMU model lowers the barrier: you can exercise the full capture path before first silicon.
- Watch the Arm-components thread of the story. If CoreSight components ever land on gtrace, RISC-V and Arm tracing converge on one kernel framework — a rare cross-ISA consolidation.
2026 年 10 月 1 日,Mayuresh Chitale 向 Linux 内核邮件列表提交了 [PATCH v6 00/14] Linux RISC-V trace framework and drivers。该系列引入 gtrace —— 一个架构中立的硬件跟踪框架,首个后端是已批准(ratified)的 RISC-V E-trace 规范。补丁署名在 Anup Patel(7 个)与 Chitale(7 个)之间对半分。如果合入,带 E-trace IP 的 RISC-V 芯片将获得 Arm 体系通过 CoreSight 享有多年的能力:在 perf 中可见的指令级硬件跟踪。
rv-etrace 分支)—— 系列未点名任何带 E-trace 的量产芯片。存档快照中也尚未出现评审回复。gtrace 是什么
gtrace(Generic Trace,通用跟踪)位于 drivers/hwtracing/gtrace/,提供每套硬件跟踪实现所需的最小公共管道:
- 组件注册 —— 跟踪源(编码器)、链接与汇聚点(sink)注册进一张组件图。
- 路径创建与销毁 —— 一条跟踪"路径"是从源到 sink 的有序组件链。
- 路径启动/停止 —— v6 新增
start_count和锁,用于串行化 start/stop/AUX 拷贝操作。 - perf AUX 缓冲集成 —— 跟踪数据进入标准 perf AUX 区域,以
PERF_RECORD_AUXTRACE记录呈现。
该设计刻意不绑定 RISC-V。封面信明确:框架是架构中立的,未来 Arm 所需组件也可以适配到同一框架上 —— 这是一个值得注意的表态,因为它把 gtrace 定位成 drivers/hwtracing/coresight/ 的潜在长期继任者或姊妹框架,而不是单一 ISA 的附属品。v5 正是完成了这一转身:早先 RISC-V 专属的 rvtrace 核心重构为 gtrace,全部驱动迁入新目录。
规范基础已经批准
与许多追随草案规范的 RISC-V 内核特性不同,本系列站在已批准的文档上:
| 规范 | 状态 | 在系列中的角色 |
|---|---|---|
RISC-V E-trace v1.0(编码器 + 封装,riscv-non-isa/e-trace-encap) | 已批准(v1.0.0-ratified 标签) | 首个跟踪协议后端 |
RISC-V Nexus 跟踪(riscv-non-isa/tg-nexus-trace) | 已批准(1.0_Ratified 标签) | 第二种受支持协议 |
驱动设计为对底层跟踪协议不可知:E-trace 与 N-trace 都应可用,协议参数的发现刻意留给用户态解码器。v6 中,跟踪格式(E-Trace 或 N-Trace)通过平台驱动的 compatible 字符串选择,并写入硬件配置与 perf 数据头。
14 个补丁的分工
| 作者 | 补丁 | 内容 |
|---|---|---|
| Anup Patel(7) | dt-bindings;gtrace 核心;RISC-V 平台驱动;路径创建/销毁;AUX 拷贝助手;DMA_RESTRICTED_POOL defconfig;MAINTAINERS | 框架本体加设备树管道:新增 riscv,trace-component.yaml 绑定、858 行的 gtrace-core.c,以及启用 DMA 受限池以支持 RAM sink 地址受限的实现 |
| Mayuresh Chitale(7) | 路径启停;编码器驱动;perf AUX 标志;RAM-sink 驱动;perf 驱动;perf 工具 PMU record;gtrace 解码器 | 其上的功能栈:RISC-V 跟踪编码器与 RAM-sink 驱动、gtrace-perf.c(390 行)、gtrace PMU,以及 tools/perf 初始支持(含桩解码器) |
总 diffstat:24 个文件,3,160 行新增。核心之外值得注意的新文件:rvtrace-ramsink.c(357 行 —— 片上 RAM sink,默认缓冲 1 MB)、rvtrace-encoder.c(236)、rvtrace-platform.c(186)、gtrace-of.c(126 —— 设备树连接解析,v6 升格进核心)、tools/perf/arch/riscv/util/auxtrace.c(221)。
v6 变了什么
版本史就是成熟史 —— v2 基于 Linux 6.18-rc3,v3 基于 7.0-rc1,v4 基于 7.1-rc1:
- v5:架构转身 —— RISC-V 专属
rvtrace核心变为架构中立的gtrace;PMU 由rvtrace改名gtrace;新增PERF_AUX_FLAG_GTRACE_FORMAT_ETRACE标志,让 sink 驱动上报 AUX 数据格式。 - v6(本次):设备树连接解析移入核心(
gtrace-of.c);新增start_count+ 锁以串行化 start/stop/AUX 拷贝;部分启用的路径现在会禁用所有已启用组件;遍历组件图时增加环检测;编码器支持 trace source ID 配置;通过 compatible 字符串选择 E-Trace/N-Trace 格式;RAM-sink 启动时回读trRamStart/trRamLimit寄存器并编程同步频率、内存格式与 stop-on-wrap;改进错误处理并在 perf 驱动中引入 path owner;修复 sashiko-bot 评审发现的若干问题。
今天如何测试
使用 Daniel Henrique Barboza 的 rv-etrace 分支中带跟踪支持的 QEMU virt 机型,配合 Chitale 的 riscv_trace_support_v6 内核分支即可测试:
$ qemu-system-riscv64 -nographic -M virt -smp 2 -bios fw_dynamic.bin \
-kernel Image -append "root=/dev/vda rw console=ttyS0 earlycon=sbi" \
-drive file=rootfs.img,id=disk1,if=none,format=raw \
-device virtio-blk-device,drive=disk1
# 用 perf 采集 gtrace 数据
$ perf record --all-cpus -e gtrace/event=0x1/ <command>
# 查看:perf.data 中是 PERF_RECORD_AUXTRACE 记录
$ perf report -D
perf.data 输出中,PERF_RECORD_AUXTRACE 段指向原始 gtrace 数据偏移;完整包解码是后续工作 —— 当前树内解码器只是一个 95 行的桩,协议参数发现明确留给用户态。
官方路线图
封面信列出了后续系列:sysfs 支持、ACPI 支持、更多跟踪驱动(funnel、ATB 等)、对即将到来的自托管跟踪(self-hosted trace)规范的支持,以及 —— 战略上最有趣的一条 —— 在 gtrace 框架下支持 Arm 组件。
开发者要点
- RISC-V 调试基础设施正在追平 Arm。 E-trace 硬件加主线 gtrace 栈,让 RISC-V 拥有 profile 和 printk 回答不了的"固件/OS 到底错在哪一步"的工具。
- perf 优先的设计很关键。 跟踪数据经由标准 perf AUX 路径与
gtracePMU 到达,现有工具链和自动化无需新守护进程即可消费。 - 带 E-trace IP 的 SoC 厂商有了内核侧验证目标。 QEMU 模型降低了门槛:流片前就能跑通完整采集路径。
- 关注"Arm 组件"这条支线。 若 CoreSight 组件将来落到 gtrace 上,RISC-V 与 Arm 的跟踪将收敛到同一个内核框架 —— 罕见的跨 ISA 整合。
Краткое содержание (RU)
1 октября 2026 года Mayuresh Chitale опубликовал v6 серии из 14 патчей «Linux RISC-V trace framework and drivers». Она добавляет gtrace — архитектурно-нейтральный фреймворк аппаратного трассирования, первый бэкенд которого — ратифицированный RISC-V E-trace. Авторство патчей пополам: Anup Patel (7) и Chitale (7). 24 файла, +3160 строк: ядро gtrace-core.c, драйверы энкодера и RAM-sink, gtrace-perf.c, PMU gtrace и начальная поддержка в tools/perf. Драйверы независимы от протокола (E-trace и N-trace); проверка — через QEMU-модель и perf record -e gtrace/event=0x1/. Проект не слит: это v6 на реконсидерации. Общество в короткой перспективе: RISC-V получает аналог Arm CoreSight в основной линейке Linux.
Resumen (ES)
El 1 de octubre de 2026, Mayuresh Chitale publicó la v6 de una serie de 14 parches titulada «Linux RISC-V trace framework and drivers». Introduce gtrace, un marco de trazado por hardware neutral respecto a la arquitectura cuyo primer backend es la especificación RISC-V E-trace ya ratificada. La autoría se reparte a partes iguales entre Anup Patel (7 parches) y Chitale (7). Son 24 archivos y 3.160 líneas nuevas: núcleo gtrace-core.c, drivers de codificador y RAM-sink, gtrace-perf.c, el PMU gtrace y soporte inicial en tools/perf. Los drivers son agnósticos al protocolo (E-trace y N-trace); las pruebas usan un modelo QEMU y perf record -e gtrace/event=0x1/. No está fusionado: es una v6 en revisión. En la práctica, RISC-V se acerca al equivalente de CoreSight en el kernel principal de Linux.
Résumé (FR)
Le 1er octobre 2026, Mayuresh Chitale a publié la v6 d'une série de 14 patchs intitulée « Linux RISC-V trace framework and drivers ». Elle ajoute gtrace, un cadriciel de traçage matériel neutre quant à l'architecture, dont le premier backend est la spécification RISC-V E-trace déjà ratifiée. La paternité se partage à parts égales entre Anup Patel (7 patchs) et Chitale (7). Au total : 24 fichiers, 3 160 lignes ajoutées — noyau gtrace-core.c, pilotes encodeur et RAM-sink, gtrace-perf.c, PMU gtrace et premier support dans tools/perf. Les pilotes sont indépendants du protocole (E-trace et N-trace) ; les tests passent par un modèle QEMU et perf record -e gtrace/event=0x1/. La série n'est pas fusionnée : c'est une v6 en revue. Concrètement, RISC-V se rapproche de l'équivalent de CoreSight dans le noyau Linux principal.
Kurzfassung (DE)
Am 1. Oktober 2026 veröffentlichte Mayuresh Chitale v6 der 14-Patch-Serie »Linux RISC-V trace framework and drivers«. Sie führt gtrace ein, ein architekturneutrales Hardware-Tracing-Framework, dessen erstes Backend die bereits ratifizierte RISC-V-E-trace-Spezifikation ist. Die Autorenschaft teilt sich hälftig: Anup Patel (7 Patches) und Chitale (7). Insgesamt 24 Dateien, +3160 Zeilen: Kern gtrace-core.c, Treiber für Encoder und RAM-Sink, gtrace-perf.c, das PMU gtrace sowie erste Unterstützung in tools/perf. Die Treiber sind protokollagnostisch (E-trace und N-trace); getestet wird über ein QEMU-Modell mit perf record -e gtrace/event=0x1/. Die Serie ist nicht gemerged — eine v6 im Review. Praktisch bedeutet es: RISC-V rückt an das CoreSight-Äquivalent im Linux-Mainline-Kernel heran.
خلاصه (FA)
در ۱ اکتبر ۲۰۲۶، Mayuresh Chitale نسخهٔ ششم سری ۱۴ پچی «Linux RISC-V trace framework and drivers» را منتشر کرد. این سری gtrace را معرفی میکند: چارچوب ردیابی سختافزاریِ مستقل از معماری که اولین بکاند آن مشخصات تأییدشدهٔ RISC-V E-trace است. مالکیت پچها نیمبهنیم است: Anup Patel (۷ پچ) و Chitale (۷ پچ). رویهمرفته ۲۴ فایل و ۳۱۶۰ خط افزودنی: هستهٔ gtrace-core.c، درایورهای انکودر و RAM-sink، gtrace-perf.c، PMU با نام gtrace و پشتیبانی اولیه در tools/perf. درایورها از پروتکل مستقلاند (هم E-trace و هم N-trace)؛ آزمایش از طریق مدل QEMU و perf record -e gtrace/event=0x1/ انجام میشود. این سری ادغام نشده است — یک v6 در حال بازبینی است. در عمل، RISC-V به معادل CoreSight در کرنل اصلی لینوکس نزدیک میشود.
Sources / 参考来源
- LKML archive — Mayuresh Chitale, "[PATCH v6 00/14] Linux RISC-V trace framework and drivers", Thu Oct 01 2026 01:23:34 EST (cover letter with full changelog, diffstat and test instructions)
- RISC-V E-trace encapsulation specification — v1.0.0-ratified release
- RISC-V TG Nexus trace specification — 1.0 Ratified release
- git://github.com/mdchitale/linux — branch riscv_trace_support_v6 (test kernel tree)
- gitlab.com/danielhb/qemu — branch rv-etrace (QEMU virt machine with RISC-V trace support)