[PATCH v3 2/3] perf bench syscall: Add close syscall benchmark
From: Tiezhu Yang
Date: Thu Oct 06 2022 - 03:42:44 EST
This commit adds a simple close syscall benchmark, more syscall
benchmarks can be added in the future.
Here are the test results:
[loongson@linux perf]$ ./perf bench syscall
# List of available benchmarks for collection 'syscall':
basic: Benchmark for basic getppid(2) calls
close: Benchmark for close(2) calls
all: Run all syscall benchmarks
[loongson@linux perf]$ ./perf bench syscall basic
# Running 'syscall/basic' benchmark:
# Executed 10000000 getppid() calls
Total time: 1.956 [sec]
0.195687 usecs/op
5110201 ops/sec
[loongson@linux perf]$ ./perf bench syscall close
# Running 'syscall/close' benchmark:
# Executed 10000000 close() calls
Total time: 6.302 [sec]
0.630297 usecs/op
1586553 ops/sec
[loongson@linux perf]$ ./perf bench syscall all
# Running syscall/basic benchmark...
# Executed 10000000 getppid() calls
Total time: 1.956 [sec]
0.195686 usecs/op
5110232 ops/sec
# Running syscall/close benchmark...
# Executed 10000000 close() calls
Total time: 6.302 [sec]
0.630271 usecs/op
1586619 ops/sec
Signed-off-by: Tiezhu Yang <yangtiezhu@xxxxxxxxxxx>
---
tools/arch/x86/include/uapi/asm/unistd_32.h | 3 +++
tools/arch/x86/include/uapi/asm/unistd_64.h | 3 +++
tools/perf/bench/bench.h | 1 +
tools/perf/bench/syscall.c | 11 +++++++++++
tools/perf/builtin-bench.c | 1 +
5 files changed, 19 insertions(+)
diff --git a/tools/arch/x86/include/uapi/asm/unistd_32.h b/tools/arch/x86/include/uapi/asm/unistd_32.h
index 4a480a0..2f24b0eb 100644
--- a/tools/arch/x86/include/uapi/asm/unistd_32.h
+++ b/tools/arch/x86/include/uapi/asm/unistd_32.h
@@ -2,6 +2,9 @@
#ifndef __NR_perf_event_open
# define __NR_perf_event_open 336
#endif
+#ifndef __NR_close
+# define __NR_close 6
+#endif
#ifndef __NR_futex
# define __NR_futex 240
#endif
diff --git a/tools/arch/x86/include/uapi/asm/unistd_64.h b/tools/arch/x86/include/uapi/asm/unistd_64.h
index 860257f..8eb32b2 100644
--- a/tools/arch/x86/include/uapi/asm/unistd_64.h
+++ b/tools/arch/x86/include/uapi/asm/unistd_64.h
@@ -2,6 +2,9 @@
#ifndef __NR_perf_event_open
# define __NR_perf_event_open 298
#endif
+#ifndef __NR_close
+# define __NR_close 3
+#endif
#ifndef __NR_futex
# define __NR_futex 202
#endif
diff --git a/tools/perf/bench/bench.h b/tools/perf/bench/bench.h
index 6cefb43..916cd47 100644
--- a/tools/perf/bench/bench.h
+++ b/tools/perf/bench/bench.h
@@ -34,6 +34,7 @@ int bench_numa(int argc, const char **argv);
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_close(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);
diff --git a/tools/perf/bench/syscall.c b/tools/perf/bench/syscall.c
index 746fd71..058394b 100644
--- a/tools/perf/bench/syscall.c
+++ b/tools/perf/bench/syscall.c
@@ -46,6 +46,9 @@ static int bench_syscall_common(int argc, const char **argv, int syscall)
case __NR_getppid:
getppid();
break;
+ case __NR_close:
+ close(dup(0));
+ break;
default:
break;
}
@@ -58,6 +61,9 @@ static int bench_syscall_common(int argc, const char **argv, int syscall)
case __NR_getppid:
name = "getppid()";
break;
+ case __NR_close:
+ name = "close()";
+ break;
default:
break;
}
@@ -100,3 +106,8 @@ int bench_syscall_basic(int argc, const char **argv)
{
return bench_syscall_common(argc, argv, __NR_getppid);
}
+
+int bench_syscall_close(int argc, const char **argv)
+{
+ return bench_syscall_common(argc, argv, __NR_close);
+}
diff --git a/tools/perf/builtin-bench.c b/tools/perf/builtin-bench.c
index 334ab89..b63c711 100644
--- a/tools/perf/builtin-bench.c
+++ b/tools/perf/builtin-bench.c
@@ -52,6 +52,7 @@ static struct bench sched_benchmarks[] = {
static struct bench syscall_benchmarks[] = {
{ "basic", "Benchmark for basic getppid(2) calls", bench_syscall_basic },
+ { "close", "Benchmark for close(2) calls", bench_syscall_close },
{ "all", "Run all syscall benchmarks", NULL },
{ NULL, NULL, NULL },
};
--
2.1.0