linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 08/12] perf test: Replace arm spe fork test workload with sqrtloop
  2022-11-09 17:46 [PATCHSET 00/12] perf test: Add test workloads (v1) Namhyung Kim
@ 2022-11-09 17:46 ` Namhyung Kim
  2022-11-10 11:45   ` Leo Yan
  0 siblings, 1 reply; 26+ messages in thread
From: Namhyung Kim @ 2022-11-09 17:46 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Jiri Olsa
  Cc: Ingo Molnar, Peter Zijlstra, LKML, Ian Rogers, Adrian Hunter,
	linux-perf-users, Leo Yan, German Gomez, Zhengjun Xing,
	James Clark

So that it can get rid of requirement of a compiler.  I've also removed
killall as it'll kill perf process now and run the test workload for 10
sec instead.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/tests/shell/test_arm_spe_fork.sh | 44 +--------------------
 1 file changed, 1 insertion(+), 43 deletions(-)

diff --git a/tools/perf/tests/shell/test_arm_spe_fork.sh b/tools/perf/tests/shell/test_arm_spe_fork.sh
index c920d3583d30..da810e1b2b9e 100755
--- a/tools/perf/tests/shell/test_arm_spe_fork.sh
+++ b/tools/perf/tests/shell/test_arm_spe_fork.sh
@@ -11,14 +11,7 @@ skip_if_no_arm_spe_event() {
 
 skip_if_no_arm_spe_event || exit 2
 
-# skip if there's no compiler
-if ! [ -x "$(command -v cc)" ]; then
-	echo "failed: no compiler, install gcc"
-	exit 2
-fi
-
-TEST_PROGRAM_SOURCE=$(mktemp /tmp/__perf_test.program.XXXXX.c)
-TEST_PROGRAM=$(mktemp /tmp/__perf_test.program.XXXXX)
+TEST_PROGRAM="perf test -w sqrtloop 10"
 PERF_DATA=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
 PERF_RECORD_LOG=$(mktemp /tmp/__perf_test.log.XXXXX)
 
@@ -27,43 +20,10 @@ cleanup_files()
 	echo "Cleaning up files..."
 	rm -f ${PERF_RECORD_LOG}
 	rm -f ${PERF_DATA}
-	rm -f ${TEST_PROGRAM_SOURCE}
-	rm -f ${TEST_PROGRAM}
 }
 
 trap cleanup_files exit term int
 
-# compile test program
-cat << EOF > $TEST_PROGRAM_SOURCE
-#include <math.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/wait.h>
-
-int workload() {
-  while (1)
-    sqrt(rand());
-  return 0;
-}
-
-int main() {
-  switch (fork()) {
-    case 0:
-      return workload();
-    case -1:
-      return 1;
-    default:
-      wait(NULL);
-  }
-  return 0;
-}
-EOF
-
-echo "Compiling test program..."
-CFLAGS="-lm"
-cc $TEST_PROGRAM_SOURCE $CFLAGS -o $TEST_PROGRAM || exit 1
-
 echo "Recording workload..."
 perf record -o ${PERF_DATA} -e arm_spe/period=65536/ -vvv -- $TEST_PROGRAM > ${PERF_RECORD_LOG} 2>&1 &
 PERFPID=$!
@@ -78,8 +38,6 @@ echo Log lines after 1 second = $log1
 
 kill $PERFPID
 wait $PERFPID
-# test program may leave an orphan process running the workload
-killall $(basename $TEST_PROGRAM)
 
 if [ "$log0" = "$log1" ];
 then
-- 
2.38.1.431.g37b22c650d-goog


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* Re: [PATCH 08/12] perf test: Replace arm spe fork test workload with sqrtloop
  2022-11-09 17:46 ` [PATCH 08/12] perf test: Replace arm spe fork test workload with sqrtloop Namhyung Kim
@ 2022-11-10 11:45   ` Leo Yan
  0 siblings, 0 replies; 26+ messages in thread
From: Leo Yan @ 2022-11-10 11:45 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: Arnaldo Carvalho de Melo, Jiri Olsa, Ingo Molnar, Peter Zijlstra,
	LKML, Ian Rogers, Adrian Hunter, linux-perf-users, German Gomez,
	Zhengjun Xing, James Clark

On Wed, Nov 09, 2022 at 09:46:31AM -0800, Namhyung Kim wrote:
> So that it can get rid of requirement of a compiler.  I've also removed
> killall as it'll kill perf process now and run the test workload for 10
> sec instead.
> 
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>

The patch looks good to me and I tested on Arm64 machine:

Tested-by: Leo Yan <leo.yan@linaro.org>

> ---
>  tools/perf/tests/shell/test_arm_spe_fork.sh | 44 +--------------------
>  1 file changed, 1 insertion(+), 43 deletions(-)
> 
> diff --git a/tools/perf/tests/shell/test_arm_spe_fork.sh b/tools/perf/tests/shell/test_arm_spe_fork.sh
> index c920d3583d30..da810e1b2b9e 100755
> --- a/tools/perf/tests/shell/test_arm_spe_fork.sh
> +++ b/tools/perf/tests/shell/test_arm_spe_fork.sh
> @@ -11,14 +11,7 @@ skip_if_no_arm_spe_event() {
>  
>  skip_if_no_arm_spe_event || exit 2
>  
> -# skip if there's no compiler
> -if ! [ -x "$(command -v cc)" ]; then
> -	echo "failed: no compiler, install gcc"
> -	exit 2
> -fi
> -
> -TEST_PROGRAM_SOURCE=$(mktemp /tmp/__perf_test.program.XXXXX.c)
> -TEST_PROGRAM=$(mktemp /tmp/__perf_test.program.XXXXX)
> +TEST_PROGRAM="perf test -w sqrtloop 10"
>  PERF_DATA=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
>  PERF_RECORD_LOG=$(mktemp /tmp/__perf_test.log.XXXXX)
>  
> @@ -27,43 +20,10 @@ cleanup_files()
>  	echo "Cleaning up files..."
>  	rm -f ${PERF_RECORD_LOG}
>  	rm -f ${PERF_DATA}
> -	rm -f ${TEST_PROGRAM_SOURCE}
> -	rm -f ${TEST_PROGRAM}
>  }
>  
>  trap cleanup_files exit term int
>  
> -# compile test program
> -cat << EOF > $TEST_PROGRAM_SOURCE
> -#include <math.h>
> -#include <stdio.h>
> -#include <stdlib.h>
> -#include <unistd.h>
> -#include <sys/wait.h>
> -
> -int workload() {
> -  while (1)
> -    sqrt(rand());
> -  return 0;
> -}
> -
> -int main() {
> -  switch (fork()) {
> -    case 0:
> -      return workload();
> -    case -1:
> -      return 1;
> -    default:
> -      wait(NULL);
> -  }
> -  return 0;
> -}
> -EOF
> -
> -echo "Compiling test program..."
> -CFLAGS="-lm"
> -cc $TEST_PROGRAM_SOURCE $CFLAGS -o $TEST_PROGRAM || exit 1
> -
>  echo "Recording workload..."
>  perf record -o ${PERF_DATA} -e arm_spe/period=65536/ -vvv -- $TEST_PROGRAM > ${PERF_RECORD_LOG} 2>&1 &
>  PERFPID=$!
> @@ -78,8 +38,6 @@ echo Log lines after 1 second = $log1
>  
>  kill $PERFPID
>  wait $PERFPID
> -# test program may leave an orphan process running the workload
> -killall $(basename $TEST_PROGRAM)
>  
>  if [ "$log0" = "$log1" ];
>  then
> -- 
> 2.38.1.431.g37b22c650d-goog
> 

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 08/12] perf test: Replace arm spe fork test workload with sqrtloop
  2022-11-10 18:19 [PATCHSET 00/12] perf test: Add test workloads (v2) Namhyung Kim
@ 2022-11-10 18:19 ` Namhyung Kim
  2022-11-14 11:12   ` James Clark
  0 siblings, 1 reply; 26+ messages in thread
From: Namhyung Kim @ 2022-11-10 18:19 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Jiri Olsa
  Cc: Ingo Molnar, Peter Zijlstra, LKML, Ian Rogers, Adrian Hunter,
	linux-perf-users, Leo Yan, German Gomez, Zhengjun Xing,
	James Clark, Athira Jajeev

So that it can get rid of requirement of a compiler.  I've also removed
killall as it'll kill perf process now and run the test workload for 10
sec instead.

Tested-by: Leo Yan <leo.yan@linaro.org>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/tests/shell/test_arm_spe_fork.sh | 44 +--------------------
 1 file changed, 1 insertion(+), 43 deletions(-)

diff --git a/tools/perf/tests/shell/test_arm_spe_fork.sh b/tools/perf/tests/shell/test_arm_spe_fork.sh
index c920d3583d30..da810e1b2b9e 100755
--- a/tools/perf/tests/shell/test_arm_spe_fork.sh
+++ b/tools/perf/tests/shell/test_arm_spe_fork.sh
@@ -11,14 +11,7 @@ skip_if_no_arm_spe_event() {
 
 skip_if_no_arm_spe_event || exit 2
 
-# skip if there's no compiler
-if ! [ -x "$(command -v cc)" ]; then
-	echo "failed: no compiler, install gcc"
-	exit 2
-fi
-
-TEST_PROGRAM_SOURCE=$(mktemp /tmp/__perf_test.program.XXXXX.c)
-TEST_PROGRAM=$(mktemp /tmp/__perf_test.program.XXXXX)
+TEST_PROGRAM="perf test -w sqrtloop 10"
 PERF_DATA=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
 PERF_RECORD_LOG=$(mktemp /tmp/__perf_test.log.XXXXX)
 
@@ -27,43 +20,10 @@ cleanup_files()
 	echo "Cleaning up files..."
 	rm -f ${PERF_RECORD_LOG}
 	rm -f ${PERF_DATA}
-	rm -f ${TEST_PROGRAM_SOURCE}
-	rm -f ${TEST_PROGRAM}
 }
 
 trap cleanup_files exit term int
 
-# compile test program
-cat << EOF > $TEST_PROGRAM_SOURCE
-#include <math.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/wait.h>
-
-int workload() {
-  while (1)
-    sqrt(rand());
-  return 0;
-}
-
-int main() {
-  switch (fork()) {
-    case 0:
-      return workload();
-    case -1:
-      return 1;
-    default:
-      wait(NULL);
-  }
-  return 0;
-}
-EOF
-
-echo "Compiling test program..."
-CFLAGS="-lm"
-cc $TEST_PROGRAM_SOURCE $CFLAGS -o $TEST_PROGRAM || exit 1
-
 echo "Recording workload..."
 perf record -o ${PERF_DATA} -e arm_spe/period=65536/ -vvv -- $TEST_PROGRAM > ${PERF_RECORD_LOG} 2>&1 &
 PERFPID=$!
@@ -78,8 +38,6 @@ echo Log lines after 1 second = $log1
 
 kill $PERFPID
 wait $PERFPID
-# test program may leave an orphan process running the workload
-killall $(basename $TEST_PROGRAM)
 
 if [ "$log0" = "$log1" ];
 then
-- 
2.38.1.493.g58b659f92b-goog


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* Re: [PATCH 08/12] perf test: Replace arm spe fork test workload with sqrtloop
  2022-11-10 18:19 ` [PATCH 08/12] perf test: Replace arm spe fork test workload with sqrtloop Namhyung Kim
@ 2022-11-14 11:12   ` James Clark
  0 siblings, 0 replies; 26+ messages in thread
From: James Clark @ 2022-11-14 11:12 UTC (permalink / raw)
  To: Namhyung Kim, Arnaldo Carvalho de Melo, Jiri Olsa
  Cc: Ingo Molnar, Peter Zijlstra, LKML, Ian Rogers, Adrian Hunter,
	linux-perf-users, Leo Yan, German Gomez, Zhengjun Xing,
	Athira Jajeev



On 10/11/2022 18:19, Namhyung Kim wrote:
> So that it can get rid of requirement of a compiler.  I've also removed
> killall as it'll kill perf process now and run the test workload for 10
> sec instead.
> 
> Tested-by: Leo Yan <leo.yan@linaro.org>
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> ---
>  tools/perf/tests/shell/test_arm_spe_fork.sh | 44 +--------------------
>  1 file changed, 1 insertion(+), 43 deletions(-)

Tested-by: James Clark <james.clark@arm.com>

