* [PATCH] perf python: Track linked libraries as extension dependencies
@ 2026-10-01 15:48 James Clark
2026-10-01 16:25 ` Ian Rogers
0 siblings, 1 reply; 3+ messages in thread
From: James Clark @ 2026-10-01 15:48 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
Ian Rogers, Adrian Hunter, Leo Yan
Cc: linux-perf-users, linux-kernel, James Clark
Since the Python extension switched to linking perf libraries, setup.py
only lists util/python.c as a source. The libraries are supplied through
LDFLAGS, which setuptools does not consider when deciding whether the
extension needs to be rebuilt.
When a library changes, make invokes setup.py, but setuptools can skip
the build and the recipe copies the stale cached extension back into
python/. This leaves perf and its Python module running different
versions of the same code.
Pass the linked library paths to setup.py and declare them as Extension
dependencies so that library changes trigger a rebuild. Include
EXTRA_PERFLIBS in the shared library list so that both make and
setuptools track those inputs as well, preserving the existing linker
order.
Fixes: 9dabf4003423 ("perf python: Switch module to linking libraries from building source")
Assisted-by: Codex:GPT-6-Astra
Signed-off-by: James Clark <james.clark@linaro.org>
---
tools/perf/Makefile.perf | 5 +++--
tools/perf/util/setup.py | 1 +
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 7ceefc1da774..dbf7cceaa005 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -526,8 +526,8 @@ endif
EXTLIBS := $(call filter-out,$(EXCLUDE_EXTLIBS),$(EXTLIBS))
LIBS = -Wl,--whole-archive $(PERFLIBS) $(EXTRA_PERFLIBS) -Wl,--no-whole-archive -Wl,--start-group $(EXTLIBS) -Wl,--end-group
-PERFLIBS_PY := $(call filter-out,$(LIBPERF_BENCH) $(LIBPERF_TEST),$(PERFLIBS))
-LIBS_PY = -Wl,--whole-archive $(PERFLIBS_PY) $(EXTRA_PERFLIBS) -Wl,--no-whole-archive -Wl,--start-group $(EXTLIBS) -Wl,--end-group
+PERFLIBS_PY := $(call filter-out,$(LIBPERF_BENCH) $(LIBPERF_TEST),$(PERFLIBS)) $(EXTRA_PERFLIBS)
+LIBS_PY = -Wl,--whole-archive $(PERFLIBS_PY) -Wl,--no-whole-archive -Wl,--start-group $(EXTLIBS) -Wl,--end-group
export INSTALL SHELL_PATH
@@ -559,6 +559,7 @@ $(shell [ -d '$(OUTPUT)python' ] || mkdir -p '$(OUTPUT)python')
$(OUTPUT)python/perf$(PYTHON_EXTENSION_SUFFIX): util/python.c util/setup.py python/perf.pyi $(PERFLIBS_PY)
$(QUIET_GEN)LDSHARED="$(CC) -pthread -shared" \
CFLAGS='$(CFLAGS)' LDFLAGS='$(LDFLAGS) $(LIBS_PY)' \
+ PYTHON_EXT_DEPS='$(PERFLIBS_PY)' \
$(PYTHON_WORD) util/setup.py \
$(python_setup_quiet) build_ext; \
cp $(PYTHON_EXTBUILD_LIB)perf*.so $(OUTPUT)python/; \
diff --git a/tools/perf/util/setup.py b/tools/perf/util/setup.py
index 8380980ade4c..3b6a59f66944 100644
--- a/tools/perf/util/setup.py
+++ b/tools/perf/util/setup.py
@@ -173,6 +173,7 @@ def main() -> None:
perf = Extension(
'perf',
sources=[os.path.join(src_perf, 'util/python.c')],
+ depends=shlex.split(os.getenv('PYTHON_EXT_DEPS', '')),
include_dirs=['util/include'],
extra_compile_args=cflags,
)
---
base-commit: 705da5b15ab89ba97b11eedbe507c2fd83d31cb9
change-id: 20261001-james-perf-stale-python-build-d6b17da2f231
Best regards,
--
James Clark <james.clark@linaro.org>
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] perf python: Track linked libraries as extension dependencies
2026-10-01 15:48 [PATCH] perf python: Track linked libraries as extension dependencies James Clark
@ 2026-10-01 16:25 ` Ian Rogers
2026-10-02 16:18 ` Arnaldo Carvalho de Melo
0 siblings, 1 reply; 3+ messages in thread
From: Ian Rogers @ 2026-10-01 16:25 UTC (permalink / raw)
To: James Clark
Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
Adrian Hunter, Leo Yan, linux-perf-users, linux-kernel
On Thu, Oct 1, 2026 at 8:48 AM James Clark <james.clark@linaro.org> wrote:
>
> Since the Python extension switched to linking perf libraries, setup.py
> only lists util/python.c as a source. The libraries are supplied through
> LDFLAGS, which setuptools does not consider when deciding whether the
> extension needs to be rebuilt.
>
> When a library changes, make invokes setup.py, but setuptools can skip
> the build and the recipe copies the stale cached extension back into
> python/. This leaves perf and its Python module running different
> versions of the same code.
>
> Pass the linked library paths to setup.py and declare them as Extension
> dependencies so that library changes trigger a rebuild. Include
> EXTRA_PERFLIBS in the shared library list so that both make and
> setuptools track those inputs as well, preserving the existing linker
> order.
>
> Fixes: 9dabf4003423 ("perf python: Switch module to linking libraries from building source")
> Assisted-by: Codex:GPT-6-Astra
> Signed-off-by: James Clark <james.clark@linaro.org>
Reviewed-by: Ian Rogers <irogers@google.com>
Thanks!
Ian
> ---
> tools/perf/Makefile.perf | 5 +++--
> tools/perf/util/setup.py | 1 +
> 2 files changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
> index 7ceefc1da774..dbf7cceaa005 100644
> --- a/tools/perf/Makefile.perf
> +++ b/tools/perf/Makefile.perf
> @@ -526,8 +526,8 @@ endif
> EXTLIBS := $(call filter-out,$(EXCLUDE_EXTLIBS),$(EXTLIBS))
> LIBS = -Wl,--whole-archive $(PERFLIBS) $(EXTRA_PERFLIBS) -Wl,--no-whole-archive -Wl,--start-group $(EXTLIBS) -Wl,--end-group
>
> -PERFLIBS_PY := $(call filter-out,$(LIBPERF_BENCH) $(LIBPERF_TEST),$(PERFLIBS))
> -LIBS_PY = -Wl,--whole-archive $(PERFLIBS_PY) $(EXTRA_PERFLIBS) -Wl,--no-whole-archive -Wl,--start-group $(EXTLIBS) -Wl,--end-group
> +PERFLIBS_PY := $(call filter-out,$(LIBPERF_BENCH) $(LIBPERF_TEST),$(PERFLIBS)) $(EXTRA_PERFLIBS)
> +LIBS_PY = -Wl,--whole-archive $(PERFLIBS_PY) -Wl,--no-whole-archive -Wl,--start-group $(EXTLIBS) -Wl,--end-group
>
> export INSTALL SHELL_PATH
>
> @@ -559,6 +559,7 @@ $(shell [ -d '$(OUTPUT)python' ] || mkdir -p '$(OUTPUT)python')
> $(OUTPUT)python/perf$(PYTHON_EXTENSION_SUFFIX): util/python.c util/setup.py python/perf.pyi $(PERFLIBS_PY)
> $(QUIET_GEN)LDSHARED="$(CC) -pthread -shared" \
> CFLAGS='$(CFLAGS)' LDFLAGS='$(LDFLAGS) $(LIBS_PY)' \
> + PYTHON_EXT_DEPS='$(PERFLIBS_PY)' \
> $(PYTHON_WORD) util/setup.py \
> $(python_setup_quiet) build_ext; \
> cp $(PYTHON_EXTBUILD_LIB)perf*.so $(OUTPUT)python/; \
> diff --git a/tools/perf/util/setup.py b/tools/perf/util/setup.py
> index 8380980ade4c..3b6a59f66944 100644
> --- a/tools/perf/util/setup.py
> +++ b/tools/perf/util/setup.py
> @@ -173,6 +173,7 @@ def main() -> None:
> perf = Extension(
> 'perf',
> sources=[os.path.join(src_perf, 'util/python.c')],
> + depends=shlex.split(os.getenv('PYTHON_EXT_DEPS', '')),
> include_dirs=['util/include'],
> extra_compile_args=cflags,
> )
>
> ---
> base-commit: 705da5b15ab89ba97b11eedbe507c2fd83d31cb9
> change-id: 20261001-james-perf-stale-python-build-d6b17da2f231
>
> Best regards,
> --
> James Clark <james.clark@linaro.org>
>
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] perf python: Track linked libraries as extension dependencies
2026-10-01 16:25 ` Ian Rogers
@ 2026-10-02 16:18 ` Arnaldo Carvalho de Melo
0 siblings, 0 replies; 3+ messages in thread
From: Arnaldo Carvalho de Melo @ 2026-10-02 16:18 UTC (permalink / raw)
To: Ian Rogers
Cc: James Clark, Peter Zijlstra, Ingo Molnar, Namhyung Kim,
Mark Rutland, Alexander Shishkin, Jiri Olsa, Adrian Hunter,
Leo Yan, linux-perf-users, linux-kernel
On Thu, Oct 01, 2026 at 09:25:02AM -0700, Ian Rogers wrote:
> On Thu, Oct 1, 2026 at 8:48 AM James Clark <james.clark@linaro.org> wrote:
> >
> > Since the Python extension switched to linking perf libraries, setup.py
> > only lists util/python.c as a source. The libraries are supplied through
> > LDFLAGS, which setuptools does not consider when deciding whether the
> > extension needs to be rebuilt.
> >
> > When a library changes, make invokes setup.py, but setuptools can skip
> > the build and the recipe copies the stale cached extension back into
> > python/. This leaves perf and its Python module running different
> > versions of the same code.
> >
> > Pass the linked library paths to setup.py and declare them as Extension
> > dependencies so that library changes trigger a rebuild. Include
> > EXTRA_PERFLIBS in the shared library list so that both make and
> > setuptools track those inputs as well, preserving the existing linker
> > order.
> >
> > Fixes: 9dabf4003423 ("perf python: Switch module to linking libraries from building source")
> > Assisted-by: Codex:GPT-6-Astra
> > Signed-off-by: James Clark <james.clark@linaro.org>
>
> Reviewed-by: Ian Rogers <irogers@google.com>
git am complained, applied manually:
⬢ [acme@tb-x2-perf perf-tools-next]$ patch -p1 < ./20261001_james_clark_perf_python_track_linked_libraries_as_extension_dependencies.mbx
patching file tools/perf/Makefile.perf
Hunk #1 succeeded at 538 (offset 12 lines).
Hunk #2 succeeded at 571 with fuzz 1 (offset 12 lines).
patching file tools/perf/util/setup.py
⬢ [acme@tb-x2-perf perf-tools-next]$
- Arnaldo
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-10-02 16:19 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-01 15:48 [PATCH] perf python: Track linked libraries as extension dependencies James Clark
2026-10-01 16:25 ` Ian Rogers
2026-10-02 16:18 ` Arnaldo Carvalho de Melo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®