netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 0/4] perf augmented_raw_syscalls: Support for arm64
@ 2019-06-06  7:56 Leo Yan
  2019-06-06  7:56 ` [PATCH v1 1/4] perf trace: Exit when build eBPF program failure Leo Yan
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Leo Yan @ 2019-06-06  7:56 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Alexander Shishkin, Jiri Olsa,
	Namhyung Kim, Alexei Starovoitov, Daniel Borkmann,
	Martin KaFai Lau, Song Liu, Yonghong Song, Adrian Hunter,
	Mathieu Poirier, Mike Leach, Suzuki K Poulose, linux-kernel,
	netdev, bpf
  Cc: Leo Yan

When I tried to run the trace on arm64 platform with eBPF program
augmented_raw_syscalls, it reports several failures for eBPF program
compilation.  So tried to resolve these issues and this patch set is
the working result.

0001 patch lets perf command to exit directly if find eBPF program
building failure.

0002 patch is minor refactoring code to remove duplicate macro.

0003 patch is to add support arm64 raw syscalls numbers.

0004 patch is to document clang configuration so that can easily use
this program on both x86_64 and aarch64 platforms.


Leo Yan (4):
  perf trace: Exit when build eBPF program failure
  perf augmented_raw_syscalls: Remove duplicate macros
  perf augmented_raw_syscalls: Support arm64 raw syscalls
  perf augmented_raw_syscalls: Document clang configuration

 tools/perf/builtin-trace.c                    |   8 ++
 .../examples/bpf/augmented_raw_syscalls.c     | 102 +++++++++++++++++-
 2 files changed, 109 insertions(+), 1 deletion(-)

-- 
2.17.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v1 1/4] perf trace: Exit when build eBPF program failure
  2019-06-06  7:56 [PATCH v1 0/4] perf augmented_raw_syscalls: Support for arm64 Leo Yan
@ 2019-06-06  7:56 ` Leo Yan
  2019-06-06  7:56 ` [PATCH v1 2/4] perf augmented_raw_syscalls: Remove duplicate macros Leo Yan
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Leo Yan @ 2019-06-06  7:56 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Alexander Shishkin, Jiri Olsa,
	Namhyung Kim, Alexei Starovoitov, Daniel Borkmann,
	Martin KaFai Lau, Song Liu, Yonghong Song, Adrian Hunter,
	Mathieu Poirier, Mike Leach, Suzuki K Poulose, linux-kernel,
	netdev, bpf
  Cc: Leo Yan

On my Juno board with ARM64 CPUs, perf trace command reports the eBPF
program building failure but the command will not exit and continue to
run.  If we define an eBPF event in config file, the event will be
parsed with below flow:

  perf_config()
    `> trace__config()
	 `> parse_events_option()
	      `> parse_events__scanner()
	           `-> parse_events_parse()
	                 `> parse_events_load_bpf()
	                      `> llvm__compile_bpf()

Though the low level functions return back error values when detect eBPF
building failure, but parse_events_option() returns 1 for this case and
trace__config() passes 1 to perf_config(); perf_config() doesn't treat
the returned value 1 as failure and it continues to parse other
configurations.  Thus the perf command continues to run even without
enabling eBPF event successfully.

This patch changes error handling in trace__config(), when it detects
failure it will return -1 rather than directly pass error value (1);
finally, perf_config() will directly bail out and perf will exit for
this case.

Signed-off-by: Leo Yan <leo.yan@linaro.org>
---
 tools/perf/builtin-trace.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 54b2d0fd0d02..4b5d004aab74 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -3664,6 +3664,14 @@ static int trace__config(const char *var, const char *value, void *arg)
 					       "event selector. use 'perf list' to list available events",
 					       parse_events_option);
 		err = parse_events_option(&o, value, 0);
+
+		/*
+		 * When parse option successfully parse_events_option() will
+		 * return 0, otherwise means the paring failure.  And it
+		 * returns 1 for eBPF program building failure; so adjust the
+		 * err value to -1 for the failure.
+		 */
+		err = err ? -1 : 0;
 	} else if (!strcmp(var, "trace.show_timestamp")) {
 		trace->show_tstamp = perf_config_bool(var, value);
 	} else if (!strcmp(var, "trace.show_duration")) {
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v1 2/4] perf augmented_raw_syscalls: Remove duplicate macros
  2019-06-06  7:56 [PATCH v1 0/4] perf augmented_raw_syscalls: Support for arm64 Leo Yan
  2019-06-06  7:56 ` [PATCH v1 1/4] perf trace: Exit when build eBPF program failure Leo Yan
