linux-stable/tools/perf
James Clark 4fe12d6bf7 perf cs-etm: Don't flush when packet_queue fills up
[ Upstream commit 5afd032961 ]

cs_etm__flush(), like cs_etm__sample() is an operation that generates a
sample and then swaps the current with the previous packet. Calling
flush after processing the queues results in two swaps which corrupts
the next sample. Therefore it wasn't appropriate to call flush here so
remove it.

Flushing is still done on a discontinuity to explicitly clear the last
branch buffer, but when the packet_queue fills up before reaching a
timestamp, that's not a discontinuity and the call to
cs_etm__process_traceid_queue() already generated samples and drained
the buffers correctly.

This is visible by looking for a branch that has the same target as the
previous branch and the following source is before the address of the
last target, which is impossible as execution would have had to have
gone backwards:

  ffff800080849d40 _find_next_and_bit+0x78 => ffff80008011cadc update_sg_lb_stats+0x94
   (packet_queue fills here before a timestamp, resulting in a flush and
    branch target ffff80008011cadc is duplicated.)
  ffff80008011cb1c update_sg_lb_stats+0xd4 => ffff80008011cadc update_sg_lb_stats+0x94
  ffff8000801117c4 cpu_util+0x24 => ffff8000801117d4 cpu_util+0x34

After removing the flush the correct branch target is used for the
second sample, and ffff8000801117c4 is no longer before the previous
address:

  ffff800080849d40 _find_next_and_bit+0x78 => ffff80008011cadc update_sg_lb_stats+0x94
  ffff80008011cb1c update_sg_lb_stats+0xd4 => ffff8000801117a0 cpu_util+0x0
  ffff8000801117c4 cpu_util+0x24 => ffff8000801117d4 cpu_util+0x34

Make sure that a final branch stack is output at the end of the trace
by calling cs_etm__end_block(). This is already done for both the
timeless decode paths.

