mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-07 19:30:30 +09:00
perf test: Add -w/--workload option
[ Upstream commit f215054d74 ]
The -w/--workload option is to run a simple workload used by testing.
This adds a basic framework to run the workloads and 'noploop' workload
as an example.
$ perf test -w noploop
The noploop does a loop doing nothing (NOP) for a second by default.
It can have an optional argument to specify the time in seconds.
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-2-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Stable-dep-of: 256ef072b384 ("perf tests: Make "test data symbol" more robust on Neoverse N1")
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
338656b35f
commit
e46035c226
@@ -103,3 +103,5 @@ endif
|
|||||||
CFLAGS_attr.o += -DBINDIR="BUILD_STR($(bindir_SQ))" -DPYTHON="BUILD_STR($(PYTHON_WORD))"
|
CFLAGS_attr.o += -DBINDIR="BUILD_STR($(bindir_SQ))" -DPYTHON="BUILD_STR($(PYTHON_WORD))"
|
||||||
CFLAGS_python-use.o += -DPYTHONPATH="BUILD_STR($(OUTPUT)python)" -DPYTHON="BUILD_STR($(PYTHON_WORD))"
|
CFLAGS_python-use.o += -DPYTHONPATH="BUILD_STR($(OUTPUT)python)" -DPYTHON="BUILD_STR($(PYTHON_WORD))"
|
||||||
CFLAGS_dwarf-unwind.o += -fno-optimize-sibling-calls
|
CFLAGS_dwarf-unwind.o += -fno-optimize-sibling-calls
|
||||||
|
|
||||||
|
perf-y += workloads/
|
||||||
|
|||||||
@@ -118,6 +118,10 @@ static struct test_suite **tests[] = {
|
|||||||
arch_tests,
|
arch_tests,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static struct test_workload *workloads[] = {
|
||||||
|
&workload__noploop,
|
||||||
|
};
|
||||||
|
|
||||||
static int num_subtests(const struct test_suite *t)
|
static int num_subtests(const struct test_suite *t)
|
||||||
{
|
{
|
||||||
int num;
|
int num;
|
||||||
@@ -475,6 +479,21 @@ static int perf_test__list(int argc, const char **argv)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int run_workload(const char *work, int argc, const char **argv)
|
||||||
|
{
|
||||||
|
unsigned int i = 0;
|
||||||
|
struct test_workload *twl;
|
||||||
|
|
||||||
|
for (i = 0; i < ARRAY_SIZE(workloads); i++) {
|
||||||
|
twl = workloads[i];
|
||||||
|
if (!strcmp(twl->name, work))
|
||||||
|
return twl->func(argc, argv);
|
||||||
|
}
|
||||||
|
|
||||||
|
pr_info("No workload found: %s\n", work);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
int cmd_test(int argc, const char **argv)
|
int cmd_test(int argc, const char **argv)
|
||||||
{
|
{
|
||||||
const char *test_usage[] = {
|
const char *test_usage[] = {
|
||||||
@@ -482,12 +501,14 @@ int cmd_test(int argc, const char **argv)
|
|||||||
NULL,
|
NULL,
|
||||||
};
|
};
|
||||||
const char *skip = NULL;
|
const char *skip = NULL;
|
||||||
|
const char *workload = NULL;
|
||||||
const struct option test_options[] = {
|
const struct option test_options[] = {
|
||||||
OPT_STRING('s', "skip", &skip, "tests", "tests to skip"),
|
OPT_STRING('s', "skip", &skip, "tests", "tests to skip"),
|
||||||
OPT_INCR('v', "verbose", &verbose,
|
OPT_INCR('v', "verbose", &verbose,
|
||||||
"be more verbose (show symbol address, etc)"),
|
"be more verbose (show symbol address, etc)"),
|
||||||
OPT_BOOLEAN('F', "dont-fork", &dont_fork,
|
OPT_BOOLEAN('F', "dont-fork", &dont_fork,
|
||||||
"Do not fork for testcase"),
|
"Do not fork for testcase"),
|
||||||
|
OPT_STRING('w', "workload", &workload, "work", "workload to run for testing"),
|
||||||
OPT_END()
|
OPT_END()
|
||||||
};
|
};
|
||||||
const char * const test_subcommands[] = { "list", NULL };
|
const char * const test_subcommands[] = { "list", NULL };
|
||||||
@@ -504,6 +525,9 @@ int cmd_test(int argc, const char **argv)
|
|||||||
if (argc >= 1 && !strcmp(argv[0], "list"))
|
if (argc >= 1 && !strcmp(argv[0], "list"))
|
||||||
return perf_test__list(argc - 1, argv + 1);
|
return perf_test__list(argc - 1, argv + 1);
|
||||||
|
|
||||||
|
if (workload)
|
||||||
|
return run_workload(workload, argc, argv);
|
||||||
|
|
||||||
symbol_conf.priv_size = sizeof(int);
|
symbol_conf.priv_size = sizeof(int);
|
||||||
symbol_conf.sort_by_name = true;
|
symbol_conf.sort_by_name = true;
|
||||||
symbol_conf.try_vmlinux_path = true;
|
symbol_conf.try_vmlinux_path = true;
|
||||||
|
|||||||
@@ -180,4 +180,26 @@ int test__arch_unwind_sample(struct perf_sample *sample,
|
|||||||
DECLARE_SUITE(vectors_page);
|
DECLARE_SUITE(vectors_page);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Define test workloads to be used in test suites.
|
||||||
|
*/
|
||||||
|
typedef int (*workload_fnptr)(int argc, const char **argv);
|
||||||
|
|
||||||
|
struct test_workload {
|
||||||
|
const char *name;
|
||||||
|
workload_fnptr func;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define DECLARE_WORKLOAD(work) \
|
||||||
|
extern struct test_workload workload__##work
|
||||||
|
|
||||||
|
#define DEFINE_WORKLOAD(work) \
|
||||||
|
struct test_workload workload__##work = { \
|
||||||
|
.name = #work, \
|
||||||
|
.func = work, \
|
||||||
|
}
|
||||||
|
|
||||||
|
/* The list of test workloads */
|
||||||
|
DECLARE_WORKLOAD(noploop);
|
||||||
|
|
||||||
#endif /* TESTS_H */
|
#endif /* TESTS_H */
|
||||||
|
|||||||
3
tools/perf/tests/workloads/Build
Normal file
3
tools/perf/tests/workloads/Build
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# SPDX-License-Identifier: GPL-2.0
|
||||||
|
|
||||||
|
perf-y += noploop.o
|
||||||
32
tools/perf/tests/workloads/noploop.c
Normal file
32
tools/perf/tests/workloads/noploop.c
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
/* SPDX-License-Identifier: GPL-2.0 */
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <linux/compiler.h>
|
||||||
|
#include "../tests.h"
|
||||||
|
|
||||||
|
static volatile sig_atomic_t done;
|
||||||
|
|
||||||
|
static void sighandler(int sig __maybe_unused)
|
||||||
|
{
|
||||||
|
done = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int noploop(int argc, const char **argv)
|
||||||
|
{
|
||||||
|
int sec = 1;
|
||||||
|
|
||||||
|
if (argc > 0)
|
||||||
|
sec = atoi(argv[0]);
|
||||||
|
|
||||||
|
signal(SIGINT, sighandler);
|
||||||
|
signal(SIGALRM, sighandler);
|
||||||
|
alarm(sec);
|
||||||
|
|
||||||
|
while (!done)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
DEFINE_WORKLOAD(noploop);
|
||||||
Reference in New Issue
Block a user