From nobody Mon Feb 9 09:40:22 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) (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 6C865239E85 for ; Wed, 21 May 2025 22:50:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747867861; cv=none; b=tuSWgW38z0WtkYgbrLH27fzkizhErW34Ru3D7f7eVmjZUi2pop3rGXnoPhLVyOpga+0YJJIaYxcDZzB0rmpGn0R8bn9Y9+jB/00NLEgc8HYIK0smkSd0huQU5XxFhvXPGs6a48KQY10Nfr2/UIkKIa/ffDPj/3p6RILBilzhXZk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747867861; c=relaxed/simple; bh=ywFw3L0GZ+G3CWaACoxs/B0PeQf1hL0TIHxJOWiRjNQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NXrHfDDJhYi4cepI8WM98FD5JtNMet1wa6A4DQdUflsTQQMqfKayWjQhrGIPBxeWuSvWMLNJLf4jp7tCX7YQUam4VzWm33XaM+3SO+5NVSIDqWyJXvgX9K0FsXUiKuAzAemfceXbtxG9tYPwsSbrNGbadbUynPmlv2o8OGjuTHo= 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=I1VYNmLA; arc=none smtp.client-ip=198.175.65.14 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="I1VYNmLA" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1747867859; x=1779403859; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ywFw3L0GZ+G3CWaACoxs/B0PeQf1hL0TIHxJOWiRjNQ=; b=I1VYNmLA50DfFhF19VGPtasupOSy1aaCzXOSXfB7JZaUQa1zxDPswJC0 kMxNpBkxLj0jknz3xJTwzCElN40TDR+WZOWuLvDVKgz9klP1h23jobATV Cn/VX2O/rVnnM3fv4NzUq1zpXg5ZBJVC7yuTM5C8eekb3birDknSr1y6t y0YbICNg0D1aDy0pfzbmznCtU+5et/y3f0Cj5QzwG92xNNeRpwO8La1Gc Q/uMReAL+/e6VlJ7o8zwt6OQ17/rht0BJ8UxNOiXY7d0pvxGYxz1OjLF7 0krImZo/FuDzqYIEmYMj626Ehx/Gy2yXF266Px9Zu5OywylxWv3bMgEib w==; X-CSE-ConnectionGUID: Kd18zVrVQ/Gkw1UctQI1mA== X-CSE-MsgGUID: FRMTY2cJRaeMbVdslHRdMQ== X-IronPort-AV: E=McAfee;i="6700,10204,11440"; a="53677606" X-IronPort-AV: E=Sophos;i="6.15,304,1739865600"; d="scan'208";a="53677606" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 May 2025 15:50:56 -0700 X-CSE-ConnectionGUID: hN8LmkuuTuG02O1GMzof7A== X-CSE-MsgGUID: 44VYTsBKSu+lQKfE9Oxx9w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,304,1739865600"; d="scan'208";a="141352123" Received: from agluck-desk3.sc.intel.com ([172.25.103.51]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 May 2025 15:50:56 -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 v5 01/29] x86,fs/resctrl: Consolidate monitor event descriptions Date: Wed, 21 May 2025 15:50:19 -0700 Message-ID: <20250521225049.132551-2-tony.luck@intel.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250521225049.132551-1-tony.luck@intel.com> References: <20250521225049.132551-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" There are currently only three monitor events, all associated with the RDT_RESOURCE_L3 resource. Growing support for additional events will be easier with some restructuring to have a single point in file system code where all attributes of all events are defined. Place all event descriptions into an array mon_event_all[]. Doing this has the beneficial side effect of removing the need for rdt_resource::evt_list. Drop the code that builds evt_list and change the two places where the list is scanned to scan mon_event_all[] instead. Architecture code now informs file system code which events are available with resctrl_enable_mon_event(). Signed-off-by: Tony Luck --- include/linux/resctrl.h | 4 +- fs/resctrl/internal.h | 10 +++-- arch/x86/kernel/cpu/resctrl/core.c | 12 ++++-- fs/resctrl/monitor.c | 63 +++++++++++++++--------------- fs/resctrl/rdtgroup.c | 11 +++--- 5 files changed, 55 insertions(+), 45 deletions(-) diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index 9ba771f2ddea..014cc6fe4a9b 100644 --- a/include/linux/resctrl.h +++ b/include/linux/resctrl.h @@ -269,7 +269,6 @@ enum resctrl_schema_fmt { * @mon_domains: RCU list of all monitor domains for this resource * @name: Name to use in "schemata" file. * @schema_fmt: Which format string and parser is used for this schema. - * @evt_list: List of monitoring events * @mbm_cfg_mask: Bandwidth sources that can be tracked when bandwidth * monitoring events can be configured. * @cdp_capable: Is the CDP feature available on this resource @@ -287,7 +286,6 @@ struct rdt_resource { struct list_head mon_domains; char *name; enum resctrl_schema_fmt schema_fmt; - struct list_head evt_list; unsigned int mbm_cfg_mask; bool cdp_capable; }; @@ -372,6 +370,8 @@ 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 evtid); + bool resctrl_arch_is_evt_configurable(enum resctrl_event_id evt); =20 /** diff --git a/fs/resctrl/internal.h b/fs/resctrl/internal.h index 9a8cf6f11151..94e635656261 100644 --- a/fs/resctrl/internal.h +++ b/fs/resctrl/internal.h @@ -52,19 +52,23 @@ static inline struct rdt_fs_context *rdt_fc2context(str= uct fs_context *fc) } =20 /** - * struct mon_evt - Entry in the event list of a resource + * struct mon_evt - Description of a monitor event * @evtid: event id + * @rid: index of the resource for this event * @name: name of the event * @configurable: true if the event is configurable - * @list: entry in &rdt_resource->evt_list + * @enabled: true if the event is enabled */ struct mon_evt { enum resctrl_event_id evtid; + enum resctrl_res_level rid; char *name; bool configurable; - struct list_head list; + bool enabled; }; =20 +extern struct mon_evt mon_event_all[QOS_NUM_EVENTS]; + /** * struct mon_data - Monitoring details for each event file. * @list: Member of the global @mon_data_kn_priv_list list. diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resct= rl/core.c index 224bed28f341..3d74c2d3dcea 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -861,12 +861,18 @@ static __init bool get_rdt_mon_resources(void) { struct rdt_resource *r =3D &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl; =20 - if (rdt_cpu_has(X86_FEATURE_CQM_OCCUP_LLC)) + if (rdt_cpu_has(X86_FEATURE_CQM_OCCUP_LLC)) { + resctrl_enable_mon_event(QOS_L3_OCCUP_EVENT_ID); rdt_mon_features |=3D (1 << QOS_L3_OCCUP_EVENT_ID); - if (rdt_cpu_has(X86_FEATURE_CQM_MBM_TOTAL)) + } + if (rdt_cpu_has(X86_FEATURE_CQM_MBM_TOTAL)) { + resctrl_enable_mon_event(QOS_L3_MBM_TOTAL_EVENT_ID); rdt_mon_features |=3D (1 << QOS_L3_MBM_TOTAL_EVENT_ID); - if (rdt_cpu_has(X86_FEATURE_CQM_MBM_LOCAL)) + } + if (rdt_cpu_has(X86_FEATURE_CQM_MBM_LOCAL)) { + resctrl_enable_mon_event(QOS_L3_MBM_LOCAL_EVENT_ID); rdt_mon_features |=3D (1 << QOS_L3_MBM_LOCAL_EVENT_ID); + } =20 if (!rdt_mon_features) return false; diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c index bde2801289d3..31c81d703ff4 100644 --- a/fs/resctrl/monitor.c +++ b/fs/resctrl/monitor.c @@ -842,38 +842,39 @@ static void dom_data_exit(struct rdt_resource *r) mutex_unlock(&rdtgroup_mutex); } =20 -static struct mon_evt llc_occupancy_event =3D { - .name =3D "llc_occupancy", - .evtid =3D QOS_L3_OCCUP_EVENT_ID, -}; - -static struct mon_evt mbm_total_event =3D { - .name =3D "mbm_total_bytes", - .evtid =3D QOS_L3_MBM_TOTAL_EVENT_ID, -}; - -static struct mon_evt mbm_local_event =3D { - .name =3D "mbm_local_bytes", - .evtid =3D QOS_L3_MBM_LOCAL_EVENT_ID, -}; - /* - * Initialize the event list for the resource. - * - * Note that MBM events are also part of RDT_RESOURCE_L3 resource - * because as per the SDM the total and local memory bandwidth - * are enumerated as part of L3 monitoring. + * All available events. Architecture code marks the ones that + * are supported by a system using resctrl_enable_mon_event() + * to set .enabled. */ -static void l3_mon_evt_init(struct rdt_resource *r) +struct mon_evt mon_event_all[QOS_NUM_EVENTS] =3D { + [QOS_L3_OCCUP_EVENT_ID] =3D { + .name =3D "llc_occupancy", + .evtid =3D QOS_L3_OCCUP_EVENT_ID, + .rid =3D RDT_RESOURCE_L3, + }, + [QOS_L3_MBM_TOTAL_EVENT_ID] =3D { + .name =3D "mbm_total_bytes", + .evtid =3D QOS_L3_MBM_TOTAL_EVENT_ID, + .rid =3D RDT_RESOURCE_L3, + }, + [QOS_L3_MBM_LOCAL_EVENT_ID] =3D { + .name =3D "mbm_local_bytes", + .evtid =3D QOS_L3_MBM_LOCAL_EVENT_ID, + .rid =3D RDT_RESOURCE_L3, + }, +}; + +void resctrl_enable_mon_event(enum resctrl_event_id evtid) { - INIT_LIST_HEAD(&r->evt_list); + if (WARN_ON_ONCE(evtid >=3D QOS_NUM_EVENTS)) + return; + if (mon_event_all[evtid].enabled) { + pr_warn("Duplicate enable for event %d\n", evtid); + return; + } =20 - if (resctrl_arch_is_llc_occupancy_enabled()) - list_add_tail(&llc_occupancy_event.list, &r->evt_list); - if (resctrl_arch_is_mbm_total_enabled()) - list_add_tail(&mbm_total_event.list, &r->evt_list); - if (resctrl_arch_is_mbm_local_enabled()) - list_add_tail(&mbm_local_event.list, &r->evt_list); + mon_event_all[evtid].enabled =3D true; } =20 /** @@ -900,15 +901,13 @@ int resctrl_mon_resource_init(void) if (ret) return ret; =20 - l3_mon_evt_init(r); - if (resctrl_arch_is_evt_configurable(QOS_L3_MBM_TOTAL_EVENT_ID)) { - mbm_total_event.configurable =3D true; + mon_event_all[QOS_L3_MBM_TOTAL_EVENT_ID].configurable =3D true; resctrl_file_fflags_init("mbm_total_bytes_config", RFTYPE_MON_INFO | RFTYPE_RES_CACHE); } if (resctrl_arch_is_evt_configurable(QOS_L3_MBM_LOCAL_EVENT_ID)) { - mbm_local_event.configurable =3D true; + mon_event_all[QOS_L3_MBM_LOCAL_EVENT_ID].configurable =3D true; resctrl_file_fflags_init("mbm_local_bytes_config", RFTYPE_MON_INFO | RFTYPE_RES_CACHE); } diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index cc37f58b47dd..69e0d40c4449 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -1150,7 +1150,9 @@ static int rdt_mon_features_show(struct kernfs_open_f= ile *of, struct rdt_resource *r =3D rdt_kn_parent_priv(of->kn); struct mon_evt *mevt; =20 - list_for_each_entry(mevt, &r->evt_list, list) { + for (mevt =3D &mon_event_all[0]; mevt < &mon_event_all[QOS_NUM_EVENTS]; m= evt++) { + if (mevt->rid !=3D r->rid || !mevt->enabled) + continue; seq_printf(seq, "%s\n", mevt->name); if (mevt->configurable) seq_printf(seq, "%s_config\n", mevt->name); @@ -3055,10 +3057,9 @@ static int mon_add_all_files(struct kernfs_node *kn,= struct rdt_mon_domain *d, struct mon_evt *mevt; int ret, domid; =20 - if (WARN_ON(list_empty(&r->evt_list))) - return -EPERM; - - list_for_each_entry(mevt, &r->evt_list, list) { + for (mevt =3D &mon_event_all[0]; mevt < &mon_event_all[QOS_NUM_EVENTS]; m= evt++) { + if (mevt->rid !=3D r->rid || !mevt->enabled) + continue; domid =3D do_sum ? d->ci->id : d->hdr.id; priv =3D mon_get_kn_priv(r->rid, domid, mevt, do_sum); if (WARN_ON_ONCE(!priv)) --=20 2.49.0