Fixes: 21fe8dc119 ("perf cs-etm: Add support for CPU-wide trace scenarios")
Reported-by: Ganapatrao Kulkarni <gankulkarni@os.amperecomputing.com>
Closes: https://lore.kernel.org/all/20240719092619.274730-1-gankulkarni@os.amperecomputing.com/
Reviewed-by: Leo Yan <leo.yan@arm.com>
Signed-off-by: James Clark <james.clark@linaro.org>
Tested-by: Ganapatrao Kulkarni <gankulkarni@os.amperecomputing.com>
Cc: Ben Gainey <ben.gainey@arm.com>
Cc: Suzuki K Poulose <suzuki.poulose@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: Mike Leach <mike.leach@linaro.org>
Cc: Ruidong Tian <tianruidong@linux.alibaba.com>
Cc: Benjamin Gray <bgray@linux.ibm.com>
Cc: linux-arm-kernel@lists.infradead.org
Cc: coresight@lists.linaro.org
Cc: John Garry <john.g.garry@oracle.com>
Cc: scclevenger@os.amperecomputing.com
Link: https://lore.kernel.org/r/20240916135743.1490403-2-james.clark@linaro.org
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-12-14 19:53:43 +01:00
..
arch perf intel-pt: Fix exclude_guest setting 2024-08-03 08:49:15 +02:00
bench perf bench internals inject-build-id: Fix trap divide when collecting just one DSO 2024-06-12 11:03:40 +02:00
dlfilters perf dlfilter dlfilter-show-cycles: Fix types for print format 2022-09-08 12:17:45 -03:00
Documentation perf: script: add raw|disasm arguments to --insn-trace option 2024-06-27 13:46:23 +02:00
examples/bpf perf tools: Fix various typos in comments 2021-03-23 17:13:43 -03:00
include perf dlfilter: Add machine_pid and vcpu 2022-07-20 11:08:13 -03:00
jvmti perf tools: Fix various typos in comments 2021-03-23 17:13:43 -03:00
pmu-events perf vendor events: Drop STORES_PER_INST metric event for power10 platform 2023-09-19 12:28:00 +02:00
python perf python: Convert tracepoint.py example to python3 2022-04-01 16:19:35 -03:00
scripts perf scripts intel-pt-events.py: Fix IPC output for Python 2 2023-05-17 11:53:39 +02:00
tests perf test: Make test_arm_callgraph_fp.sh more robust 2024-08-03 08:49:14 +02:00
trace tools headers uapi: Sync linux/stat.h with the kernel sources 2022-10-25 17:40:48 -03:00
ui perf ui browser: Avoid SEGV on title 2024-06-12 11:03:41 +02:00
util perf cs-etm: Don't flush when packet_queue fills up 2024-12-14 19:53:43 +01:00
.gitignore perf tools: Add the include/perf/ directory to .gitignore 2022-11-08 18:54:41 -03:00
Build perf kwork: New tool to trace time properties of kernel work (such as softirq, and workqueue) 2022-07-26 16:01:24 -03:00
builtin-annotate.c perf annotate: Get rid of duplicate --group option item 2024-06-12 11:03:34 +02:00
builtin-bench.c perf bench: Add missing setlocale() call to allow usage of %'d style formatting 2023-07-19 16:21:36 +02:00
builtin-buildid-cache.c perf record: Disable debuginfod by default 2022-01-15 17:41:25 -03:00
builtin-buildid-list.c perf buildid-list: Add a "-m" option to show kernel and modules build-ids 2022-07-18 16:35:34 -03:00
builtin-c2c.c perf mem/c2c: Set PERF_SAMPLE_WEIGHT for LOAD_STORE events 2022-10-06 16:29:32 -03:00
builtin-config.c
builtin-daemon.c perf daemon: Fix file leak in daemon_session__control 2024-06-12 11:03:42 +02:00
builtin-data.c perf data: Don't mention --to-ctf if it's not supported 2022-02-22 21:23:08 -03:00
builtin-diff.c perf tools: Make quiet mode consistent between tools 2022-12-31 13:33:07 +01:00
builtin-evlist.c perf tools: Remove repipe argument from perf_session__new() 2021-08-02 10:06:51 -03:00
builtin-ftrace.c perf ftrace latency: Remove unnecessary "--" from --use-nsec option 2023-06-09 10:34:02 +02:00
builtin-help.c
builtin-inject.c perf inject: Fix leader sampling inserting additional samples 2024-10-17 15:21:01 +02:00
builtin-kallsyms.c
builtin-kmem.c libsubcmd: Don't free the usage string 2024-10-17 15:22:11 +02:00
builtin-kvm.c libsubcmd: Don't free the usage string 2024-10-17 15:22:11 +02:00
builtin-kwork.c libsubcmd: Don't free the usage string 2024-10-17 15:22:11 +02:00
builtin-list.c perf list: Fix metricgroups title message 2022-10-14 12:21:42 -03:00
builtin-lock.c perf lock: Don't pass an ERR_PTR() directly to perf_session__delete() 2024-10-17 15:22:28 +02:00
builtin-mem.c libsubcmd: Don't free the usage string 2024-10-17 15:22:11 +02:00
builtin-probe.c perf probe: Check -v and -q options in the right place 2022-12-31 13:33:08 +01:00
builtin-record.c perf record: Delete session after stopping sideband thread 2024-06-12 11:03:33 +02:00
builtin-report.c perf report: Avoid SEGV in report__setup_sample_type() 2024-06-12 11:03:41 +02:00
builtin-sched.c libsubcmd: Don't free the usage string 2024-10-17 15:22:11 +02:00
builtin-script.c perf script: Show also errors for --insn-trace option 2024-06-27 13:46:23 +02:00
builtin-stat.c perf stat: Fix aggr mode initialization 2023-11-20 11:52:09 +01:00
builtin-timechart.c perf timechart: Add p_state_end helper 2022-10-04 08:55:21 -03:00
builtin-top.c perf top: Don't pass an ERR_PTR() directly to perf_session__delete() 2023-09-19 12:28:00 +02:00
builtin-trace.c perf trace: Really free the evsel->priv area 2023-09-19 12:27:59 +02:00
builtin-version.c perf version: Add HAVE_DEBUGINFOD_SUPPORT to built-in features 2022-04-20 13:32:09 -03:00
builtin.h perf kwork: New tool to trace time properties of kernel work (such as softirq, and workqueue) 2022-07-26 16:01:24 -03:00
check-headers.sh tools headers: Update the copy of x86's memcpy_64.S used in 'perf bench' 2022-10-25 17:40:48 -03:00
command-list.txt perf kwork: New tool to trace time properties of kernel work (such as softirq, and workqueue) 2022-07-26 16:01:24 -03:00
CREDITS
design.txt perf design.txt: Synchronize the definition of enum perf_hw_id with code 2021-11-13 18:11:50 -03:00
Makefile perf tools: Add a build-test variant to use in builds from a tarball 2021-04-20 08:43:58 -03:00
Makefile.config perf build: Fix library not found error when using CSLIBS 2023-07-27 08:50:39 +02:00
Makefile.perf perf test: Add arm64 asm pureloop test shell script 2022-10-06 14:50:49 -03:00
MANIFEST perf MANIFEST: Add bpftool files to allow building with BUILD_BPF_SKEL=1 2021-11-07 15:39:28 -03:00
perf-archive.sh perf archive: Fix filtering of empty build-ids 2021-03-06 16:54:31 -03:00
perf-completion.sh perf tools: Fix auto-complete on aarch64 2023-03-10 09:33:27 +01:00
perf-iostat.sh perf stat: Enable iostat mode for x86 platforms 2021-04-20 08:40:20 -03:00
perf-read-vdso.c
perf-sys.h
perf.c perf tools: Add same_cmd_with_prefix() helper 2022-10-04 08:55:21 -03:00
perf.h