1

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: 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>
This commit is contained in:
Tiezhu Yang 2022-11-10 11:50:08 +08:00 committed by Arnaldo Carvalho de Melo
parent 391f84e555
commit 540f8b5640
5 changed files with 44 additions and 0 deletions

View 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

View 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

View 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);

View 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);
}

View 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 },
};