2022-09-29 09:01:05

by Tiezhu Yang

[permalink] [raw]
Subject: [PATCH v2 1/3] 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.

Signed-off-by: Tiezhu Yang <[email protected]>
---
tools/perf/bench/syscall.c | 30 ++++++++++++++++++++++++++----
1 file changed, 26 insertions(+), 4 deletions(-)

diff --git a/tools/perf/bench/syscall.c b/tools/perf/bench/syscall.c
index 9b75101..51840e9 100644
--- a/tools/perf/bench/syscall.c
+++ b/tools/perf/bench/syscall.c
@@ -16,6 +16,7 @@
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
+#include <asm/unistd.h>

#define LOOPS_DEFAULT 10000000
static int loops = LOOPS_DEFAULT;
@@ -30,25 +31,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 +96,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);
+}
--
2.1.0


2022-10-05 08:41:44

by kernel test robot

[permalink] [raw]
Subject: [perf bench syscall] c5ba0666d8: perf-sanity-tests.perf.make_fail

Greeting,

FYI, we noticed the following commit (built with gcc-11):

commit: c5ba0666d8f6dd34cb07ad45804e6a90159d377f ("[PATCH v2 1/3] perf bench syscall: Introduce bench_syscall_common()")
url: https://github.com/intel-lab-lkp/linux/commits/Tiezhu-Yang/perf-Add-more-syscalls-to-benchmark/20220929-165832
base: https://git.kernel.org/cgit/linux/kernel/git/acme/linux.git perf/core
patch link: https://lore.kernel.org/lkml/[email protected]

in testcase: perf-sanity-tests
version: perf-x86_64-b357fd1c2afc-1_20221001
with following parameters:

perf_compiler: gcc


on test machine: 8 threads 1 sockets Intel(R) Core(TM) i7-7700 CPU @ 3.60GHz (Kaby Lake) with 32G memory

caused below changes (please refer to attached dmesg/kmsg for entire log/backtrace):


CC bench/syscall.o
bench/syscall.c: In function ‘bench_syscall_common’:
bench/syscall.c:47:8: error: ‘__NR_getppid’ undeclared (first use in this function); did you mean ‘__getpgid’?
47 | case __NR_getppid:
| ^~~~~~~~~~~~
| __getpgid
bench/syscall.c:47:8: note: each undeclared identifier is reported only once for each function it appears in
bench/syscall.c: In function ‘bench_syscall_basic’:
bench/syscall.c:102:42: error: ‘__NR_getppid’ undeclared (first use in this function); did you mean ‘__getpgid’?
102 | return bench_syscall_common(argc, argv, __NR_getppid);
| ^~~~~~~~~~~~
| __getpgid
bench/syscall.c:103:1: error: control reaches end of non-void function [-Werror=return-type]
103 | }
| ^
cc1: all warnings being treated as errors


If you fix the issue, kindly add following tag
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/r/[email protected]


To reproduce:

git clone https://github.com/intel/lkp-tests.git
cd lkp-tests
sudo bin/lkp install job.yaml # job file is attached in this email
bin/lkp split-job --compatible job.yaml # generate the yaml file for lkp run
sudo bin/lkp run generated-yaml-file

# if come across any failure that blocks the test,
# please remove ~/.lkp and /lkp dir to run from a clean state.


--
0-DAY CI Kernel Test Service
https://01.org/lkp


Attachments:
(No filename) (2.39 kB)
config-6.0.0-rc4-00276-gc5ba0666d8f6 (170.86 kB)
job-script (5.76 kB)
dmesg.xz (29.73 kB)
perf-sanity-tests (12.32 kB)
job.yaml (4.65 kB)
reproduce (207.00 B)
Download all attachments

2022-10-05 14:08:18

by Tiezhu Yang

[permalink] [raw]
Subject: Re: [perf bench syscall] c5ba0666d8: perf-sanity-tests.perf.make_fail


