From nobody Sat Sep 27 20:26:42 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (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 91BD434F473 for ; Fri, 12 Sep 2025 22:11:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757715078; cv=none; b=Gjr76+rw5kjkast7APgUfCAulMYI+CJkXf0Oi+k4GAK9E/q5glgozKuA+QUKKziJ6nMUHVr+PomZz94RYKoso9Z4qiTbCFOKrAQq53ZZofjinsYKiwR0JtE82MvGr0dSmn7mutCCH5Q/WgumkP7E/vqRCEHc39kOHsy6Hcgu+gI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757715078; c=relaxed/simple; bh=brUfVs22ux3+qnx9OXFs5Qy2k3OH4jGWqEf7kmbPa5Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IBO/XCYKvZ1y097ExjdkVKtN40wNVP3Pxv3DnACl8KMpIXuwEB69TgJuzi65E71k5/WRL7slPwQmao4f976uk31eQTxLf5B91UGXXH8ybaj8bTvLhoC/lDGnbmMFLQzKmt3WUXZsUEEGM6vkIr6p1fWuhnJVkaeMcPwd9Lahp4c= 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=Pq0u0jks; arc=none smtp.client-ip=192.198.163.17 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="Pq0u0jks" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1757715075; x=1789251075; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=brUfVs22ux3+qnx9OXFs5Qy2k3OH4jGWqEf7kmbPa5Y=; b=Pq0u0jksNIkHSbgZEgECi5GEdYYkjmQ7JdTLUpxr6TNcRcbvrbWK339y V4R6HmWWieAq+/ZOHSobugotzBDh9DuCoBFnnkog/rQkG5F55G+kOxE/r 37euAk7G0rPtNZkhnWo37vWOo+a5Mug5oWu2AuLamsNSe6M5ZQ/UMEgM1 OGiLz1YSrc/tcmDPv8RsPUZuQm+/gIglYUqdykYNHTm80kWJIk2KGl7K3 U+8a0jC8WGXUzNQp1k1FSurJ2Bd3tg9u2ubidmcgCGKU37SCgYt3Ckwr9 RYbnGOojtg01fC6wZFXem+GGpcQgj5QKilkGKDHfuT9zHJcWgHYk5jGRU Q==; X-CSE-ConnectionGUID: 102+yy/XTx29KSDQjNLwFQ== X-CSE-MsgGUID: 69Nhelj4QUy29gnhcI8y8A== X-IronPort-AV: E=McAfee;i="6800,10657,11551"; a="60002779" X-IronPort-AV: E=Sophos;i="6.18,260,1751266800"; d="scan'208";a="60002779" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Sep 2025 15:11:10 -0700 X-CSE-ConnectionGUID: b8o8GjTqR/en5E6iNJySQQ== X-CSE-MsgGUID: biteLa8xREGiZrkxoSZZPQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.18,260,1751266800"; d="scan'208";a="179265199" Received: from smoehrl-linux.amr.corp.intel.com (HELO agluck-desk3.intel.com) ([10.124.221.49]) by orviesa005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Sep 2025 15:11:09 -0700 From: Tony Luck To: Fenghua Yu , Reinette Chatre , Maciej Wieczor-Retman , Peter Newman , James Morse , Babu Moger , Drew Fustini , Dave Martin , Chen Yu Cc: x86@kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev, Tony Luck Subject: [PATCH v10 18/28] x86/resctrl: Read telemetry events Date: Fri, 12 Sep 2025 15:10:39 -0700 Message-ID: <20250912221053.11349-19-tony.luck@intel.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250912221053.11349-1-tony.luck@intel.com> References: <20250912221053.11349-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 enabled during the first mount of the resctrl file system. Mark telemetry regions that did not pass the sanity checks by clearing their MMIO address fields so that they will not be used when reading events. Introduce intel_aet_read_event() to read telemetry events for resource RDT_RESOURCE_PERF_PKG. There may be multiple aggregators tracking each package, so scan all of them and add up all counters. Aggregators may return an invalid data indication if they have received no records for a given RMID. Return success to the user if one or more aggregators provide valid data. 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 | 65 ++++++++++++++++++++++++- arch/x86/kernel/cpu/resctrl/monitor.c | 3 ++ arch/x86/Kconfig | 2 +- 4 files changed, 75 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/r= esctrl/internal.h index 07900f4ebd7a..4ad8e34444de 100644 --- a/arch/x86/kernel/cpu/resctrl/internal.h +++ b/arch/x86/kernel/cpu/resctrl/internal.h @@ -220,9 +220,16 @@ void resctrl_arch_mbm_cntr_assign_set_one(struct rdt_r= esource *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, u32 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, u32 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 98ba9ba05ee5..d53211ac6204 100644 --- a/arch/x86/kernel/cpu/resctrl/intel_aet.c +++ b/arch/x86/kernel/cpu/resctrl/intel_aet.c @@ -12,13 +12,17 @@ #define pr_fmt(fmt) "resctrl: " fmt =20 #include +#include #include #include +#include #include #include +#include #include #include #include +#include #include #include #include @@ -134,13 +138,28 @@ static bool skip_telem_region(struct telemetry_region= *tr, struct event_group *e return false; } =20 +/* + * Clear the address field of regions that did not pass the checks in + * skip_telem_region() so they will not be used by intel_aet_read_event(). + * This is safe to do because intel_pmt_get_regions_by_feature() allocates + * a new pmt_feature_group structure to return to each caller and only mak= es + * use of the pmt_feature_group::kref field when intel_pmt_put_feature_gro= up() + * returns the structure. + */ +static void mark_telem_region_unusable(struct telemetry_region *tr) +{ + tr->addr =3D NULL; +} + static bool enable_events(struct event_group *e, struct pmt_feature_group = *p) { bool usable_events =3D false; =20 for (int i =3D 0; i < p->count; i++) { - if (skip_telem_region(&p->regions[i], e)) + if (skip_telem_region(&p->regions[i], e)) { + mark_telem_region_unusable(&p->regions[i]); continue; + } usable_events =3D true; } =20 @@ -219,3 +238,47 @@ void __exit intel_aet_exit(void) (*peg)->pfg =3D NULL; } } + +#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). If an aggregator hasn't received any data for a + * specific RMID, the MMIO read indicates that data is not valid. + * Return success if at least one aggregator has valid data. + */ +int intel_aet_read_event(int domid, u32 rmid, enum resctrl_event_id eventi= d, + void *arch_priv, u64 *val) +{ + struct pmt_event *pevt =3D arch_priv; + struct event_group *e; + bool valid =3D false; + u64 evtcount; + void *pevt0; + u32 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; + + if (idx * sizeof(u64) + sizeof(u64) > e->mmio_size) { + pr_warn_once("MMIO index %u out of range\n", idx); + return -EIO; + } + + for (int i =3D 0; i < e->pfg->count; i++) { + if (!e->pfg->regions[i].addr) + continue; + if (e->pfg->regions[i].plat_info.package_id !=3D domid) + continue; + evtcount =3D readq(e->pfg->regions[i].addr + 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 175488185b06..7d14ae6a9737 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -250,6 +250,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 (!domain_header_is_valid(hdr, RESCTRL_MON_DOMAIN, RDT_RESOURCE_L3)) return -EINVAL; =20 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 183e7d43175d..3c3ed2c9816b 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" - depends on X86_CPU_RESCTRL && CPU_SUP_INTEL && INTEL_PMT_TELEMETRY=3Dy &&= INTEL_TPMI=3Dy + depends on X86_64 && X86_CPU_RESCTRL && CPU_SUP_INTEL && INTEL_PMT_TELEME= TRY=3Dy && INTEL_TPMI=3Dy help Enable per-RMID telemetry events in resctrl. =20 --=20 2.51.0