diff mbox series

[v2,4/4] perf augmented_raw_syscalls: Document clang configuration

Message ID 20190606094845.4800-5-leo.yan@linaro.org
State New
Headers show
Series [v2,1/4] perf trace: Exit when build eBPF program failure | expand

Commit Message

Leo Yan June 6, 2019, 9:48 a.m. UTC
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(+)

-- 
2.17.1

Comments

Leo Yan June 6, 2019, 2:35 p.m. UTC | #1
On Thu, Jun 06, 2019 at 11:08:00AM -0300, Arnaldo Carvalho de Melo wrote:
> Em Thu, Jun 06, 2019 at 05:48:45PM +0800, Leo Yan escreveu:

> > 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__.

> 

> So, this shouldn't be needed, all of this is supposed to be done

> automagically, have you done a 'make -C tools/perf install'?


I missed the up operation.  But after git pulled the lastest code base
from perf/core branch and used the command 'make -C tools/perf
install', I still saw the eBPF build failure.

Just now this issue is fixed after I removed the config
'clang-bpf-cmd-template' from ~/.perfconfig;  the reason is I followed
up the Documentation/perf-config.txt to set the config as below:

  clang-bpf-cmd-template = "$CLANG_EXEC -D__KERNEL__ $CLANG_OPTIONS \
                          $KERNEL_INC_OPTIONS -Wno-unused-value \
                          -Wno-pointer-sign -working-directory \
                          $WORKING_DIR -c $CLANG_SOURCE -target bpf \
                          -O2 -o -"

In fact, util/llvm-utils.c has updated the default configuration as
below:

  #define CLANG_BPF_CMD_DEFAULT_TEMPLATE                          \
                "$CLANG_EXEC -D__KERNEL__ -D__NR_CPUS__=$NR_CPUS "\
                "-DLINUX_VERSION_CODE=$LINUX_VERSION_CODE "     \
                "$CLANG_OPTIONS $PERF_BPF_INC_OPTIONS $KERNEL_INC_OPTIONS " \
                "-Wno-unused-value -Wno-pointer-sign "          \
                "-working-directory $WORKING_DIR "              \
                "-c \"$CLANG_SOURCE\" -target bpf $CLANG_EMIT_LLVM -O2 -o - $LLVM_OPTIONS_PIPE"

Maybe should update Documentation/perf-config.txt to tell users the
real default value of clang-bpf-cmd-template?

Thanks,
Leo Yan
Leo Yan June 7, 2019, 2:38 p.m. UTC | #2
Hi Arnaldo,

On Thu, Jun 06, 2019 at 03:29:41PM -0300, Arnaldo Carvalho de Melo wrote:
> Em Thu, Jun 06, 2019 at 10:35:32PM +0800, Leo Yan escreveu:

> > On Thu, Jun 06, 2019 at 11:08:00AM -0300, Arnaldo Carvalho de Melo wrote:

> > > Em Thu, Jun 06, 2019 at 05:48:45PM +0800, Leo Yan escreveu:

> > > > 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__.

> > > 

> > > So, this shouldn't be needed, all of this is supposed to be done

> > > automagically, have you done a 'make -C tools/perf install'?

> > 

> > I missed the up operation.  But after git pulled the lastest code base

> > from perf/core branch and used the command 'make -C tools/perf

> > install', I still saw the eBPF build failure.

> > 

> > Just now this issue is fixed after I removed the config

> > 'clang-bpf-cmd-template' from ~/.perfconfig;  the reason is I followed

> > up the Documentation/perf-config.txt to set the config as below:

> > 

> >   clang-bpf-cmd-template = "$CLANG_EXEC -D__KERNEL__ $CLANG_OPTIONS \

> >                           $KERNEL_INC_OPTIONS -Wno-unused-value \

> >                           -Wno-pointer-sign -working-directory \

> >                           $WORKING_DIR -c $CLANG_SOURCE -target bpf \

> >                           -O2 -o -"

> > 

> > In fact, util/llvm-utils.c has updated the default configuration as

> > below:

> > 

> >   #define CLANG_BPF_CMD_DEFAULT_TEMPLATE                          \

> >                 "$CLANG_EXEC -D__KERNEL__ -D__NR_CPUS__=$NR_CPUS "\

> >                 "-DLINUX_VERSION_CODE=$LINUX_VERSION_CODE "     \

