Commit Graph

230 Commits

Author SHA1 Message Date
Tomas Glozar 347065af81 tools/build: Use SYSTEM_BPFTOOL for system bpftool
JIRA: https://issues.redhat.com/browse/RHEL-77358

commit 814d051ebed40b27285ab3c5e2454bd01a0f9631
Author: Tomas Glozar <tglozar@redhat.com>
Date:   Wed Mar 26 01:40:18 2025 +0100

    tools/build: Use SYSTEM_BPFTOOL for system bpftool

    The feature test for system bpftool uses BPFTOOL as the variable to set
    its path, defaulting to just "bpftool" if not set by the user.

    This conflicts with selftests and a few other utilities, which expect
    BPFTOOL to be set to the in-tree bpftool path by default. For example,
    bpftool selftests fail to build:

    $ make -C tools/testing/selftests/bpf/
    make: Entering directory '/home/tglozar/dev/linux/tools/testing/selftests/bpf'

    make: *** No rule to make target 'bpftool', needed by '/home/tglozar/dev/linux/tools/testing/selftests/bpf/tools/include/vmlinux.h'.  Stop.
    make: Leaving directory '/home/tglozar/dev/linux/tools/testing/selftests/bpf'

    Fix the problem by renaming the variable used for system bpftool from
    BPFTOOL to SYSTEM_BPFTOOL, so that the new usage does not conflict with
    the existing one of BPFTOOL.

    Cc: John Kacur <jkacur@redhat.com>
    Cc: Luis Goncalves <lgoncalv@redhat.com>
    Link: https://lore.kernel.org/20250326004018.248357-1-tglozar@redhat.com
    Fixes: 8a635c3856dd ("tools/build: Add bpftool-skeletons feature test")
    Closes: https://lore.kernel.org/linux-kernel/5df6968a-2e5f-468e-b457-fc201535dd4c@linux.ibm.com/
    Reported-by: Venkat Rao Bagalkote <venkat88@linux.ibm.com>
    Tested-by: Venkat Rao Bagalkote <venkat88@linux.ibm.com>
    Suggested-by: Quentin Monnet <qmo@kernel.org>
    Acked-by: Quentin Monnet <qmo@kernel.org>
    Signed-off-by: Tomas Glozar <tglozar@redhat.com>
    Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>

Signed-off-by: Tomas Glozar <tglozar@redhat.com>
2025-04-04 11:14:45 +02:00
Tomas Glozar 6a7d90edc3 tools/build: Add bpftool-skeletons feature test
JIRA: https://issues.redhat.com/browse/RHEL-77358

commit 8a635c3856ddb74ed3fe7c856b271cdfeb65f293
Author: Tomas Glozar <tglozar@redhat.com>
Date:   Tue Feb 18 15:58:53 2025 +0100

    tools/build: Add bpftool-skeletons feature test

    Add bpftool-skeletons feature test, testing the presence of a bpftool
    capable of generating skeletons.

    This is to be used for tools that do not require building their own
    bootstrap bpftool from the kernel source tree.

    Cc: John Kacur <jkacur@redhat.com>
    Cc: Luis Goncalves <lgoncalv@redhat.com>
    Cc: Gabriele Monaco <gmonaco@redhat.com>
    Cc: Clark Williams <williams@redhat.com>
    Link: https://lore.kernel.org/20250218145859.27762-3-tglozar@redhat.com
    Signed-off-by: Tomas Glozar <tglozar@redhat.com>
    Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>

Signed-off-by: Tomas Glozar <tglozar@redhat.com>
2025-04-04 11:14:44 +02:00
Rado Vrbovsky 068c90fe4c Merge: tools/rtla: Add idle state disabling via libcpupower [rhel-9]
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/5967

JIRA: https://issues.redhat.com/browse/RHEL-69522

In addition to disabling all idle states via cpu_dma_latency, use libcpupower to set idle states only for CPUs timerlat is running on. The parameter --deepest-idle-state is added, taking the deepest allowed idle state as an argument. -1 means disable all idle states.

On RHEL 9, the patch that introduces tools/build for rtla is added, since libcpupower detection depends on it.

Signed-off-by: Tomas Glozar <tglozar@redhat.com>

Approved-by: Gabriele Monaco <gmonaco@redhat.com>
Approved-by: Eder Zulian <ezulian@redhat.com>
Approved-by: Luis Claudio R. Goncalves <lgoncalv@redhat.com>
Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com>

Merged-by: Rado Vrbovsky <rvrbovsk@redhat.com>
2024-12-18 14:25:57 +00:00
Tomas Glozar ac809f2399 tools/build: Add libcpupower dependency detection
JIRA: https://issues.redhat.com/browse/RHEL-69522

commit 0f59a6c9c421a44e652353e3ec15cf2425b904fe
Author: Tomas Glozar <tglozar@redhat.com>
Date:   Thu Oct 17 16:09:09 2024 +0200

    tools/build: Add libcpupower dependency detection

    Add the ability to detect the presence of libcpupower on a system to
    the Makefiles in tools/build.

    Link: https://lore.kernel.org/20241017140914.3200454-2-tglozar@redhat.com
    Signed-off-by: Tomas Glozar <tglozar@redhat.com>
    Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>

Signed-off-by: Tomas Glozar <tglozar@redhat.com>
2024-12-09 17:05:00 +01:00
Michael Petlan b131286c1e perf build: Fix build feature-dwarf_getlocations fail for old libdw
JIRA: https://issues.redhat.com/browse/RHEL-29796

upstream
========
commit a530337ba9ef601c93ec378fd941be43f587d563
Author: Yang Jihong <yangjihong@bytedance.com>
Date: Thu Sep 19 09:35:12 2024 +0800

description
===========
For libdw versions below 0.177, need to link libdl.a in addition to
libbebl.a during static compilation, otherwise
feature-dwarf_getlocations compilation will fail.

Before:

  $ make LDFLAGS=-static
    BUILD:   Doing 'make -j20' parallel build
  <SNIP>
  Makefile.config:483: Old libdw.h, finding variables at given 'perf probe' point will not work, install elfutils-devel/libdw-dev >= 0.157
  <SNIP>

  $ cat ../build/feature/test-dwarf_getlocations.make.output
  /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/libebl.a(eblclosebackend.o): in function `ebl_closebackend':
  (.text+0x20): undefined reference to `dlclose'
  collect2: error: ld returned 1 exit status

After:

  $ make LDFLAGS=-static
  <SNIP>
    Auto-detecting system features:
  ...                                   dwarf: [ on  ]
  <SNIP>

    $ ./perf probe
   Usage: perf probe [<options>] 'PROBEDEF' ['PROBEDEF' ...]
      or: perf probe [<options>] --add 'PROBEDEF' [--add 'PROBEDEF' ...]
      or: perf probe [<options>] --del '[GROUP:]EVENT' ...
      or: perf probe --list [GROUP:]EVENT ...
  <SNIP>

Fixes: 536661da6ea18fe6 ("perf: build: Only link libebl.a for old libdw")
    Reviewed-by: Leo Yan <leo.yan@arm.com>
    Signed-off-by: Yang Jihong <yangjihong@bytedance.com>
    Acked-by: Namhyung Kim <namhyung@kernel.org>
    Cc: Adrian Hunter <adrian.hunter@intel.com>
    Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
    Cc: Ian Rogers <irogers@google.com>
    Cc: Ingo Molnar <mingo@redhat.com>
    Cc: James Clark <james.clark@arm.com>
    Cc: Jiri Olsa <jolsa@kernel.org>
    Cc: Kan Liang <kan.liang@linux.intel.com>
    Cc: Leo Yan <leo.yan@arm.com>
    Cc: Mark Rutland <mark.rutland@arm.com>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Link: https://lore.kernel.org/r/20240919013513.118527-3-yangjihong@bytedance.com
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2024-11-18 19:23:45 +01:00
Michael Petlan daf0c6fcea perf build: Fix static compilation error when libdw is not installed
JIRA: https://issues.redhat.com/browse/RHEL-29796

upstream
========
commit 43f6564f18bf5b27e1675ef6f4baf68e786396b2
Author: Yang Jihong <yangjihong@bytedance.com>
Date: Thu Sep 19 09:35:11 2024 +0800

description
===========
If libdw is not installed in build environment, the output of
'pkg-config --modversion libdw' is empty, causing LIBDW_VERSION_2 to be
empty and the shell test will have the following error:

  /bin/sh: 1: test: -lt: unexpected operator

Before:

  $ pkg-config --modversion libdw
  Package libdw was not found in the pkg-config search path.
  Perhaps you should add the directory containing `libdw.pc'
  to the PKG_CONFIG_PATH environment variable
  No package 'libdw' found
  $ make LDFLAGS=-static -j16
    BUILD:   Doing 'make -j20' parallel build
  <SNIP>
  Package libdw was not found in the pkg-config search path.
  Perhaps you should add the directory containing `libdw.pc'
  to the PKG_CONFIG_PATH environment variable
  No package 'libdw' found
  /bin/sh: 1: test: -lt: unexpected operator

After:

  1. libdw is not installed:

  $ pkg-config --modversion libdw
  Package libdw was not found in the pkg-config search path.
  Perhaps you should add the directory containing `libdw.pc'
  to the PKG_CONFIG_PATH environment variable
  No package 'libdw' found
  $ make LDFLAGS=-static -j16
    BUILD:   Doing 'make -j20' parallel build
  <SNIP>
  Package libdw was not found in the pkg-config search path.
  Perhaps you should add the directory containing `libdw.pc'
  to the PKG_CONFIG_PATH environment variable
  No package 'libdw' found
  Makefile.config:473: No libdw DWARF unwind found, Please install elfutils-devel/libdw-dev >= 0.158 and/or set LIBDW_DIR

  2. libdw version is lower than 0.177

  $ pkg-config --modversion libdw
  0.176
  $ make LDFLAGS=-static -j16
    BUILD:   Doing 'make -j20' parallel build
  <SNIP>

  Auto-detecting system features:
  ...                                   dwarf: [ on  ]
  <SNIP>
    INSTALL libsubcmd_headers
    INSTALL libapi_headers
    INSTALL libperf_headers
    INSTALL libsymbol_headers
    INSTALL libbpf_headers
    LINK    perf

  3. libdw version is higher than 0.177

  $ pkg-config --modversion libdw
  0.186
  $ make LDFLAGS=-static -j16
    BUILD:   Doing 'make -j20' parallel build
  <SNIP>

  Auto-detecting system features:
  ...                                   dwarf: [ on  ]
  <SNIP>
    CC      util/bpf-utils.o
    CC      util/pfm.o
    LD      util/perf-util-in.o
    LD      perf-util-in.o
    AR      libperf-util.a
    LINK    perf

Fixes: 536661da6ea18fe6 ("perf: build: Only link libebl.a for old libdw")
    Reviewed-by: Leo Yan <leo.yan@arm.com>
    Signed-off-by: Yang Jihong <yangjihong@bytedance.com>
    Acked-by: Namhyung Kim <namhyung@kernel.org>
    Cc: Adrian Hunter <adrian.hunter@intel.com>
    Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
    Cc: Ian Rogers <irogers@google.com>
    Cc: Ingo Molnar <mingo@redhat.com>
    Cc: James Clark <james.clark@arm.com>
    Cc: Jiri Olsa <jolsa@kernel.org>
    Cc: Kan Liang <kan.liang@linux.intel.com>
    Cc: Leo Yan <leo.yan@arm.com>
    Cc: Mark Rutland <mark.rutland@arm.com>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Link: https://lore.kernel.org/r/20240919013513.118527-2-yangjihong@bytedance.com
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2024-11-18 19:23:45 +01:00
Michael Petlan bfe8d4e8c0 perf build: Remove unused feature test target
JIRA: https://issues.redhat.com/browse/RHEL-29796

upstream
========
commit 332f60ac052f5d7bfc646502f377c600986f10c2
Author: James Clark <james.clark@linaro.org>
Date: Tue Sep 10 15:04:01 2024 +0100

description
===========
llvm-version was removed in commit 56b11a2126bf ("perf bpf: Remove
support for embedding clang for compiling BPF events (-e foo.c)") but
some parts were left in the Makefile so finish removing them.

    Signed-off-by: James Clark <james.clark@linaro.org>
    Cc: Adrian Hunter <adrian.hunter@intel.com>
    Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
    Cc: Bill Wendling <morbo@google.com>
    Cc: Changbin Du <changbin.du@huawei.com>
    Cc: Daniel Wagner <dwagner@suse.de>
    Cc: Guilherme Amadio <amadio@gentoo.org>
    Cc: Ian Rogers <irogers@google.com>
    Cc: Ingo Molnar <mingo@redhat.com>
    Cc: Jiri Olsa <jolsa@kernel.org>
    Cc: Justin Stitt <justinstitt@google.com>
    Cc: Kan Liang <kan.liang@linux.intel.com>
    Cc: Leo Yan <leo.yan@arm.com>
    Cc: Manu Bretelle <chantr4@gmail.com>
    Cc: Mark Rutland <mark.rutland@arm.com>
    Cc: Masami Hiramatsu <mhiramat@kernel.org>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Cc: Nathan Chancellor <nathan@kernel.org>
    Cc: Nick Desaulniers <ndesaulniers@google.com>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Quentin Monnet <qmo@kernel.org>
    Cc: Steinar H. Gunderson <sesse@google.com>
    Link: https://lore.kernel.org/r/20240910140405.568791-2-james.clark@linaro.org
[ Removed one leftover, 'llvm-version' from FEATURE_TESTS_EXTRA ]
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2024-11-18 19:23:44 +01:00
Michael Petlan 6903f5a61c perf build: Autodetect minimum required llvm-dev version
JIRA: https://issues.redhat.com/browse/RHEL-29796

upstream
========
commit 206dcfca1f5cfac344bd88e5ed4b6a095014b91f
Author: James Clark <james.clark@linaro.org>
Date: Tue Sep 10 15:04:00 2024 +0100

description
===========
The new LLVM addr2line feature requires a minimum version of 13 to
compile. Add a feature check for the version so that NO_LLVM=1 doesn't
need to be explicitly added. Leave the existing llvm feature check
intact because it's used by tools other than Perf.

This fixes the following compilation error when the llvm-dev version
doesn't match:

  util/llvm-c-helpers.cpp: In function 'char* llvm_name_for_code(dso*, const char*, u64)':
  util/llvm-c-helpers.cpp:178:21: error: 'std::remove_reference_t<llvm::DILineInfo>' {aka 'struct llvm::DILineInfo'} has no member named 'StartAddress'
    178 |   addr, res_or_err->StartAddress ? *res_or_err->StartAddress : 0);

