Re: [PATCH v13 04/21] perf mutex: Use kernel style compiler-context-analysis.h annotations
From: Ian Rogers
Date: Fri Nov 20 2026 - 19:10:21 EST
On Thu, Nov 19, 2026 at 9:31 PM Namhyung Kim <namhyung@xxxxxxxxxx> wrote:
>
> On Fri, Nov 13, 2026 at 08:41:35AM -0800, Ian Rogers wrote:
> > Enable -DWARN_CONTEXT_ANALYSIS alongside -Wthread-safety for Clang
> > builds in tools/perf/Makefile.config, replace the custom lock safety
> > macros in tools/perf with the kernel's compiler-context-analysis.h
> > annotations (context_lock_struct, __guarded_by, __acquires,
> > __acquires_shared, __releases, __releases_shared, __cond_acquires,
> > __must_hold, __must_hold_shared, __must_not_hold, __returns_ctx_lock,
> > __no_context_analysis, and __context_unsafe), and remove the redundant
> > macro definitions from tools/perf/util/mutex.h.
> >
> > Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
[snip]
> > # Enabled Wthread-safety analysis for clang builds.
> > - CFLAGS += -Wthread-safety
> > + CFLAGS += -Wthread-safety -DWARN_CONTEXT_ANALYSIS
>
> Why is this needed? Also it seem to belong to the next patch.
Thanks for the review! linux/compiler-context-analysis.h gates all of
its Clang thread-safety attributes behind `#if
defined(WARN_CONTEXT_ANALYSIS)` (matching the kernel's
scripts/Makefile.context-analysis); without -DWARN_CONTEXT_ANALYSIS,
the macros expand to no-ops.
It was placed here so -Wthread-safety stayed active across removing
the mutex.h macros, but moving -DWARN_CONTEXT_ANALYSIS to patch 5 so
Makefile.config is only touched in one place is cleaner and still
builds cleanly at every commit. I'll move it to patch 5 with a comment
in v15.
Thanks,
Ian
> Thanks,
> Namhyung