On 10/5/22 16:35, kernel test robot wrote:
> Greeting,
>
> FYI, we noticed the following commit (built with gcc-11):
>
> commit: c5ba0666d8f6dd34cb07ad45804e6a90159d377f ("[PATCH v2 1/3] perf bench syscall: Introduce bench_syscall_common()")
> url: https://github.com/intel-lab-lkp/linux/commits/Tiezhu-Yang/perf-Add-more-syscalls-to-benchmark/20220929-165832
> base: https://git.kernel.org/cgit/linux/kernel/git/acme/linux.git perf/core
> patch link: https://lore.kernel.org/lkml/[email protected]
>
> in testcase: perf-sanity-tests
> version: perf-x86_64-b357fd1c2afc-1_20221001
> with following parameters:
>
> perf_compiler: gcc
>
>
> on test machine: 8 threads 1 sockets Intel(R) Core(TM) i7-7700 CPU @ 3.60GHz (Kaby Lake) with 32G memory
>
> caused below changes (please refer to attached dmesg/kmsg for entire log/backtrace):
>
>
> CC bench/syscall.o
> bench/syscall.c: In function ‘bench_syscall_common’:
> bench/syscall.c:47:8: error: ‘__NR_getppid’ undeclared (first use in this function); did you mean ‘__getpgid’?
> 47 | case __NR_getppid:
> | ^~~~~~~~~~~~
> | __getpgid
> bench/syscall.c:47:8: note: each undeclared identifier is reported only once for each function it appears in
> bench/syscall.c: In function ‘bench_syscall_basic’:
> bench/syscall.c:102:42: error: ‘__NR_getppid’ undeclared (first use in this function); did you mean ‘__getpgid’?
> 102 | return bench_syscall_common(argc, argv, __NR_getppid);
> | ^~~~~~~~~~~~
> | __getpgid
> bench/syscall.c:103:1: error: control reaches end of non-void function [-Werror=return-type]
> 103 | }
> | ^
> cc1: all warnings being treated as errors
>
>
> If you fix the issue, kindly add following tag
> | Reported-by: kernel test robot <[email protected]>
> | Link: https://lore.kernel.org/r/[email protected]
>
>
> To reproduce:
>
> git clone https://github.com/intel/lkp-tests.git
> cd lkp-tests
> sudo bin/lkp install job.yaml # job file is attached in this email
> bin/lkp split-job --compatible job.yaml # generate the yaml file for lkp run
> sudo bin/lkp run generated-yaml-file
>
> # if come across any failure that blocks the test,
> # please remove ~/.lkp and /lkp dir to run from a clean state.
>
>

I am sorry for the build issues.

In my opinion, include asm/unistd.h can fix the build error about
undeclared __NR_getppid reported by kernel test robot, and this is
what I did in the v2 patch, but it seems no effect.

Here are the definition on my x86_64 system:

[yangtiezhu@linux ~]$ grep -rn __NR_getppid /usr/include/
/usr/include/asm/unistd_x32.h:102:#define __NR_getppid
(__X32_SYSCALL_BIT + 110)
/usr/include/asm/unistd_32.h:68:#define __NR_getppid 64
/usr/include/asm/unistd_64.h:114:#define __NR_getppid 110
/usr/include/asm-generic/unistd.h:492:#define __NR_getppid 173
/usr/include/asm-generic/unistd.h:493:__SYSCALL(__NR_getppid, sys_getppid)
/usr/include/bits/syscall.h:610:#ifdef __NR_getppid
/usr/include/bits/syscall.h:611:# define SYS_getppid __NR_getppid
[yangtiezhu@linux ~]$ cat /usr/include/asm/unistd.h
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
#ifndef _ASM_X86_UNISTD_H
#define _ASM_X86_UNISTD_H

/* x32 syscall flag bit */
#define __X32_SYSCALL_BIT 0x40000000

# ifdef __i386__
# include <asm/unistd_32.h>
# elif defined(__ILP32__)
# include <asm/unistd_x32.h>
# else
# include <asm/unistd_64.h>
# endif

#endif /* _ASM_X86_UNISTD_H */
[yangtiezhu@linux ~]$ rpm -qf /usr/include/asm/unistd.h
kernel-headers-4.18.0-348.7.1.el8_5.x86_64

In order to fix the build error,

(1) Maybe I need to add the following code like
tools/build/feature/test-bpf.c:

#ifndef __NR_getppid
# if defined(__i386__)
# define __NR_getppid 64
# elif defined(__x86_64__)
# define __NR_getppid 110
# elif defined(__aarch64__)
...
# elif defined(__sparc__)
...
# elif defined(__s390__)
...
# elif defined(__mips__)
...
# else
# error __NR_getppid not defined.
# endif
#endif

(2) Maybe I need to modify the following header files:
tools/arch/x86/include/uapi/asm/unistd_32.h
tools/arch/x86/include/uapi/asm/unistd_64.h

I prefer the second method, but I am a bit confused,
why not include /usr/include/asm/unistd*.h?
I think it is to avoid cross build issues?
Am I missing something?

Let me rethink it and then send v3, thank you.

Thanks,
Tiezhu