Re: [Patch v2 7/7] perf/x86/intel: Add support for rdpmc user disable feature
From: Peter Zijlstra
Date: Mon Jan 12 2026 - 05:57:45 EST
On Mon, Jan 12, 2026 at 01:16:49PM +0800, Dapeng Mi wrote:
> +static void intel_pmu_update_rdpmc_user_disable(struct perf_event *event)
> +{
> + /*
> + * Counter scope's user-space rdpmc is disabled by default
> + * except two cases.
> + * a. rdpmc = 2 (user space rdpmc enabled unconditionally)
> + * b. rdpmc = 1 and the event is not a system-wide event.
> + * The count of non-system-wide events would be cleared when
> + * context switches, so no count data is leaked.
> + */
> + if (x86_pmu_has_rdpmc_user_disable(event->pmu)) {
> + if (x86_pmu.attr_rdpmc == X86_USER_RDPMC_ALWAYS_ENABLE ||
> + (x86_pmu.attr_rdpmc == X86_USER_RDPMC_CONDITIONAL_ENABLE &&
> + event->ctx->task))
> + event->hw.config &= ~ARCH_PERFMON_EVENTSEL_RDPMC_USER_DISABLE;
> + else
> + event->hw.config |= ARCH_PERFMON_EVENTSEL_RDPMC_USER_DISABLE;
> + }
> +}
Is it not simpler to invert that condition?
if (x86_pmu.attr_rdpmc == X86_USER_RDPMC_ALWAYS_NEVER ||
!event->ctx->task)
event->hw.config |= ARCH_PERFMON_EVENTSEL_RDPMC_USER_DISABLE;
else
event->hw.config &= ~ARCH_PERFMON_EVENTSEL_RDPMC_USER_DISABLE;