> 
> diff --git a/tools/perf/tests/shell/test_arm_spe_fork.sh b/tools/perf/tests/shell/test_arm_spe_fork.sh
> index c920d3583d30..da810e1b2b9e 100755
> --- a/tools/perf/tests/shell/test_arm_spe_fork.sh
> +++ b/tools/perf/tests/shell/test_arm_spe_fork.sh
> @@ -11,14 +11,7 @@ skip_if_no_arm_spe_event() {
>  
>  skip_if_no_arm_spe_event || exit 2
>  
> -# skip if there's no compiler
> -if ! [ -x "$(command -v cc)" ]; then
> -	echo "failed: no compiler, install gcc"
> -	exit 2
> -fi
> -
> -TEST_PROGRAM_SOURCE=$(mktemp /tmp/__perf_test.program.XXXXX.c)
> -TEST_PROGRAM=$(mktemp /tmp/__perf_test.program.XXXXX)
> +TEST_PROGRAM="perf test -w sqrtloop 10"
>  PERF_DATA=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
>  PERF_RECORD_LOG=$(mktemp /tmp/__perf_test.log.XXXXX)
>  
> @@ -27,43 +20,10 @@ cleanup_files()
>  	echo "Cleaning up files..."
>  	rm -f ${PERF_RECORD_LOG}
>  	rm -f ${PERF_DATA}
> -	rm -f ${TEST_PROGRAM_SOURCE}
> -	rm -f ${TEST_PROGRAM}
>  }
>  
>  trap cleanup_files exit term int
>  
> -# compile test program
> -cat << EOF > $TEST_PROGRAM_SOURCE
> -#include <math.h>
> -#include <stdio.h>
> -#include <stdlib.h>
> -#include <unistd.h>
> -#include <sys/wait.h>
> -
> -int workload() {
> -  while (1)
> -    sqrt(rand());
> -  return 0;
> -}
> -
> -int main() {
> -  switch (fork()) {
> -    case 0:
> -      return workload();
> -    case -1:
> -      return 1;
> -    default:
> -      wait(NULL);
> -  }
> -  return 0;
> -}
> -EOF
> -
> -echo "Compiling test program..."
> -CFLAGS="-lm"
> -cc $TEST_PROGRAM_SOURCE $CFLAGS -o $TEST_PROGRAM || exit 1
> -
>  echo "Recording workload..."
>  perf record -o ${PERF_DATA} -e arm_spe/period=65536/ -vvv -- $TEST_PROGRAM > ${PERF_RECORD_LOG} 2>&1 &
>  PERFPID=$!
> @@ -78,8 +38,6 @@ echo Log lines after 1 second = $log1
>  
>  kill $PERFPID
>  wait $PERFPID
> -# test program may leave an orphan process running the workload
> -killall $(basename $TEST_PROGRAM)
>  
>  if [ "$log0" = "$log1" ];
>  then

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCHSET 00/12] perf test: Add test workloads (v3)
@ 2022-11-16 23:38 Namhyung Kim
  2022-11-16 23:38 ` [PATCH 01/12] perf test: Add -w/--workload option Namhyung Kim
                   ` (11 more replies)
  0 siblings, 12 replies; 26+ messages in thread
From: Namhyung Kim @ 2022-11-16 23:38 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Jiri Olsa
  Cc: Ingo Molnar, Peter Zijlstra, LKML, Ian Rogers, Adrian Hunter,
	linux-perf-users, Leo Yan, German Gomez, Zhengjun Xing,
	James Clark, Athira Jajeev

Hello,

In the shell tests, it needs to run a custom test workload to verify
the behaviors.  This requires a working compiler when it runs the
tests.  However it's not available in some test environments, making
hard to run those tests.

changes in v3)
 * update brstack to set num_loops  (James)
 * fix a typo in the brstack test  (German)
 * add tags rom German and James

changes in v2)
 * use sig_atomic_t  (Arnaldo)
 * fix callgraph fp test  (Leo)
 * fix bulid in sqrtloop  (German)
 * add tags from Leo Yan

So I've added the test workload to the perf binary directly, so that
we can run them simply like:

  $ perf test -w noploop

And convert most of the shell tests need compilers with this workloads.
The buildid test still requires a compiler since it needs to check
different build options to generate different kind of build-IDs.

I've checked perf test result after the changes but could not verify
architecture-specific ones (e.g. for arm64).  It'd be nice if anyone
can check it out.

You can find it in 'perf/test-workload-v3' branch in

  git://git.kernel.org/pub/scm/linux/kernel/git/namhyung/linux-perf.git

Thanks,
Namhyung

Namhyung Kim (12):
  perf test: Add -w/--workload option
  perf test: Replace pipe test workload with noploop
  perf test: Add 'thloop' test workload
  perf test: Replace record test workload with thloop
  perf test: Add 'leafloop' test workload
  perf test: Replace arm callgraph fp test workload with leafloop
  perf test: Add 'sqrtloop' test workload
  perf test: Replace arm spe fork test workload with sqrtloop
  perf test: Add 'brstack' test workload
  perf test: Replace brstack test workload
  perf test: Add 'datasym' test workload
  perf test: Replace data symbol test workload with datasym

 tools/perf/tests/Build                        |  2 +
 tools/perf/tests/builtin-test.c               | 29 ++++++++
 tools/perf/tests/shell/pipe_test.sh           | 55 +++-------------
 tools/perf/tests/shell/record.sh              | 59 +----------------
 .../perf/tests/shell/test_arm_callgraph_fp.sh | 34 +---------
 tools/perf/tests/shell/test_arm_spe_fork.sh   | 44 +------------
 tools/perf/tests/shell/test_brstack.sh        | 66 ++++---------------
 tools/perf/tests/shell/test_data_symbol.sh    | 29 +-------
 tools/perf/tests/tests.h                      | 27 ++++++++
 tools/perf/tests/workloads/Build              | 12 ++++
 tools/perf/tests/workloads/brstack.c          | 41 ++++++++++++
 tools/perf/tests/workloads/datasym.c          | 24 +++++++
 tools/perf/tests/workloads/leafloop.c         | 34 ++++++++++
 tools/perf/tests/workloads/noploop.c          | 32 +++++++++
 tools/perf/tests/workloads/sqrtloop.c         | 45 +++++++++++++
 tools/perf/tests/workloads/thloop.c           | 53 +++++++++++++++
 16 files changed, 329 insertions(+), 257 deletions(-)
 create mode 100644 tools/perf/tests/workloads/Build
 create mode 100644 tools/perf/tests/workloads/brstack.c
 create mode 100644 tools/perf/tests/workloads/datasym.c
 create mode 100644 tools/perf/tests/workloads/leafloop.c
 create mode 100644 tools/perf/tests/workloads/noploop.c
 create mode 100644 tools/perf/tests/workloads/sqrtloop.c
 create mode 100644 tools/perf/tests/workloads/thloop.c


base-commit: 4dd7ff4a0311eee3ac946f0824442de94b34c42e
-- 
2.38.1.584.g0f3c55d4c2-goog


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 01/12] perf test: Add -w/--workload option
  2022-11-16 23:38 [PATCHSET 00/12] perf test: Add test workloads (v3) Namhyung Kim
@ 2022-11-16 23:38 ` Namhyung Kim
  2022-11-16 23:38 ` [PATCH 02/12] perf test: Replace pipe test workload with noploop Namhyung Kim
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 26+ messages in thread
From: Namhyung Kim @ 2022-11-16 23:38 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Jiri Olsa
  Cc: Ingo Molnar, Peter Zijlstra, LKML, Ian Rogers, Adrian Hunter,
	linux-perf-users, Leo Yan, German Gomez, Zhengjun Xing,
	James Clark, Athira Jajeev

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>
---
 tools/perf/tests/Build               |  2 ++
 tools/perf/tests/builtin-test.c      | 24 +++++++++++++++++++++
 tools/perf/tests/tests.h             | 22 +++++++++++++++++++
 tools/perf/tests/workloads/Build     |  3 +++
 tools/perf/tests/workloads/noploop.c | 32 ++++++++++++++++++++++++++++
 5 files changed, 83 insertions(+)
 create mode 100644 tools/perf/tests/workloads/Build
 create mode 100644 tools/perf/tests/workloads/noploop.c

diff --git a/tools/perf/tests/Build b/tools/perf/tests/Build
index 2064a640facb..11b69023011b 100644
--- a/tools/perf/tests/Build
+++ b/tools/perf/tests/Build
@@ -103,3 +103,5 @@ endif
 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_dwarf-unwind.o += -fno-optimize-sibling-calls
+
+perf-y += workloads/
diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index 7122eae1d98d..ce641ccfcf81 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -118,6 +118,10 @@ static struct test_suite **tests[] = {
 	arch_tests,
 };
 
