From nobody Fri Oct 10 23:11:57 2025 Received: from mail-oa1-f73.google.com (mail-oa1-f73.google.com [209.85.160.73]) (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 5F4602D8789 for ; Thu, 12 Jun 2025 19:49:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749757794; cv=none; b=dPQUbUdkZFJaIdlO1KEVycZd2st8agJnElpYG3T9hldvdPwj+/FVEo6uXPP5MLHcDtI4e2ATd205ZTatFQc5YWG2NlXe8c5LUAmJ8hFE78LqYvY0TesPQf+EC8oI4+yZXJr0sQI33IboGD5FKTC7CNU/qNQusfNBu4vIFe9goB4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749757794; c=relaxed/simple; bh=zMY1NElYNZzt1bGCpQPOES94FzbCwXlf9lyBYpGO4Zs=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=dph+dltAvt21pGVFb//w9to7HKdLIktuIkzG+KXSXjg7AgL0O+APYUa5yS4OH3SiK3mNJDWC8iVecx8oowHTsKhVNnkP0Q6A+JUmZ1msjLL1hWEFMDRqM1g7shWhtz+SCxN0Zcf+L1dzA+Zq8umP8xMBDEzaAZEQK74vRYKdrr4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--blakejones.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=pf/YFNdf; arc=none smtp.client-ip=209.85.160.73 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--blakejones.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="pf/YFNdf" Received: by mail-oa1-f73.google.com with SMTP id 586e51a60fabf-2e922a13d49so1066259fac.2 for ; Thu, 12 Jun 2025 12:49:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1749757791; x=1750362591; 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=tnqUhIyewIO5q6Zf7WHC0dqAJTno3LzWwwCSTFeopTU=; b=pf/YFNdf2TFfW8W83c3aYcwSTXRNJDv3IiR1eZN/O2v4IhP+nduHsTIIyYMUuRTEBQ 0IHtnZIGAAKux6EsiAibo7Cx7EYjgY2hW19ApTWr9sn1hmhtenpfCoWbT+rXVAsheCU7 7GfvmlwA/SfzF5b51VFFHPn1E33Cq+K6UQSS6ucoIwhqhuz5VL76DQCRyVg6/WwZYT8Q dX3fYRTqPHiLyGcqugEZmhsexeL6pDyeWaliA/BnGop2PbFqgA26kFnVWOi54n/YRWDt 8BzJe4GVKAyx5wHSnsLuCM/VoxDOfageIEzL1R8Zg4lyIxsitBO9cUUbTYxbPZIDVnsb XtOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749757791; x=1750362591; 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=tnqUhIyewIO5q6Zf7WHC0dqAJTno3LzWwwCSTFeopTU=; b=kr4/o9aRqPpJuYCZE04Z9LoFI6dEMJF5GdQBprLn4+AifMYzCdX/Iv9HT7HaEevuVh X6ohB0XrEME1Wq382rtUVcKinAsyQKwIR8OMrsy0wE8nWlipDKG9eXgvTHEUPJshPufj /HkFDGgUNcAksLnSHT85cO8L+oDzQZowtl5yo1fCMV3FPUt0jJI+vx2Jz5w/kJBvNafk mK9T7DiYCP4p5oTnrnWMTSjPZC5Mcjj5Ma6QY05YdfKLsoK7D4sfGI9lChqMVbYWCoGJ QGJKtydskrnFOwZN9TuMNtebPDX+3zBIzTQsk4PoQ1usw6qrxMCCCML/HFuX/pJsWoKT 2GXw== X-Forwarded-Encrypted: i=1; AJvYcCViWKxjJ/Y5m/Qtmocsi6XkSezieoXcT6aTBg3gDAqwpTZlS0CoQN1r6eXQD0ymgchScCPziUooBijOaik=@vger.kernel.org X-Gm-Message-State: AOJu0Ywq0ycDdxdJ91DQya9gOSAQaqXGhkuKlrPBZOnTFYuwE6Vuw3qb KESqadu+9Yiof7o5+Ra6pgXQ2b+DAAysbrBreiQ+KlRx04xqDau7rpQz4KxcxEhTg6zmS54qkB7 jV3UdycCZ8y2hPWJcoT9irw== X-Google-Smtp-Source: AGHT+IFNTXR/9UID8W6zRYCP3OwhC3x1U++y9rRlwJYFwQhSIGl+YEKkxpm2xUoLbRLXAHqqMRE3zncdhPzwhCzN X-Received: from oabqw11.prod.google.com ([2002:a05:6870:6f0b:b0:2d9:841d:6155]) (user=blakejones job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6871:4002:b0:2b8:e4b9:47a3 with SMTP id 586e51a60fabf-2ead509b590mr228640fac.22.1749757791440; Thu, 12 Jun 2025 12:49:51 -0700 (PDT) Date: Thu, 12 Jun 2025 12:49:39 -0700 In-Reply-To: <20250612194939.162730-1-blakejones@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250612194939.162730-1-blakejones@google.com> X-Mailer: git-send-email 2.50.0.rc1.591.g9c95f17f64-goog Message-ID: <20250612194939.162730-6-blakejones@google.com> Subject: [PATCH v4 5/5] perf: add test for PERF_RECORD_BPF_METADATA collection From: Blake Jones To: Arnaldo Carvalho de Melo , Namhyung Kim , Ian Rogers , Jiri Olsa , Peter Zijlstra , Ingo Molnar Cc: Mark Rutland , Alexander Shishkin , Adrian Hunter , Kan Liang , Steven Rostedt , Tomas Glozar , James Clark , Leo Yan , Guilherme Amadio , Yang Jihong , Charlie Jenkins , Chun-Tse Shao , Aditya Gupta , Athira Rajeev , Zhongqiu Han , Andi Kleen , Dmitry Vyukov , Yujie Liu , Graham Woodward , Yicong Yang , Ben Gainey , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, bpf@vger.kernel.org, Blake Jones Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This is an end-to-end test for the PERF_RECORD_BPF_METADATA support. It adds a new "bpf_metadata_perf_version" variable to perf's BPF programs, so that when they are loaded, there will be at least one BPF program with some metadata to parse. The test invokes "perf record" in a way that loads one of those BPF programs, and then sifts through the output to find its BPF metadata. Signed-off-by: Blake Jones --- tools/perf/Makefile.perf | 3 +- tools/perf/tests/shell/test_bpf_metadata.sh | 76 +++++++++++++++++++++ tools/perf/util/bpf_skel/perf_version.h | 17 +++++ 3 files changed, 95 insertions(+), 1 deletion(-) create mode 100755 tools/perf/tests/shell/test_bpf_metadata.sh create mode 100644 tools/perf/util/bpf_skel/perf_version.h diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf index d4c7031b01a7..4f292edeca5a 100644 --- a/tools/perf/Makefile.perf +++ b/tools/perf/Makefile.perf @@ -1250,8 +1250,9 @@ else $(Q)cp "$(VMLINUX_H)" $@ endif =20 -$(SKEL_TMP_OUT)/%.bpf.o: util/bpf_skel/%.bpf.c $(LIBBPF) $(SKEL_OUT)/vmlin= ux.h | $(SKEL_TMP_OUT) +$(SKEL_TMP_OUT)/%.bpf.o: util/bpf_skel/%.bpf.c $(OUTPUT)PERF-VERSION-FILE = util/bpf_skel/perf_version.h $(LIBBPF) $(SKEL_OUT)/vmlinux.h | $(SKEL_TMP_O= UT) $(QUIET_CLANG)$(CLANG) -g -O2 --target=3Dbpf $(CLANG_OPTIONS) $(BPF_INCLU= DE) $(TOOLS_UAPI_INCLUDE) \ + -include $(OUTPUT)PERF-VERSION-FILE -include util/bpf_skel/perf_version= .h \ -c $(filter util/bpf_skel/%.bpf.c,$^) -o $@ =20 $(SKEL_OUT)/%.skel.h: $(SKEL_TMP_OUT)/%.bpf.o | $(BPFTOOL) diff --git a/tools/perf/tests/shell/test_bpf_metadata.sh b/tools/perf/tests= /shell/test_bpf_metadata.sh new file mode 100755 index 000000000000..11df592fb661 --- /dev/null +++ b/tools/perf/tests/shell/test_bpf_metadata.sh @@ -0,0 +1,76 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 +# +# BPF metadata collection test. + +set -e + +err=3D0 +perfdata=3D$(mktemp /tmp/__perf_test.perf.data.XXXXX) + +cleanup() { + rm -f "${perfdata}" + rm -f "${perfdata}".old + trap - EXIT TERM INT +} + +trap_cleanup() { + cleanup + exit 1 +} +trap trap_cleanup EXIT TERM INT + +test_bpf_metadata() { + echo "Checking BPF metadata collection" + + if ! perf check -q feature libbpf-strings ; then + echo "Basic BPF metadata test [skipping - not supported]" + err=3D0 + return + fi + + # This is a basic invocation of perf record + # that invokes the perf_sample_filter BPF program. + if ! perf record -e task-clock --filter 'ip > 0' \ + -o "${perfdata}" sleep 1 2> /dev/null + then + echo "Basic BPF metadata test [Failed record]" + err=3D1 + return + fi + + # The BPF programs that ship with "perf" all have the following + # variable defined at compile time: + # + # const char bpf_metadata_perf_version[] SEC(".rodata") =3D <...>; + # + # This invocation looks for a PERF_RECORD_BPF_METADATA event, + # and checks that its content contains the string given by + # "perf version". + VERS=3D$(perf version | awk '{print $NF}') + if ! perf script --show-bpf-events -i "${perfdata}" | awk ' + /PERF_RECORD_BPF_METADATA.*perf_sample_filter/ { + header =3D 1; + } + /^ *entry/ { + if (header) { header =3D 0; entry =3D 1; } + } + $0 !~ /^ *entry/ { + entry =3D 0; + } + /perf_version/ { + if (entry) print $NF; + } + ' | egrep "$VERS" > /dev/null + then + echo "Basic BPF metadata test [Failed invalid output]" + err=3D1 + return + fi + echo "Basic BPF metadata test [Success]" +} + +test_bpf_metadata + +cleanup +exit $err diff --git a/tools/perf/util/bpf_skel/perf_version.h b/tools/perf/util/bpf_= skel/perf_version.h new file mode 100644 index 000000000000..1ed5b2e59bf5 --- /dev/null +++ b/tools/perf/util/bpf_skel/perf_version.h @@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */ + +#ifndef __PERF_VERSION_H__ +#define __PERF_VERSION_H__ + +#include "vmlinux.h" +#include + +/* + * This is used by tests/shell/record_bpf_metadata.sh + * to verify that BPF metadata generation works. + * + * PERF_VERSION is defined by a build rule at compile time. + */ +const char bpf_metadata_perf_version[] SEC(".rodata") =3D PERF_VERSION; + +#endif /* __PERF_VERSION_H__ */ --=20 2.50.0.rc1.591.g9c95f17f64-goog