linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] perf bench syscall: Add fork syscall benchmark
@ 2023-03-21  6:57 Tiezhu Yang
  2023-03-25  4:31 ` Namhyung Kim
  0 siblings, 1 reply; 3+ messages in thread
From: Tiezhu Yang @ 2023-03-21  6:57 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	Ian Rogers, Adrian Hunter
  Cc: linux-perf-users, linux-kernel, loongson-kernel

This is a follow up patch for the execve bench which is actually
fork + execve, it makes sense to add the fork syscall benchmark
to compare the execve part precisely.

Some archs have no __NR_fork definition which is used only as a
check condition to call test_fork(), let us just define it as -1
to avoid build error.

Suggested-by: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
---
 tools/arch/x86/include/uapi/asm/unistd_32.h |  4 ++--
 tools/arch/x86/include/uapi/asm/unistd_64.h |  3 +++
 tools/perf/bench/bench.h                    |  1 +
 tools/perf/bench/syscall.c                  | 35 +++++++++++++++++++++++++++++
 tools/perf/builtin-bench.c                  |  1 +
 5 files changed, 42 insertions(+), 2 deletions(-)

diff --git a/tools/arch/x86/include/uapi/asm/unistd_32.h b/tools/arch/x86/include/uapi/asm/unistd_32.h
index 2712d5e..b8ddfc4 100644
--- a/tools/arch/x86/include/uapi/asm/unistd_32.h
+++ b/tools/arch/x86/include/uapi/asm/unistd_32.h
@@ -1,6 +1,6 @@
 /* SPDX-License-Identifier: GPL-2.0 */
-#ifndef __NR_execve
-#define __NR_execve 11
+#ifndef __NR_fork
+#define __NR_fork 2
 #endif
 #ifndef __NR_getppid
 #define __NR_getppid 64
diff --git a/tools/arch/x86/include/uapi/asm/unistd_64.h b/tools/arch/x86/include/uapi/asm/unistd_64.h
index a6f7fe8..f70d2cad 100644
--- a/tools/arch/x86/include/uapi/asm/unistd_64.h
+++ b/tools/arch/x86/include/uapi/asm/unistd_64.h
@@ -1,4 +1,7 @@
 /* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __NR_fork
+#define __NR_fork 57
+#endif
 #ifndef __NR_execve
 #define __NR_execve 59
 #endif
diff --git a/tools/perf/bench/bench.h b/tools/perf/bench/bench.h
index e438931..edfc257 100644
--- a/tools/perf/bench/bench.h
+++ b/tools/perf/bench/bench.h
@@ -23,6 +23,7 @@ int bench_sched_messaging(int argc, const char **argv);
 int bench_sched_pipe(int argc, const char **argv);
 int bench_syscall_basic(int argc, const char **argv);
 int bench_syscall_getpgid(int argc, const char **argv);
+int bench_syscall_fork(int argc, const char **argv);
 int bench_syscall_execve(int argc, const char **argv);
 int bench_mem_memcpy(int argc, const char **argv);
 int bench_mem_memset(int argc, const char **argv);
diff --git a/tools/perf/bench/syscall.c b/tools/perf/bench/syscall.c
index fe79f7f..ea4dfc07 100644
--- a/tools/perf/bench/syscall.c
+++ b/tools/perf/bench/syscall.c
@@ -18,6 +18,10 @@
 #include <unistd.h>
 #include <stdlib.h>
 
+#ifndef __NR_fork
+#define __NR_fork -1
+#endif
+
 #define LOOPS_DEFAULT 10000000
 static	int loops = LOOPS_DEFAULT;
 
@@ -31,6 +35,23 @@ static const char * const bench_syscall_usage[] = {
 	NULL
 };
 
+static void test_fork(void)
+{
+	pid_t pid = fork();
+
+	if (pid < 0) {
+		fprintf(stderr, "fork failed\n");
+		exit(1);
+	} else if (pid == 0) {
+		exit(0);
+	} else {
+		if (waitpid(pid, NULL, 0) < 0) {
+			fprintf(stderr, "waitpid failed\n");
+			exit(1);
+		}
+	}
+}
+
 static void test_execve(void)
 {
 	const char *pathname = "/bin/true";
@@ -71,6 +92,12 @@ static int bench_syscall_common(int argc, const char **argv, int syscall)
 		case __NR_getpgid:
 			getpgid(0);
 			break;
+		case __NR_fork:
+			test_fork();
+			/* Only loop 10000 times to save time */
+			if (i == 10000)
+				loops = 10000;
+			break;
 		case __NR_execve:
 			test_execve();
 			/* Only loop 10000 times to save time */
@@ -92,6 +119,9 @@ static int bench_syscall_common(int argc, const char **argv, int syscall)
 	case __NR_getpgid:
 		name = "getpgid()";
 		break;
+	case __NR_fork:
+		name = "fork()";
+		break;
 	case __NR_execve:
 		name = "execve()";
 		break;
@@ -143,6 +173,11 @@ int bench_syscall_getpgid(int argc, const char **argv)
 	return bench_syscall_common(argc, argv, __NR_getpgid);
 }
 
+int bench_syscall_fork(int argc, const char **argv)
+{
+	return bench_syscall_common(argc, argv, __NR_fork);
+}
+
 int bench_syscall_execve(int argc, const char **argv)
 {
 	return bench_syscall_common(argc, argv, __NR_execve);
diff --git a/tools/perf/builtin-bench.c b/tools/perf/builtin-bench.c
index 814e9af..d0fcc3c 100644
--- a/tools/perf/builtin-bench.c
+++ b/tools/perf/builtin-bench.c
@@ -53,6 +53,7 @@ static struct bench sched_benchmarks[] = {
 static struct bench syscall_benchmarks[] = {
 	{ "basic",	"Benchmark for basic getppid(2) calls",		bench_syscall_basic	},
 	{ "getpgid",	"Benchmark for getpgid(2) calls",		bench_syscall_getpgid	},
+	{ "fork",	"Benchmark for fork(2) calls",			bench_syscall_fork	},
 	{ "execve",	"Benchmark for execve(2) calls",		bench_syscall_execve	},
 	{ "all",	"Run all syscall benchmarks",			NULL			},
 	{ NULL,		NULL,						NULL			},
-- 
2.1.0


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

* Re: [PATCH] perf bench syscall: Add fork syscall benchmark
  2023-03-21  6:57 [PATCH] perf bench syscall: Add fork syscall benchmark Tiezhu Yang
@ 2023-03-25  4:31 ` Namhyung Kim
  2023-03-27 11:32   ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 3+ messages in thread