+static struct test_workload *workloads[] = {
+	&workload__noploop,
+};
+
 static int num_subtests(const struct test_suite *t)
 {
 	int num;
@@ -475,6 +479,21 @@ static int perf_test__list(int argc, const char **argv)
 	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)
 {
 	const char *test_usage[] = {
@@ -482,12 +501,14 @@ int cmd_test(int argc, const char **argv)
 	NULL,
 	};
 	const char *skip = NULL;
+	const char *workload = NULL;
 	const struct option test_options[] = {
 	OPT_STRING('s', "skip", &skip, "tests", "tests to skip"),
 	OPT_INCR('v', "verbose", &verbose,
 		    "be more verbose (show symbol address, etc)"),
 	OPT_BOOLEAN('F', "dont-fork", &dont_fork,
 		    "Do not fork for testcase"),
+	OPT_STRING('w', "workload", &workload, "work", "workload to run for testing"),
 	OPT_END()
 	};
 	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"))
 		return perf_test__list(argc - 1, argv + 1);
 
+	if (workload)
+		return run_workload(workload, argc, argv);
+
 	symbol_conf.priv_size = sizeof(int);
 	symbol_conf.sort_by_name = true;
 	symbol_conf.try_vmlinux_path = true;
diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h
index 5bbb8f6a48fc..d315d0d6fc97 100644
--- a/tools/perf/tests/tests.h
+++ b/tools/perf/tests/tests.h
@@ -180,4 +180,26 @@ int test__arch_unwind_sample(struct perf_sample *sample,
 DECLARE_SUITE(vectors_page);
 #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 */
diff --git a/tools/perf/tests/workloads/Build b/tools/perf/tests/workloads/Build
new file mode 100644
index 000000000000..f98e968d4633
--- /dev/null
+++ b/tools/perf/tests/workloads/Build
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+perf-y += noploop.o
diff --git a/tools/perf/tests/workloads/noploop.c b/tools/perf/tests/workloads/noploop.c
new file mode 100644
index 000000000000..940ea5910a84
--- /dev/null
+++ b/tools/perf/tests/workloads/noploop.c
@@ -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);
-- 
2.38.1.584.g0f3c55d4c2-goog


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 02/12] perf test: Replace pipe test workload with noploop
  2022-11-16 23:38 [PATCHSET 00/12] perf test: Add test workloads (v3) Namhyung Kim
  2022-11-16 23:38 ` [PATCH 01/12] perf test: Add -w/--workload option Namhyung Kim
@ 2022-11-16 23:38 ` Namhyung Kim
  2022-11-16 23:38 ` [PATCH 03/12] perf test: Add 'thloop' test workload Namhyung Kim
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 26+ messages in thread
From: Namhyung Kim @ 2022-11-16 23:38 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Jiri Olsa
  Cc: Ingo Molnar, Peter Zijlstra, LKML, Ian Rogers, Adrian Hunter,
	linux-perf-users, Leo Yan, German Gomez, Zhengjun Xing,
	James Clark, Athira Jajeev

So that it can get rid of requirement of a compiler.
Also define and use more local symbols to ease future changes.

  $ sudo ./perf test -v pipe
   87: perf pipe recording and injection test                          :
  --- start ---
  test child forked, pid 748003
  [ perf record: Woken up 1 times to write data ]
  [ perf record: Captured and wrote 0.000 MB - ]
      748014   748014       -1 |perf
  [ perf record: Woken up 1 times to write data ]
  [ perf record: Captured and wrote 0.000 MB - ]
      99.83%  perf     perf                  [.] noploop
  [ perf record: Woken up 1 times to write data ]
  [ perf record: Captured and wrote 0.000 MB - ]
      99.85%  perf     perf                  [.] noploop
  [ perf record: Woken up 1 times to write data ]
  [ perf record: Captured and wrote 0.160 MB /tmp/perf.data.2XYPdw (4007 samples) ]
      99.83%  perf     perf                  [.] noploop
  test child finished with 0
  ---- end ----
  perf pipe recording and injection test: Ok

Tested-by: James Clark <james.clark@arm.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/tests/shell/pipe_test.sh | 55 ++++++-----------------------
 1 file changed, 10 insertions(+), 45 deletions(-)

diff --git a/tools/perf/tests/shell/pipe_test.sh b/tools/perf/tests/shell/pipe_test.sh
index 1b32b4f28391..8dd115dd35a7 100755
--- a/tools/perf/tests/shell/pipe_test.sh
+++ b/tools/perf/tests/shell/pipe_test.sh
@@ -2,68 +2,33 @@
 # perf pipe recording and injection test
 # SPDX-License-Identifier: GPL-2.0
 
-# skip if there's no compiler
-if ! [ -x "$(command -v cc)" ]; then
-	echo "failed: no compiler, install gcc"
-	exit 2
-fi
-
-file=$(mktemp /tmp/test.file.XXXXXX)
 data=$(mktemp /tmp/perf.data.XXXXXX)
+prog="perf test -w noploop"
+task="perf"
+sym="noploop"
 
-cat <<EOF | cc -o ${file} -x c -
-#include <signal.h>
-#include <stdlib.h>
-#include <unistd.h>
-
-volatile int done;
-
-void sigalrm(int sig) {
-	done = 1;
-}
-
-__attribute__((noinline)) void noploop(void) {
-	while (!done)
-		continue;
-}
-
-int main(int argc, char *argv[]) {
-	int sec = 1;
-
-	if (argc > 1)
-		sec = atoi(argv[1]);
-
-	signal(SIGALRM, sigalrm);
-	alarm(sec);
-
-	noploop();
-	return 0;
-}
-EOF
-
-
-if ! perf record -e task-clock:u -o - ${file} | perf report -i - --task | grep test.file; then
+if ! perf record -e task-clock:u -o - ${prog} | perf report -i - --task | grep ${task}; then
 	echo "cannot find the test file in the perf report"
 	exit 1
 fi
 
-if ! perf record -e task-clock:u -o - ${file} | perf inject -b | perf report -i - | grep noploop; then
+if ! perf record -e task-clock:u -o - ${prog} | perf inject -b | perf report -i - | grep ${sym}; then
 	echo "cannot find noploop function in pipe #1"
 	exit 1
 fi
 
-perf record -e task-clock:u -o - ${file} | perf inject -b -o ${data}
-if ! perf report -i ${data} | grep noploop; then
+perf record -e task-clock:u -o - ${prog} | perf inject -b -o ${data}
+if ! perf report -i ${data} | grep ${sym}; then
 	echo "cannot find noploop function in pipe #2"
 	exit 1
 fi
 
-perf record -e task-clock:u -o ${data} ${file}
-if ! perf inject -b -i ${data} | perf report -i - | grep noploop; then
+perf record -e task-clock:u -o ${data} ${prog}
+if ! perf inject -b -i ${data} | perf report -i - | grep ${sym}; then
 	echo "cannot find noploop function in pipe #3"
 	exit 1
 fi
 
 
-rm -f ${file} ${data} ${data}.old
+rm -f ${data} ${data}.old
 exit 0
-- 
2.38.1.584.g0f3c55d4c2-goog


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 03/12] perf test: Add 'thloop' test workload
  2022-11-16 23:38 [PATCHSET 00/12] perf test: Add test workloads (v3) Namhyung Kim
  2022-11-16 23:38 ` [PATCH 01/12] perf test: Add -w/--workload option Namhyung Kim
  2022-11-16 23:38 ` [PATCH 02/12] perf test: Replace pipe test workload with noploop Namhyung Kim
@ 2022-11-16 23:38 ` Namhyung Kim
  2022-11-16 23:38 ` [PATCH 04/12] perf test: Replace record test workload with thloop Namhyung Kim
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 26+ messages in thread
From: Namhyung Kim @ 2022-11-16 23:38 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Jiri Olsa
  Cc: Ingo Molnar, Peter Zijlstra, LKML, Ian Rogers, Adrian Hunter,
	linux-perf-users, Leo Yan, German Gomez, Zhengjun Xing,
	James Clark, Athira Jajeev

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>
---
 tools/perf/tests/builtin-test.c     |  1 +
 tools/perf/tests/tests.h            |  1 +
 tools/perf/tests/workloads/Build    |  1 +
 tools/perf/tests/workloads/thloop.c | 53 +++++++++++++++++++++++++++++
 4 files changed, 56 insertions(+)
 create mode 100644 tools/perf/tests/workloads/thloop.c

diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index ce641ccfcf81..161f38476e77 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -120,6 +120,7 @@ static struct test_suite **tests[] = {
 
 static struct test_workload *workloads[] = {
 	&workload__noploop,
+	&workload__thloop,
 };
 
 static int num_subtests(const struct test_suite *t)
diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h
index d315d0d6fc97..e6edfeeadaeb 100644
--- a/tools/perf/tests/tests.h
+++ b/tools/perf/tests/tests.h
@@ -201,5 +201,6 @@ struct test_workload workload__##work = {	\
 
 /* The list of test workloads */
 DECLARE_WORKLOAD(noploop);
+DECLARE_WORKLOAD(thloop);
 
 #endif /* TESTS_H */
diff --git a/tools/perf/tests/workloads/Build b/tools/perf/tests/workloads/Build
index f98e968d4633..b8964b1099c0 100644
--- a/tools/perf/tests/workloads/Build
+++ b/tools/perf/tests/workloads/Build
@@ -1,3 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0
 
 perf-y += noploop.o
+perf-y += thloop.o
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);
-- 
2.38.1.584.g0f3c55d4c2-goog


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 04/12] perf test: Replace record test workload with thloop
  2022-11-16 23:38 [PATCHSET 00/12] perf test: Add test workloads (v3) Namhyung Kim
                   ` (2 preceding siblings ...)
  2022-11-16 23:38 ` [PATCH 03/12] perf test: Add 'thloop' test workload Namhyung Kim
@ 2022-11-16 23:38 ` Namhyung Kim
  2022-11-16 23:38 ` [PATCH 05/12] perf test: Add 'leafloop' test workload Namhyung Kim
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 26+ messages in thread
From: Namhyung Kim @ 2022-11-16 23:38 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Jiri Olsa
  Cc: Ingo Molnar, Peter Zijlstra, LKML, Ian Rogers, Adrian Hunter,
	linux-perf-users, Leo Yan, German Gomez, Zhengjun Xing,
	James Clark, Athira Jajeev

So that it can get rid of requirements for a compiler.

  $ sudo ./perf test -v 92
   92: perf record tests                                               :
  --- start ---
  test child forked, pid 740204
  Basic --per-thread mode test
  Basic --per-thread mode test [Success]
  Register capture test
  Register capture test [Success]
  Basic --system-wide mode test
  Basic --system-wide mode test [Success]
  Basic target workload test
  Basic target workload test [Success]
  test child finished with 0
  ---- end ----
  perf record tests: Ok

Tested-by: James Clark <james.clark@arm.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/tests/shell/record.sh | 59 ++------------------------------
 1 file changed, 3 insertions(+), 56 deletions(-)

diff --git a/tools/perf/tests/shell/record.sh b/tools/perf/tests/shell/record.sh
index e93b3a8871fe..4dff89e3a3fd 100755
--- a/tools/perf/tests/shell/record.sh
+++ b/tools/perf/tests/shell/record.sh
@@ -9,17 +9,13 @@ shelldir=$(dirname "$0")
 
 err=0
 perfdata=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
-testprog=$(mktemp /tmp/__perf_test.prog.XXXXXX)
+testprog="perf test -w thloop"
 testsym="test_loop"
 
 cleanup() {
   rm -rf "${perfdata}"
   rm -rf "${perfdata}".old
 
-  if [ "${testprog}" != "true" ]; then
-    rm -f "${testprog}"
-  fi
-
   trap - EXIT TERM INT
 }
 
@@ -29,53 +25,6 @@ trap_cleanup() {
 }
 trap trap_cleanup EXIT TERM INT
 
-build_test_program() {
-  if ! [ -x "$(command -v cc)" ]; then
-    # No CC found. Fall back to 'true'
-    testprog=true
-    testsym=true
-    return
-  fi
-
-  echo "Build a test program"
-  cat <<EOF | cc -o ${testprog} -xc - -pthread
-#include <stdio.h>
-#include <stdlib.h>
-#include <pthread.h>
-
-void test_loop(void) {
-  volatile int count = 1000000;
-
-  while (count--)
-    continue;
-}
-
-void *thfunc(void *arg) {
-  int forever = *(int *)arg;
-
-  do {
-    test_loop();
-  } while (forever);
-
-  return NULL;
-}
-
-int main(int argc, char *argv[]) {
-  pthread_t th;
-  int forever = 0;
-
-  if (argc > 1)
-    forever = atoi(argv[1]);
-
-  pthread_create(&th, NULL, thfunc, &forever);
-  test_loop();
-  pthread_join(th, NULL);
-
-  return 0;
-}
-EOF
-}
-
 test_per_thread() {
   echo "Basic --per-thread mode test"
   if ! perf record -o /dev/null --quiet ${testprog} 2> /dev/null
@@ -96,8 +45,8 @@ test_per_thread() {
     return
   fi
 
-  # run the test program in background (forever)
-  ${testprog} 1 &
+  # run the test program in background (for 30 seconds)
+  ${testprog} 30 &
   TESTPID=$!
 
   rm -f "${perfdata}"
@@ -205,8 +154,6 @@ test_workload() {
   echo "Basic target workload test [Success]"
 }
 
-build_test_program
-
 test_per_thread
 test_register_capture
 test_system_wide
-- 
2.38.1.584.g0f3c55d4c2-goog


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 05/12] perf test: Add 'leafloop' test workload
  2022-11-16 23:38 [PATCHSET 00/12] perf test: Add test workloads (v3) Namhyung Kim
                   ` (3 preceding siblings ...)
  2022-11-16 23:38 ` [PATCH 04/12] perf test: Replace record test workload with thloop Namhyung Kim
@ 2022-11-16 23:38 ` Namhyung Kim
  2022-11-17 16:06   ` Arnaldo Carvalho de Melo
  2022-11-16 23:38 ` [PATCH 06/12] perf test: Replace arm callgraph fp test workload with leafloop Namhyung Kim
                   ` (6 subsequent siblings)
  11 siblings, 1 reply; 26+ messages in thread
From: Namhyung Kim @ 2022-11-16 23:38 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Jiri Olsa
  Cc: Ingo Molnar, Peter Zijlstra, LKML, Ian Rogers, Adrian Hunter,
	linux-perf-users, Leo Yan, German Gomez, Zhengjun Xing,
	James Clark, Athira Jajeev

The leafloop workload is to run an infinite loop in the test_leaf
function.  This is needed for the ARM fp callgraph test to verify if it
gets the correct callchains.

  $ perf test -w leafloop

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/tests/builtin-test.c       |  1 +
 tools/perf/tests/tests.h              |  1 +
 tools/perf/tests/workloads/Build      |  3 +++
 tools/perf/tests/workloads/leafloop.c | 34 +++++++++++++++++++++++++++
 4 files changed, 39 insertions(+)
 create mode 100644 tools/perf/tests/workloads/leafloop.c

diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index 161f38476e77..0ed5ac452f6e 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -121,6 +121,7 @@ static struct test_suite **tests[] = {
 static struct test_workload *workloads[] = {
 	&workload__noploop,
 	&workload__thloop,
+	&workload__leafloop,
 };
 
 static int num_subtests(const struct test_suite *t)
diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h
index e6edfeeadaeb..86804dd6452b 100644
--- a/tools/perf/tests/tests.h
+++ b/tools/perf/tests/tests.h
@@ -202,5 +202,6 @@ struct test_workload workload__##work = {	\
 /* The list of test workloads */
 DECLARE_WORKLOAD(noploop);
 DECLARE_WORKLOAD(thloop);
+DECLARE_WORKLOAD(leafloop);
 
 #endif /* TESTS_H */
diff --git a/tools/perf/tests/workloads/Build b/tools/perf/tests/workloads/Build
index b8964b1099c0..631596bdb2b3 100644
--- a/tools/perf/tests/workloads/Build
+++ b/tools/perf/tests/workloads/Build
@@ -2,3 +2,6 @@
 
 perf-y += noploop.o
 perf-y += thloop.o
+perf-y += leafloop.o
+
+CFLAGS_leafloop.o         = -g -O0 -fno-inline -fno-omit-frame-pointer
diff --git a/tools/perf/tests/workloads/leafloop.c b/tools/perf/tests/workloads/leafloop.c
new file mode 100644
index 000000000000..1bf5cc97649b
--- /dev/null
+++ b/tools/perf/tests/workloads/leafloop.c
@@ -0,0 +1,34 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#include <stdlib.h>
+#include <linux/compiler.h>
+#include "../tests.h"
+
+/* We want to check these symbols in perf script */
+noinline void leaf(volatile int b);
+noinline void parent(volatile int b);
+
+static volatile int a;
+
+noinline void leaf(volatile int b)
+{
+	for (;;)
+		a += b;
+}
+
+noinline void parent(volatile int b)
+{
+	leaf(b);
+}
+
+static int leafloop(int argc, const char **argv)
+{
+	int c = 1;
+
+	if (argc > 0)
+		c = atoi(argv[0]);
+
+	parent(c);
+	return 0;
+}
+
+DEFINE_WORKLOAD(leafloop);
-- 
2.38.1.584.g0f3c55d4c2-goog


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 06/12] perf test: Replace arm callgraph fp test workload with leafloop
  2022-11-16 23:38 [PATCHSET 00/12] perf test: Add test workloads (v3) Namhyung Kim
                   ` (4 preceding siblings ...)
  2022-11-16 23:38 ` [PATCH 05/12] perf test: Add 'leafloop' test workload Namhyung Kim
@ 2022-11-16 23:38 ` Namhyung Kim
  2022-11-16 23:38 ` [PATCH 07/12] perf test: Add 'sqrtloop' test workload Namhyung Kim
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 26+ messages in thread
From: Namhyung Kim @ 2022-11-16 23:38 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Jiri Olsa
  Cc: Ingo Molnar, Peter Zijlstra, LKML, Ian Rogers, Adrian Hunter,
	linux-perf-users, Leo Yan, German Gomez, Zhengjun Xing,
	James Clark, Athira Jajeev

So that it can get rid of requirement of a compiler.

Reviewed-by: Leo Yan <leo.yan@linaro.org>
Tested-by: James Clark <james.clark@arm.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 .../perf/tests/shell/test_arm_callgraph_fp.sh | 34 ++-----------------
 1 file changed, 3 insertions(+), 31 deletions(-)

diff --git a/tools/perf/tests/shell/test_arm_callgraph_fp.sh b/tools/perf/tests/shell/test_arm_callgraph_fp.sh
index ec108d45d3c6..e61d8deaa0c4 100755
--- a/tools/perf/tests/shell/test_arm_callgraph_fp.sh
+++ b/tools/perf/tests/shell/test_arm_callgraph_fp.sh
@@ -4,44 +4,16 @@
 
 lscpu | grep -q "aarch64" || exit 2
 
-if ! [ -x "$(command -v cc)" ]; then
-	echo "failed: no compiler, install gcc"
-	exit 2
-fi
-
 PERF_DATA=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
-TEST_PROGRAM_SOURCE=$(mktemp /tmp/test_program.XXXXX.c)
-TEST_PROGRAM=$(mktemp /tmp/test_program.XXXXX)
+TEST_PROGRAM="perf test -w leafloop"
 
 cleanup_files()
 {
 	rm -f $PERF_DATA
-	rm -f $TEST_PROGRAM_SOURCE
-	rm -f $TEST_PROGRAM
 }
 
 trap cleanup_files exit term int
 
-cat << EOF > $TEST_PROGRAM_SOURCE
-int a = 0;
-void leaf(void) {
-  for (;;)
-    a += a;
-}
-void parent(void) {
-  leaf();
-}
-int main(void) {
-  parent();
-  return 0;
-}
-EOF
-
-echo " + Compiling test program ($TEST_PROGRAM)..."
-
-CFLAGS="-g -O0 -fno-inline -fno-omit-frame-pointer"
-cc $CFLAGS $TEST_PROGRAM_SOURCE -o $TEST_PROGRAM || exit 1
-
 # Add a 1 second delay to skip samples that are not in the leaf() function
 perf record -o $PERF_DATA --call-graph fp -e cycles//u -D 1000 --user-callchains -- $TEST_PROGRAM 2> /dev/null &
 PID=$!
@@ -58,11 +30,11 @@ wait $PID
 # program
 # 	728 leaf
 # 	753 parent
-# 	76c main
+# 	76c leafloop
 # ...
 
 perf script -i $PERF_DATA -F comm,ip,sym | head -n4
 perf script -i $PERF_DATA -F comm,ip,sym | head -n4 | \
 	awk '{ if ($2 != "") sym[i++] = $2 } END { if (sym[0] != "leaf" ||
 						       sym[1] != "parent" ||
-						       sym[2] != "main") exit 1 }'
+						       sym[2] != "leafloop") exit 1 }'
-- 
2.38.1.584.g0f3c55d4c2-goog


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 07/12] perf test: Add 'sqrtloop' test workload
  2022-11-16 23:38 [PATCHSET 00/12] perf test: Add test workloads (v3) Namhyung Kim
                   ` (5 preceding siblings ...)
  2022-11-16 23:38 ` [PATCH 06/12] perf test: Replace arm callgraph fp test workload with leafloop Namhyung Kim
@ 2022-11-16 23:38 ` Namhyung Kim
  2022-11-16 23:38 ` [PATCH 08/12] perf test: Replace arm spe fork test workload with sqrtloop Namhyung Kim
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 26+ messages in thread
From: Namhyung Kim @ 2022-11-16 23:38 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Jiri Olsa
  Cc: Ingo Molnar, Peter Zijlstra, LKML, Ian Rogers, Adrian Hunter,
	linux-perf-users, Leo Yan, German Gomez, Zhengjun Xing,
	James Clark, Athira Jajeev

The sqrtloop creates a child process to run an infinite loop calling
sqrt() with rand().  This is needed for ARM SPE fork test.

  $ perf test -w sqrtloop

It can take an optional argument to specify how long it will run in
seconds (default: 1).

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/tests/builtin-test.c       |  1 +
 tools/perf/tests/tests.h              |  1 +
 tools/perf/tests/workloads/Build      |  1 +
 tools/perf/tests/workloads/sqrtloop.c | 45 +++++++++++++++++++++++++++
 4 files changed, 48 insertions(+)
 create mode 100644 tools/perf/tests/workloads/sqrtloop.c

diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index 0ed5ac452f6e..9acb7a93eeb9 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -122,6 +122,7 @@ static struct test_workload *workloads[] = {
 	&workload__noploop,
 	&workload__thloop,
 	&workload__leafloop,
+	&workload__sqrtloop,
 };
 
 static int num_subtests(const struct test_suite *t)
diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h
index 86804dd6452b..18c40319e67c 100644
--- a/tools/perf/tests/tests.h
+++ b/tools/perf/tests/tests.h
@@ -203,5 +203,6 @@ struct test_workload workload__##work = {	\
 DECLARE_WORKLOAD(noploop);
 DECLARE_WORKLOAD(thloop);
 DECLARE_WORKLOAD(leafloop);
+DECLARE_WORKLOAD(sqrtloop);
 
 #endif /* TESTS_H */
diff --git a/tools/perf/tests/workloads/Build b/tools/perf/tests/workloads/Build
index 631596bdb2b3..1ca95cb0fdb5 100644
--- a/tools/perf/tests/workloads/Build
+++ b/tools/perf/tests/workloads/Build
@@ -3,5 +3,6 @@
 perf-y += noploop.o
 perf-y += thloop.o
 perf-y += leafloop.o
+perf-y += sqrtloop.o
 
 CFLAGS_leafloop.o         = -g -O0 -fno-inline -fno-omit-frame-pointer
diff --git a/tools/perf/tests/workloads/sqrtloop.c b/tools/perf/tests/workloads/sqrtloop.c
new file mode 100644
index 000000000000..1e44d541d737
--- /dev/null
+++ b/tools/perf/tests/workloads/sqrtloop.c
@@ -0,0 +1,45 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#include <math.h>
+#include <signal.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <linux/compiler.h>
+#include <sys/wait.h>
+#include "../tests.h"
+
+static volatile sig_atomic_t done;
+
+static void sighandler(int sig __maybe_unused)
+{
+	done = 1;
+}
+
+static int __sqrtloop(int sec)
+{
+	signal(SIGALRM, sighandler);
+	alarm(sec);
+
+	while (!done)
+		sqrt(rand());
+	return 0;
+}
+
+static int sqrtloop(int argc, const char **argv)
+{
+	int sec = 1;
+
+	if (argc > 0)
+		sec = atoi(argv[0]);
+
+	switch (fork()) {
+	case 0:
+		return __sqrtloop(sec);
+	case -1:
+		return -1;
+	default:
+		wait(NULL);
+	}
+	return 0;
+}
+
+DEFINE_WORKLOAD(sqrtloop);
-- 
2.38.1.584.g0f3c55d4c2-goog


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 08/12] perf test: Replace arm spe fork test workload with sqrtloop
  2022-11-16 23:38 [PATCHSET 00/12] perf test: Add test workloads (v3) Namhyung Kim
                   ` (6 preceding siblings ...)
  2022-11-16 23:38 ` [PATCH 07/12] perf test: Add 'sqrtloop' test workload Namhyung Kim
@ 2022-11-16 23:38 ` Namhyung Kim
  2022-11-20 15:39   ` Arnaldo Carvalho de Melo
  2022-11-16 23:38 ` [PATCH 09/12] perf test: Add 'brstack' test workload Namhyung Kim
                   ` (3 subsequent siblings)
  11 siblings, 1 reply; 26+ messages in thread
From: Namhyung Kim @ 2022-11-16 23:38 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Jiri Olsa
  Cc: Ingo Molnar, Peter Zijlstra, LKML, Ian Rogers, Adrian Hunter,
	linux-perf-users, Leo Yan, German Gomez, Zhengjun Xing,
	James Clark, Athira Jajeev

So that it can get rid of requirement of a compiler.  I've also removed
killall as it'll kill perf process now and run the test workload for 10
sec instead.

Tested-by: Leo Yan <leo.yan@linaro.org>
Tested-by: James Clark <james.clark@arm.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/tests/shell/test_arm_spe_fork.sh | 44 +--------------------
 1 file changed, 1 insertion(+), 43 deletions(-)

diff --git a/tools/perf/tests/shell/test_arm_spe_fork.sh b/tools/perf/tests/shell/test_arm_spe_fork.sh
index c920d3583d30..da810e1b2b9e 100755
--- a/tools/perf/tests/shell/test_arm_spe_fork.sh
+++ b/tools/perf/tests/shell/test_arm_spe_fork.sh
@@ -11,14 +11,7 @@ skip_if_no_arm_spe_event() {
 
 skip_if_no_arm_spe_event || exit 2
 
-# skip if there's no compiler
-if ! [ -x "$(command -v cc)" ]; then
-	echo "failed: no compiler, install gcc"
-	exit 2
-fi
-
-TEST_PROGRAM_SOURCE=$(mktemp /tmp/__perf_test.program.XXXXX.c)
-TEST_PROGRAM=$(mktemp /tmp/__perf_test.program.XXXXX)
+TEST_PROGRAM="perf test -w sqrtloop 10"
 PERF_DATA=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
 PERF_RECORD_LOG=$(mktemp /tmp/__perf_test.log.XXXXX)
 
@@ -27,43 +20,10 @@ cleanup_files()
 	echo "Cleaning up files..."
 	rm -f ${PERF_RECORD_LOG}
 	rm -f ${PERF_DATA}
-	rm -f ${TEST_PROGRAM_SOURCE}
-	rm -f ${TEST_PROGRAM}
 }
 
 trap cleanup_files exit term int
 
-# compile test program
-cat << EOF > $TEST_PROGRAM_SOURCE
-#include <math.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/wait.h>
-
-int workload() {
-  while (1)
-    sqrt(rand());
-  return 0;
-}
-
-int main() {
-  switch (fork()) {
-    case 0:
-      return workload();
-    case -1:
-      return 1;
-    default:
-      wait(NULL);
-  }
-  return 0;
-}
-EOF
-
-echo "Compiling test program..."
-CFLAGS="-lm"
-cc $TEST_PROGRAM_SOURCE $CFLAGS -o $TEST_PROGRAM || exit 1
-
 echo "Recording workload..."
 perf record -o ${PERF_DATA} -e arm_spe/period=65536/ -vvv -- $TEST_PROGRAM > ${PERF_RECORD_LOG} 2>&1 &
 PERFPID=$!
@@ -78,8 +38,6 @@ echo Log lines after 1 second = $log1
 
 kill $PERFPID
 wait $PERFPID
-# test program may leave an orphan process running the workload
-killall $(basename $TEST_PROGRAM)
 
 if [ "$log0" = "$log1" ];
 then
-- 
2.38.1.584.g0f3c55d4c2-goog


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 09/12] perf test: Add 'brstack' test workload
  2022-11-16 23:38 [PATCHSET 00/12] perf test: Add test workloads (v3) Namhyung Kim
                   ` (7 preceding siblings ...)
  2022-11-16 23:38 ` [PATCH 08/12] perf test: Replace arm spe fork test workload with sqrtloop Namhyung Kim
@ 2022-11-16 23:38 ` Namhyung Kim
  2022-11-16 23:38 ` [PATCH 10/12] perf test: Replace brstack " Namhyung Kim
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 26+ messages in thread
From: Namhyung Kim @ 2022-11-16 23:38 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Jiri Olsa
  Cc: Ingo Molnar, Peter Zijlstra, LKML, Ian Rogers, Adrian Hunter,
	linux-perf-users, Leo Yan, German Gomez, Zhengjun Xing,
	James Clark, Athira Jajeev

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.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/tests/builtin-test.c      |  1 +
 tools/perf/tests/tests.h             |  1 +
 tools/perf/tests/workloads/Build     |  2 ++
 tools/perf/tests/workloads/brstack.c | 41 ++++++++++++++++++++++++++++
 4 files changed, 45 insertions(+)
 create mode 100644 tools/perf/tests/workloads/brstack.c

diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index 9acb7a93eeb9..69fa56939309 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -123,6 +123,7 @@ static struct test_workload *workloads[] = {
 	&workload__thloop,
 	&workload__leafloop,
 	&workload__sqrtloop,
+	&workload__brstack,
 };
 
 static int num_subtests(const struct test_suite *t)
diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h
index 18c40319e67c..dc96f59cac2e 100644
--- a/tools/perf/tests/tests.h
+++ b/tools/perf/tests/tests.h
@@ -204,5 +204,6 @@ DECLARE_WORKLOAD(noploop);
 DECLARE_WORKLOAD(thloop);
 DECLARE_WORKLOAD(leafloop);
 DECLARE_WORKLOAD(sqrtloop);
+DECLARE_WORKLOAD(brstack);
 
 #endif /* TESTS_H */
diff --git a/tools/perf/tests/workloads/Build b/tools/perf/tests/workloads/Build
index 1ca95cb0fdb5..c933cdcf91d1 100644
--- a/tools/perf/tests/workloads/Build
+++ b/tools/perf/tests/workloads/Build
@@ -4,5 +4,7 @@ perf-y += noploop.o
 perf-y += thloop.o
 perf-y += leafloop.o
 perf-y += sqrtloop.o
+perf-y += brstack.o
 
 CFLAGS_leafloop.o         = -g -O0 -fno-inline -fno-omit-frame-pointer
+CFLAGS_brstack.o          = -g -O0 -fno-inline
diff --git a/tools/perf/tests/workloads/brstack.c b/tools/perf/tests/workloads/brstack.c
new file mode 100644
index 000000000000..cd0386d58f97
--- /dev/null
+++ b/tools/perf/tests/workloads/brstack.c
@@ -0,0 +1,41 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#include <stdlib.h>
+#include "../tests.h"
+
+
+#define BENCH_RUNS 999999
+
+static volatile int cnt;
+
+static void brstack_bar(void) {
+}				/* return */
+
+static void brstack_foo(void) {
+	brstack_bar();		/* call */
+}				/* return */
+
+static void brstack_bench(void) {
+	void (*brstack_foo_ind)(void) = brstack_foo;
+
+	if ((cnt++) % 3)	/* branch (cond) */
+		brstack_foo();	/* call */
+	brstack_bar();		/* call */
+	brstack_foo_ind();	/* call (ind) */
+}
+
+static int brstack(int argc, const char **argv)
+{
+	int num_loops = BENCH_RUNS;
+
+	if (argc > 0)
+		num_loops = atoi(argv[0]);
+
+	while (1) {
+		if ((cnt++) > num_loops)
+			break;
+		brstack_bench();/* call */
+	}			/* branch (uncond) */
+	return 0;
+}
+
+DEFINE_WORKLOAD(brstack);
-- 
2.38.1.584.g0f3c55d4c2-goog


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 10/12] perf test: Replace brstack test workload
  2022-11-16 23:38 [PATCHSET 00/12] perf test: Add test workloads (v3) Namhyung Kim
                   ` (8 preceding siblings ...)
  2022-11-16 23:38 ` [PATCH 09/12] perf test: Add 'brstack' test workload Namhyung Kim
@ 2022-11-16 23:38 ` Namhyung Kim
  2022-11-16 23:38 ` [PATCH 11/12] perf test: Add 'datasym' " Namhyung Kim
  2022-11-16 23:38 ` [PATCH 12/12] perf test: Replace data symbol test workload with datasym Namhyung Kim
  11 siblings, 0 replies; 26+ messages in thread
