diff options
| author | Namhyung Kim <namhyung@kernel.org> | 2022-11-16 15:38:45 -0800 |
|---|---|---|
| committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2022-11-20 11:32:23 -0300 |
| commit | 69b352927885b17f03d3ee4ee38f580699af107a (patch) | |
| tree | cc7f02a60c82b7879609c1fc62fec343f86fe34a /tools/perf/tests/workloads/thloop.c | |
| parent | 24e733b29f13284aac30c4d1fb9f19201951d770 (diff) | |
| download | linux-69b352927885b17f03d3ee4ee38f580699af107a.tar.gz linux-69b352927885b17f03d3ee4ee38f580699af107a.tar.bz2 linux-69b352927885b17f03d3ee4ee38f580699af107a.zip | |
perf test: Add 'thloop' test workload
The thloop is similar to noploop but runs in two threads. This is
needed to verify perf record --per-thread to handle multi-threaded
programs properly.
$ perf test -w thloop
It also takes an optional argument to specify runtime in seconds
(default: 1).
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-4-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/tests/workloads/thloop.c')
| -rw-r--r-- | tools/perf/tests/workloads/thloop.c | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/tools/perf/tests/workloads/thloop.c b/tools/perf/tests/workloads/thloop.c new file mode 100644 index 000000000000..29193b75717e --- /dev/null +++ b/tools/perf/tests/workloads/thloop.c @@ -0,0 +1,53 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#include <pthread.h> +#include <stdlib.h> +#include <signal.h> +#include <unistd.h> +#include <linux/compiler.h> +#include "../tests.h" + +static volatile sig_atomic_t done; +static volatile unsigned count; + +/* We want to check this symbol in perf report */ +noinline void test_loop(void); + +static void sighandler(int sig __maybe_unused) +{ + done = 1; +} + +noinline void test_loop(void) +{ + while (!done) + count++; +} + +static void *thfunc(void *arg) +{ + void (*loop_fn)(void) = arg; + + loop_fn(); + return NULL; +} + +static int thloop(int argc, const char **argv) +{ + int sec = 1; + pthread_t th; + + if (argc > 0) + sec = atoi(argv[0]); + + signal(SIGINT, sighandler); + signal(SIGALRM, sighandler); + alarm(sec); + + pthread_create(&th, NULL, thfunc, test_loop); + test_loop(); + pthread_join(th, NULL); + + return 0; +} + +DEFINE_WORKLOAD(thloop); |
