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

perf test: Add 'datasym' test workload

The datasym workload is to check if perf mem command gets the data
addresses precisely. This is needed for data symbol test.

$ perf test -w datasym

I had to keep the buf1 in the data section, otherwise it could end
up in the BSS and was mmaped as a separate //anon region, then it
was not symbolized at all. It needs to be fixed separately.

Committer notes:

Add a -U _FORTIFY_SOURCE to the datasym 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-12-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Namhyung Kim and committed by
Arnaldo Carvalho de Melo
3dfc01fe 7bc1dd96

+28
+1
tools/perf/tests/builtin-test.c
··· 124 124 &workload__leafloop, 125 125 &workload__sqrtloop, 126 126 &workload__brstack, 127 + &workload__datasym, 127 128 }; 128 129 129 130 static int num_subtests(const struct test_suite *t)
+1
tools/perf/tests/tests.h
··· 205 205 DECLARE_WORKLOAD(leafloop); 206 206 DECLARE_WORKLOAD(sqrtloop); 207 207 DECLARE_WORKLOAD(brstack); 208 + DECLARE_WORKLOAD(datasym); 208 209 209 210 #endif /* TESTS_H */
+2
tools/perf/tests/workloads/Build
··· 5 5 perf-y += leafloop.o 6 6 perf-y += sqrtloop.o 7 7 perf-y += brstack.o 8 + perf-y += datasym.o 8 9 9 10 CFLAGS_sqrtloop.o = -g -O0 -fno-inline -U_FORTIFY_SOURCE 10 11 CFLAGS_leafloop.o = -g -O0 -fno-inline -fno-omit-frame-pointer -U_FORTIFY_SOURCE 11 12 CFLAGS_brstack.o = -g -O0 -fno-inline -U_FORTIFY_SOURCE 13 + CFLAGS_datasym.o = -g -O0 -fno-inline -U_FORTIFY_SOURCE
+24
tools/perf/tests/workloads/datasym.c
··· 1 + #include <linux/compiler.h> 2 + #include "../tests.h" 3 + 4 + typedef struct _buf { 5 + char data1; 6 + char reserved[55]; 7 + char data2; 8 + } buf __attribute__((aligned(64))); 9 + 10 + static buf buf1 = { 11 + /* to have this in the data section */ 12 + .reserved[0] = 1, 13 + }; 14 + 15 + static int datasym(int argc __maybe_unused, const char **argv __maybe_unused) 16 + { 17 + for (;;) { 18 + buf1.data1++; 19 + buf1.data2 += buf1.data1; 20 + } 21 + return 0; 22 + } 23 + 24 + DEFINE_WORKLOAD(datasym);