From: Namhyung Kim @ 2022-11-16 23:38 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Jiri Olsa
  Cc: Ingo Molnar, Peter Zijlstra, LKML, Ian Rogers, Adrian Hunter,
	linux-perf-users, Leo Yan, German Gomez, Zhengjun Xing,
	James Clark, Athira Jajeev

So that it can get rid of requirement of a compiler.  Also rename the
symbols to match with the perf test workload.

Acked-by: German Gomez <german.gomez@arm.com>
Tested-by: James Clark <james.clark@arm.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/tests/shell/test_brstack.sh | 66 +++++---------------------
 1 file changed, 12 insertions(+), 54 deletions(-)

diff --git a/tools/perf/tests/shell/test_brstack.sh b/tools/perf/tests/shell/test_brstack.sh
index d7ff5c4b4da4..5856639b565b 100755
--- a/tools/perf/tests/shell/test_brstack.sh
+++ b/tools/perf/tests/shell/test_brstack.sh
@@ -4,13 +4,6 @@
 # SPDX-License-Identifier: GPL-2.0
 # German Gomez <german.gomez@arm.com>, 2022
 
-# we need a C compiler to build the test programs
-# so bail if none is found
-if ! [ -x "$(command -v cc)" ]; then
-	echo "failed: no compiler, install gcc"
-	exit 2
-fi
-
 # skip the test if the hardware doesn't support branch stack sampling
 # and if the architecture doesn't support filter types: any,save_type,u
 if ! perf record -o- --no-buildid --branch-filter any,save_type,u -- true > /dev/null 2>&1 ; then
