Commit 540f8b56 authored by Tiezhu Yang's avatar Tiezhu Yang Committed by Arnaldo Carvalho de Melo

perf bench syscall: Add execve syscall benchmark

This commit adds the execve syscall benchmark, more syscall benchmarks
can be added in the future.
Signed-off-by: default avatarTiezhu Yang <yangtiezhu@loongson.cn>
Acked-by: default avatarNamhyung 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.cnSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 391f84e5
/* SPDX-License-Identifier: GPL-2.0 */ /* SPDX-License-Identifier: GPL-2.0 */
#ifndef __NR_execve
#define __NR_execve 11
#endif
#ifndef __NR_getppid #ifndef __NR_getppid
#define __NR_getppid 64 #define __NR_getppid 64
#endif #endif
......
/* SPDX-License-Identifier: GPL-2.0 */ /* SPDX-License-Identifier: GPL-2.0 */
#ifndef __NR_execve
#define __NR_execve 59
#endif
#ifndef __NR_getppid #ifndef __NR_getppid
#define __NR_getppid 110 #define __NR_getppid 110
#endif #endif
......
...@@ -23,6 +23,7 @@ int bench_sched_messaging(int argc, const char **argv); ...@@ -23,6 +23,7 @@ int bench_sched_messaging(int argc, const char **argv);
int bench_sched_pipe(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_basic(int argc, const char **argv);
int bench_syscall_getpgid(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_memcpy(int argc, const char **argv);
int bench_mem_memset(int argc, const char **argv); int bench_mem_memset(int argc, const char **argv);
int bench_mem_find_bit(int argc, const char **argv); int bench_mem_find_bit(int argc, const char **argv);
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include <sys/time.h> #include <sys/time.h>
#include <sys/syscall.h> #include <sys/syscall.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h> #include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
...@@ -30,6 +31,27 @@ static const char * const bench_syscall_usage[] = { ...@@ -30,6 +31,27 @@ static const char * const bench_syscall_usage[] = {
NULL 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) static int bench_syscall_common(int argc, const char **argv, int syscall)
{ {
struct timeval start, stop, diff; struct timeval start, stop, diff;
...@@ -49,6 +71,12 @@ static int bench_syscall_common(int argc, const char **argv, int syscall) ...@@ -49,6 +71,12 @@ static int bench_syscall_common(int argc, const char **argv, int syscall)
case __NR_getpgid: case __NR_getpgid:
getpgid(0); getpgid(0);
break; break;
case __NR_execve:
test_execve();
/* Only loop 10000 times to save time */
if (i == 10000)
loops = 10000;
break;
default: default:
break; break;
} }
...@@ -64,6 +92,9 @@ static int bench_syscall_common(int argc, const char **argv, int syscall) ...@@ -64,6 +92,9 @@ static int bench_syscall_common(int argc, const char **argv, int syscall)
case __NR_getpgid: case __NR_getpgid:
name = "getpgid()"; name = "getpgid()";
break; break;
case __NR_execve:
name = "execve()";
break;
default: default:
break; break;
} }
...@@ -111,3 +142,8 @@ int bench_syscall_getpgid(int argc, const char **argv) ...@@ -111,3 +142,8 @@ int bench_syscall_getpgid(int argc, const char **argv)
{ {
return bench_syscall_common(argc, argv, __NR_getpgid); 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);
}
...@@ -53,6 +53,7 @@ static struct bench sched_benchmarks[] = { ...@@ -53,6 +53,7 @@ static struct bench sched_benchmarks[] = {
static struct bench syscall_benchmarks[] = { static struct bench syscall_benchmarks[] = {
{ "basic", "Benchmark for basic getppid(2) calls", bench_syscall_basic }, { "basic", "Benchmark for basic getppid(2) calls", bench_syscall_basic },
{ "getpgid", "Benchmark for getpgid(2) calls", bench_syscall_getpgid }, { "getpgid", "Benchmark for getpgid(2) calls", bench_syscall_getpgid },
{ "execve", "Benchmark for execve(2) calls", bench_syscall_execve },
{ "all", "Run all syscall benchmarks", NULL }, { "all", "Run all syscall benchmarks", NULL },
{ NULL, NULL, NULL }, { NULL, NULL, NULL },
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment