Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf test: Add 'brstack' test workload

The brstack is to run different kinds of branches repeatedly. This is
necessary for brstack test case to verify if it has correct branch info.

$ perf test -w brstack

I renamed the internal functions to have brstack_ prefix as it's too
generic name.

Add a -U_FORTIFY_SOURCE to the brstack CFLAGS, as the main perf flags
set it and it requires building with optimization, and this new test has
a -O0.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Athira Jajeev <atrajeev@linux.vnet.ibm.com>
Cc: German Gomez <german.gomez@arm.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: James Clark <james.clark@arm.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Zhengjun Xing <zhengjun.xing@linux.intel.com>
Link: https://lore.kernel.org/r/20221116233854.1596378-10-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Namhyung Kim and committed by
Arnaldo Carvalho de Melo
a104f0ea e011979e

+44
+1
tools/perf/tests/builtin-test.c
··· 123 123 &workload__thloop, 124 124 &workload__leafloop, 125 125 &workload__sqrtloop, 126 + &workload__brstack, 126 127 }; 127 128 128 129 static int num_subtests(const struct test_suite *t)
+1
tools/perf/tests/tests.h
··· 204 204 DECLARE_WORKLOAD(thloop); 205 205 DECLARE_WORKLOAD(leafloop); 206 206 DECLARE_WORKLOAD(sqrtloop); 207 + DECLARE_WORKLOAD(brstack); 207 208 208 209 #endif /* TESTS_H */
+2
tools/perf/tests/workloads/Build
··· 4 4 perf-y += thloop.o 5 5 perf-y += leafloop.o 6 6 perf-y += sqrtloop.o 7 + perf-y += brstack.o 7 8 8 9 CFLAGS_sqrtloop.o = -g -O0 -fno-inline -U_FORTIFY_SOURCE 9 10 CFLAGS_leafloop.o = -g -O0 -fno-inline -fno-omit-frame-pointer -U_FORTIFY_SOURCE 11 + CFLAGS_brstack.o = -g -O0 -fno-inline -U_FORTIFY_SOURCE
+40
tools/perf/tests/workloads/brstack.c
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + #include <stdlib.h> 3 + #include "../tests.h" 4 + 5 + #define BENCH_RUNS 999999 6 + 7 + static volatile int cnt; 8 + 9 + static void brstack_bar(void) { 10 + } /* return */ 11 + 12 + static void brstack_foo(void) { 13 + brstack_bar(); /* call */ 14 + } /* return */ 15 + 16 + static void brstack_bench(void) { 17 + void (*brstack_foo_ind)(void) = brstack_foo; 18 + 19 + if ((cnt++) % 3) /* branch (cond) */ 20 + brstack_foo(); /* call */ 21 + brstack_bar(); /* call */ 22 + brstack_foo_ind(); /* call (ind) */ 23 + } 24 + 25 + static int brstack(int argc, const char **argv) 26 + { 27 + int num_loops = BENCH_RUNS; 28 + 29 + if (argc > 0) 30 + num_loops = atoi(argv[0]); 31 + 32 + while (1) { 33 + if ((cnt++) > num_loops) 34 + break; 35 + brstack_bench();/* call */ 36 + } /* branch (uncond) */ 37 + return 0; 38 + } 39 + 40 + DEFINE_WORKLOAD(brstack);