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

perf bench syscall: Introduce bench_syscall_common()

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: 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-3-git-send-email-yangtiezhu@loongson.cnSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 1bad5027
/* SPDX-License-Identifier: GPL-2.0 */ /* SPDX-License-Identifier: GPL-2.0 */
#ifndef __NR_getppid
#define __NR_getppid 64
#endif
#ifndef __NR_gettid #ifndef __NR_gettid
#define __NR_gettid 224 #define __NR_gettid 224
#endif #endif
......
/* SPDX-License-Identifier: GPL-2.0 */ /* SPDX-License-Identifier: GPL-2.0 */
#ifndef __NR_getppid
#define __NR_getppid 110
#endif
#ifndef __NR_gettid #ifndef __NR_gettid
#define __NR_gettid 186 #define __NR_gettid 186
#endif #endif
......
...@@ -30,25 +30,41 @@ static const char * const bench_syscall_usage[] = { ...@@ -30,25 +30,41 @@ static const char * const bench_syscall_usage[] = {
NULL 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; struct timeval start, stop, diff;
unsigned long long result_usec = 0; unsigned long long result_usec = 0;
const char *name = NULL;
int i; int i;
argc = parse_options(argc, argv, options, bench_syscall_usage, 0); argc = parse_options(argc, argv, options, bench_syscall_usage, 0);
gettimeofday(&start, NULL); gettimeofday(&start, NULL);
for (i = 0; i < loops; i++) for (i = 0; i < loops; i++) {
switch (syscall) {
case __NR_getppid:
getppid(); getppid();
break;
default:
break;
}
}
gettimeofday(&stop, NULL); gettimeofday(&stop, NULL);
timersub(&stop, &start, &diff); timersub(&stop, &start, &diff);
switch (syscall) {
case __NR_getppid:
name = "getppid()";
break;
default:
break;
}
switch (bench_format) { switch (bench_format) {
case BENCH_FORMAT_DEFAULT: 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_sec * 1000000;
result_usec += diff.tv_usec; result_usec += diff.tv_usec;
...@@ -79,3 +95,8 @@ int bench_syscall_basic(int argc, const char **argv) ...@@ -79,3 +95,8 @@ int bench_syscall_basic(int argc, const char **argv)
return 0; return 0;
} }
int bench_syscall_basic(int argc, const char **argv)
{
return bench_syscall_common(argc, argv, __NR_getppid);
}
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