@@ -19,6 +12,7 @@ if ! perf record -o- --no-buildid --branch-filter any,save_type,u -- true > /dev
 fi
 
 TMPDIR=$(mktemp -d /tmp/__perf_test.program.XXXXX)
+TESTPROG="perf test -w brstack"
 
 cleanup() {
 	rm -rf $TMPDIR
@@ -26,57 +20,24 @@ cleanup() {
 
 trap cleanup exit term int
 
-gen_test_program() {
-	# generate test program
-	cat << EOF > $1
-#define BENCH_RUNS 999999
-int cnt;
-void bar(void) {
-}			/* return */
-void foo(void) {
-	bar();		/* call */
-}			/* return */
-void bench(void) {
-  void (*foo_ind)(void) = foo;
-  if ((cnt++) % 3)	/* branch (cond) */
-    foo();		/* call */
-  bar();		/* call */
-  foo_ind();		/* call (ind) */
-}
-int main(void)
-{
-  int cnt = 0;
-  while (1) {
-    if ((cnt++) > BENCH_RUNS)
-      break;
-    bench();		/* call */
-  }			/* branch (uncond) */
-  return 0;
-}
-EOF
-}
-
 test_user_branches() {
 	echo "Testing user branch stack sampling"
 
-	gen_test_program "$TEMPDIR/program.c"
-	cc -fno-inline -g "$TEMPDIR/program.c" -o $TMPDIR/a.out
-
-	perf record -o $TMPDIR/perf.data --branch-filter any,save_type,u -- $TMPDIR/a.out > /dev/null 2>&1
+	perf record -o $TMPDIR/perf.data --branch-filter any,save_type,u -- ${TESTPROG} > /dev/null 2>&1
 	perf script -i $TMPDIR/perf.data --fields brstacksym | xargs -n1 > $TMPDIR/perf.script
 
 	# example of branch entries:
-	# 	foo+0x14/bar+0x40/P/-/-/0/CALL
+	# 	brstack_foo+0x14/brstack_bar+0x40/P/-/-/0/CALL
 
 	set -x
-	egrep -m1 "^bench\+[^ ]*/foo\+[^ ]*/IND_CALL$"	$TMPDIR/perf.script
-	egrep -m1 "^foo\+[^ ]*/bar\+[^ ]*/CALL$"	$TMPDIR/perf.script
-	egrep -m1 "^bench\+[^ ]*/foo\+[^ ]*/CALL$"	$TMPDIR/perf.script
-	egrep -m1 "^bench\+[^ ]*/bar\+[^ ]*/CALL$"	$TMPDIR/perf.script
-	egrep -m1 "^bar\+[^ ]*/foo\+[^ ]*/RET$"		$TMPDIR/perf.script
-	egrep -m1 "^foo\+[^ ]*/bench\+[^ ]*/RET$"	$TMPDIR/perf.script
-	egrep -m1 "^bench\+[^ ]*/bench\+[^ ]*/COND$"	$TMPDIR/perf.script
-	egrep -m1 "^main\+[^ ]*/main\+[^ ]*/UNCOND$"	$TMPDIR/perf.script
+	egrep -m1 "^brstack_bench\+[^ ]*/brstack_foo\+[^ ]*/IND_CALL$"	$TMPDIR/perf.script
+	egrep -m1 "^brstack_foo\+[^ ]*/brstack_bar\+[^ ]*/CALL$"	$TMPDIR/perf.script
+	egrep -m1 "^brstack_bench\+[^ ]*/brstack_foo\+[^ ]*/CALL$"	$TMPDIR/perf.script
+	egrep -m1 "^brstack_bench\+[^ ]*/brstack_bar\+[^ ]*/CALL$"	$TMPDIR/perf.script
+	egrep -m1 "^brstack_bar\+[^ ]*/brstack_foo\+[^ ]*/RET$"		$TMPDIR/perf.script
+	egrep -m1 "^brstack_foo\+[^ ]*/brstack_bench\+[^ ]*/RET$"	$TMPDIR/perf.script
+	egrep -m1 "^brstack_bench\+[^ ]*/brstack_bench\+[^ ]*/COND$"	$TMPDIR/perf.script
+	egrep -m1 "^brstack\+[^ ]*/brstack\+[^ ]*/UNCOND$"		$TMPDIR/perf.script
 	set +x
 
 	# some branch types are still not being tested:
@@ -91,10 +52,7 @@ test_filter() {
 
 	echo "Testing branch stack filtering permutation ($filter,$expect)"
 
-	gen_test_program "$TEMPDIR/program.c"
-	cc -fno-inline -g "$TEMPDIR/program.c" -o $TMPDIR/a.out
-
-	perf record -o $TMPDIR/perf.data --branch-filter $filter,save_type,u -- $TMPDIR/a.out > /dev/null 2>&1
+	perf record -o $TMPDIR/perf.data --branch-filter $filter,save_type,u -- ${TESTPROG} > /dev/null 2>&1
 	perf script -i $TMPDIR/perf.data --fields brstack | xargs -n1 > $TMPDIR/perf.script
 
 	# fail if we find any branch type that doesn't match any of the expected ones
-- 
2.38.1.584.g0f3c55d4c2-goog


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 11/12] perf test: Add 'datasym' test workload
  2022-11-16 23:38 [PATCHSET 00/12] perf test: Add test workloads (v3) Namhyung Kim
                   ` (9 preceding siblings ...)
  2022-11-16 23:38 ` [PATCH 10/12] perf test: Replace brstack " Namhyung Kim
@ 2022-11-16 23:38 ` Namhyung Kim
  2022-11-16 23:38 ` [PATCH 12/12] perf test: Replace data symbol test workload with datasym Namhyung Kim
  11 siblings, 0 replies; 26+ messages in thread
From: Namhyung Kim @ 2022-11-16 23:38 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Jiri Olsa
  Cc: Ingo Molnar, Peter Zijlstra, LKML, Ian Rogers, Adrian Hunter,
	linux-perf-users, Leo Yan, German Gomez, Zhengjun Xing,
	James Clark, Athira Jajeev

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.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/tests/builtin-test.c      |  1 +
 tools/perf/tests/tests.h             |  1 +
 tools/perf/tests/workloads/Build     |  2 ++
 tools/perf/tests/workloads/datasym.c | 24 ++++++++++++++++++++++++
 4 files changed, 28 insertions(+)
 create mode 100644 tools/perf/tests/workloads/datasym.c

diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index 69fa56939309..4c6ae59a4dfd 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -124,6 +124,7 @@ static struct test_workload *workloads[] = {
 	&workload__leafloop,
 	&workload__sqrtloop,
 	&workload__brstack,
+	&workload__datasym,
 };
 
 static int num_subtests(const struct test_suite *t)
diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h
index dc96f59cac2e..e15f24cfc909 100644
--- a/tools/perf/tests/tests.h
+++ b/tools/perf/tests/tests.h
@@ -205,5 +205,6 @@ DECLARE_WORKLOAD(thloop);
 DECLARE_WORKLOAD(leafloop);
 DECLARE_WORKLOAD(sqrtloop);
 DECLARE_WORKLOAD(brstack);
+DECLARE_WORKLOAD(datasym);
 
 #endif /* TESTS_H */
diff --git a/tools/perf/tests/workloads/Build b/tools/perf/tests/workloads/Build
index c933cdcf91d1..ec3cb10c52ae 100644
--- a/tools/perf/tests/workloads/Build
+++ b/tools/perf/tests/workloads/Build
@@ -5,6 +5,8 @@ perf-y += thloop.o
 perf-y += leafloop.o
 perf-y += sqrtloop.o
 perf-y += brstack.o
+perf-y += datasym.o
 
 CFLAGS_leafloop.o         = -g -O0 -fno-inline -fno-omit-frame-pointer
 CFLAGS_brstack.o          = -g -O0 -fno-inline
+CFLAGS_datasym.o          = -g -O0 -fno-inline
diff --git a/tools/perf/tests/workloads/datasym.c b/tools/perf/tests/workloads/datasym.c
new file mode 100644
index 000000000000..ddd40bc63448
--- /dev/null
+++ b/tools/perf/tests/workloads/datasym.c
@@ -0,0 +1,24 @@
+#include <linux/compiler.h>
+#include "../tests.h"
+
+typedef struct _buf {
+	char data1;
+	char reserved[55];
+	char data2;
+} buf __attribute__((aligned(64)));
+
+static buf buf1 = {
+	/* to have this in the data section */
+	.reserved[0] = 1,
+};
+
+static int datasym(int argc __maybe_unused, const char **argv __maybe_unused)
+{
+	for (;;) {
+		buf1.data1++;
+		buf1.data2 += buf1.data1;
+	}
+	return 0;
+}
+
+DEFINE_WORKLOAD(datasym);
-- 
2.38.1.584.g0f3c55d4c2-goog


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 12/12] perf test: Replace data symbol test workload with datasym
  2022-11-16 23:38 [PATCHSET 00/12] perf test: Add test workloads (v3) Namhyung Kim
                   ` (10 preceding siblings ...)
  2022-11-16 23:38 ` [PATCH 11/12] perf test: Add 'datasym' " Namhyung Kim
@ 2022-11-16 23:38 ` Namhyung Kim
  11 siblings, 0 replies; 26+ messages in thread
From: Namhyung Kim @ 2022-11-16 23:38 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Jiri Olsa
  Cc: Ingo Molnar, Peter Zijlstra, LKML, Ian Rogers, Adrian Hunter,
	linux-perf-users, Leo Yan, German Gomez, Zhengjun Xing,
	James Clark, Athira Jajeev

So that it can get rid of requirement of a compiler.

  $ sudo ./perf test -v 109
  109: Test data symbol                                                :
  --- start ---
  test child forked, pid 844526
  Recording workload...
  [ perf record: Woken up 2 times to write data ]
  [ perf record: Captured and wrote 0.354 MB /tmp/__perf_test.perf.data.GFeZO (4847 samples) ]
  Cleaning up files...
  test child finished with 0
  ---- end ----
  Test data symbol: Ok

Cc: Leo Yan <leo.yan@linaro.org>
Tested-by: James Clark <james.clark@arm.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/tests/shell/test_data_symbol.sh | 29 +---------------------
 1 file changed, 1 insertion(+), 28 deletions(-)

diff --git a/tools/perf/tests/shell/test_data_symbol.sh b/tools/perf/tests/shell/test_data_symbol.sh
index cd6eb54d235d..d871e6c743ef 100755
--- a/tools/perf/tests/shell/test_data_symbol.sh
+++ b/tools/perf/tests/shell/test_data_symbol.sh
@@ -11,13 +11,7 @@ skip_if_no_mem_event() {
 
 skip_if_no_mem_event || exit 2
 
-# skip if there's no compiler
-if ! [ -x "$(command -v cc)" ]; then
-	echo "skip: no compiler, install gcc"
-	exit 2
-fi
-
-TEST_PROGRAM=$(mktemp /tmp/__perf_test.program.XXXXX)
+TEST_PROGRAM="perf test -w datasym"
 PERF_DATA=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
 
 check_result() {
@@ -45,31 +39,10 @@ cleanup_files()
 {
 	echo "Cleaning up files..."
 	rm -f ${PERF_DATA}
-	rm -f ${TEST_PROGRAM}
 }
 
 trap cleanup_files exit term int
 
-# compile test program
-echo "Compiling test program..."
-cat << EOF | cc -o ${TEST_PROGRAM} -x c -
-typedef struct _buf {
-	char data1;
-	char reserved[55];
-	char data2;
-} buf __attribute__((aligned(64)));
-
-static buf buf1;
-
-int main(void) {
-	for (;;) {
-		buf1.data1++;
-		buf1.data2 += buf1.data1;
-	}
-	return 0;
-}
-EOF
-
 echo "Recording workload..."
 
 # perf mem/c2c internally uses IBS PMU on AMD CPU which doesn't support
-- 
2.38.1.584.g0f3c55d4c2-goog


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* Re: [PATCH 05/12] perf test: Add 'leafloop' test workload
  2022-11-16 23:38 ` [PATCH 05/12] perf test: Add 'leafloop' test workload Namhyung Kim
@ 2022-11-17 16:06   ` Arnaldo Carvalho de Melo
  2022-11-17 16:15     ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 26+ messages in thread
From: Arnaldo Carvalho de Melo @ 2022-11-17 16:06 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: Jiri Olsa, Ingo Molnar, Peter Zijlstra, LKML, Ian Rogers,
	Adrian Hunter, linux-perf-users, Leo Yan, German Gomez,
	Zhengjun Xing, James Clark, Athira Jajeev

Em Wed, Nov 16, 2022 at 03:38:47PM -0800, Namhyung Kim escreveu:
> The leafloop workload is to run an infinite loop in the test_leaf
> function.  This is needed for the ARM fp callgraph test to verify if it
> gets the correct callchains.
> 
>   $ perf test -w leafloop

On fedora:36

In file included from /usr/include/bits/libc-header-start.h:33,
                 from /usr/include/stdlib.h:26,
                 from tests/workloads/leafloop.c:2:
/usr/include/features.h:412:4: error: #warning _FORTIFY_SOURCE requires compiling with optimization (-O) [-Werror=cpp]
  412 | #  warning _FORTIFY_SOURCE requires compiling with optimization (-O)
      |    ^~~~~~~
cc1: all warnings being treated as errors
make[5]: *** [/home/acme/git/perf/tools/build/Makefile.build:96: /tmp/build/perf/tests/workloads/leafloop.o] Error 1
make[5]: *** Waiting for unfinished jobs....

I'll try removing the _FORTIFY_SOURCE
 
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> ---
>  tools/perf/tests/builtin-test.c       |  1 +
>  tools/perf/tests/tests.h              |  1 +
>  tools/perf/tests/workloads/Build      |  3 +++
>  tools/perf/tests/workloads/leafloop.c | 34 +++++++++++++++++++++++++++
>  4 files changed, 39 insertions(+)
>  create mode 100644 tools/perf/tests/workloads/leafloop.c
> 
> diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
> index 161f38476e77..0ed5ac452f6e 100644
> --- a/tools/perf/tests/builtin-test.c
> +++ b/tools/perf/tests/builtin-test.c
> @@ -121,6 +121,7 @@ static struct test_suite **tests[] = {
>  static struct test_workload *workloads[] = {
>  	&workload__noploop,
>  	&workload__thloop,
> +	&workload__leafloop,
>  };
>  
>  static int num_subtests(const struct test_suite *t)
> diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h
> index e6edfeeadaeb..86804dd6452b 100644
> --- a/tools/perf/tests/tests.h
> +++ b/tools/perf/tests/tests.h
> @@ -202,5 +202,6 @@ struct test_workload workload__##work = {	\
>  /* The list of test workloads */
>  DECLARE_WORKLOAD(noploop);
>  DECLARE_WORKLOAD(thloop);
> +DECLARE_WORKLOAD(leafloop);
>  
>  #endif /* TESTS_H */
> diff --git a/tools/perf/tests/workloads/Build b/tools/perf/tests/workloads/Build
> index b8964b1099c0..631596bdb2b3 100644
> --- a/tools/perf/tests/workloads/Build
> +++ b/tools/perf/tests/workloads/Build
> @@ -2,3 +2,6 @@
>  
>  perf-y += noploop.o
>  perf-y += thloop.o
> +perf-y += leafloop.o
> +
> +CFLAGS_leafloop.o         = -g -O0 -fno-inline -fno-omit-frame-pointer
> diff --git a/tools/perf/tests/workloads/leafloop.c b/tools/perf/tests/workloads/leafloop.c
> new file mode 100644
> index 000000000000..1bf5cc97649b
> --- /dev/null
> +++ b/tools/perf/tests/workloads/leafloop.c
> @@ -0,0 +1,34 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +#include <stdlib.h>
> +#include <linux/compiler.h>
> +#include "../tests.h"
> +
> +/* We want to check these symbols in perf script */
> +noinline void leaf(volatile int b);
> +noinline void parent(volatile int b);
> +
> +static volatile int a;
> +
> +noinline void leaf(volatile int b)
> +{
> +	for (;;)
> +		a += b;
> +}
> +
> +noinline void parent(volatile int b)
> +{
> +	leaf(b);
> +}
> +
> +static int leafloop(int argc, const char **argv)
> +{
> +	int c = 1;
> +
> +	if (argc > 0)
> +		c = atoi(argv[0]);
> +
> +	parent(c);
> +	return 0;
> +}
> +
> +DEFINE_WORKLOAD(leafloop);
> -- 
> 2.38.1.584.g0f3c55d4c2-goog

-- 

- Arnaldo

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 05/12] perf test: Add 'leafloop' test workload
  2022-11-17 16:06   ` Arnaldo Carvalho de Melo
@ 2022-11-17 16:15     ` Arnaldo Carvalho de Melo
  2022-11-17 17:16       ` Ian Rogers
  0 siblings, 1 reply; 26+ messages in thread
From: Arnaldo Carvalho de Melo @ 2022-11-17 16:15 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: Jiri Olsa, Ingo Molnar, Peter Zijlstra, LKML, Ian Rogers,
	Adrian Hunter, linux-perf-users, Leo Yan, German Gomez,
	Zhengjun Xing, James Clark, Athira Jajeev

Em Thu, Nov 17, 2022 at 01:06:16PM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Wed, Nov 16, 2022 at 03:38:47PM -0800, Namhyung Kim escreveu:
> > The leafloop workload is to run an infinite loop in the test_leaf
> > function.  This is needed for the ARM fp callgraph test to verify if it
> > gets the correct callchains.
> > 
> >   $ perf test -w leafloop
> 
> On fedora:36
> 
> In file included from /usr/include/bits/libc-header-start.h:33,
>                  from /usr/include/stdlib.h:26,
>                  from tests/workloads/leafloop.c:2:
> /usr/include/features.h:412:4: error: #warning _FORTIFY_SOURCE requires compiling with optimization (-O) [-Werror=cpp]
>   412 | #  warning _FORTIFY_SOURCE requires compiling with optimization (-O)
>       |    ^~~~~~~
> cc1: all warnings being treated as errors
> make[5]: *** [/home/acme/git/perf/tools/build/Makefile.build:96: /tmp/build/perf/tests/workloads/leafloop.o] Error 1
> make[5]: *** Waiting for unfinished jobs....
> 
> I'll try removing the _FORTIFY_SOURCE

Works after I added this to datasym.c, leafloop.c and brstack.c:


diff --git a/tools/perf/tests/workloads/leafloop.c b/tools/perf/tests/workloads/leafloop.c
index 1bf5cc97649b0e23..5d72c001320e3013 100644
--- a/tools/perf/tests/workloads/leafloop.c
+++ b/tools/perf/tests/workloads/leafloop.c
@@ -1,4 +1,5 @@
 /* SPDX-License-Identifier: GPL-2.0 */
+#undef _FORTIFY_SOURCE
 #include <stdlib.h>
 #include <linux/compiler.h>
 #include "../tests.h"

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* Re: [PATCH 05/12] perf test: Add 'leafloop' test workload
  2022-11-17 16:15     ` Arnaldo Carvalho de Melo
@ 2022-11-17 17:16       ` Ian Rogers
  2022-11-17 17:24         ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 26+ messages in thread
From: Ian Rogers @ 2022-11-17 17:16 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Namhyung Kim, Jiri Olsa, Ingo Molnar, Peter Zijlstra, LKML,
	Adrian Hunter, linux-perf-users, Leo Yan, German Gomez,
	Zhengjun Xing, James Clark, Athira Jajeev

On Thu, Nov 17, 2022 at 8:15 AM Arnaldo Carvalho de Melo
<acme@kernel.org> wrote:
>
> Em Thu, Nov 17, 2022 at 01:06:16PM -0300, Arnaldo Carvalho de Melo escreveu:
> > Em Wed, Nov 16, 2022 at 03:38:47PM -0800, Namhyung Kim escreveu:
> > > The leafloop workload is to run an infinite loop in the test_leaf
> > > function.  This is needed for the ARM fp callgraph test to verify if it
> > > gets the correct callchains.
> > >
> > >   $ perf test -w leafloop
> >
> > On fedora:36
> >
> > In file included from /usr/include/bits/libc-header-start.h:33,
> >                  from /usr/include/stdlib.h:26,
> >                  from tests/workloads/leafloop.c:2:
> > /usr/include/features.h:412:4: error: #warning _FORTIFY_SOURCE requires compiling with optimization (-O) [-Werror=cpp]
> >   412 | #  warning _FORTIFY_SOURCE requires compiling with optimization (-O)
> >       |    ^~~~~~~
> > cc1: all warnings being treated as errors
> > make[5]: *** [/home/acme/git/perf/tools/build/Makefile.build:96: /tmp/build/perf/tests/workloads/leafloop.o] Error 1
> > make[5]: *** Waiting for unfinished jobs....
> >
> > I'll try removing the _FORTIFY_SOURCE
>
> Works after I added this to datasym.c, leafloop.c and brstack.c:

Is there a reason we are compiling without -O ? Perhaps we can filter
setting _FORTIFY_SOURCE so that it depends on -O being enabled.

Thanks,
Ian

> diff --git a/tools/perf/tests/workloads/leafloop.c b/tools/perf/tests/workloads/leafloop.c
> index 1bf5cc97649b0e23..5d72c001320e3013 100644
> --- a/tools/perf/tests/workloads/leafloop.c
> +++ b/tools/perf/tests/workloads/leafloop.c
> @@ -1,4 +1,5 @@
>  /* SPDX-License-Identifier: GPL-2.0 */
> +#undef _FORTIFY_SOURCE
>  #include <stdlib.h>
>  #include <linux/compiler.h>
>  #include "../tests.h"

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 05/12] perf test: Add 'leafloop' test workload
  2022-11-17 17:16       ` Ian Rogers
@ 2022-11-17 17:24         ` Arnaldo Carvalho de Melo
  2022-11-17 17:41           ` Ian Rogers
  0 siblings, 1 reply; 26+ messages in thread
From: Arnaldo Carvalho de Melo @ 2022-11-17 17:24 UTC (permalink / raw)
  To: Ian Rogers
  Cc: Namhyung Kim, Jiri Olsa, Ingo Molnar, Peter Zijlstra, LKML,
	Adrian Hunter, linux-perf-users, Leo Yan, German Gomez,
	Zhengjun Xing, James Clark, Athira Jajeev

Em Thu, Nov 17, 2022 at 09:16:58AM -0800, Ian Rogers escreveu:
> On Thu, Nov 17, 2022 at 8:15 AM Arnaldo Carvalho de Melo
> <acme@kernel.org> wrote:
> >
> > Em Thu, Nov 17, 2022 at 01:06:16PM -0300, Arnaldo Carvalho de Melo escreveu:
> > > Em Wed, Nov 16, 2022 at 03:38:47PM -0800, Namhyung Kim escreveu:
> > > > The leafloop workload is to run an infinite loop in the test_leaf
> > > > function.  This is needed for the ARM fp callgraph test to verify if it
> > > > gets the correct callchains.
> > > >
> > > >   $ perf test -w leafloop
> > >
> > > On fedora:36
> > >
> > > In file included from /usr/include/bits/libc-header-start.h:33,
> > >                  from /usr/include/stdlib.h:26,
> > >                  from tests/workloads/leafloop.c:2:
> > > /usr/include/features.h:412:4: error: #warning _FORTIFY_SOURCE requires compiling with optimization (-O) [-Werror=cpp]
> > >   412 | #  warning _FORTIFY_SOURCE requires compiling with optimization (-O)
> > >       |    ^~~~~~~
> > > cc1: all warnings being treated as errors
> > > make[5]: *** [/home/acme/git/perf/tools/build/Makefile.build:96: /tmp/build/perf/tests/workloads/leafloop.o] Error 1
> > > make[5]: *** Waiting for unfinished jobs....
> > >
> > > I'll try removing the _FORTIFY_SOURCE
> >
> > Works after I added this to datasym.c, leafloop.c and brstack.c:
> 
> Is there a reason we are compiling without -O ? Perhaps we can filter

I assumed so as Namhyung added it, perhaps he is just carrying it from
the pre-existing shell tests?

I wonder its to have a predictable binary output that the test expects
when doing things like hardware tracing? As it come from the coresight
tests, IIRC.

- Arnaldo

> setting _FORTIFY_SOURCE so that it depends on -O being enabled.
 
> Thanks,
> Ian
> 
> > diff --git a/tools/perf/tests/workloads/leafloop.c b/tools/perf/tests/workloads/leafloop.c
> > index 1bf5cc97649b0e23..5d72c001320e3013 100644
> > --- a/tools/perf/tests/workloads/leafloop.c
> > +++ b/tools/perf/tests/workloads/leafloop.c
> > @@ -1,4 +1,5 @@
> >  /* SPDX-License-Identifier: GPL-2.0 */
> > +#undef _FORTIFY_SOURCE
> >  #include <stdlib.h>
> >  #include <linux/compiler.h>
> >  #include "../tests.h"

-- 

- Arnaldo

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 05/12] perf test: Add 'leafloop' test workload
  2022-11-17 17:24         ` Arnaldo Carvalho de Melo
@ 2022-11-17 17:41           ` Ian Rogers
  2022-11-17 18:11             ` Namhyung Kim
  0 siblings, 1 reply; 26+ messages in thread
From: Ian Rogers @ 2022-11-17 17:41 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Namhyung Kim, Jiri Olsa, Ingo Molnar, Peter Zijlstra, LKML,
	Adrian Hunter, linux-perf-users, Leo Yan, German Gomez,
	Zhengjun Xing, James Clark, Athira Jajeev

On Thu, Nov 17, 2022 at 9:24 AM Arnaldo Carvalho de Melo
<acme@kernel.org> wrote:
>
> Em Thu, Nov 17, 2022 at 09:16:58AM -0800, Ian Rogers escreveu:
> > On Thu, Nov 17, 2022 at 8:15 AM Arnaldo Carvalho de Melo
> > <acme@kernel.org> wrote:
> > >
> > > Em Thu, Nov 17, 2022 at 01:06:16PM -0300, Arnaldo Carvalho de Melo escreveu:
> > > > Em Wed, Nov 16, 2022 at 03:38:47PM -0800, Namhyung Kim escreveu:
> > > > > The leafloop workload is to run an infinite loop in the test_leaf
> > > > > function.  This is needed for the ARM fp callgraph test to verify if it
> > > > > gets the correct callchains.
> > > > >
> > > > >   $ perf test -w leafloop
> > > >
> > > > On fedora:36
> > > >
> > > > In file included from /usr/include/bits/libc-header-start.h:33,
> > > >                  from /usr/include/stdlib.h:26,
> > > >                  from tests/workloads/leafloop.c:2:
> > > > /usr/include/features.h:412:4: error: #warning _FORTIFY_SOURCE requires compiling with optimization (-O) [-Werror=cpp]
> > > >   412 | #  warning _FORTIFY_SOURCE requires compiling with optimization (-O)
> > > >       |    ^~~~~~~
> > > > cc1: all warnings being treated as errors
> > > > make[5]: *** [/home/acme/git/perf/tools/build/Makefile.build:96: /tmp/build/perf/tests/workloads/leafloop.o] Error 1
> > > > make[5]: *** Waiting for unfinished jobs....
> > > >
> > > > I'll try removing the _FORTIFY_SOURCE
> > >
> > > Works after I added this to datasym.c, leafloop.c and brstack.c:
> >
> > Is there a reason we are compiling without -O ? Perhaps we can filter
>
> I assumed so as Namhyung added it, perhaps he is just carrying it from
> the pre-existing shell tests?
>
> I wonder its to have a predictable binary output that the test expects
> when doing things like hardware tracing? As it come from the coresight
> tests, IIRC.

Would the following in the Build be better:

```
# Undefine _FORTIFY_SOURCE as it doesn't work with -O0
CFLAGS_leafloop.o         = -g -O0 -fno-inline -fno-omit-frame-pointer
-U_FORTIFY_SOURCE
```

We could also use make's `filter-out`. If we are disabling inlining
then there is also `-fno-optimize-sibling-calls` otherwise we can
still lose stack frames.

Thanks,
Ian

> - Arnaldo
>
> > setting _FORTIFY_SOURCE so that it depends on -O being enabled.
>
> > Thanks,
> > Ian
> >
> > > diff --git a/tools/perf/tests/workloads/leafloop.c b/tools/perf/tests/workloads/leafloop.c
> > > index 1bf5cc97649b0e23..5d72c001320e3013 100644
> > > --- a/tools/perf/tests/workloads/leafloop.c
> > > +++ b/tools/perf/tests/workloads/leafloop.c
> > > @@ -1,4 +1,5 @@
> > >  /* SPDX-License-Identifier: GPL-2.0 */
> > > +#undef _FORTIFY_SOURCE
> > >  #include <stdlib.h>
> > >  #include <linux/compiler.h>
> > >  #include "../tests.h"
>
> --
>
> - Arnaldo

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 05/12] perf test: Add 'leafloop' test workload
  2022-11-17 17:41           ` Ian Rogers
@ 2022-11-17 18:11             ` Namhyung Kim
  2022-11-18 11:32               ` James Clark
  0 siblings, 1 reply; 26+ messages in thread
From: Namhyung Kim @ 2022-11-17 18:11 UTC (permalink / raw)
  To: Ian Rogers, German Gomez
  Cc: Arnaldo Carvalho de Melo, Jiri Olsa, Ingo Molnar, Peter Zijlstra,
	LKML, Adrian Hunter, linux-perf-users, Leo Yan, Zhengjun Xing,
	James Clark, Athira Jajeev

Hi,

On Thu, Nov 17, 2022 at 9:42 AM Ian Rogers <irogers@google.com> wrote:
>
> On Thu, Nov 17, 2022 at 9:24 AM Arnaldo Carvalho de Melo
> <acme@kernel.org> wrote:
> >
> > Em Thu, Nov 17, 2022 at 09:16:58AM -0800, Ian Rogers escreveu:
> > > On Thu, Nov 17, 2022 at 8:15 AM Arnaldo Carvalho de Melo
> > > <acme@kernel.org> wrote:
> > > >
> > > > Em Thu, Nov 17, 2022 at 01:06:16PM -0300, Arnaldo Carvalho de Melo escreveu:
> > > > > Em Wed, Nov 16, 2022 at 03:38:47PM -0800, Namhyung Kim escreveu:
> > > > > > The leafloop workload is to run an infinite loop in the test_leaf
> > > > > > function.  This is needed for the ARM fp callgraph test to verify if it
> > > > > > gets the correct callchains.
> > > > > >
> > > > > >   $ perf test -w leafloop
> > > > >
> > > > > On fedora:36
> > > > >
> > > > > In file included from /usr/include/bits/libc-header-start.h:33,
> > > > >                  from /usr/include/stdlib.h:26,
> > > > >                  from tests/workloads/leafloop.c:2:
> > > > > /usr/include/features.h:412:4: error: #warning _FORTIFY_SOURCE requires compiling with optimization (-O) [-Werror=cpp]
> > > > >   412 | #  warning _FORTIFY_SOURCE requires compiling with optimization (-O)
> > > > >       |    ^~~~~~~
> > > > > cc1: all warnings being treated as errors
> > > > > make[5]: *** [/home/acme/git/perf/tools/build/Makefile.build:96: /tmp/build/perf/tests/workloads/leafloop.o] Error 1
> > > > > make[5]: *** Waiting for unfinished jobs....
> > > > >
> > > > > I'll try removing the _FORTIFY_SOURCE
> > > >
> > > > Works after I added this to datasym.c, leafloop.c and brstack.c:
> > >
> > > Is there a reason we are compiling without -O ? Perhaps we can filter
> >
> > I assumed so as Namhyung added it, perhaps he is just carrying it from
> > the pre-existing shell tests?

Exactly :)

> >
> > I wonder its to have a predictable binary output that the test expects
> > when doing things like hardware tracing? As it come from the coresight
> > tests, IIRC.

I think it just checks frame-pointer based callstacks on ARM to have the
precise results for leaves and their parents.


>
> Would the following in the Build be better:
>
> ```
> # Undefine _FORTIFY_SOURCE as it doesn't work with -O0
> CFLAGS_leafloop.o         = -g -O0 -fno-inline -fno-omit-frame-pointer
> -U_FORTIFY_SOURCE
> ```
>
> We could also use make's `filter-out`. If we are disabling inlining
> then there is also `-fno-optimize-sibling-calls` otherwise we can
> still lose stack frames.

I wonder if it's enough to use -O0 as it's enabled from -O2.
Maybe we can get rid of -fno-inline as well.

German, did you have any concerns for those options?

Thanks,
Namhyung

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 05/12] perf test: Add 'leafloop' test workload
  2022-11-17 18:11             ` Namhyung Kim
