From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.200 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796077229; b=H7FTHJAe8Ak8tAKfmA0VhnaZ87f1HLDp+5bC2SkHBKyPN3oxGyjZvHwdY841794QBQ0O rFCS6C9tDMhkdx7kqg98W2z2cdr2HsZzZ5dBFF5UWi8S89UkfX6EsaFVdB7aphsRjq/xj jNMI50PugHVdhAl7sL/eknKKmWKx6hpnYWnrkEZ04GsMEjfyOu1eP0Sxhl2Vv1RVGAduc lDO0ODgxys80MXRbhqG0tKAdgMPVLI80NaPPneAyCnV/M/tWoNq+YPR7jT1KGuBGFLTVz vauDbJv9xou48KIFZyrmPYoNFtn3C/LKI0PvkqkVCLRw5nHTjH2sA3oXtDTesUMyBrw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796077229; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:In-Reply-To: Mime-Version:References:X-Mailer:Message-ID:Subject:From:To:Cc: Content-Type:Content-Transfer-Encoding; bh=QdrkWtB0UbaZmhH1ywltiBFFb6MGChQxL+T0wH3EH5M=; b=xbr0beJtfn52gD0zEYXVVDr+MR438cyalxqQvrMe8TM92lcyUjPgXKKCoORYknrMecYw ztyKkaaiJkj6gmjTKatvwZ7aMaHm1cuT/EPrK/r2Ek87eaHK82dAhmgttUxx2cSpdTwsF /xfgSnrnCwS2clLvwtk/y2JqCP3ycYSS56L9fVCq0DpWpygNudZK+oSLbvxx3NiXbw8l6 g2SsjjsfjFSxzmE/0S5L4TvoQb4MsHJMuY7gu/SvaqHZDSaQJU7nl+z6VCeVGCXISI2Cp xKw8ovDdfgL3x9yX38o8QXTlH/bY6ng3wJEmo46R0EpW8tjXQiCCrCnxKHPyPyPbVxg== 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=KyMAwEYr; arc=none smtp.remote-ip=74.125.82.200 Received: from mail-dy1-f200.google.com (mail-dy1-f200.google.com [74.125.82.200]) (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 A769E606A32E for ; Mon, 30 Nov 2026 22:20:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A769E606A32E 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.a=rsa-sha256 header.s=20260707 header.b=KyMAwEYr Received: by mail-dy1-f200.google.com with SMTP id 5a478bee46e88-383ec96a7deso12746440eec.1 for ; Mon, 30 Nov 2026 14:20:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796077228; x=1796682028; darn=vger.kernel.org; h=content-transfer-encoding:content-type:cc:to:from:subject :message-id:references:mime-version:in-reply-to:date:from:to:cc :subject:date:message-id:reply-to:content-type; bh=QdrkWtB0UbaZmhH1ywltiBFFb6MGChQxL+T0wH3EH5M=; b=KyMAwEYr4UJFrGTyzDW7yXr72huCTYLxVmhQsZv1klU/NQZNs/zE4TivHgpDmloF7m WPKbX8QleDeybEqcGsznSJb1sFEI+uqFaLCtmxe61a8g7PTWiqjS5u2BBjO2GlubuhlD xJP2Vx+0qsdo/ROcSDFROpBNbDSeJyL2e+M7pnAQFdRpQHr6jsYzM4mrXRrmaBSivYE2 qpUFK3j9k9l4xlyO8/cdw8v6F+hSEFRXPnRAXoh8ux8oRXHlMueEzSxP8YKYfr/hBd0D 1N1svKhZo0LvgG6lO/uRRbw2o3P4l9GGL8BYV5gtGBTcxnZEKdJC0WRWWjxO3xv7Vome qNww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796077228; x=1796682028; h=content-transfer-encoding:content-type: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 :content-type; bh=QdrkWtB0UbaZmhH1ywltiBFFb6MGChQxL+T0wH3EH5M=; b=BdxqkY3vNPVPP2Ffi/aCsUD78PACoeNkb7zsqTU2BpngLXAKtuawTA7TBoeii1StGQ Ou0utstaRdBGdYdQq6y/M9Bl8qtim7sPiAJ5nxZ69ih/r1EusHXlBiYOUrLdkvwl3o6i EPHePf6P0yRKmspZir7A1Lrnjf2XSbb1HghzU3L/AgiN0/Lsd0raInUBk6o92QKuZTi5 48L4nXi6LlqfBaodGRDZtZ2PnO9xO2Mxd+EG+VpcB564MpenimPJxriTjwET45SkoeBa tPmK8qLt4W+Bep371/oZFh+95xsGEyBe6WRac39SKAhXLUd8jdL0JyGpplFZAy9zo2d5 AVvw== X-Forwarded-Encrypted: i=1; AL+hErF28VuB6P11Xw0SUVqhDJ5GMUiIxTFBLUfOR6eoFr9cNAnsBf9ecZXekKNl+wM69/pLaDivbfUNBOpvABU=@vger.kernel.org X-Gm-Message-State: APuU4Z8q7mqD3R5IF/DPnb3TYUBN3wv/cCGoNVPlpVziS3nLq2+GD/8x dICXS4sUlpAq1dgw16vxuw8jbRkij6YZWu7CqJD+8/arb0lCzw3jpdMGXQNekF9YSx0N2FBMF8Z N4iJyJSVltw== X-Received: from dyhd10.prod.google.com ([2002:a05:7300:828a:b0:386:95bc:ec27]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7301:46a3:b0:369:faa2:1fb2 with SMTP id 5a478bee46e88-3856f65ada3mr35121402eec.8.1796077227110; Mon, 30 Nov 2026 14:20:27 -0800 (PST) Date: Mon, 30 Nov 2026 14:20:01 -0800 In-Reply-To: <20261130222008.4189072-1-irogers@google.com> 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 References: <20261130222008.4189072-1-irogers@google.com> X-Mailer: git-send-email 2.56.1.839.g22a8290db9-goog Message-ID: <20261130222008.4189072-5-irogers@google.com> Subject: [PATCH v3 04/11] perf jevents: Encapsulate big_c_string lookups behind pmu_events__get_string() 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" Content-Transfer-Encoding: quoted-printable Replace direct &big_c_string[offset] indexing in decompress_event(), decompress_metric(), and describe_metricgroup() with calls to pmu_events__get_string(uint32_t offset), and change compact_pmu_event and metricgroups offsets to uint32_t. When generating a single file (such as empty-pmu-events.c), emit pmu_events__get_string() as a static inline helper indexing static const char big_c_string[]. When generating separate pmu-events.c and pmu-events-string.c files, keep big_c_string static to pmu-events-string.c and expose pmu_events__get_string() across the two generated translation units. Also add explicit POSIX standard header inclusions to the generated C files. This cleanly isolates the string storage representation inside pmu-events-string.c so subsequent patches can replace flat byte offsets into big_c_string[] with block-indexed string compression (where each uint32_t offset encodes (block_id << 16) | sub_offset into independently compressed ~8 KiB blocks decompressed on demand) without changing pmu-events.c. Reviewed-by: James Clark Signed-off-by: Ian Rogers --- tools/perf/pmu-events/empty-pmu-events.c | 52 +++++++++++---- tools/perf/pmu-events/jevents.py | 81 ++++++++++++++++++------ 2 files changed, 104 insertions(+), 29 deletions(-) diff --git a/tools/perf/pmu-events/empty-pmu-events.c b/tools/perf/pmu-even= ts/empty-pmu-events.c index 6121ef3d2a98..c40fa30d7235 100644 --- a/tools/perf/pmu-events/empty-pmu-events.c +++ b/tools/perf/pmu-events/empty-pmu-events.c @@ -4,11 +4,15 @@ #include #include "util/header.h" #include "util/pmu.h" -#include +#include #include +#include +#include +#include +#include =20 struct compact_pmu_event { - int offset; + uint32_t offset; }; =20 struct pmu_table_entry { @@ -18,7 +22,7 @@ struct pmu_table_entry { }; =20 /* clang-format off */ -static const char *const big_c_string =3D +static const char big_c_string[] =3D /* offset=3D0 */ "alignment-faults\000software\000Number of kernel handled memory alignment= faults\000config=3D7\000\00000\000\000\000\000\000" /* offset=3D92 */ @@ -2635,6 +2639,11 @@ static const char *const big_c_string =3D "stalled_cycles_per_instruction\000Default\000(max(stalled\\-cycles\\-fron= tend, stalled\\-cycles\\-backend) / instructions if has_event(stalled\\-cyc= les\\-frontend) & has_event(stalled\\-cycles\\-backend) else (stalled\\-cyc= les\\-frontend / instructions if has_event(stalled\\-cycles\\-frontend) els= e (stalled\\-cycles\\-backend / instructions if has_event(stalled\\-cycles\= \-backend) else 0)))\000\000Max front or backend stalls per instruction\000= \000\000\000\000\000001" ; =20 +static inline const char *pmu_events__get_string(uint32_t offset) +{ + return &big_c_string[offset]; +} + static const struct compact_pmu_event pmu_events__common_default_core[] = =3D { /* bpc\000legacy cache\000Branch prediction unit read accesses\000legacy-= cache-conf... */ { 216 }, @@ -5460,9 +5469,17 @@ static const struct pmu_sys_events pmu_sys_event_tab= les[] =3D { }, }; =20 -static void decompress_event(int offset, struct pmu_event *pe) +static void decompress_event(uint32_t offset, struct pmu_event *pe) { - const char *p =3D &big_c_string[offset]; + const char *p =3D pmu_events__get_string(offset); + + if (!p) { + const char *pmu =3D pe->pmu; + + memset(pe, 0, sizeof(*pe)); + pe->pmu =3D pmu; + return; + } =20 pe->name =3D (*p =3D=3D '\0' ? NULL : p); while (*p++); @@ -5489,9 +5506,17 @@ static void decompress_event(int offset, struct pmu_= event *pe) pe->long_desc =3D (*p =3D=3D '\0' ? NULL : p); } =20 -static void decompress_metric(int offset, struct pmu_metric *pm) +static void decompress_metric(uint32_t offset, struct pmu_metric *pm) { - const char *p =3D &big_c_string[offset]; + const char *p =3D pmu_events__get_string(offset); + + if (!p) { + const char *pmu =3D pm->pmu; + + memset(pm, 0, sizeof(*pm)); + pm->pmu =3D pmu; + return; + } =20 pm->metric_name =3D (*p =3D=3D '\0' ? NULL : p); while (*p++); @@ -6003,7 +6028,7 @@ int pmu_metrics_table__iterate_tables(pmu_metrics_tab= le_iter_t fn, void *data) return 0; } =20 -static const int metricgroups[][2] =3D { +static const uint32_t metricgroups[][2] =3D { =20 }; =20 @@ -6013,11 +6038,16 @@ const char *describe_metricgroup(const char *group) =20 while (low <=3D high) { int mid =3D (low + high) / 2; - const char *mgroup =3D &big_c_string[metricgroups[mid][0]]; - int cmp =3D strcmp(mgroup, group); + const char *mgroup =3D pmu_events__get_string(metricgroups[mid][0]); + int cmp; + + if (!mgroup) + return NULL; + + cmp =3D strcmp(mgroup, group); =20 if (cmp =3D=3D 0) - return &big_c_string[metricgroups[mid][1]]; + return pmu_events__get_string(metricgroups[mid][1]); else if (cmp < 0) low =3D mid + 1; else diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jeven= ts.py index 983b4252cbae..6da4ea60b828 100755 --- a/tools/perf/pmu-events/jevents.py +++ b/tools/perf/pmu-events/jevents.py @@ -923,9 +923,17 @@ static const struct pmu_sys_events pmu_sys_event_table= s[] =3D { \t}, }; =20 -static void decompress_event(int offset, struct pmu_event *pe) +static void decompress_event(uint32_t offset, struct pmu_event *pe) { -\tconst char *p =3D &big_c_string[offset]; +\tconst char *p =3D pmu_events__get_string(offset); + +\tif (!p) { +\t\tconst char *pmu =3D pe->pmu; + +\t\tmemset(pe, 0, sizeof(*pe)); +\t\tpe->pmu =3D pmu; +\t\treturn; +\t} """) for attr in _json_event_attributes: _args.output_file.write(f'\n\tpe->{attr} =3D ') @@ -941,9 +949,17 @@ static void decompress_event(int offset, struct pmu_ev= ent *pe) _args.output_file.write('\twhile (*p++);') _args.output_file.write("""} =20 -static void decompress_metric(int offset, struct pmu_metric *pm) +static void decompress_metric(uint32_t offset, struct pmu_metric *pm) { -\tconst char *p =3D &big_c_string[offset]; +\tconst char *p =3D pmu_events__get_string(offset); + +\tif (!p) { +\t\tconst char *pmu =3D pm->pmu; + +\t\tmemset(pm, 0, sizeof(*pm)); +\t\tpm->pmu =3D pmu; +\t\treturn; +\t} """) for attr in _json_metric_attributes: _args.output_file.write(f'\n\tpm->{attr} =3D ') @@ -1406,7 +1422,7 @@ int pmu_for_each_sys_metric(pmu_metric_iter_fn fn, vo= id *data) def print_metricgroups() -> None: assert _args is not None _args.output_file.write(""" -static const int metricgroups[][2] =3D { +static const uint32_t metricgroups[][2] =3D { """) for mgroup in sorted(_metricgroups): description =3D _metricgroups[mgroup] @@ -1424,11 +1440,16 @@ const char *describe_metricgroup(const char *group) =20 \twhile (low <=3D high) { \t\tint mid =3D (low + high) / 2; -\t\tconst char *mgroup =3D &big_c_string[metricgroups[mid][0]]; -\t\tint cmp =3D strcmp(mgroup, group); +\t\tconst char *mgroup =3D pmu_events__get_string(metricgroups[mid][0]); +\t\tint cmp; + +\t\tif (!mgroup) +\t\t\treturn NULL; + +\t\tcmp =3D strcmp(mgroup, group); =20 \t\tif (cmp =3D=3D 0) -\t\t\treturn &big_c_string[metricgroups[mid][1]]; +\t\t\treturn pmu_events__get_string(metricgroups[mid][1]); \t\telse if (cmp < 0) \t\t\tlow =3D mid + 1; \t\telse @@ -1510,11 +1531,15 @@ such as "arm/cortex-a34".''', #include #include "util/header.h" #include "util/pmu.h" -#include +#include #include +#include +#include +#include +#include =20 struct compact_pmu_event { -\tint offset; +\tuint32_t offset; }; =20 struct pmu_table_entry { @@ -1562,19 +1587,39 @@ struct pmu_table_entry { _bcs.compute() _args.output_file.write('/* clang-format off */\n') if not _args.output_string_file: - _args.output_file.write('static const char *const big_c_string =3D\n') - for s in _bcs.big_string: - _args.output_file.write(s) + _args.output_file.write('static const char big_c_string[] =3D\n') + if _bcs.big_string: + for s in _bcs.big_string: + _args.output_file.write(s) + else: + _args.output_file.write('""\n') _args.output_file.write(';\n\n') + _args.output_file.write("""static inline const char *pmu_events__get_s= tring(uint32_t offset) +{ +\treturn &big_c_string[offset]; +} + +""") else: _args.output_string_file.write('/* SPDX-License-Identifier: GPL-2.0 */= \n') _args.output_string_file.write('/* Autogenerated by jevents.py */\n') - _args.output_string_file.write('extern const char big_c_string[];\n') - _args.output_string_file.write('const char big_c_string[] =3D\n') - for s in _bcs.big_string: - _args.output_string_file.write(s) + _args.output_string_file.write('#include \n\n') + _args.output_string_file.write('const char *pmu_events__get_string(uin= t32_t offset);\n\n') + _args.output_string_file.write('/* clang-format off */\n') + _args.output_string_file.write('static const char big_c_string[] =3D\n= ') + if _bcs.big_string: + for s in _bcs.big_string: + _args.output_string_file.write(s) + else: + _args.output_string_file.write('""\n') _args.output_string_file.write(';\n') - _args.output_file.write('extern const char big_c_string[];\n\n') + _args.output_string_file.write('/* clang-format on */\n\n') + _args.output_string_file.write("""const char *pmu_events__get_string(u= int32_t offset) +{ +\treturn &big_c_string[offset]; +} +""") + _args.output_file.write('const char *pmu_events__get_string(uint32_t o= ffset);\n\n') for arch in archs: arch_path =3D f'{_args.starting_dir}/{arch}' ftw(arch_path, [], process_one_file) --=20 2.56.1.839.g22a8290db9-goog