Fixes: c3f8644c21df9b7d ("perf report: Support LLVM for addr2line()")
    Signed-off-by: James Clark <james.clark@linaro.org>
    Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
    Cc: Adrian Hunter <adrian.hunter@intel.com>
    Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
    Cc: Bill Wendling <morbo@google.com>
    Cc: Changbin Du <changbin.du@huawei.com>
    Cc: Guilherme Amadio <amadio@gentoo.org>
    Cc: Ian Rogers <irogers@google.com>
    Cc: Ingo Molnar <mingo@redhat.com>
    Cc: Jiri Olsa <jolsa@kernel.org>
    Cc: Justin Stitt <justinstitt@google.com>
    Cc: Kan Liang <kan.liang@linux.intel.com>
    Cc: Leo Yan <leo.yan@arm.com>
    Cc: Manu Bretelle <chantr4@gmail.com>
    Cc: Mark Rutland <mark.rutland@arm.com>
    Cc: Masami Hiramatsu <mhiramat@kernel.org>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Cc: Nathan Chancellor <nathan@kernel.org>
    Cc: Nick Desaulniers <ndesaulniers@google.com>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Quentin Monnet <qmo@kernel.org>
    Cc: Steinar H. Gunderson <sesse@google.com>
    Link: https://lore.kernel.org/r/20240910140405.568791-1-james.clark@linaro.org
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2024-11-18 19:23:44 +01:00
Michael Petlan 9c79fbd9df perf report: Support LLVM for addr2line()
JIRA: https://issues.redhat.com/browse/RHEL-29796

upstream
========
commit c3f8644c21df9b7db97eb70e08e2826368aaafa0
Author: Steinar H. Gunderson <sesse@google.com>
Date: Sat Aug 3 17:20:06 2024 +0200

description
===========
In addition to the existing support for libbfd and calling out to
an external addr2line command, add support for using libllvm directly.

This is both faster than libbfd, and can be enabled in distro builds
(the LLVM license has an explicit provision for GPLv2 compatibility).

Thus, it is set as the primary choice if available.

As an example, running 'perf report' on a medium-size profile with
DWARF-based backtraces took 58 seconds with LLVM, 78 seconds with
libbfd, 153 seconds with external llvm-addr2line, and I got tired and
aborted the test after waiting for 55 minutes with external bfd
addr2line (which is the default for perf as compiled by distributions
today).

Evidently, for this case, the bfd addr2line process needs 18 seconds (on
a 5.2 GHz Zen 3) to load the .debug ELF in question, hits the 1-second
timeout and gets killed during initialization, getting restarted anew
every time. Having an in-process addr2line makes this much more robust.

As future extensions, libllvm can be used in many other places where
we currently use libbfd or other libraries:

 - Symbol enumeration (in particular, for PE binaries).
 - Demangling (including non-Itanium demangling, e.g. Microsoft
   or Rust).
 - Disassembling (perf annotate).

However, these are much less pressing; most people don't profile PE
binaries, and perf has non-bfd paths for ELF. The same with demangling;
the default _cxa_demangle path works fine for most users, and while bfd
objdump can be slow on large binaries, it is possible to use
--objdump=llvm-objdump to get the speed benefits.  (It appears
LLVM-based demangling is very simple, should we want that.)

Tested with LLVM 14, 15, 16, 18 and 19. For some reason, LLVM 12 was not
correctly detected using feature_check, and thus was not tested.

Committer notes:

 Added the name and a __maybe_unused to address:

   1    13.50 almalinux:8                   : FAIL gcc version 8.5.0 20210514 (Red Hat 8.5.0-22) (GCC)
    util/srcline.c: In function 'dso__free_a2l':
    util/srcline.c:184:20: error: parameter name omitted
     void dso__free_a2l(struct dso *)
                        ^~~~~~~~~~~~
    make[3]: *** [/git/perf-6.11.0-rc3/tools/build/Makefile.build:158: util] Error 2

    Signed-off-by: Steinar H. Gunderson <sesse@google.com>
    Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
    Cc: Ian Rogers <irogers@google.com>
    Link: https://lore.kernel.org/r/20240803152008.2818485-1-sesse@google.com
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2024-11-18 19:23:42 +01:00
Michael Petlan a2bfcbb978 tools build: Provide consistent build options for fixdep
JIRA: https://issues.redhat.com/browse/RHEL-29796

upstream
========
commit b53f20b323ee3c5daa5494ad69e3ae0e77cfd82a
Author: Alexander Gordeev <agordeev@linux.ibm.com>
Date: Thu Aug 15 09:20:46 2024 +0200

description
===========
The fixdep binary is being compiled and linked in one step. While the
host linker flags are passed to the compiler the host compiler flags are
missed.

That leads to build errors at least on x86_64, arm64 and s390 as result
of the compiler vs linker flags inconsistency. For example, during RPM
package build redhat-hardened-ld script is provided to gcc, while
redhat-hardened-cc1 script is missed.

Provide both KBUILD_HOSTCFLAGS and KBUILD_HOSTLDFLAGS to avoid that.

Fixes: ea974028a049f2ce ("tools build: Avoid circular .fixdep-in.o.cmd issues")
Closes: https://lore.kernel.org/lkml/99ae0d34-ed76-4ca0-a9fd-c337da33c9f9@leemhuis.info/
    Reported-by: Thorsten Leemhuis <linux@leemhuis.info>
    Reviewed-by: Brian Norris <briannorris@chromium.org>
    Signed-off-by: Alexander Gordeev <agordeev@linux.ibm.com>
    Tested-by: Thorsten Leemhuis <linux@leemhuis.info>
    Acked-by: Jiri Olsa <jolsa@kernel.org>
    Link: https://lore.kernel.org/r/20240815072046.1002837-1-agordeev@linux.ibm.com
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2024-11-18 19:23:38 +01:00
Michael Petlan fa38ccadc6 perf build: Fix up broken capstone feature detection fast path
JIRA: https://issues.redhat.com/browse/RHEL-29796

upstream
========
commit 4c55560f23d19051adc7e76818687a88448bef83
Author: Arnaldo Carvalho de Melo <acme@redhat.com>
Date: Wed Aug 14 10:36:24 2024 -0300

description
===========
The capstone devel headers define 'struct bpf_insn' in a way that clashes with
what is in the libbpf devel headers, so we so far need to avoid including both.

