From nobody Sun Feb 8 05:25:59 2026 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.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 7B72F2405E4 for ; Fri, 6 Jun 2025 21:53:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749246782; cv=none; b=ZkEm/yJpi1UIFKrkNcotPkODNTQI9kvw7GIgZeY3F+JJcdGNWIUP839FvaMt5b4j+HB6Ehstkcn5FBsqolmpIst1c4BJfUwutP0582ngDCpgo+YEdk+1h1z961rXXhqM3ZMI7f3cGrTfHauFP9QoSlnN9T6VIIx5c/gmjo56c4E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749246782; c=relaxed/simple; bh=b5qIz6P3lrcv3sGS7KxAxKzdqooPdqfn8oztpbwmp10=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=cJto53BDWW7PnlklSj0+TOjPovwV6uiD3NXExg4hcHlkudck8Cn/ljpLr6Uoik9OAUj1tGS/Gc+7kEjCF3i2WwjV5Nj9JPu82ADaNE5qY6+407YzW9pPZWaaNSr2csBzK1VMPqAbhFaup2IPXG/yEJMDlTGAgSfiJvRwRQenSF4= 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=vTQqpHtw; arc=none smtp.client-ip=209.85.210.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--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="vTQqpHtw" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-7377139d8b1so2117771b3a.0 for ; Fri, 06 Jun 2025 14:53:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1749246780; x=1749851580; 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=8iFfeaMcLuzx3qT6HoU1lCQOc9APQy0cingwV7epWcY=; b=vTQqpHtwu0I2MBWW74Kg8c1dRSl/Hks2f3rIoPlcGVaQPIDicU5R2YMjvLRuYqpjUE Mc43D/+XV2EV/7XwdH7uswZTHcQDqI8sGYyW4yyrImlZofkNO2A5vQFSvPuoabIrRQwS ggEqqUL/avBfJ9vfKuASpCNmuD/WUdmgC6Yi80KpubFSv/V0Y7zG1MrFl7Gf2F+7nJ/y 2k4lGWkhUP7Hcu/ycoGoFBs+Uj1asmwkqJvAKx6fAV8JgOhAmrz36CHTxicv3Sw6Mikb h+OqkURj4pwXOFW3zWL5Sw4CiewZwcm7f96I9G014iMWPEO8BNGyYZGjJc/HotEd2rqD Ov2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749246780; x=1749851580; 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=8iFfeaMcLuzx3qT6HoU1lCQOc9APQy0cingwV7epWcY=; b=EYDiPLy6ximisszUJjAvO/zmVVYjf19FaKicHDSPD+NeFWDA6trUsexLAfaqrbwzTR cj3vdIUTYU/7mn6yChj7yWRMysff1OoAwp5aOL1tuWtSAA5uGupsYE4kaB1IXRjE23ky a0gEdjQec32UtWHlPH29IeELuNTXVE2Y3hsqG+BFUYWh8ffqv5WKAEJ1ai+98WKqY+8Q aXk3uO/X2Q+BKqmGh8b3fvj2IQMxIHjYmFcQGm7D0MVidg6/5oK+iCIkvyevyyhDTIrS a8DSMaOSy2KnO2qE3Obkjv0Tq5kU5AHTHBR5P2n8CNq/U9GACx36+GiKEJV4kChFE4Eu HehA== X-Forwarded-Encrypted: i=1; AJvYcCVyosnvpBhreR7CaMGy5UzNJfSLLa1Gi1FeD7PT5y2D3Ws+oRmSbqLFfP6jwmtuAJ54nRHrrUonrwYYSRY=@vger.kernel.org X-Gm-Message-State: AOJu0YzgTQZ8G1QI1G+dUOCHRrl0jg3re0XwbcTSc5FVld3eRN2aePDu qjLsn2aclJHsCO0myCZneZJdO+moNncDNU3GP29jW7B93hRJgA1/btzPJbJkh6u4FegdkzpQ5Pw L3732DDrzd5eFsISpPuaytQ== X-Google-Smtp-Source: AGHT+IFWSsiTLCA9zysSvmxqFq5C2iXTQ62Am4lukNek4+xAO1R68sTOy8bTcsuDDhcx31/Pe7r+yAxD6oKYSLrH X-Received: from pgbfq11.prod.google.com ([2002:a05:6a02:298b:b0:b2c:4fb0:bc64]) (user=blakejones job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:6009:b0:218:c22:e3e6 with SMTP id adf61e73a8af0-21ee2555021mr6431282637.12.1749246779784; Fri, 06 Jun 2025 14:52:59 -0700 (PDT) Date: Fri, 6 Jun 2025 14:52:46 -0700 In-Reply-To: <20250606215246.2419387-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: <20250606215246.2419387-1-blakejones@google.com> X-Mailer: git-send-email 2.50.0.rc0.604.gd4ff7b7c86-goog Message-ID: <20250606215246.2419387-6-blakejones@google.com> Subject: [PATCH v3 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.rc0.604.gd4ff7b7c86-goog