linux-yocto/tools/perf/tests
Leo Yan 5ec729bc5b perf tests switch-tracking: Fix timestamp comparison
[ Upstream commit 628e124404 ]

The test might fail on the Arm64 platform with the error:

  # perf test -vvv "Track with sched_switch"
  Missing sched_switch events
  #

The issue is caused by incorrect handling of timestamp comparisons. The
comparison result, a signed 64-bit value, was being directly cast to an
int, leading to incorrect sorting for sched events.

The case does not fail everytime, usually I can trigger the failure
after run 20 ~ 30 times:

  # while true; do perf test "Track with sched_switch"; done
  106: Track with sched_switch                                         : Ok
  106: Track with sched_switch                                         : Ok
  106: Track with sched_switch                                         : Ok
  106: Track with sched_switch                                         : Ok
  106: Track with sched_switch                                         : Ok
  106: Track with sched_switch                                         : Ok
  106: Track with sched_switch                                         : Ok
  106: Track with sched_switch                                         : Ok
  106: Track with sched_switch                                         : Ok
  106: Track with sched_switch                                         : Ok
  106: Track with sched_switch                                         : Ok
  106: Track with sched_switch                                         : Ok
  106: Track with sched_switch                                         : Ok
  106: Track with sched_switch                                         : Ok
  106: Track with sched_switch                                         : FAILED!
  106: Track with sched_switch                                         : Ok
  106: Track with sched_switch                                         : Ok
  106: Track with sched_switch                                         : Ok
  106: Track with sched_switch                                         : Ok
  106: Track with sched_switch                                         : Ok
  106: Track with sched_switch                                         : Ok
  106: Track with sched_switch                                         : Ok
  106: Track with sched_switch                                         : Ok
  106: Track with sched_switch                                         : FAILED!
  106: Track with sched_switch                                         : Ok
  106: Track with sched_switch                                         : Ok

I used cross compiler to build Perf tool on my host machine and tested on
Debian / Juno board.  Generally, I think this issue is not very specific
to GCC versions.  As both internal CI and my local env can reproduce the
issue.

My Host Build compiler:

  # aarch64-linux-gnu-gcc --version
  aarch64-linux-gnu-gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0

Juno Board:

  # lsb_release -a
  No LSB modules are available.
  Distributor ID: Debian
  Description:    Debian GNU/Linux 12 (bookworm)
  Release:        12
  Codename:       bookworm

Fix this by explicitly returning 0, 1, or -1 based on whether the result
is zero, positive, or negative.

