From nobody Wed Apr 1 22:20:20 2026 Received: from mail-dy1-f202.google.com (mail-dy1-f202.google.com [74.125.82.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CA09F47278B for ; Wed, 1 Apr 2026 16:13:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775060017; cv=none; b=K1SfZmBaYDQN2V/OqkpemBJ5A4iomR+y9lVnGxdnGSnehlItrSj5xuZHzJyFgSnIiIzBqRLLgSQJiZZY5Nn9wDwsL2zLju1ONhZibBDtKhhkRaFwXSQUqRxhRH5FCQWrL+ZJU//iDBixRPDR2HIx/RU8z3ld+BtOPeZ6ojtGwQM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775060017; c=relaxed/simple; bh=pQw3DSGto9YWSkBY2nT7ZjSAEw73RvDiI42ofQz12bI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=a49l7qLcbpovlvy0tZ8fg03JYRSAq/gNhCAqMJCgTawTv8ljUw5I7C36L/lqcAconCqiG32HkXFAtT2r6OjznOldaJTgw20WPcq8PO7jWVEXs1/Us+wZtdMWXbAbU1h6lQh0zr44vW6MDsHuulXqrDMPFbqLyLIzdFMotUuDYIY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=aaisriLx; arc=none smtp.client-ip=74.125.82.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="aaisriLx" Received: by mail-dy1-f202.google.com with SMTP id 5a478bee46e88-2c5b48baf75so9154399eec.0 for ; Wed, 01 Apr 2026 09:13:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1775060015; x=1775664815; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=d6aSMFYxARFqb+s5PRfj6hVV83IM5y47yqCQJKiEqaA=; b=aaisriLxk3rdYOthfaUlIa/0P/7mzdyReUVpX5NIyZBDYFeZaJ3TshBCSHInsVjrye /arTMh6b1nlXJbBKnHVwNrqCEuZd8XKHVzp83RmljX76XuNZOpsT/PwiBDVixkpUGBqk whct6JTeBUjHSV/sxt7aG5/Wkgy7GwCELlGuftpFOIb+k7Hf+d296jooX7hrEfFc4zGm 9M/ukF/x+erLgrcXiksXdoPu1QC3SnCPaOeKtyceNmiERGyG+z+YSLsorX4Q5c07SYSu AUlpO8KHp0k1YmGwg+fh92tYdJLOLXyXJ6OLxaDLU0jef0Jx6531QRtXqQEqeaclBX2u 5D6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775060015; x=1775664815; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=d6aSMFYxARFqb+s5PRfj6hVV83IM5y47yqCQJKiEqaA=; b=ehizfyXSs3QiMTb6CPVzKnjD2rmuF0tToeP7+8wQ0SxuaTwLQAL+oDtro0U/Rx3YlF Yv0dHNEUGtNFdn0Jy+x5kd6M2rPP5apiJIXKqXO6HEcFpVYtt62eSnk4hm7212w0lB9q suZuYdtJ97gOC9TdgFRXxrd203drBwkpOXIrTWbMgH5fIp4IYbeT5b4juTXm7UB7/Rzy ZXYu1XUN/FpIFbEWrJvAqyNTHHMrvmkM2ba3sAXzNyvvMIin1YPwn54Vw+u3+yCNAZIv tU1w1qCsKySbKpPZwOhYeLhnyA6AMYEA1ppFPgebLsKW22NhO52Ja5kF9VTw1Je0aV5l GbEA== X-Forwarded-Encrypted: i=1; AJvYcCWEDjCkMT/KIj4WOARqM1tphyVyU6F892FM5rrp8zX87aAFIoSs24YfjekR/KDPqKValHBPIcKQlhRPKkQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yy0V8khm0M0KmYakAp5+MAuD1n8YrU9c7i0mJs93EU4oGJ/LIt5 wSEuZgsg4pNj9oB9z/kGL9Fx+2wEzZNxNqMcLdgQPlpTSLxfasVsvz3YEgcSyGPa/rsr76Rmz/0 s1IO3lyuLZw== X-Received: from dybir8.prod.google.com ([2002:a05:7300:c8c8:b0:2c0:be02:79e8]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:3724:b0:2c1:27c:75bd with SMTP id 5a478bee46e88-2c92db587e3mr2528654eec.0.1775060014789; Wed, 01 Apr 2026 09:13:34 -0700 (PDT) Date: Wed, 1 Apr 2026 09:13:19 -0700 In-Reply-To: <20260401161324.332356-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260401055206.43187-1-irogers@google.com> <20260401161324.332356-1-irogers@google.com> X-Mailer: git-send-email 2.53.0.1118.gaef5881109-goog Message-ID: <20260401161324.332356-4-irogers@google.com> Subject: [PATCH v4 3/8] perf header: Properly warn/print when libtraceevent/libbpf support is missing From: Ian Rogers To: acme@kernel.org, namhyung@kernel.org Cc: irogers@google.com, adrian.hunter@intel.com, alexander.shishkin@linux.intel.com, ashelat@redhat.com, ctshao@google.com, derek.foreman@collabora.com, howardchu95@gmail.com, hrishikesh123s@gmail.com, james.clark@linaro.org, jolsa@kernel.org, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, mingo@redhat.com, peterz@infradead.org, swapnil.sapkal@amd.com, thomas.falcon@intel.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" By removing the features from feat_ops with ifdefs the previous logic would print "# (null)" when perf processed a feature that lacked builtin support. Remove the ifdefs from feat_ops and in the relevant functions print errors/messages about the lack of support. Signed-off-by: Ian Rogers --- tools/perf/util/header.c | 70 +++++++++++++++++++++++++++------------- 1 file changed, 47 insertions(+), 23 deletions(-) diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index fcd53271e189..50c006be895f 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -306,16 +306,19 @@ static int do_read_bitmap(struct feat_fd *ff, unsigne= d long **pset, u64 *psize) return 0; } =20 -#ifdef HAVE_LIBTRACEEVENT static int write_tracing_data(struct feat_fd *ff, - struct evlist *evlist) + struct evlist *evlist __maybe_unused) { if (WARN(ff->buf, "Error: calling %s in pipe-mode.\n", __func__)) return -1; =20 +#ifdef HAVE_LIBTRACEEVENT return read_tracing_data(ff->fd, &evlist->core.entries); -} +#else + pr_err("ERROR: Trying to write tracing data without libtraceevent support= .\n"); + return -1; #endif +} =20 static int write_build_id(struct feat_fd *ff, struct evlist *evlist __maybe_unused) @@ -1026,10 +1029,10 @@ static int write_dir_format(struct feat_fd *ff, return do_write(ff, &data->dir.version, sizeof(data->dir.version)); } =20 -#ifdef HAVE_LIBBPF_SUPPORT -static int write_bpf_prog_info(struct feat_fd *ff, +static int write_bpf_prog_info(struct feat_fd *ff __maybe_unused, struct evlist *evlist __maybe_unused) { +#ifdef HAVE_LIBBPF_SUPPORT struct perf_env *env =3D &ff->ph->env; struct rb_root *root; struct rb_node *next; @@ -1067,11 +1070,16 @@ static int write_bpf_prog_info(struct feat_fd *ff, out: up_read(&env->bpf_progs.lock); return ret; +#else + pr_err("ERROR: Trying to write bpf_prog_info without libbpf support.\n"); + return -1; +#endif // HAVE_LIBBPF_SUPPORT } =20 -static int write_bpf_btf(struct feat_fd *ff, +static int write_bpf_btf(struct feat_fd *ff __maybe_unused, struct evlist *evlist __maybe_unused) { +#ifdef HAVE_LIBBPF_SUPPORT struct perf_env *env =3D &ff->ph->env; struct rb_root *root; struct rb_node *next; @@ -1100,8 +1108,11 @@ static int write_bpf_btf(struct feat_fd *ff, out: up_read(&env->bpf_progs.lock); return ret; -} +#else + pr_err("ERROR: Trying to write btf data without libbpf support.\n"); + return -1; #endif // HAVE_LIBBPF_SUPPORT +} =20 static int cpu_cache_level__sort(const void *a, const void *b) { @@ -1980,9 +1991,9 @@ static void print_dir_format(struct feat_fd *ff, FILE= *fp) fprintf(fp, "# directory data version : %"PRIu64"\n", data->dir.version); } =20 -#ifdef HAVE_LIBBPF_SUPPORT -static void print_bpf_prog_info(struct feat_fd *ff, FILE *fp) +static void print_bpf_prog_info(struct feat_fd *ff __maybe_unused, FILE *f= p) { +#ifdef HAVE_LIBBPF_SUPPORT struct perf_env *env =3D &ff->ph->env; struct rb_root *root; struct rb_node *next; @@ -1993,7 +2004,7 @@ static void print_bpf_prog_info(struct feat_fd *ff, F= ILE *fp) next =3D rb_first(root); =20 if (!next) - printf("# bpf_prog_info empty\n"); + fprintf(fp, "# bpf_prog_info empty\n"); =20 while (next) { struct bpf_prog_info_node *node; @@ -2006,10 +2017,14 @@ static void print_bpf_prog_info(struct feat_fd *ff,= FILE *fp) } =20 up_read(&env->bpf_progs.lock); +#else + fprintf(fp, "# bpf_prog_info missing, no libbpf support\n"); +#endif // HAVE_LIBBPF_SUPPORT } =20 -static void print_bpf_btf(struct feat_fd *ff, FILE *fp) +static void print_bpf_btf(struct feat_fd *ff __maybe_unused, FILE *fp) { +#ifdef HAVE_LIBBPF_SUPPORT struct perf_env *env =3D &ff->ph->env; struct rb_root *root; struct rb_node *next; @@ -2031,8 +2046,10 @@ static void print_bpf_btf(struct feat_fd *ff, FILE *= fp) } =20 up_read(&env->bpf_progs.lock); -} +#else + fprintf(fp, "# bpf btf data missing, no libbpf support\n"); #endif // HAVE_LIBBPF_SUPPORT +} =20 static void free_event_desc(struct evsel *events) { @@ -2644,14 +2661,17 @@ static int process_e_machine(struct feat_fd *ff, vo= id *data __maybe_unused) return do_read_u32(ff, &ff->ph->env.e_flags); } =20 -#ifdef HAVE_LIBTRACEEVENT -static int process_tracing_data(struct feat_fd *ff, void *data) +static int process_tracing_data(struct feat_fd *ff __maybe_unused, void *d= ata __maybe_unused) { +#ifdef HAVE_LIBTRACEEVENT ssize_t ret =3D trace_report(ff->fd, data, false); =20 return ret < 0 ? -1 : 0; -} +#else + pr_err("ERROR: Trying to read tracing data without libtraceevent support.= \n"); + return -1; #endif +} =20 static int process_build_id(struct feat_fd *ff, void *data __maybe_unused) { @@ -3330,9 +3350,9 @@ static int process_dir_format(struct feat_fd *ff, return do_read_u64(ff, &data->dir.version); } =20 -#ifdef HAVE_LIBBPF_SUPPORT -static int process_bpf_prog_info(struct feat_fd *ff, void *data __maybe_un= used) +static int process_bpf_prog_info(struct feat_fd *ff __maybe_unused, void *= data __maybe_unused) { +#ifdef HAVE_LIBBPF_SUPPORT struct bpf_prog_info_node *info_node; struct perf_env *env =3D &ff->ph->env; struct perf_bpil *info_linear; @@ -3402,10 +3422,15 @@ static int process_bpf_prog_info(struct feat_fd *ff= , void *data __maybe_unused) free(info_node); up_write(&env->bpf_progs.lock); return err; +#else + pr_err("ERROR: Trying to read bpf_prog_info without libbpf support.\n"); + return -1; +#endif // HAVE_LIBBPF_SUPPORT } =20 -static int process_bpf_btf(struct feat_fd *ff, void *data __maybe_unused) +static int process_bpf_btf(struct feat_fd *ff __maybe_unused, void *data = __maybe_unused) { +#ifdef HAVE_LIBBPF_SUPPORT struct perf_env *env =3D &ff->ph->env; struct btf_node *node =3D NULL; u32 count, i; @@ -3449,8 +3474,11 @@ static int process_bpf_btf(struct feat_fd *ff, void = *data __maybe_unused) up_write(&env->bpf_progs.lock); free(node); return err; -} +#else + pr_err("ERROR: Trying to read btf data without libbpf support.\n"); + return -1; #endif // HAVE_LIBBPF_SUPPORT +} =20 static int process_compressed(struct feat_fd *ff, void *data __maybe_unused) @@ -3726,9 +3754,7 @@ static int process_cpu_domain_info(struct feat_fd *ff= , void *data __maybe_unused const struct perf_header_feature_ops feat_ops[HEADER_LAST_FEATURE]; =20 const struct perf_header_feature_ops feat_ops[HEADER_LAST_FEATURE] =3D { -#ifdef HAVE_LIBTRACEEVENT FEAT_OPN(TRACING_DATA, tracing_data, false), -#endif FEAT_OPN(BUILD_ID, build_id, false), FEAT_OPR(HOSTNAME, hostname, false), FEAT_OPR(OSRELEASE, osrelease, false), @@ -3752,10 +3778,8 @@ const struct perf_header_feature_ops feat_ops[HEADER= _LAST_FEATURE] =3D { FEAT_OPR(MEM_TOPOLOGY, mem_topology, true), FEAT_OPR(CLOCKID, clockid, false), FEAT_OPN(DIR_FORMAT, dir_format, false), -#ifdef HAVE_LIBBPF_SUPPORT FEAT_OPR(BPF_PROG_INFO, bpf_prog_info, false), FEAT_OPR(BPF_BTF, bpf_btf, false), -#endif FEAT_OPR(COMPRESSED, compressed, false), FEAT_OPR(CPU_PMU_CAPS, cpu_pmu_caps, false), FEAT_OPR(CLOCK_DATA, clock_data, false), --=20 2.53.0.1118.gaef5881109-goog