@ 2022-11-18 11:32               ` James Clark
  2022-11-18 14:58                 ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 26+ messages in thread
From: James Clark @ 2022-11-18 11:32 UTC (permalink / raw)
  To: Namhyung Kim, Ian Rogers, German Gomez
  Cc: Arnaldo Carvalho de Melo, Jiri Olsa, Ingo Molnar, Peter Zijlstra,
	LKML, Adrian Hunter, linux-perf-users, Leo Yan, Zhengjun Xing,
	Athira Jajeev



On 17/11/2022 18:11, Namhyung Kim wrote:
> Hi,
> 
> On Thu, Nov 17, 2022 at 9:42 AM Ian Rogers <irogers@google.com> wrote:
>>
>> On Thu, Nov 17, 2022 at 9:24 AM Arnaldo Carvalho de Melo
>> <acme@kernel.org> wrote:
>>>
>>> Em Thu, Nov 17, 2022 at 09:16:58AM -0800, Ian Rogers escreveu:
>>>> On Thu, Nov 17, 2022 at 8:15 AM Arnaldo Carvalho de Melo
>>>> <acme@kernel.org> wrote:
>>>>>
>>>>> Em Thu, Nov 17, 2022 at 01:06:16PM -0300, Arnaldo Carvalho de Melo escreveu:
>>>>>> Em Wed, Nov 16, 2022 at 03:38:47PM -0800, Namhyung Kim escreveu:
>>>>>>> The leafloop workload is to run an infinite loop in the test_leaf
>>>>>>> function.  This is needed for the ARM fp callgraph test to verify if it
>>>>>>> gets the correct callchains.
>>>>>>>
>>>>>>>   $ perf test -w leafloop
>>>>>>
>>>>>> On fedora:36
>>>>>>
>>>>>> In file included from /usr/include/bits/libc-header-start.h:33,
>>>>>>                  from /usr/include/stdlib.h:26,
>>>>>>                  from tests/workloads/leafloop.c:2:
>>>>>> /usr/include/features.h:412:4: error: #warning _FORTIFY_SOURCE requires compiling with optimization (-O) [-Werror=cpp]
>>>>>>   412 | #  warning _FORTIFY_SOURCE requires compiling with optimization (-O)
>>>>>>       |    ^~~~~~~
>>>>>> cc1: all warnings being treated as errors
>>>>>> make[5]: *** [/home/acme/git/perf/tools/build/Makefile.build:96: /tmp/build/perf/tests/workloads/leafloop.o] Error 1
>>>>>> make[5]: *** Waiting for unfinished jobs....
>>>>>>
>>>>>> I'll try removing the _FORTIFY_SOURCE
>>>>>
>>>>> Works after I added this to datasym.c, leafloop.c and brstack.c:
>>>>
>>>> Is there a reason we are compiling without -O ? Perhaps we can filter
>>>
>>> I assumed so as Namhyung added it, perhaps he is just carrying it from
>>> the pre-existing shell tests?
> 
> Exactly :)
> 
>>>
>>> I wonder its to have a predictable binary output that the test expects
>>> when doing things like hardware tracing? As it come from the coresight
>>> tests, IIRC.
> 
> I think it just checks frame-pointer based callstacks on ARM to have the
> precise results for leaves and their parents.
> 
> 
>>
>> Would the following in the Build be better:
>>
>> ```
>> # Undefine _FORTIFY_SOURCE as it doesn't work with -O0
>> CFLAGS_leafloop.o         = -g -O0 -fno-inline -fno-omit-frame-pointer
>> -U_FORTIFY_SOURCE
>> ```
>>
>> We could also use make's `filter-out`. If we are disabling inlining
>> then there is also `-fno-optimize-sibling-calls` otherwise we can
>> still lose stack frames.
> 
> I wonder if it's enough to use -O0 as it's enabled from -O2.
> Maybe we can get rid of -fno-inline as well.
> 
> German, did you have any concerns for those options?
> 

Is it possible to go with the -U_FORTIFY_SOURCE option? From looking at
the disassembly, changing -O and the other -f options makes quite a bit
of difference.

It's fairly important to that test because it's testing that the
combination of both frame pointer unwinding and dwarf unwinding result
in the complete stack.

If we change the options I'd have to go back and double check with
different compiler versions that it's still doing the right thing. For
example if a frame pointer is included for the last frame, then the
dwarf bit doesn't get tested.


> Thanks,
> Namhyung

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 05/12] perf test: Add 'leafloop' test workload
  2022-11-18 11:32               ` James Clark