@ 2019-06-06  7:56 ` Leo Yan
  2019-06-06  7:56 ` [PATCH v1 3/4] perf augmented_raw_syscalls: Support arm64 raw syscalls Leo Yan
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Leo Yan @ 2019-06-06  7:56 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Alexander Shishkin, Jiri Olsa,
	Namhyung Kim, Alexei Starovoitov, Daniel Borkmann,
	Martin KaFai Lau, Song Liu, Yonghong Song, Adrian Hunter,
	Mathieu Poirier, Mike Leach, Suzuki K Poulose, linux-kernel,
	netdev, bpf
  Cc: Leo Yan

The macro SYS_EXECVE has been defined twice, remove the duplicate one.

Signed-off-by: Leo Yan <leo.yan@linaro.org>
---
 tools/perf/examples/bpf/augmented_raw_syscalls.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/tools/perf/examples/bpf/augmented_raw_syscalls.c b/tools/perf/examples/bpf/augmented_raw_syscalls.c
index 68a3d61752ce..5c4a4e715ae6 100644
--- a/tools/perf/examples/bpf/augmented_raw_syscalls.c
+++ b/tools/perf/examples/bpf/augmented_raw_syscalls.c
@@ -90,7 +90,6 @@ struct augmented_filename {
 /* syscalls where the second arg is a string */
 
 #define SYS_PWRITE64            18
-#define SYS_EXECVE              59
 #define SYS_RENAME              82
 #define SYS_QUOTACTL           179
 #define SYS_FSETXATTR          190
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v1 3/4] perf augmented_raw_syscalls: Support arm64 raw syscalls
  2019-06-06  7:56 [PATCH v1 0/4] perf augmented_raw_syscalls: Support for arm64 Leo Yan
  2019-06-06  7:56 ` [PATCH v1 1/4] perf trace: Exit when build eBPF program failure Leo Yan
  2019-06-06  7:56 ` [PATCH v1 2/4] perf augmented_raw_syscalls: Remove duplicate macros Leo Yan
