perf bench syscall: Add execve syscall benchmark
authorTiezhu Yang <yangtiezhu@loongson.cn>
Thu, 10 Nov 2022 03:50:08 +0000 (11:50 +0800)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 2 Feb 2023 19:32:19 +0000 (16:32 -0300)
This commit adds the execve syscall benchmark, more syscall benchmarks
can be added in the future.

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/1668052208-14047-5-git-send-email-yangtiezhu@loongson.cn
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/arch/x86/include/uapi/asm/unistd_32.h
tools/arch/x86/include/uapi/asm/unistd_64.h
tools/perf/bench/bench.h
tools/perf/bench/syscall.c
tools/perf/builtin-bench.c

index 053122c79ee142655159a4ce213c834574375f7a..2712d5e03e2eb2315f2b698095f6ffd6be3dc1b1 100644 (file)
@@ -1,4 +1,7 @@
 /* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __NR_execve
+#define __NR_execve 11
+#endif
 #ifndef __NR_getppid
 #define __NR_getppid 64
 #endif
index 54a6c4d93ada5c419dbbf51d3484098526f1b678..a6f7fe84d4df12c53505cfe02298b42306a815e5 100644 (file)
@@ -1,4 +1,7 @@
 /* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __NR_execve
+#define __NR_execve 59
+#endif
 #ifndef __NR_getppid
 #define __NR_getppid 110
 #endif
index 0c58448273da231fe2dcb6bb5476a7275d999ef9..e43893151a3ed23537b9d4480ab72864d038567c 100644 (file)
@@ -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_execve(int argc, const char **argv);
 int bench_mem_memcpy(int argc, const char **argv);
 int bench_mem_memset(int argc, const char **argv);
 int bench_mem_find_bit(int argc, const char **argv);
index 6411b146ba68f4bfa1858d02d348f69460bf009d..fe79f7f3091e1e5c7ea89e930bb4f049516ad3a2 100644 (file)
@@ -14,6 +14,7 @@
 #include <sys/time.h>
 #include <sys/syscall.h>
 #include <sys/types.h>
+#include <sys/wait.h>
 #include <unistd.h>
 #include <stdlib.h>
 
@@ -30,6 +31,27 @@ static const char * const bench_syscall_usage[] = {
        NULL
 };
 
+static void test_execve(void)
+{
+       const char *pathname = "/bin/true";
+       char *const argv[] = { (char *)pathname, NULL };
+       pid_t pid = fork();
+
+       if (pid < 0) {
+               fprintf(stderr, "fork failed\n");
+               exit(1);
+       } else if (pid == 0) {
+               execve(pathname, argv, NULL);
+               fprintf(stderr, "execve /bin/true failed\n");
+               exit(1);
+       } else {
+               if (waitpid(pid, NULL, 0) < 0) {
+                       fprintf(stderr, "waitpid failed\n");
+                       exit(1);
+               }
+       }
+}
+
 static int bench_syscall_common(int argc, const char **argv, int syscall)
 {
        struct timeval start, stop, diff;
@@ -49,6 +71,12 @@ static int bench_syscall_common(int argc, const char **argv, int syscall)
                case __NR_getpgid:
                        getpgid(0);
                        break;
+               case __NR_execve:
+                       test_execve();
+                       /* Only loop 10000 times to save time */
+                       if (i == 10000)
+                               loops = 10000;
+                       break;
                default:
                        break;
                }
@@ -64,6 +92,9 @@ static int bench_syscall_common(int argc, const char **argv, int syscall)
        case __NR_getpgid:
                name = "getpgid()";
                break;
+       case __NR_execve:
+               name = "execve()";
+               break;
        default:
                break;
        }
@@ -111,3 +142,8 @@ int bench_syscall_getpgid(int argc, const char **argv)
 {
        return bench_syscall_common(argc, argv, __NR_getpgid);
 }
+
+int bench_syscall_execve(int argc, const char **argv)
+{
+       return bench_syscall_common(argc, argv, __NR_execve);
+}
index 281b22e0f257ca9cf19c9f3bd0335956a73d9479..814e9afc86f6e983980734b25f0dd6b7a5c8ff19 100644 (file)
@@ -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   },
+       { "execve",     "Benchmark for execve(2) calls",                bench_syscall_execve    },
        { "all",        "Run all syscall benchmarks",                   NULL                    },
        { NULL,         NULL,                                           NULL                    },
 };