> >                 "$CLANG_OPTIONS $PERF_BPF_INC_OPTIONS $KERNEL_INC_OPTIONS " \

> >                 "-Wno-unused-value -Wno-pointer-sign "          \

> >                 "-working-directory $WORKING_DIR "              \

> >                 "-c \"$CLANG_SOURCE\" -target bpf $CLANG_EMIT_LLVM -O2 -o - $LLVM_OPTIONS_PIPE"

> > 

> > Maybe should update Documentation/perf-config.txt to tell users the

> > real default value of clang-bpf-cmd-template?

> 

> Sure, if you fell like doing this, please update and also please figure

> out when the this changed and add a Fixes: that cset,


Thanks for guidance.  Have sent patch for this [1].

> Its great that you're going thru the docs and making sure the

> differences are noted so that we update the docs, thanks a lot!


You are welcome!

Thanks,
Leo Yan

[1] https://lkml.org/lkml/2019/6/7/477
Arnaldo Carvalho de Melo June 7, 2019, 6:33 p.m. UTC | #3
Em Fri, Jun 07, 2019 at 10:38:49PM +0800, Leo Yan escreveu:
> Hi Arnaldo,

> 

> On Thu, Jun 06, 2019 at 03:29:41PM -0300, Arnaldo Carvalho de Melo wrote:

> > Em Thu, Jun 06, 2019 at 10:35:32PM +0800, Leo Yan escreveu:

> > > On Thu, Jun 06, 2019 at 11:08:00AM -0300, Arnaldo Carvalho de Melo wrote:

> > > > Em Thu, Jun 06, 2019 at 05:48:45PM +0800, Leo Yan escreveu:

> > > > > 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__.

> > > > 

> > > > So, this shouldn't be needed, all of this is supposed to be done

> > > > automagically, have you done a 'make -C tools/perf install'?

> > > 

> > > I missed the up operation.  But after git pulled the lastest code base

> > > from perf/core branch and used the command 'make -C tools/perf

> > > install', I still saw the eBPF build failure.

> > > 

> > > Just now this issue is fixed after I removed the config

> > > 'clang-bpf-cmd-template' from ~/.perfconfig;  the reason is I followed

> > > up the Documentation/perf-config.txt to set the config as below:

> > > 

> > >   clang-bpf-cmd-template = "$CLANG_EXEC -D__KERNEL__ $CLANG_OPTIONS \

> > >                           $KERNEL_INC_OPTIONS -Wno-unused-value \

> > >                           -Wno-pointer-sign -working-directory \

> > >                           $WORKING_DIR -c $CLANG_SOURCE -target bpf \

> > >                           -O2 -o -"

> > > 

> > > In fact, util/llvm-utils.c has updated the default configuration as

> > > below:

> > > 

> > >   #define CLANG_BPF_CMD_DEFAULT_TEMPLATE                          \

> > >                 "$CLANG_EXEC -D__KERNEL__ -D__NR_CPUS__=$NR_CPUS "\

> > >                 "-DLINUX_VERSION_CODE=$LINUX_VERSION_CODE "     \

> > >                 "$CLANG_OPTIONS $PERF_BPF_INC_OPTIONS $KERNEL_INC_OPTIONS " \

> > >                 "-Wno-unused-value -Wno-pointer-sign "          \

> > >                 "-working-directory $WORKING_DIR "              \

> > >                 "-c \"$CLANG_SOURCE\" -target bpf $CLANG_EMIT_LLVM -O2 -o - $LLVM_OPTIONS_PIPE"

> > > 

> > > Maybe should update Documentation/perf-config.txt to tell users the

> > > real default value of clang-bpf-cmd-template?

> > 

> > Sure, if you fell like doing this, please update and also please figure

> > out when the this changed and add a Fixes: that cset,

> 

> Thanks for guidance.  Have sent patch for this [1].


yeah, applied already.

- Arnaldo
 
> > Its great that you're going thru the docs and making sure the

> > differences are noted so that we update the docs, thanks a lot!

> 

> You are welcome!
diff mbox series

Patch

diff --git a/tools/perf/examples/bpf/augmented_raw_syscalls.c b/tools/perf/examples/bpf/augmented_raw_syscalls.c
index a3701a4daf2e..fb6987edab2c 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.
  *