Hi,
These patches add support for using perf inject to generate branch events
and branch stacks from CoreSight ETM traces.
They apply to the recently submitted perf support for CoreSight trace [1]
with the subsequent memory cleanup fix [2]
The first patch is Sebastian's original commits from [3] reworked to
apply to the refactored version now upstreamed, with some fixes for branch
events and my work on branch stacks posted last November [4], updated with
review comments.
The second patch is a new patch that handles discontinuities in the trace
stream, e.g. when the ETM is configured to only trace certain regions or
is only active some of the time.
These probably need to be squashed together before going upstream, but I've
left them as separate commits for initial review.
Regards
Rob Walker
[1]: https://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git
tag perf-core-for-mingo-4.16-20180125
[2]: https://lkml.org/lkml/2018/1/25/432
[3]: https://github.com/Linaro/perf-opencsd/ autoFDO branch
[4]: https://lists.linaro.org/pipermail/coresight/2017-November/000955.html
Robert Walker (2):
perf tools: inject capabilitity for CoreSight traces
perf inject: Emit instruction records on ETM trace discontinuity
Documentation/trace/coresight.txt | 31 ++
tools/perf/util/cs-etm-decoder/cs-etm-decoder.c | 68 +++-
tools/perf/util/cs-etm-decoder/cs-etm-decoder.h | 2 +
tools/perf/util/cs-etm.c | 471 +++++++++++++++++++++---
4 files changed, 509 insertions(+), 63 deletions(-)
--
1.9.1
Since libopencsd is not part of the 'mainstream' libraries upstream
maintainers have decided not to display its status on the system by
default. To do so the VF=1 option is required, something this patch
documents.
Signed-off-by: Mathieu Poirier <mathieu.poirier(a)linaro.org>
---
HOWTO.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/HOWTO.md b/HOWTO.md
index 16534f858a19..b13408720d43 100644
--- a/HOWTO.md
+++ b/HOWTO.md
@@ -306,7 +306,7 @@ and needs to be installed on a system prior to compilation. Information about
the status of the openCSD library on a system is given at compile time by the
perf tools build script:
- linaro@t430:~/linaro/linux-kernel$ make -C tools/perf
+ linaro@t430:~/linaro/linux-kernel$ make VF=1 -C tools/perf
Auto-detecting system features:
... dwarf: [ on ]
... dwarf_getlocations: [ on ]
--
2.7.4
This patch set is to explore Coresight trace data for postmortem
debugging. When kernel panic happens, the Coresight panic kdump can
help save on-chip trace data and tracer metadata into DRAM, later
relies on kdump and crash/perf for "offline" analysis.
The documentation is important to understand the purpose of Coresight
panic kdump, the implementation and usage. Patches 0001/0002 are used
to relocate and add related documenation.
Patch 0003 introduces the simple panic kdump framework which can be
easily used by Coresight devices.
Patches 0004/0005 support panic kdump for ETB; Patch 0006 supports
the dump for ETMv4. As Mathieu suggested, patch 0006 distinguish two
different tracer enabling mode: sysFS interface and perf mode.
This patch set have been verified on 96boards Hikey with tracer
enabling by sysFS interface.
Changes from v2:
* Add the two patches for documentation.
* Following Mathieu suggestion, reworked the panic kdump framework,
removed the useless flag "PRE_PANIC".
* According to comment, changed to add and delete kdump node operations
in sink enable/disable functions;
* According to Mathieu suggestion, handle kdump node
addition/deletion/updating separately for sysFS interface and perf
method.
Changes from v1:
* Add support to dump ETMv4 meta data.
* Wrote 'crash' extension csdump.so so rely on it to generate 'perf'
format compatible file.
* Refactored panic dump driver to support pre & post panic dump.
Changes from RFC:
* Follow Mathieu's suggestion, use general framework to support dump
functionality.
* Changed to use perf to analyse trace data.
Leo Yan (6):
doc: Add Coresight documentation directory
doc: Add documentation for Coresight panic kdump
coresight: Support panic kdump functionality
coresight: tmc: Hook callback for panic kdump
coresight: Add and delete sink callback for panic kdump list
coresight: etm4x: Support panic kdump
Documentation/trace/coresight-cpu-debug.txt | 187 ------------
Documentation/trace/coresight.txt | 332 ---------------------
.../trace/coresight/coresight-cpu-debug.txt | 187 ++++++++++++
.../trace/coresight/coresight-panic-kdump.txt | 91 ++++++
Documentation/trace/coresight/coresight.txt | 332 +++++++++++++++++++++
MAINTAINERS | 5 +-
drivers/hwtracing/coresight/Kconfig | 9 +
drivers/hwtracing/coresight/Makefile | 1 +
drivers/hwtracing/coresight/coresight-etm-perf.c | 12 +-
drivers/hwtracing/coresight/coresight-etm4x.c | 23 ++
drivers/hwtracing/coresight/coresight-etm4x.h | 15 +
.../hwtracing/coresight/coresight-panic-kdump.c | 154 ++++++++++
drivers/hwtracing/coresight/coresight-priv.h | 13 +
drivers/hwtracing/coresight/coresight-tmc-etf.c | 29 ++
drivers/hwtracing/coresight/coresight.c | 12 +
include/linux/coresight.h | 7 +
16 files changed, 887 insertions(+), 522 deletions(-)
delete mode 100644 Documentation/trace/coresight-cpu-debug.txt
delete mode 100644 Documentation/trace/coresight.txt
create mode 100644 Documentation/trace/coresight/coresight-cpu-debug.txt
create mode 100644 Documentation/trace/coresight/coresight-panic-kdump.txt
create mode 100644 Documentation/trace/coresight/coresight.txt
create mode 100644 drivers/hwtracing/coresight/coresight-panic-kdump.c
--
2.7.4
Good day Mike,
Please find the changes to the HOWTO.md that support integration of the openCSD
library as a system library. I didn't know in what kind of state your tree is
so I added a patch that only update the library name - use it or not as you see
fit.
Thanks,
Mathieu
Mathieu Poirier (2):
opencsd: Changing library output names
opencsd: Making openCSD part of the system libraries
HOWTO.md | 120 +++++++++++++++++++++++++++++++++++++++++++--------------------
1 file changed, 83 insertions(+), 37 deletions(-)
--
2.7.4
Hi,
This patchset adds support for user space decoding of CoreSight traces [1]
of the ARM architecture. Kernel support for configuring CoreSight tracers
and collect the hardware trace data in the auxtrace section of the
perf.data file is already integrated [2]. The user space implementation
mirrors to a large degree that of the Intel Processor Trace (PT) [3]
implementation, except that the decoder library itself is separate from the
perf tool sources, and is built and maintained as a separate open source
project [4]. Instead, this patch set includes the necessary code and build
settings to interfaces to the decoder library. This approach was chosen as
the decoder library has uses outside the perf toolset and on non-linux
platforms.
The decoder library interface code in this patch set only supports ETMv4
trace decoding, though the library itself supports a broader range. Future
patches will add support for more versions of the ARM ETM trace encoding.
The trace decoder library used with this patch set is the most recent
version with tag v0.7.3
This patch set, instead of being based on commits in my private branch, has
been applied to a new copy of the perf-opencsd-master branch of [4] and
pushed to [5] with the same perf-opencsd-master branch name.
Changes since last revision:
Given this is the second time it is sent out to the new audience on
coresight(a)lists.linaro.org, I am resetting the version number to 2 to avoid
confusion with previous mailings with a more restricted audience.
Two additional commits have been added to the patches in this patch set to
be fully compatible with the most recent version of the decoder library. The
previous patch set assumed an older version.
[1] https://lwn.net/Articles/626463
[2] https://github.com/torvalds/linux/tree/master/drivers/hwtracing/coresight
[3] https://lwn.net/Articles/648154
[4] https://github.com/Linaro/OpenCSD
[5] https://github.com/tor-jeremiassen/OpenCSD
Tor Jeremiassen (23):
perf tools: Add initial hooks for decoding coresight traces
perf tools: Add processing of coresight metadata
perf tools: Add coresight trace decoder library interface
perf tools: Add data block processing function
perf tools: Add channel context item to track packet sources
perf tools: Add etmv4i packet printing capability
perf tools: Add decoder new and free
perf tools: Add trace packet print for dump_trace option
perf tools: Add code to process the auxtrace perf event
perf tools: Add function to read data from dsos
perf tools: Add mapping from cpu to cs_etm_queue
perf tools: Add functions to allocate and free queues
perf tools: Add functions to setup and initialize queues
perf tools: Add functions to allocate and free queues
perf tools: Add function to get trace data from aux buffer
perf tools: Add function to run the trace decoder and process samples
perf tools: Add functions to process queues and run the trace decoder
perf tools: Add perf event processing
perf tools: Add processing of queues when events are flushed
perf tools: Add synth_events and supporting functions
perf tools: Add function to clear the decoder packet buffer
perf tools: Add functions for full etmv4i packet decode
MAINTAINERS: Adding entry for CoreSight trace decoding
MAINTAINERS | 3 +-
tools/perf/Makefile.config | 26 +
tools/perf/util/Build | 6 +
tools/perf/util/auxtrace.c | 2 +
tools/perf/util/cs-etm-decoder/Build | 2 +
tools/perf/util/cs-etm-decoder/cs-etm-decoder.c | 581 +++++++++++
tools/perf/util/cs-etm-decoder/cs-etm-decoder.h | 138 +++
tools/perf/util/cs-etm.c | 1180 +++++++++++++++++++++++
tools/perf/util/cs-etm.h | 50 +
9 files changed, 1987 insertions(+), 1 deletion(-)
create mode 100644 tools/perf/util/cs-etm-decoder/Build
create mode 100644 tools/perf/util/cs-etm-decoder/cs-etm-decoder.c
create mode 100644 tools/perf/util/cs-etm-decoder/cs-etm-decoder.h
create mode 100644 tools/perf/util/cs-etm.c
--
2.7.4
### Introduction ###
Embedded Trace Buffer (ETB) provides on-chip storage of trace data,
usually has buffer size from 2KB to 8KB. These data has been used for
profiling and this has been well implemented in coresight driver.
This patch set is to explore ETB RAM data for postmortem debugging.
We could consider ETB RAM data is quite useful for postmortem debugging,
especially if the hardware design with local ETB buffer (ARM DDI 0461B)
chapter 1.2.7. 'Local ETF', with this kind design every CPU has one
dedicated ETB RAM. So it's quite handy that we can use alive CPU to help
dump the hang CPU ETB RAM. Then we can quickly get to know what's the
exact execution flow before its hang.
Due ETB RAM buffer has small size, if all CPUs shared one ETB buffer
then the trace data for causing error is easily to be overwritten by
other PEs; but even so sometimes we still have chance to go through the
trace data to assist debugging panic issues.
### Implementation ###
Firstly we need provide a unified APIs for panic dump functionality, so
it can be easily extended to enable panic dump for multiple drivers. This
is finished by patch 0001, it registers panic notifier, and provide the
general APIs {coresight_dump_add|coresight_dump_del} as helper functions
so any coresight device can add into dump list or delete itself
as needed.
Generally coresight devices can add itself into panic dump when
registration, if the coresight device wants to do dump it will set its
'panic_cb' in the ops structure. So patch 0002 is to add and delete panic
dump node for devices.
Patch 0003 and 0004 are to add panic callback functions for tmc and etm4x
drivers; so tmc dirver can save specific trace data for ETB/ETF when panic
happens, and etm4x driver can save metadata for offline analysis.
### Usage ###
Below are the example for how to use panic dump functionality on 96boards
Hikey, the brief flow is: when the panic happens the ETB panic callback
function saves trace data into memory, then relies on kdump to use
recovery kernel to save DDR content as kernel core dump file; after we
transfer kernel core dump file from board to host PC, use 'crash' tool +
extension program to extract trace data and generate 'perf' format
compatible file.
- Enable tracing on Hikey; in theory there have two methods to enable
tracing:
The first method is to use sysfs interface to enable coresight tracing:
echo 1 > /sys/bus/coresight/devices/f6402000.etf/enable_sink
echo 1 > /sys/bus/coresight/devices/f659c000.etm/enable_source
echo 1 > /sys/bus/coresight/devices/f659d000.etm/enable_source
echo 1 > /sys/bus/coresight/devices/f659e000.etm/enable_source
echo 1 > /sys/bus/coresight/devices/f659f000.etm/enable_source
echo 1 > /sys/bus/coresight/devices/f65dc000.etm/enable_source
echo 1 > /sys/bus/coresight/devices/f65dd000.etm/enable_source
echo 1 > /sys/bus/coresight/devices/f65de000.etm/enable_source
echo 1 > /sys/bus/coresight/devices/f65df000.etm/enable_source
The second method is to use tool 'perf' with snapshot method, this
command is expected to enable tracing and wait for specific event happen
and capture the snapshot trace data, this method also can be smoothly
used for panic dump. This command currently is failure on Hikey due
now coresight only support '--per-thread' method with perf tool:
./perf record --snapshot -S8196 -e cs_etm/(a)f6402000.etf/ -- sleep 1000 &
- Load recovery kernel for kdump:
ARM64's kdump supports to use the same kernel image both for main
kernel and dump-capture kernel; so we can simply to load dump-capture
kernel with below command:
./kexec -p vmlinux --dtb=hi6220-hikey.dtb --append="root=/dev/mmcblk0p9
rw maxcpus=1 reset_devices earlycon=pl011,0xf7113000 nohlt
initcall_debug console=tty0 console=ttyAMA3,115200 clk_ignore_unused"
- Download kernel dump file:
After kernel panic happens, the kdump launches dump-capture kernel;
so we need save kernel's dump file on target:
cp /proc/vmcore ./vmcore
Finally we can copy 'vmcore' file onto PC.
- Use 'crash' tool + csdump.so extension to extract trace data:
After we download vmcore file from Hikey board to host PC, we can
use 'crash' tool + csdump.so to generate 'perf.data' file:
./crash vmcore vmlinux
crash> extend csdump.so
crash> csdump output_dir
We can see in the 'output_dir' there will generate out three files:
output_dir/
├── cstrace.bin -> trace raw data
├── metadata.bin -> meta data
└── perf.data -> 'perf' format compatible file
The source code of 'csdump.so' will be sent to mailing list sepeartely.
- User 'perf' tool for offline analysis:
On Hikey board:
./perf script -v -F cpu,event,ip -i perf_2.data -k vmlinux
[001] instructions: ffff000008559ad0
[001] instructions: ffff000008559230
[001] instructions: ffff00000855924c
[001] instructions: ffff000008559ae0
[001] instructions: ffff000008559ad0
[001] instructions: ffff000008559230
[001] instructions: ffff00000855924c
[001] instructions: ffff000008559ae0
[001] instructions: ffff000008559ad0
Changes from v1:
* Add support to dump ETMv4 meta data.
* Wrote 'crash' extension csdump.so so rely on it to generate 'perf'
format compatible file.
* Refactored panic dump driver to support pre & post panic dump.
Changes from RFC:
* Follow Mathieu's suggestion, use general framework to support dump
functionality.
* Changed to use perf to analyse trace data.
Leo Yan (4):
coresight: Support panic dump functionality
coresight: Add and delete dump node for registration/unregistration
coresight: tmc: Hook panic dump callback for ETB/ETF
coresight: etm4x: Hook panic dump callback for etmv4
drivers/hwtracing/coresight/Kconfig | 9 +
drivers/hwtracing/coresight/Makefile | 1 +
drivers/hwtracing/coresight/coresight-etm4x.c | 22 +++
drivers/hwtracing/coresight/coresight-etm4x.h | 15 ++
drivers/hwtracing/coresight/coresight-panic-dump.c | 211 +++++++++++++++++++++
drivers/hwtracing/coresight/coresight-priv.h | 17 ++
drivers/hwtracing/coresight/coresight-tmc-etf.c | 29 +++
drivers/hwtracing/coresight/coresight.c | 7 +
include/linux/coresight.h | 7 +
9 files changed, 318 insertions(+)
create mode 100644 drivers/hwtracing/coresight/coresight-panic-dump.c
--
2.7.4