@ 2019-06-06  7:56 ` Leo Yan
  2019-06-06  7:56 ` [PATCH v1 4/4] perf augmented_raw_syscalls: Document clang configuration Leo Yan
  2019-06-06  9:52 ` [PATCH v1 0/4] perf augmented_raw_syscalls: Support for arm64 Leo Yan
  4 siblings, 0 replies; 6+ messages in thread
From: Leo Yan @ 2019-06-06  7:56 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Alexander Shishkin, Jiri Olsa,
	Namhyung Kim, Alexei Starovoitov, Daniel Borkmann,
	Martin KaFai Lau, Song Liu, Yonghong Song, Adrian Hunter,
	Mathieu Poirier, Mike Leach, Suzuki K Poulose, linux-kernel,
	netdev, bpf
  Cc: Leo Yan

This patch adds support for arm64 raw syscall numbers so that we can use
it on arm64 platform.

After applied this patch, we need to specify macro -D__aarch64__ or
-D__x86_64__ in compilation option so Clang can use the corresponding
syscall numbers for arm64 or x86_64 respectively, other architectures
will report failure when compilation.

Signed-off-by: Leo Yan <leo.yan@linaro.org>
---
 .../examples/bpf/augmented_raw_syscalls.c     | 82 +++++++++++++++++++
 1 file changed, 82 insertions(+)

diff --git a/tools/perf/examples/bpf/augmented_raw_syscalls.c b/tools/perf/examples/bpf/augmented_raw_syscalls.c
index 5c4a4e715ae6..f4ed101b697d 100644
--- a/tools/perf/examples/bpf/augmented_raw_syscalls.c
+++ b/tools/perf/examples/bpf/augmented_raw_syscalls.c
@@ -45,6 +45,84 @@ struct augmented_filename {
 	char		value[PATH_MAX];
 };
 
+#if defined(__aarch64__)
+
+/* syscalls where the first arg is a string */
+#define SYS_OPEN               1024
+#define SYS_STAT               1038
+#define SYS_LSTAT              1039
+#define SYS_ACCESS             1033
+#define SYS_EXECVE             221
+#define SYS_TRUNCATE           45
+#define SYS_CHDIR              49
+#define SYS_RENAME             1034
+#define SYS_MKDIR              1030
+#define SYS_RMDIR              1031
+#define SYS_CREAT              1064
+#define SYS_LINK               1025
+#define SYS_UNLINK             1026
+#define SYS_SYMLINK            1036
+#define SYS_READLINK           1035
+#define SYS_CHMOD              1028
+#define SYS_CHOWN              1029
+#define SYS_LCHOWN             1032
+#define SYS_MKNOD              1027
+#define SYS_STATFS             1056
+#define SYS_PIVOT_ROOT         41
+#define SYS_CHROOT             51
+#define SYS_ACCT               89
+#define SYS_SWAPON             224
+#define SYS_SWAPOFF            225
+#define SYS_DELETE_MODULE      106
+#define SYS_SETXATTR           5
+#define SYS_LSETXATTR          6
+#define SYS_GETXATTR           8
+#define SYS_LGETXATTR          9
+#define SYS_LISTXATTR          11
+#define SYS_LLISTXATTR         12
+#define SYS_REMOVEXATTR        14
+#define SYS_LREMOVEXATTR       15
+#define SYS_MQ_OPEN            180
+#define SYS_MQ_UNLINK          181
+#define SYS_ADD_KEY            217
+#define SYS_REQUEST_KEY        218
+#define SYS_SYMLINKAT          36
+#define SYS_MEMFD_CREATE       279
+
+/* syscalls where the second arg is a string */
+#define SYS_PWRITE64           68
+#define SYS_EXECVE             221
+#define SYS_RENAME             1034
+#define SYS_QUOTACTL           60
+#define SYS_FSETXATTR           7
+#define SYS_FGETXATTR          10
+#define SYS_FREMOVEXATTR       16
+#define SYS_MQ_TIMEDSEND       182
+#define SYS_REQUEST_KEY        218
+#define SYS_INOTIFY_ADD_WATCH  27
+#define SYS_OPENAT             56
+#define SYS_MKDIRAT            34
+#define SYS_MKNODAT            33
+#define SYS_FCHOWNAT           54
+#define SYS_FUTIMESAT          1066
+#define SYS_NEWFSTATAT         1054
+#define SYS_UNLINKAT           35
+#define SYS_RENAMEAT           38
+#define SYS_LINKAT             37
+#define SYS_READLINKAT         78
+#define SYS_FCHMODAT           53
+#define SYS_FACCESSAT          48
+#define SYS_UTIMENSAT          88
+#define SYS_NAME_TO_HANDLE_AT  264
+#define SYS_FINIT_MODULE       273
+#define SYS_RENAMEAT2          276
+#define SYS_EXECVEAT           281
+#define SYS_STATX              291
+#define SYS_MOVE_MOUNT         429
+#define SYS_FSPICK             433
+
+#elif defined(__x86_64__)
+
 /* syscalls where the first arg is a string */
 #define SYS_OPEN                 2
 #define SYS_STAT                 4
@@ -119,6 +197,10 @@ struct augmented_filename {
 #define SYS_MOVE_MOUNT         429
 #define SYS_FSPICK             433
 
+#else
+#error "unsupported architecture"
+#endif
+
 pid_filter(pids_filtered);
 
 struct augmented_args_filename {
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v1 4/4] perf augmented_raw_syscalls: Document clang configuration
  2019-06-06  7:56 [PATCH v1 0/4] perf augmented_raw_syscalls: Support for arm64 Leo Yan
                   ` (2 preceding siblings ...)
  2019-06-06  7:56 ` [PATCH v1 3/4] perf augmented_raw_syscalls: Support arm64 raw syscalls Leo Yan
@ 2019-06-06  7:56 ` Leo Yan
  2019-06-06  9:52 ` [PATCH v1 0/4] perf augmented_raw_syscalls: Support for arm64 Leo Yan
  4 siblings, 0 replies; 6+ messages in thread
From: Leo Yan @ 2019-06-06  7:56 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Alexander Shishkin, Jiri Olsa,
	Namhyung Kim, Alexei Starovoitov, Daniel Borkmann,
	Martin KaFai Lau, Song Liu, Yonghong Song, Adrian Hunter,
	Mathieu Poirier, Mike Leach, Suzuki K Poulose, linux-kernel,
	netdev, bpf
  Cc: Leo Yan

To build this program successfully with clang, there have three
compiler options need to be specified:

  - Header file path: tools/perf/include/bpf;
  - Specify architecture;
  - Define macro __NR_CPUS__.

This patch add comments to explain the reasons for building failure and
give two examples for llvm.clang-opt variable, one is for x86_64
architecture and another is for aarch64 architecture.

Signed-off-by: Leo Yan <leo.yan@linaro.org>
---
 .../examples/bpf/augmented_raw_syscalls.c     | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/tools/perf/examples/bpf/augmented_raw_syscalls.c b/tools/perf/examples/bpf/augmented_raw_syscalls.c
index f4ed101b697d..5adc0b3bb351 100644
--- a/tools/perf/examples/bpf/augmented_raw_syscalls.c
+++ b/tools/perf/examples/bpf/augmented_raw_syscalls.c
@@ -6,6 +6,25 @@
  *
  * perf trace -e tools/perf/examples/bpf/augmented_raw_syscalls.c cat /etc/passwd > /dev/null
  *
+ * This program include two header files 'unistd.h' and 'pid_filter.h', which
+ * are placed in the folder tools/perf/include/bpf, but this folder is not
+ * included in env $KERNEL_INC_OPTIONS and it leads to compilation failure.
+ * For building this code, we also need to specify architecture and define macro
+ * __NR_CPUS__.  To resolve these issues, variable llvm.clang-opt can be set in
+ * the file ~/.perfconfig:
+ *
+ * E.g. Test on a platform with 8 CPUs with x86_64 architecture:
+ *
+ *   [llvm]
+ *		clang-opt = "-D__NR_CPUS__=8 -D__x86_64__ \
+ *			     -I./tools/perf/include/bpf"
+ *
+ * E.g. Test on a platform with 5 CPUs with aarch64 architecture:
+ *
+ *   [llvm]
+ *		clang-opt = "-D__NR_CPUS__=5 -D__aarch64__ \
+ *			     -I./tools/perf/include/bpf"
+
  * This exactly matches what is marshalled into the raw_syscall:sys_enter
  * payload expected by the 'perf trace' beautifiers.
  *
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v1 0/4] perf augmented_raw_syscalls: Support for arm64
  2019-06-06  7:56 [PATCH v1 0/4] perf augmented_raw_syscalls: Support for arm64 Leo Yan
                   ` (3 preceding siblings ...)
  2019-06-06  7:56 ` [PATCH v1 4/4] perf augmented_raw_syscalls: Document clang configuration Leo Yan
@ 2019-06-06  9:52 ` Leo Yan
  4 siblings, 0 replies; 6+ messages in thread
