Skip to contentSkip to conversation

Fix perf tools/lib includes

PATCH Superseded Ian Rogers 2 participants 21 messages Nov 8, 2022 – Nov 15, 2022

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Ian Rogers

author reviewer
#0 lore raw

cover Fix perf tools/lib includes

The previous build would add -Itools/lib and get dependencies for libtraceevent, libsubcmd, libsymbol, libapi and libbpf meaning that overriding these libraries would change the link time dependency but the headers would erroneously come from tools/lib. Fix the build to install headers and then depend on these. To reduce exposing internal headers/APIs some clean up is performed. tools/lib/symbol has a Makefile added, while tools/lib/api and tools/lib/subcmd have install targets added. The pattern used for the dependencies in Makefile.perf is modelled on libbpf.

The problem and solution were motivated by this issue and discussion:
https://lore.kernel.org/lkml/CAEf4BzbbOHQZUAe6iWaehKCPQAf3VC=hq657buqe2_yRKxaK-A@mail.gmail.com/

Ian Rogers (14):
tools lib api: Add install target
tools lib subcmd: Add install target
perf build: Install libsubcmd locally when building perf build: Install libapi locally when building perf build: Install libperf locally when building perf build: Install libtraceevent locally when building tools lib api: Add missing install headers tools lib perf: Add missing install headers tool lib symbol: Add Makefile/Build
perf build: Install libsymbol locally when building perf expr: Tidy hashmap dependency
perf thread_map: Reduce exposure of libperf internal API perf cpumap: Tidy libperf includes
perf build: Use tools/lib headers from install path

 tools/lib/api/Makefile                        |  52 ++++++
 tools/lib/perf/Makefile                       |  10 +-
 tools/lib/subcmd/Makefile                     |  49 ++++++
 tools/lib/symbol/Build                        |   1 +
 tools/lib/symbol/Makefile                     | 115 +++++++++++++
 tools/perf/.gitignore                         |   7 +-
 tools/perf/Makefile.config                    |   2 -
 tools/perf/Makefile.perf                      | 152 ++++++++++++------
 tools/perf/builtin-stat.c                     |   1 +
 tools/perf/builtin-trace.c                    |   4 +-
 tools/perf/tests/cpumap.c                     |   2 +-
 tools/perf/tests/expr.c                       |   1 +
 tools/perf/tests/openat-syscall.c             |   1 +
 tools/perf/tests/pmu-events.c                 |   1 +
 tools/perf/tests/thread-map.c                 |   1 +
 tools/perf/util/Build                         |   5 -
 tools/perf/util/auxtrace.h                    |   2 +-
 tools/perf/util/bpf-loader.c                  |   4 -
 tools/perf/util/bpf_counter.c                 |   2 +-
 tools/perf/util/cpumap.c                      |   1 +
 tools/perf/util/cpumap.h                      |   2 +-
 tools/perf/util/evsel.c                       |   5 +-
 tools/perf/util/evsel.h                       |   2 -
 tools/perf/util/expr.c                        |   1 +
 tools/perf/util/expr.h                        |   7 +-
 tools/perf/util/metricgroup.c                 |   1 +
 tools/perf/util/python.c                      |   6 +-
 .../scripting-engines/trace-event-python.c    |   2 +-
 tools/perf/util/stat-shadow.c                 |   1 +
 tools/perf/util/stat.c                        |   4 -
 tools/perf/util/thread_map.c                  |   1 +
 tools/perf/util/thread_map.h                  |   2 -
 32 files changed, 361 insertions(+), 86 deletions(-)
 create mode 100644 tools/lib/symbol/Build
 create mode 100644 tools/lib/symbol/Makefile
Signature · 1 line
2.38.1.431.g37b22c650d-goog
author reviewer
#1 lore raw

PATCH 1/14 tools lib api: Add install target

This allows libapi to be installed as a dependency.

---
 tools/lib/api/Makefile | 49 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)
tools/lib/api/Makefile +49 -0
index e21e1b40b525..6629d0fd0130 100644
@@ -15,6 +15,16 @@ LD ?= $(CROSS_COMPILE)ld
 
 MAKEFLAGS += --no-print-directory
 
+INSTALL = install
+
+
+# Use DESTDIR for installing into a different root directory.
+# This is useful for building a package. The program will be
+# installed in this directory as if it was the root directory.
+# Then the build tool can move it later.
+DESTDIR ?=
+DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))'
+
 LIBFILE = $(OUTPUT)libapi.a
 
 CFLAGS := $(EXTRA_WARNINGS) $(EXTRA_CFLAGS)
@@ -45,10 +55,23 @@ RM = rm -f
 
 API_IN := $(OUTPUT)libapi-in.o
 
+ifeq ($(LP64), 1)
+  libdir_relative = lib64
+else
+  libdir_relative = lib
+endif
+
+prefix ?=
+libdir = $(prefix)/$(libdir_relative)
+
+# Shell quotes
+libdir_SQ = $(subst ','\'',$(libdir))
+
 all:
 
 export srctree OUTPUT CC LD CFLAGS V
 include $(srctree)/tools/build/Makefile.include
+include $(srctree)/tools/scripts/Makefile.include
 
 all: fixdep $(LIBFILE)
 
@@ -58,6 +81,32 @@ $(API_IN): FORCE
 $(LIBFILE): $(API_IN)
 	$(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(API_IN)
 
+define do_install_mkdir
+	if [ ! -d '$(DESTDIR_SQ)$1' ]; then             \
+		$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$1'; \
+	fi
+endef
+
+define do_install
+	if [ ! -d '$(DESTDIR_SQ)$2' ]; then             \
+		$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$2'; \
+	fi;                                             \
+	$(INSTALL) $1 $(if $3,-m $3,) '$(DESTDIR_SQ)$2'
+endef
+
+install_lib: $(LIBFILE)
+	$(call QUIET_INSTALL, $(LIBFILE)) \
+		$(call do_install_mkdir,$(libdir_SQ)); \
+		cp -fpR $(LIBFILE) $(DESTDIR)$(libdir_SQ)
+
+install_headers:
+	$(call QUIET_INSTALL, headers) \
+		$(call do_install,cpu.h,$(prefix)/include/api,644); \
+		$(call do_install,debug.h,$(prefix)/include/api,644); \
+		$(call do_install,io.h,$(prefix)/include/api,644);
+
+install: install_lib install_headers
+
 clean:
 	$(call QUIET_CLEAN, libapi) $(RM) $(LIBFILE); \
 	find $(or $(OUTPUT),.) -name \*.o -or -name \*.o.cmd -or -name \*.o.d | xargs $(RM)
Signature · 1 line
2.38.1.431.g37b22c650d-goog
author reviewer
#2 lore raw

PATCH 2/14 tools lib subcmd: Add install target

In reply to Ian Rogers

This allows libsubcmd to be installed as a dependency.

---
 tools/lib/subcmd/Makefile | 49 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)
tools/lib/subcmd/Makefile +49 -0
index 8f1a09cdfd17..e96566f8991c 100644
@@ -17,6 +17,15 @@ RM = rm -f
 
 MAKEFLAGS += --no-print-directory
 
+INSTALL = install
+
+# Use DESTDIR for installing into a different root directory.
+# This is useful for building a package. The program will be
+# installed in this directory as if it was the root directory.
+# Then the build tool can move it later.
+DESTDIR ?=
+DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))'
+
 LIBFILE = $(OUTPUT)libsubcmd.a
 
 CFLAGS := -ggdb3 -Wall -Wextra -std=gnu99 -fPIC
@@ -48,6 +57,18 @@ CFLAGS += $(EXTRA_WARNINGS) $(EXTRA_CFLAGS)
 
 SUBCMD_IN := $(OUTPUT)libsubcmd-in.o
 
+ifeq ($(LP64), 1)
+  libdir_relative = lib64
+else
+  libdir_relative = lib
+endif
+
+prefix ?=
+libdir = $(prefix)/$(libdir_relative)
+
+# Shell quotes
+libdir_SQ = $(subst ','\'',$(libdir))
+
 all:
 
 export srctree OUTPUT CC LD CFLAGS V
