From nobody Mon Dec 15 22:06:10 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.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 E6E083093C7 for ; Wed, 10 Dec 2025 23:14:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765408506; cv=none; b=AuUiCL/FlXRLq+Max3jipSTZ14WA4/V1LtVU2qH3lotu+/TP+WMhrJ7g05N3b56yxfoVLmdjUrTi9eaeMzjpfaoGrKtWpvZD7oIq+sbv0Qjn1XiuDYT7YQd9BEEGH9Ob/bbPWDk8OaMXDTUECo8xdsJeeuF/dvqMZWL8fimrYE4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765408506; c=relaxed/simple; bh=J1FE4YF9acDbYyCHOfHQBiCqA41cHrThw2mcW1RE+c4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LR1DE07cdT9D1r8hqZWjdD+bPmnrviJAzX3vVR3dbCpIejwn3pxysZGd6GJbJrD/vD5leAmxHL63NrkILbg5w3z9xKdVRcws4tpRxW4Rpa7hLBOIUvVfBqnJGc9tHmyxcskuaoP8+ZS4WZlYgGM7Ritc3h+J2VyEAV4irPZjLQ8= 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=Y/+0IE7y; arc=none smtp.client-ip=192.198.163.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="Y/+0IE7y" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1765408499; x=1796944499; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=J1FE4YF9acDbYyCHOfHQBiCqA41cHrThw2mcW1RE+c4=; b=Y/+0IE7y40dGlNPQs9Z79qLlrOT2VK6wxNU9LpXmQkEvEkNbaiV4IXgy 4vm2EERYZg46IWt8u1M8hhYlyFGoaKnRUo9UIb2XYpWsoTJRL6h8bUi5L dlOASSCmxhL84d6mXwhIHZfugys+/uH3hUU04ORrXMt5QQteytc0Jnd8m RkaX11w/vkD6qlBcWrEsEsv0O9bCt+3kdKP+MVqTg1TXh81uyKmx+Hw1E ege3QgdB/0ZQ1q074f/ObnFGjXrbvwjBceeDxOYTlwKlrAIdwM+BdX3zd 372uutJ2ZaM+TM2Apv15x5gJ6Q9KQbHF+34j3qui1xyFRaUkuJUmR9Juw A==; X-CSE-ConnectionGUID: gIysb2uESTmuYJlP8cdzOg== X-CSE-MsgGUID: Thc11cgWQFWp8uTOx28NHg== X-IronPort-AV: E=McAfee;i="6800,10657,11638"; a="69973628" X-IronPort-AV: E=Sophos;i="6.20,265,1758610800"; d="scan'208";a="69973628" Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Dec 2025 15:14:37 -0800 X-CSE-ConnectionGUID: r0Vm+GMeSlSWastiHMUWog== X-CSE-MsgGUID: URJn3wpaSs6/VWZlxuSIhQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.20,265,1758610800"; d="scan'208";a="227297104" Received: from daliomra-mobl3.amr.corp.intel.com (HELO agluck-desk3.intel.com) ([10.124.221.254]) by orviesa002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Dec 2025 15:14:36 -0800 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 v16 19/32] x86/resctrl: Find and enable usable telemetry events Date: Wed, 10 Dec 2025 15:13:58 -0800 Message-ID: <20251210231413.59102-20-tony.luck@intel.com> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20251210231413.59102-1-tony.luck@intel.com> References: <20251210231413.59102-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" Every event group has a private copy of the data of all telemetry event aggregators (aka "telemetry regions") tracking its feature type. Included may be regions that have the same feature type but tracking different guid from the event group's. Traverse the event group's telemetry region data and mark all regions that are not usable by the event group as unusable by clearing those regions' MMIO addresses. A region is considered unusable if: 1) guid does not match the guid of the event group. 2) Package ID is invalid. 3) The enumerated size of the MMIO region does not match the expected value from the XML description file. Hereafter any telemetry region with an MMIO address is considered valid for the event group it is associated with. Enable all the event group's events as long as there is at least one usable region from where data for its events can be read. Enabling of events can fail. Each event group is independent of other event groups. So even if no events can be enabled from one event group, keep running to enable other event groups. Note that it is architecturally possible that some telemetry events are only supported by a subset of the packages in the system. It is not expected that systems will ever do this. If they do the user will see event files in resctrl that always return "Unavailable". Signed-off-by: Tony Luck --- include/linux/resctrl.h | 2 +- arch/x86/kernel/cpu/resctrl/intel_aet.c | 67 ++++++++++++++++++++++++- fs/resctrl/monitor.c | 10 ++-- 3 files changed, 72 insertions(+), 7 deletions(-) diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index b30f99335bbe..14126d228e61 100644 --- a/include/linux/resctrl.h +++ b/include/linux/resctrl.h @@ -414,7 +414,7 @@ u32 resctrl_arch_get_num_closid(struct rdt_resource *r); u32 resctrl_arch_system_num_rmid_idx(void); int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid); =20 -void resctrl_enable_mon_event(enum resctrl_event_id eventid, bool any_cpu, +bool resctrl_enable_mon_event(enum resctrl_event_id eventid, bool any_cpu, unsigned int binary_bits, void *arch_priv); =20 bool resctrl_is_mon_event_enabled(enum resctrl_event_id eventid); diff --git a/arch/x86/kernel/cpu/resctrl/intel_aet.c b/arch/x86/kernel/cpu/= resctrl/intel_aet.c index c7d08eb26395..611c6b1fc08d 100644 --- a/arch/x86/kernel/cpu/resctrl/intel_aet.c +++ b/arch/x86/kernel/cpu/resctrl/intel_aet.c @@ -16,9 +16,11 @@ #include #include #include +#include #include #include #include +#include #include =20 #include "internal.h" @@ -110,12 +112,73 @@ static struct event_group *known_event_groups[] =3D { _peg < &known_event_groups[ARRAY_SIZE(known_event_groups)]; \ _peg++) =20 -/* Stub for now */ -static bool enable_events(struct event_group *e, struct pmt_feature_group = *p) +/* + * 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 skip_telem_region(struct telemetry_region *tr, struct event_gr= oup *e) +{ + if (tr->guid !=3D e->guid) + return true; + if (tr->plat_info.package_id >=3D topology_max_packages()) { + pr_warn("Bad package %u in guid 0x%x\n", tr->plat_info.package_id, + tr->guid); + return true; + } + if (tr->size !=3D e->mmio_size) { + pr_warn("MMIO space wrong size (%zu bytes) for guid 0x%x. Expected %zu b= ytes.\n", + tr->size, e->guid, e->mmio_size); + return true; + } + return false; } =20 +static bool group_has_usable_regions(struct event_group *e, struct pmt_fea= ture_group *p) +{ + bool usable_regions =3D false; + + for (int i =3D 0; i < p->count; i++) { + if (skip_telem_region(&p->regions[i], e)) { + mark_telem_region_unusable(&p->regions[i]); + continue; + } + usable_regions =3D true; + } + + return usable_regions; +} + +static bool enable_events(struct event_group *e, struct pmt_feature_group = *p) +{ + struct rdt_resource *r =3D &rdt_resources_all[RDT_RESOURCE_PERF_PKG].r_re= sctrl; + int skipped_events =3D 0; + + if (!group_has_usable_regions(e, p)) + return false; + + for (int j =3D 0; j < e->num_events; j++) { + if (!resctrl_enable_mon_event(e->evts[j].id, true, + e->evts[j].bin_bits, &e->evts[j])) + skipped_events++; + } + if (e->num_events =3D=3D skipped_events) { + pr_info("No events enabled in %s %s:0x%x\n", r->name, e->pfname, e->guid= ); + return false; + } + + return true; +} + static enum pmt_feature_id lookup_pfid(const char *pfname) { if (!strcmp(pfname, "energy")) diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c index af43a33ce4cb..9af08b673e39 100644 --- a/fs/resctrl/monitor.c +++ b/fs/resctrl/monitor.c @@ -997,25 +997,27 @@ struct mon_evt mon_event_all[QOS_NUM_EVENTS] =3D { MON_EVENT(PMT_EVENT_UOPS_RETIRED, "uops_retired", RDT_RESOURCE_PERF_PKG= , false), }; =20 -void resctrl_enable_mon_event(enum resctrl_event_id eventid, bool any_cpu, +bool resctrl_enable_mon_event(enum resctrl_event_id eventid, bool any_cpu, unsigned int binary_bits, void *arch_priv) { if (WARN_ON_ONCE(eventid < QOS_FIRST_EVENT || eventid >=3D QOS_NUM_EVENTS= || binary_bits > MAX_BINARY_BITS)) - return; + return false; if (mon_event_all[eventid].enabled) { pr_warn("Duplicate enable for event %d\n", eventid); - return; + return false; } if (binary_bits && !mon_event_all[eventid].is_floating_point) { pr_warn("Event %d may not be floating point\n", eventid); - return; + return false; } =20 mon_event_all[eventid].any_cpu =3D any_cpu; mon_event_all[eventid].binary_bits =3D binary_bits; mon_event_all[eventid].arch_priv =3D arch_priv; mon_event_all[eventid].enabled =3D true; + + return true; } =20 bool resctrl_is_mon_event_enabled(enum resctrl_event_id eventid) --=20 2.51.1