From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.199 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796077220; b=kkNR2SDqzfaD40dN9lXBSA1QmS6wqc8VwGcPO4D6ufpaZ3UAy0pEF306+jvMJDl/WEdf JbYIX1im+oOH8I0hTsQbF9mZgBEwQWhbhaAbj5uI/5eIm2DpSqBDFk/O8CTcNdfJ4kKft fUmAn5XTfgwI4Fgg4wGEkNs4wRIR6BOC9NtHFFOdxF0PyESBZCiOmmQ9yLLEjZMVcMcXb KOyKXa6pjBEz5bpqkXRThN4JwfePnkFzpiUjoty25L5/ZMneJ3Wx4SnHthaSGOM5yVJP8 LwXj0eQiuxZ8QCJJCLnol6+Vp2GLmDZpaKJuf+egGiefA+Fki7XBG/i8Gp+pwj+gcpA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796077220; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:Mime-Version: X-Mailer:Message-ID:Subject:From:To:Cc:Content-Type; bh=+4i+iR2WT1CSRGrka3oW9yjLVKtjliaq9AntlEi35ec=; b=K2tj2uqAouAm0wW7zsqeiY6Vai0go/azelDf+Kl7LJomt4W5IXJADAP4Ev+ajPie9tb6 2c88YBfsceHRL8ij3KSV5hgtdMHa6TrBfC9BMkgvNkXeN3LZF/86AcsR273Pn0EXqYEEq 5iBIwrgw0s0CoktwB1D2/4f2vEHOHcAozpjKNGeaxB9N1PloQ4p/HIgrDHCtmJXoMuCof sOI1AbGgkQFC+Ft8n9uajX3FlPVuQWRV4IQmbU0EPTeYHjPehOfSmR9SvpovLZzGRsTg+ G7Re70ngJlegrGoMglEBnrZL7aqXOGT03VN7J5qPxpH2R78+GdA1/IBTY++0T3D+K4g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=Zkg2KXz2; arc=none smtp.remote-ip=74.125.82.199 Received: from mail-dy1-f199.google.com (mail-dy1-f199.google.com [74.125.82.199]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2405C606A31A for ; Mon, 30 Nov 2026 22:20:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2405C606A31A 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, unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=Zkg2KXz2 Received: by mail-dy1-f199.google.com with SMTP id 5a478bee46e88-33713e5e6daso16434591eec.0 for ; Mon, 30 Nov 2026 14:20:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796077219; x=1796682019; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:mime-version:date:from :to:cc:subject:date:message-id:reply-to:content-type; bh=+4i+iR2WT1CSRGrka3oW9yjLVKtjliaq9AntlEi35ec=; b=Zkg2KXz2IsVC5ETjNnTefWcji8NP7ltoWDiX9gfHW2X2edPQVhohjJ1snqBq7hKFBN H+Mww2WQviX/BNor7r+xiRt3K1jAY02Iy/XRbINQUMMoY3xwOV9aEjLUEIxGdEBVLfa7 L2HrrAbw/LWrDVyryepUS1qJF3NgfIWu5P8gnxQSdNIyAV8t85Y1y4v1UMA0SkYtH8WA FyUQ5oRQda3ICU7j0OXI6S46ZlPqPlD/L3lU71Co9iaXaDJBadbbIW3AP23obqkB6uVg 1LqD9wmhM3A18ZzCj8uf1XykmJmzGCK4xOae82wm66IWpl5VdPG/6jpXR8wKH6upEJoQ 9IWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796077219; x=1796682019; h=content-type:cc:to:from:subject:message-id:mime-version:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=+4i+iR2WT1CSRGrka3oW9yjLVKtjliaq9AntlEi35ec=; b=sQnV29easFlxDVYjxhrCz0gKmQ7sL9LflF2vokYuyhoQl6wkJjIARYHKBaXzsz5Xnq fq5HLaB1l7KsazSupE7nDh0zWfNX4QdZvokA9bE8kFH8yx0cwp4dTZc0p9OMBGpWYYSW K1CCIBAKzmTLo4JcIfW+X222d1qWUVDtxXjZ8DM8TJEWRVm/eNTOtOb8qvYr90hPEO9D oJ739f5ddnZCZb+L/JdCIK5eUyWpTpEufTjyo+QeewFrAVl4yxNTHlbV8vwQNFyT4HwT fDH99M6f82M9DP9VB5C8ahmJ892BZtr6F9M+JTk75wWQESCYODHB9bl9B/GW3znhRkdw YCsw== X-Forwarded-Encrypted: i=1; AL+hErHavdR67zXYo9MDqK1FB00Rhy0eiUSe95FAlmRXjIn4OrPTgFna40ObQ9mVS2IR61xFYAeiAW2WnQetdUA=@vger.kernel.org X-Gm-Message-State: APuU4Z8L8fEJ7Hn1iCzZE22bvbM/dXDSz5dRVWGD/HuTqSZDgay25lVB dgbr57YJK3PManNCzN9Cpo5jnh4N83dVZHJw3Dykkmd3v5IvtxAP9s+RC3BfUVs2xbvIf/OINmP WT3CVihLqTA== X-Received: from dybto8.prod.google.com ([2002:a05:7300:f148:b0:386:c442:456c]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:693c:41c3:20b0:387:cb1:2214 with SMTP id 5a478bee46e88-3870cb12290mr4440446eec.22.1796077218837; Mon, 30 Nov 2026 14:20:18 -0800 (PST) Date: Mon, 30 Nov 2026 14:19:57 -0800 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 X-Mailer: git-send-email 2.56.1.839.g22a8290db9-goog Message-ID: <20261130222008.4189072-1-irogers@google.com> Subject: [PATCH v3 00/11] perf jevents: Block-indexed string compression and default JEVENTS_ARCH=all From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Athira Rajeev Cc: Jiri Olsa , Adrian Hunter , James Clark , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Ian Rogers Content-Type: text/plain; charset="UTF-8" Compiled-in PMU event and metric tables (pmu-events-in.o) currently store ~6.9 MiB of uncompressed string data in .rodata on x86 alone, causing JEVENTS_ARCH to default to $(SRCARCH) rather than all and preventing out-of-the-box cross-architecture perf.data event/metric resolution unless explicitly built with JEVENTS_ARCH=all. Compressing big_c_string as a single whole-table stream would force perf to allocate and decompress megabytes of unused CPU models' strings on startup just to resolve a single event, whereas compressing individual short strings suffers from poor compression ratios and per-string framing overhead. Instead, this series introduces "block-indexed string compression": sorted, suffix-folded event and metric byte records are packed into ~8 KiB blocks without splitting records across block boundaries, each block is compressed independently (sharing a single preset or trained dictionary across blocks so ~8 KiB blocks retain high compression ratios), and every uint32_t string offset is encoded as (block_id << 16) | sub_offset. An ~8 KiB target block size sits at the knee of the compression vs. random-access curve (smaller 1-4 KiB blocks pay 22-128% more .rodata for per-block entropy headers and index entries, while larger 16-64 KiB blocks yield <15% extra savings at 2-8x higher decompression and page-fault cost per binary-search probe). At runtime, pmu_events__get_string() uses a lock-free atomic block pointer cache to decompress only the touched ~8 KiB blocks on demand, leaving untouched CPU models' and non-host architectures' blocks compressed in .rodata at zero runtime CPU or heap cost. The series starts with a standalone BigCString raw-byte fix for describe_metricgroup() binary-search ordering, prepares the string and PMU table layout, adds the zlib, lzma, and zstd block compression backends, scopes metricgroup descriptions per struct pmu_metrics_table so JEVENTS_ARCH=all never leaks descriptions across architectures or models, and switches the default JEVENTS_ARCH to all: - Bug fix, string layout, and hot-path isolation (Patches 1-4): - Patch 1 stores raw NUL-delimited UTF-8 bytes in BigCString instead of C-escaped strings, fixing suffix folding and describe_metricgroup() binary-search ordering on prefix-overlapping names (such as "Bad" vs "BadSpec"; Fixes: 66c6e0c10027) without changing empty-pmu-events.c so it can be cherry-picked standalone. - Patch 2 partitions non-folded BigCString event strings before metric strings and sorts entries lexicographically by their raw UTF-8 byte sequence within each partition so identically prefixed event names, encodings, descriptions, and metric expressions cluster into adjacent ~8 KiB blocks, improving block compression ratios by ~20-23%. - Patch 3 stores PMU names directly as const char *pmu_name string literals in struct pmu_table_entry (only 68 unique PMU names / 536 B across ~443 rows across all architectures, already in .data.rel.ro) so the compiler/linker merge them in .rodata.str1.1 and hot PMU wildcard scans never touch big_c_string or trigger block decompression. - Patch 4 encapsulates big_c_string offset lookups behind pmu_events__get_string(uint32_t offset) across pmu-events.c and pmu-events-string.c. - On-demand block decompression backends (Patches 5-8): - Patch 5 packs big_c_string into ~8 KiB record-aligned blocks indexed by (block_id << 16) | sub_offset, adds lock-free thread-safe atomic per-block decompression on demand, and adds --compress=zlib using raw Deflate with a <= 32 KiB preset dictionary. - Patch 6 adds --compress=lzma using raw LZMA2 per block with a 64 KiB dictionary window. - Patch 7 adds --compress=zstd using ZSTD_decompress_usingDDict() per block with a once-digested shared 64 KiB ZSTD_DDict (~26% smaller .rodata than dictionary-free ~8 KiB zstd blocks). - Patch 8 wires JEVENTS_COMPRESS into Makefile.perf and pmu-events/Build, preferring zstd, then zlib, then lzma, and falling back to none. - Scoped metricgroups, testing, and JEVENTS_ARCH=all default (Patches 9-11): - Patch 9 scopes metricgroup descriptions to each struct pmu_metrics_table (deduplicating identical arrays across models into 31 tables across all architectures), exposes pmu_metrics_table__describe_metricgroup(), and restricts describe_metricgroup() to pmu_metrics_table__find() and pmu_metrics_table__default() so JEVENTS_ARCH=all never leaks x86 descriptions (e.g. Memory_BW) onto PowerPC or lets Intel/AMD lpm_cpu_power descriptions overwrite each other. - Patch 10 adds prefix-overlapping metricgroups.json test coverage, cross-architecture and cross-model isolation assertions (power10 Memory_BW, skylake vs amdzen4 lpm_cpu_power), and an 8-thread concurrent event/metric/metricgroup stress test in perf test pmu-events. - Patch 11 switches the default JEVENTS_ARCH to all. Bundling all architectures (x86, arm64, powerpc, riscv, s390, nds32) with zstd shrinks pmu-events-in.o from 7.16 MiB (x86 + none) to 1.10 MiB (all + zstd, -84.6%) and cuts the stripped perf binary nearly in half, with ~3 ms median wall-clock overhead on 'perf stat true'. v3: - New Patch 9: Scope metricgroup descriptions per struct pmu_metrics_table and add pmu_metrics_table__describe_metricgroup() so JEVENTS_ARCH=all does not leak x86's Memory_BW description onto PowerPC or clobber AMD/Intel lpm_cpu_power descriptions (reported by Athira Rajeev). - Patch 10 (was Patch 9): Update test__metricgroups() to exercise pmu_metrics_table__describe_metricgroup() and verify cross-arch (power10 Memory_BW) and cross-model (skylake vs amdzen4 lpm_cpu_power) isolation. - Rebase onto latest tmp.perf-tools-next (resolving the tools/perf/tests/make conflict noted by Athira Rajeev) and add James Clark's Reviewed-by on unchanged patches. - v2: https://lore.kernel.org/linux-perf-users/20261116070038.2968725-1-irogers@google.com/ v2: - Patch 1: Avoid rebinding pmu_name from str to bytes in print_pending_events() and print_pending_metrics() (use pmu_name_bytes) and annotate _args as Optional[argparse.Namespace] so mypy type-checks functions guarding on 'assert _args is not None' (Sashiko). - Patch 10 (now Patch 11): Remove the unreferenced make_jevents_all definition in tools/perf/tests/make (Sashiko). - Rebase onto latest perf-tools-next. - v1: https://lore.kernel.org/linux-perf-users/20261113210822.3112700-1-irogers@google.com/ AI Assistance Disclosure (per Documentation/process/coding-assistants.rst and Documentation/process/generated-content.rst): - Tools used: Antigravity coding assistant and Sashiko automated patch review. - Summary of prompts and assistance: Interactive design and implementation of the BigCString raw-byte fix and alphabetical sorting, struct pmu_table_entry PMU name string literals, lock-free 8 KiB block-indexed decompression across zlib, lzma, and zstd, per-table metricgroup description scoping, Makefile.config/Build integration, multithreaded unit tests, size/latency benchmarking, and review fixes. - Testing performed: Built and tested GCC (MYPY=1 PYLINT=1), CC=clang, JEVENTS_COMPRESS={none,zlib,lzma,zstd}, NO_JEVENTS=1, JEVENTS_ARCH={x86,all}, AddressSanitizer + LeakSanitizer, perf test (pmu-events, metric parsing), and scripts/checkpatch.pl. Ian Rogers (11): perf jevents: Store raw bytes in BigCString instead of C-escaped strings perf jevents: Sort BigCString entries alphabetically perf jevents: Store PMU names as string literals in struct pmu_table_entry perf jevents: Encapsulate big_c_string lookups behind pmu_events__get_string() perf jevents: Add block-indexed string packing and --compress=zlib perf jevents: Add --compress=lzma block compression backend perf jevents: Add --compress=zstd block compression backend perf build: Enable jevents string compression when available perf jevents: Scope metricgroup descriptions to struct pmu_metrics_table perf tests pmu-events: Test metricgroup descriptions and concurrent lookups perf build: Default JEVENTS_ARCH to all tools/perf/.gitignore | 1 + tools/perf/Makefile.config | 9 +- tools/perf/Makefile.perf | 13 +- tools/perf/pmu-events/Build | 49 +- .../arch/test/test_soc/cpu/metricgroups.json | 4 + tools/perf/pmu-events/empty-pmu-events.c | 7844 +++++++++-------- tools/perf/pmu-events/jevents.py | 1106 ++- tools/perf/pmu-events/pmu-events.h | 2 + tools/perf/tests/make | 6 +- tools/perf/tests/pmu-events.c | 284 +- 10 files changed, 5229 insertions(+), 4089 deletions(-) create mode 100644 tools/perf/pmu-events/arch/test/test_soc/cpu/metricgroups.json base-commit: 4a7008f739a30ee4c22d9f21af362a5128f2628d -- 2.56.1.839.g22a8290db9-goog