From nobody Tue Dec 2 00:46:19 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) (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 54E2932470C for ; Mon, 24 Nov 2025 18:55:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764010503; cv=none; b=Qnqz8LhiZKwrvpbdnyd7oTbv+EVVnIPzWlMUb52hV697cIMrmpk64vXRtrtK0Qz0gIfSpdMOK61AI/Ymu4bLjIjyp/YzNbR4/k1Au6aI2MPA8MlMDueJPoR2GoPLiAyNCdDGUmIGOFTVMOM2z0T0N2TYP6i/y9445Ynw7u3W1/I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764010503; c=relaxed/simple; bh=1/7YjHVOswPHiSd8P5BTn0s80BzXAbC++aIrzSo0rdg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pfnwa0TvqogvfcJHOXsX+S6Jl9sUtxztcXK1TizqkQsQmki0tfHlOik7a+1Q/SN6Gjo5ebvMCE2AVouUx2M86gx41w4uCZmjBwrmk5R/VYAcyugyGHvoTK7kZ91qhPtH2IloWVIaEwnb+vGw+iadV9vEdXEwUlBzemIxPdH+AB4= 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=m4zDDRwI; arc=none smtp.client-ip=192.198.163.11 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="m4zDDRwI" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1764010501; x=1795546501; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=1/7YjHVOswPHiSd8P5BTn0s80BzXAbC++aIrzSo0rdg=; b=m4zDDRwIKq+aJy8879nfl7breHA0gN9OyvhP6uxpm+YEyrpZhv9jaY+R hVRZuUAquZkhGgZH8Z1mkbODcCm00CXYjNvFwWt3muT5IDvmRe3XtaxkZ QohjeN2a+V87xeYsYjTJinB70ydfclR/GrV61UV+PkgwpkH4b5qDwv1YM WhrQ0vM5Ec6FKxMDtzGO70/WFeTQXDQiSYpOc5kv9X112jATohZ7c5hbX kq3nkNPhjpAlnzCcUTbOzv58e4v6BNtah9V9r+HuJN0erdIiOqJFoUeky tVv34/9nnLyW4eZwPzsIL61TEejIuwlDsSbDURwnbtf/h8ymEtkq6fSfO Q==; X-CSE-ConnectionGUID: LEQLjK9lQg2S/8jVlQroxQ== X-CSE-MsgGUID: r6yczpMTSAyy0+hB453p8A== X-IronPort-AV: E=McAfee;i="6800,10657,11623"; a="76636754" X-IronPort-AV: E=Sophos;i="6.20,223,1758610800"; d="scan'208";a="76636754" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Nov 2025 10:54:28 -0800 X-CSE-ConnectionGUID: 9zqU/LEfSzSb94AtyEst5g== X-CSE-MsgGUID: 2CVvVsE3TLyeTG3ALRI5AQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.20,223,1758610800"; d="scan'208";a="192225008" Received: from rfrazer-mobl3.amr.corp.intel.com (HELO agluck-desk3.home.arpa) ([10.124.222.153]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Nov 2025 10:54:28 -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 v14 19/32] x86/resctrl: Find and enable usable telemetry events Date: Mon, 24 Nov 2025 10:53:56 -0800 Message-ID: <20251124185412.24155-20-tony.luck@intel.com> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20251124185412.24155-1-tony.luck@intel.com> References: <20251124185412.24155-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. 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 | 62 ++++++++++++++++++++++++- fs/resctrl/monitor.c | 10 ++-- 3 files changed, 67 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 bb080bdde190..b6b50650e634 100644 --- a/arch/x86/kernel/cpu/resctrl/intel_aet.c +++ b/arch/x86/kernel/cpu/resctrl/intel_aet.c @@ -20,9 +20,11 @@ #include #include #include +#include #include #include #include +#include #include =20 #include "internal.h" @@ -117,12 +119,68 @@ 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) +{ + 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++; + } + + return skipped_events < e->num_events; +} + /* * Make a request to the INTEL_PMT_TELEMETRY driver for a copy of the * pmt_feature_group for each known feature. If there is one, the returned diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c index 4ef91fc09070..338a122dfcff 100644 --- a/fs/resctrl/monitor.c +++ b/fs/resctrl/monitor.c @@ -990,25 +990,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