Re: [PATCH v4] perf utilities: cln_size header

From: Namhyung Kim

Date: Thu Mar 26 2026 - 18:43:48 EST


Hello,

On Sat, Mar 21, 2026 at 08:41:55PM +0000, Ricky Ringler wrote:
> Store cacheline size during perf record in header, so
> that cacheline size can be used for other features, like
> sort.
>
> V4: Ian feedback
> V3: Rebase off perf-tools-next round two
> V2: Rebase off perf-tools-next
>
> Follow-up patch from message ID "aYZiQk6Uftzlb_JV@x1"

Please squash the patches into a single change and send it again.

>
> Testing:
> - Built perf
> - Ran record + report with feat enabled
> - Ran record + report with feat disabled
>
> Tested-by: Ricky Ringler <ricky.ringler@xxxxxxxxx>

Tested-by tag from the author may not be meaningful. We always expect
authors to test their patches. :)

> Signed-off-by: Ricky Ringler <ricky.ringler@xxxxxxxxx>
> ---
> tools/perf/builtin-inject.c | 2 +-
> tools/perf/util/header.c | 11 ++++++++---
> tools/perf/util/sort.c | 8 ++++++--
> 3 files changed, 15 insertions(+), 6 deletions(-)
>
> diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c
> index 2675d32f88cf..11ac7c8c4be3 100644
> --- a/tools/perf/builtin-inject.c
> +++ b/tools/perf/builtin-inject.c
> @@ -2134,7 +2134,7 @@ static bool keep_feat(struct perf_inject *inject, int feat)
> case HEADER_HYBRID_TOPOLOGY:
> case HEADER_PMU_CAPS:
> case HEADER_CPU_DOMAIN_INFO:
> - case HEADER_CLNq_SIZE:
> + case HEADER_CLN_SIZE:
> return true;
> /* Information that can be updated */
> case HEADER_BUILD_ID:
> diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
> index 4f65faafe75d..2d39da470267 100644
> --- a/tools/perf/util/header.c
> +++ b/tools/perf/util/header.c
> @@ -1310,8 +1310,13 @@ static int write_cln_size(struct feat_fd *ff,
> {
> int cln_size = cacheline_size();
>
> - if (!cln_size)
> - cln_size = 0;
> +
> + if (!cln_size) {
> + int default_cacheline_size = 64;

Let's get rid of the local variable.

Thanks,
Namhyung

> +
> + cln_size = default_cacheline_size;
> + }
> +
> ff->ph->env.cln_size = cln_size;
>
> return do_write(ff, &cln_size, sizeof(cln_size));
> @@ -2274,7 +2279,7 @@ static void print_cache(struct feat_fd *ff, FILE *fp __maybe_unused)
> }
> }
>
> -static void print_cln_size(struct feat_fd *ff, FILE *fp __maybe_unused)
> +static void print_cln_size(struct feat_fd *ff, FILE *fp)
> {
> fprintf(fp, "# cacheline size: %u\n", ff->ph->env.cln_size);
> }
> diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c
> index 13287ade784e..5f617cf03d5d 100644
> --- a/tools/perf/util/sort.c
> +++ b/tools/perf/util/sort.c
> @@ -2483,8 +2483,12 @@ hist_entry__cln_size(struct hist_entry *he)
> if (he && he->hists) {
> struct evsel *evsel = hists_to_evsel(he->hists);
>
> - if (evsel && evsel->evlist->session && evsel->evlist->session)
> - ret = evsel->evlist->session->header.env.cln_size;
> +
> + if (evsel) {
> + struct perf_session *session = evsel__session(evsel);
> +
> + ret = session->header.env.cln_size;
> + }
> }
>
> if (!ret || ret < 1) {
> --
> 2.53.0
>
>