@@ -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
@@ -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
@@ -35,6 +35,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_getpgrp(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);
@@ -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_getpgrp:
getpgrp();
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_getpgrp:
name = "getpgrp()";
break;
+ case __NR_execve:
+ name = "execve()";
+ break;
default:
break;
}
@@ -111,3 +142,8 @@ int bench_syscall_getpgrp(int argc, const char **argv)
{
return bench_syscall_common(argc, argv, __NR_getpgrp);
}
+
+int bench_syscall_execve(int argc, const char **argv)
+{
+ return bench_syscall_common(argc, argv, __NR_execve);
+}
@@ -53,6 +53,7 @@ static struct bench sched_benchmarks[] = {
static struct bench syscall_benchmarks[] = {
{ "basic", "Benchmark for basic getppid(2) calls", bench_syscall_basic },
{ "getpgrp", "Benchmark for getpgrp(2) calls", bench_syscall_getpgrp },
+ { "execve", "Benchmark for execve(2) calls", bench_syscall_execve },
{ "all", "Run all syscall benchmarks", NULL },
{ NULL, NULL, NULL },
};