Skip to contentSkip to conversation

x86/resctrl: mba_MBps enhancement

PATCH Applied Tony Luck 5 participants 31 messages Dec 6, 2024 – Dec 13, 2024

Subsystems (3)
lore
Share & tools
lore

Tony Luck

author maintainer
#0 lore raw

v11 cover x86/resctrl: mba_MBps enhancement

Background
----------

The resctrl filesystem supports a mount option that allows users to specify a memory bandwidth limit in MiB/s for each domain of a CTRL_MON group. The underlying implementation uses data collected from the local memory bandwidth monitoring event for the CTRL_MON group and all of its MON subgroups as input to a feedback loop that adjusts the memory bandwidth allocation control percentage up or down to keep the group within the limit set by the user.

Problem statement
-----------------

Hard coding the local memory bandwidth monitoring event has the following issues:

1) Some systems may support total memory bandwidth monitoring but not local. The user cannot use this mount option on such systems.

2) For large workloads that span NUMA domains using local bandwidth monitoring will not throttle jobs correctly.

3) Users may have a mix of large and small workloads and may want to use different input events per CTRL_MON group.

Solution
--------

A) Provide a new user interface to choose which event is used for each CTRL_MON group.

B) Allow systems that only support total memory bandwidth monitoring to use total bandwidth event.

Changes since v10:

Patch Change
----- ------

2 s/filesystm/filesystem/
Reformat block comment above definition of mba_mbps_default_event using more of 80 column width

3 s/Update_mba_bw()/update_mba_bw()

Added Reinette's Reviewed-by tag to parts 2-8

N.B. v6.13-rc1 introduced a locking change in commit f1be1788a32e ("block:
model freeze & enter queue as lock for supporting lockdep") that throws a lockdep splat when mounting the resctrl filesystem (with certain CONFIG options).

Proposed patches that fix this are here:

Babu Moger (1):
x86/resctrl: Introduce resctrl_file_fflags_init() to initialize fflags

Tony Luck (7):
x86/resctrl: Prepare for per-CTRL_MON group mba_MBps control x86/resctrl: Modify update_mba_bw() to use per CTRL_MON group event x86/resctrl: Compute memory bandwidth for all supported events x86/resctrl: Make mba_sc use total bandwidth if local is not supported x86/resctrl: Add "mba_MBps_event" file to CTRL_MON directories x86/resctrl: Add write option to "mba_MBps_event" file x86/resctrl: Document the new "mba_MBps_event" file

 Documentation/arch/x86/resctrl.rst        | 10 +++
 include/linux/resctrl.h                   |  2 +
 arch/x86/kernel/cpu/resctrl/internal.h    |  9 ++-
 arch/x86/kernel/cpu/resctrl/core.c        |  9 ++-
 arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 70 +++++++++++++++++
 arch/x86/kernel/cpu/resctrl/monitor.c     | 94 +++++++++++------------
 arch/x86/kernel/cpu/resctrl/rdtgroup.c    | 43 +++++++----
 7 files changed, 171 insertions(+), 66 deletions(-)

base-commit: 40384c840ea1944d7c5a392e8975ed088ecf0b37

Signature · 1 line
2.47.0
author maintainer
#1 lore raw

PATCH v11 1/8 x86/resctrl: Introduce resctrl_file_fflags_init() to initialize fflags

From: Babu Moger <[email protected]>

thread_throttle_mode_init() and mbm_config_rftype_init() both initialize fflags for resctrl files.

Adding new files will involve adding another function to initialize the fflags. This can be simplified by adding a new function resctrl_file_fflags_init() and passing the file name and flags to be initialized.

Consolidate fflags initialization into resctrl_file_fflags_init() and remove thread_throttle_mode_init() and mbm_config_rftype_init().

[Tony: Drop __init attribute so resctrl_file_fflags_init() can be used at run time]

---
 arch/x86/kernel/cpu/resctrl/internal.h |  3 +--
 arch/x86/kernel/cpu/resctrl/core.c     |  4 +++-
 arch/x86/kernel/cpu/resctrl/monitor.c  |  6 ++++--
 arch/x86/kernel/cpu/resctrl/rdtgroup.c | 15 ++-------------
 4 files changed, 10 insertions(+), 18 deletions(-)
arch/x86/kernel/cpu/resctrl/internal.h +1 -2
index 955999aecfca..faaff9d64102 100644
@@ -647,8 +647,7 @@ void cqm_handle_limbo(struct work_struct *work);
 bool has_busy_rmid(struct rdt_mon_domain *d);
 void __check_limbo(struct rdt_mon_domain *d, bool force_free);
 void rdt_domain_reconfigure_cdp(struct rdt_resource *r);
-void __init thread_throttle_mode_init(void);
-void __init mbm_config_rftype_init(const char *config);
+void resctrl_file_fflags_init(const char *config, unsigned long fflags);
 void rdt_staged_configs_clear(void);
 bool closid_allocated(unsigned int closid);
 int resctrl_find_cleanest_closid(void);
arch/x86/kernel/cpu/resctrl/core.c +3 -1
index b681c2e07dbf..f3ee5859b69d 100644
@@ -234,7 +234,9 @@ static __init bool __get_mem_config_intel(struct rdt_resource *r)
 		r->membw.throttle_mode = THREAD_THROTTLE_PER_THREAD;
 	else
 		r->membw.throttle_mode = THREAD_THROTTLE_MAX;
-	thread_throttle_mode_init();
+
+	resctrl_file_fflags_init("thread_throttle_mode",
+				 RFTYPE_CTRL_INFO | RFTYPE_RES_MB);
 
 	r->alloc_capable = true;
 
arch/x86/kernel/cpu/resctrl/monitor.c +4 -2
index 5fcb3d635d91..69bdc11bacf8 100644
@@ -1224,11 +1224,13 @@ int __init rdt_get_mon_l3_config(struct rdt_resource *r)
 
 		if (rdt_cpu_has(X86_FEATURE_CQM_MBM_TOTAL)) {
 			mbm_total_event.configurable = true;
-			mbm_config_rftype_init("mbm_total_bytes_config");
+			resctrl_file_fflags_init("mbm_total_bytes_config",
+						 RFTYPE_MON_INFO | RFTYPE_RES_CACHE);
 		}
 		if (rdt_cpu_has(X86_FEATURE_CQM_MBM_LOCAL)) {
 			mbm_local_event.configurable = true;
-			mbm_config_rftype_init("mbm_local_bytes_config");
+			resctrl_file_fflags_init("mbm_local_bytes_config",
+						 RFTYPE_MON_INFO | RFTYPE_RES_CACHE);
 		}
 	}
 
arch/x86/kernel/cpu/resctrl/rdtgroup.c +2 -13
index d906a1cd8491..d333570e893d 100644
@@ -2020,24 +2020,13 @@ static struct rftype *rdtgroup_get_rftype_by_name(const char *name)
 	return NULL;
 }
 
