Linux Perf Users
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Ian Rogers" <irogers@google.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH 3/8] perf build: Avoid copying pmu-events JSON files into OUTPUT
Date: Sun, 06 Dec 2026 02:26:35 +0000	[thread overview]
Message-ID: <sashiko-outbox-252063@kernel.org> (raw)
In-Reply-To: <20261206021147.3036701-4-irogers@google.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] perf build: unescaped hash in shell calls breaks GNU Make 4.0
  to 4.2
- [Low] perf build: manifest rules omit make -q/-t guards and tmp
  cleanup
--

commit e0b46c01cb6199425e57038cd246c6ade1c2f920
Author: Ian Rogers <irogers@google.com>

perf build: Avoid copying pmu-events JSON files into OUTPUT

This commit writes generated pmu-events JSON files into a separate
$(OUTPUT)pmu-events/gen directory and passes them to jevents.py via
manifests, avoiding copying checked-in JSON files into OUTPUT.

> diff --git a/tools/perf/pmu-events/Build b/tools/perf/pmu-events/Build
> index 32fc1378ef3aa..22e4db88272f3 100644
> --- a/tools/perf/pmu-events/Build
> +++ b/tools/perf/pmu-events/Build

[ ... ]

> @@ -87,103 +99,95 @@ GEN_METRIC_DEPS := pmu-events/metric.py pmu-events/common_metrics.py
>  # Functions to extract the model from an extra-metrics.json or extra-metricgroups.json path.
>  model_name = $(notdir $(patsubst %/,%,$(dir $(1))))
>  vendor_name = $(notdir $(patsubst %/,%,$(dir $(patsubst %/,%,$(dir $(1))))))
> +JEVENTS_AWK := $(or $(AWK),awk)
>  
>  ifeq ($(JEVENTS_ARCH),$(filter $(JEVENTS_ARCH),x86 all))
> +X86_MODELS := $(shell $(JEVENTS_AWK) -F, 'NR > 1 && $$0 !~ /^#/ && NF >= 3 { print $$3 }' $(SRC_DIR)/x86/mapfile.csv | sort -u)

[ ... ]

>  ifeq ($(JEVENTS_ARCH),$(filter $(JEVENTS_ARCH),arm64 all))
>  # Generate ARM Json
> -ARMS := $(shell ls -d pmu-events/arch/arm64/arm/*|grep -v cmn)
> -ARM_METRICS = $(foreach x,$(ARMS),$(OUTPUT)$(x)/extra-metrics.json)
> -ARM_METRICGROUPS = $(foreach x,$(ARMS),$(OUTPUT)$(x)/extra-metricgroups.json)
> +ARMS := $(shell $(JEVENTS_AWK) -F, 'NR > 1 && $$0 !~ /^#/ && NF >= 3 && $$3 ~ /^arm\// { print $$3 }' $(SRC_DIR)/arm64/mapfile.csv | sort -u)

[Severity: Medium]
Can the unescaped # inside $(shell ...) in X86_MODELS and ARMS break
builds on GNU Make 4.0 to 4.2?

Before GNU Make 4.3, an unescaped # inside a function call starts a
Makefile comment, truncating the line and aborting with an unterminated
$(shell ...) error.  Documentation/process/changes.rst lists GNU Make 4.0
as the minimum supported version.

tools/build/Build.include already defines pound := \#, so /^$(pound)/
works across both GNU Make 4.0-4.2 and 4.3+.

[ ... ]

> +$(JEVENTS_GEN_MANIFEST): FORCE | $(PMU_EVENTS_OUT_DIR)
> +	$(if $(findstring n,$(firstword -$(MAKEFLAGS))),,$(file > $@.tmp,$(subst $(space),$(_jevents_nl),$(strip $(GEN_JSON_REL)))))@if cmp -s $@.tmp $@ 2>/dev/null; then \
> +		rm -f $@.tmp; \
> +	else \
> +		mv -f $@.tmp $@; \
> +	fi
>  
> -endif # ifneq ($(OUTPUT),)
> +$(JEVENTS_SRC_MANIFEST): FORCE | $(PMU_EVENTS_OUT_DIR)
> +	$(if $(findstring n,$(firstword -$(MAKEFLAGS))),,$(file > $@.tmp,$(subst $(space),$(_jevents_nl),$(strip $(sort $(SRC_JSON))))))@if cmp -s $@.tmp $@ 2>/dev/null; then \
> +		rm -f $@.tmp; \
> +	else \
> +		mv -f $@.tmp $@; \
> +	fi
> +
> +$(JEVENTS_EMPTY_SRC_MANIFEST): FORCE | $(PMU_EVENTS_OUT_DIR)
> +	$(if $(findstring n,$(firstword -$(MAKEFLAGS))),,$(file > $@.tmp,$(subst $(space),$(_jevents_nl),$(strip $(sort $(SRC_COMMON_TEST))))))@if cmp -s $@.tmp $@ 2>/dev/null; then \
> +		rm -f $@.tmp; \
> +	else \
> +		mv -f $@.tmp $@; \
> +	fi

[Severity: Low]
Should these manifest rules also guard $(file > $@.tmp,...) against make
-q and -t?

Because the targets depend on FORCE, GNU Make expands their recipes under
make -q and make -t without running $(PMU_EVENTS_OUT_DIR) or the shell
cmp/rm/mv cleanup.  On a fresh out-of-tree build that fails to open
$@.tmp, and otherwise leaves jevents-*-files.tmp behind.

In addition, pmu-events-clean in tools/perf/Makefile.perf does not remove
leftover jevents-*-files.tmp files from make -q/-t or interrupted builds.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261206021147.3036701-1-irogers@google.com?part=3

  reply	other threads:[~2026-12-06  2:26 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-06  2:11 [PATCH 0/8] perf build: Avoid pmu-events copies and improve build parallelism Ian Rogers
2026-12-06  2:11 ` [PATCH 1/8] perf pmu-events: Ignore backup and non-event JSON files in metric.py Ian Rogers
2026-12-06  2:22   ` sashiko-bot
2026-12-06  2:11 ` [PATCH 2/8] perf jevents: Support --gen-dir/--gen-manifest overlay and ignore backups Ian Rogers
2026-12-06  2:23   ` sashiko-bot
2026-12-06  2:11 ` [PATCH 3/8] perf build: Avoid copying pmu-events JSON files into OUTPUT Ian Rogers
2026-12-06  2:26   ` sashiko-bot [this message]
2026-12-06  2:11 ` [PATCH 4/8] perf pmu-events: Batch metric generation and scope via mapfile.csv Ian Rogers
2026-12-06  2:28   ` sashiko-bot
2026-12-06  2:11 ` [PATCH 5/8] perf build: Batch metric JSON generation in pmu-events/Build Ian Rogers
2026-12-06  2:26   ` sashiko-bot
2026-12-06  2:11 ` [PATCH 6/8] perf build: Run pmu-events tests in parallel with jevents.py Ian Rogers
2026-12-06  2:11 ` [PATCH 7/8] perf build: Depend on lib*-headers instead of archives in prepare Ian Rogers
2026-12-06  2:11 ` [PATCH 8/8] perf tests make: Only run shellcheck, mypy and pylint in pure builds Ian Rogers
2026-12-06  2:22   ` sashiko-bot
2026-12-06  2:28 ` [PATCH 0/8] perf build: Avoid pmu-events copies and improve build parallelism sashiko-bot

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=sashiko-outbox-252063@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=irogers@google.com \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox