From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dy1-f202.google.com (mail-dy1-f202.google.com [74.125.82.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EF5212F5A34 for ; Thu, 12 Mar 2026 05:48:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773294509; cv=none; b=Zwc2w/RBXwx1ABX+yJ+FgLNvt7uyjH39WMsJS2vMV8HV4ZHZduPIPsF9wWBm5/qotlou0Io9unsAGhreSC2Y8r42ZPctKzciXinFvTapWiSS8Az+xsPkHoESWtMFTjZhTSTNTS0WeabFykpJQLJwtpnKos3msi1nmjfOdYzOHj8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773294509; c=relaxed/simple; bh=RuVytkDFOGxLZv5hZQSKqWBhPyyYvv451s5B3uiFF/A=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=a5PNPwqpizeIJ39TE0YWYamvO7ZHQYNRH3m6MxJAStFMcQESLhpN/ukOyWn85Z3OSTzrpPJdTVwmhS1YtunO9BQPq5He531v240u9klrW/mYmFPeYibRgprKxOnikqR+I8o7KzxIR7A/oGZtQ4IQ+wWk6y8+XDKFpYwDvq78eH8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=NNofy8ND; arc=none smtp.client-ip=74.125.82.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="NNofy8ND" Received: by mail-dy1-f202.google.com with SMTP id 5a478bee46e88-2be191ce356so869357eec.1 for ; Wed, 11 Mar 2026 22:48:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1773294506; x=1773899306; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=kIZKFE8GFE3BbHex+q85LNyPvOPEOZBzXZizsyJDBtk=; b=NNofy8ND/pp7fIj5mDTrIVI24XqJwhDve9fcEIs1NT4JYI6GYt+sfuGb1wzh+uQMj4 d3SIr7e9lJg8kNy6byK2SrI9O+lEVRTydpqxy7d0NxsRedeEIP7D6Hak02HkAWCLIufP cQvt6PtLXHfMVPT+CbFM7+nuljqPNh0JE47G14ElYj/rDgBaGFPgXA2UejsWl69gMxCa aHmnp4CCgFHmGvUukSaFVa/Hc2LTAwsqjAAcDc5G2L6CwDyXwEGMTzIWW3+xL8eMjZD+ 2qVVD/aBr4mayi+3+BootkimllozdJ6xMCGEpGRf+2aA5bXvRhvZu4jNLf1MuyTua5cW c2zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773294506; x=1773899306; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=kIZKFE8GFE3BbHex+q85LNyPvOPEOZBzXZizsyJDBtk=; b=LxJvlNBnI4BnADFrJI4VvHjkZsUpxFUIFC1c0nbDKBI28T83Y47bnnB1roHonq1WPw uDiJAlRrMiEcByt5h0hZMLeQoyzCQ3Cg3m7at/bizP4A3oL7sEhRNQOnWPO4jZ7GheHA bQIQf87fLldGUyaZz8Y3becNbrawCUm8RPbB+gdxoyDQvbOgfV9HaPJ7YcYbIh0pD3y4 Fb4y+WJv8N1VUC4mw+NtGP7yd9lEIdfPn2uQQb/XpK51MX7Nbqe18HoegarhCPhpblQZ m3AnYfc161I5m7Kr8jgs82W3JDjzDr84dFT0qA00hU9/KT2cj/7Oz92n6zV4gOckW8FE 0zWQ== X-Forwarded-Encrypted: i=1; AJvYcCV35dQ7UWccEUhB6t1lZWKU8ycDajq4lKVc8vGJOV1CDoIyzREHtz4MyUxyW5dTeGyzfTFG6OtodOsHnQ8=@vger.kernel.org X-Gm-Message-State: AOJu0Yx1WxgWhB4oNJfRmFoGtFXbMX+zSqmvydkOlqdQ7QdqHO6GnHoh B9dOVhGvSocQJAyHt9f/hjGZMCaWYaFKssJFtF2WDznUqmRVkdU1vmPd/exaX1hytxA1bPPNd9/ r2zr62oX8pw== X-Received: from dlbvg13.prod.google.com ([2002:a05:7022:7f0d:b0:128:db8e:c776]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:4184:b0:119:e56c:18be with SMTP id a92af1059eb24-128e787d086mr2490867c88.38.1773294505947; Wed, 11 Mar 2026 22:48:25 -0700 (PDT) Date: Wed, 11 Mar 2026 22:48:10 -0700 In-Reply-To: <20260312054810.1571020-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260312054810.1571020-1-irogers@google.com> X-Mailer: git-send-email 2.53.0.851.ga537e3e6e9-goog Message-ID: <20260312054810.1571020-2-irogers@google.com> Subject: [PATCH v1 2/2] perf/x86: Reduce is_hybrid calls and aid ellision of BUG_ON in hybrid_pmu From: Ian Rogers To: dapeng1.mi@intel.com, dapeng1.mi@linux.intel.com Cc: irogers@google.com, acme@kernel.org, adrian.hunter@intel.com, ak@linux.intel.com, alexander.shishkin@linux.intel.com, eranian@google.com, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, mingo@redhat.com, namhyung@kernel.org, peterz@infradead.org, thomas.falcon@intel.com, xudong.hao@intel.com, zide.chen@intel.com Content-Type: text/plain; charset="UTF-8" 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. Signed-off-by: Ian Rogers --- Only build tested. --- arch/x86/events/perf_event.h | 52 +++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/arch/x86/events/perf_event.h b/arch/x86/events/perf_event.h index f1123c95d174..7990d86ef233 100644 --- a/arch/x86/events/perf_event.h +++ b/arch/x86/events/perf_event.h @@ -802,34 +802,38 @@ static __always_inline struct x86_hybrid_pmu *hybrid_pmu(struct pmu *pmu) extern struct static_key_false perf_is_hybrid; #define is_hybrid() static_branch_unlikely(&perf_is_hybrid) -#define hybrid(_pmu, _field) \ -(*({ \ - typeof(&x86_pmu._field) __Fp = &x86_pmu._field; \ - \ - if (is_hybrid() && (_pmu)) \ - __Fp = &hybrid_pmu(_pmu)->_field; \ - \ - __Fp; \ + +#define hybrid(_pmu, _field) \ +(*({ \ + typeof(&x86_pmu._field) __Fp = &x86_pmu._field; \ + struct pmu *__pmu = _pmu; \ + \ + if (__pmu->capabilities & PERF_PMU_CAP_EXTENDED_HW_TYPE) \ + __Fp = &hybrid_pmu(__pmu)->_field; \ + \ + __Fp; \ })) -#define hybrid_var(_pmu, _var) \ -(*({ \ - typeof(&_var) __Fp = &_var; \ - \ - if (is_hybrid() && (_pmu)) \ - __Fp = &hybrid_pmu(_pmu)->_var; \ - \ - __Fp; \ +#define hybrid_var(_pmu, _var) \ +(*({ \ + typeof(&_var) __Fp = &_var; \ + struct pmu *__pmu = _pmu; \ + \ + if (__pmu->capabilities & PERF_PMU_CAP_EXTENDED_HW_TYPE) \ + __Fp = &hybrid_pmu(__pmu)->_var; \ + \ + __Fp; \ })) -#define hybrid_bit(_pmu, _field) \ -({ \ - bool __Fp = x86_pmu._field; \ - \ - if (is_hybrid() && (_pmu)) \ - __Fp = hybrid_pmu(_pmu)->_field; \ - \ - __Fp; \ +#define hybrid_bit(_pmu, _field) \ +({ \ + bool __Fp = x86_pmu._field; \ + struct pmu *__pmu = _pmu; \ + \ + if (__pmu->capabilities & PERF_PMU_CAP_EXTENDED_HW_TYPE) \ + __Fp = hybrid_pmu(__pmu)->_field; \ + \ + __Fp; \ }) /* -- 2.53.0.851.ga537e3e6e9-goog