From nobody Wed Oct 8 14:53:57 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (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 BD11327464F for ; Thu, 26 Jun 2025 16:49:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750956593; cv=none; b=ko4TNc1pEwR2Lvfj5T3vElNYCE/9enrbyJYdI5BIRhDOe+ObjN3VxKrGpfFnRsdXX+66CerUpqd551u3BBQN5sdAfL2NfMfjNSGQNYvd1+PWQg2upe19C0/65QOXAxwffj2CAzW/HRNfv8EOCLWRPh6PNIHFVQ2iYSh2082Q7rY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750956593; c=relaxed/simple; bh=epe/xF3oUz+9xFQ4zl+EzdN7rVrGRMfLkdZEd5lTyUg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LDelZMGYgyjRmEZLU+Uyx1qwkT/yQHau6VG3UeAGolgGhrlh075rhnCeF4ZoHSzwsiEb6USiWQ68UGaQjC9FQD6uUBlUfioHsNjir2b1/hxJENUDUrqN8yBlGhLVaA0vg0T3Hq7lwvDzS7OaFc1+BAJkSe0xC4G5Dwen3yb+X1Y= 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=FUrD0pAG; arc=none smtp.client-ip=198.175.65.19 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="FUrD0pAG" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1750956592; x=1782492592; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=epe/xF3oUz+9xFQ4zl+EzdN7rVrGRMfLkdZEd5lTyUg=; b=FUrD0pAGnOnERcvhdkfDBQq5wVDOfdGkmdr6rOCySBjUhKpB3W77VaAD DteujqfKtfeAcjcUCxPH0eKml23FEmjYmCeYmaws1xpdAMOi/fxoaGe5b Gh9FXl1LXr5Ma0hE0cRez7LoXZc8aBdg3vvUiQDvN+KHLsfF5rs3TKGxU ELOWgrm9M9kH8kLWpblyJlpxQpuDUulWCsdTHz8Ph30mktJBN9DkIopYP 5LCrP1urpfHXXqUD4hIKbyoPxG316leRMUSLwvfULSE2TclfIaRAGwahn HVyW6WIg/LucVbb8q3+0jWa4e4OIsaqlUrhoFrgHK4gIVZDOWq/oScAGd Q==; X-CSE-ConnectionGUID: FOcsb8BiS7CMgy1byUYVgw== X-CSE-MsgGUID: W74pTkcfQQOypSQzOQaVRQ== X-IronPort-AV: E=McAfee;i="6800,10657,11476"; a="53136314" X-IronPort-AV: E=Sophos;i="6.16,268,1744095600"; d="scan'208";a="53136314" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2025 09:49:51 -0700 X-CSE-ConnectionGUID: Ppmoco95SjWwk4GAG11rlQ== X-CSE-MsgGUID: xdvk0WiUT3STgJITi1t0FA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,268,1744095600"; d="scan'208";a="153069137" Received: from agluck-desk3.sc.intel.com ([172.25.103.51]) by orviesa008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2025 09:49:50 -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 v6 01/30] x86,fs/resctrl: Consolidate monitor event descriptions Date: Thu, 26 Jun 2025 09:49:10 -0700 Message-ID: <20250626164941.106341-2-tony.luck@intel.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250626164941.106341-1-tony.luck@intel.com> References: <20250626164941.106341-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. Add resctrl_event_id::QOS_FIRST_EVENT for a lower bound on range checks for event ids and as the starting index to scan mon_event_all[]. Drop the code that builds evt_list and change the two places where the list is scanned to scan mon_event_all[] instead using a new helper macro for_each_mon_event(). Architecture code now informs file system code which events are available with resctrl_enable_mon_event(). Signed-off-by: Tony Luck Reviewed-by: Fenghua Yu --- include/linux/resctrl.h | 4 +- include/linux/resctrl_types.h | 12 ++++-- fs/resctrl/internal.h | 13 ++++-- arch/x86/kernel/cpu/resctrl/core.c | 12 ++++-- fs/resctrl/monitor.c | 63 +++++++++++++++--------------- fs/resctrl/rdtgroup.c | 11 +++--- 6 files changed, 66 insertions(+), 49 deletions(-) diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index 6fb4894b8cfd..2944042bd84c 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 eventid); + bool resctrl_arch_is_evt_configurable(enum resctrl_event_id evt); =20 /** diff --git a/include/linux/resctrl_types.h b/include/linux/resctrl_types.h index a25fb9c4070d..2dadbc54e4b3 100644 --- a/include/linux/resctrl_types.h +++ b/include/linux/resctrl_types.h @@ -34,11 +34,15 @@ /* Max event bits supported */ #define MAX_EVT_CONFIG_BITS GENMASK(6, 0) =20 -/* - * Event IDs, the values match those used to program IA32_QM_EVTSEL before - * reading IA32_QM_CTR on RDT systems. - */ +/* Event IDs */ enum resctrl_event_id { + /* Must match value of first event below */ + QOS_FIRST_EVENT =3D 0x01, + + /* + * These values match those used to program IA32_QM_EVTSEL before + * reading IA32_QM_CTR on RDT systems. + */ QOS_L3_OCCUP_EVENT_ID =3D 0x01, QOS_L3_MBM_TOTAL_EVENT_ID =3D 0x02, QOS_L3_MBM_LOCAL_EVENT_ID =3D 0x03, diff --git a/fs/resctrl/internal.h b/fs/resctrl/internal.h index 0a1eedba2b03..445a41060724 100644 --- a/fs/resctrl/internal.h +++ b/fs/resctrl/internal.h @@ -52,19 +52,26 @@ 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 - Properties 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]; + +#define for_each_mon_event(mevt) for (mevt =3D &mon_event_all[QOS_FIRST_EV= ENT]; \ + mevt < &mon_event_all[QOS_NUM_EVENTS]; mevt++) + /** * 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 187d527ef73b..7fcae25874fe 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -864,12 +864,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 f5637855c3ac..2313e48de55f 100644 --- a/fs/resctrl/monitor.c +++ b/fs/resctrl/monitor.c @@ -844,38 +844,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 eventid) { - INIT_LIST_HEAD(&r->evt_list); + if (WARN_ON_ONCE(eventid < QOS_FIRST_EVENT || eventid >=3D QOS_NUM_EVENTS= )) + return; + if (mon_event_all[eventid].enabled) { + pr_warn("Duplicate enable for event %d\n", eventid); + 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[eventid].enabled =3D true; } =20 /** @@ -902,15 +903,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 77d08229d855..b95501d4b5de 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -1152,7 +1152,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_each_mon_event(mevt) { + 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); @@ -3057,10 +3059,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_each_mon_event(mevt) { + 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 Wed Oct 8 14:53:57 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (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 3CB8628CF56 for ; Thu, 26 Jun 2025 16:49:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750956594; cv=none; b=Tq0yvAAq9RnBGKLHxQZ42A6VgIi8h3CDcpIE+FUVumj/uUOOf2KFEnxO67GBe0cFmxM4rPhDDu6I/Kt/tspx50nwSV8Ne1N8z2ITRFYhzbuwGzyIivUzLCUAUYsciSAZ/B97DIEWeW2n5/ALjykwm6tqtLyFZJuUYm8G6PzUW30= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750956594; c=relaxed/simple; bh=P1DyLdgTaGAz6LHD9gt+qemOzPfnstaKPpBzXKYNy5w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WzmrswclUk/aDrJJocXn5ZGoM6GezuzUuTAkIXn7wtigDpGmkqcQoHAD5IMCm6W2ZuCK1z6/+86fMHtKkvnXozBtUHowiI6db0IOkCToZaVX/mX/YKR7uVw/RivUBCZINeU9+U9NEFwz52K8ud+cijiXHWjiuy16kRUHHfGMPrI= 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=OLDTXhEu; arc=none smtp.client-ip=198.175.65.19 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="OLDTXhEu" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1750956594; x=1782492594; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=P1DyLdgTaGAz6LHD9gt+qemOzPfnstaKPpBzXKYNy5w=; b=OLDTXhEuPSdQkPKdTfHhMJ8L0hsySTKSFCdVDj/qS27j3YqEU462etFc XDow8uVm7v5wVibRKZMGGCG06AkXqnN19epxeo+kYac0vRyjgN1rhGOg6 y8I6umqDloj3hZVBr0Iw0kdsoWTDFNlsf+cenlnsE4Hbm5lSXIeiVigV8 R0tglcSy4Bqiy8cgT9Dny89fmR5kw1wH7CaoMXcpKGRo9SQjROjarW/89 rWx2WHqbhUITAd2cUF363nlL9fzREvpd7D7q4GYLjE7Y/83cz5lnv39Cp lTFhF1BKd1JHx1ZlHQqyoXFzFd8rLIfuXbndvaVYuMtTyJWEYTWE5VuUC g==; X-CSE-ConnectionGUID: 3DAzVqG3RJm1/Nu8/WxJNg== X-CSE-MsgGUID: SD6DhMpBSL603o6YtEL1dg== X-IronPort-AV: E=McAfee;i="6800,10657,11476"; a="53136322" X-IronPort-AV: E=Sophos;i="6.16,268,1744095600"; d="scan'208";a="53136322" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2025 09:49:52 -0700 X-CSE-ConnectionGUID: 4Pvg9qBVTdSde7ghk2I7VQ== X-CSE-MsgGUID: vSB76qR9SnyIwfl5f3VOfQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,268,1744095600"; d="scan'208";a="153069145" Received: from agluck-desk3.sc.intel.com ([172.25.103.51]) by orviesa008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2025 09:49:50 -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 v6 02/30] x86,fs/resctrl: Replace architecture event enabled checks Date: Thu, 26 Jun 2025 09:49:11 -0700 Message-ID: <20250626164941.106341-3-tony.luck@intel.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250626164941.106341-1-tony.luck@intel.com> References: <20250626164941.106341-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 Reviewed-by: Fenghua Yu Reviewed-by: Reinette Chatre --- 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 | 16 +++++++++++----- fs/resctrl/rdtgroup.c | 18 +++++++++--------- 7 files changed, 28 insertions(+), 35 deletions(-) diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index 2944042bd84c..40aba6b5d4f0 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 eventid); =20 +bool resctrl_is_mon_event_enabled(enum resctrl_event_id eventid); + 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 feb93b50e990..b1dd5d6b87db 100644 --- a/arch/x86/include/asm/resctrl.h +++ b/arch/x86/include/asm/resctrl.h @@ -84,21 +84,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 7fcae25874fe..1a319ce9328c 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -402,13 +402,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 c261558276cd..61d38517e2bf 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -207,11 +207,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 d98e0d2de09f..ad7ffc6acf13 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 2313e48de55f..9e988b2c1a22 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); @@ -637,10 +637,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 @@ -879,6 +879,12 @@ void resctrl_enable_mon_event(enum resctrl_event_id ev= entid) mon_event_all[eventid].enabled =3D true; } =20 +bool resctrl_is_mon_event_enabled(enum resctrl_event_id eventid) +{ + return eventid >=3D QOS_FIRST_EVENT && eventid < QOS_NUM_EVENTS && + mon_event_all[eventid].enabled; +} + /** * resctrl_mon_resource_init() - Initialise global monitoring structures. * @@ -914,9 +920,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 b95501d4b5de..a7eeb33501da 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; @@ -4051,7 +4051,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 @@ -4087,12 +4087,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) { @@ -4100,7 +4100,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) { @@ -4145,7 +4145,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 /* @@ -4220,7 +4220,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 Wed Oct 8 14:53:57 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (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 8DE6028FFEE for ; Thu, 26 Jun 2025 16:49:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750956595; cv=none; b=cw4+vfxNaKQVX9MnS9jCiqJdMAoHjIcRN531UMfK0sa0Meek/pjqiT/9xqDkTPV0BSNpBHJKrbfzZkZeLUH9v8i9KS+ImUIzERThibZiU5MmuQzRQqCGGQpVk/f1IZHrco83UvHbI9dLmzjQ0+WE3D55yd9AM9B1smEAsfoIWpk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750956595; c=relaxed/simple; bh=ohU9oFXgklw2CWCxEtCjAVewl1W1kGyl4PI2z+dhjBI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=R/3VKoe6uIGmc8i8I42O4tcF52SUrUx0XE76wEl96RsjXWjLcuvkZGtMHDECXiYsC2pPUpuEaN7CzDFhHPYv4jiuDy9lkJUZgl9EsGisaF8wlPXfx4XlmbgVJCF8m4cDgZBj94gOPQPhBYU6bx+P+EVfOjYxj+hSnumzQjbqTEY= 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=NK5+jewY; arc=none smtp.client-ip=198.175.65.19 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="NK5+jewY" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1750956594; x=1782492594; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ohU9oFXgklw2CWCxEtCjAVewl1W1kGyl4PI2z+dhjBI=; b=NK5+jewYKm4baJcJKAFJ99iiWE1AzQvGN/LBNIA/pH6hRS7JoPAhYhQv ZvJg8BMulpw3XzeAyJfDIINS84N0Q+k7XtPlOo67b/SlRWlvlg7Di1pTs rm1IoU/fI7qlku1kbc7ZDoJbzeJq9RipbsaA56SpsTewr7dnUd/pes7ro ZdTIqAk2uratQ5ONMG9+GGzImZ7UHwfUGXSTC+MjfMPGwVOkVYsNb5Y47 qFxvopNhzyWQ5Z/JCVR4fTs1wSRMrZUOmRClayXozZOGwL2njLzYMoluk Z/6EiCBY09GKN6raNIM9UznPOEA3FsYK5/jgqZtdGqr2k8SpYu8waAM/y w==; X-CSE-ConnectionGUID: U+l+bvetQCqfHNGVK2xbGA== X-CSE-MsgGUID: X8dijuYGQq6a0wi1dB0KBw== X-IronPort-AV: E=McAfee;i="6800,10657,11476"; a="53136330" X-IronPort-AV: E=Sophos;i="6.16,268,1744095600"; d="scan'208";a="53136330" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2025 09:49:52 -0700 X-CSE-ConnectionGUID: 8qfW+FaCS8mfBeQtkRkbbQ== X-CSE-MsgGUID: cI71nm9ORAO3SuPSntI/Fg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,268,1744095600"; d="scan'208";a="153069153" Received: from agluck-desk3.sc.intel.com ([172.25.103.51]) by orviesa008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2025 09:49:51 -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 v6 03/30] x86/resctrl: Remove 'rdt_mon_features' global variable Date: Thu, 26 Jun 2025 09:49:12 -0700 Message-ID: <20250626164941.106341-4-tony.luck@intel.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250626164941.106341-1-tony.luck@intel.com> References: <20250626164941.106341-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" rdt_mon_features is used as a bitmask of enabled monitor events. A monitor event's status is now maintained in mon_evt::enabled with all monitor events' mon_evt structures found in the filesystem's mon_event_all[] array. Remove the remaining uses of rdt_mon_features. Signed-off-by: Tony Luck Reviewed-by: Reinette Chatre --- 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 b1dd5d6b87db..575f8408a9e7 100644 --- a/arch/x86/include/asm/resctrl.h +++ b/arch/x86/include/asm/resctrl.h @@ -44,7 +44,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 1a319ce9328c..5d14f9a14eda 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -863,21 +863,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 61d38517e2bf..07f8ab097cbe 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -31,11 +31,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 Wed Oct 8 14:53:57 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (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 E0DF72E175E for ; Thu, 26 Jun 2025 16:49:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750956595; cv=none; b=mLDq1yWpsvRiv7g5mptTWqLwuhfWsOQKjQdlWAj9doVwib+tyz0fzHjQ8lXYD+TUoztXoZJlgiv/FQ7xLHMyaFtJ0NNFDYjjFT8NbpYd82Hp09Aj+vBBMd0gHoZukDpSIqQe/pUSBCp2HqQwjtvwFlKBpPuKe6vI8kwB760L2bE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750956595; c=relaxed/simple; bh=XeI2npbIvV8iA7UHgrv+qOnWzMjU0neWg+s+/zR8WJg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Xq389taL3kux2bfrGjAUJMgp4kM+4d+PQ6wcgiYK+rJhffdSY9y3fsRw3lVmW2wb2/TguLl27XRTpVXD0o1u1eYUanyJcVGuRrOnvbsIGcaTLYY7mcIVH1sF6HIyy1S/PMHfHnlMfphtVruG5+Hh/2ONfOWSZ+ILo3R9GzlHdjE= 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=CRxod2Dr; arc=none smtp.client-ip=198.175.65.19 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="CRxod2Dr" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1750956595; x=1782492595; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=XeI2npbIvV8iA7UHgrv+qOnWzMjU0neWg+s+/zR8WJg=; b=CRxod2DrZgavvNRqUls2gFNSLvxUzf1ZvxcjX4HDEYqRz9abBJMWXDzX 4/K7TRCTH+eaMJMcbikwMd6Eel7hhHKKVTQz39i0oNRqhvwZ+in0EtzZC 5qOsfDFtPloH6qCJI+AP1anLbjav7Axz9AODBIR+g+kzZXit1TUBN9KM+ 4A8t/Ekqs+czEoBuiYwwmBlOhsGO7XVELBh3bt/Co/46650tYHeU+Flpg Ga30TakZnQ8JBwrMF7z8wJ3RnotPSjWYKegHiei/3g+kXCWnJNDeyOj95 VPJAL+qlbukhjrJ29GmKWKVEduXpQZNZemu7SaTQZoV2jfjeKjeGHujFT g==; X-CSE-ConnectionGUID: c9zg3fYFSruVnrDH80kEZg== X-CSE-MsgGUID: Kf2QUHVzRMW+0kWyO9lniw== X-IronPort-AV: E=McAfee;i="6800,10657,11476"; a="53136338" X-IronPort-AV: E=Sophos;i="6.16,268,1744095600"; d="scan'208";a="53136338" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2025 09:49:52 -0700 X-CSE-ConnectionGUID: vk60hN/6Qhu8YC0bRv1+vg== X-CSE-MsgGUID: +qVpA9fEQOSRYFPPdCAIQg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,268,1744095600"; d="scan'208";a="153069159" Received: from agluck-desk3.sc.intel.com ([172.25.103.51]) by orviesa008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2025 09:49:51 -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 v6 04/30] x86,fs/resctrl: Prepare for more monitor events Date: Thu, 26 Jun 2025 09:49:13 -0700 Message-ID: <20250626164941.106341-5-tony.luck@intel.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250626164941.106341-1-tony.luck@intel.com> References: <20250626164941.106341-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_id() helper macro. Cleanup variable names in functions touched to consistently use "eventid" for those with type enum resctrl_event_id. Signed-off-by: Tony Luck Reviewed-by: Reinette Chatre --- include/linux/resctrl.h | 23 +++++++++--- include/linux/resctrl_types.h | 3 ++ arch/x86/kernel/cpu/resctrl/internal.h | 8 ++--- arch/x86/kernel/cpu/resctrl/core.c | 40 +++++++++++---------- arch/x86/kernel/cpu/resctrl/monitor.c | 36 +++++++++---------- fs/resctrl/monitor.c | 13 ++++--- fs/resctrl/rdtgroup.c | 50 +++++++++++++------------- 7 files changed, 96 insertions(+), 77 deletions(-) diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index 40aba6b5d4f0..478d7a935ca3 100644 --- a/include/linux/resctrl.h +++ b/include/linux/resctrl.h @@ -161,8 +161,9 @@ struct rdt_ctrl_domain { * @hdr: common header for different domain types * @ci_id: cache info id 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: Per-event pointer to the MBM event's saved state. + * An MBM event's state is an array of struct mbm_state + * indexed by RMID on x86 or combined CLOSID, RMID on Arm. * @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 +173,7 @@ struct rdt_mon_domain { struct rdt_domain_hdr hdr; unsigned int ci_id; 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 +376,21 @@ bool resctrl_is_mon_event_enabled(enum resctrl_event_i= d eventid); =20 bool resctrl_arch_is_evt_configurable(enum resctrl_event_id evt); =20 +static inline bool resctrl_is_mbm_event(enum resctrl_event_id eventid) +{ + return (eventid >=3D QOS_L3_MBM_TOTAL_EVENT_ID && + eventid <=3D QOS_L3_MBM_LOCAL_EVENT_ID); +} + +/* Iterate over all memory bandwidth events */ +#define for_each_mbm_event_id(eventid) \ + for (eventid =3D QOS_L3_MBM_TOTAL_EVENT_ID; \ + eventid <=3D QOS_L3_MBM_LOCAL_EVENT_ID; eventid++) + +/* Iterate over memory bandwidth arrays in domain structures */ +#define for_each_mbm_idx(idx) \ + for (idx =3D 0; idx < QOS_NUM_L3_MBM_EVENTS; idx++) + /** * 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 2dadbc54e4b3..d98351663c2c 100644 --- a/include/linux/resctrl_types.h +++ b/include/linux/resctrl_types.h @@ -51,4 +51,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..58dca892a5df 100644 --- a/arch/x86/kernel/cpu/resctrl/internal.h +++ b/arch/x86/kernel/cpu/resctrl/internal.h @@ -54,15 +54,15 @@ 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: Per-event pointer to the MBM event's saved state. + * An MBM event's state is an array of struct arch_mbm_state + * indexed by RMID on x86. * * 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 5d14f9a14eda..fbf019c1ff11 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -365,8 +365,10 @@ 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); + int idx; + + for_each_mbm_idx(idx) + kfree(hw_dom->arch_mbm_states[idx]); kfree(hw_dom); } =20 @@ -400,25 +402,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(*hw_dom->arch_mbm_states[0]); + enum resctrl_event_id eventid; + int idx; + + for_each_mbm_event_id(eventid) { + if (!resctrl_is_mon_event_enabled(eventid)) + continue; + idx =3D MBM_STATE_IDX(eventid); + 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: + for_each_mbm_idx(idx) { + 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 07f8ab097cbe..f01db2034d08 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -161,18 +161,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, @@ -201,14 +197,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 eventid; + int idx; + + for_each_mbm_event_id(eventid) { + if (!resctrl_is_mon_event_enabled(eventid)) + continue; + idx =3D MBM_STATE_IDX(eventid); + memset(hw_dom->arch_mbm_states[idx], 0, + sizeof(*hw_dom->arch_mbm_states[0]) * 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 9e988b2c1a22..dcc6c00eb362 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 *state; =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; - } + + state =3D d->mbm_states[MBM_STATE_IDX(evtid)]; + + return state ? &state[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 a7eeb33501da..77336d5e4915 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. @@ -4023,9 +4017,13 @@ static void rdtgroup_setup_default(void) =20 static void domain_destroy_mon_state(struct rdt_mon_domain *d) { + int idx; + bitmap_free(d->rmid_busy_llc); - kfree(d->mbm_total); - kfree(d->mbm_local); + for_each_mbm_idx(idx) { + kfree(d->mbm_states[idx]); + d->mbm_states[idx] =3D NULL; + } } =20 void resctrl_offline_ctrl_domain(struct rdt_resource *r, struct rdt_ctrl_d= omain *d) @@ -4085,32 +4083,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(*d->mbm_states[0]); + enum resctrl_event_id eventid; + 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_id(eventid) { + if (!resctrl_is_mon_event_enabled(eventid)) + continue; + idx =3D MBM_STATE_IDX(eventid); + 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); + for_each_mbm_idx(idx) { + 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 Wed Oct 8 14:53:57 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (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 15DE12EAB75 for ; Thu, 26 Jun 2025 16:49:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750956596; cv=none; b=kcCa+mQUMorjXOL8qdqL+djEEgqdHdf11Ls/ezO5xEhTFFj7M2+9vkpLbaDKFeKZGgpE2RF3l2XrnqoXFzCSfTZoltH4lAdFr6vaFy7Y2VgnCWHP1MjNegNAUgAD0XPr40QWoIpQWs3axF3MPmMgc74GaP8A5IK9jjOQMzPUuho= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750956596; c=relaxed/simple; bh=efY5A4hn1YAZyIj3uRHRsm5NdIHqw/pWvjOTIdIQwr0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FkLitgx10jEYWwCjlq3l4f7r1hp4SIdp57JsC7bUcYgOtkBoAIS97EiqhqAMRiQO8aV3N9KZWE9EqzlXDxvDSjbbBEaXYzFbJqf9AxGPB7U0//S36WIe/Ea+m3d+ACM5SBO3aw9tG/G3lUhcM2YaGtREDy2SeKDe1vbM6/XEtj8= 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=a/jxyMwr; arc=none smtp.client-ip=198.175.65.19 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="a/jxyMwr" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1750956596; x=1782492596; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=efY5A4hn1YAZyIj3uRHRsm5NdIHqw/pWvjOTIdIQwr0=; b=a/jxyMwroMFkwoksJDjtoe7dHtq6o5NsBcpgv9p0V98KlvO2OWIzsCsk 5HVZFdDYQYQKEgTjchsDnQN3m78pE45vyIKvzQg6ZeV5Q6oQKBva/O1iU O5IpwulH5jO+KxQk/mkkSMRU19Ja8FZ6fMsuqdd9Kl19vzA+RWn6m+H1T AAbQV1OlqdwZWFVoNobOMgONn0v+inUqoIRxFEfzPqDbEqAtAvRAwFrzD perqpJ9SGtZ+aJUxwqkydSW3V8SfwmP03o4KqeFqHj+6IB3M227S6xi0R eMOUmkAAtUF9TO1BH1JlDgb2X+ncuPc5Lqq6ksAMGLe1CNHkkjIfdhoQr Q==; X-CSE-ConnectionGUID: VygmUTTjSBixsUyJ/Oa7bA== X-CSE-MsgGUID: pV2K91MmR3qlYRghF3BXOg== X-IronPort-AV: E=McAfee;i="6800,10657,11476"; a="53136346" X-IronPort-AV: E=Sophos;i="6.16,268,1744095600"; d="scan'208";a="53136346" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2025 09:49:53 -0700 X-CSE-ConnectionGUID: jWMStVZTRquUH4aO6oWWPg== X-CSE-MsgGUID: c1/2gDItRMeAvoyGZAoxMQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,268,1744095600"; d="scan'208";a="153069167" Received: from agluck-desk3.sc.intel.com ([172.25.103.51]) by orviesa008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2025 09:49:52 -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 v6 05/30] x86,fs/resctrl: Improve domain type checking Date: Thu, 26 Jun 2025 09:49:14 -0700 Message-ID: <20250626164941.106341-6-tony.luck@intel.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250626164941.106341-1-tony.luck@intel.com> References: <20250626164941.106341-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. At this point all monitoring events are tied to the RDT_RESOURCE_L3 resource. So hard code the check in rdtgroup_mondata_show() to that resource id. 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 478d7a935ca3..dc7ccd60e8c2 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 fbf019c1ff11..420e4eb7c160 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -459,7 +459,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 @@ -476,6 +476,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); @@ -515,7 +516,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 @@ -530,6 +531,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; ci =3D get_cpu_cacheinfo_level(cpu, RESCTRL_L3_CACHE); if (!ci) { pr_warn_once("Can't find L3 cache for CPU:%d resource %s\n", cpu, r->nam= e); @@ -586,7 +588,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); @@ -632,7 +634,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 ad7ffc6acf13..cdb4bc8baa99 100644 --- a/fs/resctrl/ctrlmondata.c +++ b/fs/resctrl/ctrlmondata.c @@ -643,7 +643,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, RDT_RESOURC= E_L3)) { ret =3D -ENOENT; goto out; } --=20 2.49.0 From nobody Wed Oct 8 14:53:57 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (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 4375B2EA48F for ; Thu, 26 Jun 2025 16:49:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750956597; cv=none; b=IC0gr5VAwj/4tlfEMaQfU3nQs51JtcKihoncibGzJuhEVABRAw5+H6i0F+At2UCvesLwOmOs5aV0ygpJ2uLeGWvlOj7xqi47KTxXQsXBgcwcZumNQDVFH3CrCu9gOLa61rLh2+69tRjpsM+g9i4n6ukIrwOLgEfiEjaJR247CYs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750956597; c=relaxed/simple; bh=Zv1eHL7bD5PZfEzAa30P++8w0+X3h9FO+wtSQI3RpE4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZRbBW08YRqLJ2XZSeYZ5QGd77jWeOKomOuj1dbbHbDEhItFJHzVaS8U26pT4aQZ78P9m3BdqDawfg37n2Adxj3SffbabLPYqNAB2SWAQIGdNWHSg06/ZSJR/eZTDpzF3x/rllv+b/+c7zwSvRKKL6pR7uGMDuWBXC6LdRjDAVbs= 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=niNqdodf; arc=none smtp.client-ip=198.175.65.19 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="niNqdodf" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1750956596; x=1782492596; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Zv1eHL7bD5PZfEzAa30P++8w0+X3h9FO+wtSQI3RpE4=; b=niNqdodfxcPJlKKea9LOLswS3h/Vr7BdJAg6bCbvZQkv8rC+yiUNHcDa xybZING+I/pcjVST/B9exSPuL7FJ8DgEZhGIQbmthBVlVRFJvf8kJW2Dk yGNYRgiPJTSeLLQbcBR8G9E3hYuldqCvv8/2wEFl/V+LKkLkMKSjp3Sol 2lSxWinYzooi6LJARlJ+XaqZx6/UE0XMGL9tYKH/xsfPdJ0tI6q9rBFrF MqT7xKHecUKVaZf3eelu71AGR3oUKfE8rIhSJxuHZuM6IW+1wiLzCIE0Y FC0Ix9f10UlOxt3PykEqx8Du7I4/BohPg3v8NB+4c9zdYsW5K06gougk6 A==; X-CSE-ConnectionGUID: fLoR6P7fRG6M1Dw9DYKK/A== X-CSE-MsgGUID: cVW7knxVRQWA04Sm+nzlQg== X-IronPort-AV: E=McAfee;i="6800,10657,11476"; a="53136355" X-IronPort-AV: E=Sophos;i="6.16,268,1744095600"; d="scan'208";a="53136355" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2025 09:49:53 -0700 X-CSE-ConnectionGUID: SVCo2lWfQAaKIzc+qBRz+A== X-CSE-MsgGUID: YrHU+dhiRKeQ8jeCe9CP2g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,268,1744095600"; d="scan'208";a="153069177" Received: from agluck-desk3.sc.intel.com ([172.25.103.51]) by orviesa008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2025 09:49:52 -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 v6 06/30] x86/resctrl: Move L3 initialization out of domain_add_cpu_mon() Date: Thu, 26 Jun 2025 09:49:15 -0700 Message-ID: <20250626164941.106341-7-tony.luck@intel.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250626164941.106341-1-tony.luck@intel.com> References: <20250626164941.106341-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 420e4eb7c160..20b6f2bbf858 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -496,34 +496,13 @@ 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; struct cacheinfo *ci; 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; @@ -558,6 +537,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 Wed Oct 8 14:53:57 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (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 16AD12EBDFF for ; Thu, 26 Jun 2025 16:49:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750956597; cv=none; b=ELXrkGa4kKHLz0dlLHW5/RP/3PE9sik333/EoLVybtqeC10WZ8xAr3EuRSwVyQxec5BmT4ZAYSWj5Zp0f7UokDrXwayGhzWA6n8jE6FNqmj61sZj4gMvlrYlqsa1d0iJewIewgJ5PRkgRrtE9LJ7qdNB0CEXHNxKB0lDpq385Vk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750956597; c=relaxed/simple; bh=fpNYlYp4P970kfOQQ5H3EWQ5bRaaco6gyifMD5aw5Lo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ayXyT7Tgc/6WjfVyakEacirinrt1IFq9AywE7wuYWq8SsjHAaqv2Pp6ZWxgZGAs1y75Bki1PFcIijzAgvx85JKRx+7HDI5C8tzmNuwni7+ZNSdLO7xc4tHF2F0+hra7RaAswamnGS9MGkp7GZTHj+Ph8MWekGljEwW8fLAg2d1U= 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=Fl8g6w+g; arc=none smtp.client-ip=198.175.65.19 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="Fl8g6w+g" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1750956597; x=1782492597; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fpNYlYp4P970kfOQQ5H3EWQ5bRaaco6gyifMD5aw5Lo=; b=Fl8g6w+gw4agkmPj4cp1c4YVd1DqP7+aImwG7yO5UlaW3k/9j3vrg2Hq qb/07FasQDoI4IJNudopD/LhQeF7nYMguThyvSZGc2t1lJYvg6Es2MtT3 +msyI9PhL/7ukoiKcTNU0CAd68AnJk5CDZK/vyfeAccQxObGQdgsDFaDs EsqEkY0zAeTf0uOu+Mb8XG8AUpOsc3Jy7gGQKUf6pPAbiHcAPovxmljeI HkPg9D/RAhqaFEkbph3UDaF+7+oti+lua8DJ0m5OUN4JaF+YyA/xl37l+ NcquSGmpC4AVhdP/wBmha7ZJOBc5knHzO5UoOvsFPx+cajPrpaNOsirae g==; X-CSE-ConnectionGUID: /ilZ+c86QoeCaav1NcF+GA== X-CSE-MsgGUID: l561hvM1TXKyt/jUTb0uEw== X-IronPort-AV: E=McAfee;i="6800,10657,11476"; a="53136365" X-IronPort-AV: E=Sophos;i="6.16,268,1744095600"; d="scan'208";a="53136365" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2025 09:49:54 -0700 X-CSE-ConnectionGUID: UUja31bLRIy10xts4DlssA== X-CSE-MsgGUID: TI02uNfOTgSPmgv5DP7N3A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,268,1744095600"; d="scan'208";a="153069184" Received: from agluck-desk3.sc.intel.com ([172.25.103.51]) by orviesa008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2025 09:49:53 -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 v6 07/30] x86,fs/resctrl: Refactor domain_remove_cpu_mon() ready for new domain types Date: Thu, 26 Jun 2025 09:49:16 -0700 Message-ID: <20250626164941.106341-8-tony.luck@intel.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250626164941.106341-1-tony.luck@intel.com> References: <20250626164941.106341-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 20b6f2bbf858..4bf264b6a333 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -648,17 +648,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, &d->hdr.cpu_mask); - if (cpumask_empty(&d->hdr.cpu_mask)) { + if (!cpumask_empty(&d->hdr.cpu_mask)) + return; + + 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(); 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 77336d5e4915..05438e15e2ca 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -4047,6 +4047,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 out_unlock; + 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)) { @@ -4063,7 +4066,7 @@ void resctrl_offline_mon_domain(struct rdt_resource *= r, struct rdt_mon_domain *d } =20 domain_destroy_mon_state(d); - +out_unlock: mutex_unlock(&rdtgroup_mutex); } =20 --=20 2.49.0 From nobody Wed Oct 8 14:53:57 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (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 EF13D2ECEB9 for ; Thu, 26 Jun 2025 16:49:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750956598; cv=none; b=qsm6TY3ijF809nVTxSSl/V+9+eKehYdRZTtHAdsapufT1j6olFwMIJtqX0DExOT9ml1HpTv4pY8JF2WMx4+09iQ5ayzgi/MewKaCQ/qGIL67B/EhiViaPRl0mAH4BDYvfWYY6+ylTQnf9ygqk1j/SQXnEssaQ8OkQM4GIp+4gWA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750956598; c=relaxed/simple; bh=Sz59o1KY9HW32CpIGuJWeV6g2Rwxdp5XLjIExlNvaF4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TUrGsb5VX6nws2F0+hW0mpZ2wrEyqmbSGN3XF1TsxaJZAxoWa8J8awpJTa5ea/HZPpU9biix8WyFRhYnRm4zX/mHMJUtaydVXgSfHtdJjtEP5X2RhcBTT8Uwr9sg5xSZolwCl8AYNQc2ALFInioNLAyQe0GSSYVrZyU/ifuuhQ0= 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=izC835jG; arc=none smtp.client-ip=198.175.65.19 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="izC835jG" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1750956598; x=1782492598; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Sz59o1KY9HW32CpIGuJWeV6g2Rwxdp5XLjIExlNvaF4=; b=izC835jGBSwjM6BPn74SMMTW/i83+MTSQouLe5D8CpvrfcLJEz2iYbP/ CYoKqCVU1q5JuefrFe0uvzs14/jhLSA8/qtWsnJ46jBAcaIfiN65tc5WC ldlJE8QXQ0V+Hx4CNztgozThqTcIF8TB3LS9wu72dg+wi6GJ3EZbNDByh oJ5LJiEqKEQ3XTLHKGAVlsD8w7UjN34qzvet1c0yjRVQzuTzxS34XNHPb Xvy8qF33nHdvE4OqphZ38nPz3k1AbAULU421gePyF024vSzkXe1PiJP7F 7bULdKH4nq/oVoLHMi18+XsCnGkZnugY6w+GSlrWI7mBSV2kvMJ65/fOf g==; X-CSE-ConnectionGUID: qnVbnZLTSva15PxVptuniA== X-CSE-MsgGUID: FhVLClajSXCJU7rnnjYyuw== X-IronPort-AV: E=McAfee;i="6800,10657,11476"; a="53136373" X-IronPort-AV: E=Sophos;i="6.16,268,1744095600"; d="scan'208";a="53136373" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2025 09:49:54 -0700 X-CSE-ConnectionGUID: mFVPZ2+DQXecSM+f69O0yg== X-CSE-MsgGUID: bZKfy6nFSFC6iGeGkdDzmQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,268,1744095600"; d="scan'208";a="153069193" Received: from agluck-desk3.sc.intel.com ([172.25.103.51]) by orviesa008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2025 09:49:53 -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 v6 08/30] x86/resctrl: Clean up domain_remove_cpu_ctrl() Date: Thu, 26 Jun 2025 09:49:17 -0700 Message-ID: <20250626164941.106341-9-tony.luck@intel.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250626164941.106341-1-tony.luck@intel.com> References: <20250626164941.106341-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" For symmetry with domain_remove_cpu_mon() refactor to take an early return when removing a CPU does not empty the domain. Signed-off-by: Tony Luck --- arch/x86/kernel/cpu/resctrl/core.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resct= rl/core.c index 4bf264b6a333..2075c98aa4e7 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -602,25 +602,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(&d->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(); + resctrl_offline_ctrl_domain(r, d); + list_del_rcu(&d->hdr.list); + synchronize_rcu(); =20 - /* - * 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); - - 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) --=20 2.49.0 From nobody Wed Oct 8 14:53:57 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (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 3A6AD2ECE84 for ; Thu, 26 Jun 2025 16:49:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750956600; cv=none; b=NMsaf+N01rzNEf0lGpoA9lcQ6fnvIqAe+uAFJtEKUurKQlIvqLWIm50jsdOtSXPP4d/yGG9Ib0yV0XmTmVDSJBv/6sj1npmUjQsbuMnU1om+gY2vGJ7C75jwm3+a8LifFi/YM1HKoavv69jlzlW9VtvFqkuf2BHBa/rfxN3ktiU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750956600; c=relaxed/simple; bh=XG4aift2WzNLhx9e1E/0B82zYligoCRxdA/IZqyRDxA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EbHOS3ur+MWWayktiRKOH/GYJj6ZExe+RYo2CPHAMdRgQxj3zXimJOJ7C5Vv/B03eu9yuqCsZRDDvv9dn66WQN96KBoSY+7WPgjgedZxC4LKac0Q/UInAa3ljOCszaWH9CmYk9rDxhLyWjMds8l/Sxlr2af1FNopjGuzXYV/E6o= 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=oE7tp2Dz; arc=none smtp.client-ip=198.175.65.19 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="oE7tp2Dz" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1750956598; x=1782492598; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=XG4aift2WzNLhx9e1E/0B82zYligoCRxdA/IZqyRDxA=; b=oE7tp2Dzji2fmp7AEVtVHUURJvetDBvP1UdOqMOZ7N3yktrHDTk/qoBN RlgT5UPqQ2BwdiYf8Qvd8NB0RL5Ats4fRCwBp9NjqgbHIQAcw8SbsuVcr QyBREtduZJ1y4UhfZ37sAU6uZk3OaHk7cAse1uw2I520/lQpI5GONpl4t ts5X2O5nCd+sWtRyskV0I9FlBzUDRfNRL9adFIHna6LWTQmAXD3Ua16ok oTOLBI/iDwfV7Bbeb4I02TPGezZBWjkZfZxEU4p1OKY91TIylBB5aVMzP CnvtOffMMgE8F5J5/c9yvPSa6MmIj+3WH5fS5aZm/pD4oW0DLKRsGOTyq g==; X-CSE-ConnectionGUID: ElBleRWHQOSygUnnETt4Hw== X-CSE-MsgGUID: rFGb1XSDQYCyk6TEbGvHNw== X-IronPort-AV: E=McAfee;i="6800,10657,11476"; a="53136383" X-IronPort-AV: E=Sophos;i="6.16,268,1744095600"; d="scan'208";a="53136383" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2025 09:49:55 -0700 X-CSE-ConnectionGUID: 2Qzw49+XQyexWE+7C7qgsQ== X-CSE-MsgGUID: m+GoeIjFRa29SvSFugpL4g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,268,1744095600"; d="scan'208";a="153069200" Received: from agluck-desk3.sc.intel.com ([172.25.103.51]) by orviesa008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2025 09:49:54 -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 v6 09/30] x86,fs/resctrl: Use struct rdt_domain_hdr instead of struct rdt_mon_domain Date: Thu, 26 Jun 2025 09:49:18 -0700 Message-ID: <20250626164941.106341-10-tony.luck@intel.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250626164941.106341-1-tony.luck@intel.com> References: <20250626164941.106341-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. Change calling sequence for domain addition and deletion. Also for reading events. This includes the smp_call*() IPI where the rmid_read now holds a pointer to struct rdt_domain_hdr. The mon_data structure is unchanged, but documentation is updated to not that mon_data::sum is only used for RDT_RESOURCE_L3. Signed-off-by: Tony Luck --- include/linux/resctrl.h | 8 +- fs/resctrl/internal.h | 14 ++-- arch/x86/kernel/cpu/resctrl/core.c | 4 +- arch/x86/kernel/cpu/resctrl/monitor.c | 18 ++++- fs/resctrl/ctrlmondata.c | 16 ++-- fs/resctrl/monitor.c | 31 +++++--- fs/resctrl/rdtgroup.c | 103 ++++++++++++++++++-------- 7 files changed, 130 insertions(+), 64 deletions(-) diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index dc7ccd60e8c2..b332466312e1 100644 --- a/include/linux/resctrl.h +++ b/include/linux/resctrl.h @@ -452,9 +452,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 @@ -462,7 +462,7 @@ void resctrl_offline_cpu(unsigned int cpu); * resctrl_arch_rmid_read() - Read the eventid counter corresponding to rm= id * for this resource and domain. * @r: resource that the counter should be read from. - * @d: domain that the counter should be read from. + * @hdr: Header of domain that the counter should be read from. * @closid: closid that matches the rmid. Depending on the architecture, = the * counter may match traffic of both @closid and @rmid, or @rmid * only. @@ -483,7 +483,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_domain_hdr *= hdr, u32 closid, u32 rmid, enum resctrl_event_id eventid, u64 *val, void *arch_mon_ctx); =20 diff --git a/fs/resctrl/internal.h b/fs/resctrl/internal.h index 445a41060724..ce3d24c512e3 100644 --- a/fs/resctrl/internal.h +++ b/fs/resctrl/internal.h @@ -77,8 +77,8 @@ extern struct mon_evt mon_event_all[QOS_NUM_EVENTS]; * @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. - * @sum: Set when event must be summed across multiple - * domains. + * @sum: Set for RDT_RESOURCE_L3 when event must be summed + * across multiple domains. * @domid: When @sum is zero this is the domain to which * the event file belongs. When @sum is one this * is the id of the L3 cache that all domains to be @@ -101,22 +101,22 @@ struct mon_data { * resource group then its event count is summed with the count from all * its child resource groups. * @r: Resource describing the properties of the event being read. - * @d: Domain that the counter should be read from. If NULL then sum all + * @hdr: Header of 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. * @first: Initialize MBM counter when true. - * @ci_id: Cacheinfo id for L3. Only set when @d is NULL. Used when summin= g domains. + * @ci_id: Cacheinfo id for L3. Only set when @hdr is NULL. Used when summ= ing domains. * @err: Error encountered when reading counter. * @val: Returned value of event counter. If @rgrp is a parent resource = group, * @val includes the sum of event counts from its child resource groups. - * If @d is NULL, @val includes the sum of all domains in @r sharing @c= i.id, + * If @hdr is NULL, @val includes the sum of all domains in @r sharing = @ci.id, * (summed across child resource groups if @rgrp is a parent resource g= roup). * @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; + struct rdt_domain_hdr *hdr; enum resctrl_event_id evtid; bool first; unsigned int ci_id; @@ -352,7 +352,7 @@ 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_domain_hdr *hdr, struct rdtgroup *rdtgrp, cpumask_t *cpumask, int evtid, int first); =20 int resctrl_mon_resource_init(void); diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resct= rl/core.c index 2075c98aa4e7..1fecb6425b9e 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -529,7 +529,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(); @@ -655,7 +655,7 @@ 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); + resctrl_offline_mon_domain(r, hdr); list_del_rcu(&d->hdr.list); synchronize_rcu(); mon_domain_free(hw_dom); diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/re= sctrl/monitor.c index f01db2034d08..b31794c5dcd4 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -217,20 +217,30 @@ 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_domain_hdr *= hdr, 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_resource *hw_res =3D resctrl_to_arch_res(r); - int cpu =3D cpumask_any(&d->hdr.cpu_mask); + int cpu =3D cpumask_any(&hdr->cpu_mask); + struct rdt_hw_mon_domain *hw_dom; + struct rdt_hw_resource *hw_res; struct arch_mbm_state *am; + struct rdt_mon_domain *d; u64 msr_val, chunks; u32 prmid; int ret; =20 resctrl_arch_rmid_read_context_check(); =20 + if (r->rid !=3D RDT_RESOURCE_L3) + return -EINVAL; + + if (!domain_header_is_valid(hdr, RESCTRL_MON_DOMAIN, RDT_RESOURCE_L3)) + return -EINVAL; + + d =3D container_of(hdr, struct rdt_mon_domain, hdr); + hw_dom =3D resctrl_to_arch_mon_dom(d); + hw_res =3D resctrl_to_arch_res(r); prmid =3D logical_rmid_to_physical_rmid(cpu, rmid); ret =3D __rmid_read_phys(prmid, eventid, &msr_val); if (ret) diff --git a/fs/resctrl/ctrlmondata.c b/fs/resctrl/ctrlmondata.c index cdb4bc8baa99..1c1c0e7bbc11 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_domain_hdr *hdr, struct rdtgroup *rdtgrp, cpumask_t *cpumask, int evtid, int first) { int cpu; @@ -561,7 +561,7 @@ void mon_event_read(struct rmid_read *rr, struct rdt_re= source *r, rr->rgrp =3D rdtgrp; rr->evtid =3D evtid; rr->r =3D r; - rr->d =3D d; + rr->hdr =3D hdr; rr->first =3D first; rr->arch_mon_ctx =3D resctrl_arch_mon_ctx_alloc(r, evtid); if (IS_ERR(rr->arch_mon_ctx)) { @@ -592,7 +592,6 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg) enum resctrl_event_id evtid; struct rdt_domain_hdr *hdr; struct rmid_read rr =3D {0}; - struct rdt_mon_domain *d; struct rdtgroup *rdtgrp; int domid, cpu, ret =3D 0; struct rdt_resource *r; @@ -617,6 +616,12 @@ int rdtgroup_mondata_show(struct seq_file *m, void *ar= g) r =3D resctrl_arch_get_resource(resid); =20 if (md->sum) { + struct rdt_mon_domain *d; + + if (WARN_ON_ONCE(resid !=3D RDT_RESOURCE_L3)) { + ret =3D -EIO; + goto out; + } /* * This file requires summing across all domains that share * the L3 cache id that was provided in the "domid" field of the @@ -643,12 +648,11 @@ int rdtgroup_mondata_show(struct seq_file *m, void *a= rg) * the resource to find the domain with "domid". */ hdr =3D resctrl_find_domain(&r->mon_domains, domid, NULL); - if (!hdr || !domain_header_is_valid(hdr, RESCTRL_MON_DOMAIN, RDT_RESOURC= E_L3)) { + if (!hdr || !domain_header_is_valid(hdr, RESCTRL_MON_DOMAIN, resid)) { ret =3D -ENOENT; goto out; } - d =3D container_of(hdr, struct rdt_mon_domain, hdr); - mon_event_read(&rr, r, d, rdtgrp, &d->hdr.cpu_mask, evtid, false); + mon_event_read(&rr, r, hdr, rdtgrp, &hdr->cpu_mask, evtid, false); } =20 checkresult: diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c index dcc6c00eb362..85fe88b965fa 100644 --- a/fs/resctrl/monitor.c +++ b/fs/resctrl/monitor.c @@ -159,7 +159,7 @@ void __check_limbo(struct rdt_mon_domain *d, bool force= _free) break; =20 entry =3D __rmid_entry(idx); - if (resctrl_arch_rmid_read(r, d, entry->closid, entry->rmid, + if (resctrl_arch_rmid_read(r, &d->hdr, entry->closid, entry->rmid, QOS_L3_OCCUP_EVENT_ID, &val, arch_mon_ctx)) { rmid_dirty =3D true; @@ -365,19 +365,23 @@ static int __mon_event_count(u32 closid, u32 rmid, st= ruct rmid_read *rr) int err, ret; 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); + if (rr->r->rid =3D=3D RDT_RESOURCE_L3 && rr->first) { + if (WARN_ON_ONCE(!domain_header_is_valid(rr->hdr, RESCTRL_MON_DOMAIN, + RDT_RESOURCE_L3))) + return -EINVAL; + d =3D container_of(rr->hdr, struct rdt_mon_domain, hdr); + resctrl_arch_reset_rmid(rr->r, d, closid, rmid, rr->evtid); + m =3D get_mbm_state(d, closid, rmid, rr->evtid); if (m) memset(m, 0, sizeof(struct mbm_state)); return 0; } =20 - if (rr->d) { + if (rr->hdr) { /* Reading a single domain, must be on a CPU in that domain. */ - if (!cpumask_test_cpu(cpu, &rr->d->hdr.cpu_mask)) + if (!cpumask_test_cpu(cpu, &rr->hdr->cpu_mask)) return -EINVAL; - rr->err =3D resctrl_arch_rmid_read(rr->r, rr->d, closid, rmid, + rr->err =3D resctrl_arch_rmid_read(rr->r, rr->hdr, closid, rmid, rr->evtid, &tval, rr->arch_mon_ctx); if (rr->err) return rr->err; @@ -387,6 +391,9 @@ static int __mon_event_count(u32 closid, u32 rmid, stru= ct rmid_read *rr) return 0; } =20 + if (WARN_ON_ONCE(rr->r->rid !=3D RDT_RESOURCE_L3)) + return -EINVAL; + /* Summing domains that share a cache, must be on a CPU for that cache. */ ci =3D get_cpu_cacheinfo_level(cpu, RESCTRL_L3_CACHE); if (!ci || ci->id !=3D rr->ci_id) @@ -403,7 +410,7 @@ static int __mon_event_count(u32 closid, u32 rmid, stru= ct rmid_read *rr) list_for_each_entry(d, &rr->r->mon_domains, hdr.list) { if (d->ci_id !=3D rr->ci_id) continue; - err =3D resctrl_arch_rmid_read(rr->r, d, closid, rmid, + err =3D resctrl_arch_rmid_read(rr->r, &d->hdr, closid, rmid, rr->evtid, &tval, rr->arch_mon_ctx); if (!err) { rr->val +=3D tval; @@ -432,9 +439,13 @@ static int __mon_event_count(u32 closid, u32 rmid, str= uct rmid_read *rr) static void mbm_bw_count(u32 closid, u32 rmid, struct rmid_read *rr) { u64 cur_bw, bytes, cur_bytes; + struct rdt_mon_domain *d; struct mbm_state *m; =20 - m =3D get_mbm_state(rr->d, closid, rmid, rr->evtid); + if (WARN_ON_ONCE(domain_header_is_valid(rr->hdr, RESCTRL_MON_DOMAIN, RDT_= RESOURCE_L3))) + return; + d =3D container_of(rr->hdr, struct rdt_mon_domain, hdr); + m =3D get_mbm_state(d, closid, rmid, rr->evtid); if (WARN_ON_ONCE(!m)) return; =20 @@ -608,7 +619,7 @@ static void mbm_update_one_event(struct rdt_resource *r= , struct rdt_mon_domain * struct rmid_read rr =3D {0}; =20 rr.r =3D r; - rr.d =3D d; + rr.hdr =3D &d->hdr; rr.evtid =3D evtid; rr.arch_mon_ctx =3D resctrl_arch_mon_ctx_alloc(rr.r, rr.evtid); if (IS_ERR(rr.arch_mon_ctx)) { diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index 05438e15e2ca..3828480e0426 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -2887,7 +2887,8 @@ static void rmdir_all_sub(void) * @rid: The resource id for the event file being created. * @domid: The domain id for the event file being created. * @mevt: The type of event file being created. - * @do_sum: Whether SNC summing monitors are being created. + * @do_sum: Whether SNC summing monitors are being created. Only set + * when @rid =3D=3D RDT_RESOURCE_L3. */ static struct mon_data *mon_get_kn_priv(enum resctrl_res_level rid, int do= mid, struct mon_evt *mevt, @@ -2897,6 +2898,9 @@ static struct mon_data *mon_get_kn_priv(enum resctrl_= res_level rid, int domid, =20 lockdep_assert_held(&rdtgroup_mutex); =20 + if (WARN_ON_ONCE(do_sum && rid !=3D RDT_RESOURCE_L3)) + return NULL; + 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) @@ -3024,17 +3028,27 @@ 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; + int domid =3D hdr->id; char subname[32]; - bool snc_mode; 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 (r->rid =3D=3D RDT_RESOURCE_L3) { + struct rdt_mon_domain *d; + + if (!domain_header_is_valid(hdr, RESCTRL_MON_DOMAIN, RDT_RESOURCE_L3)) + return; + d =3D container_of(hdr, struct rdt_mon_domain, hdr); + + /* SNC mode? */ + if (r->mon_scope =3D=3D RESCTRL_L3_NODE) { + domid =3D d->ci_id; + sprintf(subname, "mon_sub_%s_%02d", r->name, d->hdr.id); + } + } + sprintf(name, "mon_%s_%02d", r->name, domid); =20 list_for_each_entry(prgrp, &rdt_all_groups, rdtgroup_list) { mon_rmdir_one_subdir(prgrp->mon.mon_data_kn, name, subname); @@ -3044,19 +3058,18 @@ 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) + int domid, bool do_sum) { struct rmid_read rr =3D {0}; struct mon_data *priv; struct mon_evt *mevt; - int ret, domid; + int ret; =20 for_each_mon_event(mevt) { 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)) return -EINVAL; @@ -3065,26 +3078,38 @@ 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, hdr, 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; + int domid =3D hdr->id; + bool snc_mode =3D 0; char name[32]; - bool snc_mode; int ret =3D 0; =20 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 (r->rid =3D=3D RDT_RESOURCE_L3) { + if (!domain_header_is_valid(hdr, RESCTRL_MON_DOMAIN, RDT_RESOURCE_L3)) + return -EINVAL; + snc_mode =3D r->mon_scope =3D=3D RESCTRL_L3_NODE; + if (snc_mode) { + struct rdt_mon_domain *d; + + d =3D container_of(hdr, struct rdt_mon_domain, hdr); + domid =3D d->ci_id; + } + } + sprintf(name, "mon_%s_%02d", r->name, domid); + kn =3D kernfs_find_and_get(parent_kn, name); if (kn) { /* @@ -3100,13 +3125,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, domid, 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; @@ -3117,7 +3142,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, hdr->id, false); if (ret) goto out_destroy; } @@ -3135,7 +3160,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; @@ -3143,12 +3168,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); } } } @@ -3157,14 +3182,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; } @@ -4036,8 +4061,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 /* @@ -4045,11 +4072,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 out_unlock; =20 + if (!domain_header_is_valid(hdr, RESCTRL_MON_DOMAIN, RDT_RESOURCE_L3)) + goto out_unlock; + + 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)) { @@ -4132,12 +4163,20 @@ 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 (r->rid !=3D RDT_RESOURCE_L3) + goto mkdir; + + 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_mon_state(r, d); if (err) goto out_unlock; @@ -4151,6 +4190,8 @@ int resctrl_online_mon_domain(struct rdt_resource *r,= struct rdt_mon_domain *d) if (resctrl_is_mon_event_enabled(QOS_L3_OCCUP_EVENT_ID)) INIT_DELAYED_WORK(&d->cqm_limbo, cqm_handle_limbo); =20 +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 @@ -4158,7 +4199,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 Wed Oct 8 14:53:57 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (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 DFF462ED177 for ; Thu, 26 Jun 2025 16:49:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750956600; cv=none; b=Lx/P7iYpO3jwAXUdu0W/iflZow39bUn/7df5chxWgQV85Kt7Ubtbu4vqzqX9CLZ8kIGS3PenPLe91Rccnd6EUOerozaDRqlRPOqZb32YgfXo16Ix+umhNRVim4aC5sSIZ9B77eQn+aMIf1G0vNPy4/rllasbXv/TwehhPkkC8Eg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750956600; c=relaxed/simple; bh=jF1vd7HutLmvyoewoQ/wGbzA19euoDHykwQ1m7uB3+U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iq+4XGWiAR60OzijYGa3NBwuXcwBY0xdy2c0okWft+7vlpMpOkCKW5KjysDywPF91mVdCvLl3j/wOBIQcdpCi1HjfMsZlfSEMpOEH9PzODTwE+WncKPCKVURSQtR6yjOUVGJQBUXMyLQwNICWMsC+CSBNmBuJLKvygd5HYYenjc= 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=irx0WLhY; arc=none smtp.client-ip=198.175.65.19 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="irx0WLhY" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1750956599; x=1782492599; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=jF1vd7HutLmvyoewoQ/wGbzA19euoDHykwQ1m7uB3+U=; b=irx0WLhYSRd90KmfXfUJGXYrLdRvpIGNclO2Tw5InugeF8YzeZmtBhHQ B+XLy+16wwu9f2nYVntugrQdmilctVJQffYxE6L1Pc81/jGXSRToOVCYt n6NM5uQT8g8AcBBi8iOCrg+cfXhgQMe01e0OWPLffZxerMolYc7YjQprL iv7ziQFj7710Ol7tz7RqedBKGsNt+RdPMmCsS8l/osztXh3pDJ0O7TqsJ 6vNVgeqYvQKJJTPeDlOPh0TlIQoUOsV2uPAIr6die2rkvD1ERAm47e1Tj JSupzEIItBBmcGJYJTveDVCgdH6arD9vvs60mBzVhsNV48YAWwNOF49Md w==; X-CSE-ConnectionGUID: 68zzC1zDQX+8H9zWwR+BYQ== X-CSE-MsgGUID: +jGY+AOtQfybMXPkbm8cvg== X-IronPort-AV: E=McAfee;i="6800,10657,11476"; a="53136391" X-IronPort-AV: E=Sophos;i="6.16,268,1744095600"; d="scan'208";a="53136391" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2025 09:49:55 -0700 X-CSE-ConnectionGUID: i2gECFvVSiKPpJ5tK2Vj2Q== X-CSE-MsgGUID: sMLAfwS3SCeyZ4A7truUVw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,268,1744095600"; d="scan'208";a="153069207" Received: from agluck-desk3.sc.intel.com ([172.25.103.51]) by orviesa008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2025 09:49:54 -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 v6 10/30] x86,fs/resctrl: Rename struct rdt_mon_domain and rdt_hw_mon_domain Date: Thu, 26 Jun 2025 09:49:19 -0700 Message-ID: <20250626164941.106341-11-tony.luck@intel.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250626164941.106341-1-tony.luck@intel.com> References: <20250626164941.106341-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 | 16 ++++++------ arch/x86/kernel/cpu/resctrl/internal.h | 12 ++++----- fs/resctrl/internal.h | 8 +++--- arch/x86/kernel/cpu/resctrl/core.c | 14 +++++----- arch/x86/kernel/cpu/resctrl/monitor.c | 18 ++++++------- fs/resctrl/ctrlmondata.c | 2 +- fs/resctrl/monitor.c | 34 ++++++++++++------------ fs/resctrl/rdtgroup.c | 36 +++++++++++++------------- 8 files changed, 70 insertions(+), 70 deletions(-) diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index b332466312e1..01740acebcd1 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 a resctrl monitor reso= urce * @hdr: common header for different domain types * @ci_id: cache info id for this domain * @rmid_busy_llc: bitmap of which limbo RMIDs are above threshold @@ -178,7 +178,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; unsigned int ci_id; unsigned long *rmid_busy_llc; @@ -334,10 +334,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 /** @@ -530,7 +530,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 @@ -543,7 +543,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 58dca892a5df..224b71730cc3 100644 --- a/arch/x86/kernel/cpu/resctrl/internal.h +++ b/arch/x86/kernel/cpu/resctrl/internal.h @@ -51,7 +51,7 @@ struct rdt_hw_ctrl_domain { }; =20 /** - * struct rdt_hw_mon_domain - Arch private attributes of a set of CPUs tha= t share + * struct rdt_hw_l3_mon_domain - Arch private attributes of a set of CPUs = that share * a resource for a monitor function * @d_resctrl: Properties exposed to the resctrl file system * @arch_mbm_states: Per-event pointer to the MBM event's saved state. @@ -60,8 +60,8 @@ struct rdt_hw_ctrl_domain { * * 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 @@ -70,9 +70,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 /** @@ -124,7 +124,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_mon_domain_online(struct rdt_resource *r, struct rdt_l3_mon_doma= in *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 ce3d24c512e3..b12242d20e61 100644 --- a/fs/resctrl/internal.h +++ b/fs/resctrl/internal.h @@ -357,7 +357,7 @@ void mon_event_read(struct rmid_read *rr, struct rdt_re= source *r, =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 @@ -365,14 +365,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 1fecb6425b9e..b6bb94444943 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -363,7 +363,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 mon_domain_free(struct rdt_hw_l3_mon_domain *hw_dom) { int idx; =20 @@ -400,7 +400,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(*hw_dom->arch_mbm_states[0]); enum resctrl_event_id eventid; @@ -498,8 +498,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; struct cacheinfo *ci; int err; =20 @@ -625,9 +625,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 @@ -653,7 +653,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(&d->hdr.list); diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/re= sctrl/monitor.c index b31794c5dcd4..043f777378a6 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -157,7 +157,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) { @@ -171,11 +171,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; @@ -194,9 +194,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 eventid; int idx; =20 @@ -222,10 +222,10 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, st= ruct rdt_domain_hdr *hdr, u64 *val, void *ignored) { int cpu =3D cpumask_any(&hdr->cpu_mask); - struct rdt_hw_mon_domain *hw_dom; + struct rdt_hw_l3_mon_domain *hw_dom; struct rdt_hw_resource *hw_res; + struct rdt_l3_mon_domain *d; struct arch_mbm_state *am; - struct rdt_mon_domain *d; u64 msr_val, chunks; u32 prmid; int ret; @@ -238,7 +238,7 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, stru= ct rdt_domain_hdr *hdr, if (!domain_header_is_valid(hdr, RESCTRL_MON_DOMAIN, RDT_RESOURCE_L3)) return -EINVAL; =20 - 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); hw_res =3D resctrl_to_arch_res(r); prmid =3D logical_rmid_to_physical_rmid(cpu, rmid); @@ -275,7 +275,7 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, stru= ct rdt_domain_hdr *hdr, * 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_mon_domain_online(struct rdt_resource *r, struct rdt_l3_mon_doma= in *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 1c1c0e7bbc11..1d7086509bfa 100644 --- a/fs/resctrl/ctrlmondata.c +++ b/fs/resctrl/ctrlmondata.c @@ -616,7 +616,7 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg) r =3D resctrl_arch_get_resource(resid); =20 if (md->sum) { - struct rdt_mon_domain *d; + struct rdt_l3_mon_domain *d; =20 if (WARN_ON_ONCE(resid !=3D RDT_RESOURCE_L3)) { ret =3D -EIO; diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c index 85fe88b965fa..28d96147b9f4 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 cacheinfo *ci; struct mbm_state *m; int err, ret; @@ -369,7 +369,7 @@ static int __mon_event_count(u32 closid, u32 rmid, stru= ct rmid_read *rr) if (WARN_ON_ONCE(!domain_header_is_valid(rr->hdr, RESCTRL_MON_DOMAIN, RDT_RESOURCE_L3))) return -EINVAL; - d =3D container_of(rr->hdr, struct rdt_mon_domain, hdr); + d =3D container_of(rr->hdr, struct rdt_l3_mon_domain, hdr); resctrl_arch_reset_rmid(rr->r, d, closid, rmid, rr->evtid); m =3D get_mbm_state(d, closid, rmid, rr->evtid); if (m) @@ -439,12 +439,12 @@ static int __mon_event_count(u32 closid, u32 rmid, st= ruct rmid_read *rr) static void mbm_bw_count(u32 closid, u32 rmid, struct rmid_read *rr) { u64 cur_bw, bytes, cur_bytes; - struct rdt_mon_domain *d; + struct rdt_l3_mon_domain *d; struct mbm_state *m; =20 if (WARN_ON_ONCE(domain_header_is_valid(rr->hdr, RESCTRL_MON_DOMAIN, RDT_= RESOURCE_L3))) return; - d =3D container_of(rr->hdr, struct rdt_mon_domain, hdr); + d =3D container_of(rr->hdr, struct rdt_l3_mon_domain, hdr); m =3D get_mbm_state(d, closid, rmid, rr->evtid); if (WARN_ON_ONCE(!m)) return; @@ -545,7 +545,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; @@ -613,7 +613,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}; @@ -640,7 +640,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) { /* @@ -661,12 +661,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 @@ -689,7 +689,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); @@ -706,7 +706,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 @@ -721,7 +721,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); @@ -755,7 +755,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 3828480e0426..4d369f6df8e8 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -1617,7 +1617,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(); @@ -1665,7 +1665,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 @@ -1706,8 +1706,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(); @@ -2581,7 +2581,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 @@ -3036,11 +3036,11 @@ static void rmdir_mondata_subdir_allrdtgrp(struct r= dt_resource *r, char name[32]; =20 if (r->rid =3D=3D RDT_RESOURCE_L3) { - struct rdt_mon_domain *d; + struct rdt_l3_mon_domain *d; =20 if (!domain_header_is_valid(hdr, RESCTRL_MON_DOMAIN, RDT_RESOURCE_L3)) return; - d =3D container_of(hdr, struct rdt_mon_domain, hdr); + d =3D container_of(hdr, struct rdt_l3_mon_domain, hdr); =20 /* SNC mode? */ if (r->mon_scope =3D=3D RESCTRL_L3_NODE) { @@ -3102,9 +3102,9 @@ static int mkdir_mondata_subdir(struct kernfs_node *p= arent_kn, return -EINVAL; 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 - d =3D container_of(hdr, struct rdt_mon_domain, hdr); + d =3D container_of(hdr, struct rdt_l3_mon_domain, hdr); domid =3D d->ci_id; } } @@ -4040,7 +4040,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) { int idx; =20 @@ -4063,7 +4063,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 @@ -4080,7 +4080,7 @@ void resctrl_offline_mon_domain(struct rdt_resource *= r, struct rdt_domain_hdr *h if (!domain_header_is_valid(hdr, RESCTRL_MON_DOMAIN, RDT_RESOURCE_L3)) 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); 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)) { @@ -4114,7 +4114,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_mon_state(struct rdt_resource *r, struct rdt_mon_d= omain *d) +static int domain_setup_mon_state(struct rdt_resource *r, struct rdt_l3_mo= n_domain *d) { u32 idx_limit =3D resctrl_arch_system_num_rmid_idx(); size_t tsize =3D sizeof(*d->mbm_states[0]); @@ -4165,7 +4165,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); @@ -4176,7 +4176,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_mon_state(r, d); if (err) goto out_unlock; @@ -4225,10 +4225,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 @@ -4244,7 +4244,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 Wed Oct 8 14:53:57 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (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 DEFAB2EE260 for ; Thu, 26 Jun 2025 16:49:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750956601; cv=none; b=nKbslxadJ2uSUp20/zzaO8Aj3F4N1AJplO4A7unlDU/T7588HxbrTMV0rnop6b9O0n+Y3mA/wQ5F/ijwx2MBHQbFer9c3ROMPc0vwwJSsk1BXt/ZodLBgwn6qUstWE9hcR8crkc3znWR7x+k5LHv0zk5s7lZySxsQ9sEi14d/rY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750956601; c=relaxed/simple; bh=dAJ1mkEIpL478KODfccmji17rmpDgH7ZXFjXptAREFA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=F+haZFYV6jH4vciOrGK24yxwmMHdw7eZ3vxvG3y9LJBGkiU0wKKVGJe/8hlws6f8yIfuFdF4aAAhEadvzTyRBfNyYJxJQL7rZt5yaQT0sp+MrFe54/K88s7jBjDufohDuhhjw2UFii03vlFPDP7KFnqLqDPeAVH+oP7Ojiyzzks= 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=aA1kRnAv; arc=none smtp.client-ip=198.175.65.19 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="aA1kRnAv" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1750956600; x=1782492600; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=dAJ1mkEIpL478KODfccmji17rmpDgH7ZXFjXptAREFA=; b=aA1kRnAvkrALjQqcj9ifMkdJMt0UMx6rnhQGqSDoN7j8Kdxz284YW5Vq rvnUGJDvu1VAWqf68NdEGeufQpnlRv7N1dS2/bmfTyB0rAgF1J26HOAFp sQw5WTXL2XWxl/zTdyDXIKSKdYPCjaSJk+6eAxct+roKPbC1WXswF5vF5 vctO/1u6c9BH47IxWYBGk4H5fcn7Nhqum8FMraA6wfDynXdT8UAJzV/8a C9yZ5l/QffLD+CyEBJylFHOU3SpxjbfhOgUvmBbNHphasa3cTNOVzUXQd 0zA1VOa25Evk23dKkibOljKs4KcjlwsVJxTZte1D/HlFPByTUBA4HlMwZ A==; X-CSE-ConnectionGUID: N5PqejrqSk6q+RUoKQQz9A== X-CSE-MsgGUID: 2XclJn7WTtCZZGKOtKfAIg== X-IronPort-AV: E=McAfee;i="6800,10657,11476"; a="53136401" X-IronPort-AV: E=Sophos;i="6.16,268,1744095600"; d="scan'208";a="53136401" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2025 09:49:56 -0700 X-CSE-ConnectionGUID: ZGFRBQfXQeyiV1kWhVUNJg== X-CSE-MsgGUID: DxcXJeseS82BQFPpx1Xp9A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,268,1744095600"; d="scan'208";a="153069216" Received: from agluck-desk3.sc.intel.com ([172.25.103.51]) by orviesa008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2025 09:49:55 -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 v6 11/30] x86,fs/resctrl: Rename some L3 specific functions Date: Thu, 26 Jun 2025 09:49:20 -0700 Message-ID: <20250626164941.106341-12-tony.luck@intel.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250626164941.106341-1-tony.luck@intel.com> References: <20250626164941.106341-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 functions used to be tied to the RDT_RESOURCE_L3 resource, so generic function names to setup and tear down domains made sense. But with the arrival of monitor events tied to other domains it would be clearer if these functions were more accurately named. Two groups of functions renamed here: Functions that allocate/free architecture per-RMID mbm state information: arch_domain_mbm_alloc() -> l3_mon_domain_mbm_alloc() mon_domain_free() -> l3_mon_domain_free() Functions that allocate/free filesystem per-RMID mbm state information: domain_setup_mon_state() -> domain_setup_l3_mon_state() domain_destroy_mon_state() -> domain_destroy_l3_mon_state() Signed-off-by: Tony Luck --- arch/x86/kernel/cpu/resctrl/core.c | 16 ++++++++-------- fs/resctrl/rdtgroup.c | 10 +++++----- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resct= rl/core.c index b6bb94444943..976b4f9d1197 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -363,7 +363,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_l3_mon_domain *hw_dom) +static void l3_mon_domain_free(struct rdt_hw_l3_mon_domain *hw_dom) { int idx; =20 @@ -396,11 +396,11 @@ static int domain_setup_ctrlval(struct rdt_resource *= r, struct rdt_ctrl_domain * } =20 /** - * arch_domain_mbm_alloc() - Allocate arch private storage for the MBM cou= nters + * l3_mon_domain_mbm_alloc() - Allocate arch private storage for the MBM c= ounters * @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_l3_mon_domain= *hw_dom) +static int l3_mon_domain_mbm_alloc(u32 num_rmid, struct rdt_hw_l3_mon_doma= in *hw_dom) { size_t tsize =3D sizeof(*hw_dom->arch_mbm_states[0]); enum resctrl_event_id eventid; @@ -514,7 +514,7 @@ static void l3_mon_domain_setup(int cpu, int id, struct= rdt_resource *r, struct ci =3D get_cpu_cacheinfo_level(cpu, RESCTRL_L3_CACHE); if (!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; } d->ci_id =3D ci->id; @@ -522,8 +522,8 @@ static void l3_mon_domain_setup(int cpu, int id, struct= rdt_resource *r, struct =20 arch_mon_domain_online(r, d); =20 - if (arch_domain_mbm_alloc(r->num_rmid, hw_dom)) { - mon_domain_free(hw_dom); + if (l3_mon_domain_mbm_alloc(r->num_rmid, hw_dom)) { + l3_mon_domain_free(hw_dom); return; } =20 @@ -533,7 +533,7 @@ static void l3_mon_domain_setup(int cpu, int id, struct= rdt_resource *r, struct if (err) { list_del_rcu(&d->hdr.list); synchronize_rcu(); - mon_domain_free(hw_dom); + l3_mon_domain_free(hw_dom); } } =20 @@ -658,7 +658,7 @@ static void domain_remove_cpu_mon(int cpu, struct rdt_r= esource *r) resctrl_offline_mon_domain(r, hdr); list_del_rcu(&d->hdr.list); synchronize_rcu(); - mon_domain_free(hw_dom); + l3_mon_domain_free(hw_dom); break; default: pr_warn_once("Unknown resource rid=3D%d\n", r->rid); diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index 4d369f6df8e8..39018f6c8b14 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -4040,7 +4040,7 @@ static void rdtgroup_setup_default(void) mutex_unlock(&rdtgroup_mutex); } =20 -static void domain_destroy_mon_state(struct rdt_l3_mon_domain *d) +static void domain_destroy_l3_mon_state(struct rdt_l3_mon_domain *d) { int idx; =20 @@ -4096,13 +4096,13 @@ void resctrl_offline_mon_domain(struct rdt_resource= *r, struct rdt_domain_hdr *h cancel_delayed_work(&d->cqm_limbo); } =20 - domain_destroy_mon_state(d); + domain_destroy_l3_mon_state(d); out_unlock: mutex_unlock(&rdtgroup_mutex); } =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. * @@ -4114,7 +4114,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_mon_state(struct rdt_resource *r, struct rdt_l3_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(*d->mbm_states[0]); @@ -4177,7 +4177,7 @@ int resctrl_online_mon_domain(struct rdt_resource *r,= struct rdt_domain_hdr *hdr goto out_unlock; =20 d =3D container_of(hdr, struct rdt_l3_mon_domain, hdr); - 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 Wed Oct 8 14:53:57 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (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 1904B2EE5F0 for ; Thu, 26 Jun 2025 16:50:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750956602; cv=none; b=L1jypYMkk7kCLFyKtkb05Qkxih/aGH68G4LQeWnp8xzif4aSo+Xk+pz362JbJzMf3NvbjcJYaHVvfDBG4r62JXNcXZj+v8s1dLaKmax0dQJlBqTrWaNpdgm79rZpEAz0OyCE20EDJloE6b8DSDpdOmA0QigTMAIjtMFQCJsSpS8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750956602; c=relaxed/simple; bh=IBp9Uci+xgu2crt66gFNebWaLtoikj4mqej9J0xq1sI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MsLxT725pQCJYx3iFKNNf3AXDlVwvRrbIJ/sy9X7G+O3v0K57yW9DJU6c8zrVT09Hj//SL/11iQCotdY+h6c9b9RHHoO8mpuZw5jb/0II4nIiOoda+Nz6CvmCM/ATHmiWV94G2tMLcveksrMkbWNcrxbfqqA4fEUyF7lyiB6DCA= 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=Y0DJ78Ej; arc=none smtp.client-ip=198.175.65.19 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="Y0DJ78Ej" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1750956601; x=1782492601; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=IBp9Uci+xgu2crt66gFNebWaLtoikj4mqej9J0xq1sI=; b=Y0DJ78EjJKBLh2j5uPEd6L3VhcZYg/r21URyeZavnzF9AUAEf2ZoXpRv j8paasZp8WtgFEw8W3zE9pPqk46U8O4zSwHgj+emfg1c69tuDAa8Eobey 4gFzQ23tTflkYokkWixEp0uQNHqUpSjeR0XXShDE5bRJeJ/c2FJDR4IUE fWQcBSK5ewEn2+r2mZ5Vv3eeo5Hug7nZ+Q1hPSO1Yed2lctr1uL+U1yb4 z8KWFDSnDxLmHTIMck3TeKIChgXfinPlkWKzK7OCnyZtbKaUhabnE5/Fi CBr90dCDGNELvma4P39l7s7ATAAY7r5Qz9Pzk45SDMndJ3mTQdfQLTK0L g==; X-CSE-ConnectionGUID: YfqzOUq8SPimP1AGexVMlw== X-CSE-MsgGUID: oUvdwZlPQN6sBvldgGM/9g== X-IronPort-AV: E=McAfee;i="6800,10657,11476"; a="53136409" X-IronPort-AV: E=Sophos;i="6.16,268,1744095600"; d="scan'208";a="53136409" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2025 09:49:56 -0700 X-CSE-ConnectionGUID: /FBH1no5S+em1Mwan9iVnw== X-CSE-MsgGUID: sSt+eNGZSSudCUKw3Qbq3A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,268,1744095600"; d="scan'208";a="153069222" Received: from agluck-desk3.sc.intel.com ([172.25.103.51]) by orviesa008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2025 09:49:55 -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 v6 12/30] fs/resctrl: Make event details accessible to functions when reading events Date: Thu, 26 Jun 2025 09:49:21 -0700 Message-ID: <20250626164941.106341-13-tony.luck@intel.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250626164941.106341-1-tony.luck@intel.com> References: <20250626164941.106341-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 | 8 ++++---- fs/resctrl/ctrlmondata.c | 16 ++++++++-------- fs/resctrl/monitor.c | 17 +++++++++-------- fs/resctrl/rdtgroup.c | 6 +++--- 4 files changed, 24 insertions(+), 23 deletions(-) diff --git a/fs/resctrl/internal.h b/fs/resctrl/internal.h index b12242d20e61..1458fda64423 100644 --- a/fs/resctrl/internal.h +++ b/fs/resctrl/internal.h @@ -90,7 +90,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; }; @@ -103,7 +103,7 @@ struct mon_data { * @r: Resource describing the properties of the event being read. * @hdr: Header of 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: Event associated with the event file. * @first: Initialize MBM counter when true. * @ci_id: Cacheinfo id for L3. Only set when @hdr is NULL. Used when summ= ing domains. * @err: Error encountered when reading counter. @@ -117,7 +117,7 @@ struct rmid_read { struct rdtgroup *rgrp; struct rdt_resource *r; struct rdt_domain_hdr *hdr; - enum resctrl_event_id evtid; + struct mon_evt *evt; bool first; unsigned int ci_id; int err; @@ -353,7 +353,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_domain_hdr *hdr, 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 1d7086509bfa..a99903ac5d27 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_domain_hdr *hdr, 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->hdr =3D hdr; 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_domain_hdr *hdr; struct rmid_read rr =3D {0}; struct rdtgroup *rdtgrp; int domid, cpu, ret =3D 0; struct rdt_resource *r; struct cacheinfo *ci; + struct mon_evt *evt; struct mon_data *md; =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) { @@ -636,7 +636,7 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg) if (!ci) continue; mon_event_read(&rr, r, NULL, rdtgrp, - &ci->shared_cpu_map, evtid, false); + &ci->shared_cpu_map, evt, false); goto checkresult; } } @@ -652,7 +652,7 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg) ret =3D -ENOENT; goto out; } - mon_event_read(&rr, r, hdr, rdtgrp, &hdr->cpu_mask, evtid, false); + mon_event_read(&rr, r, hdr, rdtgrp, &hdr->cpu_mask, evt, false); } =20 checkresult: diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c index 28d96147b9f4..6d4191eff391 100644 --- a/fs/resctrl/monitor.c +++ b/fs/resctrl/monitor.c @@ -370,8 +370,8 @@ static int __mon_event_count(u32 closid, u32 rmid, stru= ct rmid_read *rr) RDT_RESOURCE_L3))) return -EINVAL; d =3D container_of(rr->hdr, struct rdt_l3_mon_domain, hdr); - resctrl_arch_reset_rmid(rr->r, d, closid, rmid, rr->evtid); - m =3D get_mbm_state(d, closid, rmid, rr->evtid); + resctrl_arch_reset_rmid(rr->r, d, closid, rmid, rr->evt->evtid); + m =3D get_mbm_state(d, closid, rmid, rr->evt->evtid); if (m) memset(m, 0, sizeof(struct mbm_state)); return 0; @@ -382,7 +382,7 @@ static int __mon_event_count(u32 closid, u32 rmid, stru= ct rmid_read *rr) if (!cpumask_test_cpu(cpu, &rr->hdr->cpu_mask)) return -EINVAL; rr->err =3D resctrl_arch_rmid_read(rr->r, rr->hdr, closid, rmid, - rr->evtid, &tval, rr->arch_mon_ctx); + rr->evt->evtid, &tval, rr->arch_mon_ctx); if (rr->err) return rr->err; =20 @@ -411,7 +411,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->hdr, 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; @@ -445,7 +445,7 @@ static void mbm_bw_count(u32 closid, u32 rmid, struct r= mid_read *rr) if (WARN_ON_ONCE(domain_header_is_valid(rr->hdr, RESCTRL_MON_DOMAIN, RDT_= RESOURCE_L3))) return; d =3D container_of(rr->hdr, struct rdt_l3_mon_domain, hdr); - m =3D get_mbm_state(d, closid, rmid, rr->evtid); + m =3D get_mbm_state(d, closid, rmid, rr->evt->evtid); if (WARN_ON_ONCE(!m)) return; =20 @@ -616,12 +616,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.hdr =3D &d->hdr; - 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)); @@ -637,7 +638,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 39018f6c8b14..a10f2f6825fc 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -2903,7 +2903,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 @@ -2914,7 +2914,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; @@ -3079,7 +3079,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, hdr, prgrp, &hdr->cpu_mask, mevt->evtid, true); + mon_event_read(&rr, r, hdr, prgrp, &hdr->cpu_mask, mevt, true); } =20 return 0; --=20 2.49.0 From nobody Wed Oct 8 14:53:57 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (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 C00BD29AB13 for ; Thu, 26 Jun 2025 16:50:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750956602; cv=none; b=crYET+7nsrMk34vvMidYZP5+okjQeuY70u+H07SljbHx9OjeFiZSH4tNNevtCqMATrfr9juy17X1Xr369uW1y4jtRRV+L3gOTZEAKz2WJXzImJCV41fS0+v+rfgMP3nbiNO3+PxNePinqGC9xASvTyoQm0EC1BVtY/tmjdEu5WM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750956602; c=relaxed/simple; bh=GpMO1o1CFn75/2cWIiwwhQ0CVknMbw38COCwIlj/LLs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gxh6JBHTbpUnF12oy1t3QnVbL7Tv3/svy0r/V30NRSTMvck0+Nn0pgfoztGriMfdpuWxxbo4NzIa3/kDWB42mW3wUk7TyJQbgWdPOIZ2Gdts8NBXiKWKLPNBEp1LtqsT+PvfrzqTbcFiHZlO/7Nuo3rJ62PS9bXPyfaDCKBB4z4= 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=nEXSQrW/; arc=none smtp.client-ip=198.175.65.19 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="nEXSQrW/" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1750956601; x=1782492601; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=GpMO1o1CFn75/2cWIiwwhQ0CVknMbw38COCwIlj/LLs=; b=nEXSQrW/QwFoCJw9MDKde778SiewAZzjf+6LeR8nSILDDrHhJYfnmYuh zmdEJ2SjoCLO2iTzV6KLal3Jq2gOiHtI5jAb34PlkmPhyNNkUXfr6qTaY eH1Kn5TeUduo0+Ap1cJ4eFkoS8kiIUV0qQmXx0A3z47hUfeYG6fWMuVSq PER2Ne4KX+4nvpgeXJlKjreS2byVAzIDyzu3nualkcae8LT/6qqzmFOaM embJU0jXw+cvT/Re3OPYMA3VfXNE5gUF4iG5VCL7nQB5tEiHpuGcIC3By Elgj5tdKHXv14y9+4IfTCHjA9YN+w20kPqaMy/dikCYm3uhQVZhRGPGM1 Q==; X-CSE-ConnectionGUID: oWUCk23ETD6+/gJUk8Xl+A== X-CSE-MsgGUID: D0IrDPjESVGI2oluYCmY/Q== X-IronPort-AV: E=McAfee;i="6800,10657,11476"; a="53136420" X-IronPort-AV: E=Sophos;i="6.16,268,1744095600"; d="scan'208";a="53136420" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2025 09:49:57 -0700 X-CSE-ConnectionGUID: TGm2D6BeTmmkgZg3fgugtg== X-CSE-MsgGUID: ADImL87MTnOANq71curkCw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,268,1744095600"; d="scan'208";a="153069231" Received: from agluck-desk3.sc.intel.com ([172.25.103.51]) by orviesa008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2025 09:49: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 v6 13/30] x86,fs/resctrl: Handle events that can be read from any CPU Date: Thu, 26 Jun 2025 09:49:22 -0700 Message-ID: <20250626164941.106341-14-tony.luck@intel.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250626164941.106341-1-tony.luck@intel.com> References: <20250626164941.106341-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 if the event 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(). Add a test for events that can be read from any domain to 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 | 36 +++++++++++++++++++++++------- 5 files changed, 40 insertions(+), 13 deletions(-) diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index 01740acebcd1..e05a1abb25d4 100644 --- a/include/linux/resctrl.h +++ b/include/linux/resctrl.h @@ -379,7 +379,7 @@ u32 resctrl_arch_get_num_closid(struct rdt_resource *r); u32 resctrl_arch_system_num_rmid_idx(void); int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid); =20 -void resctrl_enable_mon_event(enum resctrl_event_id eventid); +void resctrl_enable_mon_event(enum resctrl_event_id eventid, bool any_cpu); =20 bool resctrl_is_mon_event_enabled(enum resctrl_event_id eventid); =20 diff --git a/fs/resctrl/internal.h b/fs/resctrl/internal.h index 1458fda64423..f51d10d6a510 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 976b4f9d1197..b83861ab504f 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -887,15 +887,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 a99903ac5d27..2e65fddc3408 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 out_ctx_free; + } + 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); - +out_ctx_free: 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 6d4191eff391..aec26457d82c 100644 --- a/fs/resctrl/monitor.c +++ b/fs/resctrl/monitor.c @@ -356,11 +356,30 @@ static struct mbm_state *get_mbm_state(struct rdt_l3_= mon_domain *d, u32 closid, return state ? &state[idx] : NULL; } =20 +static bool cpu_on_correct_domain(struct rmid_read *rr) +{ + struct cacheinfo *ci; + int cpu; + + /* Any CPU is OK for this event */ + if (rr->evt->any_cpu) + return true; + + cpu =3D smp_processor_id(); + + /* Single domain. Must be on a CPU in that domain. */ + if (rr->hdr) + return cpumask_test_cpu(cpu, &rr->hdr->cpu_mask); + + /* Summing domains that share a cache, must be on a CPU for that cache. */ + ci =3D get_cpu_cacheinfo_level(cpu, RESCTRL_L3_CACHE); + + return ci && ci->id =3D=3D rr->ci_id; +} + 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 cacheinfo *ci; struct mbm_state *m; int err, ret; u64 tval =3D 0; @@ -378,9 +397,10 @@ static int __mon_event_count(u32 closid, u32 rmid, str= uct rmid_read *rr) } =20 if (rr->hdr) { - /* Reading a single domain, must be on a CPU in that domain. */ - if (!cpumask_test_cpu(cpu, &rr->hdr->cpu_mask)) + /* Single domain. */ + if (!cpu_on_correct_domain(rr)) return -EINVAL; + rr->err =3D resctrl_arch_rmid_read(rr->r, rr->hdr, closid, rmid, rr->evt->evtid, &tval, rr->arch_mon_ctx); if (rr->err) @@ -394,9 +414,8 @@ static int __mon_event_count(u32 closid, u32 rmid, stru= ct rmid_read *rr) if (WARN_ON_ONCE(rr->r->rid !=3D RDT_RESOURCE_L3)) return -EINVAL; =20 - /* Summing domains that share a cache, must be on a CPU for that cache. */ - ci =3D get_cpu_cacheinfo_level(cpu, RESCTRL_L3_CACHE); - if (!ci || ci->id !=3D rr->ci_id) + /* Sum across multiple domains. */ + if (!cpu_on_correct_domain(rr)) return -EINVAL; =20 /* @@ -878,7 +897,7 @@ struct mon_evt mon_event_all[QOS_NUM_EVENTS] =3D { }, }; =20 -void resctrl_enable_mon_event(enum resctrl_event_id eventid) +void resctrl_enable_mon_event(enum resctrl_event_id eventid, bool any_cpu) { if (WARN_ON_ONCE(eventid < QOS_FIRST_EVENT || eventid >=3D QOS_NUM_EVENTS= )) return; @@ -887,6 +906,7 @@ void resctrl_enable_mon_event(enum resctrl_event_id eve= ntid) return; } =20 + mon_event_all[eventid].any_cpu =3D any_cpu; mon_event_all[eventid].enabled =3D true; } =20 --=20 2.49.0 From nobody Wed Oct 8 14:53:57 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (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 26DF32EE995 for ; Thu, 26 Jun 2025 16:50:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750956603; cv=none; b=dp8WB8vpof2J0pDr1A/3ZzOyR2ED5smV6Q7EkAdsLamwHTOajsOc36KQUJeQ0yh4kAjgydp0vQv4eG0yukavrC2DGB8sK6fdRrFI82WIxmD04L9J6xPOWVNUzxQoXOph5hUANkLduHaN3nykgILwcg2jbISwMMMgg5NihlkmAdg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750956603; c=relaxed/simple; bh=cEygOBG7Tos0l17pLw8UJvXD04xloPv44Ad+viQBia4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rjdsXNUMy/GS3zVDgbPKkCXYidm9MU82OfQ/61eS3Dmqb0T6nZ3umXk0MTffYWyp56q8jKgBMHzZ7uDQIbP4/ILkFctXff2AAp0odG0lS3hCa3hEbZldrdkx/wyaYlDKtssCJ3DQwBcgPRQ8cdbdcPr9uT0jkqLjgy4BsHWVGPk= 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=nt5lkEk0; arc=none smtp.client-ip=198.175.65.19 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="nt5lkEk0" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1750956602; x=1782492602; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=cEygOBG7Tos0l17pLw8UJvXD04xloPv44Ad+viQBia4=; b=nt5lkEk0GOJkC43bvHCCSzTcCjrVsTNKZYkECzY53sdZ7ljC5AdnKuxh GU2AoO4XFlT/epq4VhjAtVjsLFJ/kBn75pxjVUOl/b0YUHRhUPlYmS0na 1LPBPwKr0HT3V53Atip/aP5i8zSQbD0GKOlW2DEtP4imNl14z63r79xRN GZjUpEzqGri/QjcUai+ZTC89/gaWPinOrW6FD80XwhYYKvOnRma+MPm5C xRWoXrOOJnw35qk/aI16YVaO0IfRf/wvRkSo2/euY6LodYQaYN8+RB20U JK6g2HA4zQiIZ8YO+XBkrn0qU0WYQ6fCr8jw8TBjWL4JVr7pMEXbbUiZk Q==; X-CSE-ConnectionGUID: yrLO25deQo2QGT0gkCJVzA== X-CSE-MsgGUID: NRJViEkOTay3ieLmfeOh8A== X-IronPort-AV: E=McAfee;i="6800,10657,11476"; a="53136429" X-IronPort-AV: E=Sophos;i="6.16,268,1744095600"; d="scan'208";a="53136429" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2025 09:49:57 -0700 X-CSE-ConnectionGUID: +8YQ4GblRFSgjmDWUJEv4A== X-CSE-MsgGUID: h2vsmCuATBOP7ho0nj7dow== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,268,1744095600"; d="scan'208";a="153069236" Received: from agluck-desk3.sc.intel.com ([172.25.103.51]) by orviesa008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2025 09:49: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 v6 14/30] x86,fs/resctrl: Support binary fixed point event counters Date: Thu, 26 Jun 2025 09:49:23 -0700 Message-ID: <20250626164941.106341-15-tony.luck@intel.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250626164941.106341-1-tony.luck@intel.com> References: <20250626164941.106341-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. The file system will only allow architecture to use floating point format on events that it marked with mon_evt::is_floating_point. Fixed point values are displayed with values rounded to an appropriate number of decimal places for the precision of the number of binary places provided. In general one extra decimal place is added for every three additional binary places. There are some exceptions for low precision binary values where exact representation is possible: 1 binary place is 0.0 or 0.5. =3D> 1 decimal place 2 binary places is 0.0. 0.25, 0.5, 0.75 =3D> 2 decimal places 3 binary places is 0.0, 0.125, etc. =3D> 3 decimal places Signed-off-by: Tony Luck --- include/linux/resctrl.h | 4 +- fs/resctrl/internal.h | 4 ++ arch/x86/kernel/cpu/resctrl/core.c | 6 +- fs/resctrl/ctrlmondata.c | 91 +++++++++++++++++++++++++++++- fs/resctrl/monitor.c | 10 +++- 5 files changed, 108 insertions(+), 7 deletions(-) diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index e05a1abb25d4..1060a54cc9fa 100644 --- a/include/linux/resctrl.h +++ b/include/linux/resctrl.h @@ -379,7 +379,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 eventid, bool any_cpu); +#define MAX_BINARY_BITS 27 + +void resctrl_enable_mon_event(enum resctrl_event_id eventid, bool any_cpu,= u32 binary_bits); =20 bool resctrl_is_mon_event_enabled(enum resctrl_event_id eventid); =20 diff --git a/fs/resctrl/internal.h b/fs/resctrl/internal.h index f51d10d6a510..4dc678af005c 100644 --- a/fs/resctrl/internal.h +++ b/fs/resctrl/internal.h @@ -58,6 +58,8 @@ 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 + * @is_floating_point: event values may be displayed in floating point for= mat + * @binary_bits: number of fixed-point binary bits from architecture * @enabled: true if the event is enabled */ struct mon_evt { @@ -66,6 +68,8 @@ struct mon_evt { char *name; bool configurable; bool any_cpu; + bool is_floating_point; + 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 b83861ab504f..2b6c6b61707d 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -887,15 +887,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 2e65fddc3408..29de0e380ccc 100644 --- a/fs/resctrl/ctrlmondata.c +++ b/fs/resctrl/ctrlmondata.c @@ -590,6 +590,93 @@ 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 + * @decplaces: Number of decimal places for this number of binary places. + * @pow10: Multiplier (10 ^ decimal places). + */ +struct fixed_params { + int decplaces; + int pow10; +}; + +static struct fixed_params fixed_params[MAX_BINARY_BITS + 1] =3D { + [1] =3D { .decplaces =3D 1, .pow10 =3D 10 }, + [2] =3D { .decplaces =3D 2, .pow10 =3D 100 }, + [3] =3D { .decplaces =3D 3, .pow10 =3D 1000 }, + [4] =3D { .decplaces =3D 3, .pow10 =3D 1000 }, + [5] =3D { .decplaces =3D 3, .pow10 =3D 1000 }, + [6] =3D { .decplaces =3D 3, .pow10 =3D 1000 }, + [7] =3D { .decplaces =3D 3, .pow10 =3D 1000 }, + [8] =3D { .decplaces =3D 3, .pow10 =3D 1000 }, + [9] =3D { .decplaces =3D 3, .pow10 =3D 1000 }, + [10] =3D { .decplaces =3D 4, .pow10 =3D 10000 }, + [11] =3D { .decplaces =3D 4, .pow10 =3D 10000 }, + [12] =3D { .decplaces =3D 4, .pow10 =3D 10000 }, + [13] =3D { .decplaces =3D 5, .pow10 =3D 100000 }, + [14] =3D { .decplaces =3D 5, .pow10 =3D 100000 }, + [15] =3D { .decplaces =3D 5, .pow10 =3D 100000 }, + [16] =3D { .decplaces =3D 6, .pow10 =3D 1000000 }, + [17] =3D { .decplaces =3D 6, .pow10 =3D 1000000 }, + [18] =3D { .decplaces =3D 6, .pow10 =3D 1000000 }, + [19] =3D { .decplaces =3D 7, .pow10 =3D 10000000 }, + [20] =3D { .decplaces =3D 7, .pow10 =3D 10000000 }, + [21] =3D { .decplaces =3D 7, .pow10 =3D 10000000 }, + [22] =3D { .decplaces =3D 8, .pow10 =3D 100000000 }, + [23] =3D { .decplaces =3D 8, .pow10 =3D 100000000 }, + [24] =3D { .decplaces =3D 8, .pow10 =3D 100000000 }, + [25] =3D { .decplaces =3D 9, .pow10 =3D 1000000000 }, + [26] =3D { .decplaces =3D 9, .pow10 =3D 1000000000 }, + [27] =3D { .decplaces =3D 9, .pow10 =3D 1000000000 } +}; + +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]; + + /* Mask off the integer part of the fixed-point value. */ + frac =3D val & GENMASK_ULL(binary_bits, 0); + + /* + * Multiply by 10^{desired decimal places}. The + * integer part of the fixed point value is now + * almost what is needed. + */ + frac *=3D fp->pow10; + + /* + * Round to nearest by adding a value that + * would be a "1" in the binary_bit + 1 place. + * Integer part of fixed point value is now + * the needed value. + */ + frac +=3D 1 << (binary_bits - 1); + + /* + * Extract the integer part of the value. This + * is the decimal representation of the original + * fixed-point fractional value. + */ + frac >>=3D binary_bits; + + /* + * "frac" is now in the range [0 .. fp->pow10). + * I.e. string representation will fit into + * fp->decplaces. + */ + 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; @@ -666,8 +753,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 aec26457d82c..076c0cc6e53a 100644 --- a/fs/resctrl/monitor.c +++ b/fs/resctrl/monitor.c @@ -897,16 +897,22 @@ struct mon_evt mon_event_all[QOS_NUM_EVENTS] =3D { }, }; =20 -void resctrl_enable_mon_event(enum resctrl_event_id eventid, bool any_cpu) +void resctrl_enable_mon_event(enum resctrl_event_id eventid, bool any_cpu,= u32 binary_bits) { - if (WARN_ON_ONCE(eventid < QOS_FIRST_EVENT || eventid >=3D QOS_NUM_EVENTS= )) + if (WARN_ON_ONCE(eventid < QOS_FIRST_EVENT || eventid >=3D QOS_NUM_EVENTS= ) || + binary_bits > MAX_BINARY_BITS) return; if (mon_event_all[eventid].enabled) { pr_warn("Duplicate enable for event %d\n", eventid); return; } + if (binary_bits && !mon_event_all[eventid].is_floating_point) { + pr_warn("Event %d may not be floating point\n", eventid); + return; + } =20 mon_event_all[eventid].any_cpu =3D any_cpu; + mon_event_all[eventid].binary_bits =3D binary_bits; mon_event_all[eventid].enabled =3D true; } =20 --=20 2.49.0 From nobody Wed Oct 8 14:53:57 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (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 7A0022EF656 for ; Thu, 26 Jun 2025 16:50:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750956604; cv=none; b=iS5UMTHZ7AxncqgUS1Oeq17ezl/HHEJFKW5ThIwXzcYgqx+8XlSh4cTbSC3uMh3gUZqYhmHwhBsz/ivx8dx4+Cx0Im6tOchu6i6v//sJIzCtBo5bQDgQMpuHMyeHI1TIrS/DFT4+vtcQIVuiRbUHvP1V3ypiz3ZdQpZvynV09wY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750956604; c=relaxed/simple; bh=A+84H7qMiaJDlRP4pKwCfRgA6C9VaLkHrvJnhcPosTw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gzg8Tg+FQWwjmZp7JMEka3quWkn/LzU7kiHHriNlBXS3hTVGaZ1+LjW05Ztmb4hxEkYsTp7LYg2JLpiWufvhfVAugKNaRlQiiTpUBKmbBth9TziAAig+UTzuONeGCm9Rj7L+6Ml+o3Y//zLT46IPiskUXdOOt9jMdBJmFvyrHAM= 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=jEFaweKt; arc=none smtp.client-ip=198.175.65.19 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="jEFaweKt" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1750956603; x=1782492603; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=A+84H7qMiaJDlRP4pKwCfRgA6C9VaLkHrvJnhcPosTw=; b=jEFaweKtQG1FfjJca7kHyjuupNG63smGkzna+n4B4R+fgjwUESN1WM5D cVhcoHP/vEDW1LHhfbKIE1hyp2HBT9HYywkGUJOgZF8wmgV4xG7AFn+g2 rwnRN94VQ666hW70Pgs9O7Gv+F/nBDhH8/QtXh5BZqlvawILLBYo+7BJq X+QvxxEO+Ikmgn0WKUfraCjRLcldbdLd7MyOiw8PACpJ68REq5k9m5a7A 2zz/UXDcclCuonCmzH1VBILBtNuX/0Mk9RoZeeiTIGGQqdcncMuvdtlzG 3UdyXSNGravOs1sLg00IDvbJoV2Nw6CjD6pr1SeiG5RBnPMGIo8HuGcv6 w==; X-CSE-ConnectionGUID: 7v3pX9K/QoaTMlotwKaa3Q== X-CSE-MsgGUID: 4RDy3wXSQCSYCT79x/P/GA== X-IronPort-AV: E=McAfee;i="6800,10657,11476"; a="53136437" X-IronPort-AV: E=Sophos;i="6.16,268,1744095600"; d="scan'208";a="53136437" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2025 09:49:58 -0700 X-CSE-ConnectionGUID: NEcVaPI+RL6abibx6kNfkQ== X-CSE-MsgGUID: lO2SRBZPSha9W/MnvK0r5Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,268,1744095600"; d="scan'208";a="153069242" Received: from agluck-desk3.sc.intel.com ([172.25.103.51]) by orviesa008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2025 09:49: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 v6 15/30] x86,fs/resctrl: Add an architectural hook called for each mount Date: Thu, 26 Jun 2025 09:49:24 -0700 Message-ID: <20250626164941.106341-16-tony.luck@intel.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250626164941.106341-1-tony.luck@intel.com> References: <20250626164941.106341-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 1060a54cc9fa..23e2874105e3 100644 --- a/include/linux/resctrl.h +++ b/include/linux/resctrl.h @@ -460,6 +460,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 2b6c6b61707d..03c481725fdb 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -717,6 +717,15 @@ static int resctrl_arch_offline_cpu(unsigned int cpu) return 0; } =20 +void resctrl_arch_pre_mount(void) +{ + static atomic_t only_once =3D ATOMIC_INIT(0); + 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 a10f2f6825fc..9dac8017a2f8 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -2585,6 +2585,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 Wed Oct 8 14:53:57 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (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 32EA42E5423 for ; Thu, 26 Jun 2025 16:50:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750956605; cv=none; b=Vb9SFa81+5nTjlFP3zX2wU2DuDITWvBGZs3JVGbscnb6LSA1rj091k2JKDdhpCCtN+MoMoiXCQ0U66Zvn8cTNrnYMo2UTkc5PoYVj2eO5GnMCKidB8hz8168mtpLt51REziqkxE/wnyRHJIdY00aCGSS2fI/k2r4lfxg3WS8dqY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750956605; c=relaxed/simple; bh=ixo7bJsQmnGV+5RozZo8jcxCPZZ7U9d0UgkIM6AZykU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=f8hgbW1pV0P4mk3vVl0Ht+l8tFEZvteEJJkUPHWe5fQk2ERncQfQ9CE+dDKEu3R/p4V2hI3i9H75Ff520JROR+tdJlJGHMzNzMU43iYC7LAtTtchXgJDOG9CxC67UGBhqNl9UER3E+tRfTIGGfEFKO0q7iDgSLCMb7sFHZHAGRs= 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=Gh2zL2IF; arc=none smtp.client-ip=198.175.65.19 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="Gh2zL2IF" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1750956604; x=1782492604; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ixo7bJsQmnGV+5RozZo8jcxCPZZ7U9d0UgkIM6AZykU=; b=Gh2zL2IFFzpCqMIxdMYpiUUPmShqLAMel7xv06RJsGWfXA2M36LC3YZ2 27yJdVAlrR/F9NRXXmB25vbY1oCY+2CYssIIQ5QHcH+bbuxYIjL/wa7nA AS7VXkeq3ianYBjLSQ2TObnZ/O5iLmSTa4cSDQTgL/D0Tk4wrmo8IIy9X 9EnRyubvkOzPZ+85KbXmh+Sc10CpHmhsLCnKvIRdGpxQZi6zlG91i3X41 AO5CWE3FlP284AlgvCLO49KppWYhDHAqq4TJN1E9x7zk9EOqqyH21UceS i8Nsso2eSHKQd/oSEQ2wG1ehdEb1RP6BflpNyOohgY3BnxH4iDxGZpFMT A==; X-CSE-ConnectionGUID: /qXXWounRDOQlbXNPTDFiA== X-CSE-MsgGUID: 6TQVmczcT/GMDjUXHgDKzw== X-IronPort-AV: E=McAfee;i="6800,10657,11476"; a="53136445" X-IronPort-AV: E=Sophos;i="6.16,268,1744095600"; d="scan'208";a="53136445" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2025 09:49:58 -0700 X-CSE-ConnectionGUID: hmM+XgG0RrC7Lqmu2KtvNQ== X-CSE-MsgGUID: +lXwONQGRwieTaitsKZ9xA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,268,1744095600"; d="scan'208";a="153069250" Received: from agluck-desk3.sc.intel.com ([172.25.103.51]) by orviesa008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2025 09:49: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 v6 16/30] x86,fs/resctrl: Add and initialize rdt_resource for package scope core monitor Date: Thu, 26 Jun 2025 09:49:25 -0700 Message-ID: <20250626164941.106341-17-tony.luck@intel.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250626164941.106341-1-tony.luck@intel.com> References: <20250626164941.106341-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 23e2874105e3..76c54b81e426 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, @@ -252,6 +253,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 4dc678af005c..53ced959a27d 100644 --- a/fs/resctrl/internal.h +++ b/fs/resctrl/internal.h @@ -239,6 +239,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 03c481725fdb..a5f01cac2363 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -100,6 +100,14 @@ struct rdt_hw_resource rdt_resources_all[RDT_NUM_RESOU= RCES] =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) @@ -433,6 +441,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 9dac8017a2f8..d9bb01edd582 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -2195,6 +2195,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 Wed Oct 8 14:53:57 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (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 7E9732EF9A5 for ; Thu, 26 Jun 2025 16:50:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750956605; cv=none; b=oAhNleK3uT1lU4H8H0VF4DdiBnU5dqulxJ2pI6PPl50ZxrNiSxxA1qbDNnplTNMl4vLuWzzss6VShL+p8vrW+l47xR8F3B1htubvsi6DnxEGOWmjjIhrEUARr9aDVknGRVTFsptjySPHqAOw30mviu8sgeRJbS+d8dRxcv0k4Lc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750956605; c=relaxed/simple; bh=7biPcEnJAj9OHprYSK1TT3pcgkvA7O+za+kQrNc5lkU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=d8hIS+OXdJmw3QxMga89c7Dpd/B4Yc+qRetwXa/2IsXiypbOtU7qspJvzwNMm6dyc1bNVRu0Qh35hSNeoB45K95EKhmdTUXDbw30p9eNwgwWf1+Fu0GuIbBXoSE/LnI9TrbQ4SsP381LjLrr/WSpwqKEyrScWsSmU+FJ4JLgbKQ= 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=cgzn6tcz; arc=none smtp.client-ip=198.175.65.19 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="cgzn6tcz" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1750956604; x=1782492604; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7biPcEnJAj9OHprYSK1TT3pcgkvA7O+za+kQrNc5lkU=; b=cgzn6tcz6OdMfD6gikjlo11+Nh+oD2mqejkhiyk1n5K5KMy1SQHr+Lzl CPyDuQcLqNbU+tcGwxlGdZ3r5Hn4uIku1lM+7aYi3gN9nyLeCUExqpQ+T HCUNshRwDhQYufYSglHS6x7Uh43mImsJxd2IoMdyaAfGfgY5BZ/WhZtiU Lfr2SGpcUDgPhmdGa9xu7sFYI5tbM6xpMIWDsPg91DBD0bBCCn+129t9y 7y7B3Aia10xgFZ2eDkqK6DOC7klzuzn2iqVM1hWIlhc785C5+49D+cOFO Rp2BmJQGXV05u1X5WJnQDzzDoD/rTziI7af0bWDCLcMEjGFhWxLyJaP7S w==; X-CSE-ConnectionGUID: 9xt9PVw2RTWqjZCOgtBspw== X-CSE-MsgGUID: pjsenat6SxyKTxizjjOqKg== X-IronPort-AV: E=McAfee;i="6800,10657,11476"; a="53136453" X-IronPort-AV: E=Sophos;i="6.16,268,1744095600"; d="scan'208";a="53136453" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2025 09:49:59 -0700 X-CSE-ConnectionGUID: BcPwSVbxQHKwmPKWVorxbg== X-CSE-MsgGUID: tAjvsF6XTGifWFSKeUoQTg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,268,1744095600"; d="scan'208";a="153069254" Received: from agluck-desk3.sc.intel.com ([172.25.103.51]) by orviesa008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2025 09:49: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 v6 17/30] x86/resctrl: Discover hardware telemetry events Date: Thu, 26 Jun 2025 09:49:26 -0700 Message-ID: <20250626164941.106341-18-tony.luck@intel.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250626164941.106341-1-tony.luck@intel.com> References: <20250626164941.106341-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. Add select of X86_PLATFORM_DEVICES, INTEL_VSEC and INTEL_PMT_TELEMETRY to CONFIG_X86_CPU_RESCTRL to enable use of the 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 | 122 ++++++++++++++++++++++++ arch/x86/Kconfig | 3 + arch/x86/kernel/cpu/resctrl/Makefile | 1 + 5 files changed, 134 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 224b71730cc3..e93b15bf6aab 100644 --- a/arch/x86/kernel/cpu/resctrl/internal.h +++ b/arch/x86/kernel/cpu/resctrl/internal.h @@ -169,4 +169,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 a5f01cac2363..9144766da836 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -734,6 +734,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 { @@ -1086,6 +1089,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..b09044b093dd --- /dev/null +++ b/arch/x86/kernel/cpu/resctrl/intel_aet.c @@ -0,0 +1,122 @@ +// 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 +#include + +#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 for additional structures to manage this group. */ + 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++) { + ret =3D configure_events(*peg, p); + if (!ret) { + (*peg)->pfg =3D no_free_ptr(p); + return true; + } + } + + 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/Kconfig b/arch/x86/Kconfig index 71019b3b54ea..8eb68d2230be 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -512,6 +512,9 @@ config X86_CPU_RESCTRL select ARCH_HAS_CPU_RESCTRL select RESCTRL_FS select RESCTRL_FS_PSEUDO_LOCK + select X86_PLATFORM_DEVICES + select INTEL_VSEC + select INTEL_PMT_TELEMETRY help Enable x86 CPU resource control support. =20 diff --git a/arch/x86/kernel/cpu/resctrl/Makefile b/arch/x86/kernel/cpu/res= ctrl/Makefile index d8a04b195da2..97ceb4e44dfa 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_RESCTRL_FS_PSEUDO_LOCK) +=3D pseudo_lock.o =20 # To allow define_trace.h's recursive include: --=20 2.49.0 From nobody Wed Oct 8 14:53:57 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (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 6650E2EF9DF for ; Thu, 26 Jun 2025 16:50:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750956606; cv=none; b=FsXrVdAgZcD+uSsM7pY0x0kTxowr+ueGsbVftITC8/41PJGTW6PXIzP7vKnWigfq6a/QFzCWeGTU8mbmAoohi43ay9wqcQv3JuzEnk8TycWBnnhQrJ8BPDmpbu0mdFMhBMvDgbyoE79CaI8gxgc8BMgkzr+rb1jGcfFMERs6Nm8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750956606; c=relaxed/simple; bh=/dVildZ2z+SGctJJUuboEilq0TwsoT2gkP4IyXcUnjg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pI/AMaInWqVIZNppXunEdd91B0xspbRd8Vaa37zKNQ4NPsZw6MEQe29M0Th4wnSTR1FVVXg+8aNJ/CUS1oskKtUyK0mi+c8OHv8tancwPoA4HkeRJufg8Z4jvrpW3iHIrCgLNILCBSiRpCWIeSA3C0IoOI/EOuHz9ydiwCAkn5Q= 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=XVDL/Wv4; arc=none smtp.client-ip=198.175.65.19 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="XVDL/Wv4" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1750956605; x=1782492605; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/dVildZ2z+SGctJJUuboEilq0TwsoT2gkP4IyXcUnjg=; b=XVDL/Wv4hn9MX92WnVeHnnqnQ56A8mFfcFBF9rvFusqHE/WMdU9sd3Pn wQBdXMm/C0rlxW4pgHungKsn0X7dHfTxWekdLHF1iffTyGltb+whE0o4T A5trt5N5Z0tRLRf3gwmc1mIIvnTJnT2S5KbGml5JXpR1qjkd95FurYPfQ ZwHmO/iMB7cJAsCSd+xsdfbVlWnvH+YiSBj0DOb6g946SQR0Xs9s2GPKw gL8IzWfNwhzBmDYy3qkXN/A+eT8CkCAhmeMWKvTYpav5zdF6LbIPF0WaO L3ogyH3bt7cKKYzQcKmFuNujMayI36CySyJYkHhPuitRbS+thO5t424mj w==; X-CSE-ConnectionGUID: qbIBq3sOROqcV9Lt1crQ+Q== X-CSE-MsgGUID: /KGK+3LnQouEqyhJqTINEQ== X-IronPort-AV: E=McAfee;i="6800,10657,11476"; a="53136461" X-IronPort-AV: E=Sophos;i="6.16,268,1744095600"; d="scan'208";a="53136461" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2025 09:49:59 -0700 X-CSE-ConnectionGUID: 1zdv6IPmRQmEqCKZMysuqg== X-CSE-MsgGUID: 7SUT49TNR4+fP5T0smFqVQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,268,1744095600"; d="scan'208";a="153069258" Received: from agluck-desk3.sc.intel.com ([172.25.103.51]) by orviesa008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2025 09:49: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 v6 18/30] x86/resctrl: Count valid telemetry aggregators per package Date: Thu, 26 Jun 2025 09:49:27 -0700 Message-ID: <20250626164941.106341-19-tony.luck@intel.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250626164941.106341-1-tony.luck@intel.com> References: <20250626164941.106341-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 | 55 ++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/intel_aet.c b/arch/x86/kernel/cpu/= resctrl/intel_aet.c index b09044b093dd..8d67ed709a74 100644 --- a/arch/x86/kernel/cpu/resctrl/intel_aet.c +++ b/arch/x86/kernel/cpu/resctrl/intel_aet.c @@ -15,6 +15,7 @@ #include #include #include +#include =20 #include "internal.h" =20 @@ -24,6 +25,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 for additional structures to manage this group. */ @@ -31,14 +33,19 @@ struct event_group { =20 /* Remaining fields initialized from XML file. */ u32 guid; + size_t mmio_size; }; =20 +#define XML_MMIO_SIZE(num_rmids, num_events, num_extra_status) \ + (((num_rmids) * (num_events) + (num_extra_status)) * sizeof(u64)) + /* * 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, + .mmio_size =3D XML_MMIO_SIZE(576, 2, 3), }; =20 /* @@ -47,6 +54,7 @@ static struct event_group energy_0x26696143 =3D { */ static struct event_group perf_0x26557651 =3D { .guid =3D 0x26557651, + .mmio_size =3D XML_MMIO_SIZE(576, 7, 3), }; =20 static struct event_group *known_event_groups[] =3D { @@ -56,10 +64,53 @@ 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 %zu too small for guid 0x%x\n", tr->size, e->gu= id); + 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) { - return -EINVAL; + int *pkgcounts __free(kfree) =3D NULL; + struct telemetry_region *tr; + int num_pkgs; + + num_pkgs =3D topology_max_packages(); + + /* 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; + if (!pkgcounts) { + pkgcounts =3D kcalloc(num_pkgs, sizeof(*pkgcounts), GFP_KERNEL); + if (!pkgcounts) + return -ENOMEM; + } + pkgcounts[tr->plat_info.package_id]++; + } + + if (!pkgcounts) + return -ENODEV; + + return 0; } =20 DEFINE_FREE(intel_pmt_put_feature_group, struct pmt_feature_group *, --=20 2.49.0 From nobody Wed Oct 8 14:53:57 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (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 21D662EFDA5 for ; Thu, 26 Jun 2025 16:50:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750956607; cv=none; b=gFIoatEOnMN8J2NJHYoYjdq/1CAOW+VzJVxUgI1QeZ5r6qA3hjlX+3IW9/31ll5WH+5y2KgShzNusf3HTkKBIsi7fXIhBz9F3E4VncBo2SpBdhBn/+eaB4WXmboabn3hwSqK3twX54fqJZEihVCszlIWOxNXcr6nVC63kZb5pYI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750956607; c=relaxed/simple; bh=kRgybYBII5wk9YaXFdZ5FQXPkRnG9bRWdzp1mhTykh4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HZrFsDBJ+z8Z+zTFWRD3CgqqKzxpKT8cDAH2lFyk6G6bdCvwWA9RlCI8KwJ6+jaIHfl4v82cWdAyuI+TbK71vr81t1cgEQSJfP47WsM/mAPP7+FFtYbHVDhuGSIPeUq2gU72ppgli/H90iRP48aJxwDhjiRhFJRlSZkUk95cVRY= 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=b+OknKwH; arc=none smtp.client-ip=198.175.65.19 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="b+OknKwH" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1750956606; x=1782492606; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=kRgybYBII5wk9YaXFdZ5FQXPkRnG9bRWdzp1mhTykh4=; b=b+OknKwHSJSB/MrMYwegxSgIzzwF3ZYxv9V1JzEQqRTmI7S82BdGkFbr CPV8/LQYxISyumgz9PHFYnGXw7gB6p6RKj3r1S90QS+JRJdygptA/Uif2 qSsnm3RjbX8IOxWINmJn+FHcCmi81fR5fUuBY91/P7DM/rM2sqoFMqWzT FapcwXkxN/92OlYLJylNQQJWyjMnCRy/ei+iexvWrOrI8t1l4LaXPTIJ3 KHV2kaCOx0vu1rpmapInFSsxiuvdwh3zuwapeDJ6q5VSrY7nNoVaEUaIQ pCLN8qZ9vGdoBUmtZc3ByIWxjMt1nbRQcVI1Pt/ae5/hik5no4CelWUTz w==; X-CSE-ConnectionGUID: pILCjdlKSTWlOqBY4pyRrw== X-CSE-MsgGUID: JKHK7iL9SsGFuT7oySqqyg== X-IronPort-AV: E=McAfee;i="6800,10657,11476"; a="53136469" X-IronPort-AV: E=Sophos;i="6.16,268,1744095600"; d="scan'208";a="53136469" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2025 09:50:00 -0700 X-CSE-ConnectionGUID: aCcpHcseTPKhaRirHQNcyg== X-CSE-MsgGUID: W8vRzrBjRgOpytOTRtFULg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,268,1744095600"; d="scan'208";a="153069261" Received: from agluck-desk3.sc.intel.com ([172.25.103.51]) by orviesa008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2025 09:49: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 v6 19/30] x86/resctrl: Complete telemetry event enumeration Date: Thu, 26 Jun 2025 09:49:28 -0700 Message-ID: <20250626164941.106341-20-tony.luck@intel.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250626164941.106341-1-tony.luck@intel.com> References: <20250626164941.106341-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 save the number of regions together with a flex array of the mmio 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| +----------------+ +----------------+ |num_regions =3D N | |num_regions =3D N | | addrs[0] | | addrs[0] | | addrs[1] | | addrs[1] | | ... | | ... | | addrs[N-1] | | addrs[N-1] | +----------------+ +----------------+ Signed-off-by: Tony Luck --- arch/x86/kernel/cpu/resctrl/intel_aet.c | 64 +++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/arch/x86/kernel/cpu/resctrl/intel_aet.c b/arch/x86/kernel/cpu/= resctrl/intel_aet.c index 8d67ed709a74..c770039b2525 100644 --- a/arch/x86/kernel/cpu/resctrl/intel_aet.c +++ b/arch/x86/kernel/cpu/resctrl/intel_aet.c @@ -19,17 +19,32 @@ =20 #include "internal.h" =20 +/** + * struct mmio_info - MMIO address information for one event group of a pa= ckage. + * @num_regions: Number of telemetry regions on this package. + * @addrs: Array of MMIO addresses, one per telemetry region on this pack= age. + * + * 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 num_regions; + void __iomem *addrs[] __counted_by(num_regions); +}; + /** * 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 for additional structures to manage this group. */ struct pmt_feature_group *pfg; + struct mmio_info **pkginfo; =20 /* Remaining fields initialized from XML file. */ u32 guid; @@ -81,6 +96,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. @@ -88,8 +117,10 @@ static bool skip_this_region(struct telemetry_region *t= r, struct event_group *e) */ static int configure_events(struct event_group *e, struct pmt_feature_grou= p *p) { + struct mmio_info **pkginfo __free(mmio_info) =3D NULL; int *pkgcounts __free(kfree) =3D NULL; struct telemetry_region *tr; + struct mmio_info *mmi; int num_pkgs; =20 num_pkgs =3D topology_max_packages(); @@ -99,6 +130,12 @@ static int configure_events(struct event_group *e, stru= ct pmt_feature_group *p) tr =3D &p->regions[i]; if (skip_this_region(tr, e)) continue; + + if (e->pkginfo) { + pr_warn_once("Duplicate telemetry information for guid 0x%x\n", e->guid= ); + return -EINVAL; + } + if (!pkgcounts) { pkgcounts =3D kcalloc(num_pkgs, sizeof(*pkgcounts), GFP_KERNEL); if (!pkgcounts) @@ -110,6 +147,32 @@ static int configure_events(struct event_group *e, str= uct pmt_feature_group *p) if (!pkgcounts) return -ENODEV; =20 + /* 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]->num_regions =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 @@ -169,5 +232,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 Wed Oct 8 14:53:57 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (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 D5C012F0047 for ; Thu, 26 Jun 2025 16:50:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750956608; cv=none; b=SZ0n4pGMCzVVtHttqgpai1/jUiYPR4WlOTl+Ii4DprcoFIh2YrtjpemW2jA+6V0/WCWk/Gy6bub4s4vJE/SzqWSqay9geaErUx0nN8R1fVglygiGtiFRE6nK8wdbgM0jPI1EIqx7wf0lgUAJErvS9/0qTXYK/C5f2dhhHlSLiHw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750956608; c=relaxed/simple; bh=4xr2U3sYnm63ho2dRJ6aqdktQ8/1P/BpGhAPyv7nEJs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HCWbONxtAKt5TUaDeoPHZa7rhKNcZ8iCUVUmiRfrgN+coqRwOBIii4lA9L8pyjhiLirhSpeWKMfPAj1QZh9jFjxR5JrekJyQMCCfJyqLgli8q7ZHaM/g5I5HMte5OMDmUD6Z99OLhIda7kCJqDtyPwimdl86zc8HU4t+xqDSzC8= 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=AC+Z3WsO; arc=none smtp.client-ip=198.175.65.19 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="AC+Z3WsO" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1750956607; x=1782492607; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=4xr2U3sYnm63ho2dRJ6aqdktQ8/1P/BpGhAPyv7nEJs=; b=AC+Z3WsO0bXI3VfVEELrVwW7jWjIKzzXjzCmv/9zZ0mgK+7NmGAdF/Tf FsiVQRgvJmuFIfBY218P6obPjORPulzsc6r8yTfSUTkN9zppkbpOD0RDh m6VieBZNKJ2TI4LKTDk1xsYjPTPAoRcuMiu2RVcUW7oSNuZIHociby9rS Shj2mSaN84Qjb2MC0UovMjlrP7lrjvNcKcZoG4FFEOpNHO8rDRQXOG+HI max0KG/P0GNAVSSknJ7/CG0PdyhAEYdyMbA3WddAVHTJlflJ6LRsVC8Sz ejDaWWPEWRYF7+q5edQDEyAE3GVKmhm9/amXzMXN+XjNy2bFPd60wlw4j g==; X-CSE-ConnectionGUID: ri4VCdoST2aBmSPF3eDMXw== X-CSE-MsgGUID: hPtsMsGVQE+j/w4D2hfoYw== X-IronPort-AV: E=McAfee;i="6800,10657,11476"; a="53136478" X-IronPort-AV: E=Sophos;i="6.16,268,1744095600"; d="scan'208";a="53136478" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2025 09:50:00 -0700 X-CSE-ConnectionGUID: x+DAiFY5T02d+ZujbYyuSQ== X-CSE-MsgGUID: JdOieTUpRBSkFBpIl+4wiA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,268,1744095600"; d="scan'208";a="153069268" Received: from agluck-desk3.sc.intel.com ([172.25.103.51]) by orviesa008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2025 09:49: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 v6 20/30] x86,fs/resctrl: Fill in details of Clearwater Forest events Date: Thu, 26 Jun 2025 09:49:29 -0700 Message-ID: <20250626164941.106341-21-tony.luck@intel.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250626164941.106341-1-tony.luck@intel.com> References: <20250626164941.106341-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 | 35 ++++++++++++++----------- 3 files changed, 64 insertions(+), 15 deletions(-) diff --git a/include/linux/resctrl_types.h b/include/linux/resctrl_types.h index d98351663c2c..6838b02d5ca3 100644 --- a/include/linux/resctrl_types.h +++ b/include/linux/resctrl_types.h @@ -47,6 +47,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 c770039b2525..f9b2959693a0 100644 --- a/arch/x86/kernel/cpu/resctrl/intel_aet.c +++ b/arch/x86/kernel/cpu/resctrl/intel_aet.c @@ -32,6 +32,20 @@ struct mmio_info { void __iomem *addrs[] __counted_by(num_regions); }; =20 +/** + * struct pmt_event - Telemetry event. + * @id: Resctrl event id. + * @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 id; + int idx; + int bin_bits; +}; + +#define EVT(_id, _idx, _bits) { .id =3D _id, .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 @@ -40,6 +54,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 for additional structures to manage this group. */ @@ -49,6 +65,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 #define XML_MMIO_SIZE(num_rmids, num_events, num_extra_status) \ @@ -61,6 +79,11 @@ struct event_group { static struct event_group energy_0x26696143 =3D { .guid =3D 0x26696143, .mmio_size =3D XML_MMIO_SIZE(576, 2, 3), + .num_events =3D 2, + .evts =3D { + EVT(PMT_EVENT_ENERGY, 0, 18), + EVT(PMT_EVENT_ACTIVITY, 1, 18), + } }; =20 /* @@ -70,6 +93,16 @@ static struct event_group energy_0x26696143 =3D { static struct event_group perf_0x26557651 =3D { .guid =3D 0x26557651, .mmio_size =3D XML_MMIO_SIZE(576, 7, 3), + .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 076c0cc6e53a..cff8af3a263e 100644 --- a/fs/resctrl/monitor.c +++ b/fs/resctrl/monitor.c @@ -874,27 +874,32 @@ static void dom_data_exit(struct rdt_resource *r) mutex_unlock(&rdtgroup_mutex); } =20 +#define MON_EVENT(_eventid, _name, _res, _fp) \ + [_eventid] =3D { \ + .name =3D _name, \ + .evtid =3D _eventid, \ + .rid =3D _res, \ + .is_floating_point =3D _fp, \ +} + /* * All available events. Architecture code marks the ones that * are supported by a system using resctrl_enable_mon_event() * to set .enabled. */ 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, - }, + MON_EVENT(QOS_L3_OCCUP_EVENT_ID, "llc_occupancy", RDT_RESOURCE_L3, false= ), + MON_EVENT(QOS_L3_MBM_TOTAL_EVENT_ID, "mbm_total_bytes", RDT_RESOURCE_L3,= false), + MON_EVENT(QOS_L3_MBM_LOCAL_EVENT_ID, "mbm_local_bytes", RDT_RESOURCE_L3,= false), + MON_EVENT(PMT_EVENT_ENERGY, "core_energy", RDT_RESOURCE_PERF_PKG, true= ), + MON_EVENT(PMT_EVENT_ACTIVITY, "activity", RDT_RESOURCE_PERF_PKG, true), + MON_EVENT(PMT_EVENT_STALLS_LLC_HIT, "stalls_llc_hit", RDT_RESOURCE_PERF_= PKG, false), + MON_EVENT(PMT_EVENT_C1_RES, "c1_res", RDT_RESOURCE_PERF_PKG, false), + MON_EVENT(PMT_EVENT_UNHALTED_CORE_CYCLES, "unhalted_core_cycles", RDT_RES= OURCE_PERF_PKG, false), + MON_EVENT(PMT_EVENT_STALLS_LLC_MISS, "stalls_llc_miss", RDT_RESOURCE_PER= F_PKG, false), + MON_EVENT(PMT_EVENT_AUTO_C6_RES, "c6_res", RDT_RESOURCE_PERF_PKG, false= ), + MON_EVENT(PMT_EVENT_UNHALTED_REF_CYCLES, "unhalted_ref_cycles", RDT_RESOU= RCE_PERF_PKG, false), + MON_EVENT(PMT_EVENT_UOPS_RETIRED, "uops_retired", RDT_RESOURCE_PERF_PKG= , false), }; =20 void resctrl_enable_mon_event(enum resctrl_event_id eventid, bool any_cpu,= u32 binary_bits) --=20 2.49.0 From nobody Wed Oct 8 14:53:57 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (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 7D85D2EF9C9 for ; Thu, 26 Jun 2025 16:50:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750956608; cv=none; b=KVlA86r3saRwwLUozkdkzkUOSBRG4D2oQ3BTXGaTI7EUR+5LGX2biorm1ZnVCraRAzXZlTMoDrPwUzClX5gCNe4kcP6KhwYbkquL6s83aWt2BARQ+dnF83IgDtok+f28v8rOucW0ABqFV9veZpSXZqo87js6+DS7MCU1cKYp7MQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750956608; c=relaxed/simple; bh=y83k3MtJ1MImHe0mXB07hDaFkXHwfELscLworcbBB/w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fgqp/Pzhl17OUtSEaKlRd12YOEhcuJpO0vMg52gUVOy2pv6hMchtRTaCktbE4z180BE+R36PCAqKXA+bPiOmCvt5qZSGaOWZQuHGzF5OHfvKWEamyTVG4RF5jZQP0T/H+7m+weVwspRUi7vhoQfTq28BNecQ4ywD32aAmDORcvc= 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=HonpykEg; arc=none smtp.client-ip=198.175.65.19 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="HonpykEg" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1750956607; x=1782492607; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=y83k3MtJ1MImHe0mXB07hDaFkXHwfELscLworcbBB/w=; b=HonpykEgEb3HizVPZQCtg522tF/DU5fvp9xA9Crhl0frunf+3ALJi8Tl 2L2sFr0JMpklGStslDCFjQDnHpug03Ji6imOJri35zY+/0l107faFD0YK lbZ6GLlrOKkp5B01ccYFVcKrI0VPqs3bad1VIMVDPhbBQSrnJZM1li+Jc ePSdvYPej965mU4LUpXWWxPT8h580C7rVf51aZLY8kwyNQGGfS5/rn/KZ W8FJDm7OcR1a9GZq4mwEpHqbY2hlrSUnS8isIxNTP/T2XWQCtmrcN210s sGGPOB+EY+igRJZG2YPp/cIdCtMBH93xjaTWN1Emh/zDznux8otq+EZsz Q==; X-CSE-ConnectionGUID: MbtKQJZ8R9WLPYItJAgQEA== X-CSE-MsgGUID: DxwLRGPCSFGw/DGLK804Hg== X-IronPort-AV: E=McAfee;i="6800,10657,11476"; a="53136486" X-IronPort-AV: E=Sophos;i="6.16,268,1744095600"; d="scan'208";a="53136486" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2025 09:50:01 -0700 X-CSE-ConnectionGUID: D4lNhUSyRPWt9I7QZCgfbA== X-CSE-MsgGUID: IxiV2StaRDGYHuBm7j71mw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,268,1744095600"; d="scan'208";a="153069274" Received: from agluck-desk3.sc.intel.com ([172.25.103.51]) by orviesa008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2025 09:50: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 v6 21/30] x86,fs/resctrl: Add architectural event pointer Date: Thu, 26 Jun 2025 09:49:30 -0700 Message-ID: <20250626164941.106341-22-tony.luck@intel.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250626164941.106341-1-tony.luck@intel.com> References: <20250626164941.106341-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 layer passed the domain, rmid, and event id to resctrl_arch_rmid_read() to fetch an event counter. For some resources this may not be enough information to efficiently access the counter. Add mon_evt::arch_priv void pointer. Architecture code can initialize this when marking each event enabled. File system code passes this pointer to resctrl_arch_rmid_read(). Suggested-by: Reinette Chatre Signed-off-by: Tony Luck --- include/linux/resctrl.h | 6 ++++-- fs/resctrl/internal.h | 1 + arch/x86/kernel/cpu/resctrl/core.c | 6 +++--- arch/x86/kernel/cpu/resctrl/monitor.c | 2 +- fs/resctrl/monitor.c | 12 ++++++++---- 5 files changed, 17 insertions(+), 10 deletions(-) diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index 76c54b81e426..b9f2690bee1e 100644 --- a/include/linux/resctrl.h +++ b/include/linux/resctrl.h @@ -383,7 +383,8 @@ int resctrl_arch_update_domains(struct rdt_resource *r,= u32 closid); =20 #define MAX_BINARY_BITS 27 =20 -void resctrl_enable_mon_event(enum resctrl_event_id eventid, bool any_cpu,= u32 binary_bits); +void resctrl_enable_mon_event(enum resctrl_event_id eventid, bool any_cpu, + u32 binary_bits, void *arch_priv); =20 bool resctrl_is_mon_event_enabled(enum resctrl_event_id eventid); =20 @@ -478,6 +479,7 @@ void resctrl_arch_pre_mount(void); * only. * @rmid: rmid of the counter to read. * @eventid: eventid to read, e.g. L3 occupancy. + * @arch_priv: architecture private data for this event. * @val: result of the counter read in bytes. * @arch_mon_ctx: An architecture specific value from * resctrl_arch_mon_ctx_alloc(), for MPAM this identifies @@ -495,7 +497,7 @@ void resctrl_arch_pre_mount(void); */ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain_hdr *= hdr, u32 closid, u32 rmid, enum resctrl_event_id eventid, - u64 *val, void *arch_mon_ctx); + void *arch_priv, u64 *val, void *arch_mon_ctx); =20 /** * resctrl_arch_rmid_read_context_check() - warn about invalid contexts diff --git a/fs/resctrl/internal.h b/fs/resctrl/internal.h index 53ced959a27d..2126006075f3 100644 --- a/fs/resctrl/internal.h +++ b/fs/resctrl/internal.h @@ -71,6 +71,7 @@ struct mon_evt { bool is_floating_point; int binary_bits; bool enabled; + void *arch_priv; }; =20 extern struct mon_evt mon_event_all[QOS_NUM_EVENTS]; diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resct= rl/core.c index 9144766da836..f3144fe918dd 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -909,15 +909,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, 0); + resctrl_enable_mon_event(QOS_L3_OCCUP_EVENT_ID, false, 0, NULL); ret =3D true; } if (rdt_cpu_has(X86_FEATURE_CQM_MBM_TOTAL)) { - resctrl_enable_mon_event(QOS_L3_MBM_TOTAL_EVENT_ID, false, 0); + resctrl_enable_mon_event(QOS_L3_MBM_TOTAL_EVENT_ID, false, 0, NULL); ret =3D true; } if (rdt_cpu_has(X86_FEATURE_CQM_MBM_LOCAL)) { - resctrl_enable_mon_event(QOS_L3_MBM_LOCAL_EVENT_ID, false, 0); + resctrl_enable_mon_event(QOS_L3_MBM_LOCAL_EVENT_ID, false, 0, NULL); ret =3D true; } =20 diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/re= sctrl/monitor.c index 043f777378a6..185b203f6321 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -219,7 +219,7 @@ static u64 mbm_overflow_count(u64 prev_msr, u64 cur_msr= , unsigned int width) =20 int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain_hdr *= hdr, u32 unused, u32 rmid, enum resctrl_event_id eventid, - u64 *val, void *ignored) + void *arch_priv, u64 *val, void *ignored) { int cpu =3D cpumask_any(&hdr->cpu_mask); struct rdt_hw_l3_mon_domain *hw_dom; diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c index cff8af3a263e..c4b092aec9f8 100644 --- a/fs/resctrl/monitor.c +++ b/fs/resctrl/monitor.c @@ -160,7 +160,7 @@ void __check_limbo(struct rdt_l3_mon_domain *d, bool fo= rce_free) =20 entry =3D __rmid_entry(idx); if (resctrl_arch_rmid_read(r, &d->hdr, entry->closid, entry->rmid, - QOS_L3_OCCUP_EVENT_ID, &val, + QOS_L3_OCCUP_EVENT_ID, NULL, &val, arch_mon_ctx)) { rmid_dirty =3D true; } else { @@ -402,7 +402,8 @@ static int __mon_event_count(u32 closid, u32 rmid, stru= ct rmid_read *rr) return -EINVAL; =20 rr->err =3D resctrl_arch_rmid_read(rr->r, rr->hdr, closid, rmid, - rr->evt->evtid, &tval, rr->arch_mon_ctx); + rr->evt->evtid, rr->evt->arch_priv, + &tval, rr->arch_mon_ctx); if (rr->err) return rr->err; =20 @@ -430,7 +431,8 @@ 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->hdr, closid, rmid, - rr->evt->evtid, &tval, rr->arch_mon_ctx); + rr->evt->evtid, rr->evt->arch_priv, + &tval, rr->arch_mon_ctx); if (!err) { rr->val +=3D tval; ret =3D 0; @@ -902,7 +904,8 @@ struct mon_evt mon_event_all[QOS_NUM_EVENTS] =3D { MON_EVENT(PMT_EVENT_UOPS_RETIRED, "uops_retired", RDT_RESOURCE_PERF_PKG= , false), }; =20 -void resctrl_enable_mon_event(enum resctrl_event_id eventid, bool any_cpu,= u32 binary_bits) +void resctrl_enable_mon_event(enum resctrl_event_id eventid, bool any_cpu, + u32 binary_bits, void *arch_priv) { if (WARN_ON_ONCE(eventid < QOS_FIRST_EVENT || eventid >=3D QOS_NUM_EVENTS= ) || binary_bits > MAX_BINARY_BITS) @@ -918,6 +921,7 @@ void resctrl_enable_mon_event(enum resctrl_event_id eve= ntid, bool any_cpu, u32 b =20 mon_event_all[eventid].any_cpu =3D any_cpu; mon_event_all[eventid].binary_bits =3D binary_bits; + mon_event_all[eventid].arch_priv =3D arch_priv; mon_event_all[eventid].enabled =3D true; } =20 --=20 2.49.0 From nobody Wed Oct 8 14:53:57 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (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 7454B2F0E29 for ; Thu, 26 Jun 2025 16:50:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750956609; cv=none; b=eHG7l8expQ96PLqb0uMJIjruBUrl3ynAF4UAflyLUXPcHzzYihibpoQwi50uJifjhrA7xxX3elOpYyG/X/4IHDItX9K5nIoI84DQob4maWMQ14xrRZfoTPT8Y5TFJ9ao2wrsjWaOPydLVKGhpecUHKsnzme5A+sLgYA+LpfpBwc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750956609; c=relaxed/simple; bh=OiptYH8E0/SvM8nBFEDnaTRh4DAi+rqMk7MELfRmaWI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rgiXJ9dJfER+dZ7shQPZliJhXfYbcc3GaawRyKDZdPihLg+TuLaA5LfKv6BKbR7w4q6xtLTKHsX98IRF83G/9Utxlu4cAX1C1eL/iwea1+zTr12fGJ9QQ9vkZnCH/0g2t/VMVjtd3tbh1cq9PKk/y/+qefcYxhKV5r00JN4kJcA= 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=cU+oHyMu; arc=none smtp.client-ip=198.175.65.19 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="cU+oHyMu" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1750956608; x=1782492608; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OiptYH8E0/SvM8nBFEDnaTRh4DAi+rqMk7MELfRmaWI=; b=cU+oHyMu4WsDlLLYbu+vomoeOffHw7hCbbKzpuF55FqTWxE8Ko5t0jOr B00+O8b0ZgSE678pACG0PdX1MrmvPCt0SQFq636W/P3pVB2kNAfZmUWYj UkQjG4XBj3KsoQveJu1/aYZluMnU6oNsGHV765MEG44RWeVxDhFU/W3Pi puX/WhsSi9W/C+5lZLqg7DtrTDvronOEo5UcTiUClPLsQFMvgbL8+Hw/a uHFK5oeHkaIJ1nj6a0QssiO7LMTEfE/mV5k6gm9/NCb8G0kyTm8TdimnF b+4amwlQ044kYiFX437fkjTBZl87/nhD5SBoAjfFRcaC2O9p4ppYcQ5tG w==; X-CSE-ConnectionGUID: 8mFynCCnTA+JbHqrHEuibw== X-CSE-MsgGUID: bHkFZpAmQpCkxBw6wuVpUA== X-IronPort-AV: E=McAfee;i="6800,10657,11476"; a="53136494" X-IronPort-AV: E=Sophos;i="6.16,268,1744095600"; d="scan'208";a="53136494" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2025 09:50:01 -0700 X-CSE-ConnectionGUID: bGXSNcmLTBGRDJA7+O5ivQ== X-CSE-MsgGUID: liI7gRN9Sc26EVSgoIQF0g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,268,1744095600"; d="scan'208";a="153069283" Received: from agluck-desk3.sc.intel.com ([172.25.103.51]) by orviesa008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2025 09:50: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 v6 22/30] x86/resctrl: Read core telemetry events Date: Thu, 26 Jun 2025 09:49:31 -0700 Message-ID: <20250626164941.106341-23-tony.luck@intel.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250626164941.106341-1-tony.luck@intel.com> References: <20250626164941.106341-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. Enable the events marked as readable from any CPU providing an mon_evt::arch_priv pointer to the struct pmt_event for each event. At run time when a user reads an event file the file system code provides the enum resctrl_event_id for the event and the arch_priv pointer that was supplied when the event was enabled. Resctrl now uses readq() so depends on X86_64. Update Kconfig. Signed-off-by: Tony Luck --- arch/x86/kernel/cpu/resctrl/internal.h | 2 ++ arch/x86/kernel/cpu/resctrl/intel_aet.c | 46 +++++++++++++++++++++++++ arch/x86/kernel/cpu/resctrl/monitor.c | 3 ++ arch/x86/Kconfig | 2 +- 4 files changed, 52 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/r= esctrl/internal.h index e93b15bf6aab..e8d2a754bc0c 100644 --- a/arch/x86/kernel/cpu/resctrl/internal.h +++ b/arch/x86/kernel/cpu/resctrl/internal.h @@ -171,5 +171,7 @@ 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, + void *arch_priv, 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 f9b2959693a0..10fd8b04105e 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 @@ -206,6 +207,13 @@ 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 eventid; + + eventid =3D e->evts[i].id; + resctrl_enable_mon_event(eventid, true, e->evts[i].bin_bits, &e->evts[i]= ); + } + return 0; } =20 @@ -268,3 +276,41 @@ 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 eventi= d, + void *arch_priv, u64 *val) +{ + struct pmt_event *pevt =3D arch_priv; + struct mmio_info *mmi; + struct event_group *e; + u64 evtcount; + void *pevt0; + int idx; + + pevt0 =3D pevt - pevt->idx; + e =3D container_of(pevt0, struct event_group, evts); + idx =3D rmid * e->num_events; + idx +=3D pevt->idx; + mmi =3D e->pkginfo[domid]; + + if (idx * sizeof(u64) + sizeof(u64) > e->mmio_size) { + pr_warn_once("MMIO index %d out of range\n", idx); + return -EIO; + } + + for (int i =3D 0; i < mmi->num_regions; 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 185b203f6321..51d7d99336c6 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -232,6 +232,9 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, stru= ct rdt_domain_hdr *hdr, =20 resctrl_arch_rmid_read_context_check(); =20 + if (r->rid =3D=3D RDT_RESOURCE_PERF_PKG) + return intel_aet_read_event(hdr->id, rmid, eventid, arch_priv, val); + if (r->rid !=3D RDT_RESOURCE_L3) return -EINVAL; =20 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 8eb68d2230be..a6b6ecbd3877 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -507,7 +507,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 Wed Oct 8 14:53:57 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (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 495D42F0E48 for ; Thu, 26 Jun 2025 16:50:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750956610; cv=none; b=HtIxds6rwe+jZgavK3C66LP8rPINtV9o+/0w/3XgDzEkrW27quY7S22nh7CPNmI7HsgiIVyraw8T+N+csBLTns3hrRtgZHiQR/728ob2/tFXvvTTaomD5SbE6uBSAuCQcv8xReyg5pXnRQe2hQOQHNaJnuL+Wav7VhU+iuNKoQc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750956610; c=relaxed/simple; bh=ayovP20mi/znsK/boH38Se+1pDhyqJNehHC/uWhLjhk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=V5jX3lm/7vy7njCrixFZ+kuwbGeuCXiKAQ4aV08bQb1uHzId081Hpk1bJbsIkjLZRwZTI0KGXHrS9SlzrhzK3YMv7GGJWFO7/5jJB2AE13kekcsQptKi0fK9BLb1zU5tsCi9JH32CqOIAUNHsz+FTgWNPQ8Ip2MnsEi0PAfstGg= 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=e+2RBnNq; arc=none smtp.client-ip=198.175.65.19 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="e+2RBnNq" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1750956609; x=1782492609; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ayovP20mi/znsK/boH38Se+1pDhyqJNehHC/uWhLjhk=; b=e+2RBnNqKtFdJ0oczIxbWJOED5LUac0TPQzV3kqR7Q5ULPLwlvRU9F6r KZv7v+3E/zV/FaPVfWTMWO/1mjh1MNzXaAoNMH4fjDwfPEsFUq1odcFZl LjML0EX5jtGbf8kXm4IPSxpbO2pRelT5SQJuITLUHtKUagWPEI6qEvbE1 NpJV42uk1+gm2c54uJaVM+IMZWi3cvqkwHdNK6YrqwymtrgBUAZukoMv2 zfMv0K0wc3xpL0aP3Apjy0ztrnCSiAVLVK/U8TJvUhzvFOmHja8o2D0gs TH3ns07ZamsjqhQsmSGJY2TBB9O09LtuG/uKP/tbUX4qGLX0g5LHUcBA+ w==; X-CSE-ConnectionGUID: tRNIufMAT2ipLr5XMdZqHw== X-CSE-MsgGUID: kQcg9lDqR8GR871X/ocDIw== X-IronPort-AV: E=McAfee;i="6800,10657,11476"; a="53136502" X-IronPort-AV: E=Sophos;i="6.16,268,1744095600"; d="scan'208";a="53136502" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2025 09:50:02 -0700 X-CSE-ConnectionGUID: cYCKgVy6RruREJKtSvIZsQ== X-CSE-MsgGUID: RueXSY+iQme+eFvROiv0pA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,268,1744095600"; d="scan'208";a="153069290" Received: from agluck-desk3.sc.intel.com ([172.25.103.51]) by orviesa008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2025 09:50:01 -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 v6 23/30] x86/resctrl: Handle domain creation/deletion for RDT_RESOURCE_PERF_PKG Date: Thu, 26 Jun 2025 09:49:32 -0700 Message-ID: <20250626164941.106341-24-tony.luck@intel.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250626164941.106341-1-tony.luck@intel.com> References: <20250626164941.106341-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 ++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resct= rl/core.c index f3144fe918dd..f857f92e7b8b 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -547,6 +547,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); @@ -574,6 +606,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); } @@ -670,6 +705,12 @@ static void domain_remove_cpu_mon(int cpu, struct rdt_= resource *r) synchronize_rcu(); l3_mon_domain_free(hw_dom); 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; default: pr_warn_once("Unknown resource rid=3D%d\n", r->rid); break; --=20 2.49.0 From nobody Wed Oct 8 14:53:57 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (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 D1CC92F0E5C for ; Thu, 26 Jun 2025 16:50:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750956611; cv=none; b=thCUx5YyFAPQz0F5gRYZQ4TV6/mAwinmWXA1oMG8R+DPVclXNDwRdW/6ucecUCfWyMVqg7gdY+i+o1yJCTluWr4FvBGmtDm9HlI106Ql+7fCU9rC+jrYTD98UeHZS/HC68cByN40wf9hUXlhxzLPuGRyj6oDOdZIRyicvPvo1/o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750956611; c=relaxed/simple; bh=eHqRIwvz9yrJBxiTor1hivziZIApiB48bbpm0qp3sr4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=j+LF9+keX5EBM+qyGxiCn64/RGuXU8Nfu88dsEG9uP/3lyP4L8bAoR7sAoHRwfljxOCGBWMAbhz3DMlz3uWNA8WEfWIROCReDpk6Zos/eDTNu5RGGoxfvbqgYnHQ+CJOgtr21fidTzYvZqLzvgPNmxJuSRIuXwjzq087c53wChE= 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=EEAlozBj; arc=none smtp.client-ip=198.175.65.19 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="EEAlozBj" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1750956609; x=1782492609; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=eHqRIwvz9yrJBxiTor1hivziZIApiB48bbpm0qp3sr4=; b=EEAlozBjYEOLTguee6L1UYtdnvA2ZAxeHKlxA7ZYW5//LtdfKZOSxOr/ q1ylxwVxe8z7lqLvQAchHm3P+vQ00Yrdes2GaoEF1JSuhDEct2khNHDj5 jCLdlKTCeTRNBDCOCzrqOMJXYwK307zKTrFDwcE7wMbkqM12DyUzn2ULk 87SriO4LKmW5FU/g5+3CJcq3RzMVFqbKP/TRJFOXysvOQXyP13dnPrLh2 c2SPrXU0sxE4wLf35tuLExBGx03tzmcHxY/3LgCleOZU7JQpZUVcbD45h lJlduKXgV1frWuVnoucxTZgWDB9R2sqJqZGI4AMkMlwjjDsZcC6lBBRHA A==; X-CSE-ConnectionGUID: 8k9J1SMrTJSSFUFu75npNA== X-CSE-MsgGUID: yt0LEs25RUS1e6/mry+F/Q== X-IronPort-AV: E=McAfee;i="6800,10657,11476"; a="53136510" X-IronPort-AV: E=Sophos;i="6.16,268,1744095600"; d="scan'208";a="53136510" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2025 09:50:02 -0700 X-CSE-ConnectionGUID: 7x4uhwhbTyCWepyoy4Zkng== X-CSE-MsgGUID: L6aNukbNRoSDXyhUeKIaSQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,268,1744095600"; d="scan'208";a="153069306" Received: from agluck-desk3.sc.intel.com ([172.25.103.51]) by orviesa008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2025 09:50:01 -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 v6 24/30] x86/resctrl: Add energy/perf choices to rdt boot option Date: Thu, 26 Jun 2025 09:49:33 -0700 Message-ID: <20250626164941.106341-25-tony.luck@intel.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250626164941.106341-1-tony.luck@intel.com> References: <20250626164941.106341-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 backed resctrl features are enumerated by X86_FEATURE_* flags. These may be overridden by quirks to disable features in the case of errata. Users can use kernel command line options to either disable a feature, or to force enable a feature that was disabled by a quirk. Provide similar functionality for software defined features that do not have an X86_FEATURE_* flag. Unlike other options that are tied to X86_FEATURE_* flags, these must be queried by name. Add rdt_is_software_feature_enabled() to check whether quirks or kernel command line have disabled a feature. Just like the hardware feature options the command line enable overrides quirk disable. Signed-off-by: Tony Luck --- .../admin-guide/kernel-parameters.txt | 2 +- arch/x86/kernel/cpu/resctrl/internal.h | 2 ++ arch/x86/kernel/cpu/resctrl/core.c | 30 +++++++++++++++++++ arch/x86/kernel/cpu/resctrl/intel_aet.c | 7 +++++ 4 files changed, 40 insertions(+), 1 deletion(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentatio= n/admin-guide/kernel-parameters.txt index f1f2c0874da9..4c12159f3ea0 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -6066,7 +6066,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 e8d2a754bc0c..ee1c6204722e 100644 --- a/arch/x86/kernel/cpu/resctrl/internal.h +++ b/arch/x86/kernel/cpu/resctrl/internal.h @@ -169,6 +169,8 @@ void __init intel_rdt_mbm_apply_quirk(void); =20 void rdt_domain_reconfigure_cdp(struct rdt_resource *r); =20 +bool rdt_is_software_feature_enabled(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, diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resct= rl/core.c index f857f92e7b8b..f9f3bc58290e 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -791,6 +791,8 @@ enum { RDT_FLAG_MBA, RDT_FLAG_SMBA, RDT_FLAG_BMEC, + RDT_FLAG_ENERGY, + RDT_FLAG_PERF, }; =20 #define RDT_OPT(idx, n, f) \ @@ -816,6 +818,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 @@ -865,6 +869,32 @@ bool rdt_cpu_has(int flag) return ret; } =20 +/* + * Software options that are not based on X86_FEATURE_* bits. + * There is no "h/w does not support this at all" case. + * Assume that the caller has already determined that s/w + * support is present and just needs to check if the option has been + * disabled by a quirk that has not been overridden * by a command + * line option. + */ +bool rdt_is_software_feature_enabled(char *name) +{ + struct rdt_options *o; + bool ret =3D true; + + for (o =3D rdt_options; o < &rdt_options[NUM_RDT_OPTIONS]; o++) { + if (!strcmp(name, o->name)) { + if (o->force_off) + ret =3D false; + if (o->force_on) + ret =3D true; + break; + } + } + + return ret; +} + 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 10fd8b04105e..1d2511984156 100644 --- a/arch/x86/kernel/cpu/resctrl/intel_aet.c +++ b/arch/x86/kernel/cpu/resctrl/intel_aet.c @@ -49,6 +49,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. @@ -60,6 +61,7 @@ struct pmt_event { */ struct event_group { /* Data fields for additional structures to manage this group. */ + char *name; struct pmt_feature_group *pfg; struct mmio_info **pkginfo; =20 @@ -78,6 +80,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 XML_MMIO_SIZE(576, 2, 3), .num_events =3D 2, @@ -92,6 +95,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 XML_MMIO_SIZE(576, 7, 3), .num_events =3D 7, @@ -157,6 +161,9 @@ static int configure_events(struct event_group *e, stru= ct pmt_feature_group *p) struct mmio_info *mmi; int num_pkgs; =20 + if (!rdt_is_software_feature_enabled(e->name)) + return -EINVAL; + num_pkgs =3D topology_max_packages(); =20 /* Get per-package counts of telemetry_regions for this event group */ --=20 2.49.0 From nobody Wed Oct 8 14:53:57 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (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 D6EC52F234D for ; Thu, 26 Jun 2025 16:50:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750956612; cv=none; b=Jk3NmPnGV3mqey1gwWNhEz1JaBgwe1JU7xiN30pOAaPh9KhZCSfbvarHOZ8MPsBc8IRw/hPetff8WRDHZbFYF8npbLjr1oaIf+U8BFuCMJ8JQtSLbpJHROL4U7JzGQ7GqlRtaoqpR7sW0eoyoMSK85NAyReeu26N70ypvRrf/8o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750956612; c=relaxed/simple; bh=YikFiNDb1sLidgNjOTzLL0h1wVveGVN8ygpUZOna8tk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ojIFArFjAbDXNe8U5f/FGgSpyjBMZuu3Axln5I5G3I0XYkxNN8udAvUC4npoqOg+5OhpLavUzJdzw2a6cxps/xLh5d73rgY0cuQ7daZ+HSQAmwag5kJei2qRJh8WBg95gbtIxWtm1yKJg04wML2mqEGyHEVwXg0EQ3rSUMyNEik= 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=CBv0Zo5G; arc=none smtp.client-ip=198.175.65.19 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="CBv0Zo5G" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1750956610; x=1782492610; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=YikFiNDb1sLidgNjOTzLL0h1wVveGVN8ygpUZOna8tk=; b=CBv0Zo5Gp0ek0IdlbQWYTk3iPjXU7xT0KNCoez41Q7LYhwzzsXjzmNFL yi2qiJRYv3kAeWjfsk0bdMR72+XgmxVydo5SQRZdBSamPn2mrKbzuXBX1 BUCWvq2lSkK+QJ30Rnuqmswk5Ksc09OsUahe7+7OSoLCbZ7ZjCGo9ndQk o37Uz6/wOqGKs208D25r4+/GHkiemi0AFhbIxYPqy0w7Tpr9YgfGqjX+K DMWy0rL5tf1kCPuuZwpxfBIn57YmAb1TMrsXXQNYTFm2PjX53BwEzB17O 7LRCgC+Mg/ioR24kCorLR6nOw/MAW2lmgYqN7Ic9dMzTFin0mLyiqcXqq Q==; X-CSE-ConnectionGUID: wWzpKHDhSM6byOED3RXukA== X-CSE-MsgGUID: P9mHWWZiSdiXW4ZWV9jJTw== X-IronPort-AV: E=McAfee;i="6800,10657,11476"; a="53136519" X-IronPort-AV: E=Sophos;i="6.16,268,1744095600"; d="scan'208";a="53136519" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2025 09:50:03 -0700 X-CSE-ConnectionGUID: O6dEzYqaQ6ydhXIWkxiYQg== X-CSE-MsgGUID: JsUFu0wvQ7iu+NGTQyUqjw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,268,1744095600"; d="scan'208";a="153069318" Received: from agluck-desk3.sc.intel.com ([172.25.103.51]) by orviesa008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2025 09:50:02 -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 v6 25/30] x86/resctrl: Handle number of RMIDs supported by telemetry resources Date: Thu, 26 Jun 2025 09:49:34 -0700 Message-ID: <20250626164941.106341-26-tony.luck@intel.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250626164941.106341-1-tony.luck@intel.com> References: <20250626164941.106341-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 | 4 ++++ arch/x86/kernel/cpu/resctrl/core.c | 20 +++++++++++++++++ arch/x86/kernel/cpu/resctrl/intel_aet.c | 29 +++++++++++++++++++++++++ arch/x86/kernel/cpu/resctrl/monitor.c | 2 ++ 5 files changed, 56 insertions(+), 1 deletion(-) diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index b9f2690bee1e..35ae24822493 100644 --- a/include/linux/resctrl.h +++ b/include/linux/resctrl.h @@ -288,7 +288,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 ee1c6204722e..11f25c225837 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 @@ -171,6 +173,8 @@ void rdt_domain_reconfigure_cdp(struct rdt_resource *r); =20 bool rdt_is_software_feature_enabled(char *option); =20 +bool rdt_is_software_feature_force_enabled(char *name); + 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, diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resct= rl/core.c index f9f3bc58290e..7fe4e8111773 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -895,6 +895,26 @@ bool rdt_is_software_feature_enabled(char *name) return ret; } =20 +/* + * Similar to rdt_is_software_feature_enabled() but the test is whether + * the user has force enabled the feature on the kernel command line. + */ +bool rdt_is_software_feature_force_enabled(char *name) +{ + struct rdt_options *o; + bool ret =3D false; + + for (o =3D rdt_options; o < &rdt_options[NUM_RDT_OPTIONS]; o++) { + if (!strcmp(name, o->name)) { + if (o->force_on) + ret =3D true; + break; + } + } + + return ret; +} + 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 1d2511984156..1d9edd409883 100644 --- a/arch/x86/kernel/cpu/resctrl/intel_aet.c +++ b/arch/x86/kernel/cpu/resctrl/intel_aet.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include =20 @@ -55,6 +56,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. 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. @@ -67,6 +71,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); @@ -82,6 +87,7 @@ struct event_group { static struct event_group energy_0x26696143 =3D { .name =3D "energy", .guid =3D 0x26696143, + .num_rmids =3D 576, .mmio_size =3D XML_MMIO_SIZE(576, 2, 3), .num_events =3D 2, .evts =3D { @@ -97,6 +103,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 XML_MMIO_SIZE(576, 7, 3), .num_events =3D 7, .evts =3D { @@ -177,6 +184,17 @@ static int configure_events(struct event_group *e, str= uct pmt_feature_group *p) return -EINVAL; } =20 + /* + * Ignore event group with fewer RMIDs than can be loaded + * into the IA32_PQR_ASSOC MSR unless the user used + * the rdt=3D boot option to specifically ask for it to + * be enabled. + */ + if (tr->num_rmids < rdt_num_system_rmids && + !rdt_is_software_feature_force_enabled(e->name)) + return -EINVAL; + e->num_rmids =3D min(e->num_rmids, tr->num_rmids); + if (!pkgcounts) { pkgcounts =3D kcalloc(num_pkgs, sizeof(*pkgcounts), GFP_KERNEL); if (!pkgcounts) @@ -263,11 +281,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 51d7d99336c6..b36634f1439b 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -33,6 +33,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 /* @@ -358,6 +359,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 Wed Oct 8 14:53:57 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (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 88EEB2F2367 for ; Thu, 26 Jun 2025 16:50:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750956612; cv=none; b=fYffevuUPDL/xolxwHAByQB7tT7EmdoXICnImw7qcNwRsW92DoURgORjyDF2u95gvGYLcK3wxly8pH8LDvRY0J5tQCnOVwQOyGVLfJ2dDVjmXa0kk7V82ouLIju6glzVJrrDQYkbcWFUXrw5+X7X518+9xq7dTg+fUlYzVJEzbE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750956612; c=relaxed/simple; bh=wvxX+F+XYAUy0wo6y93K5TpM8depi18EH4ekmmc2YBk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZmEhawN61BCxs283n3k48aVTn+t6rZNC25QtQK4ToHmvr/oqrbzMnepOG8VG+w+s90zPaKHE/nzWr6o7L665RXHdmRzX0pcEpZsyAZc6BsFIMePtwfwjAOTFwdwnFsyJjXwszmoHFiQjFaDFM5Bj8frOGhJJwXdW0gbkKkk34qU= 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=CRAoFzTl; arc=none smtp.client-ip=198.175.65.19 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="CRAoFzTl" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1750956611; x=1782492611; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=wvxX+F+XYAUy0wo6y93K5TpM8depi18EH4ekmmc2YBk=; b=CRAoFzTlHBPEe5AN24n4UaqOGcEwZL0+IH4V90hNiJ+l+TwqE9QeX8U3 NJmE74kFKHyF128Ec7TSjlchVThYyzrnFewMLWAsdNFc+P/t/tfNxR0yF GCyCbKhgnVQk7v6JtkzXLBWK+EC/MuUG5jpZWTKMrzcB65kQU5At/fPKp noK7dG0JFyP7+eLbV35qa3b0FD1vBXwklOyALGH1p3lGBiOW2LvtFRiOF vtpMn5greqOr1MXyLDLv3Uunw/Xwy3H5s00cEgHYfm1AKKJvLsz0nKVTz ubFkvPs9oCr/Cijqa5swal4OkzWjflCsIp882qSYseSfpU3SILoR59TYm Q==; X-CSE-ConnectionGUID: T1c1FF6qQmeIwR3/5y4GZg== X-CSE-MsgGUID: eqCdgwrYSFWxYgnK+Dzvlg== X-IronPort-AV: E=McAfee;i="6800,10657,11476"; a="53136527" X-IronPort-AV: E=Sophos;i="6.16,268,1744095600"; d="scan'208";a="53136527" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2025 09:50:03 -0700 X-CSE-ConnectionGUID: r2iYyyKzS6eMtpI/v78DNQ== X-CSE-MsgGUID: Q+E/K46uRdGQHgEHmhXKWA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,268,1744095600"; d="scan'208";a="153069335" Received: from agluck-desk3.sc.intel.com ([172.25.103.51]) by orviesa008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2025 09:50:02 -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 v6 26/30] x86,fs/resctrl: Move RMID initialization to first mount Date: Thu, 26 Jun 2025 09:49:35 -0700 Message-ID: <20250626164941.106341-27-tony.luck@intel.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250626164941.106341-1-tony.luck@intel.com> References: <20250626164941.106341-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 2126006075f3..4704ea7228ca 100644 --- a/fs/resctrl/internal.h +++ b/fs/resctrl/internal.h @@ -354,6 +354,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); @@ -364,7 +366,7 @@ void mon_event_read(struct rmid_read *rr, struct rdt_re= source *r, struct rdt_domain_hdr *hdr, 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 7fe4e8111773..50de0c29704f 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -112,10 +112,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 c4b092aec9f8..e877f5b97d18 100644 --- a/fs/resctrl/monitor.c +++ b/fs/resctrl/monitor.c @@ -796,15 +796,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 @@ -815,10 +827,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; } @@ -829,8 +839,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++) { @@ -851,13 +860,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 @@ -932,28 +938,14 @@ bool resctrl_is_mon_event_enabled(enum resctrl_event_= id eventid) } =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; @@ -970,13 +962,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 d9bb01edd582..3d87e6c4c600 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -2585,6 +2585,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(); @@ -2599,6 +2600,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; @@ -4298,9 +4306,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 Wed Oct 8 14:53:57 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (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 1A7CC2F2711 for ; Thu, 26 Jun 2025 16:50:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750956613; cv=none; b=s0IMlJQ3xTXaRDEaWowFUr4kfPf0pzHC83OXkX5G7juCeruFHQOiNEScToiKVeLJXa4AYyTcNRbhNOOrolrhJJgTqrKgZmTr3YvKmm8J3KvB7b39WGnV/C/rTLg3+Y9Q088FNNGkuq31aV6otJzclTuPJzUuvPwxTK5tBKthXzg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750956613; c=relaxed/simple; bh=rZd2hRli8Da++8V5MNk0EyR/ru9cppsEeSazevG9HTg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ScES8FVk2Tg0uLR0mYxUCmkJrBEfYA44HK0xjg0yv5xBSIXKz8pSB09Zapgmr5iV8FFg6zxzviMzDbmwJfs9GWPxZmcT50Pyew/aUZOZZLURwG14AlKihAGxY/aTkSPubAbULsPXbpRESydgFZ7TQrqwgySwJIlX3KsqOXnHaOs= 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=J8BYjmLH; arc=none smtp.client-ip=198.175.65.19 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="J8BYjmLH" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1750956612; x=1782492612; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=rZd2hRli8Da++8V5MNk0EyR/ru9cppsEeSazevG9HTg=; b=J8BYjmLHGKiuReJ9n8BCu0YjRDjSvvkotOucX+1EstFtA7f2IMs0xFGm Bm27m3RS/G1Soy3aqc9wwnUxyjA3+DbPzufBXDrZIiIzed74VN14FjeQC lkTPaD7ReXYB2ZgeDMAPB6RDmQV4rw+Cw/PoV4+guR4+OG5UpmbwtzQGI uGvcdn4vz0sb32LiG5S2Q/0hH+XNwjEeG7J8Gsb4VP0CG4BCN5Rx8iW+J w7TX2krD9/CyZ81YSnENv6x0NBlhnQi60sHxfQO83GwcUvus7zGmKiZrl iNN5romvk0HXnFX2uZq/wmKPk74EJL0acR8N5Ov4X6R/D1pwTiJkcRlUB A==; X-CSE-ConnectionGUID: 16uYs7peS/KO+DW5UpIW9A== X-CSE-MsgGUID: y/17vFWgQHya3d5d62rJ/A== X-IronPort-AV: E=McAfee;i="6800,10657,11476"; a="53136535" X-IronPort-AV: E=Sophos;i="6.16,268,1744095600"; d="scan'208";a="53136535" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2025 09:50:04 -0700 X-CSE-ConnectionGUID: zIBLx4f6Q5i+hAKCI5WIIA== X-CSE-MsgGUID: ZCB32HVDTjCtAT2e5v2v/w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,268,1744095600"; d="scan'208";a="153069344" Received: from agluck-desk3.sc.intel.com ([172.25.103.51]) by orviesa008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2025 09:50:03 -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 v6 27/30] x86/resctrl: Enable RDT_RESOURCE_PERF_PKG Date: Thu, 26 Jun 2025 09:49:36 -0700 Message-ID: <20250626164941.106341-28-tony.luck@intel.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250626164941.106341-1-tony.luck@intel.com> References: <20250626164941.106341-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 | 14 +++++++++++++- arch/x86/kernel/cpu/resctrl/intel_aet.c | 3 +++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resct= rl/core.c index 50de0c29704f..3ec8fbd2f778 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -774,14 +774,26 @@ 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 =3D ATOMIC_INIT(0); - 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); + for_each_online_cpu(cpu) + domain_add_cpu_mon(cpu, r); + mutex_unlock(&domain_list_lock); + cpus_read_unlock(); } =20 enum { diff --git a/arch/x86/kernel/cpu/resctrl/intel_aet.c b/arch/x86/kernel/cpu/= resctrl/intel_aet.c index 1d9edd409883..090e7b35c3e2 100644 --- a/arch/x86/kernel/cpu/resctrl/intel_aet.c +++ b/arch/x86/kernel/cpu/resctrl/intel_aet.c @@ -295,6 +295,9 @@ bool intel_aet_get_events(void) r->num_rmid =3D min(r->num_rmid, (*eg)->num_rmids); else r->num_rmid =3D (*eg)->num_rmids; + pr_info("%s %s monitoring detected\n", r->name, (*eg)->name); + + r->mon_capable =3D true; } =20 return ret1 || ret2; --=20 2.49.0 From nobody Wed Oct 8 14:53:57 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (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 2D4412EF9A5 for ; Thu, 26 Jun 2025 16:50:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750956614; cv=none; b=J1dMO2J9AehR2TUrCtKJbUNzl5KvzzKsRqYGQVKMDNiCtP73JYJCyFtS1usPS8XHqNTjEv/X4fpQCO2GaFbsxkxph2zX69W4Od4MZuxUKyjuNizxhqK68lI1Q2XjqM/VKr9Q7r0vfTw/fqNFv3895uuxNEyaQ5iKDOmZPWtXqVA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750956614; c=relaxed/simple; bh=RpYFUy2O9CGMMJDf9l9spIDCvPqctTPV+Vyp3ypoL80=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gBcUoWvh/pAcEEilhgwRz5vJwF0JUVmO+q/1DGMZXQmMoOLsgsMptV7JEIdejZ6g9kQFrqssXeTk77MTtYR+aF5P5cR/wkoTIYXPsubHeBNlcXR3rpUiX627kOG6BgoPz5pAo4/FwgqPtbLWa2vlNFp1wl5yX9NgIMcaT//e9S8= 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=DZsbGXOm; arc=none smtp.client-ip=198.175.65.19 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="DZsbGXOm" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1750956613; x=1782492613; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=RpYFUy2O9CGMMJDf9l9spIDCvPqctTPV+Vyp3ypoL80=; b=DZsbGXOmgDdd+1YVRss8XBxQxX0DO2fTR4vwt2jSANl4Qya+702w5I5s JrOxoMEL0EIBr6jf2ojS3eUpR32+bP0isyraDzBGM9NcNKe5jQXdof1BG AaS1u4NNgaHbsfK7vO47zKuiQCuP3GASMvc1NATPc3EuEgktGe3KD/9h4 qTFbeLfAexPjqeUgzQDLbDOIoZAuRRSOWgfUYhqXDfwudOFSyXKVC4y5F KrkQKdGYQ173iaojVOdQ5rqiJ0bsbjMKUJAtjxn6Hqufqbu01inf1XzZB 3Dspq9oCWem7zbKC97n8AVv7AUnIn1UDjANxFvcmCzLecWgaJh+qpeoYJ g==; X-CSE-ConnectionGUID: UUtmmh6eTNaFsW3olY+zbQ== X-CSE-MsgGUID: vK9aZF0ZQ/C4rQyS55jo1w== X-IronPort-AV: E=McAfee;i="6800,10657,11476"; a="53136543" X-IronPort-AV: E=Sophos;i="6.16,268,1744095600"; d="scan'208";a="53136543" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2025 09:50:04 -0700 X-CSE-ConnectionGUID: VIcc13G9SyeXMliNZ47Q3A== X-CSE-MsgGUID: XVtOF16vS16FlBjxUm27gA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,268,1744095600"; d="scan'208";a="153069351" Received: from agluck-desk3.sc.intel.com ([172.25.103.51]) by orviesa008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2025 09:50:03 -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 v6 28/30] fs/resctrl: Provide interface to create a debugfs info directory Date: Thu, 26 Jun 2025 09:49:37 -0700 Message-ID: <20250626164941.106341-29-tony.luck@intel.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250626164941.106341-1-tony.luck@intel.com> References: <20250626164941.106341-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" Architectures are constrained to just the file interfaces provided by the file system for each resource. This does not allow for architecture specific debug interfaces. Add resctrl_debugfs_mon_info_mkdir() which creates a directory in the debugfs file system for a resource. Naming follows the layout of the main resctrl hierarchy: /sys/kernel/debug/resctrl/info/{resource}_MON Suggested-by: Reinette Chatre Signed-off-by: Tony Luck --- include/linux/resctrl.h | 6 ++++++ fs/resctrl/rdtgroup.c | 24 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index 35ae24822493..a8ffd9f61c46 100644 --- a/include/linux/resctrl.h +++ b/include/linux/resctrl.h @@ -569,6 +569,12 @@ void resctrl_arch_reset_all_ctrls(struct rdt_resource = *r); extern unsigned int resctrl_rmid_realloc_threshold; extern unsigned int resctrl_rmid_realloc_limit; =20 +/** + * resctrl_debugfs_mon_info_arch_mkdir() - Create a debugfs info directory. + * @r: Resource (must be mon_capable). + */ +struct dentry *resctrl_debugfs_mon_info_arch_mkdir(struct rdt_resource *r); + int resctrl_init(void); void resctrl_exit(void); =20 diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index 3d87e6c4c600..511362a67532 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -24,6 +24,7 @@ #include #include #include +#include =20 #include =20 @@ -4350,6 +4351,29 @@ int resctrl_init(void) return ret; } =20 +/* + * Create /sys/kernel/debug/resctrl/info/{r->name}_MON/arch directory + * by request for architecture to use. + */ +struct dentry *resctrl_debugfs_mon_info_arch_mkdir(struct rdt_resource *r) +{ + static struct dentry *debugfs_resctrl_info; + struct dentry *moninfodir; + char name[32]; + + if (!r->mon_capable) + return NULL; + + if (!debugfs_resctrl_info) + debugfs_resctrl_info =3D debugfs_create_dir("info", debugfs_resctrl); + + sprintf(name, "%s_MON", r->name); + + moninfodir =3D debugfs_create_dir(name, debugfs_resctrl_info); + + return debugfs_create_dir(utsname()->machine, moninfodir); +} + static bool resctrl_online_domains_exist(void) { struct rdt_resource *r; --=20 2.49.0 From nobody Wed Oct 8 14:53:57 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (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 9E0BA2F2C70 for ; Thu, 26 Jun 2025 16:50:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750956614; cv=none; b=USkz7kb123fb/10vNzmGcpQY/Egje6sNXHxTb9x+khiUXJ2IcaOeM+82PW4qTVFs750c7BYQivuKZNgHQR9MstFelbAewEDRiCgAgjAh9SwqNcPj4lL6wXR0ynKFja0g33ISeg7yJhhSqQqsqSxhzPpE8G9ZE1g0MRp+oRtOjc4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750956614; c=relaxed/simple; bh=jUnwPXX0D6xX5B28rZv1irDlFeIdA43bvGw3/BaWN9o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mq/tBbZAFJ3O9gvwKRfFRSajMMTinGtgrb9RVqxAdt21RubZMRZDO9HAcp6NewBWLJUxBZZXKq2thFg5Z6FTBzYIciryuJ4YwER9aq+zX1rvswMMmvJ3VjATWUCVvpQAFlMvmidPlS4/BFMcpFVMXTIMlYyye8KN0Nqtf4SXJuU= 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=l56bnwL3; arc=none smtp.client-ip=198.175.65.19 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="l56bnwL3" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1750956613; x=1782492613; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=jUnwPXX0D6xX5B28rZv1irDlFeIdA43bvGw3/BaWN9o=; b=l56bnwL3SJARZtN3LqnS3M8Nh6XKjx6Eg8FmPp2b0Fh/xDvaI4dUwYD8 cPelqpBTjWYMHOU2yok3czA/D3O3SjadkH+DqtO1Re5iHrQshYrdo9MGA 2YmsLH1iQ+MNPI88Vzw49cDdfPhhECwsjlS3p4Oejs1xqUNmy3jBap3uL 8TyYHPLFkk1+u3NqNV3FSaJ2aXh+prcIWWoeH1C6hPjLcs1O43iWrj8XG ouHEvsE6oHuZYxkg4kubJqzurquab7GFda+iN2txHB4ZMw3Z2FOuU0Xtw jRqHM0lLFsq9DncOGDkTEKCozABHy+t6pYRuv//L9C8HV8Ng1ulExmKk9 g==; X-CSE-ConnectionGUID: YUPesSwNRIua1Y829szrGQ== X-CSE-MsgGUID: /L4OBonKR3uHiYU0jGJuvg== X-IronPort-AV: E=McAfee;i="6800,10657,11476"; a="53136551" X-IronPort-AV: E=Sophos;i="6.16,268,1744095600"; d="scan'208";a="53136551" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2025 09:50:05 -0700 X-CSE-ConnectionGUID: ni0ARSdCTd64cV+uEIPyeQ== X-CSE-MsgGUID: YjL/FA7/S4OfOBwomw8tug== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,268,1744095600"; d="scan'208";a="153069362" Received: from agluck-desk3.sc.intel.com ([172.25.103.51]) by orviesa008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2025 09:50:03 -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 v6 29/30] x86/resctrl: Add debug info/PERF_PKG_MON/status files Date: Thu, 26 Jun 2025 09:49:38 -0700 Message-ID: <20250626164941.106341-30-tony.luck@intel.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250626164941.106341-1-tony.luck@intel.com> References: <20250626164941.106341-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. Create files in /sys/kernel/debug/resctrl/info/PERF_PKG_MON/arch/ to display the value 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 | 56 +++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/arch/x86/kernel/cpu/resctrl/intel_aet.c b/arch/x86/kernel/cpu/= resctrl/intel_aet.c index 090e7b35c3e2..422e3e126255 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 #include @@ -275,6 +276,58 @@ static bool get_pmt_feature(enum pmt_feature_id featur= e) return false; } =20 +static ssize_t status_read(struct file *f, char __user *buf, size_t count,= loff_t *off) +{ + void __iomem *info =3D (void __iomem *)f->f_inode->i_private; + char status[32]; + int len; + + len =3D sprintf(status, "%llu\n", readq(info)); + + return simple_read_from_buffer(buf, count, off, status, len); +} + +static const struct file_operations status_fops =3D { + .read =3D status_read +}; + +static void make_status_files(struct dentry *dir, struct event_group *e, i= nt pkg, int instance) +{ + void *info =3D (void __force *)e->pkginfo[pkg]->addrs[instance] + e->mmio= _size; + char name[64]; + + sprintf(name, "%s_pkg%d_agg%d_data_loss_count", e->name, pkg, instance); + debugfs_create_file(name, 0400, dir, info - 24, &status_fops); + + sprintf(name, "%s_pkg%d_agg%d_data_loss_timestamp", e->name, pkg, instanc= e); + debugfs_create_file(name, 0400, dir, info - 16, &status_fops); + + sprintf(name, "%s_pkg%d_agg%d_last_update_timestamp", e->name, pkg, insta= nce); + debugfs_create_file(name, 0400, dir, info - 8, &status_fops); +} + +static void create_debug_event_status_files(struct dentry *dir, struct eve= nt_group *e) +{ + int num_pkgs =3D topology_max_packages(); + + for (int i =3D 0; i < num_pkgs; i++) + for (int j =3D 0; j < e->pkginfo[i]->num_regions; j++) + make_status_files(dir, e, i, j); +} + +static void create_debugfs_status_file(struct rdt_resource *r) +{ + struct event_group **eg; + struct dentry *infodir; + + infodir =3D resctrl_debugfs_mon_info_arch_mkdir(r); + for (eg =3D &known_event_groups[0]; eg < &known_event_groups[NUM_KNOWN_GR= OUPS]; eg++) { + if (!(*eg)->pfg) + continue; + create_debug_event_status_files(infodir, *eg); + } +} + /* * Ask OOBMSM discovery driver for all the RMID based telemetry groups * that it supports. @@ -300,6 +353,9 @@ bool intel_aet_get_events(void) r->mon_capable =3D true; } =20 + if (ret1 || ret2) + create_debugfs_status_file(r); + return ret1 || ret2; } =20 --=20 2.49.0 From nobody Wed Oct 8 14:53:57 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (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 28F5B2F3625 for ; Thu, 26 Jun 2025 16:50:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750956615; cv=none; b=s56m3i7cN9wluxLQvjkhjJNHEwq04XR5ojf4c5iKkgW09JqHmgvMt5Z7rSon5NP00ZJoLqXxGPNWyhtj5wPpEnqM1jfF2Q3j9VOtqYZxe2+hT6cGB8fYgoszN261YCfTbIXT54BXvaks7vyvoxjnkeIHZKbKFv4RhlHWUEaGVts= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750956615; c=relaxed/simple; bh=/krivHDJi4SFWsGi67ebg0mEW1Vx99a74/Iz9fin3WI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Rmexo/A5y7jF5bMdR+FCLwxMWVy3KyzGcsGj46WBt66Vg1FZvrCsURux6xSmgfwGKs6am8ePBgcKwue58Z6MvWxLTVWv0akoJKPuz1nhB3ElnuVFGT8zF/Bb7mePHN6W++hyiJ3vPxRH1xeEcFil3nZ1sr/DWz97TlfZIML8/3U= 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=PSxPLwa3; arc=none smtp.client-ip=198.175.65.19 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="PSxPLwa3" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1750956614; x=1782492614; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/krivHDJi4SFWsGi67ebg0mEW1Vx99a74/Iz9fin3WI=; b=PSxPLwa3Eg2yLnDuB5qSph9aSVjsmBAHQLhMTcadX9Ieytxy+x5ee3Tb Mgw6WgHnxBk9aOeCll7Mm1FjLYPh7kl5mTzn/kvQr9kn5hpD/ol5nCO+b NqUtxzkD4wcj9Wet/al/NycQnd+zGF1AGfwychfts9ponZUsxG18PiVbW QXrCS4Ck+MaQdGhDYOlozVabyoRMSEQgczk55hLDMM0v/knT4V/mGJk7c dBU7i0G/Qb1nB/lxc5RzEE70+W+ipXuiE1lE9owKRVN60X89FwUlCEYtx W172DUcX63wH5IIaYLghq9J4WhreB1r4wFw1g2iCniiLBPJ+jLS0aU3rP Q==; X-CSE-ConnectionGUID: ZBV2eXU3Th2S3VnM9ucg9w== X-CSE-MsgGUID: bmZZlSFyQQGbhbNeZO96lg== X-IronPort-AV: E=McAfee;i="6800,10657,11476"; a="53136560" X-IronPort-AV: E=Sophos;i="6.16,268,1744095600"; d="scan'208";a="53136560" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2025 09:50:05 -0700 X-CSE-ConnectionGUID: oADTCWivTweAW5jdw+hpZA== X-CSE-MsgGUID: LUfpINFiSaKLFJ7G1Kf/SA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,268,1744095600"; d="scan'208";a="153069375" Received: from agluck-desk3.sc.intel.com ([172.25.103.51]) by orviesa008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2025 09:50:04 -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 v6 30/30] x86,fs/resctrl: Update Documentation for package events Date: Thu, 26 Jun 2025 09:49:39 -0700 Message-ID: <20250626164941.106341-31-tony.luck@intel.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250626164941.106341-1-tony.luck@intel.com> References: <20250626164941.106341-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