@ 2022-11-18 14:58                 ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 26+ messages in thread
From: Arnaldo Carvalho de Melo @ 2022-11-18 14:58 UTC (permalink / raw)
  To: James Clark
  Cc: Namhyung Kim, Ian Rogers, German Gomez, Jiri Olsa, Ingo Molnar,
	Peter Zijlstra, LKML, Adrian Hunter, linux-perf-users, Leo Yan,
	Zhengjun Xing, Athira Jajeev

Em Fri, Nov 18, 2022 at 11:32:43AM +0000, James Clark escreveu:
> 
> 
> On 17/11/2022 18:11, Namhyung Kim wrote:
> > Hi,
> > 
> > On Thu, Nov 17, 2022 at 9:42 AM Ian Rogers <irogers@google.com> wrote:
> >>
> >> On Thu, Nov 17, 2022 at 9:24 AM Arnaldo Carvalho de Melo
> >> <acme@kernel.org> wrote:
> >>>
> >>> Em Thu, Nov 17, 2022 at 09:16:58AM -0800, Ian Rogers escreveu:
> >>>> On Thu, Nov 17, 2022 at 8:15 AM Arnaldo Carvalho de Melo
> >>>> <acme@kernel.org> wrote:
> >>>>>
> >>>>> Em Thu, Nov 17, 2022 at 01:06:16PM -0300, Arnaldo Carvalho de Melo escreveu:
> >>>>>> Em Wed, Nov 16, 2022 at 03:38:47PM -0800, Namhyung Kim escreveu:
> >>>>>>> The leafloop workload is to run an infinite loop in the test_leaf
> >>>>>>> function.  This is needed for the ARM fp callgraph test to verify if it
> >>>>>>> gets the correct callchains.
> >>>>>>>
> >>>>>>>   $ perf test -w leafloop
> >>>>>>
> >>>>>> On fedora:36
> >>>>>>
> >>>>>> In file included from /usr/include/bits/libc-header-start.h:33,
> >>>>>>                  from /usr/include/stdlib.h:26,
> >>>>>>                  from tests/workloads/leafloop.c:2:
> >>>>>> /usr/include/features.h:412:4: error: #warning _FORTIFY_SOURCE requires compiling with optimization (-O) [-Werror=cpp]
> >>>>>>   412 | #  warning _FORTIFY_SOURCE requires compiling with optimization (-O)
> >>>>>>       |    ^~~~~~~
> >>>>>> cc1: all warnings being treated as errors
> >>>>>> make[5]: *** [/home/acme/git/perf/tools/build/Makefile.build:96: /tmp/build/perf/tests/workloads/leafloop.o] Error 1
> >>>>>> make[5]: *** Waiting for unfinished jobs....
> >>>>>>
> >>>>>> I'll try removing the _FORTIFY_SOURCE
> >>>>>
> >>>>> Works after I added this to datasym.c, leafloop.c and brstack.c:
> >>>>
> >>>> Is there a reason we are compiling without -O ? Perhaps we can filter
> >>>
> >>> I assumed so as Namhyung added it, perhaps he is just carrying it from
> >>> the pre-existing shell tests?
> > 
> > Exactly :)
> > 
> >>>
> >>> I wonder its to have a predictable binary output that the test expects
> >>> when doing things like hardware tracing? As it come from the coresight
> >>> tests, IIRC.
> > 
> > I think it just checks frame-pointer based callstacks on ARM to have the
> > precise results for leaves and their parents.
> > 
> > 
> >>
> >> Would the following in the Build be better:
> >>
> >> ```
> >> # Undefine _FORTIFY_SOURCE as it doesn't work with -O0
> >> CFLAGS_leafloop.o         = -g -O0 -fno-inline -fno-omit-frame-pointer
> >> -U_FORTIFY_SOURCE
> >> ```
> >>
> >> We could also use make's `filter-out`. If we are disabling inlining
> >> then there is also `-fno-optimize-sibling-calls` otherwise we can
> >> still lose stack frames.
> > 
> > I wonder if it's enough to use -O0 as it's enabled from -O2.
> > Maybe we can get rid of -fno-inline as well.
> > 
> > German, did you have any concerns for those options?
> > 
> 
> Is it possible to go with the -U_FORTIFY_SOURCE option? From looking at
> the disassembly, changing -O and the other -f options makes quite a bit
> of difference.

