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

perf bench syscall: Add fork syscall benchmark

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: default avatarNamhyung Kim <namhyung@kernel.org>
Signed-off-by: default avatarTiezhu Yang <yangtiezhu@loongson.cn>
Acked-by: default avatarNamhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ian Rogers <irogers@google.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>
Cc: loongson-kernel@lists.loongnix.cn
Link: https://lore.kernel.org/r/1679381821-22736-1-git-send-email-yangtiezhu@loongson.cnSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 51ea4cb9
/* SPDX-License-Identifier: GPL-2.0 */ /* SPDX-License-Identifier: GPL-2.0 */
#ifndef __NR_execve #ifndef __NR_fork
#define __NR_execve 11 #define __NR_fork 2
#endif #endif
#ifndef __NR_getppid #ifndef __NR_getppid
#define __NR_getppid 64 #define __NR_getppid 64
......
/* SPDX-License-Identifier: GPL-2.0 */ /* SPDX-License-Identifier: GPL-2.0 */
#ifndef __NR_fork
#define __NR_fork 57
#endif
#ifndef __NR_execve #ifndef __NR_execve
#define __NR_execve 59 #define __NR_execve 59
#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_fork(int argc, const char **argv);
int bench_syscall_execve(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);
......
...@@ -18,6 +18,10 @@ ...@@ -18,6 +18,10 @@
#include <unistd.h> #include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
#ifndef __NR_fork
#define __NR_fork -1
#endif
#define LOOPS_DEFAULT 10000000 #define LOOPS_DEFAULT 10000000
static int loops = LOOPS_DEFAULT; static int loops = LOOPS_DEFAULT;
...@@ -31,6 +35,23 @@ static const char * const bench_syscall_usage[] = { ...@@ -31,6 +35,23 @@ static const char * const bench_syscall_usage[] = {
NULL 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) static void test_execve(void)
{ {
const char *pathname = "/bin/true"; const char *pathname = "/bin/true";
...@@ -71,6 +92,12 @@ static int bench_syscall_common(int argc, const char **argv, int syscall) ...@@ -71,6 +92,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_fork:
test_fork();
/* Only loop 10000 times to save time */
if (i == 10000)
loops = 10000;
break;
case __NR_execve: case __NR_execve:
test_execve(); test_execve();
/* Only loop 10000 times to save time */ /* Only loop 10000 times to save time */
...@@ -92,6 +119,9 @@ static int bench_syscall_common(int argc, const char **argv, int syscall) ...@@ -92,6 +119,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_fork:
name = "fork()";
break;
case __NR_execve: case __NR_execve:
name = "execve()"; name = "execve()";
break; break;
...@@ -143,6 +173,11 @@ int bench_syscall_getpgid(int argc, const char **argv) ...@@ -143,6 +173,11 @@ 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_fork(int argc, const char **argv)
{
return bench_syscall_common(argc, argv, __NR_fork);
}
int bench_syscall_execve(int argc, const char **argv) int bench_syscall_execve(int argc, const char **argv)
{ {
return bench_syscall_common(argc, argv, __NR_execve); 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 },
{ "fork", "Benchmark for fork(2) calls", bench_syscall_fork },
{ "execve", "Benchmark for execve(2) calls", bench_syscall_execve }, { "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