This is happening on the tools/build/feature/test-all.c file, where we try
building all the expected set of libraries to be normally available on a
system:

  ⬢[acme@toolbox perf-tools-next]$ cat /tmp/build/perf-tools-next/feature/test-all.make.output
  In file included from test-bpf.c:3,
                   from test-all.c:150:
  /home/acme/git/perf-tools-next/tools/include/uapi/linux/bpf.h:77:8: error: ‘bpf_insn’ defined as wrong kind of tag
     77 | struct bpf_insn {
        |        ^~~~~~~~
  ⬢[acme@toolbox perf-tools-next]$ cat /tmp/build/perf-tools-next/feature/test-all.make.output

When doing so there is a trick where we define main to be
main_test_libcapstone, then include the individual
tools/build/feture/test-libcapstone.c capability query test, and then we undef
'main' because we'll do it all over again with the next expected library to
be tested (at this time 'lzma').

To complete this mechanism we need to, in test-all.c 'main' routine, to
call main_test_libcapstone(), which isn't being done, so the effect of
adding references to capstone in test-all.c are not achieved.

The only thing that is happening is that test-all.c is failing to build and thus
all the tests will have to be done individually, which nullifies the test-all.c
single build speedup.

So lets remove references to capstone from test-all.c to see if this makes it
build again so that we get faster builds or go on fixing up whatever is
preventing us to get that benefit.

Nothing: after this fix we get a clean test-all.c build and get the build speedup back:

  ⬢[acme@toolbox perf-tools-next]$ cat /tmp/build/perf-tools-next/feature/test-all.make.output
  ⬢[acme@toolbox perf-tools-next]$ cat /tmp/build/perf-tools-next/feature/test-all.
  test-all.bin          test-all.d            test-all.make.output
  ⬢[acme@toolbox perf-tools-next]$ cat /tmp/build/perf-tools-next/feature/test-all.make.output
  ⬢[acme@toolbox perf-tools-next]$ ldd /tmp/build/perf-tools-next/feature/test-all.bin
  	linux-vdso.so.1 (0x00007f13277a1000)
  	libpython3.12.so.1.0 => /lib64/libpython3.12.so.1.0 (0x00007f1326e00000)
  	libm.so.6 => /lib64/libm.so.6 (0x00007f13274be000)
  	libtraceevent.so.1 => /lib64/libtraceevent.so.1 (0x00007f1327496000)
  	libtracefs.so.1 => /lib64/libtracefs.so.1 (0x00007f132746f000)
  	libcrypto.so.3 => /lib64/libcrypto.so.3 (0x00007f1326800000)
  	libunwind-x86_64.so.8 => /lib64/libunwind-x86_64.so.8 (0x00007f1327452000)
  	libunwind.so.8 => /lib64/libunwind.so.8 (0x00007f1327436000)
  	liblzma.so.5 => /lib64/liblzma.so.5 (0x00007f1327403000)
  	libdw.so.1 => /lib64/libdw.so.1 (0x00007f1326d6f000)
  	libz.so.1 => /lib64/libz.so.1 (0x00007f13273e2000)
  	libelf.so.1 => /lib64/libelf.so.1 (0x00007f1326d53000)
  	libnuma.so.1 => /lib64/libnuma.so.1 (0x00007f13273d4000)
  	libslang.so.2 => /lib64/libslang.so.2 (0x00007f1326400000)
  	libperl.so.5.38 => /lib64/libperl.so.5.38 (0x00007f1326000000)
  	libc.so.6 => /lib64/libc.so.6 (0x00007f1325e0f000)
  	libzstd.so.1 => /lib64/libzstd.so.1 (0x00007f1326741000)
  	/lib64/ld-linux-x86-64.so.2 (0x00007f13277a3000)
  	libbz2.so.1 => /lib64/libbz2.so.1 (0x00007f1326d3f000)
  	libcrypt.so.2 => /lib64/libcrypt.so.2 (0x00007f1326d07000)
  ⬢[acme@toolbox perf-tools-next]$

And when having capstone-devel installed we get it detected and linked with
perf, allowing us to benefit from the features that it enables:

  ⬢[acme@toolbox perf-tools-next]$ rpm -q capstone-devel
  capstone-devel-5.0.1-3.fc40.x86_64
  ⬢[acme@toolbox perf-tools-next]$ ldd /tmp/build/perf-tools-next/perf | grep capstone
  	libcapstone.so.5 => /lib64/libcapstone.so.5 (0x00007fe6a5c00000)
  ⬢[acme@toolbox perf-tools-next]$ /tmp/build/perf-tools-next/perf -vv | grep cap
             libcapstone: [ on  ]  # HAVE_LIBCAPSTONE_SUPPORT
  ⬢[acme@toolbox perf-tools-next]$

Fixes: 8b767db3309595a2 ("perf: build: introduce the libcapstone")
    Cc: Adrian Hunter <adrian.hunter@intel.com>
    Cc: Andi Kleen <andi@firstfloor.org>
    Cc: Changbin Du <changbin.du@huawei.com>
    Cc: Ian Rogers <irogers@google.com>
    Cc: Jiri Olsa <jolsa@kernel.org>
    Cc: Kan Liang <kan.liang@linux.intel.com>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Link: https://lore.kernel.org/lkml/Zry0sepD5Ppa5YKP@x1
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2024-11-18 19:23:38 +01:00
Michael Petlan 4adc388508 tools build: Correct bpf fixdep dependencies
JIRA: https://issues.redhat.com/browse/RHEL-29796

upstream
========
commit dbb2a7a986971ef43d5a60d235c05491647e16f4
Author: Brian Norris <briannorris@chromium.org>
Date: Mon Jul 15 13:32:44 2024 -0700

description
===========
The dependencies in tools/lib/bpf/Makefile are incorrect. Before we
recurse to build $(BPF_IN_STATIC), we need to build its 'fixdep'
executable.

I can't use the usual shortcut from Makefile.include:

  <target>: <sources> fixdep

because its 'fixdep' target relies on $(OUTPUT), and $(OUTPUT) differs
in the parent 'make' versus the child 'make' -- so I imitate it via
open-coding.

I tweak a few $(MAKE) invocations while I'm at it, because
1. I'm adding a new recursive make; and
2. these recursive 'make's print spurious lines about files that are "up
   to date" (which isn't normally a feature in Kbuild subtargets) or
   "jobserver not available" (see [1])

I also need to tweak the assignment of the OUTPUT variable, so that
relative path builds work. For example, for 'make tools/lib/bpf', OUTPUT
is unset, and is usually treated as "cwd" -- but recursive make will
change cwd and so OUTPUT has a new meaning. For consistency, I ensure
OUTPUT is always an absolute path.

And $(Q) gets a backup definition in tools/build/Makefile.include,
because Makefile.include is sometimes included without
tools/build/Makefile, so the "quiet command" stuff doesn't actually work
consistently without it.

After this change, top-level builds result in an empty grep result from:

  $ grep 'cannot find fixdep' $(find tools/ -name '*.cmd')

[1] https://www.gnu.org/software/make/manual/html_node/MAKE-Variable.html
If we're not using $(MAKE) directly, then we need to use more '+'.

    Signed-off-by: Brian Norris <briannorris@chromium.org>
    Acked-by: Andrii Nakryiko <andrii@kernel.org>
    Acked-by: Jiri Olsa <jolsa@kernel.org>
    Cc: Ian Rogers <irogers@google.com>
    Cc: Josh Poimboeuf <jpoimboe@kernel.org>
    Cc: Masahiro Yamada <masahiroy@kernel.org>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Thomas Richter <tmricht@linux.ibm.com>
    Link: https://lore.kernel.org/r/20240715203325.3832977-4-briannorris@chromium.org
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2024-11-18 19:23:34 +01:00
Michael Petlan 2250368f20 tools build: Avoid circular .fixdep-in.o.cmd issues
JIRA: https://issues.redhat.com/browse/RHEL-29796

upstream
========
commit ea974028a049f2cea4bb6be963ee3e3844a03f6d
Author: Brian Norris <briannorris@chromium.org>
Date: Mon Jul 15 13:32:43 2024 -0700

description
===========
The 'fixdep' tool is used to post-process dependency files for various
reasons, and it runs after every object file generation command. This
even includes 'fixdep' itself.

In Kbuild, this isn't actually a problem, because it uses a single
command to generate fixdep (a compile-and-link command on fixdep.c), and
afterward runs the fixdep command on the accompanying .fixdep.cmd file.

In tools/ builds (which notably is maintained separately from Kbuild),
fixdep is generated in several phases:

 1. fixdep.c -> fixdep-in.o
 2. fixdep-in.o -> fixdep

Thus, fixdep is not available in the post-processing for step 1, and
instead, we generate .cmd files that look like:

  ## from tools/objtool/libsubcmd/.fixdep.o.cmd
  # cannot find fixdep (/path/to/linux/tools/objtool/libsubcmd//fixdep)
  [...]

These invalid .cmd files are benign in some respects, but cause problems
in others (such as the linked reports).

Because the tools/ build system is rather complicated in its own right
(and pointedly different than Kbuild), I choose to simply open-code the
rule for building fixdep, and avoid the recursive-make indirection that
produces the problem in the first place.

    Signed-off-by: Brian Norris <briannorris@chromium.org>
    Acked-by: Jiri Olsa <jolsa@kernel.org>
    Cc: Ian Rogers <irogers@google.com>
    Cc: Josh Poimboeuf <jpoimboe@kernel.org>
    Cc: Masahiro Yamada <masahiroy@kernel.org>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Thomas Richter <tmricht@linux.ibm.com>
    Link: https://lore.kernel.org/all/Zk-C5Eg84yt6_nml@google.com/
    Link: https://lore.kernel.org/r/20240715203325.3832977-3-briannorris@chromium.org
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2024-11-18 19:23:34 +01:00
Michael Petlan e69c6639f4 perf: build: Link lib 'zstd' for static build
JIRA: https://issues.redhat.com/browse/RHEL-29795

upstream
========
commit f42596c73872b753ff1799bc7fc79b1100226da1
Author: Leo Yan <leo.yan@arm.com>
Date: Wed Jul 17 09:22:10 2024 +0100

description
===========
When build static perf, Makefile reports the error:

  Makefile.config:480: No libdw DWARF unwind found, Please install
  elfutils-devel/libdw-dev >= 0.158 and/or set LIBDW_DIR

The libdw has been installed on the system, but the build system fails
to build the feature detecting binary 'test-libdw-dwarf-unwind'. The
failure is caused by missing to link the lib 'zstd'.

Link lib 'zstd' for the static build, in the end, the dwarf feature can
be enabled in the static perf.

    Signed-off-by: Leo Yan <leo.yan@arm.com>
    Tested-by: Ian Rogers <irogers@google.com>
    Cc: amadio@gentoo.org
    Cc: James Clark <james.clark@linaro.org>
    Cc: Thomas Richter <tmricht@linux.ibm.com>
    Link: https://lore.kernel.org/r/20240717082211.524826-6-leo.yan@arm.com
    Signed-off-by: Namhyung Kim <namhyung@kernel.org>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2024-10-14 13:03:01 +02:00
Michael Petlan 72e836a4c9 perf: build: Link lib 'lzma' for static build
JIRA: https://issues.redhat.com/browse/RHEL-29795

upstream
========
commit 91b6a536b40658c24d6f04747ddf852d30f7f259
Author: Leo Yan <leo.yan@arm.com>
Date: Wed Jul 17 09:22:09 2024 +0100

description
===========
The libunwind feature test failed with the static linkage. This is due
to the 'lzma' lib is missed, so link it to dismiss building failure.

    Signed-off-by: Leo Yan <leo.yan@arm.com>
    Tested-by: Ian Rogers <irogers@google.com>
    Cc: amadio@gentoo.org
    Cc: James Clark <james.clark@linaro.org>
    Cc: Thomas Richter <tmricht@linux.ibm.com>
    Link: https://lore.kernel.org/r/20240717082211.524826-5-leo.yan@arm.com
    Signed-off-by: Namhyung Kim <namhyung@kernel.org>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2024-10-14 13:03:01 +02:00
Michael Petlan 2f64d7f18c perf: build: Only link libebl.a for old libdw
JIRA: https://issues.redhat.com/browse/RHEL-29795

upstream
========
commit 536661da6ea18fe6df5740bc9e9001d097b035ee
Author: Leo Yan <leo.yan@arm.com>
Date: Wed Jul 17 09:22:08 2024 +0100

description
===========
Since libdw version 0.177, elfutils has merged libebl.a into libdw (see
the commit "libebl: Don't install libebl.a, libebl.h and remove backends
from spec." in the elfutils repository).

As a result, libebl.a does not exist on Debian Bullseye and newer
releases, causing static perf builds to fail on these distributions.

This commit checks the libdw version and only links libebl.a if it
detects that the libdw version is older than 0.177.

    Signed-off-by: Leo Yan <leo.yan@arm.com>
    Tested-by: Ian Rogers <irogers@google.com>
    Cc: amadio@gentoo.org
    Cc: James Clark <james.clark@linaro.org>
    Cc: Thomas Richter <tmricht@linux.ibm.com>
    Link: https://lore.kernel.org/r/20240717082211.524826-4-leo.yan@arm.com
    Signed-off-by: Namhyung Kim <namhyung@kernel.org>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2024-10-14 13:03:01 +02:00
Michael Petlan cc2f07ab12 perf: build: Setup PKG_CONFIG_LIBDIR for cross compilation
JIRA: https://issues.redhat.com/browse/RHEL-29795

upstream
========
commit 440cf77625e300e683ca0edc39fbc4b6f3175feb
Author: Leo Yan <leo.yan@arm.com>
Date: Wed Jul 17 09:22:06 2024 +0100

description
===========
On recent Linux distros like Ubuntu Noble and Debian Bookworm, the
'pkg-config-aarch64-linux-gnu' package is missing. As a result, the
aarch64-linux-gnu-pkg-config command is not available, which causes
build failures.

When a build passes the environment variables PKG_CONFIG_LIBDIR or
PKG_CONFIG_PATH, like a user uses make command or a build system
(like Yocto, Buildroot, etc) prepares the variables and passes to the
Perf's Makefile, the commit keeps these variables for package
configuration. Otherwise, this commit sets the PKG_CONFIG_LIBDIR
variable to use the Multiarch libs for the cross compilation.

    Signed-off-by: Leo Yan <leo.yan@arm.com>
    Tested-by: Ian Rogers <irogers@google.com>
    Cc: amadio@gentoo.org
    Cc: Thomas Richter <tmricht@linux.ibm.com>
    Link: https://lore.kernel.org/r/20240717082211.524826-2-leo.yan@arm.com
    Signed-off-by: Namhyung Kim <namhyung@kernel.org>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2024-10-14 13:03:01 +02:00
Michael Petlan 497f56c782 tools: Make pkg-config dependency checks usable by other tools
JIRA: https://issues.redhat.com/browse/RHEL-29795

upstream
========
commit 8f61e98ad51f167de148488b1881de72fec0d563
Author: Guilherme Amadio <amadio@gentoo.org>
Date: Wed Jul 17 19:47:36 2024 +0200

description
===========
Other tools, in tools/verification and tools/tracing, make use of
libtraceevent and libtracefs as dependencies. This allows setting
up the feature check flags for them as well.

    Signed-off-by: Guilherme Amadio <amadio@gentoo.org>
    Tested-by: Thorsten Leemhuis <linux@leemhuis.info>
    Tested-by: Leo Yan <leo.yan@arm.com>
    Acked-by: Steven Rostedt (Google) <rostedt@goodmis.org>
    Cc: linux-trace-devel@vger.kernel.org
    Link: https://lore.kernel.org/r/20240717174739.186988-3-amadio@gentoo.org
    Signed-off-by: Namhyung Kim <namhyung@kernel.org>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2024-10-14 13:03:01 +02:00
Michael Petlan 5b38e64b18 tools: build: use correct lib name for libtracefs feature detection
JIRA: https://issues.redhat.com/browse/RHEL-29795

upstream
========
commit 28beb730ee167e505c86d1a8ae239e97d0136b13
Author: Daniel Wagner <dwagner@suse.de>
Date: Mon Jun 17 20:38:04 2024 +0200

description
===========
Use libtracefs as package name to lookup the CFLAGS for libtracefs. This
makes it possible to use the distro specific path as include path for
the header file.

    Link: https://lkml.kernel.org/r/20240617-rtla-build-v1-1-6882c34678e8@suse.de

    Cc: Daniel Bristot de Oliveira <bristot@kernel.org>
    Signed-off-by: Daniel Wagner <dwagner@suse.de>
    Signed-off-by: Daniel Bristot de Oliveira <bristot@kernel.org>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2024-10-14 13:02:55 +02:00
Michael Petlan 91d4174bdf perf: build: introduce the libcapstone
JIRA: https://issues.redhat.com/browse/RHEL-29571

upstream
========
commit 8b767db3309595a23eff1c3f2498f17b1f3a9bbc
Author: Changbin Du <changbin.du@huawei.com>
Date: Sat Feb 17 15:40:42 2024 +0800

description
===========
Later we will use libcapstone to disassemble instructions of samples.

    Signed-off-by: Changbin Du <changbin.du@huawei.com>
    Reviewed-by: Adrian Hunter <adrian.hunter@intel.com>
    Cc: changbin.du@gmail.com
    Cc: Thomas Richter <tmricht@linux.ibm.com>
    Cc: Andi Kleen <ak@linux.intel.com>
    Signed-off-by: Namhyung Kim <namhyung@kernel.org>
    Link: https://lore.kernel.org/r/20240217074046.4100789-2-changbin.du@huawei.com

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2024-06-25 10:47:30 +02:00
Michael Petlan 4c90a73c82 perf cs-etm: Bump minimum OpenCSD version to ensure a bugfix is present
JIRA: https://issues.redhat.com/browse/RHEL-25824

upstream
========
commit 2dbba30fd69b604802a9535b74bddb5bcca23793
Author: James Clark <james.clark@arm.com>
Date: Fri Sep 1 14:37:15 2023 +0100

description
===========
Since commit d927ef5004ef ("perf cs-etm: Add exception level consistency
check"), the exception that was added to Perf will be triggered unless
the following bugfix from OpenCSD is present:

 - _Version 1.2.1_:
  - __Bugfix__:
    ETM4x / ETE - output of context elements to client can in some
    circumstances be delayed until after subsequent atoms have been
    processed leading to incorrect memory decode access via the client
    callbacks. Fixed to flush context elements immediately they are
    committed.

Rather than remove the assert and silently fail, just increase the
minimum version requirement to avoid hard to debug issues and
regressions.

    Reviewed-by: Ian Rogers <irogers@google.com>
    Signed-off-by: James Clark <james.clark@arm.com>
    Tested-by: Leo Yan <leo.yan@linaro.org>
    Cc: John Garry <john.g.garry@oracle.com>
    Cc: Mike Leach <mike.leach@linaro.org>
    Cc: Will Deacon <will@kernel.org>
    Cc: linux-arm-kernel@lists.infradead.org
    Link: https://lore.kernel.org/r/20230901133716.677499-1-james.clark@arm.com
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2024-04-03 19:37:13 +02:00
Michael Petlan 83124c8e4a perf build: Add feature check for dwarf_getcfi()
JIRA: https://issues.redhat.com/browse/RHEL-25824

upstream
========
commit f67f2fda7d997a43e3323aec88d76f1b5e0ea5f2
Author: Namhyung Kim <namhyung@kernel.org>
Date: Thu Nov 9 15:59:27 2023 -0800

description
===========
The dwarf_getcfi() is available on libdw 0.142+.  Instead of just
checking the version number, it'd be nice to have a config item to check
the feature at build time.

    Suggested-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
    Signed-off-by: Namhyung Kim <namhyung@kernel.org>
    Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
    Cc: Adrian Hunter <adrian.hunter@intel.com>
    Cc: Andi Kleen <ak@linux.intel.com>
    Cc: Ian Rogers <irogers@google.com>
    Cc: Ingo Molnar <mingo@kernel.org>
    Cc: Jiri Olsa <jolsa@kernel.org>
    Cc: Linus Torvalds <torvalds@linux-foundation.org>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Stephane Eranian <eranian@google.com>
    Cc: linux-toolchains@vger.kernel.org
    Cc: linux-trace-devel@vger.kernel.org
    Link: https://lore.kernel.org/r/20231110000012.3538610-9-namhyung@kernel.org
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2024-04-03 19:37:12 +02:00
Radu Rendec dc4293fbbe tools/build: Fix -s detection code in tools/build/Makefile.build
JIRA: https://issues.redhat.com/browse/RHEL-21819

commit d9997f7ffb137447aa2f820c26cb1e6f5890d978
Author: Jiri Olsa <jolsa@kernel.org>
Date:   Sun Oct 8 23:22:50 2023 +0200

    tools/build: Fix -s detection code in tools/build/Makefile.build

    As Dmitry described in [1] changelog the current way of detecting
    -s option is broken for new make.

    Changing the tools/build -s option detection the same way as it was
    fixed for root Makefile in [1].

    [1] 4bf73588165b ("kbuild: Port silent mode detection to future gnu make.")

    Cc: Dmitry Goncharov <dgoncharov@users.sf.net>
    Signed-off-by: Jiri Olsa <jolsa@kernel.org>
    Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
    Acked-by: Namhyung Kim <namhyung@kernel.org>
    Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
    Cc: KP Singh <kpsingh@chromium.org>
    Cc: Martin KaFai Lau <kafai@fb.com>
    Cc: Song Liu <songliubraving@fb.com>
    Cc: Yonghong Song <yhs@fb.com>
    Cc: John Fastabend <john.fastabend@gmail.com>
    Cc: Hao Luo <haoluo@google.com>
    Cc: Ian Rogers <irogers@google.com>
    Cc: Stanislav Fomichev <sdf@google.com>
    Cc: Daniel Borkmann <daniel@iogearbox.net>
    Cc: Quentin Monnet <quentin@isovalent.com>
    Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
    Cc: Andrii Nakryiko <andrii@kernel.org>
    Cc: Alexei Starovoitov <ast@kernel.org>
    Cc: Ingo Molnar <mingo@kernel.org>
    Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
    Cc: bpf@vger.kernel.org
    Cc: linux-perf-users@vger.kernel.org
    Link: https://lore.kernel.org/r/20231008212251.236023-2-jolsa@kernel.org
    Signed-off-by: Namhyung Kim <namhyung@kernel.org>

Signed-off-by: Radu Rendec <rrendec@redhat.com>
2024-01-16 15:03:26 -05:00
Jerome Marchand 68dffb4663 bpf: Replace deprecated -target with --target= for Clang
JIRA: https://issues.redhat.com/browse/RHEL-10691

Conflicts: Change due to missing commit edae34a3ed92 ("selftests net:
add UDP GRO fraglist + bpf self-tests").

commit bbaf1ff06af49e856501024abbe161d96c1f0d66
Author: Fangrui Song <maskray@google.com>
Date:   Sat Jun 24 00:18:56 2023 +0000

    bpf: Replace deprecated -target with --target= for Clang

    The -target option has been deprecated since clang 3.4 in 2013. Therefore, use
    the preferred --target=bpf form instead. This also matches how we use --target=
    in scripts/Makefile.clang.

    Signed-off-by: Fangrui Song <maskray@google.com>
    Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
    Acked-by: Yonghong Song <yhs@fb.com>
    Acked-by: Quentin Monnet <quentin@isovalent.com>
    Link: 274b6f0c87
    Link: https://lore.kernel.org/bpf/20230624001856.1903733-1-maskray@google.com

Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
2023-12-14 15:22:22 +01:00
Michael Petlan 39b4d65947 tools build: Fix llvm feature detection, still used by bpftool
JIRA: https://issues.redhat.com/browse/RHEL-15009

upstream
========
commit 4fa008a2db484024a5cb52676a1b1534dc82330c
Author: Arnaldo Carvalho de Melo <acme@redhat.com>
Date: Thu Oct 19 18:09:33 2023 -0300

description
===========
When removing the BPF event for perf a feature test that checks if the
llvm devel files are availabe was removed but that is also used by
bpftool.

bpftool uses it to decide what kind of disassembly it will use: llvm or
binutils based.

Removing the tools/build/feature/test-llvm.cpp file made bpftool to
always fallback to binutils disassembly, even with the llvm devel files
installed, fix it by restoring just that small test-llvm.cpp test file.

Fixes: 56b11a2126bf2f42 ("perf bpf: Remove support for embedding clang for compiling BPF events (-e foo.c)")
    Reported-by: Manu Bretelle <chantr4@gmail.com>
    Reviewed-by: Ian Rogers <irogers@google.com>
    Reviewed-by: Manu Bretelle <chantr4@gmail.com>
    Acked-by: Quentin Monnet <quentin@isovalent.com>
    Cc: Adrian Hunter <adrian.hunter@intel.com>
    Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
    Cc: Andi Kleen <ak@linux.intel.com>
    Cc: Andrii Nakryiko <andrii@kernel.org>
    Cc: Anshuman Khandual <anshuman.khandual@arm.com>
    Cc: Carsten Haitzler <carsten.haitzler@arm.com>
    Cc: Eduard Zingerman <eddyz87@gmail.com>
    Cc: Fangrui Song <maskray@google.com>
    Cc: He Kuang <hekuang@huawei.com>
    Cc: Ingo Molnar <mingo@redhat.com>
    Cc: James Clark <james.clark@arm.com>
    Cc: Jiri Olsa <jolsa@kernel.org>
    Cc: Kan Liang <kan.liang@linux.intel.com>
    Cc: Leo Yan <leo.yan@linaro.org>
    Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
    Cc: Mark Rutland <mark.rutland@arm.com>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Cc: Nathan Chancellor <nathan@kernel.org>
    Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
    Cc: Nick Desaulniers <ndesaulniers@google.com>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Ravi Bangoria <ravi.bangoria@amd.com>
    Cc: Rob Herring <robh@kernel.org>
    Cc: Tiezhu Yang <yangtiezhu@loongson.cn>
    Cc: Tom Rix <trix@redhat.com>
    Cc: Wang Nan <wangnan0@huawei.com>
    Cc: Wang ShaoBo <bobo.shaobowang@huawei.com>
    Cc: Yang Jihong <yangjihong1@huawei.com>
    Cc: Yonghong Song <yhs@fb.com>
    Cc: YueHaibing <yuehaibing@huawei.com>
    Link: https://lore.kernel.org/lkml/ZTGa0Ukt7QyxWcVy@kernel.org
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2023-11-13 11:22:22 +01:00
Michael Petlan edb41b6cb5 perf bpf: Remove support for embedding clang for compiling BPF events (-e foo.c)
JIRA: https://issues.redhat.com/browse/RHEL-15009

upstream
========
commit 56b11a2126bf2f422831ecf6112b87a4485b221b
Author: Ian Rogers <irogers@google.com>
Date: Fri Aug 11 12:19:48 2023 -0300

description
===========
This never was in the default build for perf, is difficult to maintain
as it uses clang/llvm internals so ditch it, keeping, for now, the
external compilation of .c BPF into .o bytecode and its subsequent
loading, that is also going to be removed, do it separately to help
bisection and to properly document what is being removed and why.

Committer notes:

Extracted from a larger patch and removed some leftovers, namely
deleting these now unused feature tests:

    tools/build/feature/test-clang.cpp
    tools/build/feature/test-cxx.cpp
    tools/build/feature/test-llvm-version.cpp
    tools/build/feature/test-llvm.cpp

Testing the use of BPF events after applying this patch:

To use the external clang/llvm toolchain to compile a .c event and then
use libbpf to load it, to get the syscalls:sys_enter_open* tracepoints
and read the filename pointer, putting it into the ring buffer right
after the usual tracepoint payload for 'perf trace' to then print it:

  [root@quaco ~]# perf trace -e /home/acme/git/perf-tools-next/tools/perf/examples/bpf/augmented_raw_syscalls.c,open* --max-events=10
     0.000 systemd-oomd/959 openat(dfd: CWD, filename: "/proc/meminfo", flags: RDONLY|CLOEXEC) = 12
     0.083 abrt-dump-jour/1453 openat(dfd: CWD, filename: "/var/log/journal/d6a97235307247e09f13f326fb607e3c/system.journal", flags: RDONLY|CLOEXEC|NONBLOCK) = 4
     0.063 abrt-dump-jour/1454 openat(dfd: CWD, filename: "/var/log/journal/d6a97235307247e09f13f326fb607e3c/system.journal", flags: RDONLY|CLOEXEC|NONBLOCK) = 4
     0.082 abrt-dump-jour/1455 openat(dfd: CWD, filename: "/var/log/journal/d6a97235307247e09f13f326fb607e3c/system.journal", flags: RDONLY|CLOEXEC|NONBLOCK) = 4
   250.124 systemd-oomd/959 openat(dfd: CWD, filename: "/proc/meminfo", flags: RDONLY|CLOEXEC) = 12
   250.521 systemd-oomd/959 openat(dfd: CWD, filename: "/sys/fs/cgroup/user.slice/user-1000.slice/user@1000.service/app.slice/memory.pressure", flags: RDONLY|CLOEXEC) = 12
   251.047 systemd-oomd/959 openat(dfd: CWD, filename: "/sys/fs/cgroup/user.slice/user-1000.slice/user@1000.service/app.slice/memory.current", flags: RDONLY|CLOEXEC) = 12
   251.162 systemd-oomd/959 openat(dfd: CWD, filename: "/sys/fs/cgroup/user.slice/user-1000.slice/user@1000.service/app.slice/memory.min", flags: RDONLY|CLOEXEC) = 12
   251.242 systemd-oomd/959 openat(dfd: CWD, filename: "/sys/fs/cgroup/user.slice/user-1000.slice/user@1000.service/app.slice/memory.low", flags: RDONLY|CLOEXEC) = 12
   251.353 systemd-oomd/959 openat(dfd: CWD, filename: "/sys/fs/cgroup/user.slice/user-1000.slice/user@1000.service/app.slice/memory.swap.current", flags: RDONLY|CLOEXEC) = 12
  [root@quaco ~]#

Same thing, but with a prebuilt .o BPF bytecode:

  [root@quaco ~]# perf trace -e /home/acme/git/perf-tools-next/tools/perf/examples/bpf/augmented_raw_syscalls.o,open* --max-events=10
     0.000 systemd-oomd/959 openat(dfd: CWD, filename: "/proc/meminfo", flags: RDONLY|CLOEXEC) = 12
     0.083 abrt-dump-jour/1453 openat(dfd: CWD, filename: "/var/log/journal/d6a97235307247e09f13f326fb607e3c/system.journal", flags: RDONLY|CLOEXEC|NONBLOCK) = 4
     0.083 abrt-dump-jour/1455 openat(dfd: CWD, filename: "/var/log/journal/d6a97235307247e09f13f326fb607e3c/system.journal", flags: RDONLY|CLOEXEC|NONBLOCK) = 4
     0.062 abrt-dump-jour/1454 openat(dfd: CWD, filename: "/var/log/journal/d6a97235307247e09f13f326fb607e3c/system.journal", flags: RDONLY|CLOEXEC|NONBLOCK) = 4
   249.985 systemd-oomd/959 openat(dfd: CWD, filename: "/proc/meminfo", flags: RDONLY|CLOEXEC) = 12
   466.763 thermald/1234 openat(dfd: CWD, filename: "/sys/class/powercap/intel-rapl/intel-rapl:0/intel-rapl:0:2/energy_uj") = 13
   467.145 thermald/1234 openat(dfd: CWD, filename: "/sys/class/powercap/intel-rapl/intel-rapl:0/energy_uj") = 13
   467.311 thermald/1234 openat(dfd: CWD, filename: "/sys/class/thermal/thermal_zone2/temp") = 13
   500.040 cgroupify/24006 openat(dfd: 4, filename: ".", flags: RDONLY|CLOEXEC|DIRECTORY|NONBLOCK) = 5
   500.295 cgroupify/24006 openat(dfd: 4, filename: "24616/cgroup.procs") = 5
  [root@quaco ~]#

    Signed-off-by: Ian Rogers <irogers@google.com>
    Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
    Cc: Adrian Hunter <adrian.hunter@intel.com>
    Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
    Cc: Andi Kleen <ak@linux.intel.com>
    Cc: Andrii Nakryiko <andrii@kernel.org>
    Cc: Anshuman Khandual <anshuman.khandual@arm.com>
    Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
    Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
    Cc: Carsten Haitzler <carsten.haitzler@arm.com>
    Cc: Eduard Zingerman <eddyz87@gmail.com>
    Cc: Fangrui Song <maskray@google.com>
    Cc: He Kuang <hekuang@huawei.com>
    Cc: Ingo Molnar <mingo@redhat.com>
    Cc: James Clark <james.clark@arm.com>
    Cc: Jiri Olsa <jolsa@kernel.org>
    Cc: Kan Liang <kan.liang@linux.intel.com>
    Cc: Leo Yan <leo.yan@linaro.org>
    Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
    Cc: Mark Rutland <mark.rutland@arm.com>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Cc: Nathan Chancellor <nathan@kernel.org>
    Cc: "Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com>
    Cc: Nick Desaulniers <ndesaulniers@google.com>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Ravi Bangoria <ravi.bangoria@amd.com>
    Cc: Rob Herring <robh@kernel.org>
    Cc: Tiezhu Yang <yangtiezhu@loongson.cn>
    Cc: Tom Rix <trix@redhat.com>
    Cc: Wang Nan <wangnan0@huawei.com>
    Cc: Wang ShaoBo <bobo.shaobowang@huawei.com>
    Cc: Yang Jihong <yangjihong1@huawei.com>
    Cc: Yonghong Song <yhs@fb.com>
    Cc: YueHaibing <yuehaibing@huawei.com>
    Link: https://lore.kernel.org/lkml/ZNZWsAXg2px1sm2h@kernel.org
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2023-11-13 11:21:50 +01:00
Michael Petlan c2a67795c1 perf build: Update feature check for clang and llvm
JIRA: https://issues.redhat.com/browse/RHEL-15009

upstream
========
commit 4e95ed4f4d5bc6838a10e6952999b41b1d07e56f
Author: Thomas Richter <tmricht@linux.ibm.com>
Date: Tue Jul 25 17:03:46 2023 +0200

description
===========
Perf build auto-detects features and packages already installed for its
build. This is done in directory tools/build/feature. This directory
contains small sample programs. When they successfully compile the
necessary prereqs in form of libraries and header files are present.

Such a check is also done for llvm and clang. And the checks fail.

Fix this and update to the latest C++ standard and use the new library
provided by clang (which contains new packaging) s/ee this link for
reference:

 https://fedoraproject.org/wiki/Changes/Stop-Shipping-Individual-Component-Libraries-In-clang-lib-Package

Output before:
 # rm -f ./test-clang.bin; make test-clang.bin; ./test-clang.bin; \
	ll test-clang.make.output
 g++  -MD -Wall -Werror -o test-clang.bin test-clang.cpp \
	 	> test-clang.make.output 2>&1 -std=gnu++14 \
	-I/usr/include 		\
	-L/usr/lib64		\
	-Wl,--start-group -lclangBasic -lclangDriver	\
	  -lclangFrontend -lclangEdit -lclangLex	\
	  -lclangAST -Wl,--end-group 			\
	-lLLVM-16	\
			\
	> test-clang.make.output 2>&1
 make: *** [Makefile:356: test-clang.bin] Error 1
 -bash: ./test-clang.bin: No such file or directory
 -rw-r--r--. 1 root root 252041 Jul 12 09:56 test-clang.make.output
 #

File test-clang.make.output contains many lines of unreferenced
symbols.

Output after:
 # rm -f ./test-clang.bin; make test-clang.bin; ./test-clang.bin; \
	cat test-clang.make.output
 g++  -MD -Wall -Werror -o test-clang.bin test-clang.cpp \
	 > test-clang.make.output 2>&1 -std=gnu++17	\
	-I/usr/include 		\
	-L/usr/lib64		\
	-Wl,--start-group -lclang-cpp -Wl,--end-group	\
	-lLLVM-16	\
			\
	> test-clang.make.output 2>&1
 #

Committer notes:

Test it in the tools/build/feature directory, and have clang-devel and
llvm-devel installed.

    Signed-off-by: Thomas Richter <tmricht@linux.ibm.com>
    Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
    Cc: Heiko Carstens <hca@linux.ibm.com>
    Cc: Ian Rogers <irogers@google.com>
    Cc: Jiri Olsa <jolsa@kernel.org>
    Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
    Cc: Sven Schnelle <svens@linux.ibm.com>
    Cc: Vasily Gorbik <gor@linux.ibm.com>
    Cc: Wang Nan <wangnan0@huawei.com>
    Link: https://lore.kernel.org/r/20230725150347.3479291-1-tmricht@linux.ibm.com
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2023-11-13 11:21:46 +01:00
Michael Petlan 6f98ab6001 tools: Bump minimum LLVM C++ std to GNU++14
JIRA: https://issues.redhat.com/browse/RHEL-15009

upstream
========
commit d0d0f0c12461daf2f642d2779abe566e00716069
Author: Ian Rogers <irogers@google.com>
Date: Mon Oct 11 19:13:20 2021 -0700

description
===========
LLVM 9 (current release is LLVM 13) moved the minimum C++ version to
GNU++14. Bump the version numbers in the feature test and perf build.

    Reviewed-by: Fangrui Song <maskray@google.com>
    Signed-off-by: Ian Rogers <irogers@google.com>
    Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
    Cc: Daniel Borkmann <daniel@iogearbox.net>
    Cc: Ingo Molnar <mingo@redhat.com>
    Cc: Jiri Olsa <jolsa@redhat.com>
    Cc: Leo Yan <leo.yan@linaro.org>
    Cc: Mark Rutland <mark.rutland@arm.com>
    Cc: Michael Petlan <mpetlan@redhat.com>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Cc: Nathan Chancellor <nathan@kernel.org>
    Cc: Nick Desaulniers <ndesaulniers@google.com>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Sedat Dilek <sedat.dilek@gmail.com>
    Cc: llvm@lists.linux.dev
    Link: https://lore.kernel.org/r/20211012021321.291635-1-irogers@google.com
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2023-11-13 11:21:46 +01:00
Michael Petlan 2a49fc4965 perf build: Update build rule for generated files
JIRA: https://issues.redhat.com/browse/RHEL-15009

upstream
========
commit 7822a8913f4c51c7d1aff793b525d60c3384fb5b
Author: Namhyung Kim <namhyung@kernel.org>
Date: Thu Jul 27 19:24:46 2023 -0700

description
===========
The bison and flex generate C files from the source (.y and .l)
files.  When O= option is used, they are saved in a separate directory
but the default build rule assumes the .C files are in the source
directory.  So it might read invalid file if there are generated files
from an old version.  The same is true for the pmu-events files.

For example, the following command would cause a build failure:

  $ git checkout v6.3
  $ make -C tools/perf  # build in the same directory

  $ git checkout v6.5-rc2
  $ mkdir build  # create a build directory
  $ make -C tools/perf O=build  # build in a different directory but it
                                # refers files in the source directory

Let's update the build rule to specify those cases explicitly to depend
on the files in the output directory.

Note that it's not a complete fix and it needs the next patch for the
include path too.

Fixes: 80eeb67fe5 ("perf jevents: Program to convert JSON file")
    Signed-off-by: Namhyung Kim <namhyung@kernel.org>
    Cc: Adrian Hunter <adrian.hunter@intel.com>
    Cc: Andi Kleen <ak@linux.intel.com>
    Cc: Anup Sharma <anupnewsmail@gmail.com>
    Cc: Ian Rogers <irogers@google.com>
    Cc: Ingo Molnar <mingo@kernel.org>
    Cc: Jiri Olsa <jolsa@kernel.org>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: stable@vger.kernel.org
    Link: https://lore.kernel.org/r/20230728022447.1323563-1-namhyung@kernel.org
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2023-11-13 11:21:35 +01:00
Michael Petlan f2a3eea6a0 perf build: Fix broken feature check for libtracefs due to external lib changes
Bugzilla: https://bugzilla.redhat.com/2233483

upstream
========
commit a87834d19aa2bf455e2fd9309ef4754eccd8459a
Author: Thomas Richter <tmricht@linux.ibm.com>
Date: Tue Jul 11 15:53:38 2023 +0200

description
===========
The perf build process auto-detects features and packages already
installed for its build. This is done in directory tools/build/feature.
This directory contains small sample programs. When they successfully
compile the necessary prereqs in form of libraries and header files are
present.

Such a check is also done for libtracefs. And this check fails:

Output before:
 # rm -f test-libtracefs.bin; make test-libtracefs.bin
 gcc  -MD -Wall -Werror -o test-libtracefs.bin test-libtracefs.c \
	 > test-libtracefs.make.output 2>&1 -ltracefs
 make: *** [Makefile:211: test-libtracefs.bin] Error 1
 # cat test-libtracefs.make.output
 In file included from test-libtracefs.c:2:
 /usr/include/tracefs/tracefs.h:11:10: fatal error: \
	 event-parse.h: No such file or directory
   11 | #include <event-parse.h>
      |          ^~~~~~~~~~~~~~~
 compilation terminated.
 #

The root cause of this compile error is commit 880885d9c22e
("libtracefs: Remove "traceevent/" from referencing libtraceevent
headers") in the libtracefs project hosted here:
https://git.kernel.org/pub/scm/libs/libtrace/libtracefs.git/

That mentioned patch removes the traceevent/ directory name from
the include statement, causing the file not to be included even
when the libtraceevent-devel package is installed. This package contains
the file referred to in tracefs/tracefs.h:

 # rpm -ql libtraceevent-devel
 /usr/include/traceevent
 /usr/include/traceevent/event-parse.h  <----- here
 /usr/include/traceevent/event-utils.h
 /usr/include/traceevent/kbuffer.h
 /usr/include/traceevent/trace-seq.h
 /usr/lib64/libtraceevent.so
 /usr/lib64/pkgconfig/libtraceevent.pc
 #

With this patch the compile succeeds.

Output after:
 # rm -f test-libtracefs.bin; make test-libtracefs.bin
 gcc  -MD -Wall -Werror -o test-libtracefs.bin test-libtracefs.c \
	 > test-libtracefs.make.output 2>&1 -I/usr/include/traceevent -ltracefs
 #

Committer testing:

  $ make -k BUILD_BPF_SKEL=1 CORESIGHT=1 O=/tmp/build/perf-tools -C tools/perf install-bin

Before:

  $ cat /tmp/build/perf-tools/feature/test-libtracefs.make.output
  In file included from test-libtracefs.c:2:
  /usr/include/tracefs/tracefs.h:11:10: fatal error: event-parse.h: No such file or directory
     11 | #include <event-parse.h>
        |          ^~~~~~~~~~~~~~~
  compilation terminated.
  $
  $ grep -i tracefs /tmp/build/perf-tools/FEATURE-DUMP
  feature-libtracefs=0
  $

After:

  $ cat /tmp/build/perf-tools/feature/test-libtracefs.make.output
  $
  $ grep -i tracefs /tmp/build/perf-tools/FEATURE-DUMP
  feature-libtracefs=1
  $

    Signed-off-by: Thomas Richter <tmricht@linux.ibm.com>
    Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
    Cc: Heiko Carstens <hca@linux.ibm.com>
    Cc: Jiri Olsa <jolsa@kernel.org>
    Cc: Steven Rostedt (VMware) <rostedt@goodmis.org>
    Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
    Cc: Sven Schnelle <svens@linux.ibm.com>
    Cc: Vasily Gorbik <gor@linux.ibm.com>
    Link: https://lore.kernel.org/r/20230711135338.397473-1-tmricht@linux.ibm.com
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2023-09-18 13:03:37 +02:00
Michael Petlan 66220e6c68 tools build: Add a feature test for scandirat(), that is not implemented so far in musl and uclibc
Bugzilla: https://bugzilla.redhat.com/2233483

upstream
========
commit 9e03608e93858620317d54bc88a9a0069bce003d
Author: Arnaldo Carvalho de Melo <acme@redhat.com>
Date: Tue Apr 4 11:05:57 2023 -0300

description
===========
We use it just when listing tracepoint events, and for root, so just
emit a warning about it to get users to ask the library maintainers to
implement it, as suggested in this systemd ticket:

 https://github.com/systemd/casync/issues/129

    Cc: Adrian Hunter <adrian.hunter@intel.com>
    Cc: Ian Rogers <irogers@google.com>
    Cc: Jiri Olsa <jolsa@kernel.org>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Link: https://lore.kernel.org/lkml/ZCwv4z5Dh%2FdHUMG6@kernel.org/
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2023-09-18 11:59:54 +02:00
Michael Petlan c4dabed921 tools build: Add feature test for abi::__cxa_demangle
Bugzilla: https://bugzilla.redhat.com/2233483

upstream
========
commit 4c72e2b35afc414140a59fb3c06ebc54e506c245
Author: Ian Rogers <irogers@google.com>
Date: Fri Mar 10 22:57:48 2023 -0800

description
===========
cxxabi.h is part of libsdtc++ and LLVM's libcxx, providing
abi::__cxa_demangle a portable C++ demangler. Add a feature test to
detect that the function is available.

    Signed-off-by: Ian Rogers <irogers@google.com>
    Cc: Adrian Hunter <adrian.hunter@intel.com>
    Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
    Cc: Andres Freund <andres@anarazel.de>
    Cc: Ingo Molnar <mingo@redhat.com>
    Cc: Jiri Olsa <jolsa@kernel.org>
    Cc: Leo Yan <leo.yan@linaro.org>
    Cc: Mark Rutland <mark.rutland@arm.com>
    Cc: Martin Liška <mliska@suse.cz>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Cc: Nathan Chancellor <nathan@kernel.org>
    Cc: Nick Desaulniers <ndesaulniers@google.com>
    Cc: Pavithra Gurushankar <gpavithrasha@gmail.com>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Quentin Monnet <quentin@isovalent.com>
    Cc: Roberto Sassu <roberto.sassu@huawei.com>
    Cc: Stephane Eranian <eranian@google.com>
    Cc: Tiezhu Yang <yangtiezhu@loongson.cn>
    Cc: Tom Rix <trix@redhat.com>
    Cc: Yang Jihong <yangjihong1@huawei.com>
    Cc: llvm@lists.linux.dev
    Link: https://lore.kernel.org/r/20230311065753.3012826-2-irogers@google.com
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2023-09-18 11:59:08 +02:00
Michael Petlan 6e99dd90a1 perf build: Remove libbpf pre-1.0 feature tests
Bugzilla: https://bugzilla.redhat.com/2233483

upstream
========
commit 76a97cf2e169851ff8e3fd9d27028168eff81e37
Author: Ian Rogers <irogers@google.com>
Date: Sun Jan 15 17:01:14 2023 -0800

description
===========
The feature tests were necessary for libbpf pre-1.0, but as the libbpf
implies at least 1.0 we can remove these now.

Committer notes:

Modified tools/perf/Makefile.config to better reflect the reason for
failure when the libbpf present is < 1.0 and LIBBPF_DYNAMIC=1 was asked
for.

    Signed-off-by: Ian Rogers <irogers@google.com>
    Acked-by: Jiri Olsa <jolsa@kernel.org>
    Tested-by: Jiri Olsa <jolsa@kernel.org>
    Cc: Adrian Hunter <adrian.hunter@intel.com>
    Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
    Cc: Andres Freund <andres@anarazel.de>
    Cc: Andrii Nakryiko <andrii@kernel.org>
    Cc: Christy Lee <christylee@fb.com>
    Cc: Ingo Molnar <mingo@redhat.com>
    Cc: Mark Rutland <mark.rutland@arm.com>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Quentin Monnet <quentin@isovalent.com>
    Cc: Roberto Sassu <roberto.sassu@huawei.com>
    Cc: bpf@vger.kernel.org
    Link: https://lore.kernel.org/r/20230116010115.490713-2-irogers@google.com
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2023-09-18 11:59:05 +02:00
Michael Petlan c518739612 tools build: Pass libbpf feature only if libbpf 1.0+
Bugzilla: https://bugzilla.redhat.com/2233483

upstream
========
commit 56d5229471ee1634bd0eb029f1aa82a8d87c6fed
Author: Ian Rogers <irogers@google.com>
Date: Sun Jan 15 17:01:13 2023 -0800

description
===========
libbpf 1.0 represented a cleanup and stabilization of APIs. Simplify
development by only passing the feature test if libbpf 1.0 is installed.

Committer notes:

Change 'make -C tools/perf build-test' so that the LIBBPF_DYNAMIC=1 test
runs only if libbpf is >= 1.0.

    Signed-off-by: Ian Rogers <irogers@google.com>
    Tested-by: Jiri Olsa <jolsa@kernel.org>
    Acked-by: Jiri Olsa <jolsa@kernel.org>
    Cc: Adrian Hunter <adrian.hunter@intel.com>
    Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
    Cc: Andres Freund <andres@anarazel.de>
    Cc: Andrii Nakryiko <andrii@kernel.org>
    Cc: Christy Lee <christylee@fb.com>
    Cc: Ingo Molnar <mingo@redhat.com>
    Cc: Mark Rutland <mark.rutland@arm.com>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Quentin Monnet <quentin@isovalent.com>
    Cc: Roberto Sassu <roberto.sassu@huawei.com>
    Cc: bpf@vger.kernel.org
    Link: https://lore.kernel.org/r/20230116010115.490713-2-irogers@google.com
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2023-09-18 11:59:04 +02:00
Michael Petlan 919571ffa8 tools build: Add test echo-cmd
Bugzilla: https://bugzilla.redhat.com/2177183

upstream
========
commit e30f34053e5bc552829249941120ad042ba27723
Author: Ian Rogers <irogers@google.com>
Date: Thu Jan 26 15:36:44 2023 -0800

description
===========
Add quiet_cmd_test so that:
$(Q)$(call echo-cmd,test)

will print:
TEST   <path>

This is useful for executing compile-time tests similar to what
happens for fortify tests in the kernel's lib directory.

    Reviewed-by: Kajol Jain <kjain@linux.ibm.com>
    Signed-off-by: Ian Rogers <irogers@google.com>
    Cc: Adrian Hunter <adrian.hunter@intel.com>
    Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
    Cc: Caleb Biggers <caleb.biggers@intel.com>
    Cc: Florian Fischer <florian.fischer@muhq.space>
    Cc: Ian Rogers <irogers@google.com>
    Cc: Ingo Molnar <mingo@redhat.com>
    Cc: James Clark <james.clark@arm.com>
    Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
    Cc: Jiri Olsa <jolsa@kernel.org>
    Cc: John Garry <john.g.garry@oracle.com>
    Cc: Kan Liang <kan.liang@linux.intel.com>
    Cc: Kang Minchul <tegongkang@gmail.com>
    Cc: Kim Phillips <kim.phillips@amd.com>
    Cc: Leo Yan <leo.yan@linaro.org>
    Cc: Mark Rutland <mark.rutland@arm.com>
    Cc: Mike Leach <mike.leach@linaro.org>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Cc: Perry Taylor <perry.taylor@intel.com>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Ravi Bangoria <ravi.bangoria@amd.com>
    Cc: Rob Herring <robh@kernel.org>
    Cc: Sandipan Das <sandipan.das@amd.com>
    Cc: Stephane Eranian <eranian@google.com>
    Cc: Will Deacon <will@kernel.org>
    Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
    Cc: linux-arm-kernel@lists.infradead.org
    Cc: linuxppc-dev@lists.ozlabs.org
    Link: https://lore.kernel.org/r/20230126233645.200509-15-irogers@google.com
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2023-06-14 12:23:26 +02:00
Michael Petlan 8303f5b4a5 perf bpf: Fix build with libbpf 0.7.0 by checking if bpf_program__set_insns() is available
Bugzilla: https://bugzilla.redhat.com/2177180

upstream
========
commit f1bdebbb67bd21d7c5dfc42f313f2f54002440b8
Author: Arnaldo Carvalho de Melo <acme@redhat.com>
Date: Wed Oct 19 08:44:17 2022 -0400

description
===========
During the transition to libbpf 1.0 some functions that perf used were
deprecated and finally removed from libbpf, so bpf_program__set_insns()
was introduced for perf to continue to use its bpf loader.

But when build with LIBBPF_DYNAMIC=1 we now need to check if that
function is available so that perf can build with older libbpf versions,
even if the end result is emitting a warning to the user that the use
of the perf BPF loader requires a newer libbpf, since bpf_program__set_insns()
touches libbpf objects internal state.

This affects only 'perf trace' when using bpf C code or pre-compiled
bytecode as an event.

Noticed on RHEL9, that has libbpf 0.7.0, where bpf_program__set_insns()
isn't available.

    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2023-06-01 17:02:54 +02:00
Michael Petlan ea3263e560 tools build: Display logical OR of a feature flavors
Bugzilla: https://bugzilla.redhat.com/2177180

upstream
========
commit 74ef1cc9587870016f2a528c03634607b9d53093
Author: Roberto Sassu <roberto.sassu@huawei.com>
Date: Thu Aug 18 14:09:57 2022 +0200

description
===========
Sometimes, features are simply different flavors of another feature, to
properly detect the exact dependencies needed by different Linux
distributions.

For example, libbfd has three flavors: libbfd if the distro does not
require any additional dependency; libbfd-liberty if it requires libiberty;
libbfd-liberty-z if it requires libiberty and libz.

It might not be clear to the user whether a feature has been successfully
detected or not, given that some of its flavors will be set to OFF, others
to ON.

Instead, display only the feature main flavor if not in verbose mode
(VF != 1), and set it to ON if at least one of its flavors has been
successfully detected (logical OR), OFF otherwise. Omit the other flavors.

Accomplish that by declaring a FEATURE_GROUP_MEMBERS-<feature main flavor>
variable, with the list of the other flavors as variable value. For now, do
it just for libbfd.

In verbose mode, of if no group is defined for a feature, show the feature
detection result as before.

Committer testing:

Collecting the output from:

  $ make -C tools/bpf/bpftool/ clean
  $ make -C tools/bpf/bpftool/ |& grep "Auto-detecting system features" -A10

  $ diff -u before after
  --- before	2022-08-18 10:06:40.422086966 -0300
  +++ after	2022-08-18 10:07:59.202138282 -0300
  @@ -1,6 +1,4 @@
   Auto-detecting system features:
   ...                                  libbfd: [ on  ]
  -...                          libbfd-liberty: [ on  ]
  -...                        libbfd-liberty-z: [ on  ]
   ...                                  libcap: [ on  ]
   ...                         clang-bpf-co-re: [ on  ]
  $

    Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
    Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
    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: Namhyung Kim <namhyung@kernel.org>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Quentin Monnet <quentin@isovalent.com>
    Cc: bpf@vger.kernel.org
    Link: https://lore.kernel.org/r/20220818120957.319995-3-roberto.sassu@huaweicloud.com
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2023-06-01 17:02:35 +02:00
Michael Petlan 2af637933d tools build: Increment room for feature name in feature detection output
Bugzilla: https://bugzilla.redhat.com/2177180

upstream
========
commit 74da7697a2ab988e3889ba4db78992a0944ea83d
Author: Roberto Sassu <roberto.sassu@huawei.com>
Date: Thu Aug 18 14:09:56 2022 +0200

description
===========
Since now there are features with a long name, increase the room for them,
so that fields are correctly aligned.

    Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
    Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
    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: Namhyung Kim <namhyung@kernel.org>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Quentin Monnet <quentin@isovalent.com>
    Cc: bpf@vger.kernel.org
    Link: https://lore.kernel.org/r/20220818120957.319995-2-roberto.sassu@huaweicloud.com
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2023-06-01 17:02:35 +02:00
Michael Petlan 1306ff9b2c tools build: Fix feature detection output due to eval expansion
Bugzilla: https://bugzilla.redhat.com/2177180

upstream
========
commit 709533e51b166d5a520589a03f0044ed304b33bd
Author: Roberto Sassu <roberto.sassu@huawei.com>
Date: Thu Aug 18 14:09:55 2022 +0200

description
===========
As the first eval expansion is used only to generate Makefile statements,
messages should not be displayed at this stage, as for example conditional
expressions are not evaluated.

It can be seen for example in the output of feature detection for bpftool,
where the number of detected features does not change, despite turning on
the verbose mode (VF = 1) and there are additional features to display.

Fix this issue by escaping the $ before $(info) statements, to ensure that
messages are printed only when the function containing them is actually
executed, and not when it is expanded.

In addition, move the $(info) statement out of feature_print_status, due to
the fact that is called both inside and outside an eval context, and place
it to the caller so that the $ can be escaped when necessary. For symmetry,
move the $(info) statement also out of feature_print_text, and place it to
the caller.

Force the TMP variable evaluation in verbose mode, to display the features
in FEATURE_TESTS that are not in FEATURE_DISPLAY.

Reorder perf feature detection messages (first non-verbose, then verbose
ones) by moving the call to feature_display_entries earlier, before the VF
environment variable check.

Also, remove the newline from that function, as perf might display
additional messages. Move the newline to perf Makefile, and display another
one if displaying the detection result is not deferred as in the case of
bpftool.

Committer testing:

  Collecting the output from:

  $ make VF=1 -C tools/bpf/bpftool/ |& grep "Auto-detecting system features" -A20

  $ diff -u before after
  --- before	2022-08-18 09:59:55.460529231 -0300
  +++ after	2022-08-18 10:01:11.182517282 -0300
  @@ -4,3 +4,5 @@
   ...              libbfd-liberty-z: [ on  ]
   ...                        libcap: [ on  ]
   ...               clang-bpf-co-re: [ on  ]
  +...        disassembler-four-args: [ on  ]
  +...      disassembler-init-styled: [ OFF ]
  $

Fixes: 0afc5cad38 ("perf build: Separate feature make support into config/Makefile.feature")
    Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
    Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
    Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
    Cc: bpf@vger.kernel.org
    Cc: Ingo Molnar <mingo@redhat.com>
    Cc: Jiri Olsa <jolsa@kernel.org>
    Cc: Mark Rutland <mark.rutland@arm.com>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Quentin Monnet <quentin@isovalent.com>
    Link: https://lore.kernel.org/r/20220818120957.319995-1-roberto.sassu@huaweicloud.com
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2023-06-01 17:02:35 +02:00
Yauheni Kaliuta 9fe0951ec3 perf build: Fix btf__load_from_kernel_by_id() feature check
Bugzilla: http://bugzilla.redhat.com/2120968

commit 73534617dfa3c4cd95fe5ffaeff5315e9ffc2de6
Author: Jiri Olsa <jolsa@kernel.org>
Date:   Tue May 24 14:06:12 2022 +0200

    perf build: Fix btf__load_from_kernel_by_id() feature check
    
    The btf__load_from_kernel_by_id() only takes one arg, not two.
    
    Committer notes:
    
    I tested it just with an older libbpf, one where
    btf__load_from_kernel_by_id() wasn't introduced yet.
    
    A test with a newer dynamic libbpf would fail because the
    btf__load_from_kernel_by_id() is there, but takes just one arg.
    
    Fixes: 0ae065a5d265bc5a ("perf build: Fix check for btf__load_from_kernel_by_id() in libbpf")
    Signed-off-by: Jiri Olsa <jolsa@kernel.org>
    Cc: Heiko Carstens <hca@linux.ibm.com>
    Cc: Ian Rogers <irogers@google.com>
    Cc: Ilya Leoshkevich <iii@linux.ibm.com>
    Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
    Cc: Sven Schnelle <svens@linux.ibm.com>
    Cc: Thomas Richter <tmricht@linux.ibm.com>
    Cc: Vasily Gorbik <gor@linux.ibm.com>
    Link: http://lore.kernel.org/linux-perf-users/YozLKby7ITEtchC9@krava
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Yauheni Kaliuta <ykaliuta@redhat.com>
2022-11-30 12:47:13 +02:00
Yauheni Kaliuta dc26144a3b perf build: Stop using __weak bpf_map_create() to handle older libbpf versions
Bugzilla: http://bugzilla.redhat.com/2120968

commit df76e0038370d364d4b2154fa7ddbbccc29f629f
Author: Arnaldo Carvalho de Melo <acme@redhat.com>
Date:   Thu May 26 11:48:58 2022 -0300

    perf build: Stop using __weak bpf_map_create() to handle older libbpf versions
    
    By adding a feature test for bpf_map_create() and providing a fallback if
    it isn't present in older versions of libbpf.
    
    This also fixes the build with torvalds/master at this point:
    
      $ git log --oneline -5 torvalds/master
      babf0bb978e3c9fc (torvalds/master) Merge tag 'xfs-5.19-for-linus' of git://git.kernel.org/pub/scm/fs/xfs/xfs-linux
      e375780b631a5fc2 Merge tag 'fsnotify_for_v5.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs
      8b728edc5be16179 Merge tag 'fs_for_v5.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs
      3f306ea2e18568f6 Merge tag 'dma-mapping-5.19-2022-05-25' of git://git.infradead.org/users/hch/dma-mapping
      fbe86daca0ba878b Merge tag 'scsi-misc' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi
      $
    
    Coping with:
    
      $ git log --oneline -2 d16495a982324f75
      d16495a982324f75 libbpf: remove bpf_create_map*() APIs
      e2371b1632b1c61c libbpf: start 1.0 development cycle
      $
    
    As the __weak function fails to build as it calls the now removed
    bpf_create_map() API.
    
    Testing:
    
      $ rpm -q libbpf-devel
      libbpf-devel-0.4.0-2.fc35.x86_64
      $
      $ make -C tools/perf BUILD_BPF_SKEL=1 LIBBPF_DYNAMIC=1 O=/tmp/build/perf install-bin
      $ cat /tmp/build/perf/feature/test-libbpf-bpf_map_create.make.output
      test-libbpf-bpf_map_create.c: In function ‘main’:
      test-libbpf-bpf_map_create.c:6:16: error: implicit declaration of function ‘bpf_map_create’; did you mean ‘bpf_map_freeze’? [-Werror=implicit-function-declaration]
          6 |         return bpf_map_create(0 /* map_type */, NULL /* map_name */, 0, /* key_size */,
            |                ^~~~~~~~~~~~~~
            |                bpf_map_freeze
      test-libbpf-bpf_map_create.c:6:87: error: expected expression before ‘,’ token
          6 |         return bpf_map_create(0 /* map_type */, NULL /* map_name */, 0, /* key_size */,
            |                                                                                       ^
      cc1: all warnings being treated as errors
      $
      $ objdump -dS /tmp/build/perf/perf | grep '<bpf_map_create>:' -A20
      000000000058b290 <bpf_map_create>:
      {
        58b290:     55                      push   %rbp
        58b291:     48 89 e5                mov    %rsp,%rbp
        58b294:     48 83 ec 10             sub    $0x10,%rsp
        58b298:     64 48 8b 04 25 28 00    mov    %fs:0x28,%rax
        58b29f:     00 00
        58b2a1:     48 89 45 f8             mov    %rax,-0x8(%rbp)
        58b2a5:     31 c0                   xor    %eax,%eax
            return bpf_create_map(map_type, key_size, value_size, max_entries, 0);
        58b2a7:     48 8b 45 f8             mov    -0x8(%rbp),%rax
        58b2ab:     64 48 2b 04 25 28 00    sub    %fs:0x28,%rax
        58b2b2:     00 00
        58b2b4:     75 10                   jne    58b2c6 <bpf_map_create+0x36>
      }
        58b2b6:     c9                      leave
        58b2b7:     89 d6                   mov    %edx,%esi
        58b2b9:     89 ca                   mov    %ecx,%edx
        58b2bb:     44 89 c1                mov    %r8d,%ecx
            return bpf_create_map(map_type, key_size, value_size, max_entries, 0);
        58b2be:     45 31 c0                xor    %r8d,%r8d
      $
    
    Cc: Andrii Nakryiko <andrii@kernel.org>
    Cc: Heiko Carstens <hca@linux.ibm.com>
    Cc: Ian Rogers <irogers@google.com>
    Cc: Ilya Leoshkevich <iii@linux.ibm.com>
    Cc: Jiri Olsa <jolsa@kernel.org>
    Cc: Song Liu <songliubraving@fb.com>
    Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
    Cc: Sven Schnelle <svens@linux.ibm.com>
    Cc: Thomas Richter <tmricht@linux.ibm.com>
    Cc: Vasily Gorbik <gor@linux.ibm.com>
    Link: http://lore.kernel.org/linux-perf-users/Yo+XvQNKL4K5khl2@kernel.org
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Yauheni Kaliuta <ykaliuta@redhat.com>
2022-11-30 12:47:13 +02:00
Yauheni Kaliuta d2fe692d2a perf build: Stop using __weak btf__raw_data() to handle older libbpf versions
Bugzilla: http://bugzilla.redhat.com/2120968

commit 982be4775164d4780d9c6a2f38b365f5b5bd16d4
Author: Jiri Olsa <jolsa@kernel.org>
Date:   Tue May 24 13:16:20 2022 +0200

    perf build: Stop using __weak btf__raw_data() to handle older libbpf versions
    
    By adding a feature test for btf__raw_data() and providing a fallback if
    it isn't present in older versions of libbpf.
    
    Committer testing:
    
      $ rpm -q libbpf-devel
      libbpf-devel-0.4.0-2.fc35.x86_64
      $ make -C tools/perf LIBBPF_DYNAMIC=1 O=/tmp/build/perf install-bin
      $ cat /tmp/build/perf/feature/test-libbpf-btf__raw_data.make.output
      test-libbpf-btf__raw_data.c: In function ‘main’:
      test-libbpf-btf__raw_data.c:6:9: error: implicit declaration of function ‘btf__raw_data’; did you mean ‘btf__get_raw_data’? [-Werror=implicit-function-declaration]
          6 |         btf__raw_data(NULL /* btf_ro */, NULL /* size */);
            |         ^~~~~~~~~~~~~
            |         btf__get_raw_data
      cc1: all warnings being treated as errors
      $ objdump -dS /tmp/build/perf/perf | grep '<btf__raw_data>:' -A20
      00000000005b3050 <btf__raw_data>:
      {
        5b3050:     55                      push   %rbp
        5b3051:     48 89 e5                mov    %rsp,%rbp
        5b3054:     48 83 ec 10             sub    $0x10,%rsp
        5b3058:     64 48 8b 04 25 28 00    mov    %fs:0x28,%rax
        5b305f:     00 00
        5b3061:     48 89 45 f8             mov    %rax,-0x8(%rbp)
        5b3065:     31 c0                   xor    %eax,%eax
              return btf__get_raw_data(btf_ro, size);
        5b3067:     48 8b 45 f8             mov    -0x8(%rbp),%rax
        5b306b:     64 48 2b 04 25 28 00    sub    %fs:0x28,%rax
        5b3072:     00 00
        5b3074:     75 06                   jne    5b307c <btf__raw_data+0x2c>
      }
        5b3076:     c9                      leave
              return btf__get_raw_data(btf_ro, size);
        5b3077:     e9 14 99 e5 ff          jmp    40c990 <btf__get_raw_data@plt>
        5b307c:     e8 af a7 e5 ff          call   40d830 <__stack_chk_fail@plt>
        5b3081:     66 66 2e 0f 1f 84 00    data16 cs nopw 0x0(%rax,%rax,1)
        5b3088:     00 00 00 00
        $
    
    Signed-off-by: Jiri Olsa <jolsa@kernel.org>
    Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
    Cc: Heiko Carstens <hca@linux.ibm.com>
    Cc: Ian Rogers <irogers@google.com>
    Cc: Ilya Leoshkevich <iii@linux.ibm.com>
    Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
    Cc: Sven Schnelle <svens@linux.ibm.com>
    Cc: Thomas Richter <tmricht@linux.ibm.com>
    Cc: Vasily Gorbik <gor@linux.ibm.com>
    Link: http://lore.kernel.org/linux-perf-users/YozLKby7ITEtchC9@krava
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Yauheni Kaliuta <ykaliuta@redhat.com>
2022-11-30 12:47:13 +02:00
Yauheni Kaliuta 73f42af8c0 perf build: Stop using __weak bpf_prog_load() to handle older libbpf versions
Bugzilla: http://bugzilla.redhat.com/2120968
Conflicts: already applied
  8916d72554e5 ("perf build: Stop using __weak bpf_object__next_program() to handle older libbpf versions")
  739c9180cfa4 ("perf build: Stop using __weak bpf_object__next_map() to handle older libbpf versions")

commit 5c83eff38194ab2c69a7dc1a64a0a3683f0a3c3a
Author: Jiri Olsa <jolsa@kernel.org>
Date:   Tue May 24 13:04:43 2022 +0200

    perf build: Stop using __weak bpf_prog_load() to handle older libbpf versions

    By adding a feature test for bpf_prog_load() and providing a fallback if
    it isn't present in older versions of libbpf.

    Committer testing:

      $ rpm -q libbpf-devel
      libbpf-devel-0.4.0-2.fc35.x86_64
      $ make -C tools/perf LIBBPF_DYNAMIC=1 O=/tmp/build/perf install-bin
      $ cat /tmp/build/perf/feature/test-libbpf-bpf_prog_load.make.output
      test-libbpf-bpf_prog_load.c: In function ‘main’:
      test-libbpf-bpf_prog_load.c:6:16: error: implicit declaration of function ‘bpf_prog_load’ [-Werror=implicit-function-declaration]
          6 |         return bpf_prog_load(0 /* prog_type */, NULL /* prog_name */,
            |                ^~~~~~~~~~~~~
      cc1: all warnings being treated as errors
      $

      $ objdump -dS /tmp/build/perf/perf | grep '<bpf_prog_load>:' -A20
      00000000005b2d70 <bpf_prog_load>:
      {
        5b2d70:     55                      push   %rbp
        5b2d71:     48 89 ce                mov    %rcx,%rsi
        5b2d74:     4c 89 c8                mov    %r9,%rax
        5b2d77:     49 89 d2                mov    %rdx,%r10
        5b2d7a:     4c 89 c2                mov    %r8,%rdx
        5b2d7d:     48 89 e5                mov    %rsp,%rbp
        5b2d80:     48 83 ec 18             sub    $0x18,%rsp
        5b2d84:     64 48 8b 0c 25 28 00    mov    %fs:0x28,%rcx
        5b2d8b:     00 00
        5b2d8d:     48 89 4d f8             mov    %rcx,-0x8(%rbp)
        5b2d91:     31 c9                   xor    %ecx,%ecx
            return bpf_load_program(prog_type, insns, insn_cnt, license,
        5b2d93:     41 8b 49 5c             mov    0x5c(%r9),%ecx
        5b2d97:     51                      push   %rcx
        5b2d98:     4d 8b 49 60             mov    0x60(%r9),%r9
        5b2d9c:     4c 89 d1                mov    %r10,%rcx
        5b2d9f:     44 8b 40 1c             mov    0x1c(%rax),%r8d
        5b2da3:     e8 f8 aa e5 ff          call   40d8a0 <bpf_load_program@plt>
      }
      $

    Signed-off-by: Jiri Olsa <jolsa@kernel.org>
    Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
    Cc: Heiko Carstens <hca@linux.ibm.com>
    Cc: Ian Rogers <irogers@google.com>
    Cc: Ilya Leoshkevich <iii@linux.ibm.com>
    Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
    Cc: Sven Schnelle <svens@linux.ibm.com>
    Cc: Thomas Richter <tmricht@linux.ibm.com>
    Cc: Vasily Gorbik <gor@linux.ibm.com>
    Link: http://lore.kernel.org/linux-perf-users/YozLKby7ITEtchC9@krava
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Yauheni Kaliuta <ykaliuta@redhat.com>
2022-11-30 12:47:13 +02:00
Yauheni Kaliuta 5832b803e3 perf build: Fix check for btf__load_from_kernel_by_id() in libbpf
Bugzilla: http://bugzilla.redhat.com/2120968
Conflicts: already applied
  8916d72554e5 ("perf build: Stop using __weak bpf_object__next_program() to handle older libbpf versions")
  739c9180cfa4 ("perf build: Stop using __weak bpf_object__next_map() to handle older libbpf versions")

commit 0ae065a5d265bc5ada13e350015458e0c5e5c351
Author: Arnaldo Carvalho de Melo <acme@redhat.com>
Date:   Thu May 19 21:25:12 2022 -0300

    perf build: Fix check for btf__load_from_kernel_by_id() in libbpf

    Avi Kivity reported a problem where the __weak
    btf__load_from_kernel_by_id() in tools/perf/util/bpf-event.c was being
    used and it called btf__get_from_id() in tools/lib/bpf/btf.c that in
    turn called back to btf__load_from_kernel_by_id(), resulting in an
    endless loop.

    Fix this by adding a feature test to check if
    btf__load_from_kernel_by_id() is available when building perf with
    LIBBPF_DYNAMIC=1, and if not then provide the fallback to the old
    btf__get_from_id(), that doesn't call back to btf__load_from_kernel_by_id()
    since at that time it didn't exist at all.

    Tested on Fedora 35 where we have libbpf-devel 0.4.0 with LIBBPF_DYNAMIC
    where we don't have btf__load_from_kernel_by_id() and thus its feature
    test fail, not defining HAVE_LIBBPF_BTF__LOAD_FROM_KERNEL_BY_ID:

      $ cat /tmp/build/perf-urgent/feature/test-libbpf-btf__load_from_kernel_by_id.make.output
      test-libbpf-btf__load_from_kernel_by_id.c: In function ‘main’:
      test-libbpf-btf__load_from_kernel_by_id.c:6:16: error: implicit declaration of function ‘btf__load_from_kernel_by_id’ [-Werror=implicit-function-declaration]
          6 |         return btf__load_from_kernel_by_id(20151128, NULL);
            |                ^~~~~~~~~~~~~~~~~~~~~~~~~~~
      cc1: all warnings being treated as errors
      $

      $ nm /tmp/build/perf-urgent/perf | grep btf__load_from_kernel_by_id
      00000000005ba180 T btf__load_from_kernel_by_id
      $

      $ objdump --disassemble=btf__load_from_kernel_by_id -S /tmp/build/perf-urgent/perf

      /tmp/build/perf-urgent/perf:     file format elf64-x86-64
      <SNIP>
      00000000005ba180 <btf__load_from_kernel_by_id>:
      #include "record.h"
      #include "util/synthetic-events.h"

      #ifndef HAVE_LIBBPF_BTF__LOAD_FROM_KERNEL_BY_ID
      struct btf *btf__load_from_kernel_by_id(__u32 id)
      {
        5ba180:     55                      push   %rbp
        5ba181:     48 89 e5                mov    %rsp,%rbp
        5ba184:     48 83 ec 10             sub    $0x10,%rsp
        5ba188:     64 48 8b 04 25 28 00    mov    %fs:0x28,%rax
        5ba18f:     00 00
        5ba191:     48 89 45 f8             mov    %rax,-0x8(%rbp)
        5ba195:     31 c0                   xor    %eax,%eax
             struct btf *btf;
      #pragma GCC diagnostic push
      #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
             int err = btf__get_from_id(id, &btf);
        5ba197:     48 8d 75 f0             lea    -0x10(%rbp),%rsi
        5ba19b:     e8 a0 57 e5 ff          call   40f940 <btf__get_from_id@plt>
        5ba1a0:     89 c2                   mov    %eax,%edx
      #pragma GCC diagnostic pop

             return err ? ERR_PTR(err) : btf;
        5ba1a2:     48 98                   cltq
        5ba1a4:     85 d2                   test   %edx,%edx
        5ba1a6:     48 0f 44 45 f0          cmove  -0x10(%rbp),%rax
      }
      <SNIP>

    Fixes: 218e7b775d368f38 ("perf bpf: Provide a weak btf__load_from_kernel_by_id() for older libbpf versions")
    Reported-by: Avi Kivity <avi@scylladb.com>
    Link: https://lore.kernel.org/linux-perf-users/f0add43b-3de5-20c5-22c4-70aff4af959f@scylladb.com
    Cc: Adrian Hunter <adrian.hunter@intel.com>
    Cc: Ian Rogers <irogers@google.com>
    Cc: Jiri Olsa <jolsa@kernel.org>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Link: https://lore.kernel.org/linux-perf-users/YobjjFOblY4Xvwo7@kernel.org
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Yauheni Kaliuta <ykaliuta@redhat.com>
2022-11-30 12:47:13 +02:00
Michael Petlan 9fb1e96086 tools build: Switch to new openssl API for test-libcrypto
Bugzilla: https://bugzilla.redhat.com/2123229

upstream
========
commit 5b245985a6de5ac18b5088c37068816d413fb8ed
Author: Roberto Sassu <roberto.sassu@huawei.com>
Date: Tue Jul 19 19:05:55 2022 +0200

description
===========
Switch to new EVP API for detecting libcrypto, as Fedora 36 returns an
error when it encounters the deprecated function MD5_Init() and the others.

The error would be interpreted as missing libcrypto, while in reality it is
not.

Fixes: 6e8ccb4f62 ("tools/bpf: properly account for libbfd variations")
    Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
    Cc: Alexei Starovoitov <ast@kernel.org>
    Cc: Andrii Nakryiko <andrii@kernel.org>
    Cc: bpf@vger.kernel.org
    Cc: Daniel Borkmann <daniel@iogearbox.net>
    Cc: Ingo Molnar <mingo@redhat.com>
    Cc: John Fastabend <john.fastabend@gmail.com>
    Cc: KP Singh <kpsingh@kernel.org>
    Cc: llvm@lists.linux.dev
    Cc: Martin KaFai Lau <martin.lau@linux.dev>
    Cc: Nathan Chancellor <nathan@kernel.org>
    Cc: Nick Desaulniers <ndesaulniers@google.com>
    Cc: Nick Terrell <terrelln@fb.com>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Quentin Monnet <quentin@isovalent.com>
    Cc: Song Liu <song@kernel.org>
    Cc: Stanislav Fomichev <sdf@google.com>
    Link: https://lore.kernel.org/r/20220719170555.2576993-4-roberto.sassu@huawei.com
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2022-11-14 20:25:56 +01:00
Michael Petlan 953afe9a4c Revert "perf build: Suppress openssl v3 deprecation warnings in libcrypto feature test"
Bugzilla: https://bugzilla.redhat.com/2123229

upstream
========
commit 73f8ec5992d17a5431b7a2d123097981dbaa4769
Author: Arnaldo Carvalho de Melo <acme@redhat.com>
Date: Tue Aug 9 16:23:53 2022 -0300

description
===========
This reverts commit 10fef869a58e37ec649b61eddab545f2da57a79b.

Because a proper fix was submitted.

    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2022-11-14 20:25:56 +01:00
Michael Petlan 2957bfc02e perf build: Suppress openssl v3 deprecation warnings in libcrypto feature test
Bugzilla: https://bugzilla.redhat.com/2123229

upstream
========
commit 10fef869a58e37ec649b61eddab545f2da57a79b
Author: Zixuan Tan <tanzixuangg@gmail.com>
Date: Sat Jun 25 23:34:38 2022 +0800

description
===========
With OpenSSL v3 installed, the libcrypto feature check fails as it use the
deprecated MD5_* API (and is compiled with -Werror). The error message is
as follows.

$ make tools/perf
```
Makefile.config:778: No libcrypto.h found, disables jitted code injection,
please install openssl-devel or libssl-dev

Auto-detecting system features:
...                         dwarf: [ on  ]
...            dwarf_getlocations: [ on  ]
...                         glibc: [ on  ]
...                        libbfd: [ on  ]
...                libbfd-buildid: [ on  ]
...                        libcap: [ on  ]
...                        libelf: [ on  ]
...                       libnuma: [ on  ]
...        numa_num_possible_cpus: [ on  ]
...                       libperl: [ on  ]
...                     libpython: [ on  ]
...                     libcrypto: [ OFF ]
...                     libunwind: [ on  ]
...            libdw-dwarf-unwind: [ on  ]
...                          zlib: [ on  ]
...                          lzma: [ on  ]
...                     get_cpuid: [ on  ]
...                           bpf: [ on  ]
...                        libaio: [ on  ]
...                       libzstd: [ on  ]
...        disassembler-four-args: [ on  ]
```

This is very confusing because the suggested library (on my Ubuntu 20.04
it is libssl-dev) is already installed. As the test only checks for the
presence of libcrypto, this commit suppresses the deprecation warning to
allow the test to pass.

    Signed-off-by: Zixuan Tan <tanzixuan.me@gmail.com>
    Cc: Alexei Starovoitov <ast@kernel.org>
    Cc: Andrii Nakryiko <andrii@kernel.org>
    Cc: Daniel Borkmann <daniel@iogearbox.net>
    Cc: John Fastabend <john.fastabend@gmail.com>
    Cc: KP Singh <kpsingh@kernel.org>
    Cc: Martin KaFai Lau <kafai@fb.com>
    Cc: Nick Terrell <terrelln@fb.com>
    Cc: Song Liu <songliubraving@fb.com>
    Cc: Yonghong Song <yhs@fb.com>
    Cc: bpf@vger.kernel.org
    Cc: netdev@vger.kernel.org
    Link: https://lore.kernel.org/r/20220625153439.513559-1-tanzixuan.me@gmail.com
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2022-11-14 20:25:55 +01:00
Frantisek Hrbata f2b708e7b1 Merge: Update objtool to v5.19
Merge conflicts:
-----------------
arch/x86/include/asm/efi.h
        - arch_efi_call_virt() macro
          keep undef of arch_efi_call_virt from HEAD(!1326)
          ed88433ff2 ("efi: Simplify arch_efi_call_virt() macro"), otherwise
          resolve in favour of !1464

tools/perf/Makefile.perf
        - clean target
          keep removal of perf-with-kcore from HEAD(!1361)
          6da6e51e39 ("perf tools: Delete perf-with-kcore.sh script") and
          keep the make cond expr change from !1464
          403009a4d8 ("kbuild: replace $(if A,A,B) with $(or A,B)")

MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/1464

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2121207
Depends: !1351 for partial backport of e27e5bea956c ("x86/ibt, objtool: Add IBT_NOSEAL()")
Depends: !1370 for backport of 44b979fa302c ("x86/mm/64: Improve stack overflow warnings")

This MR seeks to update objtool and related patchsets.  The commits
incorporate patches and fixes from the following upstream patchsets
(some have been previously backported only in partial form):

v5.15:
* [PATCH 1/2] objtool: Check for gelf_update_rel[a] failures

v5.16:
* [PATCH v2 00/24] objtool/x86: noinstr vs PARAVIRT

v5.17:
* [PATCH kcsan 0/29] Kernel Concurrency Sanitizer (KCSAN) updates for v5.17
* [PATCH v2 00/23] x86: Remove anonymous out-of-line fixups
* [PATCH 00/10] Removal of most do_exit calls

v5.18:
* [PATCH v4 00/11] Re-enable ENQCMD and PASID MSR
* [PATCH v4 00/45] x86: Kernel IBT
* [PATCH] kbuild: replace $(if A,A,B) with $(or A,B) in scripts/Makefile.modpost
* [PATCH 0/4] objtool: Fix fallthrough detection for vmlinux
* [PATCH 0/2] objtool: Fix code reloc vs weak symbols
* [PATCH 0/4] objtool: Fixes
* [PATCH 0/6] x86: Various cleanups and fixes

v5.19:
* [PATCH v2 00/25] objtool: Interface overhaul

Omitted-fix: 00db58cf2118 fixes ee1f9d19143 and not this commit (inaccurate Fixed-by tag)
Omitted-fix: b1c45ad53efb fixes ee1f9d19143 and not this commit (inaccurate Fixed-by tag)

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>

Approved-by: Prarit Bhargava <prarit@redhat.com>
Approved-by: Rafael Aquini <aquini@redhat.com>
Approved-by: David Arcari <darcari@redhat.com>
Approved-by: Phil Auld <pauld@redhat.com>
Approved-by: Waiman Long <longman@redhat.com>

Signed-off-by: Frantisek Hrbata <fhrbata@redhat.com>
2022-11-09 03:13:13 -05:00
Joe Lawrence 403009a4d8 kbuild: replace $(if A,A,B) with $(or A,B)
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2121207
Conflicts:
	tools/counter/Makefile
	tools/tracing/rtla/Makefile
	- These do not exist in rhel9

commit 5c8166419acf468b5bc3e48f928a040485d3e0c2
Author: Masahiro Yamada <masahiroy@kernel.org>
Date:   Fri Feb 11 14:14:11 2022 +0900

    kbuild: replace $(if A,A,B) with $(or A,B)

    $(or ...) is available since GNU Make 3.81, and useful to shorten the
    code in some places.

    Covert as follows:

      $(if A,A,B)  -->  $(or A,B)

    This patch also converts:

      $(if A, A, B) --> $(or A, B)

    Strictly speaking, the latter is not an equivalent conversion because
    GNU Make keeps spaces after commas; if A is not empty, $(if A, A, B)
    expands to " A", while $(or A, B) expands to "A".

    Anyway, preceding spaces are not significant in the code hunks I touched.

    Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
    Reviewed-by: Nicolas Schier <nicolas@fjasle.eu>

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2022-10-27 14:27:59 -04:00
Michael Petlan 30e129789f tools build: Filter out options and warnings not supported by clang
Bugzilla: https://bugzilla.redhat.com/2123231

upstream
========
commit 41caff459a5b956b3e23ba9ca759dd0629ad3dda
Author: Arnaldo Carvalho de Melo <acme@redhat.com>
Date: Tue Apr 5 10:33:21 2022 -0300

description
===========
These make the feature check fail when using clang, so remove them just
like is done in tools/perf/Makefile.config to build perf itself.

Adding -Wno-compound-token-split-by-macro to tools/perf/Makefile.config
when building with clang is also necessary to avoid these warnings
turned into errors (-Werror):

    CC      /tmp/build/perf/util/scripting-engines/trace-event-perl.o
  In file included from util/scripting-engines/trace-event-perl.c:35:
  In file included from /usr/lib64/perl5/CORE/perl.h:4085:
  In file included from /usr/lib64/perl5/CORE/hv.h:659:
  In file included from /usr/lib64/perl5/CORE/hv_func.h:34:
  In file included from /usr/lib64/perl5/CORE/sbox32_hash.h:4:
  /usr/lib64/perl5/CORE/zaphod32_hash.h:150:5: error: '(' and '{' tokens introducing statement expression appear in different macro expansion contexts [-Werror,-Wcompound-token-split-by-macro]
      ZAPHOD32_SCRAMBLE32(state[0],0x9fade23b);
      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  /usr/lib64/perl5/CORE/zaphod32_hash.h:80:38: note: expanded from macro 'ZAPHOD32_SCRAMBLE32'
  #define ZAPHOD32_SCRAMBLE32(v,prime) STMT_START {  \
                                       ^~~~~~~~~~
  /usr/lib64/perl5/CORE/perl.h:737:29: note: expanded from macro 'STMT_START'
  #   define STMT_START   (void)( /* gcc supports "({ STATEMENTS; })" */
                                ^
  /usr/lib64/perl5/CORE/zaphod32_hash.h:150:5: note: '{' token is here
      ZAPHOD32_SCRAMBLE32(state[0],0x9fade23b);
      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  /usr/lib64/perl5/CORE/zaphod32_hash.h:80:49: note: expanded from macro 'ZAPHOD32_SCRAMBLE32'
  #define ZAPHOD32_SCRAMBLE32(v,prime) STMT_START {  \
                                                  ^
  /usr/lib64/perl5/CORE/zaphod32_hash.h:150:5: error: '}' and ')' tokens terminating statement expression appear in different macro expansion contexts [-Werror,-Wcompound-token-split-by-macro]
      ZAPHOD32_SCRAMBLE32(state[0],0x9fade23b);
      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  /usr/lib64/perl5/CORE/zaphod32_hash.h:87:41: note: expanded from macro 'ZAPHOD32_SCRAMBLE32'
      v ^= (v>>23);                       \
                                          ^
  /usr/lib64/perl5/CORE/zaphod32_hash.h:150:5: note: ')' token is here
      ZAPHOD32_SCRAMBLE32(state[0],0x9fade23b);
      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  /usr/lib64/perl5/CORE/zaphod32_hash.h:88:3: note: expanded from macro 'ZAPHOD32_SCRAMBLE32'
  } STMT_END
    ^~~~~~~~
  /usr/lib64/perl5/CORE/perl.h:738:21: note: expanded from macro 'STMT_END'
  #   define STMT_END     )
                          ^

Please refer to the discussion on the Link: tag below, where Nathan
clarifies the situation:

<quote>
acme> And then get to the problems at the end of this message, which seem
acme> similar to the problem described here:
acme>
acme> From  Nathan Chancellor <>
acme> Subject	[PATCH] mwifiex: Remove unnecessary braces from HostCmd_SET_SEQ_NO_BSS_INFO
acme>
acme> https://lkml.org/lkml/2020/9/1/135
acme>
acme> So perhaps in this case its better to disable that
acme> -Werror,-Wcompound-token-split-by-macro when building with clang?

Yes, I think that is probably the best solution. As far as I can tell,
at least in this file and context, the warning appears harmless, as the
"create a GNU C statement expression from two different macros" is very
much intentional, based on the presence of PERL_USE_GCC_BRACE_GROUPS.
The warning is fixed in upstream Perl by just avoiding creating GNU C
statement expressions using STMT_START and STMT_END:

  https://github.com/Perl/perl5/issues/18780
  https://github.com/Perl/perl5/pull/18984

If I am reading the source code correctly, an alternative to disabling
the warning would be specifying -DPERL_GCC_BRACE_GROUPS_FORBIDDEN but it
seems like that might end up impacting more than just this site,
according to the issue discussion above.
</quote>

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
2022-09-21 07:22:56 +02:00