-void __init thread_throttle_mode_init(void)
-{
-	struct rftype *rft;
-
-	rft = rdtgroup_get_rftype_by_name("thread_throttle_mode");
-	if (!rft)
-		return;
-
-	rft->fflags = RFTYPE_CTRL_INFO | RFTYPE_RES_MB;
-}
-
-void __init mbm_config_rftype_init(const char *config)
+void resctrl_file_fflags_init(const char *config, unsigned long fflags)
 {
 	struct rftype *rft;
 
 	rft = rdtgroup_get_rftype_by_name(config);
 	if (rft)
-		rft->fflags = RFTYPE_MON_INFO | RFTYPE_RES_CACHE;
+		rft->fflags = fflags;
 }
 
 /**
Signature · 1 line
2.47.0
merge bot Applied
#2 lore raw

[tip: x86/cache] x86/resctrl: Introduce resctrl_file_fflags_init() to initialize fflags

The following commit has been merged into the x86/cache branch of tip:

The following commit has been merged into the x86/cache branch of tip:

Commit-ID:     2937f9c361f7a8b230cd599e4af5264798bf4ce7
Gitweb:        https://git.kernel.org/tip/2937f9c361f7a8b230cd599e4af5264798bf4ce7
Author:        Babu Moger <[email protected]>
AuthorDate:    Fri, 06 Dec 2024 08:31:41 -08:00
Committer:     Borislav Petkov (AMD) <[email protected]>
CommitterDate: Mon, 09 Dec 2024 21:37:01 +01:00

x86/resctrl: Introduce resctrl_file_fflags_init() to initialize fflags

thread_throttle_mode_init() and mbm_config_rftype_init() both initialize fflags for resctrl files.

Adding new files will involve adding another function to initialize the fflags. This can be simplified by adding a new function resctrl_file_fflags_init() and passing the file name and flags to be initialized.

Consolidate fflags initialization into resctrl_file_fflags_init() and remove thread_throttle_mode_init() and mbm_config_rftype_init().

[ Tony: Drop __init attribute so resctrl_file_fflags_init() can be used at
run time. ]

---
 arch/x86/kernel/cpu/resctrl/core.c     |  4 +++-
 arch/x86/kernel/cpu/resctrl/internal.h |  3 +--
 arch/x86/kernel/cpu/resctrl/monitor.c  |  6 ++++--
 arch/x86/kernel/cpu/resctrl/rdtgroup.c | 15 ++-------------
 4 files changed, 10 insertions(+), 18 deletions(-)
arch/x86/kernel/cpu/resctrl/core.c +3 -1
index b681c2e..f3ee585 100644
@@ -234,7 +234,9 @@ static __init bool __get_mem_config_intel(struct rdt_resource *r)
 		r->membw.throttle_mode = THREAD_THROTTLE_PER_THREAD;
 	else
 		r->membw.throttle_mode = THREAD_THROTTLE_MAX;
-	thread_throttle_mode_init();
+
+	resctrl_file_fflags_init("thread_throttle_mode",
+				 RFTYPE_CTRL_INFO | RFTYPE_RES_MB);
 
 	r->alloc_capable = true;
 
arch/x86/kernel/cpu/resctrl/internal.h +1 -2
index 955999a..faaff9d 100644
@@ -647,8 +647,7 @@ void cqm_handle_limbo(struct work_struct *work);
 bool has_busy_rmid(struct rdt_mon_domain *d);
 void __check_limbo(struct rdt_mon_domain *d, bool force_free);
 void rdt_domain_reconfigure_cdp(struct rdt_resource *r);
-void __init thread_throttle_mode_init(void);
-void __init mbm_config_rftype_init(const char *config);
+void resctrl_file_fflags_init(const char *config, unsigned long fflags);
 void rdt_staged_configs_clear(void);
 bool closid_allocated(unsigned int closid);
 int resctrl_find_cleanest_closid(void);
arch/x86/kernel/cpu/resctrl/monitor.c +4 -2
index 5fcb3d6..69bdc11 100644
@@ -1224,11 +1224,13 @@ int __init rdt_get_mon_l3_config(struct rdt_resource *r)
 
 		if (rdt_cpu_has(X86_FEATURE_CQM_MBM_TOTAL)) {
 			mbm_total_event.configurable = true;
-			mbm_config_rftype_init("mbm_total_bytes_config");
+			resctrl_file_fflags_init("mbm_total_bytes_config",
+						 RFTYPE_MON_INFO | RFTYPE_RES_CACHE);
 		}
 		if (rdt_cpu_has(X86_FEATURE_CQM_MBM_LOCAL)) {
 			mbm_local_event.configurable = true;
-			mbm_config_rftype_init("mbm_local_bytes_config");
+			resctrl_file_fflags_init("mbm_local_bytes_config",
+						 RFTYPE_MON_INFO | RFTYPE_RES_CACHE);
 		}
 	}
 
arch/x86/kernel/cpu/resctrl/rdtgroup.c +2 -13
index d906a1c..d333570 100644
@@ -2020,24 +2020,13 @@ static struct rftype *rdtgroup_get_rftype_by_name(const char *name)
 	return NULL;
 }
 
-void __init thread_throttle_mode_init(void)
-{
-	struct rftype *rft;
-
-	rft = rdtgroup_get_rftype_by_name("thread_throttle_mode");
-	if (!rft)
-		return;
-
-	rft->fflags = RFTYPE_CTRL_INFO | RFTYPE_RES_MB;
-}
-
-void __init mbm_config_rftype_init(const char *config)
+void resctrl_file_fflags_init(const char *config, unsigned long fflags)
 {
 	struct rftype *rft;
 
 	rft = rdtgroup_get_rftype_by_name(config);
 	if (rft)
-		rft->fflags = RFTYPE_MON_INFO | RFTYPE_RES_CACHE;
+		rft->fflags = fflags;
 }
 
 /**
author maintainer
#3 lore raw

PATCH v11 2/8 x86/resctrl: Prepare for per-CTRL_MON group mba_MBps control

In reply to Tony Luck

Resctrl uses local memory bandwidth event as input to the feedback loop when the mba_MBps mount option is used. This means that this mount option cannot be used on systems that only support monitoring of total bandwidth.

Prepare to allow users to choose the input event independently for each CTRL_MON group by adding a global variable "mba_mbps_default_event" used to set the default event for each CTRL_MON group, and a new field "mba_mbps_event" in struct rdtgroup to track which event is used for each CTRL_MON group.

Notes:
1) Both of these are only used when the user mounts the filesystem with the "mba_MBps" option.
2) Only check for support of local bandwidth event when initializing mba_mbps_default_event. Support for total bandwidth event can be added after other routines in resctrl have been updated to handle total bandwidth event.

---
 include/linux/resctrl.h                |  2 ++
 arch/x86/kernel/cpu/resctrl/internal.h |  2 ++
 arch/x86/kernel/cpu/resctrl/core.c     |  3 +++
 arch/x86/kernel/cpu/resctrl/rdtgroup.c | 13 +++++++++++++
 4 files changed, 20 insertions(+)
include/linux/resctrl.h +2 -0
index d94abba1c716..fd05b937e2f4 100644
@@ -49,6 +49,8 @@ enum resctrl_event_id {
 	QOS_L3_MBM_LOCAL_EVENT_ID	= 0x03,
 };
 
+extern enum resctrl_event_id mba_mbps_default_event;
+
 /**
  * struct resctrl_staged_config - parsed configuration to be applied
  * @new_ctrl:		new ctrl value to be loaded
arch/x86/kernel/cpu/resctrl/internal.h +2 -0
index faaff9d64102..485800055a7d 100644
@@ -283,6 +283,7 @@ struct pseudo_lock_region {
  *				monitor only or ctrl_mon group
  * @mon:			mongroup related data
  * @mode:			mode of resource group
+ * @mba_mbps_event:		input monitoring event id when mba_sc is enabled
  * @plr:			pseudo-locked region
  */
 struct rdtgroup {
@@ -295,6 +296,7 @@ struct rdtgroup {
 	enum rdt_group_type		type;
 	struct mongroup			mon;
 	enum rdtgrp_mode		mode;
+	enum resctrl_event_id		mba_mbps_event;
 	struct pseudo_lock_region	*plr;
 };
 
arch/x86/kernel/cpu/resctrl/core.c +3 -0
index f3ee5859b69d..94bf559966d6 100644
@@ -963,6 +963,9 @@ static __init bool get_rdt_mon_resources(void)
 	if (!rdt_mon_features)
 		return false;
 
+	if (is_mbm_local_enabled())
+		mba_mbps_default_event = QOS_L3_MBM_LOCAL_EVENT_ID;
+
 	return !rdt_get_mon_l3_config(r);
 }
 
arch/x86/kernel/cpu/resctrl/rdtgroup.c +13 -0
index d333570e893d..8a52b25ce26b 100644
@@ -65,6 +65,15 @@ static void rdtgroup_destroy_root(void);
 
 struct dentry *debugfs_resctrl;
 
+/*
+ * Memory bandwidth monitoring event to use for the default CTRL_MON group
+ * and each new CTRL_MON group created by the user.  Only relevant when
+ * the filesystem is mounted with the "mba_MBps" option so it does not
+ * matter that it remains uninitialized on systems that do not support
+ * the "mba_MBps" option.
+ */
+enum resctrl_event_id mba_mbps_default_event;
+
 static bool resctrl_debug;
 
 void rdt_last_cmd_clear(void)
@@ -2353,6 +2362,8 @@ static int set_mba_sc(bool mba_sc)
 
 	r->membw.mba_sc = mba_sc;
 
+	rdtgroup_default.mba_mbps_event = mba_mbps_default_event;
+
 	list_for_each_entry(d, &r->ctrl_domains, hdr.list) {
 		for (i = 0; i < num_closid; i++)
 			d->mbps_val[i] = MBA_MAX_MBPS;
@@ -3611,6 +3622,8 @@ static int rdtgroup_mkdir_ctrl_mon(struct kernfs_node *parent_kn,
 			rdt_last_cmd_puts("kernfs subdir error\n");
 			goto out_del_list;
 		}
+		if (is_mba_sc(NULL))
+			rdtgrp->mba_mbps_event = mba_mbps_default_event;
 	}
 
 	goto out_unlock;
Signature · 1 line
2.47.0
maintainer
#4 lore raw

Re: [PATCH v11 2/8] x86/resctrl: Prepare for per-CTRL_MON group mba_MBps control

