* [PATCH] perf build: Only enable context analysis with Clang 23 or later
@ 2026-11-23 16:46 James Clark
2026-11-23 18:44 ` Ian Rogers
0 siblings, 1 reply; 8+ messages in thread
From: James Clark @ 2026-11-23 16:46 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Namhyung Kim, Jiri Olsa, Ian Rogers, Adrian Hunter
Cc: linux-perf-users, linux-kernel, James Clark
Context analysis requires Clang 23 or later (see
Documentation/dev-tools/context-analysis.rst), otherwise the build fails
on older versions, e.g. Clang 18:
util/env.h:142:39: error: use of undeclared identifier 'lock'
142 | struct rb_root infos __guarded_by(&lock);
Only enable it when the Clang version is supported. Leave the other
thread safety options enabled if they exist because they don't cause
build failures at the moment, and might provide benefits even without
-DWARN_CONTEXT_ANALYSIS.
Fixes: 321967859933 ("perf build: Enable context analysis and Clang thread-safety flags")
Signed-off-by: James Clark <james.clark@linaro.org>
---
Assisted by Claude Opus 5.5
---
tools/perf/Makefile.config | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
index aed2e952c8f3..f5adceee5589 100644
--- a/tools/perf/Makefile.config
+++ b/tools/perf/Makefile.config
@@ -65,11 +65,15 @@ ifeq ($(CC_NO_CLANG), 0)
CXX := $(CXX) $(CLANG_FLAGS) -fintegrated-as
endif
- # Enable context analysis (linux/compiler-context-analysis.h gates its Clang
- # attributes behind WARN_CONTEXT_ANALYSIS) and Clang thread-safety checks.
- CFLAGS += -DWARN_CONTEXT_ANALYSIS -Wthread-safety
+ CFLAGS += -Wthread-safety
CFLAGS += $(call cc-option,-Wthread-safety-pointer -Wthread-safety-beta)
- CFLAGS += $(call cc-option,-fexperimental-late-parse-attributes)
+
+ # Enable context analysis (linux/compiler-context-analysis.h gates its Clang
+ # attributes behind WARN_CONTEXT_ANALYSIS). Requires Clang 23 or later.
+ CLANG_MAJOR := $(shell echo __clang_major__ | $(CC) -E -P -x c - 2>/dev/null)
+ ifeq ($(shell test "$(CLANG_MAJOR)" -ge 23 2>/dev/null && echo y),y)
+ CFLAGS += -DWARN_CONTEXT_ANALYSIS -fexperimental-late-parse-attributes
+ endif
endif
include $(srctree)/tools/scripts/Makefile.arch
---
base-commit: eb79d2fbc230d41b009e49f20671303c6efbd946
change-id: 20261123-james-perf-late-parse-attr-4e996381859f
Best regards,
--
James Clark <james.clark@linaro.org>
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH] perf build: Only enable context analysis with Clang 23 or later 2026-11-23 16:46 [PATCH] perf build: Only enable context analysis with Clang 23 or later James Clark @ 2026-11-23 18:44 ` Ian Rogers 2026-11-23 19:55 ` Arnaldo Melo 0 siblings, 1 reply; 8+ messages in thread From: Ian Rogers @ 2026-11-23 18:44 UTC (permalink / raw) To: James Clark Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo, Namhyung Kim, Jiri Olsa, Adrian Hunter, linux-perf-users, linux-kernel On Mon, Nov 23, 2026 at 8:46 AM James Clark <james.clark@linaro.org> wrote: > > Context analysis requires Clang 23 or later (see > Documentation/dev-tools/context-analysis.rst), otherwise the build fails > on older versions, e.g. Clang 18: > > util/env.h:142:39: error: use of undeclared identifier 'lock' > 142 | struct rb_root infos __guarded_by(&lock); > > Only enable it when the Clang version is supported. Leave the other > thread safety options enabled if they exist because they don't cause > build failures at the moment, and might provide benefits even without > -DWARN_CONTEXT_ANALYSIS. So we've had -Wthread-safety for a long time in the perf tree, I'm guessing __guarded_by is missing on older clang versions. Can we just stub out the __guarded_by for these old clang versions and keep the lock checking? Thanks, Ian > Fixes: 321967859933 ("perf build: Enable context analysis and Clang thread-safety flags") > Signed-off-by: James Clark <james.clark@linaro.org> > --- > Assisted by Claude Opus 5.5 > --- > tools/perf/Makefile.config | 12 ++++++++---- > 1 file changed, 8 insertions(+), 4 deletions(-) > > diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config > index aed2e952c8f3..f5adceee5589 100644 > --- a/tools/perf/Makefile.config > +++ b/tools/perf/Makefile.config > @@ -65,11 +65,15 @@ ifeq ($(CC_NO_CLANG), 0) > CXX := $(CXX) $(CLANG_FLAGS) -fintegrated-as > endif > > - # Enable context analysis (linux/compiler-context-analysis.h gates its Clang > - # attributes behind WARN_CONTEXT_ANALYSIS) and Clang thread-safety checks. > - CFLAGS += -DWARN_CONTEXT_ANALYSIS -Wthread-safety > + CFLAGS += -Wthread-safety > CFLAGS += $(call cc-option,-Wthread-safety-pointer -Wthread-safety-beta) > - CFLAGS += $(call cc-option,-fexperimental-late-parse-attributes) > + > + # Enable context analysis (linux/compiler-context-analysis.h gates its Clang > + # attributes behind WARN_CONTEXT_ANALYSIS). Requires Clang 23 or later. > + CLANG_MAJOR := $(shell echo __clang_major__ | $(CC) -E -P -x c - 2>/dev/null) > + ifeq ($(shell test "$(CLANG_MAJOR)" -ge 23 2>/dev/null && echo y),y) > + CFLAGS += -DWARN_CONTEXT_ANALYSIS -fexperimental-late-parse-attributes > + endif > endif > > include $(srctree)/tools/scripts/Makefile.arch > > --- > base-commit: eb79d2fbc230d41b009e49f20671303c6efbd946 > change-id: 20261123-james-perf-late-parse-attr-4e996381859f > > Best regards, > -- > James Clark <james.clark@linaro.org> > ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] perf build: Only enable context analysis with Clang 23 or later 2026-11-23 18:44 ` Ian Rogers @ 2026-11-23 19:55 ` Arnaldo Melo 2026-11-23 21:23 ` Namhyung Kim 0 siblings, 1 reply; 8+ messages in thread From: Arnaldo Melo @ 2026-11-23 19:55 UTC (permalink / raw) To: linux-perf-users, Ian Rogers, James Clark Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo, Namhyung Kim, Jiri Olsa, Adrian Hunter, linux-kernel On November 23, 2026 3:44:12 PM GMT-03:00, Ian Rogers <irogers@google.com> wrote: >On Mon, Nov 23, 2026 at 8:46 AM James Clark <james.clark@linaro.org> wrote: >> >> Context analysis requires Clang 23 or later (see >> Documentation/dev-tools/context-analysis.rst), otherwise the build fails >> on older versions, e.g. Clang 18: >> >> util/env.h:142:39: error: use of undeclared identifier 'lock' >> 142 | struct rb_root infos __guarded_by(&lock); >> >> Only enable it when the Clang version is supported. Leave the other >> thread safety options enabled if they exist because they don't cause >> build failures at the moment, and might provide benefits even without >> -DWARN_CONTEXT_ANALYSIS. > >So we've had -Wthread-safety for a long time in the perf tree, I'm >guessing __guarded_by is missing on older clang versions. Can we just >stub out the __guarded_by for these old clang versions and keep the >lock checking? Looks way more reasonable, and no need for a feature test since we know the compiler version when __guarded_by was introduced, right? Regards, - Arnaldo > >Thanks, >Ian > >> Fixes: 321967859933 ("perf build: Enable context analysis and Clang thread-safety flags") >> Signed-off-by: James Clark <james.clark@linaro.org> >> --- >> Assisted by Claude Opus 5.5 >> --- >> tools/perf/Makefile.config | 12 ++++++++---- >> 1 file changed, 8 insertions(+), 4 deletions(-) >> >> diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config >> index aed2e952c8f3..f5adceee5589 100644 >> --- a/tools/perf/Makefile.config >> +++ b/tools/perf/Makefile.config >> @@ -65,11 +65,15 @@ ifeq ($(CC_NO_CLANG), 0) >> CXX := $(CXX) $(CLANG_FLAGS) -fintegrated-as >> endif >> >> - # Enable context analysis (linux/compiler-context-analysis.h gates its Clang >> - # attributes behind WARN_CONTEXT_ANALYSIS) and Clang thread-safety checks. >> - CFLAGS += -DWARN_CONTEXT_ANALYSIS -Wthread-safety >> + CFLAGS += -Wthread-safety >> CFLAGS += $(call cc-option,-Wthread-safety-pointer -Wthread-safety-beta) >> - CFLAGS += $(call cc-option,-fexperimental-late-parse-attributes) >> + >> + # Enable context analysis (linux/compiler-context-analysis.h gates its Clang >> + # attributes behind WARN_CONTEXT_ANALYSIS). Requires Clang 23 or later. >> + CLANG_MAJOR := $(shell echo __clang_major__ | $(CC) -E -P -x c - 2>/dev/null) >> + ifeq ($(shell test "$(CLANG_MAJOR)" -ge 23 2>/dev/null && echo y),y) >> + CFLAGS += -DWARN_CONTEXT_ANALYSIS -fexperimental-late-parse-attributes >> + endif >> endif >> >> include $(srctree)/tools/scripts/Makefile.arch >> >> --- >> base-commit: eb79d2fbc230d41b009e49f20671303c6efbd946 >> change-id: 20261123-james-perf-late-parse-attr-4e996381859f >> >> Best regards, >> -- >> James Clark <james.clark@linaro.org> >> > - Arnaldo ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] perf build: Only enable context analysis with Clang 23 or later 2026-11-23 19:55 ` Arnaldo Melo @ 2026-11-23 21:23 ` Namhyung Kim 2026-11-24 11:24 ` James Clark 0 siblings, 1 reply; 8+ messages in thread From: Namhyung Kim @ 2026-11-23 21:23 UTC (permalink / raw) To: Arnaldo Melo Cc: linux-perf-users, Ian Rogers, James Clark, Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo, Jiri Olsa, Adrian Hunter, linux-kernel Hello, On Mon, Nov 23, 2026 at 04:55:16PM -0300, Arnaldo Melo wrote: > > > On November 23, 2026 3:44:12 PM GMT-03:00, Ian Rogers <irogers@google.com> wrote: > >On Mon, Nov 23, 2026 at 8:46 AM James Clark <james.clark@linaro.org> wrote: > >> > >> Context analysis requires Clang 23 or later (see > >> Documentation/dev-tools/context-analysis.rst), otherwise the build fails > >> on older versions, e.g. Clang 18: > >> > >> util/env.h:142:39: error: use of undeclared identifier 'lock' > >> 142 | struct rb_root infos __guarded_by(&lock); > >> > >> Only enable it when the Clang version is supported. Leave the other > >> thread safety options enabled if they exist because they don't cause > >> build failures at the moment, and might provide benefits even without > >> -DWARN_CONTEXT_ANALYSIS. > > > >So we've had -Wthread-safety for a long time in the perf tree, I'm > >guessing __guarded_by is missing on older clang versions. Can we just > >stub out the __guarded_by for these old clang versions and keep the > >lock checking? > > Looks way more reasonable, and no need for a feature test since we know > the compiler version when __guarded_by was introduced, right? Sorry for the trouble. I checked with clang 21 and it didn't have a problem. Thanks, Namhyung ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] perf build: Only enable context analysis with Clang 23 or later 2026-11-23 21:23 ` Namhyung Kim @ 2026-11-24 11:24 ` James Clark 2026-11-24 13:08 ` Arnaldo Melo 0 siblings, 1 reply; 8+ messages in thread From: James Clark @ 2026-11-24 11:24 UTC (permalink / raw) To: Namhyung Kim, Arnaldo Melo, Ian Rogers Cc: linux-perf-users, Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo, Jiri Olsa, Adrian Hunter, linux-kernel On 23/11/2026 21:23, Namhyung Kim wrote: > Hello, > > On Mon, Nov 23, 2026 at 04:55:16PM -0300, Arnaldo Melo wrote: >> >> >> On November 23, 2026 3:44:12 PM GMT-03:00, Ian Rogers <irogers@google.com> wrote: >>> On Mon, Nov 23, 2026 at 8:46 AM James Clark <james.clark@linaro.org> wrote: >>>> >>>> Context analysis requires Clang 23 or later (see >>>> Documentation/dev-tools/context-analysis.rst), otherwise the build fails >>>> on older versions, e.g. Clang 18: >>>> >>>> util/env.h:142:39: error: use of undeclared identifier 'lock' >>>> 142 | struct rb_root infos __guarded_by(&lock); >>>> >>>> Only enable it when the Clang version is supported. Leave the other >>>> thread safety options enabled if they exist because they don't cause >>>> build failures at the moment, and might provide benefits even without >>>> -DWARN_CONTEXT_ANALYSIS. >>> >>> So we've had -Wthread-safety for a long time in the perf tree, I'm >>> guessing __guarded_by is missing on older clang versions. Can we just >>> stub out the __guarded_by for these old clang versions and keep the >>> lock checking? >> >> Looks way more reasonable, and no need for a feature test since we know >> the compiler version when __guarded_by was introduced, right? > > Sorry for the trouble. I checked with clang 21 and it didn't have a > problem. > > Thanks, > Namhyung > Looks like __guarded_by() has also been around since at least clang 18, so that wasn't the issue. The problem is that it's not supported on struct _members_ specifically until clang 19. I sent another version that stubs it out for < 19 which works. The commit summary changed to "perf build: Stub out __guarded_by() on older Clang versions". The header diverges from the kernel one which isn't great, but I suppose that's better than someone on clang 17 or 18 missing out on all of the lock analysis. ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] perf build: Only enable context analysis with Clang 23 or later 2026-11-24 11:24 ` James Clark @ 2026-11-24 13:08 ` Arnaldo Melo 2026-11-24 13:43 ` James Clark 0 siblings, 1 reply; 8+ messages in thread From: Arnaldo Melo @ 2026-11-24 13:08 UTC (permalink / raw) To: James Clark, Namhyung Kim, Ian Rogers Cc: linux-perf-users, Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo, Jiri Olsa, Adrian Hunter, linux-kernel On November 24, 2026 8:24:37 AM GMT-03:00, James Clark <james.clark@linaro.org> wrote: >Looks like __guarded_by() has also been around since at least clang 18, so that wasn't the issue. The problem is that it's not supported on struct _members_ specifically until clang 19. >I sent another version that stubs it out for < 19 which works. The commit summary changed to "perf build: Stub out __guarded_by() on older Clang versions". >The header diverges from the kernel one which isn't great, but I suppose that's better Right, but you changed how check-headers.sh treats it to cope with the difference and I'll make sure that tools/perf/scripts/sync-headers.sh handles this case as well, namely if check-headers.sh detects drift, sync-headers.sh will update the tools copy while keeping the tools specific parts. acme@number:~/git/perf-tools-next$ make -C tools/perf help | grep headers check-headers - check which header copies are out of sync with the kernel sync-headers - sync those header copies with the kernel, creating commits acme@number:~/git/perf-tools-next$ tools/perf/scripts/sync-headers.sh --helpUsage: sync-headers.sh [OPTIONS] Sync tools/ header copies with the kernel sources and create commits. Options: -n, --dry-run Show what would be done without making changes -N, --no-build Skip the perf build verification step -C, --no-commit Copy files but do not create git commits -f, --filter PAT Only process headers matching PAT (substring match against the kernel-side path) -F, --force Sync also when both copies have content the other lacks, after manual investigation; tools/ additions dropped are recorded in the commit -o, --output DIR Build output directory (default: /tmp/build/perf-tools-1000) -v, --verbose Show more details -h, --help Show this help Environment: SIGN_OFF_NAME Override git user.name for Signed-off-by SIGN_OFF_EMAIL Override git user.email for Signed-off-by OUTPUT_DIR Build output directory Through make: SYNC_HEADERS_ARGS Options to pass to this script, e.g.: make -C tools/perf sync-headers SYNC_HEADERS_ARGS='-n' The script: 1. Runs 'make -C tools/perf check-headers' to find stale copies. 2. For each stale header, identifies the kernel commits that changed it, including the merges that brought content of their own. 3. Copies the kernel header into the tools/ tree, skipping it when only the tools/ copy changed (it is ahead) or when it carries intentional edits, and stopping for manual investigation when both sides have content the other lacks. 4. For beauty headers, runs the relevant beauty script(s) before and after, showing new/changed string table entries. 5. Builds perf and the other consumers of the header to verify nothing breaks. 6. Creates a git commit per header (or group) with the standard commit message format. acme@number:~/git/perf-tools-next$ I.e. the limitation in point number three, about intentional edits, needs to be lifted. - Arnaldo > than someone on clang 17 or 18 missing out on all of the lock analysis. Right. - Arnaldo ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] perf build: Only enable context analysis with Clang 23 or later 2026-11-24 13:08 ` Arnaldo Melo @ 2026-11-24 13:43 ` James Clark 2026-11-24 19:00 ` Arnaldo Carvalho de Melo 0 siblings, 1 reply; 8+ messages in thread From: James Clark @ 2026-11-24 13:43 UTC (permalink / raw) To: Arnaldo Melo Cc: linux-perf-users, Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo, Jiri Olsa, Adrian Hunter, linux-kernel, Namhyung Kim, Ian Rogers On 24/11/2026 13:08, Arnaldo Melo wrote: > > > On November 24, 2026 8:24:37 AM GMT-03:00, James Clark <james.clark@linaro.org> wrote: > >> Looks like __guarded_by() has also been around since at least clang 18, so that wasn't the issue. The problem is that it's not supported on struct _members_ specifically until clang 19. > >> I sent another version that stubs it out for < 19 which works. The commit summary changed to "perf build: Stub out __guarded_by() on older Clang versions". > >> The header diverges from the kernel one which isn't great, but I suppose that's better > > Right, but you changed how check-headers.sh treats it to cope with the difference and I'll make sure that tools/perf/scripts/sync-headers.sh handles this case as well, namely if check-headers.sh detects drift, sync-headers.sh will update the tools copy while keeping the tools specific parts. > > acme@number:~/git/perf-tools-next$ make -C tools/perf help | grep headers > check-headers - check which header copies are out of sync with the kernel > sync-headers - sync those header copies with the kernel, creating commits > acme@number:~/git/perf-tools-next$ tools/perf/scripts/sync-headers.sh --helpUsage: sync-headers.sh [OPTIONS] > > Sync tools/ header copies with the kernel sources and create commits. > > Options: > -n, --dry-run Show what would be done without making changes > -N, --no-build Skip the perf build verification step > -C, --no-commit Copy files but do not create git commits > -f, --filter PAT Only process headers matching PAT (substring match > against the kernel-side path) > -F, --force Sync also when both copies have content the other > lacks, after manual investigation; tools/ additions > dropped are recorded in the commit > -o, --output DIR Build output directory (default: /tmp/build/perf-tools-1000) > -v, --verbose Show more details > -h, --help Show this help > > Environment: > SIGN_OFF_NAME Override git user.name for Signed-off-by > SIGN_OFF_EMAIL Override git user.email for Signed-off-by > OUTPUT_DIR Build output directory > > Through make: > SYNC_HEADERS_ARGS Options to pass to this script, e.g.: > make -C tools/perf sync-headers SYNC_HEADERS_ARGS='-n' > > The script: > 1. Runs 'make -C tools/perf check-headers' to find stale copies. > 2. For each stale header, identifies the kernel commits that changed it, > including the merges that brought content of their own. > 3. Copies the kernel header into the tools/ tree, skipping it when only > the tools/ copy changed (it is ahead) or when it carries intentional > edits, and stopping for manual investigation when both sides have > content the other lacks. > 4. For beauty headers, runs the relevant beauty script(s) before and > after, showing new/changed string table entries. > 5. Builds perf and the other consumers of the header to verify nothing > breaks. > 6. Creates a git commit per header (or group) with the standard commit > message format. > > acme@number:~/git/perf-tools-next$ > > I.e. the limitation in point number three, about intentional edits, needs to be lifted. > > - Arnaldo Oh nice I hadn't noticed sync-headers.sh. What's the plan to support tools side edits? Something like exporting the kernel change as a patch and trying to apply it on top of the tools copy? Or I suppose you could do it the other way around and try to apply the tools diff on top of a new clean kernel copy. > >> than someone on clang 17 or 18 missing out on all of the lock analysis. > > Right. > > - Arnaldo ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] perf build: Only enable context analysis with Clang 23 or later 2026-11-24 13:43 ` James Clark @ 2026-11-24 19:00 ` Arnaldo Carvalho de Melo 0 siblings, 0 replies; 8+ messages in thread From: Arnaldo Carvalho de Melo @ 2026-11-24 19:00 UTC (permalink / raw) To: James Clark Cc: Arnaldo Melo, linux-perf-users, Peter Zijlstra, Ingo Molnar, Jiri Olsa, Adrian Hunter, linux-kernel, Namhyung Kim, Ian Rogers On Tue, Nov 24, 2026 at 01:43:59PM +0000, James Clark wrote: > On 24/11/2026 13:08, Arnaldo Melo wrote: > > On November 24, 2026 8:24:37 AM GMT-03:00, James Clark <james.clark@linaro.org> wrote: > > > Looks like __guarded_by() has also been around since at least clang 18, so that wasn't the issue. The problem is that it's not supported on struct _members_ specifically until clang 19. > > > I sent another version that stubs it out for < 19 which works. The commit summary changed to "perf build: Stub out __guarded_by() on older Clang versions". > > > The header diverges from the kernel one which isn't great, but I suppose that's better > > Right, but you changed how check-headers.sh treats it to cope with the difference and I'll make sure that tools/perf/scripts/sync-headers.sh handles this case as well, namely if check-headers.sh detects drift, sync-headers.sh will update the tools copy while keeping the tools specific parts. > > > > acme@number:~/git/perf-tools-next$ make -C tools/perf help | grep headers > > check-headers - check which header copies are out of sync with the kernel > > sync-headers - sync those header copies with the kernel, creating commits > > acme@number:~/git/perf-tools-next$ tools/perf/scripts/sync-headers.sh --helpUsage: sync-headers.sh [OPTIONS] > > > > Sync tools/ header copies with the kernel sources and create commits. > > > > Options: > > -n, --dry-run Show what would be done without making changes > > -N, --no-build Skip the perf build verification step > > -C, --no-commit Copy files but do not create git commits > > -f, --filter PAT Only process headers matching PAT (substring match > > against the kernel-side path) > > -F, --force Sync also when both copies have content the other > > lacks, after manual investigation; tools/ additions > > dropped are recorded in the commit > > -o, --output DIR Build output directory (default: /tmp/build/perf-tools-1000) > > -v, --verbose Show more details > > -h, --help Show this help > > > > Environment: > > SIGN_OFF_NAME Override git user.name for Signed-off-by > > SIGN_OFF_EMAIL Override git user.email for Signed-off-by > > OUTPUT_DIR Build output directory > > > > Through make: > > SYNC_HEADERS_ARGS Options to pass to this script, e.g.: > > make -C tools/perf sync-headers SYNC_HEADERS_ARGS='-n' > > > > The script: > > 1. Runs 'make -C tools/perf check-headers' to find stale copies. > > 2. For each stale header, identifies the kernel commits that changed it, > > including the merges that brought content of their own. > > 3. Copies the kernel header into the tools/ tree, skipping it when only > > the tools/ copy changed (it is ahead) or when it carries intentional > > edits, and stopping for manual investigation when both sides have > > content the other lacks. > > 4. For beauty headers, runs the relevant beauty script(s) before and > > after, showing new/changed string table entries. > > 5. Builds perf and the other consumers of the header to verify nothing > > breaks. > > 6. Creates a git commit per header (or group) with the standard commit > > message format. > > acme@number:~/git/perf-tools-next$ > > I.e. the limitation in point number three, about intentional edits, needs to be lifted. > Oh nice I hadn't noticed sync-headers.sh. What's the plan to support tools > side edits? Something like exporting the kernel change as a patch and trying > to apply it on top of the tools copy? Or I suppose you could do it the other > way around and try to apply the tools diff on top of a new clean kernel > copy. I think the script should diff the current state, save that, copy the new header, apply the patch to get the perf tools changes, then ask opencode (or the coding agent used most frequently by the developer) to check if what was done is sensible, then ask the developer to do a last check and amends, sign off and commit. Just like the following one, that I used to send the first fixes pull req for this merge window to Linus, he accepted it straight away, so brownie points to it (or to me + opencode + DeepSeek V4 (or was it Qween Flash free? or... unsure :-))): acme@number:~/git/perf-tools-next$ cat ../perf-dev-scripts/perf-upstream-tag.sh #!/bin/bash # SPDX-License-Identifier: GPL-2.0 # # Prepare a signed tag for a pull request to Linus from the perf # tools tree. # # The merge window is derived from the latest tag in Linus' tree: # # - vN.M-rcK: the release in progress is vN.M, # - vN.M: no -rc1 for the next window was out yet, so the merge # window is vN.(M+1). # # If no perf-tools-for-vN.M tag exists yet for the current merge # window, this is the merge window pull request and the tag will be # perf-tools-for-vN.M-<seq>-<date>; otherwise it is a fixes pull # request and the tag will be perf-tools-fixes-for-vN.M-<seq>-<date>, # where vN.M is the release Linus is building. # # In two steps, the way git does commit messages: # # 1. Run without --continue. The programmatic parts happen here: # fetch, find the latest Linus tag, decide for vs fixes, compute # the tag name, get the commits not upstream via git cherry. # Their full commit texts then go, with the style rules and the # latest tag message as an example, to a coding agent (opencode # or claude, whichever is available and not disabled) to produce # the succinct grouped summary; without an agent it falls back # to one bullet per commit subject. The message is written to # $GIT_DIR/UPSTREAM_TAG_EDITMSG, like git's COMMIT_EDITMSG and # TAG_EDITMSG, for the maintainer to review and amend. # 2. After editing, run with --continue: it checks that the branch # tip didn't move, that a GPG secret key is available, picks the # key used in the latest signed tag made by this maintainer # (overridable with -k), and creates the signed tag. # # Usage: perf-upstream-tag.sh [options] # # Options: # -r, --torvalds-remote R Remote for Linus' tree (default: torvalds) # -b, --branch REF Branch to be pulled (default: perf-tools) # -u, --push-remote R Remote with the public tree, for the # push/request-pull hints (default: acme, # falling back to origin) # -k, --key KEYID GPG key for signing (default: the key # used in the latest signed tag made by # the current maintainer) # --agent NAME Coding agent for the summary: opencode, # claude or none (default: auto-detect) # --continue Create the signed tag from the message # written by a previous run # -n, --dry-run Print the plan, write nothing # --no-fetch Do not fetch the Linus remote first # -h, --help This help set -euo pipefail die() { echo "perf-upstream-tag: $*" >&2; exit 1; } torvalds=torvalds branch=perf-tools push_remote= agent=auto key= mode=draft dry_run=0 do_fetch=1 while [ $# -gt 0 ]; do case "$1" in -r|--torvalds-remote) torvalds=$2; shift 2 ;; -b|--branch) branch=$2; shift 2 ;; -u|--push-remote) push_remote=$2; shift 2 ;; -k|--key) key=$2; shift 2 ;; --agent) agent=$2; shift 2 ;; --no-agent) agent=none; shift ;; --continue) mode='continue'; shift ;; -n|--dry-run) dry_run=1; shift ;; --no-fetch) do_fetch=0; shift ;; -h|--help) sed -n '2,/^set /{ /^set /d; /^#!/d; s/^# \{0,1\}// p }' "$0"; exit 0 ;; *) die "unknown option: $1" ;; esac done gitdir=$(git rev-parse --absolute-git-dir) || die "not in a git tree" editmsg="$gitdir/UPSTREAM_TAG_EDITMSG" plan="$gitdir/UPSTREAM_TAG_PLAN" [ -n "$push_remote" ] || push_remote=$(git remote | grep -x acme || echo origin) if [ "$mode" = continue ]; then # Step 2: sign the message the maintainer left in UPSTREAM_TAG_EDITMSG. [ -f "$plan" ] || die "no $plan, run without --continue first" [ -f "$editmsg" ] || die "no $editmsg, nothing to sign" # shellcheck source=/dev/null . "$plan" tip=$(git rev-parse --verify "$BRANCH_REF" 2>/dev/null) || \ die "branch $BRANCH_REF is gone" [ "$tip" = "$SHA" ] || \ die "branch tip moved from $SHA to $tip, rerun without --continue" git rev-parse -q --verify "refs/tags/$TAG" >/dev/null && \ die "tag $TAG already exists" secret=$(gpg --list-secret-keys --with-colons 2>/dev/null | awk -F: '$1 == "sec" { print $5 }') [ -n "$secret" ] || die "no GPG secret key on $(hostname): the message is at $editmsg, the tag name in $plan. Run --continue on the machine holding your key, or pass --key when the key is in another GnuPG home" if [ -z "$key" ]; then # The key this maintainer used in the latest signed tag. email=$(git var GIT_COMMITTER_IDENT | sed -E 's/.*<([^>]*)>.*/\1/') for t in $(git for-each-ref --sort=-creatordate --format='%(refname:lstrip=2)' \ refs/tags/perf-tools-*); do te=$(git for-each-ref "refs/tags/$t" --format='%(taggeremail)' | tr -d '<>') case "$te" in *$email) ;; *) continue ;; esac line=$(git tag -v "$t" 2>&1 | sed -n 's/.*using [A-Z]* key \([0-9A-F]\{16,\}\).*/\1/p' | head -1 || true) if [ -n "$line" ]; then key=$line; break; fi done fi if [ -n "$key" ]; then echo "Signing $TAG with key $key" git tag -s -u "$key" -F "$editmsg" "$TAG" "$SHA" else echo "No previously signed tag by $email, using the default key" git tag -s -F "$editmsg" "$TAG" "$SHA" fi rm -f "$plan" echo echo "Push and send the pull request:" echo # shellcheck disable=SC2153 # PUSH_REMOTE comes from the sourced plan echo " git push $PUSH_REMOTE $BRANCH_REF refs/tags/$TAG" echo " git request-pull $LATEST_TAG <public tree url> $TAG" exit 0 fi # Step 1: figure out what the pull request is and draft its message. refname= for r in "refs/heads/$branch" "refs/remotes/$branch"; do if git rev-parse -q --verify "$r" >/dev/null; then refname=$r; break; fi done [ -n "$refname" ] || die "branch '$branch' not found" sha=$(git rev-parse --verify "$refname") if [ "$do_fetch" = 1 ]; then git fetch --quiet --tags "$torvalds" || die "cannot fetch from '$torvalds', use --no-fetch" fi latest=$(git for-each-ref --sort=-creatordate --format='%(refname:lstrip=2)' "refs/tags/v*" | grep -E '^v[0-9]+\.[0-9]+(-rc[0-9]+)?$' | head -1 || true) [ -n "$latest" ] || die "no vN.M(-rcK) tag found in the local tag list" if [ "$latest" = "${latest%-rc*}" ]; then version=${latest#v} dev_version=$version window="$(( ${version%%.*} )).$(( ${version##*.} + 1 ))" rc= else dev_version=${latest#v}; dev_version=${dev_version%-rc*} window=$dev_version rc=${latest##*-} fi upstream_ref=$(git for-each-ref --format='%(refname)' "refs/remotes/$torvalds/master") [ -n "$upstream_ref" ] || die "no refs/remotes/$torvalds/master" if [ -n "$(git for-each-ref --format='%(refname:lstrip=2)' "refs/tags/perf-tools-for-v${window}*")" ]; then kind=fixes else kind=merge-window fi if [ "$kind" = fixes ]; then target=$dev_version pattern="perf-tools-fixes-for-v${target}" title="perf tools fixes for v${target}" else target=$window pattern="perf-tools-for-v${window}" title="perf tools changes for v${window}" fi n=$(git for-each-ref --format='%(refname:lstrip=2)' "refs/tags/${pattern}*" | grep -c . || true) seq=$((n + 1)) date=$(date +%F) tag="${pattern}-${seq}-${date}" git rev-parse -q --verify "refs/tags/$tag" >/dev/null && die "tag $tag already exists" # Commits not upstream: cherry by patch-id, so commits already merged # upstream by another route are skipped. mapfile -t shas < <(git cherry -v "$upstream_ref" "$sha" | grep '^+' | cut -d' ' -f2 | tac) count=${#shas[@]} [ "$count" -gt 0 ] || die "$branch has nothing beyond $upstream_ref" committer=$(git var GIT_COMMITTER_IDENT | sed -E 's/(<[^>]*>).*/\1/') if [ "$dry_run" = 1 ]; then echo "dry run: tag $tag, $count commit(s), message not written" exit 0 fi printf 'TAG=%q\nSHA=%q\nBRANCH_REF=%q\nLATEST_TAG=%q\nPUSH_REMOTE=%q\n' \ "$tag" "$sha" "$refname" "$latest" "$push_remote" > "$plan" # The last tag message of the same kind, minus the signature, is the # style example handed to the agent. example_sha=$(git for-each-ref --sort=-creatordate --format='%(objectname)' \ "refs/tags/${pattern}-*" | head -1 || true) if [ -z "$example_sha" ]; then example_sha=$(git for-each-ref --sort=-creatordate --format='%(objectname)' \ 'refs/tags/perf-tools-for-v*' | head -1 || true) fi if [ -n "$example_sha" ]; then example=$(git cat-file tag "$example_sha" 2>/dev/null | sed -n '/^$/,$p' | sed '1d;/-----BEGIN PGP/,$d') else example='' fi commits=$(git show -s --format='%s%n%n%b' "${shas[@]}") agent_cmd= case "$agent" in auto) for a in opencode claude; do if command -v "$a" >/dev/null 2>&1; then agent_cmd=$a; break; fi done ;; none) ;; *) if command -v "$agent" >/dev/null 2>&1; then agent_cmd=$agent; else die "agent '$agent' not found"; fi ;; esac body= if [ -n "$agent_cmd" ]; then # Quoted heredoc for the fixed text: commit messages contain $ and # backticks that must never be expanded. prompt=$( cat <<'RULES' You are summarizing Linux perf commits for a maintainer's signed pull request tag message. Output ONLY the bullet block: no title line, no Signed-off-by, no fences, no preamble. Rules: - Bullet items start with "- ", continuation lines are indented two spaces, text wraps near 74 columns. - AT MOST two lines per bullet, shorter than the example: name the area or subcommand, say what the change does, and stop. No function names, no ioctl numbers, no error strings, no lists of affected machines or file paths beyond a few header names. - One item per group, never one per commit: fold the header sync commits into a single item naming the headers; group the rest by area (symbol resolution, build, tests) or by subcommand (record, report, trace, top, kvm, jitdump, jevents, ...). New features first, then fixes, then cleanups. - Succinct commentary on what the changes do, written from the full commit texts, not just the subjects. No diffstats, no review history, no walls of text. Example, the latest tag message of this kind in this tree: RULES printf '%s\n' "${example:-none available}" printf '\nCommits to summarize (%d commits):\n\n' "$count" printf '%s\n' "$commits" ) if body=$(printf '%s' "$prompt" | timeout 600 "$agent_cmd" run 2>/dev/null || \ printf '%s' "$prompt" | timeout 600 "$agent_cmd" -p 2>/dev/null) && \ [ -n "$body" ]; then echo "Summary drafted by: $agent_cmd" else body= echo "agent '$agent_cmd' failed, falling back to subject bullets" >&2 fi fi if [ -z "$body" ]; then body=$(printf '%s\n' "${shas[@]}" | xargs -rn1 git show -s --format='- %s') fi # The script adds the title and the trailer itself; drop them if the # agent echoed them anyway, plus leading/trailing/double blank lines. body=$(printf '%s\n' "$body" | awk -v title="$title" ' /^Signed-off-by:/ { next } $0 == title { next } NF == 0 { blank = 1; next } { if (seen && blank) print ""; seen = 1; blank = 0; print }') { printf '%s\n\n' "$title" printf '%s\n\n' "$body" printf 'Signed-off-by: %s\n' "$committer" } > "$editmsg" echo "Latest Linus tag: $latest${rc:+ ($rc in the v${dev_version} cycle)}" echo "Merge window: v$window, tag for it: $( [ "$kind" = fixes ] && echo "perf-tools-for-v$window exists" || echo "none yet")" echo "Tag to be created: $tag -> $sha" echo "Not upstream: $count commit(s)" echo echo "Message written to: $editmsg" echo "Review and amend it, then create the signed tag:" echo echo " $0 --continue" acme@number:~/git/perf-tools-next$ My plan is to have this in tools/perf/scripts/ so that whoever comes after me and Namhyung, if this ends up being needed, don't have to go thru such boring processes that were not automated due to lack of time even being in my mind since forever as tech debt :-\ :-) - Arnaldo ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2026-11-24 19:00 UTC | newest] Thread overview: 8+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-11-23 16:46 [PATCH] perf build: Only enable context analysis with Clang 23 or later James Clark 2026-11-23 18:44 ` Ian Rogers 2026-11-23 19:55 ` Arnaldo Melo 2026-11-23 21:23 ` Namhyung Kim 2026-11-24 11:24 ` James Clark 2026-11-24 13:08 ` Arnaldo Melo 2026-11-24 13:43 ` James Clark 2026-11-24 19:00 ` 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