Re: [PATCH v1 2/2] perf/x86: Reduce is_hybrid calls and aid ellision of BUG_ON in hybrid_pmu

From: Ian Rogers

Date: Thu Mar 12 2026 - 11:16:08 EST


On Thu, Mar 12, 2026 at 1:40 AM Peter Zijlstra <peterz@xxxxxxxxxxxxx> wrote:
>
> On Wed, Mar 11, 2026 at 10:48:10PM -0700, Ian Rogers wrote:
> > Use the capabilities of the PMU rather than the global variable
> > perf_is_hybrid to determine if a hybrid pmu has been passed to the
> > main accessors. As the pmu capabilities check mirrors that in
> > is_x86_pmu, the BUG_ON(!is_x86_pmu...) in hybrid_pmu can be elided as
> > it is provably always false (with sufficient function inlining, common
> > sub-expression elimination, etc.) in its most common uses.
>
> perf_is_hybrid is not a variable, its a static_branch. You're adding a
> runtime branch here, for no appreciable benefit.
>
> And while (Intel) client seems flooded with this hybrid nonsense,
> servers are still sane. Also AMD have uniform PMU across their regular
> and compact cores and don't need this either.

Agreed, and the AI review (set up similarly to how Dapeng suggested)
also agrees with you:

Additionally, does replacing the is_hybrid() static branch with a dynamic
pointer dereference and bitwise check introduce unnecessary overhead on hot
paths (like NMIs and context switches) for non-hybrid x86 CPUs?

This is missing what the next patch does: it introduces a dominating
branch, meaning the BUG_ON condition is known to be false at compile
time if reasonable compiler optimizations are enabled - possibly
better than a nop, although perhaps the static_branch makes the
initial capabilities check a nop too. Anyway, this series was
primarily meant to catch other inadvertent container_ofs and isn't
something that needs to be in production code. I just couldn't see an
easy way to do the equivalent of "ifndef NDEBUG". Given the comments
on the next patch I suggest we don't adopt the changes, but I'll add
some more feedback in that patch.

Thanks,
Ian