From nobody Sun Oct 5 01:49:28 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.13]) (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 379F42E3AF7 for ; Mon, 11 Aug 2025 18:17:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754936267; cv=none; b=pqEtpC8IMn9fQxHXYqcxn/CDwrjkX5gBhCpBZXejacPGAgpKyQ+fO7Lut+c/WqC54OQg6lA3zp8GqMSDGPL3SDsvATDz/ffRe1S5KSsEl+bJMgFc6IWb7qKzCo02u0nLo4beJbpzhfMjRlkOq1VQicA0ZKmOmS2igQtOiGixM1I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754936267; c=relaxed/simple; bh=fcNC4h2TEkm1ATe2ICOxIcVqPMlso311x+so9qRG1J4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FRUOS3msiQKjOviD5pXWxMfkVyAORVNVcZsZZlpH4A7MA+dZQ0Tq/rBeBjB0DB3C8JyoNBnnziWifNq8OOZdmYwI5gk/w73QK1ia/y3mIrmfF6tKUwI70AmA/rUopYtpD59Eo7RGH4SXj8tf8XmNZ/tjugrNQhRuS6QiJkDUpGQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=JBKBIVoU; arc=none smtp.client-ip=198.175.65.13 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="JBKBIVoU" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1754936266; x=1786472266; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fcNC4h2TEkm1ATe2ICOxIcVqPMlso311x+so9qRG1J4=; b=JBKBIVoUol41thSgSXcVzI0+VYikz3cOcMeaeioqONEEJq8l62IrIAMl GXCRX6wUmBeMFhfyMUNM04foMOAUtI7IbQCyAZpaLPILPN7fa34QBjyyE uHzC+aARpuuoq0QUW+bfUSSMdc9WVnmwfGSqnp7fLg3YNNVi6rt+DnwLZ /5s/YDUfzuPuyBtHeU6H0w2sXXbWKOIj/ltyqtoPLGP/RubTGhYHeeTk3 wuqRCqeLqeefx0ULvhNsaHS7JM/AN5Z1K6Ao/ASqbP6J1Gp0N9BKs2kSW FwkJHyf6CcqRfIDxRdyrtxM5781BP3Ojh012128ciQUWKBBn3jx0lefJV g==; X-CSE-ConnectionGUID: ADxpXVlDTYex4CfcCqXOZg== X-CSE-MsgGUID: 0gpEzp8eSz2EMufrKJOCZw== X-IronPort-AV: E=McAfee;i="6800,10657,11518"; a="68277477" X-IronPort-AV: E=Sophos;i="6.17,278,1747724400"; d="scan'208";a="68277477" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Aug 2025 11:17:27 -0700 X-CSE-ConnectionGUID: B/1Jy3UvTYu4Ka7d1Mo80g== X-CSE-MsgGUID: Iz8qZpK0TY2BtOEEAORk7A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.17,278,1747724400"; d="scan'208";a="196825687" Received: from puneetse-mobl.amr.corp.intel.com (HELO agluck-desk3.home.arpa) ([10.124.221.229]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Aug 2025 11:17:25 -0700 From: Tony Luck To: Fenghua Yu , Reinette Chatre , Maciej Wieczor-Retman , Peter Newman , James Morse , Babu Moger , Drew Fustini , Dave Martin , Anil Keshavamurthy , Chen Yu Cc: x86@kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev, Tony Luck Subject: [PATCH v8 22/32] x86/resctrl: Read telemetry events Date: Mon, 11 Aug 2025 11:16:56 -0700 Message-ID: <20250811181709.6241-23-tony.luck@intel.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250811181709.6241-1-tony.luck@intel.com> References: <20250811181709.6241-1-tony.luck@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Telemetry events are enumerated by the INTEL_PMT_TELEMETRY subsystem. resctrl enables events with resctrl_enable_mon_event() passing a pointer to the pmt_event structure for the event within the struct event_group. The file system stores it in mon_evt::arch_priv. Add a check to resctrl_arch_rmid_read() for resource id RDT_RESOURCE_PERF_PKG and directly call intel_aet_read_event() passing the enum resctrl_event_id for the event and the arch_priv pointer that was supplied when the event was enabled. There may be multiple aggregators tracking each package, so scan all of them and add up all counters. Resctrl now uses readq() so depends on X86_64. Update Kconfig. Signed-off-by: Tony Luck --- arch/x86/kernel/cpu/resctrl/internal.h | 7 ++++ arch/x86/kernel/cpu/resctrl/intel_aet.c | 44 +++++++++++++++++++++++++ arch/x86/kernel/cpu/resctrl/monitor.c | 3 ++ arch/x86/Kconfig | 2 +- 4 files changed, 55 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/r= esctrl/internal.h index 710493ec6548..b2f0769f63f6 100644 --- a/arch/x86/kernel/cpu/resctrl/internal.h +++ b/arch/x86/kernel/cpu/resctrl/internal.h @@ -172,9 +172,16 @@ void rdt_domain_reconfigure_cdp(struct rdt_resource *r= ); #ifdef CONFIG_X86_CPU_RESCTRL_INTEL_AET bool intel_aet_get_events(void); void __exit intel_aet_exit(void); +int intel_aet_read_event(int domid, int rmid, enum resctrl_event_id evtid, + void *arch_priv, u64 *val); #else static inline bool intel_aet_get_events(void) { return false; } static inline void __exit intel_aet_exit(void) { } +static inline int intel_aet_read_event(int domid, int rmid, enum resctrl_e= vent_id evtid, + void *arch_priv, u64 *val) +{ + return -EINVAL; +} #endif =20 #endif /* _ASM_X86_RESCTRL_INTERNAL_H */ diff --git a/arch/x86/kernel/cpu/resctrl/intel_aet.c b/arch/x86/kernel/cpu/= resctrl/intel_aet.c index dbd317e99ee0..5d49ed446b94 100644 --- a/arch/x86/kernel/cpu/resctrl/intel_aet.c +++ b/arch/x86/kernel/cpu/resctrl/intel_aet.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include =20 @@ -211,6 +212,9 @@ static int discover_events(struct event_group *e, struc= t pmt_feature_group *p) =20 list_add(&e->list, &active_event_groups); =20 + for (int i =3D 0; i < e->num_events; i++) + resctrl_enable_mon_event(e->evts[i].id, true, e->evts[i].bin_bits, &e->e= vts[i]); + return 0; } =20 @@ -278,3 +282,43 @@ void __exit intel_aet_exit(void) list_del(&evg->list); } } + +#define DATA_VALID BIT_ULL(63) +#define DATA_BITS GENMASK_ULL(62, 0) + +/* + * Read counter for an event on a domain (summing all aggregators + * on the domain). + */ +int intel_aet_read_event(int domid, int rmid, enum resctrl_event_id eventi= d, + void *arch_priv, u64 *val) +{ + struct pmt_event *pevt =3D arch_priv; + struct pkg_mmio_info *mmi; + struct event_group *e; + bool valid =3D false; + u64 evtcount; + void *pevt0; + int idx; + + pevt0 =3D pevt - pevt->idx; + e =3D container_of(pevt0, struct event_group, evts); + idx =3D rmid * e->num_events; + idx +=3D pevt->idx; + mmi =3D e->pkginfo[domid]; + + if (idx * sizeof(u64) + sizeof(u64) > e->mmio_size) { + pr_warn_once("MMIO index %d out of range\n", idx); + return -EIO; + } + + for (int i =3D 0; i < mmi->num_regions; i++) { + evtcount =3D readq(mmi->addrs[i] + idx * sizeof(u64)); + if (!(evtcount & DATA_VALID)) + continue; + *val +=3D evtcount & DATA_BITS; + valid =3D true; + } + + return valid ? 0 : -EINVAL; +} diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/re= sctrl/monitor.c index 185b203f6321..51d7d99336c6 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -232,6 +232,9 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, stru= ct rdt_domain_hdr *hdr, =20 resctrl_arch_rmid_read_context_check(); =20 + if (r->rid =3D=3D RDT_RESOURCE_PERF_PKG) + return intel_aet_read_event(hdr->id, rmid, eventid, arch_priv, val); + if (r->rid !=3D RDT_RESOURCE_L3) return -EINVAL; =20 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 56f0ff94c430..32beb66f0a92 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -527,7 +527,7 @@ config X86_CPU_RESCTRL =20 config X86_CPU_RESCTRL_INTEL_AET bool "Intel Application Energy Telemetry" if INTEL_PMT_TELEMETRY=3Dy && I= NTEL_TPMI=3Dy - depends on X86_CPU_RESCTRL && CPU_SUP_INTEL + depends on X86_64 && X86_CPU_RESCTRL && CPU_SUP_INTEL help Enable per-RMID telemetry events in resctrl =20 --=20 2.50.1