[PATCH v2 5/6] perf test: Add timeout to datasym workload

Namhyung Kim posted 6 patches 11 months, 1 week ago
[PATCH v2 5/6] perf test: Add timeout to datasym workload
Posted by Namhyung Kim 11 months, 1 week ago
Unlike others it has an infinite loop that make it annoying to call.
Make it finish after 1 second and handle command-line argument to change
the setting.

Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Leo Yan <leo.yan@arm.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/tests/workloads/datasym.c | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/tools/perf/tests/workloads/datasym.c b/tools/perf/tests/workloads/datasym.c
index 8e08fc75a973e5f7..8ddb2aa6a049e343 100644
--- a/tools/perf/tests/workloads/datasym.c
+++ b/tools/perf/tests/workloads/datasym.c
@@ -1,3 +1,6 @@
+#include <stdlib.h>
+#include <signal.h>
+#include <unistd.h>
 #include <linux/compiler.h>
 #include "../tests.h"
 
@@ -12,9 +15,25 @@ static buf buf1 = {
 	.reserved[0] = 1,
 };
 
-static int datasym(int argc __maybe_unused, const char **argv __maybe_unused)
+static volatile sig_atomic_t done;
+
+static void sighandler(int sig __maybe_unused)
+{
+	done = 1;
+}
+
+static int datasym(int argc, const char **argv)
 {
-	for (;;) {
+	int sec = 1;
+
+	if (argc > 0)
+		sec = atoi(argv[0]);
+
+	signal(SIGINT, sighandler);
+	signal(SIGALRM, sighandler);
+	alarm(sec);
+
+	while (!done) {
 		buf1.data1++;
 		if (buf1.data1 == 123) {
 			/*
-- 
2.48.1.711.g2feabab25a-goog
Re: [PATCH v2 5/6] perf test: Add timeout to datasym workload
Posted by Leo Yan 11 months, 1 week ago
On Mon, Mar 03, 2025 at 06:28:36PM -0800, Namhyung Kim wrote:
> Unlike others it has an infinite loop that make it annoying to call.
> Make it finish after 1 second and handle command-line argument to change
> the setting.
> 
> Cc: Thomas Richter <tmricht@linux.ibm.com>
> Cc: Leo Yan <leo.yan@arm.com>
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>

Reviewed-by: Leo Yan <leo.yan@arm.com>

> ---
>  tools/perf/tests/workloads/datasym.c | 23 +++++++++++++++++++++--
>  1 file changed, 21 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/perf/tests/workloads/datasym.c b/tools/perf/tests/workloads/datasym.c
> index 8e08fc75a973e5f7..8ddb2aa6a049e343 100644
> --- a/tools/perf/tests/workloads/datasym.c
> +++ b/tools/perf/tests/workloads/datasym.c
> @@ -1,3 +1,6 @@
> +#include <stdlib.h>
> +#include <signal.h>
> +#include <unistd.h>
>  #include <linux/compiler.h>
>  #include "../tests.h"
>  
> @@ -12,9 +15,25 @@ static buf buf1 = {
>  	.reserved[0] = 1,
>  };
>  
> -static int datasym(int argc __maybe_unused, const char **argv __maybe_unused)
> +static volatile sig_atomic_t done;
> +
> +static void sighandler(int sig __maybe_unused)
> +{
> +	done = 1;
> +}
> +
> +static int datasym(int argc, const char **argv)
>  {
> -	for (;;) {
> +	int sec = 1;
> +
> +	if (argc > 0)
> +		sec = atoi(argv[0]);
> +
> +	signal(SIGINT, sighandler);
> +	signal(SIGALRM, sighandler);
> +	alarm(sec);
> +
> +	while (!done) {
>  		buf1.data1++;
>  		if (buf1.data1 == 123) {
>  			/*
> -- 
> 2.48.1.711.g2feabab25a-goog
>
Re: [PATCH v2 5/6] perf test: Add timeout to datasym workload
Posted by Thomas Richter 11 months, 1 week ago
On 3/4/25 03:28, Namhyung Kim wrote:
> Unlike others it has an infinite loop that make it annoying to call.
> Make it finish after 1 second and handle command-line argument to change
> the setting.
> 
> Cc: Thomas Richter <tmricht@linux.ibm.com>
> Cc: Leo Yan <leo.yan@arm.com>
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> ---
>  tools/perf/tests/workloads/datasym.c | 23 +++++++++++++++++++++--
>  1 file changed, 21 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/perf/tests/workloads/datasym.c b/tools/perf/tests/workloads/datasym.c
> index 8e08fc75a973e5f7..8ddb2aa6a049e343 100644
> --- a/tools/perf/tests/workloads/datasym.c
> +++ b/tools/perf/tests/workloads/datasym.c
> @@ -1,3 +1,6 @@
> +#include <stdlib.h>
> +#include <signal.h>
> +#include <unistd.h>
>  #include <linux/compiler.h>
>  #include "../tests.h"
>  
> @@ -12,9 +15,25 @@ static buf buf1 = {
>  	.reserved[0] = 1,
>  };
>  
> -static int datasym(int argc __maybe_unused, const char **argv __maybe_unused)
> +static volatile sig_atomic_t done;
> +
> +static void sighandler(int sig __maybe_unused)
> +{
> +	done = 1;
> +}
> +
> +static int datasym(int argc, const char **argv)
>  {
> -	for (;;) {
> +	int sec = 1;
> +
> +	if (argc > 0)
> +		sec = atoi(argv[0]);
> +
> +	signal(SIGINT, sighandler);
> +	signal(SIGALRM, sighandler);
> +	alarm(sec);
> +
> +	while (!done) {
>  		buf1.data1++;
>  		if (buf1.data1 == 123) {
>  			/*

Tested-by: Thomas Richter <tmricht@linux.ibm.com>
-- 
Thomas Richter, Dept 3303, IBM s390 Linux Development, Boeblingen, Germany
--
IBM Deutschland Research & Development GmbH

Vorsitzender des Aufsichtsrats: Wolfgang Wendt

Geschäftsführung: David Faller

Sitz der Gesellschaft: Böblingen / Registergericht: Amtsgericht Stuttgart, HRB 243294