Fixes: d44bc55829 ("perf tests: Add a test for tracking with sched_switch")
Reviewed-by: Ian Rogers <irogers@google.com>
Signed-off-by: Leo Yan <leo.yan@arm.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: James Clark <james.clark@linaro.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: https://lore.kernel.org/r/20250331172759.115604-1-leo.yan@arm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2025-06-19 15:28:28 +02:00
..
attr perf test attr: Add back missing topdown events 2024-12-09 10:32:24 +01:00
config-fragments perf tools: Add a place to put kernel config fragments for test runs 2023-07-28 19:01:16 -03:00
shell perf tools: annotate asm_pure_loop.S 2025-04-10 14:37:35 +02:00
workloads perf test: Make test_arm_callgraph_fp.sh more robust 2024-08-03 08:53:52 +02:00
api-io.c perf tests api-io: Use zfree() to reduce chances of use after free 2023-04-12 10:14:58 -03:00
attr.c perf pmus: Remove perf_pmus__has_hybrid 2023-05-27 09:42:38 -03:00
attr.py perf test attr: Fix python SafeConfigParser() deprecation warning 2023-05-19 10:36:35 -03:00
backward-ring-buffer.c
bitmap.c
bp_account.c
bp_signal_overflow.c
bp_signal.c
Build perf util: Add a function for replacing characters in a string 2024-06-12 11:13:02 +02:00
builtin-test-list.c
builtin-test-list.h
builtin-test.c perf util: Add a function for replacing characters in a string 2024-06-12 11:13:02 +02:00
code-reading.c perf tests: Apply attributes to all events in object code reading test 2024-06-12 11:12:18 +02:00
cpumap.c perf cpumap: Add equal function 2023-05-27 09:36:44 -03:00
demangle-java-test.c
demangle-ocaml-test.c
dlfilter-test.c perf dlfilter: Add al_cleanup() 2023-08-15 16:41:49 -03:00
dso-data.c
dwarf-unwind.c perf machine: Make delete_threads part of machine__exit 2023-06-12 15:57:53 -03:00
event_groups.c perf pmu: Separate pmu and pmus 2023-05-27 09:41:39 -03:00
event_update.c
event-times.c
evsel-roundtrip-name.c perf test: Roundtrip name, don't assume 1 event per name 2023-05-15 09:12:13 -03:00
evsel-tp-sched.c
expand-cgroup.c perf evsel: Introduce evsel__name_is() method to check if the evsel name is equal to a given string 2023-04-24 14:28:11 -03:00
expr.c perf pmu: Move pmu__find_core_pmu() to pmus.c 2024-06-12 11:12:31 +02:00
fdarray.c
genelf.c
hists_common.c perf thread: Add accessor functions for thread 2023-06-12 15:57:53 -03:00
hists_common.h
hists_cumulate.c perf addr_location: Add init/exit/copy functions 2023-06-12 15:57:53 -03:00
hists_filter.c perf addr_location: Add init/exit/copy functions 2023-06-12 15:57:53 -03:00
hists_link.c perf thread: Add reference count checking 2023-06-12 15:57:53 -03:00
hists_output.c perf addr_location: Add init/exit/copy functions 2023-06-12 15:57:53 -03:00
is_printable_array.c
keep-tracking.c
kmod-path.c
make perf bpf: Remove support for embedding clang for compiling BPF events (-e foo.c) 2023-08-15 16:41:48 -03:00
maps.c perf maps: Make delete static, always use put 2023-06-12 15:57:53 -03:00
mem.c
mem2node.c
mmap-basic.c perf tests mmap-basic: Adapt for riscv 2023-08-16 08:52:47 -03:00
mmap-thread-lookup.c perf machine: Make delete_threads part of machine__exit 2023-06-12 15:57:53 -03:00
openat-syscall-all-cpus.c
openat-syscall-tp-fields.c
openat-syscall.c
parse-events.c perf parse-events: Fixes relating to no_value terms 2023-09-02 08:12:15 -03:00
parse-metric.c perf pmus: Remove perf_pmus__has_hybrid 2023-05-27 09:42:38 -03:00
parse-no-sample-id-all.c
pe-file-parsing.c perf test: Fix a compile error on pe-file-parsing.c 2023-06-27 12:14:38 -07:00
pe-file.c
pe-file.exe
pe-file.exe.debug
perf-hooks.c
perf-record.c
perf-targz-src-pkg perf thread: Add accessor functions for thread 2023-06-12 15:57:53 -03:00
perf-time-to-tsc.c
pfm.c perf evlist: Remove nr_groups 2023-03-13 17:42:27 -03:00
pmu-events.c perf jevents: Use "default_core" for events with no Unit 2023-08-29 14:16:15 -03:00
pmu.c perf parse-events: Make term's config const 2023-08-25 10:22:34 -03:00
python-use.c perf test python: Put perf python at start of sys.path 2023-05-27 09:35:14 -03:00
sample-parsing.c perf script: Show branch speculation info 2023-02-02 17:18:31 -03:00
sdt.c
sigtrap.c
stat.c perf stat: Avoid uninitialized use of perf_stat_config 2023-07-24 18:23:18 -03:00
sw-clock.c
switch-tracking.c perf tests switch-tracking: Fix timestamp comparison 2025-06-19 15:28:28 +02:00
symbols.c perf machine: Make delete_threads part of machine__exit 2023-06-12 15:57:53 -03:00
task-exit.c perf test task_exit: No need for a cycles event to check if we get an PERF_RECORD_EXIT 2023-07-17 10:27:44 -03:00
tests.h perf util: Add a function for replacing characters in a string 2024-06-12 11:13:02 +02:00
thread-map.c
thread-maps-share.c perf thread: Add accessor functions for thread 2023-06-12 15:57:53 -03:00
time-utils-test.c
topology.c perf pmus: Remove perf_pmus__has_hybrid 2023-05-27 09:42:38 -03:00
unit_number__scnprintf.c
util.c perf util: Add a function for replacing characters in a string 2024-06-12 11:13:02 +02:00
vmlinux-kallsyms.c perf map: Add set_ methods for map->{start,end,pgoff,pgoff,reloc,erange_warned,dso,map_ip,unmap_ip,priv} 2023-04-19 12:54:41 -03:00
wp.c