From nobody Fri Dec 19 19:02:40 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) (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 D60EA8F5B for ; Tue, 29 Apr 2025 00:34:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745886850; cv=none; b=YeTbthJXOa2byb5y1xwce9N5+effvD9j2R5yZIfH02fxPSuRnQgviiivp+gio0HZpXp9FO62pF6+CxvR2+Crby0WRvdCPTw2nRPgDibIBj2XQuZ1zXoUHjLg8KNZaLCexi9hMpdgSH6Uft+aBw5dDO2MySJlkLO7kWUdTbnvjqQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745886850; c=relaxed/simple; bh=zMXxTX0dFjHw525jJQwgjqxqww704cgFbPv/VmF6Ob4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OVO5RiTKAl5gugpLCJaDxJ4rJFB3+U5j/l4zkri+RAuUJjW18Dx+0NxVzmWmWZMYCqpVBuP0v3GemY6kxZqHkhMPBHXwD4z/YISd9a5Omy/dk+6uLmmVmtkv/ESaEjn0wg70jzRW6QVpQJ9AQuqEHX8kVr135OGggVB5jcCNOVw= 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=fBjurRlK; arc=none smtp.client-ip=192.198.163.9 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="fBjurRlK" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1745886849; x=1777422849; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=zMXxTX0dFjHw525jJQwgjqxqww704cgFbPv/VmF6Ob4=; b=fBjurRlK8d/y8hJ5oOHwCG6gHe+qA8Cukh3Zic/xq1l5/LWcJwRsOcW3 tonArHakQicS5x6wWFAx+xukcdZAMvKJiWV9g+14ILrkR8ydVEYP7QaTa 9qKmSwgc4fRcMabLOZ8ZVCYsJ+lStETU7nb/kphTQr1ASR8sWfufdbUb/ AmewIxI2SFy4lHVJ6DiBT3t88ewGs1imgt+lyI8FodnaeAr6MvX4o1BBE BbSSX8nj5GNzjNafeF8pO+jEue1qLJoQi8bkShLFtVvwDl3fIef0YdmUH ZDijKN45X9W2xRReuOsXvKyWNzalwOHOpfIGLMye6Qs/HH/qtDgnDAWTJ Q==; X-CSE-ConnectionGUID: 8lyCl5x5QEeWAo2fqA/gRQ== X-CSE-MsgGUID: rmw/hcrtRi+JxJ4pbIo7KQ== X-IronPort-AV: E=McAfee;i="6700,10204,11417"; a="58148035" X-IronPort-AV: E=Sophos;i="6.15,247,1739865600"; d="scan'208";a="58148035" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2025 17:34:07 -0700 X-CSE-ConnectionGUID: 1KwXNAeTSMKYhrmbBRowdg== X-CSE-MsgGUID: djWSs4FES7K/rXsF+OOStg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,247,1739865600"; d="scan'208";a="133393947" Received: from agluck-desk3.sc.intel.com ([172.25.222.70]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2025 17:34:06 -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 v4 01/31] x86,fs/resctrl: Drop rdt_mon_features variable Date: Mon, 28 Apr 2025 17:33:27 -0700 Message-ID: <20250429003359.375508-2-tony.luck@intel.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250429003359.375508-1-tony.luck@intel.com> References: <20250429003359.375508-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 fs/arch boundary is a little muddy for adding new monitor features. Clean it up by making the mon_evt structure the source of all information about each event. In this case replace the bitmap of enabled monitor features with an "enabled" bit in the mon_evt structure. Change architecture code to inform file system code which events are available on a system with resctrl_enable_mon_event(). Replace the event and architecture specific: resctrl_arch_is_llc_occupancy_enabled() resctrl_arch_is_mbm_total_enabled() resctrl_arch_is_mbm_local_enabled() functions with calls to resctrl_is_mon_event_enabled() with the appropriate QOS_L3_* enum resctrl_event_id. Signed-off-by: Tony Luck --- include/linux/resctrl.h | 2 + arch/x86/include/asm/resctrl.h | 16 ------- fs/resctrl/internal.h | 4 ++ arch/x86/kernel/cpu/resctrl/core.c | 25 +++++++---- arch/x86/kernel/cpu/resctrl/monitor.c | 9 +--- fs/resctrl/ctrlmondata.c | 4 +- fs/resctrl/monitor.c | 60 ++++++++++++++++----------- fs/resctrl/rdtgroup.c | 18 ++++---- 8 files changed, 71 insertions(+), 67 deletions(-) diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index 9ba771f2ddea..3c5d111aae65 100644 --- a/include/linux/resctrl.h +++ b/include/linux/resctrl.h @@ -372,6 +372,8 @@ u32 resctrl_arch_get_num_closid(struct rdt_resource *r); u32 resctrl_arch_system_num_rmid_idx(void); int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid); =20 +void resctrl_enable_mon_event(enum resctrl_event_id evtid); +bool resctrl_is_mon_event_enabled(enum resctrl_event_id evt); bool resctrl_arch_is_evt_configurable(enum resctrl_event_id evt); =20 /** diff --git a/arch/x86/include/asm/resctrl.h b/arch/x86/include/asm/resctrl.h index 189f885dcf3e..a59b3adb56cd 100644 --- a/arch/x86/include/asm/resctrl.h +++ b/arch/x86/include/asm/resctrl.h @@ -42,7 +42,6 @@ DECLARE_PER_CPU(struct resctrl_pqr_state, pqr_state); =20 extern bool rdt_alloc_capable; extern bool rdt_mon_capable; -extern unsigned int rdt_mon_features; =20 DECLARE_STATIC_KEY_FALSE(rdt_enable_key); DECLARE_STATIC_KEY_FALSE(rdt_alloc_enable_key); @@ -82,21 +81,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/fs/resctrl/internal.h b/fs/resctrl/internal.h index 6dd2a74cf3ec..ff89a0ca130e 100644 --- a/fs/resctrl/internal.h +++ b/fs/resctrl/internal.h @@ -70,15 +70,19 @@ static inline struct rdt_fs_context *rdt_fc2context(str= uct fs_context *fc) * @evtid: event id * @name: name of the event * @configurable: true if the event is configurable + * @enabled: true if the event is enabled * @list: entry in &rdt_resource->evt_list */ struct mon_evt { enum resctrl_event_id evtid; char *name; bool configurable; + bool enabled; struct list_head list; }; =20 +extern struct mon_evt mon_event_all[QOS_NUM_EVENTS]; + /** * struct mon_data - Monitoring details for each event file. * @list: Member of the global @mon_data_kn_priv_list list. diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resct= rl/core.c index 224bed28f341..819bc7a09327 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -401,13 +401,13 @@ static int arch_domain_mbm_alloc(u32 num_rmid, struct= rdt_hw_mon_domain *hw_dom) { size_t tsize; =20 - if (resctrl_arch_is_mbm_total_enabled()) { + if (resctrl_is_mon_event_enabled(QOS_L3_MBM_TOTAL_EVENT_ID)) { tsize =3D sizeof(*hw_dom->arch_mbm_total); hw_dom->arch_mbm_total =3D kcalloc(num_rmid, tsize, GFP_KERNEL); if (!hw_dom->arch_mbm_total) return -ENOMEM; } - if (resctrl_arch_is_mbm_local_enabled()) { + if (resctrl_is_mon_event_enabled(QOS_L3_MBM_LOCAL_EVENT_ID)) { tsize =3D sizeof(*hw_dom->arch_mbm_local); hw_dom->arch_mbm_local =3D kcalloc(num_rmid, tsize, GFP_KERNEL); if (!hw_dom->arch_mbm_local) { @@ -860,15 +860,22 @@ static __init bool get_rdt_alloc_resources(void) static __init bool get_rdt_mon_resources(void) { struct rdt_resource *r =3D &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl; + bool ret =3D false; =20 - if (rdt_cpu_has(X86_FEATURE_CQM_OCCUP_LLC)) - rdt_mon_features |=3D (1 << QOS_L3_OCCUP_EVENT_ID); - if (rdt_cpu_has(X86_FEATURE_CQM_MBM_TOTAL)) - rdt_mon_features |=3D (1 << QOS_L3_MBM_TOTAL_EVENT_ID); - if (rdt_cpu_has(X86_FEATURE_CQM_MBM_LOCAL)) - rdt_mon_features |=3D (1 << QOS_L3_MBM_LOCAL_EVENT_ID); + if (rdt_cpu_has(X86_FEATURE_CQM_OCCUP_LLC)) { + resctrl_enable_mon_event(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); + ret =3D true; + } + if (rdt_cpu_has(X86_FEATURE_CQM_MBM_LOCAL)) { + resctrl_enable_mon_event(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 3fc4d9f56f0d..fda579251dba 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -30,11 +30,6 @@ */ bool rdt_mon_capable; =20 -/* - * Global to indicate which monitoring events are enabled. - */ -unsigned int rdt_mon_features; - #define CF(cf) ((unsigned long)(1048576 * (cf) + 0.5)) =20 static int snc_nodes_per_l3_cache =3D 1; @@ -206,11 +201,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 d56b78450a99..b17b60114afd 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 bde2801289d3..7de4e219dba3 100644 --- a/fs/resctrl/monitor.c +++ b/fs/resctrl/monitor.c @@ -336,7 +336,7 @@ void free_rmid(u32 closid, u32 rmid) =20 entry =3D __rmid_entry(idx); =20 - if (resctrl_arch_is_llc_occupancy_enabled()) + if (resctrl_is_mon_event_enabled(QOS_L3_OCCUP_EVENT_ID)) add_rmid_to_limbo(entry); else list_add_tail(&entry->list, &rmid_free_lru); @@ -635,10 +635,10 @@ static void mbm_update(struct rdt_resource *r, struct= rdt_mon_domain *d, * This is protected from concurrent reads from user as both * the user and overflow handler hold the global mutex. */ - if (resctrl_arch_is_mbm_total_enabled()) + if (resctrl_is_mon_event_enabled(QOS_L3_MBM_TOTAL_EVENT_ID)) mbm_update_one_event(r, d, closid, rmid, QOS_L3_MBM_TOTAL_EVENT_ID); =20 - if (resctrl_arch_is_mbm_local_enabled()) + if (resctrl_is_mon_event_enabled(QOS_L3_MBM_LOCAL_EVENT_ID)) mbm_update_one_event(r, d, closid, rmid, QOS_L3_MBM_LOCAL_EVENT_ID); } =20 @@ -842,20 +842,33 @@ 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, +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, + }, + [QOS_L3_MBM_TOTAL_EVENT_ID] =3D { + .name =3D "mbm_total_bytes", + .evtid =3D QOS_L3_MBM_TOTAL_EVENT_ID, + }, + [QOS_L3_MBM_LOCAL_EVENT_ID] =3D { + .name =3D "mbm_local_bytes", + .evtid =3D QOS_L3_MBM_LOCAL_EVENT_ID, + }, }; =20 -static struct mon_evt mbm_total_event =3D { - .name =3D "mbm_total_bytes", - .evtid =3D QOS_L3_MBM_TOTAL_EVENT_ID, -}; +void resctrl_enable_mon_event(enum resctrl_event_id evtid) +{ + if (WARN_ON_ONCE(evtid >=3D QOS_NUM_EVENTS)) + return; =20 -static struct mon_evt mbm_local_event =3D { - .name =3D "mbm_local_bytes", - .evtid =3D QOS_L3_MBM_LOCAL_EVENT_ID, -}; + mon_event_all[evtid].enabled =3D true; +} + +bool resctrl_is_mon_event_enabled(enum resctrl_event_id evtid) +{ + return evtid < QOS_NUM_EVENTS && mon_event_all[evtid].enabled; +} =20 /* * Initialize the event list for the resource. @@ -866,14 +879,13 @@ static struct mon_evt mbm_local_event =3D { */ static void l3_mon_evt_init(struct rdt_resource *r) { + enum resctrl_event_id evt; + INIT_LIST_HEAD(&r->evt_list); =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); + for (evt =3D 0; evt < QOS_NUM_EVENTS; evt++) + if (mon_event_all[evt].enabled) + list_add_tail(&mon_event_all[evt].list, &r->evt_list); } =20 /** @@ -903,19 +915,19 @@ int resctrl_mon_resource_init(void) l3_mon_evt_init(r); =20 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); } =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 07f91d18c1b8..4a092c305255 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; @@ -4046,7 +4046,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 @@ -4082,12 +4082,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) { @@ -4095,7 +4095,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) { @@ -4140,7 +4140,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 /* @@ -4215,7 +4215,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.48.1 From nobody Fri Dec 19 19:02:40 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) (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 1026D23C9 for ; Tue, 29 Apr 2025 00:34:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745886852; cv=none; b=LaMfA+vKvtUcC7UX8pAooer0rAZsCj3q7VzYZGSC4f14c3+otoly/sXLqG4JOt2V7nOR5cAh1y+ve6YevtxaDD5GnrUb9/MXSdueYSnEmp7uGqM1MbWl8p6s3mzNyn800ulI+F4wsMKhoLYZfIlYjNi/EmZots8khnQ7yHqT3Oc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745886852; c=relaxed/simple; bh=EQyc6s7B++el6cT3FsP6xRYTJ8Y7WawpLfITmmOcT+Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dyF3DWCtNo3MHYE/HbmkBogpSEwXLXTxembCo51xGPjf7W4EJCnJQrb+JA7CRsiEClZ2gGnIsDKBlFo+abvls5ClFEOCz3ml3okpUPZ5JRrYsTVYguMP6gsuDV0L4kAFOb0DgVh63Wm3k/+EI5hOGJ7Oi4XZig0zLlqGu5o36w0= 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=ZnuljUOK; arc=none smtp.client-ip=192.198.163.9 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="ZnuljUOK" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1745886850; x=1777422850; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=EQyc6s7B++el6cT3FsP6xRYTJ8Y7WawpLfITmmOcT+Y=; b=ZnuljUOKnpydKipRlW/9X1bH/LzZhPbtr970jAQxvPxGQvLleGpOZL6n oc6I2H6xwjc1k7LidtrgKX/ahSK4CcBzc4ct183N20/vdVqLMQNeN4ZWO PaRcL0Up6Ppc6o5T4Efm3EIPFkd0aQMn8ssjGH7J6/P+FUIcAw0LEvFgs wScMxFr/e9VJV1Nwz0wlnXuCYvfjl9EZthlIq5hrLVs7ePlKx5VIytFby QViUO1RXetydtbVY4At6+MPLEmwoF3thjzpjhbsv8QpoDMKMVDNL8aO0q puvVPcnF4mgdzGtJd9by3EefLm3Zo03p/Dvbo34/80/WBkhabQmecBmT5 g==; X-CSE-ConnectionGUID: 9TSJ1ToBTV2g8W8T9/lSsg== X-CSE-MsgGUID: 3NYiUYRTQwyoxELhU+WG1w== X-IronPort-AV: E=McAfee;i="6700,10204,11417"; a="58148043" X-IronPort-AV: E=Sophos;i="6.15,247,1739865600"; d="scan'208";a="58148043" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2025 17:34:08 -0700 X-CSE-ConnectionGUID: 8CbrfteYT4G40t00+yy5Mg== X-CSE-MsgGUID: g4IC66NvQSyGkWpIOSNVOg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,247,1739865600"; d="scan'208";a="133393953" Received: from agluck-desk3.sc.intel.com ([172.25.222.70]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2025 17:34:07 -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 v4 02/31] x86,fs/resctrl: Prepare for more monitor events Date: Mon, 28 Apr 2025 17:33:28 -0700 Message-ID: <20250429003359.375508-3-tony.luck@intel.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250429003359.375508-1-tony.luck@intel.com> References: <20250429003359.375508-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_ctrl_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 the code by coding for many events using loops on which are enabled. Move resctrl_is_mbm_event() to so it can be used more widely. Also provide a for_each_mbm_event() helper macro. Signed-off-by: Tony Luck --- include/linux/resctrl.h | 15 +++++--- include/linux/resctrl_types.h | 3 ++ arch/x86/kernel/cpu/resctrl/internal.h | 6 ++-- arch/x86/kernel/cpu/resctrl/core.c | 38 ++++++++++---------- arch/x86/kernel/cpu/resctrl/monitor.c | 33 ++++++++++-------- fs/resctrl/monitor.c | 13 ++++--- fs/resctrl/rdtgroup.c | 48 ++++++++++++-------------- 7 files changed, 84 insertions(+), 72 deletions(-) diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index 3c5d111aae65..cef9b0ed984c 100644 --- a/include/linux/resctrl.h +++ b/include/linux/resctrl.h @@ -161,8 +161,7 @@ struct rdt_ctrl_domain { * @hdr: common header for different domain types * @ci: cache info for this domain * @rmid_busy_llc: bitmap of which limbo RMIDs are above threshold - * @mbm_total: saved state for MBM total bandwidth - * @mbm_local: saved state for MBM local bandwidth + * @mbm_states: saved state for each QOS MBM event * @mbm_over: worker to periodically read MBM h/w counters * @cqm_limbo: worker to periodically read CQM h/w counters * @mbm_work_cpu: worker CPU for MBM h/w counters @@ -172,8 +171,7 @@ struct rdt_mon_domain { struct rdt_domain_hdr hdr; struct cacheinfo *ci; unsigned long *rmid_busy_llc; - struct mbm_state *mbm_total; - struct mbm_state *mbm_local; + struct mbm_state *mbm_states[QOS_NUM_MBM_EVENTS]; struct delayed_work mbm_over; struct delayed_work cqm_limbo; int mbm_work_cpu; @@ -376,6 +374,15 @@ void resctrl_enable_mon_event(enum resctrl_event_id ev= tid); bool resctrl_is_mon_event_enabled(enum resctrl_event_id evt); bool resctrl_arch_is_evt_configurable(enum resctrl_event_id evt); =20 +static inline bool resctrl_is_mbm_event(int e) +{ + return (e >=3D QOS_L3_MBM_TOTAL_EVENT_ID && + e <=3D QOS_L3_MBM_LOCAL_EVENT_ID); +} + +#define for_each_mbm_event(evt) \ + for (evt =3D QOS_L3_MBM_TOTAL_EVENT_ID; evt <=3D QOS_L3_MBM_LOCAL_EVENT_I= D; evt++) + /** * resctrl_arch_mon_event_config_write() - Write the config for an event. * @config_info: struct resctrl_mon_config_info describing the resource, d= omain diff --git a/include/linux/resctrl_types.h b/include/linux/resctrl_types.h index a25fb9c4070d..5ef14a24008c 100644 --- a/include/linux/resctrl_types.h +++ b/include/linux/resctrl_types.h @@ -47,4 +47,7 @@ enum resctrl_event_id { QOS_NUM_EVENTS, }; =20 +#define QOS_NUM_MBM_EVENTS (QOS_L3_MBM_LOCAL_EVENT_ID - QOS_L3_MBM_TOTAL_E= VENT_ID + 1) +#define MBM_EVENT_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..02b535c828f3 100644 --- a/arch/x86/kernel/cpu/resctrl/internal.h +++ b/arch/x86/kernel/cpu/resctrl/internal.h @@ -54,15 +54,13 @@ struct rdt_hw_ctrl_domain { * struct rdt_hw_mon_domain - Arch private attributes of a set of CPUs tha= t share * a resource for a monitor function * @d_resctrl: Properties exposed to the resctrl file system - * @arch_mbm_total: arch private state for MBM total bandwidth - * @arch_mbm_local: arch private state for MBM local bandwidth + * @arch_mbm_states: arch private state for each MBM event * * Members of this structure are accessed via helpers that provide abstrac= tion. */ struct rdt_hw_mon_domain { struct rdt_mon_domain d_resctrl; - struct arch_mbm_state *arch_mbm_total; - struct arch_mbm_state *arch_mbm_local; + struct arch_mbm_state *arch_mbm_states[QOS_NUM_MBM_EVENTS]; }; =20 static inline struct rdt_hw_ctrl_domain *resctrl_to_arch_ctrl_dom(struct r= dt_ctrl_domain *r) diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resct= rl/core.c index 819bc7a09327..e5c91d21e8f7 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -364,8 +364,8 @@ static void ctrl_domain_free(struct rdt_hw_ctrl_domain = *hw_dom) =20 static void mon_domain_free(struct rdt_hw_mon_domain *hw_dom) { - kfree(hw_dom->arch_mbm_total); - kfree(hw_dom->arch_mbm_local); + for (int i =3D 0; i < QOS_NUM_MBM_EVENTS; i++) + kfree(hw_dom->arch_mbm_states[i]); kfree(hw_dom); } =20 @@ -399,25 +399,27 @@ static int domain_setup_ctrlval(struct rdt_resource *= r, struct rdt_ctrl_domain * */ static int arch_domain_mbm_alloc(u32 num_rmid, struct rdt_hw_mon_domain *h= w_dom) { - size_t tsize; - - if (resctrl_is_mon_event_enabled(QOS_L3_MBM_TOTAL_EVENT_ID)) { - tsize =3D sizeof(*hw_dom->arch_mbm_total); - hw_dom->arch_mbm_total =3D kcalloc(num_rmid, tsize, GFP_KERNEL); - if (!hw_dom->arch_mbm_total) - return -ENOMEM; - } - if (resctrl_is_mon_event_enabled(QOS_L3_MBM_LOCAL_EVENT_ID)) { - tsize =3D sizeof(*hw_dom->arch_mbm_local); - hw_dom->arch_mbm_local =3D kcalloc(num_rmid, tsize, GFP_KERNEL); - if (!hw_dom->arch_mbm_local) { - kfree(hw_dom->arch_mbm_total); - hw_dom->arch_mbm_total =3D NULL; - return -ENOMEM; - } + size_t tsize =3D sizeof(struct arch_mbm_state); + enum resctrl_event_id evt; + int idx; + + for_each_mbm_event(evt) { + if (!resctrl_is_mon_event_enabled(evt)) + continue; + idx =3D MBM_EVENT_IDX(evt); + hw_dom->arch_mbm_states[idx] =3D kcalloc(num_rmid, tsize, GFP_KERNEL); + if (!hw_dom->arch_mbm_states[idx]) + goto cleanup; } =20 return 0; +cleanup: + while (--idx >=3D 0) { + kfree(hw_dom->arch_mbm_states[idx]); + hw_dom->arch_mbm_states[idx] =3D NULL; + } + + return -ENOMEM; } =20 static int get_domain_id_from_scope(int cpu, enum resctrl_scope scope) diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/re= sctrl/monitor.c index fda579251dba..bf7fde07846b 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -160,18 +160,21 @@ static struct arch_mbm_state *get_arch_mbm_state(stru= ct rdt_hw_mon_domain *hw_do u32 rmid, enum resctrl_event_id eventid) { + struct arch_mbm_state *state; + 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); + fallthrough; + case QOS_L3_OCCUP_EVENT_ID: return NULL; + case QOS_L3_MBM_TOTAL_EVENT_ID: + case QOS_L3_MBM_LOCAL_EVENT_ID: + state =3D hw_dom->arch_mbm_states[MBM_EVENT_IDX(eventid)]; } + + return state ? &state[rmid] : NULL; } =20 void resctrl_arch_reset_rmid(struct rdt_resource *r, struct rdt_mon_domain= *d, @@ -200,14 +203,16 @@ void resctrl_arch_reset_rmid(struct rdt_resource *r, = struct rdt_mon_domain *d, void resctrl_arch_reset_rmid_all(struct rdt_resource *r, struct rdt_mon_do= main *d) { struct rdt_hw_mon_domain *hw_dom =3D resctrl_to_arch_mon_dom(d); - - if (resctrl_is_mon_event_enabled(QOS_L3_MBM_TOTAL_EVENT_ID)) - memset(hw_dom->arch_mbm_total, 0, - sizeof(*hw_dom->arch_mbm_total) * r->num_rmid); - - if (resctrl_is_mon_event_enabled(QOS_L3_MBM_LOCAL_EVENT_ID)) - memset(hw_dom->arch_mbm_local, 0, - sizeof(*hw_dom->arch_mbm_local) * r->num_rmid); + enum resctrl_event_id evt; + int idx; + + for_each_mbm_event(evt) { + idx =3D MBM_EVENT_IDX(evt); + if (!hw_dom->arch_mbm_states[idx]) + continue; + memset(hw_dom->arch_mbm_states[idx], 0, + sizeof(struct arch_mbm_state) * r->num_rmid); + } } =20 static u64 mbm_overflow_count(u64 prev_msr, u64 cur_msr, unsigned int widt= h) diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c index 7de4e219dba3..ef33970166af 100644 --- a/fs/resctrl/monitor.c +++ b/fs/resctrl/monitor.c @@ -346,15 +346,14 @@ static struct mbm_state *get_mbm_state(struct rdt_mon= _domain *d, u32 closid, u32 rmid, enum resctrl_event_id evtid) { u32 idx =3D resctrl_arch_rmid_idx_encode(closid, rmid); + struct mbm_state *states; =20 - switch (evtid) { - case QOS_L3_MBM_TOTAL_EVENT_ID: - return &d->mbm_total[idx]; - case QOS_L3_MBM_LOCAL_EVENT_ID: - return &d->mbm_local[idx]; - default: + if (!resctrl_is_mbm_event(evtid)) return NULL; - } + + states =3D d->mbm_states[MBM_EVENT_IDX(evtid)]; + + return states ? &states[idx] : NULL; } =20 static int __mon_event_count(u32 closid, u32 rmid, struct rmid_read *rr) diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index 4a092c305255..c06752dfcb7c 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. @@ -4019,8 +4013,10 @@ static void rdtgroup_setup_default(void) static void domain_destroy_mon_state(struct rdt_mon_domain *d) { bitmap_free(d->rmid_busy_llc); - kfree(d->mbm_total); - kfree(d->mbm_local); + for (int i =3D 0; i < QOS_NUM_MBM_EVENTS; i++) { + kfree(d->mbm_states[i]); + d->mbm_states[i] =3D NULL; + } } =20 void resctrl_offline_ctrl_domain(struct rdt_resource *r, struct rdt_ctrl_d= omain *d) @@ -4080,32 +4076,34 @@ void resctrl_offline_mon_domain(struct rdt_resource= *r, struct rdt_mon_domain *d static int domain_setup_mon_state(struct rdt_resource *r, struct rdt_mon_d= omain *d) { u32 idx_limit =3D resctrl_arch_system_num_rmid_idx(); - size_t tsize; + size_t tsize =3D sizeof(struct mbm_state); + enum resctrl_event_id evt; + int idx; =20 if (resctrl_is_mon_event_enabled(QOS_L3_OCCUP_EVENT_ID)) { d->rmid_busy_llc =3D bitmap_zalloc(idx_limit, GFP_KERNEL); if (!d->rmid_busy_llc) return -ENOMEM; } - if (resctrl_is_mon_event_enabled(QOS_L3_MBM_TOTAL_EVENT_ID)) { - tsize =3D sizeof(*d->mbm_total); - d->mbm_total =3D kcalloc(idx_limit, tsize, GFP_KERNEL); - if (!d->mbm_total) { - bitmap_free(d->rmid_busy_llc); - return -ENOMEM; - } - } - if (resctrl_is_mon_event_enabled(QOS_L3_MBM_LOCAL_EVENT_ID)) { - tsize =3D sizeof(*d->mbm_local); - d->mbm_local =3D kcalloc(idx_limit, tsize, GFP_KERNEL); - if (!d->mbm_local) { - bitmap_free(d->rmid_busy_llc); - kfree(d->mbm_total); - return -ENOMEM; - } + + for_each_mbm_event(evt) { + if (!resctrl_is_mon_event_enabled(evt)) + continue; + idx =3D MBM_EVENT_IDX(evt); + d->mbm_states[idx] =3D kcalloc(idx_limit, tsize, GFP_KERNEL); + if (!d->mbm_states[idx]) + goto cleanup; } =20 return 0; +cleanup: + bitmap_free(d->rmid_busy_llc); + while (--idx >=3D 0) { + kfree(d->mbm_states[idx]); + d->mbm_states[idx] =3D NULL; + } + + return -ENOMEM; } =20 int resctrl_online_ctrl_domain(struct rdt_resource *r, struct rdt_ctrl_dom= ain *d) --=20 2.48.1 From nobody Fri Dec 19 19:02:40 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) (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 048FB1EB39 for ; Tue, 29 Apr 2025 00:34:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745886852; cv=none; b=VfwMdueSixMPhIu8B1tR1IdU/9EZUTFjADu3oSgjvEQe3hJbPSwabeFq3KTltZYeQYE+y6v9+77kp5hJq+kDLMbxo+77poW3U6c8q/LZkMAuOQ40wrR8RDB8XU79BY0vD6ev950ThJISaIicN2ZKrmuhLz+CVXoTf+5d1YD1/uU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745886852; c=relaxed/simple; bh=s89vn9sB0pME8BKV2D41d5tcrp9Oq8gVpwGbRH8WjSA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gx+Ko9fCNSAQCaqr3lGqHsgz874PZoAu/5Cs4Jf3YXxBLAg92snafWdPqdnLqVg0oeS5muaHaNBMmWV3QpHTvLP5tlW9phnu+j0PEm9l30RDmM/IFc6ECdpiZHBKTe6svRn2E43ncXGn1mJXRvEAe/+1Lhw+A0WGqSJ5yszsK+U= 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=THKhrLCn; arc=none smtp.client-ip=192.198.163.9 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="THKhrLCn" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1745886851; x=1777422851; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=s89vn9sB0pME8BKV2D41d5tcrp9Oq8gVpwGbRH8WjSA=; b=THKhrLCnFDTTHrWx8RpKZJK4Q3LvBH7Ai+F/w+cBEhfcOdKKXT75WAlO UxCTCrJtCDrOroprm3Wiw9JImmEIMO6gnHaUogGVp1yGy+hJgDlCFAqHt AKkhwcUuKtY4mDbxDgu/kLDnzk1Z5whHPGmv6VYHfzkZTN0EMjUpH84w9 zSxEt+QNqD11ZyIdbUCZTJyjCeyCt5FCuMHw2Md4Aov0IG/ReCjt+xheb n/iWNxbm6pE0jOZdYCna1WcIOAgBGxPLqKWg0G/HuSufhx8dluV9pbJst 0trIhdMmtTfstYJFUhmTbkIk/wbue2tsCRV+ITDzxSJ3V1QmmfccnytZ/ g==; X-CSE-ConnectionGUID: FEI/AMfjTX6bU9KpXE4tgw== X-CSE-MsgGUID: trJLVPgIQfqYwWFhWt6a5A== X-IronPort-AV: E=McAfee;i="6700,10204,11417"; a="58148051" X-IronPort-AV: E=Sophos;i="6.15,247,1739865600"; d="scan'208";a="58148051" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2025 17:34:08 -0700 X-CSE-ConnectionGUID: a2HYZkUQR2K2myOHNarE9w== X-CSE-MsgGUID: pj3P/77hScSOowQJaZ4xeQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,247,1739865600"; d="scan'208";a="133393958" Received: from agluck-desk3.sc.intel.com ([172.25.222.70]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2025 17:34:08 -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 v4 03/31] fs/resctrl: Clean up rdtgroup_mba_mbps_event_{show,write}() Date: Mon, 28 Apr 2025 17:33:29 -0700 Message-ID: <20250429003359.375508-4-tony.luck@intel.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250429003359.375508-1-tony.luck@intel.com> References: <20250429003359.375508-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" These routines hard-code the two legacy mbm events. Change to allow for other mbm events in the future. Signed-off-by: Tony Luck --- fs/resctrl/internal.h | 4 ++++ fs/resctrl/ctrlmondata.c | 39 +++++++++------------------------------ fs/resctrl/monitor.c | 16 ++++++++++++++++ 3 files changed, 29 insertions(+), 30 deletions(-) diff --git a/fs/resctrl/internal.h b/fs/resctrl/internal.h index ff89a0ca130e..6029b3285dd3 100644 --- a/fs/resctrl/internal.h +++ b/fs/resctrl/internal.h @@ -393,6 +393,10 @@ bool closid_allocated(unsigned int closid); =20 int resctrl_find_cleanest_closid(void); =20 +enum resctrl_event_id resctrl_get_mon_event_by_name(char *name); + +char *resctrl_mon_event_name(enum resctrl_event_id evt); + #ifdef CONFIG_RESCTRL_FS_PSEUDO_LOCK int rdtgroup_locksetup_enter(struct rdtgroup *rdtgrp); =20 diff --git a/fs/resctrl/ctrlmondata.c b/fs/resctrl/ctrlmondata.c index b17b60114afd..53388281ff7d 100644 --- a/fs/resctrl/ctrlmondata.c +++ b/fs/resctrl/ctrlmondata.c @@ -472,26 +472,17 @@ 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_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_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; - } else { + ret =3D resctrl_get_mon_event_by_name(buf); + if (ret < 0 || !resctrl_is_mon_event_enabled(ret) || !resctrl_is_mbm_even= t(ret)) { + rdt_last_cmd_printf("Unsupported event id '%s'\n", buf); ret =3D -EINVAL; + } else { + rdtgrp->mba_mbps_event =3D ret; } =20 - if (ret) - rdt_last_cmd_printf("Unsupported event id '%s'\n", buf); - rdtgroup_kn_unlock(of->kn); =20 - return ret ?: nbytes; + return ret < 0 ? ret : nbytes; } =20 int rdtgroup_mba_mbps_event_show(struct kernfs_open_file *of, @@ -502,22 +493,10 @@ int rdtgroup_mba_mbps_event_show(struct kernfs_open_f= ile *of, =20 rdtgrp =3D rdtgroup_kn_lock_live(of->kn); =20 - if (rdtgrp) { - switch (rdtgrp->mba_mbps_event) { - case QOS_L3_MBM_LOCAL_EVENT_ID: - seq_puts(s, "mbm_local_bytes\n"); - break; - case QOS_L3_MBM_TOTAL_EVENT_ID: - seq_puts(s, "mbm_total_bytes\n"); - break; - default: - pr_warn_once("Bad event %d\n", rdtgrp->mba_mbps_event); - ret =3D -EINVAL; - break; - } - } else { + if (rdtgrp) + seq_printf(s, "%s\n", resctrl_mon_event_name(rdtgrp->mba_mbps_event)); + else ret =3D -ENOENT; - } =20 rdtgroup_kn_unlock(of->kn); =20 diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c index ef33970166af..625cd328c790 100644 --- a/fs/resctrl/monitor.c +++ b/fs/resctrl/monitor.c @@ -869,6 +869,22 @@ bool resctrl_is_mon_event_enabled(enum resctrl_event_i= d evtid) return evtid < QOS_NUM_EVENTS && mon_event_all[evtid].enabled; } =20 +enum resctrl_event_id resctrl_get_mon_event_by_name(char *name) +{ + enum resctrl_event_id evt; + + for (evt =3D 0; evt < QOS_NUM_EVENTS; evt++) + if (mon_event_all[evt].name && !strcmp(name, mon_event_all[evt].name)) + return evt; + + return -EINVAL; +} + +char *resctrl_mon_event_name(enum resctrl_event_id evt) +{ + return evt < QOS_NUM_EVENTS && mon_event_all[evt].name ? mon_event_all[ev= t].name : "unknown"; +} + /* * Initialize the event list for the resource. * --=20 2.48.1 From nobody Fri Dec 19 19:02:40 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) (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 A56D770813 for ; Tue, 29 Apr 2025 00:34:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745886853; cv=none; b=PYQgNG002XYuuOJ8jqaSQmQrwT+ergioT/ABjLU7YvgP97x+aeNWU+7IhTi/OK6cJj/WV5kbsn8XJ4/yoH2xU6XaRIBfyUy/dKKe/RrsYqBAvOwJBTSfPaJpbHoxft7mPninGqb4Yo93TBHCwx3nYGRnzt7yfwojVqc1mNBiCsg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745886853; c=relaxed/simple; bh=L1d/vvYdkqDxKWY4/nne6uJtR33vIUzSRBs3GCk6o/w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uCQXqi/T5VCjLeOB5y41agBum94XyygSanvc8hGsPIlth9OZbsAJfvflF6oUa86zHv1yl+9ChwQ6Y/ym24F9N3CPAeoznv3GWXXiPcGapiJPNouMIZ9UIVkfIONoQlcFq9q/IyBClgc8x1xbicNCkajlEwgKNOK4rQhREjLgj0M= 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=SwnShG5v; arc=none smtp.client-ip=192.198.163.9 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="SwnShG5v" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1745886851; x=1777422851; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=L1d/vvYdkqDxKWY4/nne6uJtR33vIUzSRBs3GCk6o/w=; b=SwnShG5vdPTsnwig3+XO6Pymr4X5LQ8SlBqEL7d8vaHVnbRZhI/Z+RT7 9d502ogcSFk+dm7Zsxm7BaH0wZMF8wGPDC0ZHZsnJLjYAuMNUC3DrsOsC Xb/wDGdRJ+Oq9eXYaNc1QL+iKvoWO59IGVmFNwyuyVb8040vFtIjN1KRQ M1e75qwl7GOTxjQk+BVkDqWS75IoJtifA4USzcXp8XiHtmMFMYr1I4J1d efClIuAp13gEZHtJW1FvT6vgnuq5jp4NxfnfvTzx+bxUK8Kc8/ej6dFb0 vNlwgV1X5azjJ3xJh98bXSSRJ+BGr8gegpJCij72bUMpU45GhJpcWL62+ A==; X-CSE-ConnectionGUID: Fl6tXGPwRAKs0PHgaWTVGQ== X-CSE-MsgGUID: Nkmun5jjS6KrXTZasuFAMg== X-IronPort-AV: E=McAfee;i="6700,10204,11417"; a="58148059" X-IronPort-AV: E=Sophos;i="6.15,247,1739865600"; d="scan'208";a="58148059" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2025 17:34:09 -0700 X-CSE-ConnectionGUID: p29M5rZHSuqVhD+JJa7eGw== X-CSE-MsgGUID: NAh4lRZmSn2gkE6Qqvy+tg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,247,1739865600"; d="scan'208";a="133393964" Received: from agluck-desk3.sc.intel.com ([172.25.222.70]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2025 17:34:08 -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 v4 04/31] fs/resctrl: Change how and when events are initialized Date: Mon, 28 Apr 2025 17:33:30 -0700 Message-ID: <20250429003359.375508-5-tony.luck@intel.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250429003359.375508-1-tony.luck@intel.com> References: <20250429003359.375508-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" Existing code assumes that all monitor events are associated with the RDT_RESOURCE_L3 resource. Also that all event enumeration is complete during early resctrl initialization. Neither of these assumptions remain true for new events. Each resource must include a list of enabled events that is used to add appropriately named files when creating mon_data directories and to for the contents of "info/{resource}_MON/mon_features" file. Move the building of enabled event lists for each resource from resctrl_mon_resource_init() to rdt_get_tree() to delay it until mount of the resctrl file system. Add a new field to struct mon_evt to record which resource each event is associated with so that events are added to the correct resource event list. Signed-off-by: Tony Luck --- fs/resctrl/internal.h | 4 ++++ fs/resctrl/monitor.c | 33 ++++++++++++++++++++++----------- fs/resctrl/rdtgroup.c | 2 ++ 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/fs/resctrl/internal.h b/fs/resctrl/internal.h index 6029b3285dd3..b69170760316 100644 --- a/fs/resctrl/internal.h +++ b/fs/resctrl/internal.h @@ -68,6 +68,7 @@ static inline struct rdt_fs_context *rdt_fc2context(struc= t fs_context *fc) /** * struct mon_evt - Entry in the event list of a resource * @evtid: event id + * @rid: index of the resource for this event * @name: name of the event * @configurable: true if the event is configurable * @enabled: true if the event is enabled @@ -75,6 +76,7 @@ static inline struct rdt_fs_context *rdt_fc2context(struc= t fs_context *fc) */ struct mon_evt { enum resctrl_event_id evtid; + enum resctrl_res_level rid; char *name; bool configurable; bool enabled; @@ -397,6 +399,8 @@ enum resctrl_event_id resctrl_get_mon_event_by_name(cha= r *name); =20 char *resctrl_mon_event_name(enum resctrl_event_id evt); =20 +void resctrl_init_mon_events(void); + #ifdef CONFIG_RESCTRL_FS_PSEUDO_LOCK int rdtgroup_locksetup_enter(struct rdtgroup *rdtgrp); =20 diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c index 625cd328c790..a5a523f73249 100644 --- a/fs/resctrl/monitor.c +++ b/fs/resctrl/monitor.c @@ -845,14 +845,17 @@ 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, }, }; =20 @@ -886,21 +889,31 @@ char *resctrl_mon_event_name(enum resctrl_event_id ev= t) } =20 /* - * Initialize the event list for the resource. + * Initialize the event list for all mon_capable resources. * - * 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. + * Called on each mount of the resctrl file system when all + * events have been enumerated. Only needs to build the per-resource + * event lists once. */ -static void l3_mon_evt_init(struct rdt_resource *r) +void resctrl_init_mon_events(void) { enum resctrl_event_id evt; + struct rdt_resource *r; + static bool only_once; + + if (only_once) + return; + only_once =3D true; =20 - INIT_LIST_HEAD(&r->evt_list); + for_each_mon_capable_rdt_resource(r) + INIT_LIST_HEAD(&r->evt_list); =20 - for (evt =3D 0; evt < QOS_NUM_EVENTS; evt++) - if (mon_event_all[evt].enabled) - list_add_tail(&mon_event_all[evt].list, &r->evt_list); + for (evt =3D 0; evt < QOS_NUM_EVENTS; evt++) { + if (!mon_event_all[evt].enabled) + continue; + r =3D resctrl_arch_get_resource(mon_event_all[evt].rid); + list_add_tail(&mon_event_all[evt].list, &r->evt_list); + } } =20 /** @@ -927,8 +940,6 @@ 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)) { mon_event_all[QOS_L3_MBM_TOTAL_EVENT_ID].configurable =3D true; resctrl_file_fflags_init("mbm_total_bytes_config", diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index c06752dfcb7c..e66dc041be5f 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -2591,6 +2591,8 @@ static int rdt_get_tree(struct fs_context *fc) goto out; } =20 + resctrl_init_mon_events(); + ret =3D rdtgroup_setup_root(ctx); if (ret) goto out; --=20 2.48.1 From nobody Fri Dec 19 19:02:40 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) (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 26A7481ACA for ; Tue, 29 Apr 2025 00:34:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745886853; cv=none; b=Xsm5o5nJVaWmc8seBzjyKzGklLRVieCT5gLWZM01nbBnB6CCjYYtK25lPborA4Q3WUQowvOTlCtDl5XjSxLP7SvsLO92HUBxYv5Cb02MMrZXDTMOSNxJLfwVXZvJxzNK0QlQgGWqo9xrSD0SGRLtYH2DcaX6i3Cr0tH4EjfPaRI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745886853; c=relaxed/simple; bh=PSGSVPL1y5gfIEsTCyHzQWhaIEhLiR5vVHdcdEvaO4o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iPskdxSRZRiwjQTby9gPkL5Ld5sfsdKOw9NFp6uWK3SvJeTkwV39In9pg+2beYpbXIvxppCfPawpd800HzeLz5tE9p24W9FagLmigDQBfD+oXqnw90dMK5Ja7pWrkf793uYbrmFGAy+OTEFXOe32li4xQUqwnVP/BeZKkLyeg1A= 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=KtqaYqIL; arc=none smtp.client-ip=192.198.163.9 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="KtqaYqIL" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1745886852; x=1777422852; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=PSGSVPL1y5gfIEsTCyHzQWhaIEhLiR5vVHdcdEvaO4o=; b=KtqaYqIL03thIrs3XKMtEFB+qO5xpUpag1Sk9eaA36hLiIVUXMaa4228 tkgA6yFem5rPElpWsVhznnde6b9T1vIf5niNw6QOzMyhEYhufh5LteM5T o5IRzW35sr2nT34ArLR8qGjxUvjiqJ1zO5Macu5csC1vr+YTq5Fh98dwH NrMZYmc43mwiWsOcHfRT+3bTZcycSEyhLKeY8kzzwxlGaQFlF52bEnYYE wqTOGjeTK8dtc2GmrUApsTQdEbPkjbXwFzCSAi8AQUPZrcpRRANENDtOS x9NlHiCwKj8+YDCN4sciin0F3Dvh3tljOiAUe96yGatpO4MiyiyFsXlD0 Q==; X-CSE-ConnectionGUID: 11SmuzqWQniaAODfIdiPjA== X-CSE-MsgGUID: WBG8zLqoSzWAxEzf7zXGdw== X-IronPort-AV: E=McAfee;i="6700,10204,11417"; a="58148073" X-IronPort-AV: E=Sophos;i="6.15,247,1739865600"; d="scan'208";a="58148073" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2025 17:34:10 -0700 X-CSE-ConnectionGUID: mSmTnzVlQI+ECmkty2vR+w== X-CSE-MsgGUID: d0IezkNwQZ2WHTDy4dpwFg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,247,1739865600"; d="scan'208";a="133393967" Received: from agluck-desk3.sc.intel.com ([172.25.222.70]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2025 17:34:09 -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 v4 05/31] fs/resctrl: Set up Kconfig options for telemetry events Date: Mon, 28 Apr 2025 17:33:31 -0700 Message-ID: <20250429003359.375508-6-tony.luck@intel.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250429003359.375508-1-tony.luck@intel.com> References: <20250429003359.375508-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" Intel RMID based telemetry events are counted by each CPU core and then aggregated by one or more per-socket micro controllers. Enumeration support is provided by the Intel PMT subsystem. N.B. Patches for the Intel PMT system are still in progress. They will define an INTEL_PMT_DISCOVERY Kconfig symbol that will be one of the dependencies. This is commented out for now. Final version will include this dependency. arch/x86 selects this option based on: X86_64: Counter registers are in MMIO space. There is no readq() function on 32-bit. Emulation is possible with readl(), but there are races. Running 32-bit kernels on systems that support this feature seems pointless. CPU_SUP_INTEL: It is an Intel specific feature. Signed-off-by: Tony Luck --- arch/x86/Kconfig | 1 + drivers/platform/x86/intel/pmt/Kconfig | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 5a09acf41c8e..19107fdb4264 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -508,6 +508,7 @@ config X86_CPU_RESCTRL bool "x86 CPU resource control support" depends on X86 && (CPU_SUP_INTEL || CPU_SUP_AMD) depends on MISC_FILESYSTEMS + select INTEL_AET_RESCTRL if (X86_64 && CPU_SUP_INTEL) select ARCH_HAS_CPU_RESCTRL select RESCTRL_FS select RESCTRL_FS_PSEUDO_LOCK diff --git a/drivers/platform/x86/intel/pmt/Kconfig b/drivers/platform/x86/= intel/pmt/Kconfig index e916fc966221..3a8ce39d1004 100644 --- a/drivers/platform/x86/intel/pmt/Kconfig +++ b/drivers/platform/x86/intel/pmt/Kconfig @@ -38,3 +38,10 @@ config INTEL_PMT_CRASHLOG =20 To compile this driver as a module, choose M here: the module will be called intel_pmt_crashlog. + +config INTEL_AET_RESCTRL + depends on INTEL_PMT_TELEMETRY # && INTEL_PMT_DISCOVERY + bool + help + Architecture config should "select" this option to enable + support for RMID telemetry events in the resctrl file system. --=20 2.48.1 From nobody Fri Dec 19 19:02:40 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) (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 CFCBE3987D for ; Tue, 29 Apr 2025 00:34:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745886854; cv=none; b=Mu2UAzF6F6unuMAI4fTLI0fYMqs97ev6MzSDOs8X20lwldlQKZeM9pO+ogiEseNJIOVlmWh3mZcIDGgxrq/66g01ELqJANzYFIZQ7tKh+HeJZhzNqQOoaj8ujdt3vqWLUquaHFmVw56yyWjRcSRSVhv4VY6U+dLD/n8tGBCfW5w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745886854; c=relaxed/simple; bh=wBb9GwKHIUYlO1CDbQXU4jruUv6TDbNAHBV1Nlfa4UE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ft6BF8i6ySdpnmoYreanu9ONoBH7fHwliNQ0Kv4fTTSyDxnHacKB9quhkEGOFStzeWRKH7IQ890KqTihAHkdrGmYQQs+QDqSeLk0rkodQQnxBy7QcWpmhxOg3K+lM2Lnye/9aIatLrpk2BBT4VFMlDRShl3vOglDGAIOE7TI/VY= 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=CbwXZE7v; arc=none smtp.client-ip=192.198.163.9 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="CbwXZE7v" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1745886853; x=1777422853; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=wBb9GwKHIUYlO1CDbQXU4jruUv6TDbNAHBV1Nlfa4UE=; b=CbwXZE7vOtgoGUCqVRCHZa9Yp11/QID+XexcsjrbI7t5qGW2Wy3oyfMc Rrd4uw5YhpdjeAkLxgC6IWCgRuzKu6/XuGRURCAInLwcOzsaOXWXT44KK 4N2qWGkkWMYeS2piFw6gCnYCMmuUFj3turEd9M1NLPorjyd8+aE0vkgr+ bmUINX7Co9rvW3eZm30/4+UW3PaRGtTyNhE+GSRx+IRkeZsS5d/nO5Hs2 pnb1dKJwrjnU4G4KQUFulpTzePoG0b3cfruZUZtSEO3+xF/U4+MmDvlkC laqlJ2gHefX7UAXyP0hWXrA7RfXgrsoNnD4cGHTLHKE0dNvY4ypAD8wCo Q==; X-CSE-ConnectionGUID: NX//nJXtTUqjvRVasspxSg== X-CSE-MsgGUID: TSyuiP7wRCKGXu7LOsmRXg== X-IronPort-AV: E=McAfee;i="6700,10204,11417"; a="58148084" X-IronPort-AV: E=Sophos;i="6.15,247,1739865600"; d="scan'208";a="58148084" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2025 17:34:10 -0700 X-CSE-ConnectionGUID: 24uJGXMNT/KJ2ZOnrrWqFg== X-CSE-MsgGUID: 9dxU1AMqRm2CpbClZVMBDw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,247,1739865600"; d="scan'208";a="133393970" Received: from agluck-desk3.sc.intel.com ([172.25.222.70]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2025 17:34:09 -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 v4 06/31] x86/rectrl: Fake OOBMSM interface Date: Mon, 28 Apr 2025 17:33:32 -0700 Message-ID: <20250429003359.375508-7-tony.luck@intel.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250429003359.375508-1-tony.luck@intel.com> References: <20250429003359.375508-1-tony.luck@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Real version is coming soon ... this is here so the remaining parts will build (and run ... assuming a 2 socket system that supports RDT monitoring ... only missing part is that the event counters just report fixed values). Just for ease of testing and RFC discussion. Signed-off-by: Tony Luck --- .../cpu/resctrl/fake_intel_aet_features.h | 73 ++++++++++++++ .../cpu/resctrl/fake_intel_aet_features.c | 95 +++++++++++++++++++ arch/x86/kernel/cpu/resctrl/Makefile | 1 + 3 files changed, 169 insertions(+) create mode 100644 arch/x86/kernel/cpu/resctrl/fake_intel_aet_features.h create mode 100644 arch/x86/kernel/cpu/resctrl/fake_intel_aet_features.c diff --git a/arch/x86/kernel/cpu/resctrl/fake_intel_aet_features.h b/arch/x= 86/kernel/cpu/resctrl/fake_intel_aet_features.h new file mode 100644 index 000000000000..c835c4108abc --- /dev/null +++ b/arch/x86/kernel/cpu/resctrl/fake_intel_aet_features.h @@ -0,0 +1,73 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* Bits stolen from OOBMSM VSEC discovery code */ + +enum pmt_feature_id { + FEATURE_INVALID =3D 0x0, + FEATURE_PER_CORE_PERF_TELEM =3D 0x1, + FEATURE_PER_CORE_ENV_TELEM =3D 0x2, + FEATURE_PER_RMID_PERF_TELEM =3D 0x3, + FEATURE_ACCEL_TELEM =3D 0x4, + FEATURE_UNCORE_TELEM =3D 0x5, + FEATURE_CRASH_LOG =3D 0x6, + FEATURE_PETE_LOG =3D 0x7, + FEATURE_TPMI_CTRL =3D 0x8, + FEATURE_RESERVED =3D 0x9, + FEATURE_TRACING =3D 0xA, + FEATURE_PER_RMID_ENERGY_TELEM =3D 0xB, + FEATURE_MAX =3D 0xB, +}; + +/** + * struct oobmsm_plat_info - Platform information for a device instance + * @cdie_mask: Mask of all compute dies in the partition + * @package_id: CPU Package id + * @partition: Package partition id when multiple VSEC PCI devices p= er package + * @segment: PCI segment ID + * @bus_number: PCI bus number + * @device_number: PCI device number + * @function_number: PCI function number + * + * Structure to store platform data for a OOBMSM device instance. + */ +struct oobmsm_plat_info { + u16 cdie_mask; + u8 package_id; + u8 partition; + u8 segment; + u8 bus_number; + u8 device_number; + u8 function_number; +}; + +enum oobmsm_supplier_type { + OOBMSM_SUP_PLAT_INFO, + OOBMSM_SUP_DISC_INFO, + OOBMSM_SUP_S3M_SIMICS, + OOBMSM_SUP_TYPE_MAX +}; + +struct oobmsm_mapping_supplier { + struct device *supplier_dev[OOBMSM_SUP_TYPE_MAX]; + struct oobmsm_plat_info plat_info; + unsigned long features; +}; + +struct telemetry_region { + struct oobmsm_plat_info plat_info; + void __iomem *addr; + size_t size; + u32 guid; + u32 num_rmids; +}; + +struct pmt_feature_group { + enum pmt_feature_id id; + int count; + struct kref kref; + struct telemetry_region regions[]; +}; + +struct pmt_feature_group *intel_pmt_get_regions_by_feature(enum pmt_featur= e_id id); + +void intel_pmt_put_feature_group(struct pmt_feature_group *feature_group); diff --git a/arch/x86/kernel/cpu/resctrl/fake_intel_aet_features.c b/arch/x= 86/kernel/cpu/resctrl/fake_intel_aet_features.c new file mode 100644 index 000000000000..22b7c02a538c --- /dev/null +++ b/arch/x86/kernel/cpu/resctrl/fake_intel_aet_features.c @@ -0,0 +1,95 @@ +// SPDX-License-Identifier: GPL-2.0-only +#include +#include +#include +#include "fake_intel_aet_features.h" +#include +#include + +#include "internal.h" + +/* + * Amount of memory for each fake MMIO space + * Magic numbers here match values for XML ID 0x26696143 and 0x26557651 + * 576: Number of RMIDs + * 2: Energy events in 0x26557651 + * 7: Perf events in 0x26696143 + * 3: Qwords for status counters after the event counters + * 8: Bytes for each counter + */ + +#define ENERGY_QWORDS ((576 * 2) + 3) +#define ENERGY_SIZE (ENERGY_QWORDS * 8) +#define PERF_QWORDS ((576 * 7) + 3) +#define PERF_SIZE (PERF_QWORDS * 8) + +static long pg[4 * ENERGY_QWORDS + 2 * PERF_QWORDS]; + +/* + * Fill the fake MMIO space with all different values, + * all with BIT(63) set to indicate valid entries. + */ +static int __init fill(void) +{ + u64 val =3D 0; + + for (int i =3D 0; i < sizeof(pg); i +=3D sizeof(val)) { + pg[i / sizeof(val)] =3D BIT_ULL(63) + val; + val++; + } + return 0; +} +device_initcall(fill); + +#define PKG_REGION(_entry, _guid, _addr, _size, _pkg, _num_rmids) \ + [_entry] =3D { .guid =3D _guid, .addr =3D (void __iomem *)_addr, \ + .num_rmids =3D _num_rmids, \ + .size =3D _size, .plat_info =3D { .package_id =3D _pkg }} + +/* + * Set up a fake return for call to: + * intel_pmt_get_regions_by_feature(FEATURE_PER_RMID_ENERGY_TELEM); + * Pretend there are two aggregators on each of the sockets to test + * the code that sums over multiple aggregators. + */ +static struct pmt_feature_group fake_energy =3D { + .count =3D 4, + .regions =3D { + PKG_REGION(0, 0x26696143, &pg[0 * ENERGY_QWORDS], ENERGY_SIZE, 0, 64), + PKG_REGION(1, 0x26696143, &pg[1 * ENERGY_QWORDS], ENERGY_SIZE, 0, 64), + PKG_REGION(2, 0x26696143, &pg[2 * ENERGY_QWORDS], ENERGY_SIZE, 1, 64), + PKG_REGION(3, 0x26696143, &pg[3 * ENERGY_QWORDS], ENERGY_SIZE, 1, 64) + } +}; + +/* + * Fake return for: + * intel_pmt_get_regions_by_feature(FEATURE_PER_RMID_PERF_TELEM); + */ +static struct pmt_feature_group fake_perf =3D { + .count =3D 2, + .regions =3D { + PKG_REGION(0, 0x26557651, &pg[4 * ENERGY_QWORDS + 0 * PERF_QWORDS], PERF= _SIZE, 0, 576), + PKG_REGION(1, 0x26557651, &pg[4 * ENERGY_QWORDS + 1 * PERF_QWORDS], PERF= _SIZE, 1, 576) + } +}; + +struct pmt_feature_group * +intel_pmt_get_regions_by_feature(enum pmt_feature_id id) +{ + switch (id) { + case FEATURE_PER_RMID_ENERGY_TELEM: + return &fake_energy; + case FEATURE_PER_RMID_PERF_TELEM: + return &fake_perf; + default: + return ERR_PTR(-ENOENT); + } +} + +/* + * Nothing needed for the "put" function. + */ +void intel_pmt_put_feature_group(struct pmt_feature_group *feature_group) +{ +} diff --git a/arch/x86/kernel/cpu/resctrl/Makefile b/arch/x86/kernel/cpu/res= ctrl/Makefile index d8a04b195da2..28ae1c88b2ac 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_INTEL_AET_RESCTRL) +=3D fake_intel_aet_features.o obj-$(CONFIG_RESCTRL_FS_PSEUDO_LOCK) +=3D pseudo_lock.o =20 # To allow define_trace.h's recursive include: --=20 2.48.1 From nobody Fri Dec 19 19:02:40 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) (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 90FAC13D893 for ; Tue, 29 Apr 2025 00:34:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745886856; cv=none; b=u/Q6K7FawMRyTxHtuztJ79FmMRoY2t6CCaXQtnXhVbdwZPNIqGAZqgZV+a7r2Z8D0xO0xe+rhpxDDWvvfaLIBkoqZIAgcKQ0cAeL0mafXcHYcj2lINCaFWrstbvQSVki1HwZck5/siWqb71dZ1l+LZdGZyoI6KCMqqPkkCyz614= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745886856; c=relaxed/simple; bh=XdBbnNk26unl/dT0dgAYz9UaGNxAlb+T4myEQeuJLsY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dvOL9UgiBR2WLHfnXMZlVAwC16C6jskopjDEm/4USOWA85QvXHKzP4XrRPeSPVyrIe072OrwM67g0TvpEchjuYpibFzO9JbrIgXhse87vB9PFPtqDCMqdQKWqXEIgP4ThQmcGXxcKgq76tBo+y8wRJ6gKcPKnbxIrwuM7KMrOV4= 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=UkctVA4K; arc=none smtp.client-ip=192.198.163.9 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="UkctVA4K" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1745886853; x=1777422853; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=XdBbnNk26unl/dT0dgAYz9UaGNxAlb+T4myEQeuJLsY=; b=UkctVA4KZXh6J1eqSjaAZij6E2StQovvy+nbOcWw/ncUVNw1QwrYB7s4 qADfNkeE2xKIKiBHOYcuLgAyTOoJMnpAbiJYj2D8Yw+beGxuFnBei3OqK fanZMvM0rf4cV1BZ3THZGRhzZUXeQHVZxiA4HeBR3JXkyprfwmpEQ+xvP WNzS9sWx6WaVqIkwL6vZ1HoGMBNCVCoQMHdxGEWJfNw78jUdAK+aEUmdq mL/SMjqCWfGY9rHkgwmnQCzdSSNrH0AdzO11Nzk6nUTV065PMzQkMNQ7N c3M/wa8iJ+1ijTBQG3oeS/0JpQZkdLbBsEkj4do7j0852qhiLyJVTSTQd w==; X-CSE-ConnectionGUID: x/21Of/mQHqjgTstiJ/l5w== X-CSE-MsgGUID: 3cP1f/jESmGooqDIA/5Q2A== X-IronPort-AV: E=McAfee;i="6700,10204,11417"; a="58148095" X-IronPort-AV: E=Sophos;i="6.15,247,1739865600"; d="scan'208";a="58148095" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2025 17:34:11 -0700 X-CSE-ConnectionGUID: wkO7nFdURt+1Nnqy5BIYiA== X-CSE-MsgGUID: s2fjPK8dTpG++tQRy+COIw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,247,1739865600"; d="scan'208";a="133393976" Received: from agluck-desk3.sc.intel.com ([172.25.222.70]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2025 17:34:10 -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 v4 07/31] x86,fs/resctrl: Improve domain type checking Date: Mon, 28 Apr 2025 17:33:33 -0700 Message-ID: <20250429003359.375508-8-tony.luck@intel.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250429003359.375508-1-tony.luck@intel.com> References: <20250429003359.375508-1-tony.luck@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The rdt_domain_hdr structure is used in both control and monitor domain structures to provide common methods for operations such as adding a CPU to a domain, removing a CPU from a domain, accessing the mask of all CPUs in a domain. The "type" field provides a simple check whether a domain is a control or monitor domain so that programming errors operating on domains will be quickly caught. To prepare for additional domain types that depend on the rdt_resource to which they are connected add the resource id into the header and check that in addition to the type. Signed-off-by: Tony Luck --- include/linux/resctrl.h | 9 +++++++++ arch/x86/kernel/cpu/resctrl/core.c | 10 ++++++---- fs/resctrl/ctrlmondata.c | 2 +- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index cef9b0ed984c..e700f58b5af5 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 check_domain_header(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 e5c91d21e8f7..bdd4d08a3912 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -456,7 +456,7 @@ static void domain_add_cpu_ctrl(int cpu, struct rdt_res= ource *r) =20 hdr =3D resctrl_find_domain(&r->ctrl_domains, id, &add_pos); if (hdr) { - if (WARN_ON_ONCE(hdr->type !=3D RESCTRL_CTRL_DOMAIN)) + if (check_domain_header(hdr, RESCTRL_CTRL_DOMAIN, r->rid)) return; d =3D container_of(hdr, struct rdt_ctrl_domain, hdr); =20 @@ -473,6 +473,7 @@ static void domain_add_cpu_ctrl(int cpu, struct rdt_res= ource *r) d =3D &hw_dom->d_resctrl; d->hdr.id =3D id; d->hdr.type =3D RESCTRL_CTRL_DOMAIN; + d->hdr.rid =3D r->rid; cpumask_set_cpu(cpu, &d->hdr.cpu_mask); =20 rdt_domain_reconfigure_cdp(r); @@ -511,7 +512,7 @@ static void domain_add_cpu_mon(int cpu, struct rdt_reso= urce *r) =20 hdr =3D resctrl_find_domain(&r->mon_domains, id, &add_pos); if (hdr) { - if (WARN_ON_ONCE(hdr->type !=3D RESCTRL_MON_DOMAIN)) + if (check_domain_header(hdr, RESCTRL_MON_DOMAIN, r->rid)) return; d =3D container_of(hdr, struct rdt_mon_domain, hdr); =20 @@ -526,6 +527,7 @@ static void domain_add_cpu_mon(int cpu, struct rdt_reso= urce *r) d =3D &hw_dom->d_resctrl; d->hdr.id =3D id; d->hdr.type =3D RESCTRL_MON_DOMAIN; + d->hdr.rid =3D r->rid; d->ci =3D get_cpu_cacheinfo_level(cpu, RESCTRL_L3_CACHE); if (!d->ci) { pr_warn_once("Can't find L3 cache for CPU:%d resource %s\n", cpu, r->nam= e); @@ -581,7 +583,7 @@ static void domain_remove_cpu_ctrl(int cpu, struct rdt_= resource *r) return; } =20 - if (WARN_ON_ONCE(hdr->type !=3D RESCTRL_CTRL_DOMAIN)) + if (check_domain_header(hdr, RESCTRL_CTRL_DOMAIN, r->rid)) return; =20 d =3D container_of(hdr, struct rdt_ctrl_domain, hdr); @@ -627,7 +629,7 @@ static void domain_remove_cpu_mon(int cpu, struct rdt_r= esource *r) return; } =20 - if (WARN_ON_ONCE(hdr->type !=3D RESCTRL_MON_DOMAIN)) + if (check_domain_header(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 53388281ff7d..3cbacfe52430 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) * 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 || check_domain_header(hdr, RESCTRL_MON_DOMAIN, r->rid)) { ret =3D -ENOENT; goto out; } --=20 2.48.1 From nobody Fri Dec 19 19:02:40 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) (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 E248C1494C3 for ; Tue, 29 Apr 2025 00:34:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745886855; cv=none; b=s+3hDriVkZD1N1qs+62moLGls6StH5qD3KXmp665nYnWApb8G4/JFftthJb9n0i4pFyPDqp1vz0WRUMgi3ZkIs0qoxler3czZhh1DIxsRRSSkYkq5nBr9k3JXu0MaxgZulMdGqnhgUIVoekG1PwyFz8l8c3aKeMxeJkpvCRwHwA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745886855; c=relaxed/simple; bh=DXuP7E9E2VzfYvHSOVvcEpbDHa6++ujfagg1yqnmz3E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jepwud+v1b0TVPXO66P5mTmb6sXWdikcOmkXJhmCA7+BxwkBZdwQB+r/CNKvkwOm/oxsllsCdsWtyhrkPa7A4FmAAHbrRgTvBzpwU4o7PITRaIF0S4ZF001+GH/n/+TJb7ej8p4trGcd8ZbzfcTB23rsL9fg+2PAJXGgKOcI2BM= 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=l86WYI7z; arc=none smtp.client-ip=192.198.163.9 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="l86WYI7z" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1745886854; x=1777422854; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=DXuP7E9E2VzfYvHSOVvcEpbDHa6++ujfagg1yqnmz3E=; b=l86WYI7zil8aAd/HLV0LwS6qKPwkuI/jS89dy0dHI096KsTpmD67xucM hhULVhwBFwr3Z8CRc9CiVniijwzxSV0nXV/esHDSqe+Leq8AvTR3M18OB K1werTx8Fwd681h2H+MlCxnf8nj96A7ySYuOLWlXBBYaMJVVBdI/ZnaBv d4HT4c5NyD24hx/4hrVUbb0z1quUXLGtQbE2YcEhpjqzNZGTO13MunMzl L3gwE899L9WE4P8QOASupdTEK9Ps187Uz05Zv5qEF1nutZhXag3Tz6scZ ozNFk9i9+P+VbOM/9+MRG1ed8lSx3KWCro0F9lbwgUdJaNNJLHXDaWhSF Q==; X-CSE-ConnectionGUID: OS3OrHdiTUW2MJxfFkkNpw== X-CSE-MsgGUID: 8AobsLB1RKKuhKagAaHI4g== X-IronPort-AV: E=McAfee;i="6700,10204,11417"; a="58148106" X-IronPort-AV: E=Sophos;i="6.15,247,1739865600"; d="scan'208";a="58148106" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2025 17:34:11 -0700 X-CSE-ConnectionGUID: g2/CXFh+S/e4IzNkvsvsog== X-CSE-MsgGUID: 9Dfxd0bVTdSVw4ic/XwhvQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,247,1739865600"; d="scan'208";a="133393981" Received: from agluck-desk3.sc.intel.com ([172.25.222.70]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2025 17:34:11 -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 v4 08/31] x86/resctrl: Move L3 initialization out of domain_add_cpu_mon() Date: Mon, 28 Apr 2025 17:33:34 -0700 Message-ID: <20250429003359.375508-9-tony.luck@intel.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250429003359.375508-1-tony.luck@intel.com> References: <20250429003359.375508-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 specific initialization into a helper function. Rename several functions to mark that they are specific to the L3 path. arch_mon_domain_online -> arch_l3_mon_domain_online mon_domain_free -> free_l3_mon_domain arch_mon_domain_online -> arch_l3_mon_domain_online domain_setup_mon_state -> domain_setup_l3_mon_state resctrl_online_mon_domain() is going to share some code with new reources, so keeps the same name, but include a check for RDT_RESOURCE_L3. Signed-off-by: Tony Luck --- arch/x86/kernel/cpu/resctrl/internal.h | 2 +- arch/x86/kernel/cpu/resctrl/core.c | 69 +++++++++++++++----------- arch/x86/kernel/cpu/resctrl/monitor.c | 2 +- fs/resctrl/rdtgroup.c | 11 ++-- 4 files changed, 50 insertions(+), 34 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/r= esctrl/internal.h index 02b535c828f3..b563406b4996 100644 --- a/arch/x86/kernel/cpu/resctrl/internal.h +++ b/arch/x86/kernel/cpu/resctrl/internal.h @@ -122,7 +122,7 @@ static inline struct rdt_hw_resource *resctrl_to_arch_r= es(struct rdt_resource *r =20 extern struct rdt_hw_resource rdt_resources_all[]; =20 -void arch_mon_domain_online(struct rdt_resource *r, struct rdt_mon_domain = *d); +void arch_l3_mon_domain_online(struct rdt_resource *r, struct rdt_mon_doma= in *d); =20 /* CPUID.(EAX=3D10H, ECX=3DResID=3D1).EAX */ union cpuid_0x10_1_eax { diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resct= rl/core.c index bdd4d08a3912..d48cdc85a86d 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -362,7 +362,7 @@ static void ctrl_domain_free(struct rdt_hw_ctrl_domain = *hw_dom) kfree(hw_dom); } =20 -static void mon_domain_free(struct rdt_hw_mon_domain *hw_dom) +static void free_l3_mon_domain(struct rdt_hw_mon_domain *hw_dom) { for (int i =3D 0; i < QOS_NUM_MBM_EVENTS; i++) kfree(hw_dom->arch_mbm_states[i]); @@ -493,33 +493,12 @@ static void domain_add_cpu_ctrl(int cpu, struct rdt_r= esource *r) } } =20 -static void domain_add_cpu_mon(int cpu, struct rdt_resource *r) +static void setup_l3_mon_domain(int cpu, int id, struct rdt_resource *r, s= truct list_head *add_pos) { - int id =3D get_domain_id_from_scope(cpu, r->mon_scope); - struct list_head *add_pos =3D NULL; struct rdt_hw_mon_domain *hw_dom; - struct rdt_domain_hdr *hdr; struct rdt_mon_domain *d; int err; =20 - lockdep_assert_held(&domain_list_lock); - - if (id < 0) { - pr_warn_once("Can't find monitor domain id for CPU:%d scope:%d for resou= rce %s\n", - cpu, r->mon_scope, r->name); - return; - } - - hdr =3D resctrl_find_domain(&r->mon_domains, id, &add_pos); - if (hdr) { - if (check_domain_header(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; @@ -531,15 +510,15 @@ static void domain_add_cpu_mon(int cpu, struct rdt_re= source *r) d->ci =3D get_cpu_cacheinfo_level(cpu, RESCTRL_L3_CACHE); if (!d->ci) { pr_warn_once("Can't find L3 cache for CPU:%d resource %s\n", cpu, r->nam= e); - mon_domain_free(hw_dom); + free_l3_mon_domain(hw_dom); return; } cpumask_set_cpu(cpu, &d->hdr.cpu_mask); =20 - arch_mon_domain_online(r, d); + arch_l3_mon_domain_online(r, d); =20 if (arch_domain_mbm_alloc(r->num_rmid, hw_dom)) { - mon_domain_free(hw_dom); + free_l3_mon_domain(hw_dom); return; } =20 @@ -549,7 +528,41 @@ static void domain_add_cpu_mon(int cpu, struct rdt_res= ource *r) if (err) { list_del_rcu(&d->hdr.list); synchronize_rcu(); - mon_domain_free(hw_dom); + free_l3_mon_domain(hw_dom); + } +} + +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; + struct rdt_mon_domain *d; + + 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 (check_domain_header(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; + } + + switch (r->rid) { + case RDT_RESOURCE_L3: + setup_l3_mon_domain(cpu, id, r, add_pos); + break; + default: + WARN_ON_ONCE(1); } } =20 @@ -640,7 +653,7 @@ static void domain_remove_cpu_mon(int cpu, struct rdt_r= esource *r) resctrl_offline_mon_domain(r, d); list_del_rcu(&d->hdr.list); synchronize_rcu(); - mon_domain_free(hw_dom); + free_l3_mon_domain(hw_dom); =20 return; } diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/re= sctrl/monitor.c index bf7fde07846b..d1f659dd6109 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -271,7 +271,7 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, stru= ct rdt_mon_domain *d, * must adjust RMID counter numbers based on SNC node. See * logical_rmid_to_physical_rmid() for code that does this. */ -void arch_mon_domain_online(struct rdt_resource *r, struct rdt_mon_domain = *d) +void arch_l3_mon_domain_online(struct rdt_resource *r, struct rdt_mon_doma= in *d) { if (snc_nodes_per_l3_cache > 1) msr_clear_bit(MSR_RMID_SNC_CONFIG, 0); diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index e66dc041be5f..a0d2be84832c 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -4063,7 +4063,7 @@ void resctrl_offline_mon_domain(struct rdt_resource *= r, struct rdt_mon_domain *d } =20 /** - * domain_setup_mon_state() - Initialise domain monitoring structures. + * domain_setup_l3_mon_state() - Initialise domain monitoring structures. * @r: The resource for the newly online domain. * @d: The newly online domain. * @@ -4075,7 +4075,7 @@ void resctrl_offline_mon_domain(struct rdt_resource *= r, struct rdt_mon_domain *d * * Returns 0 for success, or -ENOMEM. */ -static int domain_setup_mon_state(struct rdt_resource *r, struct rdt_mon_d= omain *d) +static int domain_setup_l3_mon_state(struct rdt_resource *r, struct rdt_mo= n_domain *d) { u32 idx_limit =3D resctrl_arch_system_num_rmid_idx(); size_t tsize =3D sizeof(struct mbm_state); @@ -4126,11 +4126,14 @@ 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_mon_domai= n *d) { - int err; + int err =3D -EINVAL; =20 mutex_lock(&rdtgroup_mutex); =20 - err =3D domain_setup_mon_state(r, d); + if (r->rid !=3D RDT_RESOURCE_L3) + goto out_unlock; + + err =3D domain_setup_l3_mon_state(r, d); if (err) goto out_unlock; =20 --=20 2.48.1 From nobody Fri Dec 19 19:02:40 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) (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 B930F1A7046 for ; Tue, 29 Apr 2025 00:34:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745886858; cv=none; b=Oa4crc4kkeVVc+QoyYi88JeXQdnYWQKk2T8dJUrMhyds9BZeBUhwNiAiHbleGM8XM6tr5DbuBCJUeW7nGZvrMzNg1HSoWmOpocuTU3hrHYJQ2ugXNEMRMlu3i8i5tFurdDrWaxWytFYbrtvrOTHODIB16xSj6tcNOJZyEP+1/3w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745886858; c=relaxed/simple; bh=aZLZ0EH5C41avMnEPqdeWhsl/dnt2eLJe5QUYjid18Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Hgp6NvfJZ5Ct7KYrk+HRFtcRVoktYoUX9p1EKQZ024cj8TJL2vO/4an1z3RglCOlBbt6dYtqDhZFsfJDf6kezx53EtGP09A7xTFr3q8cxNJSHx9M+p8sOzI47cZlrIQif6292soo0hot/6BZ5tfOgwU0MMmM/X+dbHOeGeai7TY= 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=HZRD9U8p; arc=none smtp.client-ip=192.198.163.9 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="HZRD9U8p" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1745886856; x=1777422856; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=aZLZ0EH5C41avMnEPqdeWhsl/dnt2eLJe5QUYjid18Y=; b=HZRD9U8pdtUDBYaVmn57Hd1kbCk5flepr2sVe7H2eV7CKyhrOi6xsXgS BewZB59/vEg5SPIXhGT9rmeO5fbK9nE58oySK46xdyU8158ANQfvaxARF +jDR9p9LFrM9ow9RoSL7n9BK3Obtc+ILumiovfw9wPMPjvTLi5LckAwDV HZewbgnVMGJD0nKvKLrlZvK51t78UTUCnB9tj5qp8Le9u+8tCIQB9WAkU 4l97bpW1n9HrQ8sTGKvOoeZODtMykpeFNjzZQ6PeDp7H3nH/jSa5iMv51 7Q6SCFKqPEJUgv+WmRigGy3h6JASeLrYDpspz7eerlvi8CxLgROGFGEkf A==; X-CSE-ConnectionGUID: 6DAgm/v/R8CUrzVC22YxGg== X-CSE-MsgGUID: scRUUS45RtG5YnD7Fn/0hw== X-IronPort-AV: E=McAfee;i="6700,10204,11417"; a="58148117" X-IronPort-AV: E=Sophos;i="6.15,247,1739865600"; d="scan'208";a="58148117" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2025 17:34:12 -0700 X-CSE-ConnectionGUID: LCzWPjHoQKmcjHX5ssYYQg== X-CSE-MsgGUID: SGFVKDZlTd+UlxHqh2BW5Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,247,1739865600"; d="scan'208";a="133393987" Received: from agluck-desk3.sc.intel.com ([172.25.222.70]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2025 17:34:11 -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 v4 09/31] x86,fs/resctrl: Refactor domain_remove_cpu_mon() ready for new domain types Date: Mon, 28 Apr 2025 17:33:35 -0700 Message-ID: <20250429003359.375508-10-tony.luck@intel.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250429003359.375508-1-tony.luck@intel.com> References: <20250429003359.375508-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_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 so all the L3 processing is separated from general actions of clearing the CPU bit in the mask and removing directories from mon_data. Signed-off-by: Tony Luck --- arch/x86/kernel/cpu/resctrl/core.c | 14 ++++++++------ fs/resctrl/rdtgroup.c | 5 ++++- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resct= rl/core.c index d48cdc85a86d..525439029865 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -645,17 +645,19 @@ static void domain_remove_cpu_mon(int cpu, struct rdt= _resource *r) if (check_domain_header(hdr, RESCTRL_MON_DOMAIN, r->rid)) return; =20 - d =3D container_of(hdr, struct rdt_mon_domain, hdr); - hw_dom =3D resctrl_to_arch_mon_dom(d); + cpumask_clear_cpu(cpu, &hdr->cpu_mask); + if (!cpumask_empty(&hdr->cpu_mask)) + return; =20 - cpumask_clear_cpu(cpu, &d->hdr.cpu_mask); - if (cpumask_empty(&d->hdr.cpu_mask)) { + switch (r->rid) { + case RDT_RESOURCE_L3: + d =3D container_of(hdr, struct rdt_mon_domain, hdr); + hw_dom =3D resctrl_to_arch_mon_dom(d); resctrl_offline_mon_domain(r, d); list_del_rcu(&d->hdr.list); synchronize_rcu(); free_l3_mon_domain(hw_dom); - - return; + break; } } =20 diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index a0d2be84832c..a65f3e16bdab 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -4042,6 +4042,9 @@ void resctrl_offline_mon_domain(struct rdt_resource *= r, struct rdt_mon_domain *d if (resctrl_mounted && resctrl_arch_mon_capable()) rmdir_mondata_subdir_allrdtgrp(r, d); =20 + if (r->rid !=3D RDT_RESOURCE_L3) + goto done; + if (resctrl_is_mbm_enabled()) cancel_delayed_work(&d->mbm_over); if (resctrl_is_mon_event_enabled(QOS_L3_OCCUP_EVENT_ID) && has_busy_rmid(= d)) { @@ -4058,7 +4061,7 @@ void resctrl_offline_mon_domain(struct rdt_resource *= r, struct rdt_mon_domain *d } =20 domain_destroy_mon_state(d); - +done: mutex_unlock(&rdtgroup_mutex); } =20 --=20 2.48.1 From nobody Fri Dec 19 19:02:40 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) (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 BDA661C3F02 for ; Tue, 29 Apr 2025 00:34:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745886859; cv=none; b=pjNnTokaBJUJEki0hesuYGZofO45OPf77eWdvvJEODQ6ksmVu8AyJSNSGjlsss05tCwrPXJ7xZ2xpkfLHEkQe+g13dCjjvEr8Uh0Chs/l1POanIZ1ufx8so5LnS6ixnkHd6SpHMV5YeaW8Sh9RV8Li2NemA9qAuZu3Yu+bp02Q8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745886859; c=relaxed/simple; bh=77+SDgugQw2rk4X7Ptd9s/QsMQCAFnC4x+vpVxFtxDQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Qt+8CXRB5CiMVyhbHSsbryBUKQmm0xJkR7SpuYVjLWSbcH1NGo0yyLhiOEr4BLiA2ttcvK1MOXBkyYgRE1Q+22bfZoAHuZurjHzfQFH8LOr6PtlW6/edNyY9BiwjoNzIJjRvA7F7PMLQGxYkajt+YSz7RMRMGwErNhLwiQBZpKQ= 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=GPnLQV61; arc=none smtp.client-ip=192.198.163.9 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="GPnLQV61" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1745886857; x=1777422857; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=77+SDgugQw2rk4X7Ptd9s/QsMQCAFnC4x+vpVxFtxDQ=; b=GPnLQV61cPSJompe4H5ujzpDHHZaceKqcpawjWDkoMIwabmmWW2PzLib /JNK5ebik0BNCMV5rRaE9dk43OQ4/aiXzMjOjAiznYXm0QfiJGTYtPf91 dTKZrtmflkdEK71kp9GYETgXVzswpD+aY3zGYj5MKA9+h3LB/6bVFJnMz 7bk2opSM23nmbKiJ4AuYP+HfbefX6Sw3k27xajJuLHonA+WVBzGxCfz84 Wmx0DiIQy5XnrZjCiCpcvw38P4HLeb6/nmxYZqAqgGw4oDBkD/WFdVdHI GoNmu3sQHFzHAC/DbzbjdlqgmRtoAEg1SgsLvYvfMPCrrzv27guYIcOhU w==; X-CSE-ConnectionGUID: 5SW/IfnTRsGU8OQoZkWJSQ== X-CSE-MsgGUID: MvFStvI0T3ivt5T84RwmLg== X-IronPort-AV: E=McAfee;i="6700,10204,11417"; a="58148128" X-IronPort-AV: E=Sophos;i="6.15,247,1739865600"; d="scan'208";a="58148128" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2025 17:34:13 -0700 X-CSE-ConnectionGUID: lduUjL+XRhOXlb+ixdfLHw== X-CSE-MsgGUID: fGbVgH+6TRi4psIm2LKKug== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,247,1739865600"; d="scan'208";a="133393991" Received: from agluck-desk3.sc.intel.com ([172.25.222.70]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2025 17:34:12 -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 v4 10/31] x86/resctrl: Change generic monitor functions to use struct rdt_domain_hdr Date: Mon, 28 Apr 2025 17:33:36 -0700 Message-ID: <20250429003359.375508-11-tony.luck@intel.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250429003359.375508-1-tony.luck@intel.com> References: <20250429003359.375508-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" Functions that don't need the internal details of the rdt_mon_domain can operate on just the rdt_domain_hdr. Add sanity checks where container_of() is used to find the surrounding domain structure that hdr has the expected type. Simplify code that uses "d->hdr." to "hdr->" where possible. Signed-off-by: Tony Luck --- include/linux/resctrl.h | 4 +- arch/x86/kernel/cpu/resctrl/core.c | 19 +++---- fs/resctrl/rdtgroup.c | 82 +++++++++++++++++++++--------- 3 files changed, 68 insertions(+), 37 deletions(-) diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index e700f58b5af5..bb55c449adc4 100644 --- a/include/linux/resctrl.h +++ b/include/linux/resctrl.h @@ -444,9 +444,9 @@ int resctrl_arch_update_one(struct rdt_resource *r, str= uct rdt_ctrl_domain *d, u32 resctrl_arch_get_config(struct rdt_resource *r, struct rdt_ctrl_domain= *d, u32 closid, enum resctrl_conf_type type); int resctrl_online_ctrl_domain(struct rdt_resource *r, struct rdt_ctrl_dom= ain *d); -int resctrl_online_mon_domain(struct rdt_resource *r, struct rdt_mon_domai= n *d); +int resctrl_online_mon_domain(struct rdt_resource *r, struct rdt_domain_hd= r *hdr); void resctrl_offline_ctrl_domain(struct rdt_resource *r, struct rdt_ctrl_d= omain *d); -void resctrl_offline_mon_domain(struct rdt_resource *r, struct rdt_mon_dom= ain *d); +void resctrl_offline_mon_domain(struct rdt_resource *r, struct rdt_domain_= hdr *hdr); void resctrl_online_cpu(unsigned int cpu); void resctrl_offline_cpu(unsigned int cpu); =20 diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resct= rl/core.c index 525439029865..9c78828ae32f 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -460,7 +460,7 @@ static void domain_add_cpu_ctrl(int cpu, struct rdt_res= ource *r) return; d =3D container_of(hdr, struct rdt_ctrl_domain, hdr); =20 - cpumask_set_cpu(cpu, &d->hdr.cpu_mask); + cpumask_set_cpu(cpu, &hdr->cpu_mask); if (r->cache.arch_has_per_cpu_cfg) rdt_domain_reconfigure_cdp(r); return; @@ -524,7 +524,7 @@ static void setup_l3_mon_domain(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(); @@ -537,7 +537,6 @@ static void domain_add_cpu_mon(int cpu, struct rdt_reso= urce *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; - struct rdt_mon_domain *d; =20 lockdep_assert_held(&domain_list_lock); =20 @@ -549,11 +548,7 @@ static void domain_add_cpu_mon(int cpu, struct rdt_res= ource *r) =20 hdr =3D resctrl_find_domain(&r->mon_domains, id, &add_pos); if (hdr) { - if (check_domain_header(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); + cpumask_set_cpu(cpu, &hdr->cpu_mask); return; } =20 @@ -603,9 +598,9 @@ static void domain_remove_cpu_ctrl(int cpu, struct rdt_= resource *r) 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)) { + if (cpumask_empty(&hdr->cpu_mask)) { resctrl_offline_ctrl_domain(r, d); - list_del_rcu(&d->hdr.list); + list_del_rcu(&hdr->list); synchronize_rcu(); =20 /* @@ -653,8 +648,8 @@ static void domain_remove_cpu_mon(int cpu, struct rdt_r= esource *r) case RDT_RESOURCE_L3: d =3D container_of(hdr, struct rdt_mon_domain, hdr); hw_dom =3D resctrl_to_arch_mon_dom(d); - resctrl_offline_mon_domain(r, d); - list_del_rcu(&d->hdr.list); + resctrl_offline_mon_domain(r, hdr); + list_del_rcu(&hdr->list); synchronize_rcu(); free_l3_mon_domain(hw_dom); break; diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index a65f3e16bdab..0ec87db799b4 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -3022,7 +3022,7 @@ static void mon_rmdir_one_subdir(struct kernfs_node *= pkn, char *name, char *subn * when last domain being summed is removed. */ static void rmdir_mondata_subdir_allrdtgrp(struct rdt_resource *r, - struct rdt_mon_domain *d) + struct rdt_domain_hdr *hdr) { struct rdtgroup *prgrp, *crgrp; char subname[32]; @@ -3030,9 +3030,17 @@ static void rmdir_mondata_subdir_allrdtgrp(struct rd= t_resource *r, char name[32]; =20 snc_mode =3D r->mon_scope =3D=3D RESCTRL_L3_NODE; - sprintf(name, "mon_%s_%02d", r->name, snc_mode ? d->ci->id : d->hdr.id); - if (snc_mode) - sprintf(subname, "mon_sub_%s_%02d", r->name, d->hdr.id); + if (snc_mode) { + struct rdt_mon_domain *d; + + if (check_domain_header(hdr, RESCTRL_MON_DOMAIN, r->rid)) + return; + d =3D container_of(hdr, struct rdt_mon_domain, hdr); + sprintf(name, "mon_%s_%02d", r->name, d->ci->id); + sprintf(subname, "mon_sub_%s_%02d", r->name, hdr->id); + } else { + sprintf(name, "mon_%s_%02d", r->name, hdr->id); + } =20 list_for_each_entry(prgrp, &rdt_all_groups, rdtgroup_list) { mon_rmdir_one_subdir(prgrp->mon.mon_data_kn, name, subname); @@ -3042,11 +3050,12 @@ static void rmdir_mondata_subdir_allrdtgrp(struct r= dt_resource *r, } } =20 -static int mon_add_all_files(struct kernfs_node *kn, struct rdt_mon_domain= *d, +static int mon_add_all_files(struct kernfs_node *kn, struct rdt_domain_hdr= *hdr, struct rdt_resource *r, struct rdtgroup *prgrp, bool do_sum) { struct rmid_read rr =3D {0}; + struct rdt_mon_domain *d; struct mon_data *priv; struct mon_evt *mevt; int ret, domid; @@ -3054,8 +3063,16 @@ static int mon_add_all_files(struct kernfs_node *kn,= struct rdt_mon_domain *d, if (WARN_ON(list_empty(&r->evt_list))) return -EPERM; =20 - list_for_each_entry(mevt, &r->evt_list, list) { + if (r->rid =3D=3D RDT_RESOURCE_L3) { + if (check_domain_header(hdr, RESCTRL_MON_DOMAIN, r->rid)) + return -EINVAL; + d =3D container_of(hdr, struct rdt_mon_domain, hdr); domid =3D do_sum ? d->ci->id : d->hdr.id; + } else { + domid =3D hdr->id; + } + + list_for_each_entry(mevt, &r->evt_list, list) { priv =3D mon_get_kn_priv(r->rid, domid, mevt, do_sum); if (WARN_ON_ONCE(!priv)) return -EINVAL; @@ -3064,18 +3081,19 @@ static int mon_add_all_files(struct kernfs_node *kn= , struct rdt_mon_domain *d, if (ret) return ret; =20 - if (!do_sum && resctrl_is_mbm_event(mevt->evtid)) - mon_event_read(&rr, r, d, prgrp, &d->hdr.cpu_mask, mevt->evtid, true); + if (r->rid =3D=3D RDT_RESOURCE_L3 && !do_sum && resctrl_is_mbm_event(mev= t->evtid)) + mon_event_read(&rr, r, d, prgrp, &hdr->cpu_mask, mevt->evtid, true); } =20 return 0; } =20 static int mkdir_mondata_subdir(struct kernfs_node *parent_kn, - struct rdt_mon_domain *d, + struct rdt_domain_hdr *hdr, struct rdt_resource *r, struct rdtgroup *prgrp) { struct kernfs_node *kn, *ckn; + struct rdt_mon_domain *d; char name[32]; bool snc_mode; int ret =3D 0; @@ -3083,7 +3101,14 @@ static int mkdir_mondata_subdir(struct kernfs_node *= parent_kn, lockdep_assert_held(&rdtgroup_mutex); =20 snc_mode =3D r->mon_scope =3D=3D RESCTRL_L3_NODE; - sprintf(name, "mon_%s_%02d", r->name, snc_mode ? d->ci->id : d->hdr.id); + if (snc_mode) { + if (check_domain_header(hdr, RESCTRL_MON_DOMAIN, r->rid)) + return -EINVAL; + d =3D container_of(hdr, struct rdt_mon_domain, hdr); + sprintf(name, "mon_%s_%02d", r->name, d->ci->id); + } else { + sprintf(name, "mon_%s_%02d", r->name, hdr->id); + } kn =3D kernfs_find_and_get(parent_kn, name); if (kn) { /* @@ -3099,13 +3124,13 @@ static int mkdir_mondata_subdir(struct kernfs_node = *parent_kn, ret =3D rdtgroup_kn_set_ugid(kn); if (ret) goto out_destroy; - ret =3D mon_add_all_files(kn, d, r, prgrp, snc_mode); + ret =3D mon_add_all_files(kn, hdr, r, prgrp, snc_mode); if (ret) goto out_destroy; } =20 if (snc_mode) { - sprintf(name, "mon_sub_%s_%02d", r->name, d->hdr.id); + sprintf(name, "mon_sub_%s_%02d", r->name, hdr->id); ckn =3D kernfs_create_dir(kn, name, parent_kn->mode, prgrp); if (IS_ERR(ckn)) { ret =3D -EINVAL; @@ -3116,7 +3141,7 @@ static int mkdir_mondata_subdir(struct kernfs_node *p= arent_kn, if (ret) goto out_destroy; =20 - ret =3D mon_add_all_files(ckn, d, r, prgrp, false); + ret =3D mon_add_all_files(ckn, hdr, r, prgrp, false); if (ret) goto out_destroy; } @@ -3134,7 +3159,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; @@ -3142,12 +3167,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); } } } @@ -3156,14 +3181,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; } @@ -4031,8 +4056,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 /* @@ -4040,11 +4067,15 @@ void resctrl_offline_mon_domain(struct rdt_resource= *r, struct rdt_mon_domain *d * per domain monitor data directories. */ if (resctrl_mounted && resctrl_arch_mon_capable()) - rmdir_mondata_subdir_allrdtgrp(r, d); + rmdir_mondata_subdir_allrdtgrp(r, hdr); =20 if (r->rid !=3D RDT_RESOURCE_L3) goto done; =20 + if (check_domain_header(hdr, RESCTRL_MON_DOMAIN, r->rid)) + return; + + d =3D container_of(hdr, struct rdt_mon_domain, hdr); if (resctrl_is_mbm_enabled()) cancel_delayed_work(&d->mbm_over); if (resctrl_is_mon_event_enabled(QOS_L3_OCCUP_EVENT_ID) && has_busy_rmid(= d)) { @@ -4127,8 +4158,9 @@ 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) { + struct rdt_mon_domain *d; int err =3D -EINVAL; =20 mutex_lock(&rdtgroup_mutex); @@ -4136,6 +4168,10 @@ int resctrl_online_mon_domain(struct rdt_resource *r= , struct rdt_mon_domain *d) if (r->rid !=3D RDT_RESOURCE_L3) goto out_unlock; =20 + if (check_domain_header(hdr, RESCTRL_MON_DOMAIN, r->rid)) + return err; + + d =3D container_of(hdr, struct rdt_mon_domain, hdr); err =3D domain_setup_l3_mon_state(r, d); if (err) goto out_unlock; @@ -4156,7 +4192,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.48.1 From nobody Fri Dec 19 19:02:40 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) (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 E44261D514B for ; Tue, 29 Apr 2025 00:34:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745886861; cv=none; b=Qt5/F3SpAq8jp/uah5V57s81KX6NxuXSvpnDOedbVFHdMBez8dm8oaeFHqpWVIY5STX8KLYN6RXx35H8CwY397BuuZ2ZOn0SNwaDZFN6L8KJAI/Vd+XkC4OP07JDytcAvtH3znmhnsC2JsYex/uXztfCUiXpkARwlxOqujZSkaU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745886861; c=relaxed/simple; bh=hMRGabSCoP2Mt8bNaVEGnebNCxb8RE3JYqwt6KkURyA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DvmBbg2b/1hXNQfhiLadem6okhkqZWe9/KWUpfrJyasM4BndZS5dqqoh9/U+HpsC4nL93QmcAQfIVfoVRfmLVFVtb68kKAgp5TaqEJozHvxg32FoDnX0QcpmxiXpDkuUJ1gUEnkaZNiCAKGYUZ4FFkaoGaQ2MhzTF6JQ3qGozLY= 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=CSt90bOy; arc=none smtp.client-ip=192.198.163.9 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="CSt90bOy" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1745886859; x=1777422859; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hMRGabSCoP2Mt8bNaVEGnebNCxb8RE3JYqwt6KkURyA=; b=CSt90bOyim6FkFcygFTKwpumLQybcVZf6rmVzacNV3BnCraMOSiRNdJG LTrnLSGw0rOCsaQHG4Tg6LNKIgKuaiyjDXZjBamZVqrx1XVuH8/mFP6Uv heeSzStvzUNlNd25foBqI/FeEDWZiq/AM3a9LfLE+ZUSZuodS1XwRQEtZ 3I/ByHapO+ZhcCFo5dPI+lDxisyyP1LpQI7Fh1iT/SMp5d7EUkvTcjcCO 4RPfiNcgOSM1LEHaYszTW17zBGKgUAEPlNudephWKJ3ltF5Ac0b6FzqwB PH0+3GHLfYuK5O2u0UA8sM6QsfsRHe1nBb9L8zy/qvWwltOWbEG+jb9KB g==; X-CSE-ConnectionGUID: yQx7sDbZRyOe5bWCOMb4YQ== X-CSE-MsgGUID: Q1kJArksTXysEP0JWjuaYA== X-IronPort-AV: E=McAfee;i="6700,10204,11417"; a="58148137" X-IronPort-AV: E=Sophos;i="6.15,247,1739865600"; d="scan'208";a="58148137" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2025 17:34:13 -0700 X-CSE-ConnectionGUID: MI8gAi0nT1mHyn1cvrlvbw== X-CSE-MsgGUID: Jh1iZbYiRo2hmM8lLDJCvw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,247,1739865600"; d="scan'208";a="133393999" Received: from agluck-desk3.sc.intel.com ([172.25.222.70]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2025 17:34:13 -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 v4 11/31] x86,fs/resctrl: Rename struct rdt_mon_domain and rdt_hw_mon_domain Date: Mon, 28 Apr 2025 17:33:37 -0700 Message-ID: <20250429003359.375508-12-tony.luck@intel.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250429003359.375508-1-tony.luck@intel.com> References: <20250429003359.375508-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" These structures have generic names, but are only used for L3 monitor events. Rename: rdt_mon_domain -> rdt_l3_mon_domain rdt_hw_mon_domain -> rdt_hw_l3_mon_domain Signed-off-by: Tony Luck --- include/linux/resctrl.h | 12 ++++---- arch/x86/kernel/cpu/resctrl/internal.h | 12 ++++---- fs/resctrl/internal.h | 12 ++++---- arch/x86/kernel/cpu/resctrl/core.c | 14 ++++----- arch/x86/kernel/cpu/resctrl/monitor.c | 18 ++++++------ fs/resctrl/ctrlmondata.c | 6 ++-- fs/resctrl/monitor.c | 28 +++++++++--------- fs/resctrl/rdtgroup.c | 40 +++++++++++++------------- 8 files changed, 71 insertions(+), 71 deletions(-) diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index bb55c449adc4..cd7881313d4e 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: cache info for this domain * @rmid_busy_llc: bitmap of which limbo RMIDs are above threshold @@ -176,7 +176,7 @@ struct rdt_ctrl_domain { * @mbm_work_cpu: worker CPU for MBM h/w counters * @cqm_work_cpu: worker CPU for CQM h/w counters */ -struct rdt_mon_domain { +struct rdt_l3_mon_domain { struct rdt_domain_hdr hdr; struct cacheinfo *ci; unsigned long *rmid_busy_llc; @@ -335,7 +335,7 @@ struct resctrl_cpu_defaults { =20 struct resctrl_mon_config_info { struct rdt_resource *r; - struct rdt_mon_domain *d; + struct rdt_l3_mon_domain *d; u32 evtid; u32 mon_config; }; @@ -475,7 +475,7 @@ void resctrl_offline_cpu(unsigned int cpu); * Return: * 0 on success, or -EIO, -EINVAL etc on error. */ -int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_mon_domain *= d, +int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_l3_mon_domai= n *d, u32 closid, u32 rmid, enum resctrl_event_id eventid, u64 *val, void *arch_mon_ctx); =20 @@ -522,7 +522,7 @@ struct rdt_domain_hdr *resctrl_find_domain(struct list_= head *h, int id, * * This can be called from any CPU. */ -void resctrl_arch_reset_rmid(struct rdt_resource *r, struct rdt_mon_domain= *d, +void resctrl_arch_reset_rmid(struct rdt_resource *r, struct rdt_l3_mon_dom= ain *d, u32 closid, u32 rmid, enum resctrl_event_id eventid); =20 @@ -535,7 +535,7 @@ void resctrl_arch_reset_rmid(struct rdt_resource *r, st= ruct rdt_mon_domain *d, * * This can be called from any CPU. */ -void resctrl_arch_reset_rmid_all(struct rdt_resource *r, struct rdt_mon_do= main *d); +void resctrl_arch_reset_rmid_all(struct rdt_resource *r, struct rdt_l3_mon= _domain *d); =20 /** * resctrl_arch_reset_all_ctrls() - Reset the control for each CLOSID to i= ts diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/r= esctrl/internal.h index b563406b4996..83b20e6b25d7 100644 --- a/arch/x86/kernel/cpu/resctrl/internal.h +++ b/arch/x86/kernel/cpu/resctrl/internal.h @@ -51,15 +51,15 @@ struct rdt_hw_ctrl_domain { }; =20 /** - * struct rdt_hw_mon_domain - Arch private attributes of a set of CPUs tha= t share + * 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: arch private state for each MBM event * * Members of this structure are accessed via helpers that provide abstrac= tion. */ -struct rdt_hw_mon_domain { - struct rdt_mon_domain d_resctrl; +struct rdt_hw_l3_mon_domain { + struct rdt_l3_mon_domain d_resctrl; struct arch_mbm_state *arch_mbm_states[QOS_NUM_MBM_EVENTS]; }; =20 @@ -68,9 +68,9 @@ static inline struct rdt_hw_ctrl_domain *resctrl_to_arch_= ctrl_dom(struct rdt_ctr return container_of(r, struct rdt_hw_ctrl_domain, d_resctrl); } =20 -static inline struct rdt_hw_mon_domain *resctrl_to_arch_mon_dom(struct rdt= _mon_domain *r) +static inline struct rdt_hw_l3_mon_domain *resctrl_to_arch_mon_dom(struct = rdt_l3_mon_domain *r) { - return container_of(r, struct rdt_hw_mon_domain, d_resctrl); + return container_of(r, struct rdt_hw_l3_mon_domain, d_resctrl); } =20 /** @@ -122,7 +122,7 @@ static inline struct rdt_hw_resource *resctrl_to_arch_r= es(struct rdt_resource *r =20 extern struct rdt_hw_resource rdt_resources_all[]; =20 -void arch_l3_mon_domain_online(struct rdt_resource *r, struct rdt_mon_doma= in *d); +void arch_l3_mon_domain_online(struct rdt_resource *r, struct rdt_l3_mon_d= omain *d); =20 /* CPUID.(EAX=3D10H, ECX=3DResID=3D1).EAX */ union cpuid_0x10_1_eax { diff --git a/fs/resctrl/internal.h b/fs/resctrl/internal.h index b69170760316..759768e2a2a8 100644 --- a/fs/resctrl/internal.h +++ b/fs/resctrl/internal.h @@ -129,7 +129,7 @@ struct mon_data { struct rmid_read { struct rdtgroup *rgrp; struct rdt_resource *r; - struct rdt_mon_domain *d; + struct rdt_l3_mon_domain *d; enum resctrl_event_id evtid; bool first; struct cacheinfo *ci; @@ -365,12 +365,12 @@ void mon_event_count(void *info); int rdtgroup_mondata_show(struct seq_file *m, void *arg); =20 void mon_event_read(struct rmid_read *rr, struct rdt_resource *r, - struct rdt_mon_domain *d, struct rdtgroup *rdtgrp, + struct rdt_l3_mon_domain *d, struct rdtgroup *rdtgrp, cpumask_t *cpumask, int evtid, int first); =20 int resctrl_mon_resource_init(void); =20 -void mbm_setup_overflow_handler(struct rdt_mon_domain *dom, +void mbm_setup_overflow_handler(struct rdt_l3_mon_domain *dom, unsigned long delay_ms, int exclude_cpu); =20 @@ -378,14 +378,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 9c78828ae32f..01843dd0b8b7 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -362,7 +362,7 @@ static void ctrl_domain_free(struct rdt_hw_ctrl_domain = *hw_dom) kfree(hw_dom); } =20 -static void free_l3_mon_domain(struct rdt_hw_mon_domain *hw_dom) +static void free_l3_mon_domain(struct rdt_hw_l3_mon_domain *hw_dom) { for (int i =3D 0; i < QOS_NUM_MBM_EVENTS; i++) kfree(hw_dom->arch_mbm_states[i]); @@ -397,7 +397,7 @@ static int domain_setup_ctrlval(struct rdt_resource *r,= struct rdt_ctrl_domain * * @num_rmid: The size of the MBM counter array * @hw_dom: The domain that owns the allocated arrays */ -static int arch_domain_mbm_alloc(u32 num_rmid, struct rdt_hw_mon_domain *h= w_dom) +static int arch_domain_mbm_alloc(u32 num_rmid, struct rdt_hw_l3_mon_domain= *hw_dom) { size_t tsize =3D sizeof(struct arch_mbm_state); enum resctrl_event_id evt; @@ -495,8 +495,8 @@ static void domain_add_cpu_ctrl(int cpu, struct rdt_res= ource *r) =20 static void setup_l3_mon_domain(int cpu, int id, struct rdt_resource *r, s= truct list_head *add_pos) { - struct rdt_hw_mon_domain *hw_dom; - struct rdt_mon_domain *d; + struct rdt_hw_l3_mon_domain *hw_dom; + struct rdt_l3_mon_domain *d; int err; =20 hw_dom =3D kzalloc_node(sizeof(*hw_dom), GFP_KERNEL, cpu_to_node(cpu)); @@ -618,9 +618,9 @@ static void domain_remove_cpu_ctrl(int cpu, struct rdt_= resource *r) static void domain_remove_cpu_mon(int cpu, struct rdt_resource *r) { int id =3D get_domain_id_from_scope(cpu, r->mon_scope); - struct rdt_hw_mon_domain *hw_dom; + struct rdt_hw_l3_mon_domain *hw_dom; struct rdt_domain_hdr *hdr; - struct rdt_mon_domain *d; + struct rdt_l3_mon_domain *d; =20 lockdep_assert_held(&domain_list_lock); =20 @@ -646,7 +646,7 @@ static void domain_remove_cpu_mon(int cpu, struct rdt_r= esource *r) =20 switch (r->rid) { case RDT_RESOURCE_L3: - d =3D container_of(hdr, struct rdt_mon_domain, hdr); + d =3D container_of(hdr, struct rdt_l3_mon_domain, hdr); hw_dom =3D resctrl_to_arch_mon_dom(d); resctrl_offline_mon_domain(r, hdr); list_del_rcu(&hdr->list); diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/re= sctrl/monitor.c index d1f659dd6109..8d8ec86929fa 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -108,7 +108,7 @@ static inline u64 get_corrected_mbm_count(u32 rmid, uns= igned long val) * * In RMID sharing mode there are fewer "logical RMID" values available * to accumulate data ("physical RMIDs" are divided evenly between SNC - * nodes that share an L3 cache). Linux creates an rdt_mon_domain for + * nodes that share an L3 cache). Linux creates an rdt_l3_mon_domain for * each SNC node. * * The value loaded into IA32_PQR_ASSOC is the "logical RMID". @@ -156,7 +156,7 @@ static int __rmid_read_phys(u32 prmid, enum resctrl_eve= nt_id eventid, u64 *val) return 0; } =20 -static struct arch_mbm_state *get_arch_mbm_state(struct rdt_hw_mon_domain = *hw_dom, +static struct arch_mbm_state *get_arch_mbm_state(struct rdt_hw_l3_mon_doma= in *hw_dom, u32 rmid, enum resctrl_event_id eventid) { @@ -177,11 +177,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; @@ -200,9 +200,9 @@ void resctrl_arch_reset_rmid(struct rdt_resource *r, st= ruct rdt_mon_domain *d, * Assumes that hardware counters are also reset and thus that there is * no need to record initial non-zero counts. */ -void resctrl_arch_reset_rmid_all(struct rdt_resource *r, struct rdt_mon_do= main *d) +void resctrl_arch_reset_rmid_all(struct rdt_resource *r, struct rdt_l3_mon= _domain *d) { - struct rdt_hw_mon_domain *hw_dom =3D resctrl_to_arch_mon_dom(d); + struct rdt_hw_l3_mon_domain *hw_dom =3D resctrl_to_arch_mon_dom(d); enum resctrl_event_id evt; int idx; =20 @@ -223,11 +223,11 @@ static u64 mbm_overflow_count(u64 prev_msr, u64 cur_m= sr, unsigned int width) return chunks >> shift; } =20 -int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_mon_domain *= d, +int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_l3_mon_domai= n *d, u32 unused, u32 rmid, enum resctrl_event_id eventid, u64 *val, void *ignored) { - struct rdt_hw_mon_domain *hw_dom =3D resctrl_to_arch_mon_dom(d); + struct rdt_hw_l3_mon_domain *hw_dom =3D resctrl_to_arch_mon_dom(d); struct rdt_hw_resource *hw_res =3D resctrl_to_arch_res(r); int cpu =3D cpumask_any(&d->hdr.cpu_mask); struct arch_mbm_state *am; @@ -271,7 +271,7 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, stru= ct rdt_mon_domain *d, * must adjust RMID counter numbers based on SNC node. See * logical_rmid_to_physical_rmid() for code that does this. */ -void arch_l3_mon_domain_online(struct rdt_resource *r, struct rdt_mon_doma= in *d) +void arch_l3_mon_domain_online(struct rdt_resource *r, struct rdt_l3_mon_d= omain *d) { if (snc_nodes_per_l3_cache > 1) msr_clear_bit(MSR_RMID_SNC_CONFIG, 0); diff --git a/fs/resctrl/ctrlmondata.c b/fs/resctrl/ctrlmondata.c index 3cbacfe52430..8c0f6d229130 100644 --- a/fs/resctrl/ctrlmondata.c +++ b/fs/resctrl/ctrlmondata.c @@ -526,7 +526,7 @@ struct rdt_domain_hdr *resctrl_find_domain(struct list_= head *h, int id, } =20 void mon_event_read(struct rmid_read *rr, struct rdt_resource *r, - struct rdt_mon_domain *d, struct rdtgroup *rdtgrp, + struct rdt_l3_mon_domain *d, struct rdtgroup *rdtgrp, cpumask_t *cpumask, int evtid, int first) { int cpu; @@ -569,7 +569,7 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg) struct kernfs_open_file *of =3D m->private; struct rdt_domain_hdr *hdr; struct rmid_read rr =3D {0}; - struct rdt_mon_domain *d; + struct rdt_l3_mon_domain *d; u32 resid, evtid, domid; struct rdtgroup *rdtgrp; struct rdt_resource *r; @@ -620,7 +620,7 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg) ret =3D -ENOENT; goto out; } - d =3D container_of(hdr, struct rdt_mon_domain, hdr); + d =3D container_of(hdr, struct rdt_l3_mon_domain, hdr); mon_event_read(&rr, r, d, rdtgrp, &d->hdr.cpu_mask, evtid, false); } =20 diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c index a5a523f73249..19cba29452b7 100644 --- a/fs/resctrl/monitor.c +++ b/fs/resctrl/monitor.c @@ -130,7 +130,7 @@ static void limbo_release_entry(struct rmid_entry *entr= y) * decrement the count. If the busy count gets to zero on an RMID, we * free the RMID */ -void __check_limbo(struct rdt_mon_domain *d, bool force_free) +void __check_limbo(struct rdt_l3_mon_domain *d, bool force_free) { struct rdt_resource *r =3D resctrl_arch_get_resource(RDT_RESOURCE_L3); u32 idx_limit =3D resctrl_arch_system_num_rmid_idx(); @@ -188,7 +188,7 @@ void __check_limbo(struct rdt_mon_domain *d, bool force= _free) resctrl_arch_mon_ctx_free(r, QOS_L3_OCCUP_EVENT_ID, arch_mon_ctx); } =20 -bool has_busy_rmid(struct rdt_mon_domain *d) +bool has_busy_rmid(struct rdt_l3_mon_domain *d) { u32 idx_limit =3D resctrl_arch_system_num_rmid_idx(); =20 @@ -289,7 +289,7 @@ int alloc_rmid(u32 closid) static void add_rmid_to_limbo(struct rmid_entry *entry) { struct rdt_resource *r =3D resctrl_arch_get_resource(RDT_RESOURCE_L3); - struct rdt_mon_domain *d; + struct rdt_l3_mon_domain *d; u32 idx; =20 lockdep_assert_held(&rdtgroup_mutex); @@ -342,7 +342,7 @@ void free_rmid(u32 closid, u32 rmid) list_add_tail(&entry->list, &rmid_free_lru); } =20 -static struct mbm_state *get_mbm_state(struct rdt_mon_domain *d, u32 closi= d, +static struct mbm_state *get_mbm_state(struct rdt_l3_mon_domain *d, u32 cl= osid, u32 rmid, enum resctrl_event_id evtid) { u32 idx =3D resctrl_arch_rmid_idx_encode(closid, rmid); @@ -359,7 +359,7 @@ static struct mbm_state *get_mbm_state(struct rdt_mon_d= omain *d, u32 closid, static int __mon_event_count(u32 closid, u32 rmid, struct rmid_read *rr) { int cpu =3D smp_processor_id(); - struct rdt_mon_domain *d; + struct rdt_l3_mon_domain *d; struct mbm_state *m; int err, ret; u64 tval =3D 0; @@ -532,7 +532,7 @@ static struct rdt_ctrl_domain *get_ctrl_domain_from_cpu= (int cpu, * throttle MSRs already have low percentage values. To avoid * unnecessarily restricting such rdtgroups, we also increase the bandwidt= h. */ -static void update_mba_bw(struct rdtgroup *rgrp, struct rdt_mon_domain *do= m_mbm) +static void update_mba_bw(struct rdtgroup *rgrp, struct rdt_l3_mon_domain = *dom_mbm) { u32 closid, rmid, cur_msr_val, new_msr_val; struct mbm_state *pmbm_data, *cmbm_data; @@ -600,7 +600,7 @@ static void update_mba_bw(struct rdtgroup *rgrp, struct= rdt_mon_domain *dom_mbm) resctrl_arch_update_one(r_mba, dom_mba, closid, CDP_NONE, new_msr_val); } =20 -static void mbm_update_one_event(struct rdt_resource *r, struct rdt_mon_do= main *d, +static void mbm_update_one_event(struct rdt_resource *r, struct rdt_l3_mon= _domain *d, u32 closid, u32 rmid, enum resctrl_event_id evtid) { struct rmid_read rr =3D {0}; @@ -627,7 +627,7 @@ static void mbm_update_one_event(struct rdt_resource *r= , struct rdt_mon_domain * resctrl_arch_mon_ctx_free(rr.r, rr.evtid, rr.arch_mon_ctx); } =20 -static void mbm_update(struct rdt_resource *r, struct rdt_mon_domain *d, +static void mbm_update(struct rdt_resource *r, struct rdt_l3_mon_domain *d, u32 closid, u32 rmid) { /* @@ -648,12 +648,12 @@ static void mbm_update(struct rdt_resource *r, struct= rdt_mon_domain *d, void cqm_handle_limbo(struct work_struct *work) { unsigned long delay =3D msecs_to_jiffies(CQM_LIMBOCHECK_INTERVAL); - struct rdt_mon_domain *d; + struct rdt_l3_mon_domain *d; =20 cpus_read_lock(); mutex_lock(&rdtgroup_mutex); =20 - d =3D container_of(work, struct rdt_mon_domain, cqm_limbo.work); + d =3D container_of(work, struct rdt_l3_mon_domain, cqm_limbo.work); =20 __check_limbo(d, false); =20 @@ -676,7 +676,7 @@ void cqm_handle_limbo(struct work_struct *work) * @exclude_cpu: Which CPU the handler should not run on, * RESCTRL_PICK_ANY_CPU to pick any CPU. */ -void cqm_setup_limbo_handler(struct rdt_mon_domain *dom, unsigned long del= ay_ms, +void cqm_setup_limbo_handler(struct rdt_l3_mon_domain *dom, unsigned long = delay_ms, int exclude_cpu) { unsigned long delay =3D msecs_to_jiffies(delay_ms); @@ -693,7 +693,7 @@ void mbm_handle_overflow(struct work_struct *work) { unsigned long delay =3D msecs_to_jiffies(MBM_OVERFLOW_INTERVAL); struct rdtgroup *prgrp, *crgrp; - struct rdt_mon_domain *d; + struct rdt_l3_mon_domain *d; struct list_head *head; struct rdt_resource *r; =20 @@ -708,7 +708,7 @@ void mbm_handle_overflow(struct work_struct *work) goto out_unlock; =20 r =3D resctrl_arch_get_resource(RDT_RESOURCE_L3); - d =3D container_of(work, struct rdt_mon_domain, mbm_over.work); + d =3D container_of(work, struct rdt_l3_mon_domain, mbm_over.work); =20 list_for_each_entry(prgrp, &rdt_all_groups, rdtgroup_list) { mbm_update(r, d, prgrp->closid, prgrp->mon.rmid); @@ -742,7 +742,7 @@ void mbm_handle_overflow(struct work_struct *work) * @exclude_cpu: Which CPU the handler should not run on, * RESCTRL_PICK_ANY_CPU to pick any CPU. */ -void mbm_setup_overflow_handler(struct rdt_mon_domain *dom, unsigned long = delay_ms, +void mbm_setup_overflow_handler(struct rdt_l3_mon_domain *dom, unsigned lo= ng delay_ms, int exclude_cpu) { unsigned long delay =3D msecs_to_jiffies(delay_ms); diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index 0ec87db799b4..d2f9361694b6 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -1613,7 +1613,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(); @@ -1661,7 +1661,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 @@ -1703,7 +1703,7 @@ static int mon_config_write(struct rdt_resource *r, c= har *tok, u32 evtid) { char *dom_str =3D NULL, *id_str; unsigned long dom_id, val; - struct rdt_mon_domain *d; + struct rdt_l3_mon_domain *d; =20 /* Walking r->domains, ensure it can't race with cpuhp */ lockdep_assert_cpus_held(); @@ -2577,7 +2577,7 @@ static int rdt_get_tree(struct fs_context *fc) { struct rdt_fs_context *ctx =3D rdt_fc2context(fc); unsigned long flags =3D RFTYPE_CTRL_BASE; - struct rdt_mon_domain *dom; + struct rdt_l3_mon_domain *dom; struct rdt_resource *r; int ret; =20 @@ -3031,11 +3031,11 @@ static void rmdir_mondata_subdir_allrdtgrp(struct r= dt_resource *r, =20 snc_mode =3D r->mon_scope =3D=3D RESCTRL_L3_NODE; if (snc_mode) { - struct rdt_mon_domain *d; + struct rdt_l3_mon_domain *d; =20 if (check_domain_header(hdr, RESCTRL_MON_DOMAIN, r->rid)) return; - d =3D container_of(hdr, struct rdt_mon_domain, hdr); + d =3D container_of(hdr, struct rdt_l3_mon_domain, hdr); sprintf(name, "mon_%s_%02d", r->name, d->ci->id); sprintf(subname, "mon_sub_%s_%02d", r->name, hdr->id); } else { @@ -3055,7 +3055,7 @@ static int mon_add_all_files(struct kernfs_node *kn, = struct rdt_domain_hdr *hdr, bool do_sum) { struct rmid_read rr =3D {0}; - struct rdt_mon_domain *d; + struct rdt_l3_mon_domain *d; struct mon_data *priv; struct mon_evt *mevt; int ret, domid; @@ -3066,7 +3066,7 @@ static int mon_add_all_files(struct kernfs_node *kn, = struct rdt_domain_hdr *hdr, if (r->rid =3D=3D RDT_RESOURCE_L3) { if (check_domain_header(hdr, RESCTRL_MON_DOMAIN, r->rid)) return -EINVAL; - d =3D container_of(hdr, struct rdt_mon_domain, hdr); + d =3D container_of(hdr, struct rdt_l3_mon_domain, hdr); domid =3D do_sum ? d->ci->id : d->hdr.id; } else { domid =3D hdr->id; @@ -3093,7 +3093,7 @@ static int mkdir_mondata_subdir(struct kernfs_node *p= arent_kn, struct rdt_resource *r, struct rdtgroup *prgrp) { struct kernfs_node *kn, *ckn; - struct rdt_mon_domain *d; + struct rdt_l3_mon_domain *d; char name[32]; bool snc_mode; int ret =3D 0; @@ -3104,7 +3104,7 @@ static int mkdir_mondata_subdir(struct kernfs_node *p= arent_kn, if (snc_mode) { if (check_domain_header(hdr, RESCTRL_MON_DOMAIN, r->rid)) return -EINVAL; - d =3D container_of(hdr, struct rdt_mon_domain, hdr); + d =3D container_of(hdr, struct rdt_l3_mon_domain, hdr); sprintf(name, "mon_%s_%02d", r->name, d->ci->id); } else { sprintf(name, "mon_%s_%02d", r->name, hdr->id); @@ -4037,7 +4037,7 @@ static void rdtgroup_setup_default(void) mutex_unlock(&rdtgroup_mutex); } =20 -static void domain_destroy_mon_state(struct rdt_mon_domain *d) +static void domain_destroy_mon_state(struct rdt_l3_mon_domain *d) { bitmap_free(d->rmid_busy_llc); for (int i =3D 0; i < QOS_NUM_MBM_EVENTS; i++) { @@ -4058,7 +4058,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 @@ -4075,7 +4075,7 @@ void resctrl_offline_mon_domain(struct rdt_resource *= r, struct rdt_domain_hdr *h if (check_domain_header(hdr, RESCTRL_MON_DOMAIN, r->rid)) return; =20 - d =3D container_of(hdr, struct rdt_mon_domain, hdr); + d =3D container_of(hdr, struct rdt_l3_mon_domain, hdr); if (resctrl_is_mbm_enabled()) cancel_delayed_work(&d->mbm_over); if (resctrl_is_mon_event_enabled(QOS_L3_OCCUP_EVENT_ID) && has_busy_rmid(= d)) { @@ -4109,7 +4109,7 @@ void resctrl_offline_mon_domain(struct rdt_resource *= r, struct rdt_domain_hdr *h * * Returns 0 for success, or -ENOMEM. */ -static int domain_setup_l3_mon_state(struct rdt_resource *r, struct rdt_mo= n_domain *d) +static int domain_setup_l3_mon_state(struct rdt_resource *r, struct rdt_l3= _mon_domain *d) { u32 idx_limit =3D resctrl_arch_system_num_rmid_idx(); size_t tsize =3D sizeof(struct mbm_state); @@ -4160,7 +4160,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); @@ -4171,7 +4171,7 @@ int resctrl_online_mon_domain(struct rdt_resource *r,= struct rdt_domain_hdr *hdr if (check_domain_header(hdr, RESCTRL_MON_DOMAIN, r->rid)) return err; =20 - d =3D container_of(hdr, struct rdt_mon_domain, hdr); + d =3D container_of(hdr, struct rdt_l3_mon_domain, hdr); err =3D domain_setup_l3_mon_state(r, d); if (err) goto out_unlock; @@ -4218,10 +4218,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 @@ -4237,7 +4237,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.48.1 From nobody Fri Dec 19 19:02:40 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) (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 B67C91CAA90 for ; Tue, 29 Apr 2025 00:34:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745886861; cv=none; b=lpnZ3dLRVQD/x5qNXv1ElRv/xLRs6M1AgZcmQwAX0VUHDyfNfPcUkqeWKxCKoscI/clCKRIWNxLyVRsCOvF1ZovKKkSYw1ZPBCOOz/yN4LR49ybAGf/CvTXWit10olKfR+GISneOXEHkBhPkvOP+xbqR9AP/gnZsKk/8Wjsv3kQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745886861; c=relaxed/simple; bh=IOdEcQP1Ea7d6dgzls/RDy48D4uzrPd4dk38VdRfPuE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=s2o2qnyUKbYb1WerwPgsR433ie08W8UlHKqgGKQhiKDcZnb5cj0DmPmOxSQHgSJ28xRrSYMl31WFR2TjLUAca7+t2FMeo/Ism4C4k0LYI9laOG+F3nusPCjkGO84dej5kPgG9EDok374LH3LlMW5vb6oek4+VbN1rjKBwRIn95Q= 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=hs6MnFjo; arc=none smtp.client-ip=192.198.163.9 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="hs6MnFjo" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1745886858; x=1777422858; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=IOdEcQP1Ea7d6dgzls/RDy48D4uzrPd4dk38VdRfPuE=; b=hs6MnFjosEEfFPZ7RfQ4fk6KyXvzlKXcTKV81LWtKSwdkDgPzLRHGrvs /GBKlf7tGEyr7xDm4vZxldWbHIapSDeNnL0sEkBkUhuKyAOZwmV87/hRX IfyqTTLeSKDW1Xm6o1SCgFOCAnEkuUzENsIxdsAt2cHAjeTmlUggosEIX qjK66Ue4+Qagqeqs+OvgYAl2oS8jNJcrCDyoxUZUNih5HBmdRdNILtqA+ mT5Oucf20fThXtbHMd+AqdfQH8aP7T22552o+UPZ55ERdZ828MjdLRA4P 8LwJIeinvqaDiYLd6DVgMdLk84X9o9qrEalm4jpBaRM8T8swijiKrcf4+ Q==; X-CSE-ConnectionGUID: 8LN5tKYxS7yLXIAzZYBH8g== X-CSE-MsgGUID: OwE3h/UUR52Qcb3KCbtRew== X-IronPort-AV: E=McAfee;i="6700,10204,11417"; a="58148148" X-IronPort-AV: E=Sophos;i="6.15,247,1739865600"; d="scan'208";a="58148148" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2025 17:34:14 -0700 X-CSE-ConnectionGUID: EZDv7CbmSy2JIHG3YdGeVg== X-CSE-MsgGUID: Pq4cjU7TSqinxcLztJjRnA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,247,1739865600"; d="scan'208";a="133394004" Received: from agluck-desk3.sc.intel.com ([172.25.222.70]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2025 17:34:13 -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 v4 12/31] fs/resctrl: Improve handling for events that can be read from any CPU Date: Mon, 28 Apr 2025 17:33:38 -0700 Message-ID: <20250429003359.375508-13-tony.luck@intel.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250429003359.375508-1-tony.luck@intel.com> References: <20250429003359.375508-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 cpumast_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 each instance of struct mon_evt that can be set by architecture code to indicate there is no restriction on which CPU can read the event counter. Change struct mon_data and struct rmid_read to have a pointer to the struct mon_evt instead of the event id. Add an extra argument to resctrl_enable_mon_event() so architecture code can indicate which events can be read on any CPU when enabling the event. Bypass all the smp_call*() code for events that can be read on any CPU and call mon_event_count() directly from mon_event_read(). Skip checks in __mon_event_count() that the read is being done from a CPU in the correct domain or cache scope. Signed-off-by: Tony Luck --- include/linux/resctrl.h | 2 +- fs/resctrl/internal.h | 12 +++++++----- arch/x86/kernel/cpu/resctrl/core.c | 6 +++--- fs/resctrl/ctrlmondata.c | 24 +++++++++++++++--------- fs/resctrl/monitor.c | 26 ++++++++++++++------------ fs/resctrl/rdtgroup.c | 6 +++--- 6 files changed, 43 insertions(+), 33 deletions(-) diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index cd7881313d4e..4af5e8d30193 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 evtid); +void resctrl_enable_mon_event(enum resctrl_event_id evtid, bool any_cpu); bool resctrl_is_mon_event_enabled(enum resctrl_event_id evt); bool resctrl_arch_is_evt_configurable(enum resctrl_event_id evt); =20 diff --git a/fs/resctrl/internal.h b/fs/resctrl/internal.h index 759768e2a2a8..d8aa69b42c74 100644 --- a/fs/resctrl/internal.h +++ b/fs/resctrl/internal.h @@ -72,6 +72,7 @@ static inline struct rdt_fs_context *rdt_fc2context(struc= t fs_context *fc) * @name: name of the event * @configurable: true if the event is configurable * @enabled: true if the event is enabled + * @any_cpu: true if the event can be read from any CPU * @list: entry in &rdt_resource->evt_list */ struct mon_evt { @@ -80,6 +81,7 @@ struct mon_evt { char *name; bool configurable; bool enabled; + bool any_cpu; struct list_head list; }; =20 @@ -89,7 +91,7 @@ extern struct mon_evt mon_event_all[QOS_NUM_EVENTS]; * struct mon_data - Monitoring details for each event file. * @list: Member of the global @mon_data_kn_priv_list list. * @rid: Resource id associated with the event file. - * @evtid: Event id associated with the event file. + * @evt: Event associated with the event file. * @sum: Set when event must be summed across multiple * domains. * @domid: When @sum is zero this is the domain to which @@ -103,7 +105,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; }; @@ -116,7 +118,7 @@ struct mon_data { * @r: Resource describing the properties of the event being read. * @d: Domain that the counter should be read from. If NULL then sum all * domains in @r sharing L3 @ci.id - * @evtid: Which monitor event to read. + * @evt: Which monitor event to read. * @first: Initialize MBM counter when true. * @ci: Cacheinfo for L3. Only set when @d is NULL. Used when summing d= omains. * @err: Error encountered when reading counter. @@ -130,7 +132,7 @@ struct rmid_read { struct rdtgroup *rgrp; struct rdt_resource *r; struct rdt_l3_mon_domain *d; - enum resctrl_event_id evtid; + struct mon_evt *evt; bool first; struct cacheinfo *ci; int err; @@ -366,7 +368,7 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg= ); =20 void mon_event_read(struct rmid_read *rr, struct rdt_resource *r, struct rdt_l3_mon_domain *d, struct rdtgroup *rdtgrp, - cpumask_t *cpumask, int evtid, int first); + cpumask_t *cpumask, struct mon_evt *evt, int first); =20 int resctrl_mon_resource_init(void); =20 diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resct= rl/core.c index 01843dd0b8b7..58bc218070e2 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -877,15 +877,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 8c0f6d229130..7a2957b9c13e 100644 --- a/fs/resctrl/ctrlmondata.c +++ b/fs/resctrl/ctrlmondata.c @@ -527,7 +527,7 @@ struct rdt_domain_hdr *resctrl_find_domain(struct list_= head *h, int id, =20 void mon_event_read(struct rmid_read *rr, struct rdt_resource *r, struct rdt_l3_mon_domain *d, struct rdtgroup *rdtgrp, - cpumask_t *cpumask, int evtid, int first) + cpumask_t *cpumask, struct mon_evt *evt, int first) { int cpu; =20 @@ -538,16 +538,21 @@ void mon_event_read(struct rmid_read *rr, struct rdt_= resource *r, * Setup the parameters to pass to mon_event_count() to read the data. */ rr->rgrp =3D rdtgrp; - rr->evtid =3D evtid; + rr->evt =3D evt; rr->r =3D r; rr->d =3D d; rr->first =3D first; - rr->arch_mon_ctx =3D resctrl_arch_mon_ctx_alloc(r, evtid); + rr->arch_mon_ctx =3D resctrl_arch_mon_ctx_alloc(r, evt->evtid); if (IS_ERR(rr->arch_mon_ctx)) { rr->err =3D -EINVAL; return; } =20 + if (evt->any_cpu) { + mon_event_count(rr); + goto done; + } + cpu =3D cpumask_any_housekeeping(cpumask, RESCTRL_PICK_ANY_CPU); =20 /* @@ -560,8 +565,8 @@ 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); - - resctrl_arch_mon_ctx_free(r, evtid, rr->arch_mon_ctx); +done: + resctrl_arch_mon_ctx_free(r, evt->evtid, rr->arch_mon_ctx); } =20 int rdtgroup_mondata_show(struct seq_file *m, void *arg) @@ -570,7 +575,8 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg) struct rdt_domain_hdr *hdr; struct rmid_read rr =3D {0}; struct rdt_l3_mon_domain *d; - u32 resid, evtid, domid; + struct mon_evt *evt; + u32 resid, domid; struct rdtgroup *rdtgrp; struct rdt_resource *r; struct mon_data *md; @@ -590,7 +596,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) { @@ -604,7 +610,7 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg) if (d->ci->id =3D=3D domid) { rr.ci =3D d->ci; mon_event_read(&rr, r, NULL, rdtgrp, - &d->ci->shared_cpu_map, evtid, false); + &d->ci->shared_cpu_map, evt, false); goto checkresult; } } @@ -621,7 +627,7 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg) goto out; } d =3D container_of(hdr, struct rdt_l3_mon_domain, hdr); - mon_event_read(&rr, r, d, rdtgrp, &d->hdr.cpu_mask, evtid, false); + mon_event_read(&rr, r, d, rdtgrp, &d->hdr.cpu_mask, evt, false); } =20 checkresult: diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c index 19cba29452b7..e903d3c076ee 100644 --- a/fs/resctrl/monitor.c +++ b/fs/resctrl/monitor.c @@ -365,19 +365,19 @@ static int __mon_event_count(u32 closid, u32 rmid, st= ruct rmid_read *rr) u64 tval =3D 0; =20 if (rr->first) { - resctrl_arch_reset_rmid(rr->r, rr->d, closid, rmid, rr->evtid); - m =3D get_mbm_state(rr->d, closid, rmid, rr->evtid); + resctrl_arch_reset_rmid(rr->r, rr->d, closid, rmid, rr->evt->evtid); + m =3D get_mbm_state(rr->d, closid, rmid, rr->evt->evtid); if (m) memset(m, 0, sizeof(struct mbm_state)); return 0; } =20 if (rr->d) { - /* Reading a single domain, must be on a CPU in that domain. */ - if (!cpumask_test_cpu(cpu, &rr->d->hdr.cpu_mask)) + /* Reading a single domain, must usually be on a CPU in that domain. */ + if (!rr->evt->any_cpu && !cpumask_test_cpu(cpu, &rr->d->hdr.cpu_mask)) return -EINVAL; rr->err =3D resctrl_arch_rmid_read(rr->r, rr->d, closid, rmid, - rr->evtid, &tval, rr->arch_mon_ctx); + rr->evt->evtid, &tval, rr->arch_mon_ctx); if (rr->err) return rr->err; =20 @@ -387,7 +387,7 @@ static int __mon_event_count(u32 closid, u32 rmid, stru= ct rmid_read *rr) } =20 /* Summing domains that share a cache, must be on a CPU for that cache. */ - if (!cpumask_test_cpu(cpu, &rr->ci->shared_cpu_map)) + if (!rr->evt->any_cpu && !cpumask_test_cpu(cpu, &rr->ci->shared_cpu_map)) return -EINVAL; =20 /* @@ -402,7 +402,7 @@ static int __mon_event_count(u32 closid, u32 rmid, stru= ct rmid_read *rr) if (d->ci->id !=3D rr->ci->id) continue; err =3D resctrl_arch_rmid_read(rr->r, d, closid, rmid, - rr->evtid, &tval, rr->arch_mon_ctx); + rr->evt->evtid, &tval, rr->arch_mon_ctx); if (!err) { rr->val +=3D tval; ret =3D 0; @@ -432,7 +432,7 @@ static void mbm_bw_count(u32 closid, u32 rmid, struct r= mid_read *rr) u64 cur_bw, bytes, cur_bytes; struct mbm_state *m; =20 - m =3D get_mbm_state(rr->d, closid, rmid, rr->evtid); + m =3D get_mbm_state(rr->d, closid, rmid, rr->evt->evtid); if (WARN_ON_ONCE(!m)) return; =20 @@ -603,12 +603,13 @@ static void update_mba_bw(struct rdtgroup *rgrp, stru= ct rdt_l3_mon_domain *dom_m static void mbm_update_one_event(struct rdt_resource *r, struct rdt_l3_mon= _domain *d, u32 closid, u32 rmid, enum resctrl_event_id evtid) { + struct mon_evt *evt =3D &mon_event_all[evtid]; struct rmid_read rr =3D {0}; =20 rr.r =3D r; rr.d =3D d; - rr.evtid =3D evtid; - rr.arch_mon_ctx =3D resctrl_arch_mon_ctx_alloc(rr.r, rr.evtid); + rr.evt =3D evt; + rr.arch_mon_ctx =3D resctrl_arch_mon_ctx_alloc(rr.r, evtid); if (IS_ERR(rr.arch_mon_ctx)) { pr_warn_ratelimited("Failed to allocate monitor context: %ld", PTR_ERR(rr.arch_mon_ctx)); @@ -624,7 +625,7 @@ static void mbm_update_one_event(struct rdt_resource *r= , struct rdt_l3_mon_domai if (is_mba_sc(NULL)) mbm_bw_count(closid, rmid, &rr); =20 - resctrl_arch_mon_ctx_free(rr.r, rr.evtid, rr.arch_mon_ctx); + resctrl_arch_mon_ctx_free(rr.r, evtid, rr.arch_mon_ctx); } =20 static void mbm_update(struct rdt_resource *r, struct rdt_l3_mon_domain *d, @@ -859,12 +860,13 @@ struct mon_evt mon_event_all[QOS_NUM_EVENTS] =3D { }, }; =20 -void resctrl_enable_mon_event(enum resctrl_event_id evtid) +void resctrl_enable_mon_event(enum resctrl_event_id evtid, bool any_cpu) { if (WARN_ON_ONCE(evtid >=3D QOS_NUM_EVENTS)) return; =20 mon_event_all[evtid].enabled =3D true; + mon_event_all[evtid].any_cpu =3D any_cpu; } =20 bool resctrl_is_mon_event_enabled(enum resctrl_event_id evtid) diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index d2f9361694b6..d16bb05fafe8 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -2897,7 +2897,7 @@ static struct mon_data *mon_get_kn_priv(int rid, int = domid, =20 list_for_each_entry(priv, &mon_data_kn_priv_list, list) { if (priv->rid =3D=3D rid && priv->domid =3D=3D domid && - priv->sum =3D=3D do_sum && priv->evtid =3D=3D mevt->evtid) + priv->sum =3D=3D do_sum && priv->evt =3D=3D mevt) return priv; } =20 @@ -2908,7 +2908,7 @@ static struct mon_data *mon_get_kn_priv(int 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; @@ -3082,7 +3082,7 @@ static int mon_add_all_files(struct kernfs_node *kn, = struct rdt_domain_hdr *hdr, return ret; =20 if (r->rid =3D=3D RDT_RESOURCE_L3 && !do_sum && resctrl_is_mbm_event(mev= t->evtid)) - mon_event_read(&rr, r, d, prgrp, &hdr->cpu_mask, mevt->evtid, true); + mon_event_read(&rr, r, d, prgrp, &hdr->cpu_mask, mevt, true); } =20 return 0; --=20 2.48.1 From nobody Fri Dec 19 19:02:40 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) (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 1EFFF1DB958 for ; Tue, 29 Apr 2025 00:34:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745886862; cv=none; b=n3CSMKv3kiWXJNV2tGGPGHmOJ/8cctVFJsFw2iAkSBm4VGzpRGyFk39HF2vXC5f2zx7b9Wo9D2wzBosPednpNIWbrd4wwBT3QX1SBTqN0sQgxF1083WIsZVN1zMwJHSIzp5aIe2HV4HcvtKtI1hnAiiW6DoZWQYf1hcqALxdpjk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745886862; c=relaxed/simple; bh=z0L0z/agPWaN8QNGwNrQmf+C5bmutBlZQlBrNgZsyjo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OkGssM4/UiP37G9tp527SYcn4Rx++MjVhFcCyJ7XFABI8iz1PYTOFfYOF29Ni/Ixy5lYCL50Hg7wpvT+Yf57ntbjoYij3X3Ot1Om19VL88dODIVXvTO7955/Ts4GQSioyzIs5tAsrWTFbYmEUl2BMBXfTsZVEoB6tmJbN9dskXQ= 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=fxoZB9JL; arc=none smtp.client-ip=192.198.163.9 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="fxoZB9JL" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1745886860; x=1777422860; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=z0L0z/agPWaN8QNGwNrQmf+C5bmutBlZQlBrNgZsyjo=; b=fxoZB9JLtqitAh+t+MWdEh/8mYOzTAwc3s64Cx5G+Brb5STKsSfW66p+ FPwipgk6sZCCsXlC263f95Rxardyz7QpRbFwJDdCTN9rr6xj4IlEEmr94 lQNiEWICkIaxM6/VM5cP4oHH9uSX4ldl4GaaOifrtf7Ay9HtApdosJu/0 xHQMboYu4IRr5Mj0hbwQCG4mthoOLre7voOwLahe8KglCyVQRN4HMfpct sVSy4FNnKFKlga+9dfLq5anfC2e7N0rHivfRR5laaYe+BzlJ0Suf3ENtp s/XxgMrB+duPgAaf0ZMqWDbdFsMlOUm1uoXQ4Q4Sogk1m3Gxu6PqA4L1k Q==; X-CSE-ConnectionGUID: mCvZ9plPQcaKocKq3NKVGg== X-CSE-MsgGUID: OHkW3UJUQ4qpUpb5QrEIVA== X-IronPort-AV: E=McAfee;i="6700,10204,11417"; a="58148158" X-IronPort-AV: E=Sophos;i="6.15,247,1739865600"; d="scan'208";a="58148158" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2025 17:34:15 -0700 X-CSE-ConnectionGUID: mOGWEq6iRI6gE/GzO7OrZw== X-CSE-MsgGUID: FPflHQezSCCYPULzPlcdSw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,247,1739865600"; d="scan'208";a="133394007" Received: from agluck-desk3.sc.intel.com ([172.25.222.70]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2025 17:34:14 -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 v4 13/31] fs/resctrl: Add support for additional monitor event display formats Date: Mon, 28 Apr 2025 17:33:39 -0700 Message-ID: <20250429003359.375508-14-tony.luck@intel.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250429003359.375508-1-tony.luck@intel.com> References: <20250429003359.375508-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. Some telemetry events provide greater precision where architecture code uses a fixed point format with 18 binary places. Add a "display_format" field to struct mon_evt which can specify that the value for the event be displayed as an integer for legacy events, or as a floating point value with six decimal places converted from the fixed point format received from architecture code. Signed-off-by: Tony Luck --- include/linux/resctrl_types.h | 5 +++++ fs/resctrl/internal.h | 2 ++ fs/resctrl/ctrlmondata.c | 24 +++++++++++++++++++++++- fs/resctrl/monitor.c | 21 ++++++++++++--------- 4 files changed, 42 insertions(+), 10 deletions(-) diff --git a/include/linux/resctrl_types.h b/include/linux/resctrl_types.h index 5ef14a24008c..6245034f6c76 100644 --- a/include/linux/resctrl_types.h +++ b/include/linux/resctrl_types.h @@ -50,4 +50,9 @@ enum resctrl_event_id { #define QOS_NUM_MBM_EVENTS (QOS_L3_MBM_LOCAL_EVENT_ID - QOS_L3_MBM_TOTAL_E= VENT_ID + 1) #define MBM_EVENT_IDX(evt) ((evt) - QOS_L3_MBM_TOTAL_EVENT_ID) =20 +/* Event value display formats */ +enum resctrl_event_fmt { + EVT_FORMAT_U64, + EVT_FORMAT_U46_18, +}; #endif /* __LINUX_RESCTRL_TYPES_H */ diff --git a/fs/resctrl/internal.h b/fs/resctrl/internal.h index d8aa69b42c74..aaa74a17257d 100644 --- a/fs/resctrl/internal.h +++ b/fs/resctrl/internal.h @@ -73,6 +73,7 @@ static inline struct rdt_fs_context *rdt_fc2context(struc= t fs_context *fc) * @configurable: true if the event is configurable * @enabled: true if the event is enabled * @any_cpu: true if the event can be read from any CPU + * @display_format: format to display value to users * @list: entry in &rdt_resource->evt_list */ struct mon_evt { @@ -82,6 +83,7 @@ struct mon_evt { bool configurable; bool enabled; bool any_cpu; + enum resctrl_event_fmt display_format; struct list_head list; }; =20 diff --git a/fs/resctrl/ctrlmondata.c b/fs/resctrl/ctrlmondata.c index 7a2957b9c13e..1544c103446b 100644 --- a/fs/resctrl/ctrlmondata.c +++ b/fs/resctrl/ctrlmondata.c @@ -569,6 +569,28 @@ 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 +#define NUM_FRAC_BITS 18 +#define FRAC_MASK GENMASK(NUM_FRAC_BITS - 1, 0) + +static void print_event_value(struct seq_file *m, enum resctrl_event_fmt t= ype, u64 val) +{ + u64 frac; + + switch (type) { + case EVT_FORMAT_U64: + seq_printf(m, "%llu\n", val); + break; + case EVT_FORMAT_U46_18: + frac =3D val & FRAC_MASK; + frac =3D frac * 1000000; + /* round values up to nearest decimal representation */ + frac +=3D 1ul << (NUM_FRAC_BITS - 1); + frac >>=3D NUM_FRAC_BITS; + seq_printf(m, "%llu.%06llu\n", val >> NUM_FRAC_BITS, frac); + break; + } +} + int rdtgroup_mondata_show(struct seq_file *m, void *arg) { struct kernfs_open_file *of =3D m->private; @@ -637,7 +659,7 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg) else if (rr.err =3D=3D -EINVAL) seq_puts(m, "Unavailable\n"); else - seq_printf(m, "%llu\n", rr.val); + print_event_value(m, evt->display_format, rr.val); =20 out: rdtgroup_kn_unlock(of->kn); diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c index e903d3c076ee..be78488a15e5 100644 --- a/fs/resctrl/monitor.c +++ b/fs/resctrl/monitor.c @@ -844,19 +844,22 @@ static void dom_data_exit(struct rdt_resource *r) =20 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, + .name =3D "llc_occupancy", + .evtid =3D QOS_L3_OCCUP_EVENT_ID, + .rid =3D RDT_RESOURCE_L3, + .display_format =3D EVT_FORMAT_U64, }, [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, + .name =3D "mbm_total_bytes", + .evtid =3D QOS_L3_MBM_TOTAL_EVENT_ID, + .rid =3D RDT_RESOURCE_L3, + .display_format =3D EVT_FORMAT_U64, }, [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, + .name =3D "mbm_local_bytes", + .evtid =3D QOS_L3_MBM_LOCAL_EVENT_ID, + .rid =3D RDT_RESOURCE_L3, + .display_format =3D EVT_FORMAT_U64, }, }; =20 --=20 2.48.1 From nobody Fri Dec 19 19:02:40 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) (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 2CA1A3987D for ; Tue, 29 Apr 2025 00:34:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745886862; cv=none; b=mkhEHy3WUzUnK7JaXMHq29RZGwxU/k4KRGX+JxW5FsOuyPIOxWVHmRrUMxrDdMDkMIANiy8pJqtD2dOVqZyBM/F/lzXu9fblWIRAKaq38I5BbMnRFhopv75P4/XCOVFjVIr+KCr7LGHTaJBhYs/RTBfvBXv2trblZk7fUl+Ipuo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745886862; c=relaxed/simple; bh=ClI/LqjKobUz8Hh4f9zIJCDGblt0kOvF3kyNeyzacvU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KGpvnfSeVTTnxoiUGStRH50mQCSEEvyDRLq4qJGUjcI0742OKA4IDIsb9FZ7aXeStblVKz5YqtuAql7ft+ECuMWl7y5E5yadHhii9a/pSQlAemVXkSzexYck3UtJ/eui0jYsuKOJFTcZF83+jY8DPYDRi3K5e12e7qT0XQV3NOw= 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=Z+1a6PpM; arc=none smtp.client-ip=192.198.163.9 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="Z+1a6PpM" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1745886861; x=1777422861; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ClI/LqjKobUz8Hh4f9zIJCDGblt0kOvF3kyNeyzacvU=; b=Z+1a6PpMOqiIFj/810FdRnUCwuBFKYmnoY5lFCv+cK3Fdvm2hXdV7j2C vrunRPzFoozqFZGDnc6q7/c7Q8VA3sam+gx3ifJRYXoLHrCQE5aNAQJuc MZWSwg8hQ8qV8bo5CEWpE94V5ViGugQMBjoDpbEx1re02XeLujtmdrg+o m8fHRkOWkeTB8z65WkN7vqTBm75YKyZbmIsmTSp/kl05/y037EQlWhld0 vPGUXS/aS9wyxElYvRV0u4JQaFi9bUz+HwDB2Zu9VNPOkkwJvXdEewnkJ a3RpAz5lyv0RQJyhz/hMSOfXaucgM4iEYKCL2IZ5Ms1ZtKhGYxwMXoQRV Q==; X-CSE-ConnectionGUID: Wjeo1LAOQ3+w9y5m9E8ODw== X-CSE-MsgGUID: NPoqonCAReq3WOp2WDhP3w== X-IronPort-AV: E=McAfee;i="6700,10204,11417"; a="58148166" X-IronPort-AV: E=Sophos;i="6.15,247,1739865600"; d="scan'208";a="58148166" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2025 17:34:15 -0700 X-CSE-ConnectionGUID: SzhiGjUERGWTP2OUMQY9MQ== X-CSE-MsgGUID: Qyv1VzjWSMCYxBbdPVchUA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,247,1739865600"; d="scan'208";a="133394012" Received: from agluck-desk3.sc.intel.com ([172.25.222.70]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2025 17:34:14 -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 v4 14/31] fs/resctrl: Add an architectural hook called for each mount Date: Mon, 28 Apr 2025 17:33:40 -0700 Message-ID: <20250429003359.375508-15-tony.luck@intel.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250429003359.375508-1-tony.luck@intel.com> References: <20250429003359.375508-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 | 8 ++++++++ fs/resctrl/rdtgroup.c | 2 ++ 3 files changed, 16 insertions(+) diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index 4af5e8d30193..6f424fffa083 100644 --- a/include/linux/resctrl.h +++ b/include/linux/resctrl.h @@ -450,6 +450,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 58bc218070e2..2f3efc4b1816 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -707,6 +707,14 @@ static int resctrl_arch_offline_cpu(unsigned int cpu) return 0; } =20 +void resctrl_arch_pre_mount(void) +{ + static atomic_t only_once; + + if (atomic_cmpxchg(&only_once, 0, 1)) + return; +} + enum { RDT_FLAG_CMT, RDT_FLAG_MBM_TOTAL, diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index d16bb05fafe8..da71057f3ff4 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -2581,6 +2581,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.48.1 From nobody Fri Dec 19 19:02:40 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) (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 DEA0E1E32A0 for ; Tue, 29 Apr 2025 00:34:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745886863; cv=none; b=RBup5QY4jqPvUBlydd8orwQf/qbO+iFjU1p/JDEK/TU7H/opneT7AhIErW9piBG9DOXrSwYWqvSTi/ZqyvJy0cXOqqprbJPRMKMJQVfYMDoIA3+Emc1lb0frGtL/SNOd4t/x+pPhMuxoJih9umofFQ9ury6gbhYh54JxlR3ATD0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745886863; c=relaxed/simple; bh=15VcvfROAR474ItBc9auyiDza59uw8Tb2NSQm0dC2f0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=P7VhzTDt3leBHo79SAoy3aa6fC+vNmRp1xp/Z+S3h92hL1y0rv62UJ8bD3BHT2WxtrX5Q86VwZI+SSp0j3OqMiUJBLWIX1YVu1PMAQs+ym7QE5G+CF/FLTjH3OoDJ1rgA6l5qDnDwwWlDTrq5ZifqUXo/O8FuRRSm9wMJ3WbIpU= 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=SK1j3S1+; arc=none smtp.client-ip=192.198.163.9 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="SK1j3S1+" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1745886862; x=1777422862; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=15VcvfROAR474ItBc9auyiDza59uw8Tb2NSQm0dC2f0=; b=SK1j3S1+KbgCCK+VOCPHWm6NewC3SvxD/sNN2f3jYXrYuzKz+hwKzRoA W1qV5xutSf+qvIS+fhlvTbZ6I6YeFUnLk+F6OeWRR9LyUmkyuWKecRpyc +WV23TtVwfSLpzfZZYA7YvPcV/M9z5AoRF3K9MM4BKUBRcpV5K5aCPdn5 vp8rpoCgEFQw24nTUxucYGoEcU3jO3ziqa5E8k0BCn5+6w+pciEroGzWx /q+TSp1iPuBZLKuE5zTA/1MLSagsLRLyGvQia23bFDuWp0ZiDCC4o+eXD LyBQSUYrmqBp3UpUUkkiOy49EmXmvARLTlYARL80LJ55VDj/zxzR3HzRG w==; X-CSE-ConnectionGUID: ci3vqIekRm6gNslJKPSZEQ== X-CSE-MsgGUID: uVgmPZVqSueH5nfkAT3p+w== X-IronPort-AV: E=McAfee;i="6700,10204,11417"; a="58148176" X-IronPort-AV: E=Sophos;i="6.15,247,1739865600"; d="scan'208";a="58148176" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2025 17:34:16 -0700 X-CSE-ConnectionGUID: 7Dpxym4ORNm+cMY98A0EEg== X-CSE-MsgGUID: vUPEr53IR0CjyehQ5vJJMQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,247,1739865600"; d="scan'208";a="133394016" Received: from agluck-desk3.sc.intel.com ([172.25.222.70]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2025 17:34:15 -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 v4 15/31] x86/resctrl: Add and initialize rdt_resource for package scope core monitor Date: Mon, 28 Apr 2025 17:33:41 -0700 Message-ID: <20250429003359.375508-16-tony.luck@intel.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250429003359.375508-1-tony.luck@intel.com> References: <20250429003359.375508-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 with code to build domains at the package granularity. Signed-off-by: Tony Luck --- include/linux/resctrl.h | 2 ++ arch/x86/kernel/cpu/resctrl/core.c | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index 6f424fffa083..3ae50b947a99 100644 --- a/include/linux/resctrl.h +++ b/include/linux/resctrl.h @@ -53,6 +53,7 @@ enum resctrl_res_level { RDT_RESOURCE_L2, RDT_RESOURCE_MBA, RDT_RESOURCE_SMBA, + RDT_RESOURCE_PERF_PKG, =20 /* Must be the last */ RDT_NUM_RESOURCES, @@ -250,6 +251,7 @@ enum resctrl_scope { RESCTRL_L2_CACHE =3D 2, RESCTRL_L3_CACHE =3D 3, RESCTRL_L3_NODE, + RESCTRL_PACKAGE, }; =20 /** diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resct= rl/core.c index 2f3efc4b1816..4d1556707c01 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -99,6 +99,15 @@ struct rdt_hw_resource rdt_resources_all[RDT_NUM_RESOURC= ES] =3D { .schema_fmt =3D RESCTRL_SCHEMA_RANGE, }, }, + [RDT_RESOURCE_PERF_PKG] =3D + { + .r_resctrl =3D { + .rid =3D RDT_RESOURCE_PERF_PKG, + .name =3D "PERF_PKG", + .mon_scope =3D RESCTRL_PACKAGE, + .mon_domains =3D mon_domain_init(RDT_RESOURCE_PERF_PKG), + }, + }, }; =20 u32 resctrl_arch_system_num_rmid_idx(void) @@ -430,6 +439,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; } --=20 2.48.1 From nobody Fri Dec 19 19:02:40 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) (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 52EE6130A54 for ; Tue, 29 Apr 2025 00:34:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745886864; cv=none; b=ZLvcHMHDM/Itl+QRk5zUm2kIsVAr91tX4KnmDr2Ifudo2X/hfZ4ji5Z5rAzIny0HtWvzUyZ59rNnerbwpmXG5SYO8EojgBnebb2ByDSAlhFOvLXFdiagEq8WLw8MKyHWAbgjO4RfLM9iJQcw4LYgZiKpzlKSpCQ3wmFaj0727tA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745886864; c=relaxed/simple; bh=GG8x/BhJY+MTjnC/1g0Vw3bYYenFGszoMzSoFra/LLU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CMb2xy6OeXdVUa15WbKuHADrft8T550BXj66mFgT5bBRX9xnq+zvPp4rGALyV9g2Td5U/4KYf98Tx0emLSYn0kKJD7myZYk7ycGyWvzj4avaGraPnA9zuxfgojZag//kvQ4j4OUwIgtganK16Yj1EuzZ/n8VfVuKwQ25gSFGp8w= 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=hnCt27aD; arc=none smtp.client-ip=192.198.163.9 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="hnCt27aD" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1745886862; x=1777422862; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=GG8x/BhJY+MTjnC/1g0Vw3bYYenFGszoMzSoFra/LLU=; b=hnCt27aDcU+QBY4RyVn/COAukuAjlRFKFlg/D7nyiB32YXjR9HiDgjFv oqgR0hDYcbfBw5VP1vGkM2QhadeA5TRQUKpZgvR0boCdNKs3cSlTCAV2K vg+TO0OP1z6NnkIGZcMvbhccyB3WAaiZJA/xvigL6Shmlr8H76FTlbTJm g2Yj7OTyGMJJApodtV0V+jdunBDrS32biuA16LAcA61qAUqW7KX+Dh64M LuQC1BHsNDD/MC/XBtw5n8RJT9+k00/iTe0cQ2kFMuh2eM4iR/1UDag+W tDdZ5bJlSGAao0aIFl7KQ0K/kQ374E8zospVf7JH1aTDJHv8T62bMgyxN A==; X-CSE-ConnectionGUID: A6G/cbF3Q2OdcIdx/XsYEg== X-CSE-MsgGUID: 0SlnvOhJRB+d39Vz+/irlg== X-IronPort-AV: E=McAfee;i="6700,10204,11417"; a="58148185" X-IronPort-AV: E=Sophos;i="6.15,247,1739865600"; d="scan'208";a="58148185" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2025 17:34:16 -0700 X-CSE-ConnectionGUID: laoN1NPPR0GwbxNccwn2MQ== X-CSE-MsgGUID: VqW6ZS5QSz2CJQkcxHX1LQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,247,1739865600"; d="scan'208";a="133394021" Received: from agluck-desk3.sc.intel.com ([172.25.222.70]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2025 17:34:16 -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 v4 16/31] x86/resctrl: Add first part of telemetry event enumeration Date: Mon, 28 Apr 2025 17:33:42 -0700 Message-ID: <20250429003359.375508-17-tony.luck@intel.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250429003359.375508-1-tony.luck@intel.com> References: <20250429003359.375508-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 OOBMSM VSEC discovery driver enumerates many different types of telemetry resources. Resctrl is only interested in the ones that are tied to an RMID value in the IA32_PQR_ASSOC MSR. Make a request for each of the FEATURE_PER_RMID_ENERGY_TELEM and FEATURE_PER_RMID_PERF_TELEM feature groups and scan the list of known event groups for matching guid values. Configuration to follow in subsequent patches. Hold onto references to any pmt_feature_groups that resctrl uses until resctrl exit. Signed-off-by: Tony Luck --- arch/x86/kernel/cpu/resctrl/internal.h | 8 ++ arch/x86/kernel/cpu/resctrl/core.c | 5 ++ arch/x86/kernel/cpu/resctrl/intel_aet.c | 113 ++++++++++++++++++++++++ arch/x86/kernel/cpu/resctrl/Makefile | 1 + 4 files changed, 127 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 83b20e6b25d7..571db665eca6 100644 --- a/arch/x86/kernel/cpu/resctrl/internal.h +++ b/arch/x86/kernel/cpu/resctrl/internal.h @@ -167,4 +167,12 @@ void __init intel_rdt_mbm_apply_quirk(void); =20 void rdt_domain_reconfigure_cdp(struct rdt_resource *r); =20 +#ifdef CONFIG_INTEL_AET_RESCTRL +bool intel_aet_get_events(void); +void __exit intel_aet_exit(void); +#else +static inline bool intel_aet_get_events(void) { return false; } +static inline void intel_aet_exit(void) { }; +#endif + #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 4d1556707c01..0103f577e4ca 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -724,6 +724,9 @@ void resctrl_arch_pre_mount(void) =20 if (atomic_cmpxchg(&only_once, 0, 1)) return; + + if (!intel_aet_get_events()) + return; } =20 enum { @@ -1076,6 +1079,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..dda44baf75ae --- /dev/null +++ b/arch/x86/kernel/cpu/resctrl/intel_aet.c @@ -0,0 +1,113 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Resource Director Technology(RDT) + * - Intel Application Energy Telemetry + * + * Copyright (C) 2025 Intel Corporation + * + * Author: + * Tony Luck + */ + +#define pr_fmt(fmt) "resctrl: " fmt + +#include +#include +#include + +/* Temporary - delete from final version */ +#include "fake_intel_aet_features.h" + +#include "internal.h" + +/** + * struct event_group - All information about a group of telemetry events. + * Some fields initialized with MMIO layout informati= on + * gleaned from the XML files. Others are set from da= ta + * retrieved from intel_pmt_get_regions_by_feature(). + * @pfg: The pmt_feature_group for this event group + * @guid: Unique number per XML description file + */ +struct event_group { + struct pmt_feature_group *pfg; + int guid; +}; + +/* Link: https://github.com/intel/Intel-PMT xml/CWF/OOBMSM/RMID-ENERGY *.x= ml */ +static struct event_group energy_0x26696143 =3D { + .guid =3D 0x26696143, +}; + +/* Link: https://github.com/intel/Intel-PMT xml/CWF/OOBMSM/RMID-PERF *.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) + +static bool configure_events(struct event_group *e, struct pmt_feature_gro= up *p) +{ + return false; +} + +DEFINE_FREE(intel_pmt_put_feature_group, struct pmt_feature_group *, \ + if (!IS_ERR_OR_NULL(_T)) \ + intel_pmt_put_feature_group(_T)) + +static bool get_pmt_feature(enum pmt_feature_id feature) +{ + struct pmt_feature_group *p __free(intel_pmt_put_feature_group) =3D NULL; + struct event_group **peg; + bool ret; + + p =3D intel_pmt_get_regions_by_feature(feature); + + if (IS_ERR_OR_NULL(p)) + return false; + + for (peg =3D &known_event_groups[0]; peg < &known_event_groups[NUM_KNOWN_= GROUPS]; peg++) { + for (int i =3D 0; i < p->count; i++) { + if ((*peg)->guid =3D=3D p->regions[i].guid) { + ret =3D configure_events((*peg), p); + if (ret) { + (*peg)->pfg =3D no_free_ptr(p); + return true; + } + break; + } + } + } + + return false; +} + +/* + * Ask OOBMSM discovery driver for all the RMID based telemetry groups + * that it supports. + */ +bool intel_aet_get_events(void) +{ + bool ret1, ret2; + + ret1 =3D get_pmt_feature(FEATURE_PER_RMID_ENERGY_TELEM); + ret2 =3D get_pmt_feature(FEATURE_PER_RMID_PERF_TELEM); + + return ret1 || ret2; +} + +void __exit intel_aet_exit(void) +{ + struct event_group **peg; + + for (peg =3D &known_event_groups[0]; peg < &known_event_groups[NUM_KNOWN_= GROUPS]; peg++) { + if ((*peg)->pfg) { + intel_pmt_put_feature_group((*peg)->pfg); + (*peg)->pfg =3D NULL; + } + } +} diff --git a/arch/x86/kernel/cpu/resctrl/Makefile b/arch/x86/kernel/cpu/res= ctrl/Makefile index 28ae1c88b2ac..8b4603cad783 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_INTEL_AET_RESCTRL) +=3D intel_aet.o obj-$(CONFIG_INTEL_AET_RESCTRL) +=3D fake_intel_aet_features.o obj-$(CONFIG_RESCTRL_FS_PSEUDO_LOCK) +=3D pseudo_lock.o =20 --=20 2.48.1 From nobody Fri Dec 19 19:02:40 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) (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 F32D638F80 for ; Tue, 29 Apr 2025 00:34:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745886865; cv=none; b=RELg+OpVcPOuQHo2YlYi/yI2qFvYy/LI9cQn3HRpkWsUk5q/szk4Gv8RwMDo5qgeaG8hBTQYohbm8lS7p/I1aIES2HSJyNecfwEjpXzG0cyQOAjwCEQGIRdQLZXcfh3AB03gsi66aXt8oF6KpJ7P1/QaIcY7NpAlA5Y1ei0BVbQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745886865; c=relaxed/simple; bh=DBNWvEwmeMeKU8j2/lRh512Z9DrD7XKVYbh9X8sJzag=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Lb7uZUz5qf9ATAQkyTNTQEBH8nFqgkjkdDlQ2Zjyku71IQvAF1EZKPnr22NVorGWHu7e9nCmtK1ukif9nU2ffSPl3V90w+9tZ7yJRu+fO+eddaJN3Q5TiSDf5No2YmQxsQCEP8KYAMc/AiiFuMjAMpwOe6/+JFudENs8Wet0qCw= 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=OX2IUPFc; arc=none smtp.client-ip=192.198.163.9 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="OX2IUPFc" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1745886863; x=1777422863; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=DBNWvEwmeMeKU8j2/lRh512Z9DrD7XKVYbh9X8sJzag=; b=OX2IUPFcc50kdOd/aNd7mFFytVlQVJhvxXKj8VQMZhOiWgKoYy/hbOsp mMgQTp2P0wuN3qwO7XyoygZdAr94bVnmw1vrhB/ttkqlHwrwcrtCZECAc +g4NbKZTBnPPOrnBfGrr64x5iekQauJ2rZ3KS4FsjMtBwprk6BF2QsvTE er9cyTJx/YrkHvxAGaNbQDJmCP1f5XLacn0EL6qH230odZlf7gwe4e+VA RZnM09Kq0pwC13D4IZT+p0V66ONHvmVBcVcnkpbjfA5CTbf8d2PM5zHqf PhURmvuNozR6ojQv620lZwIknK4gZRM7fveI8EkvikJCQ7WP7Yefh0JDa Q==; X-CSE-ConnectionGUID: kcBC4YT0QmyOu2rPZIt1BA== X-CSE-MsgGUID: cuU+AzwTR3OZd+C2ETfdsA== X-IronPort-AV: E=McAfee;i="6700,10204,11417"; a="58148196" X-IronPort-AV: E=Sophos;i="6.15,247,1739865600"; d="scan'208";a="58148196" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2025 17:34:17 -0700 X-CSE-ConnectionGUID: 1l3tv4A6Q8GRiWCaI8RI/Q== X-CSE-MsgGUID: 5MvWLbtbQ7iPfZ490DL4gQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,247,1739865600"; d="scan'208";a="133394024" Received: from agluck-desk3.sc.intel.com ([172.25.222.70]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2025 17:34:16 -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 v4 17/31] x86/resctrl: Add second part of telemetry event enumeration Date: Mon, 28 Apr 2025 17:33:43 -0700 Message-ID: <20250429003359.375508-18-tony.luck@intel.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250429003359.375508-1-tony.luck@intel.com> References: <20250429003359.375508-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. Signed-off-by: Tony Luck --- arch/x86/kernel/cpu/resctrl/intel_aet.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/arch/x86/kernel/cpu/resctrl/intel_aet.c b/arch/x86/kernel/cpu/= resctrl/intel_aet.c index dda44baf75ae..a0365c3ce982 100644 --- a/arch/x86/kernel/cpu/resctrl/intel_aet.c +++ b/arch/x86/kernel/cpu/resctrl/intel_aet.c @@ -52,6 +52,27 @@ static struct event_group *known_event_groups[] =3D { =20 static bool configure_events(struct event_group *e, struct pmt_feature_gro= up *p) { + int *pkgcounts __free(kfree) =3D NULL; + struct telemetry_region *tr; + int num_pkgs; + + num_pkgs =3D topology_max_packages(); + pkgcounts =3D kcalloc(num_pkgs, sizeof(*pkgcounts), GFP_KERNEL); + if (!pkgcounts) + return false; + + /* Get per-package counts of telemetry_region for this guid */ + for (int i =3D 0; i < p->count; i++) { + tr =3D &p->regions[i]; + if (tr->guid !=3D e->guid) + continue; + if (tr->plat_info.package_id >=3D num_pkgs) { + pr_warn_once("Bad package %d\n", tr->plat_info.package_id); + continue; + } + pkgcounts[tr->plat_info.package_id]++; + } + return false; } =20 --=20 2.48.1 From nobody Fri Dec 19 19:02:40 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) (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 0024A1EF080 for ; Tue, 29 Apr 2025 00:34:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745886866; cv=none; b=mTY23jfStEjfeyHB0YtfZIolvOS+dig2kjqYNammc9dQCEGqNaxdKurYi3GBtybU1gtD0YvgcCDu33ubnry0rO9KX6OUNvMmU8O+9Ntd8hX+L7nxvCCg2+bewbpXOS/KVDaMCgjhWsLfaLIkMq6LXlnfNixK4A1QjaqZTZAfBUU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745886866; c=relaxed/simple; bh=WpX4W9eMoqX5jiHgxecwgFYS8iw5BYHo22VOGiJt1VU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OFgIRDRKqVYPu+uQPZNJqu84e5einJpQ3U0PpVd/qnVyuppQhVrrqsHB11ySI4eob7IAPynkWHW98s3Y03Iqr7e2T9x+Qrm9Y3b/FMzBmG0C8iHHXoZqt7uUJJPbwePeJ91pCbZdEbC/SkcfKKc/LI2bDaUmBKNT6BawPM7Cqoc= 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=QquwfViF; arc=none smtp.client-ip=192.198.163.9 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="QquwfViF" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1745886864; x=1777422864; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=WpX4W9eMoqX5jiHgxecwgFYS8iw5BYHo22VOGiJt1VU=; b=QquwfViF4yJEO/PJLc+IC/UN+KbRi8HSsgOuRGSCp0TlDzrRBwoDzqON 8Hj2Fldd1ETSQmJ5Gj6lwMZO6bSIde77jkC4S3C00cszdu2yIe3gqybUk b8J1QZVQe7x9u6cojAdf+oJrRH9Fnv9n1EhgrfZGXwp9eJxvkoj2gr9Jc +AedaECusitGGNRV74q6umoggkX4PKCWEkBdbsD4x8ompN1O8dmXf52Sd TuqjkFCcfed0Uph29CnU2WZpdCHFmpYcX1wnkvv4FK5kXZ0UV94IGBelJ +ieCiYCAr1LZEf1HVMTjgboY6LrKKWvXNn4K08wPqmINNotU1oKPRLmam Q==; X-CSE-ConnectionGUID: PA6pXAa6QoKfy6aN+mvgRQ== X-CSE-MsgGUID: 5a7d3jxRQFqZeVMADpGvOQ== X-IronPort-AV: E=McAfee;i="6700,10204,11417"; a="58148205" X-IronPort-AV: E=Sophos;i="6.15,247,1739865600"; d="scan'208";a="58148205" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2025 17:34:18 -0700 X-CSE-ConnectionGUID: f1QFlmulS8+qVrKJD0j0rw== X-CSE-MsgGUID: Ai97tRPhRiGRxQwb+H52sw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,247,1739865600"; d="scan'208";a="133394027" Received: from agluck-desk3.sc.intel.com ([172.25.222.70]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2025 17:34:17 -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 v4 18/31] x86/resctrl: Add third part of telemetry event enumeration Date: Mon, 28 Apr 2025 17:33:44 -0700 Message-ID: <20250429003359.375508-19-tony.luck@intel.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250429003359.375508-1-tony.luck@intel.com> References: <20250429003359.375508-1-tony.luck@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Counters for telemetry events are in MMIO space. Each telemetry_region structure returned in the pmt_feature_group returned from OOBMSM contains the base MMIO address for the counters. Scan all the telemetry_region structures again and gather these addresses into a more convenient structure with addresses for each aggregator indexed by package id. Note that there may be multiple aggregators per package. Signed-off-by: Tony Luck --- arch/x86/kernel/cpu/resctrl/intel_aet.c | 55 +++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/arch/x86/kernel/cpu/resctrl/intel_aet.c b/arch/x86/kernel/cpu/= resctrl/intel_aet.c index a0365c3ce982..03839d5c369b 100644 --- a/arch/x86/kernel/cpu/resctrl/intel_aet.c +++ b/arch/x86/kernel/cpu/resctrl/intel_aet.c @@ -20,6 +20,16 @@ =20 #include "internal.h" =20 +/** + * struct mmio_info - Array of MMIO addresses for a package + * @count: Number of addresses on this package + * @addrs: The MMIO addresses + */ +struct mmio_info { + int count; + void __iomem *addrs[] __counted_by(count); +}; + /** * struct event_group - All information about a group of telemetry events. * Some fields initialized with MMIO layout informati= on @@ -27,10 +37,12 @@ * retrieved from intel_pmt_get_regions_by_feature(). * @pfg: The pmt_feature_group for this event group * @guid: Unique number per XML description file + * @pkginfo: Per-package MMIO addresses */ struct event_group { struct pmt_feature_group *pfg; int guid; + struct mmio_info **pkginfo; }; =20 /* Link: https://github.com/intel/Intel-PMT xml/CWF/OOBMSM/RMID-ENERGY *.x= ml */ @@ -50,12 +62,33 @@ static struct event_group *known_event_groups[] =3D { =20 #define NUM_KNOWN_GROUPS ARRAY_SIZE(known_event_groups) =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)) + static bool configure_events(struct event_group *e, struct pmt_feature_gro= up *p) { + struct mmio_info __free(mmio_info) **pkginfo =3D NULL; int *pkgcounts __free(kfree) =3D NULL; struct telemetry_region *tr; + struct mmio_info *mmi; int num_pkgs; =20 + if (e->pkginfo) { + pr_warn("Duplicate telemetry information for guid 0x%x\n", e->guid); + return false; + } + num_pkgs =3D topology_max_packages(); pkgcounts =3D kcalloc(num_pkgs, sizeof(*pkgcounts), GFP_KERNEL); if (!pkgcounts) @@ -73,6 +106,27 @@ static bool configure_events(struct event_group *e, str= uct pmt_feature_group *p) pkgcounts[tr->plat_info.package_id]++; } =20 + /* Allocate per-package arrays and save MMIO addresses */ + pkginfo =3D kcalloc(num_pkgs, sizeof(*pkginfo), GFP_KERNEL); + if (!pkginfo) + return false; + for (int i =3D 0; i < num_pkgs; i++) { + pkginfo[i] =3D kmalloc(struct_size(pkginfo[i], addrs, pkgcounts[i]), GFP= _KERNEL); + if (!pkginfo[i]) + return false; + pkginfo[i]->count =3D pkgcounts[i]; + } + + /* Save MMIO address(es) for each aggregator in per-package structures */ + for (int i =3D 0; i < p->count; i++) { + tr =3D &p->regions[i]; + if (tr->guid !=3D e->guid || tr->plat_info.package_id >=3D num_pkgs) + 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 false; } =20 @@ -130,5 +184,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.48.1 From nobody Fri Dec 19 19:02:40 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) (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 8C39C20299C for ; Tue, 29 Apr 2025 00:34:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745886866; cv=none; b=WB8yTK2VhC3OblpYnqZMyT7ekZtfI9gYEs44lbEXzSIP8k4QtJhMhDIQePx6qtjJfmCK46HlQcsw+0R78rnXw1BnWePDNcH+LvaE7Ja93Wc+yhuPTcbjfdkcSgIzqNvqto3e057AKYdBKHEieiK/atV90SPtBg6I4hl6aFp4V+A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745886866; c=relaxed/simple; bh=Tu5h7IDoxLqfzl78oPg61l89Ts4MzhC18FCRBVL5q00=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=K/6mHsjce+7AF963MdZ+eDX0PRFQ+tT0nqNoENWmbKwPTf6v8FROoX/HT9TSNISWwBrgQKryOyT8ECJRoxvhft+vsr3g3me8u3REcSuuVQxiD+3sGJ/yzJa957CxQfHc006f40GL6oSfVO0Krgqm6SbslCnjFihD6BNRWEwBOiA= 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=ZEwJ9a+Q; arc=none smtp.client-ip=192.198.163.9 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="ZEwJ9a+Q" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1745886864; x=1777422864; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Tu5h7IDoxLqfzl78oPg61l89Ts4MzhC18FCRBVL5q00=; b=ZEwJ9a+QZCPzdo/m6OMDixsgompzk/V2aQvyrBYSl271GpHsswAckEtK clrgQL8gK5gUq5nl7Qsbk+1gW5HKMChwm17wPx8tySw1RJJtXfZfxjtMN xug16Pt1ssxzd5BJkSKfDlrB1ErOCAYKUSDUweL86iws7PnPzfWLYHHYZ wuVFO9DIIG28mxc+j4uQd0S5/jqUsU8gtC6asLBtEweCQUlvWMtL07910 O5ToQQygQz8h38uHU3rcId5TOcJUSQXYHOT47TdPWY4xyYYqAc4LLnNzG Ii5HCaR+XphrNal09/LQXbWE75MVYtB9H0al1yiJ9x2OZ1k3SCr2GsJjI A==; X-CSE-ConnectionGUID: 39s8CVXFTnKRpVxvI4XWcQ== X-CSE-MsgGUID: bWqSOzc7TO+0QPEF/RmZVg== X-IronPort-AV: E=McAfee;i="6700,10204,11417"; a="58148213" X-IronPort-AV: E=Sophos;i="6.15,247,1739865600"; d="scan'208";a="58148213" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2025 17:34:18 -0700 X-CSE-ConnectionGUID: 1s0gbHq8ScuDwc89e4Fc4w== X-CSE-MsgGUID: 3FxbaTNZTCe+yXz+XkFWEQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,247,1739865600"; d="scan'208";a="133394032" Received: from agluck-desk3.sc.intel.com ([172.25.222.70]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2025 17:34:18 -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 v4 19/31] x86,fs/resctrl: Fill in details of Clearwater Forest events Date: Mon, 28 Apr 2025 17:33:45 -0700 Message-ID: <20250429003359.375508-20-tony.luck@intel.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250429003359.375508-1-tony.luck@intel.com> References: <20250429003359.375508-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. 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 | 31 ++++++++++++++ fs/resctrl/monitor.c | 54 +++++++++++++++++++++++++ 3 files changed, 96 insertions(+) diff --git a/include/linux/resctrl_types.h b/include/linux/resctrl_types.h index 6245034f6c76..39de5451cff8 100644 --- a/include/linux/resctrl_types.h +++ b/include/linux/resctrl_types.h @@ -43,6 +43,17 @@ enum resctrl_event_id { QOS_L3_MBM_TOTAL_EVENT_ID =3D 0x02, QOS_L3_MBM_LOCAL_EVENT_ID =3D 0x03, =20 + /* Intel Telemetry Events */ + PMT_EVENT_ENERGY, + PMT_EVENT_ACTIVITY, + PMT_EVENT_STALLS_LLC_HIT, + PMT_EVENT_C1_RES, + PMT_EVENT_UNHALTED_CORE_CYCLES, + PMT_EVENT_STALLS_LLC_MISS, + PMT_EVENT_AUTO_C6_RES, + PMT_EVENT_UNHALTED_REF_CYCLES, + PMT_EVENT_UOPS_RETIRED, + /* Must be the last */ QOS_NUM_EVENTS, }; diff --git a/arch/x86/kernel/cpu/resctrl/intel_aet.c b/arch/x86/kernel/cpu/= resctrl/intel_aet.c index 03839d5c369b..7e4f6a6672d4 100644 --- a/arch/x86/kernel/cpu/resctrl/intel_aet.c +++ b/arch/x86/kernel/cpu/resctrl/intel_aet.c @@ -30,6 +30,18 @@ struct mmio_info { void __iomem *addrs[] __counted_by(count); }; =20 +/** + * struct pmt_event - Telemetry event. + * @evtid: Resctrl event id + * @evt_idx: Counter index within each per-RMID block of counters + */ +struct pmt_event { + enum resctrl_event_id evtid; + int evt_idx; +}; + +#define EVT(id, idx) { .evtid =3D id, .evt_idx =3D idx } + /** * struct event_group - All information about a group of telemetry events. * Some fields initialized with MMIO layout informati= on @@ -38,21 +50,40 @@ struct mmio_info { * @pfg: The pmt_feature_group for this event group * @guid: Unique number per XML description file * @pkginfo: Per-package MMIO addresses + * @num_events: Number of events in this group + * @evts: Array of event descriptors */ struct event_group { struct pmt_feature_group *pfg; int guid; struct mmio_info **pkginfo; + int num_events; + struct pmt_event evts[] __counted_by(num_events); }; =20 /* Link: https://github.com/intel/Intel-PMT xml/CWF/OOBMSM/RMID-ENERGY *.x= ml */ static struct event_group energy_0x26696143 =3D { .guid =3D 0x26696143, + .num_events =3D 2, + .evts =3D { + EVT(PMT_EVENT_ENERGY, 0), + EVT(PMT_EVENT_ACTIVITY, 1), + } }; =20 /* Link: https://github.com/intel/Intel-PMT xml/CWF/OOBMSM/RMID-PERF *.xml= */ static struct event_group perf_0x26557651 =3D { .guid =3D 0x26557651, + .num_events =3D 7, + .evts =3D { + EVT(PMT_EVENT_STALLS_LLC_HIT, 0), + EVT(PMT_EVENT_C1_RES, 1), + EVT(PMT_EVENT_UNHALTED_CORE_CYCLES, 2), + EVT(PMT_EVENT_STALLS_LLC_MISS, 3), + EVT(PMT_EVENT_AUTO_C6_RES, 4), + EVT(PMT_EVENT_UNHALTED_REF_CYCLES, 5), + EVT(PMT_EVENT_UOPS_RETIRED, 6), + } }; =20 static struct event_group *known_event_groups[] =3D { diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c index be78488a15e5..f848325591b4 100644 --- a/fs/resctrl/monitor.c +++ b/fs/resctrl/monitor.c @@ -861,6 +861,60 @@ struct mon_evt mon_event_all[QOS_NUM_EVENTS] =3D { .rid =3D RDT_RESOURCE_L3, .display_format =3D EVT_FORMAT_U64, }, + [PMT_EVENT_ENERGY] =3D { + .name =3D "core_energy", + .evtid =3D PMT_EVENT_ENERGY, + .rid =3D RDT_RESOURCE_PERF_PKG, + .display_format =3D EVT_FORMAT_U46_18, + }, + [PMT_EVENT_ACTIVITY] =3D { + .name =3D "activity", + .evtid =3D PMT_EVENT_ACTIVITY, + .rid =3D RDT_RESOURCE_PERF_PKG, + .display_format =3D EVT_FORMAT_U46_18, + }, + [PMT_EVENT_STALLS_LLC_HIT] =3D { + .name =3D "stalls_llc_hit", + .evtid =3D PMT_EVENT_STALLS_LLC_HIT, + .rid =3D RDT_RESOURCE_PERF_PKG, + .display_format =3D EVT_FORMAT_U64, + }, + [PMT_EVENT_C1_RES] =3D { + .name =3D "c1_res", + .evtid =3D PMT_EVENT_C1_RES, + .rid =3D RDT_RESOURCE_PERF_PKG, + .display_format =3D EVT_FORMAT_U64, + }, + [PMT_EVENT_UNHALTED_CORE_CYCLES] =3D { + .name =3D "unhalted_core_cycles", + .evtid =3D PMT_EVENT_UNHALTED_CORE_CYCLES, + .rid =3D RDT_RESOURCE_PERF_PKG, + .display_format =3D EVT_FORMAT_U64, + }, + [PMT_EVENT_STALLS_LLC_MISS] =3D { + .name =3D "stalls_llc_miss", + .evtid =3D PMT_EVENT_STALLS_LLC_MISS, + .rid =3D RDT_RESOURCE_PERF_PKG, + .display_format =3D EVT_FORMAT_U64, + }, + [PMT_EVENT_AUTO_C6_RES] =3D { + .name =3D "c6_res", + .evtid =3D PMT_EVENT_AUTO_C6_RES, + .rid =3D RDT_RESOURCE_PERF_PKG, + .display_format =3D EVT_FORMAT_U64, + }, + [PMT_EVENT_UNHALTED_REF_CYCLES] =3D { + .name =3D "unhalted_ref_cycles", + .evtid =3D PMT_EVENT_UNHALTED_REF_CYCLES, + .rid =3D RDT_RESOURCE_PERF_PKG, + .display_format =3D EVT_FORMAT_U64, + }, + [PMT_EVENT_UOPS_RETIRED] =3D { + .name =3D "uops_retired", + .evtid =3D PMT_EVENT_UOPS_RETIRED, + .rid =3D RDT_RESOURCE_PERF_PKG, + .display_format =3D EVT_FORMAT_U64, + }, }; =20 void resctrl_enable_mon_event(enum resctrl_event_id evtid, bool any_cpu) --=20 2.48.1 From nobody Fri Dec 19 19:02:40 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) (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 3C96220C02F for ; Tue, 29 Apr 2025 00:34:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745886867; cv=none; b=AtAjVrraIVFVTsY5+a//AzdsQ3FX74GdBB5dAxIh/17nDjJW+4FuPt3/hpgHOCAnLt67UARvoKCW8iGXMd/VIEOE9b+RFLoAFDvkLjY8Q2huVxu2Kp5+6StrAE7l0u0HcLPCyk3Cs1NYjniK7R/AABl9TFBc44qDZyL+wxoN8bY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745886867; c=relaxed/simple; bh=Be8xmCPgLLae0t8N+ASzNaMmLpZD+PZ5AUQZY9NvT8s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sXnyI7SisOcGZzr/5prwpKu+h7hnDmhljvhrEVg9I/9XzwAMKX7FLaWOaHSw6BdySeE80NyZ2dddv1h61kMoXJed+oywHrJDPIgvHH66YsAjMcHzhoanbi81r4tYHaJDy+sC6FhQnIvfc7N74zOunLfxbxXKDU6gssuiNSvsyIE= 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=TeckOM2w; arc=none smtp.client-ip=192.198.163.9 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="TeckOM2w" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1745886865; x=1777422865; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Be8xmCPgLLae0t8N+ASzNaMmLpZD+PZ5AUQZY9NvT8s=; b=TeckOM2wUcV4BEjHBeX44DRoiF0+jawmnxYTQwUu1zYOh8TfK7RUAXfo ZgrxEpxuwf/eB7pm8/5FOkKio0sExEvBXAgH1wi9ytxfHMmoOl8CADXLP YofCK3YjFVuBI90ZRqextX8aufKzrKoSdsnpPyN8ClfN73xzvcH2Rh+I5 MOtGPIhSvg9XQg/ipoGdX3QYdgVYXh2ewVzTjyb/ef8oCDxOKL5m5CbuB u+WQHzrXMc3kF4OcxYAdauEkRamNJi7r9Re9F55OCDskB3tpjR09kL3U2 2dNWh/3WuNEm91wAkBBx7vYY3iEGENkZ3Zwdg8ymf208CYCY4lXo9QwYc Q==; X-CSE-ConnectionGUID: uRVD0aZATwSLaK7Py+k53w== X-CSE-MsgGUID: M1vUJMHuTNCGf/S6RcQT0A== X-IronPort-AV: E=McAfee;i="6700,10204,11417"; a="58148225" X-IronPort-AV: E=Sophos;i="6.15,247,1739865600"; d="scan'208";a="58148225" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2025 17:34:19 -0700 X-CSE-ConnectionGUID: PKS2wv+NT6CRD/aoT20yDQ== X-CSE-MsgGUID: wB95YmXASoaY6NNbeFSg3Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,247,1739865600"; d="scan'208";a="133394035" Received: from agluck-desk3.sc.intel.com ([172.25.222.70]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2025 17:34:18 -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 v4 20/31] x86/resctrl: Check for adequate MMIO space Date: Mon, 28 Apr 2025 17:33:46 -0700 Message-ID: <20250429003359.375508-21-tony.luck@intel.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250429003359.375508-1-tony.luck@intel.com> References: <20250429003359.375508-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 MMIO space for each telemetry aggregator is arranged as a array of count registers for each event for RMID 0, followed by RMID 1, and so on. After all event counters there are three status registers. All registers are 8 bytes each. The total size of MMIO space as described by the XML files is thus: (NUM_RMIDS * NUM_COUNTERS + 3) * 8 Add an "mmio_size" field to the event_group structure and a sanity check that the size reported in the telemetry_region structure obtained from intel_pmt_get_regions_by_feature() is as large as expected. Signed-off-by: Tony Luck --- arch/x86/kernel/cpu/resctrl/intel_aet.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/cpu/resctrl/intel_aet.c b/arch/x86/kernel/cpu/= resctrl/intel_aet.c index 7e4f6a6672d4..37dd493df250 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 { * retrieved from intel_pmt_get_regions_by_feature(). * @pfg: The pmt_feature_group for this event group * @guid: Unique number per XML description file + * @mmio_size: Number of bytes of mmio registers for this group * @pkginfo: Per-package MMIO addresses * @num_events: Number of events in this group * @evts: Array of event descriptors @@ -56,6 +57,7 @@ struct pmt_event { struct event_group { struct pmt_feature_group *pfg; int guid; + int mmio_size; struct mmio_info **pkginfo; int num_events; struct pmt_event evts[] __counted_by(num_events); @@ -64,6 +66,7 @@ struct event_group { /* Link: https://github.com/intel/Intel-PMT xml/CWF/OOBMSM/RMID-ENERGY *.x= ml */ static struct event_group energy_0x26696143 =3D { .guid =3D 0x26696143, + .mmio_size =3D (576 * 2 + 3) * 8, .num_events =3D 2, .evts =3D { EVT(PMT_EVENT_ENERGY, 0), @@ -74,6 +77,7 @@ static struct event_group energy_0x26696143 =3D { /* Link: https://github.com/intel/Intel-PMT xml/CWF/OOBMSM/RMID-PERF *.xml= */ static struct event_group perf_0x26557651 =3D { .guid =3D 0x26557651, + .mmio_size =3D (576 * 7 + 3) * 8, .num_events =3D 7, .evts =3D { EVT(PMT_EVENT_STALLS_LLC_HIT, 0), @@ -134,6 +138,10 @@ static bool configure_events(struct event_group *e, st= ruct pmt_feature_group *p) pr_warn_once("Bad package %d\n", tr->plat_info.package_id); continue; } + if (tr->size < e->mmio_size) { + pr_warn_once("MMIO space too small for guid 0x%x\n", e->guid); + continue; + } pkgcounts[tr->plat_info.package_id]++; } =20 @@ -151,7 +159,8 @@ static bool configure_events(struct event_group *e, str= uct pmt_feature_group *p) /* Save MMIO address(es) for each aggregator in per-package structures */ for (int i =3D 0; i < p->count; i++) { tr =3D &p->regions[i]; - if (tr->guid !=3D e->guid || tr->plat_info.package_id >=3D num_pkgs) + if (tr->guid !=3D e->guid || tr->plat_info.package_id >=3D num_pkgs || + tr->size < e->mmio_size) continue; mmi =3D pkginfo[tr->plat_info.package_id]; mmi->addrs[--pkgcounts[tr->plat_info.package_id]] =3D tr->addr; --=20 2.48.1 From nobody Fri Dec 19 19:02:40 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) (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 46A5920D4E7 for ; Tue, 29 Apr 2025 00:34:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745886868; cv=none; b=q2xBRAhKiyBbv5/Ek1ssEbkG1CKBTq4ZLBy1Ujx5JzOgM4EgWFlr4B4tIEajhOsIpFphG2sljTZkbuCzh3Fv4cbHNyzxvwk1Cs1Vwp0LXloUxg3gNi8W3ebaX8qL7Bpt+nRShiLcSbtNFaBOp4Yc0dZ5vOiVqXMvVjn0IUtdZt8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745886868; c=relaxed/simple; bh=8U+X+AdbxvgBo9oLxgDF886iRXiEr6TfU7ORbMoBQ1Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lqOV7/pq5noyRLF4WWyeARF1Qf7nWVYuqbPz0ATDkLM8P92dkKoZTUa8sf6FD7wQXIGc48sPxP9Mdb3xbHf0lLwP5agtenilaZibFQkNEoJwHaFYUE0MYNvWW3UffuaOdOxIDRVF5aVkp7nlSgXI2dy0O8Yz8Q9Jz96qivVArCI= 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=PRw1+nZ6; arc=none smtp.client-ip=192.198.163.9 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="PRw1+nZ6" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1745886866; x=1777422866; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8U+X+AdbxvgBo9oLxgDF886iRXiEr6TfU7ORbMoBQ1Y=; b=PRw1+nZ6iBhhDiHaW2Qnx8uqZb/w6djBaMX3WR3xkIpAH4kur5wPCGjs p1WZZr9IZshZv8Gu5c/FEVD89Nzu3eapRN7AqgvJMZv/b2pCiOm2+VteS zcUzCgN8Sk49xKMGsh/8q0Ov4VXdJndHkW7te/D5fiftnDYNmBZ9WHo4Y bH5tfrBMNCK0Y303dw9d2R5qOuOSG+aOite5BGIlu+5y0w56scXSAcbLO 9nqaAAogCr7CwM/EagDMSQeRReC33mhMo0n5uxGCgjKlrPjQDGx81fh0/ NCqRfPZu54qyb/ZZV65J3SNN0IFuKthGYtcwkeG7Rr8dXfhkVsFNGzZUA g==; X-CSE-ConnectionGUID: HvSa0QlSSIqZD0tUSSf3Vg== X-CSE-MsgGUID: MDWzU8XPQGenY1facbPDiw== X-IronPort-AV: E=McAfee;i="6700,10204,11417"; a="58148235" X-IronPort-AV: E=Sophos;i="6.15,247,1739865600"; d="scan'208";a="58148235" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2025 17:34:19 -0700 X-CSE-ConnectionGUID: NmOB4kMNSv2CB59XVCKEkQ== X-CSE-MsgGUID: cTtCIv9xTvWV7XZ7G9inEw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,247,1739865600"; d="scan'208";a="133394040" Received: from agluck-desk3.sc.intel.com ([172.25.222.70]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2025 17:34:19 -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 v4 21/31] x86/resctrl: Add fourth part of telemetry event enumeration Date: Mon, 28 Apr 2025 17:33:47 -0700 Message-ID: <20250429003359.375508-22-tony.luck@intel.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250429003359.375508-1-tony.luck@intel.com> References: <20250429003359.375508-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" At run time when a user reads an event file the file system code provides the enum resctrl_event_id for the event. Create a lookup table indexed by event id to provide the telem_entry structure and the event index into MMIO space. Enable the events marked as readable from any CPU. Signed-off-by: Tony Luck --- arch/x86/kernel/cpu/resctrl/intel_aet.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/cpu/resctrl/intel_aet.c b/arch/x86/kernel/cpu/= resctrl/intel_aet.c index 37dd493df250..e1cb6bd4788d 100644 --- a/arch/x86/kernel/cpu/resctrl/intel_aet.c +++ b/arch/x86/kernel/cpu/resctrl/intel_aet.c @@ -97,6 +97,16 @@ static struct event_group *known_event_groups[] =3D { =20 #define NUM_KNOWN_GROUPS ARRAY_SIZE(known_event_groups) =20 +/** + * struct evtinfo - lookup table from resctrl_event_id to useful informati= on + * @event_group: Pointer to the telem_entry structure for this event + * @idx: Counter index within each per-RMID block of counters + */ +static struct evtinfo { + struct event_group *event_group; + int idx; +} evtinfo[QOS_NUM_EVENTS]; + static void free_mmio_info(struct mmio_info **mmi) { int num_pkgs =3D topology_max_packages(); @@ -167,7 +177,16 @@ static bool configure_events(struct event_group *e, st= ruct pmt_feature_group *p) } e->pkginfo =3D no_free_ptr(pkginfo); =20 - return false; + for (int i =3D 0; i < e->num_events; i++) { + enum resctrl_event_id evt; + + evt =3D e->evts[i].evtid; + evtinfo[evt].event_group =3D e; + evtinfo[evt].idx =3D e->evts[i].evt_idx; + resctrl_enable_mon_event(evt, true); + } + + return true; } =20 DEFINE_FREE(intel_pmt_put_feature_group, struct pmt_feature_group *, \ --=20 2.48.1 From nobody Fri Dec 19 19:02:40 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) (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 1D6512116FA for ; Tue, 29 Apr 2025 00:34:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745886869; cv=none; b=LCCwXwnlnyi8W7Bxf4RT8ObMxZD7AswlAIRzVEle93BhyPLC+D7PN2iY6CTcGaWGZGOPzzbF8B24PU1HBBhHo5tj1z408Z2B1I52Z6Lc74nQ/lAZWOFdhLqSd7CD8FRlWgCtwltWCbpPZkDIIK1FK29CF1B6gGqakQCBnRApYMM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745886869; c=relaxed/simple; bh=g3YsS9Ba5gWLVPZVGSbNAWbF90rXvwt3rICU9VNcUdM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DCbzhuOV6Bo9SWwLFb1fvR4V1TACpGs39ZF5nGCGRaQDwARCc8F6g7PHPvzEtT8JmyTErjjS45LmKLa/0CfmeQgie7wSlVpwKNxm6rqALYrZzIO0lgk5a8VCF3e7s4HgU4uW3XPAuBw8hhtjF5Mr58PNZLo8PQyVZlk0NzVOWVU= 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=dJWFqNjz; arc=none smtp.client-ip=192.198.163.9 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="dJWFqNjz" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1745886867; x=1777422867; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=g3YsS9Ba5gWLVPZVGSbNAWbF90rXvwt3rICU9VNcUdM=; b=dJWFqNjzqj2fxeLizNdJinAtX5Eu0bs++Y2mpyQxb5af4sI5bRxnblx/ nRN0WMwvt8n3HSfvqIZ9CEbth+8nj/4BNXTRIOfiBl9xMtPkbHhBsmQYl GFKQtkm5nHzp3T3hz3u6bOFzee4LWXjTLt33wtIYCa6ap+yVxoVm4mCyl 33qVb3oFLk+T14h8Oc5yMJhSWliLpoLWFjY0NlcANl+8TiIx+Kj5ClYIc 2XRxJNbZyhK7JvCJeGbTCj6ZWce3FfTcvipgmSIatvZstH/GVudE6O3Jy WfD4BSWbUWUKs7eAeZdbVqKdB+/lvoviVI/R3o7F7jBgXw5TETksQ08FC A==; X-CSE-ConnectionGUID: iLeRCL5hSZuVPIMz8axc4g== X-CSE-MsgGUID: 2aI7Ga3HQfe62yKBxtN2+w== X-IronPort-AV: E=McAfee;i="6700,10204,11417"; a="58148243" X-IronPort-AV: E=Sophos;i="6.15,247,1739865600"; d="scan'208";a="58148243" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2025 17:34:20 -0700 X-CSE-ConnectionGUID: +6bIUJcYQWeJfw0FKNCM8A== X-CSE-MsgGUID: L7bfGbOBSSS8PG7+BavF/A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,247,1739865600"; d="scan'208";a="133394047" Received: from agluck-desk3.sc.intel.com ([172.25.222.70]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2025 17:34:19 -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 v4 22/31] x86/resctrl: Read core telemetry events Date: Mon, 28 Apr 2025 17:33:48 -0700 Message-ID: <20250429003359.375508-23-tony.luck@intel.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250429003359.375508-1-tony.luck@intel.com> References: <20250429003359.375508-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() function 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 devices tracking each package, so scan all of them and add up all counters. Signed-off-by: Tony Luck --- arch/x86/kernel/cpu/resctrl/internal.h | 5 ++++ arch/x86/kernel/cpu/resctrl/intel_aet.c | 34 +++++++++++++++++++++++++ arch/x86/kernel/cpu/resctrl/monitor.c | 3 +++ 3 files changed, 42 insertions(+) diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/r= esctrl/internal.h index 571db665eca6..dd5fe8a98304 100644 --- a/arch/x86/kernel/cpu/resctrl/internal.h +++ b/arch/x86/kernel/cpu/resctrl/internal.h @@ -170,9 +170,14 @@ void rdt_domain_reconfigure_cdp(struct rdt_resource *r= ); #ifdef CONFIG_INTEL_AET_RESCTRL bool intel_aet_get_events(void); void __exit intel_aet_exit(void); +int intel_aet_read_event(int domid, int rmid, enum resctrl_event_id evtid,= u64 *val); #else static inline bool intel_aet_get_events(void) { return false; } static inline void intel_aet_exit(void) { }; +static inline int intel_aet_read_event(int domid, int rmid, enum resctrl_e= vent_id evtid, u64 *val) +{ + return -EINVAL; +} #endif =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 e1cb6bd4788d..0bbf991da981 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 =20 /* Temporary - delete from final version */ @@ -246,3 +247,36 @@ void __exit intel_aet_exit(void) free_mmio_info((*peg)->pkginfo); } } + +#define VALID_BIT BIT_ULL(63) +#define DATA_BITS GENMASK_ULL(62, 0) + +/* + * Read counter for an event on a domain (summing all aggregators + * on the domain). + */ +int intel_aet_read_event(int domid, int rmid, enum resctrl_event_id evtid,= u64 *val) +{ + struct evtinfo *info =3D &evtinfo[evtid]; + struct mmio_info *mmi; + u64 evtcount; + int idx; + + idx =3D rmid * info->event_group->num_events; + idx +=3D info->idx; + mmi =3D info->event_group->pkginfo[domid]; + + if (idx * sizeof(u64) > info->event_group->mmio_size) { + pr_warn_once("MMIO index %d out of range\n", idx); + return -EINVAL; + } + + for (int i =3D 0; i < mmi->count; i++) { + evtcount =3D readq(mmi->addrs[i] + idx * sizeof(u64)); + if (!(evtcount & VALID_BIT)) + 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 8d8ec86929fa..04214585824b 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -237,6 +237,9 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, stru= ct rdt_l3_mon_domain *d, =20 resctrl_arch_rmid_read_context_check(); =20 + if (r->rid =3D=3D RDT_RESOURCE_PERF_PKG) + return intel_aet_read_event(d->hdr.id, rmid, eventid, val); + prmid =3D logical_rmid_to_physical_rmid(cpu, rmid); ret =3D __rmid_read_phys(prmid, eventid, &msr_val); if (ret) --=20 2.48.1 From nobody Fri Dec 19 19:02:40 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) (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 D6CAD1CAA90 for ; Tue, 29 Apr 2025 00:34:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745886869; cv=none; b=u97uOlnnxwXmuiMGZVTvJdobynfmCguyOxP/ybyCaeeF+XsU1slKMFK/nOJqc9RnSLyEG4HaQDuIKzfZpr5OPU5+3yHlb/w1Yq8EN2Ih+GQzZCRBr5gOmw3zFXT6p2InJVLDM0ULjzyUB4Rsn74TUBY3u48HJh2w1XPL3l2T2zE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745886869; c=relaxed/simple; bh=NDR7vXDn/AXv08PVU0Ra2XFtF46qLg6h6Xut6cwotbo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gA9g9M5VmD7wcZWT4q6kGaeD5nbAmI4g32rkmcOG+/mp8Cgl0B9xaXy+f9Y9U74h7Enyx28WDPYNbeY/zwCM2XQ+9cdEQx2LW+y2vRSC/f+C8epUoDhJ+AhwXVKmRunjCxJbbV7WY+QjOr+iZus6X/rGorgG7gvmSj+2X1dC0jQ= 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=d2XFTE22; arc=none smtp.client-ip=192.198.163.9 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="d2XFTE22" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1745886868; x=1777422868; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=NDR7vXDn/AXv08PVU0Ra2XFtF46qLg6h6Xut6cwotbo=; b=d2XFTE22HG7HYH9P18HtRfYban5YD+gLsArJGcJuYaiCXT8gcg2Xwp9u twYFXfrKKPC5yFh9oAWN7qsfLzf5YYmsHz8UtXhqHms3Lh6Zx46epRzg8 /S5HYL8lTVWZrdut9D5r2qSK8dcNDG2eChwYFH4rXbc/eKmUZ30JdApx+ ZzBeZGMAPdOAdpBBRMozl4wP7Z1EM6GSQvdjYsXeyEDu33geTtTNTzFmj itZoSsQa/kWQuhZPewW/WbSIWpedc4DIKN0WIe7kl+BUWraKNU7mgv3z5 6s4tJKtEHts6lJM0a4sxQnKQT18fRUxkSsgRdqu03F6MPjoGgXEkPxzZx A==; X-CSE-ConnectionGUID: 1En6XosYTYGHmwXLgDxKYA== X-CSE-MsgGUID: x+YdhMycTE6pG2Q5PQWu2Q== X-IronPort-AV: E=McAfee;i="6700,10204,11417"; a="58148257" X-IronPort-AV: E=Sophos;i="6.15,247,1739865600"; d="scan'208";a="58148257" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2025 17:34:21 -0700 X-CSE-ConnectionGUID: NBwkPYgnQW2XCE7GgSXXNw== X-CSE-MsgGUID: iglkXtJqTNO3ASzBUdoWlQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,247,1739865600"; d="scan'208";a="133394055" Received: from agluck-desk3.sc.intel.com ([172.25.222.70]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2025 17:34:20 -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 v4 23/31] x86,fs/resctrl: Handle domain creation/deletion for RDT_RESOURCE_PERF_PKG Date: Mon, 28 Apr 2025 17:33:49 -0700 Message-ID: <20250429003359.375508-24-tony.luck@intel.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250429003359.375508-1-tony.luck@intel.com> References: <20250429003359.375508-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 domsins in the PERF_PKG resource. Signed-off-by: Tony Luck --- arch/x86/kernel/cpu/resctrl/core.c | 41 ++++++++++++++++++++++++++++++ fs/resctrl/rdtgroup.c | 4 +++ 2 files changed, 45 insertions(+) diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resct= rl/core.c index 0103f577e4ca..97fb2001c8d8 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -543,6 +543,38 @@ static void setup_l3_mon_domain(int cpu, int id, struc= t rdt_resource *r, struct } } =20 +/** + * struct rdt_perf_pkg_mon_domain - CPUs sharing an Intel-PMT-scoped resct= rl monitor resource + * @hdr: common header for different domain types + */ +struct rdt_perf_pkg_mon_domain { + struct rdt_domain_hdr hdr; +}; + +static void setup_intel_aet_mon_domain(int cpu, int id, struct rdt_resourc= e *r, + struct list_head *add_pos) +{ + struct rdt_perf_pkg_mon_domain *d; + int err; + + d =3D kzalloc_node(sizeof(*d), GFP_KERNEL, cpu_to_node(cpu)); + if (!d) + return; + + d->hdr.id =3D id; + d->hdr.type =3D RESCTRL_MON_DOMAIN; + d->hdr.rid =3D r->rid; + cpumask_set_cpu(cpu, &d->hdr.cpu_mask); + list_add_tail_rcu(&d->hdr.list, add_pos); + + err =3D resctrl_online_mon_domain(r, &d->hdr); + if (err) { + list_del_rcu(&d->hdr.list); + synchronize_rcu(); + kfree(d); + } +} + static void domain_add_cpu_mon(int cpu, struct rdt_resource *r) { int id =3D get_domain_id_from_scope(cpu, r->mon_scope); @@ -567,6 +599,9 @@ static void domain_add_cpu_mon(int cpu, struct rdt_reso= urce *r) case RDT_RESOURCE_L3: setup_l3_mon_domain(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); } @@ -664,6 +699,12 @@ static void domain_remove_cpu_mon(int cpu, struct rdt_= resource *r) synchronize_rcu(); free_l3_mon_domain(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; } } =20 diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index da71057f3ff4..5e0d1777f162 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -4167,6 +4167,8 @@ int resctrl_online_mon_domain(struct rdt_resource *r,= struct rdt_domain_hdr *hdr =20 mutex_lock(&rdtgroup_mutex); =20 + if (r->rid =3D=3D RDT_RESOURCE_PERF_PKG) + goto do_mkdir; if (r->rid !=3D RDT_RESOURCE_L3) goto out_unlock; =20 @@ -4187,6 +4189,8 @@ int resctrl_online_mon_domain(struct rdt_resource *r,= struct rdt_domain_hdr *hdr if (resctrl_is_mon_event_enabled(QOS_L3_OCCUP_EVENT_ID)) INIT_DELAYED_WORK(&d->cqm_limbo, cqm_handle_limbo); =20 +do_mkdir: + err =3D 0; /* * If the filesystem is not mounted then only the default resource group * exists. Creation of its directories is deferred until mount time --=20 2.48.1 From nobody Fri Dec 19 19:02:40 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) (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 7C03C214A90 for ; Tue, 29 Apr 2025 00:34:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745886870; cv=none; b=n2yKxipI7wxwZwNRPf1uZA0x4/mwVhYGz7ihAE9G0mvpbZVSBJ7uzwbL3vW69GraxWWQbyW9FYcgdq3M97DmkiLgECT7kttNA2ZFi+08GidhwcHq8HAGs/Qm3PfgW3oK/dJenJ13GFCEyNCOQibBa6KdPvf7WjwRVCa60k3rfyM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745886870; c=relaxed/simple; bh=rmmM2/1ELIlDH8mRrn9+En13+yPbD0Vwms0V/5K0CoM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WRTsdw8hVFKGPz5X6ZInePpZGxjVNzcYxVKcuY+omDZBqcy4ka/mztE1WZuqwQS/z/VcQDQmuRXwaNWiVuUFe5U1tHHV3Z0CishRKUduRB8dLyZnd/sU7gNvo0wmJ4IR3HZMEh6uaSTdnBP4bcO7geE7uiSbcYRNQODvl8SaACg= 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=fls6gmok; arc=none smtp.client-ip=192.198.163.9 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="fls6gmok" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1745886868; x=1777422868; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=rmmM2/1ELIlDH8mRrn9+En13+yPbD0Vwms0V/5K0CoM=; b=fls6gmokv4WDSbLI8fk59E+yOpAXTOtB4eSmQXa1M1d+CsNU7Qw2ULUN OvrjTEed3zfiCYUrmyGSZxNE9+bYJmCLWdIAJ/OLzoy8UzcRnuiSju3Wy Q9WtLl3UKYq8BfCzGIQG5OPPktfK9m88VAswdGdqFAn4xeKlAD2848ldz yuNIG4RI8m3exvieJEnzckjOFez7aPa7kuJK3L8yibFCRG47s9Rcu4VIH WnoLuiK3zAvhsXyLeYsOAgzVcAYo9XASW0gCh8Pm9GwitTRwTO1Ji/+0K cuowNe086UBMRN507dtv5GFG1DjHqTduBxuM69TvQugHMYdjrL6yff5fX w==; X-CSE-ConnectionGUID: z+uUPW1fTLaFnTJHqpRMcg== X-CSE-MsgGUID: Oj/FCC9OT32dt2cKfWFKpg== X-IronPort-AV: E=McAfee;i="6700,10204,11417"; a="58148266" X-IronPort-AV: E=Sophos;i="6.15,247,1739865600"; d="scan'208";a="58148266" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2025 17:34:21 -0700 X-CSE-ConnectionGUID: KmXTL6uSSHWQ1l1tmdxnaA== X-CSE-MsgGUID: 45MHkHiHTT+uBvpYlgDLoQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,247,1739865600"; d="scan'208";a="133394060" Received: from agluck-desk3.sc.intel.com ([172.25.222.70]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2025 17:34:21 -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 v4 24/31] fs/resctrl: Add type define for PERF_PKG files Date: Mon, 28 Apr 2025 17:33:50 -0700 Message-ID: <20250429003359.375508-25-tony.luck@intel.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250429003359.375508-1-tony.luck@intel.com> References: <20250429003359.375508-1-tony.luck@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Creation of the default info file for monitor resources requires an RFTYPE_RES_ define and for fflags_from_resource() to map from the RDT_RESOURCE_PERF_PKG resource to the RFTYPE_RES_PERF_PKG value. Add the define and case in fflags_from_resource(). Signed-off-by: Tony Luck --- fs/resctrl/internal.h | 2 ++ fs/resctrl/rdtgroup.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/fs/resctrl/internal.h b/fs/resctrl/internal.h index aaa74a17257d..623a9fadc18a 100644 --- a/fs/resctrl/internal.h +++ b/fs/resctrl/internal.h @@ -250,6 +250,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/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index 5e0d1777f162..544fa721e067 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -2191,6 +2191,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.48.1 From nobody Fri Dec 19 19:02:40 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) (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 6531E215186 for ; Tue, 29 Apr 2025 00:34:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745886871; cv=none; b=DuxFZmm9For0Hm9lFU4vE29QT0B8RpgKKcd2TGfP6nWEiKyMngImFPSdi0d91jGyoNTkDCBbyO9qqqgzOjGNgR55VsWv5fwqPJDRZJ6seWoOcEsD3zlTXeyKg82Wk7cuYeFkeesRwWZlE28nw/8EquShVSleqCUSOYtnbqPVKuk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745886871; c=relaxed/simple; bh=ndLXdrx5e+eeWbCrX0njshMSXqZWltIeXhsH3kzx+dw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LsX+f7idPf3H+6/CPC2Da+qnCDtJQ6GMqfdLMIBc/TO+k+KzP5tNVbHhBIXfCe6sQjcG76u+DQ8XQqG4m6U5zuRvawcnG1WkLeRSqHNhcu7h9ozUo4CXRosfVL7Cp9tWhSKb0R7OIdt5HJs7DJSLkBFTqwg5kY4xgzIlHx/Lzq8= 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=UcRINqsS; arc=none smtp.client-ip=192.198.163.9 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="UcRINqsS" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1745886869; x=1777422869; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ndLXdrx5e+eeWbCrX0njshMSXqZWltIeXhsH3kzx+dw=; b=UcRINqsSLkN4AqAu5bc4KdoiPp4QHupJ8236+EA1fjU036sC+ft5pgU+ 9J4W7CAVInBHO6BoPhVXay1qEhj4CsrIq32yv6JsDWoAaS+pfjYym5Pka HXUlllIvx0MCaLtvvmhVlx0l+5FKS+mkcXvBaiJxUnMxMPHwuKSp3oghU t1dZCwvzfEDLuh8fd+avKPnomP+OFOmaa3hh9T6DbF7X+zWOmRCDMUuI+ N+vqz4PlVfLOMm9c7kVCW/mpCCOAUUjbKnQJ/vz47AskBOWL1ZDm6gcPQ QqMW0wyn097pYQNxETfosjTOR3xWQGVF2WaPHd6iTwCTRuc5EdJIeloAn w==; X-CSE-ConnectionGUID: gR3TszF3S8atVsQxBS4S2g== X-CSE-MsgGUID: ymov1qnuRoe+hg2eLFOsJg== X-IronPort-AV: E=McAfee;i="6700,10204,11417"; a="58148279" X-IronPort-AV: E=Sophos;i="6.15,247,1739865600"; d="scan'208";a="58148279" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2025 17:34:22 -0700 X-CSE-ConnectionGUID: EU03d3FhR12wZw305kOzpg== X-CSE-MsgGUID: 5sYYQ2ImR0yjxmZHHbf7mA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,247,1739865600"; d="scan'208";a="133394067" Received: from agluck-desk3.sc.intel.com ([172.25.222.70]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2025 17:34:21 -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 v4 25/31] x86/resctrl: Final steps to enable RDT_RESOURCE_PERF_PKG Date: Mon, 28 Apr 2025 17:33:51 -0700 Message-ID: <20250429003359.375508-26-tony.luck@intel.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250429003359.375508-1-tony.luck@intel.com> References: <20250429003359.375508-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 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resct= rl/core.c index 97fb2001c8d8..9fa4cc66faf4 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -761,13 +761,27 @@ static int resctrl_arch_offline_cpu(unsigned int cpu) =20 void resctrl_arch_pre_mount(void) { + struct rdt_resource *r =3D &rdt_resources_all[RDT_RESOURCE_PERF_PKG].r_re= sctrl; static atomic_t only_once; + int cpu; =20 if (atomic_cmpxchg(&only_once, 0, 1)) return; =20 if (!intel_aet_get_events()) return; + + /* + * Late discovery of telemetry events means the domains for the + * resource were not built. Do that now. + */ + cpus_read_lock(); + mutex_lock(&domain_list_lock); + r->mon_capable =3D true; + for_each_online_cpu(cpu) + domain_add_cpu_mon(cpu, r); + mutex_unlock(&domain_list_lock); + cpus_read_unlock(); } =20 enum { --=20 2.48.1 From nobody Fri Dec 19 19:02:40 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) (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 08EE5215791 for ; Tue, 29 Apr 2025 00:34:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745886872; cv=none; b=nxYOQoqBVXT32JPMqZKyDrLUi4d0Rb+N8xquJopFhTrtEi+tQz05pCJs6hQis+2EKaDE44OHmP3vjD0wZ6/2xhEMAq4Lv4enTpzUPYWqIysFWLitNhyXh+vokmMB6kxfMBqte8ev4hbENMVvwQsQfW9C/jcXIGzuDp54VdltExQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745886872; c=relaxed/simple; bh=kOMp9z1scfUT1uqprTrt2iskyhryhvGGEZykm2shN0g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=o+khZZkUTmSEFI/I9LYjAyrohXBw1q9bqzq7RXWzfHqw0uvgcWl++W4zliNbqHNQKzzGq1QqIUHjrz4nUYReOWvXRP1wcA7Y28FLcI3lR8f9QYslvix/9Vd9FFmc5X+SsA4UGDurRbwLPbA4yFz/16w7x4YRXw9G/SvJNUXLgFU= 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=LchUxxS2; arc=none smtp.client-ip=192.198.163.9 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="LchUxxS2" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1745886870; x=1777422870; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=kOMp9z1scfUT1uqprTrt2iskyhryhvGGEZykm2shN0g=; b=LchUxxS2j9tRwaOp3/trpkVFuke+rQrRRoVCo6mFQt3z5gSS5D9dhZKz XXzvPorEbdpToCrEltnUVOhX8eOoHNwgqeA+ldfUaId5Bj2ZYEf6pdmdf xa7zbwWwNwbrGMURzcGrVNBjtkZPLCFWoJFMVvWMzs24c+5+figgYd+XV bIemcgH7RmtxzU3yDYVPSgE5TUvrz55WF2eWBGezpcQE9nRHEDR66X3si DprvSd5TmRN+mpvYBROTx1Poe9Q9U1xepS4F3UqcCoPCyRKkK6TPZPLvO xX/V78Wpu70nIeyImmGf8L2l6w8mTPOptj7K81vOEM+FojmtPF28KWBwz w==; X-CSE-ConnectionGUID: CcJqwPT0R4Ky/0kF2BNpVQ== X-CSE-MsgGUID: pDDmBCoLTnqmRz6yg3o2yw== X-IronPort-AV: E=McAfee;i="6700,10204,11417"; a="58148289" X-IronPort-AV: E=Sophos;i="6.15,247,1739865600"; d="scan'208";a="58148289" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2025 17:34:23 -0700 X-CSE-ConnectionGUID: +SwzuqKUSzqHyiQw2izBYw== X-CSE-MsgGUID: W9zYiQgXQ4umUZVchGkaXw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,247,1739865600"; d="scan'208";a="133394073" Received: from agluck-desk3.sc.intel.com ([172.25.222.70]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2025 17:34:22 -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 v4 26/31] x86/resctrl: Add energy/perf choices to rdt boot option Date: Mon, 28 Apr 2025 17:33:52 -0700 Message-ID: <20250429003359.375508-27-tony.luck@intel.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250429003359.375508-1-tony.luck@intel.com> References: <20250429003359.375508-1-tony.luck@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Users may want to force either of the telemetry features on (in the case where they are disabled due to erratum) or off (in the case that a limited number of RMIDs for a telemetry feature reduces the number of monitor groups that can be created.) Unlike other options that are tied to X86_FEATURE_* flags, these must be queried by name. Add a function to do that. Add checks for users who forced either feature off. Signed-off-by: Tony Luck --- .../admin-guide/kernel-parameters.txt | 2 +- arch/x86/kernel/cpu/resctrl/internal.h | 2 ++ arch/x86/kernel/cpu/resctrl/core.c | 19 +++++++++++++++++++ arch/x86/kernel/cpu/resctrl/intel_aet.c | 6 ++++++ 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentatio= n/admin-guide/kernel-parameters.txt index d9fd26b95b34..4811bc812f0f 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -5988,7 +5988,7 @@ rdt=3D [HW,X86,RDT] Turn on/off individual RDT features. List is: cmt, mbmtotal, mbmlocal, l3cat, l3cdp, l2cat, l2cdp, - mba, smba, bmec. + mba, smba, bmec, energy, perf. E.g. to turn on cmt and turn off mba use: rdt=3Dcmt,!mba =20 diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/r= esctrl/internal.h index dd5fe8a98304..92cbba9d82a8 100644 --- a/arch/x86/kernel/cpu/resctrl/internal.h +++ b/arch/x86/kernel/cpu/resctrl/internal.h @@ -167,6 +167,8 @@ void __init intel_rdt_mbm_apply_quirk(void); =20 void rdt_domain_reconfigure_cdp(struct rdt_resource *r); =20 +bool rdt_check_option(char *name, bool is_on, bool is_off); + #ifdef CONFIG_INTEL_AET_RESCTRL bool intel_aet_get_events(void); void __exit intel_aet_exit(void); diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resct= rl/core.c index 9fa4cc66faf4..dc312e24ab87 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -795,6 +795,8 @@ enum { RDT_FLAG_MBA, RDT_FLAG_SMBA, RDT_FLAG_BMEC, + RDT_FLAG_ENERGY, + RDT_FLAG_PERF, }; =20 #define RDT_OPT(idx, n, f) \ @@ -820,6 +822,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 @@ -869,6 +873,21 @@ bool rdt_cpu_has(int flag) return ret; } =20 +/* Check if a named option has been forced on, or forced off */ +bool rdt_check_option(char *name, bool is_on, bool is_off) +{ + struct rdt_options *o; + + WARN_ON(!(is_on ^ is_off)); + + for (o =3D rdt_options; o < &rdt_options[NUM_RDT_OPTIONS]; o++) { + if (!strcmp(name, o->name)) + return (is_on && o->force_on) || (is_off && o->force_off); + } + + return false; +} + bool resctrl_arch_is_evt_configurable(enum resctrl_event_id evt) { if (!rdt_cpu_has(X86_FEATURE_BMEC)) diff --git a/arch/x86/kernel/cpu/resctrl/intel_aet.c b/arch/x86/kernel/cpu/= resctrl/intel_aet.c index 0bbf991da981..aacaedcc7b74 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 { * gleaned from the XML files. Others are set from da= ta * retrieved from intel_pmt_get_regions_by_feature(). * @pfg: The pmt_feature_group for this event group + * @name: Name for this group * @guid: Unique number per XML description file * @mmio_size: Number of bytes of mmio registers for this group * @pkginfo: Per-package MMIO addresses @@ -57,6 +58,7 @@ struct pmt_event { */ struct event_group { struct pmt_feature_group *pfg; + char *name; int guid; int mmio_size; struct mmio_info **pkginfo; @@ -66,6 +68,7 @@ struct event_group { =20 /* Link: https://github.com/intel/Intel-PMT xml/CWF/OOBMSM/RMID-ENERGY *.x= ml */ static struct event_group energy_0x26696143 =3D { + .name =3D "energy", .guid =3D 0x26696143, .mmio_size =3D (576 * 2 + 3) * 8, .num_events =3D 2, @@ -77,6 +80,7 @@ static struct event_group energy_0x26696143 =3D { =20 /* Link: https://github.com/intel/Intel-PMT xml/CWF/OOBMSM/RMID-PERF *.xml= */ static struct event_group perf_0x26557651 =3D { + .name =3D "perf", .guid =3D 0x26557651, .mmio_size =3D (576 * 7 + 3) * 8, .num_events =3D 7, @@ -208,6 +212,8 @@ static bool get_pmt_feature(enum pmt_feature_id feature) for (peg =3D &known_event_groups[0]; peg < &known_event_groups[NUM_KNOWN_= GROUPS]; peg++) { for (int i =3D 0; i < p->count; i++) { if ((*peg)->guid =3D=3D p->regions[i].guid) { + if (rdt_check_option((*peg)->name, false, true)) + return false; ret =3D configure_events((*peg), p); if (ret) { (*peg)->pfg =3D no_free_ptr(p); --=20 2.48.1 From nobody Fri Dec 19 19:02:40 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) (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 825FB21638E for ; Tue, 29 Apr 2025 00:34:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745886872; cv=none; b=D9V2tvlicbBycQ0trbaZougJXsLhhd/ny+icDPI+qJyagsS5LhM3pbZkowrm2EeesP26b7ECIoxos6LHcm9KbfpSSeWfLAeAjzhjLfyayK/1neyfn99JC7Dwrzrkv2Ni6jX0lnEwNwVpUWL1y4DIfwyXzfdgXHZpiEMGDJpj3y0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745886872; c=relaxed/simple; bh=CbqfS32/zpFwALbJJC3W65D8XOQshA6SfI3V0NpHq2I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lc9zg9LtX4849BZmK2Btd3P8fMJUOvCvzYhTb4dIvUFuoEfZx+q0brB/vTWm1dXaRJgEufudFmnPIdyn4uEfDPkPodFMZhkTRRn2DYzRZYe08KE0FpLqIwJY7lUOqoOdiCO+atss4kdupR859yhib2n0O+KzzvYB/jfekK1AV1A= 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=NVu0B5il; arc=none smtp.client-ip=192.198.163.9 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="NVu0B5il" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1745886870; x=1777422870; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=CbqfS32/zpFwALbJJC3W65D8XOQshA6SfI3V0NpHq2I=; b=NVu0B5il5uAEkstU34LUmaIz1aznX29iFEM2aYDr2XZ54QZmd3SFnt7J GvUt8IihjjZOTHFXT3g8OVUYAgfmtOokyc8mfqTeZJeo2Eozcd/yFO0B+ GRt8FDPNzobLpqmTSgwYNU2JjFLrVE1F4HmbYI8h++SzSyx7Wc9einnvE 5ibF//DlrQGsvxAgoZIdqLGz1az+UM9LQDgcs1DJ0syvIU834udY0+k0d jyey1I3hIfYOc4h7t2nIn0v6zpb+a9gyFiH/6VlM0bcHkyJhUVzIGa2PY VIImBSo055IM6Hx/QRT3ecZ9Nj4Wbu1V2uwDH88+JjmE+CvERbOOZR3t3 w==; X-CSE-ConnectionGUID: iyFG6z6pQnSCtjffedKMhA== X-CSE-MsgGUID: m5C1J1NDSuOwefj1+dADDw== X-IronPort-AV: E=McAfee;i="6700,10204,11417"; a="58148298" X-IronPort-AV: E=Sophos;i="6.15,247,1739865600"; d="scan'208";a="58148298" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2025 17:34:23 -0700 X-CSE-ConnectionGUID: fxbYq1s9TZ6+Jii4BzZT+A== X-CSE-MsgGUID: XXnqL8eWQ3+9g7ZicQ+i8A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,247,1739865600"; d="scan'208";a="133394077" Received: from agluck-desk3.sc.intel.com ([172.25.222.70]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2025 17:34:23 -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 v4 27/31] x86/resctrl: Handle number of RMIDs supported by telemetry resources Date: Mon, 28 Apr 2025 17:33:53 -0700 Message-ID: <20250429003359.375508-28-tony.luck@intel.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250429003359.375508-1-tony.luck@intel.com> References: <20250429003359.375508-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 placed into event_group::num_rmids. 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. Signed-off-by: Tony Luck --- arch/x86/kernel/cpu/resctrl/internal.h | 2 ++ arch/x86/kernel/cpu/resctrl/intel_aet.c | 25 +++++++++++++++++++++++++ arch/x86/kernel/cpu/resctrl/monitor.c | 2 ++ 3 files changed, 29 insertions(+) diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/r= esctrl/internal.h index 92cbba9d82a8..31499bcd2065 100644 --- a/arch/x86/kernel/cpu/resctrl/internal.h +++ b/arch/x86/kernel/cpu/resctrl/internal.h @@ -18,6 +18,8 @@ =20 #define RMID_VAL_UNAVAIL BIT_ULL(62) =20 +extern int rdt_num_system_rmids; + /* * With the above fields in use 62 bits remain in MSR_IA32_QM_CTR for * data to be returned. The counter width is discovered from the hardware diff --git a/arch/x86/kernel/cpu/resctrl/intel_aet.c b/arch/x86/kernel/cpu/= resctrl/intel_aet.c index aacaedcc7b74..eec5eb625f13 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 =20 /* Temporary - delete from final version */ @@ -51,6 +52,7 @@ struct pmt_event { * @pfg: The pmt_feature_group for this event group * @name: Name for this group * @guid: Unique number per XML description file + * @num_rmids: Number of RMIDS supported by this group * @mmio_size: Number of bytes of mmio registers for this group * @pkginfo: Per-package MMIO addresses * @num_events: Number of events in this group @@ -60,6 +62,7 @@ struct event_group { struct pmt_feature_group *pfg; char *name; int guid; + int num_rmids; int mmio_size; struct mmio_info **pkginfo; int num_events; @@ -70,6 +73,7 @@ struct event_group { static struct event_group energy_0x26696143 =3D { .name =3D "energy", .guid =3D 0x26696143, + .num_rmids =3D 576, .mmio_size =3D (576 * 2 + 3) * 8, .num_events =3D 2, .evts =3D { @@ -82,6 +86,7 @@ static struct event_group energy_0x26696143 =3D { static struct event_group perf_0x26557651 =3D { .name =3D "perf", .guid =3D 0x26557651, + .num_rmids =3D 576, .mmio_size =3D (576 * 7 + 3) * 8, .num_events =3D 7, .evts =3D { @@ -214,6 +219,15 @@ static bool get_pmt_feature(enum pmt_feature_id featur= e) if ((*peg)->guid =3D=3D p->regions[i].guid) { if (rdt_check_option((*peg)->name, false, true)) return false; + /* + * Ignore event group with insufficient RMIDs unless the + * user used the rdt=3D boot option to specifically ask + * for it to be enabled. + */ + if (p->regions[i].num_rmids < rdt_num_system_rmids && + !rdt_check_option((*peg)->name, true, false)) + return false; + (*peg)->num_rmids =3D p->regions[i].num_rmids; ret =3D configure_events((*peg), p); if (ret) { (*peg)->pfg =3D no_free_ptr(p); @@ -233,11 +247,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 04214585824b..7e3a68058b90 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -32,6 +32,7 @@ bool rdt_mon_capable; =20 #define CF(cf) ((unsigned long)(1048576 * (cf) + 0.5)) =20 +int rdt_num_system_rmids; static int snc_nodes_per_l3_cache =3D 1; =20 /* @@ -354,6 +355,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.48.1 From nobody Fri Dec 19 19:02:40 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) (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 5D68A217F26 for ; Tue, 29 Apr 2025 00:34:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745886873; cv=none; b=i00y4K1X67kmT1c9rLsCahd/A9WO8nnCXrlMvyYxPr9qSvW/LG1qoHvJZVR9YpgYIUAkuruM71ng9/yq3yyTTAMLMDAZjAS8Y+x82+HpMDrsG9j9Pq/gucgpxt/7tFPqn6YrBf9Vlkx7y/iPfIyGwYS0u1UgN80EEl3f9oHy44w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745886873; c=relaxed/simple; bh=Nc8PBuxU/Zr6RfO730ZadTnp1SP5khITKMe7nIqiyZQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bE6GjM9dYXY4razmXw/kX8Pz0aF+dMPQh5Z5c8nC7GA0/2zJplxaY3dV7xy4rh/XD22bQ4vzLkM9DM9DbBRh/aIVPoCePBBG7alh3WKLkDxq7VGtIkg9P062ME5ITNsUMMhZcdE1m3BvNSXkq7F2CBkFHudcqYe3fh7JwHqr+bQ= 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=juFr4hgJ; arc=none smtp.client-ip=192.198.163.9 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="juFr4hgJ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1745886871; x=1777422871; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Nc8PBuxU/Zr6RfO730ZadTnp1SP5khITKMe7nIqiyZQ=; b=juFr4hgJiT8Peh/W6N4+H2AXZUd1MzK83LUrwvj0ITFBL+ibZeAxgyjJ HqwAbRaXrMO2whFCJT4I0OZ/XEQcWQ0Qy9p3VoO6UuhiOkRNXVCKOOfbP UJ5hxCmfXBVHkzftNnNiX6MOPAgWUwLqFkFLEK9Tz9yFXPkmKhAEPo5PZ z3/FLHum0q4v4qvMfJbDyox8AJYI/G2MfTayq07faew7qSMLmUDqty5D2 Zk805cUUYHNJMweR6+NdZJOBZ/hrEeu+bxMwMFRjj/4FR1DX7YeCZcg24 UPGkNrqYeTsphBhnTr/ILiFpS969lJ9yQXf+ckqBN5YdKikgTRcwmrfqv w==; X-CSE-ConnectionGUID: uUt0KAWcR32hsUG7PS4QOw== X-CSE-MsgGUID: KihGjYWmSfeSyGbBM+8H9w== X-IronPort-AV: E=McAfee;i="6700,10204,11417"; a="58148308" X-IronPort-AV: E=Sophos;i="6.15,247,1739865600"; d="scan'208";a="58148308" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2025 17:34:24 -0700 X-CSE-ConnectionGUID: y4vW/neFQ+eI0ludOzZs0g== X-CSE-MsgGUID: qa12DkJOR5CnQIpQ93tjYg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,247,1739865600"; d="scan'208";a="133394082" Received: from agluck-desk3.sc.intel.com ([172.25.222.70]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2025 17:34:23 -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 v4 28/31] x86,fs/resctrl: Fix RMID allocation for multiple monitor resources Date: Mon, 28 Apr 2025 17:33:54 -0700 Message-ID: <20250429003359.375508-29-tony.luck@intel.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250429003359.375508-1-tony.luck@intel.com> References: <20250429003359.375508-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 | 48 +++++++++++++----------------- fs/resctrl/rdtgroup.c | 13 ++++---- 4 files changed, 35 insertions(+), 38 deletions(-) diff --git a/fs/resctrl/internal.h b/fs/resctrl/internal.h index 623a9fadc18a..fb5ae8ba0c17 100644 --- a/fs/resctrl/internal.h +++ b/fs/resctrl/internal.h @@ -364,7 +364,7 @@ int alloc_rmid(u32 closid); =20 void free_rmid(u32 closid, u32 rmid); =20 -void resctrl_mon_resource_exit(void); +void resctrl_dom_data_exit(void); =20 void mon_event_count(void *info); =20 @@ -405,7 +405,7 @@ enum resctrl_event_id resctrl_get_mon_event_by_name(cha= r *name); =20 char *resctrl_mon_event_name(enum resctrl_event_id evt); =20 -void resctrl_init_mon_events(void); +int resctrl_init_mon_events(void); =20 #ifdef CONFIG_RESCTRL_FS_PSEUDO_LOCK int rdtgroup_locksetup_enter(struct rdtgroup *rdtgrp); diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resct= rl/core.c index dc312e24ab87..d921f32a1b6c 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; + struct rdt_resource *r; + int num_rmids =3D S32_MAX; + + 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 f848325591b4..f7a5ffe9be25 100644 --- a/fs/resctrl/monitor.c +++ b/fs/resctrl/monitor.c @@ -762,7 +762,7 @@ void mbm_setup_overflow_handler(struct rdt_l3_mon_domai= n *dom, unsigned long del schedule_delayed_work_on(cpu, &dom->mbm_over, delay); } =20 -static int dom_data_init(struct rdt_resource *r) +static int resctrl_dom_data_init(struct rdt_resource *r) { u32 idx_limit =3D resctrl_arch_system_num_rmid_idx(); u32 num_closid =3D resctrl_arch_get_num_closid(r); @@ -770,7 +770,10 @@ static int dom_data_init(struct rdt_resource *r) int err =3D 0, i; u32 idx; =20 - mutex_lock(&rdtgroup_mutex); + /* Are there any mon_capable resources? */ + if (idx_limit =3D=3D S32_MAX) + return 0; + if (IS_ENABLED(CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID)) { u32 *tmp; =20 @@ -783,7 +786,7 @@ static int dom_data_init(struct rdt_resource *r) tmp =3D kcalloc(num_closid, sizeof(*tmp), GFP_KERNEL); if (!tmp) { err =3D -ENOMEM; - goto out_unlock; + goto out; } =20 closid_num_dirty_rmid =3D tmp; @@ -796,7 +799,7 @@ static int dom_data_init(struct rdt_resource *r) closid_num_dirty_rmid =3D NULL; } err =3D -ENOMEM; - goto out_unlock; + goto out; } =20 for (i =3D 0; i < idx_limit; i++) { @@ -817,14 +820,15 @@ 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); +out: =20 return err; } =20 -static void dom_data_exit(struct rdt_resource *r) +void resctrl_dom_data_exit(void) { + struct rdt_resource *r =3D resctrl_arch_get_resource(RDT_RESOURCE_L3); + mutex_lock(&rdtgroup_mutex); =20 if (!r->mon_capable) @@ -954,16 +958,21 @@ char *resctrl_mon_event_name(enum resctrl_event_id ev= t) * events have been enumerated. Only needs to build the per-resource * event lists once. */ -void resctrl_init_mon_events(void) +int resctrl_init_mon_events(void) { + struct rdt_resource *r =3D resctrl_arch_get_resource(RDT_RESOURCE_L3); enum resctrl_event_id evt; - struct rdt_resource *r; static bool only_once; + int ret; =20 if (only_once) - return; + return 0; only_once =3D true; =20 + ret =3D resctrl_dom_data_init(r); + if (ret) + return ret; + for_each_mon_capable_rdt_resource(r) INIT_LIST_HEAD(&r->evt_list); =20 @@ -973,6 +982,8 @@ void resctrl_init_mon_events(void) r =3D resctrl_arch_get_resource(mon_event_all[evt].rid); list_add_tail(&mon_event_all[evt].list, &r->evt_list); } + + return ret; } =20 /** @@ -989,16 +1000,6 @@ void resctrl_init_mon_events(void) */ int resctrl_mon_resource_init(void) { - struct rdt_resource *r =3D resctrl_arch_get_resource(RDT_RESOURCE_L3); - int ret; - - if (!r->mon_capable) - return 0; - - ret =3D dom_data_init(r); - if (ret) - return ret; - if (resctrl_arch_is_evt_configurable(QOS_L3_MBM_TOTAL_EVENT_ID)) { mon_event_all[QOS_L3_MBM_TOTAL_EVENT_ID].configurable =3D true; resctrl_file_fflags_init("mbm_total_bytes_config", @@ -1017,10 +1018,3 @@ int resctrl_mon_resource_init(void) =20 return 0; } - -void resctrl_mon_resource_exit(void) -{ - struct rdt_resource *r =3D resctrl_arch_get_resource(RDT_RESOURCE_L3); - - dom_data_exit(r); -} diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index 544fa721e067..195e41eb73fb 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -2595,7 +2595,9 @@ static int rdt_get_tree(struct fs_context *fc) goto out; } =20 - resctrl_init_mon_events(); + ret =3D resctrl_init_mon_events(); + if (ret) + goto out; =20 ret =3D rdtgroup_setup_root(ctx); if (ret) @@ -4300,10 +4302,8 @@ int resctrl_init(void) return ret; =20 ret =3D sysfs_create_mount_point(fs_kobj, "resctrl"); - if (ret) { - resctrl_mon_resource_exit(); + if (ret) return ret; - } =20 ret =3D register_filesystem(&rdt_fs_type); if (ret) @@ -4336,7 +4336,6 @@ int resctrl_init(void) =20 cleanup_mountpoint: sysfs_remove_mount_point(fs_kobj, "resctrl"); - resctrl_mon_resource_exit(); =20 return ret; } @@ -4363,7 +4362,7 @@ static bool resctrl_online_domains_exist(void) * When called by the architecture code, all CPUs and resctrl domains must= be * offline. This ensures the limbo and overflow handlers are not scheduled= to * run, meaning the data structures they access can be freed by - * resctrl_mon_resource_exit(). + * resctrl_dom_data_exit(). * * After this function has returned, the architecture code should return an * from all resctrl_arch_ functions that can do this. @@ -4390,5 +4389,5 @@ void resctrl_exit(void) * it can be used to umount resctrl. */ =20 - resctrl_mon_resource_exit(); + resctrl_dom_data_exit(); } --=20 2.48.1 From nobody Fri Dec 19 19:02:40 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) (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 4BA35217F53 for ; Tue, 29 Apr 2025 00:34:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745886874; cv=none; b=rP587mNo3diDdbuhNZHn6rw9GxklG263LpbBMV2/xUNUKx7aYD6xPQYZCbuqyQCn7b6TW4Bnayhnhyc2UZdAKhSTW4esm3gXX1WinTwFsWP9BEHHgEpJS6UWdWeKw+MlHA64n0gMW3+2NC8Nkwla5XK/bo6dlrXe767Bcmf1Pgc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745886874; c=relaxed/simple; bh=YUTOhGbd6dZ07bX6i5x+8jR4iKqyRRJwMY4hLQXMO6w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=n0P+z1RxN6VvtBFzRjfn01rrSEkcMmN2vctA4ZQUjAaZo8HI5aSZl1fm+w5evWABXYuqH/u4uFvxuxGtKMZIVY9Kusdi1xFwWgkYnv2KyLP1w4ZZL9fqdbYgv7PT02/NZWYaDZqmol2TvQyLkEZ8WT68hpbJb6gZ4REX8D9vSis= 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=daog34a3; arc=none smtp.client-ip=192.198.163.9 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="daog34a3" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1745886872; x=1777422872; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=YUTOhGbd6dZ07bX6i5x+8jR4iKqyRRJwMY4hLQXMO6w=; b=daog34a3l0gIXVEbuctA2JYuogakXbjNU7ss0iZFy30W7Ixvyjrpy8+x 9wAZXYt494FBO6jGxIQn8kdP99YKfvatWgf4sUs8KOrw6fIrXkjBHTAyg 0/zdEfu7Xa+PAcQfzD2wo4k5+RHYFWpIIxTRLyNfMaCnAmW/V0AWIJwoa L9BiUMtHYr3ZdGOjdTs2SWYqKfzsI/don0jgPd/t/sX4xLrZjDTpOSe4v P5F1H8QxWyctj6X+PEzhqsFe0+3lEr90Ws8lFkxw83VtqiOdA8CwY/eph Q5iW9OO+fqj5G3PTo31NxBSmiwK45W9WbolBpv7rP0yZ4RELnPHDmV5pD g==; X-CSE-ConnectionGUID: W8hkLjy+Q2qCLP+H40eiFw== X-CSE-MsgGUID: rpaH3QhQRPCbn94y5Cj/NA== X-IronPort-AV: E=McAfee;i="6700,10204,11417"; a="58148316" X-IronPort-AV: E=Sophos;i="6.15,247,1739865600"; d="scan'208";a="58148316" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2025 17:34:25 -0700 X-CSE-ConnectionGUID: mWOeDafiSPGZibV08Ym2wQ== X-CSE-MsgGUID: rtUInqN9RcqmWFms5o5K3Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,247,1739865600"; d="scan'208";a="133394087" Received: from agluck-desk3.sc.intel.com ([172.25.222.70]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2025 17:34:24 -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 v4 29/31] fs/resctrl: Add interface for per-resource debug info files Date: Mon, 28 Apr 2025 17:33:55 -0700 Message-ID: <20250429003359.375508-30-tony.luck@intel.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250429003359.375508-1-tony.luck@intel.com> References: <20250429003359.375508-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 some status registers on each of the telemetry aggregators. Users may need to view these to understand unexpected event counter values. Add the file system support for a "status" file in each mon_capable resource directory in the "info" directory. This will only be present if the file system is mounted with the "-o debug" option. It will only have content for resources that provide a rdt_resource::info_debug() routine. Signed-off-by: Tony Luck --- include/linux/resctrl.h | 1 + fs/resctrl/rdtgroup.c | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index 3ae50b947a99..675cfbe3e6c6 100644 --- a/include/linux/resctrl.h +++ b/include/linux/resctrl.h @@ -299,6 +299,7 @@ struct rdt_resource { struct list_head evt_list; unsigned int mbm_cfg_mask; bool cdp_capable; + void (*info_debug)(struct seq_file *s); }; =20 /* diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index 195e41eb73fb..5948e279b44c 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -1022,6 +1022,17 @@ static int rdt_shareable_bits_show(struct kernfs_ope= n_file *of, return 0; } =20 +static int rdtgroup_info_debug_show(struct kernfs_open_file *of, + struct seq_file *s, void *v) +{ + struct rdt_resource *r =3D rdt_kn_parent_priv(of->kn); + + if (r->info_debug) + r->info_debug(s); + + return 0; +} + /* * rdt_bit_usage_show - Display current usage of resources * @@ -1983,6 +1994,13 @@ static struct rftype res_common_files[] =3D { .seq_show =3D rdtgroup_closid_show, .fflags =3D RFTYPE_CTRL_BASE | RFTYPE_DEBUG, }, + { + .name =3D "status", + .mode =3D 0444, + .kf_ops =3D &rdtgroup_kf_single_ops, + .seq_show =3D rdtgroup_info_debug_show, + .fflags =3D RFTYPE_MON_INFO | RFTYPE_DEBUG, + }, }; =20 static int rdtgroup_add_files(struct kernfs_node *kn, unsigned long fflags) --=20 2.48.1 From nobody Fri Dec 19 19:02:40 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) (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 E1C152192E1 for ; Tue, 29 Apr 2025 00:34:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745886875; cv=none; b=n/arscvU2L3Z9gPiHh/ZxrlomIt8hxJlIGp+HTVZBG6zSgyEqaiOw3qxo25GIzMhWPBYlghbld6guDAiQkYg8dxId0wDOtXfJq0QH1G+71aqIepNg5nLkI+U1e8o5zGfGevmDAWcvhfPZzrT4lsLR9Q2qoj65+QwU8XxDyP3mt4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745886875; c=relaxed/simple; bh=NlNHfrc2wwtjmk4C/GF1Qzcg97B066KGqDpMx3SpahE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=A24jGsQcHgiHWHwe5jafgr1Bfa5GCjH9I0SHBa75ezcn59diOEJ6yIp7AnqUW90q1NTow2k6mQyVNt5B8zEjEfhY5kGki9w+tYxQtziWtmHROvtVMFT/DYcpyPLNrH+b2ncahSNy5n4tSA76D2+YNoE0Z2LeXgFQSca/Esp1zPM= 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=FxRmhrAa; arc=none smtp.client-ip=192.198.163.9 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="FxRmhrAa" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1745886873; x=1777422873; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=NlNHfrc2wwtjmk4C/GF1Qzcg97B066KGqDpMx3SpahE=; b=FxRmhrAacMFZ1t+lvfU/UMR6QgUXTMvBN4vF152liDmVarABU8TS3SGD zKT86hlwsk+oxuy98PnatFVtKZLlYpkKIMjgUG20WBLS2Ei1iV+tCm7cG HbFVMdnYGlE5JnqNjX33gYjgVAvlY9W2k+HypGIQPUgbHSpR4k7edtR5q v21dJ5MqQOofcppaNw23lDfU00QU+l7LiMmwu6CAw4D72tzz2iV7xqvpK 34So8gk4CuZDMUmnhnm91eFL1gwseX88dWv/6QX+yIkhFjr3ktEpQFvZS SNFziWB0aNO5gHZcbCn7leND3I3FGn+WtEpAqwaYxzvAMdZHqwhkbX6tH w==; X-CSE-ConnectionGUID: Ngu22ZLzQu+NER1/Sd581Q== X-CSE-MsgGUID: kDZOid8HQmqCzqmFVim9UA== X-IronPort-AV: E=McAfee;i="6700,10204,11417"; a="58148325" X-IronPort-AV: E=Sophos;i="6.15,247,1739865600"; d="scan'208";a="58148325" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2025 17:34:25 -0700 X-CSE-ConnectionGUID: BbRAxVpCQiOwZ+GE78soDA== X-CSE-MsgGUID: abSf4hMMQOiC8TP6ltieMw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,247,1739865600"; d="scan'208";a="133394091" Received: from agluck-desk3.sc.intel.com ([172.25.222.70]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2025 17:34:24 -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 v4 30/31] x86/resctrl: Add info/PERF_PKG_MON/status file Date: Mon, 28 Apr 2025 17:33:56 -0700 Message-ID: <20250429003359.375508-31-tony.luck@intel.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250429003359.375508-1-tony.luck@intel.com> References: <20250429003359.375508-1-tony.luck@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Each telemetry aggregator provides three status registers at the top end of MMIO space after all the per-RMID per-event counters: agg_data_loss_count: This counts the number of times that this aggregator failed to accumulate a counter value supplied by a CPU core. agg_data_loss_timestamp: This is a "timestamp" from a free running 25MHz uncore timer indicating when the most recent data loss occurred. last_update_timestamp: Another 25MHz timestamp indicating when the most recent counter update was successfully applied. When the resctrl file system is mounted with the "-o debug" option display the values of each of these status registers for each aggregator in each enabled event group. Signed-off-by: Tony Luck --- arch/x86/kernel/cpu/resctrl/intel_aet.c | 30 +++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/arch/x86/kernel/cpu/resctrl/intel_aet.c b/arch/x86/kernel/cpu/= resctrl/intel_aet.c index eec5eb625f13..80a8af3c4711 100644 --- a/arch/x86/kernel/cpu/resctrl/intel_aet.c +++ b/arch/x86/kernel/cpu/resctrl/intel_aet.c @@ -16,6 +16,7 @@ #include #include #include +#include =20 /* Temporary - delete from final version */ #include "fake_intel_aet_features.h" @@ -241,6 +242,33 @@ static bool get_pmt_feature(enum pmt_feature_id featur= e) return false; } =20 +static void show_debug(struct seq_file *s, struct event_group *e, int pkg,= int instance) +{ + u64 *info __iomem =3D e->pkginfo[pkg]->addrs[instance] + e->mmio_size; + + /* Information registers are the last three qwords in MMIO space */ + seq_printf(s, "%s %d:%d agg_data_loss_count =3D %llu\n", e->name, pkg, in= stance, + readq(&info[-3])); + seq_printf(s, "%s %d:%d agg_data_loss_timestamp =3D %llu\n", e->name, pkg= , instance, + readq(&info[-2])); + seq_printf(s, "%s %d:%d last_update_timestamp =3D %llu\n", e->name, pkg, = instance, + readq(&info[-1])); +} + +static void info_debug(struct seq_file *s) +{ + int num_pkgs =3D topology_max_packages(); + struct event_group **eg; + + for (eg =3D &known_event_groups[0]; eg < &known_event_groups[NUM_KNOWN_GR= OUPS]; eg++) { + if (!(*eg)->pfg) + continue; + for (int i =3D 0; i < num_pkgs; i++) + for (int j =3D 0; j < (*eg)->pkginfo[i]->count; j++) + show_debug(s, *eg, i, j); + } +} + /* * Ask OOBMSM discovery driver for all the RMID based telemetry groups * that it supports. @@ -263,6 +291,8 @@ bool intel_aet_get_events(void) r->num_rmid =3D (*eg)->num_rmids; } =20 + r->info_debug =3D info_debug; + return ret1 || ret2; } =20 --=20 2.48.1 From nobody Fri Dec 19 19:02:40 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) (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 BEBCC219A89 for ; Tue, 29 Apr 2025 00:34:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745886876; cv=none; b=CsNdAfSMoCV0GPeA9blhOHL7WxL9r6EBCFA7870jg7cbFsdoX80sUzHZdbICEj8cV7ZI2mCDj2O4kgfDSZ4eahBkKWqYxTJFeZl53Ps9dnTLuTDB9YZFUTsc7VJfAuYq5WmmtxnC9wxu9pFXj0q0YISmeRyVJOuCfJkCE2JXtJs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745886876; c=relaxed/simple; bh=NRSYi9njI6kQ0Knk+/+VA3mUTIkHFCwTpsUiejjGJh8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rHCh/2wKfiK4jtTZla66LI3tFdf0P72mYMie53QZ9YxetqHAsaoUfOpZNm1VaQfQNazUaJZ2EwyKIx0NZW2EGCW+eUZ6pTomB5asfS7LjsxBt9vkv8NHhzJ4oObGWhgemVeonVRrMVzJsXluefHZRk0GJjbNImFFnIFRtjKTRYU= 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=GUzbwSiH; arc=none smtp.client-ip=192.198.163.9 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="GUzbwSiH" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1745886873; x=1777422873; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=NRSYi9njI6kQ0Knk+/+VA3mUTIkHFCwTpsUiejjGJh8=; b=GUzbwSiHVVyC6PI9otlEiYZyC5cAKZ2pYJZg5YMAjVTU4aou6ndXbBt2 pX+CEBLsO5DGx57wd3o6QDaKnbPQZaZgKIpEK13r2ssR5I+TGg43AhdXm 9pmZL2MSPx96lJelEURPbdRhtRva8GnuukjZX3MUbEkru0MrDYBhPuNZj frw4G+imN8t2VJUULq/ougcuE8IZDEzTNwE5kew0hyoJEZaXO7NnLv9U1 /yuv77uSNFQD34io0+rPc8LRWYkiZXo76hoeniNRmvGwxDqUdgwhCPkSL 0YGJMWU0ecSlXdkrC0saOsHn4Up3l/t0dXxRNQ2VXTz6C3U3RzNDzh7Ck Q==; X-CSE-ConnectionGUID: YdbcHR7MRoOvKvGMDOAlXQ== X-CSE-MsgGUID: QG+CSAl2SJy3w7rDlXwQDw== X-IronPort-AV: E=McAfee;i="6700,10204,11417"; a="58148333" X-IronPort-AV: E=Sophos;i="6.15,247,1739865600"; d="scan'208";a="58148333" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2025 17:34:26 -0700 X-CSE-ConnectionGUID: yb/TSNteSoe+u5KS2RXjLA== X-CSE-MsgGUID: ZaNk/BYnSKK4/fH49hN4mg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,247,1739865600"; d="scan'208";a="133394095" Received: from agluck-desk3.sc.intel.com ([172.25.222.70]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2025 17:34:25 -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 v4 31/31] x86/resctrl: Update Documentation for package events Date: Mon, 28 Apr 2025 17:33:57 -0700 Message-ID: <20250429003359.375508-32-tony.luck@intel.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250429003359.375508-1-tony.luck@intel.com> References: <20250429003359.375508-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.48.1