From: Namhyung Kim @ 2023-03-25  4:31 UTC (permalink / raw)
  To: Tiezhu Yang
  Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Ian Rogers,
	Adrian Hunter, linux-perf-users, linux-kernel, loongson-kernel

Hello,

On Mon, Mar 20, 2023 at 11:57 PM Tiezhu Yang <yangtiezhu@loongson.cn> wrote:
>
> This is a follow up patch for the execve bench which is actually
> fork + execve, it makes sense to add the fork syscall benchmark
> to compare the execve part precisely.
>
> Some archs have no __NR_fork definition which is used only as a
> check condition to call test_fork(), let us just define it as -1
> to avoid build error.
>
> Suggested-by: Namhyung Kim <namhyung@kernel.org>
> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>

Acked-by: Namhyung Kim <namhyung@kernel.org>

Thanks,
Namhyung


> ---
>  tools/arch/x86/include/uapi/asm/unistd_32.h |  4 ++--
>  tools/arch/x86/include/uapi/asm/unistd_64.h |  3 +++
>  tools/perf/bench/bench.h                    |  1 +
>  tools/perf/bench/syscall.c                  | 35 +++++++++++++++++++++++++++++
>  tools/perf/builtin-bench.c                  |  1 +
>  5 files changed, 42 insertions(+), 2 deletions(-)
>
> diff --git a/tools/arch/x86/include/uapi/asm/unistd_32.h b/tools/arch/x86/include/uapi/asm/unistd_32.h
> index 2712d5e..b8ddfc4 100644
> --- a/tools/arch/x86/include/uapi/asm/unistd_32.h
> +++ b/tools/arch/x86/include/uapi/asm/unistd_32.h
> @@ -1,6 +1,6 @@
>  /* SPDX-License-Identifier: GPL-2.0 */
> -#ifndef __NR_execve
> -#define __NR_execve 11
> +#ifndef __NR_fork
> +#define __NR_fork 2
>  #endif
>  #ifndef __NR_getppid
>  #define __NR_getppid 64
> diff --git a/tools/arch/x86/include/uapi/asm/unistd_64.h b/tools/arch/x86/include/uapi/asm/unistd_64.h
> index a6f7fe8..f70d2cad 100644
> --- a/tools/arch/x86/include/uapi/asm/unistd_64.h
> +++ b/tools/arch/x86/include/uapi/asm/unistd_64.h
> @@ -1,4 +1,7 @@
>  /* SPDX-License-Identifier: GPL-2.0 */
> +#ifndef __NR_fork
> +#define __NR_fork 57
> +#endif
>  #ifndef __NR_execve
>  #define __NR_execve 59
>  #endif
> diff --git a/tools/perf/bench/bench.h b/tools/perf/bench/bench.h
> index e438931..edfc257 100644
> --- a/tools/perf/bench/bench.h
> +++ b/tools/perf/bench/bench.h
> @@ -23,6 +23,7 @@ int bench_sched_messaging(int argc, const char **argv);
>  int bench_sched_pipe(int argc, const char **argv);
>  int bench_syscall_basic(int argc, const char **argv);
>  int bench_syscall_getpgid(int argc, const char **argv);
> +int bench_syscall_fork(int argc, const char **argv);
>  int bench_syscall_execve(int argc, const char **argv);
>  int bench_mem_memcpy(int argc, const char **argv);
>  int bench_mem_memset(int argc, const char **argv);
> diff --git a/tools/perf/bench/syscall.c b/tools/perf/bench/syscall.c
> index fe79f7f..ea4dfc07 100644
> --- a/tools/perf/bench/syscall.c
> +++ b/tools/perf/bench/syscall.c
> @@ -18,6 +18,10 @@
>  #include <unistd.h>
>  #include <stdlib.h>
>
> +#ifndef __NR_fork
> +#define __NR_fork -1
> +#endif
> +
>  #define LOOPS_DEFAULT 10000000
>  static int loops = LOOPS_DEFAULT;
>
> @@ -31,6 +35,23 @@ static const char * const bench_syscall_usage[] = {
>         NULL
>  };
>
> +static void test_fork(void)
> +{
> +       pid_t pid = fork();
> +
> +       if (pid < 0) {
> +               fprintf(stderr, "fork failed\n");
> +               exit(1);
> +       } else if (pid == 0) {
> +               exit(0);
> +       } else {
> +               if (waitpid(pid, NULL, 0) < 0) {
> +                       fprintf(stderr, "waitpid failed\n");
> +                       exit(1);
> +               }
> +       }
> +}
> +
>  static void test_execve(void)
>  {
>         const char *pathname = "/bin/true";
> @@ -71,6 +92,12 @@ static int bench_syscall_common(int argc, const char **argv, int syscall)
>                 case __NR_getpgid:
>                         getpgid(0);
>                         break;
> +               case __NR_fork:
> +                       test_fork();
> +                       /* Only loop 10000 times to save time */
> +                       if (i == 10000)
> +                               loops = 10000;
> +                       break;
>                 case __NR_execve:
>                         test_execve();
>                         /* Only loop 10000 times to save time */
> @@ -92,6 +119,9 @@ static int bench_syscall_common(int argc, const char **argv, int syscall)
>         case __NR_getpgid:
>                 name = "getpgid()";
>                 break;
> +       case __NR_fork:
> +               name = "fork()";
> +               break;
>         case __NR_execve:
>                 name = "execve()";
>                 break;
> @@ -143,6 +173,11 @@ int bench_syscall_getpgid(int argc, const char **argv)
>         return bench_syscall_common(argc, argv, __NR_getpgid);
>  }
>
> +int bench_syscall_fork(int argc, const char **argv)
> +{
> +       return bench_syscall_common(argc, argv, __NR_fork);
> +}
> +
>  int bench_syscall_execve(int argc, const char **argv)
>  {
>         return bench_syscall_common(argc, argv, __NR_execve);
> diff --git a/tools/perf/builtin-bench.c b/tools/perf/builtin-bench.c
> index 814e9af..d0fcc3c 100644
> --- a/tools/perf/builtin-bench.c
> +++ b/tools/perf/builtin-bench.c
> @@ -53,6 +53,7 @@ static struct bench sched_benchmarks[] = {
>  static struct bench syscall_benchmarks[] = {
>         { "basic",      "Benchmark for basic getppid(2) calls",         bench_syscall_basic     },
>         { "getpgid",    "Benchmark for getpgid(2) calls",               bench_syscall_getpgid   },
> +       { "fork",       "Benchmark for fork(2) calls",                  bench_syscall_fork      },
>         { "execve",     "Benchmark for execve(2) calls",                bench_syscall_execve    },
>         { "all",        "Run all syscall benchmarks",                   NULL                    },
>         { NULL,         NULL,                                           NULL                    },
> --
> 2.1.0
>

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

* Re: [PATCH] perf bench syscall: Add fork syscall benchmark
  2023-03-25  4:31 ` Namhyung Kim
@ 2023-03-27 11:32   ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 3+ messages in thread
From: Arnaldo Carvalho de Melo @ 2023-03-27 11:32 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: Tiezhu Yang, Peter Zijlstra, Ingo Molnar, Mark Rutland,
	Alexander Shishkin, Jiri Olsa, Ian Rogers, Adrian Hunter,
	linux-perf-users, linux-kernel, loongson-kernel

Em Fri, Mar 24, 2023 at 09:31:25PM -0700, Namhyung Kim escreveu:
> Hello,
> 
> On Mon, Mar 20, 2023 at 11:57 PM Tiezhu Yang <yangtiezhu@loongson.cn> wrote:
> >
> > This is a follow up patch for the execve bench which is actually
> > fork + execve, it makes sense to add the fork syscall benchmark
> > to compare the execve part precisely.
> >
> > Some archs have no __NR_fork definition which is used only as a
> > check condition to call test_fork(), let us just define it as -1
> > to avoid build error.
> >
> > Suggested-by: Namhyung Kim <namhyung@kernel.org>
> > Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
> 
> Acked-by: Namhyung Kim <namhyung@kernel.org>

Thanks, applied.

- Arnaldo

 
> Thanks,
> Namhyung
> 
> 
> > ---
> >  tools/arch/x86/include/uapi/asm/unistd_32.h |  4 ++--
> >  tools/arch/x86/include/uapi/asm/unistd_64.h |  3 +++
> >  tools/perf/bench/bench.h                    |  1 +
> >  tools/perf/bench/syscall.c                  | 35 +++++++++++++++++++++++++++++
> >  tools/perf/builtin-bench.c                  |  1 +
> >  5 files changed, 42 insertions(+), 2 deletions(-)
> >
> > diff --git a/tools/arch/x86/include/uapi/asm/unistd_32.h b/tools/arch/x86/include/uapi/asm/unistd_32.h
> > index 2712d5e..b8ddfc4 100644
> > --- a/tools/arch/x86/include/uapi/asm/unistd_32.h
> > +++ b/tools/arch/x86/include/uapi/asm/unistd_32.h
> > @@ -1,6 +1,6 @@
> >  /* SPDX-License-Identifier: GPL-2.0 */
> > -#ifndef __NR_execve
> > -#define __NR_execve 11
> > +#ifndef __NR_fork
> > +#define __NR_fork 2
> >  #endif
> >  #ifndef __NR_getppid
> >  #define __NR_getppid 64
> > diff --git a/tools/arch/x86/include/uapi/asm/unistd_64.h b/tools/arch/x86/include/uapi/asm/unistd_64.h
> > index a6f7fe8..f70d2cad 100644
> > --- a/tools/arch/x86/include/uapi/asm/unistd_64.h
> > +++ b/tools/arch/x86/include/uapi/asm/unistd_64.h
> > @@ -1,4 +1,7 @@
> >  /* SPDX-License-Identifier: GPL-2.0 */
> > +#ifndef __NR_fork
> > +#define __NR_fork 57
> > +#endif
> >  #ifndef __NR_execve
> >  #define __NR_execve 59
> >  #endif
> > diff --git a/tools/perf/bench/bench.h b/tools/perf/bench/bench.h
> > index e438931..edfc257 100644
> > --- a/tools/perf/bench/bench.h
> > +++ b/tools/perf/bench/bench.h
> > @@ -23,6 +23,7 @@ int bench_sched_messaging(int argc, const char **argv);
> >  int bench_sched_pipe(int argc, const char **argv);
> >  int bench_syscall_basic(int argc, const char **argv);
> >  int bench_syscall_getpgid(int argc, const char **argv);
> > +int bench_syscall_fork(int argc, const char **argv);
> >  int bench_syscall_execve(int argc, const char **argv);
> >  int bench_mem_memcpy(int argc, const char **argv);
> >  int bench_mem_memset(int argc, const char **argv);
> > diff --git a/tools/perf/bench/syscall.c b/tools/perf/bench/syscall.c
> > index fe79f7f..ea4dfc07 100644
> > --- a/tools/perf/bench/syscall.c
> > +++ b/tools/perf/bench/syscall.c
> > @@ -18,6 +18,10 @@
> >  #include <unistd.h>
> >  #include <stdlib.h>
> >
> > +#ifndef __NR_fork
> > +#define __NR_fork -1
> > +#endif
> > +
> >  #define LOOPS_DEFAULT 10000000
> >  static int loops = LOOPS_DEFAULT;
> >
> > @@ -31,6 +35,23 @@ static const char * const bench_syscall_usage[] = {
> >         NULL
> >  };
> >
> > +static void test_fork(void)
> > +{
> > +       pid_t pid = fork();
> > +
> > +       if (pid < 0) {
> > +               fprintf(stderr, "fork failed\n");
> > +               exit(1);
> > +       } else if (pid == 0) {
> > +               exit(0);
> > +       } else {
> > +               if (waitpid(pid, NULL, 0) < 0) {
> > +                       fprintf(stderr, "waitpid failed\n");
> > +                       exit(1);
> > +               }
> > +       }
> > +}
> > +
> >  static void test_execve(void)
> >  {
> >         const char *pathname = "/bin/true";
> > @@ -71,6 +92,12 @@ static int bench_syscall_common(int argc, const char **argv, int syscall)
> >                 case __NR_getpgid:
> >                         getpgid(0);
> >                         break;
> > +               case __NR_fork:
> > +                       test_fork();
> > +                       /* Only loop 10000 times to save time */
> > +                       if (i == 10000)
> > +                               loops = 10000;
> > +                       break;
> >                 case __NR_execve:
> >                         test_execve();
> >                         /* Only loop 10000 times to save time */
> > @@ -92,6 +119,9 @@ static int bench_syscall_common(int argc, const char **argv, int syscall)
> >         case __NR_getpgid:
> >                 name = "getpgid()";
> >                 break;
> > +       case __NR_fork:
> > +               name = "fork()";
> > +               break;
> >         case __NR_execve:
> >                 name = "execve()";
> >                 break;
> > @@ -143,6 +173,11 @@ int bench_syscall_getpgid(int argc, const char **argv)
> >         return bench_syscall_common(argc, argv, __NR_getpgid);
> >  }
> >
> > +int bench_syscall_fork(int argc, const char **argv)
> > +{
> > +       return bench_syscall_common(argc, argv, __NR_fork);
> > +}
> > +
> >  int bench_syscall_execve(int argc, const char **argv)
> >  {
> >         return bench_syscall_common(argc, argv, __NR_execve);
> > diff --git a/tools/perf/builtin-bench.c b/tools/perf/builtin-bench.c
> > index 814e9af..d0fcc3c 100644
> > --- a/tools/perf/builtin-bench.c
> > +++ b/tools/perf/builtin-bench.c
> > @@ -53,6 +53,7 @@ static struct bench sched_benchmarks[] = {
> >  static struct bench syscall_benchmarks[] = {
> >         { "basic",      "Benchmark for basic getppid(2) calls",         bench_syscall_basic     },
> >         { "getpgid",    "Benchmark for getpgid(2) calls",               bench_syscall_getpgid   },
> > +       { "fork",       "Benchmark for fork(2) calls",                  bench_syscall_fork      },
> >         { "execve",     "Benchmark for execve(2) calls",                bench_syscall_execve    },
> >         { "all",        "Run all syscall benchmarks",                   NULL                    },
> >         { NULL,         NULL,                                           NULL                    },
> > --
> > 2.1.0
> >

-- 

- Arnaldo

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

end of thread, other threads:[~2023-03-27 11:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-21  6:57 [PATCH] perf bench syscall: Add fork syscall benchmark Tiezhu Yang
2023-03-25  4:31 ` Namhyung Kim
2023-03-27 11:32   ` Arnaldo Carvalho de Melo

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).