From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 673C23403F7; Tue, 30 Jun 2026 09:09:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782810583; cv=none; b=TkDfxm2fJ4VCUXLgE8lzU2rWUoVZ/4vIGxLs2K+4DLOahvvqHyBKQNsoFobpd/wW0cAjBzcMMSZP1Umq8HOFuwgdtqkU8QDN+Gu7C1SmyNsUZJQhjqNqJMaU90nkyp0KdUWdQv2IY9rYXZnsY88fcEmiYxxU//Dn787s7qpynTU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782810583; c=relaxed/simple; bh=gPLX98FLPLrrP8vCdtCo+NyKsWRKN9GPlWyD8GYXzlI=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=jTwP7mSXfUzTi8wHyeFWVD1ZRvf9iycbL6Hl+QNvQfUUiJtsXF18IlemIVrLQtyOWgyDsSkls7/wNFGSR959+OOwVLbVaxzMsYPjEcNk9gPUBZmQhJINr9eHPNVEbV7ySgwPVzefsLw0oMiJxU3noco3NdvHLPHHX4hTe9qzofk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=UrXMRoxm; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=+bZ7jFsY; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="UrXMRoxm"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="+bZ7jFsY" Date: Tue, 30 Jun 2026 09:09:39 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1782810581; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VKiwT7cBjNC60Wv1Zbt7EUJffA8Upf5BohXRB/uqunQ=; b=UrXMRoxmB1gG/4A+o8cOCMeQCXWu55c5CO3KxDuP5troN9TSpBjlBMV/DrR8SqgB6C3uKJ 6yct4+Romzw0fAeW6DXcB3TcafdUtUaeYIf8txIcMhPm4DmoKxULRHA27UDV6RP8bdR3ip WcnIAB4xNTD0DQoDK1XuEw/9Kr39VZPxUJm5Ks9rd5NKwbjO1z+mofZ0dAHRo94hcnIU7y grXScwtrhdLPdvUoYNTy8inwaeTpSeUh/Atjas9zkJTKbgt+ya8m+DU/eVnmtQQ+u/eIZo PEn0HiiU0a24DSWA1XMkDl87kSho4UQRvQaN+fxKPVH2Mx57J11tiG1gE0NIlA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1782810581; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VKiwT7cBjNC60Wv1Zbt7EUJffA8Upf5BohXRB/uqunQ=; b=+bZ7jFsYy/1YR9W8awsTorbxa2ErOa4OLrU590HUx9VsdQolvDy1+nOq5/ggboiXK13Uye mdw1TbIMwiWPTtCg== From: "tip-bot2 for Zide Chen" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: perf/core] perf/x86/intel/uncore: Implement lazy setup for MSR/MMIO PMUs Cc: Zide Chen , "Peter Zijlstra (Intel)" , Dapeng Mi , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20260611160033.66760-9-zide.chen@intel.com> References: <20260611160033.66760-9-zide.chen@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <178281057964.3843924.14433674573568314607.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The following commit has been merged into the perf/core branch of tip: Commit-ID: b25813b17944b4df532246cddae82201fb880481 Gitweb: https://git.kernel.org/tip/b25813b17944b4df532246cddae82201fb8= 80481 Author: Zide Chen AuthorDate: Thu, 11 Jun 2026 09:00:33 -07:00 Committer: Peter Zijlstra CommitterDate: Tue, 30 Jun 2026 10:57:05 +02:00 perf/x86/intel/uncore: Implement lazy setup for MSR/MMIO PMUs MSR and MMIO uncore PMUs are currently registered at module init time and appear in sysfs even when no PMU boxes are functional. Apply the same lazy registration model used by PCI uncore PMUs: the PMU is registered when the first box is successfully initialized, and unregistered when the last box exits. If a box fails to initialize on a subsequent die, the PMU is marked broken but remains registered to avoid disrupting any in-flight perf events. Box allocation and freeing remain at module init/exit time to avoid repeated kfree/alloc cycles across CPU offline/online events. Signed-off-by: Zide Chen Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Dapeng Mi Link: https://patch.msgid.link/20260611160033.66760-9-zide.chen@intel.com --- arch/x86/events/intel/uncore.c | 78 ++++++--------------------------- arch/x86/events/intel/uncore.h | 6 +++- 2 files changed, 22 insertions(+), 62 deletions(-) diff --git a/arch/x86/events/intel/uncore.c b/arch/x86/events/intel/uncore.c index b9ac2f7..9f8a80c 100644 --- a/arch/x86/events/intel/uncore.c +++ b/arch/x86/events/intel/uncore.c @@ -1570,8 +1570,13 @@ static void uncore_box_unref(struct intel_uncore_type = **types, int die) pmu =3D type->pmus; for (i =3D 0; i < type->num_boxes; i++, pmu++) { box =3D pmu->boxes[die]; - if (box && box->cpu >=3D 0 && atomic_dec_return(&box->refcnt) =3D=3D 0) + if (box && box->cpu >=3D 0 && + atomic_dec_return(&box->refcnt) =3D=3D 0) { + if (uncore_box_active(box) && + atomic_dec_return(&pmu->activeboxes) =3D=3D 0) + uncore_pmu_unregister(pmu); uncore_box_exit(box); + } } } } @@ -1658,7 +1663,7 @@ static int uncore_box_ref(struct intel_uncore_type **ty= pes, for (i =3D 0; i < type->num_boxes; i++, pmu++) { box =3D pmu->boxes[die]; if (box && box->cpu >=3D 0 && atomic_inc_return(&box->refcnt) =3D=3D 1) - uncore_box_init(box); + uncore_box_setup(pmu, box); } } return 0; @@ -1689,67 +1694,12 @@ static int uncore_event_cpu_online(unsigned int cpu) return 0; } =20 -static int __init type_pmu_register(struct intel_uncore_type *type) -{ - int i, ret; - - for (i =3D 0; i < type->num_boxes; i++) { - ret =3D uncore_pmu_register(&type->pmus[i]); - if (ret) - return ret; - } - return 0; -} - -static int __init uncore_msr_pmus_register(void) -{ - struct intel_uncore_type **types =3D uncore_msr_uncores; - int ret; - - for (; *types; types++) { - ret =3D type_pmu_register(*types); - if (ret) - return ret; - } - return 0; -} - -static int __init uncore_cpu_init(void) -{ - int ret; - - ret =3D uncore_types_init(uncore_msr_uncores); - if (ret) - goto err; - - ret =3D uncore_msr_pmus_register(); - if (ret) - goto err; - return 0; -err: - uncore_types_exit(uncore_msr_uncores); - uncore_msr_uncores =3D empty_uncore; - return ret; -} - -static int __init uncore_mmio_init(void) +static int __init uncore_pmu_types_init(struct intel_uncore_type **types) { - struct intel_uncore_type **types =3D uncore_mmio_uncores; - int ret; - - ret =3D uncore_types_init(types); + int ret =3D uncore_types_init(types); if (ret) - goto err; + uncore_types_exit(types); =20 - for (; *types; types++) { - ret =3D type_pmu_register(*types); - if (ret) - goto err; - } - return 0; -err: - uncore_types_exit(uncore_mmio_uncores); - uncore_mmio_uncores =3D empty_uncore; return ret; } =20 @@ -2050,12 +2000,16 @@ static int __init intel_uncore_init(void) =20 if (uncore_init->cpu_init) { uncore_init->cpu_init(); - cret =3D uncore_cpu_init(); + cret =3D uncore_pmu_types_init(uncore_msr_uncores); + if (cret) + uncore_msr_uncores =3D empty_uncore; } =20 if (uncore_init->mmio_init) { uncore_init->mmio_init(); - mret =3D uncore_mmio_init(); + mret =3D uncore_pmu_types_init(uncore_mmio_uncores); + if (mret) + uncore_mmio_uncores =3D empty_uncore; } =20 if (cret && pret && mret) { diff --git a/arch/x86/events/intel/uncore.h b/arch/x86/events/intel/uncore.h index 0adb477..c8dfa2d 100644 --- a/arch/x86/events/intel/uncore.h +++ b/arch/x86/events/intel/uncore.h @@ -568,6 +568,12 @@ static inline u64 uncore_read_counter(struct intel_uncor= e_box *box, return box->pmu->type->ops->read_counter(box, event); } =20 +static inline bool uncore_box_active(struct intel_uncore_box *box) +{ + return (!box->pmu->type->ops->init_box || + test_bit(UNCORE_BOX_FLAG_INITIALIZED, &box->flags)); +} + static inline int uncore_box_init(struct intel_uncore_box *box) { int ret =3D 0;