perf build: Reduce build time by one third
Subsystems (3)
Ian Rogers
reviewerPATCH v5 2/14 perf trace beauty: Make beauty generated C code standalone .o files
In reply to Ian RogersPreviously, builtin-trace.c directly included 15 embedded C files (e.g. trace/beauty/mmap.c and fsconfig_arrays.c), which in turn depend on dozens of generated beauty script arrays. To satisfy these embedded inclusions, the global Makefile.perf would define all the generator variables/rules and include them in the prepare umbrella target, choking parallel build startup.
Furthermore, tools/perf/util/syscalltbl.c included its own generated mapper, and util/env.c conditionally included arch_errno_names.c inline, splitting consumers across directories and preventing clean Make encapsulation.
Refactor the framework to achieve better encapsulation:
1. Move util/syscalltbl.[ch] into trace/beauty/ to co-locate with all generated code consumers.
2. Create fsconfig.c and flatten embedded beauty .c files to compile as independent standalone objects via trace/beauty/Build, exporting their formatting functions via beauty.h and env.h. Switch arch_errno_names.o and syscalltbl.o assignments directly to perf-util-y and add an unconditional top-level recursive kbuild hook (perf-util-y += trace/beauty/) to compile them into libperf-util.a, resolving remote linkage for util/env.c, util/bpf-trace-summary.c, and standalone python extensions.
3. Bridge private opaque references (struct trace) securely via accessors trace__show_zeros() and trace__host(), avoiding header entanglements.
4. Consolidate all generator variables, script paths, and array generation rules entirely out of Makefile.perf and place them directly inside the exact local Build files where their output objects are compiled (trace/beauty/Build and trace/beauty/tracepoints/Build), binding prerequisites locally. Use directly inside
generator recipes to guarantee dynamic directory creation before script redirection, and append across all rules to print
clean, standardized GEN ... file.c output during compilation.
5. Clean up clean target to recursively remove the generated directory instead of relying on dozens of individual variables.
This unchokes the "prepare" target parallel barrier, allows make to evaluate generation scripts purely locally where consumed, and flattens the tracepoint formatting architecture.
Testing a parallel build (make -j28 all from scratch) shows improvements:
Before:
real 0m28.689s
user 2m38.490s
sys 0m30.148sAfter:
real 0m27.642s
user 2m32.356s
sys 0m26.683sSo reclaiming ~9.6 seconds of raw CPU time and over 1 full second off overall real-world build latency, by overlapping sub-make startup and avoiding top-level double-parsing overhead.
---
tools/perf/Build | 2 +
tools/perf/Makefile.perf | 282 +-----------------
tools/perf/builtin-trace.c | 32 +-
tools/perf/trace/beauty/Build | 276 +++++++++++++++++
tools/perf/trace/beauty/arch_errno_names.c | 2 +
tools/perf/trace/beauty/arch_errno_names.sh | 2 +-
tools/perf/trace/beauty/beauty.h | 60 ++++
tools/perf/trace/beauty/eventfd.c | 6 +-
tools/perf/trace/beauty/fsconfig.c | 5 +
tools/perf/trace/beauty/futex_op.c | 5 +-
tools/perf/trace/beauty/futex_val3.c | 5 +-
tools/perf/trace/beauty/mmap.c | 24 +-
tools/perf/trace/beauty/mode_t.c | 6 +-
tools/perf/trace/beauty/msg_flags.c | 8 +-
tools/perf/trace/beauty/open_flags.c | 2 +
tools/perf/trace/beauty/perf_event_open.c | 21 +-
tools/perf/trace/beauty/pid.c | 5 +-
tools/perf/trace/beauty/sched_policy.c | 8 +-
tools/perf/trace/beauty/seccomp.c | 12 +-
tools/perf/trace/beauty/signum.c | 6 +-
tools/perf/trace/beauty/socket_type.c | 6 +-
.../perf/{util => trace/beauty}/syscalltbl.c | 0
.../perf/{util => trace/beauty}/syscalltbl.h | 0
tools/perf/trace/beauty/tracepoints/Build | 21 ++
tools/perf/trace/beauty/waitid_options.c | 8 +-
tools/perf/util/Build | 4 +-
tools/perf/util/bpf-trace-summary.c | 2 +-
tools/perf/util/env.c | 4 -
tools/perf/util/env.h | 1 +
29 files changed, 447 insertions(+), 368 deletions(-)
create mode 100644 tools/perf/trace/beauty/fsconfig.c
rename tools/perf/{util => trace/beauty}/syscalltbl.c (100%)
rename tools/perf/{util => trace/beauty}/syscalltbl.h (100%)tools/perf/Build +2 -0
@@ -34,6 +34,8 @@ ifeq ($(CONFIG_LIBTRACEEVENT),y) perf-$(CONFIG_TRACE) += trace/beauty/ endif +perf-util-y += trace/beauty/ + perf-$(CONFIG_LIBELF) += builtin-probe.o perf-bench-y += bench/
tools/perf/Makefile.perf +2 -280
300 lines not on this page · raw message
tools/perf/builtin-trace.c +12 -20
@@ -60,12 +60,13 @@#include "callchain.h" #include "print_binary.h" #include "string2.h" -#include "syscalltbl.h" +#include "trace/beauty/syscalltbl.h" #include "../perf.h" #include "trace_augment.h" #include "dwarf-regs.h" #include <errno.h> +#include <sys/stat.h> #include <inttypes.h> #include <poll.h> #include <signal.h>
@@ -234,6 +235,16 @@ struct trace {const char *uid_str; }; +bool trace__show_zeros (const struct trace *trace) +{ +return trace->show_zeros; +} + +struct machine *trace__host (const struct trace *trace) +{ +return trace->host; +} +static void trace__load_vmlinux_btf (struct trace *trace__maybe_unused ) {#ifdef HAVE_LIBBPF_SUPPORT
@@ -776,10 +787,6 @@ static const char *fsmount_flags[] = { }; static DEFINE_STRARRAY(fsmount_flags, "FSMOUNT_"); -#include "trace/beauty/generated/fsconfig_arrays.c" - -static DEFINE_STRARRAY(fsconfig_cmds, "FSCONFIG_"); -static const char *epoll_ctl_ops[] = {"ADD" ,"DEL" ,"MOD" , }; static DEFINE_STRARRAY_OFFSET(epoll_ctl_ops, "EPOLL_CTL_", 1);
@@ -1128,21 +1135,6 @@ static bool syscall_arg__strtoul_btf_type(char *bf __maybe_unused, size_t size _ .parm = &strarray__##array, \ .show_zero = true, } -#include "trace/beauty/eventfd.c" -#include "trace/beauty/futex_op.c" -#include "trace/beauty/futex_val3.c" -#include "trace/beauty/mmap.c" -#include "trace/beauty/mode_t.c" -#include "trace/beauty/msg_flags.c" -#include "trace/beauty/open_flags.c" -#include "trace/beauty/perf_event_open.c" -#include "trace/beauty/pid.c" -#include "trace/beauty/sched_policy.c" -#include "trace/beauty/seccomp.c" -#include "trace/beauty/signum.c" -#include "trace/beauty/socket_type.c" -#include "trace/beauty/waitid_options.c" -static const struct syscall_fmt syscall_fmts[] = { { .name ="access" , .arg = { [1 ] = { .scnprintf =SCA_ACCMODE ,/* mode */ }, }, },
tools/perf/trace/beauty/Build +276 -0
285 lines not on this page · raw message
tools/perf/trace/beauty/arch_errno_names.c +2 -0
@@ -1 +1,3 @@ +// SPDX-License-Identifier: GPL-2.0 +#include "util/env.h" #include "trace/beauty/generated/arch_errno_name_array.c"
tools/perf/trace/beauty/arch_errno_names.sh +1 -1
@@ -57,7 +57,7 @@ create_arch_errno_table_func() archlist="$1" default="$2" - printf 'static arch_syscalls__strerrno_t *\n' + printf 'arch_syscalls__strerrno_t *\n' printf 'arch_syscalls__strerrno_function(const char *arch)\n' printf '{\n' for arch in $archlist; do
tools/perf/trace/beauty/beauty.h +60 -0
70 lines not on this page · raw message
tools/perf/trace/beauty/eventfd.c +3 -3
@@ -1,4 +1,6 @@// SPDX-License-Identifier: LGPL-2.1 +#include "trace/beauty/beauty.h" +#ifndef EFD_SEMAPHORE #define EFD_SEMAPHORE 1#endif
@@ -11,7 +13,7 @@#define EFD_CLOEXEC 02000000#endif -static size_t syscall_arg__scnprintf_eventfd_flags (char *bf,size_t size,struct syscall_arg *arg) +size_t syscall_arg__scnprintf_eventfd_flags (char *bf,size_t size,struct syscall_arg *arg) {bool show_prefix = arg->show_string_prefix;const char *prefix ="EFD_" ;
@@ -35,5 +37,3 @@ static size_t syscall_arg__scnprintf_eventfd_flags(char *bf, size_t size, structreturn printed; } - -#define SCA_EFD_FLAGS syscall_arg__scnprintf_eventfd_flags
tools/perf/trace/beauty/fsconfig.c new file +5 -0
@@ -0,0 +1,5 @@ +// SPDX-License-Identifier: LGPL-2.1 +#include "trace/beauty/beauty.h" +#include "trace/beauty/generated/fsconfig_arrays.c" + +DEFINE_STRARRAY (fsconfig_cmds,"FSCONFIG_" );
tools/perf/trace/beauty/futex_op.c +2 -3
@@ -1,4 +1,5 @@// SPDX-License-Identifier: LGPL-2.1 +#include "trace/beauty/beauty.h" #include <linux/futex.h> #ifndef FUTEX_WAIT_BITSET
@@ -17,7 +18,7 @@#define FUTEX_CLOCK_REALTIME 256#endif -static size_t syscall_arg__scnprintf_futex_op (char *bf,size_t size,struct syscall_arg *arg) +size_t syscall_arg__scnprintf_futex_op (char *bf,size_t size,struct syscall_arg *arg) {bool show_prefix = arg->show_string_prefix;const char *prefix ="FUTEX_" ;
@@ -59,5 +60,3 @@ static size_t syscall_arg__scnprintf_futex_op(char *bf, size_t size, struct syscreturn printed; } - -#define SCA_FUTEX_OP syscall_arg__scnprintf_futex_op
tools/perf/trace/beauty/futex_val3.c +2 -3
@@ -1,11 +1,12 @@// SPDX-License-Identifier: LGPL-2.1 +#include "trace/beauty/beauty.h" #include <linux/futex.h> #ifndef FUTEX_BITSET_MATCH_ANY #define FUTEX_BITSET_MATCH_ANY 0xffffffff#endif -static size_t syscall_arg__scnprintf_futex_val3 (char *bf,size_t size,struct syscall_arg *arg) +size_t syscall_arg__scnprintf_futex_val3 (char *bf,size_t size,struct syscall_arg *arg) {const char *prefix ="FUTEX_BITSET_" ;unsigned int bitset = arg->val;
@@ -15,5 +16,3 @@ static size_t syscall_arg__scnprintf_futex_val3(char *bf, size_t size, struct syreturn scnprintf (bf, size,"%#xd" , bitset); } - -#define SCA_FUTEX_VAL3 syscall_arg__scnprintf_futex_val3
tools/perf/trace/beauty/mmap.c +11 -13
@@ -1,5 +1,6 @@// SPDX-License-Identifier: LGPL-2.1 #include <linux/log2.h> +#include "trace/beauty/beauty.h" #include "trace/beauty/generated/mmap_prot_array.c" static DEFINE_STRARRAY(mmap_prot, "PROT_");
@@ -8,8 +9,7 @@ static size_t mmap__scnprintf_prot(unsigned long prot, char *bf, size_t size, bo {return strarray__scnprintf_flags (&strarray__mmap_prot, bf, size, show_prefix, prot); } - -static size_t syscall_arg__scnprintf_mmap_prot (char *bf,size_t size,struct syscall_arg *arg) +size_t syscall_arg__scnprintf_mmap_prot (char *bf,size_t size,struct syscall_arg *arg) {unsigned long prot = arg->val;
@@ -19,18 +19,18 @@ static size_t syscall_arg__scnprintf_mmap_prot(char *bf, size_t size, struct sysreturn mmap__scnprintf_prot (prot, bf, size, arg->show_string_prefix); } -#define SCA_MMAP_PROT syscall_arg__scnprintf_mmap_prot +#include "trace/beauty/generated/mmap_flags_array.c" -static DEFINE_STRARRAY(mmap_flags, "MAP_"); +DEFINE_STRARRAY (mmap_flags,"MAP_" );static size_t mmap__scnprintf_flags (unsigned long flags,char *bf,size_t size,bool show_prefix) {return strarray__scnprintf_flags (&strarray__mmap_flags, bf, size, show_prefix, flags); } -static size_t syscall_arg__scnprintf_mmap_flags (char *bf,size_t size, -struct syscall_arg *arg) +size_t syscall_arg__scnprintf_mmap_flags (char *bf,size_t size, +struct syscall_arg *arg) {unsigned long flags = arg->val;
@@ -40,7 +40,7 @@ static size_t syscall_arg__scnprintf_mmap_flags(char *bf, size_t size,return mmap__scnprintf_flags (flags, bf, size, arg->show_string_prefix); } -#define SCA_MMAP_FLAGS syscall_arg__scnprintf_mmap_flags +#include "trace/beauty/generated/mremap_flags_array.c" static DEFINE_STRARRAY(mremap_flags, "MREMAP_");
@@ -50,7 +50,7 @@ static size_t mremap__scnprintf_flags(unsigned long flags, char *bf, size_t sizereturn strarray__scnprintf_flags (&strarray__mremap_flags, bf, size, show_prefix, flags); } -static size_t syscall_arg__scnprintf_mremap_flags (char *bf,size_t size,struct syscall_arg *arg) +size_t syscall_arg__scnprintf_mremap_flags (char *bf,size_t size,struct syscall_arg *arg) {unsigned long flags = arg->val;
@@ -60,7 +60,7 @@ static size_t syscall_arg__scnprintf_mremap_flags(char *bf, size_t size, structreturn mremap__scnprintf_flags (flags, bf, size, arg->show_string_prefix); } -#define SCA_MREMAP_FLAGS syscall_arg__scnprintf_mremap_flags +static size_t madvise__scnprintf_behavior (int behavior,char *bf,size_t size) {
@@ -73,10 +73,8 @@ static size_t madvise__scnprintf_behavior(int behavior, char *bf, size_t size)return scnprintf (bf, size,"%#" , behavior); } -static size_t syscall_arg__scnprintf_madvise_behavior (char *bf,size_t size, -struct syscall_arg *arg) +size_t syscall_arg__scnprintf_madvise_behavior (char *bf,size_t size, +struct syscall_arg *arg) {return madvise__scnprintf_behavior (arg->val, bf, size); } - -#define SCA_MADV_BHV syscall_arg__scnprintf_madvise_behavior
tools/perf/trace/beauty/mode_t.c +3 -3
@@ -1,4 +1,6 @@// SPDX-License-Identifier: LGPL-2.1 +#include "trace/beauty/beauty.h" +#include <sys/types.h> #include <sys/stat.h> #include <unistd.h>
@@ -20,7 +22,7 @@#define S_IXUGO (S_IXUSR|S_IXGRP|S_IXOTH)#endif -static size_t syscall_arg__scnprintf_mode_t (char *bf,size_t size,struct syscall_arg *arg) +size_t syscall_arg__scnprintf_mode_t (char *bf,size_t size,struct syscall_arg *arg) {bool show_prefix = arg->show_string_prefix;const char *prefix ="S_" ;
@@ -67,5 +69,3 @@ static size_t syscall_arg__scnprintf_mode_t(char *bf, size_t size, struct syscalreturn printed; } - -#define SCA_MODE_T syscall_arg__scnprintf_mode_t
tools/perf/trace/beauty/msg_flags.c +4 -4
@@ -1,4 +1,6 @@// SPDX-License-Identifier: LGPL-2.1 +#include "trace/beauty/beauty.h" +#include <sys/types.h> #include <sys/socket.h>
@@ -27,8 +29,8 @@# define MSG_CMSG_CLOEXEC 0x40000000#endif -static size_t syscall_arg__scnprintf_msg_flags (char *bf,size_t size, -struct syscall_arg *arg) +size_t syscall_arg__scnprintf_msg_flags (char *bf,size_t size, +struct syscall_arg *arg) {bool show_prefix = arg->show_string_prefix;const char *prefix ="MSG_" ;
@@ -72,5 +74,3 @@ static size_t syscall_arg__scnprintf_msg_flags(char *bf, size_t size,return printed; } - -#define SCA_MSG_FLAGS syscall_arg__scnprintf_msg_flags
tools/perf/trace/beauty/open_flags.c +2 -0
@@ -1,4 +1,6 @@// SPDX-License-Identifier: LGPL-2.1 +#include "trace/beauty/beauty.h" +#include <sys/types.h> #include <sys/stat.h> #include <fcntl.h>
tools/perf/trace/beauty/perf_event_open.c +10 -11
@@ -1,4 +1,8 @@// SPDX-License-Identifier: LGPL-2.1 +#include "trace/beauty/beauty.h" +#include "util/evsel_fprintf.h" +#include <linux/perf_event.h> +#ifndef PERF_FLAG_FD_NO_GROUP # define PERF_FLAG_FD_NO_GROUP (1UL << 0)#endif
@@ -15,8 +19,8 @@# define PERF_FLAG_FD_CLOEXEC (1UL << 3)/* O_CLOEXEC */ #endif -static size_t syscall_arg__scnprintf_perf_flags (char *bf,size_t size, -struct syscall_arg *arg) +size_t syscall_arg__scnprintf_perf_flags (char *bf,size_t size, +struct syscall_arg *arg) {bool show_prefix = arg->show_string_prefix;const char *prefix ="PERF_" ;
@@ -43,7 +47,7 @@ static size_t syscall_arg__scnprintf_perf_flags(char *bf, size_t size,return printed; } -#define SCA_PERF_FLAGS syscall_arg__scnprintf_perf_flags +struct attr_fprintf_args {size_t size, printed;
@@ -76,19 +80,14 @@ static size_t perf_event_attr___scnprintf(struct perf_event_attr *attr, char *bfstatic size_t syscall_arg__scnprintf_augmented_perf_event_attr (struct syscall_arg *arg,char *bf,size_t size) { -return perf_event_attr___scnprintf ((void *)arg->augmented.args->value, bf, size, arg->trace->show_zeros); +return perf_event_attr___scnprintf ((void *)arg->augmented.args->value, bf, size, +trace__show_zeros (arg->trace)); } -static size_t syscall_arg__scnprintf_perf_event_attr (char *bf,size_t size,struct syscall_arg *arg) +size_t syscall_arg__scnprintf_perf_event_attr (char *bf,size_t size,struct syscall_arg *arg) {if (arg->augmented.args)return syscall_arg__scnprintf_augmented_perf_event_attr (arg, bf, size);return scnprintf (bf, size,"%#lx" , arg->val); } - -#define SCA_PERF_ATTR syscall_arg__scnprintf_perf_event_attr -// 'argname' is just documentational at this point, to remove the previous comment with that info -#define SCA_PERF_ATTR_FROM_USER (argname) \ - { .scnprintf = SCA_PERF_ATTR, \ - .from_user = true, }
tools/perf/trace/beauty/pid.c +4 -1
@@ -1,11 +1,14 @@// SPDX-License-Identifier: LGPL-2.1 +#include "trace/beauty/beauty.h" +#include "util/machine.h" +#include "util/thread.h" size_t syscall_arg__scnprintf_pid (char *bf,size_t size,struct syscall_arg *arg) {int pid = arg->val;struct trace *trace = arg->trace;size_t printed =scnprintf (bf, size,"%d" , pid); -struct thread *thread =machine__findnew_thread (trace->host, pid, pid); +struct thread *thread =machine__findnew_thread (trace__host (trace), pid, pid);if (thread !=NULL ) {if (!thread__comm_set (thread))
tools/perf/trace/beauty/sched_policy.c +4 -4
@@ -1,4 +1,6 @@// SPDX-License-Identifier: LGPL-2.1 +#include "trace/beauty/beauty.h" +#include <sched.h> /*
@@ -14,8 +16,8 @@#define SCHED_RESET_ON_FORK 0x40000000#endif -static size_t syscall_arg__scnprintf_sched_policy (char *bf,size_t size, -struct syscall_arg *arg) +size_t syscall_arg__scnprintf_sched_policy (char *bf,size_t size, +struct syscall_arg *arg) {bool show_prefix = arg->show_string_prefix;const char *prefix ="SCHED_" ;
@@ -46,5 +48,3 @@ static size_t syscall_arg__scnprintf_sched_policy(char *bf, size_t size,return printed; } - -#define SCA_SCHED_POLICY syscall_arg__scnprintf_sched_policy
tools/perf/trace/beauty/seccomp.c +6 -6
@@ -1,4 +1,6 @@// SPDX-License-Identifier: LGPL-2.1 +#include "trace/beauty/beauty.h" +#ifndef SECCOMP_SET_MODE_STRICT #define SECCOMP_SET_MODE_STRICT 0#endif
@@ -6,7 +8,7 @@#define SECCOMP_SET_MODE_FILTER 1#endif -static size_t syscall_arg__scnprintf_seccomp_op (char *bf,size_t size,struct syscall_arg *arg) +size_t syscall_arg__scnprintf_seccomp_op (char *bf,size_t size,struct syscall_arg *arg) {bool show_prefix = arg->show_string_prefix;const char *prefix ="SECCOMP_SET_MODE_" ;
@@ -24,14 +26,14 @@ static size_t syscall_arg__scnprintf_seccomp_op(char *bf, size_t size, struct syreturn printed; } -#define SCA_SECCOMP_OP syscall_arg__scnprintf_seccomp_op +#ifndef SECCOMP_FILTER_FLAG_TSYNC #define SECCOMP_FILTER_FLAG_TSYNC 1#endif -static size_t syscall_arg__scnprintf_seccomp_flags (char *bf,size_t size, -struct syscall_arg *arg) +size_t syscall_arg__scnprintf_seccomp_flags (char *bf,size_t size, +struct syscall_arg *arg) {bool show_prefix = arg->show_string_prefix;const char *prefix ="SECCOMP_FILTER_FLAG_" ;
@@ -51,5 +53,3 @@ static size_t syscall_arg__scnprintf_seccomp_flags(char *bf, size_t size,return printed; } - -#define SCA_SECCOMP_FLAGS syscall_arg__scnprintf_seccomp_flags
tools/perf/trace/beauty/signum.c +3 -3
@@ -1,7 +1,9 @@// SPDX-License-Identifier: LGPL-2.1 +#include "trace/beauty/beauty.h" +#include <signal.h> -static size_t syscall_arg__scnprintf_signum (char *bf,size_t size,struct syscall_arg *arg) +size_t syscall_arg__scnprintf_signum (char *bf,size_t size,struct syscall_arg *arg) {bool show_prefix = arg->show_string_prefix;const char *prefix ="SIG" ;
@@ -53,5 +55,3 @@ static size_t syscall_arg__scnprintf_signum(char *bf, size_t size, struct syscalreturn scnprintf (bf, size,"%#x" , sig); } - -#define SCA_SIGNUM syscall_arg__scnprintf_signum
tools/perf/trace/beauty/socket_type.c +3 -3
@@ -1,4 +1,6 @@// SPDX-License-Identifier: LGPL-2.1 +#include "trace/beauty/beauty.h" +#include <sys/types.h> #include <sys/socket.h>
@@ -18,7 +20,7 @@#define SOCK_TYPE_MASK 0xf#endif -static size_t syscall_arg__scnprintf_socket_type (char *bf,size_t size,struct syscall_arg *arg) +size_t syscall_arg__scnprintf_socket_type (char *bf,size_t size,struct syscall_arg *arg) {bool show_prefix = arg->show_string_prefix;const char *prefix ="SOCK_" ;
@@ -59,5 +61,3 @@ static size_t syscall_arg__scnprintf_socket_type(char *bf, size_t size, struct sreturn printed; } - -#define SCA_SK_TYPE syscall_arg__scnprintf_socket_type
tools/perf/trace/beauty/syscalltbl.c renamed from tools/perf/util/syscalltbl.c +0 -0
tools/perf/trace/beauty/syscalltbl.h renamed from tools/perf/util/syscalltbl.h +0 -0
tools/perf/trace/beauty/tracepoints/Build +21 -0
@@ -1,2 +1,23 @@ perf-y += x86_irq_vectors.o perf-y += x86_msr.o + +beauty_outdir := $(OUTPUT)trace/beauty/generated +beauty_arch_asm_dir := $(srctree)/tools/perf/trace/beauty/arch/x86/include/asm/ +x86_arch_asm_dir := $(srctree)/tools/arch/x86/include/asm/ + +x86_arch_irq_vectors_array := $(beauty_outdir)/x86_arch_irq_vectors_array.c +x86_arch_irq_vectors_tbl := $(srctree)/tools/perf/trace/beauty/tracepoints/x86_irq_vectors.sh + +$(x86_arch_irq_vectors_array): $(beauty_arch_asm_dir)/irq_vectors.h $(x86_arch_irq_vectors_tbl) + $(call rule_mkdir) + $(Q)$(call echo-cmd,gen)$(SHELL) '$(x86_arch_irq_vectors_tbl)' $(beauty_arch_asm_dir) > $@ + +x86_arch_MSRs_array := $(beauty_outdir)/x86_arch_MSRs_array.c +x86_arch_MSRs_tbl := $(srctree)/tools/perf/trace/beauty/tracepoints/x86_msr.sh + +$(x86_arch_MSRs_array): $(x86_arch_asm_dir)/msr-index.h $(x86_arch_MSRs_tbl) + $(call rule_mkdir) + $(Q)$(call echo-cmd,gen)$(SHELL) '$(x86_arch_MSRs_tbl)' $(x86_arch_asm_dir) > $@ + +$(OUTPUT)trace/beauty/tracepoints/x86_irq_vectors.o: $(x86_arch_irq_vectors_array) +$(OUTPUT)trace/beauty/tracepoints/x86_msr.o: $(x86_arch_MSRs_array)
tools/perf/trace/beauty/waitid_options.c +4 -4
@@ -1,9 +1,11 @@// SPDX-License-Identifier: LGPL-2.1 +#include "trace/beauty/beauty.h" +#include <sys/types.h> #include <sys/wait.h> -static size_t syscall_arg__scnprintf_waitid_options (char *bf,size_t size, -struct syscall_arg *arg) +size_t syscall_arg__scnprintf_waitid_options (char *bf,size_t size, +struct syscall_arg *arg) {bool show_prefix = arg->show_string_prefix;const char *prefix ="W" ;
@@ -25,5 +27,3 @@ static size_t syscall_arg__scnprintf_waitid_options(char *bf, size_t size,return printed; } - -#define SCA_WAITID_OPTIONS syscall_arg__scnprintf_waitid_options
tools/perf/util/Build +3 -1
@@ -75,7 +75,7 @@ perf-util-y += sample.o perf-util-y += sample-raw.o perf-util-y += s390-sample-raw.o perf-util-y += amd-sample-raw.o -perf-util-$(CONFIG_TRACE) += syscalltbl.o + perf-util-y += ordered-events.o perf-util-y += namespaces.o perf-util-y += comm.o
@@ -441,3 +441,5 @@ $(OUTPUT)%.pylint_log: % $(Q)$(call echo-cmd,test)pylint "$<" > $@ || (cat $@ && rm $@ && false) perf-util-y += $(PYLINT_TEST_LOGS) + +
tools/perf/util/bpf-trace-summary.c +1 -1
@@ -6,7 +6,7 @@#include <stdlib.h> #include "dwarf-regs.h" /* for EM_HOST */ -#include "syscalltbl.h" +#include "trace/beauty/syscalltbl.h" #include "util/cgroup.h" #include "util/hashmap.h" #include "util/trace.h"
tools/perf/util/env.c +0 -4
@@ -635,10 +635,6 @@ const char *perf_env__arch(struct perf_env *env)return normalize_arch (arch_name); } -#if defined(HAVE_LIBTRACEEVENT ) -#include "trace/beauty/arch_errno_names.c" -#endif -const char *perf_env__arch_strerrno (struct perf_env *env__maybe_unused ,int err__maybe_unused ) {#if defined(HAVE_LIBTRACEEVENT )
tools/perf/util/env.h +1 -0
@@ -189,6 +189,7 @@ void cpu_cache_level__free(struct cpu_cache_level *cache);const char *perf_env__arch (struct perf_env *env);const char *perf_env__arch_strerrno (struct perf_env *env,int err); +arch_syscalls__strerrno_t *arch_syscalls__strerrno_function (const char *arch);const char *perf_env__cpuid (struct perf_env *env);const char *perf_env__raw_arch (struct perf_env *env);int perf_env__nr_cpus_avail (struct perf_env *env);
Signature · 1 line
2.54.0.563.g4f69b47b94-goog
Ian Rogers
reviewerPATCH v5 3/14 perf build: Decouple pmu-events from prepare umbrella target
In reply to Ian RogersCurrently, the $(LIBPMU_EVENTS_IN) sub-make depends on the massive "prepare" umbrella target. Because "prepare" depends on external libraries (libapi, libperf, etc.) as well as dozens of generated headers, make completely serializes the launch of the pmu-events sub-make behind some of those unrelated prerequisites.
Since pmu-events is a large compilation unit, unblock its startup by binding it directly to only $(LIBPERF) instead of prepare. This allows background python generation scripts to overlap simultaneously with the rest of the build.
Testing a parallel build (make -j28 clean all) shows improvements:
Before:
real 0m27.642s
user 2m32.356s
sys 0m26.683sAfter:
real 0m22.254s
user 2m32.810s
sys 0m24.646sThis reclaims over 5 full seconds of build latency (~19.5% overall reduction) by elevating average CPU concurrency from ~5.5 active cores up to ~8 active cores.
--- tools/perf/Makefile.perf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/Makefile.perf +1 -1
@@ -550,7 +550,7 @@ build := -f $(srctree)/tools/build/Makefile.build dir=. obj $(PERF_IN): prepare FORCE $(Q)$(MAKE) $(build)=perf -$(LIBPMU_EVENTS_IN): FORCE prepare +$(LIBPMU_EVENTS_IN): FORCE $(LIBPERF) $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=pmu-events obj=pmu-events $(LIBPMU_EVENTS): $(LIBPMU_EVENTS_IN)
Signature · 1 line
2.54.0.563.g4f69b47b94-goog
Ian Rogers
reviewerPATCH v5 4/14 perf build: Remove empty archheaders target
In reply to Ian RogersRemove empty target that doesn't do anything.
--- tools/perf/Makefile.perf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/Makefile.perf +2 -2
@@ -627,7 +627,7 @@ endif __build-dir = $(subst $(OUTPUT),,$(dir $@)) build-dir = $(or $(__build-dir),.) -prepare: $(OUTPUT)PERF-VERSION-FILE archheaders \ +prepare: $(OUTPUT)PERF-VERSION-FILE \ arm64-sysreg-defs \ $(LIBAPI) \ $(LIBPERF) \
@@ -1070,7 +1070,7 @@ FORCE: .PHONY: all install clean config-clean strip install-gtk .PHONY: shell_compatibility_test please_set_SHELL_PATH_to_a_more_modern_shell .PHONY: .FORCE-PERF-VERSION-FILE TAGS tags cscope FORCE prepare -.PHONY: archheaders python_perf_target +.PHONY: python_perf_target endif # force_fixdep
Signature · 1 line
2.54.0.563.g4f69b47b94-goog
Ian Rogers
reviewerPATCH v5 5/14 perf build: Move BPF skeleton generation out of Makefile.perf
In reply to Ian RogersCurrently, the top-level Makefile.perf defines a massive global bpf-skel umbrella target that pre-compiles all 12+ BPF skeletons (%.skel.h) upfront before launching sub-makes. This forces unrelated sub-makes to serialize behind bpftool and clang BPF target evaluations, causing parallel build bottlenecks.
Furthermore, bench_uprobe.bpf.c lived inside util/bpf_skel/, breaking conceptual directory encapsulation since it is consumed purely by bench/uprobe.c.
Refactor the BPF skeletons to better achieve directory isolation:
1. Move tools/perf/util/bpf_skel/bench_uprobe.bpf.c directly into tools/perf/bench/bpf_skel/.
2. Extract the skeleton generation infrastructure out of Makefile.perf into a shared inclusion file tools/perf/bpf_skel.mak.
3. Include bpf_skel.mak locally inside tools/perf/util/Build and tools/perf/bench/Build and bind precise local prerequisites.
4. Safely synchronize the shared bpftool bootstrap and vmlinux.h targets via the conditional prepare: umbrella to avoid parallel sub-make races, while evaluating the actual skeletons completely locally on demand. A later patch will move these targets into bpf_skel.mak.
5. Export CLANG from the global Makefile to ensure accurate tool propagation.
6. Clean up Makefile.perf by stripping the global bpf-skel umbrella target and its SKELETONS list.
While removing code from Makefile.perf generally helps build performance, the impact here is minimal. The main motivation for the change is to better encapsulate things in the build and simplify Makefile.perf that has around 50 lines removed.
---
tools/perf/Makefile.perf | 59 ++-----------------
tools/perf/bench/Build | 6 ++
.../bpf_skel/bench_uprobe.bpf.c | 0
tools/perf/bench/uprobe.c | 2 +-
tools/perf/bpf_skel.mak | 54 +++++++++++++++++
tools/perf/util/Build | 15 ++++-
6 files changed, 79 insertions(+), 57 deletions(-)
rename tools/perf/{util => bench}/bpf_skel/bench_uprobe.bpf.c (100%)
create mode 100644 tools/perf/bpf_skel.maktools/perf/Makefile.perf +4 -55
@@ -274,7 +274,7 @@ ifeq ($(PYLINT),1) PYLINT := $(shell which pylint 2> /dev/null) endif -export srctree OUTPUT RM CC CXX RUSTC LD AR CFLAGS CXXFLAGS RUST_FLAGS V BISON FLEX AWK +export srctree OUTPUT RM CC CXX RUSTC CLANG LD AR CFLAGS CXXFLAGS RUST_FLAGS V BISON FLEX AWK LIBBPF export HOSTCC HOSTLD HOSTAR HOSTCFLAGS SHELLCHECK MYPY PYLINT include $(srctree)/tools/build/Makefile.include
@@ -632,8 +632,7 @@ prepare: $(OUTPUT)PERF-VERSION-FILE \ $(LIBAPI) \ $(LIBPERF) \ $(LIBSUBCMD) \ - $(LIBSYMBOL) \ - bpf-skel + $(LIBSYMBOL) ifdef LIBBPF_STATIC prepare: $(LIBBPF)
@@ -914,44 +913,13 @@ python-clean: SKEL_OUT := $(abspath $(OUTPUT)util/bpf_skel) SKEL_TMP_OUT := $(abspath $(SKEL_OUT)/.tmp) -SKELETONS := $(SKEL_OUT)/bpf_prog_profiler.skel.h -SKELETONS += $(SKEL_OUT)/bperf_leader.skel.h $(SKEL_OUT)/bperf_follower.skel.h -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_OUT)/sample_filter.skel.h -SKELETONS += $(SKEL_OUT)/kwork_top.skel.h $(SKEL_OUT)/syscall_summary.skel.h -SKELETONS += $(SKEL_OUT)/bench_uprobe.skel.h -SKELETONS += $(SKEL_OUT)/augmented_raw_syscalls.skel.h $(SKEL_TMP_OUT) $(LIBAPI_OUTPUT) $(LIBBPF_OUTPUT) $(LIBPERF_OUTPUT) $(LIBSUBCMD_OUTPUT) $(LIBSYMBOL_OUTPUT): $(Q)$(MKDIR) -p $@ ifeq ($(CONFIG_PERF_BPF_SKEL),y) +prepare: $(BPFTOOL) $(SKEL_OUT)/vmlinux.h BPFTOOL := $(SKEL_TMP_OUT)/bootstrap/bpftool -# Get Clang's default includes on this system, as opposed to those seen by -# '--target=bpf'. This fixes "missing" files on some architectures/distros, -# such as asm/byteorder.h, asm/socket.h, asm/sockios.h, sys/cdefs.h etc. -# -# Use '-idirafter': Don't interfere with include mechanics except where the -# build would have failed anyways. -define get_sys_includes -$(shell $(1) $(2) -v -E - </dev/null 2>&1 \ - | sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }') \ -$(shell $(1) $(2) -dM -E - </dev/null | grep '__riscv_xlen ' | awk '{printf("-D__riscv_xlen=%d -D__BITS_PER_LONG=%d", $$3, $$3)}') -endef - -ifneq ($(CROSS_COMPILE),) -CLANG_TARGET_ARCH = --target=$(notdir $(CROSS_COMPILE:%-=%)) -endif - -CLANG_OPTIONS = -Wall -CLANG_SYS_INCLUDES = $(call get_sys_includes,$(CLANG),$(CLANG_TARGET_ARCH)) -BPF_INCLUDE := -I$(SKEL_TMP_OUT)/.. -I$(LIBBPF_INCLUDE) $(CLANG_SYS_INCLUDES) -TOOLS_UAPI_INCLUDE := -I$(srctree)/tools/include/uapi - -ifneq ($(WERROR),0) - CLANG_OPTIONS += -Werror -endif $(BPFTOOL): | $(SKEL_TMP_OUT) $(Q)CFLAGS= $(MAKE) -C ../bpf/bpftool \
@@ -993,29 +961,10 @@ else $(Q)cp "$(VMLINUX_H)" $@ endif -$(SKEL_TMP_OUT)/%.bpf.o: $(OUTPUT)PERF-VERSION-FILE util/bpf_skel/perf_version.h | $(SKEL_TMP_OUT) -$(SKEL_TMP_OUT)/%.bpf.o: util/bpf_skel/%.bpf.c $(LIBBPF) $(SKEL_OUT)/vmlinux.h - $(QUIET_CLANG)$(CLANG) -g -O2 -fno-stack-protector --target=bpf \ - $(CLANG_OPTIONS) $(EXTRA_BPF_FLAGS) $(BPF_INCLUDE) $(TOOLS_UAPI_INCLUDE) \ - -include $(OUTPUT)PERF-VERSION-FILE -include util/bpf_skel/perf_version.h \ - -fms-extensions -Wno-microsoft-anon-tag \ - -c $(filter util/bpf_skel/%.bpf.c,$^) -o $@ - -$(SKEL_OUT)/%.skel.h: $(SKEL_TMP_OUT)/%.bpf.o | $(BPFTOOL) - $(QUIET_GENSKEL)$(BPFTOOL) gen skeleton $< > $@ - -bpf-skel: $(SKELETONS) - -.PRECIOUS: $(SKEL_TMP_OUT)/%.bpf.o - -else # CONFIG_PERF_BPF_SKEL - -bpf-skel: - endif # CONFIG_PERF_BPF_SKEL bpf-skel-clean: - $(call QUIET_CLEAN, bpf-skel) $(RM) -r $(SKEL_TMP_OUT) $(SKELETONS) $(SKEL_OUT)/vmlinux.h + $(call QUIET_CLEAN, bpf-skel) $(RM) -r $(SKEL_TMP_OUT) $(SKEL_OUT)/*.skel.h $(SKEL_OUT)/vmlinux.h $(OUTPUT)bench/bpf_skel/*.skel.h $(OUTPUT)bench/bpf_skel/.tmp pmu-events-clean: ifeq ($(OUTPUT),)
tools/perf/bench/Build +6 -0
@@ -24,3 +24,9 @@ perf-bench-$(CONFIG_X86_64) += mem-memcpy-x86-64-asm.o perf-bench-$(CONFIG_X86_64) += mem-memset-x86-64-asm.o perf-bench-$(CONFIG_NUMA) += numa.o + +ifeq ($(CONFIG_PERF_BPF_SKEL),y) +include $(srctree)/tools/perf/bpf_skel.mak + +$(OUTPUT)bench/uprobe.o: $(SKEL_OUT)/bench_uprobe.skel.h +endif
tools/perf/bench/bpf_skel/bench_uprobe.bpf.c renamed from tools/perf/util/bpf_skel/bench_uprobe.bpf.c +0 -0
tools/perf/bench/uprobe.c +1 -1
@@ -44,7 +44,7 @@ static const char * const bench_uprobe_usage[] = { };#ifdef HAVE_BPF_SKEL -#include "bpf_skel/bench_uprobe.skel.h" +#include "bench/bpf_skel/bench_uprobe.skel.h" #define bench_uprobe__attach_uprobe(prog) \ skel->links.prog = bpf_program__attach_uprobe_opts(/*prog=*/skel->progs.prog, \
tools/perf/bpf_skel.mak new file +54 -0
54 lines not on this page · raw message
tools/perf/util/Build +14 -1
@@ -442,4 +442,17 @@ $(OUTPUT)%.pylint_log: % perf-util-y += $(PYLINT_TEST_LOGS) - +ifeq ($(CONFIG_PERF_BPF_SKEL),y) +include $(srctree)/tools/perf/bpf_skel.mak + +$(OUTPUT)util/bpf_ftrace.o: $(SKEL_OUT)/func_latency.skel.h +$(OUTPUT)util/bpf-filter.o: $(SKEL_OUT)/sample_filter.skel.h +$(OUTPUT)util/bpf_kwork_top.o: $(SKEL_OUT)/kwork_top.skel.h +$(OUTPUT)util/bpf_off_cpu.o: $(SKEL_OUT)/off_cpu.skel.h +$(OUTPUT)util/bpf-trace-summary.o: $(SKEL_OUT)/syscall_summary.skel.h +$(OUTPUT)util/bpf_counter_cgroup.o: $(SKEL_OUT)/bperf_cgroup.skel.h +$(OUTPUT)util/bpf_trace_augment.o: $(SKEL_OUT)/augmented_raw_syscalls.skel.h +$(OUTPUT)util/bpf_counter.o: $(SKEL_OUT)/bpf_prog_profiler.skel.h $(SKEL_OUT)/bperf_leader.skel.h $(SKEL_OUT)/bperf_follower.skel.h +$(OUTPUT)util/bpf_lock_contention.o: $(SKEL_OUT)/lock_contention.skel.h +$(OUTPUT)util/bpf_kwork.o: $(SKEL_OUT)/kwork_trace.skel.h +endif
Signature · 1 line
2.54.0.563.g4f69b47b94-goog
Ian Rogers
reviewerPATCH v5 6/14 perf build: Encapsulate vmlinux.h and bpftool in bpf_skel.mak
In reply to Ian RogersCurrently, bpftool and vmlinux.h are prerequisites of the top-level prepare target in Makefile.perf. This unnecessarily blocks the massive parallel C compilation of libraries (perf-util, perf-ui, pmu-events) during the initial startup phase.
Move all bpftool and vmlinux.h generation rules down into tools/perf/bpf_skel.mak to encapsulate BPF tooling completely within the skeleton framework. Remove them entirely from prepare to unblock immediate parallel build execution.
To prevent parallel sub-makes (perf-util and perf-bench) from racing to build shared prerequisites concurrently, while maintaining strict directory encapsulation without top-level inclusions, serialize bench after the util static archive finishes using an order-only prerequisite:
$(LIBPERF_BENCH_IN): FORCE prepare | $(LIBPERF_UTIL)
--- tools/perf/Makefile.config | 2 +- tools/perf/Makefile.perf | 61 +++++--------------------------------- tools/perf/bpf_skel.mak | 47 +++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 55 deletions(-)
tools/perf/Makefile.config +1 -1
@@ -736,7 +736,7 @@ ifeq ($(BUILD_BPF_SKEL),1) endif ifndef GEN_VMLINUX_H - VMLINUX_H=$(src-perf)/util/bpf_skel/vmlinux/vmlinux.h + VMLINUX_H_FILE=$(src-perf)/util/bpf_skel/vmlinux/vmlinux.h endif dwarf-post-unwind := 1
tools/perf/Makefile.perf +7 -54
88 lines not on this page · raw message
tools/perf/bpf_skel.mak +47 -0
57 lines not on this page · raw message
Signature · 1 line
2.54.0.563.g4f69b47b94-goog
Ian Rogers
reviewerPATCH v5 7/14 perf build: Pre-generate BPF skeleton tooling during umbrella prepare phase
In reply to Ian RogersCurrently, BPF skeleton generation rules (bpf_skel.mak) are evaluated as part of util/Build. However, because LIBPERF_UTIL_IN explicitly depends on the top-level static libbpf archive, Make completely blocked the execution of bpftool bootstrap and skeleton generation until libbpf finished compiling midway through the build.
Since bpftool bootstrap compiles its own independent copy of libbpf.a, it does not depend on the top-level libbpf target.
Decouple early skeleton tooling generation by attaching bpf-skel-prepare to the umbrella prepare target, exporting CONFIG_PERF_BPF_SKEL to ensure accurate feature propagation. This allows Make to compile bpftool and dump vmlinux.h in the background at build startup, eliminating the initial sub-make startup bottleneck before BPF object compilation while keeping 100% of tooling rules perfectly encapsulated in bpf_skel.mak. Provide an empty fallback target to ensure builds succeed when BPF skeletons are disabled.
--- tools/perf/Makefile.perf | 8 ++++++-- tools/perf/bpf_skel.mak | 8 ++++++++ 2 files changed, 14 insertions(+), 2 deletions(-)
tools/perf/Makefile.perf +6 -2
@@ -275,7 +275,7 @@ ifeq ($(PYLINT),1) endif export srctree OUTPUT RM CC CXX RUSTC CLANG LD AR CFLAGS CXXFLAGS RUST_FLAGS V BISON FLEX AWK LIBBPF READELF -export HOSTCC HOSTLD HOSTAR HOSTCFLAGS SHELLCHECK MYPY PYLINT +export HOSTCC HOSTLD HOSTAR HOSTCFLAGS SHELLCHECK MYPY PYLINT CONFIG_PERF_BPF_SKEL include $(srctree)/tools/build/Makefile.include
@@ -629,8 +629,12 @@ endif __build-dir = $(subst $(OUTPUT),,$(dir $@)) build-dir = $(or $(__build-dir),.) +bpf-skel-prepare: + $(Q)$(MAKE) -f bpf_skel.mak bpf-skel-prepare + prepare: $(OUTPUT)PERF-VERSION-FILE \ arm64-sysreg-defs \ + bpf-skel-prepare \ $(LIBAPI) \ $(LIBPERF) \ $(LIBSUBCMD) \
@@ -971,7 +975,7 @@ FORCE: .PHONY: all install clean config-clean strip install-gtk .PHONY: shell_compatibility_test please_set_SHELL_PATH_to_a_more_modern_shell -.PHONY: .FORCE-PERF-VERSION-FILE TAGS tags cscope FORCE prepare +.PHONY: .FORCE-PERF-VERSION-FILE TAGS tags cscope FORCE prepare bpf-skel-prepare .PHONY: python_perf_target endif # force_fixdep
tools/perf/bpf_skel.mak +8 -0
@@ -15,6 +15,10 @@ ifeq ($(CONFIG_PERF_BPF_SKEL),y) BPFTOOL := $(SKEL_TOOL_TMP_OUT)/bootstrap/bpftool VMLINUX_H := $(SKEL_TOOL_OUT)/vmlinux.h +.PHONY: bpf-skel-prepare +bpf-skel-prepare: $(BPFTOOL) $(VMLINUX_H) + @: + define get_sys_includes $(shell $(1) $(2) -v -E - </dev/null 2>&1 \ | sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }') \
@@ -93,6 +97,10 @@ $(SKEL_OUT)/%.skel.h: $(SKEL_TMP_OUT)/%.bpf.o $(BPFTOOL) .PRECIOUS: $(SKEL_TMP_OUT)/%.bpf.o +else # CONFIG_PERF_BPF_SKEL +.PHONY: bpf-skel-prepare +bpf-skel-prepare: + @: endif # CONFIG_PERF_BPF_SKEL clean:
Signature · 1 line
2.54.0.563.g4f69b47b94-goog
Ian Rogers
reviewerPATCH v5 8/14 perf build: Move libsymbol dependency out of prepare step
In reply to Ian RogersThe prepare step is a large serialization point before parallel sub-makes build the perf tool. The libsymbol headers are used in the bench and util libraries. Move the libsymbol dependency out of the prepare step and into the dependencies for those targets to avoid it being a source of serialization in the prepare step.
--- tools/perf/Makefile.perf | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
tools/perf/Makefile.perf +3 -4
@@ -558,7 +558,7 @@ $(LIBPMU_EVENTS): $(LIBPMU_EVENTS_IN) # The $(LIBPERF_UTIL) dependency is to ensure bpftool and vmlinux.h # aren't racily built for bench/bpf_skel/bench_uprobe.bpf.c -$(LIBPERF_BENCH_IN): FORCE prepare | $(LIBPERF_UTIL) +$(LIBPERF_BENCH_IN): FORCE prepare $(LIBSYMBOL) | $(LIBPERF_UTIL) $(Q)$(MAKE) $(build)=perf-bench $(LIBPERF_BENCH): $(LIBPERF_BENCH_IN)
@@ -576,7 +576,7 @@ $(LIBPERF_UI_IN): FORCE prepare $(LIBPERF_UI): $(LIBPERF_UI_IN) $(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $< -$(LIBPERF_UTIL_IN): FORCE prepare +$(LIBPERF_UTIL_IN): FORCE prepare $(LIBSYMBOL) $(Q)$(MAKE) $(build)=perf-util $(LIBPERF_UTIL): $(LIBPERF_UTIL_IN)
@@ -637,8 +637,7 @@ prepare: $(OUTPUT)PERF-VERSION-FILE \ bpf-skel-prepare \ $(LIBAPI) \ $(LIBPERF) \ - $(LIBSUBCMD) \ - $(LIBSYMBOL) + $(LIBSUBCMD) ifdef LIBBPF_STATIC prepare: $(LIBBPF)
Signature · 1 line
2.54.0.563.g4f69b47b94-goog
[email protected]
AI reviewRe: [PATCH v5 08/14] perf build: Move libsymbol dependency out of prepare step
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] Removing `$(LIBSYMBOL)` from the `prepare` step breaks the `make check` target and manual object…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] Removing $(LIBSYMBOL) from the prepare step breaks the make check target and manual object file compilation (e.g., make util/symbol.o). --
commit 6df47358116c567d6b28b1ca848835d2f69dc679
Author: Ian Rogers <[email protected]>
perf build: Move libsymbol dependency out of prepare step
This commit moves the libsymbol dependency out of the prepare step and into the dependencies for the bench and util libraries to reduce serialization during the build.
Quoted 4 lines
tools/perf/Makefile.perf +0
-0
[ ... ]
tools/perf/Makefile.perf prepare: $(OUTPUT)PERF-VERSION-FILE \ · line 640
Quoted 7 lines
tools/perf/Makefile.perf +1
-2@@ -637,8 +637,7 @@ prepare: $(OUTPUT)PERF-VERSION-FILE \ bpf-skel-prepare \ $(LIBAPI) \ $(LIBPERF) \ - $(LIBSUBCMD) \ - $(LIBSYMBOL) + $(LIBSUBCMD)
Could removing $(LIBSYMBOL) from the prepare step introduce a regression for the make check target and manual object file compilation?
Both the make check target and the generic object fallback rules, such as make util/symbol.o, depend exclusively on the prepare target:
check: prepare
if sparse; \
...
$(OUTPUT)%.o: %.c prepare FORCE
$(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=$(build-dir) $@
Previously, prepare triggered the $(LIBSYMBOL) target, which installed required libsymbol headers like <symbol/kallsyms.h>.
By removing this dependency, are we no longer guaranteed to have the necessary headers installed when running make check or manually building object files from a clean tree?
It appears this could cause them to fail with a 'No such file or directory' error when processing files that include libsymbol headers.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
Ian Rogers
reviewerRe: [PATCH v5 08/14] perf build: Move libsymbol dependency out of prepare step
Quoted 45 lines · On Fri, May 15, 2026 at 12:53 PM <[email protected]> wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] Removing$(LIBSYMBOL)from thepreparestep breaks themake checktarget and manual object file compilation (e.g.,make util/symbol.o). --commit
6df47358116c567d6b28b1ca848835d2f69dc679
Author: Ian Rogers <[email protected]>perf build: Move libsymbol dependency out of prepare step
This commit moves the libsymbol dependency out of the prepare step and into the dependencies for the bench and util libraries to reduce serialization during the build.
Quoted 4 lines
tools/perf/Makefile.perf +0
-0[ ... ]
tools/perf/Makefile.perf prepare: $(OUTPUT)PERF-VERSION-FILE \ · line 640
Quoted 7 lines
tools/perf/Makefile.perf +1
-2@@ -637,8 +637,7 @@ prepare: $(OUTPUT)PERF-VERSION-FILE \ bpf-skel-prepare \ $(LIBAPI) \ $(LIBPERF) \ - $(LIBSUBCMD) \ - $(LIBSYMBOL) + $(LIBSUBCMD)Could removing $(LIBSYMBOL) from the prepare step introduce a regression for the make check target and manual object file compilation?
Both the make check target and the generic object fallback rules, such as make
util/symbol.o, depend exclusively on the prepare target:check: prepare
if sparse; \...
$(OUTPUT)%.o: %.c prepare FORCE
$(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=$(build-dir) $@Previously, prepare triggered the $(LIBSYMBOL) target, which installed required libsymbol headers like <
symbol/kallsyms.h>.
Quoted 6 lines
By removing this dependency, are we no longer guaranteed to have the necessary headers installed when running make check or manually building object files from a clean tree?
It appears this could cause them to fail with a 'No such file or directory' error when processing files that include libsymbol headers.
It would, so the user shouldn't do this, they should just use regular targets like "all" or build these targets incrementally after running an "all" build. Putting the target on these rules would be equivalent to putting it back in the prepare step.
Thanks,
Ian
Quoted 2 lines
--
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
Ian Rogers
reviewerPATCH v5 9/14 perf build: Remove redundant libbpf feature check for static builds
In reply to Ian RogersBy default, the perf tool compiles and statically links against its own internal copy of libbpf (tools/lib/bpf/libbpf.a), setting LIBBPF_STATIC=1.
Despite this static linkage, Makefile.config unconditionally executed $(call feature_check,libbpf), which forced a synchronous sub-make fork during AST parsing to detect dynamic system libbpf libraries.
As noted in the internal Makefile comments, this check was executed purely so that running make VF=1 would display the detection status of system libbpf. During standard builds without LIBBPF_DYNAMIC=1, the detection result was entirely ignored.
Wrap the libbpf feature check inside LIBBPF_DYNAMIC=1 so Make avoids the redundant sub-make fork overhead during standard static builds.
--- tools/perf/Makefile.config | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
tools/perf/Makefile.config +1 -3
@@ -587,10 +587,8 @@ ifndef NO_LIBELF ifndef NO_LIBBPF ifeq ($(feature-bpf), 1) - # detecting libbpf without LIBBPF_DYNAMIC, so make VF=1 shows libbpf detection status - $(call feature_check,libbpf) - ifdef LIBBPF_DYNAMIC + $(call feature_check,libbpf) ifeq ($(feature-libbpf), 1) EXTLIBS += -lbpf CFLAGS += -DHAVE_LIBBPF_SUPPORT
Signature · 1 line
2.54.0.563.g4f69b47b94-goog
Ian Rogers
reviewerPATCH v5 10/14 perf pmu-events: Split big_c_string storage into standalone compilation unit
In reply to Ian RogersCurrently, jevents.py emits both the massive 2.8 MB big_c_string literal and tens of thousands of compact_pmu_event struct arrays into a single pmu-events.c compilation unit. Compiling this giant file takes ~2.2 seconds on a single CPU core during Kbuild startup.
Refactor jevents.py to emit big_c_string into a dedicated pmu-events-string.c compilation unit. This allows Kbuild to compile pmu-events.o and pmu-events-string.o simultaneously in parallel across two separate CPU cores, preserving 100% string deduplication and zero dynamic ELF relocations while cutting C compilation latency in half.
Add pmu-events-string.c to tools/perf/.gitignore to ensure in-tree Kbuild runs do not leave untracked generated files in the working directory.
To guarantee 100% backward compatibility with GNU Make 4.0+ (avoiding the Make 4.3+ grouped target &: syntax which causes older Make versions like 4.2.1 to spawn multiple concurrent jevents.py processes during parallel builds), implement a robust dependency chaining pattern:
$(PMU_EVENTS_C): $(JEVENTS_DEPS)
$(PMU_EVENTS_STRING_C): $(PMU_EVENTS_C)
@:
This ensures jevents.py is invoked exactly once. If jevents.py aborts early, Make's .DELETE_ON_ERROR: purges pmu-events.c, guaranteeing that subsequent Make invocations correctly re-execute the script and overwrite pmu-events-string.c. In jevents.py, defer closing output_string_file until the absolute tail of main() to guarantee identical modification timestamps with output_file, preventing redundant rebuilds during incremental runs.
--- tools/perf/.gitignore | 1 + tools/perf/Makefile.perf | 4 ++-- tools/perf/pmu-events/Build | 16 +++++++++++++++- tools/perf/pmu-events/jevents.py | 22 ++++++++++++++++++---- 4 files changed, 36 insertions(+), 7 deletions(-)
tools/perf/.gitignore +1 -0
@@ -38,6 +38,7 @@ arch/*/include/generated/ trace/beauty/generated/ pmu-events/arch/common/common/legacy-cache.json pmu-events/pmu-events.c +pmu-events/pmu-events-string.c pmu-events/jevents pmu-events/metric_test.log pmu-events/empty-pmu-events.log
tools/perf/Makefile.perf +2 -2
@@ -925,7 +925,7 @@ bpf-skel-clean: pmu-events-clean: ifeq ($(OUTPUT),) $(call QUIET_CLEAN, pmu-events) $(RM) \ - pmu-events/pmu-events.c \ + pmu-events/pmu-events*.c \ pmu-events/metric_test.log \ pmu-events/test-empty-pmu-events.c \ pmu-events/empty-pmu-events.log
@@ -933,7 +933,7 @@ ifeq ($(OUTPUT),) -name 'extra-metricgroups.json' -delete else # When an OUTPUT directory is present, clean up the copied pmu-events/arch directory. $(call QUIET_CLEAN, pmu-events) $(RM) -r $(OUTPUT)pmu-events/arch \ - $(OUTPUT)pmu-events/pmu-events.c \ + $(OUTPUT)pmu-events/pmu-events*.c \ $(OUTPUT)pmu-events/metric_test.log \ $(OUTPUT)pmu-events/test-empty-pmu-events.c \ $(OUTPUT)pmu-events/empty-pmu-events.log
tools/perf/pmu-events/Build +15 -1
@@ -1,7 +1,12 @@ EMPTY_PMU_EVENTS_C = pmu-events/empty-pmu-events.c # pmu-events.c will be generated by jevents.py or copied from EMPTY_PMU_EVENTS_C PMU_EVENTS_C = $(OUTPUT)pmu-events/pmu-events.c +PMU_EVENTS_STRING_C = $(OUTPUT)pmu-events/pmu-events-string.c + pmu-events-y += pmu-events.o +ifneq ($(NO_JEVENTS),1) +pmu-events-y += pmu-events-string.o +endif # pmu-events.c file is generated in the OUTPUT directory so it needs a # separate rule to depend on it properly
@@ -9,6 +14,10 @@ $(OUTPUT)pmu-events/pmu-events.o: $(PMU_EVENTS_C) $(call rule_mkdir) $(call if_changed_dep,cc_o_c) +$(OUTPUT)pmu-events/pmu-events-string.o: $(PMU_EVENTS_STRING_C) + $(call rule_mkdir) + $(call if_changed_dep,cc_o_c) + # Message for $(call echo-cmd,cp), possibly remove the src file from # the destination to save space in the build log. quiet_cmd_cp = COPY $(patsubst %$<,%,$@) <- $<
@@ -118,6 +127,7 @@ CUR_OUT_JSON := $(shell [ -d $(OUT_DIR) ] && find $(OUT_DIR) -type f) # Things in the OUTPUT directory but shouldn't be there as computed by # OUT_JSON and GEN_JSON. + ORPHAN_FILES := $(filter-out $(OUT_JSON) $(GEN_JSON),$(CUR_OUT_JSON)) # Message for $(call echo-cmd,mkd). There is already a mkdir message
@@ -224,6 +234,10 @@ endif # and inputs are dependencies. $(PMU_EVENTS_C): $(JEVENTS_DEPS) $(call rule_mkdir) - $(Q)$(call echo-cmd,gen)$(PYTHON) $(JEVENTS_PY) $(JEVENTS_ARCH) $(JEVENTS_MODEL) $(OUT_DIR) $@ + $(Q)$(call echo-cmd,gen)$(PYTHON) $(JEVENTS_PY) $(JEVENTS_ARCH) $(JEVENTS_MODEL) \ + $(OUT_DIR) $(PMU_EVENTS_C) $(PMU_EVENTS_STRING_C) + +$(PMU_EVENTS_STRING_C): $(PMU_EVENTS_C) + @: endif # ifeq ($(NO_JEVENTS),1)
tools/perf/pmu-events/jevents.py +18 -4
@@ -1422,6 +1422,8 @@ such as "arm/cortex-a34".''', ) ap.add_argument( 'output_file', type=argparse.FileType('w', encoding='utf-8'), nargs='?', default=sys.stdout) + ap.add_argument( + 'output_string_file', type=argparse.FileType('w', encoding='utf-8'), nargs='?', default=None) _args = ap.parse_args() _args.output_file.write(f"""
@@ -1463,10 +1465,20 @@ struct pmu_table_entry { ftw(arch_path, [], preprocess_one_file) _bcs.compute() - _args.output_file.write('static const char *const big_c_string =\n') - for s in _bcs.big_string: - _args.output_file.write(s) - _args.output_file.write(';\n\n') + if not _args.output_string_file: + _args.output_file.write('static const char *const big_c_string =\n') + for s in _bcs.big_string: + _args.output_file.write(s) + _args.output_file.write(';\n\n') + else: + _args.output_string_file.write('/* SPDX-License-Identifier: GPL-2.0 */\n') + _args.output_string_file.write('/* Autogenerated by jevents.py */\n') + _args.output_string_file.write('extern const char big_c_string[];\n') + _args.output_string_file.write('const char big_c_string[] =\n') + for s in _bcs.big_string: + _args.output_string_file.write(s) + _args.output_string_file.write(';\n') + _args.output_file.write('extern const char big_c_string[];\n\n') for arch in archs: arch_path = f'{_args.starting_dir}/{arch}' ftw(arch_path, [], process_one_file)
@@ -1476,6 +1488,8 @@ struct pmu_table_entry { print_mapping_table(archs) print_system_mapping_table() print_metricgroups() + if _args.output_string_file: + _args.output_string_file.close() if __name__ == '__main__': main()
Signature · 1 line
2.54.0.563.g4f69b47b94-goog
[email protected]
AI reviewRe: [PATCH v5 10/14] perf pmu-events: Split big_c_string storage into standalone compilation unit
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] Incremental build breakage and partial clean failure due to Makefile dependency chaining and…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Incremental build breakage and partial clean failure due to Makefile dependency chaining and Python file closing order. --
commit 6c014984ddc9092cbb7ef975a3904baefa427ed5
Author: Ian Rogers <[email protected]>
perf pmu-events: Split big_c_string storage into standalone compilation unit
This commit splits the large big_c_string literal into a dedicated pmu-events-string.c file to allow parallel compilation during Kbuild. It updates jevents.py to output both files and adjusts the Makefile dependencies to ensure jevents.py is only executed once.
Quoted 3 lines
In
jevents.py, defer closingoutput_string_fileuntil
the absolute tail ofmain()to guarantee identical modification timestamps withoutput_file, preventing redundant rebuilds during incremental runs.
Is this guarantee accurate? Since output_file is never explicitly closed in main(), it gets flushed and closed automatically during Python interpreter shutdown, strictly after main() returns.
Will this result in pmu-events.c having a slightly newer modification timestamp than pmu-events-string.c on filesystems with nanosecond resolution?
Quoted 3 lines
tools/perf/pmu-events/Build +0
-0
[ ... ]
tools/perf/pmu-events/Build endif · line 241
Quoted 10 lines
tools/perf/pmu-events/Build +5
-1@@ -224,6 +234,10 @@ endif # and inputs are dependencies. $(PMU_EVENTS_C): $(JEVENTS_DEPS) $(call rule_mkdir) - $(Q)$(call echo-cmd,gen)$(PYTHON) $(JEVENTS_PY) $(JEVENTS_ARCH) $(JEVENTS_MODEL) $(OUT_DIR) $@ + $(Q)$(call echo-cmd,gen)$(PYTHON) $(JEVENTS_PY) $(JEVENTS_ARCH) $(JEVENTS_MODEL) \ + $(OUT_DIR) $(PMU_EVENTS_C) $(PMU_EVENTS_STRING_C) + +$(PMU_EVENTS_STRING_C): $(PMU_EVENTS_C) + @:
If pmu-events.c consistently ends up newer than pmu-events-string.c due to the Python teardown order, won't Make permanently see pmu-events-string.c as out-of-date?
Could this silently trigger redundant recompilations of pmu-events-string.o and relinking of perf on every incremental build?
Additionally, if pmu-events-string.c is deleted while pmu-events.c remains up-to-date, Make will execute this dummy recipe and then attempt to compile a missing file. Does this pattern handle partial cleanups gracefully without creating a build regression?
Quoted 3 lines
tools/perf/pmu-events/jevents.py +0
-0
[ ... ]
tools/perf/pmu-events/jevents.py struct pmu_table_entry { · line 1495
Quoted 9 lines
tools/perf/pmu-events/jevents.py +2
-0@@ -1476,6 +1488,8 @@ struct pmu_table_entry { print_mapping_table(archs) print_system_mapping_table() print_metricgroups() + if _args.output_string_file: + _args.output_string_file.close() if __name__ == '__main__': main()
Should _args.output_file.close() be added here alongside output_string_file.close() to ensure their final filesystem writes happen simultaneously before interpreter shutdown?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=10
Ian Rogers
reviewerRe: [PATCH v5 10/14] perf pmu-events: Split big_c_string storage into standalone compilation unit
Quoted 19 lines · On Fri, May 15, 2026 at 12:58 PM <[email protected]> wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Incremental build breakage and partial clean failure due toMakefiledependency chaining and Python file closing order. --commit
6c014984ddc9092cbb7ef975a3904baefa427ed5
Author: Ian Rogers <[email protected]>perf pmu-events: Split
big_c_stringstorage into standalone compilation unitThis commit splits the large
big_c_stringliteral into a dedicatedpmu-events-string.cfile to allow parallel compilation duringKbuild. It updatesjevents.pyto output both files and adjusts theMakefiledependencies to ensurejevents.pyis only executed once.Quoted 3 lines
In
jevents.py, defer closingoutput_string_fileuntil
the absolute tail ofmain()to guarantee identical modification timestamps withoutput_file, preventing redundant rebuilds during incremental runs.
Quoted 7 lines
Is this guarantee accurate? Since
output_fileis never explicitly closed inmain(), it gets flushed and closed automatically during Python interpreter shutdown, strictly aftermain()returns.Will this result in
pmu-events.chaving a slightly newer modification timestamp thanpmu-events-string.con filesystems with nanosecond resolution?
So previously we were worried about the opposite scenario. Using &:
for a group of generated files solves the problem but Linux builds only require GNU make 4.0 not 4.3, which added this group construct. We may need to drop this change as I don't see a way to satisfy Sashiko.
Thanks,
Ian
Quoted 51 lines
Quoted 3 lines
tools/perf/pmu-events/Build +0
-0[ ... ]
tools/perf/pmu-events/Build endif · line 241
Quoted 10 lines
tools/perf/pmu-events/Build +5
-1@@ -224,6 +234,10 @@ endif # and inputs are dependencies. $(PMU_EVENTS_C): $(JEVENTS_DEPS) $(call rule_mkdir) - $(Q)$(call echo-cmd,gen)$(PYTHON) $(JEVENTS_PY) $(JEVENTS_ARCH) $(JEVENTS_MODEL) $(OUT_DIR) $@ + $(Q)$(call echo-cmd,gen)$(PYTHON) $(JEVENTS_PY) $(JEVENTS_ARCH) $(JEVENTS_MODEL) \ + $(OUT_DIR) $(PMU_EVENTS_C) $(PMU_EVENTS_STRING_C) + +$(PMU_EVENTS_STRING_C): $(PMU_EVENTS_C) + @:If
pmu-events.cconsistently ends up newer thanpmu-events-string.cdue to the Python teardown order, won't Make permanently seepmu-events-string.cas out-of-date?Could this silently trigger redundant recompilations of pmu-events-string.o and relinking of perf on every incremental build?
Additionally, if
pmu-events-string.cis deleted whilepmu-events.cremains up-to-date, Make will execute this dummy recipe and then attempt to compile a missing file. Does this pattern handle partial cleanups gracefully without creating a build regression?Quoted 3 lines
tools/perf/pmu-events/jevents.py +0
-0[ ... ]
tools/perf/pmu-events/jevents.py struct pmu_table_entry { · line 1495
Quoted 9 lines
tools/perf/pmu-events/jevents.py +2
-0@@ -1476,6 +1488,8 @@ struct pmu_table_entry { print_mapping_table(archs) print_system_mapping_table() print_metricgroups() + if _args.output_string_file: + _args.output_string_file.close() if __name__ == '__main__': main()Should
_args.output_file.close()be added here alongsideoutput_string_file.close()to ensure their final filesystem writes happen simultaneously before interpreter shutdown?--
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=10
Namhyung Kim
maintainerRe: [PATCH v5 10/14] perf pmu-events: Split big_c_string storage into standalone compilation unit
Quoted 28 lines · Ian Rogers
Quoted 19 lines · On Fri, May 15, 2026 at 12:58 PM <[email protected]> wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Incremental build breakage and partial clean failure due toMakefiledependency chaining and Python file closing order. --commit
6c014984ddc9092cbb7ef975a3904baefa427ed5
Author: Ian Rogers <[email protected]>perf pmu-events: Split
big_c_stringstorage into standalone compilation unitThis commit splits the large
big_c_stringliteral into a dedicatedpmu-events-string.cfile to allow parallel compilation duringKbuild. It updatesjevents.pyto output both files and adjusts theMakefiledependencies to ensurejevents.pyis only executed once.Quoted 3 lines
In
jevents.py, defer closingoutput_string_fileuntil
the absolute tail ofmain()to guarantee identical modification timestamps withoutput_file, preventing redundant rebuilds during incremental runs.Quoted 7 lines
Is this guarantee accurate? Since
output_fileis never explicitly closed inmain(), it gets flushed and closed automatically during Python interpreter shutdown, strictly aftermain()returns.Will this result in
pmu-events.chaving a slightly newer modification timestamp thanpmu-events-string.con filesystems with nanosecond resolution?
Quoted 5 lines
So previously we were worried about the opposite scenario. Using &:
for a group of generated files solves the problem but Linux builds only require GNU make 4.0 not 4.3, which added this group construct. We may need to drop this change as I don't see a way to satisfy Sashiko.
Isn't the message at the end a proposed solution by Sashiko to satisfy the problem? See below ...
Quoted 42 lines
Quoted 42 lines
Quoted 3 lines
tools/perf/pmu-events/Build +0
-0[ ... ]
tools/perf/pmu-events/Build endif · line 241
Quoted 10 lines
tools/perf/pmu-events/Build +5
-1@@ -224,6 +234,10 @@ endif # and inputs are dependencies. $(PMU_EVENTS_C): $(JEVENTS_DEPS) $(call rule_mkdir) - $(Q)$(call echo-cmd,gen)$(PYTHON) $(JEVENTS_PY) $(JEVENTS_ARCH) $(JEVENTS_MODEL) $(OUT_DIR) $@ + $(Q)$(call echo-cmd,gen)$(PYTHON) $(JEVENTS_PY) $(JEVENTS_ARCH) $(JEVENTS_MODEL) \ + $(OUT_DIR) $(PMU_EVENTS_C) $(PMU_EVENTS_STRING_C) + +$(PMU_EVENTS_STRING_C): $(PMU_EVENTS_C) + @:If
pmu-events.cconsistently ends up newer thanpmu-events-string.cdue to the Python teardown order, won't Make permanently seepmu-events-string.cas out-of-date?Could this silently trigger redundant recompilations of pmu-events-string.o and relinking of perf on every incremental build?
Additionally, if
pmu-events-string.cis deleted whilepmu-events.cremains up-to-date, Make will execute this dummy recipe and then attempt to compile a missing file. Does this pattern handle partial cleanups gracefully without creating a build regression?Quoted 3 lines
tools/perf/pmu-events/jevents.py +0
-0[ ... ]
Quoted 7 lines
tools/perf/pmu-events/jevents.py +2
-0@@ -1476,6 +1488,8 @@ struct pmu_table_entry { print_mapping_table(archs) print_system_mapping_table() print_metricgroups() + if _args.output_string_file: + _args.output_string_file.close()
Quoted 6 lines
Quoted 6 lines
tools/perf/pmu-events/jevents.py struct pmu_table_entry { · line 1495
Quoted 2 lines
tools/perf/pmu-events/jevents.py +0
-0if __name__ == '__main__': main()Should
_args.output_file.close()be added here alongsideoutput_string_file.close()to ensure their final filesystem writes happen simultaneously before interpreter shutdown?
... here. Or, maybe you can call os.utime().
Thanks,
Namhyung
Ian Rogers
reviewerRe: [PATCH v5 10/14] perf pmu-events: Split big_c_string storage into standalone compilation unit
Quoted 82 lines · Namhyung Kim
Quoted 28 lines · Ian Rogers
Quoted 19 lines · On Fri, May 15, 2026 at 12:58 PM <[email protected]> wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Incremental build breakage and partial clean failure due toMakefiledependency chaining and Python file closing order. --commit
6c014984ddc9092cbb7ef975a3904baefa427ed5
Author: Ian Rogers <[email protected]>perf pmu-events: Split
big_c_stringstorage into standalone compilation unitThis commit splits the large
big_c_stringliteral into a dedicatedpmu-events-string.cfile to allow parallel compilation duringKbuild. It updatesjevents.pyto output both files and adjusts theMakefiledependencies to ensurejevents.pyis only executed once.Quoted 3 lines
In
jevents.py, defer closingoutput_string_fileuntil
the absolute tail ofmain()to guarantee identical modification timestamps withoutput_file, preventing redundant rebuilds during incremental runs.Quoted 7 lines
Is this guarantee accurate? Since
output_fileis never explicitly closed inmain(), it gets flushed and closed automatically during Python interpreter shutdown, strictly aftermain()returns.Will this result in
pmu-events.chaving a slightly newer modification timestamp thanpmu-events-string.con filesystems with nanosecond resolution?Quoted 5 lines
So previously we were worried about the opposite scenario. Using &:
for a group of generated files solves the problem but Linux builds only require GNU make 4.0 not 4.3, which added this group construct. We may need to drop this change as I don't see a way to satisfy Sashiko.Isn't the message at the end a proposed solution by Sashiko to satisfy the problem? See below ...
Quoted 42 lines
Quoted 42 lines
Quoted 3 lines
tools/perf/pmu-events/Build +0
-0[ ... ]
tools/perf/pmu-events/Build endif · line 241
Quoted 10 lines
tools/perf/pmu-events/Build +5
-1@@ -224,6 +234,10 @@ endif # and inputs are dependencies. $(PMU_EVENTS_C): $(JEVENTS_DEPS) $(call rule_mkdir) - $(Q)$(call echo-cmd,gen)$(PYTHON) $(JEVENTS_PY) $(JEVENTS_ARCH) $(JEVENTS_MODEL) $(OUT_DIR) $@ + $(Q)$(call echo-cmd,gen)$(PYTHON) $(JEVENTS_PY) $(JEVENTS_ARCH) $(JEVENTS_MODEL) \ + $(OUT_DIR) $(PMU_EVENTS_C) $(PMU_EVENTS_STRING_C) + +$(PMU_EVENTS_STRING_C): $(PMU_EVENTS_C) + @:If
pmu-events.cconsistently ends up newer thanpmu-events-string.cdue to the Python teardown order, won't Make permanently seepmu-events-string.cas out-of-date?Could this silently trigger redundant recompilations of pmu-events-string.o and relinking of perf on every incremental build?
Additionally, if
pmu-events-string.cis deleted whilepmu-events.cremains up-to-date, Make will execute this dummy recipe and then attempt to compile a missing file. Does this pattern handle partial cleanups gracefully without creating a build regression?Quoted 3 lines
tools/perf/pmu-events/jevents.py +0
-0[ ... ]
Quoted 7 lines
tools/perf/pmu-events/jevents.py +2
-0@@ -1476,6 +1488,8 @@ struct pmu_table_entry { print_mapping_table(archs) print_system_mapping_table() print_metricgroups() + if _args.output_string_file: + _args.output_string_file.close()
Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
tools/perf/pmu-events/jevents.py struct pmu_table_entry { · line 1495
Quoted 2 lines
tools/perf/pmu-events/jevents.py +0
-0if __name__ == '__main__': main()Should
_args.output_file.close()be added here alongsideoutput_string_file.close()to ensure their final filesystem writes happen simultaneously before interpreter shutdown?... here. Or, maybe you can call
os.utime().
Let's give it a try.
Thanks,
Ian
Quoted 3 lines
Thanks,
Namhyung
Ian Rogers
reviewerPATCH v5 11/14 perf pmu-events: Parallelize JSON and metric pre-computation in jevents.py
In reply to Ian RogersCurrently, jevents.py parses hundreds of JSON event and metric files sequentially across all CPU architectures during Kbuild startup, taking ~3.3 seconds of pure single-core execution time.
Refactor jevents.py to pre-populate its internal JSON AST cache in parallel across all available CPU cores using ProcessPoolExecutor. Define the worker process initializer _init_worker at the top-level module scope to guarantee flawless pickling and standard event mapping inheritance under spawn multiprocessing semantics (avoiding AttributeError crashes when spawn is used instead of fork). This accelerates jevents.py execution by over 11x (from 3.3s down to ~290ms), fully reclaiming multi-core concurrency during the build generation phase.
--- tools/perf/pmu-events/jevents.py | 36 ++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-)
tools/perf/pmu-events/jevents.py +32 -4
@@ -457,8 +457,8 @@ class JsonEvent: return f'{{ { _bcs.offsets[s] } }}, /* {fix_comment(s)} */\n' -@lru_cache(maxsize=None) -def read_json_events(path: str, topic: str) -> Sequence[JsonEvent]: +_json_cache = {} +def _read_json_events_impl(path: str, topic: str) -> Sequence[JsonEvent]: """Read json events from the specified file.""" try: events = json.load(open(path), object_hook=JsonEvent)
@@ -474,12 +474,16 @@ def read_json_events(path: str, topic: str) -> Sequence[JsonEvent]: if updates: for event in events: if event.metric_name in updates: - # print(f'Updated {event.metric_name} from\n"{event.metric_expr}"\n' - # f'to\n"{updates[event.metric_name]}"') event.metric_expr = updates[event.metric_name] return events +def read_json_events(path: str, topic: str) -> Sequence[JsonEvent]: + key = (path, topic) + if key not in _json_cache: + _json_cache[key] = _read_json_events_impl(path, topic) + return _json_cache[key] + def preprocess_arch_std_files(archpath: str) -> None: """Read in all architecture standard events.""" global _arch_std_events
@@ -1381,6 +1385,14 @@ const char *describe_metricgroup(const char *group) } """) +def _parallel_read_json_events(task: Tuple[str, str]) -> Tuple[str, str, Sequence[JsonEvent]]: + path, topic = task + return path, topic, _read_json_events_impl(path, topic) + +def _init_worker(std_events: dict) -> None: + global _arch_std_events + _arch_std_events = std_events + def main() -> None: global _args
@@ -1459,9 +1471,25 @@ struct pmu_table_entry { raise IOError(f'Missing architecture directory \'{_args.arch}\'') archs.sort() + import concurrent.futures + tasks = [] + def collect_json(parents: Sequence[str], item: os.DirEntry) -> None: + if len(parents) == 0: + return + if item.is_file() and item.name.endswith('.json') and not item.name.endswith('metricgroups.json'): + tasks.append((item.path, get_topic(item.name))) + for arch in archs: arch_path = f'{_args.starting_dir}/{arch}' preprocess_arch_std_files(arch_path) + ftw(arch_path, [], collect_json) + + with concurrent.futures.ProcessPoolExecutor(initializer=_init_worker, initargs=(_arch_std_events,)) as executor: + for path, topic, events in executor.map(_parallel_read_json_events, tasks): + _json_cache[(path, topic)] = events + + for arch in archs: + arch_path = f'{_args.starting_dir}/{arch}' ftw(arch_path, [], preprocess_one_file) _bcs.compute()
Signature · 1 line
2.54.0.563.g4f69b47b94-goog
[email protected]
AI reviewRe: [PATCH v5 11/14] perf pmu-events: Parallelize JSON and metric pre-computation in jevents.py
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] Unconditional use of ProcessPoolExecutor bypasses the Kbuild jobserver limits, causing severe…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Unconditional use of ProcessPoolExecutor bypasses the Kbuild jobserver limits, causing severe CPU oversubscription during the build. --
commit 3ed526c623f5b05d6418cda5b990edc4c0a3a462
Author: Ian Rogers <[email protected]>
perf pmu-events: Parallelize JSON and metric pre-computation in jevents.py
This commit refactors jevents.py to use ProcessPoolExecutor to parse JSON event and metric files in parallel. This accelerates execution by caching the JSON AST across available CPU cores.
Quoted 4 lines
tools/perf/pmu-events/jevents.py +0
-0
[ ... ]
Quoted 8 lines
tools/perf/pmu-events/jevents.py +4
-0@@ -1459,9 +1471,25 @@ struct pmu_table_entry { raise IOError(f'Missing architecture directory \'{_args.arch}\'') archs.sort() + import concurrent.futures + tasks = [] + def collect_json(parents: Sequence[str], item: os.DirEntry) -> None: + if len(parents) == 0:
tools/perf/pmu-events/jevents.py struct pmu_table_entry { · line 1487
Quoted 10 lines
tools/perf/pmu-events/jevents.py +7
-0+ return + if item.is_file() and item.name.endswith('.json') and not item.name.endswith('metricgroups.json'): + tasks.append((item.path, get_topic(item.name))) + for arch in archs: arch_path = f'{_args.starting_dir}/{arch}' preprocess_arch_std_files(arch_path) + ftw(arch_path, [], collect_json) + + with concurrent.futures.ProcessPoolExecutor(initializer=_init_worker, initargs=(_arch_std_events,)) as executor:
Does this bypass the Kbuild jobserver limits?
By default, instantiating ProcessPoolExecutor without explicitly configuring max_workers will spawn os.cpu_count() child processes.
Since the kernel build system uses Make's jobserver to carefully coordinate parallelism across the tree, ignoring the user-specified resource limits (such as make -j8) could lead to massive process thrashing and potential out-of-memory conditions on high-core machines.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=11
Ian Rogers
reviewerPATCH v5 12/14 perf build: Prefix SCRIPTS with output directory to fix continuous rebuilds
In reply to Ian RogersIn Makefile.perf, ALL_PROGRAMS includes SCRIPTS (perf-archive, perf-iostat). However, unlike PROGRAMS and DLFILTERS, SCRIPTS was not prefixed with $(OUTPUT).
During out-of-tree builds (or when O= is specified), Make checked for the unprefixed target 'tools/perf/perf-archive'. Since the actual script was installed into $(OUTPUT)perf-archive, Make concluded the target was missing and continuously re-executed the script installation rule on every single incremental build.
Prefix SCRIPTS with $(OUTPUT) and update the static pattern rule to ensure Kbuild correctly tracks generated script prerequisites during incremental builds.
--- tools/perf/Makefile.perf | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
tools/perf/Makefile.perf +3 -3
@@ -405,7 +405,7 @@ python-clean := $(call QUIET_CLEAN, python) $(RM) -r $(PYTHON_EXTBUILD) $(OUTPUT # Use the detected configuration -include $(OUTPUT).config-detected -SCRIPTS = $(patsubst %.sh,%,$(SCRIPT_SH)) +SCRIPTS = $(addprefix $(OUTPUT),$(patsubst %.sh,%,$(SCRIPT_SH))) PROGRAMS += $(OUTPUT)perf
@@ -592,8 +592,8 @@ $(GTK_IN): FORCE prepare $(OUTPUT)libperf-gtk.so: $(GTK_IN) $(PERFLIBS) $(QUIET_LINK)$(CC) -o $@ -shared $(LDFLAGS) $(filter %.o,$^) $(GTK_LIBS) -$(SCRIPTS) : % : %.sh - $(QUIET_GEN)$(INSTALL) '[email protected]' '$(OUTPUT)$@' +$(SCRIPTS) : $(OUTPUT)% : %.sh + $(QUIET_GEN)$(INSTALL) '$<' '$@' $(OUTPUT)PERF-VERSION-FILE: .FORCE-PERF-VERSION-FILE $(Q)$(SHELL_PATH) util/PERF-VERSION-GEN $(OUTPUT)
Signature · 1 line
2.54.0.563.g4f69b47b94-goog
Ian Rogers
reviewerPATCH v5 13/14 perf pmu-events: Convert recursive shell assignments and macros to Make built-ins
In reply to Ian RogersIn pmu-events/Build, ZENS, ARMS, and INTELS were assigned using recursive assignment (=), and model_name/vendor_name were evaluated using shell macros (echo ... | sed ...).
Because these variables were expanded inside the COPY_RULE dependency evaluation loop across hundreds of PMU JSON files and inside every metric generation recipe, Kbuild continuously re-executed 'ls', 'grep', and 'sed' shell forks thousands of times during AST parsing and execution.
Convert ZENS, ARMS, and INTELS to simply expanded variables (:=) and replace model_name/vendor_name with pure GNU Make string functions. This guarantees Make executes directory probing shell forks exactly once when the Build file is parsed and evaluates path macros purely in memory, completely eliminating over 7,800 redundant sub-processes during build startup.
--- tools/perf/pmu-events/Build | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
tools/perf/pmu-events/Build +5 -5
@@ -56,12 +56,12 @@ $(LEGACY_CACHE_JSON): $(LEGACY_CACHE_PY) # Python to generate architectural metrics GEN_METRIC_DEPS := pmu-events/metric.py pmu-events/common_metrics.py # Functions to extract the model from an extra-metrics.json or extra-metricgroups.json path. -model_name = $(shell echo $(1)|sed -e 's@.\+/\(.*\)/extra-metric.*\.json@\1@') -vendor_name = $(shell echo $(1)|sed -e 's@.\+/\(.*\)/[^/]*/extra-metric.*\.json@\1@') +model_name = $(notdir $(patsubst %/,%,$(dir $(1)))) +vendor_name = $(notdir $(patsubst %/,%,$(dir $(patsubst %/,%,$(dir $(1)))))) ifeq ($(JEVENTS_ARCH),$(filter $(JEVENTS_ARCH),x86 all)) # Generate AMD Json -ZENS = $(shell ls -d pmu-events/arch/x86/amdzen*) +ZENS := $(shell ls -d pmu-events/arch/x86/amdzen*) ZEN_METRICS = $(foreach x,$(ZENS),$(OUTPUT)$(x)/extra-metrics.json) ZEN_METRICGROUPS = $(foreach x,$(ZENS),$(OUTPUT)$(x)/extra-metricgroups.json) GEN_JSON += $(ZEN_METRICS) $(ZEN_METRICGROUPS)
@@ -78,7 +78,7 @@ endif ifeq ($(JEVENTS_ARCH),$(filter $(JEVENTS_ARCH),arm64 all)) # Generate ARM Json -ARMS = $(shell ls -d pmu-events/arch/arm64/arm/*|grep -v cmn) +ARMS := $(shell ls -d pmu-events/arch/arm64/arm/*|grep -v cmn) ARM_METRICS = $(foreach x,$(ARMS),$(OUTPUT)$(x)/extra-metrics.json) ARM_METRICGROUPS = $(foreach x,$(ARMS),$(OUTPUT)$(x)/extra-metricgroups.json) GEN_JSON += $(ARM_METRICS) $(ARM_METRICGROUPS)
@@ -95,7 +95,7 @@ endif ifeq ($(JEVENTS_ARCH),$(filter $(JEVENTS_ARCH),x86 all)) # Generate Intel Json -INTELS = $(shell ls -d pmu-events/arch/x86/*|grep -v amdzen|grep -v mapfile.csv) +INTELS := $(shell ls -d pmu-events/arch/x86/*|grep -v amdzen|grep -v mapfile.csv) INTEL_METRICS = $(foreach x,$(INTELS),$(OUTPUT)$(x)/extra-metrics.json) INTEL_METRICGROUPS = $(foreach x,$(INTELS),$(OUTPUT)$(x)/extra-metricgroups.json) GEN_JSON += $(INTEL_METRICS) $(INTEL_METRICGROUPS)
Signature · 1 line
2.54.0.563.g4f69b47b94-goog
Ian Rogers
reviewerPATCH v5 14/14 perf build: Convert llvm-config shell queries to simply expanded variables
In reply to Ian RogersIn Makefile.config, CFLAGS, CXXFLAGS, LIBLLVM, and EXTLIBS were assigned using recursive expansion or appended with raw $(shell $(LLVM_CONFIG) ...) calls. Because these variables were expanded during dependency evaluation across every single object file compilation rule, Kbuild continuously re-executed llvm-config forks nearly 200 times during incremental builds.
Convert llvm-config shell queries to simply expanded variables (:=) to ensure Make evaluates LLVM compiler flags and library paths exactly once when Makefile.config is parsed, eliminating ~185 redundant sub-processes during build startup.
--- tools/perf/Makefile.config | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
tools/perf/Makefile.config +8 -5
@@ -951,11 +951,14 @@ ifndef NO_LIBLLVM $(call feature_check,llvm-perf) ifeq ($(feature-llvm-perf), 1) CFLAGS += -DHAVE_LIBLLVM_SUPPORT - CFLAGS += $(shell $(LLVM_CONFIG) --cflags) - CXXFLAGS += -DHAVE_LIBLLVM_SUPPORT - CXXFLAGS += $(shell $(LLVM_CONFIG) --cxxflags) - LIBLLVM = $(shell $(LLVM_CONFIG) --libs all) $(shell $(LLVM_CONFIG) --system-libs) - EXTLIBS += -L$(shell $(LLVM_CONFIG) --libdir) $(LIBLLVM) + LLVM_CFLAGS := $(shell $(LLVM_CONFIG) --cflags 2>/dev/null) + LLVM_CXXFLAGS := $(shell $(LLVM_CONFIG) --cxxflags 2>/dev/null) + LLVM_LIBLLVM := $(shell $(LLVM_CONFIG) --libs all 2>/dev/null) $(shell $(LLVM_CONFIG) --system-libs 2>/dev/null) + LLVM_LIBDIR := $(shell $(LLVM_CONFIG) --libdir 2>/dev/null) + CFLAGS += $(LLVM_CFLAGS) + CXXFLAGS += -DHAVE_LIBLLVM_SUPPORT $(LLVM_CXXFLAGS) + LIBLLVM := $(LLVM_LIBLLVM) + EXTLIBS += -L$(LLVM_LIBDIR) $(LIBLLVM) EXTLIBS += -lstdc++ $(call detected,CONFIG_LIBLLVM) else
Signature · 1 line
2.54.0.563.g4f69b47b94-goog
Ian Rogers
reviewerRe: [PATCH v5 00/14] perf build: Reduce build time by nearly half
In reply to Ian RogersQuoted 98 lines · Ian Rogers
This patch series refactors
Kbuildinternals, BPF skeleton generation, Python AST pre-computation, and foundational tooling dependencies across the perf tool build system. By eliminating umbrella target synchronization barriers, decoupling static library prerequisites, parallelizing single-core script generators, and eradicating redundant feature checks, this series unlocks greater concurrency duringKbuildstartup.On a 28-core build workstation (make -j28 all from scratch), clean build latency improves by over 44%:
Before:
real 0m29.006s user 2m46.019s sys 0m30.610sAfter:
real 0m16.091s user 2m40.135s sys 0m25.740sSaving 12.9 full seconds time per clean build. Furthermore, nothing to build incremental builds are improved by nearly 7x:
Before:
real 0m11.528s user 0m9.633s sys 0m6.965sAfter:
real 0m1.717s user 0m1.682s sys 0m0.960sSummary of Patches:
1: Fast-Path Feature Detection
- Refactors test-clang-bpf-co-re.bin and test-bpftool-skeletons.bin feature checks to group shell pipelines within curly braces and redirect both stdout and stderr to .make.output before touching $@ purely upon success
(> $(@:.bin=.make.output) 2>&1 && touch $@). Grouping the pipeline ({ cmd1 | cmd2; }) ensures that compiler stderr is successfully captured in .make.output rather than escaping to the parent shell. This perfectly matches standardKbuildfeature check conventions and ensures the target files are touched on disk purely upon success, allowingKbuildto cache positive detections and avoid continuous sub-make re-evaluations during incremental builds. Adds test-bpftool-skeletons.bin to the clean FILES list and explicit source prerequisitetest-clang-bpf-co-re.c.2-4: Flattening Umbrella Prepare Barriers
- builtin-trace embedded inclusions and pmu-events generation are completely decoupled from the sequential "prepare" umbrella target, eliminating Make AST double-parsing overhead and unchoking parallel compilation barriers.5-7: Decoupling & Pre-generating BPF Skeletons
- BPF skeleton rules are extracted out of Makefile.perf into bpf_skel.mak.
- Decouples bpftool bootstrap from top-level static libbpf dependencies, attaching bpf-skel-prepare directly to the umbrella prepare target. This allows Make to pre-compile bpftool and dumpvmlinux.hin the background at build startup, removing the 7-second serialization bottleneck before BPF object compilation.
- Ensures benchmark skeleton intermediate .bpf.o files are cleanly removed during make clean, and adds bpf-skel-prepare to .PHONY.8-9: Foundational Linkage Optimization
- Moves static libsymbol library prerequisites out of the prepare step.
- Eliminates redundant libbpf sub-make feature checks during static builds.10-11:
jevents.pyConcurrency & Deduplication
- Splits the massive 2.8 MBbig_c_stringliteral out ofpmu-events.cinto a dedicatedpmu-events-string.ccompilation unit. This slices C compilation latency in half by compiling string and struct tables simultaneously across separate CPU cores while preserving zero dynamic ELF relocations. Addspmu-events-string.cto .gitignore, declares extern const char big_c_string[]; locally insideoutput_string_fileandoutput_filewhen split to prevent linkage conflicts withempty-pmu-events.c, defers file closures to ensure identical timestamps, and uses canonical Make 4.0 @: dependency chaining.
- Pre-populatesjevents.pyJSON ASTs and metric formulas in parallel across all available CPU cores using ProcessPoolExecutor (accelerating Python execution by 11x, from 3.3s down to ~290ms). Moves_init_workerto top-level scope to ensure clean pickling under spawn multiprocessing start methods.12: Out-of-Tree Incremental Rebuild Fix
- Prefixes SCRIPTS (perf-archive, perf-iostat) with $(OUTPUT) to prevent Make from continuously re-executing script installation rules on already built out-of-tree builds.13-14: AST Parsing Optimization & Shell Fork Eradication
- Converts ZENS, ARMS, and INTELS in pmu-events/Build from recursive assignment (=) to simply expanded assignment (:=) and replaces model_name/vendor_name with pure GNU Make string functions. This guarantees Make executes directory probing shell forks exactly once during AST parsing and evaluates path macros purely in memory, completely eradicating over 7,800 redundant sub-processes during out-of-tree build evaluation.
- Converts llvm-config shell queries in Makefile.config from recursive assignment (=) to simply expanded assignment (:=). This eliminates ~185 redundant sub-processes that were previously executed across object compilation dependency checks.
Quoted 15 lines
Changes since v4:
- tools build (Patch 1): Refactored test-bpftool-skeletons.bin and test-clang-bpf-co-re.bin feature check recipes to group the shell pipeline within curly braces ({ cmd1 | cmd2; }) so that compiler stderr is successfully captured in .make.output rather than escaping to the parent shell. Added test-bpftool-skeletons.bin to the clean FILES list in feature/Makefile so that make clean correctly purges the generated binary and prevents permanent feature cache poisoning.
- perf pmu-events (Patch 10): Reverted secondary target rule in pmu-events/Build back to the canonical Make 4.0 @: dependency chaining pattern to prevent concurrency race conditions during parallel compilation. Removed global extern const char big_c_string[]; declaration frompmu-events.hand instead emitted the extern declaration locally insideoutput_string_fileandoutput_filewhen split, preventing type and linkage conflicts withempty-pmu-events.cwhen building with NO_JEVENTS=1.
Just to add that Sashiko on v5 has 2 medium and 1 low priority warning across the 14 patches:
https://sashiko.dev/#/patchset/20260515193314.1593560-1-irogers%40google.com
We could get it to 0 by removing the 3 patches it is warning about, dropping the jevents.py changes would impact build time the most. I'd prefer to land this series as it is.
Thanks,
Ian
Quoted 70 lines
Ian Rogers (14):
tools build: Fix feature checks to touch target files on success perf trace beauty: Make beauty generated C code standalone .o files perf build: Decouple pmu-events from prepare umbrella target perf build: Remove empty archheaders target
perf build: Move BPF skeleton generation out of Makefile.perf perf build: Encapsulatevmlinux.hand bpftool in bpf_skel.mak perf build: Pre-generate BPF skeleton tooling during umbrella prepare
phase
perf build: Move libsymbol dependency out of prepare step perf build: Remove redundant libbpf feature check for static builds perf pmu-events: Splitbig_c_stringstorage into standalone
compilation unit
perf pmu-events: Parallelize JSON and metric pre-computation in
jevents.py
perf build: Prefix SCRIPTS with output directory to fix continuous
rebuilds
perf pmu-events: Convert recursive shell assignments and macros to
Make built-ins
perf build: Convert llvm-config shell queries to simply expanded
variablestools/build/feature/Makefile | 13 +- tools/perf/.gitignore | 1 + tools/perf/Build | 2 + tools/perf/Makefile.config | 19 +- tools/perf/Makefile.perf | 423 ++---------------- tools/perf/bench/Build | 6 + .../bpf_skel/bench_uprobe.bpf.c | 0 tools/perf/bench/uprobe.c | 2 +- tools/perf/bpf_skel.mak | 109 +++++ tools/perf/builtin-trace.c | 32 +- tools/perf/pmu-events/Build | 26 +- tools/perf/pmu-events/jevents.py | 58 ++- tools/perf/trace/beauty/Build | 276 ++++++++++++ tools/perf/trace/beauty/arch_errno_names.c | 2 + tools/perf/trace/beauty/arch_errno_names.sh | 2 +- tools/perf/trace/beauty/beauty.h | 60 +++ tools/perf/trace/beauty/eventfd.c | 6 +- tools/perf/trace/beauty/fsconfig.c | 5 + tools/perf/trace/beauty/futex_op.c | 5 +- tools/perf/trace/beauty/futex_val3.c | 5 +- tools/perf/trace/beauty/mmap.c | 24 +- tools/perf/trace/beauty/mode_t.c | 6 +- tools/perf/trace/beauty/msg_flags.c | 8 +- tools/perf/trace/beauty/open_flags.c | 2 + tools/perf/trace/beauty/perf_event_open.c | 21 +- tools/perf/trace/beauty/pid.c | 5 +- tools/perf/trace/beauty/sched_policy.c | 8 +- tools/perf/trace/beauty/seccomp.c | 12 +- tools/perf/trace/beauty/signum.c | 6 +- tools/perf/trace/beauty/socket_type.c | 6 +- .../perf/{util => trace/beauty}/syscalltbl.c | 0 .../perf/{util => trace/beauty}/syscalltbl.h | 0 tools/perf/trace/beauty/tracepoints/Build | 21 + tools/perf/trace/beauty/waitid_options.c | 8 +- tools/perf/util/Build | 17 +- tools/perf/util/bpf-trace-summary.c | 2 +- tools/perf/util/env.c | 4 - tools/perf/util/env.h | 1 + 38 files changed, 687 insertions(+), 516 deletions(-) rename tools/perf/{util => bench}/bpf_skel/bench_uprobe.bpf.c (100%) create mode 100644 tools/perf/bpf_skel.mak create mode 100644 tools/perf/trace/beauty/fsconfig.c rename tools/perf/{util => trace/beauty}/syscalltbl.c (100%) rename tools/perf/{util => trace/beauty}/syscalltbl.h (100%)--
2.54.0.563.g4f69b47b94-goog
Ian Rogers
reviewerv6 cover perf build: Reduce build time by nearly half
In reply to Ian RogersThis patch series refactors Kbuild internals, BPF skeleton generation, Python AST pre-computation, and foundational tooling dependencies across the perf tool build system. By eliminating umbrella target synchronization barriers, decoupling static library prerequisites, parallelizing single-core script generators, and eradicating redundant feature checks, this series unlocks absolute theoretical peak multi-core concurrency during Kbuild startup.
On a 28-core build workstation (make -j28 all from scratch), clean build latency improves by over 44%:
Before:
real 0m29.006s
user 2m46.019s
sys 0m30.610sAfter:
real 0m16.091s
user 2m40.135s
sys 0m25.740sSaving 12.9 full seconds time per clean build. Furthermore, nothing to build incremental builds are improved by nearly 7x:
Before:
real 0m11.528s
user 0m9.633s
sys 0m6.965sAfter:
real 0m1.717s
user 0m1.682s
sys 0m0.960sSummary of Patches:
1: Fast-Path Feature Detection
- Refactors test-clang-bpf-co-re.bin and test-bpftool-skeletons.bin feature checks to group shell pipelines within curly braces and redirect both stdout and stderr to .make.output before touching $@ purely upon success
(> $(@:.bin=.make.output) 2>&1 && touch $@). Grouping the pipeline ({ cmd1 | cmd2; }) ensures that compiler stderr is successfully captured in .make.output rather than escaping to the parent shell. This perfectly matches standard Kbuild feature check conventions and ensures the target files are touched on disk purely upon success, allowing Kbuild to cache positive detections and avoid continuous sub-make re-evaluations during incremental builds. Adds test-bpftool-skeletons.bin to the clean FILES list and explicit source prerequisite test-clang-bpf-co-re.c.
2-4: Flattening Umbrella Prepare Barriers
- builtin-trace embedded inclusions and pmu-events generation are completely decoupled from the sequential "prepare" umbrella target, eliminating Make AST double-parsing overhead and unchoking parallel compilation barriers.
5-7: Decoupling & Pre-generating BPF Skeletons
- BPF skeleton rules are extracted out of Makefile.perf into bpf_skel.mak.
- Decouples bpftool bootstrap from top-level static libbpf dependencies, attaching bpf-skel-prepare directly to the umbrella prepare target. This allows Make to pre-compile bpftool and dump vmlinux.h in the background at build startup, removing the 7-second serialization bottleneck before BPF object compilation.
- Ensures benchmark skeleton intermediate .bpf.o files are cleanly removed during make clean, and adds bpf-skel-prepare to .PHONY.
8-9: Foundational Linkage Optimization
- Moves static libsymbol library prerequisites out of the prepare step.
- Eliminates redundant libbpf sub-make feature checks during static builds.
10-11: jevents.py Concurrency & Deduplication
- Splits the massive 2.8 MB big_c_string literal out of pmu-events.c into a dedicated pmu-events-string.c compilation unit. This slices C compilation latency in half by compiling string and struct tables simultaneously across separate CPU cores while preserving zero dynamic ELF relocations. Adds pmu-events-string.c to .gitignore, declares extern const char big_c_string[]; locally inside output_string_file and output_file when split to prevent linkage conflicts with empty-pmu-events.c, defers file closures to ensure identical timestamps, and uses canonical Make 4.0 @: dependency chaining.
- Pre-populates jevents.py JSON ASTs and metric formulas in parallel across all available CPU cores using ProcessPoolExecutor (accelerating Python execution by 11x, from 3.3s down to ~290ms). Moves _init_worker to top-level scope to ensure clean pickling under spawn multiprocessing start methods.
12: Out-of-Tree Incremental Rebuild Fix
- Prefixes SCRIPTS (perf-archive, perf-iostat) with $(OUTPUT) to prevent Make from continuously re-executing script installation rules on already built out-of-tree builds.
13-14: AST Parsing Optimization & Shell Fork Eradication
- Converts ZENS, ARMS, and INTELS in pmu-events/Build from recursive assignment (=) to simply expanded assignment (:=) and replaces model_name/vendor_name with pure GNU Make string functions. This guarantees Make executes directory probing shell forks exactly once during AST parsing and evaluates path macros purely in memory, completely eradicating over 7,800 redundant sub-processes during out-of-tree build evaluation.
- Converts llvm-config shell queries in Makefile.config from recursive assignment (=) to simply expanded assignment (:=). This eliminates ~185 redundant sub-processes that were previously executed across object compilation dependency checks.
Changes since v5:
- perf pmu-events (Patch 10): Refactored jevents.py to explicitly close output_file first and output_string_file second at the absolute tail of main(), guaranteeing that pmu-events-string.c receives a filesystem modification timestamp strictly greater than or equal to pmu-events.c. This completely eliminates any nanosecond timestamp discrepancy during Python teardown, ensuring Make's canonical @:
dependency chaining rule correctly sees pmu-events-string.c as fully up to date and preventing redundant recompilations during incremental builds without requiring manual touch commands in the Makefile.
Ian Rogers (14):
tools build: Fix feature checks to touch target files on success perf trace beauty: Make beauty generated C code standalone .o files perf build: Decouple pmu-events from prepare umbrella target perf build: Remove empty archheaders target
perf build: Move BPF skeleton generation out of Makefile.perf perf build: Encapsulate vmlinux.h and bpftool in bpf_skel.mak perf build: Pre-generate BPF skeleton tooling during umbrella prepare
phase
perf build: Move libsymbol dependency out of prepare step perf build: Remove redundant libbpf feature check for static builds perf pmu-events: Split big_c_string storage into standalone
compilation unit
perf pmu-events: Parallelize JSON and metric pre-computation in
jevents.py
perf build: Prefix SCRIPTS with output directory to fix continuous
rebuilds
perf pmu-events: Convert recursive shell assignments and macros to
Make built-ins
perf build: Convert llvm-config shell queries to simply expanded
variables
tools/build/feature/Makefile | 13 +-
tools/perf/.gitignore | 1 +
tools/perf/Build | 2 +
tools/perf/Makefile.config | 19 +-
tools/perf/Makefile.perf | 423 ++----------------
tools/perf/bench/Build | 6 +
.../bpf_skel/bench_uprobe.bpf.c | 0
tools/perf/bench/uprobe.c | 2 +-
tools/perf/bpf_skel.mak | 109 +++++
tools/perf/builtin-trace.c | 32 +-
tools/perf/pmu-events/Build | 26 +-
tools/perf/pmu-events/jevents.py | 59 ++-
tools/perf/trace/beauty/Build | 276 ++++++++++++
tools/perf/trace/beauty/arch_errno_names.c | 2 +
tools/perf/trace/beauty/arch_errno_names.sh | 2 +-
tools/perf/trace/beauty/beauty.h | 60 +++
tools/perf/trace/beauty/eventfd.c | 6 +-
tools/perf/trace/beauty/fsconfig.c | 5 +
tools/perf/trace/beauty/futex_op.c | 5 +-
tools/perf/trace/beauty/futex_val3.c | 5 +-
tools/perf/trace/beauty/mmap.c | 24 +-
tools/perf/trace/beauty/mode_t.c | 6 +-
tools/perf/trace/beauty/msg_flags.c | 8 +-
tools/perf/trace/beauty/open_flags.c | 2 +
tools/perf/trace/beauty/perf_event_open.c | 21 +-
tools/perf/trace/beauty/pid.c | 5 +-
tools/perf/trace/beauty/sched_policy.c | 8 +-
tools/perf/trace/beauty/seccomp.c | 12 +-
tools/perf/trace/beauty/signum.c | 6 +-
tools/perf/trace/beauty/socket_type.c | 6 +-
.../perf/{util => trace/beauty}/syscalltbl.c | 0
.../perf/{util => trace/beauty}/syscalltbl.h | 0
tools/perf/trace/beauty/tracepoints/Build | 21 +
tools/perf/trace/beauty/waitid_options.c | 8 +-
tools/perf/util/Build | 17 +-
tools/perf/util/bpf-trace-summary.c | 2 +-
tools/perf/util/env.c | 4 -
tools/perf/util/env.h | 1 +
38 files changed, 688 insertions(+), 516 deletions(-)
rename tools/perf/{util => bench}/bpf_skel/bench_uprobe.bpf.c (100%)
create mode 100644 tools/perf/bpf_skel.mak
create mode 100644 tools/perf/trace/beauty/fsconfig.c
rename tools/perf/{util => trace/beauty}/syscalltbl.c (100%)
rename tools/perf/{util => trace/beauty}/syscalltbl.h (100%)Signature · 1 line
2.54.0.563.g4f69b47b94-goog
Ian Rogers
reviewerPATCH v6 1/14 tools build: Fix feature checks to touch target files on success
In tools/build/feature/Makefile, test-clang-bpf-co-re.bin and test-bpftool-skeletons.bin redirected grep output but never touched or created the $@ target file upon success.
Because the target file was never created on disk, Kbuild could never cache the result of the check. Consequently, Make treated the prerequisite as missing and continuously re-executed the Clang BPF backend and bpftool feature checks on every single sub-make evaluation during build startup.
Refactor both feature check recipes to group the shell pipeline within curly braces and redirect both stdout and stderr to .make.output before touching $@ purely upon success (> $(@:.bin=.make.output) 2>&1 && touch $@). Grouping the pipeline ({ cmd1 | cmd2; }) ensures that compiler stderr is successfully captured in .make.output rather than escaping to the parent shell. This perfectly matches standard Kbuild feature check conventions, allowing Make to cache positive detections and avoid redundant sub-make forks during incremental builds. Add test-bpftool-skeletons.bin to the FILES list so that make clean correctly purges the generated binary. For test-clang-bpf-co-re.bin, add explicit source file prerequisite test-clang-bpf-co-re.c and simplify the Clang recipe using $<.
--- tools/build/feature/Makefile | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
tools/build/feature/Makefile +7 -6
@@ -72,7 +72,8 @@ FILES= \ test-file-handle.bin \ test-libpfm4.bin \ test-rust.bin \ - test-libopenssl.bin + test-libopenssl.bin \ + test-bpftool-skeletons.bin FILES := $(addprefix $(OUTPUT),$(FILES))
@@ -379,9 +380,9 @@ $(OUTPUT)test-libaio.bin: $(OUTPUT)test-libzstd.bin: $(BUILD) -lzstd -$(OUTPUT)test-clang-bpf-co-re.bin: - $(CLANG) -S -g --target=bpf -o - $(patsubst %.bin,%.c,$(@F)) | \ - grep BTF_KIND_VAR +$(OUTPUT)test-clang-bpf-co-re.bin: test-clang-bpf-co-re.c + { $(CLANG) -S -g --target=bpf -o - $< | \ + grep BTF_KIND_VAR; } > $(@:.bin=.make.output) 2>&1 && touch $@ $(OUTPUT)test-file-handle.bin: $(BUILD)
@@ -393,8 +394,8 @@ $(OUTPUT)test-libopenssl.bin: $(BUILD) $(shell $(PKG_CONFIG) --libs --cflags openssl 2>/dev/null) $(OUTPUT)test-bpftool-skeletons.bin: - $(SYSTEM_BPFTOOL) version | grep '^features:.*skeletons' \ - > $(@:.bin=.make.output) 2>&1 + { $(SYSTEM_BPFTOOL) version | grep '^features:.*skeletons'; } \ + > $(@:.bin=.make.output) 2>&1 && touch $@ # Testing Rust is special: we don't compile anything, it's enough to check the # compiler presence. Compiling a test code for this purposes is problematic,
Signature · 1 line
2.54.0.563.g4f69b47b94-goog
Ian Rogers
reviewerPATCH v6 2/14 perf trace beauty: Make beauty generated C code standalone .o files
In reply to Ian RogersPreviously, builtin-trace.c directly included 15 embedded C files (e.g. trace/beauty/mmap.c and fsconfig_arrays.c), which in turn depend on dozens of generated beauty script arrays. To satisfy these embedded inclusions, the global Makefile.perf would define all the generator variables/rules and include them in the prepare umbrella target, choking parallel build startup.
Furthermore, tools/perf/util/syscalltbl.c included its own generated mapper, and util/env.c conditionally included arch_errno_names.c inline, splitting consumers across directories and preventing clean Make encapsulation.
Refactor the framework to achieve better encapsulation:
1. Move util/syscalltbl.[ch] into trace/beauty/ to co-locate with all generated code consumers.
2. Create fsconfig.c and flatten embedded beauty .c files to compile as independent standalone objects via trace/beauty/Build, exporting their formatting functions via beauty.h and env.h. Switch arch_errno_names.o and syscalltbl.o assignments directly to perf-util-y and add an unconditional top-level recursive kbuild hook (perf-util-y += trace/beauty/) to compile them into libperf-util.a, resolving remote linkage for util/env.c, util/bpf-trace-summary.c, and standalone python extensions.
3. Bridge private opaque references (struct trace) securely via accessors trace__show_zeros() and trace__host(), avoiding header entanglements.
4. Consolidate all generator variables, script paths, and array generation rules entirely out of Makefile.perf and place them directly inside the exact local Build files where their output objects are compiled (trace/beauty/Build and trace/beauty/tracepoints/Build), binding prerequisites locally. Use directly inside
generator recipes to guarantee dynamic directory creation before script redirection, and append across all rules to print
clean, standardized GEN ... file.c output during compilation.
5. Clean up clean target to recursively remove the generated directory instead of relying on dozens of individual variables.
This unchokes the "prepare" target parallel barrier, allows make to evaluate generation scripts purely locally where consumed, and flattens the tracepoint formatting architecture.
Testing a parallel build (make -j28 all from scratch) shows improvements:
Before:
real 0m28.689s
user 2m38.490s
sys 0m30.148sAfter:
real 0m27.642s
user 2m32.356s
sys 0m26.683sSo reclaiming ~9.6 seconds of raw CPU time and over 1 full second off overall real-world build latency, by overlapping sub-make startup and avoiding top-level double-parsing overhead.
---
tools/perf/Build | 2 +
tools/perf/Makefile.perf | 282 +-----------------
tools/perf/builtin-trace.c | 32 +-
tools/perf/trace/beauty/Build | 276 +++++++++++++++++
tools/perf/trace/beauty/arch_errno_names.c | 2 +
tools/perf/trace/beauty/arch_errno_names.sh | 2 +-
tools/perf/trace/beauty/beauty.h | 60 ++++
tools/perf/trace/beauty/eventfd.c | 6 +-
tools/perf/trace/beauty/fsconfig.c | 5 +
tools/perf/trace/beauty/futex_op.c | 5 +-
tools/perf/trace/beauty/futex_val3.c | 5 +-
tools/perf/trace/beauty/mmap.c | 24 +-
tools/perf/trace/beauty/mode_t.c | 6 +-
tools/perf/trace/beauty/msg_flags.c | 8 +-
tools/perf/trace/beauty/open_flags.c | 2 +
tools/perf/trace/beauty/perf_event_open.c | 21 +-
tools/perf/trace/beauty/pid.c | 5 +-
tools/perf/trace/beauty/sched_policy.c | 8 +-
tools/perf/trace/beauty/seccomp.c | 12 +-
tools/perf/trace/beauty/signum.c | 6 +-
tools/perf/trace/beauty/socket_type.c | 6 +-
.../perf/{util => trace/beauty}/syscalltbl.c | 0
.../perf/{util => trace/beauty}/syscalltbl.h | 0
tools/perf/trace/beauty/tracepoints/Build | 21 ++
tools/perf/trace/beauty/waitid_options.c | 8 +-
tools/perf/util/Build | 4 +-
tools/perf/util/bpf-trace-summary.c | 2 +-
tools/perf/util/env.c | 4 -
tools/perf/util/env.h | 1 +
29 files changed, 447 insertions(+), 368 deletions(-)
create mode 100644 tools/perf/trace/beauty/fsconfig.c
rename tools/perf/{util => trace/beauty}/syscalltbl.c (100%)
rename tools/perf/{util => trace/beauty}/syscalltbl.h (100%)tools/perf/Build +2 -0
@@ -34,6 +34,8 @@ ifeq ($(CONFIG_LIBTRACEEVENT),y) perf-$(CONFIG_TRACE) += trace/beauty/ endif +perf-util-y += trace/beauty/ + perf-$(CONFIG_LIBELF) += builtin-probe.o perf-bench-y += bench/
tools/perf/Makefile.perf +2 -280
300 lines not on this page · raw message
tools/perf/builtin-trace.c +12 -20
@@ -60,12 +60,13 @@#include "callchain.h" #include "print_binary.h" #include "string2.h" -#include "syscalltbl.h" +#include "trace/beauty/syscalltbl.h" #include "../perf.h" #include "trace_augment.h" #include "dwarf-regs.h" #include <errno.h> +#include <sys/stat.h> #include <inttypes.h> #include <poll.h> #include <signal.h>
@@ -235,6 +236,16 @@ struct trace {const char *uid_str; }; +bool trace__show_zeros (const struct trace *trace) +{ +return trace->show_zeros; +} + +struct machine *trace__host (const struct trace *trace) +{ +return trace->host; +} +static void trace__load_vmlinux_btf (struct trace *trace__maybe_unused ) {#ifdef HAVE_LIBBPF_SUPPORT
@@ -777,10 +788,6 @@ static const char *fsmount_flags[] = { }; static DEFINE_STRARRAY(fsmount_flags, "FSMOUNT_"); -#include "trace/beauty/generated/fsconfig_arrays.c" - -static DEFINE_STRARRAY(fsconfig_cmds, "FSCONFIG_"); -static const char *epoll_ctl_ops[] = {"ADD" ,"DEL" ,"MOD" , }; static DEFINE_STRARRAY_OFFSET(epoll_ctl_ops, "EPOLL_CTL_", 1);
@@ -1129,21 +1136,6 @@ static bool syscall_arg__strtoul_btf_type(char *bf __maybe_unused, size_t size _ .parm = &strarray__##array, \ .show_zero = true, } -#include "trace/beauty/eventfd.c" -#include "trace/beauty/futex_op.c" -#include "trace/beauty/futex_val3.c" -#include "trace/beauty/mmap.c" -#include "trace/beauty/mode_t.c" -#include "trace/beauty/msg_flags.c" -#include "trace/beauty/open_flags.c" -#include "trace/beauty/perf_event_open.c" -#include "trace/beauty/pid.c" -#include "trace/beauty/sched_policy.c" -#include "trace/beauty/seccomp.c" -#include "trace/beauty/signum.c" -#include "trace/beauty/socket_type.c" -#include "trace/beauty/waitid_options.c" -static const struct syscall_fmt syscall_fmts[] = { { .name ="access" , .arg = { [1 ] = { .scnprintf =SCA_ACCMODE ,/* mode */ }, }, },
tools/perf/trace/beauty/Build +276 -0
285 lines not on this page · raw message
tools/perf/trace/beauty/arch_errno_names.c +2 -0
@@ -1 +1,3 @@ +// SPDX-License-Identifier: GPL-2.0 +#include "util/env.h" #include "trace/beauty/generated/arch_errno_name_array.c"
tools/perf/trace/beauty/arch_errno_names.sh +1 -1
@@ -57,7 +57,7 @@ create_arch_errno_table_func() archlist="$1" default="$2" - printf 'static arch_syscalls__strerrno_t *\n' + printf 'arch_syscalls__strerrno_t *\n' printf 'arch_syscalls__strerrno_function(const char *arch)\n' printf '{\n' for arch in $archlist; do
tools/perf/trace/beauty/beauty.h +60 -0
70 lines not on this page · raw message
tools/perf/trace/beauty/eventfd.c +3 -3
@@ -1,4 +1,6 @@// SPDX-License-Identifier: LGPL-2.1 +#include "trace/beauty/beauty.h" +#ifndef EFD_SEMAPHORE #define EFD_SEMAPHORE 1#endif
@@ -11,7 +13,7 @@#define EFD_CLOEXEC 02000000#endif -static size_t syscall_arg__scnprintf_eventfd_flags (char *bf,size_t size,struct syscall_arg *arg) +size_t syscall_arg__scnprintf_eventfd_flags (char *bf,size_t size,struct syscall_arg *arg) {bool show_prefix = arg->show_string_prefix;const char *prefix ="EFD_" ;
@@ -35,5 +37,3 @@ static size_t syscall_arg__scnprintf_eventfd_flags(char *bf, size_t size, structreturn printed; } - -#define SCA_EFD_FLAGS syscall_arg__scnprintf_eventfd_flags
tools/perf/trace/beauty/fsconfig.c new file +5 -0
@@ -0,0 +1,5 @@ +// SPDX-License-Identifier: LGPL-2.1 +#include "trace/beauty/beauty.h" +#include "trace/beauty/generated/fsconfig_arrays.c" + +DEFINE_STRARRAY (fsconfig_cmds,"FSCONFIG_" );
tools/perf/trace/beauty/futex_op.c +2 -3
@@ -1,4 +1,5 @@// SPDX-License-Identifier: LGPL-2.1 +#include "trace/beauty/beauty.h" #include <linux/futex.h> #ifndef FUTEX_WAIT_BITSET
@@ -17,7 +18,7 @@#define FUTEX_CLOCK_REALTIME 256#endif -static size_t syscall_arg__scnprintf_futex_op (char *bf,size_t size,struct syscall_arg *arg) +size_t syscall_arg__scnprintf_futex_op (char *bf,size_t size,struct syscall_arg *arg) {bool show_prefix = arg->show_string_prefix;const char *prefix ="FUTEX_" ;
@@ -59,5 +60,3 @@ static size_t syscall_arg__scnprintf_futex_op(char *bf, size_t size, struct syscreturn printed; } - -#define SCA_FUTEX_OP syscall_arg__scnprintf_futex_op
tools/perf/trace/beauty/futex_val3.c +2 -3
@@ -1,11 +1,12 @@// SPDX-License-Identifier: LGPL-2.1 +#include "trace/beauty/beauty.h" #include <linux/futex.h> #ifndef FUTEX_BITSET_MATCH_ANY #define FUTEX_BITSET_MATCH_ANY 0xffffffff#endif -static size_t syscall_arg__scnprintf_futex_val3 (char *bf,size_t size,struct syscall_arg *arg) +size_t syscall_arg__scnprintf_futex_val3 (char *bf,size_t size,struct syscall_arg *arg) {const char *prefix ="FUTEX_BITSET_" ;unsigned int bitset = arg->val;
@@ -15,5 +16,3 @@ static size_t syscall_arg__scnprintf_futex_val3(char *bf, size_t size, struct syreturn scnprintf (bf, size,"%#xd" , bitset); } - -#define SCA_FUTEX_VAL3 syscall_arg__scnprintf_futex_val3
tools/perf/trace/beauty/mmap.c +11 -13
@@ -1,5 +1,6 @@// SPDX-License-Identifier: LGPL-2.1 #include <linux/log2.h> +#include "trace/beauty/beauty.h" #include "trace/beauty/generated/mmap_prot_array.c" static DEFINE_STRARRAY(mmap_prot, "PROT_");
@@ -8,8 +9,7 @@ static size_t mmap__scnprintf_prot(unsigned long prot, char *bf, size_t size, bo {return strarray__scnprintf_flags (&strarray__mmap_prot, bf, size, show_prefix, prot); } - -static size_t syscall_arg__scnprintf_mmap_prot (char *bf,size_t size,struct syscall_arg *arg) +size_t syscall_arg__scnprintf_mmap_prot (char *bf,size_t size,struct syscall_arg *arg) {unsigned long prot = arg->val;
@@ -19,18 +19,18 @@ static size_t syscall_arg__scnprintf_mmap_prot(char *bf, size_t size, struct sysreturn mmap__scnprintf_prot (prot, bf, size, arg->show_string_prefix); } -#define SCA_MMAP_PROT syscall_arg__scnprintf_mmap_prot +#include "trace/beauty/generated/mmap_flags_array.c" -static DEFINE_STRARRAY(mmap_flags, "MAP_"); +DEFINE_STRARRAY (mmap_flags,"MAP_" );static size_t mmap__scnprintf_flags (unsigned long flags,char *bf,size_t size,bool show_prefix) {return strarray__scnprintf_flags (&strarray__mmap_flags, bf, size, show_prefix, flags); } -static size_t syscall_arg__scnprintf_mmap_flags (char *bf,size_t size, -struct syscall_arg *arg) +size_t syscall_arg__scnprintf_mmap_flags (char *bf,size_t size, +struct syscall_arg *arg) {unsigned long flags = arg->val;
@@ -40,7 +40,7 @@ static size_t syscall_arg__scnprintf_mmap_flags(char *bf, size_t size,return mmap__scnprintf_flags (flags, bf, size, arg->show_string_prefix); } -#define SCA_MMAP_FLAGS syscall_arg__scnprintf_mmap_flags +#include "trace/beauty/generated/mremap_flags_array.c" static DEFINE_STRARRAY(mremap_flags, "MREMAP_");
@@ -50,7 +50,7 @@ static size_t mremap__scnprintf_flags(unsigned long flags, char *bf, size_t sizereturn strarray__scnprintf_flags (&strarray__mremap_flags, bf, size, show_prefix, flags); } -static size_t syscall_arg__scnprintf_mremap_flags (char *bf,size_t size,struct syscall_arg *arg) +size_t syscall_arg__scnprintf_mremap_flags (char *bf,size_t size,struct syscall_arg *arg) {unsigned long flags = arg->val;
@@ -60,7 +60,7 @@ static size_t syscall_arg__scnprintf_mremap_flags(char *bf, size_t size, structreturn mremap__scnprintf_flags (flags, bf, size, arg->show_string_prefix); } -#define SCA_MREMAP_FLAGS syscall_arg__scnprintf_mremap_flags +static size_t madvise__scnprintf_behavior (int behavior,char *bf,size_t size) {
@@ -73,10 +73,8 @@ static size_t madvise__scnprintf_behavior(int behavior, char *bf, size_t size)return scnprintf (bf, size,"%#" , behavior); } -static size_t syscall_arg__scnprintf_madvise_behavior (char *bf,size_t size, -struct syscall_arg *arg) +size_t syscall_arg__scnprintf_madvise_behavior (char *bf,size_t size, +struct syscall_arg *arg) {return madvise__scnprintf_behavior (arg->val, bf, size); } - -#define SCA_MADV_BHV syscall_arg__scnprintf_madvise_behavior
tools/perf/trace/beauty/mode_t.c +3 -3
@@ -1,4 +1,6 @@// SPDX-License-Identifier: LGPL-2.1 +#include "trace/beauty/beauty.h" +#include <sys/types.h> #include <sys/stat.h> #include <unistd.h>
@@ -20,7 +22,7 @@#define S_IXUGO (S_IXUSR|S_IXGRP|S_IXOTH)#endif -static size_t syscall_arg__scnprintf_mode_t (char *bf,size_t size,struct syscall_arg *arg) +size_t syscall_arg__scnprintf_mode_t (char *bf,size_t size,struct syscall_arg *arg) {bool show_prefix = arg->show_string_prefix;const char *prefix ="S_" ;
@@ -67,5 +69,3 @@ static size_t syscall_arg__scnprintf_mode_t(char *bf, size_t size, struct syscalreturn printed; } - -#define SCA_MODE_T syscall_arg__scnprintf_mode_t
tools/perf/trace/beauty/msg_flags.c +4 -4
@@ -1,4 +1,6 @@// SPDX-License-Identifier: LGPL-2.1 +#include "trace/beauty/beauty.h" +#include <sys/types.h> #include <sys/socket.h>
@@ -27,8 +29,8 @@# define MSG_CMSG_CLOEXEC 0x40000000#endif -static size_t syscall_arg__scnprintf_msg_flags (char *bf,size_t size, -struct syscall_arg *arg) +size_t syscall_arg__scnprintf_msg_flags (char *bf,size_t size, +struct syscall_arg *arg) {bool show_prefix = arg->show_string_prefix;const char *prefix ="MSG_" ;
@@ -72,5 +74,3 @@ static size_t syscall_arg__scnprintf_msg_flags(char *bf, size_t size,return printed; } - -#define SCA_MSG_FLAGS syscall_arg__scnprintf_msg_flags
tools/perf/trace/beauty/open_flags.c +2 -0
@@ -1,4 +1,6 @@// SPDX-License-Identifier: LGPL-2.1 +#include "trace/beauty/beauty.h" +#include <sys/types.h> #include <sys/stat.h> #include <fcntl.h>
tools/perf/trace/beauty/perf_event_open.c +10 -11
@@ -1,4 +1,8 @@// SPDX-License-Identifier: LGPL-2.1 +#include "trace/beauty/beauty.h" +#include "util/evsel_fprintf.h" +#include <linux/perf_event.h> +#ifndef PERF_FLAG_FD_NO_GROUP # define PERF_FLAG_FD_NO_GROUP (1UL << 0)#endif
@@ -15,8 +19,8 @@# define PERF_FLAG_FD_CLOEXEC (1UL << 3)/* O_CLOEXEC */ #endif -static size_t syscall_arg__scnprintf_perf_flags (char *bf,size_t size, -struct syscall_arg *arg) +size_t syscall_arg__scnprintf_perf_flags (char *bf,size_t size, +struct syscall_arg *arg) {bool show_prefix = arg->show_string_prefix;const char *prefix ="PERF_" ;
@@ -43,7 +47,7 @@ static size_t syscall_arg__scnprintf_perf_flags(char *bf, size_t size,return printed; } -#define SCA_PERF_FLAGS syscall_arg__scnprintf_perf_flags +struct attr_fprintf_args {size_t size, printed;
@@ -76,19 +80,14 @@ static size_t perf_event_attr___scnprintf(struct perf_event_attr *attr, char *bfstatic size_t syscall_arg__scnprintf_augmented_perf_event_attr (struct syscall_arg *arg,char *bf,size_t size) { -return perf_event_attr___scnprintf ((void *)arg->augmented.args->value, bf, size, arg->trace->show_zeros); +return perf_event_attr___scnprintf ((void *)arg->augmented.args->value, bf, size, +trace__show_zeros (arg->trace)); } -static size_t syscall_arg__scnprintf_perf_event_attr (char *bf,size_t size,struct syscall_arg *arg) +size_t syscall_arg__scnprintf_perf_event_attr (char *bf,size_t size,struct syscall_arg *arg) {if (arg->augmented.args)return syscall_arg__scnprintf_augmented_perf_event_attr (arg, bf, size);return scnprintf (bf, size,"%#lx" , arg->val); } - -#define SCA_PERF_ATTR syscall_arg__scnprintf_perf_event_attr -// 'argname' is just documentational at this point, to remove the previous comment with that info -#define SCA_PERF_ATTR_FROM_USER (argname) \ - { .scnprintf = SCA_PERF_ATTR, \ - .from_user = true, }
tools/perf/trace/beauty/pid.c +4 -1
@@ -1,11 +1,14 @@// SPDX-License-Identifier: LGPL-2.1 +#include "trace/beauty/beauty.h" +#include "util/machine.h" +#include "util/thread.h" size_t syscall_arg__scnprintf_pid (char *bf,size_t size,struct syscall_arg *arg) {int pid = arg->val;struct trace *trace = arg->trace;size_t printed =scnprintf (bf, size,"%d" , pid); -struct thread *thread =machine__findnew_thread (trace->host, pid, pid); +struct thread *thread =machine__findnew_thread (trace__host (trace), pid, pid);if (thread !=NULL ) {if (!thread__comm_set (thread))
tools/perf/trace/beauty/sched_policy.c +4 -4
@@ -1,4 +1,6 @@// SPDX-License-Identifier: LGPL-2.1 +#include "trace/beauty/beauty.h" +#include <sched.h> /*
@@ -14,8 +16,8 @@#define SCHED_RESET_ON_FORK 0x40000000#endif -static size_t syscall_arg__scnprintf_sched_policy (char *bf,size_t size, -struct syscall_arg *arg) +size_t syscall_arg__scnprintf_sched_policy (char *bf,size_t size, +struct syscall_arg *arg) {bool show_prefix = arg->show_string_prefix;const char *prefix ="SCHED_" ;
@@ -46,5 +48,3 @@ static size_t syscall_arg__scnprintf_sched_policy(char *bf, size_t size,return printed; } - -#define SCA_SCHED_POLICY syscall_arg__scnprintf_sched_policy
tools/perf/trace/beauty/seccomp.c +6 -6
@@ -1,4 +1,6 @@// SPDX-License-Identifier: LGPL-2.1 +#include "trace/beauty/beauty.h" +#ifndef SECCOMP_SET_MODE_STRICT #define SECCOMP_SET_MODE_STRICT 0#endif
@@ -6,7 +8,7 @@#define SECCOMP_SET_MODE_FILTER 1#endif -static size_t syscall_arg__scnprintf_seccomp_op (char *bf,size_t size,struct syscall_arg *arg) +size_t syscall_arg__scnprintf_seccomp_op (char *bf,size_t size,struct syscall_arg *arg) {bool show_prefix = arg->show_string_prefix;const char *prefix ="SECCOMP_SET_MODE_" ;
@@ -24,14 +26,14 @@ static size_t syscall_arg__scnprintf_seccomp_op(char *bf, size_t size, struct syreturn printed; } -#define SCA_SECCOMP_OP syscall_arg__scnprintf_seccomp_op +#ifndef SECCOMP_FILTER_FLAG_TSYNC #define SECCOMP_FILTER_FLAG_TSYNC 1#endif -static size_t syscall_arg__scnprintf_seccomp_flags (char *bf,size_t size, -struct syscall_arg *arg) +size_t syscall_arg__scnprintf_seccomp_flags (char *bf,size_t size, +struct syscall_arg *arg) {bool show_prefix = arg->show_string_prefix;const char *prefix ="SECCOMP_FILTER_FLAG_" ;
@@ -51,5 +53,3 @@ static size_t syscall_arg__scnprintf_seccomp_flags(char *bf, size_t size,return printed; } - -#define SCA_SECCOMP_FLAGS syscall_arg__scnprintf_seccomp_flags
tools/perf/trace/beauty/signum.c +3 -3
@@ -1,7 +1,9 @@// SPDX-License-Identifier: LGPL-2.1 +#include "trace/beauty/beauty.h" +#include <signal.h> -static size_t syscall_arg__scnprintf_signum (char *bf,size_t size,struct syscall_arg *arg) +size_t syscall_arg__scnprintf_signum (char *bf,size_t size,struct syscall_arg *arg) {bool show_prefix = arg->show_string_prefix;const char *prefix ="SIG" ;
@@ -53,5 +55,3 @@ static size_t syscall_arg__scnprintf_signum(char *bf, size_t size, struct syscalreturn scnprintf (bf, size,"%#x" , sig); } - -#define SCA_SIGNUM syscall_arg__scnprintf_signum
tools/perf/trace/beauty/socket_type.c +3 -3
@@ -1,4 +1,6 @@// SPDX-License-Identifier: LGPL-2.1 +#include "trace/beauty/beauty.h" +#include <sys/types.h> #include <sys/socket.h>
@@ -18,7 +20,7 @@#define SOCK_TYPE_MASK 0xf#endif -static size_t syscall_arg__scnprintf_socket_type (char *bf,size_t size,struct syscall_arg *arg) +size_t syscall_arg__scnprintf_socket_type (char *bf,size_t size,struct syscall_arg *arg) {bool show_prefix = arg->show_string_prefix;const char *prefix ="SOCK_" ;
@@ -59,5 +61,3 @@ static size_t syscall_arg__scnprintf_socket_type(char *bf, size_t size, struct sreturn printed; } - -#define SCA_SK_TYPE syscall_arg__scnprintf_socket_type
tools/perf/trace/beauty/syscalltbl.c renamed from tools/perf/util/syscalltbl.c +0 -0
tools/perf/trace/beauty/syscalltbl.h renamed from tools/perf/util/syscalltbl.h +0 -0
tools/perf/trace/beauty/tracepoints/Build +21 -0
@@ -1,2 +1,23 @@ perf-y += x86_irq_vectors.o perf-y += x86_msr.o + +beauty_outdir := $(OUTPUT)trace/beauty/generated +beauty_arch_asm_dir := $(srctree)/tools/perf/trace/beauty/arch/x86/include/asm/ +x86_arch_asm_dir := $(srctree)/tools/arch/x86/include/asm/ + +x86_arch_irq_vectors_array := $(beauty_outdir)/x86_arch_irq_vectors_array.c +x86_arch_irq_vectors_tbl := $(srctree)/tools/perf/trace/beauty/tracepoints/x86_irq_vectors.sh + +$(x86_arch_irq_vectors_array): $(beauty_arch_asm_dir)/irq_vectors.h $(x86_arch_irq_vectors_tbl) + $(call rule_mkdir) + $(Q)$(call echo-cmd,gen)$(SHELL) '$(x86_arch_irq_vectors_tbl)' $(beauty_arch_asm_dir) > $@ + +x86_arch_MSRs_array := $(beauty_outdir)/x86_arch_MSRs_array.c +x86_arch_MSRs_tbl := $(srctree)/tools/perf/trace/beauty/tracepoints/x86_msr.sh + +$(x86_arch_MSRs_array): $(x86_arch_asm_dir)/msr-index.h $(x86_arch_MSRs_tbl) + $(call rule_mkdir) + $(Q)$(call echo-cmd,gen)$(SHELL) '$(x86_arch_MSRs_tbl)' $(x86_arch_asm_dir) > $@ + +$(OUTPUT)trace/beauty/tracepoints/x86_irq_vectors.o: $(x86_arch_irq_vectors_array) +$(OUTPUT)trace/beauty/tracepoints/x86_msr.o: $(x86_arch_MSRs_array)
tools/perf/trace/beauty/waitid_options.c +4 -4
@@ -1,9 +1,11 @@// SPDX-License-Identifier: LGPL-2.1 +#include "trace/beauty/beauty.h" +#include <sys/types.h> #include <sys/wait.h> -static size_t syscall_arg__scnprintf_waitid_options (char *bf,size_t size, -struct syscall_arg *arg) +size_t syscall_arg__scnprintf_waitid_options (char *bf,size_t size, +struct syscall_arg *arg) {bool show_prefix = arg->show_string_prefix;const char *prefix ="W" ;
@@ -25,5 +27,3 @@ static size_t syscall_arg__scnprintf_waitid_options(char *bf, size_t size,return printed; } - -#define SCA_WAITID_OPTIONS syscall_arg__scnprintf_waitid_options
tools/perf/util/Build +3 -1
@@ -75,7 +75,7 @@ perf-util-y += sample.o perf-util-y += sample-raw.o perf-util-y += s390-sample-raw.o perf-util-y += amd-sample-raw.o -perf-util-$(CONFIG_TRACE) += syscalltbl.o + perf-util-y += ordered-events.o perf-util-y += namespaces.o perf-util-y += comm.o
@@ -440,3 +440,5 @@ $(OUTPUT)%.pylint_log: % $(Q)$(call echo-cmd,test)pylint "$<" > $@ || (cat $@ && rm $@ && false) perf-util-y += $(PYLINT_TEST_LOGS) + +
tools/perf/util/bpf-trace-summary.c +1 -1
@@ -6,7 +6,7 @@#include <stdlib.h> #include "dwarf-regs.h" /* for EM_HOST */ -#include "syscalltbl.h" +#include "trace/beauty/syscalltbl.h" #include "util/cgroup.h" #include "util/hashmap.h" #include "util/trace.h"
tools/perf/util/env.c +0 -4
@@ -635,10 +635,6 @@ const char *perf_env__arch(struct perf_env *env)return normalize_arch (arch_name); } -#if defined(HAVE_LIBTRACEEVENT ) -#include "trace/beauty/arch_errno_names.c" -#endif -const char *perf_env__arch_strerrno (struct perf_env *env__maybe_unused ,int err__maybe_unused ) {#if defined(HAVE_LIBTRACEEVENT )
tools/perf/util/env.h +1 -0
@@ -189,6 +189,7 @@ void cpu_cache_level__free(struct cpu_cache_level *cache);const char *perf_env__arch (struct perf_env *env);const char *perf_env__arch_strerrno (struct perf_env *env,int err); +arch_syscalls__strerrno_t *arch_syscalls__strerrno_function (const char *arch);const char *perf_env__cpuid (struct perf_env *env);const char *perf_env__raw_arch (struct perf_env *env);int perf_env__nr_cpus_avail (struct perf_env *env);
Signature · 1 line
2.54.0.563.g4f69b47b94-goog
Ian Rogers
reviewerPATCH v6 3/14 perf build: Decouple pmu-events from prepare umbrella target
In reply to Ian RogersCurrently, the $(LIBPMU_EVENTS_IN) sub-make depends on the massive "prepare" umbrella target. Because "prepare" depends on external libraries (libapi, libperf, etc.) as well as dozens of generated headers, make completely serializes the launch of the pmu-events sub-make behind some of those unrelated prerequisites.
Since pmu-events is a large compilation unit, unblock its startup by binding it directly to only $(LIBPERF) instead of prepare. This allows background python generation scripts to overlap simultaneously with the rest of the build.
Testing a parallel build (make -j28 clean all) shows improvements:
Before:
real 0m27.642s
user 2m32.356s
sys 0m26.683sAfter:
real 0m22.254s
user 2m32.810s
sys 0m24.646sThis reclaims over 5 full seconds of build latency (~19.5% overall reduction) by elevating average CPU concurrency from ~5.5 active cores up to ~8 active cores.
--- tools/perf/Makefile.perf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/Makefile.perf +1 -1
@@ -550,7 +550,7 @@ build := -f $(srctree)/tools/build/Makefile.build dir=. obj $(PERF_IN): prepare FORCE $(Q)$(MAKE) $(build)=perf -$(LIBPMU_EVENTS_IN): FORCE prepare +$(LIBPMU_EVENTS_IN): FORCE $(LIBPERF) $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=pmu-events obj=pmu-events $(LIBPMU_EVENTS): $(LIBPMU_EVENTS_IN)
Signature · 1 line
2.54.0.563.g4f69b47b94-goog
Ian Rogers
reviewerPATCH v6 4/14 perf build: Remove empty archheaders target
In reply to Ian RogersRemove empty target that doesn't do anything.
--- tools/perf/Makefile.perf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/Makefile.perf +2 -2
@@ -627,7 +627,7 @@ endif __build-dir = $(subst $(OUTPUT),,$(dir $@)) build-dir = $(or $(__build-dir),.) -prepare: $(OUTPUT)PERF-VERSION-FILE archheaders \ +prepare: $(OUTPUT)PERF-VERSION-FILE \ arm64-sysreg-defs \ $(LIBAPI) \ $(LIBPERF) \
@@ -1070,7 +1070,7 @@ FORCE: .PHONY: all install clean config-clean strip install-gtk .PHONY: shell_compatibility_test please_set_SHELL_PATH_to_a_more_modern_shell .PHONY: .FORCE-PERF-VERSION-FILE TAGS tags cscope FORCE prepare -.PHONY: archheaders python_perf_target +.PHONY: python_perf_target endif # force_fixdep
Signature · 1 line
2.54.0.563.g4f69b47b94-goog
Ian Rogers
reviewerPATCH v6 5/14 perf build: Move BPF skeleton generation out of Makefile.perf
In reply to Ian RogersCurrently, the top-level Makefile.perf defines a massive global bpf-skel umbrella target that pre-compiles all 12+ BPF skeletons (%.skel.h) upfront before launching sub-makes. This forces unrelated sub-makes to serialize behind bpftool and clang BPF target evaluations, causing parallel build bottlenecks.
Furthermore, bench_uprobe.bpf.c lived inside util/bpf_skel/, breaking conceptual directory encapsulation since it is consumed purely by bench/uprobe.c.
Refactor the BPF skeletons to better achieve directory isolation:
1. Move tools/perf/util/bpf_skel/bench_uprobe.bpf.c directly into tools/perf/bench/bpf_skel/.
2. Extract the skeleton generation infrastructure out of Makefile.perf into a shared inclusion file tools/perf/bpf_skel.mak.
3. Include bpf_skel.mak locally inside tools/perf/util/Build and tools/perf/bench/Build and bind precise local prerequisites.
4. Safely synchronize the shared bpftool bootstrap and vmlinux.h targets via the conditional prepare: umbrella to avoid parallel sub-make races, while evaluating the actual skeletons completely locally on demand. A later patch will move these targets into bpf_skel.mak.
5. Export CLANG from the global Makefile to ensure accurate tool propagation.
6. Clean up Makefile.perf by stripping the global bpf-skel umbrella target and its SKELETONS list.
While removing code from Makefile.perf generally helps build performance, the impact here is minimal. The main motivation for the change is to better encapsulate things in the build and simplify Makefile.perf that has around 50 lines removed.
---
tools/perf/Makefile.perf | 59 ++-----------------
tools/perf/bench/Build | 6 ++
.../bpf_skel/bench_uprobe.bpf.c | 0
tools/perf/bench/uprobe.c | 2 +-
tools/perf/bpf_skel.mak | 54 +++++++++++++++++
tools/perf/util/Build | 15 ++++-
6 files changed, 79 insertions(+), 57 deletions(-)
rename tools/perf/{util => bench}/bpf_skel/bench_uprobe.bpf.c (100%)
create mode 100644 tools/perf/bpf_skel.maktools/perf/Makefile.perf +4 -55
@@ -274,7 +274,7 @@ ifeq ($(PYLINT),1) PYLINT := $(shell which pylint 2> /dev/null) endif -export srctree OUTPUT RM CC CXX RUSTC LD AR CFLAGS CXXFLAGS RUST_FLAGS V BISON FLEX AWK +export srctree OUTPUT RM CC CXX RUSTC CLANG LD AR CFLAGS CXXFLAGS RUST_FLAGS V BISON FLEX AWK LIBBPF export HOSTCC HOSTLD HOSTAR HOSTCFLAGS SHELLCHECK MYPY PYLINT include $(srctree)/tools/build/Makefile.include
@@ -632,8 +632,7 @@ prepare: $(OUTPUT)PERF-VERSION-FILE \ $(LIBAPI) \ $(LIBPERF) \ $(LIBSUBCMD) \ - $(LIBSYMBOL) \ - bpf-skel + $(LIBSYMBOL) ifdef LIBBPF_STATIC prepare: $(LIBBPF)
@@ -914,44 +913,13 @@ python-clean: SKEL_OUT := $(abspath $(OUTPUT)util/bpf_skel) SKEL_TMP_OUT := $(abspath $(SKEL_OUT)/.tmp) -SKELETONS := $(SKEL_OUT)/bpf_prog_profiler.skel.h -SKELETONS += $(SKEL_OUT)/bperf_leader.skel.h $(SKEL_OUT)/bperf_follower.skel.h -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_OUT)/sample_filter.skel.h -SKELETONS += $(SKEL_OUT)/kwork_top.skel.h $(SKEL_OUT)/syscall_summary.skel.h -SKELETONS += $(SKEL_OUT)/bench_uprobe.skel.h -SKELETONS += $(SKEL_OUT)/augmented_raw_syscalls.skel.h $(SKEL_TMP_OUT) $(LIBAPI_OUTPUT) $(LIBBPF_OUTPUT) $(LIBPERF_OUTPUT) $(LIBSUBCMD_OUTPUT) $(LIBSYMBOL_OUTPUT): $(Q)$(MKDIR) -p $@ ifeq ($(CONFIG_PERF_BPF_SKEL),y) +prepare: $(BPFTOOL) $(SKEL_OUT)/vmlinux.h BPFTOOL := $(SKEL_TMP_OUT)/bootstrap/bpftool -# Get Clang's default includes on this system, as opposed to those seen by -# '--target=bpf'. This fixes "missing" files on some architectures/distros, -# such as asm/byteorder.h, asm/socket.h, asm/sockios.h, sys/cdefs.h etc. -# -# Use '-idirafter': Don't interfere with include mechanics except where the -# build would have failed anyways. -define get_sys_includes -$(shell $(1) $(2) -v -E - </dev/null 2>&1 \ - | sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }') \ -$(shell $(1) $(2) -dM -E - </dev/null | grep '__riscv_xlen ' | awk '{printf("-D__riscv_xlen=%d -D__BITS_PER_LONG=%d", $$3, $$3)}') -endef - -ifneq ($(CROSS_COMPILE),) -CLANG_TARGET_ARCH = --target=$(notdir $(CROSS_COMPILE:%-=%)) -endif - -CLANG_OPTIONS = -Wall -CLANG_SYS_INCLUDES = $(call get_sys_includes,$(CLANG),$(CLANG_TARGET_ARCH)) -BPF_INCLUDE := -I$(SKEL_TMP_OUT)/.. -I$(LIBBPF_INCLUDE) $(CLANG_SYS_INCLUDES) -TOOLS_UAPI_INCLUDE := -I$(srctree)/tools/include/uapi - -ifneq ($(WERROR),0) - CLANG_OPTIONS += -Werror -endif $(BPFTOOL): | $(SKEL_TMP_OUT) $(Q)CFLAGS= $(MAKE) -C ../bpf/bpftool \
@@ -993,29 +961,10 @@ else $(Q)cp "$(VMLINUX_H)" $@ endif -$(SKEL_TMP_OUT)/%.bpf.o: $(OUTPUT)PERF-VERSION-FILE util/bpf_skel/perf_version.h | $(SKEL_TMP_OUT) -$(SKEL_TMP_OUT)/%.bpf.o: util/bpf_skel/%.bpf.c $(LIBBPF) $(SKEL_OUT)/vmlinux.h - $(QUIET_CLANG)$(CLANG) -g -O2 -fno-stack-protector --target=bpf \ - $(CLANG_OPTIONS) $(EXTRA_BPF_FLAGS) $(BPF_INCLUDE) $(TOOLS_UAPI_INCLUDE) \ - -include $(OUTPUT)PERF-VERSION-FILE -include util/bpf_skel/perf_version.h \ - -fms-extensions -Wno-microsoft-anon-tag \ - -c $(filter util/bpf_skel/%.bpf.c,$^) -o $@ - -$(SKEL_OUT)/%.skel.h: $(SKEL_TMP_OUT)/%.bpf.o | $(BPFTOOL) - $(QUIET_GENSKEL)$(BPFTOOL) gen skeleton $< > $@ - -bpf-skel: $(SKELETONS) - -.PRECIOUS: $(SKEL_TMP_OUT)/%.bpf.o - -else # CONFIG_PERF_BPF_SKEL - -bpf-skel: - endif # CONFIG_PERF_BPF_SKEL bpf-skel-clean: - $(call QUIET_CLEAN, bpf-skel) $(RM) -r $(SKEL_TMP_OUT) $(SKELETONS) $(SKEL_OUT)/vmlinux.h + $(call QUIET_CLEAN, bpf-skel) $(RM) -r $(SKEL_TMP_OUT) $(SKEL_OUT)/*.skel.h $(SKEL_OUT)/vmlinux.h $(OUTPUT)bench/bpf_skel/*.skel.h $(OUTPUT)bench/bpf_skel/.tmp pmu-events-clean: ifeq ($(OUTPUT),)
tools/perf/bench/Build +6 -0
@@ -24,3 +24,9 @@ perf-bench-$(CONFIG_X86_64) += mem-memcpy-x86-64-asm.o perf-bench-$(CONFIG_X86_64) += mem-memset-x86-64-asm.o perf-bench-$(CONFIG_NUMA) += numa.o + +ifeq ($(CONFIG_PERF_BPF_SKEL),y) +include $(srctree)/tools/perf/bpf_skel.mak + +$(OUTPUT)bench/uprobe.o: $(SKEL_OUT)/bench_uprobe.skel.h +endif
tools/perf/bench/bpf_skel/bench_uprobe.bpf.c renamed from tools/perf/util/bpf_skel/bench_uprobe.bpf.c +0 -0
tools/perf/bench/uprobe.c +1 -1
@@ -44,7 +44,7 @@ static const char * const bench_uprobe_usage[] = { };#ifdef HAVE_BPF_SKEL -#include "bpf_skel/bench_uprobe.skel.h" +#include "bench/bpf_skel/bench_uprobe.skel.h" #define bench_uprobe__attach_uprobe(prog) \ skel->links.prog = bpf_program__attach_uprobe_opts(/*prog=*/skel->progs.prog, \
tools/perf/bpf_skel.mak new file +54 -0
54 lines not on this page · raw message
tools/perf/util/Build +14 -1
@@ -441,4 +441,17 @@ $(OUTPUT)%.pylint_log: % perf-util-y += $(PYLINT_TEST_LOGS) - +ifeq ($(CONFIG_PERF_BPF_SKEL),y) +include $(srctree)/tools/perf/bpf_skel.mak + +$(OUTPUT)util/bpf_ftrace.o: $(SKEL_OUT)/func_latency.skel.h +$(OUTPUT)util/bpf-filter.o: $(SKEL_OUT)/sample_filter.skel.h +$(OUTPUT)util/bpf_kwork_top.o: $(SKEL_OUT)/kwork_top.skel.h +$(OUTPUT)util/bpf_off_cpu.o: $(SKEL_OUT)/off_cpu.skel.h +$(OUTPUT)util/bpf-trace-summary.o: $(SKEL_OUT)/syscall_summary.skel.h +$(OUTPUT)util/bpf_counter_cgroup.o: $(SKEL_OUT)/bperf_cgroup.skel.h +$(OUTPUT)util/bpf_trace_augment.o: $(SKEL_OUT)/augmented_raw_syscalls.skel.h +$(OUTPUT)util/bpf_counter.o: $(SKEL_OUT)/bpf_prog_profiler.skel.h $(SKEL_OUT)/bperf_leader.skel.h $(SKEL_OUT)/bperf_follower.skel.h +$(OUTPUT)util/bpf_lock_contention.o: $(SKEL_OUT)/lock_contention.skel.h +$(OUTPUT)util/bpf_kwork.o: $(SKEL_OUT)/kwork_trace.skel.h +endif
Signature · 1 line
2.54.0.563.g4f69b47b94-goog
Ian Rogers
reviewerPATCH v6 6/14 perf build: Encapsulate vmlinux.h and bpftool in bpf_skel.mak
In reply to Ian RogersCurrently, bpftool and vmlinux.h are prerequisites of the top-level prepare target in Makefile.perf. This unnecessarily blocks the massive parallel C compilation of libraries (perf-util, perf-ui, pmu-events) during the initial startup phase.
Move all bpftool and vmlinux.h generation rules down into tools/perf/bpf_skel.mak to encapsulate BPF tooling completely within the skeleton framework. Remove them entirely from prepare to unblock immediate parallel build execution.
To prevent parallel sub-makes (perf-util and perf-bench) from racing to build shared prerequisites concurrently, while maintaining strict directory encapsulation without top-level inclusions, serialize bench after the util static archive finishes using an order-only prerequisite:
$(LIBPERF_BENCH_IN): FORCE prepare | $(LIBPERF_UTIL)
--- tools/perf/Makefile.config | 2 +- tools/perf/Makefile.perf | 61 +++++--------------------------------- tools/perf/bpf_skel.mak | 47 +++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 55 deletions(-)
tools/perf/Makefile.config +1 -1
@@ -681,7 +681,7 @@ ifeq ($(BUILD_BPF_SKEL),1) endif ifndef GEN_VMLINUX_H - VMLINUX_H=$(src-perf)/util/bpf_skel/vmlinux/vmlinux.h + VMLINUX_H_FILE=$(src-perf)/util/bpf_skel/vmlinux/vmlinux.h endif ifndef NO_LIBUNWIND
tools/perf/Makefile.perf +7 -54
88 lines not on this page · raw message
tools/perf/bpf_skel.mak +47 -0
57 lines not on this page · raw message
Signature · 1 line
2.54.0.563.g4f69b47b94-goog
Ian Rogers
reviewerPATCH v6 7/14 perf build: Pre-generate BPF skeleton tooling during umbrella prepare phase
In reply to Ian RogersCurrently, BPF skeleton generation rules (bpf_skel.mak) are evaluated as part of util/Build. However, because LIBPERF_UTIL_IN explicitly depends on the top-level static libbpf archive, Make completely blocked the execution of bpftool bootstrap and skeleton generation until libbpf finished compiling midway through the build.
Since bpftool bootstrap compiles its own independent copy of libbpf.a, it does not depend on the top-level libbpf target.
Decouple early skeleton tooling generation by attaching bpf-skel-prepare to the umbrella prepare target, exporting CONFIG_PERF_BPF_SKEL to ensure accurate feature propagation. This allows Make to compile bpftool and dump vmlinux.h in the background at build startup, eliminating the initial sub-make startup bottleneck before BPF object compilation while keeping 100% of tooling rules perfectly encapsulated in bpf_skel.mak. Provide an empty fallback target to ensure builds succeed when BPF skeletons are disabled.
--- tools/perf/Makefile.perf | 8 ++++++-- tools/perf/bpf_skel.mak | 8 ++++++++ 2 files changed, 14 insertions(+), 2 deletions(-)
tools/perf/Makefile.perf +6 -2
@@ -275,7 +275,7 @@ ifeq ($(PYLINT),1) endif export srctree OUTPUT RM CC CXX RUSTC CLANG LD AR CFLAGS CXXFLAGS RUST_FLAGS V BISON FLEX AWK LIBBPF READELF -export HOSTCC HOSTLD HOSTAR HOSTCFLAGS SHELLCHECK MYPY PYLINT +export HOSTCC HOSTLD HOSTAR HOSTCFLAGS SHELLCHECK MYPY PYLINT CONFIG_PERF_BPF_SKEL include $(srctree)/tools/build/Makefile.include
@@ -629,8 +629,12 @@ endif __build-dir = $(subst $(OUTPUT),,$(dir $@)) build-dir = $(or $(__build-dir),.) +bpf-skel-prepare: + $(Q)$(MAKE) -f bpf_skel.mak bpf-skel-prepare + prepare: $(OUTPUT)PERF-VERSION-FILE \ arm64-sysreg-defs \ + bpf-skel-prepare \ $(LIBAPI) \ $(LIBPERF) \ $(LIBSUBCMD) \
@@ -971,7 +975,7 @@ FORCE: .PHONY: all install clean config-clean strip install-gtk .PHONY: shell_compatibility_test please_set_SHELL_PATH_to_a_more_modern_shell -.PHONY: .FORCE-PERF-VERSION-FILE TAGS tags cscope FORCE prepare +.PHONY: .FORCE-PERF-VERSION-FILE TAGS tags cscope FORCE prepare bpf-skel-prepare .PHONY: python_perf_target endif # force_fixdep
tools/perf/bpf_skel.mak +8 -0
@@ -15,6 +15,10 @@ ifeq ($(CONFIG_PERF_BPF_SKEL),y) BPFTOOL := $(SKEL_TOOL_TMP_OUT)/bootstrap/bpftool VMLINUX_H := $(SKEL_TOOL_OUT)/vmlinux.h +.PHONY: bpf-skel-prepare +bpf-skel-prepare: $(BPFTOOL) $(VMLINUX_H) + @: + define get_sys_includes $(shell $(1) $(2) -v -E - </dev/null 2>&1 \ | sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }') \
@@ -93,6 +97,10 @@ $(SKEL_OUT)/%.skel.h: $(SKEL_TMP_OUT)/%.bpf.o $(BPFTOOL) .PRECIOUS: $(SKEL_TMP_OUT)/%.bpf.o +else # CONFIG_PERF_BPF_SKEL +.PHONY: bpf-skel-prepare +bpf-skel-prepare: + @: endif # CONFIG_PERF_BPF_SKEL clean:
Signature · 1 line
2.54.0.563.g4f69b47b94-goog
Ian Rogers
reviewerPATCH v6 8/14 perf build: Move libsymbol dependency out of prepare step
In reply to Ian RogersThe prepare step is a large serialization point before parallel sub-makes build the perf tool. The libsymbol headers are used in the bench and util libraries. Move the libsymbol dependency out of the prepare step and into the dependencies for those targets to avoid it being a source of serialization in the prepare step.
--- tools/perf/Makefile.perf | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
tools/perf/Makefile.perf +3 -4
@@ -558,7 +558,7 @@ $(LIBPMU_EVENTS): $(LIBPMU_EVENTS_IN) # The $(LIBPERF_UTIL) dependency is to ensure bpftool and vmlinux.h # aren't racily built for bench/bpf_skel/bench_uprobe.bpf.c -$(LIBPERF_BENCH_IN): FORCE prepare | $(LIBPERF_UTIL) +$(LIBPERF_BENCH_IN): FORCE prepare $(LIBSYMBOL) | $(LIBPERF_UTIL) $(Q)$(MAKE) $(build)=perf-bench $(LIBPERF_BENCH): $(LIBPERF_BENCH_IN)
@@ -576,7 +576,7 @@ $(LIBPERF_UI_IN): FORCE prepare $(LIBPERF_UI): $(LIBPERF_UI_IN) $(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $< -$(LIBPERF_UTIL_IN): FORCE prepare +$(LIBPERF_UTIL_IN): FORCE prepare $(LIBSYMBOL) $(Q)$(MAKE) $(build)=perf-util $(LIBPERF_UTIL): $(LIBPERF_UTIL_IN)
@@ -637,8 +637,7 @@ prepare: $(OUTPUT)PERF-VERSION-FILE \ bpf-skel-prepare \ $(LIBAPI) \ $(LIBPERF) \ - $(LIBSUBCMD) \ - $(LIBSYMBOL) + $(LIBSUBCMD) ifdef LIBBPF_STATIC prepare: $(LIBBPF)
Signature · 1 line
2.54.0.563.g4f69b47b94-goog
Ian Rogers
reviewerPATCH v6 9/14 perf build: Remove redundant libbpf feature check for static builds
In reply to Ian RogersBy default, the perf tool compiles and statically links against its own internal copy of libbpf (tools/lib/bpf/libbpf.a), setting LIBBPF_STATIC=1.
Despite this static linkage, Makefile.config unconditionally executed $(call feature_check,libbpf), which forced a synchronous sub-make fork during AST parsing to detect dynamic system libbpf libraries.
As noted in the internal Makefile comments, this check was executed purely so that running make VF=1 would display the detection status of system libbpf. During standard builds without LIBBPF_DYNAMIC=1, the detection result was entirely ignored.
Wrap the libbpf feature check inside LIBBPF_DYNAMIC=1 so Make avoids the redundant sub-make fork overhead during standard static builds.
--- tools/perf/Makefile.config | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
tools/perf/Makefile.config +1 -3
@@ -575,10 +575,8 @@ ifndef NO_LIBELF ifndef NO_LIBBPF ifeq ($(feature-bpf), 1) - # detecting libbpf without LIBBPF_DYNAMIC, so make VF=1 shows libbpf detection status - $(call feature_check,libbpf) - ifdef LIBBPF_DYNAMIC + $(call feature_check,libbpf) ifeq ($(feature-libbpf), 1) EXTLIBS += -lbpf CFLAGS += -DHAVE_LIBBPF_SUPPORT
Signature · 1 line
2.54.0.563.g4f69b47b94-goog
Ian Rogers
reviewerPATCH v6 10/14 perf pmu-events: Split big_c_string storage into standalone compilation unit
In reply to Ian RogersCurrently, jevents.py emits both the massive 2.8 MB big_c_string literal and tens of thousands of compact_pmu_event struct arrays into a single pmu-events.c compilation unit. Compiling this giant file takes ~2.2 seconds on a single CPU core during Kbuild startup.
Refactor jevents.py to emit big_c_string into a dedicated pmu-events-string.c compilation unit. This allows Kbuild to compile pmu-events.o and pmu-events-string.o simultaneously in parallel across two separate CPU cores, preserving 100% string deduplication and zero dynamic ELF relocations while cutting C compilation latency in half.
Add pmu-events-string.c to tools/perf/.gitignore to ensure in-tree Kbuild runs do not leave untracked generated files in the working directory.
To guarantee 100% backward compatibility with GNU Make 4.0+ (avoiding the Make 4.3+ grouped target &: syntax which causes older Make versions like 4.2.1 to spawn multiple concurrent jevents.py processes during parallel builds), implement a robust dependency chaining pattern:
$(PMU_EVENTS_C): $(JEVENTS_DEPS)
$(PMU_EVENTS_STRING_C): $(PMU_EVENTS_C)
@:
This ensures jevents.py is invoked exactly once. If jevents.py aborts early, Make's .DELETE_ON_ERROR: purges pmu-events.c, guaranteeing that subsequent Make invocations correctly re-execute the script and overwrite pmu-events-string.c. In jevents.py, explicitly close output_file first and output_string_file second at the tail of main() to guarantee that pmu-events-string.c receives a filesystem timestamp greater than or equal to pmu-events.c, completely avoiding redundant incremental rebuilds.
--- tools/perf/.gitignore | 1 + tools/perf/Makefile.perf | 4 ++-- tools/perf/pmu-events/Build | 16 +++++++++++++++- tools/perf/pmu-events/jevents.py | 23 +++++++++++++++++++---- 4 files changed, 37 insertions(+), 7 deletions(-)
tools/perf/.gitignore +1 -0
@@ -38,6 +38,7 @@ arch/*/include/generated/ trace/beauty/generated/ pmu-events/arch/common/common/legacy-cache.json pmu-events/pmu-events.c +pmu-events/pmu-events-string.c pmu-events/jevents pmu-events/metric_test.log pmu-events/empty-pmu-events.log
tools/perf/Makefile.perf +2 -2
@@ -925,7 +925,7 @@ bpf-skel-clean: pmu-events-clean: ifeq ($(OUTPUT),) $(call QUIET_CLEAN, pmu-events) $(RM) \ - pmu-events/pmu-events.c \ + pmu-events/pmu-events*.c \ pmu-events/metric_test.log \ pmu-events/test-empty-pmu-events.c \ pmu-events/empty-pmu-events.log
@@ -933,7 +933,7 @@ ifeq ($(OUTPUT),) -name 'extra-metricgroups.json' -delete else # When an OUTPUT directory is present, clean up the copied pmu-events/arch directory. $(call QUIET_CLEAN, pmu-events) $(RM) -r $(OUTPUT)pmu-events/arch \ - $(OUTPUT)pmu-events/pmu-events.c \ + $(OUTPUT)pmu-events/pmu-events*.c \ $(OUTPUT)pmu-events/metric_test.log \ $(OUTPUT)pmu-events/test-empty-pmu-events.c \ $(OUTPUT)pmu-events/empty-pmu-events.log
tools/perf/pmu-events/Build +15 -1
@@ -1,7 +1,12 @@ EMPTY_PMU_EVENTS_C = pmu-events/empty-pmu-events.c # pmu-events.c will be generated by jevents.py or copied from EMPTY_PMU_EVENTS_C PMU_EVENTS_C = $(OUTPUT)pmu-events/pmu-events.c +PMU_EVENTS_STRING_C = $(OUTPUT)pmu-events/pmu-events-string.c + pmu-events-y += pmu-events.o +ifneq ($(NO_JEVENTS),1) +pmu-events-y += pmu-events-string.o +endif # pmu-events.c file is generated in the OUTPUT directory so it needs a # separate rule to depend on it properly
@@ -9,6 +14,10 @@ $(OUTPUT)pmu-events/pmu-events.o: $(PMU_EVENTS_C) $(call rule_mkdir) $(call if_changed_dep,cc_o_c) +$(OUTPUT)pmu-events/pmu-events-string.o: $(PMU_EVENTS_STRING_C) + $(call rule_mkdir) + $(call if_changed_dep,cc_o_c) + # Message for $(call echo-cmd,cp), possibly remove the src file from # the destination to save space in the build log. quiet_cmd_cp = COPY $(patsubst %$<,%,$@) <- $<
@@ -118,6 +127,7 @@ CUR_OUT_JSON := $(shell [ -d $(OUT_DIR) ] && find $(OUT_DIR) -type f) # Things in the OUTPUT directory but shouldn't be there as computed by # OUT_JSON and GEN_JSON. + ORPHAN_FILES := $(filter-out $(OUT_JSON) $(GEN_JSON),$(CUR_OUT_JSON)) # Message for $(call echo-cmd,mkd). There is already a mkdir message
@@ -224,6 +234,10 @@ endif # and inputs are dependencies. $(PMU_EVENTS_C): $(JEVENTS_DEPS) $(call rule_mkdir) - $(Q)$(call echo-cmd,gen)$(PYTHON) $(JEVENTS_PY) $(JEVENTS_ARCH) $(JEVENTS_MODEL) $(OUT_DIR) $@ + $(Q)$(call echo-cmd,gen)$(PYTHON) $(JEVENTS_PY) $(JEVENTS_ARCH) $(JEVENTS_MODEL) \ + $(OUT_DIR) $(PMU_EVENTS_C) $(PMU_EVENTS_STRING_C) + +$(PMU_EVENTS_STRING_C): $(PMU_EVENTS_C) + @: endif # ifeq ($(NO_JEVENTS),1)
tools/perf/pmu-events/jevents.py +19 -4
@@ -1422,6 +1422,8 @@ such as "arm/cortex-a34".''', ) ap.add_argument( 'output_file', type=argparse.FileType('w', encoding='utf-8'), nargs='?', default=sys.stdout) + ap.add_argument( + 'output_string_file', type=argparse.FileType('w', encoding='utf-8'), nargs='?', default=None) _args = ap.parse_args() _args.output_file.write(f"""
@@ -1463,10 +1465,20 @@ struct pmu_table_entry { ftw(arch_path, [], preprocess_one_file) _bcs.compute() - _args.output_file.write('static const char *const big_c_string =\n') - for s in _bcs.big_string: - _args.output_file.write(s) - _args.output_file.write(';\n\n') + if not _args.output_string_file: + _args.output_file.write('static const char *const big_c_string =\n') + for s in _bcs.big_string: + _args.output_file.write(s) + _args.output_file.write(';\n\n') + else: + _args.output_string_file.write('/* SPDX-License-Identifier: GPL-2.0 */\n') + _args.output_string_file.write('/* Autogenerated by jevents.py */\n') + _args.output_string_file.write('extern const char big_c_string[];\n') + _args.output_string_file.write('const char big_c_string[] =\n') + for s in _bcs.big_string: + _args.output_string_file.write(s) + _args.output_string_file.write(';\n') + _args.output_file.write('extern const char big_c_string[];\n\n') for arch in archs: arch_path = f'{_args.starting_dir}/{arch}' ftw(arch_path, [], process_one_file)
@@ -1476,6 +1488,9 @@ struct pmu_table_entry { print_mapping_table(archs) print_system_mapping_table() print_metricgroups() + _args.output_file.close() + if _args.output_string_file: + _args.output_string_file.close() if __name__ == '__main__': main()
Signature · 1 line
2.54.0.563.g4f69b47b94-goog
Ian Rogers
reviewerPATCH v6 11/14 perf pmu-events: Parallelize JSON and metric pre-computation in jevents.py
In reply to Ian RogersCurrently, jevents.py parses hundreds of JSON event and metric files sequentially across all CPU architectures during Kbuild startup, taking ~3.3 seconds of pure single-core execution time.
Refactor jevents.py to pre-populate its internal JSON AST cache in parallel across all available CPU cores using ProcessPoolExecutor. Define the worker process initializer _init_worker at the top-level module scope to guarantee flawless pickling and standard event mapping inheritance under spawn multiprocessing semantics (avoiding AttributeError crashes when spawn is used instead of fork). This accelerates jevents.py execution by over 11x (from 3.3s down to ~290ms), fully reclaiming multi-core concurrency during the build generation phase.
--- tools/perf/pmu-events/jevents.py | 36 ++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-)
tools/perf/pmu-events/jevents.py +32 -4
@@ -457,8 +457,8 @@ class JsonEvent: return f'{{ { _bcs.offsets[s] } }}, /* {fix_comment(s)} */\n' -@lru_cache(maxsize=None) -def read_json_events(path: str, topic: str) -> Sequence[JsonEvent]: +_json_cache = {} +def _read_json_events_impl(path: str, topic: str) -> Sequence[JsonEvent]: """Read json events from the specified file.""" try: events = json.load(open(path), object_hook=JsonEvent)
@@ -474,12 +474,16 @@ def read_json_events(path: str, topic: str) -> Sequence[JsonEvent]: if updates: for event in events: if event.metric_name in updates: - # print(f'Updated {event.metric_name} from\n"{event.metric_expr}"\n' - # f'to\n"{updates[event.metric_name]}"') event.metric_expr = updates[event.metric_name] return events +def read_json_events(path: str, topic: str) -> Sequence[JsonEvent]: + key = (path, topic) + if key not in _json_cache: + _json_cache[key] = _read_json_events_impl(path, topic) + return _json_cache[key] + def preprocess_arch_std_files(archpath: str) -> None: """Read in all architecture standard events.""" global _arch_std_events
@@ -1381,6 +1385,14 @@ const char *describe_metricgroup(const char *group) } """) +def _parallel_read_json_events(task: Tuple[str, str]) -> Tuple[str, str, Sequence[JsonEvent]]: + path, topic = task + return path, topic, _read_json_events_impl(path, topic) + +def _init_worker(std_events: dict) -> None: + global _arch_std_events + _arch_std_events = std_events + def main() -> None: global _args
@@ -1459,9 +1471,25 @@ struct pmu_table_entry { raise IOError(f'Missing architecture directory \'{_args.arch}\'') archs.sort() + import concurrent.futures + tasks = [] + def collect_json(parents: Sequence[str], item: os.DirEntry) -> None: + if len(parents) == 0: + return + if item.is_file() and item.name.endswith('.json') and not item.name.endswith('metricgroups.json'): + tasks.append((item.path, get_topic(item.name))) + for arch in archs: arch_path = f'{_args.starting_dir}/{arch}' preprocess_arch_std_files(arch_path) + ftw(arch_path, [], collect_json) + + with concurrent.futures.ProcessPoolExecutor(initializer=_init_worker, initargs=(_arch_std_events,)) as executor: + for path, topic, events in executor.map(_parallel_read_json_events, tasks): + _json_cache[(path, topic)] = events + + for arch in archs: + arch_path = f'{_args.starting_dir}/{arch}' ftw(arch_path, [], preprocess_one_file) _bcs.compute()
Signature · 1 line
2.54.0.563.g4f69b47b94-goog
Ian Rogers
reviewerPATCH v6 12/14 perf build: Prefix SCRIPTS with output directory to fix continuous rebuilds
In reply to Ian RogersIn Makefile.perf, ALL_PROGRAMS includes SCRIPTS (perf-archive, perf-iostat). However, unlike PROGRAMS and DLFILTERS, SCRIPTS was not prefixed with $(OUTPUT).
During out-of-tree builds (or when O= is specified), Make checked for the unprefixed target 'tools/perf/perf-archive'. Since the actual script was installed into $(OUTPUT)perf-archive, Make concluded the target was missing and continuously re-executed the script installation rule on every single incremental build.
Prefix SCRIPTS with $(OUTPUT) and update the static pattern rule to ensure Kbuild correctly tracks generated script prerequisites during incremental builds.
--- tools/perf/Makefile.perf | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
tools/perf/Makefile.perf +3 -3
@@ -405,7 +405,7 @@ python-clean := $(call QUIET_CLEAN, python) $(RM) -r $(PYTHON_EXTBUILD) $(OUTPUT # Use the detected configuration -include $(OUTPUT).config-detected -SCRIPTS = $(patsubst %.sh,%,$(SCRIPT_SH)) +SCRIPTS = $(addprefix $(OUTPUT),$(patsubst %.sh,%,$(SCRIPT_SH))) PROGRAMS += $(OUTPUT)perf
@@ -592,8 +592,8 @@ $(GTK_IN): FORCE prepare $(OUTPUT)libperf-gtk.so: $(GTK_IN) $(PERFLIBS) $(QUIET_LINK)$(CC) -o $@ -shared $(LDFLAGS) $(filter %.o,$^) $(GTK_LIBS) -$(SCRIPTS) : % : %.sh - $(QUIET_GEN)$(INSTALL) '[email protected]' '$(OUTPUT)$@' +$(SCRIPTS) : $(OUTPUT)% : %.sh + $(QUIET_GEN)$(INSTALL) '$<' '$@' $(OUTPUT)PERF-VERSION-FILE: .FORCE-PERF-VERSION-FILE $(Q)$(SHELL_PATH) util/PERF-VERSION-GEN $(OUTPUT)
Signature · 1 line
2.54.0.563.g4f69b47b94-goog
Ian Rogers
reviewerPATCH v6 13/14 perf pmu-events: Convert recursive shell assignments and macros to Make built-ins
In reply to Ian RogersIn pmu-events/Build, ZENS, ARMS, and INTELS were assigned using recursive assignment (=), and model_name/vendor_name were evaluated using shell macros (echo ... | sed ...).
Because these variables were expanded inside the COPY_RULE dependency evaluation loop across hundreds of PMU JSON files and inside every metric generation recipe, Kbuild continuously re-executed 'ls', 'grep', and 'sed' shell forks thousands of times during AST parsing and execution.
Convert ZENS, ARMS, and INTELS to simply expanded variables (:=) and replace model_name/vendor_name with pure GNU Make string functions. This guarantees Make executes directory probing shell forks exactly once when the Build file is parsed and evaluates path macros purely in memory, completely eliminating over 7,800 redundant sub-processes during build startup.
--- tools/perf/pmu-events/Build | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
tools/perf/pmu-events/Build +5 -5
@@ -56,12 +56,12 @@ $(LEGACY_CACHE_JSON): $(LEGACY_CACHE_PY) # Python to generate architectural metrics GEN_METRIC_DEPS := pmu-events/metric.py pmu-events/common_metrics.py # Functions to extract the model from an extra-metrics.json or extra-metricgroups.json path. -model_name = $(shell echo $(1)|sed -e 's@.\+/\(.*\)/extra-metric.*\.json@\1@') -vendor_name = $(shell echo $(1)|sed -e 's@.\+/\(.*\)/[^/]*/extra-metric.*\.json@\1@') +model_name = $(notdir $(patsubst %/,%,$(dir $(1)))) +vendor_name = $(notdir $(patsubst %/,%,$(dir $(patsubst %/,%,$(dir $(1)))))) ifeq ($(JEVENTS_ARCH),$(filter $(JEVENTS_ARCH),x86 all)) # Generate AMD Json -ZENS = $(shell ls -d pmu-events/arch/x86/amdzen*) +ZENS := $(shell ls -d pmu-events/arch/x86/amdzen*) ZEN_METRICS = $(foreach x,$(ZENS),$(OUTPUT)$(x)/extra-metrics.json) ZEN_METRICGROUPS = $(foreach x,$(ZENS),$(OUTPUT)$(x)/extra-metricgroups.json) GEN_JSON += $(ZEN_METRICS) $(ZEN_METRICGROUPS)
@@ -78,7 +78,7 @@ endif ifeq ($(JEVENTS_ARCH),$(filter $(JEVENTS_ARCH),arm64 all)) # Generate ARM Json -ARMS = $(shell ls -d pmu-events/arch/arm64/arm/*|grep -v cmn) +ARMS := $(shell ls -d pmu-events/arch/arm64/arm/*|grep -v cmn) ARM_METRICS = $(foreach x,$(ARMS),$(OUTPUT)$(x)/extra-metrics.json) ARM_METRICGROUPS = $(foreach x,$(ARMS),$(OUTPUT)$(x)/extra-metricgroups.json) GEN_JSON += $(ARM_METRICS) $(ARM_METRICGROUPS)
@@ -95,7 +95,7 @@ endif ifeq ($(JEVENTS_ARCH),$(filter $(JEVENTS_ARCH),x86 all)) # Generate Intel Json -INTELS = $(shell ls -d pmu-events/arch/x86/*|grep -v amdzen|grep -v mapfile.csv) +INTELS := $(shell ls -d pmu-events/arch/x86/*|grep -v amdzen|grep -v mapfile.csv) INTEL_METRICS = $(foreach x,$(INTELS),$(OUTPUT)$(x)/extra-metrics.json) INTEL_METRICGROUPS = $(foreach x,$(INTELS),$(OUTPUT)$(x)/extra-metricgroups.json) GEN_JSON += $(INTEL_METRICS) $(INTEL_METRICGROUPS)
Signature · 1 line
2.54.0.563.g4f69b47b94-goog
Ian Rogers
reviewerPATCH v6 14/14 perf build: Convert llvm-config shell queries to simply expanded variables
In reply to Ian RogersIn Makefile.config, CFLAGS, CXXFLAGS, LIBLLVM, and EXTLIBS were assigned using recursive expansion or appended with raw $(shell $(LLVM_CONFIG) ...) calls. Because these variables were expanded during dependency evaluation across every single object file compilation rule, Kbuild continuously re-executed llvm-config forks nearly 200 times during incremental builds.
Convert llvm-config shell queries to simply expanded variables (:=) to ensure Make evaluates LLVM compiler flags and library paths exactly once when Makefile.config is parsed, eliminating ~185 redundant sub-processes during build startup.
--- tools/perf/Makefile.config | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
tools/perf/Makefile.config +8 -5
@@ -925,11 +925,14 @@ ifndef NO_LIBLLVM $(call feature_check,llvm-perf) ifeq ($(feature-llvm-perf), 1) CFLAGS += -DHAVE_LIBLLVM_SUPPORT - CFLAGS += $(shell $(LLVM_CONFIG) --cflags) - CXXFLAGS += -DHAVE_LIBLLVM_SUPPORT - CXXFLAGS += $(shell $(LLVM_CONFIG) --cxxflags) - LIBLLVM = $(shell $(LLVM_CONFIG) --libs all) $(shell $(LLVM_CONFIG) --system-libs) - EXTLIBS += -L$(shell $(LLVM_CONFIG) --libdir) $(LIBLLVM) + LLVM_CFLAGS := $(shell $(LLVM_CONFIG) --cflags 2>/dev/null) + LLVM_CXXFLAGS := $(shell $(LLVM_CONFIG) --cxxflags 2>/dev/null) + LLVM_LIBLLVM := $(shell $(LLVM_CONFIG) --libs all 2>/dev/null) $(shell $(LLVM_CONFIG) --system-libs 2>/dev/null) + LLVM_LIBDIR := $(shell $(LLVM_CONFIG) --libdir 2>/dev/null) + CFLAGS += $(LLVM_CFLAGS) + CXXFLAGS += -DHAVE_LIBLLVM_SUPPORT $(LLVM_CXXFLAGS) + LIBLLVM := $(LLVM_LIBLLVM) + EXTLIBS += -L$(LLVM_LIBDIR) $(LIBLLVM) EXTLIBS += -lstdc++ $(call detected,CONFIG_LIBLLVM) else
Signature · 1 line
2.54.0.563.g4f69b47b94-goog
Ian Rogers
reviewerv7 cover perf build: Reduce build time by nearly half
In reply to Ian RogersThis patch series refactors Kbuild internals, BPF skeleton generation, Python AST pre-computation, and foundational tooling dependencies across the perf tool build system. By eliminating umbrella target synchronization barriers, decoupling static library prerequisites, parallelizing single-core script generators, and eradicating redundant feature checks, this series unlocks absolute theoretical peak multi-core concurrency during Kbuild startup.
On a 28-core build workstation (make -j28 all from scratch), clean build latency improves by over 44%:
Before:
real 0m29.006s
user 2m46.019s
sys 0m30.610sAfter:
real 0m16.091s
user 2m40.135s
sys 0m25.740sSaving 12.9 full seconds time per clean build. Furthermore, nothing to build incremental builds are improved by nearly 7x:
Before:
real 0m11.528s
user 0m9.633s
sys 0m6.965sAfter:
real 0m1.717s
user 0m1.682s
sys 0m0.960sSummary of Patches:
1: Fast-Path Feature Detection
- Refactors test-clang-bpf-co-re.bin and test-bpftool-skeletons.bin feature checks to group shell pipelines within curly braces and redirect both stdout and stderr to .make.output before touching $@ purely upon success
(> $(@:.bin=.make.output) 2>&1 && touch $@). Grouping the pipeline ({ cmd1 | cmd2; }) ensures that compiler stderr is successfully captured in .make.output rather than escaping to the parent shell. This perfectly matches standard Kbuild feature check conventions and ensures the target files are touched on disk purely upon success, allowing Kbuild to cache positive detections and avoid continuous sub-make re-evaluations during incremental builds. Adds test-bpftool-skeletons.bin to the clean FILES list and explicit source prerequisite test-clang-bpf-co-re.c.
2-4: Flattening Umbrella Prepare Barriers
- builtin-trace embedded inclusions and pmu-events generation are completely decoupled from the sequential "prepare" umbrella target, eliminating Make AST double-parsing overhead and unchoking parallel compilation barriers.
5-7: Decoupling & Pre-generating BPF Skeletons
- BPF skeleton rules are extracted out of Makefile.perf into bpf_skel.mak.
- Decouples bpftool bootstrap from top-level static libbpf dependencies, attaching bpf-skel-prepare directly to the umbrella prepare target. This allows Make to pre-compile bpftool and dump vmlinux.h in the background at build startup, removing the 7-second serialization bottleneck before BPF object compilation.
- Ensures benchmark skeleton intermediate .bpf.o files are cleanly removed during make clean, and adds bpf-skel-prepare to .PHONY.
8-9: Foundational Linkage Optimization
- Moves static libsymbol library prerequisites out of the prepare step.
- Eliminates redundant libbpf sub-make feature checks during static builds.
10-11: jevents.py Concurrency & Deduplication
- Splits the massive 2.8 MB big_c_string literal out of pmu-events.c into a dedicated pmu-events-string.c compilation unit. This slices C compilation latency in half by compiling string and struct tables simultaneously across separate CPU cores while preserving zero dynamic ELF relocations. Adds pmu-events-string.c to .gitignore, declares extern const char big_c_string[]; locally inside output_string_file and output_file when split to prevent linkage conflicts with empty-pmu-events.c, defers file closures to ensure identical timestamps, and uses canonical Make 4.0 @: dependency chaining.
- Pre-populates jevents.py JSON ASTs and metric formulas in parallel across all available CPU cores using ProcessPoolExecutor (accelerating Python execution by 11x, from 3.3s down to ~290ms). Moves _init_worker to top-level scope to ensure clean pickling under spawn multiprocessing start methods.
12: Out-of-Tree Incremental Rebuild Fix
- Prefixes SCRIPTS (perf-archive, perf-iostat) with $(OUTPUT) to prevent Make from continuously re-executing script installation rules on already built out-of-tree builds.
13-14: AST Parsing Optimization & Shell Fork Eradication
- Converts ZENS, ARMS, and INTELS in pmu-events/Build from recursive assignment (=) to simply expanded assignment (:=) and replaces model_name/vendor_name with pure GNU Make string functions. This guarantees Make executes directory probing shell forks exactly once during AST parsing and evaluates path macros purely in memory, completely eradicating over 7,800 redundant sub-processes during out-of-tree build evaluation.
- Converts llvm-config shell queries in Makefile.config from recursive assignment (=) to simply expanded assignment (:=). This eliminates ~185 redundant sub-processes that were previously executed across object compilation dependency checks.
Changes since v6:
- Rebase/resend as last series failed to apply by Sashiko.
Ian Rogers (14):
tools build: Fix feature checks to touch target files on success perf trace beauty: Make beauty generated C code standalone .o files perf build: Decouple pmu-events from prepare umbrella target perf build: Remove empty archheaders target
perf build: Move BPF skeleton generation out of Makefile.perf perf build: Encapsulate vmlinux.h and bpftool in bpf_skel.mak perf build: Pre-generate BPF skeleton tooling during umbrella prepare
phase
perf build: Move libsymbol dependency out of prepare step perf build: Remove redundant libbpf feature check for static builds perf pmu-events: Split big_c_string storage into standalone
compilation unit
perf pmu-events: Parallelize JSON and metric pre-computation in
jevents.py
perf build: Prefix SCRIPTS with output directory to fix continuous
rebuilds
perf pmu-events: Convert recursive shell assignments and macros to
Make built-ins
perf build: Convert llvm-config shell queries to simply expanded
variables
tools/build/feature/Makefile | 13 +-
tools/perf/.gitignore | 1 +
tools/perf/Build | 2 +
tools/perf/Makefile.config | 19 +-
tools/perf/Makefile.perf | 423 ++----------------
tools/perf/bench/Build | 6 +
.../bpf_skel/bench_uprobe.bpf.c | 0
tools/perf/bench/uprobe.c | 2 +-
tools/perf/bpf_skel.mak | 109 +++++
tools/perf/builtin-trace.c | 32 +-
tools/perf/pmu-events/Build | 26 +-
tools/perf/pmu-events/jevents.py | 59 ++-
tools/perf/trace/beauty/Build | 276 ++++++++++++
tools/perf/trace/beauty/arch_errno_names.c | 2 +
tools/perf/trace/beauty/arch_errno_names.sh | 2 +-
tools/perf/trace/beauty/beauty.h | 60 +++
tools/perf/trace/beauty/eventfd.c | 6 +-
tools/perf/trace/beauty/fsconfig.c | 5 +
tools/perf/trace/beauty/futex_op.c | 5 +-
tools/perf/trace/beauty/futex_val3.c | 5 +-
tools/perf/trace/beauty/mmap.c | 24 +-
tools/perf/trace/beauty/mode_t.c | 6 +-
tools/perf/trace/beauty/msg_flags.c | 8 +-
tools/perf/trace/beauty/open_flags.c | 2 +
tools/perf/trace/beauty/perf_event_open.c | 21 +-
tools/perf/trace/beauty/pid.c | 5 +-
tools/perf/trace/beauty/sched_policy.c | 8 +-
tools/perf/trace/beauty/seccomp.c | 12 +-
tools/perf/trace/beauty/signum.c | 6 +-
tools/perf/trace/beauty/socket_type.c | 6 +-
.../perf/{util => trace/beauty}/syscalltbl.c | 0
.../perf/{util => trace/beauty}/syscalltbl.h | 0
tools/perf/trace/beauty/tracepoints/Build | 21 +
tools/perf/trace/beauty/waitid_options.c | 8 +-
tools/perf/util/Build | 17 +-
tools/perf/util/bpf-trace-summary.c | 2 +-
tools/perf/util/env.c | 4 -
tools/perf/util/env.h | 1 +
38 files changed, 688 insertions(+), 516 deletions(-)
rename tools/perf/{util => bench}/bpf_skel/bench_uprobe.bpf.c (100%)
create mode 100644 tools/perf/bpf_skel.mak
create mode 100644 tools/perf/trace/beauty/fsconfig.c
rename tools/perf/{util => trace/beauty}/syscalltbl.c (100%)
rename tools/perf/{util => trace/beauty}/syscalltbl.h (100%)Signature · 1 line
2.54.0.563.g4f69b47b94-goog
Ian Rogers
reviewerPATCH v7 1/14 tools build: Fix feature checks to touch target files on success
In tools/build/feature/Makefile, test-clang-bpf-co-re.bin and test-bpftool-skeletons.bin redirected grep output but never touched or created the $@ target file upon success.
Because the target file was never created on disk, Kbuild could never cache the result of the check. Consequently, Make treated the prerequisite as missing and continuously re-executed the Clang BPF backend and bpftool feature checks on every single sub-make evaluation during build startup.
Refactor both feature check recipes to group the shell pipeline within curly braces and redirect both stdout and stderr to .make.output before touching $@ purely upon success (> $(@:.bin=.make.output) 2>&1 && touch $@). Grouping the pipeline ({ cmd1 | cmd2; }) ensures that compiler stderr is successfully captured in .make.output rather than escaping to the parent shell. This perfectly matches standard Kbuild feature check conventions, allowing Make to cache positive detections and avoid redundant sub-make forks during incremental builds. Add test-bpftool-skeletons.bin to the FILES list so that make clean correctly purges the generated binary. For test-clang-bpf-co-re.bin, add explicit source file prerequisite test-clang-bpf-co-re.c and simplify the Clang recipe using $<.
--- tools/build/feature/Makefile | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
tools/build/feature/Makefile +7 -6
@@ -72,7 +72,8 @@ FILES= \ test-file-handle.bin \ test-libpfm4.bin \ test-rust.bin \ - test-libopenssl.bin + test-libopenssl.bin \ + test-bpftool-skeletons.bin FILES := $(addprefix $(OUTPUT),$(FILES))
@@ -379,9 +380,9 @@ $(OUTPUT)test-libaio.bin: $(OUTPUT)test-libzstd.bin: $(BUILD) -lzstd -$(OUTPUT)test-clang-bpf-co-re.bin: - $(CLANG) -S -g --target=bpf -o - $(patsubst %.bin,%.c,$(@F)) | \ - grep BTF_KIND_VAR +$(OUTPUT)test-clang-bpf-co-re.bin: test-clang-bpf-co-re.c + { $(CLANG) -S -g --target=bpf -o - $< | \ + grep BTF_KIND_VAR; } > $(@:.bin=.make.output) 2>&1 && touch $@ $(OUTPUT)test-file-handle.bin: $(BUILD)
@@ -393,8 +394,8 @@ $(OUTPUT)test-libopenssl.bin: $(BUILD) $(shell $(PKG_CONFIG) --libs --cflags openssl 2>/dev/null) $(OUTPUT)test-bpftool-skeletons.bin: - $(SYSTEM_BPFTOOL) version | grep '^features:.*skeletons' \ - > $(@:.bin=.make.output) 2>&1 + { $(SYSTEM_BPFTOOL) version | grep '^features:.*skeletons'; } \ + > $(@:.bin=.make.output) 2>&1 && touch $@ # Testing Rust is special: we don't compile anything, it's enough to check the # compiler presence. Compiling a test code for this purposes is problematic,
Signature · 1 line
2.54.0.563.g4f69b47b94-goog
Ian Rogers
reviewerPATCH v7 2/14 perf trace beauty: Make beauty generated C code standalone .o files
In reply to Ian RogersPreviously, builtin-trace.c directly included 15 embedded C files (e.g. trace/beauty/mmap.c and fsconfig_arrays.c), which in turn depend on dozens of generated beauty script arrays. To satisfy these embedded inclusions, the global Makefile.perf would define all the generator variables/rules and include them in the prepare umbrella target, choking parallel build startup.
Furthermore, tools/perf/util/syscalltbl.c included its own generated mapper, and util/env.c conditionally included arch_errno_names.c inline, splitting consumers across directories and preventing clean Make encapsulation.
Refactor the framework to achieve better encapsulation:
1. Move util/syscalltbl.[ch] into trace/beauty/ to co-locate with all generated code consumers.
2. Create fsconfig.c and flatten embedded beauty .c files to compile as independent standalone objects via trace/beauty/Build, exporting their formatting functions via beauty.h and env.h. Switch arch_errno_names.o and syscalltbl.o assignments directly to perf-util-y and add an unconditional top-level recursive kbuild hook (perf-util-y += trace/beauty/) to compile them into libperf-util.a, resolving remote linkage for util/env.c, util/bpf-trace-summary.c, and standalone python extensions.
3. Bridge private opaque references (struct trace) securely via accessors trace__show_zeros() and trace__host(), avoiding header entanglements.
4. Consolidate all generator variables, script paths, and array generation rules entirely out of Makefile.perf and place them directly inside the exact local Build files where their output objects are compiled (trace/beauty/Build and trace/beauty/tracepoints/Build), binding prerequisites locally. Use directly inside
generator recipes to guarantee dynamic directory creation before script redirection, and append across all rules to print
clean, standardized GEN ... file.c output during compilation.
5. Clean up clean target to recursively remove the generated directory instead of relying on dozens of individual variables.
This unchokes the "prepare" target parallel barrier, allows make to evaluate generation scripts purely locally where consumed, and flattens the tracepoint formatting architecture.
Testing a parallel build (make -j28 all from scratch) shows improvements:
Before:
real 0m28.689s
user 2m38.490s
sys 0m30.148sAfter:
real 0m27.642s
user 2m32.356s
sys 0m26.683sSo reclaiming ~9.6 seconds of raw CPU time and over 1 full second off overall real-world build latency, by overlapping sub-make startup and avoiding top-level double-parsing overhead.
---
tools/perf/Build | 2 +
tools/perf/Makefile.perf | 282 +-----------------
tools/perf/builtin-trace.c | 32 +-
tools/perf/trace/beauty/Build | 276 +++++++++++++++++
tools/perf/trace/beauty/arch_errno_names.c | 2 +
tools/perf/trace/beauty/arch_errno_names.sh | 2 +-
tools/perf/trace/beauty/beauty.h | 60 ++++
tools/perf/trace/beauty/eventfd.c | 6 +-
tools/perf/trace/beauty/fsconfig.c | 5 +
tools/perf/trace/beauty/futex_op.c | 5 +-
tools/perf/trace/beauty/futex_val3.c | 5 +-
tools/perf/trace/beauty/mmap.c | 24 +-
tools/perf/trace/beauty/mode_t.c | 6 +-
tools/perf/trace/beauty/msg_flags.c | 8 +-
tools/perf/trace/beauty/open_flags.c | 2 +
tools/perf/trace/beauty/perf_event_open.c | 21 +-
tools/perf/trace/beauty/pid.c | 5 +-
tools/perf/trace/beauty/sched_policy.c | 8 +-
tools/perf/trace/beauty/seccomp.c | 12 +-
tools/perf/trace/beauty/signum.c | 6 +-
tools/perf/trace/beauty/socket_type.c | 6 +-
.../perf/{util => trace/beauty}/syscalltbl.c | 0
.../perf/{util => trace/beauty}/syscalltbl.h | 0
tools/perf/trace/beauty/tracepoints/Build | 21 ++
tools/perf/trace/beauty/waitid_options.c | 8 +-
tools/perf/util/Build | 4 +-
tools/perf/util/bpf-trace-summary.c | 2 +-
tools/perf/util/env.c | 4 -
tools/perf/util/env.h | 1 +
29 files changed, 447 insertions(+), 368 deletions(-)
create mode 100644 tools/perf/trace/beauty/fsconfig.c
rename tools/perf/{util => trace/beauty}/syscalltbl.c (100%)
rename tools/perf/{util => trace/beauty}/syscalltbl.h (100%)tools/perf/Build +2 -0
@@ -34,6 +34,8 @@ ifeq ($(CONFIG_LIBTRACEEVENT),y) perf-$(CONFIG_TRACE) += trace/beauty/ endif +perf-util-y += trace/beauty/ + perf-$(CONFIG_LIBELF) += builtin-probe.o perf-bench-y += bench/
tools/perf/Makefile.perf +2 -280
300 lines not on this page · raw message
tools/perf/builtin-trace.c +12 -20
@@ -60,12 +60,13 @@#include "callchain.h" #include "print_binary.h" #include "string2.h" -#include "syscalltbl.h" +#include "trace/beauty/syscalltbl.h" #include "../perf.h" #include "trace_augment.h" #include "dwarf-regs.h" #include <errno.h> +#include <sys/stat.h> #include <inttypes.h> #include <poll.h> #include <signal.h>
@@ -235,6 +236,16 @@ struct trace {const char *uid_str; }; +bool trace__show_zeros (const struct trace *trace) +{ +return trace->show_zeros; +} + +struct machine *trace__host (const struct trace *trace) +{ +return trace->host; +} +static void trace__load_vmlinux_btf (struct trace *trace__maybe_unused ) {#ifdef HAVE_LIBBPF_SUPPORT
@@ -777,10 +788,6 @@ static const char *fsmount_flags[] = { }; static DEFINE_STRARRAY(fsmount_flags, "FSMOUNT_"); -#include "trace/beauty/generated/fsconfig_arrays.c" - -static DEFINE_STRARRAY(fsconfig_cmds, "FSCONFIG_"); -static const char *epoll_ctl_ops[] = {"ADD" ,"DEL" ,"MOD" , }; static DEFINE_STRARRAY_OFFSET(epoll_ctl_ops, "EPOLL_CTL_", 1);
@@ -1129,21 +1136,6 @@ static bool syscall_arg__strtoul_btf_type(char *bf __maybe_unused, size_t size _ .parm = &strarray__##array, \ .show_zero = true, } -#include "trace/beauty/eventfd.c" -#include "trace/beauty/futex_op.c" -#include "trace/beauty/futex_val3.c" -#include "trace/beauty/mmap.c" -#include "trace/beauty/mode_t.c" -#include "trace/beauty/msg_flags.c" -#include "trace/beauty/open_flags.c" -#include "trace/beauty/perf_event_open.c" -#include "trace/beauty/pid.c" -#include "trace/beauty/sched_policy.c" -#include "trace/beauty/seccomp.c" -#include "trace/beauty/signum.c" -#include "trace/beauty/socket_type.c" -#include "trace/beauty/waitid_options.c" -static const struct syscall_fmt syscall_fmts[] = { { .name ="access" , .arg = { [1 ] = { .scnprintf =SCA_ACCMODE ,/* mode */ }, }, },
tools/perf/trace/beauty/Build +276 -0
285 lines not on this page · raw message
tools/perf/trace/beauty/arch_errno_names.c +2 -0
@@ -1 +1,3 @@ +// SPDX-License-Identifier: GPL-2.0 +#include "util/env.h" #include "trace/beauty/generated/arch_errno_name_array.c"
tools/perf/trace/beauty/arch_errno_names.sh +1 -1
@@ -57,7 +57,7 @@ create_arch_errno_table_func() archlist="$1" default="$2" - printf 'static arch_syscalls__strerrno_t *\n' + printf 'arch_syscalls__strerrno_t *\n' printf 'arch_syscalls__strerrno_function(const char *arch)\n' printf '{\n' for arch in $archlist; do
tools/perf/trace/beauty/beauty.h +60 -0
70 lines not on this page · raw message
tools/perf/trace/beauty/eventfd.c +3 -3
@@ -1,4 +1,6 @@// SPDX-License-Identifier: LGPL-2.1 +#include "trace/beauty/beauty.h" +#ifndef EFD_SEMAPHORE #define EFD_SEMAPHORE 1#endif
@@ -11,7 +13,7 @@#define EFD_CLOEXEC 02000000#endif -static size_t syscall_arg__scnprintf_eventfd_flags (char *bf,size_t size,struct syscall_arg *arg) +size_t syscall_arg__scnprintf_eventfd_flags (char *bf,size_t size,struct syscall_arg *arg) {bool show_prefix = arg->show_string_prefix;const char *prefix ="EFD_" ;
@@ -35,5 +37,3 @@ static size_t syscall_arg__scnprintf_eventfd_flags(char *bf, size_t size, structreturn printed; } - -#define SCA_EFD_FLAGS syscall_arg__scnprintf_eventfd_flags
tools/perf/trace/beauty/fsconfig.c new file +5 -0
@@ -0,0 +1,5 @@ +// SPDX-License-Identifier: LGPL-2.1 +#include "trace/beauty/beauty.h" +#include "trace/beauty/generated/fsconfig_arrays.c" + +DEFINE_STRARRAY (fsconfig_cmds,"FSCONFIG_" );
tools/perf/trace/beauty/futex_op.c +2 -3
@@ -1,4 +1,5 @@// SPDX-License-Identifier: LGPL-2.1 +#include "trace/beauty/beauty.h" #include <linux/futex.h> #ifndef FUTEX_WAIT_BITSET
@@ -17,7 +18,7 @@#define FUTEX_CLOCK_REALTIME 256#endif -static size_t syscall_arg__scnprintf_futex_op (char *bf,size_t size,struct syscall_arg *arg) +size_t syscall_arg__scnprintf_futex_op (char *bf,size_t size,struct syscall_arg *arg) {bool show_prefix = arg->show_string_prefix;const char *prefix ="FUTEX_" ;
@@ -59,5 +60,3 @@ static size_t syscall_arg__scnprintf_futex_op(char *bf, size_t size, struct syscreturn printed; } - -#define SCA_FUTEX_OP syscall_arg__scnprintf_futex_op
tools/perf/trace/beauty/futex_val3.c +2 -3
@@ -1,11 +1,12 @@// SPDX-License-Identifier: LGPL-2.1 +#include "trace/beauty/beauty.h" #include <linux/futex.h> #ifndef FUTEX_BITSET_MATCH_ANY #define FUTEX_BITSET_MATCH_ANY 0xffffffff#endif -static size_t syscall_arg__scnprintf_futex_val3 (char *bf,size_t size,struct syscall_arg *arg) +size_t syscall_arg__scnprintf_futex_val3 (char *bf,size_t size,struct syscall_arg *arg) {const char *prefix ="FUTEX_BITSET_" ;unsigned int bitset = arg->val;
@@ -15,5 +16,3 @@ static size_t syscall_arg__scnprintf_futex_val3(char *bf, size_t size, struct syreturn scnprintf (bf, size,"%#xd" , bitset); } - -#define SCA_FUTEX_VAL3 syscall_arg__scnprintf_futex_val3
tools/perf/trace/beauty/mmap.c +11 -13
@@ -1,5 +1,6 @@// SPDX-License-Identifier: LGPL-2.1 #include <linux/log2.h> +#include "trace/beauty/beauty.h" #include "trace/beauty/generated/mmap_prot_array.c" static DEFINE_STRARRAY(mmap_prot, "PROT_");
@@ -8,8 +9,7 @@ static size_t mmap__scnprintf_prot(unsigned long prot, char *bf, size_t size, bo {return strarray__scnprintf_flags (&strarray__mmap_prot, bf, size, show_prefix, prot); } - -static size_t syscall_arg__scnprintf_mmap_prot (char *bf,size_t size,struct syscall_arg *arg) +size_t syscall_arg__scnprintf_mmap_prot (char *bf,size_t size,struct syscall_arg *arg) {unsigned long prot = arg->val;
@@ -19,18 +19,18 @@ static size_t syscall_arg__scnprintf_mmap_prot(char *bf, size_t size, struct sysreturn mmap__scnprintf_prot (prot, bf, size, arg->show_string_prefix); } -#define SCA_MMAP_PROT syscall_arg__scnprintf_mmap_prot +#include "trace/beauty/generated/mmap_flags_array.c" -static DEFINE_STRARRAY(mmap_flags, "MAP_"); +DEFINE_STRARRAY (mmap_flags,"MAP_" );static size_t mmap__scnprintf_flags (unsigned long flags,char *bf,size_t size,bool show_prefix) {return strarray__scnprintf_flags (&strarray__mmap_flags, bf, size, show_prefix, flags); } -static size_t syscall_arg__scnprintf_mmap_flags (char *bf,size_t size, -struct syscall_arg *arg) +size_t syscall_arg__scnprintf_mmap_flags (char *bf,size_t size, +struct syscall_arg *arg) {unsigned long flags = arg->val;
@@ -40,7 +40,7 @@ static size_t syscall_arg__scnprintf_mmap_flags(char *bf, size_t size,return mmap__scnprintf_flags (flags, bf, size, arg->show_string_prefix); } -#define SCA_MMAP_FLAGS syscall_arg__scnprintf_mmap_flags +#include "trace/beauty/generated/mremap_flags_array.c" static DEFINE_STRARRAY(mremap_flags, "MREMAP_");
@@ -50,7 +50,7 @@ static size_t mremap__scnprintf_flags(unsigned long flags, char *bf, size_t sizereturn strarray__scnprintf_flags (&strarray__mremap_flags, bf, size, show_prefix, flags); } -static size_t syscall_arg__scnprintf_mremap_flags (char *bf,size_t size,struct syscall_arg *arg) +size_t syscall_arg__scnprintf_mremap_flags (char *bf,size_t size,struct syscall_arg *arg) {unsigned long flags = arg->val;
@@ -60,7 +60,7 @@ static size_t syscall_arg__scnprintf_mremap_flags(char *bf, size_t size, structreturn mremap__scnprintf_flags (flags, bf, size, arg->show_string_prefix); } -#define SCA_MREMAP_FLAGS syscall_arg__scnprintf_mremap_flags +static size_t madvise__scnprintf_behavior (int behavior,char *bf,size_t size) {
@@ -73,10 +73,8 @@ static size_t madvise__scnprintf_behavior(int behavior, char *bf, size_t size)return scnprintf (bf, size,"%#" , behavior); } -static size_t syscall_arg__scnprintf_madvise_behavior (char *bf,size_t size, -struct syscall_arg *arg) +size_t syscall_arg__scnprintf_madvise_behavior (char *bf,size_t size, +struct syscall_arg *arg) {return madvise__scnprintf_behavior (arg->val, bf, size); } - -#define SCA_MADV_BHV syscall_arg__scnprintf_madvise_behavior
tools/perf/trace/beauty/mode_t.c +3 -3
@@ -1,4 +1,6 @@// SPDX-License-Identifier: LGPL-2.1 +#include "trace/beauty/beauty.h" +#include <sys/types.h> #include <sys/stat.h> #include <unistd.h>
@@ -20,7 +22,7 @@#define S_IXUGO (S_IXUSR|S_IXGRP|S_IXOTH)#endif -static size_t syscall_arg__scnprintf_mode_t (char *bf,size_t size,struct syscall_arg *arg) +size_t syscall_arg__scnprintf_mode_t (char *bf,size_t size,struct syscall_arg *arg) {bool show_prefix = arg->show_string_prefix;const char *prefix ="S_" ;
@@ -67,5 +69,3 @@ static size_t syscall_arg__scnprintf_mode_t(char *bf, size_t size, struct syscalreturn printed; } - -#define SCA_MODE_T syscall_arg__scnprintf_mode_t
tools/perf/trace/beauty/msg_flags.c +4 -4
@@ -1,4 +1,6 @@// SPDX-License-Identifier: LGPL-2.1 +#include "trace/beauty/beauty.h" +#include <sys/types.h> #include <sys/socket.h>
@@ -27,8 +29,8 @@# define MSG_CMSG_CLOEXEC 0x40000000#endif -static size_t syscall_arg__scnprintf_msg_flags (char *bf,size_t size, -struct syscall_arg *arg) +size_t syscall_arg__scnprintf_msg_flags (char *bf,size_t size, +struct syscall_arg *arg) {bool show_prefix = arg->show_string_prefix;const char *prefix ="MSG_" ;
@@ -72,5 +74,3 @@ static size_t syscall_arg__scnprintf_msg_flags(char *bf, size_t size,return printed; } - -#define SCA_MSG_FLAGS syscall_arg__scnprintf_msg_flags
tools/perf/trace/beauty/open_flags.c +2 -0
@@ -1,4 +1,6 @@// SPDX-License-Identifier: LGPL-2.1 +#include "trace/beauty/beauty.h" +#include <sys/types.h> #include <sys/stat.h> #include <fcntl.h>
tools/perf/trace/beauty/perf_event_open.c +10 -11
@@ -1,4 +1,8 @@// SPDX-License-Identifier: LGPL-2.1 +#include "trace/beauty/beauty.h" +#include "util/evsel_fprintf.h" +#include <linux/perf_event.h> +#ifndef PERF_FLAG_FD_NO_GROUP # define PERF_FLAG_FD_NO_GROUP (1UL << 0)#endif
@@ -15,8 +19,8 @@# define PERF_FLAG_FD_CLOEXEC (1UL << 3)/* O_CLOEXEC */ #endif -static size_t syscall_arg__scnprintf_perf_flags (char *bf,size_t size, -struct syscall_arg *arg) +size_t syscall_arg__scnprintf_perf_flags (char *bf,size_t size, +struct syscall_arg *arg) {bool show_prefix = arg->show_string_prefix;const char *prefix ="PERF_" ;
@@ -43,7 +47,7 @@ static size_t syscall_arg__scnprintf_perf_flags(char *bf, size_t size,return printed; } -#define SCA_PERF_FLAGS syscall_arg__scnprintf_perf_flags +struct attr_fprintf_args {size_t size, printed;
@@ -76,19 +80,14 @@ static size_t perf_event_attr___scnprintf(struct perf_event_attr *attr, char *bfstatic size_t syscall_arg__scnprintf_augmented_perf_event_attr (struct syscall_arg *arg,char *bf,size_t size) { -return perf_event_attr___scnprintf ((void *)arg->augmented.args->value, bf, size, arg->trace->show_zeros); +return perf_event_attr___scnprintf ((void *)arg->augmented.args->value, bf, size, +trace__show_zeros (arg->trace)); } -static size_t syscall_arg__scnprintf_perf_event_attr (char *bf,size_t size,struct syscall_arg *arg) +size_t syscall_arg__scnprintf_perf_event_attr (char *bf,size_t size,struct syscall_arg *arg) {if (arg->augmented.args)return syscall_arg__scnprintf_augmented_perf_event_attr (arg, bf, size);return scnprintf (bf, size,"%#lx" , arg->val); } - -#define SCA_PERF_ATTR syscall_arg__scnprintf_perf_event_attr -// 'argname' is just documentational at this point, to remove the previous comment with that info -#define SCA_PERF_ATTR_FROM_USER (argname) \ - { .scnprintf = SCA_PERF_ATTR, \ - .from_user = true, }
tools/perf/trace/beauty/pid.c +4 -1
@@ -1,11 +1,14 @@// SPDX-License-Identifier: LGPL-2.1 +#include "trace/beauty/beauty.h" +#include "util/machine.h" +#include "util/thread.h" size_t syscall_arg__scnprintf_pid (char *bf,size_t size,struct syscall_arg *arg) {int pid = arg->val;struct trace *trace = arg->trace;size_t printed =scnprintf (bf, size,"%d" , pid); -struct thread *thread =machine__findnew_thread (trace->host, pid, pid); +struct thread *thread =machine__findnew_thread (trace__host (trace), pid, pid);if (thread !=NULL ) {if (!thread__comm_set (thread))
tools/perf/trace/beauty/sched_policy.c +4 -4
@@ -1,4 +1,6 @@// SPDX-License-Identifier: LGPL-2.1 +#include "trace/beauty/beauty.h" +#include <sched.h> /*
@@ -14,8 +16,8 @@#define SCHED_RESET_ON_FORK 0x40000000#endif -static size_t syscall_arg__scnprintf_sched_policy (char *bf,size_t size, -struct syscall_arg *arg) +size_t syscall_arg__scnprintf_sched_policy (char *bf,size_t size, +struct syscall_arg *arg) {bool show_prefix = arg->show_string_prefix;const char *prefix ="SCHED_" ;
@@ -46,5 +48,3 @@ static size_t syscall_arg__scnprintf_sched_policy(char *bf, size_t size,return printed; } - -#define SCA_SCHED_POLICY syscall_arg__scnprintf_sched_policy
tools/perf/trace/beauty/seccomp.c +6 -6
@@ -1,4 +1,6 @@// SPDX-License-Identifier: LGPL-2.1 +#include "trace/beauty/beauty.h" +#ifndef SECCOMP_SET_MODE_STRICT #define SECCOMP_SET_MODE_STRICT 0#endif
@@ -6,7 +8,7 @@#define SECCOMP_SET_MODE_FILTER 1#endif -static size_t syscall_arg__scnprintf_seccomp_op (char *bf,size_t size,struct syscall_arg *arg) +size_t syscall_arg__scnprintf_seccomp_op (char *bf,size_t size,struct syscall_arg *arg) {bool show_prefix = arg->show_string_prefix;const char *prefix ="SECCOMP_SET_MODE_" ;
@@ -24,14 +26,14 @@ static size_t syscall_arg__scnprintf_seccomp_op(char *bf, size_t size, struct syreturn printed; } -#define SCA_SECCOMP_OP syscall_arg__scnprintf_seccomp_op +#ifndef SECCOMP_FILTER_FLAG_TSYNC #define SECCOMP_FILTER_FLAG_TSYNC 1#endif -static size_t syscall_arg__scnprintf_seccomp_flags (char *bf,size_t size, -struct syscall_arg *arg) +size_t syscall_arg__scnprintf_seccomp_flags (char *bf,size_t size, +struct syscall_arg *arg) {bool show_prefix = arg->show_string_prefix;const char *prefix ="SECCOMP_FILTER_FLAG_" ;
@@ -51,5 +53,3 @@ static size_t syscall_arg__scnprintf_seccomp_flags(char *bf, size_t size,return printed; } - -#define SCA_SECCOMP_FLAGS syscall_arg__scnprintf_seccomp_flags
tools/perf/trace/beauty/signum.c +3 -3
@@ -1,7 +1,9 @@// SPDX-License-Identifier: LGPL-2.1 +#include "trace/beauty/beauty.h" +#include <signal.h> -static size_t syscall_arg__scnprintf_signum (char *bf,size_t size,struct syscall_arg *arg) +size_t syscall_arg__scnprintf_signum (char *bf,size_t size,struct syscall_arg *arg) {bool show_prefix = arg->show_string_prefix;const char *prefix ="SIG" ;
@@ -53,5 +55,3 @@ static size_t syscall_arg__scnprintf_signum(char *bf, size_t size, struct syscalreturn scnprintf (bf, size,"%#x" , sig); } - -#define SCA_SIGNUM syscall_arg__scnprintf_signum
tools/perf/trace/beauty/socket_type.c +3 -3
@@ -1,4 +1,6 @@// SPDX-License-Identifier: LGPL-2.1 +#include "trace/beauty/beauty.h" +#include <sys/types.h> #include <sys/socket.h>
@@ -18,7 +20,7 @@#define SOCK_TYPE_MASK 0xf#endif -static size_t syscall_arg__scnprintf_socket_type (char *bf,size_t size,struct syscall_arg *arg) +size_t syscall_arg__scnprintf_socket_type (char *bf,size_t size,struct syscall_arg *arg) {bool show_prefix = arg->show_string_prefix;const char *prefix ="SOCK_" ;
@@ -59,5 +61,3 @@ static size_t syscall_arg__scnprintf_socket_type(char *bf, size_t size, struct sreturn printed; } - -#define SCA_SK_TYPE syscall_arg__scnprintf_socket_type
tools/perf/trace/beauty/syscalltbl.c renamed from tools/perf/util/syscalltbl.c +0 -0
tools/perf/trace/beauty/syscalltbl.h renamed from tools/perf/util/syscalltbl.h +0 -0
tools/perf/trace/beauty/tracepoints/Build +21 -0
@@ -1,2 +1,23 @@ perf-y += x86_irq_vectors.o perf-y += x86_msr.o + +beauty_outdir := $(OUTPUT)trace/beauty/generated +beauty_arch_asm_dir := $(srctree)/tools/perf/trace/beauty/arch/x86/include/asm/ +x86_arch_asm_dir := $(srctree)/tools/arch/x86/include/asm/ + +x86_arch_irq_vectors_array := $(beauty_outdir)/x86_arch_irq_vectors_array.c +x86_arch_irq_vectors_tbl := $(srctree)/tools/perf/trace/beauty/tracepoints/x86_irq_vectors.sh + +$(x86_arch_irq_vectors_array): $(beauty_arch_asm_dir)/irq_vectors.h $(x86_arch_irq_vectors_tbl) + $(call rule_mkdir) + $(Q)$(call echo-cmd,gen)$(SHELL) '$(x86_arch_irq_vectors_tbl)' $(beauty_arch_asm_dir) > $@ + +x86_arch_MSRs_array := $(beauty_outdir)/x86_arch_MSRs_array.c +x86_arch_MSRs_tbl := $(srctree)/tools/perf/trace/beauty/tracepoints/x86_msr.sh + +$(x86_arch_MSRs_array): $(x86_arch_asm_dir)/msr-index.h $(x86_arch_MSRs_tbl) + $(call rule_mkdir) + $(Q)$(call echo-cmd,gen)$(SHELL) '$(x86_arch_MSRs_tbl)' $(x86_arch_asm_dir) > $@ + +$(OUTPUT)trace/beauty/tracepoints/x86_irq_vectors.o: $(x86_arch_irq_vectors_array) +$(OUTPUT)trace/beauty/tracepoints/x86_msr.o: $(x86_arch_MSRs_array)
tools/perf/trace/beauty/waitid_options.c +4 -4
@@ -1,9 +1,11 @@// SPDX-License-Identifier: LGPL-2.1 +#include "trace/beauty/beauty.h" +#include <sys/types.h> #include <sys/wait.h> -static size_t syscall_arg__scnprintf_waitid_options (char *bf,size_t size, -struct syscall_arg *arg) +size_t syscall_arg__scnprintf_waitid_options (char *bf,size_t size, +struct syscall_arg *arg) {bool show_prefix = arg->show_string_prefix;const char *prefix ="W" ;
@@ -25,5 +27,3 @@ static size_t syscall_arg__scnprintf_waitid_options(char *bf, size_t size,return printed; } - -#define SCA_WAITID_OPTIONS syscall_arg__scnprintf_waitid_options
tools/perf/util/Build +3 -1
@@ -75,7 +75,7 @@ perf-util-y += sample.o perf-util-y += sample-raw.o perf-util-y += s390-sample-raw.o perf-util-y += amd-sample-raw.o -perf-util-$(CONFIG_TRACE) += syscalltbl.o + perf-util-y += ordered-events.o perf-util-y += namespaces.o perf-util-y += comm.o
@@ -440,3 +440,5 @@ $(OUTPUT)%.pylint_log: % $(Q)$(call echo-cmd,test)pylint "$<" > $@ || (cat $@ && rm $@ && false) perf-util-y += $(PYLINT_TEST_LOGS) + +
tools/perf/util/bpf-trace-summary.c +1 -1
@@ -6,7 +6,7 @@#include <stdlib.h> #include "dwarf-regs.h" /* for EM_HOST */ -#include "syscalltbl.h" +#include "trace/beauty/syscalltbl.h" #include "util/cgroup.h" #include "util/hashmap.h" #include "util/trace.h"
tools/perf/util/env.c +0 -4
@@ -635,10 +635,6 @@ const char *perf_env__arch(struct perf_env *env)return normalize_arch (arch_name); } -#if defined(HAVE_LIBTRACEEVENT ) -#include "trace/beauty/arch_errno_names.c" -#endif -const char *perf_env__arch_strerrno (struct perf_env *env__maybe_unused ,int err__maybe_unused ) {#if defined(HAVE_LIBTRACEEVENT )
tools/perf/util/env.h +1 -0
@@ -189,6 +189,7 @@ void cpu_cache_level__free(struct cpu_cache_level *cache);const char *perf_env__arch (struct perf_env *env);const char *perf_env__arch_strerrno (struct perf_env *env,int err); +arch_syscalls__strerrno_t *arch_syscalls__strerrno_function (const char *arch);const char *perf_env__cpuid (struct perf_env *env);const char *perf_env__raw_arch (struct perf_env *env);int perf_env__nr_cpus_avail (struct perf_env *env);
Signature · 1 line
2.54.0.563.g4f69b47b94-goog
Ian Rogers
reviewerPATCH v7 3/14 perf build: Decouple pmu-events from prepare umbrella target
In reply to Ian RogersCurrently, the $(LIBPMU_EVENTS_IN) sub-make depends on the massive "prepare" umbrella target. Because "prepare" depends on external libraries (libapi, libperf, etc.) as well as dozens of generated headers, make completely serializes the launch of the pmu-events sub-make behind some of those unrelated prerequisites.
Since pmu-events is a large compilation unit, unblock its startup by binding it directly to only $(LIBPERF) instead of prepare. This allows background python generation scripts to overlap simultaneously with the rest of the build.
Testing a parallel build (make -j28 clean all) shows improvements:
Before:
real 0m27.642s
user 2m32.356s
sys 0m26.683sAfter:
real 0m22.254s
user 2m32.810s
sys 0m24.646sThis reclaims over 5 full seconds of build latency (~19.5% overall reduction) by elevating average CPU concurrency from ~5.5 active cores up to ~8 active cores.
--- tools/perf/Makefile.perf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/Makefile.perf +1 -1
@@ -550,7 +550,7 @@ build := -f $(srctree)/tools/build/Makefile.build dir=. obj $(PERF_IN): prepare FORCE $(Q)$(MAKE) $(build)=perf -$(LIBPMU_EVENTS_IN): FORCE prepare +$(LIBPMU_EVENTS_IN): FORCE $(LIBPERF) $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=pmu-events obj=pmu-events $(LIBPMU_EVENTS): $(LIBPMU_EVENTS_IN)
Signature · 1 line
2.54.0.563.g4f69b47b94-goog
Ian Rogers
reviewerPATCH v7 4/14 perf build: Remove empty archheaders target
In reply to Ian RogersRemove empty target that doesn't do anything.
--- tools/perf/Makefile.perf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/Makefile.perf +2 -2
@@ -627,7 +627,7 @@ endif __build-dir = $(subst $(OUTPUT),,$(dir $@)) build-dir = $(or $(__build-dir),.) -prepare: $(OUTPUT)PERF-VERSION-FILE archheaders \ +prepare: $(OUTPUT)PERF-VERSION-FILE \ arm64-sysreg-defs \ $(LIBAPI) \ $(LIBPERF) \
@@ -1070,7 +1070,7 @@ FORCE: .PHONY: all install clean config-clean strip install-gtk .PHONY: shell_compatibility_test please_set_SHELL_PATH_to_a_more_modern_shell .PHONY: .FORCE-PERF-VERSION-FILE TAGS tags cscope FORCE prepare -.PHONY: archheaders python_perf_target +.PHONY: python_perf_target endif # force_fixdep
Signature · 1 line
2.54.0.563.g4f69b47b94-goog
Ian Rogers
reviewerPATCH v7 5/14 perf build: Move BPF skeleton generation out of Makefile.perf
In reply to Ian RogersCurrently, the top-level Makefile.perf defines a massive global bpf-skel umbrella target that pre-compiles all 12+ BPF skeletons (%.skel.h) upfront before launching sub-makes. This forces unrelated sub-makes to serialize behind bpftool and clang BPF target evaluations, causing parallel build bottlenecks.
Furthermore, bench_uprobe.bpf.c lived inside util/bpf_skel/, breaking conceptual directory encapsulation since it is consumed purely by bench/uprobe.c.
Refactor the BPF skeletons to better achieve directory isolation:
1. Move tools/perf/util/bpf_skel/bench_uprobe.bpf.c directly into tools/perf/bench/bpf_skel/.
2. Extract the skeleton generation infrastructure out of Makefile.perf into a shared inclusion file tools/perf/bpf_skel.mak.
3. Include bpf_skel.mak locally inside tools/perf/util/Build and tools/perf/bench/Build and bind precise local prerequisites.
4. Safely synchronize the shared bpftool bootstrap and vmlinux.h targets via the conditional prepare: umbrella to avoid parallel sub-make races, while evaluating the actual skeletons completely locally on demand. A later patch will move these targets into bpf_skel.mak.
5. Export CLANG from the global Makefile to ensure accurate tool propagation.
6. Clean up Makefile.perf by stripping the global bpf-skel umbrella target and its SKELETONS list.
While removing code from Makefile.perf generally helps build performance, the impact here is minimal. The main motivation for the change is to better encapsulate things in the build and simplify Makefile.perf that has around 50 lines removed.
---
tools/perf/Makefile.perf | 59 ++-----------------
tools/perf/bench/Build | 6 ++
.../bpf_skel/bench_uprobe.bpf.c | 0
tools/perf/bench/uprobe.c | 2 +-
tools/perf/bpf_skel.mak | 54 +++++++++++++++++
tools/perf/util/Build | 15 ++++-
6 files changed, 79 insertions(+), 57 deletions(-)
rename tools/perf/{util => bench}/bpf_skel/bench_uprobe.bpf.c (100%)
create mode 100644 tools/perf/bpf_skel.maktools/perf/Makefile.perf +4 -55
@@ -274,7 +274,7 @@ ifeq ($(PYLINT),1) PYLINT := $(shell which pylint 2> /dev/null) endif -export srctree OUTPUT RM CC CXX RUSTC LD AR CFLAGS CXXFLAGS RUST_FLAGS V BISON FLEX AWK +export srctree OUTPUT RM CC CXX RUSTC CLANG LD AR CFLAGS CXXFLAGS RUST_FLAGS V BISON FLEX AWK LIBBPF export HOSTCC HOSTLD HOSTAR HOSTCFLAGS SHELLCHECK MYPY PYLINT include $(srctree)/tools/build/Makefile.include
@@ -632,8 +632,7 @@ prepare: $(OUTPUT)PERF-VERSION-FILE \ $(LIBAPI) \ $(LIBPERF) \ $(LIBSUBCMD) \ - $(LIBSYMBOL) \ - bpf-skel + $(LIBSYMBOL) ifdef LIBBPF_STATIC prepare: $(LIBBPF)
@@ -914,44 +913,13 @@ python-clean: SKEL_OUT := $(abspath $(OUTPUT)util/bpf_skel) SKEL_TMP_OUT := $(abspath $(SKEL_OUT)/.tmp) -SKELETONS := $(SKEL_OUT)/bpf_prog_profiler.skel.h -SKELETONS += $(SKEL_OUT)/bperf_leader.skel.h $(SKEL_OUT)/bperf_follower.skel.h -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_OUT)/sample_filter.skel.h -SKELETONS += $(SKEL_OUT)/kwork_top.skel.h $(SKEL_OUT)/syscall_summary.skel.h -SKELETONS += $(SKEL_OUT)/bench_uprobe.skel.h -SKELETONS += $(SKEL_OUT)/augmented_raw_syscalls.skel.h $(SKEL_TMP_OUT) $(LIBAPI_OUTPUT) $(LIBBPF_OUTPUT) $(LIBPERF_OUTPUT) $(LIBSUBCMD_OUTPUT) $(LIBSYMBOL_OUTPUT): $(Q)$(MKDIR) -p $@ ifeq ($(CONFIG_PERF_BPF_SKEL),y) +prepare: $(BPFTOOL) $(SKEL_OUT)/vmlinux.h BPFTOOL := $(SKEL_TMP_OUT)/bootstrap/bpftool -# Get Clang's default includes on this system, as opposed to those seen by -# '--target=bpf'. This fixes "missing" files on some architectures/distros, -# such as asm/byteorder.h, asm/socket.h, asm/sockios.h, sys/cdefs.h etc. -# -# Use '-idirafter': Don't interfere with include mechanics except where the -# build would have failed anyways. -define get_sys_includes -$(shell $(1) $(2) -v -E - </dev/null 2>&1 \ - | sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }') \ -$(shell $(1) $(2) -dM -E - </dev/null | grep '__riscv_xlen ' | awk '{printf("-D__riscv_xlen=%d -D__BITS_PER_LONG=%d", $$3, $$3)}') -endef - -ifneq ($(CROSS_COMPILE),) -CLANG_TARGET_ARCH = --target=$(notdir $(CROSS_COMPILE:%-=%)) -endif - -CLANG_OPTIONS = -Wall -CLANG_SYS_INCLUDES = $(call get_sys_includes,$(CLANG),$(CLANG_TARGET_ARCH)) -BPF_INCLUDE := -I$(SKEL_TMP_OUT)/.. -I$(LIBBPF_INCLUDE) $(CLANG_SYS_INCLUDES) -TOOLS_UAPI_INCLUDE := -I$(srctree)/tools/include/uapi - -ifneq ($(WERROR),0) - CLANG_OPTIONS += -Werror -endif $(BPFTOOL): | $(SKEL_TMP_OUT) $(Q)CFLAGS= $(MAKE) -C ../bpf/bpftool \
@@ -993,29 +961,10 @@ else $(Q)cp "$(VMLINUX_H)" $@ endif -$(SKEL_TMP_OUT)/%.bpf.o: $(OUTPUT)PERF-VERSION-FILE util/bpf_skel/perf_version.h | $(SKEL_TMP_OUT) -$(SKEL_TMP_OUT)/%.bpf.o: util/bpf_skel/%.bpf.c $(LIBBPF) $(SKEL_OUT)/vmlinux.h - $(QUIET_CLANG)$(CLANG) -g -O2 -fno-stack-protector --target=bpf \ - $(CLANG_OPTIONS) $(EXTRA_BPF_FLAGS) $(BPF_INCLUDE) $(TOOLS_UAPI_INCLUDE) \ - -include $(OUTPUT)PERF-VERSION-FILE -include util/bpf_skel/perf_version.h \ - -fms-extensions -Wno-microsoft-anon-tag \ - -c $(filter util/bpf_skel/%.bpf.c,$^) -o $@ - -$(SKEL_OUT)/%.skel.h: $(SKEL_TMP_OUT)/%.bpf.o | $(BPFTOOL) - $(QUIET_GENSKEL)$(BPFTOOL) gen skeleton $< > $@ - -bpf-skel: $(SKELETONS) - -.PRECIOUS: $(SKEL_TMP_OUT)/%.bpf.o - -else # CONFIG_PERF_BPF_SKEL - -bpf-skel: - endif # CONFIG_PERF_BPF_SKEL bpf-skel-clean: - $(call QUIET_CLEAN, bpf-skel) $(RM) -r $(SKEL_TMP_OUT) $(SKELETONS) $(SKEL_OUT)/vmlinux.h + $(call QUIET_CLEAN, bpf-skel) $(RM) -r $(SKEL_TMP_OUT) $(SKEL_OUT)/*.skel.h $(SKEL_OUT)/vmlinux.h $(OUTPUT)bench/bpf_skel/*.skel.h $(OUTPUT)bench/bpf_skel/.tmp pmu-events-clean: ifeq ($(OUTPUT),)
tools/perf/bench/Build +6 -0
@@ -24,3 +24,9 @@ perf-bench-$(CONFIG_X86_64) += mem-memcpy-x86-64-asm.o perf-bench-$(CONFIG_X86_64) += mem-memset-x86-64-asm.o perf-bench-$(CONFIG_NUMA) += numa.o + +ifeq ($(CONFIG_PERF_BPF_SKEL),y) +include $(srctree)/tools/perf/bpf_skel.mak + +$(OUTPUT)bench/uprobe.o: $(SKEL_OUT)/bench_uprobe.skel.h +endif
tools/perf/bench/bpf_skel/bench_uprobe.bpf.c renamed from tools/perf/util/bpf_skel/bench_uprobe.bpf.c +0 -0
tools/perf/bench/uprobe.c +1 -1
@@ -44,7 +44,7 @@ static const char * const bench_uprobe_usage[] = { };#ifdef HAVE_BPF_SKEL -#include "bpf_skel/bench_uprobe.skel.h" +#include "bench/bpf_skel/bench_uprobe.skel.h" #define bench_uprobe__attach_uprobe(prog) \ skel->links.prog = bpf_program__attach_uprobe_opts(/*prog=*/skel->progs.prog, \
tools/perf/bpf_skel.mak new file +54 -0
54 lines not on this page · raw message
tools/perf/util/Build +14 -1
@@ -441,4 +441,17 @@ $(OUTPUT)%.pylint_log: % perf-util-y += $(PYLINT_TEST_LOGS) - +ifeq ($(CONFIG_PERF_BPF_SKEL),y) +include $(srctree)/tools/perf/bpf_skel.mak + +$(OUTPUT)util/bpf_ftrace.o: $(SKEL_OUT)/func_latency.skel.h +$(OUTPUT)util/bpf-filter.o: $(SKEL_OUT)/sample_filter.skel.h +$(OUTPUT)util/bpf_kwork_top.o: $(SKEL_OUT)/kwork_top.skel.h +$(OUTPUT)util/bpf_off_cpu.o: $(SKEL_OUT)/off_cpu.skel.h +$(OUTPUT)util/bpf-trace-summary.o: $(SKEL_OUT)/syscall_summary.skel.h +$(OUTPUT)util/bpf_counter_cgroup.o: $(SKEL_OUT)/bperf_cgroup.skel.h +$(OUTPUT)util/bpf_trace_augment.o: $(SKEL_OUT)/augmented_raw_syscalls.skel.h +$(OUTPUT)util/bpf_counter.o: $(SKEL_OUT)/bpf_prog_profiler.skel.h $(SKEL_OUT)/bperf_leader.skel.h $(SKEL_OUT)/bperf_follower.skel.h +$(OUTPUT)util/bpf_lock_contention.o: $(SKEL_OUT)/lock_contention.skel.h +$(OUTPUT)util/bpf_kwork.o: $(SKEL_OUT)/kwork_trace.skel.h +endif
Signature · 1 line
2.54.0.563.g4f69b47b94-goog
Ian Rogers
reviewerPATCH v7 6/14 perf build: Encapsulate vmlinux.h and bpftool in bpf_skel.mak
In reply to Ian RogersCurrently, bpftool and vmlinux.h are prerequisites of the top-level prepare target in Makefile.perf. This unnecessarily blocks the massive parallel C compilation of libraries (perf-util, perf-ui, pmu-events) during the initial startup phase.
Move all bpftool and vmlinux.h generation rules down into tools/perf/bpf_skel.mak to encapsulate BPF tooling completely within the skeleton framework. Remove them entirely from prepare to unblock immediate parallel build execution.
To prevent parallel sub-makes (perf-util and perf-bench) from racing to build shared prerequisites concurrently, while maintaining strict directory encapsulation without top-level inclusions, serialize bench after the util static archive finishes using an order-only prerequisite:
$(LIBPERF_BENCH_IN): FORCE prepare | $(LIBPERF_UTIL)
--- tools/perf/Makefile.config | 2 +- tools/perf/Makefile.perf | 61 +++++--------------------------------- tools/perf/bpf_skel.mak | 47 +++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 55 deletions(-)
tools/perf/Makefile.config +1 -1
@@ -681,7 +681,7 @@ ifeq ($(BUILD_BPF_SKEL),1) endif ifndef GEN_VMLINUX_H - VMLINUX_H=$(src-perf)/util/bpf_skel/vmlinux/vmlinux.h + VMLINUX_H_FILE=$(src-perf)/util/bpf_skel/vmlinux/vmlinux.h endif ifndef NO_LIBUNWIND
tools/perf/Makefile.perf +7 -54
88 lines not on this page · raw message
tools/perf/bpf_skel.mak +47 -0
57 lines not on this page · raw message
Signature · 1 line
2.54.0.563.g4f69b47b94-goog
Ian Rogers
reviewerPATCH v7 7/14 perf build: Pre-generate BPF skeleton tooling during umbrella prepare phase
In reply to Ian RogersCurrently, BPF skeleton generation rules (bpf_skel.mak) are evaluated as part of util/Build. However, because LIBPERF_UTIL_IN explicitly depends on the top-level static libbpf archive, Make completely blocked the execution of bpftool bootstrap and skeleton generation until libbpf finished compiling midway through the build.
Since bpftool bootstrap compiles its own independent copy of libbpf.a, it does not depend on the top-level libbpf target.
Decouple early skeleton tooling generation by attaching bpf-skel-prepare to the umbrella prepare target, exporting CONFIG_PERF_BPF_SKEL to ensure accurate feature propagation. This allows Make to compile bpftool and dump vmlinux.h in the background at build startup, eliminating the initial sub-make startup bottleneck before BPF object compilation while keeping 100% of tooling rules perfectly encapsulated in bpf_skel.mak. Provide an empty fallback target to ensure builds succeed when BPF skeletons are disabled.
--- tools/perf/Makefile.perf | 8 ++++++-- tools/perf/bpf_skel.mak | 8 ++++++++ 2 files changed, 14 insertions(+), 2 deletions(-)
tools/perf/Makefile.perf +6 -2
@@ -275,7 +275,7 @@ ifeq ($(PYLINT),1) endif export srctree OUTPUT RM CC CXX RUSTC CLANG LD AR CFLAGS CXXFLAGS RUST_FLAGS V BISON FLEX AWK LIBBPF READELF -export HOSTCC HOSTLD HOSTAR HOSTCFLAGS SHELLCHECK MYPY PYLINT +export HOSTCC HOSTLD HOSTAR HOSTCFLAGS SHELLCHECK MYPY PYLINT CONFIG_PERF_BPF_SKEL include $(srctree)/tools/build/Makefile.include
@@ -629,8 +629,12 @@ endif __build-dir = $(subst $(OUTPUT),,$(dir $@)) build-dir = $(or $(__build-dir),.) +bpf-skel-prepare: + $(Q)$(MAKE) -f bpf_skel.mak bpf-skel-prepare + prepare: $(OUTPUT)PERF-VERSION-FILE \ arm64-sysreg-defs \ + bpf-skel-prepare \ $(LIBAPI) \ $(LIBPERF) \ $(LIBSUBCMD) \
@@ -971,7 +975,7 @@ FORCE: .PHONY: all install clean config-clean strip install-gtk .PHONY: shell_compatibility_test please_set_SHELL_PATH_to_a_more_modern_shell -.PHONY: .FORCE-PERF-VERSION-FILE TAGS tags cscope FORCE prepare +.PHONY: .FORCE-PERF-VERSION-FILE TAGS tags cscope FORCE prepare bpf-skel-prepare .PHONY: python_perf_target endif # force_fixdep
tools/perf/bpf_skel.mak +8 -0
@@ -15,6 +15,10 @@ ifeq ($(CONFIG_PERF_BPF_SKEL),y) BPFTOOL := $(SKEL_TOOL_TMP_OUT)/bootstrap/bpftool VMLINUX_H := $(SKEL_TOOL_OUT)/vmlinux.h +.PHONY: bpf-skel-prepare +bpf-skel-prepare: $(BPFTOOL) $(VMLINUX_H) + @: + define get_sys_includes $(shell $(1) $(2) -v -E - </dev/null 2>&1 \ | sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }') \
@@ -93,6 +97,10 @@ $(SKEL_OUT)/%.skel.h: $(SKEL_TMP_OUT)/%.bpf.o $(BPFTOOL) .PRECIOUS: $(SKEL_TMP_OUT)/%.bpf.o +else # CONFIG_PERF_BPF_SKEL +.PHONY: bpf-skel-prepare +bpf-skel-prepare: + @: endif # CONFIG_PERF_BPF_SKEL clean:
Signature · 1 line
2.54.0.563.g4f69b47b94-goog
Ian Rogers
reviewerPATCH v7 8/14 perf build: Move libsymbol dependency out of prepare step
In reply to Ian RogersThe prepare step is a large serialization point before parallel sub-makes build the perf tool. The libsymbol headers are used in the bench and util libraries. Move the libsymbol dependency out of the prepare step and into the dependencies for those targets to avoid it being a source of serialization in the prepare step.
--- tools/perf/Makefile.perf | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
tools/perf/Makefile.perf +3 -4
@@ -558,7 +558,7 @@ $(LIBPMU_EVENTS): $(LIBPMU_EVENTS_IN) # The $(LIBPERF_UTIL) dependency is to ensure bpftool and vmlinux.h # aren't racily built for bench/bpf_skel/bench_uprobe.bpf.c -$(LIBPERF_BENCH_IN): FORCE prepare | $(LIBPERF_UTIL) +$(LIBPERF_BENCH_IN): FORCE prepare $(LIBSYMBOL) | $(LIBPERF_UTIL) $(Q)$(MAKE) $(build)=perf-bench $(LIBPERF_BENCH): $(LIBPERF_BENCH_IN)
@@ -576,7 +576,7 @@ $(LIBPERF_UI_IN): FORCE prepare $(LIBPERF_UI): $(LIBPERF_UI_IN) $(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $< -$(LIBPERF_UTIL_IN): FORCE prepare +$(LIBPERF_UTIL_IN): FORCE prepare $(LIBSYMBOL) $(Q)$(MAKE) $(build)=perf-util $(LIBPERF_UTIL): $(LIBPERF_UTIL_IN)
@@ -637,8 +637,7 @@ prepare: $(OUTPUT)PERF-VERSION-FILE \ bpf-skel-prepare \ $(LIBAPI) \ $(LIBPERF) \ - $(LIBSUBCMD) \ - $(LIBSYMBOL) + $(LIBSUBCMD) ifdef LIBBPF_STATIC prepare: $(LIBBPF)
Signature · 1 line
2.54.0.563.g4f69b47b94-goog
Ian Rogers
reviewerPATCH v7 9/14 perf build: Remove redundant libbpf feature check for static builds
In reply to Ian RogersBy default, the perf tool compiles and statically links against its own internal copy of libbpf (tools/lib/bpf/libbpf.a), setting LIBBPF_STATIC=1.
Despite this static linkage, Makefile.config unconditionally executed $(call feature_check,libbpf), which forced a synchronous sub-make fork during AST parsing to detect dynamic system libbpf libraries.
As noted in the internal Makefile comments, this check was executed purely so that running make VF=1 would display the detection status of system libbpf. During standard builds without LIBBPF_DYNAMIC=1, the detection result was entirely ignored.
Wrap the libbpf feature check inside LIBBPF_DYNAMIC=1 so Make avoids the redundant sub-make fork overhead during standard static builds.
--- tools/perf/Makefile.config | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
tools/perf/Makefile.config +1 -3
@@ -575,10 +575,8 @@ ifndef NO_LIBELF ifndef NO_LIBBPF ifeq ($(feature-bpf), 1) - # detecting libbpf without LIBBPF_DYNAMIC, so make VF=1 shows libbpf detection status - $(call feature_check,libbpf) - ifdef LIBBPF_DYNAMIC + $(call feature_check,libbpf) ifeq ($(feature-libbpf), 1) EXTLIBS += -lbpf CFLAGS += -DHAVE_LIBBPF_SUPPORT
Signature · 1 line
2.54.0.563.g4f69b47b94-goog
Ian Rogers
reviewerPATCH v7 10/14 perf pmu-events: Split big_c_string storage into standalone compilation unit
In reply to Ian RogersCurrently, jevents.py emits both the massive 2.8 MB big_c_string literal and tens of thousands of compact_pmu_event struct arrays into a single pmu-events.c compilation unit. Compiling this giant file takes ~2.2 seconds on a single CPU core during Kbuild startup.
Refactor jevents.py to emit big_c_string into a dedicated pmu-events-string.c compilation unit. This allows Kbuild to compile pmu-events.o and pmu-events-string.o simultaneously in parallel across two separate CPU cores, preserving 100% string deduplication and zero dynamic ELF relocations while cutting C compilation latency in half.
Add pmu-events-string.c to tools/perf/.gitignore to ensure in-tree Kbuild runs do not leave untracked generated files in the working directory.
To guarantee 100% backward compatibility with GNU Make 4.0+ (avoiding the Make 4.3+ grouped target &: syntax which causes older Make versions like 4.2.1 to spawn multiple concurrent jevents.py processes during parallel builds), implement a robust dependency chaining pattern:
$(PMU_EVENTS_C): $(JEVENTS_DEPS)
$(PMU_EVENTS_STRING_C): $(PMU_EVENTS_C)
@:
This ensures jevents.py is invoked exactly once. If jevents.py aborts early, Make's .DELETE_ON_ERROR: purges pmu-events.c, guaranteeing that subsequent Make invocations correctly re-execute the script and overwrite pmu-events-string.c. In jevents.py, explicitly close output_file first and output_string_file second at the tail of main() to guarantee that pmu-events-string.c receives a filesystem timestamp greater than or equal to pmu-events.c, completely avoiding redundant incremental rebuilds.
--- tools/perf/.gitignore | 1 + tools/perf/Makefile.perf | 4 ++-- tools/perf/pmu-events/Build | 16 +++++++++++++++- tools/perf/pmu-events/jevents.py | 23 +++++++++++++++++++---- 4 files changed, 37 insertions(+), 7 deletions(-)
tools/perf/.gitignore +1 -0
@@ -38,6 +38,7 @@ arch/*/include/generated/ trace/beauty/generated/ pmu-events/arch/common/common/legacy-cache.json pmu-events/pmu-events.c +pmu-events/pmu-events-string.c pmu-events/jevents pmu-events/metric_test.log pmu-events/empty-pmu-events.log
tools/perf/Makefile.perf +2 -2
@@ -925,7 +925,7 @@ bpf-skel-clean: pmu-events-clean: ifeq ($(OUTPUT),) $(call QUIET_CLEAN, pmu-events) $(RM) \ - pmu-events/pmu-events.c \ + pmu-events/pmu-events*.c \ pmu-events/metric_test.log \ pmu-events/test-empty-pmu-events.c \ pmu-events/empty-pmu-events.log
@@ -933,7 +933,7 @@ ifeq ($(OUTPUT),) -name 'extra-metricgroups.json' -delete else # When an OUTPUT directory is present, clean up the copied pmu-events/arch directory. $(call QUIET_CLEAN, pmu-events) $(RM) -r $(OUTPUT)pmu-events/arch \ - $(OUTPUT)pmu-events/pmu-events.c \ + $(OUTPUT)pmu-events/pmu-events*.c \ $(OUTPUT)pmu-events/metric_test.log \ $(OUTPUT)pmu-events/test-empty-pmu-events.c \ $(OUTPUT)pmu-events/empty-pmu-events.log
tools/perf/pmu-events/Build +15 -1
@@ -1,7 +1,12 @@ EMPTY_PMU_EVENTS_C = pmu-events/empty-pmu-events.c # pmu-events.c will be generated by jevents.py or copied from EMPTY_PMU_EVENTS_C PMU_EVENTS_C = $(OUTPUT)pmu-events/pmu-events.c +PMU_EVENTS_STRING_C = $(OUTPUT)pmu-events/pmu-events-string.c + pmu-events-y += pmu-events.o +ifneq ($(NO_JEVENTS),1) +pmu-events-y += pmu-events-string.o +endif # pmu-events.c file is generated in the OUTPUT directory so it needs a # separate rule to depend on it properly
@@ -9,6 +14,10 @@ $(OUTPUT)pmu-events/pmu-events.o: $(PMU_EVENTS_C) $(call rule_mkdir) $(call if_changed_dep,cc_o_c) +$(OUTPUT)pmu-events/pmu-events-string.o: $(PMU_EVENTS_STRING_C) + $(call rule_mkdir) + $(call if_changed_dep,cc_o_c) + # Message for $(call echo-cmd,cp), possibly remove the src file from # the destination to save space in the build log. quiet_cmd_cp = COPY $(patsubst %$<,%,$@) <- $<
@@ -118,6 +127,7 @@ CUR_OUT_JSON := $(shell [ -d $(OUT_DIR) ] && find $(OUT_DIR) -type f) # Things in the OUTPUT directory but shouldn't be there as computed by # OUT_JSON and GEN_JSON. + ORPHAN_FILES := $(filter-out $(OUT_JSON) $(GEN_JSON),$(CUR_OUT_JSON)) # Message for $(call echo-cmd,mkd). There is already a mkdir message
@@ -224,6 +234,10 @@ endif # and inputs are dependencies. $(PMU_EVENTS_C): $(JEVENTS_DEPS) $(call rule_mkdir) - $(Q)$(call echo-cmd,gen)$(PYTHON) $(JEVENTS_PY) $(JEVENTS_ARCH) $(JEVENTS_MODEL) $(OUT_DIR) $@ + $(Q)$(call echo-cmd,gen)$(PYTHON) $(JEVENTS_PY) $(JEVENTS_ARCH) $(JEVENTS_MODEL) \ + $(OUT_DIR) $(PMU_EVENTS_C) $(PMU_EVENTS_STRING_C) + +$(PMU_EVENTS_STRING_C): $(PMU_EVENTS_C) + @: endif # ifeq ($(NO_JEVENTS),1)
tools/perf/pmu-events/jevents.py +19 -4
@@ -1422,6 +1422,8 @@ such as "arm/cortex-a34".''', ) ap.add_argument( 'output_file', type=argparse.FileType('w', encoding='utf-8'), nargs='?', default=sys.stdout) + ap.add_argument( + 'output_string_file', type=argparse.FileType('w', encoding='utf-8'), nargs='?', default=None) _args = ap.parse_args() _args.output_file.write(f"""
@@ -1463,10 +1465,20 @@ struct pmu_table_entry { ftw(arch_path, [], preprocess_one_file) _bcs.compute() - _args.output_file.write('static const char *const big_c_string =\n') - for s in _bcs.big_string: - _args.output_file.write(s) - _args.output_file.write(';\n\n') + if not _args.output_string_file: + _args.output_file.write('static const char *const big_c_string =\n') + for s in _bcs.big_string: + _args.output_file.write(s) + _args.output_file.write(';\n\n') + else: + _args.output_string_file.write('/* SPDX-License-Identifier: GPL-2.0 */\n') + _args.output_string_file.write('/* Autogenerated by jevents.py */\n') + _args.output_string_file.write('extern const char big_c_string[];\n') + _args.output_string_file.write('const char big_c_string[] =\n') + for s in _bcs.big_string: + _args.output_string_file.write(s) + _args.output_string_file.write(';\n') + _args.output_file.write('extern const char big_c_string[];\n\n') for arch in archs: arch_path = f'{_args.starting_dir}/{arch}' ftw(arch_path, [], process_one_file)
@@ -1476,6 +1488,9 @@ struct pmu_table_entry { print_mapping_table(archs) print_system_mapping_table() print_metricgroups() + _args.output_file.close() + if _args.output_string_file: + _args.output_string_file.close() if __name__ == '__main__': main()
Signature · 1 line
2.54.0.563.g4f69b47b94-goog
Ian Rogers
reviewerPATCH v7 11/14 perf pmu-events: Parallelize JSON and metric pre-computation in jevents.py
In reply to Ian RogersCurrently, jevents.py parses hundreds of JSON event and metric files sequentially across all CPU architectures during Kbuild startup, taking ~3.3 seconds of pure single-core execution time.
Refactor jevents.py to pre-populate its internal JSON AST cache in parallel across all available CPU cores using ProcessPoolExecutor. Define the worker process initializer _init_worker at the top-level module scope to guarantee flawless pickling and standard event mapping inheritance under spawn multiprocessing semantics (avoiding AttributeError crashes when spawn is used instead of fork). This accelerates jevents.py execution by over 11x (from 3.3s down to ~290ms), fully reclaiming multi-core concurrency during the build generation phase.
--- tools/perf/pmu-events/jevents.py | 36 ++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-)
tools/perf/pmu-events/jevents.py +32 -4
@@ -457,8 +457,8 @@ class JsonEvent: return f'{{ { _bcs.offsets[s] } }}, /* {fix_comment(s)} */\n' -@lru_cache(maxsize=None) -def read_json_events(path: str, topic: str) -> Sequence[JsonEvent]: +_json_cache = {} +def _read_json_events_impl(path: str, topic: str) -> Sequence[JsonEvent]: """Read json events from the specified file.""" try: events = json.load(open(path), object_hook=JsonEvent)
@@ -474,12 +474,16 @@ def read_json_events(path: str, topic: str) -> Sequence[JsonEvent]: if updates: for event in events: if event.metric_name in updates: - # print(f'Updated {event.metric_name} from\n"{event.metric_expr}"\n' - # f'to\n"{updates[event.metric_name]}"') event.metric_expr = updates[event.metric_name] return events +def read_json_events(path: str, topic: str) -> Sequence[JsonEvent]: + key = (path, topic) + if key not in _json_cache: + _json_cache[key] = _read_json_events_impl(path, topic) + return _json_cache[key] + def preprocess_arch_std_files(archpath: str) -> None: """Read in all architecture standard events.""" global _arch_std_events
@@ -1381,6 +1385,14 @@ const char *describe_metricgroup(const char *group) } """) +def _parallel_read_json_events(task: Tuple[str, str]) -> Tuple[str, str, Sequence[JsonEvent]]: + path, topic = task + return path, topic, _read_json_events_impl(path, topic) + +def _init_worker(std_events: dict) -> None: + global _arch_std_events + _arch_std_events = std_events + def main() -> None: global _args
@@ -1459,9 +1471,25 @@ struct pmu_table_entry { raise IOError(f'Missing architecture directory \'{_args.arch}\'') archs.sort() + import concurrent.futures + tasks = [] + def collect_json(parents: Sequence[str], item: os.DirEntry) -> None: + if len(parents) == 0: + return + if item.is_file() and item.name.endswith('.json') and not item.name.endswith('metricgroups.json'): + tasks.append((item.path, get_topic(item.name))) + for arch in archs: arch_path = f'{_args.starting_dir}/{arch}' preprocess_arch_std_files(arch_path) + ftw(arch_path, [], collect_json) + + with concurrent.futures.ProcessPoolExecutor(initializer=_init_worker, initargs=(_arch_std_events,)) as executor: + for path, topic, events in executor.map(_parallel_read_json_events, tasks): + _json_cache[(path, topic)] = events + + for arch in archs: + arch_path = f'{_args.starting_dir}/{arch}' ftw(arch_path, [], preprocess_one_file) _bcs.compute()
Signature · 1 line
2.54.0.563.g4f69b47b94-goog
Ian Rogers
reviewerPATCH v7 12/14 perf build: Prefix SCRIPTS with output directory to fix continuous rebuilds
In reply to Ian RogersIn Makefile.perf, ALL_PROGRAMS includes SCRIPTS (perf-archive, perf-iostat). However, unlike PROGRAMS and DLFILTERS, SCRIPTS was not prefixed with $(OUTPUT).
During out-of-tree builds (or when O= is specified), Make checked for the unprefixed target 'tools/perf/perf-archive'. Since the actual script was installed into $(OUTPUT)perf-archive, Make concluded the target was missing and continuously re-executed the script installation rule on every single incremental build.
Prefix SCRIPTS with $(OUTPUT) and update the static pattern rule to ensure Kbuild correctly tracks generated script prerequisites during incremental builds.
--- tools/perf/Makefile.perf | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
tools/perf/Makefile.perf +3 -3
@@ -405,7 +405,7 @@ python-clean := $(call QUIET_CLEAN, python) $(RM) -r $(PYTHON_EXTBUILD) $(OUTPUT # Use the detected configuration -include $(OUTPUT).config-detected -SCRIPTS = $(patsubst %.sh,%,$(SCRIPT_SH)) +SCRIPTS = $(addprefix $(OUTPUT),$(patsubst %.sh,%,$(SCRIPT_SH))) PROGRAMS += $(OUTPUT)perf
@@ -592,8 +592,8 @@ $(GTK_IN): FORCE prepare $(OUTPUT)libperf-gtk.so: $(GTK_IN) $(PERFLIBS) $(QUIET_LINK)$(CC) -o $@ -shared $(LDFLAGS) $(filter %.o,$^) $(GTK_LIBS) -$(SCRIPTS) : % : %.sh - $(QUIET_GEN)$(INSTALL) '[email protected]' '$(OUTPUT)$@' +$(SCRIPTS) : $(OUTPUT)% : %.sh + $(QUIET_GEN)$(INSTALL) '$<' '$@' $(OUTPUT)PERF-VERSION-FILE: .FORCE-PERF-VERSION-FILE $(Q)$(SHELL_PATH) util/PERF-VERSION-GEN $(OUTPUT)
Signature · 1 line
2.54.0.563.g4f69b47b94-goog
Ian Rogers
reviewerPATCH v7 13/14 perf pmu-events: Convert recursive shell assignments and macros to Make built-ins
In reply to Ian RogersIn pmu-events/Build, ZENS, ARMS, and INTELS were assigned using recursive assignment (=), and model_name/vendor_name were evaluated using shell macros (echo ... | sed ...).
Because these variables were expanded inside the COPY_RULE dependency evaluation loop across hundreds of PMU JSON files and inside every metric generation recipe, Kbuild continuously re-executed 'ls', 'grep', and 'sed' shell forks thousands of times during AST parsing and execution.
Convert ZENS, ARMS, and INTELS to simply expanded variables (:=) and replace model_name/vendor_name with pure GNU Make string functions. This guarantees Make executes directory probing shell forks exactly once when the Build file is parsed and evaluates path macros purely in memory, completely eliminating over 7,800 redundant sub-processes during build startup.
--- tools/perf/pmu-events/Build | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
tools/perf/pmu-events/Build +5 -5
@@ -56,12 +56,12 @@ $(LEGACY_CACHE_JSON): $(LEGACY_CACHE_PY) # Python to generate architectural metrics GEN_METRIC_DEPS := pmu-events/metric.py pmu-events/common_metrics.py # Functions to extract the model from an extra-metrics.json or extra-metricgroups.json path. -model_name = $(shell echo $(1)|sed -e 's@.\+/\(.*\)/extra-metric.*\.json@\1@') -vendor_name = $(shell echo $(1)|sed -e 's@.\+/\(.*\)/[^/]*/extra-metric.*\.json@\1@') +model_name = $(notdir $(patsubst %/,%,$(dir $(1)))) +vendor_name = $(notdir $(patsubst %/,%,$(dir $(patsubst %/,%,$(dir $(1)))))) ifeq ($(JEVENTS_ARCH),$(filter $(JEVENTS_ARCH),x86 all)) # Generate AMD Json -ZENS = $(shell ls -d pmu-events/arch/x86/amdzen*) +ZENS := $(shell ls -d pmu-events/arch/x86/amdzen*) ZEN_METRICS = $(foreach x,$(ZENS),$(OUTPUT)$(x)/extra-metrics.json) ZEN_METRICGROUPS = $(foreach x,$(ZENS),$(OUTPUT)$(x)/extra-metricgroups.json) GEN_JSON += $(ZEN_METRICS) $(ZEN_METRICGROUPS)
@@ -78,7 +78,7 @@ endif ifeq ($(JEVENTS_ARCH),$(filter $(JEVENTS_ARCH),arm64 all)) # Generate ARM Json -ARMS = $(shell ls -d pmu-events/arch/arm64/arm/*|grep -v cmn) +ARMS := $(shell ls -d pmu-events/arch/arm64/arm/*|grep -v cmn) ARM_METRICS = $(foreach x,$(ARMS),$(OUTPUT)$(x)/extra-metrics.json) ARM_METRICGROUPS = $(foreach x,$(ARMS),$(OUTPUT)$(x)/extra-metricgroups.json) GEN_JSON += $(ARM_METRICS) $(ARM_METRICGROUPS)
@@ -95,7 +95,7 @@ endif ifeq ($(JEVENTS_ARCH),$(filter $(JEVENTS_ARCH),x86 all)) # Generate Intel Json -INTELS = $(shell ls -d pmu-events/arch/x86/*|grep -v amdzen|grep -v mapfile.csv) +INTELS := $(shell ls -d pmu-events/arch/x86/*|grep -v amdzen|grep -v mapfile.csv) INTEL_METRICS = $(foreach x,$(INTELS),$(OUTPUT)$(x)/extra-metrics.json) INTEL_METRICGROUPS = $(foreach x,$(INTELS),$(OUTPUT)$(x)/extra-metricgroups.json) GEN_JSON += $(INTEL_METRICS) $(INTEL_METRICGROUPS)
Signature · 1 line
2.54.0.563.g4f69b47b94-goog
Ian Rogers
reviewerPATCH v7 14/14 perf build: Convert llvm-config shell queries to simply expanded variables
In reply to Ian RogersIn Makefile.config, CFLAGS, CXXFLAGS, LIBLLVM, and EXTLIBS were assigned using recursive expansion or appended with raw $(shell $(LLVM_CONFIG) ...) calls. Because these variables were expanded during dependency evaluation across every single object file compilation rule, Kbuild continuously re-executed llvm-config forks nearly 200 times during incremental builds.
Convert llvm-config shell queries to simply expanded variables (:=) to ensure Make evaluates LLVM compiler flags and library paths exactly once when Makefile.config is parsed, eliminating ~185 redundant sub-processes during build startup.
--- tools/perf/Makefile.config | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
tools/perf/Makefile.config +8 -5
@@ -925,11 +925,14 @@ ifndef NO_LIBLLVM $(call feature_check,llvm-perf) ifeq ($(feature-llvm-perf), 1) CFLAGS += -DHAVE_LIBLLVM_SUPPORT - CFLAGS += $(shell $(LLVM_CONFIG) --cflags) - CXXFLAGS += -DHAVE_LIBLLVM_SUPPORT - CXXFLAGS += $(shell $(LLVM_CONFIG) --cxxflags) - LIBLLVM = $(shell $(LLVM_CONFIG) --libs all) $(shell $(LLVM_CONFIG) --system-libs) - EXTLIBS += -L$(shell $(LLVM_CONFIG) --libdir) $(LIBLLVM) + LLVM_CFLAGS := $(shell $(LLVM_CONFIG) --cflags 2>/dev/null) + LLVM_CXXFLAGS := $(shell $(LLVM_CONFIG) --cxxflags 2>/dev/null) + LLVM_LIBLLVM := $(shell $(LLVM_CONFIG) --libs all 2>/dev/null) $(shell $(LLVM_CONFIG) --system-libs 2>/dev/null) + LLVM_LIBDIR := $(shell $(LLVM_CONFIG) --libdir 2>/dev/null) + CFLAGS += $(LLVM_CFLAGS) + CXXFLAGS += -DHAVE_LIBLLVM_SUPPORT $(LLVM_CXXFLAGS) + LIBLLVM := $(LLVM_LIBLLVM) + EXTLIBS += -L$(LLVM_LIBDIR) $(LIBLLVM) EXTLIBS += -lstdc++ $(call detected,CONFIG_LIBLLVM) else
Signature · 1 line
2.54.0.563.g4f69b47b94-goog
Re: [PATCH v7 00/14] perf build: Reduce build time by nearly half
In reply to Ian RogersQuoted 35 lines · Ian Rogers
This patch series refactors
Kbuildinternals, BPF skeleton generation, Python AST pre-computation, and foundational tooling dependencies across the perf tool build system. By eliminating umbrella target synchronization barriers, decoupling static library prerequisites, parallelizing single-core script generators, and eradicating redundant feature checks, this series unlocks absolute theoretical peak multi-core concurrency duringKbuildstartup.On a 28-core build workstation (make -j28 all from scratch), clean build latency improves by over 44%:
Before:
real 0m29.006s user 2m46.019s sys 0m30.610sAfter:
real 0m16.091s user 2m40.135s sys 0m25.740sSaving 12.9 full seconds time per clean build. Furthermore, nothing to build incremental builds are improved by nearly 7x:
Before:
real 0m11.528s user 0m9.633s sys 0m6.965sAfter:
real 0m1.717s user 0m1.682s sys 0m0.960sSummary of Patches:
Quoted 12 lines
1: Fast-Path Feature Detection
- Refactors test-clang-bpf-co-re.bin and test-bpftool-skeletons.bin feature checks to group shell pipelines within curly braces and redirect both stdout and stderr to .make.output before touching $@ purely upon success
(> $(@:.bin=.make.output) 2>&1 && touch $@). Grouping the pipeline ({ cmd1 | cmd2; }) ensures that compiler stderr is successfully captured in .make.output rather than escaping to the parent shell. This perfectly matches standardKbuildfeature check conventions and ensures the target files are touched on disk purely upon success, allowingKbuildto cache positive detections and avoid continuous sub-make re-evaluations during incremental builds. Adds test-bpftool-skeletons.bin to the clean FILES list and explicit source prerequisitetest-clang-bpf-co-re.c.
I think patch 1 can be separated and needs Ack/Review from BPF folks.
Quoted 66 lines
2-4: Flattening Umbrella Prepare Barriers
- builtin-trace embedded inclusions and pmu-events generation are completely decoupled from the sequential "prepare" umbrella target, eliminating Make AST double-parsing overhead and unchoking parallel compilation barriers.5-7: Decoupling & Pre-generating BPF Skeletons
- BPF skeleton rules are extracted out of Makefile.perf into bpf_skel.mak.
- Decouples bpftool bootstrap from top-level static libbpf dependencies, attaching bpf-skel-prepare directly to the umbrella prepare target. This allows Make to pre-compile bpftool and dumpvmlinux.hin the background at build startup, removing the 7-second serialization bottleneck before BPF object compilation.
- Ensures benchmark skeleton intermediate .bpf.o files are cleanly removed during make clean, and adds bpf-skel-prepare to .PHONY.8-9: Foundational Linkage Optimization
- Moves static libsymbol library prerequisites out of the prepare step.
- Eliminates redundant libbpf sub-make feature checks during static builds.10-11:
jevents.pyConcurrency & Deduplication
- Splits the massive 2.8 MBbig_c_stringliteral out ofpmu-events.cinto a dedicatedpmu-events-string.ccompilation unit. This slices C compilation latency in half by compiling string and struct tables simultaneously across separate CPU cores while preserving zero dynamic ELF relocations. Addspmu-events-string.cto .gitignore, declares extern const char big_c_string[]; locally insideoutput_string_fileandoutput_filewhen split to prevent linkage conflicts withempty-pmu-events.c, defers file closures to ensure identical timestamps, and uses canonical Make 4.0 @: dependency chaining.
- Pre-populatesjevents.pyJSON ASTs and metric formulas in parallel across all available CPU cores using ProcessPoolExecutor (accelerating Python execution by 11x, from 3.3s down to ~290ms). Moves_init_workerto top-level scope to ensure clean pickling under spawn multiprocessing start methods.12: Out-of-Tree Incremental Rebuild Fix
- Prefixes SCRIPTS (perf-archive, perf-iostat) with $(OUTPUT) to prevent Make from continuously re-executing script installation rules on already built out-of-tree builds.13-14: AST Parsing Optimization & Shell Fork Eradication
- Converts ZENS, ARMS, and INTELS in pmu-events/Build from recursive assignment (=) to simply expanded assignment (:=) and replaces model_name/vendor_name with pure GNU Make string functions. This guarantees Make executes directory probing shell forks exactly once during AST parsing and evaluates path macros purely in memory, completely eradicating over 7,800 redundant sub-processes during out-of-tree build evaluation.
- Converts llvm-config shell queries in Makefile.config from recursive assignment (=) to simply expanded assignment (:=). This eliminates ~185 redundant sub-processes that were previously executed across object compilation dependency checks.Changes since v6:
- Rebase/resend as last series failed to apply by Sashiko.Ian Rogers (14):
tools build: Fix feature checks to touch target files on success perf trace beauty: Make beauty generated C code standalone .o files perf build: Decouple pmu-events from prepare umbrella target perf build: Remove empty archheaders target
perf build: Move BPF skeleton generation out of Makefile.perf perf build: Encapsulatevmlinux.hand bpftool in bpf_skel.mak perf build: Pre-generate BPF skeleton tooling during umbrella prepare
phase
perf build: Move libsymbol dependency out of prepare step perf build: Remove redundant libbpf feature check for static builds perf pmu-events: Splitbig_c_stringstorage into standalone
compilation unit
Quoted 8 lines
perf pmu-events: Parallelize JSON and metric pre-computation in
jevents.py
perf build: Prefix SCRIPTS with output directory to fix continuous
rebuilds
perf pmu-events: Convert recursive shell assignments and macros to
Make built-ins
perf build: Convert llvm-config shell queries to simply expanded
variables
Thanks,
Namhyung
Ian Rogers
reviewerRe: [PATCH v7 00/14] perf build: Reduce build time by nearly half
Quoted 50 lines · Namhyung Kim
Quoted 35 lines · Ian Rogers
This patch series refactors
Kbuildinternals, BPF skeleton generation, Python AST pre-computation, and foundational tooling dependencies across the perf tool build system. By eliminating umbrella target synchronization barriers, decoupling static library prerequisites, parallelizing single-core script generators, and eradicating redundant feature checks, this series unlocks absolute theoretical peak multi-core concurrency duringKbuildstartup.On a 28-core build workstation (make -j28 all from scratch), clean build latency improves by over 44%:
Before:
real 0m29.006s user 2m46.019s sys 0m30.610sAfter:
real 0m16.091s user 2m40.135s sys 0m25.740sSaving 12.9 full seconds time per clean build. Furthermore, nothing to build incremental builds are improved by nearly 7x:
Before:
real 0m11.528s user 0m9.633s sys 0m6.965sAfter:
real 0m1.717s user 0m1.682s sys 0m0.960sSummary of Patches:
Quoted 12 lines
1: Fast-Path Feature Detection
- Refactors test-clang-bpf-co-re.bin and test-bpftool-skeletons.bin feature checks to group shell pipelines within curly braces and redirect both stdout and stderr to .make.output before touching $@ purely upon success
(> $(@:.bin=.make.output) 2>&1 && touch $@). Grouping the pipeline ({ cmd1 | cmd2; }) ensures that compiler stderr is successfully captured in .make.output rather than escaping to the parent shell. This perfectly matches standardKbuildfeature check conventions and ensures the target files are touched on disk purely upon success, allowingKbuildto cache positive detections and avoid continuous sub-make re-evaluations during incremental builds. Adds test-bpftool-skeletons.bin to the clean FILES list and explicit source prerequisitetest-clang-bpf-co-re.c.
Quoted 1 line
I think patch 1 can be separated and needs Ack/Review from BPF folks.
So I dropped the patch restricting the features tested when making bpftool in bootstrap mode as perf does:
https://lore.kernel.org/linux-perf-users/[email protected]/
We don't need to test for libbfd disassembly support for bpftool if we just need the bootstrap version. But anyway, I dropped that patch and hopefully someone on the BPF side can take it or something. I find the BPF mailing list has a difficult user interface.
The only patch remaining is:
https://lore.kernel.org/linux-perf-users/[email protected]/
```
...
-$(OUTPUT)test-clang-bpf-co-re.bin:
- $(CLANG) -S -g --target=bpf -o - $(patsubst %.bin,%.c,$(@F)) | \
- grep BTF_KIND_VAR
+$(OUTPUT)test-clang-bpf-co-re.bin: test-clang-bpf-co-re.c
+ { $(CLANG) -S -g --target=bpf -o - $< | \
+ grep BTF_KIND_VAR; } > $(@:.bin=.make.output) 2>&1 && touch $@
$(OUTPUT)test-file-handle.bin:
$(BUILD)
@@ -393,8 +394,8 @@ $(OUTPUT)test-libopenssl.bin:
$(BUILD) $(shell $(PKG_CONFIG) --libs --cflags openssl 2>/dev/null)
$(OUTPUT)test-bpftool-skeletons.bin:
- $(SYSTEM_BPFTOOL) version | grep '^features:.*skeletons' \
- > $(@:.bin=.make.output) 2>&1
+ { $(SYSTEM_BPFTOOL) version | grep '^features:.*skeletons'; } \
+ > $(@:.bin=.make.output) 2>&1 && touch $@
...
```which just adds && touch $@ so that every incremental build doesn't re-detect these features. None of the logic changes, so I was hoping that a BPF sign off wouldn't be a requirement. But anyway, let's hope a BPF person responds.
Quoted 75 lines
Quoted 66 lines
2-4: Flattening Umbrella Prepare Barriers
- builtin-trace embedded inclusions and pmu-events generation are completely decoupled from the sequential "prepare" umbrella target, eliminating Make AST double-parsing overhead and unchoking parallel compilation barriers.5-7: Decoupling & Pre-generating BPF Skeletons
- BPF skeleton rules are extracted out of Makefile.perf into bpf_skel.mak.
- Decouples bpftool bootstrap from top-level static libbpf dependencies, attaching bpf-skel-prepare directly to the umbrella prepare target. This allows Make to pre-compile bpftool and dumpvmlinux.hin the background at build startup, removing the 7-second serialization bottleneck before BPF object compilation.
- Ensures benchmark skeleton intermediate .bpf.o files are cleanly removed during make clean, and adds bpf-skel-prepare to .PHONY.8-9: Foundational Linkage Optimization
- Moves static libsymbol library prerequisites out of the prepare step.
- Eliminates redundant libbpf sub-make feature checks during static builds.10-11:
jevents.pyConcurrency & Deduplication
- Splits the massive 2.8 MBbig_c_stringliteral out ofpmu-events.cinto a dedicatedpmu-events-string.ccompilation unit. This slices C compilation latency in half by compiling string and struct tables simultaneously across separate CPU cores while preserving zero dynamic ELF relocations. Addspmu-events-string.cto .gitignore, declares extern const char big_c_string[]; locally insideoutput_string_fileandoutput_filewhen split to prevent linkage conflicts withempty-pmu-events.c, defers file closures to ensure identical timestamps, and uses canonical Make 4.0 @: dependency chaining.
- Pre-populatesjevents.pyJSON ASTs and metric formulas in parallel across all available CPU cores using ProcessPoolExecutor (accelerating Python execution by 11x, from 3.3s down to ~290ms). Moves_init_workerto top-level scope to ensure clean pickling under spawn multiprocessing start methods.12: Out-of-Tree Incremental Rebuild Fix
- Prefixes SCRIPTS (perf-archive, perf-iostat) with $(OUTPUT) to prevent Make from continuously re-executing script installation rules on already built out-of-tree builds.13-14: AST Parsing Optimization & Shell Fork Eradication
- Converts ZENS, ARMS, and INTELS in pmu-events/Build from recursive assignment (=) to simply expanded assignment (:=) and replaces model_name/vendor_name with pure GNU Make string functions. This guarantees Make executes directory probing shell forks exactly once during AST parsing and evaluates path macros purely in memory, completely eradicating over 7,800 redundant sub-processes during out-of-tree build evaluation.
- Converts llvm-config shell queries in Makefile.config from recursive assignment (=) to simply expanded assignment (:=). This eliminates ~185 redundant sub-processes that were previously executed across object compilation dependency checks.Changes since v6:
- Rebase/resend as last series failed to apply by Sashiko.Ian Rogers (14):
tools build: Fix feature checks to touch target files on success perf trace beauty: Make beauty generated C code standalone .o files perf build: Decouple pmu-events from prepare umbrella target perf build: Remove empty archheaders target
perf build: Move BPF skeleton generation out of Makefile.perf perf build: Encapsulatevmlinux.hand bpftool in bpf_skel.mak perf build: Pre-generate BPF skeleton tooling during umbrella prepare
phase
perf build: Move libsymbol dependency out of prepare step perf build: Remove redundant libbpf feature check for static builds perf pmu-events: Splitbig_c_stringstorage into standalone
compilation unitQuoted 8 lines
perf pmu-events: Parallelize JSON and metric pre-computation in
jevents.py
perf build: Prefix SCRIPTS with output directory to fix continuous
rebuilds
perf pmu-events: Convert recursive shell assignments and macros to
Make built-ins
perf build: Convert llvm-config shell queries to simply expanded
variables
Quoted 1 line
Reviewed-by Namhyung Kim <[email protected]>
Thanks!
Ian
Quoted 3 lines
Thanks,
Namhyung
Arnaldo Carvalho de Melo
maintainerRe: [PATCH v7 00/14] perf build: Reduce build time by nearly half
In reply to Namhyung KimQuoted 126 lines · Namhyung Kim
Quoted 35 lines · Ian Rogers
This patch series refactors
Kbuildinternals, BPF skeleton generation, Python AST pre-computation, and foundational tooling dependencies across the perf tool build system. By eliminating umbrella target synchronization barriers, decoupling static library prerequisites, parallelizing single-core script generators, and eradicating redundant feature checks, this series unlocks absolute theoretical peak multi-core concurrency duringKbuildstartup.On a 28-core build workstation (make -j28 all from scratch), clean build latency improves by over 44%:
Before:
real 0m29.006s user 2m46.019s sys 0m30.610sAfter:
real 0m16.091s user 2m40.135s sys 0m25.740sSaving 12.9 full seconds time per clean build. Furthermore, nothing to build incremental builds are improved by nearly 7x:
Before:
real 0m11.528s user 0m9.633s sys 0m6.965sAfter:
real 0m1.717s user 0m1.682s sys 0m0.960sSummary of Patches:
Quoted 12 lines
1: Fast-Path Feature Detection
- Refactors test-clang-bpf-co-re.bin and test-bpftool-skeletons.bin feature checks to group shell pipelines within curly braces and redirect both stdout and stderr to .make.output before touching $@ purely upon success
(> $(@:.bin=.make.output) 2>&1 && touch $@). Grouping the pipeline ({ cmd1 | cmd2; }) ensures that compiler stderr is successfully captured in .make.output rather than escaping to the parent shell. This perfectly matches standardKbuildfeature check conventions and ensures the target files are touched on disk purely upon success, allowingKbuildto cache positive detections and avoid continuous sub-make re-evaluations during incremental builds. Adds test-bpftool-skeletons.bin to the clean FILES list and explicit source prerequisitetest-clang-bpf-co-re.c.I think patch 1 can be separated and needs Ack/Review from BPF folks.
Quoted 66 lines
2-4: Flattening Umbrella Prepare Barriers
- builtin-trace embedded inclusions and pmu-events generation are completely decoupled from the sequential "prepare" umbrella target, eliminating Make AST double-parsing overhead and unchoking parallel compilation barriers.5-7: Decoupling & Pre-generating BPF Skeletons
- BPF skeleton rules are extracted out of Makefile.perf into bpf_skel.mak.
- Decouples bpftool bootstrap from top-level static libbpf dependencies, attaching bpf-skel-prepare directly to the umbrella prepare target. This allows Make to pre-compile bpftool and dumpvmlinux.hin the background at build startup, removing the 7-second serialization bottleneck before BPF object compilation.
- Ensures benchmark skeleton intermediate .bpf.o files are cleanly removed during make clean, and adds bpf-skel-prepare to .PHONY.8-9: Foundational Linkage Optimization
- Moves static libsymbol library prerequisites out of the prepare step.
- Eliminates redundant libbpf sub-make feature checks during static builds.10-11:
jevents.pyConcurrency & Deduplication
- Splits the massive 2.8 MBbig_c_stringliteral out ofpmu-events.cinto a dedicatedpmu-events-string.ccompilation unit. This slices C compilation latency in half by compiling string and struct tables simultaneously across separate CPU cores while preserving zero dynamic ELF relocations. Addspmu-events-string.cto .gitignore, declares extern const char big_c_string[]; locally insideoutput_string_fileandoutput_filewhen split to prevent linkage conflicts withempty-pmu-events.c, defers file closures to ensure identical timestamps, and uses canonical Make 4.0 @: dependency chaining.
- Pre-populatesjevents.pyJSON ASTs and metric formulas in parallel across all available CPU cores using ProcessPoolExecutor (accelerating Python execution by 11x, from 3.3s down to ~290ms). Moves_init_workerto top-level scope to ensure clean pickling under spawn multiprocessing start methods.12: Out-of-Tree Incremental Rebuild Fix
- Prefixes SCRIPTS (perf-archive, perf-iostat) with $(OUTPUT) to prevent Make from continuously re-executing script installation rules on already built out-of-tree builds.13-14: AST Parsing Optimization & Shell Fork Eradication
- Converts ZENS, ARMS, and INTELS in pmu-events/Build from recursive assignment (=) to simply expanded assignment (:=) and replaces model_name/vendor_name with pure GNU Make string functions. This guarantees Make executes directory probing shell forks exactly once during AST parsing and evaluates path macros purely in memory, completely eradicating over 7,800 redundant sub-processes during out-of-tree build evaluation.
- Converts llvm-config shell queries in Makefile.config from recursive assignment (=) to simply expanded assignment (:=). This eliminates ~185 redundant sub-processes that were previously executed across object compilation dependency checks.Changes since v6:
- Rebase/resend as last series failed to apply by Sashiko.Ian Rogers (14):
tools build: Fix feature checks to touch target files on success perf trace beauty: Make beauty generated C code standalone .o files perf build: Decouple pmu-events from prepare umbrella target perf build: Remove empty archheaders target
perf build: Move BPF skeleton generation out of Makefile.perf perf build: Encapsulatevmlinux.hand bpftool in bpf_skel.mak perf build: Pre-generate BPF skeleton tooling during umbrella prepare
phase
perf build: Move libsymbol dependency out of prepare step perf build: Remove redundant libbpf feature check for static builds perf pmu-events: Splitbig_c_stringstorage into standalone
compilation unitQuoted 8 lines
perf pmu-events: Parallelize JSON and metric pre-computation in
jevents.py
perf build: Prefix SCRIPTS with output directory to fix continuous
rebuilds
perf pmu-events: Convert recursive shell assignments and macros to
Make built-ins
perf build: Convert llvm-config shell queries to simply expanded
variables
Quoted 1 line
Reviewed-by Namhyung Kim <[email protected]>
So this is for 2-14? I haven't checked if 1 can be left out of an initial merge by me.
- Arnaldo
Ian Rogers
reviewerRe: [PATCH v7 00/14] perf build: Reduce build time by nearly half
Quoted 128 lines · Arnaldo Carvalho de Melo
Quoted 126 lines · Namhyung Kim
Quoted 35 lines · Ian Rogers
This patch series refactors
Kbuildinternals, BPF skeleton generation, Python AST pre-computation, and foundational tooling dependencies across the perf tool build system. By eliminating umbrella target synchronization barriers, decoupling static library prerequisites, parallelizing single-core script generators, and eradicating redundant feature checks, this series unlocks absolute theoretical peak multi-core concurrency duringKbuildstartup.On a 28-core build workstation (make -j28 all from scratch), clean build latency improves by over 44%:
Before:
real 0m29.006s user 2m46.019s sys 0m30.610sAfter:
real 0m16.091s user 2m40.135s sys 0m25.740sSaving 12.9 full seconds time per clean build. Furthermore, nothing to build incremental builds are improved by nearly 7x:
Before:
real 0m11.528s user 0m9.633s sys 0m6.965sAfter:
real 0m1.717s user 0m1.682s sys 0m0.960sSummary of Patches:
Quoted 12 lines
1: Fast-Path Feature Detection
- Refactors test-clang-bpf-co-re.bin and test-bpftool-skeletons.bin feature checks to group shell pipelines within curly braces and redirect both stdout and stderr to .make.output before touching $@ purely upon success
(> $(@:.bin=.make.output) 2>&1 && touch $@). Grouping the pipeline ({ cmd1 | cmd2; }) ensures that compiler stderr is successfully captured in .make.output rather than escaping to the parent shell. This perfectly matches standardKbuildfeature check conventions and ensures the target files are touched on disk purely upon success, allowingKbuildto cache positive detections and avoid continuous sub-make re-evaluations during incremental builds. Adds test-bpftool-skeletons.bin to the clean FILES list and explicit source prerequisitetest-clang-bpf-co-re.c.I think patch 1 can be separated and needs Ack/Review from BPF folks.
Quoted 74 lines
2-4: Flattening Umbrella Prepare Barriers
- builtin-trace embedded inclusions and pmu-events generation are completely decoupled from the sequential "prepare" umbrella target, eliminating Make AST double-parsing overhead and unchoking parallel compilation barriers.5-7: Decoupling & Pre-generating BPF Skeletons
- BPF skeleton rules are extracted out of Makefile.perf into bpf_skel.mak.
- Decouples bpftool bootstrap from top-level static libbpf dependencies, attaching bpf-skel-prepare directly to the umbrella prepare target. This allows Make to pre-compile bpftool and dumpvmlinux.hin the background at build startup, removing the 7-second serialization bottleneck before BPF object compilation.
- Ensures benchmark skeleton intermediate .bpf.o files are cleanly removed during make clean, and adds bpf-skel-prepare to .PHONY.8-9: Foundational Linkage Optimization
- Moves static libsymbol library prerequisites out of the prepare step.
- Eliminates redundant libbpf sub-make feature checks during static builds.10-11:
jevents.pyConcurrency & Deduplication
- Splits the massive 2.8 MBbig_c_stringliteral out ofpmu-events.cinto a dedicatedpmu-events-string.ccompilation unit. This slices C compilation latency in half by compiling string and struct tables simultaneously across separate CPU cores while preserving zero dynamic ELF relocations. Addspmu-events-string.cto .gitignore, declares extern const char big_c_string[]; locally insideoutput_string_fileandoutput_filewhen split to prevent linkage conflicts withempty-pmu-events.c, defers file closures to ensure identical timestamps, and uses canonical Make 4.0 @: dependency chaining.
- Pre-populatesjevents.pyJSON ASTs and metric formulas in parallel across all available CPU cores using ProcessPoolExecutor (accelerating Python execution by 11x, from 3.3s down to ~290ms). Moves_init_workerto top-level scope to ensure clean pickling under spawn multiprocessing start methods.12: Out-of-Tree Incremental Rebuild Fix
- Prefixes SCRIPTS (perf-archive, perf-iostat) with $(OUTPUT) to prevent Make from continuously re-executing script installation rules on already built out-of-tree builds.13-14: AST Parsing Optimization & Shell Fork Eradication
- Converts ZENS, ARMS, and INTELS in pmu-events/Build from recursive assignment (=) to simply expanded assignment (:=) and replaces model_name/vendor_name with pure GNU Make string functions. This guarantees Make executes directory probing shell forks exactly once during AST parsing and evaluates path macros purely in memory, completely eradicating over 7,800 redundant sub-processes during out-of-tree build evaluation.
- Converts llvm-config shell queries in Makefile.config from recursive assignment (=) to simply expanded assignment (:=). This eliminates ~185 redundant sub-processes that were previously executed across object compilation dependency checks.Changes since v6:
- Rebase/resend as last series failed to apply by Sashiko.Ian Rogers (14):
tools build: Fix feature checks to touch target files on success perf trace beauty: Make beauty generated C code standalone .o files perf build: Decouple pmu-events from prepare umbrella target perf build: Remove empty archheaders target
perf build: Move BPF skeleton generation out of Makefile.perf perf build: Encapsulatevmlinux.hand bpftool in bpf_skel.mak perf build: Pre-generate BPF skeleton tooling during umbrella prepare
phase
perf build: Move libsymbol dependency out of prepare step perf build: Remove redundant libbpf feature check for static builds perf pmu-events: Splitbig_c_stringstorage into standalone
compilation unit
perf pmu-events: Parallelize JSON and metric pre-computation in
jevents.py
perf build: Prefix SCRIPTS with output directory to fix continuous
rebuilds
perf pmu-events: Convert recursive shell assignments and macros to
Make built-ins
perf build: Convert llvm-config shell queries to simply expanded
variables
Quoted 4 lines
Quoted 1 line
Reviewed-by Namhyung Kim <[email protected]>So this is for 2-14? I haven't checked if 1 can be left out of an initial merge by me.
I believe you are correct. Patch 1 is completely independent because it is the only change in tools/build; everything else is in tools/perf.
Thanks,
Ian
Quoted 1 line
- Arnaldo
Namhyung Kim
maintainerRe: [PATCH v7 00/14] perf build: Reduce build time by nearly half
Quoted 130 lines · Ian Rogers
Quoted 128 lines · Arnaldo Carvalho de Melo
Quoted 126 lines · Namhyung Kim
Quoted 35 lines · Ian Rogers
This patch series refactors
Kbuildinternals, BPF skeleton generation, Python AST pre-computation, and foundational tooling dependencies across the perf tool build system. By eliminating umbrella target synchronization barriers, decoupling static library prerequisites, parallelizing single-core script generators, and eradicating redundant feature checks, this series unlocks absolute theoretical peak multi-core concurrency duringKbuildstartup.On a 28-core build workstation (make -j28 all from scratch), clean build latency improves by over 44%:
Before:
real 0m29.006s user 2m46.019s sys 0m30.610sAfter:
real 0m16.091s user 2m40.135s sys 0m25.740sSaving 12.9 full seconds time per clean build. Furthermore, nothing to build incremental builds are improved by nearly 7x:
Before:
real 0m11.528s user 0m9.633s sys 0m6.965sAfter:
real 0m1.717s user 0m1.682s sys 0m0.960sSummary of Patches:
Quoted 12 lines
1: Fast-Path Feature Detection
- Refactors test-clang-bpf-co-re.bin and test-bpftool-skeletons.bin feature checks to group shell pipelines within curly braces and redirect both stdout and stderr to .make.output before touching $@ purely upon success
(> $(@:.bin=.make.output) 2>&1 && touch $@). Grouping the pipeline ({ cmd1 | cmd2; }) ensures that compiler stderr is successfully captured in .make.output rather than escaping to the parent shell. This perfectly matches standardKbuildfeature check conventions and ensures the target files are touched on disk purely upon success, allowingKbuildto cache positive detections and avoid continuous sub-make re-evaluations during incremental builds. Adds test-bpftool-skeletons.bin to the clean FILES list and explicit source prerequisitetest-clang-bpf-co-re.c.I think patch 1 can be separated and needs Ack/Review from BPF folks.
Quoted 74 lines
2-4: Flattening Umbrella Prepare Barriers
- builtin-trace embedded inclusions and pmu-events generation are completely decoupled from the sequential "prepare" umbrella target, eliminating Make AST double-parsing overhead and unchoking parallel compilation barriers.5-7: Decoupling & Pre-generating BPF Skeletons
- BPF skeleton rules are extracted out of Makefile.perf into bpf_skel.mak.
- Decouples bpftool bootstrap from top-level static libbpf dependencies, attaching bpf-skel-prepare directly to the umbrella prepare target. This allows Make to pre-compile bpftool and dumpvmlinux.hin the background at build startup, removing the 7-second serialization bottleneck before BPF object compilation.
- Ensures benchmark skeleton intermediate .bpf.o files are cleanly removed during make clean, and adds bpf-skel-prepare to .PHONY.8-9: Foundational Linkage Optimization
- Moves static libsymbol library prerequisites out of the prepare step.
- Eliminates redundant libbpf sub-make feature checks during static builds.10-11:
jevents.pyConcurrency & Deduplication
- Splits the massive 2.8 MBbig_c_stringliteral out ofpmu-events.cinto a dedicatedpmu-events-string.ccompilation unit. This slices C compilation latency in half by compiling string and struct tables simultaneously across separate CPU cores while preserving zero dynamic ELF relocations. Addspmu-events-string.cto .gitignore, declares extern const char big_c_string[]; locally insideoutput_string_fileandoutput_filewhen split to prevent linkage conflicts withempty-pmu-events.c, defers file closures to ensure identical timestamps, and uses canonical Make 4.0 @: dependency chaining.
- Pre-populatesjevents.pyJSON ASTs and metric formulas in parallel across all available CPU cores using ProcessPoolExecutor (accelerating Python execution by 11x, from 3.3s down to ~290ms). Moves_init_workerto top-level scope to ensure clean pickling under spawn multiprocessing start methods.12: Out-of-Tree Incremental Rebuild Fix
- Prefixes SCRIPTS (perf-archive, perf-iostat) with $(OUTPUT) to prevent Make from continuously re-executing script installation rules on already built out-of-tree builds.13-14: AST Parsing Optimization & Shell Fork Eradication
- Converts ZENS, ARMS, and INTELS in pmu-events/Build from recursive assignment (=) to simply expanded assignment (:=) and replaces model_name/vendor_name with pure GNU Make string functions. This guarantees Make executes directory probing shell forks exactly once during AST parsing and evaluates path macros purely in memory, completely eradicating over 7,800 redundant sub-processes during out-of-tree build evaluation.
- Converts llvm-config shell queries in Makefile.config from recursive assignment (=) to simply expanded assignment (:=). This eliminates ~185 redundant sub-processes that were previously executed across object compilation dependency checks.Changes since v6:
- Rebase/resend as last series failed to apply by Sashiko.Ian Rogers (14):
tools build: Fix feature checks to touch target files on success perf trace beauty: Make beauty generated C code standalone .o files perf build: Decouple pmu-events from prepare umbrella target perf build: Remove empty archheaders target
perf build: Move BPF skeleton generation out of Makefile.perf perf build: Encapsulatevmlinux.hand bpftool in bpf_skel.mak perf build: Pre-generate BPF skeleton tooling during umbrella prepare
phase
perf build: Move libsymbol dependency out of prepare step perf build: Remove redundant libbpf feature check for static builds perf pmu-events: Splitbig_c_stringstorage into standalone
compilation unit
perf pmu-events: Parallelize JSON and metric pre-computation in
jevents.py
perf build: Prefix SCRIPTS with output directory to fix continuous
rebuilds
perf pmu-events: Convert recursive shell assignments and macros to
Make built-ins
perf build: Convert llvm-config shell queries to simply expanded
variables
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Reviewed-by Namhyung Kim <[email protected]>So this is for 2-14? I haven't checked if 1 can be left out of an initial merge by me.
I believe you are correct. Patch 1 is completely independent because it is the only change in
tools/build; everything else is intools/perf.
Actually it goes to the patch 1 as well. But we can take 2-14 in the perf tree first.
Thanks,
Namhyung
Arnaldo Carvalho de Melo
maintainerRe: [PATCH v7 00/14] perf build: Reduce build time by nearly half
Quoted 136 lines · Namhyung Kim
Quoted 135 lines · Ian Rogers
Quoted 132 lines · Arnaldo Carvalho de Melo
Quoted 126 lines · Namhyung Kim
Quoted 35 lines · Ian Rogers
This patch series refactors
Kbuildinternals, BPF skeleton generation, Python AST pre-computation, and foundational tooling dependencies across the perf tool build system. By eliminating umbrella target synchronization barriers, decoupling static library prerequisites, parallelizing single-core script generators, and eradicating redundant feature checks, this series unlocks absolute theoretical peak multi-core concurrency duringKbuildstartup.On a 28-core build workstation (make -j28 all from scratch), clean build latency improves by over 44%:
Before:
real 0m29.006s user 2m46.019s sys 0m30.610sAfter:
real 0m16.091s user 2m40.135s sys 0m25.740sSaving 12.9 full seconds time per clean build. Furthermore, nothing to build incremental builds are improved by nearly 7x:
Before:
real 0m11.528s user 0m9.633s sys 0m6.965sAfter:
real 0m1.717s user 0m1.682s sys 0m0.960sSummary of Patches:
Quoted 12 lines
1: Fast-Path Feature Detection
- Refactors test-clang-bpf-co-re.bin and test-bpftool-skeletons.bin feature checks to group shell pipelines within curly braces and redirect both stdout and stderr to .make.output before touching $@ purely upon success
(> $(@:.bin=.make.output) 2>&1 && touch $@). Grouping the pipeline ({ cmd1 | cmd2; }) ensures that compiler stderr is successfully captured in .make.output rather than escaping to the parent shell. This perfectly matches standardKbuildfeature check conventions and ensures the target files are touched on disk purely upon success, allowingKbuildto cache positive detections and avoid continuous sub-make re-evaluations during incremental builds. Adds test-bpftool-skeletons.bin to the clean FILES list and explicit source prerequisitetest-clang-bpf-co-re.c.I think patch 1 can be separated and needs Ack/Review from BPF folks.
Quoted 66 lines
2-4: Flattening Umbrella Prepare Barriers
- builtin-trace embedded inclusions and pmu-events generation are completely decoupled from the sequential "prepare" umbrella target, eliminating Make AST double-parsing overhead and unchoking parallel compilation barriers.5-7: Decoupling & Pre-generating BPF Skeletons
- BPF skeleton rules are extracted out of Makefile.perf into bpf_skel.mak.
- Decouples bpftool bootstrap from top-level static libbpf dependencies, attaching bpf-skel-prepare directly to the umbrella prepare target. This allows Make to pre-compile bpftool and dumpvmlinux.hin the background at build startup, removing the 7-second serialization bottleneck before BPF object compilation.
- Ensures benchmark skeleton intermediate .bpf.o files are cleanly removed during make clean, and adds bpf-skel-prepare to .PHONY.8-9: Foundational Linkage Optimization
- Moves static libsymbol library prerequisites out of the prepare step.
- Eliminates redundant libbpf sub-make feature checks during static builds.10-11:
jevents.pyConcurrency & Deduplication
- Splits the massive 2.8 MBbig_c_stringliteral out ofpmu-events.cinto a dedicatedpmu-events-string.ccompilation unit. This slices C compilation latency in half by compiling string and struct tables simultaneously across separate CPU cores while preserving zero dynamic ELF relocations. Addspmu-events-string.cto .gitignore, declares extern const char big_c_string[]; locally insideoutput_string_fileandoutput_filewhen split to prevent linkage conflicts withempty-pmu-events.c, defers file closures to ensure identical timestamps, and uses canonical Make 4.0 @: dependency chaining.
- Pre-populatesjevents.pyJSON ASTs and metric formulas in parallel across all available CPU cores using ProcessPoolExecutor (accelerating Python execution by 11x, from 3.3s down to ~290ms). Moves_init_workerto top-level scope to ensure clean pickling under spawn multiprocessing start methods.12: Out-of-Tree Incremental Rebuild Fix
- Prefixes SCRIPTS (perf-archive, perf-iostat) with $(OUTPUT) to prevent Make from continuously re-executing script installation rules on already built out-of-tree builds.13-14: AST Parsing Optimization & Shell Fork Eradication
- Converts ZENS, ARMS, and INTELS in pmu-events/Build from recursive assignment (=) to simply expanded assignment (:=) and replaces model_name/vendor_name with pure GNU Make string functions. This guarantees Make executes directory probing shell forks exactly once during AST parsing and evaluates path macros purely in memory, completely eradicating over 7,800 redundant sub-processes during out-of-tree build evaluation.
- Converts llvm-config shell queries in Makefile.config from recursive assignment (=) to simply expanded assignment (:=). This eliminates ~185 redundant sub-processes that were previously executed across object compilation dependency checks.Changes since v6:
- Rebase/resend as last series failed to apply by Sashiko.Ian Rogers (14):
tools build: Fix feature checks to touch target files on success perf trace beauty: Make beauty generated C code standalone .o files perf build: Decouple pmu-events from prepare umbrella target perf build: Remove empty archheaders target
perf build: Move BPF skeleton generation out of Makefile.perf perf build: Encapsulatevmlinux.hand bpftool in bpf_skel.mak perf build: Pre-generate BPF skeleton tooling during umbrella prepare
phase
perf build: Move libsymbol dependency out of prepare step perf build: Remove redundant libbpf feature check for static builds perf pmu-events: Splitbig_c_stringstorage into standalone
compilation unitQuoted 8 lines
perf pmu-events: Parallelize JSON and metric pre-computation in
jevents.py
perf build: Prefix SCRIPTS with output directory to fix continuous
rebuilds
perf pmu-events: Convert recursive shell assignments and macros to
Make built-ins
perf build: Convert llvm-config shell queries to simply expanded
variablesQuoted 1 line
Reviewed-by Namhyung Kim <[email protected]>So this is for 2-14? I haven't checked if 1 can be left out of an initial merge by me.
Quoted 6 lines
Quoted 3 lines
I believe you are correct. Patch 1 is completely independent because it is the only change in
tools/build; everything else is intools/perf.Actually it goes to the patch 1 as well. But we can take 2-14 in the perf tree first.
Ok, lets go with 2-14, we can look at 1 later.
- Arnaldo
Namhyung Kim
maintainerRe: [PATCH v3 00/17] perf build: Reduce build time by nearly half
In reply to Ian RogersQuoted 82 lines · Ian Rogers
Quoted 81 lines · Namhyung Kim
Quoted 24 lines · Ian Rogers
This patch series refactors
Kbuildinternals, BPF skeleton generation, Python AST pre-computation, and foundational tooling dependencies across the perf tool build system. By eliminating umbrella target synchronization barriers, decoupling static library prerequisites, parallelizing single-core script generators, and eradicating redundant feature checks, this series unlocks absolute theoretical peak multi-core concurrency duringKbuildstartup.On a 28-core build workstation (make -j28 all from scratch), clean build latency improves by over 49%:
Before:
real 0m29.006s user 2m46.019s sys 0m30.610sAfter:
real 0m14.782s user 2m39.527s sys 0m22.938sSaving 14.2 full seconds time per clean build. Furthermore, nothing to build incremental builds are improved by nearly 7x:
Before:
Quoted 8 lines
real 0m11.528s user 0m9.633s sys 0m6.965sAfter:
real 0m1.729s user 0m1.600s sys 0m0.884sI've quickly checked it with latency profiling like below:
$ perf record --latency -- make -C tools/perf$ perf report --latency -s commThe result looks like this.
Before:
#
# Samples: 715K of event 'cpu/cycles/Pu'
# Event count (approx.): 422452811481
## Latency Overhead Command # ........ ........ ............... # 45.28% 71.33% cc1 34.48% 16.92% python3 11.15% 2.21% ld 2.58% 1.51% x86_64-linux-gn 2.22% 0.99% cc1plus 0.71% 0.63% sh 0.69% 0.14% llvm-config 0.62% 0.56% clang 0.57% 4.40% shellcheck 0.44% 0.12% perlAfter:
#
# Samples: 709K of event 'cpu/cycles/Pu'
# Event count (approx.): 416654798495
## Latency Overhead Command # ........ ........ ............... # 64.99% 71.16% cc1 15.07% 1.81% ld 7.14% 17.59% python3 3.66% 1.53% x86_64-linux-gn 3.48% 0.75% cc1plus 1.11% 4.43% shellcheck 1.09% 0.74% sh 0.86% 0.59% clang 0.77% 0.12% perl 0.45% 0.23% make
Quoted 5 lines
Quoted 2 lines
Now I see a big drop in the latency from python. And the llvm-config doesn't show up in the top 10.
This looks good. What is "x86_64-linux-gn", and since we default off LIBPERL, why does perl show up in the commands?
I don't know exactly, but it seems we have some path to run perl during the build even LIBPERL is off. This is what perf report --tasks shows.
3577076 3577076 3576925 | sh 3577077 3577077 3577076 | make 3577078 3577078 3577077 | sh 3577079 3577079 3577078 | gcc 3577081 3577081 3577079 | cc1 3577080 3577080 3577078 | grep 3577082 3577082 3577077 | which 3577083 3577083 3577077 | sh 3577084 3577084 3577083 | perl 3577085 3577085 3577077 | sh 3577086 3577086 3577085 | perl 3577087 3577087 3577086 | pwd 3577088 3577088 3577086 | sh 3577089 3577089 3577088 | x86_64-linux-gn 3577090 3577090 3577089 | cc1
Thanks,
Namhyung
Quoted 12 lines · Ian Rogers
This patch series refactors many aspects of the perf build aiming to better encapsulate BPF code generation, remove serial build code and gain build parallelism. The prepare step that blocks the parallel build is reduced to a core 6 smaller dependencies. BPF skeletons are made regular dependencies on the targets that use them. Feature tests and dependencies are reorgnized. The
jevents.pyscript processes json files in parallel and allows thebig_c_stringto be compiled separately.On a 28-core build workstation (make -j28 all from scratch), clean build latency improves by over 36%:
Quoted 10 lines
Before:
real 0m29.006s
user 2m46.019s
sys 0m30.610s
After:
real 0m18.498s
user 2m32.922s
sys 0m27.623sI also get similar numbers, even when using ccache:
Before:
real 0m29.584s user 0m48.993s sys 0m20.466s
After:
real 0m18.322s user 0m49.995s sys 0m17.077s
Quoted 105 lines
Summary of Patches:
1: bpftool Bootstrap Optimization
- Exempts bpftool bootstrap from non-essential feature tests (LLVM, libbfd, libcap), saving 1.1s of sub-make fork overhead duringKbuildstartup.2-4: Flattening Umbrella Prepare Barriers
- builtin-trace embedded inclusions and pmu-events generation are completely decoupled from the sequential "prepare" umbrella target, eliminating Make AST double-parsing overhead and unchoking parallel compilation barriers.5-8: Decoupling & Pre-generating BPF Skeletons
- BPF skeleton rules are extracted out of Makefile.perf into bpf_skel.mak.
- Decouples bpftool bootstrap from top-level static libbpf dependencies, attaching bpf-skel-prepare directly to the umbrella prepare target. This allows Make to pre-compile bpftool and dumpvmlinux.hin the background at build startup, removing the 7-second serialization bottleneck before BPF object compilation.9-11: Foundational Linkage & Fast-Path Feature Detection
- Eliminates redundant libbpf sub-make feature checks during static builds.
- Integrates libdebuginfod directly intotest-all.c, allowing Make to skip individual feature check sub-make forks during AST parsing on fully configured workstations.12-13:
jevents.pyConcurrency & Deduplication
- Splits the massive 2.8 MBbig_c_stringliteral out ofpmu-events.cinto a dedicatedpmu-events-string.ccompilation unit. This slices C compilation latency in half by compiling string and struct tables simultaneously across separate CPU cores while preserving zero dynamic ELF relocations.
- Pre-populatesjevents.pyJSON ASTs and metric formulas in parallel across all available CPU cores using ProcessPoolExecutor (accelerating Python execution by 11x, from 3.3s down to ~290ms).14: Out-of-Tree Incremental Rebuild Fix
- Prefixes SCRIPTS (perf-archive, perf-iostat) with $(OUTPUT) to prevent Make from continuously re-executing script installation rules on already built out-of-tree builds.Ian Rogers (14):
bpftool build: Restrict feature tests during bootstrap compilation perf trace beauty: Make beauty generated C code standalone .o files perf build: Decouple pmu-events from prepare umbrella target perf build: Remove empty archheaders target
perf build: Move BPF skeleton generation out of Makefile.perf perf build: Encapsulatevmlinux.hand bpftool in bpf_skel.mak perf build: Move static libbpf dependency out of prepare step perf build: Pre-generate BPF skeletons during umbrella prepare phase perf build: Move libsymbol dependency out of prepare step perf build: Remove redundant libbpf feature check for static builds tools build: Integrate libdebuginfod into test-all fast path perf pmu-events: Splitbig_c_stringstorage into standalone
compilation unit
perf pmu-events: Parallelize JSON and metric pre-computation in
jevents.py
perf build: Prefix SCRIPTS with output directory to fix continuous
rebuildstools/bpf/bpftool/Makefile | 5 + tools/build/Makefile.feature | 6 +- tools/build/feature/Makefile | 2 +- tools/build/feature/test-all.c | 5 + tools/perf/Build | 2 + tools/perf/Makefile.config | 6 +- tools/perf/Makefile.perf | 427 +----------------- tools/perf/bench/Build | 6 + .../bpf_skel/bench_uprobe.bpf.c | 0 tools/perf/bench/uprobe.c | 2 +- tools/perf/bpf_skel.mak | 110 +++++ tools/perf/builtin-trace.c | 30 +- tools/perf/pmu-events/Build | 15 +- tools/perf/pmu-events/jevents.py | 56 ++- tools/perf/trace/beauty/Build | 280 ++++++++++++ tools/perf/trace/beauty/arch_errno_names.c | 2 + tools/perf/trace/beauty/arch_errno_names.sh | 2 +- tools/perf/trace/beauty/beauty.h | 60 +++ tools/perf/trace/beauty/eventfd.c | 6 +- tools/perf/trace/beauty/fsconfig.c | 5 + tools/perf/trace/beauty/futex_op.c | 6 +- tools/perf/trace/beauty/futex_val3.c | 6 +- tools/perf/trace/beauty/mmap.c | 24 +- tools/perf/trace/beauty/mode_t.c | 6 +- tools/perf/trace/beauty/msg_flags.c | 8 +- tools/perf/trace/beauty/open_flags.c | 1 + tools/perf/trace/beauty/perf_event_open.c | 22 +- tools/perf/trace/beauty/pid.c | 5 +- tools/perf/trace/beauty/sched_policy.c | 8 +- tools/perf/trace/beauty/seccomp.c | 12 +- tools/perf/trace/beauty/signum.c | 6 +- tools/perf/trace/beauty/socket_type.c | 6 +- .../perf/{util => trace/beauty}/syscalltbl.c | 0 .../perf/{util => trace/beauty}/syscalltbl.h | 0 tools/perf/trace/beauty/tracepoints/Build | 22 + tools/perf/trace/beauty/waitid_options.c | 8 +- tools/perf/util/Build | 17 +- tools/perf/util/bpf-trace-summary.c | 2 +- tools/perf/util/env.c | 4 +- tools/perf/util/env.h | 1 + 40 files changed, 700 insertions(+), 491 deletions(-)rename
tools/perf/{util=>bench}/bpf_skel/bench_uprobe.bpf.c(100%) create mode 100644tools/perf/bpf_skel.mak
create mode 100644tools/perf/trace/beauty/fsconfig.crenametools/perf/{util=>trace/beauty}/syscalltbl.c(100%) renametools/perf/{util=>trace/beauty}/syscalltbl.h(100%)