include/linux/resctrl.h enum resctrl_event_id { · line 52

Quoted 9 lines · Tony Luck
include/linux/resctrl.h +1 -0
index d94abba1c716..fd05b937e2f4 100644
@@ -49,6 +49,8 @@ enum resctrl_event_id {
 	QOS_L3_MBM_LOCAL_EVENT_ID	= 0x03,
 };
 
+extern enum resctrl_event_id mba_mbps_default_event;

Any reason this extern isn't in

arch/x86/kernel/cpu/resctrl/internal.h

?

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
author maintainer
#5 lore raw

RE: [PATCH v11 2/8] x86/resctrl: Prepare for per-CTRL_MON group mba_MBps control

Quoted 8 lines
Quoted 8 lines
include/linux/resctrl.h +0 -0
index d94abba1c716..fd05b937e2f4 100644
@@ -49,6 +49,8 @@ enum resctrl_event_id {
    QOS_L3_MBM_LOCAL_EVENT_ID       = 0x03,
 };
 
Quoted 5 lines

include/linux/resctrl.h enum resctrl_event_id { · line 52

Quoted 1 line
include/linux/resctrl.h +1 -0
+extern enum resctrl_event_id mba_mbps_default_event;

Any reason this extern isn't in

arch/x86/kernel/cpu/resctrl/internal.h

Trying to avoid making more work for the ARM folks as they split resctrl into "file system" and "architecture specific" bits.

mba_mbps_default_event isn't architecture specific. The mba_MBps feedback code could be implemented on any architecture that supports both measurement and control of memory bandwidth.

-Tony

maintainer
#6 lore raw

Re: [PATCH v11 2/8] x86/resctrl: Prepare for per-CTRL_MON group mba_MBps control

Quoted 3 lines · Tony

mba_mbps_default_event isn't architecture specific. The mba_MBps feedback code could be implemented on any architecture that supports both measurement and control of memory bandwidth.

Yes, and it should be moved to that header then, right?

But not earlier.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
author maintainer
#7 lore raw

RE: [PATCH v11 2/8] x86/resctrl: Prepare for per-CTRL_MON group mba_MBps control

Quoted 7 lines
Quoted 3 lines

mba_mbps_default_event isn't architecture specific. The mba_MBps feedback code could be implemented on any architecture that supports both measurement and control of memory bandwidth.

Yes, and it should be moved to that header then, right?

But not earlier.

If you feel strongly about it then go ahead and cut the line from <linux/rectrl.h> and paste it into <asm/resctrl.h>

-Tony

maintainer
#8 lore raw

Re: [PATCH v11 2/8] x86/resctrl: Prepare for per-CTRL_MON group mba_MBps control

Hi Tony,

Quoted 10 lines · Tony
Quoted 7 lines
Quoted 3 lines

mba_mbps_default_event isn't architecture specific. The mba_MBps feedback code could be implemented on any architecture that supports both measurement and control of memory bandwidth.

Yes, and it should be moved to that header then, right?

But not earlier.

If you feel strongly about it then go ahead and cut the line from <linux/rectrl.h> and paste it into <asm/resctrl.h>

I am not sure about this ... I expect the code needing this initially will form part of the filesystem code so it may be more intuitive to have it be located in arch/x86/kernel/cpu/resctrl/internal.h as Boris suggested. As part of the arch/fs split it may then move to fs/resctrl/internal.h

mba_mbps_default_event may even stay internal to the fs/resctrl code with an arch helper created later to initialize it. This is because I think the initialization of mba_mbps_default_event may move out of get_rdt_mon_resources() into resctrl_mon_resource_init() that is being created as part of the MPAM work [1]. An example of current fs initialization done in arch code that is moved to it can be found in [2].

Reinette

[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/

author maintainer
#9 lore raw

Re: [PATCH v11 2/8] x86/resctrl: Prepare for per-CTRL_MON group mba_MBps control

Quoted 19 lines · Reinette Chatre

Hi Tony,

Quoted 10 lines · Tony
Quoted 7 lines
Quoted 3 lines

mba_mbps_default_event isn't architecture specific. The mba_MBps feedback code could be implemented on any architecture that supports both measurement and control of memory bandwidth.

Yes, and it should be moved to that header then, right?

But not earlier.

If you feel strongly about it then go ahead and cut the line from <linux/rectrl.h> and paste it into <asm/resctrl.h>

I am not sure about this ... I expect the code needing this initially will form part of the filesystem code so it may be more intuitive to have it be located in arch/x86/kernel/cpu/resctrl/internal.h as Boris suggested. As part of the arch/fs split it may then move to fs/resctrl/internal.h

Quoted 6 lines

mba_mbps_default_event may even stay internal to the fs/resctrl code with an arch helper created later to initialize it. This is because I think the initialization of mba_mbps_default_event may move out of get_rdt_mon_resources() into resctrl_mon_resource_init() that is being created as part of the MPAM work [1]. An example of current fs initialization done in arch code that is moved to it can be found in [2].

Reinette is right. The post-split home of this is not <linux/resctrl.h> but fs/resctrl/internal.h which doesn't exist yet.

So Boris is right, this declaration should be added to arch/x86/kernel/cpu/resctrl/internal.h by this patch to be moved later.

Quoted 3 lines

[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/

-Tony

maintainer
#10 lore raw

Re: [PATCH v11 2/8] x86/resctrl: Prepare for per-CTRL_MON group mba_MBps control

Quoted 5 lines · Tony

Reinette is right. The post-split home of this is not <linux/resctrl.h> but fs/resctrl/internal.h which doesn't exist yet.

So Boris is right, this declaration should be added to arch/x86/kernel/cpu/resctrl/internal.h by this patch to be moved later.

Done:

arch/x86/kernel/cpu/resctrl/internal.h +1 -1
index 485800055a7d..542d01c055aa 100644
@@ -510,6 +510,7 @@ extern struct mutex rdtgroup_mutex;
 extern struct rdt_hw_resource rdt_resources_all[];
 extern struct rdtgroup rdtgroup_default;
 extern struct dentry *debugfs_resctrl;
+extern enum resctrl_event_id mba_mbps_default_event;
 
 enum resctrl_res_level {
 	RDT_RESOURCE_L3,
@@ -653,5 +654,4 @@ void resctrl_file_fflags_init(const char *config, unsigned long fflags);
 void rdt_staged_configs_clear(void);
 bool closid_allocated(unsigned int closid);
 int resctrl_find_cleanest_closid(void);
-
 #endif /* _ASM_X86_RESCTRL_INTERNAL_H */
include/linux/resctrl.h +0 -2
index fd05b937e2f4..d94abba1c716 100644
@@ -49,8 +49,6 @@ enum resctrl_event_id {
 	QOS_L3_MBM_LOCAL_EVENT_ID	= 0x03,
 };
 
-extern enum resctrl_event_id mba_mbps_default_event;
-
 /**
  * struct resctrl_staged_config - parsed configuration to be applied
  * @new_ctrl:		new ctrl value to be loaded
Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
maintainer
#11 lore raw

Re: [PATCH v11 2/8] x86/resctrl: Prepare for per-CTRL_MON group mba_MBps control

Hi Boris,

Quoted 33 lines · Borislav Petkov
Quoted 5 lines · Tony

Reinette is right. The post-split home of this is not <linux/resctrl.h> but fs/resctrl/internal.h which doesn't exist yet.

So Boris is right, this declaration should be added to arch/x86/kernel/cpu/resctrl/internal.h by this patch to be moved later.

Done:

arch/x86/kernel/cpu/resctrl/internal.h +1 -1
index 485800055a7d..542d01c055aa 100644
@@ -510,6 +510,7 @@ extern struct mutex rdtgroup_mutex;
 extern struct rdt_hw_resource rdt_resources_all[];
 extern struct rdtgroup rdtgroup_default;
 extern struct dentry *debugfs_resctrl;
+extern enum resctrl_event_id mba_mbps_default_event;
 
 enum resctrl_res_level {
 	RDT_RESOURCE_L3,
@@ -653,5 +654,4 @@ void resctrl_file_fflags_init(const char *config, unsigned long fflags);
 void rdt_staged_configs_clear(void);
 bool closid_allocated(unsigned int closid);
 int resctrl_find_cleanest_closid(void);
-
 #endif /* _ASM_X86_RESCTRL_INTERNAL_H */
include/linux/resctrl.h +0 -0
index fd05b937e2f4..d94abba1c716 100644

include/linux/resctrl.h enum resctrl_event_id { · line 54

Quoted 8 lines
include/linux/resctrl.h +0 -2
@@ -49,8 +49,6 @@ enum resctrl_event_id {
 	QOS_L3_MBM_LOCAL_EVENT_ID	= 0x03,
 };
 
-extern enum resctrl_event_id mba_mbps_default_event;
-
 /**
  * struct resctrl_staged_config - parsed configuration to be applied
  * @new_ctrl:		new ctrl value to be loaded

Thank you very much for catching the issue and taking the time to create the fix.

The middle hunk looks to be an unrelated change. I squashed the first and last hunk of this change into the original patch and all my tests pass. I am still waiting the 0day test report though.

What would work best for you to have this fix included?

Reinette

maintainer
#12 lore raw

Re: [PATCH v11 2/8] x86/resctrl: Prepare for per-CTRL_MON group mba_MBps control

Quoted 2 lines · Reinette Chatre

Thank you very much for catching the issue and taking the time to create the fix.

For nothing. :)

Quoted 1 line

The middle hunk looks to be an unrelated change.

Yeah, I zapped the superfluous newline while at it.

Quoted 5 lines

I squashed the first and
last hunk of this change into the original patch and all my tests pass. I am still waiting the 0day test report though.

What would work best for you to have this fix included?

Already folded into Tony's patchset.

Will push out once I've gone through the set.

Thx.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
merge bot Applied
#13 lore raw

[tip: x86/cache] x86/resctrl: Prepare for per-CTRL_MON group mba_MBps control

In reply to Tony Luck
The following commit has been merged into the x86/cache branch of tip:

The following commit has been merged into the x86/cache branch of tip:

Commit-ID:     3b49c37a2f4657730dd38a050b9d221363889dea
Gitweb:        https://git.kernel.org/tip/3b49c37a2f4657730dd38a050b9d221363889dea
Author:        Tony Luck <[email protected]>
AuthorDate:    Fri, 06 Dec 2024 08:31:42 -08:00
Committer:     Borislav Petkov (AMD) <[email protected]>
CommitterDate: Tue, 10 Dec 2024 11:13:48 +01:00

x86/resctrl: Prepare for per-CTRL_MON group mba_MBps control

Resctrl uses local memory bandwidth event as input to the feedback loop when the mba_MBps mount option is used. This means that this mount option cannot be used on systems that only support monitoring of total bandwidth.

Prepare to allow users to choose the input event independently for each CTRL_MON group by adding a global variable "mba_mbps_default_event" used to set the default event for each CTRL_MON group, and a new field "mba_mbps_event" in struct rdtgroup to track which event is used for each CTRL_MON group.

Notes:

1) Both of these are only used when the user mounts the filesystem with the "mba_MBps" option.
2) Only check for support of local bandwidth event when initializing mba_mbps_default_event. Support for total bandwidth event can be added after other routines in resctrl have been updated to handle total bandwidth event.

[ bp: Move mba_mbps_default_event extern into the arch header. ]

---
 arch/x86/kernel/cpu/resctrl/core.c     |  3 +++
 arch/x86/kernel/cpu/resctrl/internal.h |  4 +++-
 arch/x86/kernel/cpu/resctrl/rdtgroup.c | 13 +++++++++++++
 3 files changed, 19 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/resctrl/core.c +3 -0
index f3ee585..94bf559 100644
@@ -963,6 +963,9 @@ static __init bool get_rdt_mon_resources(void)
 	if (!rdt_mon_features)
 		return false;
 
+	if (is_mbm_local_enabled())
+		mba_mbps_default_event = QOS_L3_MBM_LOCAL_EVENT_ID;
+
 	return !rdt_get_mon_l3_config(r);
 }
 
arch/x86/kernel/cpu/resctrl/internal.h +3 -1
index faaff9d..542d01c 100644
@@ -283,6 +283,7 @@ struct pseudo_lock_region {
  *				monitor only or ctrl_mon group
  * @mon:			mongroup related data
  * @mode:			mode of resource group
+ * @mba_mbps_event:		input monitoring event id when mba_sc is enabled
  * @plr:			pseudo-locked region
  */
 struct rdtgroup {
@@ -295,6 +296,7 @@ struct rdtgroup {
 	enum rdt_group_type		type;
 	struct mongroup			mon;
 	enum rdtgrp_mode		mode;
+	enum resctrl_event_id		mba_mbps_event;
 	struct pseudo_lock_region	*plr;
 };
 
@@ -508,6 +510,7 @@ extern struct mutex rdtgroup_mutex;
 extern struct rdt_hw_resource rdt_resources_all[];
 extern struct rdtgroup rdtgroup_default;
 extern struct dentry *debugfs_resctrl;
+extern enum resctrl_event_id mba_mbps_default_event;
 
 enum resctrl_res_level {
 	RDT_RESOURCE_L3,
@@ -651,5 +654,4 @@ void resctrl_file_fflags_init(const char *config, unsigned long fflags);
 void rdt_staged_configs_clear(void);
 bool closid_allocated(unsigned int closid);
 int resctrl_find_cleanest_closid(void);
-
 #endif /* _ASM_X86_RESCTRL_INTERNAL_H */
arch/x86/kernel/cpu/resctrl/rdtgroup.c +13 -0
index d333570..8a52b25 100644
@@ -65,6 +65,15 @@ static void rdtgroup_destroy_root(void);
 
 struct dentry *debugfs_resctrl;
 
+/*
+ * Memory bandwidth monitoring event to use for the default CTRL_MON group
+ * and each new CTRL_MON group created by the user.  Only relevant when
+ * the filesystem is mounted with the "mba_MBps" option so it does not
+ * matter that it remains uninitialized on systems that do not support
+ * the "mba_MBps" option.
+ */
+enum resctrl_event_id mba_mbps_default_event;
+
 static bool resctrl_debug;
 
 void rdt_last_cmd_clear(void)
@@ -2353,6 +2362,8 @@ static int set_mba_sc(bool mba_sc)
 
 	r->membw.mba_sc = mba_sc;
 
+	rdtgroup_default.mba_mbps_event = mba_mbps_default_event;
+
 	list_for_each_entry(d, &r->ctrl_domains, hdr.list) {
 		for (i = 0; i < num_closid; i++)
 			d->mbps_val[i] = MBA_MAX_MBPS;
@@ -3611,6 +3622,8 @@ static int rdtgroup_mkdir_ctrl_mon(struct kernfs_node *parent_kn,
 			rdt_last_cmd_puts("kernfs subdir error\n");
 			goto out_del_list;
 		}
+		if (is_mba_sc(NULL))
+			rdtgrp->mba_mbps_event = mba_mbps_default_event;
 	}
 
 	goto out_unlock;
author maintainer
#14 lore raw

PATCH v11 3/8 x86/resctrl: Modify update_mba_bw() to use per CTRL_MON group event

In reply to Tony Luck

update_mba_bw() hard codes use of the memory bandwidth local event which prevents more flexible options from being deployed.

Change this function to use the event specified in the rdtgroup that is being processed.

Mount time checks for the "mba_MBps" option ensure that local memory bandwidth is enabled. So drop the redundant is_mbm_local_enabled() check.

---
 arch/x86/kernel/cpu/resctrl/monitor.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
arch/x86/kernel/cpu/resctrl/monitor.c +9 -7
index 69bdc11bacf8..adb18f088979 100644
@@ -752,20 +752,20 @@ static void update_mba_bw(struct rdtgroup *rgrp, struct rdt_mon_domain *dom_mbm)
 	u32 closid, rmid, cur_msr_val, new_msr_val;
 	struct mbm_state *pmbm_data, *cmbm_data;
 	struct rdt_ctrl_domain *dom_mba;
+	enum resctrl_event_id evt_id;
 	struct rdt_resource *r_mba;
-	u32 cur_bw, user_bw, idx;
 	struct list_head *head;
 	struct rdtgroup *entry;
-
-	if (!is_mbm_local_enabled())
-		return;
+	u32 cur_bw, user_bw;
 
 	r_mba = &rdt_resources_all[RDT_RESOURCE_MBA].r_resctrl;
+	evt_id = rgrp->mba_mbps_event;
 
 	closid = rgrp->closid;
 	rmid = rgrp->mon.rmid;
-	idx = resctrl_arch_rmid_idx_encode(closid, rmid);
-	pmbm_data = &dom_mbm->mbm_local[idx];
+	pmbm_data = get_mbm_state(dom_mbm, closid, rmid, evt_id);
+	if (WARN_ON_ONCE(!pmbm_data))
+		return;
 
 	dom_mba = get_ctrl_domain_from_cpu(smp_processor_id(), r_mba);
 	if (!dom_mba) {
@@ -784,7 +784,9 @@ static void update_mba_bw(struct rdtgroup *rgrp, struct rdt_mon_domain *dom_mbm)
 	 */
 	head = &rgrp->mon.crdtgrp_list;
 	list_for_each_entry(entry, head, mon.crdtgrp_list) {
-		cmbm_data = &dom_mbm->mbm_local[entry->mon.rmid];
+		cmbm_data = get_mbm_state(dom_mbm, entry->closid, entry->mon.rmid, evt_id);
+		if (WARN_ON_ONCE(!cmbm_data))
+			return;
 		cur_bw += cmbm_data->prev_bw;
 	}
 
Signature · 1 line
2.47.0
merge bot Applied
#15 lore raw

[tip: x86/cache] x86/resctrl: Modify update_mba_bw() to use per CTRL_MON group event

The following commit has been merged into the x86/cache branch of tip:

The following commit has been merged into the x86/cache branch of tip:

Commit-ID:     481d363748b2df881df21569f3697b3c7fcf8fc1
Gitweb:        https://git.kernel.org/tip/481d363748b2df881df21569f3697b3c7fcf8fc1
Author:        Tony Luck <[email protected]>
AuthorDate:    Fri, 06 Dec 2024 08:31:43 -08:00
Committer:     Borislav Petkov (AMD) <[email protected]>
CommitterDate: Tue, 10 Dec 2024 11:15:19 +01:00

x86/resctrl: Modify update_mba_bw() to use per CTRL_MON group event

update_mba_bw() hard codes use of the memory bandwidth local event which prevents more flexible options from being deployed.

Change this function to use the event specified in the rdtgroup that is being processed.

Mount time checks for the "mba_MBps" option ensure that local memory bandwidth is enabled. So drop the redundant is_mbm_local_enabled() check.

---
 arch/x86/kernel/cpu/resctrl/monitor.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
arch/x86/kernel/cpu/resctrl/monitor.c +9 -7
index 69bdc11..adb18f0 100644
@@ -752,20 +752,20 @@ static void update_mba_bw(struct rdtgroup *rgrp, struct rdt_mon_domain *dom_mbm)
 	u32 closid, rmid, cur_msr_val, new_msr_val;
 	struct mbm_state *pmbm_data, *cmbm_data;
 	struct rdt_ctrl_domain *dom_mba;
+	enum resctrl_event_id evt_id;
 	struct rdt_resource *r_mba;
-	u32 cur_bw, user_bw, idx;
 	struct list_head *head;
 	struct rdtgroup *entry;
-
-	if (!is_mbm_local_enabled())
-		return;
+	u32 cur_bw, user_bw;
 
 	r_mba = &rdt_resources_all[RDT_RESOURCE_MBA].r_resctrl;
+	evt_id = rgrp->mba_mbps_event;
 
 	closid = rgrp->closid;
 	rmid = rgrp->mon.rmid;
-	idx = resctrl_arch_rmid_idx_encode(closid, rmid);
-	pmbm_data = &dom_mbm->mbm_local[idx];
+	pmbm_data = get_mbm_state(dom_mbm, closid, rmid, evt_id);
+	if (WARN_ON_ONCE(!pmbm_data))
+		return;
 
 	dom_mba = get_ctrl_domain_from_cpu(smp_processor_id(), r_mba);
 	if (!dom_mba) {
@@ -784,7 +784,9 @@ static void update_mba_bw(struct rdtgroup *rgrp, struct rdt_mon_domain *dom_mbm)
 	 */
 	head = &rgrp->mon.crdtgrp_list;
 	list_for_each_entry(entry, head, mon.crdtgrp_list) {
-		cmbm_data = &dom_mbm->mbm_local[entry->mon.rmid];
+		cmbm_data = get_mbm_state(dom_mbm, entry->closid, entry->mon.rmid, evt_id);
+		if (WARN_ON_ONCE(!cmbm_data))
+			return;
 		cur_bw += cmbm_data->prev_bw;
 	}
 
author maintainer
#16 lore raw

PATCH v11 4/8 x86/resctrl: Compute memory bandwidth for all supported events

In reply to Tony Luck

Switching between local and total memory bandwidth events as the input to the mba_sc feedback loop would be cumbersome and take effect slowly in the current implementation as the bandwidth is only known after two consecutive readings of the same event.

Compute the bandwidth for all supported events. This doesn't add significant overhead and will make changing which event is used simple.

---
 arch/x86/kernel/cpu/resctrl/monitor.c | 72 ++++++++++++---------------
 1 file changed, 33 insertions(+), 39 deletions(-)
arch/x86/kernel/cpu/resctrl/monitor.c +33 -39
index adb18f088979..94a1d9780461 100644
@@ -663,9 +663,12 @@ static int __mon_event_count(u32 closid, u32 rmid, struct rmid_read *rr)
  */
 static void mbm_bw_count(u32 closid, u32 rmid, struct rmid_read *rr)
 {
-	u32 idx = resctrl_arch_rmid_idx_encode(closid, rmid);
-	struct mbm_state *m = &rr->d->mbm_local[idx];
 	u64 cur_bw, bytes, cur_bytes;
+	struct mbm_state *m;
+
+	m = get_mbm_state(rr->d, closid, rmid, rr->evtid);
+	if (WARN_ON_ONCE(!m))
+		return;
 
 	cur_bytes = rr->val;
 	bytes = cur_bytes - m->prev_bw_bytes;
@@ -815,54 +818,45 @@ 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);
 }
 
-static void mbm_update(struct rdt_resource *r, struct rdt_mon_domain *d,
-		       u32 closid, u32 rmid)
+static void mbm_update_one_event(struct rdt_resource *r, struct rdt_mon_domain *d,
+				 u32 closid, u32 rmid, enum resctrl_event_id evtid)
 {
 	struct rmid_read rr = {0};
 
 	rr.r = r;
 	rr.d = d;
+	rr.evtid = evtid;
+	rr.arch_mon_ctx = resctrl_arch_mon_ctx_alloc(rr.r, rr.evtid);
+	if (IS_ERR(rr.arch_mon_ctx)) {
+		pr_warn_ratelimited("Failed to allocate monitor context: %ld",
+				    PTR_ERR(rr.arch_mon_ctx));
+		return;
+	}
+
+	__mon_event_count(closid, rmid, &rr);
 
 	/*
-	 * This is protected from concurrent reads from user
-	 * as both the user and we hold the global mutex.
+	 * If the software controller is enabled, compute the
+	 * bandwidth for this event id.
 	 */
-	if (is_mbm_total_enabled()) {
-		rr.evtid = QOS_L3_MBM_TOTAL_EVENT_ID;
-		rr.val = 0;
-		rr.arch_mon_ctx = resctrl_arch_mon_ctx_alloc(rr.r, rr.evtid);
-		if (IS_ERR(rr.arch_mon_ctx)) {
-			pr_warn_ratelimited("Failed to allocate monitor context: %ld",
-					    PTR_ERR(rr.arch_mon_ctx));
-			return;
-		}
+	if (is_mba_sc(NULL))
+		mbm_bw_count(closid, rmid, &rr);
 
-		__mon_event_count(closid, rmid, &rr);
-
-		resctrl_arch_mon_ctx_free(rr.r, rr.evtid, rr.arch_mon_ctx);
-	}
-	if (is_mbm_local_enabled()) {
-		rr.evtid = QOS_L3_MBM_LOCAL_EVENT_ID;
-		rr.val = 0;
-		rr.arch_mon_ctx = resctrl_arch_mon_ctx_alloc(rr.r, rr.evtid);
-		if (IS_ERR(rr.arch_mon_ctx)) {
-			pr_warn_ratelimited("Failed to allocate monitor context: %ld",
-					    PTR_ERR(rr.arch_mon_ctx));
-			return;
-		}
-
-		__mon_event_count(closid, rmid, &rr);
+	resctrl_arch_mon_ctx_free(rr.r, rr.evtid, rr.arch_mon_ctx);
+}
 
-		/*
-		 * Call the MBA software controller only for the
-		 * control groups and when user has enabled
-		 * the software controller explicitly.
-		 */
-		if (is_mba_sc(NULL))
-			mbm_bw_count(closid, rmid, &rr);
+static void mbm_update(struct rdt_resource *r, struct rdt_mon_domain *d,
+		       u32 closid, u32 rmid)
+{
+	/*
+	 * This is protected from concurrent reads from user as both
+	 * the user and overflow handler hold the global mutex.
+	 */
+	if (is_mbm_total_enabled())
+		mbm_update_one_event(r, d, closid, rmid, QOS_L3_MBM_TOTAL_EVENT_ID);
 
-		resctrl_arch_mon_ctx_free(rr.r, rr.evtid, rr.arch_mon_ctx);
-	}
+	if (is_mbm_local_enabled())
+		mbm_update_one_event(r, d, closid, rmid, QOS_L3_MBM_LOCAL_EVENT_ID);
 }
 
 /*
Signature · 1 line
2.47.0
merge bot Applied
#17 lore raw

[tip: x86/cache] x86/resctrl: Compute memory bandwidth for all supported events

The following commit has been merged into the x86/cache branch of tip:

The following commit has been merged into the x86/cache branch of tip:

Commit-ID:     2c272fadb58b590eb973c6c447b039f10631f5f7
Gitweb:        https://git.kernel.org/tip/2c272fadb58b590eb973c6c447b039f10631f5f7
Author:        Tony Luck <[email protected]>
AuthorDate:    Fri, 06 Dec 2024 08:31:44 -08:00
Committer:     Borislav Petkov (AMD) <[email protected]>
CommitterDate: Tue, 10 Dec 2024 16:13:48 +01:00

x86/resctrl: Compute memory bandwidth for all supported events

Switching between local and total memory bandwidth events as the input to the mba_sc feedback loop would be cumbersome and take effect slowly in the current implementation as the bandwidth is only known after two consecutive readings of the same event.

Compute the bandwidth for all supported events. This doesn't add significant overhead and will make changing which event is used simple.

---
 arch/x86/kernel/cpu/resctrl/monitor.c | 72 +++++++++++---------------
 1 file changed, 33 insertions(+), 39 deletions(-)
arch/x86/kernel/cpu/resctrl/monitor.c +33 -39
index adb18f0..94a1d97 100644
@@ -663,9 +663,12 @@ static int __mon_event_count(u32 closid, u32 rmid, struct rmid_read *rr)
  */
 static void mbm_bw_count(u32 closid, u32 rmid, struct rmid_read *rr)
 {
-	u32 idx = resctrl_arch_rmid_idx_encode(closid, rmid);
-	struct mbm_state *m = &rr->d->mbm_local[idx];
 	u64 cur_bw, bytes, cur_bytes;
+	struct mbm_state *m;
+
+	m = get_mbm_state(rr->d, closid, rmid, rr->evtid);
+	if (WARN_ON_ONCE(!m))
+		return;
 
 	cur_bytes = rr->val;
 	bytes = cur_bytes - m->prev_bw_bytes;
@@ -815,54 +818,45 @@ 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);
 }
 
-static void mbm_update(struct rdt_resource *r, struct rdt_mon_domain *d,
-		       u32 closid, u32 rmid)
+static void mbm_update_one_event(struct rdt_resource *r, struct rdt_mon_domain *d,
+				 u32 closid, u32 rmid, enum resctrl_event_id evtid)
 {
 	struct rmid_read rr = {0};
 
 	rr.r = r;
 	rr.d = d;
+	rr.evtid = evtid;
+	rr.arch_mon_ctx = resctrl_arch_mon_ctx_alloc(rr.r, rr.evtid);
+	if (IS_ERR(rr.arch_mon_ctx)) {
+		pr_warn_ratelimited("Failed to allocate monitor context: %ld",
+				    PTR_ERR(rr.arch_mon_ctx));
+		return;
+	}
+
+	__mon_event_count(closid, rmid, &rr);
 
 	/*
-	 * This is protected from concurrent reads from user
-	 * as both the user and we hold the global mutex.
+	 * If the software controller is enabled, compute the
+	 * bandwidth for this event id.
 	 */
-	if (is_mbm_total_enabled()) {
-		rr.evtid = QOS_L3_MBM_TOTAL_EVENT_ID;
-		rr.val = 0;
-		rr.arch_mon_ctx = resctrl_arch_mon_ctx_alloc(rr.r, rr.evtid);
-		if (IS_ERR(rr.arch_mon_ctx)) {
-			pr_warn_ratelimited("Failed to allocate monitor context: %ld",
-					    PTR_ERR(rr.arch_mon_ctx));
-			return;
-		}
+	if (is_mba_sc(NULL))
+		mbm_bw_count(closid, rmid, &rr);
 
-		__mon_event_count(closid, rmid, &rr);
-
-		resctrl_arch_mon_ctx_free(rr.r, rr.evtid, rr.arch_mon_ctx);
-	}
-	if (is_mbm_local_enabled()) {
-		rr.evtid = QOS_L3_MBM_LOCAL_EVENT_ID;
-		rr.val = 0;
-		rr.arch_mon_ctx = resctrl_arch_mon_ctx_alloc(rr.r, rr.evtid);
-		if (IS_ERR(rr.arch_mon_ctx)) {
-			pr_warn_ratelimited("Failed to allocate monitor context: %ld",
-					    PTR_ERR(rr.arch_mon_ctx));
-			return;
-		}
-
-		__mon_event_count(closid, rmid, &rr);
+	resctrl_arch_mon_ctx_free(rr.r, rr.evtid, rr.arch_mon_ctx);
+}
 
-		/*
-		 * Call the MBA software controller only for the
-		 * control groups and when user has enabled
-		 * the software controller explicitly.
-		 */
-		if (is_mba_sc(NULL))
-			mbm_bw_count(closid, rmid, &rr);
+static void mbm_update(struct rdt_resource *r, struct rdt_mon_domain *d,
+		       u32 closid, u32 rmid)
+{
+	/*
+	 * This is protected from concurrent reads from user as both
+	 * the user and overflow handler hold the global mutex.
+	 */
+	if (is_mbm_total_enabled())
+		mbm_update_one_event(r, d, closid, rmid, QOS_L3_MBM_TOTAL_EVENT_ID);
 
-		resctrl_arch_mon_ctx_free(rr.r, rr.evtid, rr.arch_mon_ctx);
-	}
+	if (is_mbm_local_enabled())
+		mbm_update_one_event(r, d, closid, rmid, QOS_L3_MBM_LOCAL_EVENT_ID);
 }
 
 /*
author maintainer
#18 lore raw

PATCH v11 5/8 x86/resctrl: Make mba_sc use total bandwidth if local is not supported

In reply to Tony Luck

The default input measurement to the mba_sc feedback loop for memory bandwidth control when the user mounts with the "mba_MBps" option is the local bandwidth event.

But some systems may not support a local bandwidth event.

When local bandwidth event is not supported, check for support of total bandwidth and use that instead.

Relax the mount option check to allow use of the "mba_MBps" option for systems when only total bandwidth monitoring is supported. Also update the error message.

---
 arch/x86/kernel/cpu/resctrl/core.c     | 2 ++
 arch/x86/kernel/cpu/resctrl/rdtgroup.c | 4 ++--
 2 files changed, 4 insertions(+), 2 deletions(-)
arch/x86/kernel/cpu/resctrl/core.c +2 -0
index 94bf559966d6..3d1735ed8d1f 100644
@@ -965,6 +965,8 @@ static __init bool get_rdt_mon_resources(void)
 
 	if (is_mbm_local_enabled())
 		mba_mbps_default_event = QOS_L3_MBM_LOCAL_EVENT_ID;
+	else if (is_mbm_total_enabled())
+		mba_mbps_default_event = QOS_L3_MBM_TOTAL_EVENT_ID;
 
 	return !rdt_get_mon_l3_config(r);
 }
arch/x86/kernel/cpu/resctrl/rdtgroup.c +2 -2
index 8a52b25ce26b..0659b8e2a71b 100644
@@ -2341,7 +2341,7 @@ static bool supports_mba_mbps(void)
 	struct rdt_resource *rmbm = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl;
 	struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_MBA].r_resctrl;
 
-	return (is_mbm_local_enabled() &&
+	return (is_mbm_enabled() &&
 		r->alloc_capable && is_mba_linear() &&
 		r->ctrl_scope == rmbm->mon_scope);
 }
@@ -2768,7 +2768,7 @@ static int rdt_parse_param(struct fs_context *fc, struct fs_parameter *param)
 		ctx->enable_cdpl2 = true;
 		return 0;
 	case Opt_mba_mbps:
-		msg = "mba_MBps requires local MBM and linear scale MBA at L3 scope";
+		msg = "mba_MBps requires MBM and linear scale MBA at L3 scope";
 		if (!supports_mba_mbps())
 			return invalfc(fc, msg);
 		ctx->enable_mba_mbps = true;
Signature · 1 line
2.47.0
merge bot Applied
#19 lore raw

[tip: x86/cache] x86/resctrl: Make mba_sc use total bandwidth if local is not supported

The following commit has been merged into the x86/cache branch of tip:

The following commit has been merged into the x86/cache branch of tip:

Commit-ID:     141cb5c482b38d7e494a207f881d0fe61e4848ef
Gitweb:        https://git.kernel.org/tip/141cb5c482b38d7e494a207f881d0fe61e4848ef
Author:        Tony Luck <[email protected]>
AuthorDate:    Fri, 06 Dec 2024 08:31:45 -08:00
Committer:     Borislav Petkov (AMD) <[email protected]>
CommitterDate: Tue, 10 Dec 2024 16:15:14 +01:00

x86/resctrl: Make mba_sc use total bandwidth if local is not supported

The default input measurement to the mba_sc feedback loop for memory bandwidth control when the user mounts with the "mba_MBps" option is the local bandwidth event. But some systems may not support a local bandwidth event.

When local bandwidth event is not supported, check for support of total bandwidth and use that instead.

Relax the mount option check to allow use of the "mba_MBps" option for systems when only total bandwidth monitoring is supported. Also update the error message.

---
 arch/x86/kernel/cpu/resctrl/core.c     | 2 ++
 arch/x86/kernel/cpu/resctrl/rdtgroup.c | 4 ++--
 2 files changed, 4 insertions(+), 2 deletions(-)
arch/x86/kernel/cpu/resctrl/core.c +2 -0
index 94bf559..3d1735e 100644
@@ -965,6 +965,8 @@ static __init bool get_rdt_mon_resources(void)
 
 	if (is_mbm_local_enabled())
 		mba_mbps_default_event = QOS_L3_MBM_LOCAL_EVENT_ID;
+	else if (is_mbm_total_enabled())
+		mba_mbps_default_event = QOS_L3_MBM_TOTAL_EVENT_ID;
 
 	return !rdt_get_mon_l3_config(r);
 }
arch/x86/kernel/cpu/resctrl/rdtgroup.c +2 -2
index 8a52b25..0659b8e 100644
@@ -2341,7 +2341,7 @@ static bool supports_mba_mbps(void)
 	struct rdt_resource *rmbm = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl;
 	struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_MBA].r_resctrl;
 
-	return (is_mbm_local_enabled() &&
+	return (is_mbm_enabled() &&
 		r->alloc_capable && is_mba_linear() &&
 		r->ctrl_scope == rmbm->mon_scope);
 }
@@ -2768,7 +2768,7 @@ static int rdt_parse_param(struct fs_context *fc, struct fs_parameter *param)
 		ctx->enable_cdpl2 = true;
 		return 0;
 	case Opt_mba_mbps:
-		msg = "mba_MBps requires local MBM and linear scale MBA at L3 scope";
+		msg = "mba_MBps requires MBM and linear scale MBA at L3 scope";
 		if (!supports_mba_mbps())
 			return invalfc(fc, msg);
 		ctx->enable_mba_mbps = true;
author maintainer
#20 lore raw

PATCH v11 6/8 x86/resctrl: Add "mba_MBps_event" file to CTRL_MON directories

In reply to Tony Luck

The "mba_MBps" mount option provides an alternate method to control memory bandwidth. Instead of specifying allowable bandwidth as a percentage of maximum possible, the user provides a MiB/s limit value.

In preparation to allow the user to pick the memory bandwidth monitoring event used as input to the feedback loop, provide a file in each CTRL_MON group directory that shows the event currently in use. Note that this file is only visible when the "mba_MBps" mount option is in use.

---
 arch/x86/kernel/cpu/resctrl/internal.h    |  2 ++
 arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 30 +++++++++++++++++++++++
 arch/x86/kernel/cpu/resctrl/rdtgroup.c    | 10 ++++++++
 3 files changed, 42 insertions(+)
arch/x86/kernel/cpu/resctrl/internal.h +2 -0
index 485800055a7d..ce10a883ecf8 100644
@@ -609,6 +609,8 @@ ssize_t rdtgroup_schemata_write(struct kernfs_open_file *of,
 				char *buf, size_t nbytes, loff_t off);
 int rdtgroup_schemata_show(struct kernfs_open_file *of,
 			   struct seq_file *s, void *v);
+int rdtgroup_mba_mbps_event_show(struct kernfs_open_file *of,
+				 struct seq_file *s, void *v);
 bool rdtgroup_cbm_overlaps(struct resctrl_schema *s, struct rdt_ctrl_domain *d,
 			   unsigned long cbm, int closid, bool exclusive);
 unsigned int rdtgroup_cbm_to_size(struct rdt_resource *r, struct rdt_ctrl_domain *d,
arch/x86/kernel/cpu/resctrl/ctrlmondata.c +30 -0
index 200d89a64027..5fa37b4ecc7a 100644
@@ -518,6 +518,36 @@ static int smp_mon_event_count(void *arg)
 	return 0;
 }
 
+int rdtgroup_mba_mbps_event_show(struct kernfs_open_file *of,
+				 struct seq_file *s, void *v)
+{
+	struct rdtgroup *rdtgrp;
+	int ret = 0;
+
+	rdtgrp = rdtgroup_kn_lock_live(of->kn);
+
+	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 = -EINVAL;
+			break;
+		}
+	} else {
+		ret = -ENOENT;
+	}
+
+	rdtgroup_kn_unlock(of->kn);
+
+	return ret;
+}
+
 void mon_event_read(struct rmid_read *rr, struct rdt_resource *r,
 		    struct rdt_mon_domain *d, struct rdtgroup *rdtgrp,
 		    cpumask_t *cpumask, int evtid, int first)
arch/x86/kernel/cpu/resctrl/rdtgroup.c +10 -0
index 0659b8e2a71b..6eb930b8bdfd 100644
@@ -1950,6 +1950,12 @@ static struct rftype res_common_files[] = {
 		.seq_show	= rdtgroup_schemata_show,
 		.fflags		= RFTYPE_CTRL_BASE,
 	},
+	{
+		.name		= "mba_MBps_event",
+		.mode		= 0444,
+		.kf_ops		= &rdtgroup_kf_single_ops,
+		.seq_show	= rdtgroup_mba_mbps_event_show,
+	},
 	{
 		.name		= "mode",
 		.mode		= 0644,
@@ -2355,6 +2361,7 @@ static int set_mba_sc(bool mba_sc)
 	struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_MBA].r_resctrl;
 	u32 num_closid = resctrl_arch_get_num_closid(r);
 	struct rdt_ctrl_domain *d;
+	unsigned long fflags;
 	int i;
 
 	if (!supports_mba_mbps() || mba_sc == is_mba_sc(r))
@@ -2369,6 +2376,9 @@ static int set_mba_sc(bool mba_sc)
 			d->mbps_val[i] = MBA_MAX_MBPS;
 	}
 
+	fflags = mba_sc ? RFTYPE_CTRL_BASE | RFTYPE_MON_BASE : 0;
+	resctrl_file_fflags_init("mba_MBps_event", fflags);
+
 	return 0;
 }
 
Signature · 1 line
2.47.0
merge bot Applied
#21 lore raw

[tip: x86/cache] x86/resctrl: Add "mba_MBps_event" file to CTRL_MON directories

The following commit has been merged into the x86/cache branch of tip:

The following commit has been merged into the x86/cache branch of tip:

Commit-ID:     f5cd0e316f14d79c9eb0cf8fe7e60cee3a657aa8
Gitweb:        https://git.kernel.org/tip/f5cd0e316f14d79c9eb0cf8fe7e60cee3a657aa8
Author:        Tony Luck <[email protected]>
AuthorDate:    Fri, 06 Dec 2024 08:31:46 -08:00
Committer:     Borislav Petkov (AMD) <[email protected]>
CommitterDate: Thu, 12 Dec 2024 11:27:28 +01:00

x86/resctrl: Add "mba_MBps_event" file to CTRL_MON directories

The "mba_MBps" mount option provides an alternate method to control memory bandwidth. Instead of specifying allowable bandwidth as a percentage of maximum possible, the user provides a MiB/s limit value.

In preparation to allow the user to pick the memory bandwidth monitoring event used as input to the feedback loop, provide a file in each CTRL_MON group directory that shows the event currently in use. Note that this file is only visible when the "mba_MBps" mount option is in use.

---
 arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 30 ++++++++++++++++++++++-
 arch/x86/kernel/cpu/resctrl/internal.h    |  2 +-
 arch/x86/kernel/cpu/resctrl/rdtgroup.c    | 10 +++++++-
 3 files changed, 42 insertions(+)
arch/x86/kernel/cpu/resctrl/ctrlmondata.c +30 -0
index 200d89a..5fa37b4 100644
@@ -518,6 +518,36 @@ static int smp_mon_event_count(void *arg)
 	return 0;
 }
 
+int rdtgroup_mba_mbps_event_show(struct kernfs_open_file *of,
+				 struct seq_file *s, void *v)
+{
+	struct rdtgroup *rdtgrp;
+	int ret = 0;
+
+	rdtgrp = rdtgroup_kn_lock_live(of->kn);
+
+	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 = -EINVAL;
+			break;
+		}
+	} else {
+		ret = -ENOENT;
+	}
+
+	rdtgroup_kn_unlock(of->kn);
+
+	return ret;
+}
+
 void mon_event_read(struct rmid_read *rr, struct rdt_resource *r,
 		    struct rdt_mon_domain *d, struct rdtgroup *rdtgrp,
 		    cpumask_t *cpumask, int evtid, int first)
arch/x86/kernel/cpu/resctrl/internal.h +2 -0
index 542d01c..1bd61ed 100644
@@ -610,6 +610,8 @@ ssize_t rdtgroup_schemata_write(struct kernfs_open_file *of,
 				char *buf, size_t nbytes, loff_t off);
 int rdtgroup_schemata_show(struct kernfs_open_file *of,
 			   struct seq_file *s, void *v);
+int rdtgroup_mba_mbps_event_show(struct kernfs_open_file *of,
+				 struct seq_file *s, void *v);
 bool rdtgroup_cbm_overlaps(struct resctrl_schema *s, struct rdt_ctrl_domain *d,
 			   unsigned long cbm, int closid, bool exclusive);
 unsigned int rdtgroup_cbm_to_size(struct rdt_resource *r, struct rdt_ctrl_domain *d,
arch/x86/kernel/cpu/resctrl/rdtgroup.c +10 -0
index 0659b8e..6eb930b 100644
@@ -1951,6 +1951,12 @@ static struct rftype res_common_files[] = {
 		.fflags		= RFTYPE_CTRL_BASE,
 	},
 	{
+		.name		= "mba_MBps_event",
+		.mode		= 0444,
+		.kf_ops		= &rdtgroup_kf_single_ops,
+		.seq_show	= rdtgroup_mba_mbps_event_show,
+	},
+	{
 		.name		= "mode",
 		.mode		= 0644,
 		.kf_ops		= &rdtgroup_kf_single_ops,
@@ -2355,6 +2361,7 @@ static int set_mba_sc(bool mba_sc)
 	struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_MBA].r_resctrl;
 	u32 num_closid = resctrl_arch_get_num_closid(r);
 	struct rdt_ctrl_domain *d;
+	unsigned long fflags;
 	int i;
 
 	if (!supports_mba_mbps() || mba_sc == is_mba_sc(r))
@@ -2369,6 +2376,9 @@ static int set_mba_sc(bool mba_sc)
 			d->mbps_val[i] = MBA_MAX_MBPS;
 	}
 
+	fflags = mba_sc ? RFTYPE_CTRL_BASE | RFTYPE_MON_BASE : 0;
+	resctrl_file_fflags_init("mba_MBps_event", fflags);
+
 	return 0;
 }
 
author maintainer
#22 lore raw

PATCH v11 7/8 x86/resctrl: Add write option to "mba_MBps_event" file

In reply to Tony Luck

The "mba_MBps" mount option provides an alternate method to control memory bandwidth. Instead of specifying allowable bandwidth as a percentage of maximum possible, the user provides a MiB/s limit value.

There is a file in each CTRL_MON group directory that shows the event currently in use.

Allow writing that file to choose a different event.

A user can choose any of the memory bandwidth monitoring events listed in /sys/fs/resctrl/info/L3_mon/mon_features independently for each CTRL_MON group by writing to each of the "mba_MBps_event" files.

---
 arch/x86/kernel/cpu/resctrl/internal.h    |  2 ++
 arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 40 +++++++++++++++++++++++
 arch/x86/kernel/cpu/resctrl/rdtgroup.c    |  3 +-
 3 files changed, 44 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/resctrl/internal.h +2 -0
index ce10a883ecf8..6345ab3e0890 100644
@@ -609,6 +609,8 @@ ssize_t rdtgroup_schemata_write(struct kernfs_open_file *of,
 				char *buf, size_t nbytes, loff_t off);
 int rdtgroup_schemata_show(struct kernfs_open_file *of,
 			   struct seq_file *s, void *v);
+ssize_t rdtgroup_mba_mbps_event_write(struct kernfs_open_file *of,
+				      char *buf, size_t nbytes, loff_t off);
 int rdtgroup_mba_mbps_event_show(struct kernfs_open_file *of,
 				 struct seq_file *s, void *v);
 bool rdtgroup_cbm_overlaps(struct resctrl_schema *s, struct rdt_ctrl_domain *d,
arch/x86/kernel/cpu/resctrl/ctrlmondata.c +40 -0
index 5fa37b4ecc7a..536351159cc2 100644
@@ -518,6 +518,46 @@ static int smp_mon_event_count(void *arg)
 	return 0;
 }
 
+ssize_t rdtgroup_mba_mbps_event_write(struct kernfs_open_file *of,
+				      char *buf, size_t nbytes, loff_t off)
+{
+	struct rdtgroup *rdtgrp;
+	int ret = 0;
+
+	/* Valid input requires a trailing newline */
+	if (nbytes == 0 || buf[nbytes - 1] != '\n')
+		return -EINVAL;
+	buf[nbytes - 1] = '\0';
+
+	rdtgrp = rdtgroup_kn_lock_live(of->kn);
+	if (!rdtgrp) {
+		rdtgroup_kn_unlock(of->kn);
+		return -ENOENT;
+	}
+	rdt_last_cmd_clear();
+
+	if (!strcmp(buf, "mbm_local_bytes")) {
+		if (is_mbm_local_enabled())
+			rdtgrp->mba_mbps_event = QOS_L3_MBM_LOCAL_EVENT_ID;
+		else
+			ret = -EINVAL;
+	} else if (!strcmp(buf, "mbm_total_bytes")) {
+		if (is_mbm_total_enabled())
+			rdtgrp->mba_mbps_event = QOS_L3_MBM_TOTAL_EVENT_ID;
+		else
+			ret = -EINVAL;
+	} else {
+		ret = -EINVAL;
+	}
+
+	if (ret)
+		rdt_last_cmd_printf("Unsupported event id '%s'\n", buf);
+
+	rdtgroup_kn_unlock(of->kn);
+
+	return ret ?: nbytes;
+}
+
 int rdtgroup_mba_mbps_event_show(struct kernfs_open_file *of,
 				 struct seq_file *s, void *v)
 {
arch/x86/kernel/cpu/resctrl/rdtgroup.c +2 -1
index 6eb930b8bdfd..6419e04d8a7b 100644
@@ -1952,8 +1952,9 @@ static struct rftype res_common_files[] = {
 	},
 	{
 		.name		= "mba_MBps_event",
-		.mode		= 0444,
+		.mode		= 0644,
 		.kf_ops		= &rdtgroup_kf_single_ops,
+		.write		= rdtgroup_mba_mbps_event_write,
 		.seq_show	= rdtgroup_mba_mbps_event_show,
 	},
 	{
Signature · 1 line
2.47.0
merge bot Applied
#23 lore raw

[tip: x86/cache] x86/resctrl: Add write option to "mba_MBps_event" file

The following commit has been merged into the x86/cache branch of tip:

The following commit has been merged into the x86/cache branch of tip:

Commit-ID:     8e931105acae688ff0fc8f875a6c05e5aed8ab79
Gitweb:        https://git.kernel.org/tip/8e931105acae688ff0fc8f875a6c05e5aed8ab79
Author:        Tony Luck <[email protected]>
AuthorDate:    Fri, 06 Dec 2024 08:31:47 -08:00
Committer:     Borislav Petkov (AMD) <[email protected]>
CommitterDate: Thu, 12 Dec 2024 11:27:37 +01:00

x86/resctrl: Add write option to "mba_MBps_event" file

The "mba_MBps" mount option provides an alternate method to control memory bandwidth. Instead of specifying allowable bandwidth as a percentage of maximum possible, the user provides a MiB/s limit value.

There is a file in each CTRL_MON group directory that shows the event currently in use.

Allow writing that file to choose a different event.

A user can choose any of the memory bandwidth monitoring events listed in /sys/fs/resctrl/info/L3_mon/mon_features independently for each CTRL_MON group by writing to each of the "mba_MBps_event" files.

---
 arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 40 ++++++++++++++++++++++-
 arch/x86/kernel/cpu/resctrl/internal.h    |  2 +-
 arch/x86/kernel/cpu/resctrl/rdtgroup.c    |  3 +-
 3 files changed, 44 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/resctrl/ctrlmondata.c +40 -0
index 5fa37b4..5363511 100644
@@ -518,6 +518,46 @@ static int smp_mon_event_count(void *arg)
 	return 0;
 }
 
+ssize_t rdtgroup_mba_mbps_event_write(struct kernfs_open_file *of,
+				      char *buf, size_t nbytes, loff_t off)
+{
+	struct rdtgroup *rdtgrp;
+	int ret = 0;
+
+	/* Valid input requires a trailing newline */
+	if (nbytes == 0 || buf[nbytes - 1] != '\n')
+		return -EINVAL;
+	buf[nbytes - 1] = '\0';
+
+	rdtgrp = rdtgroup_kn_lock_live(of->kn);
+	if (!rdtgrp) {
+		rdtgroup_kn_unlock(of->kn);
+		return -ENOENT;
+	}
+	rdt_last_cmd_clear();
+
+	if (!strcmp(buf, "mbm_local_bytes")) {
+		if (is_mbm_local_enabled())
+			rdtgrp->mba_mbps_event = QOS_L3_MBM_LOCAL_EVENT_ID;
+		else
+			ret = -EINVAL;
+	} else if (!strcmp(buf, "mbm_total_bytes")) {
+		if (is_mbm_total_enabled())
+			rdtgrp->mba_mbps_event = QOS_L3_MBM_TOTAL_EVENT_ID;
+		else
+			ret = -EINVAL;
+	} else {
+		ret = -EINVAL;
+	}
+
+	if (ret)
+		rdt_last_cmd_printf("Unsupported event id '%s'\n", buf);
+
+	rdtgroup_kn_unlock(of->kn);
+
+	return ret ?: nbytes;
+}
+
 int rdtgroup_mba_mbps_event_show(struct kernfs_open_file *of,
 				 struct seq_file *s, void *v)
 {
arch/x86/kernel/cpu/resctrl/internal.h +2 -0
index 1bd61ed..20c898f 100644
@@ -610,6 +610,8 @@ ssize_t rdtgroup_schemata_write(struct kernfs_open_file *of,
 				char *buf, size_t nbytes, loff_t off);
 int rdtgroup_schemata_show(struct kernfs_open_file *of,
 			   struct seq_file *s, void *v);
+ssize_t rdtgroup_mba_mbps_event_write(struct kernfs_open_file *of,
+				      char *buf, size_t nbytes, loff_t off);
 int rdtgroup_mba_mbps_event_show(struct kernfs_open_file *of,
 				 struct seq_file *s, void *v);
 bool rdtgroup_cbm_overlaps(struct resctrl_schema *s, struct rdt_ctrl_domain *d,
arch/x86/kernel/cpu/resctrl/rdtgroup.c +2 -1
index 6eb930b..6419e04 100644
@@ -1952,8 +1952,9 @@ static struct rftype res_common_files[] = {
 	},
 	{
 		.name		= "mba_MBps_event",
-		.mode		= 0444,
+		.mode		= 0644,
 		.kf_ops		= &rdtgroup_kf_single_ops,
+		.write		= rdtgroup_mba_mbps_event_write,
 		.seq_show	= rdtgroup_mba_mbps_event_show,
 	},
 	{
author maintainer
#24 lore raw

PATCH v11 8/8 x86/resctrl: Document the new "mba_MBps_event" file

In reply to Tony Luck

Add a section to document a new read/write file that shows/sets the memory bandwidth event used to control bandwidth used by each CTRL_MON group.

---
 Documentation/arch/x86/resctrl.rst | 10 ++++++++++
 1 file changed, 10 insertions(+)
Documentation/arch/x86/resctrl.rst +10 -0
index a824affd741d..6768fc1fad16 100644
@@ -384,6 +384,16 @@ When monitoring is enabled all MON groups will also contain:
 	Available only with debug option. The identifier used by hardware
 	for the monitor group. On x86 this is the RMID.
 
+When the "mba_MBps" mount option is used all CTRL_MON groups will also contain:
+
+"mba_MBps_event":
+	Reading this file shows which memory bandwidth event is used
+	as input to the software feedback loop that keeps memory bandwidth
+	below the value specified in the schemata file. Writing the
+	name of one of the supported memory bandwidth events found in
+	/sys/fs/resctrl/info/L3_MON/mon_features changes the input
+	event.
+
 Resource allocation rules
 -------------------------
 
Signature · 1 line
2.47.0
merge bot Applied
#25 lore raw

[tip: x86/cache] x86/resctrl: Document the new "mba_MBps_event" file

The following commit has been merged into the x86/cache branch of tip:

The following commit has been merged into the x86/cache branch of tip:

Commit-ID:     faf6ef673787956ec4d33ac8bf56f8ea929abf37
Gitweb:        https://git.kernel.org/tip/faf6ef673787956ec4d33ac8bf56f8ea929abf37
Author:        Tony Luck <[email protected]>
AuthorDate:    Fri, 06 Dec 2024 08:31:48 -08:00
Committer:     Borislav Petkov (AMD) <[email protected]>
CommitterDate: Thu, 12 Dec 2024 11:27:43 +01:00

x86/resctrl: Document the new "mba_MBps_event" file

Add a section to document a new read/write file that shows/sets the memory bandwidth event used to control bandwidth used by each CTRL_MON group.

---
 Documentation/arch/x86/resctrl.rst | 10 ++++++++++
 1 file changed, 10 insertions(+)
Documentation/arch/x86/resctrl.rst +10 -0
index a824aff..6768fc1 100644
@@ -384,6 +384,16 @@ When monitoring is enabled all MON groups will also contain:
 	Available only with debug option. The identifier used by hardware
 	for the monitor group. On x86 this is the RMID.
 
+When the "mba_MBps" mount option is used all CTRL_MON groups will also contain:
+
+"mba_MBps_event":
+	Reading this file shows which memory bandwidth event is used
+	as input to the software feedback loop that keeps memory bandwidth
+	below the value specified in the schemata file. Writing the
+	name of one of the supported memory bandwidth events found in
+	/sys/fs/resctrl/info/L3_MON/mon_features changes the input
+	event.
+
 Resource allocation rules
 -------------------------
 
maintainer
#26 lore raw
In reply to Tony Luck

Hi Boris,

Quoted 41 lines · Tony Luck

Background
----------

The resctrl filesystem supports a mount option that allows users to specify a memory bandwidth limit in MiB/s for each domain of a CTRL_MON group. The underlying implementation uses data collected from the local memory bandwidth monitoring event for the CTRL_MON group and all of its MON subgroups as input to a feedback loop that adjusts the memory bandwidth allocation control percentage up or down to keep the group within the limit set by the user.

Problem statement
-----------------

Hard coding the local memory bandwidth monitoring event has the following issues:

1) Some systems may support total memory bandwidth monitoring but not local. The user cannot use this mount option on such systems.

2) For large workloads that span NUMA domains using local bandwidth monitoring will not throttle jobs correctly.

3) Users may have a mix of large and small workloads and may want to use different input events per CTRL_MON group.

Solution
--------

A) Provide a new user interface to choose which event is used for each CTRL_MON group.

B) Allow systems that only support total memory bandwidth monitoring to use total bandwidth event.

Changes since v10:

Patch Change
----- ------

Quoted 7 lines

2 s/filesystm/filesystem/
Reformat block comment above definition of mba_mbps_default_event using more of 80 column width

3 s/Update_mba_bw()/update_mba_bw()

Added Reinette's Reviewed-by tag to parts 2-8

Could you please consider this series for inclusion?

Quoted 11 lines

N.B. v6.13-rc1 introduced a locking change in commit f1be1788a32e ("block:
model freeze & enter queue as lock for supporting lockdep") that throws a lockdep splat when mounting the resctrl filesystem (with certain CONFIG options).

Proposed patches that fix this are here:

This fix has been merged into v6.13-rc2.

Thank you very much.

Reinette

maintainer
#27 lore raw
Quoted 1 line · Reinette Chatre

Could you please consider this series for inclusion?

Lemme take a look...

Quoted 1 line

This fix has been merged into v6.13-rc2.

You mean, I should queue the set ontop of -rc2?

Thx.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
author maintainer
#28 lore raw
Quoted 7 lines
Quoted 1 line

Could you please consider this series for inclusion?

Lemme take a look...

Quoted 1 line

This fix has been merged into v6.13-rc2.

You mean, I should queue the set ontop of -rc2?

v6.13-rc1 may give a lockdep splat when mounting /sys/fs/resctrl (known CONFIG options to trigger this are:

	PROVE_LOCKING && SELINUX && (EXT4 || BTRFS)

but there may be others).

These resctrl patches are not directly dependent on the fixes that went into -rc2:

22465bbac53c blk-mq: move cpuhp callback registering out of q->sysfs_lock 4bf485a7db5d blk-mq: register cpuhp callback after hctx is added to xarray table

they work ok on top of -rc1 (as long as you ignore the lockdep splat).

I see you already have one patch in TIP x86/cache on top of v6.13-rc1

Your choice whether to rebase that to -rc2 and then apply my series. It might make testing smoother.

-Tony

maintainer
#29 lore raw
Quoted 7 lines · Tony

v6.13-rc1 may give a lockdep splat when mounting /sys/fs/resctrl (known CONFIG options to trigger this are:

	PROVE_LOCKING && SELINUX && (EXT4 || BTRFS)

but there may be others).

Quoted 7 lines

These resctrl patches are not directly dependent on the fixes that went into -rc2:

22465bbac53c blk-mq: move cpuhp callback registering out of q->sysfs_lock 4bf485a7db5d blk-mq: register cpuhp callback after hctx is added to xarray table

they work ok on top of -rc1 (as long as you ignore the lockdep splat).

Thanks for the details.

Quoted 4 lines

I see you already have one patch in TIP x86/cache on top of v6.13-rc1

Your choice whether to rebase that to -rc2 and then apply my series. It might make testing smoother.

Yah, I can rebase. Not worth the hassle of dealing with bogus reports.

Thx.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
reviewer Tested-by
#30 lore raw
Quoted 16 lines · Borislav Petkov
Quoted 7 lines · Tony

v6.13-rc1 may give a lockdep splat when mounting /sys/fs/resctrl (known CONFIG options to trigger this are:

	PROVE_LOCKING && SELINUX && (EXT4 || BTRFS)

but there may be others).

Quoted 7 lines

These resctrl patches are not directly dependent on the fixes that went into -rc2:

22465bbac53c blk-mq: move cpuhp callback registering out of q->sysfs_lock 4bf485a7db5d blk-mq: register cpuhp callback after hctx is added to xarray table

they work ok on top of -rc1 (as long as you ignore the lockdep splat).

Quoted 9 lines

Thanks for the details.

Quoted 4 lines

I see you already have one patch in TIP x86/cache on top of v6.13-rc1

Your choice whether to rebase that to -rc2 and then apply my series. It might make testing smoother.

Yah, I can rebase. Not worth the hassle of dealing with bogus reports.

Sanity tested on AMD system. Changes look good.

Signature · 2 lines
Thanks
Babu Moger