I thought about doing it as a -U_FORTIFY_SOURCE but ended up doing it in
each test as I thought that way to be more robust, i.e. the way the
makefiles get that per-object CFLAGS and add to the global one could
flip and then this would break again.

But if people prefer it in the per-object file Build rule, np.

- Arnaldo
 
> It's fairly important to that test because it's testing that the
> combination of both frame pointer unwinding and dwarf unwinding result
> in the complete stack.
> 
> If we change the options I'd have to go back and double check with
> different compiler versions that it's still doing the right thing. For
> example if a frame pointer is included for the last frame, then the
> dwarf bit doesn't get tested.
> 
> 
> > Thanks,
> > Namhyung

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 08/12] perf test: Replace arm spe fork test workload with sqrtloop
  2022-11-16 23:38 ` [PATCH 08/12] perf test: Replace arm spe fork test workload with sqrtloop Namhyung Kim
@ 2022-11-20 15:39   ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 26+ messages in thread
From: Arnaldo Carvalho de Melo @ 2022-11-20 15:39 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: Jiri Olsa, Ingo Molnar, Peter Zijlstra, LKML, Ian Rogers,
	Adrian Hunter, linux-perf-users, Leo Yan, German Gomez,
	Zhengjun Xing, James Clark, Athira Jajeev

Em Wed, Nov 16, 2022 at 03:38:50PM -0800, Namhyung Kim escreveu:
> So that it can get rid of requirement of a compiler.  I've also removed
> killall as it'll kill perf process now and run the test workload for 10
> sec instead.

   8    73.81 alpine:edge                   : FAIL gcc version 11.2.1 20220219 (Alpine 11.2.1_git20220219)
    tests/workloads/sqrtloop.c:23:3: error: ignoring return value of function declared with const attribute [-Werror,-Wunused-value]
                    sqrt(rand());
                    ^~~~ ~~~~~~
    1 error generated.
    make[4]: *** [/git/perf-6.1.0-rc5/tools/build/Makefile.build:139: workloads] Error 2
    make[3]: *** [/git/perf-6.1.0-rc5/tools/build/Makefile.build:139: tests] Error 2


I'll fix this one, probably just prepending a (void *).

- Arnaldo
 
> Tested-by: Leo Yan <leo.yan@linaro.org>
> Tested-by: James Clark <james.clark@arm.com>
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> ---
>  tools/perf/tests/shell/test_arm_spe_fork.sh | 44 +--------------------
>  1 file changed, 1 insertion(+), 43 deletions(-)
> 
> diff --git a/tools/perf/tests/shell/test_arm_spe_fork.sh b/tools/perf/tests/shell/test_arm_spe_fork.sh
> index c920d3583d30..da810e1b2b9e 100755
> --- a/tools/perf/tests/shell/test_arm_spe_fork.sh
> +++ b/tools/perf/tests/shell/test_arm_spe_fork.sh
> @@ -11,14 +11,7 @@ skip_if_no_arm_spe_event() {
>  
>  skip_if_no_arm_spe_event || exit 2
>  
> -# skip if there's no compiler
> -if ! [ -x "$(command -v cc)" ]; then
> -	echo "failed: no compiler, install gcc"
> -	exit 2
> -fi
> -
> -TEST_PROGRAM_SOURCE=$(mktemp /tmp/__perf_test.program.XXXXX.c)
> -TEST_PROGRAM=$(mktemp /tmp/__perf_test.program.XXXXX)
> +TEST_PROGRAM="perf test -w sqrtloop 10"
>  PERF_DATA=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
>  PERF_RECORD_LOG=$(mktemp /tmp/__perf_test.log.XXXXX)
>  
> @@ -27,43 +20,10 @@ cleanup_files()
>  	echo "Cleaning up files..."
>  	rm -f ${PERF_RECORD_LOG}
>  	rm -f ${PERF_DATA}
> -	rm -f ${TEST_PROGRAM_SOURCE}
> -	rm -f ${TEST_PROGRAM}
>  }
>  
>  trap cleanup_files exit term int
>  
> -# compile test program
> -cat << EOF > $TEST_PROGRAM_SOURCE
> -#include <math.h>
> -#include <stdio.h>
> -#include <stdlib.h>
> -#include <unistd.h>
> -#include <sys/wait.h>
> -
> -int workload() {
> -  while (1)
> -    sqrt(rand());
> -  return 0;
> -}
> -
> -int main() {
> -  switch (fork()) {
> -    case 0:
> -      return workload();
> -    case -1:
> -      return 1;
> -    default:
> -      wait(NULL);
> -  }
> -  return 0;
> -}
> -EOF
> -
> -echo "Compiling test program..."
> -CFLAGS="-lm"
> -cc $TEST_PROGRAM_SOURCE $CFLAGS -o $TEST_PROGRAM || exit 1
> -
>  echo "Recording workload..."
>  perf record -o ${PERF_DATA} -e arm_spe/period=65536/ -vvv -- $TEST_PROGRAM > ${PERF_RECORD_LOG} 2>&1 &
>  PERFPID=$!
> @@ -78,8 +38,6 @@ echo Log lines after 1 second = $log1
>  
>  kill $PERFPID
>  wait $PERFPID
> -# test program may leave an orphan process running the workload
> -killall $(basename $TEST_PROGRAM)
>  
>  if [ "$log0" = "$log1" ];
>  then
> -- 
> 2.38.1.584.g0f3c55d4c2-goog

-- 

- Arnaldo

^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2022-11-20 15:39 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-16 23:38 [PATCHSET 00/12] perf test: Add test workloads (v3) Namhyung Kim
2022-11-16 23:38 ` [PATCH 01/12] perf test: Add -w/--workload option Namhyung Kim
2022-11-16 23:38 ` [PATCH 02/12] perf test: Replace pipe test workload with noploop Namhyung Kim
2022-11-16 23:38 ` [PATCH 03/12] perf test: Add 'thloop' test workload Namhyung Kim
2022-11-16 23:38 ` [PATCH 04/12] perf test: Replace record test workload with thloop Namhyung Kim
2022-11-16 23:38 ` [PATCH 05/12] perf test: Add 'leafloop' test workload Namhyung Kim
2022-11-17 16:06   ` Arnaldo Carvalho de Melo
2022-11-17 16:15     ` Arnaldo Carvalho de Melo
2022-11-17 17:16       ` Ian Rogers
2022-11-17 17:24         ` Arnaldo Carvalho de Melo
2022-11-17 17:41           ` Ian Rogers
2022-11-17 18:11             ` Namhyung Kim
2022-11-18 11:32               ` James Clark
2022-11-18 14:58                 ` Arnaldo Carvalho de Melo
2022-11-16 23:38 ` [PATCH 06/12] perf test: Replace arm callgraph fp test workload with leafloop Namhyung Kim
2022-11-16 23:38 ` [PATCH 07/12] perf test: Add 'sqrtloop' test workload Namhyung Kim
2022-11-16 23:38 ` [PATCH 08/12] perf test: Replace arm spe fork test workload with sqrtloop Namhyung Kim
2022-11-20 15:39   ` Arnaldo Carvalho de Melo
2022-11-16 23:38 ` [PATCH 09/12] perf test: Add 'brstack' test workload Namhyung Kim
2022-11-16 23:38 ` [PATCH 10/12] perf test: Replace brstack " Namhyung Kim
2022-11-16 23:38 ` [PATCH 11/12] perf test: Add 'datasym' " Namhyung Kim
2022-11-16 23:38 ` [PATCH 12/12] perf test: Replace data symbol test workload with datasym Namhyung Kim
  -- strict thread matches above, loose matches on Subject: below --
2022-11-10 18:19 [PATCHSET 00/12] perf test: Add test workloads (v2) Namhyung Kim
2022-11-10 18:19 ` [PATCH 08/12] perf test: Replace arm spe fork test workload with sqrtloop Namhyung Kim
2022-11-14 11:12   ` James Clark
2022-11-09 17:46 [PATCHSET 00/12] perf test: Add test workloads (v1) Namhyung Kim
2022-11-09 17:46 ` [PATCH 08/12] perf test: Replace arm spe fork test workload with sqrtloop Namhyung Kim
2022-11-10 11:45   ` Leo Yan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).