From: Leo Yan @ 2019-06-06  9:52 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Alexander Shishkin, Jiri Olsa,
	Namhyung Kim, Alexei Starovoitov, Daniel Borkmann,
	Martin KaFai Lau, Song Liu, Yonghong Song, Adrian Hunter,
	Mathieu Poirier, Mike Leach, Suzuki K Poulose, linux-kernel,
	netdev, bpf

Hi all,

On Thu, Jun 06, 2019 at 03:56:13PM +0800, Leo Yan wrote:
> When I tried to run the trace on arm64 platform with eBPF program
> augmented_raw_syscalls, it reports several failures for eBPF program
> compilation.  So tried to resolve these issues and this patch set is
> the working result.
> 
> 0001 patch lets perf command to exit directly if find eBPF program
> building failure.
> 
> 0002 patch is minor refactoring code to remove duplicate macro.
> 
> 0003 patch is to add support arm64 raw syscalls numbers.

I found minor issues in patch 0003, so sent out v2 for reviewing.

Sorry for spamming.

Thanks,
Leo Yan

> 0004 patch is to document clang configuration so that can easily use
> this program on both x86_64 and aarch64 platforms.
> 
> 
> Leo Yan (4):
>   perf trace: Exit when build eBPF program failure
>   perf augmented_raw_syscalls: Remove duplicate macros
>   perf augmented_raw_syscalls: Support arm64 raw syscalls
>   perf augmented_raw_syscalls: Document clang configuration
> 
>  tools/perf/builtin-trace.c                    |   8 ++
>  .../examples/bpf/augmented_raw_syscalls.c     | 102 +++++++++++++++++-
>  2 files changed, 109 insertions(+), 1 deletion(-)
> 
> -- 
> 2.17.1
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-06-06  9:52 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-06  7:56 [PATCH v1 0/4] perf augmented_raw_syscalls: Support for arm64 Leo Yan
2019-06-06  7:56 ` [PATCH v1 1/4] perf trace: Exit when build eBPF program failure Leo Yan
2019-06-06  7:56 ` [PATCH v1 2/4] perf augmented_raw_syscalls: Remove duplicate macros Leo Yan
2019-06-06  7:56 ` [PATCH v1 3/4] perf augmented_raw_syscalls: Support arm64 raw syscalls Leo Yan
2019-06-06  7:56 ` [PATCH v1 4/4] perf augmented_raw_syscalls: Document clang configuration Leo Yan
2019-06-06  9:52 ` [PATCH v1 0/4] perf augmented_raw_syscalls: Support for arm64 Leo Yan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).