All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ian Rogers <irogers@google.com>
To: Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	 Arnaldo Carvalho de Melo <acme@kernel.org>,
	Namhyung Kim <namhyung@kernel.org>,
	 Athira Rajeev <atrajeev@linux.ibm.com>
Cc: Jiri Olsa <jolsa@kernel.org>,
	Adrian Hunter <adrian.hunter@intel.com>,
	 James Clark <james.clark@linaro.org>,
	linux-perf-users@vger.kernel.org,  linux-kernel@vger.kernel.org,
	Ian Rogers <irogers@google.com>
Subject: [PATCH v3 06/11] perf jevents: Add --compress=lzma block compression backend
Date: Mon, 30 Nov 2026 14:20:03 -0800	[thread overview]
Message-ID: <20261130222008.4189072-7-irogers@google.com> (raw)
In-Reply-To: <20261130222008.4189072-1-irogers@google.com>

Add an 'lzma' block-indexed string compression backend to jevents.py
using Python's standard-library lzma module (imported lazily) to
compress each ~8 KiB string block independently as a raw LZMA2 stream
(FORMAT_RAW + FILTER_LZMA2, dict_size=64 KiB) decoded on demand via
liblzma's lzma_raw_buffer_decode() in pmu-events-string.c.

This provides random-access per-block string decompression indexed by
(block_id << 16) | sub_offset on builds where liblzma is enabled without
libzstd or zlib. On x86, --compress=lzma shrinks pmu-events-string.o
from ~6.90 MB to ~819 KB.

Reviewed-by: James Clark <james.clark@linaro.org>
Signed-off-by: Ian Rogers <irogers@google.com>
---
 tools/perf/pmu-events/jevents.py | 44 ++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)

diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jevents.py
index 86c3263ed750..008e6331f4e8 100755
--- a/tools/perf/pmu-events/jevents.py
+++ b/tools/perf/pmu-events/jevents.py
@@ -259,10 +259,54 @@ def _compress_blocks_zlib(blocks: Sequence[bytes]) -> Optional[CompressedStringO
   )
 
 
+def _compress_blocks_lzma(blocks: Sequence[bytes]) -> Optional[CompressedStringOutput]:
+  """Compress blocks using stdlib lzma raw LZMA2 streams."""
+  try:
+    lzma_mod = importlib.import_module('lzma')
+  except ImportError:
+    return None
+
+  dict_size = 1 << _BIG_C_STRING_BLOCK_SHIFT
+  filters = [{'id': lzma_mod.FILTER_LZMA2, 'preset': 6, 'dict_size': dict_size}]
+  compressed_blocks = [
+      lzma_mod.compress(block, format=lzma_mod.FORMAT_RAW, filters=filters)
+      for block in blocks
+  ]
+
+  decompress_fn = f"""static bool decompress_block(const unsigned char *src, uint32_t src_len,
+\t\t\t     char *dst, uint32_t dst_len)
+{{
+\tlzma_options_lzma opt = {{
+\t\t.dict_size = {dict_size}U,
+\t\t.preset_dict = NULL,
+\t\t.preset_dict_size = 0,
+\t}};
+\tconst lzma_filter filters[] = {{
+\t\t{{ .id = LZMA_FILTER_LZMA2, .options = &opt }},
+\t\t{{ .id = LZMA_VLI_UNKNOWN, .options = NULL }},
+\t}};
+\tsize_t in_pos = 0, out_pos = 0;
+\tlzma_ret ret;
+
+\tret = lzma_raw_buffer_decode(filters, NULL, src, &in_pos, src_len,
+\t\t\t\t     (uint8_t *)dst, &out_pos, dst_len);
+\treturn ret == LZMA_OK && in_pos == src_len && out_pos == dst_len;
+}}
+"""
+  return CompressedStringOutput(
+      name='lzma',
+      c_headers=['<lzma.h>'],
+      compressed_blocks=compressed_blocks,
+      extra_c_decls='',
+      decompress_c_fn=decompress_fn,
+  )
+
+
 _COMPRESS_BACKENDS: Dict[
     str, Optional[Callable[[Sequence[bytes]], Optional[CompressedStringOutput]]]
 ] = {
     'none': None,
+    'lzma': _compress_blocks_lzma,
     'zlib': _compress_blocks_zlib,
 }
 
-- 
2.56.1.839.g22a8290db9-goog


  parent reply	other threads:[~2026-11-30 22:20 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 22:19 [PATCH v3 00/11] perf jevents: Block-indexed string compression and default JEVENTS_ARCH=all Ian Rogers
2026-11-30 22:19 ` [PATCH v3 01/11] perf jevents: Store raw bytes in BigCString instead of C-escaped strings Ian Rogers
2026-11-30 22:19 ` [PATCH v3 02/11] perf jevents: Sort BigCString entries alphabetically Ian Rogers
2026-11-30 22:20 ` [PATCH v3 03/11] perf jevents: Store PMU names as string literals in struct pmu_table_entry Ian Rogers
2026-11-30 22:20 ` [PATCH v3 04/11] perf jevents: Encapsulate big_c_string lookups behind pmu_events__get_string() Ian Rogers
2026-11-30 22:20 ` [PATCH v3 05/11] perf jevents: Add block-indexed string packing and --compress=zlib Ian Rogers
2026-11-30 22:20 ` Ian Rogers [this message]
2026-11-30 22:20 ` [PATCH v3 07/11] perf jevents: Add --compress=zstd block compression backend Ian Rogers
2026-11-30 22:20 ` [PATCH v3 08/11] perf build: Enable jevents string compression when available Ian Rogers
2026-11-30 22:20 ` [PATCH v3 09/11] perf jevents: Scope metricgroup descriptions to struct pmu_metrics_table Ian Rogers
2026-11-30 22:20 ` [PATCH v3 10/11] perf tests pmu-events: Test metricgroup descriptions and concurrent lookups Ian Rogers
2026-11-30 22:20 ` [PATCH v3 11/11] perf build: Default JEVENTS_ARCH to all Ian Rogers
2026-11-30 22:38 ` [PATCH v3 00/11] perf jevents: Block-indexed string compression and default JEVENTS_ARCH=all sashiko-bot
2026-12-01 14:01 ` Athira Rajeev

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261130222008.4189072-7-irogers@google.com \
    --to=irogers@google.com \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=atrajeev@linux.ibm.com \
    --cc=james.clark@linaro.org \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.