From nobody Sun Dec 14 19:24:21 2025 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 From nobody Sun Dec 14 19:24:21 2025 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 6DCFA239E6E for ; Wed, 21 May 2025 22:50:58 +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=PjrSt0IngSqFGufH1ASMlWZgEP1zibgfflldKWo1F9C2X/8ClNzXZRb55mUA//L7lwdbhLKBpMuf2tDc4GpaBoNVtSTickr4QwtODewMuZUmBP9VB7Ne1OyoaML8joIUMQTH7WEeecTV6X0eAmY36+5+VKeWgmVihOMHmwCCFNk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747867861; c=relaxed/simple; bh=FyMtcU8pjumPYl9johWW2QnKCrbwPUJ5LmdQhIrC+9s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sM6Z88USYVIlCxM3dk7JIf5wZLf48uqhaA9BbrLONdNcM8u+OB+rZECrNwxcRg3Q1Ag3GeDVUPwEGOQ38AYwclGiQmMXxgVob8uOiza4U0li8PAfif5d4VATxnaUArG39mgULOuxLAn/TuP4nb782DvqCMILPbEZPSXPJpA+gZo= 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=ACBGsSLS; 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="ACBGsSLS" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1747867858; x=1779403858; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=FyMtcU8pjumPYl9johWW2QnKCrbwPUJ5LmdQhIrC+9s=; b=ACBGsSLS7BDQGgy/4riTdCW8nqPqZWyPpomErzF8c3xn6NP+HOYkAIt9 BZzoA82FiGD0qTUOmIYnT68lGdZRyfWfwt/Yo27SFyxZrHnO1G41Oj8pE 3mAvXCP7A4dtixQ6smsddhF5+xnuLF7T9v/5m3zvj94Eno+r+cB9A0Ylx evFT+fblMGEHkIkoKtgR9eeHGfUfLdje3Y5GvQgr721JIkLFCwjhGfNiO h0fi1FNpNlIyh/Ik5Z/PIggwM6xqjSXVhIkk8Tm2LmxsMoBB6LHwhn+hY swisx0LectOBqfl/4YeMWlr7iXx0ablFV1m+wrU2wT66KyZLcq/dB4sbi A==; X-CSE-ConnectionGUID: 1ZxNpmMxRMy6lKAyZRiyGA== X-CSE-MsgGUID: 70vblQRmQoGQSEOscKMXhA== X-IronPort-AV: E=McAfee;i="6700,10204,11440"; a="53677613" X-IronPort-AV: E=Sophos;i="6.15,304,1739865600"; d="scan'208";a="53677613" 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: wah0pVrnRgGVZb9hvLLVqw== X-CSE-MsgGUID: lTq3dcwjQ5mCC5QG4hwUkg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,304,1739865600"; d="scan'208";a="141352126" 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 02/29] x86,fs/resctrl: Replace architecture event enabled checks Date: Wed, 21 May 2025 15:50:20 -0700 Message-ID: <20250521225049.132551-3-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" The resctrl file system now has complete knowledge of the status of every event. So there is no need for per-event function calls to check. Replace each of the resctrl_arch_is_{event}enabled() calls with resctrl_is_mon_event_enabled(QOS_{EVENT}). No functional change. Signed-off-by: Tony Luck --- include/linux/resctrl.h | 2 ++ arch/x86/include/asm/resctrl.h | 15 --------------- arch/x86/kernel/cpu/resctrl/core.c | 4 ++-- arch/x86/kernel/cpu/resctrl/monitor.c | 4 ++-- fs/resctrl/ctrlmondata.c | 4 ++-- fs/resctrl/monitor.c | 15 ++++++++++----- fs/resctrl/rdtgroup.c | 18 +++++++++--------- 7 files changed, 27 insertions(+), 35 deletions(-) diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index 014cc6fe4a9b..843ad7c8e247 100644 --- a/include/linux/resctrl.h +++ b/include/linux/resctrl.h @@ -372,6 +372,8 @@ int resctrl_arch_update_domains(struct rdt_resource *r,= u32 closid); =20 void resctrl_enable_mon_event(enum resctrl_event_id evtid); =20 +bool resctrl_is_mon_event_enabled(enum resctrl_event_id evt); + bool resctrl_arch_is_evt_configurable(enum resctrl_event_id evt); =20 /** diff --git a/arch/x86/include/asm/resctrl.h b/arch/x86/include/asm/resctrl.h index ad497ab196d1..9c889f51b7f1 100644 --- a/arch/x86/include/asm/resctrl.h +++ b/arch/x86/include/asm/resctrl.h @@ -82,21 +82,6 @@ static inline void resctrl_arch_disable_mon(void) static_branch_dec_cpuslocked(&rdt_enable_key); } =20 -static inline bool resctrl_arch_is_llc_occupancy_enabled(void) -{ - return (rdt_mon_features & (1 << QOS_L3_OCCUP_EVENT_ID)); -} - -static inline bool resctrl_arch_is_mbm_total_enabled(void) -{ - return (rdt_mon_features & (1 << QOS_L3_MBM_TOTAL_EVENT_ID)); -} - -static inline bool resctrl_arch_is_mbm_local_enabled(void) -{ - return (rdt_mon_features & (1 << QOS_L3_MBM_LOCAL_EVENT_ID)); -} - /* * __resctrl_sched_in() - Writes the task's CLOSid/RMID to IA32_PQR_MSR * diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resct= rl/core.c index 3d74c2d3dcea..f4f4c1d42710 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -401,13 +401,13 @@ static int arch_domain_mbm_alloc(u32 num_rmid, struct= rdt_hw_mon_domain *hw_dom) { size_t tsize; =20 - if (resctrl_arch_is_mbm_total_enabled()) { + if (resctrl_is_mon_event_enabled(QOS_L3_MBM_TOTAL_EVENT_ID)) { tsize =3D sizeof(*hw_dom->arch_mbm_total); hw_dom->arch_mbm_total =3D kcalloc(num_rmid, tsize, GFP_KERNEL); if (!hw_dom->arch_mbm_total) return -ENOMEM; } - if (resctrl_arch_is_mbm_local_enabled()) { + if (resctrl_is_mon_event_enabled(QOS_L3_MBM_LOCAL_EVENT_ID)) { tsize =3D sizeof(*hw_dom->arch_mbm_local); hw_dom->arch_mbm_local =3D kcalloc(num_rmid, tsize, GFP_KERNEL); if (!hw_dom->arch_mbm_local) { diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/re= sctrl/monitor.c index 3fc4d9f56f0d..a1296ee7d508 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -206,11 +206,11 @@ void resctrl_arch_reset_rmid_all(struct rdt_resource = *r, struct rdt_mon_domain * { struct rdt_hw_mon_domain *hw_dom =3D resctrl_to_arch_mon_dom(d); =20 - if (resctrl_arch_is_mbm_total_enabled()) + if (resctrl_is_mon_event_enabled(QOS_L3_MBM_TOTAL_EVENT_ID)) memset(hw_dom->arch_mbm_total, 0, sizeof(*hw_dom->arch_mbm_total) * r->num_rmid); =20 - if (resctrl_arch_is_mbm_local_enabled()) + if (resctrl_is_mon_event_enabled(QOS_L3_MBM_LOCAL_EVENT_ID)) memset(hw_dom->arch_mbm_local, 0, sizeof(*hw_dom->arch_mbm_local) * r->num_rmid); } diff --git a/fs/resctrl/ctrlmondata.c b/fs/resctrl/ctrlmondata.c index 6ed2dfd4dbbd..6be423c5e2e0 100644 --- a/fs/resctrl/ctrlmondata.c +++ b/fs/resctrl/ctrlmondata.c @@ -473,12 +473,12 @@ ssize_t rdtgroup_mba_mbps_event_write(struct kernfs_o= pen_file *of, rdt_last_cmd_clear(); =20 if (!strcmp(buf, "mbm_local_bytes")) { - if (resctrl_arch_is_mbm_local_enabled()) + if (resctrl_is_mon_event_enabled(QOS_L3_MBM_LOCAL_EVENT_ID)) rdtgrp->mba_mbps_event =3D QOS_L3_MBM_LOCAL_EVENT_ID; else ret =3D -EINVAL; } else if (!strcmp(buf, "mbm_total_bytes")) { - if (resctrl_arch_is_mbm_total_enabled()) + if (resctrl_is_mon_event_enabled(QOS_L3_MBM_TOTAL_EVENT_ID)) rdtgrp->mba_mbps_event =3D QOS_L3_MBM_TOTAL_EVENT_ID; else ret =3D -EINVAL; diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c index 31c81d703ff4..325e23c1a403 100644 --- a/fs/resctrl/monitor.c +++ b/fs/resctrl/monitor.c @@ -336,7 +336,7 @@ void free_rmid(u32 closid, u32 rmid) =20 entry =3D __rmid_entry(idx); =20 - if (resctrl_arch_is_llc_occupancy_enabled()) + if (resctrl_is_mon_event_enabled(QOS_L3_OCCUP_EVENT_ID)) add_rmid_to_limbo(entry); else list_add_tail(&entry->list, &rmid_free_lru); @@ -635,10 +635,10 @@ static void mbm_update(struct rdt_resource *r, struct= rdt_mon_domain *d, * This is protected from concurrent reads from user as both * the user and overflow handler hold the global mutex. */ - if (resctrl_arch_is_mbm_total_enabled()) + if (resctrl_is_mon_event_enabled(QOS_L3_MBM_TOTAL_EVENT_ID)) mbm_update_one_event(r, d, closid, rmid, QOS_L3_MBM_TOTAL_EVENT_ID); =20 - if (resctrl_arch_is_mbm_local_enabled()) + if (resctrl_is_mon_event_enabled(QOS_L3_MBM_LOCAL_EVENT_ID)) mbm_update_one_event(r, d, closid, rmid, QOS_L3_MBM_LOCAL_EVENT_ID); } =20 @@ -877,6 +877,11 @@ void resctrl_enable_mon_event(enum resctrl_event_id ev= tid) mon_event_all[evtid].enabled =3D true; } =20 +bool resctrl_is_mon_event_enabled(enum resctrl_event_id evtid) +{ + return evtid < QOS_NUM_EVENTS && mon_event_all[evtid].enabled; +} + /** * resctrl_mon_resource_init() - Initialise global monitoring structures. * @@ -912,9 +917,9 @@ int resctrl_mon_resource_init(void) RFTYPE_MON_INFO | RFTYPE_RES_CACHE); } =20 - if (resctrl_arch_is_mbm_local_enabled()) + if (resctrl_is_mon_event_enabled(QOS_L3_MBM_LOCAL_EVENT_ID)) mba_mbps_default_event =3D QOS_L3_MBM_LOCAL_EVENT_ID; - else if (resctrl_arch_is_mbm_total_enabled()) + else if (resctrl_is_mon_event_enabled(QOS_L3_MBM_TOTAL_EVENT_ID)) mba_mbps_default_event =3D QOS_L3_MBM_TOTAL_EVENT_ID; =20 return 0; diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index 69e0d40c4449..80e74940281a 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -123,8 +123,8 @@ void rdt_staged_configs_clear(void) =20 static bool resctrl_is_mbm_enabled(void) { - return (resctrl_arch_is_mbm_total_enabled() || - resctrl_arch_is_mbm_local_enabled()); + return (resctrl_is_mon_event_enabled(QOS_L3_MBM_TOTAL_EVENT_ID) || + resctrl_is_mon_event_enabled(QOS_L3_MBM_LOCAL_EVENT_ID)); } =20 static bool resctrl_is_mbm_event(int e) @@ -196,7 +196,7 @@ static int closid_alloc(void) lockdep_assert_held(&rdtgroup_mutex); =20 if (IS_ENABLED(CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID) && - resctrl_arch_is_llc_occupancy_enabled()) { + resctrl_is_mon_event_enabled(QOS_L3_OCCUP_EVENT_ID)) { cleanest_closid =3D resctrl_find_cleanest_closid(); if (cleanest_closid < 0) return cleanest_closid; @@ -4047,7 +4047,7 @@ void resctrl_offline_mon_domain(struct rdt_resource *= r, struct rdt_mon_domain *d =20 if (resctrl_is_mbm_enabled()) cancel_delayed_work(&d->mbm_over); - if (resctrl_arch_is_llc_occupancy_enabled() && has_busy_rmid(d)) { + if (resctrl_is_mon_event_enabled(QOS_L3_OCCUP_EVENT_ID) && has_busy_rmid(= d)) { /* * When a package is going down, forcefully * decrement rmid->ebusy. There is no way to know @@ -4083,12 +4083,12 @@ static int domain_setup_mon_state(struct rdt_resour= ce *r, struct rdt_mon_domain u32 idx_limit =3D resctrl_arch_system_num_rmid_idx(); size_t tsize; =20 - if (resctrl_arch_is_llc_occupancy_enabled()) { + if (resctrl_is_mon_event_enabled(QOS_L3_OCCUP_EVENT_ID)) { d->rmid_busy_llc =3D bitmap_zalloc(idx_limit, GFP_KERNEL); if (!d->rmid_busy_llc) return -ENOMEM; } - if (resctrl_arch_is_mbm_total_enabled()) { + if (resctrl_is_mon_event_enabled(QOS_L3_MBM_TOTAL_EVENT_ID)) { tsize =3D sizeof(*d->mbm_total); d->mbm_total =3D kcalloc(idx_limit, tsize, GFP_KERNEL); if (!d->mbm_total) { @@ -4096,7 +4096,7 @@ static int domain_setup_mon_state(struct rdt_resource= *r, struct rdt_mon_domain return -ENOMEM; } } - if (resctrl_arch_is_mbm_local_enabled()) { + if (resctrl_is_mon_event_enabled(QOS_L3_MBM_LOCAL_EVENT_ID)) { tsize =3D sizeof(*d->mbm_local); d->mbm_local =3D kcalloc(idx_limit, tsize, GFP_KERNEL); if (!d->mbm_local) { @@ -4141,7 +4141,7 @@ int resctrl_online_mon_domain(struct rdt_resource *r,= struct rdt_mon_domain *d) RESCTRL_PICK_ANY_CPU); } =20 - if (resctrl_arch_is_llc_occupancy_enabled()) + if (resctrl_is_mon_event_enabled(QOS_L3_OCCUP_EVENT_ID)) INIT_DELAYED_WORK(&d->cqm_limbo, cqm_handle_limbo); =20 /* @@ -4216,7 +4216,7 @@ void resctrl_offline_cpu(unsigned int cpu) cancel_delayed_work(&d->mbm_over); mbm_setup_overflow_handler(d, 0, cpu); } - if (resctrl_arch_is_llc_occupancy_enabled() && + if (resctrl_is_mon_event_enabled(QOS_L3_OCCUP_EVENT_ID) && cpu =3D=3D d->cqm_work_cpu && has_busy_rmid(d)) { cancel_delayed_work(&d->cqm_limbo); cqm_setup_limbo_handler(d, 0, cpu); --=20 2.49.0 From nobody Sun Dec 14 19:24:21 2025 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 DDBBB134AC for ; Wed, 21 May 2025 22:51:00 +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=1747867862; cv=none; b=c6IZ3sUbn6xsD0g7NKwQ/BPIeaxFp73v/PA7H2Glpfy6Honv7NcTatbyP3Y9FMjYPQf0IXOL7isfjuFYK4PvR/o8rnlsA71ZUACH0RoL07YZIFA58x+LG4dozxpB9FRaj+dStZ66sdMkzn4cmWsx+UTDRS3H8q7DL0dOQn/aG0k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747867862; c=relaxed/simple; bh=IVy4LhDAZM5Nxy/pPdww1lQYsqOkYwzTZTnTQf1NwTM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aS1rgS6flD7Wnk2X+d1OAMG+UftDRCYPTjPEr8akGLvruSxdFIcnHOsXgmwFbK28yEIBaIPmdjINlpHr7Uvs12Ro04uxROPjinO8i11plrxy8m1SCWlFmujLuuWqFnoJ8Z6KjDJ8h6q2FPG9kJP6OA/t5bH9PAoOANLsNvPoCF0= 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=VHWBMNNG; 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="VHWBMNNG" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1747867861; x=1779403861; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=IVy4LhDAZM5Nxy/pPdww1lQYsqOkYwzTZTnTQf1NwTM=; b=VHWBMNNGUK//VMG0ah140w5m+vgo5Tp55yQnDBhWIJwMXNWHZLImo52+ +NpJ5dcFYNQ9aVx8auWtHXA4CMBM14PlbVt7pEmJ581N5u8dgVha+FzK5 tq58PRn+6gEoBYu57L9OKt/Oc3K3TP3Qe6xxlzPTiaq7YpcYPyN2BpKnP T+UAcFUfpIzyjNruPZXY81iUrKCjbb8VS9ONFdAU/f09uA4IFM3pCM4Ra IF1JcBFDe4wMfXn0pp/U+NMDaPTmsPCjeB/Hac/rASBz+ATR9zhxz6VHl wJ+IYugN3H/wHcw0/TzKNPUsACIBBe+ObdTaiqo2WajHv/owR5nQwzSeu Q==; X-CSE-ConnectionGUID: g24lcoQBRPKA7WodIuZPPg== X-CSE-MsgGUID: XwWa6ZZ5RGKxRYtDJjf5jA== X-IronPort-AV: E=McAfee;i="6700,10204,11440"; a="53677622" X-IronPort-AV: E=Sophos;i="6.15,304,1739865600"; d="scan'208";a="53677622" 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:57 -0700 X-CSE-ConnectionGUID: Iw9HxtXpReKbTAMpGKTWqw== X-CSE-MsgGUID: 3AcI84ZHSZy3N/Ce6wn3vQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,304,1739865600"; d="scan'208";a="141352129" 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 03/29] x86/resctrl: Remove 'rdt_mon_features' global variable Date: Wed, 21 May 2025 15:50:21 -0700 Message-ID: <20250521225049.132551-4-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" This variable was used as a bitmask of enabled monitor events. But that function is now provided by the filesystem mon_event_all[] array. Remove the remaining uses of this variable. Signed-off-by: Tony Luck --- arch/x86/include/asm/resctrl.h | 1 - arch/x86/kernel/cpu/resctrl/core.c | 9 +++++---- arch/x86/kernel/cpu/resctrl/monitor.c | 5 ----- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/arch/x86/include/asm/resctrl.h b/arch/x86/include/asm/resctrl.h index 9c889f51b7f1..089742970cc1 100644 --- a/arch/x86/include/asm/resctrl.h +++ b/arch/x86/include/asm/resctrl.h @@ -42,7 +42,6 @@ DECLARE_PER_CPU(struct resctrl_pqr_state, pqr_state); =20 extern bool rdt_alloc_capable; extern bool rdt_mon_capable; -extern unsigned int rdt_mon_features; =20 DECLARE_STATIC_KEY_FALSE(rdt_enable_key); DECLARE_STATIC_KEY_FALSE(rdt_alloc_enable_key); diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resct= rl/core.c index f4f4c1d42710..819bc7a09327 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -860,21 +860,22 @@ static __init bool get_rdt_alloc_resources(void) static __init bool get_rdt_mon_resources(void) { struct rdt_resource *r =3D &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl; + bool ret =3D false; =20 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); + ret =3D true; } 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); + ret =3D true; } 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); + ret =3D true; } =20 - if (!rdt_mon_features) + if (!ret) return false; =20 return !rdt_get_mon_l3_config(r); diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/re= sctrl/monitor.c index a1296ee7d508..fda579251dba 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -30,11 +30,6 @@ */ bool rdt_mon_capable; =20 -/* - * Global to indicate which monitoring events are enabled. - */ -unsigned int rdt_mon_features; - #define CF(cf) ((unsigned long)(1048576 * (cf) + 0.5)) =20 static int snc_nodes_per_l3_cache =3D 1; --=20 2.49.0 From nobody Sun Dec 14 19:24:21 2025 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 575D223A9B0 for ; Wed, 21 May 2025 22:51:01 +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=1747867863; cv=none; b=c998MUB+kkSLhP8rqlE7jKrEKcnhpjZ8oB/74huFlbNhLOUEZyeRyaLdzA7HfPcJuot/O/W/qrePFj+3FK/oqEJiwWSZJLlJ+O2aw2IY/Bs2GArcKPMf0CEjQfIdIHPyEgxsCJJ9ncSpOD3G4tjhPev3iWuG4dduITxKi2QR2Oc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747867863; c=relaxed/simple; bh=G+ZEs5+MSKrphrsPXnNImY6OjN0jyQ57iVz/F6B7pnI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qeKUJrxWcnQKWZe9rtcIg6NrOnbZpRMIfCEEk3Gku6mHYuhafKOYjXLuf6rHFRyLptL5SrdxxxqJTM8qz5LP/JJMD0r/nK+kSxaJRLhFPRqjtccMoISfLI43NTMbWu47fpXjut/6Sgug06k+GmhwaG9l7isxAjxmu+Pxp2RYvcc= 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=GbuWtnoN; 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="GbuWtnoN" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1747867861; x=1779403861; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=G+ZEs5+MSKrphrsPXnNImY6OjN0jyQ57iVz/F6B7pnI=; b=GbuWtnoNkoU2GBGNgtgLz5HnvZ8Emvw9dYemXYsy6y3bI9I5hsTOr14S MYjBjtxJ65LAmrbWuLADhXjI0ckUV9BGM9FnOtw9cnt9eaA1aqnPmV9N5 qclKJ1ccLLMlwSleNUgIvEinQAM7VEtryyqHKlX3lZuTD3r4ECa1EMBwd VUQ/Ez74B9nIAiussAOOnA5Ztz6ol1LVelpdAuCs1iTdGgEH8HgIwivPh bdq9uM0R4PIAwCB8ywjlw8/xPeqBegmlOZsUFORVqX4Yjoyoa1AUCyOJM dM6UItHQwia7TT33YHwoufTw/9ze1XOOyzAl9YmvCpfE/p90Z18sRkYRJ Q==; X-CSE-ConnectionGUID: avfOeGJnQc26ZWFXxa9PRw== X-CSE-MsgGUID: Nb48mYpRRuivqdB8IytQLw== X-IronPort-AV: E=McAfee;i="6700,10204,11440"; a="53677628" X-IronPort-AV: E=Sophos;i="6.15,304,1739865600"; d="scan'208";a="53677628" 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:57 -0700 X-CSE-ConnectionGUID: VMdfxvwbSHSVy2NLaR70Fg== X-CSE-MsgGUID: UiBsrY2YR3mfXRgp3eKjoQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,304,1739865600"; d="scan'208";a="141352132" 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 04/29] x86,fs/resctrl: Prepare for more monitor events Date: Wed, 21 May 2025 15:50:22 -0700 Message-ID: <20250521225049.132551-5-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's a rule in computer programming that objects appear zero, once, or many times. So code accordingly. There are two MBM events and resctrl is coded with a lot of if (local) do one thing if (total) do a different thing Change the rdt_mon_domain and rdt_hw_mon_domain structures to hold arrays of pointers to per event data instead of explicit fields for total and local bandwidth. Simplify by coding for many events using loops on which are enabled. Move resctrl_is_mbm_event() to so it can be used more widely. Also provide a for_each_mbm_event() helper macro. Signed-off-by: Tony Luck --- include/linux/resctrl.h | 15 +++++--- include/linux/resctrl_types.h | 3 ++ arch/x86/kernel/cpu/resctrl/internal.h | 6 ++-- arch/x86/kernel/cpu/resctrl/core.c | 38 ++++++++++---------- arch/x86/kernel/cpu/resctrl/monitor.c | 36 +++++++++---------- fs/resctrl/monitor.c | 13 ++++--- fs/resctrl/rdtgroup.c | 48 ++++++++++++-------------- 7 files changed, 82 insertions(+), 77 deletions(-) diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index 843ad7c8e247..40f2d0d48d02 100644 --- a/include/linux/resctrl.h +++ b/include/linux/resctrl.h @@ -161,8 +161,7 @@ struct rdt_ctrl_domain { * @hdr: common header for different domain types * @ci: cache info for this domain * @rmid_busy_llc: bitmap of which limbo RMIDs are above threshold - * @mbm_total: saved state for MBM total bandwidth - * @mbm_local: saved state for MBM local bandwidth + * @mbm_states: saved state for each QOS MBM event * @mbm_over: worker to periodically read MBM h/w counters * @cqm_limbo: worker to periodically read CQM h/w counters * @mbm_work_cpu: worker CPU for MBM h/w counters @@ -172,8 +171,7 @@ struct rdt_mon_domain { struct rdt_domain_hdr hdr; struct cacheinfo *ci; unsigned long *rmid_busy_llc; - struct mbm_state *mbm_total; - struct mbm_state *mbm_local; + struct mbm_state *mbm_states[QOS_NUM_L3_MBM_EVENTS]; struct delayed_work mbm_over; struct delayed_work cqm_limbo; int mbm_work_cpu; @@ -376,6 +374,15 @@ bool resctrl_is_mon_event_enabled(enum resctrl_event_i= d evt); =20 bool resctrl_arch_is_evt_configurable(enum resctrl_event_id evt); =20 +static inline bool resctrl_is_mbm_event(enum resctrl_event_id e) +{ + return (e >=3D QOS_L3_MBM_TOTAL_EVENT_ID && + e <=3D QOS_L3_MBM_LOCAL_EVENT_ID); +} + +#define for_each_mbm_event(evt) \ + for (evt =3D QOS_L3_MBM_TOTAL_EVENT_ID; evt <=3D QOS_L3_MBM_LOCAL_EVENT_I= D; evt++) + /** * resctrl_arch_mon_event_config_write() - Write the config for an event. * @config_info: struct resctrl_mon_config_info describing the resource, d= omain diff --git a/include/linux/resctrl_types.h b/include/linux/resctrl_types.h index a25fb9c4070d..b468bfbab9ea 100644 --- a/include/linux/resctrl_types.h +++ b/include/linux/resctrl_types.h @@ -47,4 +47,7 @@ enum resctrl_event_id { QOS_NUM_EVENTS, }; =20 +#define QOS_NUM_L3_MBM_EVENTS (QOS_L3_MBM_LOCAL_EVENT_ID - QOS_L3_MBM_TOTA= L_EVENT_ID + 1) +#define MBM_STATE_IDX(evt) ((evt) - QOS_L3_MBM_TOTAL_EVENT_ID) + #endif /* __LINUX_RESCTRL_TYPES_H */ diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/r= esctrl/internal.h index 5e3c41b36437..ea185b4d0d59 100644 --- a/arch/x86/kernel/cpu/resctrl/internal.h +++ b/arch/x86/kernel/cpu/resctrl/internal.h @@ -54,15 +54,13 @@ struct rdt_hw_ctrl_domain { * struct rdt_hw_mon_domain - Arch private attributes of a set of CPUs tha= t share * a resource for a monitor function * @d_resctrl: Properties exposed to the resctrl file system - * @arch_mbm_total: arch private state for MBM total bandwidth - * @arch_mbm_local: arch private state for MBM local bandwidth + * @arch_mbm_states: arch private state for each MBM event * * Members of this structure are accessed via helpers that provide abstrac= tion. */ struct rdt_hw_mon_domain { struct rdt_mon_domain d_resctrl; - struct arch_mbm_state *arch_mbm_total; - struct arch_mbm_state *arch_mbm_local; + struct arch_mbm_state *arch_mbm_states[QOS_NUM_L3_MBM_EVENTS]; }; =20 static inline struct rdt_hw_ctrl_domain *resctrl_to_arch_ctrl_dom(struct r= dt_ctrl_domain *r) diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resct= rl/core.c index 819bc7a09327..4403a820db12 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -364,8 +364,8 @@ static void ctrl_domain_free(struct rdt_hw_ctrl_domain = *hw_dom) =20 static void mon_domain_free(struct rdt_hw_mon_domain *hw_dom) { - kfree(hw_dom->arch_mbm_total); - kfree(hw_dom->arch_mbm_local); + for (int i =3D 0; i < QOS_NUM_L3_MBM_EVENTS; i++) + kfree(hw_dom->arch_mbm_states[i]); kfree(hw_dom); } =20 @@ -399,25 +399,27 @@ static int domain_setup_ctrlval(struct rdt_resource *= r, struct rdt_ctrl_domain * */ static int arch_domain_mbm_alloc(u32 num_rmid, struct rdt_hw_mon_domain *h= w_dom) { - size_t tsize; - - if (resctrl_is_mon_event_enabled(QOS_L3_MBM_TOTAL_EVENT_ID)) { - tsize =3D sizeof(*hw_dom->arch_mbm_total); - hw_dom->arch_mbm_total =3D kcalloc(num_rmid, tsize, GFP_KERNEL); - if (!hw_dom->arch_mbm_total) - return -ENOMEM; - } - if (resctrl_is_mon_event_enabled(QOS_L3_MBM_LOCAL_EVENT_ID)) { - tsize =3D sizeof(*hw_dom->arch_mbm_local); - hw_dom->arch_mbm_local =3D kcalloc(num_rmid, tsize, GFP_KERNEL); - if (!hw_dom->arch_mbm_local) { - kfree(hw_dom->arch_mbm_total); - hw_dom->arch_mbm_total =3D NULL; - return -ENOMEM; - } + size_t tsize =3D sizeof(struct arch_mbm_state); + enum resctrl_event_id evt; + int idx; + + for_each_mbm_event(evt) { + if (!resctrl_is_mon_event_enabled(evt)) + continue; + idx =3D MBM_STATE_IDX(evt); + hw_dom->arch_mbm_states[idx] =3D kcalloc(num_rmid, tsize, GFP_KERNEL); + if (!hw_dom->arch_mbm_states[idx]) + goto cleanup; } =20 return 0; +cleanup: + while (--idx >=3D 0) { + kfree(hw_dom->arch_mbm_states[idx]); + hw_dom->arch_mbm_states[idx] =3D NULL; + } + + return -ENOMEM; } =20 static int get_domain_id_from_scope(int cpu, enum resctrl_scope scope) diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/re= sctrl/monitor.c index fda579251dba..85526e5540f2 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -160,18 +160,14 @@ static struct arch_mbm_state *get_arch_mbm_state(stru= ct rdt_hw_mon_domain *hw_do u32 rmid, enum resctrl_event_id eventid) { - switch (eventid) { - case QOS_L3_OCCUP_EVENT_ID: - return NULL; - case QOS_L3_MBM_TOTAL_EVENT_ID: - return &hw_dom->arch_mbm_total[rmid]; - case QOS_L3_MBM_LOCAL_EVENT_ID: - return &hw_dom->arch_mbm_local[rmid]; - default: - /* Never expect to get here */ - WARN_ON_ONCE(1); + struct arch_mbm_state *state; + + if (!resctrl_is_mbm_event(eventid)) return NULL; - } + + state =3D hw_dom->arch_mbm_states[MBM_STATE_IDX(eventid)]; + + return state ? &state[rmid] : NULL; } =20 void resctrl_arch_reset_rmid(struct rdt_resource *r, struct rdt_mon_domain= *d, @@ -200,14 +196,16 @@ void resctrl_arch_reset_rmid(struct rdt_resource *r, = struct rdt_mon_domain *d, void resctrl_arch_reset_rmid_all(struct rdt_resource *r, struct rdt_mon_do= main *d) { struct rdt_hw_mon_domain *hw_dom =3D resctrl_to_arch_mon_dom(d); - - if (resctrl_is_mon_event_enabled(QOS_L3_MBM_TOTAL_EVENT_ID)) - memset(hw_dom->arch_mbm_total, 0, - sizeof(*hw_dom->arch_mbm_total) * r->num_rmid); - - if (resctrl_is_mon_event_enabled(QOS_L3_MBM_LOCAL_EVENT_ID)) - memset(hw_dom->arch_mbm_local, 0, - sizeof(*hw_dom->arch_mbm_local) * r->num_rmid); + enum resctrl_event_id evt; + int idx; + + for_each_mbm_event(evt) { + idx =3D MBM_STATE_IDX(evt); + if (!hw_dom->arch_mbm_states[idx]) + continue; + memset(hw_dom->arch_mbm_states[idx], 0, + sizeof(struct arch_mbm_state) * r->num_rmid); + } } =20 static u64 mbm_overflow_count(u64 prev_msr, u64 cur_msr, unsigned int widt= h) diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c index 325e23c1a403..4cd0789998bf 100644 --- a/fs/resctrl/monitor.c +++ b/fs/resctrl/monitor.c @@ -346,15 +346,14 @@ static struct mbm_state *get_mbm_state(struct rdt_mon= _domain *d, u32 closid, u32 rmid, enum resctrl_event_id evtid) { u32 idx =3D resctrl_arch_rmid_idx_encode(closid, rmid); + struct mbm_state *states; =20 - switch (evtid) { - case QOS_L3_MBM_TOTAL_EVENT_ID: - return &d->mbm_total[idx]; - case QOS_L3_MBM_LOCAL_EVENT_ID: - return &d->mbm_local[idx]; - default: + if (!resctrl_is_mbm_event(evtid)) return NULL; - } + + states =3D d->mbm_states[MBM_STATE_IDX(evtid)]; + + return states ? &states[idx] : NULL; } =20 static int __mon_event_count(u32 closid, u32 rmid, struct rmid_read *rr) diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index 80e74940281a..8649b89d7bfd 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -127,12 +127,6 @@ static bool resctrl_is_mbm_enabled(void) resctrl_is_mon_event_enabled(QOS_L3_MBM_LOCAL_EVENT_ID)); } =20 -static bool resctrl_is_mbm_event(int e) -{ - return (e >=3D QOS_L3_MBM_TOTAL_EVENT_ID && - e <=3D QOS_L3_MBM_LOCAL_EVENT_ID); -} - /* * Trivial allocator for CLOSIDs. Use BITMAP APIs to manipulate a bitmap * of free CLOSIDs. @@ -4020,8 +4014,10 @@ static void rdtgroup_setup_default(void) static void domain_destroy_mon_state(struct rdt_mon_domain *d) { bitmap_free(d->rmid_busy_llc); - kfree(d->mbm_total); - kfree(d->mbm_local); + for (int i =3D 0; i < QOS_NUM_L3_MBM_EVENTS; i++) { + kfree(d->mbm_states[i]); + d->mbm_states[i] =3D NULL; + } } =20 void resctrl_offline_ctrl_domain(struct rdt_resource *r, struct rdt_ctrl_d= omain *d) @@ -4081,32 +4077,34 @@ void resctrl_offline_mon_domain(struct rdt_resource= *r, struct rdt_mon_domain *d static int domain_setup_mon_state(struct rdt_resource *r, struct rdt_mon_d= omain *d) { u32 idx_limit =3D resctrl_arch_system_num_rmid_idx(); - size_t tsize; + size_t tsize =3D sizeof(struct mbm_state); + enum resctrl_event_id evt; + int idx; =20 if (resctrl_is_mon_event_enabled(QOS_L3_OCCUP_EVENT_ID)) { d->rmid_busy_llc =3D bitmap_zalloc(idx_limit, GFP_KERNEL); if (!d->rmid_busy_llc) return -ENOMEM; } - if (resctrl_is_mon_event_enabled(QOS_L3_MBM_TOTAL_EVENT_ID)) { - tsize =3D sizeof(*d->mbm_total); - d->mbm_total =3D kcalloc(idx_limit, tsize, GFP_KERNEL); - if (!d->mbm_total) { - bitmap_free(d->rmid_busy_llc); - return -ENOMEM; - } - } - if (resctrl_is_mon_event_enabled(QOS_L3_MBM_LOCAL_EVENT_ID)) { - tsize =3D sizeof(*d->mbm_local); - d->mbm_local =3D kcalloc(idx_limit, tsize, GFP_KERNEL); - if (!d->mbm_local) { - bitmap_free(d->rmid_busy_llc); - kfree(d->mbm_total); - return -ENOMEM; - } + + for_each_mbm_event(evt) { + if (!resctrl_is_mon_event_enabled(evt)) + continue; + idx =3D MBM_STATE_IDX(evt); + d->mbm_states[idx] =3D kcalloc(idx_limit, tsize, GFP_KERNEL); + if (!d->mbm_states[idx]) + goto cleanup; } =20 return 0; +cleanup: + bitmap_free(d->rmid_busy_llc); + while (--idx >=3D 0) { + kfree(d->mbm_states[idx]); + d->mbm_states[idx] =3D NULL; + } + + return -ENOMEM; } =20 int resctrl_online_ctrl_domain(struct rdt_resource *r, struct rdt_ctrl_dom= ain *d) --=20 2.49.0 From nobody Sun Dec 14 19:24:21 2025 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 9650423AE83 for ; Wed, 21 May 2025 22:51:01 +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=1747867863; cv=none; b=ljvJ0XvmF1RmslxO7DNCA8zJ6XchbHetzXnvxdaPy4qaWYy7z7bFiyoW3FUGAWOrbvQxH21m1AmSTWoGkeFCMMBNvXgeoMWuxk/01esnNFwgXz+cFNyc2ddvsCOpucWXew/iOiP402J8Xe7GsU34BbyNG+woEK49n03HXq+I2+Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747867863; c=relaxed/simple; bh=u4remCQ7yALVTBfJjdkLnvJkrC2xewpiTnEZzkuYuRY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SQ1Id5vzGTwDJ4kA4IlTzCHc/12kWL8fWftv5UMJEv22UJ4483FZzSouKU6YnsrVPoO6JUJyUdsM2RhAwUskGaD4S8FQzuPtrteFgxUGKDdgdDKNGXpqzMOiNWaZcDSmFzXVI2OTBFSA2YahxZAB6HCNyz11/4wTx5CRj0uZkm4= 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=YJW6yMQp; 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="YJW6yMQp" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1747867862; x=1779403862; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=u4remCQ7yALVTBfJjdkLnvJkrC2xewpiTnEZzkuYuRY=; b=YJW6yMQpOkGWGJIQXQSOvx+t9aGfHsY+Z8l0YSJrejhQ29IvlU8HBji7 xwlASjl6aO4VbxpFXOG7Zedb7Xgs1sytOXbtz6z2SZRKeADVvb4kNqqrp q8y4Ym/H0WWBc/g34ldMh8XYiWuKvtO3gDoe+iqLfJWEsfil6iBlbQOmO HaW77rCot4ODNIDZk+5uZTuonujVf9lbwP0Kl+272bJxXAyBJqMR38SEb Ml50y0vZvHrL8rEnD30YIGobSSsQ8nNLwN05z2J8wSlQzUvIoj+odV6Xs qeOradbBNF8jMpAHj5D8688TjmRJimDAI6jvNzemyS5XEpp9yW9Wbu+mA Q==; X-CSE-ConnectionGUID: +WOT4S1xSaGi6QLFCccfOQ== X-CSE-MsgGUID: 2y/gCD1MQge0U3P7XHEqBA== X-IronPort-AV: E=McAfee;i="6700,10204,11440"; a="53677638" X-IronPort-AV: E=Sophos;i="6.15,304,1739865600"; d="scan'208";a="53677638" 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:57 -0700 X-CSE-ConnectionGUID: bM6/BJxpR3uJrpyA/7psjg== X-CSE-MsgGUID: GXy8KqfiRCilRGKzDZc1AA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,304,1739865600"; d="scan'208";a="141352135" 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:57 -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 05/29] x86/rectrl: Fake OOBMSM interface Date: Wed, 21 May 2025 15:50:23 -0700 Message-ID: <20250521225049.132551-6-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" Real version is coming soon[1] ... this is here so the remaining parts will build (and run ... assuming a 2 socket system that supports RDT monitoring ... only missing part is that the event counters just report fixed values). Faked values are provided to exercise some special conditions: 1) Multiple counter aggregators for an event per-socket. 2) Different number of supported RMIDs for each group. Just for ease of testing and RFC discussion. [1] Link: https://lore.kernel.org/all/20250430212106.369208-1-david.e.box@linux= .intel.com/ Signed-off-by: Tony Luck --- .../cpu/resctrl/fake_intel_aet_features.h | 73 ++++++++++++++ .../cpu/resctrl/fake_intel_aet_features.c | 97 +++++++++++++++++++ arch/x86/kernel/cpu/resctrl/Makefile | 1 + 3 files changed, 171 insertions(+) create mode 100644 arch/x86/kernel/cpu/resctrl/fake_intel_aet_features.h create mode 100644 arch/x86/kernel/cpu/resctrl/fake_intel_aet_features.c diff --git a/arch/x86/kernel/cpu/resctrl/fake_intel_aet_features.h b/arch/x= 86/kernel/cpu/resctrl/fake_intel_aet_features.h new file mode 100644 index 000000000000..c835c4108abc --- /dev/null +++ b/arch/x86/kernel/cpu/resctrl/fake_intel_aet_features.h @@ -0,0 +1,73 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* Bits stolen from OOBMSM VSEC discovery code */ + +enum pmt_feature_id { + FEATURE_INVALID =3D 0x0, + FEATURE_PER_CORE_PERF_TELEM =3D 0x1, + FEATURE_PER_CORE_ENV_TELEM =3D 0x2, + FEATURE_PER_RMID_PERF_TELEM =3D 0x3, + FEATURE_ACCEL_TELEM =3D 0x4, + FEATURE_UNCORE_TELEM =3D 0x5, + FEATURE_CRASH_LOG =3D 0x6, + FEATURE_PETE_LOG =3D 0x7, + FEATURE_TPMI_CTRL =3D 0x8, + FEATURE_RESERVED =3D 0x9, + FEATURE_TRACING =3D 0xA, + FEATURE_PER_RMID_ENERGY_TELEM =3D 0xB, + FEATURE_MAX =3D 0xB, +}; + +/** + * struct oobmsm_plat_info - Platform information for a device instance + * @cdie_mask: Mask of all compute dies in the partition + * @package_id: CPU Package id + * @partition: Package partition id when multiple VSEC PCI devices p= er package + * @segment: PCI segment ID + * @bus_number: PCI bus number + * @device_number: PCI device number + * @function_number: PCI function number + * + * Structure to store platform data for a OOBMSM device instance. + */ +struct oobmsm_plat_info { + u16 cdie_mask; + u8 package_id; + u8 partition; + u8 segment; + u8 bus_number; + u8 device_number; + u8 function_number; +}; + +enum oobmsm_supplier_type { + OOBMSM_SUP_PLAT_INFO, + OOBMSM_SUP_DISC_INFO, + OOBMSM_SUP_S3M_SIMICS, + OOBMSM_SUP_TYPE_MAX +}; + +struct oobmsm_mapping_supplier { + struct device *supplier_dev[OOBMSM_SUP_TYPE_MAX]; + struct oobmsm_plat_info plat_info; + unsigned long features; +}; + +struct telemetry_region { + struct oobmsm_plat_info plat_info; + void __iomem *addr; + size_t size; + u32 guid; + u32 num_rmids; +}; + +struct pmt_feature_group { + enum pmt_feature_id id; + int count; + struct kref kref; + struct telemetry_region regions[]; +}; + +struct pmt_feature_group *intel_pmt_get_regions_by_feature(enum pmt_featur= e_id id); + +void intel_pmt_put_feature_group(struct pmt_feature_group *feature_group); diff --git a/arch/x86/kernel/cpu/resctrl/fake_intel_aet_features.c b/arch/x= 86/kernel/cpu/resctrl/fake_intel_aet_features.c new file mode 100644 index 000000000000..80f38f1ee3df --- /dev/null +++ b/arch/x86/kernel/cpu/resctrl/fake_intel_aet_features.c @@ -0,0 +1,97 @@ +// SPDX-License-Identifier: GPL-2.0-only +#include +#include +#include +#include "fake_intel_aet_features.h" +#include +#include + +#include "internal.h" + +/* + * Amount of memory for each fake MMIO space + * Magic numbers here match values for XML ID 0x26696143 and 0x26557651 + * 576: Number of RMIDs + * 2: Energy events in 0x26557651 + * 7: Perf events in 0x26696143 + * 3: Qwords for status counters after the event counters + * 8: Bytes for each counter + */ + +#define ENERGY_QWORDS ((576 * 2) + 3) +#define ENERGY_SIZE (ENERGY_QWORDS * 8) +#define PERF_QWORDS ((576 * 7) + 3) +#define PERF_SIZE (PERF_QWORDS * 8) + +static long pg[4 * ENERGY_QWORDS + 2 * PERF_QWORDS]; + +/* + * Fill the fake MMIO space with all different values, + * all with BIT(63) set to indicate valid entries. + */ +static int __init fill(void) +{ + u64 val =3D 0; + + for (int i =3D 0; i < sizeof(pg); i +=3D sizeof(val)) { + pg[i / sizeof(val)] =3D BIT_ULL(63) + val; + val++; + } + return 0; +} +device_initcall(fill); + +#define PKG_REGION(_entry, _guid, _addr, _size, _pkg, _num_rmids) \ + [_entry] =3D { .guid =3D _guid, .addr =3D (void __iomem *)_addr, \ + .num_rmids =3D _num_rmids, \ + .size =3D _size, .plat_info =3D { .package_id =3D _pkg }} + +/* + * Set up a fake return for call to: + * intel_pmt_get_regions_by_feature(FEATURE_PER_RMID_ENERGY_TELEM); + * Pretend there are two aggregators on each of the sockets to test + * the code that sums over multiple aggregators. + * Pretend this group only supports 64 RMIDs to exercise the code + * that reconciles support for different RMID counts. + */ +static struct pmt_feature_group fake_energy =3D { + .count =3D 4, + .regions =3D { + PKG_REGION(0, 0x26696143, &pg[0 * ENERGY_QWORDS], ENERGY_SIZE, 0, 64), + PKG_REGION(1, 0x26696143, &pg[1 * ENERGY_QWORDS], ENERGY_SIZE, 0, 64), + PKG_REGION(2, 0x26696143, &pg[2 * ENERGY_QWORDS], ENERGY_SIZE, 1, 64), + PKG_REGION(3, 0x26696143, &pg[3 * ENERGY_QWORDS], ENERGY_SIZE, 1, 64) + } +}; + +/* + * Fake return for: + * intel_pmt_get_regions_by_feature(FEATURE_PER_RMID_PERF_TELEM); + */ +static struct pmt_feature_group fake_perf =3D { + .count =3D 2, + .regions =3D { + PKG_REGION(0, 0x26557651, &pg[4 * ENERGY_QWORDS + 0 * PERF_QWORDS], PERF= _SIZE, 0, 576), + PKG_REGION(1, 0x26557651, &pg[4 * ENERGY_QWORDS + 1 * PERF_QWORDS], PERF= _SIZE, 1, 576) + } +}; + +struct pmt_feature_group * +intel_pmt_get_regions_by_feature(enum pmt_feature_id id) +{ + switch (id) { + case FEATURE_PER_RMID_ENERGY_TELEM: + return &fake_energy; + case FEATURE_PER_RMID_PERF_TELEM: + return &fake_perf; + default: + return ERR_PTR(-ENOENT); + } +} + +/* + * Nothing needed for the "put" function. + */ +void intel_pmt_put_feature_group(struct pmt_feature_group *feature_group) +{ +} diff --git a/arch/x86/kernel/cpu/resctrl/Makefile b/arch/x86/kernel/cpu/res= ctrl/Makefile index d8a04b195da2..cf4fac58d068 100644 --- a/arch/x86/kernel/cpu/resctrl/Makefile +++ b/arch/x86/kernel/cpu/resctrl/Makefile @@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_X86_CPU_RESCTRL) +=3D core.o rdtgroup.o monitor.o obj-$(CONFIG_X86_CPU_RESCTRL) +=3D ctrlmondata.o +obj-$(CONFIG_X86_CPU_RESCTRL) +=3D fake_intel_aet_features.o obj-$(CONFIG_RESCTRL_FS_PSEUDO_LOCK) +=3D pseudo_lock.o =20 # To allow define_trace.h's recursive include: --=20 2.49.0 From nobody Sun Dec 14 19:24:21 2025 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 09A6923BF8F for ; Wed, 21 May 2025 22:51:03 +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=1747867865; cv=none; b=s+241CEyT6k2EWnN/hiTC3ikvVgt6BzF3UG8d8Hs57P3aaI6U1KXCrGTdmwHNpPltJzzdT7cjbI+aBue/6oOHmRZmgc4qdIhBK0EEzgh52XJyS5YYPCupAddaV4tzamB5c70DNW8qbJuxc+OXD/yM5QpbvH2FGXj8Ye9wkD8xpE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747867865; c=relaxed/simple; bh=OrRpV3I1kmApqu7pISV/Fdj42l5xdyQgmRM4iWRKWNc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AtvO+LXv2ydSDouFKDx6IiXmLM4DuqsvMuNB92go7+DShcVnG+j3i2+uNeS3HKSr15TpNEQcMsodTZjv567iA2e3ft1W+d2E4rcJxsnaFBdLad08T8HNY3jiwFCOjolVPP3cy+NlZZZy2wxquhDlqyv97acSOLx5/dmAp3MgC0g= 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=jrFwTvih; 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="jrFwTvih" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1747867863; x=1779403863; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OrRpV3I1kmApqu7pISV/Fdj42l5xdyQgmRM4iWRKWNc=; b=jrFwTvihhgzlHiQsWwyPt46m2l6sDQFt8oWixmFHtJJRSxY3zHsHzCSI TA5G/rJI2PGw9TZwobT3eYXB78fcomq76StKT87rb8QWyNDzR/6Hl8UBr zPf+kT97JpA+S9KG5fb6QZh68ee8c9ZD64hJsnVYFozh2BiKE88tum9Yp 5L10ij89FecNVopSz7OKa/YGGgLea6d8AqxavWyqQH9lBxG9z8MbrJ1Yu Bo49GH7iCuLvy4as3EBfDZDxtXQVu/R8/OyPEfrFnN84EcfdiPUAME5LW VZZz0lIuu0u2ejWkc3z4b2w5MxrihdYWav3sfh1gJNBLpDbxnKOoCZcbx g==; X-CSE-ConnectionGUID: 9AnioJS4RLGId5Cz5elplQ== X-CSE-MsgGUID: 13jAAa91Snu6DB6/pRuzPQ== X-IronPort-AV: E=McAfee;i="6700,10204,11440"; a="53677643" X-IronPort-AV: E=Sophos;i="6.15,304,1739865600"; d="scan'208";a="53677643" 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:57 -0700 X-CSE-ConnectionGUID: Fp0hbPWFTSOgI1IL2ghIhw== X-CSE-MsgGUID: j3w5u8wQR4ab2DSZtJXu1w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,304,1739865600"; d="scan'208";a="141352138" 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:57 -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 06/29] x86,fs/resctrl: Improve domain type checking Date: Wed, 21 May 2025 15:50:24 -0700 Message-ID: <20250521225049.132551-7-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" The rdt_domain_hdr structure is used in both control and monitor domain structures to provide common methods for operations such as adding a CPU to a domain, removing a CPU from a domain, accessing the mask of all CPUs in a domain. The "type" field provides a simple check whether a domain is a control or monitor domain so that programming errors operating on domains will be quickly caught. To prepare for additional domain types that depend on the rdt_resource to which they are connected add the resource id into the header and check that in addition to the type. Signed-off-by: Tony Luck --- include/linux/resctrl.h | 9 +++++++++ arch/x86/kernel/cpu/resctrl/core.c | 10 ++++++---- fs/resctrl/ctrlmondata.c | 2 +- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index 40f2d0d48d02..d6b09952ef92 100644 --- a/include/linux/resctrl.h +++ b/include/linux/resctrl.h @@ -131,15 +131,24 @@ enum resctrl_domain_type { * @list: all instances of this resource * @id: unique id for this instance * @type: type of this instance + * @rid: index of resource for this domain * @cpu_mask: which CPUs share this resource */ struct rdt_domain_hdr { struct list_head list; int id; enum resctrl_domain_type type; + enum resctrl_res_level rid; struct cpumask cpu_mask; }; =20 +static inline bool domain_header_is_valid(struct rdt_domain_hdr *hdr, + enum resctrl_domain_type type, + enum resctrl_res_level rid) +{ + return !WARN_ON_ONCE(hdr->type !=3D type || hdr->rid !=3D rid); +} + /** * struct rdt_ctrl_domain - group of CPUs sharing a resctrl control resour= ce * @hdr: common header for different domain types diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resct= rl/core.c index 4403a820db12..4983f6f81218 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -456,7 +456,7 @@ static void domain_add_cpu_ctrl(int cpu, struct rdt_res= ource *r) =20 hdr =3D resctrl_find_domain(&r->ctrl_domains, id, &add_pos); if (hdr) { - if (WARN_ON_ONCE(hdr->type !=3D RESCTRL_CTRL_DOMAIN)) + if (!domain_header_is_valid(hdr, RESCTRL_CTRL_DOMAIN, r->rid)) return; d =3D container_of(hdr, struct rdt_ctrl_domain, hdr); =20 @@ -473,6 +473,7 @@ static void domain_add_cpu_ctrl(int cpu, struct rdt_res= ource *r) d =3D &hw_dom->d_resctrl; d->hdr.id =3D id; d->hdr.type =3D RESCTRL_CTRL_DOMAIN; + d->hdr.rid =3D r->rid; cpumask_set_cpu(cpu, &d->hdr.cpu_mask); =20 rdt_domain_reconfigure_cdp(r); @@ -511,7 +512,7 @@ static void domain_add_cpu_mon(int cpu, struct rdt_reso= urce *r) =20 hdr =3D resctrl_find_domain(&r->mon_domains, id, &add_pos); if (hdr) { - if (WARN_ON_ONCE(hdr->type !=3D RESCTRL_MON_DOMAIN)) + if (!domain_header_is_valid(hdr, RESCTRL_MON_DOMAIN, r->rid)) return; d =3D container_of(hdr, struct rdt_mon_domain, hdr); =20 @@ -526,6 +527,7 @@ static void domain_add_cpu_mon(int cpu, struct rdt_reso= urce *r) d =3D &hw_dom->d_resctrl; d->hdr.id =3D id; d->hdr.type =3D RESCTRL_MON_DOMAIN; + d->hdr.rid =3D r->rid; d->ci =3D get_cpu_cacheinfo_level(cpu, RESCTRL_L3_CACHE); if (!d->ci) { pr_warn_once("Can't find L3 cache for CPU:%d resource %s\n", cpu, r->nam= e); @@ -581,7 +583,7 @@ static void domain_remove_cpu_ctrl(int cpu, struct rdt_= resource *r) return; } =20 - if (WARN_ON_ONCE(hdr->type !=3D RESCTRL_CTRL_DOMAIN)) + if (!domain_header_is_valid(hdr, RESCTRL_CTRL_DOMAIN, r->rid)) return; =20 d =3D container_of(hdr, struct rdt_ctrl_domain, hdr); @@ -627,7 +629,7 @@ static void domain_remove_cpu_mon(int cpu, struct rdt_r= esource *r) return; } =20 - if (WARN_ON_ONCE(hdr->type !=3D RESCTRL_MON_DOMAIN)) + if (!domain_header_is_valid(hdr, RESCTRL_MON_DOMAIN, r->rid)) return; =20 d =3D container_of(hdr, struct rdt_mon_domain, hdr); diff --git a/fs/resctrl/ctrlmondata.c b/fs/resctrl/ctrlmondata.c index 6be423c5e2e0..7d16f7eb6985 100644 --- a/fs/resctrl/ctrlmondata.c +++ b/fs/resctrl/ctrlmondata.c @@ -638,7 +638,7 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg) * the resource to find the domain with "domid". */ hdr =3D resctrl_find_domain(&r->mon_domains, domid, NULL); - if (!hdr || WARN_ON_ONCE(hdr->type !=3D RESCTRL_MON_DOMAIN)) { + if (!hdr || !domain_header_is_valid(hdr, RESCTRL_MON_DOMAIN, r->rid)) { ret =3D -ENOENT; goto out; } --=20 2.49.0 From nobody Sun Dec 14 19:24:21 2025 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 94F1A23BD05 for ; Wed, 21 May 2025 22:51:02 +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=1747867864; cv=none; b=OEln0L4nsmooS4Wp28dw894GqrMEyQtYhR9tZWcpag85wtQCxIxh2KIqDQl9INI57uaaQtaw0oZbbHgpmpcA0jPJVK7hUeZT34TV/0j1B+SzVeoDZ3dQMmCuA6kmnu68sePiz3TMMeOrMfbytyzLNCMGQPMbYP2Pi4JUDhlB9jc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747867864; c=relaxed/simple; bh=bxm0GFpFfi1yDG0odbhafAGnb4KiXJUTK0G7cRb0SGA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BeL2KyTwAqXpqz98gDHeRvER+/ivYCmWJ25UO0lotZss9y/Hbu2G9MHs84FMpKZEITpcWF43ix7KBtotmddPt8mjrS8gDZkPG77caphTp+AQTE3BQ8eFWKvNkvy8KynxwP/MehctG+jJvUxGC0zd6/+IePBMjRLpUiyGQnK36b0= 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=fyzPsUcH; 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="fyzPsUcH" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1747867863; x=1779403863; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=bxm0GFpFfi1yDG0odbhafAGnb4KiXJUTK0G7cRb0SGA=; b=fyzPsUcH72qTEGHCQbhnc+zrI6VM2evvGAG5IA1IuW51AAIktOCrAn3S LDHEv9nwc2sqJWHggyoQetkfXASDxi0Pj96E+Z0Qm3+GJLIkqtI6r2zwc ko0mwbqvjXzAezUPmYdY9lqPxH3oCNPp/7+LLCPMjrynDOtzoz8KT20PG 6DPUVJAXlr3zxP8iYGH5tVtA62Fj0pYg1UJ0DDauR+RuRBiWyK3lypG3Z JI3UeUQwiIHBe34WaqTZ2igaxJkfZllX4AZxw39LrAZt81v8IJN4uA3Ph aNJ2UF63aPl70kZtsjSVGbJE3kBYm4dvEkECHzAAIl9PTqxSsAGETeUAM A==; X-CSE-ConnectionGUID: NeUnS0iqToWSJ762L/PytQ== X-CSE-MsgGUID: WjhZkApcShqI3576e6ghpQ== X-IronPort-AV: E=McAfee;i="6700,10204,11440"; a="53677651" X-IronPort-AV: E=Sophos;i="6.15,304,1739865600"; d="scan'208";a="53677651" 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:57 -0700 X-CSE-ConnectionGUID: I/VhpvHjQwqhGato0zTXTw== X-CSE-MsgGUID: Ppc3bJ/dTDO/R3A+SUx5cA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,304,1739865600"; d="scan'208";a="141352141" 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:57 -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 07/29] x86,fs/resctrl: Rename some L3 specific functions Date: Wed, 21 May 2025 15:50:25 -0700 Message-ID: <20250521225049.132551-8-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" All monitor events used to be connected to the L3 resource so it was OK for function names to be generic. But this will cause confusion with additional events tied to other resources. Rename functions that are only used for L3 features: arch_mon_domain_online() -> arch_l3_mon_domain_online() mon_domain_free() -> l3_mon_domain_free() domain_setup_mon_state() -> domain_setup_l3_mon_state No functional change. Signed-off-by: Tony Luck --- arch/x86/kernel/cpu/resctrl/internal.h | 2 +- arch/x86/kernel/cpu/resctrl/core.c | 12 ++++++------ arch/x86/kernel/cpu/resctrl/monitor.c | 2 +- fs/resctrl/rdtgroup.c | 6 +++--- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/r= esctrl/internal.h index ea185b4d0d59..038c888dcdcf 100644 --- a/arch/x86/kernel/cpu/resctrl/internal.h +++ b/arch/x86/kernel/cpu/resctrl/internal.h @@ -122,7 +122,7 @@ static inline struct rdt_hw_resource *resctrl_to_arch_r= es(struct rdt_resource *r =20 extern struct rdt_hw_resource rdt_resources_all[]; =20 -void arch_mon_domain_online(struct rdt_resource *r, struct rdt_mon_domain = *d); +void arch_l3_mon_domain_online(struct rdt_resource *r, struct rdt_mon_doma= in *d); =20 /* CPUID.(EAX=3D10H, ECX=3DResID=3D1).EAX */ union cpuid_0x10_1_eax { diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resct= rl/core.c index 4983f6f81218..c721d1712e97 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -362,7 +362,7 @@ static void ctrl_domain_free(struct rdt_hw_ctrl_domain = *hw_dom) kfree(hw_dom); } =20 -static void mon_domain_free(struct rdt_hw_mon_domain *hw_dom) +static void l3_mon_domain_free(struct rdt_hw_mon_domain *hw_dom) { for (int i =3D 0; i < QOS_NUM_L3_MBM_EVENTS; i++) kfree(hw_dom->arch_mbm_states[i]); @@ -531,15 +531,15 @@ static void domain_add_cpu_mon(int cpu, struct rdt_re= source *r) d->ci =3D get_cpu_cacheinfo_level(cpu, RESCTRL_L3_CACHE); if (!d->ci) { pr_warn_once("Can't find L3 cache for CPU:%d resource %s\n", cpu, r->nam= e); - mon_domain_free(hw_dom); + l3_mon_domain_free(hw_dom); return; } cpumask_set_cpu(cpu, &d->hdr.cpu_mask); =20 - arch_mon_domain_online(r, d); + arch_l3_mon_domain_online(r, d); =20 if (arch_domain_mbm_alloc(r->num_rmid, hw_dom)) { - mon_domain_free(hw_dom); + l3_mon_domain_free(hw_dom); return; } =20 @@ -549,7 +549,7 @@ static void domain_add_cpu_mon(int cpu, struct rdt_reso= urce *r) if (err) { list_del_rcu(&d->hdr.list); synchronize_rcu(); - mon_domain_free(hw_dom); + l3_mon_domain_free(hw_dom); } } =20 @@ -640,7 +640,7 @@ static void domain_remove_cpu_mon(int cpu, struct rdt_r= esource *r) resctrl_offline_mon_domain(r, d); list_del_rcu(&d->hdr.list); synchronize_rcu(); - mon_domain_free(hw_dom); + l3_mon_domain_free(hw_dom); =20 return; } diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/re= sctrl/monitor.c index 85526e5540f2..659265330783 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -264,7 +264,7 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, stru= ct rdt_mon_domain *d, * must adjust RMID counter numbers based on SNC node. See * logical_rmid_to_physical_rmid() for code that does this. */ -void arch_mon_domain_online(struct rdt_resource *r, struct rdt_mon_domain = *d) +void arch_l3_mon_domain_online(struct rdt_resource *r, struct rdt_mon_doma= in *d) { if (snc_nodes_per_l3_cache > 1) msr_clear_bit(MSR_RMID_SNC_CONFIG, 0); diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index 8649b89d7bfd..8aa9a7e68a59 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -4062,7 +4062,7 @@ void resctrl_offline_mon_domain(struct rdt_resource *= r, struct rdt_mon_domain *d } =20 /** - * domain_setup_mon_state() - Initialise domain monitoring structures. + * domain_setup_l3_mon_state() - Initialise domain monitoring structures. * @r: The resource for the newly online domain. * @d: The newly online domain. * @@ -4074,7 +4074,7 @@ void resctrl_offline_mon_domain(struct rdt_resource *= r, struct rdt_mon_domain *d * * Returns 0 for success, or -ENOMEM. */ -static int domain_setup_mon_state(struct rdt_resource *r, struct rdt_mon_d= omain *d) +static int domain_setup_l3_mon_state(struct rdt_resource *r, struct rdt_mo= n_domain *d) { u32 idx_limit =3D resctrl_arch_system_num_rmid_idx(); size_t tsize =3D sizeof(struct mbm_state); @@ -4129,7 +4129,7 @@ int resctrl_online_mon_domain(struct rdt_resource *r,= struct rdt_mon_domain *d) =20 mutex_lock(&rdtgroup_mutex); =20 - err =3D domain_setup_mon_state(r, d); + err =3D domain_setup_l3_mon_state(r, d); if (err) goto out_unlock; =20 --=20 2.49.0 From nobody Sun Dec 14 19:24:21 2025 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 7E03E23C4F4 for ; Wed, 21 May 2025 22:51:03 +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=1747867865; cv=none; b=C6w78A+ZLTUvkcmMW55jVYljdnynRsVMeT0B2l//qwnRUyH0fSIgzr3rD1Si5YaZDBkYDZ3FOSQ51vENbyft+g4X22E6y4tg9LmYOPP2VlPb95OB1hXsQs65Sg2eRotOlMmIx/f3+HzjTkihx96vPg9mg5iA+rAwXceoXbSEqWg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747867865; c=relaxed/simple; bh=AlGp/WzhswgLTg6Sf2jDcddhQNvZ6OI3nQs2xzlNejU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZiJREuy/c8TNfAd+OPhKA7lTJtB+jK/k3C/HBAaAbvGgOkiHC8PQ0bO9dp4W7wIpHxZRRSQ5SNXZsDg3E4uJGPDMkPhtqjswX1M9RR4BdRTG6FqQ+aCjOrm1XH1+kBYyB/zQnJepVBu34vehCIQHx/8Z+h6wt+N8DUwKGtfFC+0= 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=Gr2fvddJ; 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="Gr2fvddJ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1747867863; x=1779403863; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=AlGp/WzhswgLTg6Sf2jDcddhQNvZ6OI3nQs2xzlNejU=; b=Gr2fvddJ2jPlGryOK9Z0EGeyDciFGD5xMwG1tbuanmKLvcYjuIz4Kr1R j6junHM9Fc/3DJkq1vaiMn8RPRFnwW7OYSUZ1K6faCpxZ+2s9UmZp1q1s q1wnF009ZCTtPDqpjMv2jL1Xi3HTZhIea+OjCT5HbmIVykj7sl+kbCKOz 0cOoBxqH9BtMxK9aYBe8Mc02WLVE3PL32fh66copaPv6jLwmFlquVTkql RVUV6f10zJ1mt2rl1qog83GibAuZdqHjqb3RJKkXAv7g0k5Qr60xX65Aq dh7eQjIN7CW3X4xnVIl2VCPZxyZRdpXNx0jfhNujwPBiqnX5Q1TP5GqDX g==; X-CSE-ConnectionGUID: ANu9ZWPpSkGs3bKFHq5ETw== X-CSE-MsgGUID: MQ4hvobJT5+EHW72KFl1mw== X-IronPort-AV: E=McAfee;i="6700,10204,11440"; a="53677658" X-IronPort-AV: E=Sophos;i="6.15,304,1739865600"; d="scan'208";a="53677658" 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:57 -0700 X-CSE-ConnectionGUID: eGYhwU6kT6+gW0sCTS0J3Q== X-CSE-MsgGUID: 9fGYt8ZrQTqWe4cezWP5Yg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,304,1739865600"; d="scan'208";a="141352144" 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:57 -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 08/29] x86/resctrl: Move L3 initialization out of domain_add_cpu_mon() Date: Wed, 21 May 2025 15:50:26 -0700 Message-ID: <20250521225049.132551-9-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" To prepare for additional types of monitoring domains, move all the L3 resource monitoring domain initialization out of domain_add_cpu_mon() and into a new helper function l3_mon_domain_setup() (name chosen as the partner of existing l3_mon_domain_free()). Signed-off-by: Tony Luck --- arch/x86/kernel/cpu/resctrl/core.c | 55 ++++++++++++++++++------------ 1 file changed, 33 insertions(+), 22 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resct= rl/core.c index c721d1712e97..990a0c1af634 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -493,33 +493,12 @@ static void domain_add_cpu_ctrl(int cpu, struct rdt_r= esource *r) } } =20 -static void domain_add_cpu_mon(int cpu, struct rdt_resource *r) +static void l3_mon_domain_setup(int cpu, int id, struct rdt_resource *r, s= truct list_head *add_pos) { - int id =3D get_domain_id_from_scope(cpu, r->mon_scope); - struct list_head *add_pos =3D NULL; struct rdt_hw_mon_domain *hw_dom; - struct rdt_domain_hdr *hdr; struct rdt_mon_domain *d; int err; =20 - lockdep_assert_held(&domain_list_lock); - - if (id < 0) { - pr_warn_once("Can't find monitor domain id for CPU:%d scope:%d for resou= rce %s\n", - cpu, r->mon_scope, r->name); - return; - } - - hdr =3D resctrl_find_domain(&r->mon_domains, id, &add_pos); - if (hdr) { - if (!domain_header_is_valid(hdr, RESCTRL_MON_DOMAIN, r->rid)) - return; - d =3D container_of(hdr, struct rdt_mon_domain, hdr); - - cpumask_set_cpu(cpu, &d->hdr.cpu_mask); - return; - } - hw_dom =3D kzalloc_node(sizeof(*hw_dom), GFP_KERNEL, cpu_to_node(cpu)); if (!hw_dom) return; @@ -553,6 +532,38 @@ static void domain_add_cpu_mon(int cpu, struct rdt_res= ource *r) } } =20 +static void domain_add_cpu_mon(int cpu, struct rdt_resource *r) +{ + int id =3D get_domain_id_from_scope(cpu, r->mon_scope); + struct list_head *add_pos =3D NULL; + struct rdt_domain_hdr *hdr; + + lockdep_assert_held(&domain_list_lock); + + if (id < 0) { + pr_warn_once("Can't find monitor domain id for CPU:%d scope:%d for resou= rce %s\n", + cpu, r->mon_scope, r->name); + return; + } + + hdr =3D resctrl_find_domain(&r->mon_domains, id, &add_pos); + if (hdr) { + if (!domain_header_is_valid(hdr, RESCTRL_MON_DOMAIN, r->rid)) + return; + cpumask_set_cpu(cpu, &hdr->cpu_mask); + + return; + } + + switch (r->rid) { + case RDT_RESOURCE_L3: + l3_mon_domain_setup(cpu, id, r, add_pos); + break; + default: + WARN_ON_ONCE(1); + } +} + static void domain_add_cpu(int cpu, struct rdt_resource *r) { if (r->alloc_capable) --=20 2.49.0 From nobody Sun Dec 14 19:24:21 2025 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 A2B0723C501 for ; Wed, 21 May 2025 22:51:03 +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=1747867865; cv=none; b=RlG7Y0mYS5IkKRRkAo6XfmGTy/fscOeqsTVWUyqW7ge0/oiAWOdxvPxOvhja+I4Hk2AeELZutQJMV/dSMnk9SuBVi1d7dGr1IM2P6+Dx6IJFoPwdzL23yNypV27G5Wju3px+xYm55t6dmMtmuosTMVjFfdJ9VDPbDTtt0s2TKqc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747867865; c=relaxed/simple; bh=SDaugYWsXAZOMN3McHsAwSd3XAzRSKSYbucAMxD81bc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oKGCS/b2qqmBQ9P4D1y3JM1izApcv1nLcWCT3n2qFf/dA6/E6n1DhjUFzSesVKNng5tiz2wXJFAhFNuhC3+7FcZdB6v1Vc9/0b3CtxXxjX15btcwbMJG6ejm17oG5LHZZAjtOJ+dbgbArXwF1Q7yRI0fJoQqtLTM0ALLihnrJ+c= 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=MmeLXv4F; 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="MmeLXv4F" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1747867864; x=1779403864; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=SDaugYWsXAZOMN3McHsAwSd3XAzRSKSYbucAMxD81bc=; b=MmeLXv4FAfwyOFHasDWnom8h5NcitUaqW3qqPkN2DUT3UH/ISsCxWLWh zPXnpSy3/63ckLDr10cP4WJzkDoFBFlbxaJBuwViqtkPLlA1X+sZWLGhz WrI0x6Bs5BtUiXUQfF5m0altg1udYNZ5259A+SomdF0VlHxbMMJPVps9K l4nsAtfkTnTqLl+Uml7ZDGe2tsnrflVZJ/1sECdvbbUKBrG6G9SDbIzDY QvNCBQ61Ut/akgdtJ4Dtit1x1babwD58F/3uMwoFP/6qGKfLRErvAUFNg vkIqUSV96wpGE5E/AJhHsuz4d4V0eyn6PrP4ZiaiN3gd912s2sX8bxV96 Q==; X-CSE-ConnectionGUID: sJGPkRNXQKmmZnzzd0IevQ== X-CSE-MsgGUID: sH2m0Q94QGqIHxtMcYNkDg== X-IronPort-AV: E=McAfee;i="6700,10204,11440"; a="53677666" X-IronPort-AV: E=Sophos;i="6.15,304,1739865600"; d="scan'208";a="53677666" 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:57 -0700 X-CSE-ConnectionGUID: znuLcpe2RNCyNAucDITqAQ== X-CSE-MsgGUID: aIBn2m5pTSOHEQidYHnb8g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,304,1739865600"; d="scan'208";a="141352147" 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:57 -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 09/29] x86,fs/resctrl: Refactor domain_remove_cpu_mon() ready for new domain types Date: Wed, 21 May 2025 15:50:27 -0700 Message-ID: <20250521225049.132551-10-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" Historically all monitoring events have been associated with the L3 resource. This will change when support for telemetry events is added. The RDT_RESOURCE_L3 resource carries a lot of state in the domain structures which needs to be dealt with when a domain is taken offline by removing the last CPU in the domain. Refactor domain_remove_cpu_mon() so all the L3 processing is separated from general actions of clearing the CPU bit in the mask and removing directories from mon_data. resctrl_offline_mon_domain() will still need to remove domain specific directories and files from the "mon_data" directories, but can skip the L3 resource specific cleanup when called for other resource types. Signed-off-by: Tony Luck --- arch/x86/kernel/cpu/resctrl/core.c | 17 +++++++++++------ fs/resctrl/rdtgroup.c | 5 ++++- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resct= rl/core.c index 990a0c1af634..e4125161ffbd 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -643,17 +643,22 @@ static void domain_remove_cpu_mon(int cpu, struct rdt= _resource *r) if (!domain_header_is_valid(hdr, RESCTRL_MON_DOMAIN, r->rid)) return; =20 - d =3D container_of(hdr, struct rdt_mon_domain, hdr); - hw_dom =3D resctrl_to_arch_mon_dom(d); + cpumask_clear_cpu(cpu, &hdr->cpu_mask); + if (!cpumask_empty(&hdr->cpu_mask)) + return; =20 - cpumask_clear_cpu(cpu, &d->hdr.cpu_mask); - if (cpumask_empty(&d->hdr.cpu_mask)) { + switch (r->rid) { + case RDT_RESOURCE_L3: + d =3D container_of(hdr, struct rdt_mon_domain, hdr); + hw_dom =3D resctrl_to_arch_mon_dom(d); resctrl_offline_mon_domain(r, d); list_del_rcu(&d->hdr.list); synchronize_rcu(); l3_mon_domain_free(hw_dom); - - return; + break; + default: + pr_warn_once("Unknown resource rid=3D%d\n", r->rid); + break; } } =20 diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index 8aa9a7e68a59..828c743ec470 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -4041,6 +4041,9 @@ void resctrl_offline_mon_domain(struct rdt_resource *= r, struct rdt_mon_domain *d if (resctrl_mounted && resctrl_arch_mon_capable()) rmdir_mondata_subdir_allrdtgrp(r, d); =20 + if (r->rid !=3D RDT_RESOURCE_L3) + goto done; + if (resctrl_is_mbm_enabled()) cancel_delayed_work(&d->mbm_over); if (resctrl_is_mon_event_enabled(QOS_L3_OCCUP_EVENT_ID) && has_busy_rmid(= d)) { @@ -4057,7 +4060,7 @@ void resctrl_offline_mon_domain(struct rdt_resource *= r, struct rdt_mon_domain *d } =20 domain_destroy_mon_state(d); - +done: mutex_unlock(&rdtgroup_mutex); } =20 --=20 2.49.0 From nobody Sun Dec 14 19:24:21 2025 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 90D7E23D282 for ; Wed, 21 May 2025 22:51:04 +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=1747867866; cv=none; b=DVI4M/geOqIXN1pE6dkSXtAk/RwFBINqGjH93vURa8TAdajVDiPp3o2ATAuW0TZzQoZ3WHGuTRePa500rzD+2XYC/XzgABpgD/krSN4Pl0ora8ziZkpz8jz99DozQtpXSjwMqTl/sZ4Umbdd1LSPzN5Kn8cKEn4OGcBdcuCo4Uk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747867866; c=relaxed/simple; bh=SzbfmjWbTgU6gMZvn+iYunnqZycYnhJqvnGD32HC5NY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ML7rgCWWG+pS1vSWqAJ/vVBKeotfkBfkHcBjtxNdDktdu2uGIoYbnq0ofNEJWJECBbEvhpxe74OR9hjH0sIbsdDLXQmNM2NH45FRKzJmJ9uPVKMUgf3nmnsItF3Y5AZHLHd+6ZER7wdD7bEGwzEAcOhVDwOfwjzEhRz4FSYGpR0= 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=Et5ojVZm; 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="Et5ojVZm" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1747867865; x=1779403865; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=SzbfmjWbTgU6gMZvn+iYunnqZycYnhJqvnGD32HC5NY=; b=Et5ojVZmv0TKJKm8lamOxmnFWzXtLvgo56IHjUl/szzSWn4OMpgj7xYa hCbsr/2lrbSNlWSGf678wueiWOISO4gTckuLXkHosFucYM47wPxYPShwW zkSza24DAH02Q40MPbCI/piVwhx7wt8S2vgntrKdRUzXosy2myMT+tiEJ 9483HQXWWdgMcsRXx0oehHtmjk5DvRMfb3/ykIQ17PcOJQHv3Njz2XoEN hlPCijycyXgARI/3Q5I5rudkACRg+HObrkM0dRayD0VqBjkQXiG6dX8z8 owrz5xOtuQ0aZASy/QPOnAfG5eKidkCuwrVZ2d7FtEqdyKXdxP0tM691T g==; X-CSE-ConnectionGUID: /szKGa8LSnigmBr40Hs8TQ== X-CSE-MsgGUID: QJVKI+P2TKK7AZa7Na0PNg== X-IronPort-AV: E=McAfee;i="6700,10204,11440"; a="53677681" X-IronPort-AV: E=Sophos;i="6.15,304,1739865600"; d="scan'208";a="53677681" 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:58 -0700 X-CSE-ConnectionGUID: Vzv7ETHMQru5DlJEBHptZA== X-CSE-MsgGUID: Tho1t4pxQpCZQ1lu6aUXxQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,304,1739865600"; d="scan'208";a="141352151" 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:57 -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 10/29] x86/resctrl: Change generic domain functions to use struct rdt_domain_hdr Date: Wed, 21 May 2025 15:50:28 -0700 Message-ID: <20250521225049.132551-11-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" Historically all monitoring events have been associated with the L3 resource and it made sense to use "struct rdt_mon_domain *" arguments to functions manipulating domains. But the addition of monitor events tied to other resources changes this assumption. Some functionality like: *) adding a CPU to an existing domain *) removing a CPU that is not the last one from a domain can be achieved with just access to the rdt_domain_hdr structure. Change arguments from "rdt_*_domain" to rdt_domain_hdr so functions can be used on domains from any resource. Add sanity checks where container_of() is used to find the surrounding domain structure that hdr has the expected type. Simplify code that uses "d->hdr." to "hdr->" where possible. Signed-off-by: Tony Luck --- include/linux/resctrl.h | 4 +- arch/x86/kernel/cpu/resctrl/core.c | 39 +++++++------- fs/resctrl/rdtgroup.c | 83 +++++++++++++++++++++--------- 3 files changed, 79 insertions(+), 47 deletions(-) diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index d6b09952ef92..c02a4d59f3eb 100644 --- a/include/linux/resctrl.h +++ b/include/linux/resctrl.h @@ -444,9 +444,9 @@ int resctrl_arch_update_one(struct rdt_resource *r, str= uct rdt_ctrl_domain *d, u32 resctrl_arch_get_config(struct rdt_resource *r, struct rdt_ctrl_domain= *d, u32 closid, enum resctrl_conf_type type); int resctrl_online_ctrl_domain(struct rdt_resource *r, struct rdt_ctrl_dom= ain *d); -int resctrl_online_mon_domain(struct rdt_resource *r, struct rdt_mon_domai= n *d); +int resctrl_online_mon_domain(struct rdt_resource *r, struct rdt_domain_hd= r *hdr); void resctrl_offline_ctrl_domain(struct rdt_resource *r, struct rdt_ctrl_d= omain *d); -void resctrl_offline_mon_domain(struct rdt_resource *r, struct rdt_mon_dom= ain *d); +void resctrl_offline_mon_domain(struct rdt_resource *r, struct rdt_domain_= hdr *hdr); void resctrl_online_cpu(unsigned int cpu); void resctrl_offline_cpu(unsigned int cpu); =20 diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resct= rl/core.c index e4125161ffbd..71b884f25475 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -458,9 +458,7 @@ static void domain_add_cpu_ctrl(int cpu, struct rdt_res= ource *r) if (hdr) { if (!domain_header_is_valid(hdr, RESCTRL_CTRL_DOMAIN, r->rid)) return; - d =3D container_of(hdr, struct rdt_ctrl_domain, hdr); - - cpumask_set_cpu(cpu, &d->hdr.cpu_mask); + cpumask_set_cpu(cpu, &hdr->cpu_mask); if (r->cache.arch_has_per_cpu_cfg) rdt_domain_reconfigure_cdp(r); return; @@ -524,7 +522,7 @@ static void l3_mon_domain_setup(int cpu, int id, struct= rdt_resource *r, struct =20 list_add_tail_rcu(&d->hdr.list, add_pos); =20 - err =3D resctrl_online_mon_domain(r, d); + err =3D resctrl_online_mon_domain(r, &d->hdr); if (err) { list_del_rcu(&d->hdr.list); synchronize_rcu(); @@ -597,25 +595,24 @@ static void domain_remove_cpu_ctrl(int cpu, struct rd= t_resource *r) if (!domain_header_is_valid(hdr, RESCTRL_CTRL_DOMAIN, r->rid)) return; =20 + cpumask_clear_cpu(cpu, &d->hdr.cpu_mask); + if (!cpumask_empty(&hdr->cpu_mask)) + return; + d =3D container_of(hdr, struct rdt_ctrl_domain, hdr); hw_dom =3D resctrl_to_arch_ctrl_dom(d); =20 - cpumask_clear_cpu(cpu, &d->hdr.cpu_mask); - if (cpumask_empty(&d->hdr.cpu_mask)) { - resctrl_offline_ctrl_domain(r, d); - list_del_rcu(&d->hdr.list); - synchronize_rcu(); - - /* - * rdt_ctrl_domain "d" is going to be freed below, so clear - * its pointer from pseudo_lock_region struct. - */ - if (d->plr) - d->plr->d =3D NULL; - ctrl_domain_free(hw_dom); + resctrl_offline_ctrl_domain(r, d); + list_del_rcu(&hdr->list); + synchronize_rcu(); =20 - return; - } + /* + * rdt_ctrl_domain "d" is going to be freed below, so clear + * its pointer from pseudo_lock_region struct. + */ + if (d->plr) + d->plr->d =3D NULL; + ctrl_domain_free(hw_dom); } =20 static void domain_remove_cpu_mon(int cpu, struct rdt_resource *r) @@ -651,8 +648,8 @@ static void domain_remove_cpu_mon(int cpu, struct rdt_r= esource *r) case RDT_RESOURCE_L3: d =3D container_of(hdr, struct rdt_mon_domain, hdr); hw_dom =3D resctrl_to_arch_mon_dom(d); - resctrl_offline_mon_domain(r, d); - list_del_rcu(&d->hdr.list); + resctrl_offline_mon_domain(r, hdr); + list_del_rcu(&hdr->list); synchronize_rcu(); l3_mon_domain_free(hw_dom); break; diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index 828c743ec470..0213fb3a1113 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -3022,7 +3022,7 @@ static void mon_rmdir_one_subdir(struct kernfs_node *= pkn, char *name, char *subn * when last domain being summed is removed. */ static void rmdir_mondata_subdir_allrdtgrp(struct rdt_resource *r, - struct rdt_mon_domain *d) + struct rdt_domain_hdr *hdr) { struct rdtgroup *prgrp, *crgrp; char subname[32]; @@ -3030,9 +3030,17 @@ static void rmdir_mondata_subdir_allrdtgrp(struct rd= t_resource *r, char name[32]; =20 snc_mode =3D r->mon_scope =3D=3D RESCTRL_L3_NODE; - sprintf(name, "mon_%s_%02d", r->name, snc_mode ? d->ci->id : d->hdr.id); - if (snc_mode) - sprintf(subname, "mon_sub_%s_%02d", r->name, d->hdr.id); + if (snc_mode) { + struct rdt_mon_domain *d; + + if (!domain_header_is_valid(hdr, RESCTRL_MON_DOMAIN, r->rid)) + return; + d =3D container_of(hdr, struct rdt_mon_domain, hdr); + sprintf(name, "mon_%s_%02d", r->name, d->ci->id); + sprintf(subname, "mon_sub_%s_%02d", r->name, hdr->id); + } else { + sprintf(name, "mon_%s_%02d", r->name, hdr->id); + } =20 list_for_each_entry(prgrp, &rdt_all_groups, rdtgroup_list) { mon_rmdir_one_subdir(prgrp->mon.mon_data_kn, name, subname); @@ -3042,11 +3050,12 @@ static void rmdir_mondata_subdir_allrdtgrp(struct r= dt_resource *r, } } =20 -static int mon_add_all_files(struct kernfs_node *kn, struct rdt_mon_domain= *d, +static int mon_add_all_files(struct kernfs_node *kn, struct rdt_domain_hdr= *hdr, struct rdt_resource *r, struct rdtgroup *prgrp, bool do_sum) { struct rmid_read rr =3D {0}; + struct rdt_mon_domain *d; struct mon_data *priv; struct mon_evt *mevt; int ret, domid; @@ -3054,7 +3063,14 @@ static int mon_add_all_files(struct kernfs_node *kn,= struct rdt_mon_domain *d, 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; + if (r->rid =3D=3D RDT_RESOURCE_L3) { + if (!domain_header_is_valid(hdr, RESCTRL_MON_DOMAIN, r->rid)) + return -EINVAL; + d =3D container_of(hdr, struct rdt_mon_domain, hdr); + domid =3D do_sum ? d->ci->id : d->hdr.id; + } else { + domid =3D hdr->id; + } priv =3D mon_get_kn_priv(r->rid, domid, mevt, do_sum); if (WARN_ON_ONCE(!priv)) return -EINVAL; @@ -3063,18 +3079,19 @@ static int mon_add_all_files(struct kernfs_node *kn= , struct rdt_mon_domain *d, if (ret) return ret; =20 - if (!do_sum && resctrl_is_mbm_event(mevt->evtid)) - mon_event_read(&rr, r, d, prgrp, &d->hdr.cpu_mask, mevt->evtid, true); + if (r->rid =3D=3D RDT_RESOURCE_L3 && !do_sum && resctrl_is_mbm_event(mev= t->evtid)) + mon_event_read(&rr, r, d, prgrp, &hdr->cpu_mask, mevt->evtid, true); } =20 return 0; } =20 static int mkdir_mondata_subdir(struct kernfs_node *parent_kn, - struct rdt_mon_domain *d, + struct rdt_domain_hdr *hdr, struct rdt_resource *r, struct rdtgroup *prgrp) { struct kernfs_node *kn, *ckn; + struct rdt_mon_domain *d; char name[32]; bool snc_mode; int ret =3D 0; @@ -3082,7 +3099,14 @@ static int mkdir_mondata_subdir(struct kernfs_node *= parent_kn, lockdep_assert_held(&rdtgroup_mutex); =20 snc_mode =3D r->mon_scope =3D=3D RESCTRL_L3_NODE; - sprintf(name, "mon_%s_%02d", r->name, snc_mode ? d->ci->id : d->hdr.id); + if (snc_mode) { + if (!domain_header_is_valid(hdr, RESCTRL_MON_DOMAIN, r->rid)) + return -EINVAL; + d =3D container_of(hdr, struct rdt_mon_domain, hdr); + sprintf(name, "mon_%s_%02d", r->name, d->ci->id); + } else { + sprintf(name, "mon_%s_%02d", r->name, hdr->id); + } kn =3D kernfs_find_and_get(parent_kn, name); if (kn) { /* @@ -3098,13 +3122,13 @@ static int mkdir_mondata_subdir(struct kernfs_node = *parent_kn, ret =3D rdtgroup_kn_set_ugid(kn); if (ret) goto out_destroy; - ret =3D mon_add_all_files(kn, d, r, prgrp, snc_mode); + ret =3D mon_add_all_files(kn, hdr, r, prgrp, snc_mode); if (ret) goto out_destroy; } =20 if (snc_mode) { - sprintf(name, "mon_sub_%s_%02d", r->name, d->hdr.id); + sprintf(name, "mon_sub_%s_%02d", r->name, hdr->id); ckn =3D kernfs_create_dir(kn, name, parent_kn->mode, prgrp); if (IS_ERR(ckn)) { ret =3D -EINVAL; @@ -3115,7 +3139,7 @@ static int mkdir_mondata_subdir(struct kernfs_node *p= arent_kn, if (ret) goto out_destroy; =20 - ret =3D mon_add_all_files(ckn, d, r, prgrp, false); + ret =3D mon_add_all_files(ckn, hdr, r, prgrp, false); if (ret) goto out_destroy; } @@ -3133,7 +3157,7 @@ static int mkdir_mondata_subdir(struct kernfs_node *p= arent_kn, * and "monitor" groups with given domain id. */ static void mkdir_mondata_subdir_allrdtgrp(struct rdt_resource *r, - struct rdt_mon_domain *d) + struct rdt_domain_hdr *hdr) { struct kernfs_node *parent_kn; struct rdtgroup *prgrp, *crgrp; @@ -3141,12 +3165,12 @@ static void mkdir_mondata_subdir_allrdtgrp(struct r= dt_resource *r, =20 list_for_each_entry(prgrp, &rdt_all_groups, rdtgroup_list) { parent_kn =3D prgrp->mon.mon_data_kn; - mkdir_mondata_subdir(parent_kn, d, r, prgrp); + mkdir_mondata_subdir(parent_kn, hdr, r, prgrp); =20 head =3D &prgrp->mon.crdtgrp_list; list_for_each_entry(crgrp, head, mon.crdtgrp_list) { parent_kn =3D crgrp->mon.mon_data_kn; - mkdir_mondata_subdir(parent_kn, d, r, crgrp); + mkdir_mondata_subdir(parent_kn, hdr, r, crgrp); } } } @@ -3155,14 +3179,14 @@ static int mkdir_mondata_subdir_alldom(struct kernf= s_node *parent_kn, struct rdt_resource *r, struct rdtgroup *prgrp) { - struct rdt_mon_domain *dom; + struct rdt_domain_hdr *hdr; int ret; =20 /* Walking r->domains, ensure it can't race with cpuhp */ lockdep_assert_cpus_held(); =20 - list_for_each_entry(dom, &r->mon_domains, hdr.list) { - ret =3D mkdir_mondata_subdir(parent_kn, dom, r, prgrp); + list_for_each_entry(hdr, &r->mon_domains, list) { + ret =3D mkdir_mondata_subdir(parent_kn, hdr, r, prgrp); if (ret) return ret; } @@ -4030,8 +4054,10 @@ void resctrl_offline_ctrl_domain(struct rdt_resource= *r, struct rdt_ctrl_domain mutex_unlock(&rdtgroup_mutex); } =20 -void resctrl_offline_mon_domain(struct rdt_resource *r, struct rdt_mon_dom= ain *d) +void resctrl_offline_mon_domain(struct rdt_resource *r, struct rdt_domain_= hdr *hdr) { + struct rdt_mon_domain *d; + mutex_lock(&rdtgroup_mutex); =20 /* @@ -4039,11 +4065,15 @@ void resctrl_offline_mon_domain(struct rdt_resource= *r, struct rdt_mon_domain *d * per domain monitor data directories. */ if (resctrl_mounted && resctrl_arch_mon_capable()) - rmdir_mondata_subdir_allrdtgrp(r, d); + rmdir_mondata_subdir_allrdtgrp(r, hdr); =20 if (r->rid !=3D RDT_RESOURCE_L3) goto done; =20 + if (!domain_header_is_valid(hdr, RESCTRL_MON_DOMAIN, r->rid)) + return; + + d =3D container_of(hdr, struct rdt_mon_domain, hdr); if (resctrl_is_mbm_enabled()) cancel_delayed_work(&d->mbm_over); if (resctrl_is_mon_event_enabled(QOS_L3_OCCUP_EVENT_ID) && has_busy_rmid(= d)) { @@ -4126,12 +4156,17 @@ int resctrl_online_ctrl_domain(struct rdt_resource = *r, struct rdt_ctrl_domain *d return err; } =20 -int resctrl_online_mon_domain(struct rdt_resource *r, struct rdt_mon_domai= n *d) +int resctrl_online_mon_domain(struct rdt_resource *r, struct rdt_domain_hd= r *hdr) { - int err; + struct rdt_mon_domain *d; + int err =3D -EINVAL; =20 mutex_lock(&rdtgroup_mutex); =20 + if (!domain_header_is_valid(hdr, RESCTRL_MON_DOMAIN, r->rid)) + goto out_unlock; + + d =3D container_of(hdr, struct rdt_mon_domain, hdr); err =3D domain_setup_l3_mon_state(r, d); if (err) goto out_unlock; @@ -4152,7 +4187,7 @@ int resctrl_online_mon_domain(struct rdt_resource *r,= struct rdt_mon_domain *d) * If resctrl is mounted, add per domain monitor data directories. */ if (resctrl_mounted && resctrl_arch_mon_capable()) - mkdir_mondata_subdir_allrdtgrp(r, d); + mkdir_mondata_subdir_allrdtgrp(r, hdr); =20 out_unlock: mutex_unlock(&rdtgroup_mutex); --=20 2.49.0 From nobody Sun Dec 14 19:24:21 2025 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 1B3D623D29D for ; Wed, 21 May 2025 22:51:05 +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=1747867868; cv=none; b=YdokJsub0fjHkdC7bcYaOtSaXwgn78tWScfzj4PhqpEucSRdZOIscWCiMZB99NBImQy+LB9KRJBhZC4UPNh0q4W6m0Ifaw2phtQPeRxolaLEwQdUP3RuFSLXAjSUASAbMpwjDqBCYFvHhM7/xIPDICZmEntQ1e5pJqHMHdVD2Qk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747867868; c=relaxed/simple; bh=ANv5i15C6Cl5cQUG6cnbO6zdMC193z25eBqSwqpdnaM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gwjzoRwKHejzrXjBlATlmJJoOiRN2FrFEHHcp/gBiJ3DdzATgYQDjKlDP+lzxksprKm1Ped/bgw/205IgIvBxCHj9O2wR5kF7OZAbpX7LVsf5P0+nKmyyAZujY/cLX5+5r6p/kTE8AU7ENdulzlgZI0LNyOXqYwOjWI6/LwL5QQ= 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=RuPr7Zo1; 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="RuPr7Zo1" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1747867865; x=1779403865; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ANv5i15C6Cl5cQUG6cnbO6zdMC193z25eBqSwqpdnaM=; b=RuPr7Zo11Keb7clxdt+Zy7GZ7XLW5J+nOoKidPcpukYZ6ZDpgqemuptf tLjcNhvxbF967AgHVlhVI7QMlbmbEM/Viil3JmkJMYcu2xBLfYq77clYf JkHrMZrnWjTqBBDyhEC3Qi8Kz8HGo2fjYdOXjBUYpQWW14fZTJnWleLXk QOZiohWALYLldxn2Xy5MoDvODEDXjHU8LXYgROr0irVLia8rdrAU+efH/ uCemCEdrJPrUdAM5CoiTtDJzN9cYtHTgVbJewNkoDjHPXwNj68iwmW9Gb aeczkJ/uYX/Vu2ABQSmQNrnXie9q55D30OOnxYMJS9p6t9nqIZuqp0Mk7 Q==; X-CSE-ConnectionGUID: EgIgW0geSBerMbYkFlSoJw== X-CSE-MsgGUID: E27ai+2+QpmnMvizJH7Cfg== X-IronPort-AV: E=McAfee;i="6700,10204,11440"; a="53677678" X-IronPort-AV: E=Sophos;i="6.15,304,1739865600"; d="scan'208";a="53677678" 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:58 -0700 X-CSE-ConnectionGUID: UGx0D4p5TuyC1Gh1Otbk0g== X-CSE-MsgGUID: xnjWxzNlRiOhDsaAgOVd/g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,304,1739865600"; d="scan'208";a="141352154" 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:57 -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 11/29] x86,fs/resctrl: Rename struct rdt_mon_domain and rdt_hw_mon_domain Date: Wed, 21 May 2025 15:50:29 -0700 Message-ID: <20250521225049.132551-12-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" Historically all monitoring events have been associated with the L3 resource. This will change when support for telemetry events is added. The structures to track monitor domains at both the file system and architecture level have generic names. This may cause confusion when support for monitoring events in other resources is added. Rename by adding "l3_" into the names: rdt_mon_domain -> rdt_l3_mon_domain rdt_hw_mon_domain -> rdt_hw_l3_mon_domain No functional change. Signed-off-by: Tony Luck --- include/linux/resctrl.h | 18 ++++++------ arch/x86/kernel/cpu/resctrl/internal.h | 14 ++++----- fs/resctrl/internal.h | 28 +++++++++--------- arch/x86/kernel/cpu/resctrl/core.c | 14 ++++----- arch/x86/kernel/cpu/resctrl/monitor.c | 18 ++++++------ fs/resctrl/ctrlmondata.c | 6 ++-- fs/resctrl/monitor.c | 28 +++++++++--------- fs/resctrl/rdtgroup.c | 40 +++++++++++++------------- 8 files changed, 83 insertions(+), 83 deletions(-) diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index c02a4d59f3eb..b7a4c7bf4feb 100644 --- a/include/linux/resctrl.h +++ b/include/linux/resctrl.h @@ -166,7 +166,7 @@ struct rdt_ctrl_domain { }; =20 /** - * struct rdt_mon_domain - group of CPUs sharing a resctrl monitor resource + * struct rdt_l3_mon_domain - group of CPUs sharing the resctrl L3 monitor= resource * @hdr: common header for different domain types * @ci: cache info for this domain * @rmid_busy_llc: bitmap of which limbo RMIDs are above threshold @@ -176,7 +176,7 @@ struct rdt_ctrl_domain { * @mbm_work_cpu: worker CPU for MBM h/w counters * @cqm_work_cpu: worker CPU for CQM h/w counters */ -struct rdt_mon_domain { +struct rdt_l3_mon_domain { struct rdt_domain_hdr hdr; struct cacheinfo *ci; unsigned long *rmid_busy_llc; @@ -332,10 +332,10 @@ struct resctrl_cpu_defaults { }; =20 struct resctrl_mon_config_info { - struct rdt_resource *r; - struct rdt_mon_domain *d; - u32 evtid; - u32 mon_config; + struct rdt_resource *r; + struct rdt_l3_mon_domain *d; + u32 evtid; + u32 mon_config; }; =20 /** @@ -475,7 +475,7 @@ void resctrl_offline_cpu(unsigned int cpu); * Return: * 0 on success, or -EIO, -EINVAL etc on error. */ -int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_mon_domain *= d, +int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_l3_mon_domai= n *d, u32 closid, u32 rmid, enum resctrl_event_id eventid, u64 *val, void *arch_mon_ctx); =20 @@ -522,7 +522,7 @@ struct rdt_domain_hdr *resctrl_find_domain(struct list_= head *h, int id, * * This can be called from any CPU. */ -void resctrl_arch_reset_rmid(struct rdt_resource *r, struct rdt_mon_domain= *d, +void resctrl_arch_reset_rmid(struct rdt_resource *r, struct rdt_l3_mon_dom= ain *d, u32 closid, u32 rmid, enum resctrl_event_id eventid); =20 @@ -535,7 +535,7 @@ void resctrl_arch_reset_rmid(struct rdt_resource *r, st= ruct rdt_mon_domain *d, * * This can be called from any CPU. */ -void resctrl_arch_reset_rmid_all(struct rdt_resource *r, struct rdt_mon_do= main *d); +void resctrl_arch_reset_rmid_all(struct rdt_resource *r, struct rdt_l3_mon= _domain *d); =20 /** * resctrl_arch_reset_all_ctrls() - Reset the control for each CLOSID to i= ts diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/r= esctrl/internal.h index 038c888dcdcf..02c9e7d163dc 100644 --- a/arch/x86/kernel/cpu/resctrl/internal.h +++ b/arch/x86/kernel/cpu/resctrl/internal.h @@ -51,15 +51,15 @@ struct rdt_hw_ctrl_domain { }; =20 /** - * struct rdt_hw_mon_domain - Arch private attributes of a set of CPUs tha= t share - * a resource for a monitor function + * struct rdt_hw_l3_mon_domain - Arch private attributes of a set of CPUs = that share + * the L3 resource for a monitor function * @d_resctrl: Properties exposed to the resctrl file system * @arch_mbm_states: arch private state for each MBM event * * Members of this structure are accessed via helpers that provide abstrac= tion. */ -struct rdt_hw_mon_domain { - struct rdt_mon_domain d_resctrl; +struct rdt_hw_l3_mon_domain { + struct rdt_l3_mon_domain d_resctrl; struct arch_mbm_state *arch_mbm_states[QOS_NUM_L3_MBM_EVENTS]; }; =20 @@ -68,9 +68,9 @@ static inline struct rdt_hw_ctrl_domain *resctrl_to_arch_= ctrl_dom(struct rdt_ctr return container_of(r, struct rdt_hw_ctrl_domain, d_resctrl); } =20 -static inline struct rdt_hw_mon_domain *resctrl_to_arch_mon_dom(struct rdt= _mon_domain *r) +static inline struct rdt_hw_l3_mon_domain *resctrl_to_arch_mon_dom(struct = rdt_l3_mon_domain *r) { - return container_of(r, struct rdt_hw_mon_domain, d_resctrl); + return container_of(r, struct rdt_hw_l3_mon_domain, d_resctrl); } =20 /** @@ -122,7 +122,7 @@ static inline struct rdt_hw_resource *resctrl_to_arch_r= es(struct rdt_resource *r =20 extern struct rdt_hw_resource rdt_resources_all[]; =20 -void arch_l3_mon_domain_online(struct rdt_resource *r, struct rdt_mon_doma= in *d); +void arch_l3_mon_domain_online(struct rdt_resource *r, struct rdt_l3_mon_d= omain *d); =20 /* CPUID.(EAX=3D10H, ECX=3DResID=3D1).EAX */ union cpuid_0x10_1_eax { diff --git a/fs/resctrl/internal.h b/fs/resctrl/internal.h index 94e635656261..8659ee33b76f 100644 --- a/fs/resctrl/internal.h +++ b/fs/resctrl/internal.h @@ -111,15 +111,15 @@ struct mon_data { * @arch_mon_ctx: Hardware monitor allocated for this read request (MPAM o= nly). */ struct rmid_read { - struct rdtgroup *rgrp; - struct rdt_resource *r; - struct rdt_mon_domain *d; - enum resctrl_event_id evtid; - bool first; - struct cacheinfo *ci; - int err; - u64 val; - void *arch_mon_ctx; + struct rdtgroup *rgrp; + struct rdt_resource *r; + struct rdt_l3_mon_domain *d; + enum resctrl_event_id evtid; + bool first; + struct cacheinfo *ci; + int err; + u64 val; + void *arch_mon_ctx; }; =20 extern struct list_head resctrl_schema_all; @@ -349,12 +349,12 @@ void mon_event_count(void *info); int rdtgroup_mondata_show(struct seq_file *m, void *arg); =20 void mon_event_read(struct rmid_read *rr, struct rdt_resource *r, - struct rdt_mon_domain *d, struct rdtgroup *rdtgrp, + struct rdt_l3_mon_domain *d, struct rdtgroup *rdtgrp, cpumask_t *cpumask, int evtid, int first); =20 int resctrl_mon_resource_init(void); =20 -void mbm_setup_overflow_handler(struct rdt_mon_domain *dom, +void mbm_setup_overflow_handler(struct rdt_l3_mon_domain *dom, unsigned long delay_ms, int exclude_cpu); =20 @@ -362,14 +362,14 @@ void mbm_handle_overflow(struct work_struct *work); =20 bool is_mba_sc(struct rdt_resource *r); =20 -void cqm_setup_limbo_handler(struct rdt_mon_domain *dom, unsigned long del= ay_ms, +void cqm_setup_limbo_handler(struct rdt_l3_mon_domain *dom, unsigned long = delay_ms, int exclude_cpu); =20 void cqm_handle_limbo(struct work_struct *work); =20 -bool has_busy_rmid(struct rdt_mon_domain *d); +bool has_busy_rmid(struct rdt_l3_mon_domain *d); =20 -void __check_limbo(struct rdt_mon_domain *d, bool force_free); +void __check_limbo(struct rdt_l3_mon_domain *d, bool force_free); =20 void resctrl_file_fflags_init(const char *config, unsigned long fflags); =20 diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resct= rl/core.c index 71b884f25475..b39537658618 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -362,7 +362,7 @@ static void ctrl_domain_free(struct rdt_hw_ctrl_domain = *hw_dom) kfree(hw_dom); } =20 -static void l3_mon_domain_free(struct rdt_hw_mon_domain *hw_dom) +static void l3_mon_domain_free(struct rdt_hw_l3_mon_domain *hw_dom) { for (int i =3D 0; i < QOS_NUM_L3_MBM_EVENTS; i++) kfree(hw_dom->arch_mbm_states[i]); @@ -397,7 +397,7 @@ static int domain_setup_ctrlval(struct rdt_resource *r,= struct rdt_ctrl_domain * * @num_rmid: The size of the MBM counter array * @hw_dom: The domain that owns the allocated arrays */ -static int arch_domain_mbm_alloc(u32 num_rmid, struct rdt_hw_mon_domain *h= w_dom) +static int arch_domain_mbm_alloc(u32 num_rmid, struct rdt_hw_l3_mon_domain= *hw_dom) { size_t tsize =3D sizeof(struct arch_mbm_state); enum resctrl_event_id evt; @@ -493,8 +493,8 @@ static void domain_add_cpu_ctrl(int cpu, struct rdt_res= ource *r) =20 static void l3_mon_domain_setup(int cpu, int id, struct rdt_resource *r, s= truct list_head *add_pos) { - struct rdt_hw_mon_domain *hw_dom; - struct rdt_mon_domain *d; + struct rdt_hw_l3_mon_domain *hw_dom; + struct rdt_l3_mon_domain *d; int err; =20 hw_dom =3D kzalloc_node(sizeof(*hw_dom), GFP_KERNEL, cpu_to_node(cpu)); @@ -618,9 +618,9 @@ static void domain_remove_cpu_ctrl(int cpu, struct rdt_= resource *r) static void domain_remove_cpu_mon(int cpu, struct rdt_resource *r) { int id =3D get_domain_id_from_scope(cpu, r->mon_scope); - struct rdt_hw_mon_domain *hw_dom; + struct rdt_hw_l3_mon_domain *hw_dom; + struct rdt_l3_mon_domain *d; struct rdt_domain_hdr *hdr; - struct rdt_mon_domain *d; =20 lockdep_assert_held(&domain_list_lock); =20 @@ -646,7 +646,7 @@ static void domain_remove_cpu_mon(int cpu, struct rdt_r= esource *r) =20 switch (r->rid) { case RDT_RESOURCE_L3: - d =3D container_of(hdr, struct rdt_mon_domain, hdr); + d =3D container_of(hdr, struct rdt_l3_mon_domain, hdr); hw_dom =3D resctrl_to_arch_mon_dom(d); resctrl_offline_mon_domain(r, hdr); list_del_rcu(&hdr->list); diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/re= sctrl/monitor.c index 659265330783..1f6dc253112f 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -108,7 +108,7 @@ static inline u64 get_corrected_mbm_count(u32 rmid, uns= igned long val) * * In RMID sharing mode there are fewer "logical RMID" values available * to accumulate data ("physical RMIDs" are divided evenly between SNC - * nodes that share an L3 cache). Linux creates an rdt_mon_domain for + * nodes that share an L3 cache). Linux creates an rdt_l3_mon_domain for * each SNC node. * * The value loaded into IA32_PQR_ASSOC is the "logical RMID". @@ -156,7 +156,7 @@ static int __rmid_read_phys(u32 prmid, enum resctrl_eve= nt_id eventid, u64 *val) return 0; } =20 -static struct arch_mbm_state *get_arch_mbm_state(struct rdt_hw_mon_domain = *hw_dom, +static struct arch_mbm_state *get_arch_mbm_state(struct rdt_hw_l3_mon_doma= in *hw_dom, u32 rmid, enum resctrl_event_id eventid) { @@ -170,11 +170,11 @@ static struct arch_mbm_state *get_arch_mbm_state(stru= ct rdt_hw_mon_domain *hw_do return state ? &state[rmid] : NULL; } =20 -void resctrl_arch_reset_rmid(struct rdt_resource *r, struct rdt_mon_domain= *d, +void resctrl_arch_reset_rmid(struct rdt_resource *r, struct rdt_l3_mon_dom= ain *d, u32 unused, u32 rmid, enum resctrl_event_id eventid) { - struct rdt_hw_mon_domain *hw_dom =3D resctrl_to_arch_mon_dom(d); + struct rdt_hw_l3_mon_domain *hw_dom =3D resctrl_to_arch_mon_dom(d); int cpu =3D cpumask_any(&d->hdr.cpu_mask); struct arch_mbm_state *am; u32 prmid; @@ -193,9 +193,9 @@ void resctrl_arch_reset_rmid(struct rdt_resource *r, st= ruct rdt_mon_domain *d, * Assumes that hardware counters are also reset and thus that there is * no need to record initial non-zero counts. */ -void resctrl_arch_reset_rmid_all(struct rdt_resource *r, struct rdt_mon_do= main *d) +void resctrl_arch_reset_rmid_all(struct rdt_resource *r, struct rdt_l3_mon= _domain *d) { - struct rdt_hw_mon_domain *hw_dom =3D resctrl_to_arch_mon_dom(d); + struct rdt_hw_l3_mon_domain *hw_dom =3D resctrl_to_arch_mon_dom(d); enum resctrl_event_id evt; int idx; =20 @@ -216,11 +216,11 @@ static u64 mbm_overflow_count(u64 prev_msr, u64 cur_m= sr, unsigned int width) return chunks >> shift; } =20 -int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_mon_domain *= d, +int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_l3_mon_domai= n *d, u32 unused, u32 rmid, enum resctrl_event_id eventid, u64 *val, void *ignored) { - struct rdt_hw_mon_domain *hw_dom =3D resctrl_to_arch_mon_dom(d); + struct rdt_hw_l3_mon_domain *hw_dom =3D resctrl_to_arch_mon_dom(d); struct rdt_hw_resource *hw_res =3D resctrl_to_arch_res(r); int cpu =3D cpumask_any(&d->hdr.cpu_mask); struct arch_mbm_state *am; @@ -264,7 +264,7 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, stru= ct rdt_mon_domain *d, * must adjust RMID counter numbers based on SNC node. See * logical_rmid_to_physical_rmid() for code that does this. */ -void arch_l3_mon_domain_online(struct rdt_resource *r, struct rdt_mon_doma= in *d) +void arch_l3_mon_domain_online(struct rdt_resource *r, struct rdt_l3_mon_d= omain *d) { if (snc_nodes_per_l3_cache > 1) msr_clear_bit(MSR_RMID_SNC_CONFIG, 0); diff --git a/fs/resctrl/ctrlmondata.c b/fs/resctrl/ctrlmondata.c index 7d16f7eb6985..6db24f7a3de5 100644 --- a/fs/resctrl/ctrlmondata.c +++ b/fs/resctrl/ctrlmondata.c @@ -547,7 +547,7 @@ struct rdt_domain_hdr *resctrl_find_domain(struct list_= head *h, int id, } =20 void mon_event_read(struct rmid_read *rr, struct rdt_resource *r, - struct rdt_mon_domain *d, struct rdtgroup *rdtgrp, + struct rdt_l3_mon_domain *d, struct rdtgroup *rdtgrp, cpumask_t *cpumask, int evtid, int first) { int cpu; @@ -590,9 +590,9 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg) struct kernfs_open_file *of =3D m->private; enum resctrl_res_level resid; enum resctrl_event_id evtid; + struct rdt_l3_mon_domain *d; struct rdt_domain_hdr *hdr; struct rmid_read rr =3D {0}; - struct rdt_mon_domain *d; struct rdtgroup *rdtgrp; struct rdt_resource *r; struct mon_data *md; @@ -642,7 +642,7 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg) ret =3D -ENOENT; goto out; } - d =3D container_of(hdr, struct rdt_mon_domain, hdr); + d =3D container_of(hdr, struct rdt_l3_mon_domain, hdr); mon_event_read(&rr, r, d, rdtgrp, &d->hdr.cpu_mask, evtid, false); } =20 diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c index 4cd0789998bf..c1d248a7fdbc 100644 --- a/fs/resctrl/monitor.c +++ b/fs/resctrl/monitor.c @@ -130,7 +130,7 @@ static void limbo_release_entry(struct rmid_entry *entr= y) * decrement the count. If the busy count gets to zero on an RMID, we * free the RMID */ -void __check_limbo(struct rdt_mon_domain *d, bool force_free) +void __check_limbo(struct rdt_l3_mon_domain *d, bool force_free) { struct rdt_resource *r =3D resctrl_arch_get_resource(RDT_RESOURCE_L3); u32 idx_limit =3D resctrl_arch_system_num_rmid_idx(); @@ -188,7 +188,7 @@ void __check_limbo(struct rdt_mon_domain *d, bool force= _free) resctrl_arch_mon_ctx_free(r, QOS_L3_OCCUP_EVENT_ID, arch_mon_ctx); } =20 -bool has_busy_rmid(struct rdt_mon_domain *d) +bool has_busy_rmid(struct rdt_l3_mon_domain *d) { u32 idx_limit =3D resctrl_arch_system_num_rmid_idx(); =20 @@ -289,7 +289,7 @@ int alloc_rmid(u32 closid) static void add_rmid_to_limbo(struct rmid_entry *entry) { struct rdt_resource *r =3D resctrl_arch_get_resource(RDT_RESOURCE_L3); - struct rdt_mon_domain *d; + struct rdt_l3_mon_domain *d; u32 idx; =20 lockdep_assert_held(&rdtgroup_mutex); @@ -342,7 +342,7 @@ void free_rmid(u32 closid, u32 rmid) list_add_tail(&entry->list, &rmid_free_lru); } =20 -static struct mbm_state *get_mbm_state(struct rdt_mon_domain *d, u32 closi= d, +static struct mbm_state *get_mbm_state(struct rdt_l3_mon_domain *d, u32 cl= osid, u32 rmid, enum resctrl_event_id evtid) { u32 idx =3D resctrl_arch_rmid_idx_encode(closid, rmid); @@ -359,7 +359,7 @@ static struct mbm_state *get_mbm_state(struct rdt_mon_d= omain *d, u32 closid, static int __mon_event_count(u32 closid, u32 rmid, struct rmid_read *rr) { int cpu =3D smp_processor_id(); - struct rdt_mon_domain *d; + struct rdt_l3_mon_domain *d; struct mbm_state *m; int err, ret; u64 tval =3D 0; @@ -532,7 +532,7 @@ static struct rdt_ctrl_domain *get_ctrl_domain_from_cpu= (int cpu, * throttle MSRs already have low percentage values. To avoid * unnecessarily restricting such rdtgroups, we also increase the bandwidt= h. */ -static void update_mba_bw(struct rdtgroup *rgrp, struct rdt_mon_domain *do= m_mbm) +static void update_mba_bw(struct rdtgroup *rgrp, struct rdt_l3_mon_domain = *dom_mbm) { u32 closid, rmid, cur_msr_val, new_msr_val; struct mbm_state *pmbm_data, *cmbm_data; @@ -600,7 +600,7 @@ static void update_mba_bw(struct rdtgroup *rgrp, struct= rdt_mon_domain *dom_mbm) resctrl_arch_update_one(r_mba, dom_mba, closid, CDP_NONE, new_msr_val); } =20 -static void mbm_update_one_event(struct rdt_resource *r, struct rdt_mon_do= main *d, +static void mbm_update_one_event(struct rdt_resource *r, struct rdt_l3_mon= _domain *d, u32 closid, u32 rmid, enum resctrl_event_id evtid) { struct rmid_read rr =3D {0}; @@ -627,7 +627,7 @@ static void mbm_update_one_event(struct rdt_resource *r= , struct rdt_mon_domain * resctrl_arch_mon_ctx_free(rr.r, rr.evtid, rr.arch_mon_ctx); } =20 -static void mbm_update(struct rdt_resource *r, struct rdt_mon_domain *d, +static void mbm_update(struct rdt_resource *r, struct rdt_l3_mon_domain *d, u32 closid, u32 rmid) { /* @@ -648,12 +648,12 @@ static void mbm_update(struct rdt_resource *r, struct= rdt_mon_domain *d, void cqm_handle_limbo(struct work_struct *work) { unsigned long delay =3D msecs_to_jiffies(CQM_LIMBOCHECK_INTERVAL); - struct rdt_mon_domain *d; + struct rdt_l3_mon_domain *d; =20 cpus_read_lock(); mutex_lock(&rdtgroup_mutex); =20 - d =3D container_of(work, struct rdt_mon_domain, cqm_limbo.work); + d =3D container_of(work, struct rdt_l3_mon_domain, cqm_limbo.work); =20 __check_limbo(d, false); =20 @@ -676,7 +676,7 @@ void cqm_handle_limbo(struct work_struct *work) * @exclude_cpu: Which CPU the handler should not run on, * RESCTRL_PICK_ANY_CPU to pick any CPU. */ -void cqm_setup_limbo_handler(struct rdt_mon_domain *dom, unsigned long del= ay_ms, +void cqm_setup_limbo_handler(struct rdt_l3_mon_domain *dom, unsigned long = delay_ms, int exclude_cpu) { unsigned long delay =3D msecs_to_jiffies(delay_ms); @@ -693,7 +693,7 @@ void mbm_handle_overflow(struct work_struct *work) { unsigned long delay =3D msecs_to_jiffies(MBM_OVERFLOW_INTERVAL); struct rdtgroup *prgrp, *crgrp; - struct rdt_mon_domain *d; + struct rdt_l3_mon_domain *d; struct list_head *head; struct rdt_resource *r; =20 @@ -708,7 +708,7 @@ void mbm_handle_overflow(struct work_struct *work) goto out_unlock; =20 r =3D resctrl_arch_get_resource(RDT_RESOURCE_L3); - d =3D container_of(work, struct rdt_mon_domain, mbm_over.work); + d =3D container_of(work, struct rdt_l3_mon_domain, mbm_over.work); =20 list_for_each_entry(prgrp, &rdt_all_groups, rdtgroup_list) { mbm_update(r, d, prgrp->closid, prgrp->mon.rmid); @@ -742,7 +742,7 @@ void mbm_handle_overflow(struct work_struct *work) * @exclude_cpu: Which CPU the handler should not run on, * RESCTRL_PICK_ANY_CPU to pick any CPU. */ -void mbm_setup_overflow_handler(struct rdt_mon_domain *dom, unsigned long = delay_ms, +void mbm_setup_overflow_handler(struct rdt_l3_mon_domain *dom, unsigned lo= ng delay_ms, int exclude_cpu) { unsigned long delay =3D msecs_to_jiffies(delay_ms); diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index 0213fb3a1113..39e046fba60a 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -1615,7 +1615,7 @@ static void mondata_config_read(struct resctrl_mon_co= nfig_info *mon_info) static int mbm_config_show(struct seq_file *s, struct rdt_resource *r, u32= evtid) { struct resctrl_mon_config_info mon_info; - struct rdt_mon_domain *dom; + struct rdt_l3_mon_domain *dom; bool sep =3D false; =20 cpus_read_lock(); @@ -1663,7 +1663,7 @@ static int mbm_local_bytes_config_show(struct kernfs_= open_file *of, } =20 static void mbm_config_write_domain(struct rdt_resource *r, - struct rdt_mon_domain *d, u32 evtid, u32 val) + struct rdt_l3_mon_domain *d, u32 evtid, u32 val) { struct resctrl_mon_config_info mon_info =3D {0}; =20 @@ -1704,8 +1704,8 @@ static void mbm_config_write_domain(struct rdt_resour= ce *r, static int mon_config_write(struct rdt_resource *r, char *tok, u32 evtid) { char *dom_str =3D NULL, *id_str; + struct rdt_l3_mon_domain *d; unsigned long dom_id, val; - struct rdt_mon_domain *d; =20 /* Walking r->domains, ensure it can't race with cpuhp */ lockdep_assert_cpus_held(); @@ -2579,7 +2579,7 @@ static int rdt_get_tree(struct fs_context *fc) { struct rdt_fs_context *ctx =3D rdt_fc2context(fc); unsigned long flags =3D RFTYPE_CTRL_BASE; - struct rdt_mon_domain *dom; + struct rdt_l3_mon_domain *dom; struct rdt_resource *r; int ret; =20 @@ -3031,11 +3031,11 @@ static void rmdir_mondata_subdir_allrdtgrp(struct r= dt_resource *r, =20 snc_mode =3D r->mon_scope =3D=3D RESCTRL_L3_NODE; if (snc_mode) { - struct rdt_mon_domain *d; + struct rdt_l3_mon_domain *d; =20 if (!domain_header_is_valid(hdr, RESCTRL_MON_DOMAIN, r->rid)) return; - d =3D container_of(hdr, struct rdt_mon_domain, hdr); + d =3D container_of(hdr, struct rdt_l3_mon_domain, hdr); sprintf(name, "mon_%s_%02d", r->name, d->ci->id); sprintf(subname, "mon_sub_%s_%02d", r->name, hdr->id); } else { @@ -3054,8 +3054,8 @@ static int mon_add_all_files(struct kernfs_node *kn, = struct rdt_domain_hdr *hdr, struct rdt_resource *r, struct rdtgroup *prgrp, bool do_sum) { + struct rdt_l3_mon_domain *d; struct rmid_read rr =3D {0}; - struct rdt_mon_domain *d; struct mon_data *priv; struct mon_evt *mevt; int ret, domid; @@ -3066,7 +3066,7 @@ static int mon_add_all_files(struct kernfs_node *kn, = struct rdt_domain_hdr *hdr, if (r->rid =3D=3D RDT_RESOURCE_L3) { if (!domain_header_is_valid(hdr, RESCTRL_MON_DOMAIN, r->rid)) return -EINVAL; - d =3D container_of(hdr, struct rdt_mon_domain, hdr); + d =3D container_of(hdr, struct rdt_l3_mon_domain, hdr); domid =3D do_sum ? d->ci->id : d->hdr.id; } else { domid =3D hdr->id; @@ -3091,7 +3091,7 @@ static int mkdir_mondata_subdir(struct kernfs_node *p= arent_kn, struct rdt_resource *r, struct rdtgroup *prgrp) { struct kernfs_node *kn, *ckn; - struct rdt_mon_domain *d; + struct rdt_l3_mon_domain *d; char name[32]; bool snc_mode; int ret =3D 0; @@ -3102,7 +3102,7 @@ static int mkdir_mondata_subdir(struct kernfs_node *p= arent_kn, if (snc_mode) { if (!domain_header_is_valid(hdr, RESCTRL_MON_DOMAIN, r->rid)) return -EINVAL; - d =3D container_of(hdr, struct rdt_mon_domain, hdr); + d =3D container_of(hdr, struct rdt_l3_mon_domain, hdr); sprintf(name, "mon_%s_%02d", r->name, d->ci->id); } else { sprintf(name, "mon_%s_%02d", r->name, hdr->id); @@ -4035,7 +4035,7 @@ static void rdtgroup_setup_default(void) mutex_unlock(&rdtgroup_mutex); } =20 -static void domain_destroy_mon_state(struct rdt_mon_domain *d) +static void domain_destroy_mon_state(struct rdt_l3_mon_domain *d) { bitmap_free(d->rmid_busy_llc); for (int i =3D 0; i < QOS_NUM_L3_MBM_EVENTS; i++) { @@ -4056,7 +4056,7 @@ void resctrl_offline_ctrl_domain(struct rdt_resource = *r, struct rdt_ctrl_domain =20 void resctrl_offline_mon_domain(struct rdt_resource *r, struct rdt_domain_= hdr *hdr) { - struct rdt_mon_domain *d; + struct rdt_l3_mon_domain *d; =20 mutex_lock(&rdtgroup_mutex); =20 @@ -4073,7 +4073,7 @@ void resctrl_offline_mon_domain(struct rdt_resource *= r, struct rdt_domain_hdr *h if (!domain_header_is_valid(hdr, RESCTRL_MON_DOMAIN, r->rid)) return; =20 - d =3D container_of(hdr, struct rdt_mon_domain, hdr); + d =3D container_of(hdr, struct rdt_l3_mon_domain, hdr); if (resctrl_is_mbm_enabled()) cancel_delayed_work(&d->mbm_over); if (resctrl_is_mon_event_enabled(QOS_L3_OCCUP_EVENT_ID) && has_busy_rmid(= d)) { @@ -4107,7 +4107,7 @@ void resctrl_offline_mon_domain(struct rdt_resource *= r, struct rdt_domain_hdr *h * * Returns 0 for success, or -ENOMEM. */ -static int domain_setup_l3_mon_state(struct rdt_resource *r, struct rdt_mo= n_domain *d) +static int domain_setup_l3_mon_state(struct rdt_resource *r, struct rdt_l3= _mon_domain *d) { u32 idx_limit =3D resctrl_arch_system_num_rmid_idx(); size_t tsize =3D sizeof(struct mbm_state); @@ -4158,7 +4158,7 @@ int resctrl_online_ctrl_domain(struct rdt_resource *r= , struct rdt_ctrl_domain *d =20 int resctrl_online_mon_domain(struct rdt_resource *r, struct rdt_domain_hd= r *hdr) { - struct rdt_mon_domain *d; + struct rdt_l3_mon_domain *d; int err =3D -EINVAL; =20 mutex_lock(&rdtgroup_mutex); @@ -4166,7 +4166,7 @@ int resctrl_online_mon_domain(struct rdt_resource *r,= struct rdt_domain_hdr *hdr if (!domain_header_is_valid(hdr, RESCTRL_MON_DOMAIN, r->rid)) goto out_unlock; =20 - d =3D container_of(hdr, struct rdt_mon_domain, hdr); + d =3D container_of(hdr, struct rdt_l3_mon_domain, hdr); err =3D domain_setup_l3_mon_state(r, d); if (err) goto out_unlock; @@ -4213,10 +4213,10 @@ static void clear_childcpus(struct rdtgroup *r, uns= igned int cpu) } } =20 -static struct rdt_mon_domain *get_mon_domain_from_cpu(int cpu, - struct rdt_resource *r) +static struct rdt_l3_mon_domain *get_mon_domain_from_cpu(int cpu, + struct rdt_resource *r) { - struct rdt_mon_domain *d; + struct rdt_l3_mon_domain *d; =20 lockdep_assert_cpus_held(); =20 @@ -4232,7 +4232,7 @@ static struct rdt_mon_domain *get_mon_domain_from_cpu= (int cpu, void resctrl_offline_cpu(unsigned int cpu) { struct rdt_resource *l3 =3D resctrl_arch_get_resource(RDT_RESOURCE_L3); - struct rdt_mon_domain *d; + struct rdt_l3_mon_domain *d; struct rdtgroup *rdtgrp; =20 mutex_lock(&rdtgroup_mutex); --=20 2.49.0 From nobody Sun Dec 14 19:24:21 2025 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 A9E2323D2BD for ; Wed, 21 May 2025 22:51:05 +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=1747867867; cv=none; b=B56cEzPnxfwurwEFQbE1zQ3hi8cMapgElpBFGMaMtzrtoOglU/v/I9e6JCLjTdSPzThNusDZBmi1tEWoL0MsSrJ7HUqGTUMzUciyRwu9M/x5Ht+IXND39HE24avlWtfNLPB43Nb4X5/zDgeXl33UNDkYVQozOevs3t8K5EG9Dco= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747867867; c=relaxed/simple; bh=RHtFrgfRLs7QN22cgd5bl7QEOXwgCvO4cbIQoDsFohU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LbsajmSBcb4dp7nG6yrd0t6nzterDJIATSNcFYF2sPHKmGviCMPIQ+9NcWH8wmk7aTsowaxnB0iL2XGjoPVMbKACGOwRGaYglmqfslwu5f9pQyeNLsmUAZVvWSIo44/ToMfTh0qnPIQ1S99KOtaQMFlEQMC+QcwPDZmyz6iRepI= 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=hexeCfGY; 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="hexeCfGY" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1747867866; x=1779403866; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=RHtFrgfRLs7QN22cgd5bl7QEOXwgCvO4cbIQoDsFohU=; b=hexeCfGYShobmIL0i81uoDEN9IHinlkpNWn45Ul+N6CPbQEOMFDV/Bpy vWHWaZK5tsT15PXAH3xUZ3dy+vgThaFzZGvphNbCTMRqaVhQrrm994rmh IzkFhjrp05wnYE5icP02jvvBDPU4cgVl9kxuegSqv2ZwUyLZ+GnWa1KwY dsxFfSp8OiEfaJl5MGzUWr3tS7H07swC7sIdZ1tasaTnA0PHUC9iYfpkG rvYZB1JLSFwmD/xenyTdIBm8vxr8FzrKrIx5mLTUaKme5GSSa9fG5NaLg PGsoKAWgajSF0lqAUd+4me6tbNSvfVLxTIhVM4z9Kc+PaHlrK9nQusB46 Q==; X-CSE-ConnectionGUID: h8dHBZPqTLexCj2+a6TJEw== X-CSE-MsgGUID: sclb3KtwSKKdwEVKjvGwTg== X-IronPort-AV: E=McAfee;i="6700,10204,11440"; a="53677710" X-IronPort-AV: E=Sophos;i="6.15,304,1739865600"; d="scan'208";a="53677710" 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:58 -0700 X-CSE-ConnectionGUID: 9dHqkLrHSkqYZHdaeQJkYQ== X-CSE-MsgGUID: Z9rqHpDhSFuEMmkdpeV6UQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,304,1739865600"; d="scan'208";a="141352157" 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:57 -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 12/29] fs/resctrl: Make event details accessible to functions when reading events Date: Wed, 21 May 2025 15:50:30 -0700 Message-ID: <20250521225049.132551-13-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" All details about a monitor event are kept in the mon_evt structure. Upper levels of code only provide the event id to lower levels. This will become a problem when new attributes are added to the mon_evt structure. Change the mon_data and rmid_read structures to hold a pointer to the mon_evt structure instead of just taking a copy of the event id. No functional change. Signed-off-by: Tony Luck --- fs/resctrl/internal.h | 10 +++++----- fs/resctrl/ctrlmondata.c | 16 ++++++++-------- fs/resctrl/monitor.c | 17 +++++++++-------- fs/resctrl/rdtgroup.c | 6 +++--- 4 files changed, 25 insertions(+), 24 deletions(-) diff --git a/fs/resctrl/internal.h b/fs/resctrl/internal.h index 8659ee33b76f..085a2ee1922f 100644 --- a/fs/resctrl/internal.h +++ b/fs/resctrl/internal.h @@ -73,7 +73,7 @@ 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. * @rid: Resource id associated with the event file. - * @evtid: Event id associated with the event file. + * @evt: Event associated with the event file. * @sum: Set when event must be summed across multiple * domains. * @domid: When @sum is zero this is the domain to which @@ -87,7 +87,7 @@ extern struct mon_evt mon_event_all[QOS_NUM_EVENTS]; struct mon_data { struct list_head list; enum resctrl_res_level rid; - enum resctrl_event_id evtid; + struct mon_evt *evt; int domid; bool sum; }; @@ -100,7 +100,7 @@ struct mon_data { * @r: Resource describing the properties of the event being read. * @d: Domain that the counter should be read from. If NULL then sum all * domains in @r sharing L3 @ci.id - * @evtid: Which monitor event to read. + * @evt: Which monitor event to read. * @first: Initialize MBM counter when true. * @ci: Cacheinfo for L3. Only set when @d is NULL. Used when summing d= omains. * @err: Error encountered when reading counter. @@ -114,7 +114,7 @@ struct rmid_read { struct rdtgroup *rgrp; struct rdt_resource *r; struct rdt_l3_mon_domain *d; - enum resctrl_event_id evtid; + struct mon_evt *evt; bool first; struct cacheinfo *ci; int err; @@ -350,7 +350,7 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg= ); =20 void mon_event_read(struct rmid_read *rr, struct rdt_resource *r, struct rdt_l3_mon_domain *d, struct rdtgroup *rdtgrp, - cpumask_t *cpumask, int evtid, int first); + cpumask_t *cpumask, struct mon_evt *evt, int first); =20 int resctrl_mon_resource_init(void); =20 diff --git a/fs/resctrl/ctrlmondata.c b/fs/resctrl/ctrlmondata.c index 6db24f7a3de5..dcde27f6f2ec 100644 --- a/fs/resctrl/ctrlmondata.c +++ b/fs/resctrl/ctrlmondata.c @@ -548,7 +548,7 @@ struct rdt_domain_hdr *resctrl_find_domain(struct list_= head *h, int id, =20 void mon_event_read(struct rmid_read *rr, struct rdt_resource *r, struct rdt_l3_mon_domain *d, struct rdtgroup *rdtgrp, - cpumask_t *cpumask, int evtid, int first) + cpumask_t *cpumask, struct mon_evt *evt, int first) { int cpu; =20 @@ -559,11 +559,11 @@ void mon_event_read(struct rmid_read *rr, struct rdt_= resource *r, * Setup the parameters to pass to mon_event_count() to read the data. */ rr->rgrp =3D rdtgrp; - rr->evtid =3D evtid; + rr->evt =3D evt; rr->r =3D r; rr->d =3D d; rr->first =3D first; - rr->arch_mon_ctx =3D resctrl_arch_mon_ctx_alloc(r, evtid); + rr->arch_mon_ctx =3D resctrl_arch_mon_ctx_alloc(r, evt->evtid); if (IS_ERR(rr->arch_mon_ctx)) { rr->err =3D -EINVAL; return; @@ -582,20 +582,20 @@ void mon_event_read(struct rmid_read *rr, struct rdt_= resource *r, else smp_call_on_cpu(cpu, smp_mon_event_count, rr, false); =20 - resctrl_arch_mon_ctx_free(r, evtid, rr->arch_mon_ctx); + resctrl_arch_mon_ctx_free(r, evt->evtid, rr->arch_mon_ctx); } =20 int rdtgroup_mondata_show(struct seq_file *m, void *arg) { struct kernfs_open_file *of =3D m->private; enum resctrl_res_level resid; - enum resctrl_event_id evtid; struct rdt_l3_mon_domain *d; struct rdt_domain_hdr *hdr; struct rmid_read rr =3D {0}; struct rdtgroup *rdtgrp; struct rdt_resource *r; struct mon_data *md; + struct mon_evt *evt; int domid, ret =3D 0; =20 rdtgrp =3D rdtgroup_kn_lock_live(of->kn); @@ -612,7 +612,7 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg) =20 resid =3D md->rid; domid =3D md->domid; - evtid =3D md->evtid; + evt =3D md->evt; r =3D resctrl_arch_get_resource(resid); =20 if (md->sum) { @@ -626,7 +626,7 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg) if (d->ci->id =3D=3D domid) { rr.ci =3D d->ci; mon_event_read(&rr, r, NULL, rdtgrp, - &d->ci->shared_cpu_map, evtid, false); + &d->ci->shared_cpu_map, evt, false); goto checkresult; } } @@ -643,7 +643,7 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg) goto out; } d =3D container_of(hdr, struct rdt_l3_mon_domain, hdr); - mon_event_read(&rr, r, d, rdtgrp, &d->hdr.cpu_mask, evtid, false); + mon_event_read(&rr, r, d, rdtgrp, &d->hdr.cpu_mask, evt, false); } =20 checkresult: diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c index c1d248a7fdbc..3cfd1bf1845e 100644 --- a/fs/resctrl/monitor.c +++ b/fs/resctrl/monitor.c @@ -365,8 +365,8 @@ static int __mon_event_count(u32 closid, u32 rmid, stru= ct rmid_read *rr) u64 tval =3D 0; =20 if (rr->first) { - resctrl_arch_reset_rmid(rr->r, rr->d, closid, rmid, rr->evtid); - m =3D get_mbm_state(rr->d, closid, rmid, rr->evtid); + resctrl_arch_reset_rmid(rr->r, rr->d, closid, rmid, rr->evt->evtid); + m =3D get_mbm_state(rr->d, closid, rmid, rr->evt->evtid); if (m) memset(m, 0, sizeof(struct mbm_state)); return 0; @@ -377,7 +377,7 @@ static int __mon_event_count(u32 closid, u32 rmid, stru= ct rmid_read *rr) if (!cpumask_test_cpu(cpu, &rr->d->hdr.cpu_mask)) return -EINVAL; rr->err =3D resctrl_arch_rmid_read(rr->r, rr->d, closid, rmid, - rr->evtid, &tval, rr->arch_mon_ctx); + rr->evt->evtid, &tval, rr->arch_mon_ctx); if (rr->err) return rr->err; =20 @@ -402,7 +402,7 @@ static int __mon_event_count(u32 closid, u32 rmid, stru= ct rmid_read *rr) if (d->ci->id !=3D rr->ci->id) continue; err =3D resctrl_arch_rmid_read(rr->r, d, closid, rmid, - rr->evtid, &tval, rr->arch_mon_ctx); + rr->evt->evtid, &tval, rr->arch_mon_ctx); if (!err) { rr->val +=3D tval; ret =3D 0; @@ -432,7 +432,7 @@ static void mbm_bw_count(u32 closid, u32 rmid, struct r= mid_read *rr) u64 cur_bw, bytes, cur_bytes; struct mbm_state *m; =20 - m =3D get_mbm_state(rr->d, closid, rmid, rr->evtid); + m =3D get_mbm_state(rr->d, closid, rmid, rr->evt->evtid); if (WARN_ON_ONCE(!m)) return; =20 @@ -603,12 +603,13 @@ static void update_mba_bw(struct rdtgroup *rgrp, stru= ct rdt_l3_mon_domain *dom_m static void mbm_update_one_event(struct rdt_resource *r, struct rdt_l3_mon= _domain *d, u32 closid, u32 rmid, enum resctrl_event_id evtid) { + struct mon_evt *evt =3D &mon_event_all[evtid]; struct rmid_read rr =3D {0}; =20 rr.r =3D r; rr.d =3D d; - rr.evtid =3D evtid; - rr.arch_mon_ctx =3D resctrl_arch_mon_ctx_alloc(rr.r, rr.evtid); + rr.evt =3D evt; + rr.arch_mon_ctx =3D resctrl_arch_mon_ctx_alloc(rr.r, evt->evtid); if (IS_ERR(rr.arch_mon_ctx)) { pr_warn_ratelimited("Failed to allocate monitor context: %ld", PTR_ERR(rr.arch_mon_ctx)); @@ -624,7 +625,7 @@ static void mbm_update_one_event(struct rdt_resource *r= , struct rdt_l3_mon_domai if (is_mba_sc(NULL)) mbm_bw_count(closid, rmid, &rr); =20 - resctrl_arch_mon_ctx_free(rr.r, rr.evtid, rr.arch_mon_ctx); + resctrl_arch_mon_ctx_free(rr.r, evt->evtid, rr.arch_mon_ctx); } =20 static void mbm_update(struct rdt_resource *r, struct rdt_l3_mon_domain *d, diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index 39e046fba60a..67482f1110b3 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -2897,7 +2897,7 @@ static struct mon_data *mon_get_kn_priv(enum resctrl_= res_level rid, int domid, =20 list_for_each_entry(priv, &mon_data_kn_priv_list, list) { if (priv->rid =3D=3D rid && priv->domid =3D=3D domid && - priv->sum =3D=3D do_sum && priv->evtid =3D=3D mevt->evtid) + priv->sum =3D=3D do_sum && priv->evt =3D=3D mevt) return priv; } =20 @@ -2908,7 +2908,7 @@ static struct mon_data *mon_get_kn_priv(enum resctrl_= res_level rid, int domid, priv->rid =3D rid; priv->domid =3D domid; priv->sum =3D do_sum; - priv->evtid =3D mevt->evtid; + priv->evt =3D mevt; list_add_tail(&priv->list, &mon_data_kn_priv_list); =20 return priv; @@ -3080,7 +3080,7 @@ static int mon_add_all_files(struct kernfs_node *kn, = struct rdt_domain_hdr *hdr, return ret; =20 if (r->rid =3D=3D RDT_RESOURCE_L3 && !do_sum && resctrl_is_mbm_event(mev= t->evtid)) - mon_event_read(&rr, r, d, prgrp, &hdr->cpu_mask, mevt->evtid, true); + mon_event_read(&rr, r, d, prgrp, &hdr->cpu_mask, mevt, true); } =20 return 0; --=20 2.49.0 From nobody Sun Dec 14 19:24:21 2025 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 A9D8F23D2BC for ; Wed, 21 May 2025 22:51:05 +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=1747867867; cv=none; b=Gvj8hTER2jTlP7k9GtFQVi8q1wx0Hs0vYs1Dl1v/CSiC2vmdYyL4Po0obU0evZvZn9EAnMNp/1ZlmsVZHeubMjm1ubo5BoO99n/jIqOf5U6GHYNj9zTgOK//GO8JtMtyR6Dci281beVGxT6yw/KE7+auh2nKxV4KgOygPtsGjoc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747867867; c=relaxed/simple; bh=YkH8pInjOA8YZNAMBZOi7J5lUe3CDx68wNebUeznpXQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=d5i71dc9fvRO3IA5LEgvcDPyInyosoLYbx04HKPUMc/50Rks268G2RLl6WEnGqogJP16irTSst1yf9IfwVuWrz4H7neAkK+J5iaDxBbz3x56VJzNt+zlOvqQLbDKcD0LcGxz7K0q4fVq7UVUgET1uJE2keBCS2CqNc3BaYUaqtc= 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=lDjYg64s; 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="lDjYg64s" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1747867866; x=1779403866; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=YkH8pInjOA8YZNAMBZOi7J5lUe3CDx68wNebUeznpXQ=; b=lDjYg64sMUSHjV7qHLV5CVOEwzDBXHkqbbBkPbNpYNsYKVBGkoJtDpzL /l0kSkmwazl70xUi8BYqRa3kowHZ0qT0bsQsokUDM5bu66Vk+EAB3kbrx btBRN+pIA6+jLidcnwKta5D4/yPwp/vPAicJmLwD/h2QyawlkKsdofBnK Iwe+Qi2KHSUaeCv1lM0Kg1vi0h81oN9OfHqreHzWnaJpxav8xHHIsOSKh 5/vBaDEGCnaKqgYDRIxzID4UbZNDbd19Qq5KMGLDl3UCZU8fvNL990OJp 8bAwjifTqzl+0yF2t1lOrtkKK4Yi4iFM9WbF0ZnBElHt2SIVlNS118Poi g==; X-CSE-ConnectionGUID: eEHbmFxnRv2iM+wYF9Nt+A== X-CSE-MsgGUID: r9YYsiZ9QHu7kUFFVzrKFQ== X-IronPort-AV: E=McAfee;i="6700,10204,11440"; a="53677726" X-IronPort-AV: E=Sophos;i="6.15,304,1739865600"; d="scan'208";a="53677726" 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:59 -0700 X-CSE-ConnectionGUID: 8xVbxhROS22n7AbDQJZEVw== X-CSE-MsgGUID: S1pT8Y/cQ/udrchiuI3Q7g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,304,1739865600"; d="scan'208";a="141352160" 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:58 -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 13/29] x86,fs/resctrl: Handle events that can be read from any CPU Date: Wed, 21 May 2025 15:50:31 -0700 Message-ID: <20250521225049.132551-14-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" Resctrl file system code was built with the assumption that monitor events can only be read from a CPU in the cpumask_t set for each domain. This was true for x86 events accessed with an MSR interface, but may not be true for other access methods such as MMIO. Add a flag to struct mon_evt to indicate which events can be read on any CPU. Architecture uses resctrl_enable_mon_event() to enable an event and set the flag appropriately. Bypass all the smp_call*() code for events that can be read on any CPU and call mon_event_count() directly from mon_event_read(). Skip checks in __mon_event_count() that the read is being done from a CPU in the correct domain or cache scope. Signed-off-by: Tony Luck --- include/linux/resctrl.h | 2 +- fs/resctrl/internal.h | 2 ++ arch/x86/kernel/cpu/resctrl/core.c | 6 +++--- fs/resctrl/ctrlmondata.c | 7 ++++++- fs/resctrl/monitor.c | 26 ++++++++++++++++++++------ 5 files changed, 32 insertions(+), 11 deletions(-) diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index b7a4c7bf4feb..9aab3d78005a 100644 --- a/include/linux/resctrl.h +++ b/include/linux/resctrl.h @@ -377,7 +377,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 evtid); +void resctrl_enable_mon_event(enum resctrl_event_id evtid, bool any_cpu); =20 bool resctrl_is_mon_event_enabled(enum resctrl_event_id evt); =20 diff --git a/fs/resctrl/internal.h b/fs/resctrl/internal.h index 085a2ee1922f..eb6e92d1ab15 100644 --- a/fs/resctrl/internal.h +++ b/fs/resctrl/internal.h @@ -57,6 +57,7 @@ static inline struct rdt_fs_context *rdt_fc2context(struc= t fs_context *fc) * @rid: index of the resource for this event * @name: name of the event * @configurable: true if the event is configurable + * @any_cpu: true if the event can be read from any CPU * @enabled: true if the event is enabled */ struct mon_evt { @@ -64,6 +65,7 @@ struct mon_evt { enum resctrl_res_level rid; char *name; bool configurable; + bool any_cpu; bool enabled; }; =20 diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resct= rl/core.c index b39537658618..5d9a024ce4b0 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -880,15 +880,15 @@ static __init bool get_rdt_mon_resources(void) bool ret =3D false; =20 if (rdt_cpu_has(X86_FEATURE_CQM_OCCUP_LLC)) { - resctrl_enable_mon_event(QOS_L3_OCCUP_EVENT_ID); + resctrl_enable_mon_event(QOS_L3_OCCUP_EVENT_ID, false); ret =3D true; } if (rdt_cpu_has(X86_FEATURE_CQM_MBM_TOTAL)) { - resctrl_enable_mon_event(QOS_L3_MBM_TOTAL_EVENT_ID); + resctrl_enable_mon_event(QOS_L3_MBM_TOTAL_EVENT_ID, false); ret =3D true; } if (rdt_cpu_has(X86_FEATURE_CQM_MBM_LOCAL)) { - resctrl_enable_mon_event(QOS_L3_MBM_LOCAL_EVENT_ID); + resctrl_enable_mon_event(QOS_L3_MBM_LOCAL_EVENT_ID, false); ret =3D true; } =20 diff --git a/fs/resctrl/ctrlmondata.c b/fs/resctrl/ctrlmondata.c index dcde27f6f2ec..1337716f59c8 100644 --- a/fs/resctrl/ctrlmondata.c +++ b/fs/resctrl/ctrlmondata.c @@ -569,6 +569,11 @@ void mon_event_read(struct rmid_read *rr, struct rdt_r= esource *r, return; } =20 + if (evt->any_cpu) { + mon_event_count(rr); + goto done; + } + cpu =3D cpumask_any_housekeeping(cpumask, RESCTRL_PICK_ANY_CPU); =20 /* @@ -581,7 +586,7 @@ void mon_event_read(struct rmid_read *rr, struct rdt_re= source *r, smp_call_function_any(cpumask, mon_event_count, rr, 1); else smp_call_on_cpu(cpu, smp_mon_event_count, rr, false); - +done: resctrl_arch_mon_ctx_free(r, evt->evtid, rr->arch_mon_ctx); } =20 diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c index 3cfd1bf1845e..e6e3be990638 100644 --- a/fs/resctrl/monitor.c +++ b/fs/resctrl/monitor.c @@ -356,9 +356,24 @@ static struct mbm_state *get_mbm_state(struct rdt_l3_m= on_domain *d, u32 closid, return states ? &states[idx] : NULL; } =20 +static bool cpu_on_wrong_domain(struct rmid_read *rr) +{ + cpumask_t *mask; + + if (rr->evt->any_cpu) + return false; + + /* + * When reading from a specific domain the CPU must be in that + * domain. Otherwise the CPU must be one that shares the cache. + */ + mask =3D rr->d ? &rr->d->hdr.cpu_mask : &rr->ci->shared_cpu_map; + + return !cpumask_test_cpu(smp_processor_id(), mask); +} + static int __mon_event_count(u32 closid, u32 rmid, struct rmid_read *rr) { - int cpu =3D smp_processor_id(); struct rdt_l3_mon_domain *d; struct mbm_state *m; int err, ret; @@ -373,8 +388,7 @@ static int __mon_event_count(u32 closid, u32 rmid, stru= ct rmid_read *rr) } =20 if (rr->d) { - /* Reading a single domain, must be on a CPU in that domain. */ - if (!cpumask_test_cpu(cpu, &rr->d->hdr.cpu_mask)) + if (cpu_on_wrong_domain(rr)) return -EINVAL; rr->err =3D resctrl_arch_rmid_read(rr->r, rr->d, closid, rmid, rr->evt->evtid, &tval, rr->arch_mon_ctx); @@ -386,8 +400,7 @@ static int __mon_event_count(u32 closid, u32 rmid, stru= ct rmid_read *rr) return 0; } =20 - /* Summing domains that share a cache, must be on a CPU for that cache. */ - if (!cpumask_test_cpu(cpu, &rr->ci->shared_cpu_map)) + if (cpu_on_wrong_domain(rr)) return -EINVAL; =20 /* @@ -865,7 +878,7 @@ struct mon_evt mon_event_all[QOS_NUM_EVENTS] =3D { }, }; =20 -void resctrl_enable_mon_event(enum resctrl_event_id evtid) +void resctrl_enable_mon_event(enum resctrl_event_id evtid, bool any_cpu) { if (WARN_ON_ONCE(evtid >=3D QOS_NUM_EVENTS)) return; @@ -874,6 +887,7 @@ void resctrl_enable_mon_event(enum resctrl_event_id evt= id) return; } =20 + mon_event_all[evtid].any_cpu =3D any_cpu; mon_event_all[evtid].enabled =3D true; } =20 --=20 2.49.0 From nobody Sun Dec 14 19:24:21 2025 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 2064E23ED68 for ; Wed, 21 May 2025 22:51:07 +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=1747867869; cv=none; b=XZ2FcC5zS7aQ4whK86cFbk898tzxqMZUourJJFzSROAy9a3zPR82SSREG+n0UijM3IDBiDIFJ1y562Wni0I7YZYlNSLhCbLKfqTbd4OePjQOLD3MxsGr7EuRRnF4gASX2OorCU/hodW7DyBFCBy7b2p+M5f83cSnfKF20bhwu9E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747867869; c=relaxed/simple; bh=5gTvtBqwCiz3yA1qAMmHe8YRGbU+roL/wG25p3KREaY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GZMalLVmOmxcoEtc+iZ7KhP7hQ177qZH7t/WbZYg9bAOBv8FjQ3TaZmkfSpGCEDRRyn6Ofk3eOAgXSIqtiJAeVNkp+yZW0LEezSk6AIt5MTB3aDQ54NsPUxOsEwPpd0RaYApkWNOx4LAk30tYmSmK1lTJG6GyxgV7NTUFrQ4e78= 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=NJDWBfNg; 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="NJDWBfNg" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1747867867; x=1779403867; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5gTvtBqwCiz3yA1qAMmHe8YRGbU+roL/wG25p3KREaY=; b=NJDWBfNg7LL1lASBzRuZDJCq58Hau+RmhR1QXIgYaslPnVDOhk6hOxOi F3z0LYFGGt6jQnMRb4qY/9si5rOK34/Zx5vSmifc9RgMuZSRMIGITJQ+6 uTHo6AAgN32u2iy9IjQXtbU+zt+YvCgJuBZ/uGWFSGSPr9a+GqH8iUsQO XJcNlYvbOxMBpAgHpfgBjIcnHhyAMROwRnWOeTpJGMIp79aLoB5Nri0eW L3sDDsUcN8Zv5V346xvsEcP+A6bZmaoKM5gQkouLy8bkLHAJuDzoX5++H duiwBrbkwFJT2ES02UF7Mc+Bc3nsL5Y3qnp4FugvfbZMg4OKKMnD67XCP g==; X-CSE-ConnectionGUID: JLfsFts1SDSHVrh++6OqXA== X-CSE-MsgGUID: +oT6ZQTPQGys3z59C1BCzw== X-IronPort-AV: E=McAfee;i="6700,10204,11440"; a="53677748" X-IronPort-AV: E=Sophos;i="6.15,304,1739865600"; d="scan'208";a="53677748" 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:59 -0700 X-CSE-ConnectionGUID: VNWoHoMIQA+WSFuxGpzYVg== X-CSE-MsgGUID: wUTivwGkTjOI0RJAbTWDQA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,304,1739865600"; d="scan'208";a="141352163" 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:58 -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 14/29] x86,fs/resctrl: Support binary fixed point event counters Date: Wed, 21 May 2025 15:50:32 -0700 Message-ID: <20250521225049.132551-15-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" Resctrl was written with the assumption that all monitor events can be displayed as unsigned decimal integers. Hardware architecture counters may provide some telemetry events with greater precision where the event is not a simple count, but is a measurement of some sort (e.g. Joules for energy consumed). Add a new argument to resctrl_enable_mon_event() for architecture code to inform the file system that the value for a counter is a fixed-point value with a specific number of binary places. Fixed point values are displayed with values rounded to an appropriate number of decimal places. Signed-off-by: Tony Luck --- include/linux/resctrl.h | 4 +- fs/resctrl/internal.h | 2 + arch/x86/kernel/cpu/resctrl/core.c | 6 +-- fs/resctrl/ctrlmondata.c | 75 +++++++++++++++++++++++++++++- fs/resctrl/monitor.c | 5 +- 5 files changed, 85 insertions(+), 7 deletions(-) diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index 9aab3d78005a..46ba62ee94a1 100644 --- a/include/linux/resctrl.h +++ b/include/linux/resctrl.h @@ -377,7 +377,9 @@ 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 any_cpu); +#define MAX_BINARY_BITS 27 + +void resctrl_enable_mon_event(enum resctrl_event_id evtid, bool any_cpu, u= 32 binary_bits); =20 bool resctrl_is_mon_event_enabled(enum resctrl_event_id evt); =20 diff --git a/fs/resctrl/internal.h b/fs/resctrl/internal.h index eb6e92d1ab15..d5045491790e 100644 --- a/fs/resctrl/internal.h +++ b/fs/resctrl/internal.h @@ -58,6 +58,7 @@ static inline struct rdt_fs_context *rdt_fc2context(struc= t fs_context *fc) * @name: name of the event * @configurable: true if the event is configurable * @any_cpu: true if the event can be read from any CPU + * @binary_bits: number of fixed-point binary bits from architecture * @enabled: true if the event is enabled */ struct mon_evt { @@ -66,6 +67,7 @@ struct mon_evt { char *name; bool configurable; bool any_cpu; + int binary_bits; bool enabled; }; =20 diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resct= rl/core.c index 5d9a024ce4b0..306afb50fd37 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -880,15 +880,15 @@ static __init bool get_rdt_mon_resources(void) bool ret =3D false; =20 if (rdt_cpu_has(X86_FEATURE_CQM_OCCUP_LLC)) { - resctrl_enable_mon_event(QOS_L3_OCCUP_EVENT_ID, false); + resctrl_enable_mon_event(QOS_L3_OCCUP_EVENT_ID, false, 0); ret =3D true; } if (rdt_cpu_has(X86_FEATURE_CQM_MBM_TOTAL)) { - resctrl_enable_mon_event(QOS_L3_MBM_TOTAL_EVENT_ID, false); + resctrl_enable_mon_event(QOS_L3_MBM_TOTAL_EVENT_ID, false, 0); ret =3D true; } if (rdt_cpu_has(X86_FEATURE_CQM_MBM_LOCAL)) { - resctrl_enable_mon_event(QOS_L3_MBM_LOCAL_EVENT_ID, false); + resctrl_enable_mon_event(QOS_L3_MBM_LOCAL_EVENT_ID, false, 0); ret =3D true; } =20 diff --git a/fs/resctrl/ctrlmondata.c b/fs/resctrl/ctrlmondata.c index 1337716f59c8..07bf44834a46 100644 --- a/fs/resctrl/ctrlmondata.c +++ b/fs/resctrl/ctrlmondata.c @@ -590,6 +590,77 @@ void mon_event_read(struct rmid_read *rr, struct rdt_r= esource *r, resctrl_arch_mon_ctx_free(r, evt->evtid, rr->arch_mon_ctx); } =20 +/** + * struct fixed_params - parameters to decode a binary fixed point value + * @mask: Mask for fractional part of value. + * @lshift: Shift to round-up binary places. + * @pow10: Multiplier (10 ^ decimal places). + * @round: Add to round up to nearest decimal representation. + * @rshift: Shift back for final answer. + * @decplaces: Number of decimal places for this number of binary places. + */ +struct fixed_params { + u64 mask; + int lshift; + int pow10; + u64 round; + int rshift; + int decplaces; +}; + +static struct fixed_params fixed_params[MAX_BINARY_BITS + 1] =3D { + [1] =3D { GENMASK_ULL(1, 0), 0, 10, 0x00000000, 1, 1 }, + [2] =3D { GENMASK_ULL(2, 0), 0, 100, 0x00000000, 2, 2 }, + [3] =3D { GENMASK_ULL(3, 0), 0, 1000, 0x00000000, 3, 3 }, + [4] =3D { GENMASK_ULL(4, 0), 2, 1000, 0x00000020, 6, 3 }, + [5] =3D { GENMASK_ULL(5, 0), 1, 1000, 0x00000020, 6, 3 }, + [6] =3D { GENMASK_ULL(6, 0), 0, 1000, 0x00000020, 6, 3 }, + [7] =3D { GENMASK_ULL(7, 0), 2, 1000, 0x00000100, 9, 3 }, + [8] =3D { GENMASK_ULL(8, 0), 1, 1000, 0x00000100, 9, 3 }, + [9] =3D { GENMASK_ULL(9, 0), 0, 1000, 0x00000100, 9, 3 }, + [10] =3D { GENMASK_ULL(10, 0), 2, 10000, 0x00000800, 12, 4 }, + [11] =3D { GENMASK_ULL(11, 0), 1, 10000, 0x00000800, 12, 4 }, + [12] =3D { GENMASK_ULL(12, 0), 0, 10000, 0x00000800, 12, 4 }, + [13] =3D { GENMASK_ULL(13, 0), 2, 100000, 0x00004000, 15, 5 }, + [14] =3D { GENMASK_ULL(14, 0), 1, 100000, 0x00004000, 15, 5 }, + [15] =3D { GENMASK_ULL(15, 0), 0, 100000, 0x00004000, 15, 5 }, + [16] =3D { GENMASK_ULL(16, 0), 2, 1000000, 0x00020000, 18, 6 }, + [17] =3D { GENMASK_ULL(17, 0), 1, 1000000, 0x00020000, 18, 6 }, + [18] =3D { GENMASK_ULL(18, 0), 0, 1000000, 0x00020000, 18, 6 }, + [19] =3D { GENMASK_ULL(19, 0), 2, 10000000, 0x00100000, 21, 7 }, + [20] =3D { GENMASK_ULL(20, 0), 1, 10000000, 0x00100000, 21, 7 }, + [21] =3D { GENMASK_ULL(21, 0), 0, 10000000, 0x00100000, 21, 7 }, + [22] =3D { GENMASK_ULL(22, 0), 2, 100000000, 0x00800000, 24, 8 }, + [23] =3D { GENMASK_ULL(23, 0), 1, 100000000, 0x00800000, 24, 8 }, + [24] =3D { GENMASK_ULL(24, 0), 0, 100000000, 0x00800000, 24, 8 }, + [25] =3D { GENMASK_ULL(25, 0), 2, 1000000000, 0x04000000, 27, 9 }, + [26] =3D { GENMASK_ULL(26, 0), 1, 1000000000, 0x04000000, 27, 9 }, + [27] =3D { GENMASK_ULL(27, 0), 0, 1000000000, 0x04000000, 27, 9 } +}; + +static void print_event_value(struct seq_file *m, int binary_bits, u64 val) +{ + struct fixed_params *fp =3D &fixed_params[binary_bits]; + unsigned long long frac; + char buf[10]; + + frac =3D val & fp->mask; + frac <<=3D fp->lshift; + frac *=3D fp->pow10; + frac +=3D fp->round; + frac >>=3D fp->rshift; + + sprintf(buf, "%0*llu", fp->decplaces, frac); + + /* Trim trailing zeroes */ + for (int i =3D fp->decplaces - 1; i > 0; i--) { + if (buf[i] !=3D '0') + break; + buf[i] =3D '\0'; + } + seq_printf(m, "%llu.%s\n", val >> binary_bits, buf); +} + int rdtgroup_mondata_show(struct seq_file *m, void *arg) { struct kernfs_open_file *of =3D m->private; @@ -657,8 +728,10 @@ int rdtgroup_mondata_show(struct seq_file *m, void *ar= g) seq_puts(m, "Error\n"); else if (rr.err =3D=3D -EINVAL) seq_puts(m, "Unavailable\n"); - else + else if (evt->binary_bits =3D=3D 0) seq_printf(m, "%llu\n", rr.val); + else + print_event_value(m, evt->binary_bits, rr.val); =20 out: rdtgroup_kn_unlock(of->kn); diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c index e6e3be990638..f554d7933739 100644 --- a/fs/resctrl/monitor.c +++ b/fs/resctrl/monitor.c @@ -878,9 +878,9 @@ struct mon_evt mon_event_all[QOS_NUM_EVENTS] =3D { }, }; =20 -void resctrl_enable_mon_event(enum resctrl_event_id evtid, bool any_cpu) +void resctrl_enable_mon_event(enum resctrl_event_id evtid, bool any_cpu, u= 32 binary_bits) { - if (WARN_ON_ONCE(evtid >=3D QOS_NUM_EVENTS)) + if (WARN_ON_ONCE(evtid >=3D QOS_NUM_EVENTS) || binary_bits > MAX_BINARY_B= ITS) return; if (mon_event_all[evtid].enabled) { pr_warn("Duplicate enable for event %d\n", evtid); @@ -888,6 +888,7 @@ void resctrl_enable_mon_event(enum resctrl_event_id evt= id, bool any_cpu) } =20 mon_event_all[evtid].any_cpu =3D any_cpu; + mon_event_all[evtid].binary_bits =3D binary_bits; mon_event_all[evtid].enabled =3D true; } =20 --=20 2.49.0 From nobody Sun Dec 14 19:24:21 2025 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 0FA05241105 for ; Wed, 21 May 2025 22:51:08 +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=1747867870; cv=none; b=W5mKAtVb9zIFaVovPlHD6x+tXZ1Bk5jb7Yyr0AWqoRN+zuVYUA+S8/E838RSi2F+Pwj1aSgpejO884aetAV4vmeEku7vsMa+JCgUPzGrQDBXqoJw7CwEktcL5VUxjPIIOlh1jBaU3vLFkD86nFaL+/rRAVuaZwPIPbXZalA0EFE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747867870; c=relaxed/simple; bh=0F07DEq15poZiIZ6S3FcEqN2NGOe2aVEvkV51hDbxXk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KuLebyMc1Y838U70Q9paNIiC3gdSqAl4GGstfONv4U+x7fy+XH8oYJLSUOQtHuB7czOm5W/ifR2Y6hVR3lqLNNa50pkbAQPkBU92+G6wgYz/ErCwptfr8CcCnaejApBpWkcWwPm9I8bRheSiynKMpujgfd2NSLgzf5gaLXU4pOE= 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=F+JVQxhS; 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="F+JVQxhS" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1747867868; x=1779403868; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=0F07DEq15poZiIZ6S3FcEqN2NGOe2aVEvkV51hDbxXk=; b=F+JVQxhSdGEvbkgH5nG3VSKQ2LzJ7ybbqM2hbrzjDTeQIERy2QLdhyuZ 4vWL5o+vq162hfi1p/pWBIwhokjHlAfPg+UmerZWfkMN922DiAfwHNt6a my4xLZ3eT/hCnxVMJBYTCD0OQEME/v2PpJE4kQDMvcF6+jdr66WUQg9ro If4Q7KVQ+PLL2FVBZL4wdm+SYt8cwXwtG/mdqTFa4/ozcZL33iJnNhdun H013RBnaGEbboC0ey+nXYmCbWjfcxgU1slHt/wzbVaPg5CnYhhM3QgX10 llhKeqjooNqroLhFY2jpZL5SXCE6yUpXYudcudPXsXkJMyOku/lNtnPYz Q==; X-CSE-ConnectionGUID: xtABFvAtQLqM4FB3xx6LQQ== X-CSE-MsgGUID: vXYJczYLSN21yFMD/wKjzg== X-IronPort-AV: E=McAfee;i="6700,10204,11440"; a="53677774" X-IronPort-AV: E=Sophos;i="6.15,304,1739865600"; d="scan'208";a="53677774" 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:59 -0700 X-CSE-ConnectionGUID: NPkrjNmiRNmXRyNsKiRtZQ== X-CSE-MsgGUID: 1g6f3jqtQZuZ1PGErah1ig== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,304,1739865600"; d="scan'208";a="141352166" 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:58 -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 15/29] fs/resctrl: Add an architectural hook called for each mount Date: Wed, 21 May 2025 15:50:33 -0700 Message-ID: <20250521225049.132551-16-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" Enumeration of Intel telemetry events is not complete when the resctrl "late_init" code is executed. Add a hook at the beginning of the mount code that will be used to check for telemetry events and initialize if any are found. The hook is called on every attempted mount. But expectations are that most actions (like enumeration) will only need to be performed on the first call. The call is made with no locks held. Architecture code is responsible for any required locking. Signed-off-by: Tony Luck --- include/linux/resctrl.h | 6 ++++++ arch/x86/kernel/cpu/resctrl/core.c | 9 +++++++++ fs/resctrl/rdtgroup.c | 2 ++ 3 files changed, 17 insertions(+) diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index 46ba62ee94a1..4ad3d7f10580 100644 --- a/include/linux/resctrl.h +++ b/include/linux/resctrl.h @@ -452,6 +452,12 @@ void resctrl_offline_mon_domain(struct rdt_resource *r= , struct rdt_domain_hdr *h void resctrl_online_cpu(unsigned int cpu); void resctrl_offline_cpu(unsigned int cpu); =20 +/* + * Architecture hook called for each attempted file system mount. + * No locks are held. + */ +void resctrl_arch_pre_mount(void); + /** * resctrl_arch_rmid_read() - Read the eventid counter corresponding to rm= id * for this resource and domain. diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resct= rl/core.c index 306afb50fd37..f8c9840ce7dc 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -710,6 +710,15 @@ static int resctrl_arch_offline_cpu(unsigned int cpu) return 0; } =20 +void resctrl_arch_pre_mount(void) +{ + static atomic_t only_once; + int old =3D 0; + + if (!atomic_try_cmpxchg(&only_once, &old, 1)) + return; +} + enum { RDT_FLAG_CMT, RDT_FLAG_MBM_TOTAL, diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index 67482f1110b3..bdad98ac0d27 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -2583,6 +2583,8 @@ static int rdt_get_tree(struct fs_context *fc) struct rdt_resource *r; int ret; =20 + resctrl_arch_pre_mount(); + cpus_read_lock(); mutex_lock(&rdtgroup_mutex); /* --=20 2.49.0 From nobody Sun Dec 14 19:24:21 2025 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 0FADC241116 for ; Wed, 21 May 2025 22:51:08 +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=1747867870; cv=none; b=QfQHtE022MGAo0VgPQpPLSsHy+VHqeKKZ5bhMeeq3iSpEbTbSoDdoNJvhZ8FF2rI7A3/2dosfHV6m3wLQ3rQr2tpejDj/z+h2pvDIEBpr2TVTFvUHZc+ynpwmn1R3L647e2ITJPMhrv5nYqi6N++leW9v1PVLY2MKxN2LrN8NW8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747867870; c=relaxed/simple; bh=DPZAwBEsXW/4j3Zsp6qfubUvBA55fJAptJ9A0jOaC7M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dIExCARE2guRNPL5oG1W2saZLQFK/m3h/vMyyf/MpxJZHCJKzfcGklVvt7nPb6v4Qlp3KGd31fRe2uYmxayP1ZtFeVKh69US3HfqfWfKbEFDc0x2CU6b2lGAwL0Op7b9KDyNBLTbBWb+0wX4a2aPlnZM92fuGECvKKbMr4QtYHQ= 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=Au65npNB; 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="Au65npNB" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1747867868; x=1779403868; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=DPZAwBEsXW/4j3Zsp6qfubUvBA55fJAptJ9A0jOaC7M=; b=Au65npNBTd5ddihk3EaHUQoijCtPCIA4uv46a15Yu80wyMdMn7pirtKT 96veSDXGnFBJ0dSpEaskYGiiaefd6W7OUeHWZjWXFjXpGEGfDO6D4tUfu UgRnEwLUVfGCR5UlCEsuOXiK+AZ9U+N9DmtshEafZr9f5QquBxC7rxSVr /HP/o08ke6zgfEBzMiOQrRMUyzvYPRURS8XxtfJW7Upo0chZmwjBwnsKg vBwKneAL+7cJ0l8KfJ+ciqPfkwshTPvGEgipZYH84hNaRwNEOnQlEWs28 1PfLLsykHRDFdb4y4hXpQW6j+qVMfIqlVI6XrfsrmpvXPg6uxtrjNzh8C w==; X-CSE-ConnectionGUID: rEvtst+KQvWd7jHsRE/wIw== X-CSE-MsgGUID: DSUyB0tUR/upANnD6NBE9g== X-IronPort-AV: E=McAfee;i="6700,10204,11440"; a="53677784" X-IronPort-AV: E=Sophos;i="6.15,304,1739865600"; d="scan'208";a="53677784" 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:59 -0700 X-CSE-ConnectionGUID: 4/o9t1teSRiIaDVSMdFqEw== X-CSE-MsgGUID: BzjeVJB9Tiu/s1mIIPmsgQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,304,1739865600"; d="scan'208";a="141352169" 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:58 -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 16/29] x86/resctrl: Add and initialize rdt_resource for package scope core monitor Date: Wed, 21 May 2025 15:50:34 -0700 Message-ID: <20250521225049.132551-17-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" Counts for each Intel telemetry event are periodically sent to one or more aggregators on each package where accumulated totals are made available in MMIO registers. Add a new resource for monitoring these events so that CPU hotplug notifiers will build domains at the package granularity. Signed-off-by: Tony Luck --- include/linux/resctrl.h | 2 ++ fs/resctrl/internal.h | 2 ++ arch/x86/kernel/cpu/resctrl/core.c | 10 ++++++++++ fs/resctrl/rdtgroup.c | 2 ++ 4 files changed, 16 insertions(+) diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index 4ad3d7f10580..4ba51cb598e1 100644 --- a/include/linux/resctrl.h +++ b/include/linux/resctrl.h @@ -53,6 +53,7 @@ enum resctrl_res_level { RDT_RESOURCE_L2, RDT_RESOURCE_MBA, RDT_RESOURCE_SMBA, + RDT_RESOURCE_PERF_PKG, =20 /* Must be the last */ RDT_NUM_RESOURCES, @@ -250,6 +251,7 @@ enum resctrl_scope { RESCTRL_L2_CACHE =3D 2, RESCTRL_L3_CACHE =3D 3, RESCTRL_L3_NODE, + RESCTRL_PACKAGE, }; =20 /** diff --git a/fs/resctrl/internal.h b/fs/resctrl/internal.h index d5045491790e..64c1c226d676 100644 --- a/fs/resctrl/internal.h +++ b/fs/resctrl/internal.h @@ -234,6 +234,8 @@ struct rdtgroup { =20 #define RFTYPE_DEBUG BIT(10) =20 +#define RFTYPE_RES_PERF_PKG BIT(11) + #define RFTYPE_CTRL_INFO (RFTYPE_INFO | RFTYPE_CTRL) =20 #define RFTYPE_MON_INFO (RFTYPE_INFO | RFTYPE_MON) diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resct= rl/core.c index f8c9840ce7dc..ce4885c751e4 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -99,6 +99,14 @@ struct rdt_hw_resource rdt_resources_all[RDT_NUM_RESOURC= ES] =3D { .schema_fmt =3D RESCTRL_SCHEMA_RANGE, }, }, + [RDT_RESOURCE_PERF_PKG] =3D + { + .r_resctrl =3D { + .name =3D "PERF_PKG", + .mon_scope =3D RESCTRL_PACKAGE, + .mon_domains =3D mon_domain_init(RDT_RESOURCE_PERF_PKG), + }, + }, }; =20 u32 resctrl_arch_system_num_rmid_idx(void) @@ -430,6 +438,8 @@ static int get_domain_id_from_scope(int cpu, enum resct= rl_scope scope) return get_cpu_cacheinfo_id(cpu, scope); case RESCTRL_L3_NODE: return cpu_to_node(cpu); + case RESCTRL_PACKAGE: + return topology_physical_package_id(cpu); default: break; } diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index bdad98ac0d27..1e1cc8001cbc 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -2193,6 +2193,8 @@ static unsigned long fflags_from_resource(struct rdt_= resource *r) case RDT_RESOURCE_MBA: case RDT_RESOURCE_SMBA: return RFTYPE_RES_MB; + case RDT_RESOURCE_PERF_PKG: + return RFTYPE_RES_PERF_PKG; } =20 return WARN_ON_ONCE(1); --=20 2.49.0 From nobody Sun Dec 14 19:24:21 2025 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 9B3CE2417C4 for ; Wed, 21 May 2025 22:51:08 +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=1747867871; cv=none; b=qvifdEQKZu5Hx1iakj7uluAtUG4Y6ZazQi1W6a6TFUwVmVK4vF6vGpMCrT5/Nh2Zdf95/Bm0wBIATynT1uMPTuCuCfIZoN8iyem5Y4vA4qM0U34XVx1Jf0eO0fAB9ZMxSxGq0fhjT87kcdLlT+pAvFCTunpqrgIkW5LzH+5q2Gg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747867871; c=relaxed/simple; bh=822xnb/jdoR2cK+I8yE6V0NV0swnShWV0Uhr4ay0ejM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TQwrYGgrGbPpf91T4KDhJECuFv1peGvWB0C4om0L17f83Yyf92BeQ+83C0e9caLBna+JbJo7N5mn85pSld9/UlwLc72mIKgsNPhKqOfApPu6MtVSBYsBQDmMoOl0XcgOsD7dkLzLK9bv3ObpHdFxwYQROnFb9MflLE1a4vvAL1c= 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=Dvade1MZ; 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="Dvade1MZ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1747867869; x=1779403869; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=822xnb/jdoR2cK+I8yE6V0NV0swnShWV0Uhr4ay0ejM=; b=Dvade1MZ/JHzo2E+YMNRiHYJGoMhsDvjkx93Kd7ODHi6HbIz0GQPNIpf RsdkiHM9F7i3LhzjVDZmeJR/salqONXiD7wIxwr8Z2cLykCx4bj3OJbd0 MUiSAZyBcGvO0tQ5D4V8rFe4QKeqLaHf4cbrnYBY1w12MFo/TeHJBvAgn Bg30jYKfbGyEUC9grt+OZYJuroxdYuE0koRY+e0N8WBEhQhD3FzVnHEKJ 7ENFV43MwGLXxOdfXa+8AoU6+uEfE3voPcqyuhdGq1mA5S4t6D8iYAXoE zPVEIgEF5kpdPpbncAVZyvNBhbMhiKqQ22BEzhE/XTmfhj6+cygoua/r6 Q==; X-CSE-ConnectionGUID: eGhRcwsOTRe8RDXX0cK3PQ== X-CSE-MsgGUID: C4BlPNIeRXabi+fO9NjW7g== X-IronPort-AV: E=McAfee;i="6700,10204,11440"; a="53677786" X-IronPort-AV: E=Sophos;i="6.15,304,1739865600"; d="scan'208";a="53677786" 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:59 -0700 X-CSE-ConnectionGUID: 1mWQzem4TVSJ2cgR4QxdcQ== X-CSE-MsgGUID: QSt0W77vSYiFMkKUsRCXdg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,304,1739865600"; d="scan'208";a="141352172" 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:58 -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 17/29] x86/resctrl: Discover hardware telemetry events Date: Wed, 21 May 2025 15:50:35 -0700 Message-ID: <20250521225049.132551-18-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" Hardware has one or more telemetry event aggregators per package for each group of telemetry events. Each aggregator provides access to event counts in an array of 64-bit values in MMIO space. There is a "guid" (in this case a unique 32-bit integer) which refers to an XML file published in the https://github.com/intel/Intel-PMT that provides all the details about each aggregator. The XML files provide the following information: 1) Which telemetry events are included in the group for this aggregator. 2) The order in which the event counters appear for each RMID. 3) The value type of each event counter (integer or fixed-point). 4) The number of RMIDs supported. 5) Which additional aggregator status registers are included. 6) The total size of the MMIO region for this aggregator. There is an INTEL_PMT_DISCOVERY driver that enumerate all aggregators on the system with intel_pmt_get_regions_by_feature(). Call this for each pmt_feature_id that indicates per-RMID telemetry. Save the returned pmt_feature_group pointers with guids that are known to resctrl for use at run time. Those pointers are returned to the INTEL_PMT_DISCOVERY driver at resctrl_arch_exit() time. Signed-off-by: Tony Luck --- arch/x86/kernel/cpu/resctrl/internal.h | 3 + arch/x86/kernel/cpu/resctrl/core.c | 5 + arch/x86/kernel/cpu/resctrl/intel_aet.c | 129 ++++++++++++++++++++++++ arch/x86/kernel/cpu/resctrl/Makefile | 1 + 4 files changed, 138 insertions(+) create mode 100644 arch/x86/kernel/cpu/resctrl/intel_aet.c diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/r= esctrl/internal.h index 02c9e7d163dc..2b2d4b5a4643 100644 --- a/arch/x86/kernel/cpu/resctrl/internal.h +++ b/arch/x86/kernel/cpu/resctrl/internal.h @@ -167,4 +167,7 @@ void __init intel_rdt_mbm_apply_quirk(void); =20 void rdt_domain_reconfigure_cdp(struct rdt_resource *r); =20 +bool intel_aet_get_events(void); +void __exit intel_aet_exit(void); + #endif /* _ASM_X86_RESCTRL_INTERNAL_H */ diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resct= rl/core.c index ce4885c751e4..64ce561e77a0 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -727,6 +727,9 @@ void resctrl_arch_pre_mount(void) =20 if (!atomic_try_cmpxchg(&only_once, &old, 1)) return; + + if (!intel_aet_get_events()) + return; } =20 enum { @@ -1079,6 +1082,8 @@ late_initcall(resctrl_arch_late_init); =20 static void __exit resctrl_arch_exit(void) { + intel_aet_exit(); + cpuhp_remove_state(rdt_online); =20 resctrl_exit(); diff --git a/arch/x86/kernel/cpu/resctrl/intel_aet.c b/arch/x86/kernel/cpu/= resctrl/intel_aet.c new file mode 100644 index 000000000000..df73b9476c4d --- /dev/null +++ b/arch/x86/kernel/cpu/resctrl/intel_aet.c @@ -0,0 +1,129 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Resource Director Technology(RDT) + * - Intel Application Energy Telemetry + * + * Copyright (C) 2025 Intel Corporation + * + * Author: + * Tony Luck + */ + +#define pr_fmt(fmt) "resctrl: " fmt + +#include +#include +#include + +/* Temporary - delete from final version */ +#include "fake_intel_aet_features.h" + +#include "internal.h" + +/** + * struct event_group - All information about a group of telemetry events. + * @pfg: Points to the aggregated telemetry space information + * within the OOBMSM driver that contains data for all + * telemetry regions. + * @guid: Unique number per XML description file. + */ +struct event_group { + /* Data fields used by this code. */ + struct pmt_feature_group *pfg; + + /* Remaining fields initialized from XML file. */ + u32 guid; +}; + +/* + * Link: https://github.com/intel/Intel-PMT + * File: xml/CWF/OOBMSM/RMID-ENERGY/cwf_aggregator.xml + */ +static struct event_group energy_0x26696143 =3D { + .guid =3D 0x26696143, +}; + +/* + * Link: https://github.com/intel/Intel-PMT + * File: xml/CWF/OOBMSM/RMID-PERF/cwf_aggregator.xml + */ +static struct event_group perf_0x26557651 =3D { + .guid =3D 0x26557651, +}; + +static struct event_group *known_event_groups[] =3D { + &energy_0x26696143, + &perf_0x26557651, +}; + +#define NUM_KNOWN_GROUPS ARRAY_SIZE(known_event_groups) + +/* Stub for now */ +static int configure_events(struct event_group *e, struct pmt_feature_grou= p *p) +{ + return -EINVAL; +} + +DEFINE_FREE(intel_pmt_put_feature_group, struct pmt_feature_group *, \ + if (!IS_ERR_OR_NULL(_T)) \ + intel_pmt_put_feature_group(_T)) + +/* + * Make a request to the INTEL_PMT_DISCOVERY driver for the + * pmt_feature_group for a specific feature. If there is + * one the returned structure has an array of telemetry_region + * structures. Each describes one telemetry aggregator. + * Try to configure any with a known matching guid. + */ +static bool get_pmt_feature(enum pmt_feature_id feature) +{ + struct pmt_feature_group *p __free(intel_pmt_put_feature_group) =3D NULL; + struct event_group **peg; + bool ret; + + p =3D intel_pmt_get_regions_by_feature(feature); + + if (IS_ERR_OR_NULL(p)) + return false; + + for (peg =3D &known_event_groups[0]; peg < &known_event_groups[NUM_KNOWN_= GROUPS]; peg++) { + for (int i =3D 0; i < p->count; i++) { + if ((*peg)->guid =3D=3D p->regions[i].guid) { + ret =3D configure_events(*peg, p); + if (!ret) { + (*peg)->pfg =3D no_free_ptr(p); + return true; + } + break; + } + } + } + + return false; +} + +/* + * Ask OOBMSM discovery driver for all the RMID based telemetry groups + * that it supports. + */ +bool intel_aet_get_events(void) +{ + bool ret1, ret2; + + ret1 =3D get_pmt_feature(FEATURE_PER_RMID_ENERGY_TELEM); + ret2 =3D get_pmt_feature(FEATURE_PER_RMID_PERF_TELEM); + + return ret1 || ret2; +} + +void __exit intel_aet_exit(void) +{ + struct event_group **peg; + + for (peg =3D &known_event_groups[0]; peg < &known_event_groups[NUM_KNOWN_= GROUPS]; peg++) { + if ((*peg)->pfg) { + intel_pmt_put_feature_group((*peg)->pfg); + (*peg)->pfg =3D NULL; + } + } +} diff --git a/arch/x86/kernel/cpu/resctrl/Makefile b/arch/x86/kernel/cpu/res= ctrl/Makefile index cf4fac58d068..cca23f06d15d 100644 --- a/arch/x86/kernel/cpu/resctrl/Makefile +++ b/arch/x86/kernel/cpu/resctrl/Makefile @@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_X86_CPU_RESCTRL) +=3D core.o rdtgroup.o monitor.o obj-$(CONFIG_X86_CPU_RESCTRL) +=3D ctrlmondata.o +obj-$(CONFIG_X86_CPU_RESCTRL) +=3D intel_aet.o obj-$(CONFIG_X86_CPU_RESCTRL) +=3D fake_intel_aet_features.o obj-$(CONFIG_RESCTRL_FS_PSEUDO_LOCK) +=3D pseudo_lock.o =20 --=20 2.49.0 From nobody Sun Dec 14 19:24:21 2025 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 85EB1242D98 for ; Wed, 21 May 2025 22:51:09 +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=1747867871; cv=none; b=PqIvyl3WJdRFPAJeKqoNDnMf9Eg7pvnB3C/xXXlHYzzCrLnidPa6Y+3ntfHXYc6a/vpbRuyG9csav7GK89bUA8+7KRSqh4AvcgWYduhKKKJjrsMPyh7OoKcSBLglBL5jwvmLSU6K4VRQzzqRHCVR0IL7CkTCpcUH0Wbm9o1vY5k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747867871; c=relaxed/simple; bh=jZvJTkcSVjRmkGLeOmMgrgMCrGaQmQ2myZ1ADMCEudg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sh3uFTFODzTP1zp+LfF0U/WOT8OJBCLKiRhGzu0y9mjbatDdYM9CE3OBoNWhb3K80LenpVCXZuf0VcnnfGuBDHLvXLS6YLujPg7uIMyKoXSRx1wI8i7WuKElgGeAOBEBNdOY++b1+QxVKVLjCe1EQpu1WrIjGwhwpLgMwk6hdWI= 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=bS83gCPd; 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="bS83gCPd" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1747867869; x=1779403869; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=jZvJTkcSVjRmkGLeOmMgrgMCrGaQmQ2myZ1ADMCEudg=; b=bS83gCPdLTvQePLaO3UqDHVWJlr4evFXb1htiloUGHR2O6GWVkejuWb+ lkgsgqvwQrA5hY1kI7y4Ys0g1okxyta7YPSIKUvakt0uXWdA1Eh7/CI4T KXpYODDZ/lGHrGoZegjvg7NIgtXy5n9oikeTqJ4i+zcFrmlpjTTm6FcwZ kmhEISm5ZqbQtE9pxbW6MxtP343VbVOjwbORAM+6pdhwISXTbtlQ99QTy 8vfcrE2fFqV0asCsPI4Zu4Xc0Ha/fDpoz+MROfiJwmYlKuG1zXKvRF+ae VEaLYkolzVoqQs50pfhPP2LgNostwh+7amIZtbPwxKao0gqq9TNXqYkIh w==; X-CSE-ConnectionGUID: OaWGExS1Q82MPi/ygA3VkQ== X-CSE-MsgGUID: XtmSAtz2TAanFIZX0nBA+Q== X-IronPort-AV: E=McAfee;i="6700,10204,11440"; a="53677794" X-IronPort-AV: E=Sophos;i="6.15,304,1739865600"; d="scan'208";a="53677794" 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:59 -0700 X-CSE-ConnectionGUID: kYvU0AH5TgaIJ3vMsEriSA== X-CSE-MsgGUID: pjtoTgD/Sz2zCUini76Tfw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,304,1739865600"; d="scan'208";a="141352176" 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:58 -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 18/29] x86/resctrl: Count valid telemetry aggregators per package Date: Wed, 21 May 2025 15:50:36 -0700 Message-ID: <20250521225049.132551-19-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 may be multiple telemetry aggregators per package, each enumerated by a telemetry region structure in the feature group. Scan the array of telemetry region structures and count how many are in each package in preparation to allocate structures to save the MMIO addresses for each in a convenient format for use when reading event counters. Sanity check that the telemetry region structures have a valid package_id and that the size they report for the MMIO space is as large as expected from the XML description of the registers in the region. Signed-off-by: Tony Luck --- arch/x86/kernel/cpu/resctrl/intel_aet.c | 45 ++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/cpu/resctrl/intel_aet.c b/arch/x86/kernel/cpu/= resctrl/intel_aet.c index df73b9476c4d..ffcb54be54ea 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 =20 /* Temporary - delete from final version */ #include "fake_intel_aet_features.h" @@ -26,6 +27,7 @@ * within the OOBMSM driver that contains data for all * telemetry regions. * @guid: Unique number per XML description file. + * @mmio_size: Number of bytes of MMIO registers for this group. */ struct event_group { /* Data fields used by this code. */ @@ -33,6 +35,7 @@ struct event_group { =20 /* Remaining fields initialized from XML file. */ u32 guid; + size_t mmio_size; }; =20 /* @@ -41,6 +44,7 @@ struct event_group { */ static struct event_group energy_0x26696143 =3D { .guid =3D 0x26696143, + .mmio_size =3D (576 * 2 + 3) * 8, }; =20 /* @@ -49,6 +53,7 @@ static struct event_group energy_0x26696143 =3D { */ static struct event_group perf_0x26557651 =3D { .guid =3D 0x26557651, + .mmio_size =3D (576 * 7 + 3) * 8, }; =20 static struct event_group *known_event_groups[] =3D { @@ -58,9 +63,47 @@ static struct event_group *known_event_groups[] =3D { =20 #define NUM_KNOWN_GROUPS ARRAY_SIZE(known_event_groups) =20 -/* Stub for now */ +static bool skip_this_region(struct telemetry_region *tr, struct event_gro= up *e) +{ + if (tr->guid !=3D e->guid) + return true; + if (tr->plat_info.package_id >=3D topology_max_packages()) { + pr_warn_once("Bad package %d in guid 0x%x\n", tr->plat_info.package_id, + tr->guid); + return true; + } + if (tr->size < e->mmio_size) { + pr_warn_once("MMIO space too small for guid 0x%x\n", e->guid); + return true; + } + + return false; +} + +/* + * Configure events from one pmt_feature_group. + * 1) Count how many per package. + * 2...) To be continued. + */ static int configure_events(struct event_group *e, struct pmt_feature_grou= p *p) { + int *pkgcounts __free(kfree) =3D NULL; + struct telemetry_region *tr; + int num_pkgs; + + num_pkgs =3D topology_max_packages(); + pkgcounts =3D kcalloc(num_pkgs, sizeof(*pkgcounts), GFP_KERNEL); + if (!pkgcounts) + return -ENOMEM; + + /* Get per-package counts of telemetry_regions for this event group */ + for (int i =3D 0; i < p->count; i++) { + tr =3D &p->regions[i]; + if (skip_this_region(tr, e)) + continue; + pkgcounts[tr->plat_info.package_id]++; + } + return -EINVAL; } =20 --=20 2.49.0 From nobody Sun Dec 14 19:24:21 2025 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 5A76F244685 for ; Wed, 21 May 2025 22:51:10 +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=1747867872; cv=none; b=ATBUflYJ5eZim5AsyB5KpZpADkTURiR59+d/2/9u6a/eUfKgsGi486qLg9Pc9LWozp0o8hGXFATWTn0Edgoy+UTUK3V/Llec686r1vJN+Ys/LttmRaYixKfemYoHAJdT5V6aBFuz3umzDa7ka05ez6mC3DpvQh6zpE+6vR/1uNE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747867872; c=relaxed/simple; bh=2MysUjKQnyqtaSPcf1h7ioPaq/BxZtCdUKufIMkwxg4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=X0WABYQu4uQJfuMPw2uZ4kcBDZImS9VgNChRqT5HZAAZnfHN6b6TG6iC1vtIKmJmnuBwFXeQ3D2JpZbW7isQ7P4+fW4OIW+B4XmBTTiZlvMx5McP0vNe4Qmo5MGq41nTqlvqMyL7Yy4qm1eEdL60xDzl7yfzf804SnI1J+iNZHI= 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=P2VhshKN; 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="P2VhshKN" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1747867870; x=1779403870; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=2MysUjKQnyqtaSPcf1h7ioPaq/BxZtCdUKufIMkwxg4=; b=P2VhshKNceNhu8Q5bnG4SsQGkXD6qOvtTIOhbWNHzl0RrfrnZm1CCj7u k74pz8lfYkecMCukT6DVektjAotqqz5pmvYIbbKZlpg5fy5ErYk3QAJjA 1JxXW1q7xnllYgVLCm17P4Y6N1mqO9mJinyF758PIclTn65gNvZbIjiPa uEB+/mp0triv7ycKQLGB16CLiTl7BOfpy12CR2BE8zLJlvbhOtEoLks2C 7oNKGT312FUERjP/kraDPCjcMAdFDHjWZGsT3ButYHyR/dWPaS3+Jm5SN /VAzeQwvGrmlkMWOULEN0FMyTZbwy11sMUbo/rVY9SJoTNKtUUBGda8ET Q==; X-CSE-ConnectionGUID: p7Gp1oQ6TG+HlweaN7mH/w== X-CSE-MsgGUID: HYNqjypSQPOT+1HTPcbZGA== X-IronPort-AV: E=McAfee;i="6700,10204,11440"; a="53677796" X-IronPort-AV: E=Sophos;i="6.15,304,1739865600"; d="scan'208";a="53677796" 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:59 -0700 X-CSE-ConnectionGUID: MOlEEor5SH2ym2TBCiMzpA== X-CSE-MsgGUID: 8OPnoIgkRAK7NyXqbeDKTg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,304,1739865600"; d="scan'208";a="141352179" 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:58 -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 19/29] x86/resctrl: Complete telemetry event enumeration Date: Wed, 21 May 2025 15:50:37 -0700 Message-ID: <20250521225049.132551-20-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" Counters for telemetry events are in MMIO space. Each telemetry_region structure returned in the pmt_feature_group returned from OOBMSM contains the base MMIO address for the counters. Scan all the telemetry_region structures again and gather these addresses into a more convenient structure with addresses for each aggregator indexed by package id. Note that there may be multiple aggregators per package. Completed structure for each event group looks like this: +---------------------+---------------------+ pkginfo** -->| pkginfo[0] | pkginfo[1] | +---------------------+---------------------+ | | v v +----------------+ +----------------+ |struct mmio_info| |struct mmio_info| +----------------+ +----------------+ | count =3D N | | count =3D N | | addrs[0] | | addrs[0] | | addrs[0] | | addrs[0] | | ... | | ... | | addrs[N-1] | | addrs[N-1] | +----------------+ +----------------+ Signed-off-by: Tony Luck --- arch/x86/kernel/cpu/resctrl/intel_aet.c | 65 ++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/cpu/resctrl/intel_aet.c b/arch/x86/kernel/cpu/= resctrl/intel_aet.c index ffcb54be54ea..2316198eb69e 100644 --- a/arch/x86/kernel/cpu/resctrl/intel_aet.c +++ b/arch/x86/kernel/cpu/resctrl/intel_aet.c @@ -21,17 +21,32 @@ =20 #include "internal.h" =20 +/** + * struct mmio_info - Array of MMIO addresses for one event group for a pa= ckage + * @count: Number of addresses on this package + * @addrs: The MMIO addresses + * + * Provides convenient access to all MMIO addresses of one event group + * for one package. Used when reading event data on a package. + */ +struct mmio_info { + int count; + void __iomem *addrs[] __counted_by(count); +}; + /** * struct event_group - All information about a group of telemetry events. * @pfg: Points to the aggregated telemetry space information * within the OOBMSM driver that contains data for all * telemetry regions. + * @pkginfo: Per-package MMIO addresses of telemetry regions belonging to= this group * @guid: Unique number per XML description file. * @mmio_size: Number of bytes of MMIO registers for this group. */ struct event_group { /* Data fields used by this code. */ struct pmt_feature_group *pfg; + struct mmio_info **pkginfo; =20 /* Remaining fields initialized from XML file. */ u32 guid; @@ -80,6 +95,20 @@ static bool skip_this_region(struct telemetry_region *tr= , struct event_group *e) return false; } =20 +static void free_mmio_info(struct mmio_info **mmi) +{ + int num_pkgs =3D topology_max_packages(); + + if (!mmi) + return; + + for (int i =3D 0; i < num_pkgs; i++) + kfree(mmi[i]); + kfree(mmi); +} + +DEFINE_FREE(mmio_info, struct mmio_info **, free_mmio_info(_T)) + /* * Configure events from one pmt_feature_group. * 1) Count how many per package. @@ -87,10 +116,17 @@ static bool skip_this_region(struct telemetry_region *= tr, struct event_group *e) */ static int configure_events(struct event_group *e, struct pmt_feature_grou= p *p) { + struct mmio_info __free(mmio_info) **pkginfo =3D NULL; int *pkgcounts __free(kfree) =3D NULL; struct telemetry_region *tr; + struct mmio_info *mmi; int num_pkgs; =20 + if (e->pkginfo) { + pr_warn("Duplicate telemetry information for guid 0x%x\n", e->guid); + return -EINVAL; + } + num_pkgs =3D topology_max_packages(); pkgcounts =3D kcalloc(num_pkgs, sizeof(*pkgcounts), GFP_KERNEL); if (!pkgcounts) @@ -104,7 +140,33 @@ static int configure_events(struct event_group *e, str= uct pmt_feature_group *p) pkgcounts[tr->plat_info.package_id]++; } =20 - return -EINVAL; + /* Allocate array for per-package struct mmio_info data */ + pkginfo =3D kcalloc(num_pkgs, sizeof(*pkginfo), GFP_KERNEL); + if (!pkginfo) + return -ENOMEM; + + /* + * Allocate per-package mmio_info structures and initialize + * count of telemetry_regions in each one. + */ + for (int i =3D 0; i < num_pkgs; i++) { + pkginfo[i] =3D kzalloc(struct_size(pkginfo[i], addrs, pkgcounts[i]), GFP= _KERNEL); + if (!pkginfo[i]) + return -ENOMEM; + pkginfo[i]->count =3D pkgcounts[i]; + } + + /* Save MMIO address(es) for each telemetry region in per-package structu= res */ + for (int i =3D 0; i < p->count; i++) { + tr =3D &p->regions[i]; + if (skip_this_region(tr, e)) + continue; + mmi =3D pkginfo[tr->plat_info.package_id]; + mmi->addrs[--pkgcounts[tr->plat_info.package_id]] =3D tr->addr; + } + e->pkginfo =3D no_free_ptr(pkginfo); + + return 0; } =20 DEFINE_FREE(intel_pmt_put_feature_group, struct pmt_feature_group *, \ @@ -168,5 +230,6 @@ void __exit intel_aet_exit(void) intel_pmt_put_feature_group((*peg)->pfg); (*peg)->pfg =3D NULL; } + free_mmio_info((*peg)->pkginfo); } } --=20 2.49.0 From nobody Sun Dec 14 19:24:21 2025 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 DB68724728B for ; Wed, 21 May 2025 22:51:12 +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=1747867875; cv=none; b=ThBrafPnNFh6slCxqj6ftFCu4AJjG0pajwEATndS8jBPXLanFlb9jGeUI639R04xkLBoSGJf41ECvLZEuKQarXJ+zNqMMysusRxwOb0eYV1EGHHchbatHWxfRrow5tZ+Bi/ZztuTF/RwUf5eN1rv2RRoqVokBW7KQu5a6nz5xRA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747867875; c=relaxed/simple; bh=HdxDZ5f2ywmXFv5AWkW81eQVoVUNGgR0kjdBK51/DYI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PyCMRK2vm7zofr3urMwYQk1ad0wWzYjBSC32qKwKBkzSBazfHDEgiXz6qgXhj4DuVHLRAl74Ts0pwuRkfyl2TN5rSjDy6QwA4ZWtZ/+fAkk0HW3k5yXZnR3erJd0KUYI8FhCRueoTiQMA4lIypJ0jtPSST/3rE20omZJlYEnqdU= 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=iC9sHCmF; 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="iC9sHCmF" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1747867873; x=1779403873; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=HdxDZ5f2ywmXFv5AWkW81eQVoVUNGgR0kjdBK51/DYI=; b=iC9sHCmFOICyvBzNuVMXcmmZhFFsT1/q/34cBLmUw7X+eG9bptvmWfiV ANnEEPNIWA6j5e3tntdDGB53xZ2t6RVCBqCu8kXoxqz9uSYJL+UnD0aOP agY744PGrqOEIhn3HZdCSyfLz69fFVNwm7liJpVYNLcIvqRij+DDvGIbS aFJ1+mcWUfmK4nXOQj44FUVv5X+AvM5fwnfSBDkkGtihImNa8FXrdKucb LL8Fko1GVj2kE8zDO/sJXgGGe7cdZnt9JSoTAq1MG3G0F1n7M8QLWA8LY Q/yQTv5B8C76R6HQ+HyNplpnMm27YjMvmrtdNMI/fqpSuVGwTFbglR7dF A==; X-CSE-ConnectionGUID: 9isiZ0RtQECPG1wRNFt7CQ== X-CSE-MsgGUID: Pe5qrTB7TGWsm0vPiLWb/A== X-IronPort-AV: E=McAfee;i="6700,10204,11440"; a="53677804" X-IronPort-AV: E=Sophos;i="6.15,304,1739865600"; d="scan'208";a="53677804" 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:51:00 -0700 X-CSE-ConnectionGUID: uITqucr5Rau9AKYUs98qjQ== X-CSE-MsgGUID: cmvKq3H6Q5mJu67fFhVRhw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,304,1739865600"; d="scan'208";a="141352183" 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:58 -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 20/29] x86,fs/resctrl: Fill in details of Clearwater Forest events Date: Wed, 21 May 2025 15:50:38 -0700 Message-ID: <20250521225049.132551-21-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" Clearwater Forest supports two energy related telemetry events and seven perf style events. The counters are arranged in per-RMID blocks like this: MMIO offset:0x00 Counter for RMID 0 Event 0 MMIO offset:0x08 Counter for RMID 0 Event 1 MMIO offset:0x10 Counter for RMID 0 Event 2 MMIO offset:0x18 Counter for RMID 1 Event 0 MMIO offset:0x20 Counter for RMID 1 Event 1 MMIO offset:0x28 Counter for RMID 1 Event 2 ... Define these events in the file system code and add the events to the event_group structures. PMT_EVENT_ENERGY and PMT_EVENT_ACTIVITY are produced in fixed point format. File system code must output as floating point values. Signed-off-by: Tony Luck --- include/linux/resctrl_types.h | 11 ++++++ arch/x86/kernel/cpu/resctrl/intel_aet.c | 33 ++++++++++++++++++ fs/resctrl/monitor.c | 45 +++++++++++++++++++++++++ 3 files changed, 89 insertions(+) diff --git a/include/linux/resctrl_types.h b/include/linux/resctrl_types.h index b468bfbab9ea..455b29a0a9b9 100644 --- a/include/linux/resctrl_types.h +++ b/include/linux/resctrl_types.h @@ -43,6 +43,17 @@ enum resctrl_event_id { QOS_L3_MBM_TOTAL_EVENT_ID =3D 0x02, QOS_L3_MBM_LOCAL_EVENT_ID =3D 0x03, =20 + /* Intel Telemetry Events */ + PMT_EVENT_ENERGY, + PMT_EVENT_ACTIVITY, + PMT_EVENT_STALLS_LLC_HIT, + PMT_EVENT_C1_RES, + PMT_EVENT_UNHALTED_CORE_CYCLES, + PMT_EVENT_STALLS_LLC_MISS, + PMT_EVENT_AUTO_C6_RES, + PMT_EVENT_UNHALTED_REF_CYCLES, + PMT_EVENT_UOPS_RETIRED, + /* Must be the last */ QOS_NUM_EVENTS, }; diff --git a/arch/x86/kernel/cpu/resctrl/intel_aet.c b/arch/x86/kernel/cpu/= resctrl/intel_aet.c index 2316198eb69e..bf8e2a6126d2 100644 --- a/arch/x86/kernel/cpu/resctrl/intel_aet.c +++ b/arch/x86/kernel/cpu/resctrl/intel_aet.c @@ -34,6 +34,20 @@ struct mmio_info { void __iomem *addrs[] __counted_by(count); }; =20 +/** + * struct pmt_event - Telemetry event. + * @evtid: Resctrl event id + * @evt_idx: Counter index within each per-RMID block of counters + * @bin_bits: Zero for integer valued events, else number bits in fixed-po= int + */ +struct pmt_event { + enum resctrl_event_id evtid; + int evt_idx; + int bin_bits; +}; + +#define EVT(id, idx, bits) { .evtid =3D id, .evt_idx =3D idx, .bin_bits = =3D bits } + /** * struct event_group - All information about a group of telemetry events. * @pfg: Points to the aggregated telemetry space information @@ -42,6 +56,8 @@ struct mmio_info { * @pkginfo: Per-package MMIO addresses of telemetry regions belonging to= this group * @guid: Unique number per XML description file. * @mmio_size: Number of bytes of MMIO registers for this group. + * @num_events: Number of events in this group. + * @evts: Array of event descriptors. */ struct event_group { /* Data fields used by this code. */ @@ -51,6 +67,8 @@ struct event_group { /* Remaining fields initialized from XML file. */ u32 guid; size_t mmio_size; + int num_events; + struct pmt_event evts[] __counted_by(num_events); }; =20 /* @@ -60,6 +78,11 @@ struct event_group { static struct event_group energy_0x26696143 =3D { .guid =3D 0x26696143, .mmio_size =3D (576 * 2 + 3) * 8, + .num_events =3D 2, + .evts =3D { + EVT(PMT_EVENT_ENERGY, 0, 18), + EVT(PMT_EVENT_ACTIVITY, 1, 18), + } }; =20 /* @@ -69,6 +92,16 @@ static struct event_group energy_0x26696143 =3D { static struct event_group perf_0x26557651 =3D { .guid =3D 0x26557651, .mmio_size =3D (576 * 7 + 3) * 8, + .num_events =3D 7, + .evts =3D { + EVT(PMT_EVENT_STALLS_LLC_HIT, 0, 0), + EVT(PMT_EVENT_C1_RES, 1, 0), + EVT(PMT_EVENT_UNHALTED_CORE_CYCLES, 2, 0), + EVT(PMT_EVENT_STALLS_LLC_MISS, 3, 0), + EVT(PMT_EVENT_AUTO_C6_RES, 4, 0), + EVT(PMT_EVENT_UNHALTED_REF_CYCLES, 5, 0), + EVT(PMT_EVENT_UOPS_RETIRED, 6, 0), + } }; =20 static struct event_group *known_event_groups[] =3D { diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c index f554d7933739..f24a568f7b67 100644 --- a/fs/resctrl/monitor.c +++ b/fs/resctrl/monitor.c @@ -876,6 +876,51 @@ struct mon_evt mon_event_all[QOS_NUM_EVENTS] =3D { .evtid =3D QOS_L3_MBM_LOCAL_EVENT_ID, .rid =3D RDT_RESOURCE_L3, }, + [PMT_EVENT_ENERGY] =3D { + .name =3D "core_energy", + .evtid =3D PMT_EVENT_ENERGY, + .rid =3D RDT_RESOURCE_PERF_PKG, + }, + [PMT_EVENT_ACTIVITY] =3D { + .name =3D "activity", + .evtid =3D PMT_EVENT_ACTIVITY, + .rid =3D RDT_RESOURCE_PERF_PKG, + }, + [PMT_EVENT_STALLS_LLC_HIT] =3D { + .name =3D "stalls_llc_hit", + .evtid =3D PMT_EVENT_STALLS_LLC_HIT, + .rid =3D RDT_RESOURCE_PERF_PKG, + }, + [PMT_EVENT_C1_RES] =3D { + .name =3D "c1_res", + .evtid =3D PMT_EVENT_C1_RES, + .rid =3D RDT_RESOURCE_PERF_PKG, + }, + [PMT_EVENT_UNHALTED_CORE_CYCLES] =3D { + .name =3D "unhalted_core_cycles", + .evtid =3D PMT_EVENT_UNHALTED_CORE_CYCLES, + .rid =3D RDT_RESOURCE_PERF_PKG, + }, + [PMT_EVENT_STALLS_LLC_MISS] =3D { + .name =3D "stalls_llc_miss", + .evtid =3D PMT_EVENT_STALLS_LLC_MISS, + .rid =3D RDT_RESOURCE_PERF_PKG, + }, + [PMT_EVENT_AUTO_C6_RES] =3D { + .name =3D "c6_res", + .evtid =3D PMT_EVENT_AUTO_C6_RES, + .rid =3D RDT_RESOURCE_PERF_PKG, + }, + [PMT_EVENT_UNHALTED_REF_CYCLES] =3D { + .name =3D "unhalted_ref_cycles", + .evtid =3D PMT_EVENT_UNHALTED_REF_CYCLES, + .rid =3D RDT_RESOURCE_PERF_PKG, + }, + [PMT_EVENT_UOPS_RETIRED] =3D { + .name =3D "uops_retired", + .evtid =3D PMT_EVENT_UOPS_RETIRED, + .rid =3D RDT_RESOURCE_PERF_PKG, + }, }; =20 void resctrl_enable_mon_event(enum resctrl_event_id evtid, bool any_cpu, u= 32 binary_bits) --=20 2.49.0 From nobody Sun Dec 14 19:24:21 2025 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 29DCB248F44 for ; Wed, 21 May 2025 22:51:14 +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=1747867876; cv=none; b=OlqG68mTV6CpimJjYG8z5dVPujqsTDMS6Sh/urdADY77KZp2pUjsBqG8sYDeywYpFjqOp0A/dCyBFYFRrpqn/JyAiGhMmrvfejUfqiTgqEa7uwCUH45WP3hyoaYew2xZWPhVYnDMo27xIWo6j9f5HoSgxynbXjA66nl4CCkEqjE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747867876; c=relaxed/simple; bh=cQ0nMrQ6c2gQCxZp3p2gu7oAjsNdkQuELZWDf8DPdCU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IaIEr1yeHQ3tVWGmd/JTMYHHn1bFy3eGkdK/+pSMaxtdfEi+L4qenu2BhTgi8YLB4yfCQESRIluV5Ik/oNuUeHhEU9Jn3tm8I4Ap2NLNU3drvgpnbQEsqPviAot6jSOp+gtOIsrgfcy3PLjFoKQQUdEuZs+QkbNjhSJSheG2mMk= 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=VK1BUGdF; 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="VK1BUGdF" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1747867874; x=1779403874; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=cQ0nMrQ6c2gQCxZp3p2gu7oAjsNdkQuELZWDf8DPdCU=; b=VK1BUGdFRWdJ4Ul6TWlx51GqGkxb+0SOpIVX8yzw/yM41/TCPEr8dEN+ ez1Ds0lMvAUfisd1kNV43cdn53fOkl/XjsC0X81i8V0H3kA4sd+NrQogH 96uVSf2wtWtDxsstsvn0wekVhwh+B14BuTKf4Q/sqyk4D//D/oY0I5In7 bPUrHWBxEZyfJ9SLdgJiTuCsZEEpWrs6DC5OWZxrF/1u461aB9kGSRRwM UJ6oPqiwOT4lpDopAOosk+/evSuBhgkP2wS9fNyoghgy/T6WVKEx6tFV7 o8HCvZBp4ibQmdw65hTyMWmxnSRDHrf+1Hj/n9NXuHUuY8kicVneZaydr Q==; X-CSE-ConnectionGUID: NgRfcAJrRYuOTmeQmkOFmg== X-CSE-MsgGUID: cDPyNdaCSKuZFsS3XFaRKA== X-IronPort-AV: E=McAfee;i="6700,10204,11440"; a="53677813" X-IronPort-AV: E=Sophos;i="6.15,304,1739865600"; d="scan'208";a="53677813" 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:51:00 -0700 X-CSE-ConnectionGUID: 2OrNL80PTlGdcCgCsPo8Lw== X-CSE-MsgGUID: 9uT2xy+8QU6vS7oemHAQBA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,304,1739865600"; d="scan'208";a="141352186" 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:58 -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 21/29] x86/resctrl: x86/resctrl: Read core telemetry events Date: Wed, 21 May 2025 15:50:39 -0700 Message-ID: <20250521225049.132551-22-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" The resctrl file system passes requests to read event monitor files to the architecture resctrl_arch_rmid_read() to collect values from hardware counters. Use the resctrl resource to differentiate between calls to read legacy L3 events from the new telemetry events (which are attached to RDT_RESOURCE_PERF_PKG). There may be multiple aggregators tracking each package, so scan all of them and add up all counters. At run time when a user reads an event file the file system code provides the enum resctrl_event_id for the event. Create a lookup table indexed by event id to provide the telem_entry structure and the event index into MMIO space. Enable the events marked as readable from any CPU. Resctrl now uses readq() so depends on X86_64. Update Kconfig. Signed-off-by: Tony Luck --- arch/x86/kernel/cpu/resctrl/internal.h | 1 + arch/x86/kernel/cpu/resctrl/intel_aet.c | 53 +++++++++++++++++++++++++ arch/x86/kernel/cpu/resctrl/monitor.c | 6 +++ arch/x86/Kconfig | 2 +- 4 files changed, 61 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/r= esctrl/internal.h index 2b2d4b5a4643..42da0a222c7c 100644 --- a/arch/x86/kernel/cpu/resctrl/internal.h +++ b/arch/x86/kernel/cpu/resctrl/internal.h @@ -169,5 +169,6 @@ void rdt_domain_reconfigure_cdp(struct rdt_resource *r); =20 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,= u64 *val); =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 bf8e2a6126d2..be52c9302a80 100644 --- a/arch/x86/kernel/cpu/resctrl/intel_aet.c +++ b/arch/x86/kernel/cpu/resctrl/intel_aet.c @@ -13,6 +13,7 @@ =20 #include #include +#include #include #include =20 @@ -128,6 +129,16 @@ static bool skip_this_region(struct telemetry_region *= tr, struct event_group *e) return false; } =20 +/** + * struct evtinfo - lookup table from resctrl_event_id to useful informati= on + * @event_group: Pointer to the telem_entry structure for this event + * @idx: Counter index within each per-RMID block of counters + */ +static struct evtinfo { + struct event_group *event_group; + int idx; +} evtinfo[QOS_NUM_EVENTS]; + static void free_mmio_info(struct mmio_info **mmi) { int num_pkgs =3D topology_max_packages(); @@ -199,6 +210,15 @@ static int configure_events(struct event_group *e, str= uct pmt_feature_group *p) } e->pkginfo =3D no_free_ptr(pkginfo); =20 + for (int i =3D 0; i < e->num_events; i++) { + enum resctrl_event_id evt; + + evt =3D e->evts[i].evtid; + evtinfo[evt].event_group =3D e; + evtinfo[evt].idx =3D e->evts[i].evt_idx; + resctrl_enable_mon_event(evt, true, e->evts[i].bin_bits); + } + return 0; } =20 @@ -266,3 +286,36 @@ void __exit intel_aet_exit(void) free_mmio_info((*peg)->pkginfo); } } + +#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 evtid,= u64 *val) +{ + struct evtinfo *info =3D &evtinfo[evtid]; + struct mmio_info *mmi; + u64 evtcount; + int idx; + + idx =3D rmid * info->event_group->num_events; + idx +=3D info->idx; + mmi =3D info->event_group->pkginfo[domid]; + + if (idx * sizeof(u64) + sizeof(u64) > info->event_group->mmio_size) { + pr_warn_once("MMIO index %d out of range\n", idx); + return -EIO; + } + + for (int i =3D 0; i < mmi->count; i++) { + evtcount =3D readq(mmi->addrs[i] + idx * sizeof(u64)); + if (!(evtcount & DATA_VALID)) + return -EINVAL; + *val +=3D evtcount & DATA_BITS; + } + + return 0; +} diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/re= sctrl/monitor.c index 1f6dc253112f..c99aa9dacfd8 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -230,6 +230,12 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, str= uct rdt_l3_mon_domain *d, =20 resctrl_arch_rmid_read_context_check(); =20 + if (r->rid =3D=3D RDT_RESOURCE_PERF_PKG) + return intel_aet_read_event(d->hdr.id, rmid, eventid, val); + + if (r->rid !=3D RDT_RESOURCE_L3) + return -EIO; + prmid =3D logical_rmid_to_physical_rmid(cpu, rmid); ret =3D __rmid_read_phys(prmid, eventid, &msr_val); if (ret) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 52cfb69c343f..24df3f04a115 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -506,7 +506,7 @@ config X86_MPPARSE =20 config X86_CPU_RESCTRL bool "x86 CPU resource control support" - depends on X86 && (CPU_SUP_INTEL || CPU_SUP_AMD) + depends on X86_64 && (CPU_SUP_INTEL || CPU_SUP_AMD) depends on MISC_FILESYSTEMS select ARCH_HAS_CPU_RESCTRL select RESCTRL_FS --=20 2.49.0 From nobody Sun Dec 14 19:24:21 2025 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 598AF244684 for ; Wed, 21 May 2025 22:51:10 +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=1747867874; cv=none; b=k0058eKWNN7GL5TPjntuTgsCZqcMn92GXOt6zlA15LLYnEHCiqHE+hIBz6g9prAr0o3ghHtQ4mzKzYDrWjsXs2IcAymlTonlmgF7jkDHXmOFxd25Ni/HHYtTSCUKthNapadWKEjXbMK/N7PI6owpP+QMenPfDKw4ddgrHjbJsCc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747867874; c=relaxed/simple; bh=uPQU9YRN+KUbwCcHdG0+C2skJzAiOOPQTYpRYK0gF6I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JyFdawh4HQ2lPoNVkJs94wRQ1T5/74oaLpsgmSHQATZNxtwv+EpcFuSgQtaemrfDAQKCcpDrQbyAmzr223WZXgJoVqZYQnTc1sDeUvnwVx2vmO5tWJTDrrSgjHZ9KYhy9Rur6aFmws53nncfjJqQNGA2DIDCyb70pWG+5jNz3+w= 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=YsYSXppo; 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="YsYSXppo" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1747867870; x=1779403870; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=uPQU9YRN+KUbwCcHdG0+C2skJzAiOOPQTYpRYK0gF6I=; b=YsYSXppoAvLwZo4UCeTotx3iIxzqmNFOtfJs7wETzQ6Qhwf9G3qVYrQd O4S33IrgOGB2ZNhWi+0kpm+vqiKyR11qhfzdBf9EbONe30HEX8ETo1y+y tRjPWN5QnBZsJqzroMXYdIVmfrceII2kOVg915TPCnDtt+ihSRAIztkTn fXP3wY0NAHpnlTt4OJdSqR0V35u+dfTZYXcRCoWGbyPHxlWt4zUup5fa+ lLTa92Bzo1JTp8UbmJt0agDbFq47K3Wan/VqIRxiOtrBCbi6f4hmPbMBr 7XaBMhtHkpDIwcB5BuMlTO5akj5XXmVYCz5b3wO68Wqys0KG9h8NzMz8A w==; X-CSE-ConnectionGUID: CO7AdfDOSlWltRlPC7wXXA== X-CSE-MsgGUID: 4+KkFto6SQWc+r+kLz6/MA== X-IronPort-AV: E=McAfee;i="6700,10204,11440"; a="53677814" X-IronPort-AV: E=Sophos;i="6.15,304,1739865600"; d="scan'208";a="53677814" 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:51:00 -0700 X-CSE-ConnectionGUID: Q1IRm/hiT1CboqPRR1ZSZg== X-CSE-MsgGUID: 75PdtZpKRKWDedYLqoTeFw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,304,1739865600"; d="scan'208";a="141352189" 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:59 -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 22/29] x86,fs/resctrl: Handle domain creation/deletion for RDT_RESOURCE_PERF_PKG Date: Wed, 21 May 2025 15:50:40 -0700 Message-ID: <20250521225049.132551-23-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" The L3 resource has several requirements for domains. There are structures that hold the 64-bit values of counters, and elements to keep track of the overflow and limbo threads. None of these are needed for the PERF_PKG resource. The hardware counters are wide enough that they do not wrap around for decades. Define a new rdt_perf_pkg_mon_domain structure which just consists of the standard rdt_domain_hdr to keep track of domain id and CPU mask. Change domain_add_cpu_mon(), domain_remove_cpu_mon(), resctrl_offline_mon_domain(), and resctrl_online_mon_domain() to check resource type and perform only the operations needed for domains in the PERF_PKG resource. Signed-off-by: Tony Luck --- arch/x86/kernel/cpu/resctrl/core.c | 41 ++++++++++++++++++++++++++++++ fs/resctrl/rdtgroup.c | 4 +++ 2 files changed, 45 insertions(+) diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resct= rl/core.c index 64ce561e77a0..18d84c497ee4 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -540,6 +540,38 @@ static void l3_mon_domain_setup(int cpu, int id, struc= t rdt_resource *r, struct } } =20 +/** + * struct rdt_perf_pkg_mon_domain - CPUs sharing an Intel-PMT-scoped resct= rl monitor resource + * @hdr: common header for different domain types + */ +struct rdt_perf_pkg_mon_domain { + struct rdt_domain_hdr hdr; +}; + +static void setup_intel_aet_mon_domain(int cpu, int id, struct rdt_resourc= e *r, + struct list_head *add_pos) +{ + struct rdt_perf_pkg_mon_domain *d; + int err; + + d =3D kzalloc_node(sizeof(*d), GFP_KERNEL, cpu_to_node(cpu)); + if (!d) + return; + + d->hdr.id =3D id; + d->hdr.type =3D RESCTRL_MON_DOMAIN; + d->hdr.rid =3D r->rid; + cpumask_set_cpu(cpu, &d->hdr.cpu_mask); + list_add_tail_rcu(&d->hdr.list, add_pos); + + err =3D resctrl_online_mon_domain(r, &d->hdr); + if (err) { + list_del_rcu(&d->hdr.list); + synchronize_rcu(); + kfree(d); + } +} + static void domain_add_cpu_mon(int cpu, struct rdt_resource *r) { int id =3D get_domain_id_from_scope(cpu, r->mon_scope); @@ -567,6 +599,9 @@ static void domain_add_cpu_mon(int cpu, struct rdt_reso= urce *r) case RDT_RESOURCE_L3: l3_mon_domain_setup(cpu, id, r, add_pos); break; + case RDT_RESOURCE_PERF_PKG: + setup_intel_aet_mon_domain(cpu, id, r, add_pos); + break; default: WARN_ON_ONCE(1); } @@ -666,6 +701,12 @@ static void domain_remove_cpu_mon(int cpu, struct rdt_= resource *r) default: pr_warn_once("Unknown resource rid=3D%d\n", r->rid); break; + case RDT_RESOURCE_PERF_PKG: + resctrl_offline_mon_domain(r, hdr); + list_del_rcu(&hdr->list); + synchronize_rcu(); + kfree(container_of(hdr, struct rdt_perf_pkg_mon_domain, hdr)); + break; } } =20 diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index 1e1cc8001cbc..6078cdd5cad0 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -4170,6 +4170,8 @@ int resctrl_online_mon_domain(struct rdt_resource *r,= struct rdt_domain_hdr *hdr if (!domain_header_is_valid(hdr, RESCTRL_MON_DOMAIN, r->rid)) goto out_unlock; =20 + if (r->rid =3D=3D RDT_RESOURCE_PERF_PKG) + goto do_mkdir; d =3D container_of(hdr, struct rdt_l3_mon_domain, hdr); err =3D domain_setup_l3_mon_state(r, d); if (err) @@ -4184,6 +4186,8 @@ int resctrl_online_mon_domain(struct rdt_resource *r,= struct rdt_domain_hdr *hdr if (resctrl_is_mon_event_enabled(QOS_L3_OCCUP_EVENT_ID)) INIT_DELAYED_WORK(&d->cqm_limbo, cqm_handle_limbo); =20 +do_mkdir: + err =3D 0; /* * If the filesystem is not mounted then only the default resource group * exists. Creation of its directories is deferred until mount time --=20 2.49.0 From nobody Sun Dec 14 19:24:21 2025 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 CC04523AE9A for ; Wed, 21 May 2025 22:51:11 +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=1747867874; cv=none; b=swb/54OyNla7z4qp4i2TmjM74E2Ko0y+PbfTFnX8mUUzQSH/YLu/C/8zpIuFOxKTBIQu+mqO2q4ILyttdm3TOd+QXFnfzgUDZKirLIQKYsav6L94qvH7dswUAUFTJm9TjFS+iwTOXDrIuC+kX5gKt/CfIMhCLosLCimtcrqaz/g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747867874; c=relaxed/simple; bh=Vuq2Y1X1WqGtNgyMA65DiHUQ7pD0Ew/rt+rgo5WAH70=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=W7X3uC6rdJU70uPUic2bZEKd+PZB2q+ZjhY4RTRgUtLMknKaLtopVUnbq1URuIHk6XbL0gOeHVT/mUyUCt0XOXRXkArOfkbQoGQpboOiaXGQXGhIo/qKPHESR16HQM2cU79/begMBfvUqwy+R2n/xhgTswlxvFzvveYJ+xK1fZ4= 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=dymt+6s6; 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="dymt+6s6" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1747867872; x=1779403872; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Vuq2Y1X1WqGtNgyMA65DiHUQ7pD0Ew/rt+rgo5WAH70=; b=dymt+6s6EfW2rn7AZSkQZ+ZkyvLHyzKfiC6wU82jrC2q4iIlOiUAnfdU pqJApZ9HtuIQwuR7wftp3wizqCHfHAsB/HJDPO5SrMeAxn1feOw6IDpTA hL8pczEQvQQeTgT9XCufxpOuGzw+nNtoKfSQJbOx/EjCX4fE3UZwRrr/N fhaKHZ7FH1AnLqiT717QlGWf1jdEV98lodsgjPb5DZbS/25LOWdJmioT6 dPON2usUthsFnlP6oSK78RQiPYJ8b6hRkbzU7vsGU+ftFawaCTZbbzjYS VNrlNwA3KERpV6J0kmtt8Y2/+h+WV/TlT1gZYJlgnNJvbKuxR17DyQt9y Q==; X-CSE-ConnectionGUID: Bf/BEhsCQFe9SEwu6AqWnw== X-CSE-MsgGUID: md+9ZUvjRWWQqTTuN6G7Gg== X-IronPort-AV: E=McAfee;i="6700,10204,11440"; a="53677822" X-IronPort-AV: E=Sophos;i="6.15,304,1739865600"; d="scan'208";a="53677822" 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:51:00 -0700 X-CSE-ConnectionGUID: pC9+aHUnSQ6Kze+YGjV2dA== X-CSE-MsgGUID: 3cV8fQp7TGaBMx0MQwIr6A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,304,1739865600"; d="scan'208";a="141352193" 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:59 -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 23/29] x86/resctrl: Enable RDT_RESOURCE_PERF_PKG Date: Wed, 21 May 2025 15:50:41 -0700 Message-ID: <20250521225049.132551-24-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" The RDT_RESOURCE_PERF_PKG resource is not marked as "mon_capable" during early resctrl initialization. This means that the domain lists for the resource are not built when the CPU hot plug notifiers are registered. Mark the resource as mon_capable and call domain_add_cpu_mon() for each online CPU to build the domain lists in the first call to the resctrl_arch_pre_mount() hook. Signed-off-by: Tony Luck --- arch/x86/kernel/cpu/resctrl/core.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resct= rl/core.c index 18d84c497ee4..f07f5b58639a 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -763,14 +763,27 @@ static int resctrl_arch_offline_cpu(unsigned int cpu) =20 void resctrl_arch_pre_mount(void) { + struct rdt_resource *r =3D &rdt_resources_all[RDT_RESOURCE_PERF_PKG].r_re= sctrl; static atomic_t only_once; - int old =3D 0; + int cpu, old =3D 0; =20 if (!atomic_try_cmpxchg(&only_once, &old, 1)) return; =20 if (!intel_aet_get_events()) return; + + /* + * Late discovery of telemetry events means the domains for the + * resource were not built. Do that now. + */ + cpus_read_lock(); + mutex_lock(&domain_list_lock); + r->mon_capable =3D true; + for_each_online_cpu(cpu) + domain_add_cpu_mon(cpu, r); + mutex_unlock(&domain_list_lock); + cpus_read_unlock(); } =20 enum { --=20 2.49.0 From nobody Sun Dec 14 19:24:21 2025 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 2DA1B2459F3 for ; Wed, 21 May 2025 22:51:11 +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=1747867873; cv=none; b=m/mWiZRmYqbKCt75DA8WDTRLlv4gSI1L/7uy4LUn3mtED9CRYAROs9PNGjaF6TBXsvczzjWBei69YieLxXuouMGaouto+uPT+lOIkOva1kQ8yChcD09kUW2jXy0f/CyUykInO7t3GqreOln3OKjMjtYPgX1xu/AT4O5LoYlFNjQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747867873; c=relaxed/simple; bh=tFZIOgmF1yBHMePyVDJXVVS9f4ngI3WXCqT1ILeychM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HqgnIjatD6YK/DHwWBAVYvC4Uu7KtoriGREBQ2nXVP+3jlFr9MQInN/18ugQB6ocNKXLGQ5GjJM1F9IfPJUoXvt+PfXTd1if1U6WmWvDC1akEoAgLsdI9qWJZSfEUR9B07L5Hya8X1EFfVnwD1qR2QlTDViZyehAj6MCaI15FUI= 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=JKH9A6YE; 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="JKH9A6YE" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1747867871; x=1779403871; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tFZIOgmF1yBHMePyVDJXVVS9f4ngI3WXCqT1ILeychM=; b=JKH9A6YEYZpwmJIA+v5tf0aVUtXEf0o6Br758hQ4onY4yjVMYZ21K6Gu dFPvgToeIV7WEess179b3fJjFWMqfwl/SyaU9NPG0GqGdm15k4u8JSlrm /Z2TRjcTHjicsuCtZib+lSAnK910owbjrZj0Seqzc7mI+W1dVzJDsnB5X 0hIQOAoNSHRymjxaH6a7RVBDWX5WIANuupxbpVxK7wxLQ9+hN9LoyDcDa dRa+oHMGMbUNbiCmYpvCcDzgGf0JYjcdXvVexrLEOmnFkNIpoagamHR+S zjW0+9f/GUyKabshvTSQ8IXVlLZCZ2i/krDhvoTHTZP/85gTTRicNcC/l w==; X-CSE-ConnectionGUID: i4JHuDsbSpyHOIRu96O9rQ== X-CSE-MsgGUID: hYoUU38SQpOJfelW7q4Ttw== X-IronPort-AV: E=McAfee;i="6700,10204,11440"; a="53677823" X-IronPort-AV: E=Sophos;i="6.15,304,1739865600"; d="scan'208";a="53677823" 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:51:00 -0700 X-CSE-ConnectionGUID: UCwfJBwyQdy9Xpy3VZxTQg== X-CSE-MsgGUID: BLn1/SjZTgaA+zcfYnixXQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,304,1739865600"; d="scan'208";a="141352197" 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:59 -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 24/29] x86/resctrl: Add energy/perf choices to rdt boot option Date: Wed, 21 May 2025 15:50:42 -0700 Message-ID: <20250521225049.132551-25-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" Users may want to force either of the telemetry features on (in the case where they are disabled due to erratum) or off (in the case that a limited number of RMIDs for a telemetry feature reduces the number of monitor groups that can be created.) Unlike other options that are tied to X86_FEATURE_* flags, these must be queried by name. Add a function to do that. Add checks for users who forced either feature off. Signed-off-by: Tony Luck --- .../admin-guide/kernel-parameters.txt | 2 +- arch/x86/kernel/cpu/resctrl/internal.h | 4 +++ arch/x86/kernel/cpu/resctrl/core.c | 28 +++++++++++++++++++ arch/x86/kernel/cpu/resctrl/intel_aet.c | 6 ++++ 4 files changed, 39 insertions(+), 1 deletion(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentatio= n/admin-guide/kernel-parameters.txt index d9fd26b95b34..4811bc812f0f 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -5988,7 +5988,7 @@ rdt=3D [HW,X86,RDT] Turn on/off individual RDT features. List is: cmt, mbmtotal, mbmlocal, l3cat, l3cdp, l2cat, l2cdp, - mba, smba, bmec. + mba, smba, bmec, energy, perf. E.g. to turn on cmt and turn off mba use: rdt=3Dcmt,!mba =20 diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/r= esctrl/internal.h index 42da0a222c7c..524f3c183900 100644 --- a/arch/x86/kernel/cpu/resctrl/internal.h +++ b/arch/x86/kernel/cpu/resctrl/internal.h @@ -167,6 +167,10 @@ void __init intel_rdt_mbm_apply_quirk(void); =20 void rdt_domain_reconfigure_cdp(struct rdt_resource *r); =20 +bool rdt_is_option_force_enabled(char *option); + +bool rdt_is_option_force_disabled(char *option); + 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,= u64 *val); diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resct= rl/core.c index f07f5b58639a..b23309566500 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -797,6 +797,8 @@ enum { RDT_FLAG_MBA, RDT_FLAG_SMBA, RDT_FLAG_BMEC, + RDT_FLAG_ENERGY, + RDT_FLAG_PERF, }; =20 #define RDT_OPT(idx, n, f) \ @@ -822,6 +824,8 @@ static struct rdt_options rdt_options[] __ro_after_ini= t =3D { RDT_OPT(RDT_FLAG_MBA, "mba", X86_FEATURE_MBA), RDT_OPT(RDT_FLAG_SMBA, "smba", X86_FEATURE_SMBA), RDT_OPT(RDT_FLAG_BMEC, "bmec", X86_FEATURE_BMEC), + RDT_OPT(RDT_FLAG_ENERGY, "energy", 0), + RDT_OPT(RDT_FLAG_PERF, "perf", 0), }; #define NUM_RDT_OPTIONS ARRAY_SIZE(rdt_options) =20 @@ -871,6 +875,30 @@ bool rdt_cpu_has(int flag) return ret; } =20 +bool rdt_is_option_force_enabled(char *name) +{ + struct rdt_options *o; + + for (o =3D rdt_options; o < &rdt_options[NUM_RDT_OPTIONS]; o++) { + if (!strcmp(name, o->name)) + return o->force_on; + } + + return false; +} + +bool rdt_is_option_force_disabled(char *name) +{ + struct rdt_options *o; + + for (o =3D rdt_options; o < &rdt_options[NUM_RDT_OPTIONS]; o++) { + if (!strcmp(name, o->name)) + return o->force_off; + } + + return false; +} + bool resctrl_arch_is_evt_configurable(enum resctrl_event_id evt) { if (!rdt_cpu_has(X86_FEATURE_BMEC)) diff --git a/arch/x86/kernel/cpu/resctrl/intel_aet.c b/arch/x86/kernel/cpu/= resctrl/intel_aet.c index be52c9302a80..c1fc85dbf0d8 100644 --- a/arch/x86/kernel/cpu/resctrl/intel_aet.c +++ b/arch/x86/kernel/cpu/resctrl/intel_aet.c @@ -51,6 +51,7 @@ struct pmt_event { =20 /** * struct event_group - All information about a group of telemetry events. + * @name: Name for this group (used by boot rdt=3D option) * @pfg: Points to the aggregated telemetry space information * within the OOBMSM driver that contains data for all * telemetry regions. @@ -62,6 +63,7 @@ struct pmt_event { */ struct event_group { /* Data fields used by this code. */ + char *name; struct pmt_feature_group *pfg; struct mmio_info **pkginfo; =20 @@ -77,6 +79,7 @@ struct event_group { * File: xml/CWF/OOBMSM/RMID-ENERGY/cwf_aggregator.xml */ static struct event_group energy_0x26696143 =3D { + .name =3D "energy", .guid =3D 0x26696143, .mmio_size =3D (576 * 2 + 3) * 8, .num_events =3D 2, @@ -91,6 +94,7 @@ static struct event_group energy_0x26696143 =3D { * File: xml/CWF/OOBMSM/RMID-PERF/cwf_aggregator.xml */ static struct event_group perf_0x26557651 =3D { + .name =3D "perf", .guid =3D 0x26557651, .mmio_size =3D (576 * 7 + 3) * 8, .num_events =3D 7, @@ -247,6 +251,8 @@ static bool get_pmt_feature(enum pmt_feature_id feature) for (peg =3D &known_event_groups[0]; peg < &known_event_groups[NUM_KNOWN_= GROUPS]; peg++) { for (int i =3D 0; i < p->count; i++) { if ((*peg)->guid =3D=3D p->regions[i].guid) { + if (rdt_is_option_force_disabled((*peg)->name)) + return false; ret =3D configure_events(*peg, p); if (!ret) { (*peg)->pfg =3D no_free_ptr(p); --=20 2.49.0 From nobody Sun Dec 14 19:24:21 2025 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 A85DF24886F for ; Wed, 21 May 2025 22:51:13 +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=1747867876; cv=none; b=LkVC0QuFLTXK5lwZGt/TGLSEjIieKpZqHx3N8Wgqv8V/Z9Ve5iPv0B0RVSsTIKtj4zShiLIKZaIxRRwqUWnsCulbTEaBWmeSkdgg737gHfR7TxuP+kHoHwFdOjtu4bDYHGNpblphdJa+pVBgixrGu5JmuBybo5PbuH+j3BqiKnA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747867876; c=relaxed/simple; bh=JFDhcWFdpPeO9F/sP8unuhO2mLfulMtfa551HkDW0Ig=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Yy/w/IG/bH/Ccs9nUdcPRLnmFcZhRlbBXIpjYjre0/9iqSI8bfs8tJrVKq5Me8HjQv3IMo4lhFnYK9XvRtKIhrMbIOa7C2EtD0j15cA95/tkFo+/C6BrUH+LVKd00VDwO3Phrzc6RclgMBLasIqm1h8rNrT9xVuTw9hemFytgQE= 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=b6uynKwa; 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="b6uynKwa" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1747867874; x=1779403874; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=JFDhcWFdpPeO9F/sP8unuhO2mLfulMtfa551HkDW0Ig=; b=b6uynKwa4rKgfanHzwyJ8fghY7sd1Vkrbg8MB856j4HKuAyMDKq18Xp/ 2CO4c1zVoE4ZMQ+3qJ84366AUsgLq+zjSGIMNiAs0gKuDr57Qwg7n5P7k g6Makjq0CrX7jcwKNXw8rPEO6PNDwq45uRDwRS/Q1yjjUsT8kOsXWdv4/ KsY6EoT1+6k2Fz8O9jEgj4YNVvlg+nhI2X9IIYxE1Q2YQExeWIcY4C8kN aTWwCg154oUHjGHXfu/wiCDYqkrkxTjViy+RT1hnQ7bvo5255YKX/a+qw lVRKgj7mrsYTqU4g84urPldmmvPaYA6L1Ibc3JO1PpEyKQjtIZT0r8Mk3 A==; X-CSE-ConnectionGUID: xAJkestNQZqCsnQ4TL2p/g== X-CSE-MsgGUID: RSPPNTGHTm6p9UymOazhvA== X-IronPort-AV: E=McAfee;i="6700,10204,11440"; a="53677831" X-IronPort-AV: E=Sophos;i="6.15,304,1739865600"; d="scan'208";a="53677831" 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:51:00 -0700 X-CSE-ConnectionGUID: GnBbC+6+S2+xP7/Aur9XrA== X-CSE-MsgGUID: wCPA3aTzR7+LZ57BImkWEw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,304,1739865600"; d="scan'208";a="141352200" 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:59 -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 25/29] x86/resctrl: Handle number of RMIDs supported by telemetry resources Date: Wed, 21 May 2025 15:50:43 -0700 Message-ID: <20250521225049.132551-26-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 now three meanings for "number of RMIDs": 1) The number for legacy features enumerated by CPUID leaf 0xF. This is the maximum number of distinct values that can be loaded into the IA32_PQR_ASSOC MSR. Note that systems with Sub-NUMA Cluster mode enabled will force scaling down the CPUID enumerated value by the number of SNC nodes per L3-cache. 2) The number of registers in MMIO space for each event. This is enumerated in the XML files and is the value initialized into event_group::num_rmids. This will be overwritten with a lower value if hardware does not support all these registers at the same time (see next case). 3) The number of "h/w counters" (this isn't a strictly accurate description of how things work, but serves as a useful analogy that does describe the limitations) feeding to those MMIO registers. This is enumerated in telemetry_region::num_rmids returned from the call to intel_pmt_get_regions_by_feature() Event groups with insufficient "h/w counter" to track all RMIDs are difficult for users to use, since the system may reassign "h/w counters" as any time. This means that users cannot reliably collect two consecutive event counts to compute the rate at which events are occurring. Ignore such under-resourced event groups unless the user explicitly requests to enable them using the "rdt=3D" Linux boot argument. Scan all enabled event groups and assign the RDT_RESOURCE_PERF_PKG resource "num_rmids" value to the smallest of these values to ensure that all resctrl groups have equal monitor capabilities. N.B. Changed type of rdt_resource::num_rmids to u32 to match. Signed-off-by: Tony Luck --- include/linux/resctrl.h | 2 +- arch/x86/kernel/cpu/resctrl/internal.h | 2 ++ arch/x86/kernel/cpu/resctrl/intel_aet.c | 27 +++++++++++++++++++++++++ arch/x86/kernel/cpu/resctrl/monitor.c | 2 ++ 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index 4ba51cb598e1..b7e15abcde23 100644 --- a/include/linux/resctrl.h +++ b/include/linux/resctrl.h @@ -286,7 +286,7 @@ struct rdt_resource { int rid; bool alloc_capable; bool mon_capable; - int num_rmid; + u32 num_rmid; enum resctrl_scope ctrl_scope; enum resctrl_scope mon_scope; struct resctrl_cache cache; diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/r= esctrl/internal.h index 524f3c183900..795534b9b9d2 100644 --- a/arch/x86/kernel/cpu/resctrl/internal.h +++ b/arch/x86/kernel/cpu/resctrl/internal.h @@ -18,6 +18,8 @@ =20 #define RMID_VAL_UNAVAIL BIT_ULL(62) =20 +extern int rdt_num_system_rmids; + /* * With the above fields in use 62 bits remain in MSR_IA32_QM_CTR for * data to be returned. The counter width is discovered from the hardware diff --git a/arch/x86/kernel/cpu/resctrl/intel_aet.c b/arch/x86/kernel/cpu/= resctrl/intel_aet.c index c1fc85dbf0d8..1b41167ad976 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 @@ -57,6 +58,9 @@ struct pmt_event { * telemetry regions. * @pkginfo: Per-package MMIO addresses of telemetry regions belonging to= this group * @guid: Unique number per XML description file. + * @num_rmids: Number of RMIDS supported by this group. Will be adjusted = downwards + * if enumeration from intel_pmt_get_regions_by_feature() indicates + * fewer RMIDs can be tracked simultaneously. * @mmio_size: Number of bytes of MMIO registers for this group. * @num_events: Number of events in this group. * @evts: Array of event descriptors. @@ -69,6 +73,7 @@ struct event_group { =20 /* Remaining fields initialized from XML file. */ u32 guid; + u32 num_rmids; size_t mmio_size; int num_events; struct pmt_event evts[] __counted_by(num_events); @@ -81,6 +86,7 @@ struct event_group { static struct event_group energy_0x26696143 =3D { .name =3D "energy", .guid =3D 0x26696143, + .num_rmids =3D 576, .mmio_size =3D (576 * 2 + 3) * 8, .num_events =3D 2, .evts =3D { @@ -96,6 +102,7 @@ static struct event_group energy_0x26696143 =3D { static struct event_group perf_0x26557651 =3D { .name =3D "perf", .guid =3D 0x26557651, + .num_rmids =3D 576, .mmio_size =3D (576 * 7 + 3) * 8, .num_events =3D 7, .evts =3D { @@ -253,6 +260,15 @@ static bool get_pmt_feature(enum pmt_feature_id featur= e) if ((*peg)->guid =3D=3D p->regions[i].guid) { if (rdt_is_option_force_disabled((*peg)->name)) return false; + /* + * Ignore event group with insufficient RMIDs unless the + * user used the rdt=3D boot option to specifically ask + * for it to be enabled. + */ + if (p->regions[i].num_rmids < rdt_num_system_rmids && + !rdt_is_option_force_enabled((*peg)->name)) + return false; + (*peg)->num_rmids =3D min((*peg)->num_rmids, p->regions[i].num_rmids); ret =3D configure_events(*peg, p); if (!ret) { (*peg)->pfg =3D no_free_ptr(p); @@ -272,11 +288,22 @@ static bool get_pmt_feature(enum pmt_feature_id featu= re) */ bool intel_aet_get_events(void) { + struct rdt_resource *r =3D &rdt_resources_all[RDT_RESOURCE_PERF_PKG].r_re= sctrl; + struct event_group **eg; bool ret1, ret2; =20 ret1 =3D get_pmt_feature(FEATURE_PER_RMID_ENERGY_TELEM); ret2 =3D get_pmt_feature(FEATURE_PER_RMID_PERF_TELEM); =20 + for (eg =3D &known_event_groups[0]; eg < &known_event_groups[NUM_KNOWN_GR= OUPS]; eg++) { + if (!(*eg)->pfg) + continue; + if (r->num_rmid) + r->num_rmid =3D min(r->num_rmid, (*eg)->num_rmids); + else + r->num_rmid =3D (*eg)->num_rmids; + } + return ret1 || ret2; } =20 diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/re= sctrl/monitor.c index c99aa9dacfd8..9cd37be262a2 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -32,6 +32,7 @@ bool rdt_mon_capable; =20 #define CF(cf) ((unsigned long)(1048576 * (cf) + 0.5)) =20 +int rdt_num_system_rmids; static int snc_nodes_per_l3_cache =3D 1; =20 /* @@ -350,6 +351,7 @@ int __init rdt_get_mon_l3_config(struct rdt_resource *r) resctrl_rmid_realloc_limit =3D boot_cpu_data.x86_cache_size * 1024; hw_res->mon_scale =3D boot_cpu_data.x86_cache_occ_scale / snc_nodes_per_l= 3_cache; r->num_rmid =3D (boot_cpu_data.x86_cache_max_rmid + 1) / snc_nodes_per_l3= _cache; + rdt_num_system_rmids =3D r->num_rmid; hw_res->mbm_width =3D MBM_CNTR_WIDTH_BASE; =20 if (mbm_offset > 0 && mbm_offset <=3D MBM_CNTR_WIDTH_OFFSET_MAX) --=20 2.49.0 From nobody Sun Dec 14 19:24:21 2025 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 27EBD248F43 for ; Wed, 21 May 2025 22:51:14 +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=1747867876; cv=none; b=Oq7nwuO/Doby1+MCkLNrZlQEzHtLF6Jlni6h+oBbb0VqtYDbS0fs3xY9dR58Oen1exI1f/vcqRyiitnihpr4LD2KGBE6eXXT2ucBK+lPUab/v+nVb8Xo45jUtzVHSfC/AuSk7RLo4h8pG+ln5aBCEeqOD+R4LbLjiQ5bcCy0ai4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747867876; c=relaxed/simple; bh=Tf5Vr/3BaV/jZLBI9TGK8FQ85PWBU2b3anQXN/sHg2Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KZjAzN8+fw65Ul1b/B9VZGPUNhnNXGh/O2Rl+SBlSu7f9EFqH7n6dsIuOc7h/ms/MBK9A+eItak6qUc0FoHZ1RMTPmR5ccYlvquUiYpgqpO4NABfsPmQWnDQgo6g3tLfZWXaxpHl5fUn7BdO+xjJmHp321orHH6+A0uUc2Gzt/A= 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=X6ZpXKzY; 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="X6ZpXKzY" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1747867874; x=1779403874; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Tf5Vr/3BaV/jZLBI9TGK8FQ85PWBU2b3anQXN/sHg2Y=; b=X6ZpXKzYbzkv1mZc8zZeWTIwDNMEH0HLbCeYFOe5xUOZDmyCXfBdLAEG Fx35ODfXWVGwOMkemgw9AjNOFF4UsaueylfTliZpwi9m7cmhemMkwH+x2 l1OVp+BemulICeMN8bR7rQhRq08A2zSR4kx+oIdp//7S5DBpU9eFPozr6 +705sgRwERBOwFxfAJaA3BWOgdbo0kyZ9rdJG2RCoXZnx0L85SmxCtaSE OOH6QVpQXOfSm7bHEjrAqQBNfqX5irHTJFooRwdFrHcSIFqNZaDsxuFPE w0Q+7NPHRpICY79cJycU6k8zj5EoJnzcoeisvO2DqJq3cY6zHPIwhD+CL g==; X-CSE-ConnectionGUID: v92OrKJjSfKwy0LNHp3PRQ== X-CSE-MsgGUID: hbCjzkpvQay5EzDQiTrPQA== X-IronPort-AV: E=McAfee;i="6700,10204,11440"; a="53677832" X-IronPort-AV: E=Sophos;i="6.15,304,1739865600"; d="scan'208";a="53677832" 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:51:00 -0700 X-CSE-ConnectionGUID: o3JN4+EvTXqaiZDMpvXi7A== X-CSE-MsgGUID: DENlstCJROiZqDbPH5xF7Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,304,1739865600"; d="scan'208";a="141352203" 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:59 -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 26/29] x86,fs/resctrl: Move RMID initialization to first mount Date: Wed, 21 May 2025 15:50:44 -0700 Message-ID: <20250521225049.132551-27-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" The resctrl file system code assumed that the only monitor events were tied to the RDT_RESOURCE_L3 resource. Also that the number of supported RMIDs was enumerated during early initialization. RDT_RESOURCE_PERF_PKG breaks both of those assumptions. Delay the final enumeration of the number of RMIDs and subsequent allocation of structures until first mount of the resctrl file system. Signed-off-by: Tony Luck --- fs/resctrl/internal.h | 4 ++- arch/x86/kernel/cpu/resctrl/core.c | 8 +++-- fs/resctrl/monitor.c | 58 +++++++++++++----------------- fs/resctrl/rdtgroup.c | 12 +++++-- 4 files changed, 42 insertions(+), 40 deletions(-) diff --git a/fs/resctrl/internal.h b/fs/resctrl/internal.h index 64c1c226d676..1f4800cfcd6a 100644 --- a/fs/resctrl/internal.h +++ b/fs/resctrl/internal.h @@ -348,6 +348,8 @@ int alloc_rmid(u32 closid); =20 void free_rmid(u32 closid, u32 rmid); =20 +int resctrl_mon_dom_data_init(void); + void resctrl_mon_resource_exit(void); =20 void mon_event_count(void *info); @@ -358,7 +360,7 @@ void mon_event_read(struct rmid_read *rr, struct rdt_re= source *r, struct rdt_l3_mon_domain *d, struct rdtgroup *rdtgrp, cpumask_t *cpumask, struct mon_evt *evt, int first); =20 -int resctrl_mon_resource_init(void); +void resctrl_mon_l3_resource_init(void); =20 void mbm_setup_overflow_handler(struct rdt_l3_mon_domain *dom, unsigned long delay_ms, diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resct= rl/core.c index b23309566500..8a9ceb03e252 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -111,10 +111,14 @@ struct rdt_hw_resource rdt_resources_all[RDT_NUM_RESO= URCES] =3D { =20 u32 resctrl_arch_system_num_rmid_idx(void) { - struct rdt_resource *r =3D &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl; + u32 num_rmids =3D U32_MAX; + struct rdt_resource *r; + + for_each_mon_capable_rdt_resource(r) + num_rmids =3D min(num_rmids, r->num_rmid); =20 /* RMID are independent numbers for x86. num_rmid_idx =3D=3D num_rmid */ - return r->num_rmid; + return num_rmids; } =20 struct rdt_resource *resctrl_arch_get_resource(enum resctrl_res_level l) diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c index f24a568f7b67..6041cb304624 100644 --- a/fs/resctrl/monitor.c +++ b/fs/resctrl/monitor.c @@ -775,15 +775,27 @@ void mbm_setup_overflow_handler(struct rdt_l3_mon_dom= ain *dom, unsigned long del schedule_delayed_work_on(cpu, &dom->mbm_over, delay); } =20 -static int dom_data_init(struct rdt_resource *r) +/* + * resctrl_dom_data_init() - Initialise global monitoring structures. + * + * Allocate and initialise global monitor resources that do not belong to a + * specific domain. i.e. the rmid_ptrs[] used for the limbo and free lists. + * Called once during boot after the struct rdt_resource's have been confi= gured + * but before the filesystem is mounted. + * Resctrl's cpuhp callbacks may be called before this point to bring a do= main + * online. + * + * Returns 0 for success, or -ENOMEM. + */ +int resctrl_mon_dom_data_init(void) { + struct rdt_resource *r =3D resctrl_arch_get_resource(RDT_RESOURCE_L3); u32 idx_limit =3D resctrl_arch_system_num_rmid_idx(); u32 num_closid =3D resctrl_arch_get_num_closid(r); struct rmid_entry *entry =3D NULL; - int err =3D 0, i; u32 idx; + int i; =20 - mutex_lock(&rdtgroup_mutex); if (IS_ENABLED(CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID)) { u32 *tmp; =20 @@ -794,10 +806,8 @@ static int dom_data_init(struct rdt_resource *r) * use. */ tmp =3D kcalloc(num_closid, sizeof(*tmp), GFP_KERNEL); - if (!tmp) { - err =3D -ENOMEM; - goto out_unlock; - } + if (!tmp) + return -ENOMEM; =20 closid_num_dirty_rmid =3D tmp; } @@ -808,8 +818,7 @@ static int dom_data_init(struct rdt_resource *r) kfree(closid_num_dirty_rmid); closid_num_dirty_rmid =3D NULL; } - err =3D -ENOMEM; - goto out_unlock; + return -ENOMEM; } =20 for (i =3D 0; i < idx_limit; i++) { @@ -830,13 +839,10 @@ static int dom_data_init(struct rdt_resource *r) entry =3D __rmid_entry(idx); list_del(&entry->list); =20 -out_unlock: - mutex_unlock(&rdtgroup_mutex); - - return err; + return 0; } =20 -static void dom_data_exit(struct rdt_resource *r) +static void resctrl_mon_dom_data_exit(struct rdt_resource *r) { mutex_lock(&rdtgroup_mutex); =20 @@ -943,28 +949,14 @@ bool resctrl_is_mon_event_enabled(enum resctrl_event_= id evtid) } =20 /** - * resctrl_mon_resource_init() - Initialise global monitoring structures. - * - * Allocate and initialise global monitor resources that do not belong to a - * specific domain. i.e. the rmid_ptrs[] used for the limbo and free lists. - * Called once during boot after the struct rdt_resource's have been confi= gured - * but before the filesystem is mounted. - * Resctrl's cpuhp callbacks may be called before this point to bring a do= main - * online. - * - * Returns 0 for success, or -ENOMEM. + * resctrl_mon_l3_resource_init() - Initialise L3 configuration options. */ -int resctrl_mon_resource_init(void) +void resctrl_mon_l3_resource_init(void) { struct rdt_resource *r =3D resctrl_arch_get_resource(RDT_RESOURCE_L3); - int ret; =20 if (!r->mon_capable) - return 0; - - ret =3D dom_data_init(r); - if (ret) - return ret; + return; =20 if (resctrl_arch_is_evt_configurable(QOS_L3_MBM_TOTAL_EVENT_ID)) { mon_event_all[QOS_L3_MBM_TOTAL_EVENT_ID].configurable =3D true; @@ -981,13 +973,11 @@ int resctrl_mon_resource_init(void) mba_mbps_default_event =3D QOS_L3_MBM_LOCAL_EVENT_ID; else if (resctrl_is_mon_event_enabled(QOS_L3_MBM_TOTAL_EVENT_ID)) mba_mbps_default_event =3D QOS_L3_MBM_TOTAL_EVENT_ID; - - return 0; } =20 void resctrl_mon_resource_exit(void) { struct rdt_resource *r =3D resctrl_arch_get_resource(RDT_RESOURCE_L3); =20 - dom_data_exit(r); + resctrl_mon_dom_data_exit(r); } diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index 6078cdd5cad0..e212e46e0780 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -2583,6 +2583,7 @@ static int rdt_get_tree(struct fs_context *fc) unsigned long flags =3D RFTYPE_CTRL_BASE; struct rdt_l3_mon_domain *dom; struct rdt_resource *r; + static bool once; int ret; =20 resctrl_arch_pre_mount(); @@ -2597,6 +2598,13 @@ static int rdt_get_tree(struct fs_context *fc) goto out; } =20 + if (resctrl_arch_mon_capable() && !once) { + ret =3D resctrl_mon_dom_data_init(); + if (ret) + goto out; + once =3D true; + } + ret =3D rdtgroup_setup_root(ctx); if (ret) goto out; @@ -4290,9 +4298,7 @@ int resctrl_init(void) =20 thread_throttle_mode_init(); =20 - ret =3D resctrl_mon_resource_init(); - if (ret) - return ret; + resctrl_mon_l3_resource_init(); =20 ret =3D sysfs_create_mount_point(fs_kobj, "resctrl"); if (ret) { --=20 2.49.0 From nobody Sun Dec 14 19:24:21 2025 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 72BA724C07B for ; Wed, 21 May 2025 22:51:16 +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=1747867878; cv=none; b=E9U+lIM/0uKOcim+POYlV0KuuOFHxTtRnmPaQH30xI0uui5+SuAfvKkRJkelYbs6D+P2QfMOgDyK2WffZw5q9qRqb5N92PWFJkJIo1UduiBWpuWdI2hMmrFVrIA9jz+SuPhtMswC1LLgWU5J3CbHOyMsrj06CWHxT0cxhoFiHiw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747867878; c=relaxed/simple; bh=jrQloV55Ky0xgLq1zhFh0R9wuW/MuUNKJYq9Raj0okk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=A03ezfbLgp7fG7ZTwpqtgavqCWdJm0nouPSdnPsNLPkrrlCAmJQluNgLMQbgZL8JfnTdy6UPBmQm7L60U+uxrRf7g6uecEpD+3Dbu+pAEhc26500LiPIgbogrBNuQX7DAWTyHCSnZI/pMp9LrzaB/Jw1wtht/8uuurk/p4OOEjk= 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=MuOi5n/u; 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="MuOi5n/u" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1747867876; x=1779403876; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=jrQloV55Ky0xgLq1zhFh0R9wuW/MuUNKJYq9Raj0okk=; b=MuOi5n/ue6jm8BzFdtkEFVrD/HOC+ApZl7raivivmrQxZxRSNklfW1ZF IboUhYa7gS6jhkUK/mGNHISSX5xDzxzMArxsrU0wDadFYqOya3Ed9neIQ syTU29CtetWctSLCoaUahHXYiAc4vSfD+1zfCB0ZNwM8ylv3ghTKj6N6H 1f+uoDfxoGz8/orXDu1x08Zkj0ePAT9AxCh/e4tN0XAOFV7FcOni5ozGJ pSS8n+xUGo0AmK75uV97I41SCQgfc2heRW40RbjKxFoO81o+H2+qhxOON UJh4kwVTyRDBDTEtPm9OXOtyacc0VXDrwgvolgh9IQcDTPeQv+RQb1k+g A==; X-CSE-ConnectionGUID: 8iQFIdJqQ++Xvh1J3j2pTg== X-CSE-MsgGUID: uH/qzomLSW2jlhcOp9srVw== X-IronPort-AV: E=McAfee;i="6700,10204,11440"; a="53677837" X-IronPort-AV: E=Sophos;i="6.15,304,1739865600"; d="scan'208";a="53677837" 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:51:00 -0700 X-CSE-ConnectionGUID: PhPr06BlSii+AiDBGoPJHA== X-CSE-MsgGUID: fd64e14iStGT9CnV3YtdCQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,304,1739865600"; d="scan'208";a="141352206" 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:59 -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 27/29] fs/resctrl: Add file system mechanism for architecture info file Date: Wed, 21 May 2025 15:50:45 -0700 Message-ID: <20250521225049.132551-28-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" Creation of all files in the resctrl file system is under control of the file system layer. But some resources may need to add a file to the info/{resource} directory for debug purposes. Add a new rdt_resource::info_file field for the resource to specify show() and/or write() operations. These will be called with the rdtgroup_mutex held. Architecture can note the file is only for debug using by setting the rftype::flags RFTYPE_DEBUG bit. Signed-off-by: Tony Luck --- include/linux/resctrl.h | 33 +++++++++++++++++++++++++++ fs/resctrl/internal.h | 31 ++----------------------- fs/resctrl/rdtgroup.c | 50 ++++++++++++++++++++++++++++++++++++++--- 3 files changed, 82 insertions(+), 32 deletions(-) diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index b7e15abcde23..e067007c633c 100644 --- a/include/linux/resctrl.h +++ b/include/linux/resctrl.h @@ -73,6 +73,37 @@ enum resctrl_conf_type { =20 #define CDP_NUM_TYPES (CDP_DATA + 1) =20 +/** + * struct rftype - describe each file in the resctrl file system + * @name: File name + * @mode: Access mode + * @kf_ops: File operations + * @flags: File specific RFTYPE_FLAGS_* flags + * @fflags: File specific RFTYPE_* flags + * @seq_show: Show content of the file + * @write: Write to the file + */ +struct rftype { + char *name; + umode_t mode; + const struct kernfs_ops *kf_ops; + unsigned long flags; + unsigned long fflags; + + int (*seq_show)(struct kernfs_open_file *of, + struct seq_file *sf, void *v); + /* + * write() is the generic write callback which maps directly to + * kernfs write operation and overrides all other operations. + * Maximum write size is determined by ->max_write_len. + */ + ssize_t (*write)(struct kernfs_open_file *of, + char *buf, size_t nbytes, loff_t off); +}; + +/* Only rftype::flags option available to architecture code */ +#define RFTYPE_DEBUG BIT(10) + /* * struct pseudo_lock_region - pseudo-lock region information * @s: Resctrl schema for the resource to which this @@ -281,6 +312,7 @@ enum resctrl_schema_fmt { * @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 + * @info_file: Optional per-resource debug info file */ struct rdt_resource { int rid; @@ -297,6 +329,7 @@ struct rdt_resource { enum resctrl_schema_fmt schema_fmt; unsigned int mbm_cfg_mask; bool cdp_capable; + struct rftype info_file; }; =20 /* diff --git a/fs/resctrl/internal.h b/fs/resctrl/internal.h index 1f4800cfcd6a..f13b63804c1a 100644 --- a/fs/resctrl/internal.h +++ b/fs/resctrl/internal.h @@ -232,7 +232,8 @@ struct rdtgroup { =20 #define RFTYPE_RES_MB BIT(9) =20 -#define RFTYPE_DEBUG BIT(10) +// RFTYPE_DEBUG available to architecture code in +//#define RFTYPE_DEBUG BIT(10) =20 #define RFTYPE_RES_PERF_PKG BIT(11) =20 @@ -251,34 +252,6 @@ extern struct list_head rdt_all_groups; =20 extern int max_name_width; =20 -/** - * struct rftype - describe each file in the resctrl file system - * @name: File name - * @mode: Access mode - * @kf_ops: File operations - * @flags: File specific RFTYPE_FLAGS_* flags - * @fflags: File specific RFTYPE_* flags - * @seq_show: Show content of the file - * @write: Write to the file - */ -struct rftype { - char *name; - umode_t mode; - const struct kernfs_ops *kf_ops; - unsigned long flags; - unsigned long fflags; - - int (*seq_show)(struct kernfs_open_file *of, - struct seq_file *sf, void *v); - /* - * write() is the generic write callback which maps directly to - * kernfs write operation and overrides all other operations. - * Maximum write size is determined by ->max_write_len. - */ - ssize_t (*write)(struct kernfs_open_file *of, - char *buf, size_t nbytes, loff_t off); -}; - /** * struct mbm_state - status for each MBM counter in each domain * @prev_bw_bytes: Previous bytes value read for bandwidth calculation diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index e212e46e0780..f09674c209f8 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -329,6 +329,37 @@ static const struct kernfs_ops rdtgroup_kf_single_ops = =3D { .seq_show =3D rdtgroup_seqfile_show, }; =20 +static int rdtgroup_seqfile_show_locked(struct seq_file *m, void *arg) +{ + struct kernfs_open_file *of =3D m->private; + struct rftype *rft =3D of->kn->priv; + + guard(mutex)(&rdtgroup_mutex); + + if (rft->seq_show) + return rft->seq_show(of, m, arg); + return 0; +} + +static ssize_t rdtgroup_file_write_locked(struct kernfs_open_file *of, cha= r *buf, + size_t nbytes, loff_t off) +{ + struct rftype *rft =3D of->kn->priv; + + guard(mutex)(&rdtgroup_mutex); + + if (rft->write) + return rft->write(of, buf, nbytes, off); + + return -EINVAL; +} + +static const struct kernfs_ops rdtgroup_kf_single_locked_ops =3D { + .atomic_write_len =3D PAGE_SIZE, + .write =3D rdtgroup_file_write_locked, + .seq_show =3D rdtgroup_seqfile_show_locked, +}; + static const struct kernfs_ops kf_mondata_ops =3D { .atomic_write_len =3D PAGE_SIZE, .seq_show =3D rdtgroup_mondata_show, @@ -2162,7 +2193,7 @@ int rdtgroup_kn_mode_restore(struct rdtgroup *r, cons= t char *name, return ret; } =20 -static int rdtgroup_mkdir_info_resdir(void *priv, char *name, +static int rdtgroup_mkdir_info_resdir(struct rdt_resource *r, void *priv, = char *name, unsigned long fflags) { struct kernfs_node *kn_subdir; @@ -2177,6 +2208,19 @@ static int rdtgroup_mkdir_info_resdir(void *priv, ch= ar *name, if (ret) return ret; =20 + if (r->info_file.name && + (!(r->info_file.flags & RFTYPE_DEBUG) || resctrl_debug)) { + r->info_file.mode =3D 0; + if (r->info_file.seq_show) + r->info_file.mode |=3D 0444; + if (r->info_file.write) + r->info_file.mode |=3D 0200; + r->info_file.kf_ops =3D &rdtgroup_kf_single_locked_ops; + ret =3D rdtgroup_add_file(kn_subdir, &r->info_file); + if (ret) + return ret; + } + ret =3D rdtgroup_add_files(kn_subdir, fflags); if (!ret) kernfs_activate(kn_subdir); @@ -2221,7 +2265,7 @@ static int rdtgroup_create_info_dir(struct kernfs_nod= e *parent_kn) list_for_each_entry(s, &resctrl_schema_all, list) { r =3D s->res; fflags =3D fflags_from_resource(r) | RFTYPE_CTRL_INFO; - ret =3D rdtgroup_mkdir_info_resdir(s, s->name, fflags); + ret =3D rdtgroup_mkdir_info_resdir(r, s, s->name, fflags); if (ret) goto out_destroy; } @@ -2229,7 +2273,7 @@ static int rdtgroup_create_info_dir(struct kernfs_nod= e *parent_kn) for_each_mon_capable_rdt_resource(r) { fflags =3D fflags_from_resource(r) | RFTYPE_MON_INFO; sprintf(name, "%s_MON", r->name); - ret =3D rdtgroup_mkdir_info_resdir(r, name, fflags); + ret =3D rdtgroup_mkdir_info_resdir(r, r, name, fflags); if (ret) goto out_destroy; } --=20 2.49.0 From nobody Sun Dec 14 19:24:21 2025 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 517A224679C for ; Wed, 21 May 2025 22:51:15 +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=1747867877; cv=none; b=TbDdmSEjZq6plAAXYTodZykwWU+p2K6mAqIh4I90ZqFFGNjoD/52HCZ1bbxSPT0yXei9FClpwCC1NWcb1A+/rH9MP+jr3e48Kyttx8DLHFkOz0wdKuf9/kxkw3Ir+4dWgikQ0R8BUExl7jYQzXX6ZLop0hzTRZgU+34WTq6axtU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747867877; c=relaxed/simple; bh=nTKGW0I+DoGgJM+8xAB2cEl0yFDD+Y66fzXvGw9DxBk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tb6T+POSilaExWP1l0xToWMyfUU3qW5HGg6qtasfmWaRfbNsVWH0gaem6jDNw1riWPr3htjDpNoY7MRq+FO/mqUjQUS2+Q1k0y8sYQooFT8unL4XA1PXxvdk2Lef4czPnx6YlW3CyYWi2zoT3Lx1ezdauI86FXXJzdbHg5tnfXs= 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=gIGAMQVl; 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="gIGAMQVl" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1747867875; x=1779403875; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=nTKGW0I+DoGgJM+8xAB2cEl0yFDD+Y66fzXvGw9DxBk=; b=gIGAMQVl4dbfcHP7IGuRgmKGBgPjc9IwCAOei1FWcDJ62/dyOhRfB7p4 6OHtQ290/bmjOR22m1J6uyoRlQ9rC83xycn+G5w+9TPNHY3m9USJ7DqKE p153sYXMX4zsmZcylytBJowLlV7gNJQVC78Uai47nU7n0QCHX4iFtUo9n bIa1FxEnkhdXQQLIsaPU1EditFHRaZrtcGRnStio35s61L616wugiS/80 zfzSy4Z3cuLlZuO+Cd6cEDOuELFwXzBodb5DOZ5V1kjO1e7TeEIAw7i88 0dMDby4EHsFuOPM7UTPADz5D3H//lgrscbwzfIUghaL1JasoBh/N+PHJO w==; X-CSE-ConnectionGUID: fNOY9KN6QBeDOk+FcyW1iQ== X-CSE-MsgGUID: 3A++0sT+QKe+BD/r4gBJCw== X-IronPort-AV: E=McAfee;i="6700,10204,11440"; a="53677839" X-IronPort-AV: E=Sophos;i="6.15,304,1739865600"; d="scan'208";a="53677839" 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:51:00 -0700 X-CSE-ConnectionGUID: sAqNBOaLS1yAwHJlCHn5Mg== X-CSE-MsgGUID: LqS3nE6ET5q2MpXEJN56uw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,304,1739865600"; d="scan'208";a="141352209" 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:59 -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 28/29] x86/resctrl: Add info/PERF_PKG_MON/status file Date: Wed, 21 May 2025 15:50:46 -0700 Message-ID: <20250521225049.132551-29-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" Each telemetry aggregator provides three status registers at the top end of MMIO space after all the per-RMID per-event counters: agg_data_loss_count: This counts the number of times that this aggregator failed to accumulate a counter value supplied by a CPU core. agg_data_loss_timestamp: This is a "timestamp" from a free running 25MHz uncore timer indicating when the most recent data loss occurred. last_update_timestamp: Another 25MHz timestamp indicating when the most recent counter update was successfully applied. When the resctrl file system is mounted with the "-o debug" option display the values of each of these status registers for each aggregator in each enabled event group. Signed-off-by: Tony Luck --- arch/x86/kernel/cpu/resctrl/intel_aet.c | 34 +++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/arch/x86/kernel/cpu/resctrl/intel_aet.c b/arch/x86/kernel/cpu/= resctrl/intel_aet.c index 1b41167ad976..459e42459178 100644 --- a/arch/x86/kernel/cpu/resctrl/intel_aet.c +++ b/arch/x86/kernel/cpu/resctrl/intel_aet.c @@ -16,6 +16,7 @@ #include #include #include +#include #include =20 /* Temporary - delete from final version */ @@ -282,6 +283,35 @@ static bool get_pmt_feature(enum pmt_feature_id featur= e) return false; } =20 +static void show_debug(struct seq_file *s, struct event_group *e, int pkg,= int instance) +{ + void __iomem *info =3D e->pkginfo[pkg]->addrs[instance] + e->mmio_size; + + /* Information registers are the last three qwords in MMIO space */ + seq_printf(s, "%s %d:%d agg_data_loss_count =3D %llu\n", e->name, pkg, in= stance, + readq(info - 24)); + seq_printf(s, "%s %d:%d agg_data_loss_timestamp =3D %llu\n", e->name, pkg= , instance, + readq(info - 16)); + seq_printf(s, "%s %d:%d last_update_timestamp =3D %llu\n", e->name, pkg, = instance, + readq(info - 8)); +} + +static int info_status(struct kernfs_open_file *of, struct seq_file *s, vo= id *v) +{ + int num_pkgs =3D topology_max_packages(); + struct event_group **eg; + + for (eg =3D &known_event_groups[0]; eg < &known_event_groups[NUM_KNOWN_GR= OUPS]; eg++) { + if (!(*eg)->pfg) + continue; + for (int i =3D 0; i < num_pkgs; i++) + for (int j =3D 0; j < (*eg)->pkginfo[i]->count; j++) + show_debug(s, *eg, i, j); + } + + return 0; +} + /* * Ask OOBMSM discovery driver for all the RMID based telemetry groups * that it supports. @@ -304,6 +334,10 @@ bool intel_aet_get_events(void) r->num_rmid =3D (*eg)->num_rmids; } =20 + r->info_file.name =3D "status"; + r->info_file.seq_show =3D info_status; + r->info_file.flags =3D RFTYPE_DEBUG; + return ret1 || ret2; } =20 --=20 2.49.0 From nobody Sun Dec 14 19:24:21 2025 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 ADC0B24887D for ; Wed, 21 May 2025 22:51:16 +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=1747867878; cv=none; b=Y1F5UGVZ/e5Ob13VZeRv3xYtrDhFH/GcACs8kUv1U5Z0beelGuOHubRrsGdlkSdLh3mPUWEyx4Ww5KMZUlbqVST+iV21OchtDsGjHdD7c5XGMZsVHEyBqhZbpUQ//GH3RGDKKsRCHSQHbxZM6MTTclAEiq8BetqcuXzzykEFxTA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747867878; c=relaxed/simple; bh=/krivHDJi4SFWsGi67ebg0mEW1Vx99a74/Iz9fin3WI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EVj5GkUZM6Y+1TezQyscfKLoJNu5omvttP6c7N6Mf+95/kBUvOBkt2Ryv3aooTw+goh0vBl3W/CeL6iujTK6ocQnS68ah8obQDhvvwfeOInjBYG2hA16s8eDpdEn+gzQrX8lbJWO381qrC9VPmPDoOpJN0WDiHheJoKGQ+Ae9+g= 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=fQwhQD11; 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="fQwhQD11" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1747867877; x=1779403877; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/krivHDJi4SFWsGi67ebg0mEW1Vx99a74/Iz9fin3WI=; b=fQwhQD111XKSJS4W1ieGRHlIw2U9F3TmYTluyKgqdUpF91CgG1pGvBdv csj2T+z+hh2MXYO8L3L3btIrbf218WweYrxnaQy5+GuqkpMx9uzY/c8Vp T3hMppCPZMIKrHomZ4eH0ih7MEVSMmL5z3IfE1e3PhpgzbWYce8M1OJ8l 75qvLKZVytA683H116kLWe7naqvhPt7l4F5jLEhzs4cJc5EQQMj6WpYmC gtVmI9giInMTR0ij9+bxl7I3Bwq2lywDxroLwXZr8ZJ/Ax18a1t2iriuF s/AmyUtX+bloHU4y7786DawfH7AK9q1u1kX0742A8OA6Kt18QCvj7Jcm4 w==; X-CSE-ConnectionGUID: G5zRwWKDSSy1ovYHS4qHMg== X-CSE-MsgGUID: CRvIYUfISoCRDWoA7FxrXQ== X-IronPort-AV: E=McAfee;i="6700,10204,11440"; a="53677840" X-IronPort-AV: E=Sophos;i="6.15,304,1739865600"; d="scan'208";a="53677840" 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:51:00 -0700 X-CSE-ConnectionGUID: tfRJrB6qQY6jUplilk01Uw== X-CSE-MsgGUID: W+qKfc4lQxCn8z6+DovZNA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,304,1739865600"; d="scan'208";a="141352212" 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:51:00 -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 29/29] x86/resctrl: Update Documentation for package events Date: Wed, 21 May 2025 15:50:47 -0700 Message-ID: <20250521225049.132551-30-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" Each "mon_data" directory is now divided between L3 events and package events. The "info/PERF_PKG_MON" directory contains parameters for perf events. Signed-off-by: Tony Luck --- Documentation/filesystems/resctrl.rst | 53 ++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 10 deletions(-) diff --git a/Documentation/filesystems/resctrl.rst b/Documentation/filesyst= ems/resctrl.rst index c7949dd44f2f..a452fd54b3ae 100644 --- a/Documentation/filesystems/resctrl.rst +++ b/Documentation/filesystems/resctrl.rst @@ -167,7 +167,7 @@ with respect to allocation: bandwidth percentages are directly applied to the threads running on the core =20 -If RDT monitoring is available there will be an "L3_MON" directory +If L3 monitoring is available there will be an "L3_MON" directory with the following files: =20 "num_rmids": @@ -261,6 +261,23 @@ with the following files: bytes) at which a previously used LLC_occupancy counter can be considered for re-use. =20 +If telemetry monitoring is available there will be an "PERF_PKG_MON" direc= tory +with the following files: + +"num_rmids": + The number of telemetry RMIDs supported. If this is different + from the number reported in the L3_MON directory the limit + on the number of "CTRL_MON" + "MON" directories is the + minimum of the values. + +"mon_features": + Lists the telemetry monitoring events that are enabled on this system. + +When the filesystem is mounted with the debug option each subdirectory +for a monitor resource of the "info" directory will contain a "status" +file. Resources may use this to supply debug information about the status +of the hardware implementing the resource. + Finally, in the top level of the "info" directory there is a file named "last_cmd_status". This is reset with every "command" issued via the file system (making new directories or writing to any of the @@ -366,15 +383,31 @@ When control is enabled all CTRL_MON groups will also= contain: When monitoring is enabled all MON groups will also contain: =20 "mon_data": - This contains a set of files organized by L3 domain and by - RDT event. E.g. on a system with two L3 domains there will - be subdirectories "mon_L3_00" and "mon_L3_01". Each of these - directories have one file per event (e.g. "llc_occupancy", - "mbm_total_bytes", and "mbm_local_bytes"). In a MON group these - files provide a read out of the current value of the event for - all tasks in the group. In CTRL_MON groups these files provide - the sum for all tasks in the CTRL_MON group and all tasks in - MON groups. Please see example section for more details on usage. + This contains a set of directories, one for each instance + of an L3 cache, or of a processor package. The L3 cache + directories are named "mon_L3_00", "mon_L3_01" etc. The + package directories "mon_PERF_PKG_00", "mon_PERF_PKG_01" etc. + + Within each directory there is one file per event. In + the L3 directories: "llc_occupancy", "mbm_total_bytes", + and "mbm_local_bytes". In the PERF_PKG directories: "core_energy", + "activity", etc. + + "core_energy" reports a floating point number for the energy + (in Joules) used by cores for each RMID. + + "activity" also reports a floating point value (in Farads). + This provides an estimate of work done independent of the + frequency that the cores used for execution. + + All other events report decimal integer values. + + In a MON group these files provide a read out of the current + value of the event for all tasks in the group. In CTRL_MON groups + these files provide the sum for all tasks in the CTRL_MON group + and all tasks in MON groups. Please see example section for more + details on usage. + On systems with Sub-NUMA Cluster (SNC) enabled there are extra directories for each node (located within the "mon_L3_XX" directory for the L3 cache they occupy). These are named "mon_sub_L3_YY" --=20 2.49.0