@@ -61,6 +82,34 @@ $(SUBCMD_IN): FORCE
 $(LIBFILE): $(SUBCMD_IN)
 	$(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(SUBCMD_IN)
 
+define do_install_mkdir
+	if [ ! -d '$(DESTDIR_SQ)$1' ]; then             \
+		$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$1'; \
+	fi
+endef
+
+define do_install
+	if [ ! -d '$(DESTDIR_SQ)$2' ]; then             \
+		$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$2'; \
+	fi;                                             \
+	$(INSTALL) $1 $(if $3,-m $3,) '$(DESTDIR_SQ)$2'
+endef
+
+install_lib: $(LIBFILE)
+	$(call QUIET_INSTALL, $(LIBFILE)) \
+		$(call do_install_mkdir,$(libdir_SQ)); \
+		cp -fpR $(LIBFILE) $(DESTDIR)$(libdir_SQ)
+
+install_headers:
+	$(call QUIET_INSTALL, headers) \
+		$(call do_install,exec-cmd.h,$(prefix)/include/subcmd,644); \
+		$(call do_install,help.h,$(prefix)/include/subcmd,644); \
+		$(call do_install,pager.h,$(prefix)/include/subcmd,644); \
+		$(call do_install,parse-options.h,$(prefix)/include/subcmd,644); \
+		$(call do_install,run-command.h,$(prefix)/include/subcmd,644);
+
+install: install_lib install_headers
+
 clean:
 	$(call QUIET_CLEAN, libsubcmd) $(RM) $(LIBFILE); \
 	find $(or $(OUTPUT),.) -name \*.o -or -name \*.o.cmd -or -name \*.o.d | xargs $(RM)
Signature · 1 line
2.38.1.431.g37b22c650d-goog
author reviewer
#3 lore raw

PATCH 3/14 perf build: Install libsubcmd locally when building

In reply to Ian Rogers

The perf build currently has a '-Itools/lib' on the CC command line. This causes issues as the libapi, libsubcmd, libtraceevent, libbpf headers are all found via this path, making it impossible to override include behavior. Change the libsubcmd build mirroring the libbpf build, so that it is installed in a directory along with its headers. A later change will modify the include behavior.

---
 tools/perf/.gitignore    |  1 +
 tools/perf/Makefile.perf | 24 ++++++++++++++++--------
 2 files changed, 17 insertions(+), 8 deletions(-)
tools/perf/.gitignore +1 -0
index a653311d9693..626f5dd9a037 100644
@@ -39,6 +39,7 @@ pmu-events/pmu-events.c
 pmu-events/jevents
 feature/
 libbpf/
+libsubcmd/
 fixdep
 libtraceevent-dynamic-list
 Documentation/doc.dep
tools/perf/Makefile.perf +16 -8
index a432e59afc42..af62c6b9ed7a 100644
@@ -244,7 +244,7 @@ else # force_fixdep
 LIB_DIR         = $(srctree)/tools/lib/api/
 TRACE_EVENT_DIR = $(srctree)/tools/lib/traceevent/
 LIBBPF_DIR      = $(srctree)/tools/lib/bpf/
-SUBCMD_DIR      = $(srctree)/tools/lib/subcmd/
+LIBSUBCMD_DIR   = $(srctree)/tools/lib/subcmd/
 LIBPERF_DIR     = $(srctree)/tools/lib/perf/
 DOC_DIR         = $(srctree)/tools/perf/Documentation/
 
@@ -294,7 +294,6 @@ strip-libs = $(filter-out -l%,$(1))
 ifneq ($(OUTPUT),)
   TE_PATH=$(OUTPUT)
   PLUGINS_PATH=$(OUTPUT)
-  SUBCMD_PATH=$(OUTPUT)
   LIBPERF_PATH=$(OUTPUT)
 ifneq ($(subdir),)
   API_PATH=$(OUTPUT)/../lib/api/
@@ -305,7 +304,6 @@ else
   TE_PATH=$(TRACE_EVENT_DIR)
   PLUGINS_PATH=$(TRACE_EVENT_DIR)plugins/
   API_PATH=$(LIB_DIR)
-  SUBCMD_PATH=$(SUBCMD_DIR)
   LIBPERF_PATH=$(LIBPERF_DIR)
 endif
 
@@ -332,7 +330,14 @@ LIBBPF_DESTDIR = $(LIBBPF_OUTPUT)
 LIBBPF_INCLUDE = $(LIBBPF_DESTDIR)/include
 LIBBPF = $(LIBBPF_OUTPUT)/libbpf.a
 
-LIBSUBCMD = $(SUBCMD_PATH)libsubcmd.a
+ifneq ($(OUTPUT),)
+  LIBSUBCMD_OUTPUT = $(abspath $(OUTPUT))/libsubcmd
+else
+  LIBSUBCMD_OUTPUT = $(CURDIR)/libsubcmd
+endif
+LIBSUBCMD_DESTDIR = $(LIBSUBCMD_OUTPUT)
+LIBSUBCMD_INCLUDE = $(LIBSUBCMD_DESTDIR)/include
+LIBSUBCMD = $(LIBSUBCMD_OUTPUT)/libsubcmd.a
 
 LIBPERF = $(LIBPERF_PATH)libperf.a
 export LIBPERF
@@ -849,11 +854,14 @@ $(LIBPERF)-clean:
 	$(call QUIET_CLEAN, libperf)
 	$(Q)$(MAKE) -C $(LIBPERF_DIR) O=$(OUTPUT) clean >/dev/null
 
-$(LIBSUBCMD): FORCE
-	$(Q)$(MAKE) -C $(SUBCMD_DIR) O=$(OUTPUT) $(OUTPUT)libsubcmd.a
+$(LIBSUBCMD): FORCE | $(LIBSUBCMD_OUTPUT)
+	$(Q)$(MAKE) -C $(LIBSUBCMD_DIR) O=$(LIBSUBCMD_OUTPUT) \
+		DESTDIR=$(LIBSUBCMD_DESTDIR) prefix= \
+		$@ install_headers
 
 $(LIBSUBCMD)-clean:
-	$(Q)$(MAKE) -C $(SUBCMD_DIR) O=$(OUTPUT) clean
+	$(call QUIET_CLEAN, libsubcmd)
+	$(Q)$(RM) -r -- $(LIBSUBCMD_OUTPUT)
 
 help:
 	@echo 'Perf make targets:'
@@ -1044,7 +1052,7 @@ SKELETONS += $(SKEL_OUT)/bperf_cgroup.skel.h $(SKEL_OUT)/func_latency.skel.h
 SKELETONS += $(SKEL_OUT)/off_cpu.skel.h $(SKEL_OUT)/lock_contention.skel.h
 SKELETONS += $(SKEL_OUT)/kwork_trace.skel.h
 
-$(SKEL_TMP_OUT) $(LIBBPF_OUTPUT):
+$(SKEL_TMP_OUT) $(LIBBPF_OUTPUT) $(LIBSUBCMD_OUTPUT):
 	$(Q)$(MKDIR) -p $@
 
 ifdef BUILD_BPF_SKEL
Signature · 1 line
2.38.1.431.g37b22c650d-goog
author reviewer
#4 lore raw

PATCH 4/14 perf build: Install libapi locally when building

In reply to Ian Rogers

The perf build currently has a '-Itools/lib' on the CC command line. This causes issues as the libapi, libsubcmd, libtraceevent, libbpf headers are all found via this path, making it impossible to override include behavior. Change the libapi build mirroring the libbpf and libsubcmd build, so that it is installed in a directory along with its headers. A later change will modify the include behavior.

---
 tools/perf/.gitignore    |  1 +
 tools/perf/Makefile.perf | 27 +++++++++++++++------------
 2 files changed, 16 insertions(+), 12 deletions(-)
tools/perf/.gitignore +1 -0
index 626f5dd9a037..1932848343f3 100644
@@ -38,6 +38,7 @@ trace/beauty/generated/
 pmu-events/pmu-events.c
 pmu-events/jevents
 feature/
+libapi/
 libbpf/
 libsubcmd/
 fixdep
tools/perf/Makefile.perf +15 -12
index af62c6b9ed7a..3874d88d72c9 100644
@@ -241,7 +241,7 @@ sub-make: fixdep
 
 else # force_fixdep
 
-LIB_DIR         = $(srctree)/tools/lib/api/
+LIBAPI_DIR      = $(srctree)/tools/lib/api/
 TRACE_EVENT_DIR = $(srctree)/tools/lib/traceevent/
 LIBBPF_DIR      = $(srctree)/tools/lib/bpf/
 LIBSUBCMD_DIR   = $(srctree)/tools/lib/subcmd/
@@ -295,15 +295,9 @@ ifneq ($(OUTPUT),)
   TE_PATH=$(OUTPUT)
   PLUGINS_PATH=$(OUTPUT)
   LIBPERF_PATH=$(OUTPUT)
-ifneq ($(subdir),)
-  API_PATH=$(OUTPUT)/../lib/api/
-else
-  API_PATH=$(OUTPUT)
-endif
 else
   TE_PATH=$(TRACE_EVENT_DIR)
   PLUGINS_PATH=$(TRACE_EVENT_DIR)plugins/
-  API_PATH=$(LIB_DIR)
   LIBPERF_PATH=$(LIBPERF_DIR)
 endif
 
@@ -318,7 +312,14 @@ LIBTRACEEVENT_DYNAMIC_LIST = $(PLUGINS_PATH)libtraceevent-dynamic-list
 DYNAMIC_LIST_LDFLAGS               = -Xlinker --dynamic-list=$(LIBTRACEEVENT_DYNAMIC_LIST)
 LIBTRACEEVENT_DYNAMIC_LIST_LDFLAGS = $(if $(findstring -static,$(LDFLAGS)),,$(DYNAMIC_LIST_LDFLAGS))
 
-LIBAPI = $(API_PATH)libapi.a
+ifneq ($(OUTPUT),)
+  LIBAPI_OUTPUT = $(abspath $(OUTPUT))/libapi
+else
+  LIBAPI_OUTPUT = $(CURDIR)/libapi
+endif
+LIBAPI_DESTDIR = $(LIBAPI_OUTPUT)
+LIBAPI_INCLUDE = $(LIBAPI_DESTDIR)/include
+LIBAPI = $(LIBAPI_OUTPUT)/libapi.a
 export LIBAPI
 
 ifneq ($(OUTPUT),)
@@ -831,12 +832,14 @@ $(LIBTRACEEVENT)-clean:
 install-traceevent-plugins: libtraceevent_plugins
 	$(Q)$(MAKE) -C $(TRACE_EVENT_DIR) $(LIBTRACEEVENT_FLAGS) O=$(OUTPUT) install_plugins
 
-$(LIBAPI): FORCE
-	$(Q)$(MAKE) -C $(LIB_DIR) O=$(OUTPUT) $(OUTPUT)libapi.a
+$(LIBAPI): FORCE | $(LIBAPI_OUTPUT)
+	$(Q)$(MAKE) -C $(LIBAPI_DIR) O=$(LIBAPI_OUTPUT) \
+		DESTDIR=$(LIBAPI_DESTDIR) prefix= \
+		$@ install_headers
 
 $(LIBAPI)-clean:
 	$(call QUIET_CLEAN, libapi)
-	$(Q)$(MAKE) -C $(LIB_DIR) O=$(OUTPUT) clean >/dev/null
+	$(Q)$(RM) -r -- $(LIBAPI_OUTPUT)
 
 $(LIBBPF): FORCE | $(LIBBPF_OUTPUT)
 	$(Q)$(MAKE) -C $(LIBBPF_DIR) FEATURES_DUMP=$(FEATURE_DUMP_EXPORT) \
@@ -1052,7 +1055,7 @@ SKELETONS += $(SKEL_OUT)/bperf_cgroup.skel.h $(SKEL_OUT)/func_latency.skel.h
 SKELETONS += $(SKEL_OUT)/off_cpu.skel.h $(SKEL_OUT)/lock_contention.skel.h
 SKELETONS += $(SKEL_OUT)/kwork_trace.skel.h
 
-$(SKEL_TMP_OUT) $(LIBBPF_OUTPUT) $(LIBSUBCMD_OUTPUT):
+$(SKEL_TMP_OUT) $(LIBAPI_OUTPUT) $(LIBBPF_OUTPUT) $(LIBSUBCMD_OUTPUT):
 	$(Q)$(MKDIR) -p $@
 
 ifdef BUILD_BPF_SKEL
Signature · 1 line
2.38.1.431.g37b22c650d-goog
author reviewer
#5 lore raw

PATCH 5/14 perf build: Install libperf locally when building

In reply to Ian Rogers

The perf build currently has a '-Itools/lib' on the CC command line. This causes issues as the libapi, libsubcmd, libtraceevent, libbpf headers are all found via this path, making it impossible to override include behavior. Change the libperf build mirroring the libbpf, libsubcmd and libapi build, so that it is installed in a directory along with its headers. A later change will modify the include behavior.

---
 tools/perf/.gitignore    |  1 +
 tools/perf/Makefile.perf | 21 ++++++++++++++-------
 2 files changed, 15 insertions(+), 7 deletions(-)
tools/perf/.gitignore +1 -0
index 1932848343f3..43f6621ef05e 100644
@@ -40,6 +40,7 @@ pmu-events/jevents
 feature/
 libapi/
 libbpf/
+libperf/
 libsubcmd/
 fixdep
 libtraceevent-dynamic-list
tools/perf/Makefile.perf +14 -7
index 3874d88d72c9..5a2a3c4f045d 100644
@@ -294,11 +294,9 @@ strip-libs = $(filter-out -l%,$(1))
 ifneq ($(OUTPUT),)
   TE_PATH=$(OUTPUT)
   PLUGINS_PATH=$(OUTPUT)
-  LIBPERF_PATH=$(OUTPUT)
 else
   TE_PATH=$(TRACE_EVENT_DIR)
   PLUGINS_PATH=$(TRACE_EVENT_DIR)plugins/
-  LIBPERF_PATH=$(LIBPERF_DIR)
 endif
 
 LIBTRACEEVENT = $(TE_PATH)libtraceevent.a
@@ -340,7 +338,14 @@ LIBSUBCMD_DESTDIR = $(LIBSUBCMD_OUTPUT)
 LIBSUBCMD_INCLUDE = $(LIBSUBCMD_DESTDIR)/include
 LIBSUBCMD = $(LIBSUBCMD_OUTPUT)/libsubcmd.a
 
-LIBPERF = $(LIBPERF_PATH)libperf.a
+ifneq ($(OUTPUT),)
+  LIBPERF_OUTPUT = $(abspath $(OUTPUT))/libperf
+else
+  LIBPERF_OUTPUT = $(CURDIR)/libperf
+endif
+LIBPERF_DESTDIR = $(LIBPERF_OUTPUT)
+LIBPERF_INCLUDE = $(LIBPERF_DESTDIR)/include
+LIBPERF = $(LIBPERF_OUTPUT)/libperf.a
 export LIBPERF
 
 # python extension build directories
@@ -850,12 +855,14 @@ $(LIBBPF)-clean:
 	$(call QUIET_CLEAN, libbpf)
 	$(Q)$(RM) -r -- $(LIBBPF_OUTPUT)
 
-$(LIBPERF): FORCE
-	$(Q)$(MAKE) -C $(LIBPERF_DIR) EXTRA_CFLAGS="$(LIBPERF_CFLAGS)" O=$(OUTPUT) $(OUTPUT)libperf.a
+$(LIBPERF): FORCE | $(LIBPERF_OUTPUT)
+	$(Q)$(MAKE) -C $(LIBPERF_DIR) O=$(LIBPERF_OUTPUT) \
+		DESTDIR=$(LIBPERF_DESTDIR) prefix= \
+		$@ install_headers
 
 $(LIBPERF)-clean:
 	$(call QUIET_CLEAN, libperf)
-	$(Q)$(MAKE) -C $(LIBPERF_DIR) O=$(OUTPUT) clean >/dev/null
+	$(Q)$(RM) -r -- $(LIBPERF_OUTPUT)
 
 $(LIBSUBCMD): FORCE | $(LIBSUBCMD_OUTPUT)
 	$(Q)$(MAKE) -C $(LIBSUBCMD_DIR) O=$(LIBSUBCMD_OUTPUT) \
@@ -1055,7 +1062,7 @@ SKELETONS += $(SKEL_OUT)/bperf_cgroup.skel.h $(SKEL_OUT)/func_latency.skel.h
 SKELETONS += $(SKEL_OUT)/off_cpu.skel.h $(SKEL_OUT)/lock_contention.skel.h
 SKELETONS += $(SKEL_OUT)/kwork_trace.skel.h
 
-$(SKEL_TMP_OUT) $(LIBAPI_OUTPUT) $(LIBBPF_OUTPUT) $(LIBSUBCMD_OUTPUT):
+$(SKEL_TMP_OUT) $(LIBAPI_OUTPUT) $(LIBBPF_OUTPUT) $(LIBPERF_OUTPUT) $(LIBSUBCMD_OUTPUT):
 	$(Q)$(MKDIR) -p $@
 
 ifdef BUILD_BPF_SKEL
Signature · 1 line
2.38.1.431.g37b22c650d-goog
author reviewer
#6 lore raw

PATCH 6/14 perf build: Install libtraceevent locally when building

In reply to Ian Rogers

The perf build currently has a '-Itools/lib' on the CC command line. This causes issues as the libapi, libsubcmd, libtraceevent, libbpf headers are all found via this path, making it impossible to override include behavior. Change the libtraceevent build mirroring the libbpf, libsubcmd, libapi and libperf build, so that it is installed in a directory along with its headers. A later change will modify the include behavior.

Similarly, the plugins are now installed into libtraceevent_plugins except they have no header files.

---
 tools/perf/.gitignore    |  3 ++-
 tools/perf/Makefile.perf | 57 ++++++++++++++++++++++++++--------------
 2 files changed, 40 insertions(+), 20 deletions(-)
tools/perf/.gitignore +2 -1
index 43f6621ef05e..65b995159cf1 100644
@@ -42,6 +42,7 @@ libapi/
 libbpf/
 libperf/
 libsubcmd/
+libtraceevent/
+libtraceevent_plugins/
 fixdep
-libtraceevent-dynamic-list
 Documentation/doc.dep
tools/perf/Makefile.perf +38 -19

95 lines not on this page · raw message

Signature · 1 line
2.38.1.431.g37b22c650d-goog
author reviewer
#7 lore raw

PATCH 7/14 tools lib api: Add missing install headers

In reply to Ian Rogers

Headers necessary for the perf build.

---
 tools/lib/api/Makefile | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
tools/lib/api/Makefile +4 -1
index 6629d0fd0130..3e5ef1e0e890 100644
@@ -103,7 +103,10 @@ install_headers:
 	$(call QUIET_INSTALL, headers) \
 		$(call do_install,cpu.h,$(prefix)/include/api,644); \
 		$(call do_install,debug.h,$(prefix)/include/api,644); \
-		$(call do_install,io.h,$(prefix)/include/api,644);
+		$(call do_install,io.h,$(prefix)/include/api,644); \
+		$(call do_install,fd/array.h,$(prefix)/include/api/fd,644); \
+		$(call do_install,fs/fs.h,$(prefix)/include/api/fs,644);
+		$(call do_install,fs/tracing_path.h,$(prefix)/include/api/fs,644);
 
 install: install_lib install_headers
 
Signature · 1 line
2.38.1.431.g37b22c650d-goog
author reviewer
#8 lore raw

PATCH 8/14 tools lib perf: Add missing install headers

In reply to Ian Rogers

Headers necessary for the perf build. Note, internal headers are also installed as these are necessary for the build.

---
 tools/lib/perf/Makefile | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
tools/lib/perf/Makefile +9 -1
index 21df023a2103..1badc0a04676 100644
@@ -189,13 +189,21 @@ install_lib: libs
 
 install_headers:
 	$(call QUIET_INSTALL, headers) \
+		$(call do_install,include/perf/bpf_perf.h,$(prefix)/include/perf,644); \
 		$(call do_install,include/perf/core.h,$(prefix)/include/perf,644); \
 		$(call do_install,include/perf/cpumap.h,$(prefix)/include/perf,644); \
 		$(call do_install,include/perf/threadmap.h,$(prefix)/include/perf,644); \
 		$(call do_install,include/perf/evlist.h,$(prefix)/include/perf,644); \
 		$(call do_install,include/perf/evsel.h,$(prefix)/include/perf,644); \
 		$(call do_install,include/perf/event.h,$(prefix)/include/perf,644); \
-		$(call do_install,include/perf/mmap.h,$(prefix)/include/perf,644);
+		$(call do_install,include/perf/mmap.h,$(prefix)/include/perf,644); \
+		$(call do_install,include/internal/cpumap.h,$(prefix)/include/internal,644); \
+		$(call do_install,include/internal/evlist.h,$(prefix)/include/internal,644); \
+		$(call do_install,include/internal/evsel.h,$(prefix)/include/internal,644); \
+		$(call do_install,include/internal/lib.h,$(prefix)/include/internal,644); \
+		$(call do_install,include/internal/mmap.h,$(prefix)/include/internal,644); \
+		$(call do_install,include/internal/threadmap.h,$(prefix)/include/internal,644); \
+		$(call do_install,include/internal/xyarray.h,$(prefix)/include/internal,644);
 
 install_pkgconfig: $(LIBPERF_PC)
 	$(call QUIET_INSTALL, $(LIBPERF_PC)) \
Signature · 1 line
2.38.1.431.g37b22c650d-goog
author reviewer
#9 lore raw

PATCH 9/14 tool lib symbol: Add Makefile/Build

In reply to Ian Rogers

Add sufficient Makefile for libsymbol to be built as a dependency and header files installed.

---
 tools/lib/symbol/Build    |   1 +
 tools/lib/symbol/Makefile | 115 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 116 insertions(+)
 create mode 100644 tools/lib/symbol/Build
 create mode 100644 tools/lib/symbol/Makefile
tools/lib/symbol/Build new file +1 -0
new file mode 100644
index 000000000000..9b9a9c78d3c9
@@ -0,0 +1 @@
+libsymbol-y += kallsyms.o
tools/lib/symbol/Makefile new file +115 -0

115 lines not on this page · raw message

Signature · 1 line
2.38.1.431.g37b22c650d-goog
author reviewer
#10 lore raw

PATCH 10/14 perf build: Install libsymbol locally when building

In reply to Ian Rogers

The perf build currently has a '-Itools/lib' on the CC command line. This causes issues as the libapi, libsubcmd, libtraceevent, libbpf and libsymbol headers are all found via this path, making it impossible to override include behavior. Change the libsymbol build mirroring the libbpf, libsubcmd, libapi, libperf and libtraceevent build, so that it is installed in a directory along with its headers. A later change will modify the include behavior. Don't build kallsyms.o as part of util as this will lead to duplicate definitions.

---
 tools/perf/.gitignore    |  1 +
 tools/perf/Makefile.perf | 25 ++++++++++++++++++++++---
 tools/perf/util/Build    |  5 -----
 3 files changed, 23 insertions(+), 8 deletions(-)
tools/perf/.gitignore +1 -0
index 65b995159cf1..675c03ec1f1c 100644
@@ -42,6 +42,7 @@ libapi/
 libbpf/
 libperf/
 libsubcmd/
+libsymbol/
 libtraceevent/
 libtraceevent_plugins/
 fixdep
tools/perf/Makefile.perf +22 -3
index 537ac7055a35..1d90d78303b4 100644
@@ -246,6 +246,7 @@ LIBTRACEEVENT_DIR = $(srctree)/tools/lib/traceevent/
 LIBTRACEEVENT_PLUGINS_DIR = $(LIBTRACEEVENT_DIR)/plugins
 LIBBPF_DIR      = $(srctree)/tools/lib/bpf/
 LIBSUBCMD_DIR   = $(srctree)/tools/lib/subcmd/
+LIBSYMBOL_DIR   = $(srctree)/tools/lib/symbol/
 LIBPERF_DIR     = $(srctree)/tools/lib/perf/
 DOC_DIR         = $(srctree)/tools/perf/Documentation/
 
@@ -340,6 +341,15 @@ LIBSUBCMD_DESTDIR = $(LIBSUBCMD_OUTPUT)
 LIBSUBCMD_INCLUDE = $(LIBSUBCMD_DESTDIR)/include
 LIBSUBCMD = $(LIBSUBCMD_OUTPUT)/libsubcmd.a
 
+ifneq ($(OUTPUT),)
+  LIBSYMBOL_OUTPUT = $(abspath $(OUTPUT))/libsymbol
+else
+  LIBSYMBOL_OUTPUT = $(CURDIR)/libsymbol
+endif
+LIBSYMBOL_DESTDIR = $(LIBSYMBOL_OUTPUT)
+LIBSYMBOL_INCLUDE = $(LIBSYMBOL_DESTDIR)/include
+LIBSYMBOL = $(LIBSYMBOL_OUTPUT)/libsymbol.a
+
 ifneq ($(OUTPUT),)
   LIBPERF_OUTPUT = $(abspath $(OUTPUT))/libperf
 else
@@ -398,7 +408,7 @@ endif
 
 export PERL_PATH
 
-PERFLIBS = $(LIBAPI) $(LIBSUBCMD) $(LIBPERF)
+PERFLIBS = $(LIBAPI) $(LIBPERF) $(LIBSUBCMD) $(LIBSYMBOL)
 ifndef NO_LIBBPF
   ifndef LIBBPF_DYNAMIC
     PERFLIBS += $(LIBBPF)
@@ -887,6 +897,15 @@ $(LIBSUBCMD)-clean:
 	$(call QUIET_CLEAN, libsubcmd)
 	$(Q)$(RM) -r -- $(LIBSUBCMD_OUTPUT)
 
+$(LIBSYMBOL): FORCE | $(LIBSYMBOL_OUTPUT)
+	$(Q)$(MAKE) -C $(LIBSYMBOL_DIR) O=$(LIBSYMBOL_OUTPUT) \
+		DESTDIR=$(LIBSYMBOL_DESTDIR) prefix= \
+		$@ install_headers
+
+$(LIBSYMBOL)-clean:
+	$(call QUIET_CLEAN, libsymbol)
+	$(Q)$(RM) -r -- $(LIBSYMBOL_OUTPUT)
+
 help:
 	@echo 'Perf make targets:'
 	@echo '  doc		- make *all* documentation (see below)'
@@ -1076,7 +1095,7 @@ SKELETONS += $(SKEL_OUT)/bperf_cgroup.skel.h $(SKEL_OUT)/func_latency.skel.h
 SKELETONS += $(SKEL_OUT)/off_cpu.skel.h $(SKEL_OUT)/lock_contention.skel.h
 SKELETONS += $(SKEL_OUT)/kwork_trace.skel.h
 
-$(SKEL_TMP_OUT) $(LIBAPI_OUTPUT) $(LIBBPF_OUTPUT) $(LIBPERF_OUTPUT) $(LIBSUBCMD_OUTPUT):
+$(SKEL_TMP_OUT) $(LIBAPI_OUTPUT) $(LIBBPF_OUTPUT) $(LIBPERF_OUTPUT) $(LIBSUBCMD_OUTPUT) $(LIBSYMBOL_OUTPUT):
 	$(Q)$(MKDIR) -p $@
 
 ifndef LIBTRACEEVENT_DYNAMIC
@@ -1126,7 +1145,7 @@ endif # BUILD_BPF_SKEL
 bpf-skel-clean:
 	$(call QUIET_CLEAN, bpf-skel) $(RM) -r $(SKEL_TMP_OUT) $(SKELETONS)
 
-clean:: $(LIBTRACEEVENT)-clean $(LIBAPI)-clean $(LIBBPF)-clean $(LIBSUBCMD)-clean $(LIBPERF)-clean fixdep-clean python-clean bpf-skel-clean tests-coresight-targets-clean libtraceevent_plugins-clean
+clean:: $(LIBTRACEEVENT)-clean $(LIBAPI)-clean $(LIBBPF)-clean $(LIBSUBCMD)-clean $(LIBSYMBOL)-clean $(LIBPERF)-clean fixdep-clean python-clean bpf-skel-clean tests-coresight-targets-clean libtraceevent_plugins-clean
 	$(call QUIET_CLEAN, core-objs)  $(RM) $(LIBPERF_A) $(OUTPUT)perf-archive $(OUTPUT)perf-iostat $(LANG_BINDINGS)
 	$(Q)find $(or $(OUTPUT),.) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
 	$(Q)$(RM) $(OUTPUT).config-detected
tools/perf/util/Build +0 -5
index e315ecaec323..45f3d2723725 100644
@@ -19,7 +19,6 @@ perf-y += perf_event_attr_fprintf.o
 perf-y += evswitch.o
 perf-y += find_bit.o
 perf-y += get_current_dir_name.o
-perf-y += kallsyms.o
 perf-y += levenshtein.o
 perf-y += llvm-utils.o
 perf-y += mmap.o
@@ -294,10 +293,6 @@ CFLAGS_expr.o          += -Wno-redundant-decls
 CFLAGS_header.o        += -include $(OUTPUT)PERF-VERSION-FILE
 CFLAGS_arm-spe.o       += -I$(srctree)/tools/arch/arm64/include/
 
-$(OUTPUT)util/kallsyms.o: ../lib/symbol/kallsyms.c FORCE
-	$(call rule_mkdir)
-	$(call if_changed_dep,cc_o_c)
-
 $(OUTPUT)util/argv_split.o: ../lib/argv_split.c FORCE
 	$(call rule_mkdir)
 	$(call if_changed_dep,cc_o_c)
Signature · 1 line
2.38.1.431.g37b22c650d-goog
author reviewer
#11 lore raw

PATCH 11/14 perf expr: Tidy hashmap dependency

In reply to Ian Rogers

hashmap.h comes from libbpf but isn't installed with its headers. Always use the header file of the code in util. Change the hashmap.h dependency in expr.h to a forward declaration, add the necessary header file includes in the C files.

---
 tools/perf/tests/expr.c       | 1 +
 tools/perf/tests/pmu-events.c | 1 +
 tools/perf/util/bpf-loader.c  | 4 ----
 tools/perf/util/evsel.c       | 4 ----
 tools/perf/util/expr.c        | 1 +
 tools/perf/util/expr.h        | 7 +------
 tools/perf/util/metricgroup.c | 1 +
 tools/perf/util/stat-shadow.c | 1 +
 tools/perf/util/stat.c        | 4 ----
 9 files changed, 6 insertions(+), 18 deletions(-)
tools/perf/tests/expr.c +1 -0
index 6512f5e22045..b6667501ebb4 100644
@@ -2,6 +2,7 @@
 #include "util/cputopo.h"
 #include "util/debug.h"
 #include "util/expr.h"
+#include "util/hashmap.h"
 #include "util/header.h"
 #include "util/smt.h"
 #include "tests.h"
tools/perf/tests/pmu-events.c +1 -0
index 5d0d3b239a68..f7b9dbbad97f 100644
@@ -12,6 +12,7 @@
 #include <perf/evlist.h>
 #include "util/evlist.h"
 #include "util/expr.h"
+#include "util/hashmap.h"
 #include "util/parse-events.h"
 #include "metricgroup.h"
 #include "stat.h"
tools/perf/util/bpf-loader.c +0 -4
index f4adeccdbbcb..b3c8174360bf 100644
@@ -27,11 +27,7 @@
 #include "util.h"
 #include "llvm-utils.h"
 #include "c++/clang-c.h"
-#ifdef HAVE_LIBBPF_SUPPORT
-#include <bpf/hashmap.h>
-#else
 #include "util/hashmap.h"
-#endif
 #include "asm/bug.h"
 
 #include <internal/xyarray.h>
tools/perf/util/evsel.c +0 -4
index cdde5b5f8ad2..2139e8b0e401 100644
@@ -46,11 +46,7 @@
 #include "string2.h"
 #include "memswap.h"
 #include "util.h"
-#ifdef HAVE_LIBBPF_SUPPORT
-#include <bpf/hashmap.h>
-#else
 #include "util/hashmap.h"
-#endif
 #include "pmu-hybrid.h"
 #include "off_cpu.h"
 #include "../perf-sys.h"
tools/perf/util/expr.c +1 -0
index aaacf514dc09..140f2acdb325 100644
@@ -11,6 +11,7 @@
 #include "expr.h"
 #include "expr-bison.h"
 #include "expr-flex.h"
+#include "util/hashmap.h"
 #include "smt.h"
 #include "tsc.h"
 #include <linux/err.h>
tools/perf/util/expr.h +1 -6
index d6c1668dc1a0..029271540fb0 100644
@@ -2,12 +2,7 @@
 #ifndef PARSE_CTX_H
 #define PARSE_CTX_H 1
 
-#ifdef HAVE_LIBBPF_SUPPORT
-#include <bpf/hashmap.h>
-#else
-#include "util/hashmap.h"
-#endif
-
+struct hashmap;
 struct metric_ref;
 
 struct expr_scanner_ctx {
tools/perf/util/metricgroup.c +1 -0
index 4c98ac29ee13..15441e9bfb73 100644
@@ -28,6 +28,7 @@
 #include "util.h"
 #include <asm/bug.h>
 #include "cgroup.h"
+#include "util/hashmap.h"
 
 struct metric_event *metricgroup__lookup(struct rblist *metric_events,
 					 struct evsel *evsel,
tools/perf/util/stat-shadow.c +1 -0
index 07b29fe272c7..9bde9224a97c 100644
@@ -14,6 +14,7 @@
 #include "units.h"
 #include <linux/zalloc.h>
 #include "iostat.h"
+#include "util/hashmap.h"
 
 /*
  * AGGR_GLOBAL: Use CPU 0
tools/perf/util/stat.c +0 -4
index 3a432a949d46..273a5b32e815 100644
@@ -14,11 +14,7 @@
 #include "evlist.h"
 #include "evsel.h"
 #include "thread_map.h"
-#ifdef HAVE_LIBBPF_SUPPORT
-#include <bpf/hashmap.h>
-#else
 #include "util/hashmap.h"
-#endif
 #include <linux/zalloc.h>
 
 void update_stats(struct stats *stats, u64 val)
Signature · 1 line
2.38.1.431.g37b22c650d-goog
author reviewer
#12 lore raw

PATCH 12/14 perf thread_map: Reduce exposure of libperf internal API

In reply to Ian Rogers

Remove unnecessary include of internal threadmap.h and refcount.h in thread_map.h. Switch to using public APIs when possible or including the internal header file in the C file. Fix a transitive dependency in openat-syscall.c broken by the clean up.

---
 tools/perf/builtin-stat.c                              | 1 +
 tools/perf/builtin-trace.c                             | 4 ++--
 tools/perf/tests/openat-syscall.c                      | 1 +
 tools/perf/tests/thread-map.c                          | 1 +
 tools/perf/util/bpf_counter.c                          | 2 +-
 tools/perf/util/evsel.c                                | 1 +
 tools/perf/util/python.c                               | 6 +++---
 tools/perf/util/scripting-engines/trace-event-python.c | 2 +-
 tools/perf/util/thread_map.c                           | 1 +
 tools/perf/util/thread_map.h                           | 2 --
 10 files changed, 12 insertions(+), 9 deletions(-)
tools/perf/builtin-stat.c +1 -0
index d5e1670bca20..fb2d13650e42 100644
@@ -93,6 +93,7 @@
 
 #include <linux/ctype.h>
 #include <perf/evlist.h>
+#include <internal/threadmap.h>
 
 #define DEFAULT_SEPARATOR	" "
 #define FREEZE_ON_SMI_PATH	"devices/cpu/freeze_on_smi"
tools/perf/builtin-trace.c +2 -2
index 72991528687e..b403f3fab2a4 100644
@@ -4092,8 +4092,8 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
 	}
 
 	trace->multiple_threads = perf_thread_map__pid(evlist->core.threads, 0) == -1 ||
-				  evlist->core.threads->nr > 1 ||
-				  evlist__first(evlist)->core.attr.inherit;
+		perf_thread_map__nr(evlist->core.threads) > 1 ||
+		evlist__first(evlist)->core.attr.inherit;
 
 	/*
 	 * Now that we already used evsel->core.attr to ask the kernel to setup the
tools/perf/tests/openat-syscall.c +1 -0
index 7e05b8b5cc95..131b62271bfa 100644
@@ -7,6 +7,7 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
+#include <unistd.h>
 #include "thread_map.h"
 #include "evsel.h"
 #include "debug.h"
tools/perf/tests/thread-map.c +1 -0
index e413c1387fcb..74308c1368fe 100644
@@ -11,6 +11,7 @@
 #include "util/synthetic-events.h"
 #include <linux/zalloc.h>
 #include <perf/event.h>
+#include <internal/threadmap.h>
 
 struct perf_sample;
 struct perf_tool;
tools/perf/util/bpf_counter.c +1 -1
index ef1c15e4aeba..eeee899fcf34 100644
@@ -561,7 +561,7 @@ static int bperf__load(struct evsel *evsel, struct target *target)
 
 		if (filter_type == BPERF_FILTER_PID ||
 		    filter_type == BPERF_FILTER_TGID)
-			key = evsel->core.threads->map[i].pid;
+			key = perf_thread_map__pid(evsel->core.threads, i);
 		else if (filter_type == BPERF_FILTER_CPU)
 			key = evsel->core.cpus->map[i].cpu;
 		else
tools/perf/util/evsel.c +1 -0
index 2139e8b0e401..2e212ae73b9f 100644
@@ -53,6 +53,7 @@
 #include "util/parse-branch-options.h"
 #include <internal/xyarray.h>
 #include <internal/lib.h>
+#include <internal/threadmap.h>
 
 #include <linux/ctype.h>
 
tools/perf/util/python.c +3 -3
index 5be5fa2391de..b5941c74a0d6 100644
@@ -718,17 +718,17 @@ static Py_ssize_t pyrf_thread_map__length(PyObject *obj)
 {
 	struct pyrf_thread_map *pthreads = (void *)obj;
 
-	return pthreads->threads->nr;
+	return perf_thread_map__nr(pthreads->threads);
 }
 
 static PyObject *pyrf_thread_map__item(PyObject *obj, Py_ssize_t i)
 {
 	struct pyrf_thread_map *pthreads = (void *)obj;
 
-	if (i >= pthreads->threads->nr)
+	if (i >= perf_thread_map__nr(pthreads->threads))
 		return NULL;
 
-	return Py_BuildValue("i", pthreads->threads->map[i]);
+	return Py_BuildValue("i", perf_thread_map__pid(pthreads->threads, i));
 }
 
 static PySequenceMethods pyrf_thread_map__sequence_methods = {
tools/perf/util/scripting-engines/trace-event-python.c +1 -1
index 1985d1a42a22..1cf65db8f861 100644
@@ -1654,7 +1654,7 @@ static void python_process_stat(struct perf_stat_config *config,
 	struct perf_cpu_map *cpus = counter->core.cpus;
 	int cpu, thread;
 
-	for (thread = 0; thread < threads->nr; thread++) {
+	for (thread = 0; thread < perf_thread_map__nr(threads); thread++) {
 		for (cpu = 0; cpu < perf_cpu_map__nr(cpus); cpu++) {
 			process_stat(counter, perf_cpu_map__cpu(cpus, cpu),
 				     perf_thread_map__pid(threads, thread), tstamp,
tools/perf/util/thread_map.c +1 -0
index c9bfe4696943..e848579e61a8 100644
@@ -18,6 +18,7 @@
 #include "thread_map.h"
 #include "debug.h"
 #include "event.h"
+#include <internal/threadmap.h>
 
 /* Skip "." and ".." directories */
 static int filter(const struct dirent *dir)
tools/perf/util/thread_map.h +0 -2
index 3bb860a32b8e..00ec05fc1656 100644
@@ -4,8 +4,6 @@
 
 #include <sys/types.h>
 #include <stdio.h>
-#include <linux/refcount.h>
-#include <internal/threadmap.h>
 #include <perf/threadmap.h>
 
 struct perf_record_thread_map;
Signature · 1 line
2.38.1.431.g37b22c650d-goog
author reviewer
#13 lore raw

PATCH 13/14 perf cpumap: Tidy libperf includes

In reply to Ian Rogers

Use public API when possible, don't include internal API in header files in evsel.h. Fix any related breakages.

---
 tools/perf/tests/cpumap.c  | 2 +-
 tools/perf/util/auxtrace.h | 2 +-
 tools/perf/util/cpumap.c   | 1 +
 tools/perf/util/cpumap.h   | 2 +-
 tools/perf/util/evsel.h    | 2 --
 5 files changed, 4 insertions(+), 5 deletions(-)
tools/perf/tests/cpumap.c +1 -1
index 7c873c6ae3eb..3150fc1fed6f 100644
@@ -6,7 +6,7 @@
 #include "util/synthetic-events.h"
 #include <string.h>
 #include <linux/bitops.h>
-#include <perf/cpumap.h>
+#include <internal/cpumap.h>
 #include "debug.h"
 
 struct machine;
tools/perf/util/auxtrace.h +1 -1
index 6a0f9b98f059..2cf63d377831 100644
@@ -15,7 +15,7 @@
 #include <linux/list.h>
 #include <linux/perf_event.h>
 #include <linux/types.h>
-#include <internal/cpumap.h>
+#include <perf/cpumap.h>
 #include <asm/bitsperlong.h>
 #include <asm/barrier.h>
 
tools/perf/util/cpumap.c +1 -0
index 6e3fcf523de9..5e564974fba4 100644
@@ -12,6 +12,7 @@
 
 #include <linux/ctype.h>
 #include <linux/zalloc.h>
+#include <internal/cpumap.h>
 
 static struct perf_cpu max_cpu_num;
 static struct perf_cpu max_present_cpu_num;
tools/perf/util/cpumap.h +1 -1
index da28b3146ef9..c2f5824a3a22 100644
@@ -4,8 +4,8 @@
 
 #include <stdbool.h>
 #include <stdio.h>
-#include <internal/cpumap.h>
 #include <perf/cpumap.h>
+#include <linux/refcount.h>
 
 /** Identify where counts are aggregated, -1 implies not to aggregate. */
 struct aggr_cpu_id {
tools/perf/util/evsel.h +0 -2
index 989865e16aad..f5d9f6a351cd 100644
@@ -10,8 +10,6 @@
 #include <internal/evsel.h>
 #include <perf/evsel.h>
 #include "symbol_conf.h"
-#include <internal/cpumap.h>
-#include <perf/cpumap.h>
 
 struct bpf_object;
 struct cgroup;
Signature · 1 line
2.38.1.431.g37b22c650d-goog
author reviewer
#14 lore raw

PATCH 14/14 perf build: Use tools/lib headers from install path

In reply to Ian Rogers

Switch -I from tools/lib to the install path for the tools/lib libraries that are depended upon.

---
 tools/perf/Makefile.config | 2 --
 tools/perf/Makefile.perf   | 6 ++++++
 2 files changed, 6 insertions(+), 2 deletions(-)
tools/perf/Makefile.config +0 -2
index d3d3c13a9f25..d7fcd1624cd7 100644
@@ -349,7 +349,6 @@ ifeq ($(DEBUG),0)
   endif
 endif
 
-INC_FLAGS += -I$(srctree)/tools/lib/perf/include
 INC_FLAGS += -I$(src-perf)/util/include
 INC_FLAGS += -I$(src-perf)/arch/$(SRCARCH)/include
 INC_FLAGS += -I$(srctree)/tools/include/
@@ -367,7 +366,6 @@ endif
 
 INC_FLAGS += -I$(src-perf)/util
 INC_FLAGS += -I$(src-perf)
-INC_FLAGS += -I$(srctree)/tools/lib/
 
 CORE_CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
 
tools/perf/Makefile.perf +6 -0
index 1d90d78303b4..851dcc0272e5 100644
@@ -305,6 +305,7 @@ LIBTRACEEVENT_INCLUDE = $(LIBTRACEEVENT_DESTDIR)/include
 LIBTRACEEVENT = $(LIBTRACEEVENT_OUTPUT)/libtraceevent.a
 export LIBTRACEEVENT
 LIBTRACEEVENT_DYNAMIC_LIST = $(LIBTRACEEVENT_PLUGINS_OUTPUT)/libtraceevent-dynamic-list
+CFLAGS += -I$(LIBTRACEEVENT_OUTPUT)/include
 
 #
 # The static build has no dynsym table, so this does not work for
@@ -322,6 +323,7 @@ LIBAPI_DESTDIR = $(LIBAPI_OUTPUT)
 LIBAPI_INCLUDE = $(LIBAPI_DESTDIR)/include
 LIBAPI = $(LIBAPI_OUTPUT)/libapi.a
 export LIBAPI
+CFLAGS += -I$(LIBAPI_OUTPUT)/include
 
 ifneq ($(OUTPUT),)
   LIBBPF_OUTPUT = $(abspath $(OUTPUT))/libbpf
@@ -331,6 +333,7 @@ endif
 LIBBPF_DESTDIR = $(LIBBPF_OUTPUT)
 LIBBPF_INCLUDE = $(LIBBPF_DESTDIR)/include
 LIBBPF = $(LIBBPF_OUTPUT)/libbpf.a
+CFLAGS += -I$(LIBBPF_OUTPUT)/include
 
 ifneq ($(OUTPUT),)
   LIBSUBCMD_OUTPUT = $(abspath $(OUTPUT))/libsubcmd
@@ -340,6 +343,7 @@ endif
 LIBSUBCMD_DESTDIR = $(LIBSUBCMD_OUTPUT)
 LIBSUBCMD_INCLUDE = $(LIBSUBCMD_DESTDIR)/include
 LIBSUBCMD = $(LIBSUBCMD_OUTPUT)/libsubcmd.a
+CFLAGS += -I$(LIBSUBCMD_OUTPUT)/include
 
 ifneq ($(OUTPUT),)
   LIBSYMBOL_OUTPUT = $(abspath $(OUTPUT))/libsymbol
@@ -349,6 +353,7 @@ endif
 LIBSYMBOL_DESTDIR = $(LIBSYMBOL_OUTPUT)
 LIBSYMBOL_INCLUDE = $(LIBSYMBOL_DESTDIR)/include
 LIBSYMBOL = $(LIBSYMBOL_OUTPUT)/libsymbol.a
+CFLAGS += -I$(LIBSYMBOL_OUTPUT)/include
 
 ifneq ($(OUTPUT),)
   LIBPERF_OUTPUT = $(abspath $(OUTPUT))/libperf
@@ -359,6 +364,7 @@ LIBPERF_DESTDIR = $(LIBPERF_OUTPUT)
 LIBPERF_INCLUDE = $(LIBPERF_DESTDIR)/include
 LIBPERF = $(LIBPERF_OUTPUT)/libperf.a
 export LIBPERF
+CFLAGS += -I$(LIBPERF_OUTPUT)/include
 
 # python extension build directories
 PYTHON_EXTBUILD     := $(OUTPUT)python_ext_build/
Signature · 1 line
2.38.1.431.g37b22c650d-goog
#15 lore raw
In reply to Ian Rogers

Em Mon, Nov 07, 2022 at 11:35:04PM -0800, Ian Rogers escreveu:

Quoted 9 lines

The previous build would add -Itools/lib and get dependencies for libtraceevent, libsubcmd, libsymbol, libapi and libbpf meaning that overriding these libraries would change the link time dependency but the headers would erroneously come from tools/lib. Fix the build to install headers and then depend on these. To reduce exposing internal headers/APIs some clean up is performed. tools/lib/symbol has a Makefile added, while tools/lib/api and tools/lib/subcmd have install targets added. The pattern used for the dependencies in Makefile.perf is modelled on libbpf.

It builds with O=, I tried it one by one, but there are problems with make from a detached tarball, that is how I do the container builds, see below, I'm trying to figure this out...

⬢[acme@toolbox perf]$ make perf-tar-src-pkg
TAR
PERF_VERSION = 6.1.rc3.g7e5d8b7a1fbd
⬢[acme@toolbox perf]$ mv perf-6.1.0-rc3.tar /tmp ⬢[acme@toolbox perf]$ cd /tmp
⬢[acme@toolbox tmp]$ tar xf perf-6.1.0-rc3.tar ⬢[acme@toolbox tmp]$ cd perf-6.1.0-rc3/ ⬢[acme@toolbox perf-6.1.0-rc3]$ make -C tools/perf
make: Entering directory '/tmp/perf-6.1.0-rc3/tools/perf'
BUILD: Doing 'make -j32' parallel build

  HOSTCC  fixdep.o
  HOSTLD  fixdep-in.o
  LINK    fixdep

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: [ on  ]
...                               libunwind: [ on  ]
...                      libdw-dwarf-unwind: [ on  ]
...                                    zlib: [ on  ]
...                                    lzma: [ on  ]
...                               get_cpuid: [ on  ]
...                                     bpf: [ on  ]
...                                  libaio: [ on  ]
...                                 libzstd: [ on  ]

GEN common-cmds.h
PERF_VERSION = 6.1.rc3.g7e5d8b7a1fbd

  CC      perf-read-vdso32
  GEN     perf-archive
  GEN     perf-iostat
  CC      dlfilters/dlfilter-test-api-v0.o
  CC      dlfilters/dlfilter-show-cycles.o
  CC      jvmti/libjvmti.o
make[3]: *** No rule to make target '/tmp/perf-6.1.0-rc3/tools/perf/libsymbol/libsymbol.a'.  Stop.
make[2]: *** [Makefile.perf:907: /tmp/perf-6.1.0-rc3/tools/perf/libsymbol/libsymbol.a] Error 2
make[2]: *** Waiting for unfinished jobs....
  CC      jvmti/jvmti_agent.o
  CC      jvmti/libstring.o
  CC      jvmti/libctype.o
  GEN     pmu-events/pmu-events.c
  INSTALL headers
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libsubcmd/exec-cmd.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libsubcmd/help.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libsubcmd/pager.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libsubcmd/parse-options.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libsubcmd/run-command.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libsubcmd/sigchain.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libsubcmd/subcmd-config.o
  INSTALL headers
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent/event-parse.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_jbd2.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_hrtimer.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_kmem.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_kvm.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_mac80211.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_function.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_sched_switch.o
  INSTALL headers
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libperf/core.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libapi/cpu.o
  MKDIR   /tmp/perf-6.1.0-rc3/tools/perf/libapi/fd/
  MKDIR   /tmp/perf-6.1.0-rc3/tools/perf/libapi/fs/
  MKDIR   /tmp/perf-6.1.0-rc3/tools/perf/libapi/fs/
  MKDIR   /tmp/perf-6.1.0-rc3/tools/perf/libapi/fs/
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libapi/fd/array.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libapi/fs/fs.o
  GEN     /tmp/perf-6.1.0-rc3/tools/perf/libbpf/bpf_helper_defs.h
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libapi/fs/tracing_path.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libapi/fs/cgroup.o
  INSTALL /tmp/perf-6.1.0-rc3/tools/perf/libbpf/include/bpf/bpf.h
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libapi/debug.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_futex.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_xen.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_scsi.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_cfg80211.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_tlb.o
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_jbd2-in.o
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_hrtimer-in.o
  INSTALL /tmp/perf-6.1.0-rc3/tools/perf/libbpf/include/bpf/libbpf.h
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_kmem-in.o
  INSTALL headers
  INSTALL /tmp/perf-6.1.0-rc3/tools/perf/libbpf/include/bpf/btf.h
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_mac80211-in.o
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_sched_switch-in.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libperf/cpumap.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libperf/threadmap.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libapi/str_error_r.o
  INSTALL /tmp/perf-6.1.0-rc3/tools/perf/libbpf/include/bpf/libbpf_common.h
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_jbd2.so
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_hrtimer.so
  INSTALL /tmp/perf-6.1.0-rc3/tools/perf/libbpf/include/bpf/libbpf_legacy.h
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_function-in.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libperf/evsel.o
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_kvm-in.o
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_kmem.so
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_mac80211.so
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_sched_switch.so
  INSTALL /tmp/perf-6.1.0-rc3/tools/perf/libbpf/include/bpf/bpf_helpers.h
  INSTALL /tmp/perf-6.1.0-rc3/tools/perf/libbpf/include/bpf/bpf_tracing.h
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent/event-plugin.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libperf/evlist.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libperf/mmap.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent/trace-seq.o
  INSTALL /tmp/perf-6.1.0-rc3/tools/perf/libbpf/include/bpf/bpf_endian.h
  INSTALL /tmp/perf-6.1.0-rc3/tools/perf/libbpf/include/bpf/bpf_core_read.h
if [ ! -d ''/tmp/perf-6.1.0-rc3/tools/perf/libapi'/include/api/fs' ]; then install -d -m 755 ''/tmp/perf-6.1.0-rc3/tools/perf/libapi'/include/api/fs'; fi; install fs/tracing_path.h -m 644 ''/tmp/perf-6.1.0-rc3/tools/perf/libapi'/include/api/fs';
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libapi/fd/libapi-in.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libperf/zalloc.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent/parse-filter.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent/parse-utils.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent/kbuffer-parse.o
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_xen-in.o
  INSTALL /tmp/perf-6.1.0-rc3/tools/perf/libbpf/include/bpf/skel_internal.h
  INSTALL /tmp/perf-6.1.0-rc3/tools/perf/libbpf/include/bpf/libbpf_version.h
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent/tep_strerror.o
  INSTALL /tmp/perf-6.1.0-rc3/tools/perf/libbpf/include/bpf/usdt.bpf.h
  INSTALL /tmp/perf-6.1.0-rc3/tools/perf/libbpf/include/bpf/bpf_helper_defs.h
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent/event-parse-api.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libperf/xyarray.o
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_function.so
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_xen.so
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_futex-in.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libperf/lib.o
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_scsi-in.o
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_cfg80211-in.o
  MKDIR   /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/
  MKDIR   /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/
  MKDIR   /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/
  MKDIR   /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_kvm.so
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/libbpf.o
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_futex.so
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_scsi.so
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/bpf.o
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libapi/fs/libapi-in.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/nlattr.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/btf.o
  MKDIR   /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_tlb-in.o
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_cfg80211.so
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/str_error.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/netlink.o
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libapi/libapi-in.o
  LD      jvmti/jvmti-in.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/libbpf_errno.o
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_tlb.so
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/bpf_prog_linfo.o
  AR      /tmp/perf-6.1.0-rc3/tools/perf/libapi/libapi.a
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/libbpf_probes.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/hashmap.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/btf_dump.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/ringbuf.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/strset.o
  GEN     /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/libtraceevent-dynamic-list
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/linker.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/gen_loader.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/relo_core.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/usdt.o
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libsubcmd/libsubcmd-in.o
  AR      /tmp/perf-6.1.0-rc3/tools/perf/libsubcmd/libsubcmd.a
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libperf/libperf-in.o
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent/libtraceevent-in.o
  AR      /tmp/perf-6.1.0-rc3/tools/perf/libperf/libperf.a
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent/libtraceevent.a
  CC      pmu-events/pmu-events.o
  LD      pmu-events/pmu-events-in.o
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/libbpf-in.o
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libbpf/libbpf.a

make[1]: *** [Makefile.perf:240: sub-make] Error 2
make: *** [Makefile:70: all] Error 2
make: Leaving directory '/tmp/perf-6.1.0-rc3/tools/perf' ⬢[acme@toolbox perf-6.1.0-rc3]$

Quoted 57 lines

The problem and solution were motivated by this issue and discussion:
https://lore.kernel.org/lkml/CAEf4BzbbOHQZUAe6iWaehKCPQAf3VC=hq657buqe2_yRKxaK-A@mail.gmail.com/

Ian Rogers (14):
tools lib api: Add install target
tools lib subcmd: Add install target
perf build: Install libsubcmd locally when building perf build: Install libapi locally when building perf build: Install libperf locally when building perf build: Install libtraceevent locally when building tools lib api: Add missing install headers tools lib perf: Add missing install headers tool lib symbol: Add Makefile/Build
perf build: Install libsymbol locally when building perf expr: Tidy hashmap dependency
perf thread_map: Reduce exposure of libperf internal API perf cpumap: Tidy libperf includes
perf build: Use tools/lib headers from install path

 tools/lib/api/Makefile                        |  52 ++++++
 tools/lib/perf/Makefile                       |  10 +-
 tools/lib/subcmd/Makefile                     |  49 ++++++
 tools/lib/symbol/Build                        |   1 +
 tools/lib/symbol/Makefile                     | 115 +++++++++++++
 tools/perf/.gitignore                         |   7 +-
 tools/perf/Makefile.config                    |   2 -
 tools/perf/Makefile.perf                      | 152 ++++++++++++------
 tools/perf/builtin-stat.c                     |   1 +
 tools/perf/builtin-trace.c                    |   4 +-
 tools/perf/tests/cpumap.c                     |   2 +-
 tools/perf/tests/expr.c                       |   1 +
 tools/perf/tests/openat-syscall.c             |   1 +
 tools/perf/tests/pmu-events.c                 |   1 +
 tools/perf/tests/thread-map.c                 |   1 +
 tools/perf/util/Build                         |   5 -
 tools/perf/util/auxtrace.h                    |   2 +-
 tools/perf/util/bpf-loader.c                  |   4 -
 tools/perf/util/bpf_counter.c                 |   2 +-
 tools/perf/util/cpumap.c                      |   1 +
 tools/perf/util/cpumap.h                      |   2 +-
 tools/perf/util/evsel.c                       |   5 +-
 tools/perf/util/evsel.h                       |   2 -
 tools/perf/util/expr.c                        |   1 +
 tools/perf/util/expr.h                        |   7 +-
 tools/perf/util/metricgroup.c                 |   1 +
 tools/perf/util/python.c                      |   6 +-
 .../scripting-engines/trace-event-python.c    |   2 +-
 tools/perf/util/stat-shadow.c                 |   1 +
 tools/perf/util/stat.c                        |   4 -
 tools/perf/util/thread_map.c                  |   1 +
 tools/perf/util/thread_map.h                  |   2 -
 32 files changed, 361 insertions(+), 86 deletions(-)
 create mode 100644 tools/lib/symbol/Build
 create mode 100644 tools/lib/symbol/Makefile
Signature · 1 line
2.38.1.431.g37b22c650d-goog
Signature · 1 line
- Arnaldo
author reviewer
#16 lore raw
Quoted 12 lines · Arnaldo Carvalho de Melo

Em Mon, Nov 07, 2022 at 11:35:04PM -0800, Ian Rogers escreveu:

Quoted 9 lines

The previous build would add -Itools/lib and get dependencies for libtraceevent, libsubcmd, libsymbol, libapi and libbpf meaning that overriding these libraries would change the link time dependency but the headers would erroneously come from tools/lib. Fix the build to install headers and then depend on these. To reduce exposing internal headers/APIs some clean up is performed. tools/lib/symbol has a Makefile added, while tools/lib/api and tools/lib/subcmd have install targets added. The pattern used for the dependencies in Makefile.perf is modelled on libbpf.

Quoted 3 lines

It builds with O=, I tried it one by one, but there are problems with make from a detached tarball, that is how I do the container builds, see below, I'm trying to figure this out...

Sorry, I didn't know to test this. The added Build and Makefile in libsymbol are missing, so I'd guess that's the major issue.

Thanks,
Ian

Quoted 247 lines

⬢[acme@toolbox perf]$ make perf-tar-src-pkg
TAR
PERF_VERSION = 6.1.rc3.g7e5d8b7a1fbd
⬢[acme@toolbox perf]$ mv perf-6.1.0-rc3.tar /tmp ⬢[acme@toolbox perf]$ cd /tmp
⬢[acme@toolbox tmp]$ tar xf perf-6.1.0-rc3.tar ⬢[acme@toolbox tmp]$ cd perf-6.1.0-rc3/ ⬢[acme@toolbox perf-6.1.0-rc3]$ make -C tools/perf
make: Entering directory '/tmp/perf-6.1.0-rc3/tools/perf'
BUILD: Doing 'make -j32' parallel build

  HOSTCC  fixdep.o
  HOSTLD  fixdep-in.o
  LINK    fixdep

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: [ on  ]
...                               libunwind: [ on  ]
...                      libdw-dwarf-unwind: [ on  ]
...                                    zlib: [ on  ]
...                                    lzma: [ on  ]
...                               get_cpuid: [ on  ]
...                                     bpf: [ on  ]
...                                  libaio: [ on  ]
...                                 libzstd: [ on  ]

GEN common-cmds.h
PERF_VERSION = 6.1.rc3.g7e5d8b7a1fbd

  CC      perf-read-vdso32
  GEN     perf-archive
  GEN     perf-iostat
  CC      dlfilters/dlfilter-test-api-v0.o
  CC      dlfilters/dlfilter-show-cycles.o
  CC      jvmti/libjvmti.o
make[3]: *** No rule to make target '/tmp/perf-6.1.0-rc3/tools/perf/libsymbol/libsymbol.a'.  Stop.
make[2]: *** [Makefile.perf:907: /tmp/perf-6.1.0-rc3/tools/perf/libsymbol/libsymbol.a] Error 2
make[2]: *** Waiting for unfinished jobs....
  CC      jvmti/jvmti_agent.o
  CC      jvmti/libstring.o
  CC      jvmti/libctype.o
  GEN     pmu-events/pmu-events.c
  INSTALL headers
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libsubcmd/exec-cmd.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libsubcmd/help.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libsubcmd/pager.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libsubcmd/parse-options.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libsubcmd/run-command.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libsubcmd/sigchain.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libsubcmd/subcmd-config.o
  INSTALL headers
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent/event-parse.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_jbd2.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_hrtimer.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_kmem.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_kvm.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_mac80211.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_function.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_sched_switch.o
  INSTALL headers
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libperf/core.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libapi/cpu.o
  MKDIR   /tmp/perf-6.1.0-rc3/tools/perf/libapi/fd/
  MKDIR   /tmp/perf-6.1.0-rc3/tools/perf/libapi/fs/
  MKDIR   /tmp/perf-6.1.0-rc3/tools/perf/libapi/fs/
  MKDIR   /tmp/perf-6.1.0-rc3/tools/perf/libapi/fs/
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libapi/fd/array.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libapi/fs/fs.o
  GEN     /tmp/perf-6.1.0-rc3/tools/perf/libbpf/bpf_helper_defs.h
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libapi/fs/tracing_path.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libapi/fs/cgroup.o
  INSTALL /tmp/perf-6.1.0-rc3/tools/perf/libbpf/include/bpf/bpf.h
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libapi/debug.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_futex.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_xen.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_scsi.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_cfg80211.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_tlb.o
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_jbd2-in.o
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_hrtimer-in.o
  INSTALL /tmp/perf-6.1.0-rc3/tools/perf/libbpf/include/bpf/libbpf.h
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_kmem-in.o
  INSTALL headers
  INSTALL /tmp/perf-6.1.0-rc3/tools/perf/libbpf/include/bpf/btf.h
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_mac80211-in.o
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_sched_switch-in.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libperf/cpumap.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libperf/threadmap.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libapi/str_error_r.o
  INSTALL /tmp/perf-6.1.0-rc3/tools/perf/libbpf/include/bpf/libbpf_common.h
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_jbd2.so
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_hrtimer.so
  INSTALL /tmp/perf-6.1.0-rc3/tools/perf/libbpf/include/bpf/libbpf_legacy.h
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_function-in.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libperf/evsel.o
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_kvm-in.o
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_kmem.so
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_mac80211.so
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_sched_switch.so
  INSTALL /tmp/perf-6.1.0-rc3/tools/perf/libbpf/include/bpf/bpf_helpers.h
  INSTALL /tmp/perf-6.1.0-rc3/tools/perf/libbpf/include/bpf/bpf_tracing.h
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent/event-plugin.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libperf/evlist.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libperf/mmap.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent/trace-seq.o
  INSTALL /tmp/perf-6.1.0-rc3/tools/perf/libbpf/include/bpf/bpf_endian.h
  INSTALL /tmp/perf-6.1.0-rc3/tools/perf/libbpf/include/bpf/bpf_core_read.h
if [ ! -d ''/tmp/perf-6.1.0-rc3/tools/perf/libapi'/include/api/fs' ]; then install -d -m 755 ''/tmp/perf-6.1.0-rc3/tools/perf/libapi'/include/api/fs'; fi; install fs/tracing_path.h -m 644 ''/tmp/perf-6.1.0-rc3/tools/perf/libapi'/include/api/fs';
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libapi/fd/libapi-in.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libperf/zalloc.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent/parse-filter.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent/parse-utils.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent/kbuffer-parse.o
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_xen-in.o
  INSTALL /tmp/perf-6.1.0-rc3/tools/perf/libbpf/include/bpf/skel_internal.h
  INSTALL /tmp/perf-6.1.0-rc3/tools/perf/libbpf/include/bpf/libbpf_version.h
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent/tep_strerror.o
  INSTALL /tmp/perf-6.1.0-rc3/tools/perf/libbpf/include/bpf/usdt.bpf.h
  INSTALL /tmp/perf-6.1.0-rc3/tools/perf/libbpf/include/bpf/bpf_helper_defs.h
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent/event-parse-api.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libperf/xyarray.o
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_function.so
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_xen.so
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_futex-in.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libperf/lib.o
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_scsi-in.o
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_cfg80211-in.o
  MKDIR   /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/
  MKDIR   /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/
  MKDIR   /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/
  MKDIR   /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_kvm.so
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/libbpf.o
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_futex.so
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_scsi.so
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/bpf.o
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libapi/fs/libapi-in.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/nlattr.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/btf.o
  MKDIR   /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_tlb-in.o
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_cfg80211.so
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/str_error.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/netlink.o
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libapi/libapi-in.o
  LD      jvmti/jvmti-in.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/libbpf_errno.o
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_tlb.so
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/bpf_prog_linfo.o
  AR      /tmp/perf-6.1.0-rc3/tools/perf/libapi/libapi.a
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/libbpf_probes.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/hashmap.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/btf_dump.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/ringbuf.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/strset.o
  GEN     /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/libtraceevent-dynamic-list
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/linker.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/gen_loader.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/relo_core.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/usdt.o
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libsubcmd/libsubcmd-in.o
  AR      /tmp/perf-6.1.0-rc3/tools/perf/libsubcmd/libsubcmd.a
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libperf/libperf-in.o
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent/libtraceevent-in.o
  AR      /tmp/perf-6.1.0-rc3/tools/perf/libperf/libperf.a
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent/libtraceevent.a
  CC      pmu-events/pmu-events.o
  LD      pmu-events/pmu-events-in.o
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/libbpf-in.o
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libbpf/libbpf.a

make[1]: *** [Makefile.perf:240: sub-make] Error 2
make: *** [Makefile:70: all] Error 2
make: Leaving directory '/tmp/perf-6.1.0-rc3/tools/perf' ⬢[acme@toolbox perf-6.1.0-rc3]$

Quoted 55 lines

The problem and solution were motivated by this issue and discussion:
https://lore.kernel.org/lkml/CAEf4BzbbOHQZUAe6iWaehKCPQAf3VC=hq657buqe2_yRKxaK-A@mail.gmail.com/

Ian Rogers (14):
tools lib api: Add install target
tools lib subcmd: Add install target
perf build: Install libsubcmd locally when building perf build: Install libapi locally when building perf build: Install libperf locally when building perf build: Install libtraceevent locally when building tools lib api: Add missing install headers tools lib perf: Add missing install headers tool lib symbol: Add Makefile/Build
perf build: Install libsymbol locally when building perf expr: Tidy hashmap dependency
perf thread_map: Reduce exposure of libperf internal API perf cpumap: Tidy libperf includes
perf build: Use tools/lib headers from install path

 tools/lib/api/Makefile                        |  52 ++++++
 tools/lib/perf/Makefile                       |  10 +-
 tools/lib/subcmd/Makefile                     |  49 ++++++
 tools/lib/symbol/Build                        |   1 +
 tools/lib/symbol/Makefile                     | 115 +++++++++++++
 tools/perf/.gitignore                         |   7 +-
 tools/perf/Makefile.config                    |   2 -
 tools/perf/Makefile.perf                      | 152 ++++++++++++------
 tools/perf/builtin-stat.c                     |   1 +
 tools/perf/builtin-trace.c                    |   4 +-
 tools/perf/tests/cpumap.c                     |   2 +-
 tools/perf/tests/expr.c                       |   1 +
 tools/perf/tests/openat-syscall.c             |   1 +
 tools/perf/tests/pmu-events.c                 |   1 +
 tools/perf/tests/thread-map.c                 |   1 +
 tools/perf/util/Build                         |   5 -
 tools/perf/util/auxtrace.h                    |   2 +-
 tools/perf/util/bpf-loader.c                  |   4 -
 tools/perf/util/bpf_counter.c                 |   2 +-
 tools/perf/util/cpumap.c                      |   1 +
 tools/perf/util/cpumap.h                      |   2 +-
 tools/perf/util/evsel.c                       |   5 +-
 tools/perf/util/evsel.h                       |   2 -
 tools/perf/util/expr.c                        |   1 +
 tools/perf/util/expr.h                        |   7 +-
 tools/perf/util/metricgroup.c                 |   1 +
 tools/perf/util/python.c                      |   6 +-
 .../scripting-engines/trace-event-python.c    |   2 +-
 tools/perf/util/stat-shadow.c                 |   1 +
 tools/perf/util/stat.c                        |   4 -
 tools/perf/util/thread_map.c                  |   1 +
 tools/perf/util/thread_map.h                  |   2 -
 32 files changed, 361 insertions(+), 86 deletions(-)
 create mode 100644 tools/lib/symbol/Build
 create mode 100644 tools/lib/symbol/Makefile
Quoted 2 lines

--
2.38.1.431.g37b22c650d-goog

--

- Arnaldo

author reviewer
#17 lore raw
Quoted 18 lines · Ian Rogers
Quoted 12 lines · Arnaldo Carvalho de Melo

Em Mon, Nov 07, 2022 at 11:35:04PM -0800, Ian Rogers escreveu:

Quoted 9 lines

The previous build would add -Itools/lib and get dependencies for libtraceevent, libsubcmd, libsymbol, libapi and libbpf meaning that overriding these libraries would change the link time dependency but the headers would erroneously come from tools/lib. Fix the build to install headers and then depend on these. To reduce exposing internal headers/APIs some clean up is performed. tools/lib/symbol has a Makefile added, while tools/lib/api and tools/lib/subcmd have install targets added. The pattern used for the dependencies in Makefile.perf is modelled on libbpf.

Quoted 3 lines

It builds with O=, I tried it one by one, but there are problems with make from a detached tarball, that is how I do the container builds, see below, I'm trying to figure this out...

Quoted 5 lines

Sorry, I didn't know to test this. The added Build and Makefile in libsymbol are missing, so I'd guess that's the major issue.

Thanks,
Ian

The following fixes this for me:

tools/perf/MANIFEST +0 -0
@@ -13,8 +13,7 @@ tools/lib/ctype.c

tools/lib/hweight.c
tools/lib/rbtree.c
tools/lib/string.c
-tools/lib/symbol/kallsyms.c
-tools/lib/symbol/kallsyms.h
+tools/lib/symbol
tools/lib/find_bit.c
tools/lib/bitmap.c
tools/lib/list_sort.c

Thanks,
Ian

Quoted 247 lines
Quoted 247 lines

⬢[acme@toolbox perf]$ make perf-tar-src-pkg
TAR
PERF_VERSION = 6.1.rc3.g7e5d8b7a1fbd
⬢[acme@toolbox perf]$ mv perf-6.1.0-rc3.tar /tmp ⬢[acme@toolbox perf]$ cd /tmp
⬢[acme@toolbox tmp]$ tar xf perf-6.1.0-rc3.tar ⬢[acme@toolbox tmp]$ cd perf-6.1.0-rc3/ ⬢[acme@toolbox perf-6.1.0-rc3]$ make -C tools/perf
make: Entering directory '/tmp/perf-6.1.0-rc3/tools/perf'
BUILD: Doing 'make -j32' parallel build

  HOSTCC  fixdep.o
  HOSTLD  fixdep-in.o
  LINK    fixdep

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: [ on  ]
...                               libunwind: [ on  ]
...                      libdw-dwarf-unwind: [ on  ]
...                                    zlib: [ on  ]
...                                    lzma: [ on  ]
...                               get_cpuid: [ on  ]
...                                     bpf: [ on  ]
...                                  libaio: [ on  ]
...                                 libzstd: [ on  ]

GEN common-cmds.h
PERF_VERSION = 6.1.rc3.g7e5d8b7a1fbd

  CC      perf-read-vdso32
  GEN     perf-archive
  GEN     perf-iostat
  CC      dlfilters/dlfilter-test-api-v0.o
  CC      dlfilters/dlfilter-show-cycles.o
  CC      jvmti/libjvmti.o
make[3]: *** No rule to make target '/tmp/perf-6.1.0-rc3/tools/perf/libsymbol/libsymbol.a'.  Stop.
make[2]: *** [Makefile.perf:907: /tmp/perf-6.1.0-rc3/tools/perf/libsymbol/libsymbol.a] Error 2
make[2]: *** Waiting for unfinished jobs....
  CC      jvmti/jvmti_agent.o
  CC      jvmti/libstring.o
  CC      jvmti/libctype.o
  GEN     pmu-events/pmu-events.c
  INSTALL headers
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libsubcmd/exec-cmd.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libsubcmd/help.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libsubcmd/pager.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libsubcmd/parse-options.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libsubcmd/run-command.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libsubcmd/sigchain.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libsubcmd/subcmd-config.o
  INSTALL headers
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent/event-parse.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_jbd2.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_hrtimer.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_kmem.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_kvm.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_mac80211.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_function.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_sched_switch.o
  INSTALL headers
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libperf/core.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libapi/cpu.o
  MKDIR   /tmp/perf-6.1.0-rc3/tools/perf/libapi/fd/
  MKDIR   /tmp/perf-6.1.0-rc3/tools/perf/libapi/fs/
  MKDIR   /tmp/perf-6.1.0-rc3/tools/perf/libapi/fs/
  MKDIR   /tmp/perf-6.1.0-rc3/tools/perf/libapi/fs/
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libapi/fd/array.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libapi/fs/fs.o
  GEN     /tmp/perf-6.1.0-rc3/tools/perf/libbpf/bpf_helper_defs.h
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libapi/fs/tracing_path.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libapi/fs/cgroup.o
  INSTALL /tmp/perf-6.1.0-rc3/tools/perf/libbpf/include/bpf/bpf.h
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libapi/debug.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_futex.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_xen.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_scsi.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_cfg80211.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_tlb.o
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_jbd2-in.o
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_hrtimer-in.o
  INSTALL /tmp/perf-6.1.0-rc3/tools/perf/libbpf/include/bpf/libbpf.h
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_kmem-in.o
  INSTALL headers
  INSTALL /tmp/perf-6.1.0-rc3/tools/perf/libbpf/include/bpf/btf.h
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_mac80211-in.o
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_sched_switch-in.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libperf/cpumap.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libperf/threadmap.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libapi/str_error_r.o
  INSTALL /tmp/perf-6.1.0-rc3/tools/perf/libbpf/include/bpf/libbpf_common.h
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_jbd2.so
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_hrtimer.so
  INSTALL /tmp/perf-6.1.0-rc3/tools/perf/libbpf/include/bpf/libbpf_legacy.h
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_function-in.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libperf/evsel.o
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_kvm-in.o
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_kmem.so
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_mac80211.so
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_sched_switch.so
  INSTALL /tmp/perf-6.1.0-rc3/tools/perf/libbpf/include/bpf/bpf_helpers.h
  INSTALL /tmp/perf-6.1.0-rc3/tools/perf/libbpf/include/bpf/bpf_tracing.h
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent/event-plugin.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libperf/evlist.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libperf/mmap.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent/trace-seq.o
  INSTALL /tmp/perf-6.1.0-rc3/tools/perf/libbpf/include/bpf/bpf_endian.h
  INSTALL /tmp/perf-6.1.0-rc3/tools/perf/libbpf/include/bpf/bpf_core_read.h
if [ ! -d ''/tmp/perf-6.1.0-rc3/tools/perf/libapi'/include/api/fs' ]; then install -d -m 755 ''/tmp/perf-6.1.0-rc3/tools/perf/libapi'/include/api/fs'; fi; install fs/tracing_path.h -m 644 ''/tmp/perf-6.1.0-rc3/tools/perf/libapi'/include/api/fs';
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libapi/fd/libapi-in.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libperf/zalloc.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent/parse-filter.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent/parse-utils.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent/kbuffer-parse.o
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_xen-in.o
  INSTALL /tmp/perf-6.1.0-rc3/tools/perf/libbpf/include/bpf/skel_internal.h
  INSTALL /tmp/perf-6.1.0-rc3/tools/perf/libbpf/include/bpf/libbpf_version.h
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent/tep_strerror.o
  INSTALL /tmp/perf-6.1.0-rc3/tools/perf/libbpf/include/bpf/usdt.bpf.h
  INSTALL /tmp/perf-6.1.0-rc3/tools/perf/libbpf/include/bpf/bpf_helper_defs.h
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent/event-parse-api.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libperf/xyarray.o
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_function.so
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_xen.so
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_futex-in.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libperf/lib.o
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_scsi-in.o
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_cfg80211-in.o
  MKDIR   /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/
  MKDIR   /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/
  MKDIR   /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/
  MKDIR   /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_kvm.so
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/libbpf.o
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_futex.so
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_scsi.so
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/bpf.o
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libapi/fs/libapi-in.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/nlattr.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/btf.o
  MKDIR   /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_tlb-in.o
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_cfg80211.so
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/str_error.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/netlink.o
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libapi/libapi-in.o
  LD      jvmti/jvmti-in.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/libbpf_errno.o
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_tlb.so
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/bpf_prog_linfo.o
  AR      /tmp/perf-6.1.0-rc3/tools/perf/libapi/libapi.a
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/libbpf_probes.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/hashmap.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/btf_dump.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/ringbuf.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/strset.o
  GEN     /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/libtraceevent-dynamic-list
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/linker.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/gen_loader.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/relo_core.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/usdt.o
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libsubcmd/libsubcmd-in.o
  AR      /tmp/perf-6.1.0-rc3/tools/perf/libsubcmd/libsubcmd.a
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libperf/libperf-in.o
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent/libtraceevent-in.o
  AR      /tmp/perf-6.1.0-rc3/tools/perf/libperf/libperf.a
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent/libtraceevent.a
  CC      pmu-events/pmu-events.o
  LD      pmu-events/pmu-events-in.o
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/libbpf-in.o
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libbpf/libbpf.a

make[1]: *** [Makefile.perf:240: sub-make] Error 2
make: *** [Makefile:70: all] Error 2
make: Leaving directory '/tmp/perf-6.1.0-rc3/tools/perf' ⬢[acme@toolbox perf-6.1.0-rc3]$

Quoted 55 lines

The problem and solution were motivated by this issue and discussion:
https://lore.kernel.org/lkml/CAEf4BzbbOHQZUAe6iWaehKCPQAf3VC=hq657buqe2_yRKxaK-A@mail.gmail.com/

Ian Rogers (14):
tools lib api: Add install target
tools lib subcmd: Add install target
perf build: Install libsubcmd locally when building perf build: Install libapi locally when building perf build: Install libperf locally when building perf build: Install libtraceevent locally when building tools lib api: Add missing install headers tools lib perf: Add missing install headers tool lib symbol: Add Makefile/Build
perf build: Install libsymbol locally when building perf expr: Tidy hashmap dependency
perf thread_map: Reduce exposure of libperf internal API perf cpumap: Tidy libperf includes
perf build: Use tools/lib headers from install path

 tools/lib/api/Makefile                        |  52 ++++++
 tools/lib/perf/Makefile                       |  10 +-
 tools/lib/subcmd/Makefile                     |  49 ++++++
 tools/lib/symbol/Build                        |   1 +
 tools/lib/symbol/Makefile                     | 115 +++++++++++++
 tools/perf/.gitignore                         |   7 +-
 tools/perf/Makefile.config                    |   2 -
 tools/perf/Makefile.perf                      | 152 ++++++++++++------
 tools/perf/builtin-stat.c                     |   1 +
 tools/perf/builtin-trace.c                    |   4 +-
 tools/perf/tests/cpumap.c                     |   2 +-
 tools/perf/tests/expr.c                       |   1 +
 tools/perf/tests/openat-syscall.c             |   1 +
 tools/perf/tests/pmu-events.c                 |   1 +
 tools/perf/tests/thread-map.c                 |   1 +
 tools/perf/util/Build                         |   5 -
 tools/perf/util/auxtrace.h                    |   2 +-
 tools/perf/util/bpf-loader.c                  |   4 -
 tools/perf/util/bpf_counter.c                 |   2 +-
 tools/perf/util/cpumap.c                      |   1 +
 tools/perf/util/cpumap.h                      |   2 +-
 tools/perf/util/evsel.c                       |   5 +-
 tools/perf/util/evsel.h                       |   2 -
 tools/perf/util/expr.c                        |   1 +
 tools/perf/util/expr.h                        |   7 +-
 tools/perf/util/metricgroup.c                 |   1 +
 tools/perf/util/python.c                      |   6 +-
 .../scripting-engines/trace-event-python.c    |   2 +-
 tools/perf/util/stat-shadow.c                 |   1 +
 tools/perf/util/stat.c                        |   4 -
 tools/perf/util/thread_map.c                  |   1 +
 tools/perf/util/thread_map.h                  |   2 -
 32 files changed, 361 insertions(+), 86 deletions(-)
 create mode 100644 tools/lib/symbol/Build
 create mode 100644 tools/lib/symbol/Makefile
Quoted 2 lines

--
2.38.1.431.g37b22c650d-goog

--

- Arnaldo

#18 lore raw

Em Wed, Nov 09, 2022 at 08:57:01AM -0800, Ian Rogers escreveu:

Quoted 19 lines · Ian Rogers
Quoted 18 lines · Arnaldo Carvalho de Melo
Quoted 15 lines

Em Mon, Nov 07, 2022 at 11:35:04PM -0800, Ian Rogers escreveu:

Quoted 9 lines

The previous build would add -Itools/lib and get dependencies for libtraceevent, libsubcmd, libsymbol, libapi and libbpf meaning that overriding these libraries would change the link time dependency but the headers would erroneously come from tools/lib. Fix the build to install headers and then depend on these. To reduce exposing internal headers/APIs some clean up is performed. tools/lib/symbol has a Makefile added, while tools/lib/api and tools/lib/subcmd have install targets added. The pattern used for the dependencies in Makefile.perf is modelled on libbpf.

It builds with O=, I tried it one by one, but there are problems with make from a detached tarball, that is how I do the container builds, see below, I'm trying to figure this out...

Quoted 7 lines
Quoted 5 lines

Sorry, I didn't know to test this. The added Build and Makefile in libsymbol are missing, so I'd guess that's the major issue.

Thanks,
Ian

The following fixes this for me:

But then there are some other problems related to making sure those libraries are built and installed _before_ perf proper starts building when it expects to find the headers for those libraries.

So perhaps we need to first run the 'install' target for those libraries before build perf proper?

I'm pushing what I have to perf/tools-libs-includes branch.

- Arnaldo

Quoted 263 lines
tools/perf/MANIFEST +0 -0
@@ -13,8 +13,7 @@ tools/lib/ctype.c

tools/lib/hweight.c
tools/lib/rbtree.c
tools/lib/string.c

tools/perf/MANIFEST +1 -2
-tools/lib/symbol/kallsyms.c
-tools/lib/symbol/kallsyms.h
+tools/lib/symbol

tools/lib/find_bit.c
tools/lib/bitmap.c
tools/lib/list_sort.c

Thanks,
Ian

Quoted 247 lines
Quoted 247 lines

⬢[acme@toolbox perf]$ make perf-tar-src-pkg
TAR
PERF_VERSION = 6.1.rc3.g7e5d8b7a1fbd
⬢[acme@toolbox perf]$ mv perf-6.1.0-rc3.tar /tmp ⬢[acme@toolbox perf]$ cd /tmp
⬢[acme@toolbox tmp]$ tar xf perf-6.1.0-rc3.tar ⬢[acme@toolbox tmp]$ cd perf-6.1.0-rc3/ ⬢[acme@toolbox perf-6.1.0-rc3]$ make -C tools/perf
make: Entering directory '/tmp/perf-6.1.0-rc3/tools/perf'
BUILD: Doing 'make -j32' parallel build

  HOSTCC  fixdep.o
  HOSTLD  fixdep-in.o
  LINK    fixdep

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: [ on  ]
...                               libunwind: [ on  ]
...                      libdw-dwarf-unwind: [ on  ]
...                                    zlib: [ on  ]
...                                    lzma: [ on  ]
...                               get_cpuid: [ on  ]
...                                     bpf: [ on  ]
...                                  libaio: [ on  ]
...                                 libzstd: [ on  ]

GEN common-cmds.h
PERF_VERSION = 6.1.rc3.g7e5d8b7a1fbd

  CC      perf-read-vdso32
  GEN     perf-archive
  GEN     perf-iostat
  CC      dlfilters/dlfilter-test-api-v0.o
  CC      dlfilters/dlfilter-show-cycles.o
  CC      jvmti/libjvmti.o
make[3]: *** No rule to make target '/tmp/perf-6.1.0-rc3/tools/perf/libsymbol/libsymbol.a'.  Stop.
make[2]: *** [Makefile.perf:907: /tmp/perf-6.1.0-rc3/tools/perf/libsymbol/libsymbol.a] Error 2
make[2]: *** Waiting for unfinished jobs....
  CC      jvmti/jvmti_agent.o
  CC      jvmti/libstring.o
  CC      jvmti/libctype.o
  GEN     pmu-events/pmu-events.c
  INSTALL headers
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libsubcmd/exec-cmd.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libsubcmd/help.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libsubcmd/pager.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libsubcmd/parse-options.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libsubcmd/run-command.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libsubcmd/sigchain.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libsubcmd/subcmd-config.o
  INSTALL headers
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent/event-parse.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_jbd2.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_hrtimer.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_kmem.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_kvm.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_mac80211.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_function.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_sched_switch.o
  INSTALL headers
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libperf/core.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libapi/cpu.o
  MKDIR   /tmp/perf-6.1.0-rc3/tools/perf/libapi/fd/
  MKDIR   /tmp/perf-6.1.0-rc3/tools/perf/libapi/fs/
  MKDIR   /tmp/perf-6.1.0-rc3/tools/perf/libapi/fs/
  MKDIR   /tmp/perf-6.1.0-rc3/tools/perf/libapi/fs/
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libapi/fd/array.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libapi/fs/fs.o
  GEN     /tmp/perf-6.1.0-rc3/tools/perf/libbpf/bpf_helper_defs.h
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libapi/fs/tracing_path.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libapi/fs/cgroup.o
  INSTALL /tmp/perf-6.1.0-rc3/tools/perf/libbpf/include/bpf/bpf.h
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libapi/debug.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_futex.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_xen.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_scsi.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_cfg80211.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_tlb.o
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_jbd2-in.o
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_hrtimer-in.o
  INSTALL /tmp/perf-6.1.0-rc3/tools/perf/libbpf/include/bpf/libbpf.h
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_kmem-in.o
  INSTALL headers
  INSTALL /tmp/perf-6.1.0-rc3/tools/perf/libbpf/include/bpf/btf.h
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_mac80211-in.o
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_sched_switch-in.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libperf/cpumap.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libperf/threadmap.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libapi/str_error_r.o
  INSTALL /tmp/perf-6.1.0-rc3/tools/perf/libbpf/include/bpf/libbpf_common.h
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_jbd2.so
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_hrtimer.so
  INSTALL /tmp/perf-6.1.0-rc3/tools/perf/libbpf/include/bpf/libbpf_legacy.h
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_function-in.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libperf/evsel.o
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_kvm-in.o
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_kmem.so
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_mac80211.so
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_sched_switch.so
  INSTALL /tmp/perf-6.1.0-rc3/tools/perf/libbpf/include/bpf/bpf_helpers.h
  INSTALL /tmp/perf-6.1.0-rc3/tools/perf/libbpf/include/bpf/bpf_tracing.h
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent/event-plugin.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libperf/evlist.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libperf/mmap.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent/trace-seq.o
  INSTALL /tmp/perf-6.1.0-rc3/tools/perf/libbpf/include/bpf/bpf_endian.h
  INSTALL /tmp/perf-6.1.0-rc3/tools/perf/libbpf/include/bpf/bpf_core_read.h
if [ ! -d ''/tmp/perf-6.1.0-rc3/tools/perf/libapi'/include/api/fs' ]; then install -d -m 755 ''/tmp/perf-6.1.0-rc3/tools/perf/libapi'/include/api/fs'; fi; install fs/tracing_path.h -m 644 ''/tmp/perf-6.1.0-rc3/tools/perf/libapi'/include/api/fs';
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libapi/fd/libapi-in.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libperf/zalloc.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent/parse-filter.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent/parse-utils.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent/kbuffer-parse.o
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_xen-in.o
  INSTALL /tmp/perf-6.1.0-rc3/tools/perf/libbpf/include/bpf/skel_internal.h
  INSTALL /tmp/perf-6.1.0-rc3/tools/perf/libbpf/include/bpf/libbpf_version.h
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent/tep_strerror.o
  INSTALL /tmp/perf-6.1.0-rc3/tools/perf/libbpf/include/bpf/usdt.bpf.h
  INSTALL /tmp/perf-6.1.0-rc3/tools/perf/libbpf/include/bpf/bpf_helper_defs.h
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent/event-parse-api.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libperf/xyarray.o
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_function.so
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_xen.so
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_futex-in.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libperf/lib.o
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_scsi-in.o
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_cfg80211-in.o
  MKDIR   /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/
  MKDIR   /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/
  MKDIR   /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/
  MKDIR   /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_kvm.so
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/libbpf.o
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_futex.so
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_scsi.so
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/bpf.o
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libapi/fs/libapi-in.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/nlattr.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/btf.o
  MKDIR   /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_tlb-in.o
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_cfg80211.so
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/str_error.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/netlink.o
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libapi/libapi-in.o
  LD      jvmti/jvmti-in.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/libbpf_errno.o
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_tlb.so
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/bpf_prog_linfo.o
  AR      /tmp/perf-6.1.0-rc3/tools/perf/libapi/libapi.a
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/libbpf_probes.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/hashmap.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/btf_dump.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/ringbuf.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/strset.o
  GEN     /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/libtraceevent-dynamic-list
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/linker.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/gen_loader.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/relo_core.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/usdt.o
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libsubcmd/libsubcmd-in.o
  AR      /tmp/perf-6.1.0-rc3/tools/perf/libsubcmd/libsubcmd.a
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libperf/libperf-in.o
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent/libtraceevent-in.o
  AR      /tmp/perf-6.1.0-rc3/tools/perf/libperf/libperf.a
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent/libtraceevent.a
  CC      pmu-events/pmu-events.o
  LD      pmu-events/pmu-events-in.o
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/libbpf-in.o
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libbpf/libbpf.a

make[1]: *** [Makefile.perf:240: sub-make] Error 2
make: *** [Makefile:70: all] Error 2
make: Leaving directory '/tmp/perf-6.1.0-rc3/tools/perf' ⬢[acme@toolbox perf-6.1.0-rc3]$

Quoted 55 lines

The problem and solution were motivated by this issue and discussion:
https://lore.kernel.org/lkml/CAEf4BzbbOHQZUAe6iWaehKCPQAf3VC=hq657buqe2_yRKxaK-A@mail.gmail.com/

Ian Rogers (14):
tools lib api: Add install target
tools lib subcmd: Add install target
perf build: Install libsubcmd locally when building perf build: Install libapi locally when building perf build: Install libperf locally when building perf build: Install libtraceevent locally when building tools lib api: Add missing install headers tools lib perf: Add missing install headers tool lib symbol: Add Makefile/Build
perf build: Install libsymbol locally when building perf expr: Tidy hashmap dependency
perf thread_map: Reduce exposure of libperf internal API perf cpumap: Tidy libperf includes
perf build: Use tools/lib headers from install path

 tools/lib/api/Makefile                        |  52 ++++++
 tools/lib/perf/Makefile                       |  10 +-
 tools/lib/subcmd/Makefile                     |  49 ++++++
 tools/lib/symbol/Build                        |   1 +
 tools/lib/symbol/Makefile                     | 115 +++++++++++++
 tools/perf/.gitignore                         |   7 +-
 tools/perf/Makefile.config                    |   2 -
 tools/perf/Makefile.perf                      | 152 ++++++++++++------
 tools/perf/builtin-stat.c                     |   1 +
 tools/perf/builtin-trace.c                    |   4 +-
 tools/perf/tests/cpumap.c                     |   2 +-
 tools/perf/tests/expr.c                       |   1 +
 tools/perf/tests/openat-syscall.c             |   1 +
 tools/perf/tests/pmu-events.c                 |   1 +
 tools/perf/tests/thread-map.c                 |   1 +
 tools/perf/util/Build                         |   5 -
 tools/perf/util/auxtrace.h                    |   2 +-
 tools/perf/util/bpf-loader.c                  |   4 -
 tools/perf/util/bpf_counter.c                 |   2 +-
 tools/perf/util/cpumap.c                      |   1 +
 tools/perf/util/cpumap.h                      |   2 +-
 tools/perf/util/evsel.c                       |   5 +-
 tools/perf/util/evsel.h                       |   2 -
 tools/perf/util/expr.c                        |   1 +
 tools/perf/util/expr.h                        |   7 +-
 tools/perf/util/metricgroup.c                 |   1 +
 tools/perf/util/python.c                      |   6 +-
 .../scripting-engines/trace-event-python.c    |   2 +-
 tools/perf/util/stat-shadow.c                 |   1 +
 tools/perf/util/stat.c                        |   4 -
 tools/perf/util/thread_map.c                  |   1 +
 tools/perf/util/thread_map.h                  |   2 -
 32 files changed, 361 insertions(+), 86 deletions(-)
 create mode 100644 tools/lib/symbol/Build
 create mode 100644 tools/lib/symbol/Makefile
Quoted 2 lines

--
2.38.1.431.g37b22c650d-goog

--

- Arnaldo

Signature · 1 line
- Arnaldo
author reviewer Acked-by Namhyung Kim
#19 lore raw
Quoted 29 lines · Arnaldo Carvalho de Melo

Em Wed, Nov 09, 2022 at 08:57:01AM -0800, Ian Rogers escreveu:

Quoted 19 lines · Ian Rogers
Quoted 18 lines · Arnaldo Carvalho de Melo
Quoted 15 lines

Em Mon, Nov 07, 2022 at 11:35:04PM -0800, Ian Rogers escreveu:

Quoted 9 lines

The previous build would add -Itools/lib and get dependencies for libtraceevent, libsubcmd, libsymbol, libapi and libbpf meaning that overriding these libraries would change the link time dependency but the headers would erroneously come from tools/lib. Fix the build to install headers and then depend on these. To reduce exposing internal headers/APIs some clean up is performed. tools/lib/symbol has a Makefile added, while tools/lib/api and tools/lib/subcmd have install targets added. The pattern used for the dependencies in Makefile.perf is modelled on libbpf.

It builds with O=, I tried it one by one, but there are problems with make from a detached tarball, that is how I do the container builds, see below, I'm trying to figure this out...

Quoted 7 lines
Quoted 5 lines

Sorry, I didn't know to test this. The added Build and Makefile in libsymbol are missing, so I'd guess that's the major issue.

Thanks,
Ian

The following fixes this for me:

Quoted 8 lines

But then there are some other problems related to making sure those libraries are built and installed _before_ perf proper starts building when it expects to find the headers for those libraries.

So perhaps we need to first run the 'install' target for those libraries before build perf proper?

I'm pushing what I have to perf/tools-libs-includes branch.

Attached is the last patch with changes to the dependencies. Moving the dependencies to prepare addresses the issue. I tested by adding sleeps to the install_headers targets to make them slow.

Thanks,
Ian

Quoted 262 lines

- Arnaldo

Quoted 260 lines
tools/perf/MANIFEST +0 -0
@@ -13,8 +13,7 @@ tools/lib/ctype.c

tools/lib/hweight.c
tools/lib/rbtree.c
tools/lib/string.c

tools/perf/MANIFEST +1 -2
-tools/lib/symbol/kallsyms.c
-tools/lib/symbol/kallsyms.h
+tools/lib/symbol

tools/lib/find_bit.c
tools/lib/bitmap.c
tools/lib/list_sort.c

Thanks,
Ian

Quoted 244 lines
Quoted 244 lines

⬢[acme@toolbox perf]$ make perf-tar-src-pkg
TAR
PERF_VERSION = 6.1.rc3.g7e5d8b7a1fbd
⬢[acme@toolbox perf]$ mv perf-6.1.0-rc3.tar /tmp ⬢[acme@toolbox perf]$ cd /tmp
⬢[acme@toolbox tmp]$ tar xf perf-6.1.0-rc3.tar ⬢[acme@toolbox tmp]$ cd perf-6.1.0-rc3/ ⬢[acme@toolbox perf-6.1.0-rc3]$ make -C tools/perf
make: Entering directory '/tmp/perf-6.1.0-rc3/tools/perf'
BUILD: Doing 'make -j32' parallel build

  HOSTCC  fixdep.o
  HOSTLD  fixdep-in.o
  LINK    fixdep

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: [ on  ]
...                               libunwind: [ on  ]
...                      libdw-dwarf-unwind: [ on  ]
...                                    zlib: [ on  ]
...                                    lzma: [ on  ]
...                               get_cpuid: [ on  ]
...                                     bpf: [ on  ]
...                                  libaio: [ on  ]
...                                 libzstd: [ on  ]

GEN common-cmds.h
PERF_VERSION = 6.1.rc3.g7e5d8b7a1fbd

  CC      perf-read-vdso32
  GEN     perf-archive
  GEN     perf-iostat
  CC      dlfilters/dlfilter-test-api-v0.o
  CC      dlfilters/dlfilter-show-cycles.o
  CC      jvmti/libjvmti.o
make[3]: *** No rule to make target '/tmp/perf-6.1.0-rc3/tools/perf/libsymbol/libsymbol.a'.  Stop.
make[2]: *** [Makefile.perf:907: /tmp/perf-6.1.0-rc3/tools/perf/libsymbol/libsymbol.a] Error 2
make[2]: *** Waiting for unfinished jobs....
  CC      jvmti/jvmti_agent.o
  CC      jvmti/libstring.o
  CC      jvmti/libctype.o
  GEN     pmu-events/pmu-events.c
  INSTALL headers
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libsubcmd/exec-cmd.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libsubcmd/help.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libsubcmd/pager.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libsubcmd/parse-options.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libsubcmd/run-command.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libsubcmd/sigchain.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libsubcmd/subcmd-config.o
  INSTALL headers
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent/event-parse.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_jbd2.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_hrtimer.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_kmem.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_kvm.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_mac80211.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_function.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_sched_switch.o
  INSTALL headers
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libperf/core.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libapi/cpu.o
  MKDIR   /tmp/perf-6.1.0-rc3/tools/perf/libapi/fd/
  MKDIR   /tmp/perf-6.1.0-rc3/tools/perf/libapi/fs/
  MKDIR   /tmp/perf-6.1.0-rc3/tools/perf/libapi/fs/
  MKDIR   /tmp/perf-6.1.0-rc3/tools/perf/libapi/fs/
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libapi/fd/array.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libapi/fs/fs.o
  GEN     /tmp/perf-6.1.0-rc3/tools/perf/libbpf/bpf_helper_defs.h
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libapi/fs/tracing_path.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libapi/fs/cgroup.o
  INSTALL /tmp/perf-6.1.0-rc3/tools/perf/libbpf/include/bpf/bpf.h
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libapi/debug.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_futex.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_xen.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_scsi.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_cfg80211.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_tlb.o
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_jbd2-in.o
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_hrtimer-in.o
  INSTALL /tmp/perf-6.1.0-rc3/tools/perf/libbpf/include/bpf/libbpf.h
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_kmem-in.o
  INSTALL headers
  INSTALL /tmp/perf-6.1.0-rc3/tools/perf/libbpf/include/bpf/btf.h
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_mac80211-in.o
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_sched_switch-in.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libperf/cpumap.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libperf/threadmap.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libapi/str_error_r.o
  INSTALL /tmp/perf-6.1.0-rc3/tools/perf/libbpf/include/bpf/libbpf_common.h
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_jbd2.so
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_hrtimer.so
  INSTALL /tmp/perf-6.1.0-rc3/tools/perf/libbpf/include/bpf/libbpf_legacy.h
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_function-in.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libperf/evsel.o
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_kvm-in.o
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_kmem.so
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_mac80211.so
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_sched_switch.so
  INSTALL /tmp/perf-6.1.0-rc3/tools/perf/libbpf/include/bpf/bpf_helpers.h
  INSTALL /tmp/perf-6.1.0-rc3/tools/perf/libbpf/include/bpf/bpf_tracing.h
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent/event-plugin.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libperf/evlist.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libperf/mmap.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent/trace-seq.o
  INSTALL /tmp/perf-6.1.0-rc3/tools/perf/libbpf/include/bpf/bpf_endian.h
  INSTALL /tmp/perf-6.1.0-rc3/tools/perf/libbpf/include/bpf/bpf_core_read.h
if [ ! -d ''/tmp/perf-6.1.0-rc3/tools/perf/libapi'/include/api/fs' ]; then install -d -m 755 ''/tmp/perf-6.1.0-rc3/tools/perf/libapi'/include/api/fs'; fi; install fs/tracing_path.h -m 644 ''/tmp/perf-6.1.0-rc3/tools/perf/libapi'/include/api/fs';
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libapi/fd/libapi-in.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libperf/zalloc.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent/parse-filter.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent/parse-utils.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent/kbuffer-parse.o
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_xen-in.o
  INSTALL /tmp/perf-6.1.0-rc3/tools/perf/libbpf/include/bpf/skel_internal.h
  INSTALL /tmp/perf-6.1.0-rc3/tools/perf/libbpf/include/bpf/libbpf_version.h
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent/tep_strerror.o
  INSTALL /tmp/perf-6.1.0-rc3/tools/perf/libbpf/include/bpf/usdt.bpf.h
  INSTALL /tmp/perf-6.1.0-rc3/tools/perf/libbpf/include/bpf/bpf_helper_defs.h
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent/event-parse-api.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libperf/xyarray.o
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_function.so
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_xen.so
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_futex-in.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libperf/lib.o
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_scsi-in.o
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_cfg80211-in.o
  MKDIR   /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/
  MKDIR   /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/
  MKDIR   /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/
  MKDIR   /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_kvm.so
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/libbpf.o
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_futex.so
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_scsi.so
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/bpf.o
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libapi/fs/libapi-in.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/nlattr.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/btf.o
  MKDIR   /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_tlb-in.o
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_cfg80211.so
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/str_error.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/netlink.o
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libapi/libapi-in.o
  LD      jvmti/jvmti-in.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/libbpf_errno.o
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/plugin_tlb.so
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/bpf_prog_linfo.o
  AR      /tmp/perf-6.1.0-rc3/tools/perf/libapi/libapi.a
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/libbpf_probes.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/hashmap.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/btf_dump.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/ringbuf.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/strset.o
  GEN     /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent_plugins/libtraceevent-dynamic-list
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/linker.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/gen_loader.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/relo_core.o
  CC      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/usdt.o
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libsubcmd/libsubcmd-in.o
  AR      /tmp/perf-6.1.0-rc3/tools/perf/libsubcmd/libsubcmd.a
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libperf/libperf-in.o
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent/libtraceevent-in.o
  AR      /tmp/perf-6.1.0-rc3/tools/perf/libperf/libperf.a
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libtraceevent/libtraceevent.a
  CC      pmu-events/pmu-events.o
  LD      pmu-events/pmu-events-in.o
  LD      /tmp/perf-6.1.0-rc3/tools/perf/libbpf/staticobjs/libbpf-in.o
  LINK    /tmp/perf-6.1.0-rc3/tools/perf/libbpf/libbpf.a

make[1]: *** [Makefile.perf:240: sub-make] Error 2
make: *** [Makefile:70: all] Error 2
make: Leaving directory '/tmp/perf-6.1.0-rc3/tools/perf' ⬢[acme@toolbox perf-6.1.0-rc3]$

Quoted 57 lines

The problem and solution were motivated by this issue and discussion:
https://lore.kernel.org/lkml/CAEf4BzbbOHQZUAe6iWaehKCPQAf3VC=hq657buqe2_yRKxaK-A@mail.gmail.com/

Ian Rogers (14):
tools lib api: Add install target
tools lib subcmd: Add install target
perf build: Install libsubcmd locally when building perf build: Install libapi locally when building perf build: Install libperf locally when building perf build: Install libtraceevent locally when building tools lib api: Add missing install headers tools lib perf: Add missing install headers tool lib symbol: Add Makefile/Build
perf build: Install libsymbol locally when building perf expr: Tidy hashmap dependency
perf thread_map: Reduce exposure of libperf internal API perf cpumap: Tidy libperf includes
perf build: Use tools/lib headers from install path

 tools/lib/api/Makefile                        |  52 ++++++
 tools/lib/perf/Makefile                       |  10 +-
 tools/lib/subcmd/Makefile                     |  49 ++++++
 tools/lib/symbol/Build                        |   1 +
 tools/lib/symbol/Makefile                     | 115 +++++++++++++
 tools/perf/.gitignore                         |   7 +-
 tools/perf/Makefile.config                    |   2 -
 tools/perf/Makefile.perf                      | 152 ++++++++++++------
 tools/perf/builtin-stat.c                     |   1 +
 tools/perf/builtin-trace.c                    |   4 +-
 tools/perf/tests/cpumap.c                     |   2 +-
 tools/perf/tests/expr.c                       |   1 +
 tools/perf/tests/openat-syscall.c             |   1 +
 tools/perf/tests/pmu-events.c                 |   1 +
 tools/perf/tests/thread-map.c                 |   1 +
 tools/perf/util/Build                         |   5 -
 tools/perf/util/auxtrace.h                    |   2 +-
 tools/perf/util/bpf-loader.c                  |   4 -
 tools/perf/util/bpf_counter.c                 |   2 +-
 tools/perf/util/cpumap.c                      |   1 +
 tools/perf/util/cpumap.h                      |   2 +-
 tools/perf/util/evsel.c                       |   5 +-
 tools/perf/util/evsel.h                       |   2 -
 tools/perf/util/expr.c                        |   1 +
 tools/perf/util/expr.h                        |   7 +-
 tools/perf/util/metricgroup.c                 |   1 +
 tools/perf/util/python.c                      |   6 +-
 .../scripting-engines/trace-event-python.c    |   2 +-
 tools/perf/util/stat-shadow.c                 |   1 +
 tools/perf/util/stat.c                        |   4 -
 tools/perf/util/thread_map.c                  |   1 +
 tools/perf/util/thread_map.h                  |   2 -
 32 files changed, 361 insertions(+), 86 deletions(-)
 create mode 100644 tools/lib/symbol/Build
 create mode 100644 tools/lib/symbol/Makefile

--
2.38.1.431.g37b22c650d-goog

Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

--

- Arnaldo

--

- Arnaldo

From 8cdca3f85cd4398ceeddea5bbc9d421f0bfdc76a Mon Sep 17 00:00:00 2001
From: Ian Rogers <[email protected]>
Date: Wed, 9 Nov 2022 10:49:14 -0800
Subject: [PATCH] perf build: Use tools/lib headers from install path

Switch -I from tools/lib to the install path for the tools/lib libraries. Add the include_headers build targets to prepare target, as well as pmu-events.c compilation that dependes on libperf.

---
 tools/perf/Makefile.config |  2 --
 tools/perf/Makefile.perf   | 14 +++++++++++++-
 2 files changed, 13 insertions(+), 3 deletions(-)
tools/perf/Makefile.config +0 -2
index a7f6c0669fae..9cc3c48f3288 100644
@@ -349,7 +349,6 @@ ifeq ($(DEBUG),0)
   endif
 endif
 
-INC_FLAGS += -I$(srctree)/tools/lib/perf/include
 INC_FLAGS += -I$(src-perf)/util/include
 INC_FLAGS += -I$(src-perf)/arch/$(SRCARCH)/include
 INC_FLAGS += -I$(srctree)/tools/include/
@@ -367,7 +366,6 @@ endif
 
 INC_FLAGS += -I$(src-perf)/util
 INC_FLAGS += -I$(src-perf)
-INC_FLAGS += -I$(srctree)/tools/lib/
 
 CORE_CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
 
tools/perf/Makefile.perf +13 -1
index 6c1a2a3ccc38..766ec9471183 100644
@@ -305,6 +305,7 @@ LIBTRACEEVENT_INCLUDE = $(LIBTRACEEVENT_DESTDIR)/include
 LIBTRACEEVENT = $(LIBTRACEEVENT_OUTPUT)/libtraceevent.a
 export LIBTRACEEVENT
 LIBTRACEEVENT_DYNAMIC_LIST = $(LIBTRACEEVENT_PLUGINS_OUTPUT)/libtraceevent-dynamic-list
+CFLAGS += -I$(LIBTRACEEVENT_OUTPUT)/include
 
 #
 # The static build has no dynsym table, so this does not work for
@@ -322,6 +323,7 @@ LIBAPI_DESTDIR = $(LIBAPI_OUTPUT)
 LIBAPI_INCLUDE = $(LIBAPI_DESTDIR)/include
 LIBAPI = $(LIBAPI_OUTPUT)/libapi.a
 export LIBAPI
+CFLAGS += -I$(LIBAPI_OUTPUT)/include
 
 ifneq ($(OUTPUT),)
   LIBBPF_OUTPUT = $(abspath $(OUTPUT))/libbpf
@@ -331,6 +333,7 @@ endif
 LIBBPF_DESTDIR = $(LIBBPF_OUTPUT)
 LIBBPF_INCLUDE = $(LIBBPF_DESTDIR)/include
 LIBBPF = $(LIBBPF_OUTPUT)/libbpf.a
+CFLAGS += -I$(LIBBPF_OUTPUT)/include
 
 ifneq ($(OUTPUT),)
   LIBSUBCMD_OUTPUT = $(abspath $(OUTPUT))/libsubcmd
@@ -340,6 +343,7 @@ endif
 LIBSUBCMD_DESTDIR = $(LIBSUBCMD_OUTPUT)
 LIBSUBCMD_INCLUDE = $(LIBSUBCMD_DESTDIR)/include
 LIBSUBCMD = $(LIBSUBCMD_OUTPUT)/libsubcmd.a
+CFLAGS += -I$(LIBSUBCMD_OUTPUT)/include
 
 ifneq ($(OUTPUT),)
   LIBSYMBOL_OUTPUT = $(abspath $(OUTPUT))/libsymbol
@@ -349,6 +353,7 @@ endif
 LIBSYMBOL_DESTDIR = $(LIBSYMBOL_OUTPUT)
 LIBSYMBOL_INCLUDE = $(LIBSYMBOL_DESTDIR)/include
 LIBSYMBOL = $(LIBSYMBOL_OUTPUT)/libsymbol.a
+CFLAGS += -I$(LIBSYMBOL_OUTPUT)/include
 
 ifneq ($(OUTPUT),)
   LIBPERF_OUTPUT = $(abspath $(OUTPUT))/libperf
@@ -359,6 +364,7 @@ LIBPERF_DESTDIR = $(LIBPERF_OUTPUT)
 LIBPERF_INCLUDE = $(LIBPERF_DESTDIR)/include
 LIBPERF = $(LIBPERF_OUTPUT)/libperf.a
 export LIBPERF
+CFLAGS += -I$(LIBPERF_OUTPUT)/include
 
 # python extension build directories
 PYTHON_EXTBUILD     := $(OUTPUT)python_ext_build/
@@ -691,7 +697,7 @@ build := -f $(srctree)/tools/build/Makefile.build dir=. obj
 $(PERF_IN): prepare FORCE
 	$(Q)$(MAKE) $(build)=perf
 
-$(PMU_EVENTS_IN): FORCE
+$(PMU_EVENTS_IN): FORCE $(LIBPERF)
 	$(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=pmu-events obj=pmu-events
 
 $(OUTPUT)perf: $(PERFLIBS) $(PERF_IN) $(PMU_EVENTS_IN) $(LIBTRACEEVENT_DYNAMIC_LIST)
@@ -774,6 +780,12 @@ prepare: $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)common-cmds.h archheaders $(drm_ioc
 	$(rename_flags_array) \
 	$(arch_errno_name_array) \
 	$(sync_file_range_arrays) \
+	$(LIBAPI) \
+	$(LIBBPF) \
+	$(LIBPERF) \
+	$(LIBSUBCMD) \
+	$(LIBSYMBOL) \
+	$(LIBTRACEEVENT) \
 	bpf-skel
 
 $(OUTPUT)%.o: %.c prepare FORCE
Signature · 1 line
2.38.1.431.g37b22c650d-goog
#20 lore raw
In reply to Arnaldo Carvalho de Melo

Em Wed, Nov 09, 2022 at 12:27:19PM -0300, Arnaldo Carvalho de Melo escreveu:

Quoted 30 lines

Em Mon, Nov 07, 2022 at 11:35:04PM -0800, Ian Rogers escreveu:

Quoted 9 lines

The previous build would add -Itools/lib and get dependencies for libtraceevent, libsubcmd, libsymbol, libapi and libbpf meaning that overriding these libraries would change the link time dependency but the headers would erroneously come from tools/lib. Fix the build to install headers and then depend on these. To reduce exposing internal headers/APIs some clean up is performed. tools/lib/symbol has a Makefile added, while tools/lib/api and tools/lib/subcmd have install targets added. The pattern used for the dependencies in Makefile.perf is modelled on libbpf.

It builds with O=, I tried it one by one, but there are problems with make from a detached tarball, that is how I do the container builds, see below, I'm trying to figure this out...

⬢[acme@toolbox perf]$ make perf-tar-src-pkg
TAR
PERF_VERSION = 6.1.rc3.g7e5d8b7a1fbd
⬢[acme@toolbox perf]$ mv perf-6.1.0-rc3.tar /tmp ⬢[acme@toolbox perf]$ cd /tmp
⬢[acme@toolbox tmp]$ tar xf perf-6.1.0-rc3.tar ⬢[acme@toolbox tmp]$ cd perf-6.1.0-rc3/ ⬢[acme@toolbox perf-6.1.0-rc3]$ make -C tools/perf
make: Entering directory '/tmp/perf-6.1.0-rc3/tools/perf'
BUILD: Doing 'make -j32' parallel build

  HOSTCC  fixdep.o
  HOSTLD  fixdep-in.o
  LINK    fixdep

Auto-detecting system features:

<SNIP>

Quoted 5 lines

... dwarf: [ on ]
CC jvmti/libjvmti.o
make[3]: *** No rule to make target '/tmp/perf-6.1.0-rc3/tools/perf/libsymbol/libsymbol.a'. Stop. make[2]: *** [Makefile.perf:907: /tmp/perf-6.1.0-rc3/tools/perf/libsymbol/libsymbol.a] Error 2 make[2]: *** Waiting for unfinished jobs....

So this cures it:

tools/perf/MANIFEST +1 -2
index f5d72f936a6bad2c..c8e8e05b4ff1f56f 100644
@@ -13,8 +13,7 @@ tools/lib/ctype.c
 tools/lib/hweight.c
 tools/lib/rbtree.c
 tools/lib/string.c
-tools/lib/symbol/kallsyms.c
-tools/lib/symbol/kallsyms.h
+tools/lib/symbol
 tools/lib/find_bit.c
 tools/lib/bitmap.c
 tools/lib/list_sort.c