perf bench syscall: Introduce bench_syscall_common()
authorTiezhu Yang <yangtiezhu@loongson.cn>
Thu, 10 Nov 2022 03:50:06 +0000 (11:50 +0800)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 2 Feb 2023 19:32:19 +0000 (16:32 -0300)
In the current code, there is only a basic syscall benchmark via
getppid, this is not enough. Introduce bench_syscall_common() so that we
can add more syscalls to benchmark.

This is preparation for later patch, no functionality change.

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-3-git-send-email-yangtiezhu@loongson.cn
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/arch/x86/include/uapi/asm/unistd_32.h
tools/arch/x86/include/uapi/asm/unistd_64.h
tools/perf/bench/syscall.c

index e1cc62d238d2f5c7a84bb166bad2801840ae2d0c..4d8873a9f519591a808d67bab8562c63c1b2dc82 100644 (file)
@@ -1,4 +1,7 @@
 /* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __NR_getppid
+#define __NR_getppid 64
+#endif
 #ifndef __NR_gettid
 #define __NR_gettid 224
 #endif
index ce8b7ab12045fc6c5f50cb590fb0537aad572e45..e29038af133c037a7323a20ac446b0a2dfba2efd 100644 (file)
@@ -1,4 +1,7 @@
 /* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __NR_getppid
+#define __NR_getppid 110
+#endif
 #ifndef __NR_gettid
 #define __NR_gettid 186
 #endif
index 9b751016f4b65560ad128153b9e6e1c05590e89f..746fd7171921cf80e92f0a64c244b5e87bdaab26 100644 (file)
@@ -30,25 +30,41 @@ static const char * const bench_syscall_usage[] = {
        NULL
 };
 
-int bench_syscall_basic(int argc, const char **argv)
+static int bench_syscall_common(int argc, const char **argv, int syscall)
 {
        struct timeval start, stop, diff;
        unsigned long long result_usec = 0;
+       const char *name = NULL;
        int i;
 
        argc = parse_options(argc, argv, options, bench_syscall_usage, 0);
 
        gettimeofday(&start, NULL);
 
-       for (i = 0; i < loops; i++)
-               getppid();
+       for (i = 0; i < loops; i++) {
+               switch (syscall) {
+               case __NR_getppid:
+                       getppid();
+                       break;
+               default:
+                       break;
+               }
+       }
 
        gettimeofday(&stop, NULL);
        timersub(&stop, &start, &diff);
 
+       switch (syscall) {
+       case __NR_getppid:
+               name = "getppid()";
+               break;
+       default:
+               break;
+       }
+
        switch (bench_format) {
        case BENCH_FORMAT_DEFAULT:
-               printf("# Executed %'d getppid() calls\n", loops);
+               printf("# Executed %'d %s calls\n", loops, name);
 
                result_usec = diff.tv_sec * 1000000;
                result_usec += diff.tv_usec;
@@ -79,3 +95,8 @@ int bench_syscall_basic(int argc, const char **argv)
 
        return 0;
 }
+
+int bench_syscall_basic(int argc, const char **argv)
+{
+       return bench_syscall_common(argc, argv, __NR_getppid);
+}