Skip to contentSkip to conversation

x86/resctrl: Make resctrl_arch_rmid_read() return values in bytes

PATCH Superseded James Morse 6 participants 49 messages Feb 17, 2022 – Apr 4, 2022

Subsystems (2)

v3 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

James Morse

author reviewer
#0 lore raw

v3 cover x86/resctrl: Make resctrl_arch_rmid_read() return values in bytes

Changes in this version? Expanded the commit message of patch 12, and made a few things static, as reported by the kbuild robot.

---
The aim of this series is to insert a split between the parts of the monitor code that the architecture must implement, and those that are part of the resctrl filesystem. The eventual aim is to move all filesystem parts out to live in /fs/resctrl, so that resctrl can be wired up for MPAM.

What's MPAM? See the cover letter of a previous series. [1]

The series adds domain online/offline callbacks to allow the filesystem to manage some of its structures itself, then moves all the 'mba_sc' behaviour to be part of the filesystem.
This means another architecture doesn't need to provide an mbps_val array. As its all software, the resctrl filesystem should be able to do this without any help from the architecture code.

Finally __rmid_read() is refactored to be the API call that the architecture provides to read a counter value. All the hardware specific overflow detection, scaling and value correction should occur behind this helper.

This series is based on v5.17-rc1, and can be retrieved from:
git://git.kernel.org/pub/scm/linux/kernel/git/morse/linux.git mpam/resctrl_monitors_in_bytes/v3

[0] git://git.kernel.org/pub/scm/linux/kernel/git/morse/linux.git mpam/resctrl_merge_cdp/v7
[1] https://lore.kernel.org/lkml/[email protected]/

[v1] https://lore.kernel.org/lkml/[email protected]/
[v2] https://lore.kernel.org/lkml/[email protected]/

Thanks,

James Morse (21):
x86/resctrl: Kill off alloc_enabled
x86/resctrl: Merge mon_capable and mon_enabled x86/resctrl: Add domain online callback for resctrl work x86/resctrl: Group struct rdt_hw_domain cleanup x86/resctrl: Add domain offline callback for resctrl work x86/resctrl: Remove set_mba_sc()s control array re-initialisation x86/resctrl: Create mba_sc configuration in the rdt_domain x86/resctrl: Switch over to the resctrl mbps_val list x86/resctrl: Remove architecture copy of mbps_val x86/resctrl: Abstract and use supports_mba_mbps() x86/resctrl: Allow update_mba_bw() to update controls directly x86/resctrl: Calculate bandwidth from the previous __mon_event_count()
chunks
x86/recstrl: Add per-rmid arch private storage for overflow and chunks x86/recstrl: Allow per-rmid arch private storage to be reset x86/resctrl: Abstract __rmid_read()
x86/resctrl: Pass the required parameters into
resctrl_arch_rmid_read()
x86/resctrl: Move mbm_overflow_count() into resctrl_arch_rmid_read() x86/resctrl: Move get_corrected_mbm_count() into
resctrl_arch_rmid_read()
x86/resctrl: Rename and change the units of resctrl_cqm_threshold x86/resctrl: Add resctrl_rmid_realloc_limit to abstract x86's
boot_cpu_data
x86/resctrl: Make resctrl_arch_rmid_read() return values in bytes

 arch/x86/kernel/cpu/resctrl/core.c        | 117 ++++--------
 arch/x86/kernel/cpu/resctrl/ctrlmondata.c |  75 +++++---
 arch/x86/kernel/cpu/resctrl/internal.h    |  61 +++----
 arch/x86/kernel/cpu/resctrl/monitor.c     | 211 ++++++++++++++--------
 arch/x86/kernel/cpu/resctrl/pseudo_lock.c |   2 +-
 arch/x86/kernel/cpu/resctrl/rdtgroup.c    | 205 +++++++++++++++++----
 include/linux/resctrl.h                   |  62 ++++++-
 7 files changed, 478 insertions(+), 255 deletions(-)
Signature · 1 line
2.30.2
author reviewer
#1 lore raw

PATCH v3 1/21 x86/resctrl: Kill off alloc_enabled

rdt_resources_all[] used to have extra entries for L2CODE/L2DATA. These were hidden from resctrl by the alloc_enabled value.

Now that the L2/L2CODE/L2DATA resources have been merged together, alloc_enabled doesn't mean anything, it always has the same value as alloc_capable which indicates which indicates allocation is supported by this resource.

Remove alloc_enabled and its helpers.

---
Changes since v1:
* Fixed comment in rdtgroup_create_info_dir()

---
 arch/x86/kernel/cpu/resctrl/core.c        | 4 ----
 arch/x86/kernel/cpu/resctrl/internal.h    | 4 ----
 arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 2 +-
 arch/x86/kernel/cpu/resctrl/rdtgroup.c    | 6 +++---
 include/linux/resctrl.h                   | 2 --
 5 files changed, 4 insertions(+), 14 deletions(-)
arch/x86/kernel/cpu/resctrl/core.c +0 -4
index bb1c3f5f60c8..2f87177f1f69 100644
@@ -147,7 +147,6 @@ static inline void cache_alloc_hsw_probe(void)
 	r->cache.shareable_bits = 0xc0000;
 	r->cache.min_cbm_bits = 2;
 	r->alloc_capable = true;
-	r->alloc_enabled = true;
 
 	rdt_alloc_capable = true;
 }
@@ -211,7 +210,6 @@ static bool __get_mem_config_intel(struct rdt_resource *r)
 	thread_throttle_mode_init();
 
 	r->alloc_capable = true;
-	r->alloc_enabled = true;
 
 	return true;
 }
@@ -242,7 +240,6 @@ static bool __rdt_get_mem_config_amd(struct rdt_resource *r)
 	r->data_width = 4;
 
 	r->alloc_capable = true;
-	r->alloc_enabled = true;
 
 	return true;
 }
@@ -261,7 +258,6 @@ static void rdt_get_cache_alloc_cfg(int idx, struct rdt_resource *r)
 	r->cache.shareable_bits = ebx & r->default_ctrl;
 	r->data_width = (r->cache.cbm_len + 3) / 4;
 	r->alloc_capable = true;
-	r->alloc_enabled = true;
 }
 
 static void rdt_get_cdp_config(int level)
arch/x86/kernel/cpu/resctrl/internal.h +0 -4
index 1d647188a43b..53f3d275a98f 100644
@@ -459,10 +459,6 @@ int resctrl_arch_set_cdp_enabled(enum resctrl_res_level l, bool enable);
 	for_each_rdt_resource(r)					      \
 		if (r->mon_capable)
 
-#define for_each_alloc_enabled_rdt_resource(r)				      \
-	for_each_rdt_resource(r)					      \
-		if (r->alloc_enabled)
-
 #define for_each_mon_enabled_rdt_resource(r)				      \
 	for_each_rdt_resource(r)					      \
 		if (r->mon_enabled)
arch/x86/kernel/cpu/resctrl/pseudo_lock.c +1 -1
index db813f819ad6..f810969ced4b 100644
@@ -835,7 +835,7 @@ bool rdtgroup_pseudo_locked_in_hierarchy(struct rdt_domain *d)
 	 * First determine which cpus have pseudo-locked regions
 	 * associated with them.
 	 */
-	for_each_alloc_enabled_rdt_resource(r) {
+	for_each_alloc_capable_rdt_resource(r) {
 		list_for_each_entry(d_i, &r->domains, list) {
 			if (d_i->plr)
 				cpumask_or(cpu_with_psl, cpu_with_psl,
arch/x86/kernel/cpu/resctrl/rdtgroup.c +3 -3
index b57b3db9a6a7..e327f8d1c8a3 100644
@@ -1756,7 +1756,7 @@ static int rdtgroup_create_info_dir(struct kernfs_node *parent_kn)
 	if (ret)
 		goto out_destroy;
 
-	/* loop over enabled controls, these are all alloc_enabled */
+	/* loop over enabled controls, these are all alloc_capable */
 	list_for_each_entry(s, &resctrl_schema_all, list) {
 		r = s->res;
 		fflags =  r->fflags | RF_CTRL_INFO;
@@ -2106,7 +2106,7 @@ static int schemata_list_create(void)
 	struct rdt_resource *r;
 	int ret = 0;
 
-	for_each_alloc_enabled_rdt_resource(r) {
+	for_each_alloc_capable_rdt_resource(r) {
 		if (resctrl_arch_get_cdp_enabled(r->rid)) {
 			ret = schemata_list_add(r, CDP_CODE);
 			if (ret)
@@ -2452,7 +2452,7 @@ static void rdt_kill_sb(struct super_block *sb)
 	set_mba_sc(false);
 
 	/*Put everything back to default values. */
-	for_each_alloc_enabled_rdt_resource(r)
+	for_each_alloc_capable_rdt_resource(r)
 		reset_all_ctrls(r);
 	cdp_disable_all();
 	rmdir_all_sub();
include/linux/resctrl.h +0 -2
index 21deb5212bbd..386ab3a41500 100644
@@ -130,7 +130,6 @@ struct resctrl_schema;
 /**
  * struct rdt_resource - attributes of a resctrl resource
  * @rid:		The index of the resource
- * @alloc_enabled:	Is allocation enabled on this machine
  * @mon_enabled:	Is monitoring enabled for this feature
  * @alloc_capable:	Is allocation available on this machine
  * @mon_capable:	Is monitor feature available on this machine
@@ -150,7 +149,6 @@ struct resctrl_schema;
  */
 struct rdt_resource {
 	int			rid;
-	bool			alloc_enabled;
 	bool			mon_enabled;
 	bool			alloc_capable;
 	bool			mon_capable;
Signature · 1 line
2.30.2
maintainer
#2 lore raw

Re: [PATCH v3 01/21] x86/resctrl: Kill off alloc_enabled

Hi James,

Quoted 7 lines · James Morse

rdt_resources_all[] used to have extra entries for L2CODE/L2DATA. These were hidden from resctrl by the alloc_enabled value.

Now that the L2/L2CODE/L2DATA resources have been merged together, alloc_enabled doesn't mean anything, it always has the same value as alloc_capable which indicates which indicates allocation is supported by this resource.

"which indicates which indicates" -> "which indicates"

Reinette

author reviewer
#3 lore raw

PATCH v3 2/21 x86/resctrl: Merge mon_capable and mon_enabled

In reply to James Morse

mon_enabled and mon_capable are always set as a pair by rdt_get_mon_l3_config().

There is no point having two values.

Merge them together.

---
Changes since v1:
* Removed stray cdp_capable changes.

---
 arch/x86/kernel/cpu/resctrl/internal.h | 4 ----
 arch/x86/kernel/cpu/resctrl/monitor.c  | 1 -
 arch/x86/kernel/cpu/resctrl/rdtgroup.c | 8 ++++----
 include/linux/resctrl.h                | 2 --
 4 files changed, 4 insertions(+), 11 deletions(-)
arch/x86/kernel/cpu/resctrl/internal.h +0 -4
index 53f3d275a98f..8828b5c1b6d2 100644
@@ -459,10 +459,6 @@ int resctrl_arch_set_cdp_enabled(enum resctrl_res_level l, bool enable);
 	for_each_rdt_resource(r)					      \
 		if (r->mon_capable)
 
-#define for_each_mon_enabled_rdt_resource(r)				      \
-	for_each_rdt_resource(r)					      \
-		if (r->mon_enabled)
-
 /* CPUID.(EAX=10H, ECX=ResID=1).EAX */
 union cpuid_0x10_1_eax {
 	struct {
arch/x86/kernel/cpu/resctrl/monitor.c +0 -1
index eaf25a234ff5..497cadf3285d 100644
@@ -717,7 +717,6 @@ int rdt_get_mon_l3_config(struct rdt_resource *r)
 	l3_mon_evt_init(r);
 
 	r->mon_capable = true;
-	r->mon_enabled = true;
 
 	return 0;
 }
arch/x86/kernel/cpu/resctrl/rdtgroup.c +4 -4
index e327f8d1c8a3..e243c7d15b81 100644
@@ -1765,7 +1765,7 @@ static int rdtgroup_create_info_dir(struct kernfs_node *parent_kn)
 			goto out_destroy;
 	}
 
-	for_each_mon_enabled_rdt_resource(r) {
+	for_each_mon_capable_rdt_resource(r) {
 		fflags =  r->fflags | RF_MON_INFO;
 		sprintf(name, "%s_MON", r->name);
 		ret = rdtgroup_mkdir_info_resdir(r, name, fflags);
@@ -2504,7 +2504,7 @@ void rmdir_mondata_subdir_allrdtgrp(struct rdt_resource *r, unsigned int dom_id)
 	struct rdtgroup *prgrp, *crgrp;
 	char name[32];
 
-	if (!r->mon_enabled)
+	if (!r->mon_capable)
 		return;
 
 	list_for_each_entry(prgrp, &rdt_all_groups, rdtgroup_list) {
@@ -2572,7 +2572,7 @@ void mkdir_mondata_subdir_allrdtgrp(struct rdt_resource *r,
 	struct rdtgroup *prgrp, *crgrp;
 	struct list_head *head;
 
-	if (!r->mon_enabled)
+	if (!r->mon_capable)
 		return;
 
 	list_for_each_entry(prgrp, &rdt_all_groups, rdtgroup_list) {
@@ -2642,7 +2642,7 @@ static int mkdir_mondata_all(struct kernfs_node *parent_kn,
 	 * Create the subdirectories for each domain. Note that all events
 	 * in a domain like L3 are grouped into a resource whose domain is L3
 	 */
-	for_each_mon_enabled_rdt_resource(r) {
+	for_each_mon_capable_rdt_resource(r) {
 		ret = mkdir_mondata_subdir_alldom(kn, r, prgrp);
 		if (ret)
 			goto out_destroy;
include/linux/resctrl.h +0 -2
index 386ab3a41500..8180c539800d 100644
@@ -130,7 +130,6 @@ struct resctrl_schema;
 /**
  * struct rdt_resource - attributes of a resctrl resource
  * @rid:		The index of the resource
- * @mon_enabled:	Is monitoring enabled for this feature
  * @alloc_capable:	Is allocation available on this machine
  * @mon_capable:	Is monitor feature available on this machine
  * @num_rmid:		Number of RMIDs available
@@ -149,7 +148,6 @@ struct resctrl_schema;
  */
 struct rdt_resource {
 	int			rid;
-	bool			mon_enabled;
 	bool			alloc_capable;
 	bool			mon_capable;
 	int			num_rmid;
Signature · 1 line
2.30.2
author reviewer
#4 lore raw

PATCH v3 3/21 x86/resctrl: Add domain online callback for resctrl work

In reply to James Morse

Because domains are exposed to user-space via resctrl, the filesystem must update its state when CPU hotplug callbacks are triggered.

Some of this work is common to any architecture that would support resctrl, but the work is tied up with the architecture code to allocate the memory.

Move domain_setup_mon_state(), the monitor subdir creation call and the mbm/limbo workers into a new resctrl_online_domain() call. These bits are not specific to the architecture. Grouping them in one function allows that code to be moved to /fs/ and re-used by another architecture.

---
Changes since v2:
* Fixed kfree(d) rebase artefact.

Changes since v1:
* Capitalisation
* Removed inline comment
* Added to the commit message

---
 arch/x86/kernel/cpu/resctrl/core.c     | 57 ++++------------------
 arch/x86/kernel/cpu/resctrl/internal.h |  2 -
 arch/x86/kernel/cpu/resctrl/rdtgroup.c | 65 ++++++++++++++++++++++++--
 include/linux/resctrl.h                |  1 +
 4 files changed, 69 insertions(+), 56 deletions(-)
arch/x86/kernel/cpu/resctrl/core.c +8 -49
index 2f87177f1f69..25f30148478b 100644
@@ -443,42 +443,6 @@ static int domain_setup_ctrlval(struct rdt_resource *r, struct rdt_domain *d)
 	return 0;
 }
 
-static int domain_setup_mon_state(struct rdt_resource *r, struct rdt_domain *d)
-{
-	size_t tsize;
-
-	if (is_llc_occupancy_enabled()) {
-		d->rmid_busy_llc = bitmap_zalloc(r->num_rmid, GFP_KERNEL);
-		if (!d->rmid_busy_llc)
-			return -ENOMEM;
-		INIT_DELAYED_WORK(&d->cqm_limbo, cqm_handle_limbo);
-	}
-	if (is_mbm_total_enabled()) {
-		tsize = sizeof(*d->mbm_total);
-		d->mbm_total = kcalloc(r->num_rmid, tsize, GFP_KERNEL);
-		if (!d->mbm_total) {
-			bitmap_free(d->rmid_busy_llc);
-			return -ENOMEM;
-		}
-	}
-	if (is_mbm_local_enabled()) {
-		tsize = sizeof(*d->mbm_local);
-		d->mbm_local = kcalloc(r->num_rmid, tsize, GFP_KERNEL);
-		if (!d->mbm_local) {
-			bitmap_free(d->rmid_busy_llc);
-			kfree(d->mbm_total);
-			return -ENOMEM;
-		}
-	}
-
-	if (is_mbm_enabled()) {
-		INIT_DELAYED_WORK(&d->mbm_over, mbm_handle_overflow);
-		mbm_setup_overflow_handler(d, MBM_OVERFLOW_INTERVAL);
-	}
-
-	return 0;
-}
-
 /*
  * domain_add_cpu - Add a cpu to a resource's domain list.
  *
@@ -498,6 +462,7 @@ static void domain_add_cpu(int cpu, struct rdt_resource *r)
 	struct list_head *add_pos = NULL;
 	struct rdt_hw_domain *hw_dom;
 	struct rdt_domain *d;
+	int err;
 
 	d = rdt_find_domain(r, id, &add_pos);
 	if (IS_ERR(d)) {
@@ -527,21 +492,15 @@ static void domain_add_cpu(int cpu, struct rdt_resource *r)
 		return;
 	}
 
-	if (r->mon_capable && domain_setup_mon_state(r, d)) {
-		kfree(hw_dom->ctrl_val);
-		kfree(hw_dom->mbps_val);
-		kfree(hw_dom);
-		return;
-	}
-
 	list_add_tail(&d->list, add_pos);
 
-	/*
-	 * If resctrl is mounted, add
-	 * per domain monitor data directories.
-	 */
-	if (static_branch_unlikely(&rdt_mon_enable_key))
-		mkdir_mondata_subdir_allrdtgrp(r, d);
+	err = resctrl_online_domain(r, d);
+	if (err) {
+		list_del(&d->list);
+		kfree(hw_dom->ctrl_val);
+		kfree(hw_dom->mbps_val);
+		kfree(hw_dom);
+	}
 }
 
 static void domain_remove_cpu(int cpu, struct rdt_resource *r)
arch/x86/kernel/cpu/resctrl/internal.h +0 -2
index 8828b5c1b6d2..be48a682dbdb 100644
@@ -524,8 +524,6 @@ void mon_event_count(void *info);
 int rdtgroup_mondata_show(struct seq_file *m, void *arg);
 void rmdir_mondata_subdir_allrdtgrp(struct rdt_resource *r,
 				    unsigned int dom_id);
-void mkdir_mondata_subdir_allrdtgrp(struct rdt_resource *r,
-				    struct rdt_domain *d);
 void mon_event_read(struct rmid_read *rr, struct rdt_resource *r,
 		    struct rdt_domain *d, struct rdtgroup *rdtgrp,
 		    int evtid, int first);
arch/x86/kernel/cpu/resctrl/rdtgroup.c +60 -5

82 lines not on this page · raw message

include/linux/resctrl.h +1 -0
index 8180c539800d..d512455b4c3a 100644
@@ -192,5 +192,6 @@ u32 resctrl_arch_get_num_closid(struct rdt_resource *r);
 int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid);
 u32 resctrl_arch_get_config(struct rdt_resource *r, struct rdt_domain *d,
 			    u32 closid, enum resctrl_conf_type type);
+int resctrl_online_domain(struct rdt_resource *r, struct rdt_domain *d);
 
 #endif /* _RESCTRL_H */
Signature · 1 line
2.30.2
author reviewer
#5 lore raw

PATCH v3 4/21 x86/resctrl: Group struct rdt_hw_domain cleanup

In reply to James Morse

domain_add_cpu() and domain_remove_cpu() need to kfree() the child arrays that were allocated by domain_setup_ctrlval().

As this memory is moved around, and new arrays are created, adjusting the error handling cleanup code becomes noisier.

To simplify this, move all the kfree() calls into a domain_free() helper. This depends on struct rdt_hw_domain being kzalloc()d, allowing it to unconditionally kfree() all the child arrays.

---
Changes since v2:
* Made domain_free() static.

Changes since v1:
* This patch is new

---
 arch/x86/kernel/cpu/resctrl/core.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)
arch/x86/kernel/cpu/resctrl/core.c +10 -7
index 25f30148478b..e37889f7a1a5 100644
@@ -414,6 +414,13 @@ void setup_default_ctrlval(struct rdt_resource *r, u32 *dc, u32 *dm)
 	}
 }
 
+static void domain_free(struct rdt_hw_domain *hw_dom)
+{
+	kfree(hw_dom->ctrl_val);
+	kfree(hw_dom->mbps_val);
+	kfree(hw_dom);
+}
+
 static int domain_setup_ctrlval(struct rdt_resource *r, struct rdt_domain *d)
 {
 	struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r);
@@ -488,7 +495,7 @@ static void domain_add_cpu(int cpu, struct rdt_resource *r)
 	rdt_domain_reconfigure_cdp(r);
 
 	if (r->alloc_capable && domain_setup_ctrlval(r, d)) {
-		kfree(hw_dom);
+		domain_free(hw_dom);
 		return;
 	}
 
@@ -497,9 +504,7 @@ static void domain_add_cpu(int cpu, struct rdt_resource *r)
 	err = resctrl_online_domain(r, d);
 	if (err) {
 		list_del(&d->list);
-		kfree(hw_dom->ctrl_val);
-		kfree(hw_dom->mbps_val);
-		kfree(hw_dom);
+		domain_free(hw_dom);
 	}
 }
 
@@ -547,12 +552,10 @@ static void domain_remove_cpu(int cpu, struct rdt_resource *r)
 		if (d->plr)
 			d->plr->d = NULL;
 
-		kfree(hw_dom->ctrl_val);
-		kfree(hw_dom->mbps_val);
 		bitmap_free(d->rmid_busy_llc);
 		kfree(d->mbm_total);
 		kfree(d->mbm_local);
-		kfree(hw_dom);
+		domain_free(hw_dom);
 		return;
 	}
 
Signature · 1 line
2.30.2
author reviewer
#6 lore raw

PATCH v3 5/21 x86/resctrl: Add domain offline callback for resctrl work

In reply to James Morse

Because domains are exposed to user-space via resctrl, the filesystem must update its state when CPU hotplug callbacks are triggered.

Some of this work is common to any architecture that would support resctrl, but the work is tied up with the architecture code to free the memory.

Move the monitor subdir removal and the cancelling of the mbm/limbo works into a new resctrl_offline_domain() call. These bits are not specific to the architecture. Grouping them in one function allows that code to be moved to /fs/ and re-used by another architecture.

---
Changes since v2:
* Moved kfree()ing to domain_destroy_mon_state() for later re-use.

Changes since v1:
* Removed a redundant mon_capable check
* Capitalisation
* Removed inline comment
* Added to the commit message

---
 arch/x86/kernel/cpu/resctrl/core.c     | 26 ++-------------
 arch/x86/kernel/cpu/resctrl/internal.h |  2 --
 arch/x86/kernel/cpu/resctrl/rdtgroup.c | 45 +++++++++++++++++++++++---
 include/linux/resctrl.h                |  1 +
 4 files changed, 44 insertions(+), 30 deletions(-)
arch/x86/kernel/cpu/resctrl/core.c +2 -24
index e37889f7a1a5..f69182973175 100644
@@ -523,27 +523,8 @@ static void domain_remove_cpu(int cpu, struct rdt_resource *r)
 
 	cpumask_clear_cpu(cpu, &d->cpu_mask);
 	if (cpumask_empty(&d->cpu_mask)) {
-		/*
-		 * If resctrl is mounted, remove all the
-		 * per domain monitor data directories.
-		 */
-		if (static_branch_unlikely(&rdt_mon_enable_key))
-			rmdir_mondata_subdir_allrdtgrp(r, d->id);
+		resctrl_offline_domain(r, d);
 		list_del(&d->list);
-		if (r->mon_capable && is_mbm_enabled())
-			cancel_delayed_work(&d->mbm_over);
-		if (is_llc_occupancy_enabled() &&  has_busy_rmid(r, d)) {
-			/*
-			 * When a package is going down, forcefully
-			 * decrement rmid->ebusy. There is no way to know
-			 * that the L3 was flushed and hence may lead to
-			 * incorrect counts in rare scenarios, but leaving
-			 * the RMID as busy creates RMID leaks if the
-			 * package never comes back.
-			 */
-			__check_limbo(d, true);
-			cancel_delayed_work(&d->cqm_limbo);
-		}
 
 		/*
 		 * rdt_domain "d" is going to be freed below, so clear
@@ -551,11 +532,8 @@ static void domain_remove_cpu(int cpu, struct rdt_resource *r)
 		 */
 		if (d->plr)
 			d->plr->d = NULL;
-
-		bitmap_free(d->rmid_busy_llc);
-		kfree(d->mbm_total);
-		kfree(d->mbm_local);
 		domain_free(hw_dom);
+
 		return;
 	}
 
arch/x86/kernel/cpu/resctrl/internal.h +0 -2
index be48a682dbdb..e12b55f815bf 100644
@@ -522,8 +522,6 @@ void free_rmid(u32 rmid);
 int rdt_get_mon_l3_config(struct rdt_resource *r);
 void mon_event_count(void *info);
 int rdtgroup_mondata_show(struct seq_file *m, void *arg);
-void rmdir_mondata_subdir_allrdtgrp(struct rdt_resource *r,
-				    unsigned int dom_id);
 void mon_event_read(struct rmid_read *rr, struct rdt_resource *r,
 		    struct rdt_domain *d, struct rdtgroup *rdtgrp,
 		    int evtid, int first);
arch/x86/kernel/cpu/resctrl/rdtgroup.c +41 -4

61 lines not on this page · raw message

include/linux/resctrl.h +1 -0
index d512455b4c3a..5d283bdd6162 100644
@@ -193,5 +193,6 @@ int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid);
 u32 resctrl_arch_get_config(struct rdt_resource *r, struct rdt_domain *d,
 			    u32 closid, enum resctrl_conf_type type);
 int resctrl_online_domain(struct rdt_resource *r, struct rdt_domain *d);
+void resctrl_offline_domain(struct rdt_resource *r, struct rdt_domain *d);
 
 #endif /* _RESCTRL_H */
Signature · 1 line
2.30.2
author reviewer
#7 lore raw

PATCH v3 6/21 x86/resctrl: Remove set_mba_sc()s control array re-initialisation

In reply to James Morse

set_mba_sc() enables the 'software controller' to regulate the bandwidth based on the byte counters. This can be managed entirely in the parts of resctrl that move to /fs/, without any extra support from the architecture specific code.
set_mba_sc() is called by rdt_enable_ctx() during mount and umount. It currently resets the arch code's ctrl_val[] and mbps_val[] arrays.

The ctrl_val[] was already reset when the domain was created, and by reset_all_ctrls() when the filesystem was last umounted. Doing the work in set_mba_sc() is not necessary as the values are already at their defaults due to the creation of the domain, or were previsouly reset during umount(), or are about to reset during umount().

Add a reset of the mbps_val[] in reset_all_ctrls(), allowing the code in set_mba_sc() that reaches in to the architecture specific structures to be removed.

Changes since v2:
* Moved earlier in the series, added the reset in reset_all_ctrls().
* Rephrased commit message.

---
 arch/x86/kernel/cpu/resctrl/rdtgroup.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
arch/x86/kernel/cpu/resctrl/rdtgroup.c +3 -7
index 281b38b363c2..794a84ba9097 100644
@@ -1898,18 +1898,12 @@ void rdt_domain_reconfigure_cdp(struct rdt_resource *r)
 static int set_mba_sc(bool mba_sc)
 {
 	struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_MBA].r_resctrl;
-	struct rdt_hw_domain *hw_dom;
-	struct rdt_domain *d;
 
 	if (!is_mbm_enabled() || !is_mba_linear() ||
 	    mba_sc == is_mba_sc(r))
 		return -EINVAL;
 
 	r->membw.mba_sc = mba_sc;
-	list_for_each_entry(d, &r->domains, list) {
-		hw_dom = resctrl_to_arch_dom(d);
-		setup_default_ctrlval(r, hw_dom->ctrl_val, hw_dom->mbps_val);
-	}
 
 	return 0;
 }
@@ -2327,8 +2321,10 @@ static int reset_all_ctrls(struct rdt_resource *r)
 		hw_dom = resctrl_to_arch_dom(d);
 		cpumask_set_cpu(cpumask_any(&d->cpu_mask), cpu_mask);
 
-		for (i = 0; i < hw_res->num_closid; i++)
+		for (i = 0; i < hw_res->num_closid; i++) {
 			hw_dom->ctrl_val[i] = r->default_ctrl;
+			hw_dom->mbps_val[i] = MBA_MAX_MBPS;
+		}
 	}
 	cpu = get_cpu();
 	/* Update CBM on this cpu if it's in cpu_mask. */
Signature · 1 line
2.30.2
author reviewer
#8 lore raw

PATCH v3 7/21 x86/resctrl: Create mba_sc configuration in the rdt_domain

In reply to James Morse

To support resctrl's MBA software controller, the architecture must provide a second configuration array to hold the mbps_val[] from user-space.

This complicates the interface between the architecture specific code and the filesystem portions of resctrl that will move to /fs/, to allow multiple architectures to support resctrl.

Make the filesystem parts of resctrl create an array for the mba_sc values when is_mba_sc() is set to true. The software controller can be changed to use this, allowing the architecture code to only consider the values configured in hardware.

---
Changes since v2:
* Split patch in two, the liftime parts are a separate patch.
* Added reset in set_mba_sc() now that we can't depend on the lifetime.
* Initialise ret in mba_sc_allocate(),
* Made mbps_val allocation/freeing symmetric for cpuhp calls.
* Removed reference to squashed-out struct.
* Preserved kerneldoc for mbps_val.

Changes since v1:
* Added missing error handling to mba_sc_domain_allocate() in domain_setup_mon_state()
* Added comment about mba_sc_domain_allocate() races
* Squashed out struct resctrl_mba_sc
* Moved mount time alloc/free calls to set_mba_sc().
* Removed mount check in resctrl_offline_domain()
* Reword commit message

---
 arch/x86/kernel/cpu/resctrl/internal.h |  1 -
 arch/x86/kernel/cpu/resctrl/rdtgroup.c | 41 ++++++++++++++++++++++++++
 include/linux/resctrl.h                |  7 +++++
 3 files changed, 48 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/resctrl/internal.h +0 -1
index e12b55f815bf..a7e2cbce29d5 100644
@@ -36,7 +36,6 @@
 #define MBM_OVERFLOW_INTERVAL		1000
 #define MAX_MBA_BW			100u
 #define MBA_IS_LINEAR			0x4
-#define MBA_MAX_MBPS			U32_MAX
 #define MAX_MBA_BW_AMD			0x800
 #define MBM_CNTR_WIDTH_OFFSET_AMD	20
 
arch/x86/kernel/cpu/resctrl/rdtgroup.c +41 -0

71 lines not on this page · raw message

include/linux/resctrl.h +7 -0
index 5d283bdd6162..46ab9fb5562e 100644
@@ -15,6 +15,9 @@ int proc_resctrl_show(struct seq_file *m,
 
 #endif
 
+/* max value for struct rdt_domain's mbps_val */
+#define MBA_MAX_MBPS   U32_MAX
+
 /**
  * enum resctrl_conf_type - The type of configuration.
  * @CDP_NONE:	No prioritisation, both code and data are controlled or monitored.
@@ -53,6 +56,9 @@ struct resctrl_staged_config {
  * @cqm_work_cpu:	worker CPU for CQM h/w counters
  * @plr:		pseudo-locked region (if any) associated with domain
  * @staged_config:	parsed configuration to be applied
+ * @mbps_val:		When mba_sc is enabled, this holds the array of user
+ * 			specified control values for mba_sc in MBps, indexed
+ *			by closid
  */
 struct rdt_domain {
 	struct list_head		list;
@@ -67,6 +73,7 @@ struct rdt_domain {
 	int				cqm_work_cpu;
 	struct pseudo_lock_region	*plr;
 	struct resctrl_staged_config	staged_config[CDP_NUM_TYPES];
+	u32				*mbps_val;
 };
 
 /**
Signature · 1 line
2.30.2
maintainer
#9 lore raw

Re: [PATCH v3 07/21] x86/resctrl: Create mba_sc configuration in the rdt_domain

Hi James,

Quoted 80 lines · James Morse

To support resctrl's MBA software controller, the architecture must provide a second configuration array to hold the mbps_val[] from user-space.

This complicates the interface between the architecture specific code and the filesystem portions of resctrl that will move to /fs/, to allow multiple architectures to support resctrl.

Make the filesystem parts of resctrl create an array for the mba_sc values when is_mba_sc() is set to true. The software controller can be changed to use this, allowing the architecture code to only consider the values configured in hardware.

---
Changes since v2:
* Split patch in two, the liftime parts are a separate patch.
* Added reset in set_mba_sc() now that we can't depend on the lifetime.
* Initialise ret in mba_sc_allocate(),
* Made mbps_val allocation/freeing symmetric for cpuhp calls.
* Removed reference to squashed-out struct.
* Preserved kerneldoc for mbps_val.

Changes since v1:
* Added missing error handling to mba_sc_domain_allocate() in domain_setup_mon_state()
* Added comment about mba_sc_domain_allocate() races
* Squashed out struct resctrl_mba_sc
* Moved mount time alloc/free calls to set_mba_sc().
* Removed mount check in resctrl_offline_domain()
* Reword commit message

---
 arch/x86/kernel/cpu/resctrl/internal.h |  1 -
 arch/x86/kernel/cpu/resctrl/rdtgroup.c | 41 ++++++++++++++++++++++++++
 include/linux/resctrl.h                |  7 +++++
 3 files changed, 48 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/resctrl/internal.h +0 -1
index e12b55f815bf..a7e2cbce29d5 100644
@@ -36,7 +36,6 @@
 #define MBM_OVERFLOW_INTERVAL		1000
 #define MAX_MBA_BW			100u
 #define MBA_IS_LINEAR			0x4
-#define MBA_MAX_MBPS			U32_MAX
 #define MAX_MBA_BW_AMD			0x800
 #define MBM_CNTR_WIDTH_OFFSET_AMD	20
 
arch/x86/kernel/cpu/resctrl/rdtgroup.c +24 -0
index 794a84ba9097..e4313f907eb6 100644
@@ -1889,6 +1889,30 @@ void rdt_domain_reconfigure_cdp(struct rdt_resource *r)
 		l3_qos_cfg_update(&hw_res->cdp_enabled);
 }
 
+static int mba_sc_domain_allocate(struct rdt_resource *r, struct rdt_domain *d)
+{
+	u32 num_closid = resctrl_arch_get_num_closid(r);
+	int cpu = cpumask_any(&d->cpu_mask);
+	int i;
+
+	d->mbps_val = kcalloc_node(num_closid, sizeof(*d->mbps_val),
+				   GFP_KERNEL, cpu_to_node(cpu));
+	if (!d->mbps_val)
+		return -ENOMEM;
+
+	for (i = 0; i < num_closid; i++)
+		d->mbps_val[i] = MBA_MAX_MBPS;
+
+	return 0;
+}
+
+static void mba_sc_domain_destroy(struct rdt_resource *r,
+				  struct rdt_domain *d)
+{
+	kfree(d->mbps_val);
+	d->mbps_val = NULL;
+}
+

...

Quoted 11 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +3 -0
@@ -3263,6 +3295,9 @@ void resctrl_offline_domain(struct rdt_resource *r, struct rdt_domain *d)
 		cancel_delayed_work(&d->cqm_limbo);
 	}
 
+	if (is_mba_sc(r))
+		mba_sc_domain_destroy(r, d);
+
 	domain_destroy_mon_state(d);
 }
 

arch/x86/kernel/cpu/resctrl/rdtgroup.c int resctrl_online_domain(struct rdt_resource *r, struct rdt_domain *d) · line 3352

Quoted 9 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +6 -0
@@ -3309,6 +3344,12 @@ int resctrl_online_domain(struct rdt_resource *r, struct rdt_domain *d)
 	if (err)
 		return err;
 
+	err = mba_sc_domain_allocate(r, d);
+	if (err) {
+		domain_destroy_mon_state(d);
+		return err;
+	}
+

Thank you for making this all symmetrical. It seems as though the new array is always created but only destroyed when is_mba_sc() is true. Is this correct?

Reinette

author reviewer
#10 lore raw

Re: [PATCH v3 07/21] x86/resctrl: Create mba_sc configuration in the rdt_domain

Hi Reinette,

Quoted 12 lines · Reinette Chatre
Quoted 11 lines · James Morse

To support resctrl's MBA software controller, the architecture must provide a second configuration array to hold the mbps_val[] from user-space.

This complicates the interface between the architecture specific code and the filesystem portions of resctrl that will move to /fs/, to allow multiple architectures to support resctrl.

Make the filesystem parts of resctrl create an array for the mba_sc values when is_mba_sc() is set to true. The software controller can be changed to use this, allowing the architecture code to only consider the values configured in hardware.

...

Quoted 14 lines
Quoted 14 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +3 -0
@@ -3263,6 +3295,9 @@ void resctrl_offline_domain(struct rdt_resource *r, struct rdt_domain *d)
 		cancel_delayed_work(&d->cqm_limbo);
 	}
 
+	if (is_mba_sc(r))
+		mba_sc_domain_destroy(r, d);
+
 	domain_destroy_mon_state(d);
 }
 
@@ -3309,6 +3344,12 @@ int resctrl_online_domain(struct rdt_resource *r, struct rdt_domain *d)
 	if (err)
 		return err;
 
Quoted 10 lines

arch/x86/kernel/cpu/resctrl/rdtgroup.c int resctrl_online_domain(struct rdt_resource *r, struct rdt_domain *d) · line 3352

Quoted 6 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +6 -0
+	err = mba_sc_domain_allocate(r, d);
+	if (err) {
+		domain_destroy_mon_state(d);
+		return err;
+	}
+

Thank you for making this all symmetrical. It seems as though the new array is always created but only destroyed when is_mba_sc() is true. Is this correct?

That looks broken. Oops.

I'll fix it to always allocate the array, as that is what domain_setup_ctrlval() does today, and it saves the hotplug headache.

Thanks,

James

maintainer
#11 lore raw

Re: [PATCH v3 07/21] x86/resctrl: Create mba_sc configuration in the rdt_domain

In reply to James Morse

Hi James,

I tried out this work and encountered a null pointer de-reference that seems related to this patch. After digging into that it is not clear to me how this is expected to work.

I encounter the issue just by attempting to mount with "-o mba_MBps" which is the way to enable the mba_sc and exactly what this patch aims to address.

More below ...

Quoted 14 lines · James Morse

To support resctrl's MBA software controller, the architecture must provide a second configuration array to hold the mbps_val[] from user-space.

This complicates the interface between the architecture specific code and the filesystem portions of resctrl that will move to /fs/, to allow multiple architectures to support resctrl.

Make the filesystem parts of resctrl create an array for the mba_sc values when is_mba_sc() is set to true. The software controller can be changed to use this, allowing the architecture code to only consider the values configured in hardware.

---

...

Quoted 26 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +17 -0
index 794a84ba9097..e4313f907eb6 100644
@@ -1889,6 +1889,30 @@ void rdt_domain_reconfigure_cdp(struct rdt_resource *r)
 		l3_qos_cfg_update(&hw_res->cdp_enabled);
 }
 
+static int mba_sc_domain_allocate(struct rdt_resource *r, struct rdt_domain *d)
+{
+	u32 num_closid = resctrl_arch_get_num_closid(r);
+	int cpu = cpumask_any(&d->cpu_mask);
+	int i;
+
+	d->mbps_val = kcalloc_node(num_closid, sizeof(*d->mbps_val),
+				   GFP_KERNEL, cpu_to_node(cpu));
+	if (!d->mbps_val)
+		return -ENOMEM;
+
+	for (i = 0; i < num_closid; i++)
+		d->mbps_val[i] = MBA_MAX_MBPS;
+
+	return 0;
+}
+

...

Quoted 12 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +5 -0
@@ -1905,6 +1932,11 @@ static int set_mba_sc(bool mba_sc)
 
 	r->membw.mba_sc = mba_sc;
 
+	list_for_each_entry(d, &r->domains, list) {
+		for (i = 0; i < num_closid; i++)
+			d->mbps_val[i] = MBA_MAX_MBPS;
+	}
+
 	return 0;
 }
 

...

arch/x86/kernel/cpu/resctrl/rdtgroup.c int resctrl_online_domain(struct rdt_resource *r, struct rdt_domain *d) · line 3352

Quoted 10 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +6 -0
@@ -3309,6 +3344,12 @@ int resctrl_online_domain(struct rdt_resource *r, struct rdt_domain *d)
 	if (err)
 		return err;
 
+	err = mba_sc_domain_allocate(r, d);
+	if (err) {
+		domain_destroy_mon_state(d);
+		return err;
+	}
+

Before the above snippet there is a check if the resource is capable of monitoring:

resctrl_online_domain()

{
	...
	if (!r->mon_capable)
		return 0;

	...
	err = mba_sc_domain_allocate(r, d);
	...
}

Thus, the rdt_domain->mbps_val array will only exist in those resources that support monitoring.

Taking a look at where mon_capable is set we see it is done in get_rdt_mon_resources() and as you can see it is only done for RDT_RESOURCE_L3.

get_rdt_mon_resources()

{
	struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl;

	...

	return !rdt_get_mon_l3_config(r); /* mon_capable is set within */
}

Based on the above the rdt_domain->mbps_val array can only exist for those domains that belong to resource RDT_RESOURCE_L3 (if it is capable of monitoring).

Now, looking at set_mba_sc() changed here, it only interacts with RDT_RESOURCE_MBA:

set_mba_sc()

{
	struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_MBA].r_resctrl;

	...

	list_for_each_entry(d, &r->domains, list) {
		for (i = 0; i < num_closid; i++)
			d->mbps_val[i] = MBA_MAX_MBPS;
	}
}

Considering that no domain belonging to RDT_RESOURCE_MBA will have this array this always ends up being a null pointer de-reference.

Reinette

author reviewer
#12 lore raw

Re: [PATCH v3 07/21] x86/resctrl: Create mba_sc configuration in the rdt_domain

Hi Reinette,

Quoted 21 lines · Reinette Chatre

I tried out this work and encountered a null pointer de-reference that seems related to this patch. After digging into that it is not clear to me how this is expected to work.

I encounter the issue just by attempting to mount with "-o mba_MBps" which is the way to enable the mba_sc and exactly what this patch aims to address.

More below ...

Quoted 11 lines · James Morse

To support resctrl's MBA software controller, the architecture must provide a second configuration array to hold the mbps_val[] from user-space.

This complicates the interface between the architecture specific code and the filesystem portions of resctrl that will move to /fs/, to allow multiple architectures to support resctrl.

Make the filesystem parts of resctrl create an array for the mba_sc values when is_mba_sc() is set to true. The software controller can be changed to use this, allowing the architecture code to only consider the values configured in hardware.

...

Quoted 56 lines

Review int resctrl_online_domain(struct rdt_resource *r, struct rdt_domain *d) · line 3352

Quoted 10 lines
(quoted diff) +6 -0
@@ -3309,6 +3344,12 @@ int resctrl_online_domain(struct rdt_resource *r, struct rdt_domain *d)
 	if (err)
 		return err;
 
+	err = mba_sc_domain_allocate(r, d);
+	if (err) {
+		domain_destroy_mon_state(d);
+		return err;
+	}
+

Before the above snippet there is a check if the resource is capable of monitoring:

resctrl_online_domain()

{
	...
	if (!r->mon_capable)
		return 0;

	...
	err = mba_sc_domain_allocate(r, d);
	...
}

Thus, the rdt_domain->mbps_val array will only exist in those resources that support monitoring.

Taking a look at where mon_capable is set we see it is done in get_rdt_mon_resources() and as you can see it is only done for RDT_RESOURCE_L3.

get_rdt_mon_resources()

{
	struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl;

	...

	return !rdt_get_mon_l3_config(r); /* mon_capable is set within */
}

Based on the above the rdt_domain->mbps_val array can only exist for those domains that belong to resource RDT_RESOURCE_L3 (if it is capable of monitoring).

Now, looking at set_mba_sc() changed here, it only interacts with RDT_RESOURCE_MBA:

set_mba_sc()

{
	struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_MBA].r_resctrl;

	...

	list_for_each_entry(d, &r->domains, list) {
		for (i = 0; i < num_closid; i++)
			d->mbps_val[i] = MBA_MAX_MBPS;
	}
}
Quoted 2 lines

Considering that no domain belonging to RDT_RESOURCE_MBA will have this array this always ends up being a null pointer de-reference.

Ugh. I'm not sure how I managed to miss that. Thanks for debugging it!

That loop was added to reset the array when the filesystem is mounted, as it may hold stale values from a previous mount of the filesystem. Its currently done by reset_all_ctrls(), but that function should really belong to the architecture code.

Because mbm_handle_overflow() always passes a domain from the L3 to update_mba_bw(), I think the cleanest thing to do is move the reset to a helper that always operates on the L3 array. (and leave some breadcrumbs in the comments).

Thanks!

James

-----------------%<-----------------

arch/x86/kernel/cpu/resctrl/rdtgroup.c +18 -8
index 36edae7dbc6a..3b52f079a5b3 100644
@@ -1913,6 +1913,23 @@ static void mba_sc_domain_destroy(struct rdt_resource *r,
        d->mbps_val = NULL;
 }
 
+static void mba_sc_reset(void)
+{
+       /*
+        * mbm_handle_overflow() only passes domains of the L3 resource to
+        * update_mba_bw(), so mba_sc only supports monitoring on the L3.
+        */
+       struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl;
+       u32 num_closid = resctrl_arch_get_num_closid(r);
+       struct rdt_domain *d;
+       int i;
+
+       list_for_each_entry(d, &r->domains, list) {
+               for (i = 0; i < num_closid; i++)
+                       d->mbps_val[i] = MBA_MAX_MBPS;
+       }
+}
+
 /*
  * Enable or disable the MBA software controller
  * which helps user specify bandwidth in MBps.
@@ -1922,20 +1939,13 @@ static void mba_sc_domain_destroy(struct rdt_resource *r,
 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_domain *d;
-       int i;
 
        if (!is_mbm_enabled() || !is_mba_linear() ||
            mba_sc == is_mba_sc(r))
                return -EINVAL;
 
        r->membw.mba_sc = mba_sc;
-
-       list_for_each_entry(d, &r->domains, list) {
-               for (i = 0; i < num_closid; i++)
-                       d->mbps_val[i] = MBA_MAX_MBPS;
-       }
+       mba_sc_reset();
 
        return 0;
 }

-----------------%<-----------------

maintainer
#13 lore raw

Re: [PATCH v3 07/21] x86/resctrl: Create mba_sc configuration in the rdt_domain

Hi James,

Quoted 88 lines · James Morse

Hi Reinette,

Quoted 21 lines · Reinette Chatre

I tried out this work and encountered a null pointer de-reference that seems related to this patch. After digging into that it is not clear to me how this is expected to work.

I encounter the issue just by attempting to mount with "-o mba_MBps" which is the way to enable the mba_sc and exactly what this patch aims to address.

More below ...

Quoted 11 lines · James Morse

To support resctrl's MBA software controller, the architecture must provide a second configuration array to hold the mbps_val[] from user-space.

This complicates the interface between the architecture specific code and the filesystem portions of resctrl that will move to /fs/, to allow multiple architectures to support resctrl.

Make the filesystem parts of resctrl create an array for the mba_sc values when is_mba_sc() is set to true. The software controller can be changed to use this, allowing the architecture code to only consider the values configured in hardware.

...

Quoted 56 lines

Review int resctrl_online_domain(struct rdt_resource *r, struct rdt_domain *d) · line 3352

Quoted 10 lines
(quoted diff) +6 -0
@@ -3309,6 +3344,12 @@ int resctrl_online_domain(struct rdt_resource *r, struct rdt_domain *d)
 	if (err)
 		return err;
 
+	err = mba_sc_domain_allocate(r, d);
+	if (err) {
+		domain_destroy_mon_state(d);
+		return err;
+	}
+

Before the above snippet there is a check if the resource is capable of monitoring:

resctrl_online_domain()

{
	...
	if (!r->mon_capable)
		return 0;

	...
	err = mba_sc_domain_allocate(r, d);
	...
}

Thus, the rdt_domain->mbps_val array will only exist in those resources that support monitoring.

Taking a look at where mon_capable is set we see it is done in get_rdt_mon_resources() and as you can see it is only done for RDT_RESOURCE_L3.

get_rdt_mon_resources()

{
	struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl;

	...

	return !rdt_get_mon_l3_config(r); /* mon_capable is set within */
}

Based on the above the rdt_domain->mbps_val array can only exist for those domains that belong to resource RDT_RESOURCE_L3 (if it is capable of monitoring).

Now, looking at set_mba_sc() changed here, it only interacts with RDT_RESOURCE_MBA:

set_mba_sc()

{
	struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_MBA].r_resctrl;

	...

	list_for_each_entry(d, &r->domains, list) {
		for (i = 0; i < num_closid; i++)
			d->mbps_val[i] = MBA_MAX_MBPS;
	}
}
Quoted 2 lines

Considering that no domain belonging to RDT_RESOURCE_MBA will have this array this always ends up being a null pointer de-reference.

Ugh. I'm not sure how I managed to miss that. Thanks for debugging it!

Quoted 9 lines

That loop was added to reset the array when the filesystem is mounted, as it may hold stale values from a previous mount of the filesystem. Its currently done by reset_all_ctrls(), but that function should really belong to the architecture code.

Because mbm_handle_overflow() always passes a domain from the L3 to update_mba_bw(), I think the cleanest thing to do is move the reset to a helper that always operates on the L3 array. (and leave some breadcrumbs in the comments).

I think this points to more than a need to reset the correct array on mount/unmount ... or perhaps I am not understanding this correctly?

As the analysis above shows the mbps_val array only exists for rdt_domains associated with RDT_RESOURCE_L3 but yet mbps_val will contain the MB value provided by user space associated with RDT_RESOURCE_MBA.

For example, following what happens when the user writes to the schemata, would this series not attempt to set the user provided MB value in the rdt_domain->mbps_val that belongs to RDT_RESOURCE_MBA ... but that array would not exist for the domain since the resource is not monitor capable, no?

Reinette

author reviewer
#14 lore raw

Re: [PATCH v3 07/21] x86/resctrl: Create mba_sc configuration in the rdt_domain

Hi Reinette,

Quoted 14 lines · Reinette Chatre
Quoted 13 lines · James Morse
Quoted 12 lines · Reinette Chatre
Quoted 11 lines · James Morse

To support resctrl's MBA software controller, the architecture must provide a second configuration array to hold the mbps_val[] from user-space.

This complicates the interface between the architecture specific code and the filesystem portions of resctrl that will move to /fs/, to allow multiple architectures to support resctrl.

Make the filesystem parts of resctrl create an array for the mba_sc values when is_mba_sc() is set to true. The software controller can be changed to use this, allowing the architecture code to only consider the values configured in hardware.

[...]

Quoted 13 lines
Quoted 5 lines
Quoted 2 lines

Considering that no domain belonging to RDT_RESOURCE_MBA will have this array this always ends up being a null pointer de-reference.

Ugh. I'm not sure how I managed to miss that. Thanks for debugging it!

Quoted 7 lines

That loop was added to reset the array when the filesystem is mounted, as it may hold stale values from a previous mount of the filesystem. Its currently done by reset_all_ctrls(), but that function should really belong to the architecture code.

Because mbm_handle_overflow() always passes a domain from the L3 to update_mba_bw(), I think the cleanest thing to do is move the reset to a helper that always operates on the L3 array. (and leave some breadcrumbs in the comments).

Quoted 6 lines

I think this points to more than a need to reset the correct array on mount/unmount ... or perhaps I am not understanding this correctly?

As the analysis above shows the mbps_val array only exists for rdt_domains associated with RDT_RESOURCE_L3 but yet mbps_val will contain the MB value provided by user space associated with RDT_RESOURCE_MBA.

I've finally got my head round what is going on here: I've muddled up whether mon_capable is a resource or system property. mba_sc depends on the L3 being mon_capable, but the configuration should be associated with MBA (wherever that is).
(basically ignore my previous reply!)

The creation of the mbps_val[] should depend on supports_mba_mbps(), which uses is_mbm_enabled() to check whether the L3 is mon_capable. I'll check the rid too to make it clear its only MBA that has this.
The call to allocate the domain in resctrl_online_domain() should be above the mon_capable check. (which is still needed to avoid the work guarded by is_mbm_enabled() and friends running for each domain).

Thanks,

James

-----------------------%<-----------------------

arch/x86/kernel/cpu/resctrl/rdtgroup.c +8 -6
index e3c90f33baf2..ad0411eb2147 100644
@@ -3345,6 +3345,14 @@ int resctrl_online_domain(struct rdt_resource *r, struct rdt_domain *d)
 
        lockdep_assert_held(&rdtgroup_mutex);
 
+       if (is_mbm_enabled() && r->rid == RDT_RESOURCE_MBA) {
+               err = mba_sc_domain_allocate(r, d);
+               if (err) {
+                       domain_destroy_mon_state(d);
+                       return err;
+               }
+       }
+
        if (!r->mon_capable)
                return 0;
 
@@ -3352,12 +3360,6 @@ int resctrl_online_domain(struct rdt_resource *r, struct rdt_domain *d)
        if (err)
                return err;
 
-       err = mba_sc_domain_allocate(r, d);
-       if (err) {
-               domain_destroy_mon_state(d);
-               return err;
-       }
-
        if (is_mbm_enabled()) {
                INIT_DELAYED_WORK(&d->mbm_over, mbm_handle_overflow);
                mbm_setup_overflow_handler(d, MBM_OVERFLOW_INTERVAL);

-----------------------%<-----------------------

maintainer
#15 lore raw

Re: [PATCH v3 07/21] x86/resctrl: Create mba_sc configuration in the rdt_domain

Hi James,

Quoted 83 lines · James Morse

Hi Reinette,

Quoted 14 lines · Reinette Chatre
Quoted 13 lines · James Morse
Quoted 12 lines · Reinette Chatre
Quoted 11 lines · James Morse

To support resctrl's MBA software controller, the architecture must provide a second configuration array to hold the mbps_val[] from user-space.

This complicates the interface between the architecture specific code and the filesystem portions of resctrl that will move to /fs/, to allow multiple architectures to support resctrl.

Make the filesystem parts of resctrl create an array for the mba_sc values when is_mba_sc() is set to true. The software controller can be changed to use this, allowing the architecture code to only consider the values configured in hardware.

[...]

Quoted 13 lines
Quoted 5 lines
Quoted 2 lines

Considering that no domain belonging to RDT_RESOURCE_MBA will have this array this always ends up being a null pointer de-reference.

Ugh. I'm not sure how I managed to miss that. Thanks for debugging it!

Quoted 7 lines

That loop was added to reset the array when the filesystem is mounted, as it may hold stale values from a previous mount of the filesystem. Its currently done by reset_all_ctrls(), but that function should really belong to the architecture code.

Because mbm_handle_overflow() always passes a domain from the L3 to update_mba_bw(), I think the cleanest thing to do is move the reset to a helper that always operates on the L3 array. (and leave some breadcrumbs in the comments).

Quoted 6 lines

I think this points to more than a need to reset the correct array on mount/unmount ... or perhaps I am not understanding this correctly?

As the analysis above shows the mbps_val array only exists for rdt_domains associated with RDT_RESOURCE_L3 but yet mbps_val will contain the MB value provided by user space associated with RDT_RESOURCE_MBA.

I've finally got my head round what is going on here: I've muddled up whether mon_capable is a resource or system property. mba_sc depends on the L3 being mon_capable, but the configuration should be associated with MBA (wherever that is).
(basically ignore my previous reply!)

The creation of the mbps_val[] should depend on supports_mba_mbps(), which uses is_mbm_enabled() to check whether the L3 is mon_capable. I'll check the rid too to make it clear its only MBA that has this.
The call to allocate the domain in resctrl_online_domain() should be above the mon_capable check. (which is still needed to avoid the work guarded by is_mbm_enabled() and friends running for each domain).

Thanks,

James

-----------------------%<-----------------------

arch/x86/kernel/cpu/resctrl/rdtgroup.c +0 -0
index e3c90f33baf2..ad0411eb2147 100644
@@ -3345,6 +3345,14 @@ int resctrl_online_domain(struct rdt_resource *r, struct rdt_domain *d)


        lockdep_assert_held(&rdtgroup_mutex);

+       if (is_mbm_enabled() && r->rid == RDT_RESOURCE_MBA) { +               err = mba_sc_domain_allocate(r, d); +               if (err) {
+                       domain_destroy_mon_state(d); +                       return err;
+               }
+       }
+
        if (!r->mon_capable)
                return 0;

arch/x86/kernel/cpu/resctrl/rdtgroup.c +0 -0
@@ -3352,12 +3360,6 @@ int resctrl_online_domain(struct rdt_resource *r, struct rdt_domain *d)
         if (err)
                 return err;


-       err = mba_sc_domain_allocate(r, d);
-       if (err) {

Quoted 8 lines

-               domain_destroy_mon_state(d);
-               return err;
-       }
-
        if (is_mbm_enabled()) { INIT_DELAYED_WORK(&d->mbm_over, mbm_handle_overflow); mbm_setup_overflow_handler(d, MBM_OVERFLOW_INTERVAL); -----------------------%<-----------------------

Thank you. Having mbps_val be part of RDT_RESOURCE_MBA makes things clear to me.

In the snippet you provide you may need to check the error path cleanup, I do not think domain_destroy_mon_state(d) would be needed after moving the allocation earlier.

Reinette

author reviewer
#16 lore raw

PATCH v3 8/21 x86/resctrl: Switch over to the resctrl mbps_val list

In reply to James Morse

Updates to resctrl's software controller follow the same path as other configuration updates, but they don't modify the hardware state. rdtgroup_schemata_write() uses parse_line() and the resource's parse_ctrlval() function to stage the configuration. resctrl_arch_update_domains() then updates the mbps_val[] array instead, and resctrl_arch_update_domains() skips the rdt_ctrl_update() call that would update hardware.

This complicates the interface between resctrl's filesystem parts and architecture specific code. It should be possible for mba_sc to be completely implemented by the filesystem parts of resctrl. This would allow it to work on a second architecture with no additional code. resctrl_arch_update_domains() using the mbps_val[] array prevents this.

Change parse_bw() to write the configuration value directly to the mbps_val[] array in the domain structure. Change rdtgroup_schemata_write() to skip the call to resctrl_arch_update_domains(), meaning all the mba_sc specific code in resctrl_arch_update_domains() can be removed. On the read-side, show_doms() and update_mba_bw() are changed to read the mbps_val[] array from the domain structure. With this, resctrl_arch_get_config() no longer needs to consider mba_sc resources.

---
Changes since v2:
* Fixed some names in the commit message.
* Added missing 'or mbps_val[]' code to rdtgroup_size_show()

Changes since v1:
* Squashed out struct resctrl_mba_sc
* Removed stray paragraphs from commit message

---
 arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 44 ++++++++++++++---------
 arch/x86/kernel/cpu/resctrl/monitor.c     | 10 +++---
 arch/x86/kernel/cpu/resctrl/rdtgroup.c    | 14 ++++++--
 3 files changed, 42 insertions(+), 26 deletions(-)
arch/x86/kernel/cpu/resctrl/ctrlmondata.c +27 -17
index 87666275eed9..9f45207a6c74 100644
@@ -61,6 +61,7 @@ int parse_bw(struct rdt_parse_data *data, struct resctrl_schema *s,
 	     struct rdt_domain *d)
 {
 	struct resctrl_staged_config *cfg;
+	u32 closid = data->rdtgrp->closid;
 	struct rdt_resource *r = s->res;
 	unsigned long bw_val;
 
@@ -72,6 +73,12 @@ int parse_bw(struct rdt_parse_data *data, struct resctrl_schema *s,
 
 	if (!bw_validate(data->buf, &bw_val, r))
 		return -EINVAL;
+
+	if (is_mba_sc(r)) {
+		d->mbps_val[closid] = bw_val;
+		return 0;
+	}
+
 	cfg->new_ctrl = bw_val;
 	cfg->have_new_ctrl = true;
 
@@ -261,14 +268,13 @@ static u32 get_config_index(u32 closid, enum resctrl_conf_type type)
 
 static bool apply_config(struct rdt_hw_domain *hw_dom,
 			 struct resctrl_staged_config *cfg, u32 idx,
-			 cpumask_var_t cpu_mask, bool mba_sc)
+			 cpumask_var_t cpu_mask)
 {
 	struct rdt_domain *dom = &hw_dom->d_resctrl;
-	u32 *dc = !mba_sc ? hw_dom->ctrl_val : hw_dom->mbps_val;
 
-	if (cfg->new_ctrl != dc[idx]) {
+	if (cfg->new_ctrl != hw_dom->ctrl_val[idx]) {
 		cpumask_set_cpu(cpumask_any(&dom->cpu_mask), cpu_mask);
-		dc[idx] = cfg->new_ctrl;
+		hw_dom->ctrl_val[idx] = cfg->new_ctrl;
 
 		return true;
 	}
@@ -284,14 +290,12 @@ int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid)
 	enum resctrl_conf_type t;
 	cpumask_var_t cpu_mask;
 	struct rdt_domain *d;
-	bool mba_sc;
 	int cpu;
 	u32 idx;
 
 	if (!zalloc_cpumask_var(&cpu_mask, GFP_KERNEL))
 		return -ENOMEM;
 
-	mba_sc = is_mba_sc(r);
 	msr_param.res = NULL;
 	list_for_each_entry(d, &r->domains, list) {
 		hw_dom = resctrl_to_arch_dom(d);
@@ -301,7 +305,7 @@ int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid)
 				continue;
 
 			idx = get_config_index(closid, t);
-			if (!apply_config(hw_dom, cfg, idx, cpu_mask, mba_sc))
+			if (!apply_config(hw_dom, cfg, idx, cpu_mask))
 				continue;
 
 			if (!msr_param.res) {
@@ -315,11 +319,7 @@ int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid)
 		}
 	}
 
-	/*
-	 * Avoid writing the control msr with control values when
-	 * MBA software controller is enabled
-	 */
-	if (cpumask_empty(cpu_mask) || mba_sc)
+	if (cpumask_empty(cpu_mask))
 		goto done;
 	cpu = get_cpu();
 	/* Update resource control msr on this CPU if it's in cpu_mask. */
@@ -406,6 +406,14 @@ ssize_t rdtgroup_schemata_write(struct kernfs_open_file *of,
 
 	list_for_each_entry(s, &resctrl_schema_all, list) {
 		r = s->res;
+
+		/*
+		 * Writes to mba_sc resources update the software controller,
+		 * not the control msr.
+		 */
+		if (is_mba_sc(r))
+			continue;
+
 		ret = resctrl_arch_update_domains(r, rdtgrp->closid);
 		if (ret)
 			goto out;
@@ -433,9 +441,7 @@ u32 resctrl_arch_get_config(struct rdt_resource *r, struct rdt_domain *d,
 	struct rdt_hw_domain *hw_dom = resctrl_to_arch_dom(d);
 	u32 idx = get_config_index(closid, type);
 
-	if (!is_mba_sc(r))
-		return hw_dom->ctrl_val[idx];
-	return hw_dom->mbps_val[idx];
+	return hw_dom->ctrl_val[idx];
 }
 
 static void show_doms(struct seq_file *s, struct resctrl_schema *schema, int closid)
@@ -450,8 +456,12 @@ static void show_doms(struct seq_file *s, struct resctrl_schema *schema, int clo
 		if (sep)
 			seq_puts(s, ";");
 
-		ctrl_val = resctrl_arch_get_config(r, dom, closid,
-						   schema->conf_type);
+		if (is_mba_sc(r))
+			ctrl_val = dom->mbps_val[closid];
+		else
+			ctrl_val = resctrl_arch_get_config(r, dom, closid,
+							   schema->conf_type);
+
 		seq_printf(s, r->format_str, dom->id, max_data_width,
 			   ctrl_val);
 		sep = true;
arch/x86/kernel/cpu/resctrl/monitor.c +4 -6
index 497cadf3285d..5cc1e6b229d4 100644
@@ -447,13 +447,11 @@ static void update_mba_bw(struct rdtgroup *rgrp, struct rdt_domain *dom_mbm)
 	hw_dom_mba = resctrl_to_arch_dom(dom_mba);
 
 	cur_bw = pmbm_data->prev_bw;
-	user_bw = resctrl_arch_get_config(r_mba, dom_mba, closid, CDP_NONE);
+	user_bw = dom_mba->mbps_val[closid];
 	delta_bw = pmbm_data->delta_bw;
-	/*
-	 * resctrl_arch_get_config() chooses the mbps/ctrl value to return
-	 * based on is_mba_sc(). For now, reach into the hw_dom.
-	 */
-	cur_msr_val = hw_dom_mba->ctrl_val[closid];
+
+	/* MBA monitor resource doesn't support CDP */
+	cur_msr_val = resctrl_arch_get_config(r_mba, dom_mba, closid, CDP_NONE);
 
 	/*
 	 * For Ctrl groups read data from child monitor groups.
arch/x86/kernel/cpu/resctrl/rdtgroup.c +11 -3
index e4313f907eb6..7b8a23e2eadd 100644
@@ -1356,11 +1356,13 @@ static int rdtgroup_size_show(struct kernfs_open_file *of,
 			      struct seq_file *s, void *v)
 {
 	struct resctrl_schema *schema;
+	enum resctrl_conf_type type;
 	struct rdtgroup *rdtgrp;
 	struct rdt_resource *r;
 	struct rdt_domain *d;
 	unsigned int size;
 	int ret = 0;
+	u32 closid;
 	bool sep;
 	u32 ctrl;
 
@@ -1386,8 +1388,11 @@ static int rdtgroup_size_show(struct kernfs_open_file *of,
 		goto out;
 	}
 
+	closid = rdtgrp->closid;
+
 	list_for_each_entry(schema, &resctrl_schema_all, list) {
 		r = schema->res;
+		type = schema->conf_type;
 		sep = false;
 		seq_printf(s, "%*s:", max_name_width, schema->name);
 		list_for_each_entry(d, &r->domains, list) {
@@ -1396,9 +1401,12 @@ static int rdtgroup_size_show(struct kernfs_open_file *of,
 			if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP) {
 				size = 0;
 			} else {
-				ctrl = resctrl_arch_get_config(r, d,
-							       rdtgrp->closid,
-							       schema->conf_type);
+				if (is_mba_sc(r))
+					ctrl = d->mbps_val[closid];
+				else
+					ctrl = resctrl_arch_get_config(r, d,
+								       closid,
+								       type);
 				if (r->rid == RDT_RESOURCE_MBA)
 					size = ctrl;
 				else
Signature · 1 line
2.30.2
author reviewer
#17 lore raw

PATCH v3 9/21 x86/resctrl: Remove architecture copy of mbps_val

In reply to James Morse

The resctrl arch code provides a second configuration array mbps_val[] for the MBA software controller.

Since resctrl switched over to allocating and freeing its own array when needed, nothing uses the arch code version.

Remove it.

---
Changes since v2:
* Made setup_default_ctrlval() static.

Changes since v1:
* Fixed spelling mistake
* Capitalisation

---
 arch/x86/kernel/cpu/resctrl/core.c     | 20 ++++----------------
 arch/x86/kernel/cpu/resctrl/internal.h |  3 ---
 arch/x86/kernel/cpu/resctrl/rdtgroup.c |  4 +---
 3 files changed, 5 insertions(+), 22 deletions(-)
arch/x86/kernel/cpu/resctrl/core.c +4 -16
index f69182973175..f0e2820af475 100644
@@ -397,7 +397,7 @@ struct rdt_domain *rdt_find_domain(struct rdt_resource *r, int id,
 	return NULL;
 }
 
-void setup_default_ctrlval(struct rdt_resource *r, u32 *dc, u32 *dm)
+static void setup_default_ctrlval(struct rdt_resource *r, u32 *dc)
 {
 	struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r);
 	int i;
@@ -406,18 +406,14 @@ void setup_default_ctrlval(struct rdt_resource *r, u32 *dc, u32 *dm)
 	 * Initialize the Control MSRs to having no control.
 	 * For Cache Allocation: Set all bits in cbm
 	 * For Memory Allocation: Set b/w requested to 100%
-	 * and the bandwidth in MBps to U32_MAX
 	 */
-	for (i = 0; i < hw_res->num_closid; i++, dc++, dm++) {
+	for (i = 0; i < hw_res->num_closid; i++, dc++)
 		*dc = r->default_ctrl;
-		*dm = MBA_MAX_MBPS;
-	}
 }
 
 static void domain_free(struct rdt_hw_domain *hw_dom)
 {
 	kfree(hw_dom->ctrl_val);
-	kfree(hw_dom->mbps_val);
 	kfree(hw_dom);
 }
 
@@ -426,23 +422,15 @@ static int domain_setup_ctrlval(struct rdt_resource *r, struct rdt_domain *d)
 	struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r);
 	struct rdt_hw_domain *hw_dom = resctrl_to_arch_dom(d);
 	struct msr_param m;
-	u32 *dc, *dm;
+	u32 *dc;
 
 	dc = kmalloc_array(hw_res->num_closid, sizeof(*hw_dom->ctrl_val),
 			   GFP_KERNEL);
 	if (!dc)
 		return -ENOMEM;
 
-	dm = kmalloc_array(hw_res->num_closid, sizeof(*hw_dom->mbps_val),
-			   GFP_KERNEL);
-	if (!dm) {
-		kfree(dc);
-		return -ENOMEM;
-	}
-
 	hw_dom->ctrl_val = dc;
-	hw_dom->mbps_val = dm;
-	setup_default_ctrlval(r, dc, dm);
+	setup_default_ctrlval(r, dc);
 
 	m.low = 0;
 	m.high = hw_res->num_closid;
arch/x86/kernel/cpu/resctrl/internal.h +0 -3
index a7e2cbce29d5..373aaba53ecd 100644
@@ -308,14 +308,12 @@ struct mbm_state {
  *			  a resource
  * @d_resctrl:	Properties exposed to the resctrl file system
  * @ctrl_val:	array of cache or mem ctrl values (indexed by CLOSID)
- * @mbps_val:	When mba_sc is enabled, this holds the bandwidth in MBps
  *
  * Members of this structure are accessed via helpers that provide abstraction.
  */
 struct rdt_hw_domain {
 	struct rdt_domain		d_resctrl;
 	u32				*ctrl_val;
-	u32				*mbps_val;
 };
 
 static inline struct rdt_hw_domain *resctrl_to_arch_dom(struct rdt_domain *r)
@@ -529,7 +527,6 @@ void mbm_setup_overflow_handler(struct rdt_domain *dom,
 void mbm_handle_overflow(struct work_struct *work);
 void __init intel_rdt_mbm_apply_quirk(void);
 bool is_mba_sc(struct rdt_resource *r);
-void setup_default_ctrlval(struct rdt_resource *r, u32 *dc, u32 *dm);
 u32 delay_bw_map(unsigned long bw, struct rdt_resource *r);
 void cqm_setup_limbo_handler(struct rdt_domain *dom, unsigned long delay_ms);
 void cqm_handle_limbo(struct work_struct *work);
arch/x86/kernel/cpu/resctrl/rdtgroup.c +1 -3
index 7b8a23e2eadd..22ebfdb4472d 100644
@@ -2361,10 +2361,8 @@ static int reset_all_ctrls(struct rdt_resource *r)
 		hw_dom = resctrl_to_arch_dom(d);
 		cpumask_set_cpu(cpumask_any(&d->cpu_mask), cpu_mask);
 
-		for (i = 0; i < hw_res->num_closid; i++) {
+		for (i = 0; i < hw_res->num_closid; i++)
 			hw_dom->ctrl_val[i] = r->default_ctrl;
-			hw_dom->mbps_val[i] = MBA_MAX_MBPS;
-		}
 	}
 	cpu = get_cpu();
 	/* Update CBM on this cpu if it's in cpu_mask. */
Signature · 1 line
2.30.2
author reviewer
#18 lore raw

PATCH v3 10/21 x86/resctrl: Abstract and use supports_mba_mbps()

In reply to James Morse

To determine whether the mba_MBps option to resctrl should be supported, resctrl tests the boot CPUs' x86_vendor.

This isn't portable, and needs abstracting behind a helper so this check can be part of the filesystem code that moves to /fs/.

Re-use the tests set_mba_sc() does to determine if the mba_sc is supported on this system. An 'alloc_capable' test is added so that support for the controls isn't implied by the 'delay_linear' property, which is always true for MPAM.

---
Changes since v1:
* Capitalisation
* Added MPAM example in commit message
* Fixed supports_mba_mbps() logic error in rdt_parse_param()

---
 arch/x86/kernel/cpu/resctrl/rdtgroup.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)
arch/x86/kernel/cpu/resctrl/rdtgroup.c +14 -5
index 22ebfdb4472d..7ec089d72ab7 100644
@@ -1922,11 +1922,21 @@ static void mba_sc_domain_destroy(struct rdt_resource *r,
 }
 
 /*
- * Enable or disable the MBA software controller
- * which helps user specify bandwidth in MBps.
  * MBA software controller is supported only if
  * MBM is supported and MBA is in linear scale.
  */
+static bool supports_mba_mbps(void)
+{
+	struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_MBA].r_resctrl;
+
+	return (is_mbm_enabled() &&
+		r->alloc_capable && is_mba_linear());
+}
+
+/*
+ * Enable or disable the MBA software controller
+ * which helps user specify bandwidth in MBps.
+ */
 static int set_mba_sc(bool mba_sc)
 {
 	struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_MBA].r_resctrl;
@@ -1934,8 +1944,7 @@ static int set_mba_sc(bool mba_sc)
 	struct rdt_domain *d;
 	int i;
 
-	if (!is_mbm_enabled() || !is_mba_linear() ||
-	    mba_sc == is_mba_sc(r))
+	if (!supports_mba_mbps() || mba_sc == is_mba_sc(r))
 		return -EINVAL;
 
 	r->membw.mba_sc = mba_sc;
@@ -2295,7 +2304,7 @@ static int rdt_parse_param(struct fs_context *fc, struct fs_parameter *param)
 		ctx->enable_cdpl2 = true;
 		return 0;
 	case Opt_mba_mbps:
-		if (boot_cpu_data.x86_vendor != X86_VENDOR_INTEL)
+		if (!supports_mba_mbps())
 			return -EINVAL;
 		ctx->enable_mba_mbps = true;
 		return 0;
Signature · 1 line
2.30.2
author reviewer
#19 lore raw

PATCH v3 11/21 x86/resctrl: Allow update_mba_bw() to update controls directly

In reply to James Morse

update_mba_bw() calculates a new control value for the MBA resource based on the user provided mbps_val and the current measured bandwidth. Some control values need remapping by delay_bw_map().

It does this by calling wrmsrl() directly. This needs splitting up to be done by an architecture specific helper, so that the remainder can eventually be moved to /fs/.

Add resctrl_arch_update_one() to apply one configuration value to the provided resource and domain. This avoids the staging and cross-calling that is only needed with changes made by user-space. delay_bw_map() moves to be part of the arch code, to maintain the 'percentage control' view of MBA resources in resctrl.

---
Chagnes since v2:
* Call msr_update() directly from resctrl_arch_update_one().

Changes since v1:
* Capitalisation

---
 arch/x86/kernel/cpu/resctrl/core.c        |  2 +-
 arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 21 +++++++++++++++++++++
 arch/x86/kernel/cpu/resctrl/internal.h    |  1 -
 arch/x86/kernel/cpu/resctrl/monitor.c     | 13 ++++---------
 include/linux/resctrl.h                   |  8 ++++++++
 5 files changed, 34 insertions(+), 11 deletions(-)
arch/x86/kernel/cpu/resctrl/core.c +1 -1
index f0e2820af475..90ebb7d71af2 100644
@@ -296,7 +296,7 @@ mba_wrmsr_amd(struct rdt_domain *d, struct msr_param *m, struct rdt_resource *r)
  * that can be written to QOS_MSRs.
  * There are currently no SKUs which support non linear delay values.
  */
-u32 delay_bw_map(unsigned long bw, struct rdt_resource *r)
+static u32 delay_bw_map(unsigned long bw, struct rdt_resource *r)
 {
 	if (r->membw.delay_linear)
 		return MAX_MBA_BW - bw;
arch/x86/kernel/cpu/resctrl/ctrlmondata.c +21 -0
index 9f45207a6c74..ece3a1e0e6f2 100644
@@ -282,6 +282,27 @@ static bool apply_config(struct rdt_hw_domain *hw_dom,
 	return false;
 }
 
+int resctrl_arch_update_one(struct rdt_resource *r, struct rdt_domain *d,
+			    u32 closid, enum resctrl_conf_type t, u32 cfg_val)
+{
+	struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r);
+	struct rdt_hw_domain *hw_dom = resctrl_to_arch_dom(d);
+	u32 idx = get_config_index(closid, t);
+	struct msr_param msr_param;
+
+	if (!cpumask_test_cpu(smp_processor_id(), &d->cpu_mask))
+		return -EINVAL;
+
+	hw_dom->ctrl_val[idx] = cfg_val;
+
+	msr_param.res = r;
+	msr_param.low = idx;
+	msr_param.high = idx + 1;
+	hw_res->msr_update(d, &msr_param, r);
+
+	return 0;
+}
+
 int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid)
 {
 	struct resctrl_staged_config *cfg;
arch/x86/kernel/cpu/resctrl/internal.h +0 -1
index 373aaba53ecd..3b9e43ba7590 100644
@@ -527,7 +527,6 @@ void mbm_setup_overflow_handler(struct rdt_domain *dom,
 void mbm_handle_overflow(struct work_struct *work);
 void __init intel_rdt_mbm_apply_quirk(void);
 bool is_mba_sc(struct rdt_resource *r);
-u32 delay_bw_map(unsigned long bw, struct rdt_resource *r);
 void cqm_setup_limbo_handler(struct rdt_domain *dom, unsigned long delay_ms);
 void cqm_handle_limbo(struct work_struct *work);
 bool has_busy_rmid(struct rdt_resource *r, struct rdt_domain *d);
arch/x86/kernel/cpu/resctrl/monitor.c +4 -9
index 5cc1e6b229d4..ac1a2e8998bb 100644
@@ -420,10 +420,8 @@ void mon_event_count(void *info)
  */
 static void update_mba_bw(struct rdtgroup *rgrp, struct rdt_domain *dom_mbm)
 {
-	u32 closid, rmid, cur_msr, cur_msr_val, new_msr_val;
+	u32 closid, rmid, cur_msr_val, new_msr_val;
 	struct mbm_state *pmbm_data, *cmbm_data;
-	struct rdt_hw_resource *hw_r_mba;
-	struct rdt_hw_domain *hw_dom_mba;
 	u32 cur_bw, delta_bw, user_bw;
 	struct rdt_resource *r_mba;
 	struct rdt_domain *dom_mba;
@@ -433,8 +431,8 @@ static void update_mba_bw(struct rdtgroup *rgrp, struct rdt_domain *dom_mbm)
 	if (!is_mbm_local_enabled())
 		return;
 
-	hw_r_mba = &rdt_resources_all[RDT_RESOURCE_MBA];
-	r_mba = &hw_r_mba->r_resctrl;
+	r_mba = &rdt_resources_all[RDT_RESOURCE_MBA].r_resctrl;
+
 	closid = rgrp->closid;
 	rmid = rgrp->mon.rmid;
 	pmbm_data = &dom_mbm->mbm_local[rmid];
@@ -444,7 +442,6 @@ static void update_mba_bw(struct rdtgroup *rgrp, struct rdt_domain *dom_mbm)
 		pr_warn_once("Failure to get domain for MBA update\n");
 		return;
 	}
-	hw_dom_mba = resctrl_to_arch_dom(dom_mba);
 
 	cur_bw = pmbm_data->prev_bw;
 	user_bw = dom_mba->mbps_val[closid];
@@ -486,9 +483,7 @@ static void update_mba_bw(struct rdtgroup *rgrp, struct rdt_domain *dom_mbm)
 		return;
 	}
 
-	cur_msr = hw_r_mba->msr_base + closid;
-	wrmsrl(cur_msr, delay_bw_map(new_msr_val, r_mba));
-	hw_dom_mba->ctrl_val[closid] = new_msr_val;
+	resctrl_arch_update_one(r_mba, dom_mba, closid, CDP_NONE, new_msr_val);
 
 	/*
 	 * Delta values are updated dynamically package wise for each
include/linux/resctrl.h +8 -0
index 46ab9fb5562e..84e815cb3be6 100644
@@ -197,6 +197,14 @@ struct resctrl_schema {
 /* The number of closid supported by this resource regardless of CDP */
 u32 resctrl_arch_get_num_closid(struct rdt_resource *r);
 int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid);
+
+/*
+ * Update the ctrl_val and apply this config right now.
+ * Must be called on one of the domain's CPUs.
+ */
+int resctrl_arch_update_one(struct rdt_resource *r, struct rdt_domain *d,
+			    u32 closid, enum resctrl_conf_type t, u32 cfg_val);
+
 u32 resctrl_arch_get_config(struct rdt_resource *r, struct rdt_domain *d,
 			    u32 closid, enum resctrl_conf_type type);
 int resctrl_online_domain(struct rdt_resource *r, struct rdt_domain *d);
Signature · 1 line
2.30.2
author reviewer
#20 lore raw

PATCH v3 12/21 x86/resctrl: Calculate bandwidth from the previous __mon_event_count() chunks

In reply to James Morse

mbm_bw_count() is only called by the mbm_handle_overflow() worker once a second. It reads the hardware register, calculates the bandwidth and updates m->prev_bw_msr which is used to hold the previous hardware register value.

Operating directly on hardware register values makes it difficult to make this code architecture independent, so that it can be moved to /fs/, making the mba_sc feature something resctrl supports with no additional support from the architecture.
Prior to calling mbm_bw_count(), mbm_update() reads from the same hardware register using __mon_event_count().

Change mbm_bw_count() to use the current chunks value most recently saved by __mon_event_count(). This removes an extra call to __rmid_read(). Instead of using m->prev_msr to calculate the number of chunks seen, use the rr->val that was updated by __mon_event_count(). This removes a extra calls to mbm_overflow_count() and get_corrected_mbm_count(). Calculating bandwidth like this means mbm_bw_count() no longer operates on hardware register values directly.

---
Changes since v2:
* Expanded commit message

Changes since v1:
* This patch was rewritten

---
 arch/x86/kernel/cpu/resctrl/internal.h |  4 ++--
 arch/x86/kernel/cpu/resctrl/monitor.c  | 24 +++++++++++++++---------
 2 files changed, 17 insertions(+), 11 deletions(-)
arch/x86/kernel/cpu/resctrl/internal.h +2 -2
index 3b9e43ba7590..c50c8911ef59 100644
@@ -289,7 +289,7 @@ struct rftype {
  * struct mbm_state - status for each MBM counter in each domain
  * @chunks:	Total data moved (multiply by rdt_group.mon_scale to get bytes)
  * @prev_msr:	Value of IA32_QM_CTR for this RMID last time we read it
- * @prev_bw_msr:Value of previous IA32_QM_CTR for bandwidth counting
+ * @prev_bw_chunks: Previous chunks value read when for bandwidth calculation
  * @prev_bw:	The most recent bandwidth in MBps
  * @delta_bw:	Difference between the current and previous bandwidth
  * @delta_comp:	Indicates whether to compute the delta_bw
@@ -297,7 +297,7 @@ struct rftype {
 struct mbm_state {
 	u64	chunks;
 	u64	prev_msr;
-	u64	prev_bw_msr;
+	u64	prev_bw_chunks;
 	u32	prev_bw;
 	u32	delta_bw;
 	bool	delta_comp;
arch/x86/kernel/cpu/resctrl/monitor.c +15 -9
index ac1a2e8998bb..8ae375e29256 100644
@@ -315,7 +315,7 @@ static u64 __mon_event_count(u32 rmid, struct rmid_read *rr)
 
 	if (rr->first) {
 		memset(m, 0, sizeof(struct mbm_state));
-		m->prev_bw_msr = m->prev_msr = tval;
+		m->prev_msr = tval;
 		return 0;
 	}
 
@@ -329,27 +329,32 @@ static u64 __mon_event_count(u32 rmid, struct rmid_read *rr)
 }
 
 /*
+ * mbm_bw_count() - Update bw count from values previously read by
+ *		    __mon_event_count().
+ * @rmid:	The rmid used to identify the cached mbm_state.
+ * @rr:		The struct rmid_read populated by __mon_event_count().
+ *
  * Supporting function to calculate the memory bandwidth
- * and delta bandwidth in MBps.
+ * and delta bandwidth in MBps. The chunks value previously read by
+ * __mon_event_count() is compared with the chunks value from the previous
+ * invocation. This must be called oncer per second to maintain values in MBps.
  */
 static void mbm_bw_count(u32 rmid, struct rmid_read *rr)
 {
 	struct rdt_hw_resource *hw_res = resctrl_to_arch_res(rr->r);
 	struct mbm_state *m = &rr->d->mbm_local[rmid];
-	u64 tval, cur_bw, chunks;
+	u64 cur_bw, chunks, cur_chunks;
 
-	tval = __rmid_read(rmid, rr->evtid);
-	if (tval & (RMID_VAL_ERROR | RMID_VAL_UNAVAIL))
-		return;
+	cur_chunks = rr->val;
+	chunks = cur_chunks - m->prev_bw_chunks;
+	m->prev_bw_chunks = cur_chunks;
 
-	chunks = mbm_overflow_count(m->prev_bw_msr, tval, hw_res->mbm_width);
-	cur_bw = (get_corrected_mbm_count(rmid, chunks) * hw_res->mon_scale) >> 20;
+	cur_bw = (chunks * hw_res->mon_scale) >> 20;
 
 	if (m->delta_comp)
 		m->delta_bw = abs(cur_bw - m->prev_bw);
 	m->delta_comp = false;
 	m->prev_bw = cur_bw;
-	m->prev_bw_msr = tval;
 }
 
 /*
@@ -509,6 +514,7 @@ static void mbm_update(struct rdt_resource *r, struct rdt_domain *d, int rmid)
 	rr.first = false;
 	rr.r = r;
 	rr.d = d;
+	rr.val = 0;
 
 	/*
 	 * This is protected from concurrent reads from user
Signature · 1 line
2.30.2
maintainer
#21 lore raw

Re: [PATCH v3 12/21] x86/resctrl: Calculate bandwidth from the previous __mon_event_count() chunks

Hi James,

Quoted 12 lines · James Morse

mbm_bw_count() is only called by the mbm_handle_overflow() worker once a second. It reads the hardware register, calculates the bandwidth and updates m->prev_bw_msr which is used to hold the previous hardware register value.

Operating directly on hardware register values makes it difficult to make this code architecture independent, so that it can be moved to /fs/, making the mba_sc feature something resctrl supports with no additional support from the architecture.
Prior to calling mbm_bw_count(), mbm_update() reads from the same hardware register using __mon_event_count().

Quoted 6 lines

Change mbm_bw_count() to use the current chunks value most recently saved by __mon_event_count(). This removes an extra call to __rmid_read().

Instead of using m->prev_msr to calculate the number of chunks seen, use the rr->val that was updated by __mon_event_count(). This removes a extra calls to mbm_overflow_count() and get_corrected_mbm_count().

"removes a extra calls" -> "removes an extra call" ?

__mon_event_count() ends with "rr->val += get_corrected_mbm_count()" and it is called twice by mbm_update(). The intention in this change is for mbm_bw_count() to benefit from the rmid read done just before ... but would using rr->val within mbm_bw_count() not result in it getting data from both rmid reads due to the increment?

mbm_update() {

	rr.val = 0;

	if (is_mbm_total_enabled()) {
		...
		__mon_event_count() /* rr->val += ... */
	}
	if (is_mbm_local_enabled()) {
		...
		__mon_event_count() /* rr->val += ... */

		if (is_mba_sc(NULL))
			mbm_bw_count(rmid, &rr); /* Use rr-> val */
	}

Should rr.val perhaps be reset before each __mon_event_count() call instead of just at the beginning of mbm_update()?

Quoted 20 lines

Calculating bandwidth like this means mbm_bw_count() no longer operates on hardware register values directly.

---
Changes since v2:
* Expanded commit message

Changes since v1:
* This patch was rewritten

---
 arch/x86/kernel/cpu/resctrl/internal.h |  4 ++--
 arch/x86/kernel/cpu/resctrl/monitor.c  | 24 +++++++++++++++---------
 2 files changed, 17 insertions(+), 11 deletions(-)
arch/x86/kernel/cpu/resctrl/internal.h +0 -0
index 3b9e43ba7590..c50c8911ef59 100644

arch/x86/kernel/cpu/resctrl/internal.h struct rftype { · line 292

Quoted 5 lines
arch/x86/kernel/cpu/resctrl/internal.h +1 -1
@@ -289,7 +289,7 @@ struct rftype {
  * struct mbm_state - status for each MBM counter in each domain
  * @chunks:	Total data moved (multiply by rdt_group.mon_scale to get bytes)
  * @prev_msr:	Value of IA32_QM_CTR for this RMID last time we read it
- * @prev_bw_msr:Value of previous IA32_QM_CTR for bandwidth counting
+ * @prev_bw_chunks: Previous chunks value read when for bandwidth calculation

"value read when for" -> "value read for"?

Quoted 29 lines
arch/x86/kernel/cpu/resctrl/internal.h +1 -1
  * @prev_bw:	The most recent bandwidth in MBps
  * @delta_bw:	Difference between the current and previous bandwidth
  * @delta_comp:	Indicates whether to compute the delta_bw
@@ -297,7 +297,7 @@ struct rftype {
 struct mbm_state {
 	u64	chunks;
 	u64	prev_msr;
-	u64	prev_bw_msr;
+	u64	prev_bw_chunks;
 	u32	prev_bw;
 	u32	delta_bw;
 	bool	delta_comp;
arch/x86/kernel/cpu/resctrl/monitor.c +1 -1
index ac1a2e8998bb..8ae375e29256 100644
@@ -315,7 +315,7 @@ static u64 __mon_event_count(u32 rmid, struct rmid_read *rr)
 
 	if (rr->first) {
 		memset(m, 0, sizeof(struct mbm_state));
-		m->prev_bw_msr = m->prev_msr = tval;
+		m->prev_msr = tval;
 		return 0;
 	}
 
@@ -329,27 +329,32 @@ static u64 __mon_event_count(u32 rmid, struct rmid_read *rr)
 }
 
 /*

arch/x86/kernel/cpu/resctrl/monitor.c static u64 __mon_event_count(u32 rmid, struct rmid_read *rr) · line 340

Quoted 10 lines
arch/x86/kernel/cpu/resctrl/monitor.c +8 -1
+ * mbm_bw_count() - Update bw count from values previously read by
+ *		    __mon_event_count().
+ * @rmid:	The rmid used to identify the cached mbm_state.
+ * @rr:		The struct rmid_read populated by __mon_event_count().
+ *
  * Supporting function to calculate the memory bandwidth
- * and delta bandwidth in MBps.
+ * and delta bandwidth in MBps. The chunks value previously read by
+ * __mon_event_count() is compared with the chunks value from the previous
+ * invocation. This must be called oncer per second to maintain values in MBps.

"must be called oncer" -> "must be called once"

Quoted 28 lines
arch/x86/kernel/cpu/resctrl/monitor.c +5 -7
  */
 static void mbm_bw_count(u32 rmid, struct rmid_read *rr)
 {
 	struct rdt_hw_resource *hw_res = resctrl_to_arch_res(rr->r);
 	struct mbm_state *m = &rr->d->mbm_local[rmid];
-	u64 tval, cur_bw, chunks;
+	u64 cur_bw, chunks, cur_chunks;
 
-	tval = __rmid_read(rmid, rr->evtid);
-	if (tval & (RMID_VAL_ERROR | RMID_VAL_UNAVAIL))
-		return;
+	cur_chunks = rr->val;
+	chunks = cur_chunks - m->prev_bw_chunks;
+	m->prev_bw_chunks = cur_chunks;
 
-	chunks = mbm_overflow_count(m->prev_bw_msr, tval, hw_res->mbm_width);
-	cur_bw = (get_corrected_mbm_count(rmid, chunks) * hw_res->mon_scale) >> 20;
+	cur_bw = (chunks * hw_res->mon_scale) >> 20;
 
 	if (m->delta_comp)
 		m->delta_bw = abs(cur_bw - m->prev_bw);
 	m->delta_comp = false;
 	m->prev_bw = cur_bw;
-	m->prev_bw_msr = tval;
 }
 
 /*

arch/x86/kernel/cpu/resctrl/monitor.c static void mbm_update(struct rdt_resource *r, struct rdt_domain *d, int rmid) · line 520

Quoted 7 lines
arch/x86/kernel/cpu/resctrl/monitor.c +1 -0
@@ -509,6 +514,7 @@ static void mbm_update(struct rdt_resource *r, struct rdt_domain *d, int rmid)
 	rr.first = false;
 	rr.r = r;
 	rr.d = d;
+	rr.val = 0;
 
 	/*
 	 * This is protected from concurrent reads from user

Reinette

author reviewer
#22 lore raw

Re: [PATCH v3 12/21] x86/resctrl: Calculate bandwidth from the previous __mon_event_count() chunks

Hi Reinette,

Quoted 20 lines · Reinette Chatre
Quoted 12 lines · James Morse

mbm_bw_count() is only called by the mbm_handle_overflow() worker once a second. It reads the hardware register, calculates the bandwidth and updates m->prev_bw_msr which is used to hold the previous hardware register value.

Operating directly on hardware register values makes it difficult to make this code architecture independent, so that it can be moved to /fs/, making the mba_sc feature something resctrl supports with no additional support from the architecture.
Prior to calling mbm_bw_count(), mbm_update() reads from the same hardware register using __mon_event_count().

Quoted 6 lines

Change mbm_bw_count() to use the current chunks value most recently saved by __mon_event_count(). This removes an extra call to __rmid_read().

Instead of using m->prev_msr to calculate the number of chunks seen, use the rr->val that was updated by __mon_event_count(). This removes a extra calls to mbm_overflow_count() and get_corrected_mbm_count().

Quoted 7 lines

"removes a extra calls" -> "removes an extra call" ?

__mon_event_count() ends with "rr->val += get_corrected_mbm_count()" and it is called twice by mbm_update(). The intention in this change is for mbm_bw_count() to benefit from the rmid read done just before ... but would using rr->val within mbm_bw_count() not result in it getting data from both rmid reads due to the increment?

Yes, bother. I thought those were mutually exclusive, but its __mon_event_count() that uses a different struct mbm_state for each set of raw values, not mbm_update().

[...]

Quoted 2 lines

Should rr.val perhaps be reset before each __mon_event_count() call instead of just at the beginning of mbm_update()?

Yes. This is because the struct rmid_read is just to allow __mon_event_count() to do its thing, nothing used to read those values.

Quoted 2 lines
Quoted 2 lines

Calculating bandwidth like this means mbm_bw_count() no longer operates on hardware register values directly.

Thanks!

James

author reviewer
#23 lore raw

PATCH v3 13/21 x86/recstrl: Add per-rmid arch private storage for overflow and chunks

In reply to James Morse

A renamed __rmid_read() is intended as the function that an architecture agnostic resctrl filesystem driver can use to read a value in bytes from a counter. Currently the function returns the MBM values in chunks directly from hardware. For bandwidth counters the resctrl filesystem uses this to calculate the number of bytes ever seen.

MPAM's scaling of counters can be changed at runtime, reducing the resolution but increasing the range. When this is changed the prev_msr values need to be converted by the architecture code.

Add an array for per-rmid private storage. The prev_msr and chunks values will move here to allow resctrl_arch_rmid_read() to always return the number of bytes read by this counter without assistance from the filesystem. The values are moved in later patches when the overflow and correction calls are moved into __rmid_read().

----
Changes since v2:
* Capitalisation
* Use __rmid_read() as this patch is earlier in the series.
* kfree() one array in arch_domain_mbm_alloc() when allocating the other fails, instead of relying on domain_free().
* Remove the documentation that domain_free() has to be called to cleanup if this call fails.

---
 arch/x86/kernel/cpu/resctrl/core.c     | 35 ++++++++++++++++++++++++++
 arch/x86/kernel/cpu/resctrl/internal.h | 14 +++++++++++
 2 files changed, 49 insertions(+)
arch/x86/kernel/cpu/resctrl/core.c +35 -0
index 90ebb7d71af2..de62b0b87ced 100644
@@ -413,6 +413,8 @@ static void setup_default_ctrlval(struct rdt_resource *r, u32 *dc)
 
 static void domain_free(struct rdt_hw_domain *hw_dom)
 {
+	kfree(hw_dom->arch_mbm_total);
+	kfree(hw_dom->arch_mbm_local);
 	kfree(hw_dom->ctrl_val);
 	kfree(hw_dom);
 }
@@ -438,6 +440,34 @@ static int domain_setup_ctrlval(struct rdt_resource *r, struct rdt_domain *d)
 	return 0;
 }
 
+/**
+ * arch_domain_mbm_alloc() - Allocate arch private storage for the MBM counters
+ * @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_domain *hw_dom)
+{
+	size_t tsize;
+
+	if (is_mbm_total_enabled()) {
+		tsize = sizeof(*hw_dom->arch_mbm_total);
+		hw_dom->arch_mbm_total = kcalloc(num_rmid, tsize, GFP_KERNEL);
+		if (!hw_dom->arch_mbm_total)
+			return -ENOMEM;
+	}
+	if (is_mbm_local_enabled()) {
+		tsize = sizeof(*hw_dom->arch_mbm_local);
+		hw_dom->arch_mbm_local = kcalloc(num_rmid, tsize, GFP_KERNEL);
+		if (!hw_dom->arch_mbm_local) {
+			kfree(hw_dom->arch_mbm_total);
+			hw_dom->arch_mbm_total = NULL;
+			return -ENOMEM;
+		}
+	}
+
+	return 0;
+}
+
 /*
  * domain_add_cpu - Add a cpu to a resource's domain list.
  *
@@ -487,6 +517,11 @@ static void domain_add_cpu(int cpu, struct rdt_resource *r)
 		return;
 	}
 
+	if (r->mon_capable && arch_domain_mbm_alloc(r->num_rmid, hw_dom)) {
+		domain_free(hw_dom);
+		return;
+	}
+
 	list_add_tail(&d->list, add_pos);
 
 	err = resctrl_online_domain(r, d);
arch/x86/kernel/cpu/resctrl/internal.h +14 -0
index c50c8911ef59..156d526c6952 100644
@@ -303,17 +303,31 @@ struct mbm_state {
 	bool	delta_comp;
 };
 
+/**
+ * struct arch_mbm_state - values used to compute resctrl_arch_rmid_read()s
+ *			   return value.
+ * @prev_msr:	Value of IA32_QM_CTR last time it was read for the RMID used to
+ *		find this struct.
+ */
+struct arch_mbm_state {
+	u64	prev_msr;
+};
+
 /**
  * struct rdt_hw_domain - Arch private attributes of a set of CPUs that share
  *			  a resource
  * @d_resctrl:	Properties exposed to the resctrl file system
  * @ctrl_val:	array of cache or mem ctrl values (indexed by CLOSID)
+ * @arch_mbm_total:	arch private state for MBM total bandwidth
+ * @arch_mbm_local:	arch private state for MBM local bandwidth
  *
  * Members of this structure are accessed via helpers that provide abstraction.
  */
 struct rdt_hw_domain {
 	struct rdt_domain		d_resctrl;
 	u32				*ctrl_val;
+	struct arch_mbm_state		*arch_mbm_total;
+	struct arch_mbm_state		*arch_mbm_local;
 };
 
 static inline struct rdt_hw_domain *resctrl_to_arch_dom(struct rdt_domain *r)
Signature · 1 line
2.30.2
maintainer
#24 lore raw

Re: [PATCH v3 13/21] x86/recstrl: Add per-rmid arch private storage for overflow and chunks

Hi James,

Note the subject line: "x86/recstrl" -> "x86/resctrl"

Quoted 11 lines · James Morse

A renamed __rmid_read() is intended as the function that an architecture agnostic resctrl filesystem driver can use to read a value in bytes from a counter. Currently the function returns the MBM values in chunks directly from hardware. For bandwidth counters the resctrl filesystem uses this to calculate the number of bytes ever seen.

MPAM's scaling of counters can be changed at runtime, reducing the resolution but increasing the range. When this is changed the prev_msr values need to be converted by the architecture code.

Quoted 7 lines

Add an array for per-rmid private storage. The prev_msr and chunks values will move here to allow resctrl_arch_rmid_read() to always return the number of bytes read by this counter without assistance from the filesystem. The values are moved in later patches when the overflow and correction calls are moved into __rmid_read().

Reinette

author reviewer
#25 lore raw

PATCH v3 14/21 x86/recstrl: Allow per-rmid arch private storage to be reset

In reply to James Morse

To abstract the rmid counters into a helper that returns the number of bytes counted, architecture specific per-rmid state is needed.

It needs to be possible to reset this hidden state, as the values may outlive the life of an rmid, or the mount time of the filesystem.

mon_event_read() is called with first = true when an rmid is first allocated in mkdir_mondata_subdir(). Add resctrl_arch_reset_rmid() and call it from __mon_event_count()'s rr->first check.

---
Changes since v1:
* Aded WARN_ON_ONCE() for a case that should never happen.

---
 arch/x86/kernel/cpu/resctrl/internal.h | 18 ++++---------
 arch/x86/kernel/cpu/resctrl/monitor.c  | 35 +++++++++++++++++++++++++-
 include/linux/resctrl.h                | 23 +++++++++++++++++
 3 files changed, 62 insertions(+), 14 deletions(-)
arch/x86/kernel/cpu/resctrl/internal.h +5 -13
index 156d526c6952..726065bc02e4 100644
@@ -22,14 +22,6 @@
 
 #define L2_QOS_CDP_ENABLE		0x01ULL
 
-/*
- * Event IDs are used to program IA32_QM_EVTSEL before reading event
- * counter from IA32_QM_CTR
- */
-#define QOS_L3_OCCUP_EVENT_ID		0x01
-#define QOS_L3_MBM_TOTAL_EVENT_ID	0x02
-#define QOS_L3_MBM_LOCAL_EVENT_ID	0x03
-
 #define CQM_LIMBOCHECK_INTERVAL	1000
 
 #define MBM_CNTR_WIDTH_BASE		24
@@ -73,7 +65,7 @@ DECLARE_STATIC_KEY_FALSE(rdt_mon_enable_key);
  * @list:		entry in &rdt_resource->evt_list
  */
 struct mon_evt {
-	u32			evtid;
+	enum resctrl_event_id	evtid;
 	char			*name;
 	struct list_head	list;
 };
@@ -90,9 +82,9 @@ struct mon_evt {
 union mon_data_bits {
 	void *priv;
 	struct {
-		unsigned int rid	: 10;
-		unsigned int evtid	: 8;
-		unsigned int domid	: 14;
+		unsigned int rid		: 10;
+		enum resctrl_event_id evtid	: 8;
+		unsigned int domid		: 14;
 	} u;
 };
 
@@ -100,7 +92,7 @@ struct rmid_read {
 	struct rdtgroup		*rgrp;
 	struct rdt_resource	*r;
 	struct rdt_domain	*d;
-	int			evtid;
+	enum resctrl_event_id	evtid;
 	bool			first;
 	u64			val;
 };
arch/x86/kernel/cpu/resctrl/monitor.c +34 -1
index 8ae375e29256..431acc3d3eb8 100644
@@ -137,7 +137,37 @@ static inline struct rmid_entry *__rmid_entry(u32 rmid)
 	return entry;
 }
 
-static u64 __rmid_read(u32 rmid, u32 eventid)
+static struct arch_mbm_state *get_arch_mbm_state(struct rdt_hw_domain *hw_dom,
+						 u32 rmid,
+						 enum resctrl_event_id eventid)
+{
+	switch (eventid) {
+	case QOS_L3_OCCUP_EVENT_ID:
+		return NULL;
+	case QOS_L3_MBM_TOTAL_EVENT_ID:
+		return &hw_dom->arch_mbm_total[rmid];
+	case QOS_L3_MBM_LOCAL_EVENT_ID:
+		return &hw_dom->arch_mbm_local[rmid];
+	}
+
+	/* Never expect to get here */
+	WARN_ON_ONCE(1);
+
+	return NULL;
+}
+
+void resctrl_arch_reset_rmid(struct rdt_resource *r, struct rdt_domain *d,
+			     u32 rmid, enum resctrl_event_id eventid)
+{
+	struct rdt_hw_domain *hw_dom = resctrl_to_arch_dom(d);
+	struct arch_mbm_state *am;
+
+	am = get_arch_mbm_state(hw_dom, rmid, eventid);
+	if (am)
+		memset(am, 0, sizeof(*am));
+}
+
+static u64 __rmid_read(u32 rmid, enum resctrl_event_id eventid)
 {
 	u64 val;
 
@@ -291,6 +321,9 @@ static u64 __mon_event_count(u32 rmid, struct rmid_read *rr)
 	struct mbm_state *m;
 	u64 chunks, tval;
 
+	if (rr->first)
+		resctrl_arch_reset_rmid(rr->r, rr->d, rmid, rr->evtid);
+
 	tval = __rmid_read(rmid, rr->evtid);
 	if (tval & (RMID_VAL_ERROR | RMID_VAL_UNAVAIL)) {
 		return tval;
include/linux/resctrl.h +23 -0
index 84e815cb3be6..0b48239f5920 100644
@@ -32,6 +32,16 @@ enum resctrl_conf_type {
 
 #define CDP_NUM_TYPES	(CDP_DATA + 1)
 
+/*
+ * Event IDs, the values match those used to program IA32_QM_EVTSEL before
+ * reading IA32_QM_CTR on RDT systems.
+ */
+enum resctrl_event_id {
+	QOS_L3_OCCUP_EVENT_ID		= 0x01,
+	QOS_L3_MBM_TOTAL_EVENT_ID	= 0x02,
+	QOS_L3_MBM_LOCAL_EVENT_ID	= 0x03,
+};
+
 /**
  * struct resctrl_staged_config - parsed configuration to be applied
  * @new_ctrl:		new ctrl value to be loaded
@@ -210,4 +220,17 @@ u32 resctrl_arch_get_config(struct rdt_resource *r, struct rdt_domain *d,
 int resctrl_online_domain(struct rdt_resource *r, struct rdt_domain *d);
 void resctrl_offline_domain(struct rdt_resource *r, struct rdt_domain *d);
 
+/**
+ * resctrl_arch_reset_rmid() - Reset any private state associated with rmid
+ *			       and eventid.
+ * @r:		The domain's resource.
+ * @d:		The rmid's domain.
+ * @rmid:	The rmid whose counter values should be reset.
+ * @eventid:	The eventid whose counter values should be reset.
+ *
+ * This can be called from any CPU.
+ */
+void resctrl_arch_reset_rmid(struct rdt_resource *r, struct rdt_domain *d,
+			     u32 rmid, enum resctrl_event_id eventid);
+
 #endif /* _RESCTRL_H */
Signature · 1 line
2.30.2
maintainer
#26 lore raw

Re: [PATCH v3 14/21] x86/recstrl: Allow per-rmid arch private storage to be reset

Hi James,

Note the subject line: "x86/recstrl" -> "x86/resctrl"

Quoted 6 lines · James Morse

To abstract the rmid counters into a helper that returns the number of bytes counted, architecture specific per-rmid state is needed.

It needs to be possible to reset this hidden state, as the values may outlive the life of an rmid, or the mount time of the filesystem.

Quoted 6 lines

mon_event_read() is called with first = true when an rmid is first allocated in mkdir_mondata_subdir(). Add resctrl_arch_reset_rmid() and call it from __mon_event_count()'s rr->first check.

Reinette

author reviewer
#27 lore raw

PATCH v3 15/21 x86/resctrl: Abstract __rmid_read()

In reply to James Morse

__rmid_read() selects the specified eventid and returns the counter value from the MSR. The error handling is architecture specific, and handled by the callers, rdtgroup_mondata_show() and __mon_event_count().

Error handling should be handled by architecture specific code, as a different architecture may have different requirements. MPAM's counters can report that they are 'not ready', requiring a second read after a short delay. This should be hidden from resctrl.

Make __rmid_read() the architecture specific function for reading a counter. Rename it resctrl_arch_rmid_read() and move the error handling into it.

---
Changes since v2:
* Capitalisation
* Stray newline restored
* Removed rr->val set to the error value, and replaced it with clearing the the error to hide Unavailable from monitor group reads. (and added a block comment).

Changes since v1:
* Return EINVAL from the impossible case in __mon_event_count() instead of an x86 hardware specific value.

---
 arch/x86/kernel/cpu/resctrl/ctrlmondata.c |  4 +-
 arch/x86/kernel/cpu/resctrl/internal.h    |  1 +
 arch/x86/kernel/cpu/resctrl/monitor.c     | 53 +++++++++++++++--------
 include/linux/resctrl.h                   |  1 +
 4 files changed, 39 insertions(+), 20 deletions(-)
arch/x86/kernel/cpu/resctrl/ctrlmondata.c +2 -2
index ece3a1e0e6f2..d3f7eb2ac14b 100644
@@ -579,9 +579,9 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg)
 
 	mon_event_read(&rr, r, d, rdtgrp, evtid, false);
 
-	if (rr.val & RMID_VAL_ERROR)
+	if (rr.err == -EIO)
 		seq_puts(m, "Error\n");
-	else if (rr.val & RMID_VAL_UNAVAIL)
+	else if (rr.err == -EINVAL)
 		seq_puts(m, "Unavailable\n");
 	else
 		seq_printf(m, "%llu\n", rr.val * hw_res->mon_scale);
arch/x86/kernel/cpu/resctrl/internal.h +1 -0
index 726065bc02e4..e55d1774ce9c 100644
@@ -94,6 +94,7 @@ struct rmid_read {
 	struct rdt_domain	*d;
 	enum resctrl_event_id	evtid;
 	bool			first;
+	int			err;
 	u64			val;
 };
 
arch/x86/kernel/cpu/resctrl/monitor.c +35 -18

105 lines not on this page · raw message

include/linux/resctrl.h +1 -0
index 0b48239f5920..70112dbfa128 100644
@@ -219,6 +219,7 @@ u32 resctrl_arch_get_config(struct rdt_resource *r, struct rdt_domain *d,
 			    u32 closid, enum resctrl_conf_type type);
 int resctrl_online_domain(struct rdt_resource *r, struct rdt_domain *d);
 void resctrl_offline_domain(struct rdt_resource *r, struct rdt_domain *d);
+int resctrl_arch_rmid_read(u32 rmid, enum resctrl_event_id eventid, u64 *res);
 
 /**
  * resctrl_arch_reset_rmid() - Reset any private state associated with rmid
Signature · 1 line
2.30.2
maintainer
#28 lore raw

Re: [PATCH v3 15/21] x86/resctrl: Abstract __rmid_read()

Hi James,

Quoted 14 lines · James Morse

__rmid_read() selects the specified eventid and returns the counter value from the MSR. The error handling is architecture specific, and handled by the callers, rdtgroup_mondata_show() and __mon_event_count().

Error handling should be handled by architecture specific code, as a different architecture may have different requirements. MPAM's counters can report that they are 'not ready', requiring a second read after a short delay. This should be hidden from resctrl.

Make __rmid_read() the architecture specific function for reading a counter. Rename it resctrl_arch_rmid_read() and move the error handling into it.

...

Quoted 19 lines
arch/x86/kernel/cpu/resctrl/monitor.c +3 -3
@@ -167,9 +167,9 @@ void resctrl_arch_reset_rmid(struct rdt_resource *r, struct rdt_domain *d,
 		memset(am, 0, sizeof(*am));
 }
 
-static u64 __rmid_read(u32 rmid, enum resctrl_event_id eventid)
+int resctrl_arch_rmid_read(u32 rmid, enum resctrl_event_id eventid, u64 *val)
 {
-	u64 val;
+	u64 msr_val;
 
 	/*
 	 * As per the SDM, when IA32_QM_EVTSEL.EvtID (bits 7:0) is configured
@@ -180,14 +180,24 @@ static u64 __rmid_read(u32 rmid, enum resctrl_event_id eventid)
 	 * are error bits.
 	 */
 	wrmsr(MSR_IA32_QM_EVTSEL, eventid, rmid);
-	rdmsrl(MSR_IA32_QM_CTR, val);
+	rdmsrl(MSR_IA32_QM_CTR, msr_val);
 

arch/x86/kernel/cpu/resctrl/monitor.c static u64 __rmid_read(u32 rmid, enum resctrl_event_id eventid) · line 193

Quoted 10 lines
arch/x86/kernel/cpu/resctrl/monitor.c +8 -1
-	return val;
+	if (msr_val & RMID_VAL_ERROR)
+		return -EIO;
+	if (msr_val & RMID_VAL_UNAVAIL)
+		return -EINVAL;
+
+	*val = msr_val;
+
+	return 0;
 }

From above we see that resctrl_arch_rmid_read() returns an int that could be -EIO or -EINVAL ...

...

Quoted 8 lines
arch/x86/kernel/cpu/resctrl/monitor.c +1 -1
@@ -319,15 +331,15 @@ static u64 __mon_event_count(u32 rmid, struct rmid_read *rr)
 {
 	struct rdt_hw_resource *hw_res = resctrl_to_arch_res(rr->r);
 	struct mbm_state *m;
-	u64 chunks, tval;
+	u64 chunks, tval = 0;
 
 	if (rr->first)

arch/x86/kernel/cpu/resctrl/monitor.c static u64 __mon_event_count(u32 rmid, struct rmid_read *rr) · line 342

Quoted 10 lines
arch/x86/kernel/cpu/resctrl/monitor.c +4 -4
 		resctrl_arch_reset_rmid(rr->r, rr->d, rmid, rr->evtid);
 
-	tval = __rmid_read(rmid, rr->evtid);
-	if (tval & (RMID_VAL_ERROR | RMID_VAL_UNAVAIL)) {
-		return tval;
-	}
+	rr->err = resctrl_arch_rmid_read(rmid, rr->evtid, &tval);
+	if (rr->err)
+		return rr->err;
+

Setting rr->err, an int, to the return of resctrl_arch_rmid_read() is ok and can handle the negative error codes, but returning it here means that __mon_event_count()'s return type should be changed,
it is currently u64.

arch/x86/kernel/cpu/resctrl/monitor.c static u64 __mon_event_count(u32 rmid, struct rmid_read *rr) · line 358

Quoted 9 lines
arch/x86/kernel/cpu/resctrl/monitor.c +1 -1
 	switch (rr->evtid) {
 	case QOS_L3_OCCUP_EVENT_ID:
 		rr->val += tval;
@@ -343,7 +355,7 @@ static u64 __mon_event_count(u32 rmid, struct rmid_read *rr)
 		 * Code would never reach here because an invalid
 		 * event id would fail the __rmid_read.
 		 */
-		return RMID_VAL_ERROR;
+		return -EINVAL;

Same here ... __mon_event_count() is u64 still ...

arch/x86/kernel/cpu/resctrl/monitor.c void mon_event_count(void *info) · line 433

Quoted 7 lines
arch/x86/kernel/cpu/resctrl/monitor.c +0 -0
 	}
 
 	if (rr->first) {
@@ -419,9 +431,14 @@ void mon_event_count(void *info)
 		}
 	}
 

Also take care here ... ret_val in mon_event_count() is still u64 while __mon_event_count() attempts to return negative errors.

arch/x86/kernel/cpu/resctrl/monitor.c void mon_event_count(void *info) · line 439

Quoted 9 lines
arch/x86/kernel/cpu/resctrl/monitor.c +6 -3
-	/* Report error if none of rmid_reads are successful */
-	if (ret_val)
-		rr->val = ret_val;
+	/*
+	 * __mon_event_count() calls for newly created monitor groups may
+	 * report -EINVAL/Unavailable if the monitor hasn't seen any traffic.
+	 * If the first call for the control group succeed, discard any error
+	 * set by reads of monitor groups.
+	 */

Additionally, if the first call fails, but a following read of monitor group succeeds then the first call's error is discarded.

How about if the last sentence is replaced with:
"Discard error if any of the monitor event reads succeeded."

Quoted 10 lines
arch/x86/kernel/cpu/resctrl/monitor.c +2 -0
+	if (ret_val == 0)
+		rr->err = 0;
 }
 
 /*
include/linux/resctrl.h +0 -0
index 0b48239f5920..70112dbfa128 100644

include/linux/resctrl.h u32 resctrl_arch_get_config(struct rdt_resource *r, struct rdt_domain *d, · line 225

Quoted 7 lines
include/linux/resctrl.h +1 -0
@@ -219,6 +219,7 @@ u32 resctrl_arch_get_config(struct rdt_resource *r, struct rdt_domain *d,
 			    u32 closid, enum resctrl_conf_type type);
 int resctrl_online_domain(struct rdt_resource *r, struct rdt_domain *d);
 void resctrl_offline_domain(struct rdt_resource *r, struct rdt_domain *d);
+int resctrl_arch_rmid_read(u32 rmid, enum resctrl_event_id eventid, u64 *res);
 
 /**
  * resctrl_arch_reset_rmid() - Reset any private state associated with rmid

Reinette

author reviewer
#29 lore raw

Re: [PATCH v3 15/21] x86/resctrl: Abstract __rmid_read()

Hi Reinette,

Quoted 47 lines · Reinette Chatre
Quoted 20 lines · James Morse

__rmid_read() selects the specified eventid and returns the counter value from the MSR. The error handling is architecture specific, and handled by the callers, rdtgroup_mondata_show() and __mon_event_count().

Error handling should be handled by architecture specific code, as a different architecture may have different requirements. MPAM's counters can report that they are 'not ready', requiring a second read after a short delay. This should be hidden from resctrl.

Make __rmid_read() the architecture specific function for reading a counter. Rename it resctrl_arch_rmid_read() and move the error handling into it.

arch/x86/kernel/cpu/resctrl/monitor.c +1 -1
@@ -180,14 +180,24 @@ static u64 __rmid_read(u32 rmid, enum resctrl_event_id eventid)
 	 * are error bits.
 	 */
 	wrmsr(MSR_IA32_QM_EVTSEL, eventid, rmid);
-	rdmsrl(MSR_IA32_QM_CTR, val);
+	rdmsrl(MSR_IA32_QM_CTR, msr_val);
 

arch/x86/kernel/cpu/resctrl/monitor.c static u64 __rmid_read(u32 rmid, enum resctrl_event_id eventid) · line 193

Quoted 10 lines
arch/x86/kernel/cpu/resctrl/monitor.c +8 -1
-	return val;
+	if (msr_val & RMID_VAL_ERROR)
+		return -EIO;
+	if (msr_val & RMID_VAL_UNAVAIL)
+		return -EINVAL;
+
+	*val = msr_val;
+
+	return 0;
 }

From above we see that resctrl_arch_rmid_read() returns an int that could be -EIO or -EINVAL ...

...

Quoted 10 lines
arch/x86/kernel/cpu/resctrl/monitor.c +1 -1
@@ -319,15 +331,15 @@ static u64 __mon_event_count(u32 rmid, struct rmid_read *rr)
 {
 	struct rdt_hw_resource *hw_res = resctrl_to_arch_res(rr->r);
 	struct mbm_state *m;
-	u64 chunks, tval;
+	u64 chunks, tval = 0;
 
 	if (rr->first)
 		resctrl_arch_reset_rmid(rr->r, rr->d, rmid, rr->evtid);
 
Quoted 13 lines

arch/x86/kernel/cpu/resctrl/monitor.c static u64 __mon_event_count(u32 rmid, struct rmid_read *rr) · line 342

Quoted 8 lines
arch/x86/kernel/cpu/resctrl/monitor.c +4 -4
-	tval = __rmid_read(rmid, rr->evtid);
-	if (tval & (RMID_VAL_ERROR | RMID_VAL_UNAVAIL)) {
-		return tval;
-	}
+	rr->err = resctrl_arch_rmid_read(rmid, rr->evtid, &tval);
+	if (rr->err)
+		return rr->err;
+

Setting rr->err, an int, to the return of resctrl_arch_rmid_read() is ok and can handle the negative error codes, but returning it here means that __mon_event_count()'s return type should be changed,
it is currently u64.

Good point. Fixed.

Quoted 7 lines

Review void mon_event_count(void *info) · line 433

Quoted 4 lines
(quoted diff) +0 -0
@@ -419,9 +431,14 @@ void mon_event_count(void *info)
 		}
 	}
 

Also take care here ... ret_val in mon_event_count() is still u64 while __mon_event_count() attempts to return negative errors.

(yup, fixed)

Quoted 13 lines

arch/x86/kernel/cpu/resctrl/monitor.c void mon_event_count(void *info) · line 439

Quoted 9 lines
arch/x86/kernel/cpu/resctrl/monitor.c +6 -3
-	/* Report error if none of rmid_reads are successful */
-	if (ret_val)
-		rr->val = ret_val;
+	/*
+	 * __mon_event_count() calls for newly created monitor groups may
+	 * report -EINVAL/Unavailable if the monitor hasn't seen any traffic.
+	 * If the first call for the control group succeed, discard any error
+	 * set by reads of monitor groups.
+	 */

Additionally, if the first call fails, but a following read of monitor group succeeds then the first call's error is discarded.

Quoted 2 lines

How about if the last sentence is replaced with:
"Discard error if any of the monitor event reads succeeded."

Sure,

Thanks,

James

author reviewer
#30 lore raw

PATCH v3 16/21 x86/resctrl: Pass the required parameters into resctrl_arch_rmid_read()

In reply to James Morse

resctrl_arch_rmid_read() is intended as the function that an architecture agnostic resctrl filesystem driver can use to read a value in bytes from a hardware register. Currently the function returns the MBM values in chunks directly from hardware.

To convert this to bytes, some correction and overflow calculations are needed. These depend on the resource and domain structures. Overflow detection requires the old chunks value. None of this is available to resctrl_arch_rmid_read(). MPAM requires the resource and domain structures to find the MMIO device that holds the registers.

Pass the resource and domain to resctrl_arch_rmid_read(). This make rmid_dirty() too big, instead merge it with its only caller, the name is kept as a local variable.

---
Changes since v2:
* Typos.
* Kerneldoc fixes.

This is all a little noisy for __mon_event_count(), as the switch statement work is now before the resctrl_arch_rmid_read() call.

---
 arch/x86/kernel/cpu/resctrl/monitor.c | 31 +++++++++++++++------------
 include/linux/resctrl.h               | 16 +++++++++++++-
 2 files changed, 32 insertions(+), 15 deletions(-)
arch/x86/kernel/cpu/resctrl/monitor.c +17 -14
index b6ad290fda8d..277c22f8c976 100644
@@ -167,10 +167,14 @@ void resctrl_arch_reset_rmid(struct rdt_resource *r, struct rdt_domain *d,
 		memset(am, 0, sizeof(*am));
 }
 
-int resctrl_arch_rmid_read(u32 rmid, enum resctrl_event_id eventid, u64 *val)
+int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain *d,
+			   u32 rmid, enum resctrl_event_id eventid, u64 *val)
 {
 	u64 msr_val;
 
+	if (!cpumask_test_cpu(smp_processor_id(), &d->cpu_mask))
+		return -EINVAL;
+
 	/*
 	 * As per the SDM, when IA32_QM_EVTSEL.EvtID (bits 7:0) is configured
 	 * with a valid event code for supported resource type and the bits
@@ -192,16 +196,6 @@ int resctrl_arch_rmid_read(u32 rmid, enum resctrl_event_id eventid, u64 *val)
 	return 0;
 }
 
-static bool rmid_dirty(struct rmid_entry *entry)
-{
-	u64 val = 0;
-
-	if (resctrl_arch_rmid_read(entry->rmid, QOS_L3_OCCUP_EVENT_ID, &val))
-		return true;
-
-	return val >= resctrl_cqm_threshold;
-}
-
 /*
  * Check the RMIDs that are marked as busy for this domain. If the
  * reported LLC occupancy is below the threshold clear the busy bit and
@@ -213,6 +207,8 @@ void __check_limbo(struct rdt_domain *d, bool force_free)
 	struct rmid_entry *entry;
 	struct rdt_resource *r;
 	u32 crmid = 1, nrmid;
+	bool rmid_dirty;
+	u64 val = 0;
 
 	r = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl;
 
@@ -228,7 +224,14 @@ void __check_limbo(struct rdt_domain *d, bool force_free)
 			break;
 
 		entry = __rmid_entry(nrmid);
-		if (force_free || !rmid_dirty(entry)) {
+
+		if (resctrl_arch_rmid_read(r, d, entry->rmid,
+					   QOS_L3_OCCUP_EVENT_ID, &val))
+			rmid_dirty = true;
+		else
+			rmid_dirty = (val >= resctrl_cqm_threshold);
+
+		if (force_free || !rmid_dirty) {
 			clear_bit(entry->rmid, d->rmid_busy_llc);
 			if (!--entry->busy) {
 				rmid_limbo_count--;
@@ -278,7 +281,7 @@ static void add_rmid_to_limbo(struct rmid_entry *entry)
 	cpu = get_cpu();
 	list_for_each_entry(d, &r->domains, list) {
 		if (cpumask_test_cpu(cpu, &d->cpu_mask)) {
-			err = resctrl_arch_rmid_read(entry->rmid,
+			err = resctrl_arch_rmid_read(r, d, entry->rmid,
 						     QOS_L3_OCCUP_EVENT_ID,
 						     &val);
 			if (err || val <= resctrl_cqm_threshold)
@@ -336,7 +339,7 @@ static u64 __mon_event_count(u32 rmid, struct rmid_read *rr)
 	if (rr->first)
 		resctrl_arch_reset_rmid(rr->r, rr->d, rmid, rr->evtid);
 
-	rr->err = resctrl_arch_rmid_read(rmid, rr->evtid, &tval);
+	rr->err = resctrl_arch_rmid_read(rr->r, rr->d, rmid, rr->evtid, &tval);
 	if (rr->err)
 		return rr->err;
 
include/linux/resctrl.h +15 -1
index 70112dbfa128..5d57e2610c79 100644
@@ -219,7 +219,21 @@ u32 resctrl_arch_get_config(struct rdt_resource *r, struct rdt_domain *d,
 			    u32 closid, enum resctrl_conf_type type);
 int resctrl_online_domain(struct rdt_resource *r, struct rdt_domain *d);
 void resctrl_offline_domain(struct rdt_resource *r, struct rdt_domain *d);
-int resctrl_arch_rmid_read(u32 rmid, enum resctrl_event_id eventid, u64 *res);
+
+/**
+ * resctrl_arch_rmid_read() - Read the eventid counter corresponding to rmid
+ *			      for this resource and domain.
+ * @r:			resource that the counter should be read from.
+ * @d:			domain that the counter should be read from.
+ * @rmid:		rmid of the counter to read.
+ * @eventid:		eventid to read, e.g. L3 occupancy.
+ * @val:		result of the counter read in chunks.
+ *
+ * Return:
+ * 0 on success, or -EIO, -EINVAL etc on error.
+ */
+int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain *d,
+			   u32 rmid, enum resctrl_event_id eventid, u64 *val);
 
 /**
  * resctrl_arch_reset_rmid() - Reset any private state associated with rmid
Signature · 1 line
2.30.2
#31 lore raw

Re: [PATCH v3 16/21] x86/resctrl: Pass the required parameters into resctrl_arch_rmid_read()

Quoted 5 lines · James Morse

resctrl_arch_rmid_read() is intended as the function that an architecture agnostic resctrl filesystem driver can use to read a value in bytes from a hardware register. Currently the function returns the MBM values in chunks directly from hardware.

Quoted 8 lines

To convert this to bytes, some correction and overflow calculations are needed. These depend on the resource and domain structures. Overflow detection requires the old chunks value. None of this is available to resctrl_arch_rmid_read(). MPAM requires the resource and domain structures to find the MMIO device that holds the registers.

Pass the resource and domain to resctrl_arch_rmid_read(). This make

s/make/makes/

Quoted 2 lines

rmid_dirty() too big, instead merge it with its only caller, the name is kept as a local variable.

... big. Instead, merge it with its only caller, and the name...

Quoted 19 lines

---
Changes since v2:
* Typos.
* Kerneldoc fixes.

This is all a little noisy for __mon_event_count(), as the switch statement work is now before the resctrl_arch_rmid_read() call.

---
 arch/x86/kernel/cpu/resctrl/monitor.c | 31 +++++++++++++++------------
 include/linux/resctrl.h               | 16 +++++++++++++-
 2 files changed, 32 insertions(+), 15 deletions(-)
arch/x86/kernel/cpu/resctrl/monitor.c +0 -0
index b6ad290fda8d..277c22f8c976 100644

arch/x86/kernel/cpu/resctrl/monitor.c void resctrl_arch_reset_rmid(struct rdt_resource *r, struct rdt_domain *d, · line 175

Quoted 10 lines
arch/x86/kernel/cpu/resctrl/monitor.c +3 -1
@@ -167,10 +167,14 @@ void resctrl_arch_reset_rmid(struct rdt_resource *r, struct rdt_domain *d,
 		memset(am, 0, sizeof(*am));
 }
 
-int resctrl_arch_rmid_read(u32 rmid, enum resctrl_event_id eventid, u64 *val)
+int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain *d,
+			   u32 rmid, enum resctrl_event_id eventid, u64 *val)
 {
 	u64 msr_val;
 
+	if (!cpumask_test_cpu(smp_processor_id(), &d->cpu_mask))

We already tested this and disabled preemption. (At least from some caller AFAICT from this patch.) I'd assume we'd want the fs code to handle preemption disable and checking cpumask. In any case, it should be clear what guarantees resctrl_arch_rmid_read() has.

Quoted 9 lines
arch/x86/kernel/cpu/resctrl/monitor.c +1 -1
@@ -278,7 +281,7 @@ static void add_rmid_to_limbo(struct rmid_entry *entry)
 	cpu = get_cpu();
 	list_for_each_entry(d, &r->domains, list) {
 		if (cpumask_test_cpu(cpu, &d->cpu_mask)) {
-			err = resctrl_arch_rmid_read(entry->rmid,
+			err = resctrl_arch_rmid_read(r, d, entry->rmid,
 						     QOS_L3_OCCUP_EVENT_ID,
 						     &val);
 			if (err || val <= resctrl_cqm_threshold)
author reviewer
#32 lore raw

Re: [PATCH v3 16/21] x86/resctrl: Pass the required parameters into resctrl_arch_rmid_read()

Hi Rob,

Quoted 27 lines · Rob Herring
Quoted 26 lines · James Morse

resctrl_arch_rmid_read() is intended as the function that an architecture agnostic resctrl filesystem driver can use to read a value in bytes from a hardware register. Currently the function returns the MBM values in chunks directly from hardware.

To convert this to bytes, some correction and overflow calculations are needed. These depend on the resource and domain structures. Overflow detection requires the old chunks value. None of this is available to resctrl_arch_rmid_read(). MPAM requires the resource and domain structures to find the MMIO device that holds the registers.

arch/x86/kernel/cpu/resctrl/monitor.c +2 -1
index b6ad290fda8d..277c22f8c976 100644
@@ -167,10 +167,14 @@ void resctrl_arch_reset_rmid(struct rdt_resource *r, struct rdt_domain *d,
 		memset(am, 0, sizeof(*am));
 }
 
-int resctrl_arch_rmid_read(u32 rmid, enum resctrl_event_id eventid, u64 *val)
+int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain *d,
+			   u32 rmid, enum resctrl_event_id eventid, u64 *val)
 {
 	u64 msr_val;
 
Quoted 6 lines

arch/x86/kernel/cpu/resctrl/monitor.c void resctrl_arch_reset_rmid(struct rdt_resource *r, struct rdt_domain *d, · line 175

Quoted 1 line
arch/x86/kernel/cpu/resctrl/monitor.c +1 -0
+	if (!cpumask_test_cpu(smp_processor_id(), &d->cpu_mask))

We already tested this and disabled preemption. (At least from some caller AFAICT from this patch.) I'd assume we'd want the fs code to handle preemption disable and checking cpumask. In any case, it should be clear what guarantees resctrl_arch_rmid_read() has.

This started as a lockdep warning for things that don't matter on x86, but would break arm64. Combined with some half baked thinking about RT.

I'll add a comment, (in the header file).

It needs to be called on the correct CPU, but from process context as MPAM needs to send IPI from here. I didn't want to add a preempt_disable() lockdep annotation here as its not pre-emption that's the problem, but migration. cqm_handle_limbo() and mbm_handle_overflow() are the two main routes in here, and they both use schedule_delayed_work_on() to target the 'correct' CPU.

Thanks,

James

author reviewer
#33 lore raw

PATCH v3 17/21 x86/resctrl: Move mbm_overflow_count() into resctrl_arch_rmid_read()

In reply to James Morse

resctrl_arch_rmid_read() is intended as the function that an architecture agnostic resctrl filesystem driver can use to read a value in bytes from a counter. Currently the function returns the MBM values in chunks directly from hardware. When reading a bandwidth counter, mbm_overflow_count() must be used to correct for any possible overflow.

mbm_overflow_count() is architecture specific, its behaviour should be part of resctrl_arch_rmid_read().

Move the mbm_overflow_count() calls into resctrl_arch_rmid_read(). This allows the resctrl filesystems's prev_msr to be removed in favour of the architecture private version.

---
 arch/x86/kernel/cpu/resctrl/internal.h |  2 --
 arch/x86/kernel/cpu/resctrl/monitor.c  | 35 +++++++++++++++-----------
 2 files changed, 20 insertions(+), 17 deletions(-)
arch/x86/kernel/cpu/resctrl/internal.h +0 -2
index e55d1774ce9c..5ab8b448fb7e 100644
@@ -281,7 +281,6 @@ struct rftype {
 /**
  * struct mbm_state - status for each MBM counter in each domain
  * @chunks:	Total data moved (multiply by rdt_group.mon_scale to get bytes)
- * @prev_msr:	Value of IA32_QM_CTR for this RMID last time we read it
  * @prev_bw_chunks: Previous chunks value read when for bandwidth calculation
  * @prev_bw:	The most recent bandwidth in MBps
  * @delta_bw:	Difference between the current and previous bandwidth
@@ -289,7 +288,6 @@ struct rftype {
  */
 struct mbm_state {
 	u64	chunks;
-	u64	prev_msr;
 	u64	prev_bw_chunks;
 	u32	prev_bw;
 	u32	delta_bw;
arch/x86/kernel/cpu/resctrl/monitor.c +20 -15
index 277c22f8c976..e04bc97c710d 100644
@@ -167,9 +167,20 @@ void resctrl_arch_reset_rmid(struct rdt_resource *r, struct rdt_domain *d,
 		memset(am, 0, sizeof(*am));
 }
 
+static u64 mbm_overflow_count(u64 prev_msr, u64 cur_msr, unsigned int width)
+{
+	u64 shift = 64 - width, chunks;
+
+	chunks = (cur_msr << shift) - (prev_msr << shift);
+	return chunks >> shift;
+}
+
 int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain *d,
 			   u32 rmid, enum resctrl_event_id eventid, u64 *val)
 {
+	struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r);
+	struct rdt_hw_domain *hw_dom = resctrl_to_arch_dom(d);
+	struct arch_mbm_state *am;
 	u64 msr_val;
 
 	if (!cpumask_test_cpu(smp_processor_id(), &d->cpu_mask))
@@ -191,7 +202,13 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain *d,
 	if (msr_val & RMID_VAL_UNAVAIL)
 		return -EINVAL;
 
-	*val = msr_val;
+	am = get_arch_mbm_state(hw_dom, rmid, eventid);
+	if (am) {
+		*val = mbm_overflow_count(am->prev_msr, msr_val, hw_res->mbm_width);
+		am->prev_msr = msr_val;
+	} else {
+		*val = msr_val;
+	}
 
 	return 0;
 }
@@ -322,19 +339,10 @@ void free_rmid(u32 rmid)
 		list_add_tail(&entry->list, &rmid_free_lru);
 }
 
-static u64 mbm_overflow_count(u64 prev_msr, u64 cur_msr, unsigned int width)
-{
-	u64 shift = 64 - width, chunks;
-
-	chunks = (cur_msr << shift) - (prev_msr << shift);
-	return chunks >> shift;
-}
-
 static u64 __mon_event_count(u32 rmid, struct rmid_read *rr)
 {
-	struct rdt_hw_resource *hw_res = resctrl_to_arch_res(rr->r);
 	struct mbm_state *m;
-	u64 chunks, tval = 0;
+	u64 tval = 0;
 
 	if (rr->first)
 		resctrl_arch_reset_rmid(rr->r, rr->d, rmid, rr->evtid);
@@ -363,13 +371,10 @@ static u64 __mon_event_count(u32 rmid, struct rmid_read *rr)
 
 	if (rr->first) {
 		memset(m, 0, sizeof(struct mbm_state));
-		m->prev_msr = tval;
 		return 0;
 	}
 
-	chunks = mbm_overflow_count(m->prev_msr, tval, hw_res->mbm_width);
-	m->chunks += chunks;
-	m->prev_msr = tval;
+	m->chunks += tval;
 
 	rr->val += get_corrected_mbm_count(rmid, m->chunks);
 
Signature · 1 line
2.30.2
author reviewer
#34 lore raw

PATCH v3 18/21 x86/resctrl: Move get_corrected_mbm_count() into resctrl_arch_rmid_read()

In reply to James Morse

resctrl_arch_rmid_read() is intended as the function that an architecture agnostic resctrl filesystem driver can use to read a value in bytes from a counter. Currently the function returns the MBM values in chunks directly from hardware. When reading a bandwidth counter, get_corrected_mbm_count() must be used to correct the value read.

get_corrected_mbm_count() is architecture specific, this work should be done in resctrl_arch_rmid_read().

Move the function calls. This allows the resctrl filesystems's chunks value to be removed in favour of the architecture private version.

---
 arch/x86/kernel/cpu/resctrl/internal.h | 4 ++--
 arch/x86/kernel/cpu/resctrl/monitor.c  | 8 ++++----
 2 files changed, 6 insertions(+), 6 deletions(-)
arch/x86/kernel/cpu/resctrl/internal.h +2 -2
index 5ab8b448fb7e..c8d52fbee8cd 100644
@@ -280,14 +280,12 @@ struct rftype {
 
 /**
  * struct mbm_state - status for each MBM counter in each domain
- * @chunks:	Total data moved (multiply by rdt_group.mon_scale to get bytes)
  * @prev_bw_chunks: Previous chunks value read when for bandwidth calculation
  * @prev_bw:	The most recent bandwidth in MBps
  * @delta_bw:	Difference between the current and previous bandwidth
  * @delta_comp:	Indicates whether to compute the delta_bw
  */
 struct mbm_state {
-	u64	chunks;
 	u64	prev_bw_chunks;
 	u32	prev_bw;
 	u32	delta_bw;
@@ -297,10 +295,12 @@ struct mbm_state {
 /**
  * struct arch_mbm_state - values used to compute resctrl_arch_rmid_read()s
  *			   return value.
+ * @chunks:	Total data moved (multiply by rdt_group.mon_scale to get bytes)
  * @prev_msr:	Value of IA32_QM_CTR last time it was read for the RMID used to
  *		find this struct.
  */
 struct arch_mbm_state {
+	u64	chunks;
 	u64	prev_msr;
 };
 
arch/x86/kernel/cpu/resctrl/monitor.c +4 -4
index e04bc97c710d..e89ae648046b 100644
@@ -204,7 +204,9 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain *d,
 
 	am = get_arch_mbm_state(hw_dom, rmid, eventid);
 	if (am) {
-		*val = mbm_overflow_count(am->prev_msr, msr_val, hw_res->mbm_width);
+		am->chunks += mbm_overflow_count(am->prev_msr, msr_val,
+						 hw_res->mbm_width);
+		*val = get_corrected_mbm_count(rmid, am->chunks);
 		am->prev_msr = msr_val;
 	} else {
 		*val = msr_val;
@@ -374,9 +376,7 @@ static u64 __mon_event_count(u32 rmid, struct rmid_read *rr)
 		return 0;
 	}
 
-	m->chunks += tval;
-
-	rr->val += get_corrected_mbm_count(rmid, m->chunks);
+	rr->val += tval;
 
 	return 0;
 }
Signature · 1 line
2.30.2
author reviewer
#35 lore raw

PATCH v3 19/21 x86/resctrl: Rename and change the units of resctrl_cqm_threshold

In reply to James Morse

resctrl_cqm_threshold is stored in a hardware specific chunk size, but exposed to user-space as bytes.

This means the filesystem parts of resctrl need to know how the hardware counts, to convert the user provided byte value to chunks. The interface between the architecture's resctrl code and the filesystem ought to treat everything as bytes.

Change the unit of resctrl_cqm_threshold to bytes. resctrl_arch_rmid_read() still returns its value in chunks, so this needs converting to bytes. As all the callers have been touched, rename the variable to resctrl_rmid_realloc_threshold, which describes what the value is for.

---
 arch/x86/kernel/cpu/resctrl/internal.h |  1 -
 arch/x86/kernel/cpu/resctrl/monitor.c  | 34 ++++++++++++--------------
 arch/x86/kernel/cpu/resctrl/rdtgroup.c |  9 ++-----
 include/linux/resctrl.h                |  2 ++
 4 files changed, 20 insertions(+), 26 deletions(-)
arch/x86/kernel/cpu/resctrl/internal.h +0 -1
index c8d52fbee8cd..e26a4d67e204 100644
@@ -98,7 +98,6 @@ struct rmid_read {
 	u64			val;
 };
 
-extern unsigned int resctrl_cqm_threshold;
 extern bool rdt_alloc_capable;
 extern bool rdt_mon_capable;
 extern unsigned int rdt_mon_features;
arch/x86/kernel/cpu/resctrl/monitor.c +16 -18
index e89ae648046b..e91d9a7024a2 100644
@@ -37,8 +37,8 @@ static LIST_HEAD(rmid_free_lru);
  * @rmid_limbo_count     count of currently unused but (potentially)
  *     dirty RMIDs.
  *     This counts RMIDs that no one is currently using but that
- *     may have a occupancy value > intel_cqm_threshold. User can change
- *     the threshold occupancy value.
+ *     may have a occupancy value > resctrl_rmid_realloc_threshold. User can
+ *     change the threshold occupancy value.
  */
 static unsigned int rmid_limbo_count;
 
@@ -59,10 +59,10 @@ bool rdt_mon_capable;
 unsigned int rdt_mon_features;
 
 /*
- * This is the threshold cache occupancy at which we will consider an
+ * This is the threshold cache occupancy in bytes at which we will consider an
  * RMID available for re-allocation.
  */
-unsigned int resctrl_cqm_threshold;
+unsigned int resctrl_rmid_realloc_threshold;
 
 #define CF(cf)	((unsigned long)(1048576 * (cf) + 0.5))
 
@@ -223,14 +223,13 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain *d,
  */
 void __check_limbo(struct rdt_domain *d, bool force_free)
 {
+	struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl;
+	struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r);
 	struct rmid_entry *entry;
-	struct rdt_resource *r;
 	u32 crmid = 1, nrmid;
 	bool rmid_dirty;
 	u64 val = 0;
 
-	r = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl;
-
 	/*
 	 * Skip RMID 0 and start from RMID 1 and check all the RMIDs that
 	 * are marked as busy for occupancy < threshold. If the occupancy
@@ -245,10 +244,12 @@ void __check_limbo(struct rdt_domain *d, bool force_free)
 		entry = __rmid_entry(nrmid);
 
 		if (resctrl_arch_rmid_read(r, d, entry->rmid,
-					   QOS_L3_OCCUP_EVENT_ID, &val))
+					   QOS_L3_OCCUP_EVENT_ID, &val)) {
 			rmid_dirty = true;
-		else
-			rmid_dirty = (val >= resctrl_cqm_threshold);
+		} else {
+			val *= hw_res->mon_scale;
+			rmid_dirty = (val >= resctrl_rmid_realloc_threshold);
+		}
 
 		if (force_free || !rmid_dirty) {
 			clear_bit(entry->rmid, d->rmid_busy_llc);
@@ -289,13 +290,12 @@ int alloc_rmid(void)
 
 static void add_rmid_to_limbo(struct rmid_entry *entry)
 {
-	struct rdt_resource *r;
+	struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl;
+	struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r);
 	struct rdt_domain *d;
 	int cpu, err;
 	u64 val = 0;
 
-	r = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl;
-
 	entry->busy = 0;
 	cpu = get_cpu();
 	list_for_each_entry(d, &r->domains, list) {
@@ -303,7 +303,8 @@ static void add_rmid_to_limbo(struct rmid_entry *entry)
 			err = resctrl_arch_rmid_read(r, d, entry->rmid,
 						     QOS_L3_OCCUP_EVENT_ID,
 						     &val);
-			if (err || val <= resctrl_cqm_threshold)
+			val *= hw_res->mon_scale;
+			if (err || val <= resctrl_rmid_realloc_threshold)
 				continue;
 		}
 
@@ -762,10 +763,7 @@ int rdt_get_mon_l3_config(struct rdt_resource *r)
 	 *
 	 * For a 35MB LLC and 56 RMIDs, this is ~1.8% of the LLC.
 	 */
-	resctrl_cqm_threshold = cl_size * 1024 / r->num_rmid;
-
-	/* h/w works in units of "boot_cpu_data.x86_cache_occ_scale" */
-	resctrl_cqm_threshold /= hw_res->mon_scale;
+	resctrl_rmid_realloc_threshold = cl_size * 1024 / r->num_rmid;
 
 	ret = dom_data_init(r);
 	if (ret)
arch/x86/kernel/cpu/resctrl/rdtgroup.c +2 -7
index 7ec089d72ab7..93b3697027df 100644
@@ -1030,10 +1030,7 @@ static int rdt_delay_linear_show(struct kernfs_open_file *of,
 static int max_threshold_occ_show(struct kernfs_open_file *of,
 				  struct seq_file *seq, void *v)
 {
-	struct rdt_resource *r = of->kn->parent->priv;
-	struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r);
-
-	seq_printf(seq, "%u\n", resctrl_cqm_threshold * hw_res->mon_scale);
+	seq_printf(seq, "%u\n", resctrl_rmid_realloc_threshold);
 
 	return 0;
 }
@@ -1055,7 +1052,6 @@ static int rdt_thread_throttle_mode_show(struct kernfs_open_file *of,
 static ssize_t max_threshold_occ_write(struct kernfs_open_file *of,
 				       char *buf, size_t nbytes, loff_t off)
 {
-	struct rdt_hw_resource *hw_res;
 	unsigned int bytes;
 	int ret;
 
@@ -1066,8 +1062,7 @@ static ssize_t max_threshold_occ_write(struct kernfs_open_file *of,
 	if (bytes > (boot_cpu_data.x86_cache_size * 1024))
 		return -EINVAL;
 
-	hw_res = resctrl_to_arch_res(of->kn->parent->priv);
-	resctrl_cqm_threshold = bytes / hw_res->mon_scale;
+	resctrl_rmid_realloc_threshold = bytes;
 
 	return nbytes;
 }
include/linux/resctrl.h +2 -0
index 5d57e2610c79..c79a180e578c 100644
@@ -248,4 +248,6 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain *d,
 void resctrl_arch_reset_rmid(struct rdt_resource *r, struct rdt_domain *d,
 			     u32 rmid, enum resctrl_event_id eventid);
 
+extern unsigned int resctrl_rmid_realloc_threshold;
+
 #endif /* _RESCTRL_H */
Signature · 1 line
2.30.2
maintainer
#36 lore raw

Re: [PATCH v3 19/21] x86/resctrl: Rename and change the units of resctrl_cqm_threshold

Hi James,

Quoted 14 lines · James Morse

resctrl_cqm_threshold is stored in a hardware specific chunk size, but exposed to user-space as bytes.

This means the filesystem parts of resctrl need to know how the hardware counts, to convert the user provided byte value to chunks. The interface between the architecture's resctrl code and the filesystem ought to treat everything as bytes.

Change the unit of resctrl_cqm_threshold to bytes. resctrl_arch_rmid_read() still returns its value in chunks, so this needs converting to bytes. As all the callers have been touched, rename the variable to resctrl_rmid_realloc_threshold, which describes what the value is for.

...

Quoted 18 lines
arch/x86/kernel/cpu/resctrl/monitor.c +1 -4
@@ -762,10 +763,7 @@ int rdt_get_mon_l3_config(struct rdt_resource *r)
 	 *
 	 * For a 35MB LLC and 56 RMIDs, this is ~1.8% of the LLC.
 	 */
-	resctrl_cqm_threshold = cl_size * 1024 / r->num_rmid;
-
-	/* h/w works in units of "boot_cpu_data.x86_cache_occ_scale" */
-	resctrl_cqm_threshold /= hw_res->mon_scale;
+	resctrl_rmid_realloc_threshold = cl_size * 1024 / r->num_rmid;
 
 	ret = dom_data_init(r);
 	if (ret)
arch/x86/kernel/cpu/resctrl/rdtgroup.c +0 -0
index 7ec089d72ab7..93b3697027df 100644
@@ -1030,10 +1030,7 @@ static int rdt_delay_linear_show(struct kernfs_open_file *of,
 static int max_threshold_occ_show(struct kernfs_open_file *of,

arch/x86/kernel/cpu/resctrl/rdtgroup.c static int rdt_delay_linear_show(struct kernfs_open_file *of, · line 1036

Quoted 10 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +1 -4
 				  struct seq_file *seq, void *v)
 {
-	struct rdt_resource *r = of->kn->parent->priv;
-	struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r);
-
-	seq_printf(seq, "%u\n", resctrl_cqm_threshold * hw_res->mon_scale);
+	seq_printf(seq, "%u\n", resctrl_rmid_realloc_threshold);
 
 	return 0;
 }

This change has some user visible impact that I am still digesting but thought that I would share for your consideration.

As seen in the above two snippets, the original code did:

resctrl_cqm_threshold /= hw_res->mon_scale; /* resctrl_cqm_threshold used internally */

resctrl_cqm_threshold * hw_res->mon_scale; /* this is displayed to user */

The original loss due to truncation during the division is not recovered when the value is displayed to the user the user may see significant differences before and after this patch.

I tried this out on a system with a large cache and the before and after information is significant:
Before this patch:
info/L3_MON/max_threshold_occupancy:147456

After this patch:
info/L3_MON/max_threshold_occupancy:196608

As I understand this change indeed represents the information more accurately but I found it noteworthy that this is not just a simple "change the units" and may thus have broader impact and may indeed result in different behavior that should be considered.

Reinette

author reviewer
#37 lore raw

Re: [PATCH v3 19/21] x86/resctrl: Rename and change the units of resctrl_cqm_threshold

Hi Reinette,

Quoted 57 lines · Reinette Chatre
Quoted 31 lines · James Morse

resctrl_cqm_threshold is stored in a hardware specific chunk size, but exposed to user-space as bytes.

This means the filesystem parts of resctrl need to know how the hardware counts, to convert the user provided byte value to chunks. The interface between the architecture's resctrl code and the filesystem ought to treat everything as bytes.

Change the unit of resctrl_cqm_threshold to bytes. resctrl_arch_rmid_read() still returns its value in chunks, so this needs converting to bytes. As all the callers have been touched, rename the variable to resctrl_rmid_realloc_threshold, which describes what the value is for.

(quoted diff) +1 -4
@@ -762,10 +763,7 @@ int rdt_get_mon_l3_config(struct rdt_resource *r)
 	 *
 	 * For a 35MB LLC and 56 RMIDs, this is ~1.8% of the LLC.
 	 */
-	resctrl_cqm_threshold = cl_size * 1024 / r->num_rmid;
-
-	/* h/w works in units of "boot_cpu_data.x86_cache_occ_scale" */
-	resctrl_cqm_threshold /= hw_res->mon_scale;
+	resctrl_rmid_realloc_threshold = cl_size * 1024 / r->num_rmid;
 
 	ret = dom_data_init(r);
 	if (ret)
arch/x86/kernel/cpu/resctrl/rdtgroup.c +0 -0
index 7ec089d72ab7..93b3697027df 100644
@@ -1030,10 +1030,7 @@ static int rdt_delay_linear_show(struct kernfs_open_file *of,
 static int max_threshold_occ_show(struct kernfs_open_file *of,

arch/x86/kernel/cpu/resctrl/rdtgroup.c static int rdt_delay_linear_show(struct kernfs_open_file *of, · line 1036

Quoted 10 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +1 -4
 				  struct seq_file *seq, void *v)
 {
-	struct rdt_resource *r = of->kn->parent->priv;
-	struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r);
-
-	seq_printf(seq, "%u\n", resctrl_cqm_threshold * hw_res->mon_scale);
+	seq_printf(seq, "%u\n", resctrl_rmid_realloc_threshold);
 
 	return 0;
 }

This change has some user visible impact that I am still digesting but thought that I would share for your consideration.

As seen in the above two snippets, the original code did:

resctrl_cqm_threshold /= hw_res->mon_scale; /* resctrl_cqm_threshold used internally */

resctrl_cqm_threshold * hw_res->mon_scale; /* this is displayed to user */

The original loss due to truncation during the division is not recovered when the value is displayed to the user the user may see significant differences before and after this patch.

Quoted 7 lines

I tried this out on a system with a large cache and the before and after information is significant:
Before this patch:
info/L3_MON/max_threshold_occupancy:147456

After this patch:
info/L3_MON/max_threshold_occupancy:196608

Hmm. I hadn't considered that information would be lost by the current way of doing this. It looks like this happens because num_rmid isn't necessarily a power of 2.

Quoted 4 lines

As I understand this change indeed represents the information more accurately but I found it noteworthy that this is not just a simple "change the units" and may thus have broader impact and may indeed result in different behavior that should be considered.

I agree it more accurately reflects resctrl's calculation of "the number of lines tagged per RMID if all RMIDs have the same number of lines", but if that produces a number the hardware will never actually measure, then the rounding is still happening, but somewhere else.

I think the right thing to do is round resctrl_rmid_realloc_threshold down to the nearest multiple of hw_res->mon_scale in rdt_get_mon_l3_config(). This way the filesystem parts still handle things in bytes, and the architecture code provides the quantised value that will actually get measured. Its this value that should be reported to user-space.

It doesn't look like the 'Upscaling Factor' is guaranteed to be a power of 2, so I can't use the round_down() helpers.

I've added this to the commit message:

| Neither r->num_rmid nor hw_res->mon_scale are guaranteed to be a power
| of 2, so the existing code introduces a rounding error from resctrl's
| theoretical fraction of the cache usage. This behaviour is kept as it
| ensures the user visible value matches the value read from hardware
| when the rmid will be reallocated.

and the hunk below, which fixes it for me.

Thanks,

James

---------------%<---------------

arch/x86/kernel/cpu/resctrl/monitor.c +10 -1
index b18e227d585c..fb81d650c457 100644
@@ -753,6 +753,7 @@ int rdt_get_mon_l3_config(struct rdt_resource *r)
        unsigned int mbm_offset = boot_cpu_data.x86_cache_mbm_width_offset;
        struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r);
        unsigned int cl_size = boot_cpu_data.x86_cache_size;
+       u64 threshold;
        int ret;
 
        hw_res->mon_scale = boot_cpu_data.x86_cache_occ_scale;
@@ -771,7 +772,15 @@ int rdt_get_mon_l3_config(struct rdt_resource *r)
         *
         * For a 35MB LLC and 56 RMIDs, this is ~1.8% of the LLC.
         */
-       resctrl_rmid_realloc_threshold = cl_size * 1024 / r->num_rmid;
+       threshold = cl_size * 1024 / r->num_rmid;
+
+       /*
+        * Because num_rmid may not be a power of two, round the value
+        * to the nearest multiple of hw_res->mon_scale so it matches a
+        * value the hardware will measure. mon_scale may not be a power of 2.
+        */
+       threshold /= hw_res->mon_scale;
+       resctrl_rmid_realloc_threshold = threshold * hw_res->mon_scale;
 
        ret = dom_data_init(r);
        if (ret)

---------------%<---------------

maintainer
#38 lore raw

Re: [PATCH v3 19/21] x86/resctrl: Rename and change the units of resctrl_cqm_threshold

Hi James,

Quoted 126 lines · James Morse

Hi Reinette,

Quoted 57 lines · Reinette Chatre
Quoted 31 lines · James Morse

resctrl_cqm_threshold is stored in a hardware specific chunk size, but exposed to user-space as bytes.

This means the filesystem parts of resctrl need to know how the hardware counts, to convert the user provided byte value to chunks. The interface between the architecture's resctrl code and the filesystem ought to treat everything as bytes.

Change the unit of resctrl_cqm_threshold to bytes. resctrl_arch_rmid_read() still returns its value in chunks, so this needs converting to bytes. As all the callers have been touched, rename the variable to resctrl_rmid_realloc_threshold, which describes what the value is for.

arch/x86/kernel/cpu/resctrl/monitor.c +1 -4
@@ -762,10 +763,7 @@ int rdt_get_mon_l3_config(struct rdt_resource *r)
 	 *
 	 * For a 35MB LLC and 56 RMIDs, this is ~1.8% of the LLC.
 	 */
-	resctrl_cqm_threshold = cl_size * 1024 / r->num_rmid;
-
-	/* h/w works in units of "boot_cpu_data.x86_cache_occ_scale" */
-	resctrl_cqm_threshold /= hw_res->mon_scale;
+	resctrl_rmid_realloc_threshold = cl_size * 1024 / r->num_rmid;
 
 	ret = dom_data_init(r);
 	if (ret)
arch/x86/kernel/cpu/resctrl/rdtgroup.c +0 -0
index 7ec089d72ab7..93b3697027df 100644
@@ -1030,10 +1030,7 @@ static int rdt_delay_linear_show(struct kernfs_open_file *of,
 static int max_threshold_occ_show(struct kernfs_open_file *of,

arch/x86/kernel/cpu/resctrl/rdtgroup.c static int rdt_delay_linear_show(struct kernfs_open_file *of, · line 1036

Quoted 10 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +1 -4
 				  struct seq_file *seq, void *v)
 {
-	struct rdt_resource *r = of->kn->parent->priv;
-	struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r);
-
-	seq_printf(seq, "%u\n", resctrl_cqm_threshold * hw_res->mon_scale);
+	seq_printf(seq, "%u\n", resctrl_rmid_realloc_threshold);
 
 	return 0;
 }

This change has some user visible impact that I am still digesting but thought that I would share for your consideration.

As seen in the above two snippets, the original code did:

resctrl_cqm_threshold /= hw_res->mon_scale; /* resctrl_cqm_threshold used internally */

resctrl_cqm_threshold * hw_res->mon_scale; /* this is displayed to user */

The original loss due to truncation during the division is not recovered when the value is displayed to the user the user may see significant differences before and after this patch.

Quoted 7 lines

I tried this out on a system with a large cache and the before and after information is significant:
Before this patch:
info/L3_MON/max_threshold_occupancy:147456

After this patch:
info/L3_MON/max_threshold_occupancy:196608

Hmm. I hadn't considered that information would be lost by the current way of doing this. It looks like this happens because num_rmid isn't necessarily a power of 2.

Quoted 4 lines

As I understand this change indeed represents the information more accurately but I found it noteworthy that this is not just a simple "change the units" and may thus have broader impact and may indeed result in different behavior that should be considered.

I agree it more accurately reflects resctrl's calculation of "the number of lines tagged per RMID if all RMIDs have the same number of lines", but if that produces a number the hardware will never actually measure, then the rounding is still happening, but somewhere else.

I think the right thing to do is round resctrl_rmid_realloc_threshold down to the nearest multiple of hw_res->mon_scale in rdt_get_mon_l3_config(). This way the filesystem parts still handle things in bytes, and the architecture code provides the quantised value that will actually get measured. Its this value that should be reported to user-space.

It doesn't look like the 'Upscaling Factor' is guaranteed to be a power of 2, so I can't use the round_down() helpers.

I've added this to the commit message:

| Neither r->num_rmid nor hw_res->mon_scale are guaranteed to be a power
| of 2, so the existing code introduces a rounding error from resctrl's
| theoretical fraction of the cache usage. This behaviour is kept as it
| ensures the user visible value matches the value read from hardware
| when the rmid will be reallocated.

and the hunk below, which fixes it for me.

Thanks,

James

---------------%<---------------

arch/x86/kernel/cpu/resctrl/monitor.c +4 -1
index b18e227d585c..fb81d650c457 100644
@@ -753,6 +753,7 @@ int rdt_get_mon_l3_config(struct rdt_resource *r)
        unsigned int mbm_offset = boot_cpu_data.x86_cache_mbm_width_offset;
        struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r);
        unsigned int cl_size = boot_cpu_data.x86_cache_size;
+       u64 threshold;
        int ret;
 
        hw_res->mon_scale = boot_cpu_data.x86_cache_occ_scale;
@@ -771,7 +772,15 @@ int rdt_get_mon_l3_config(struct rdt_resource *r)
         *
         * For a 35MB LLC and 56 RMIDs, this is ~1.8% of the LLC.
         */
-       resctrl_rmid_realloc_threshold = cl_size * 1024 / r->num_rmid;
+       threshold = cl_size * 1024 / r->num_rmid;
+
+       /*

arch/x86/kernel/cpu/resctrl/monitor.c int rdt_get_mon_l3_config(struct rdt_resource *r)

Quoted 10 lines
arch/x86/kernel/cpu/resctrl/monitor.c +6 -1
+        * Because num_rmid may not be a power of two, round the value
+        * to the nearest multiple of hw_res->mon_scale so it matches a
+        * value the hardware will measure. mon_scale may not be a power of 2.
+        */
+       threshold /= hw_res->mon_scale;
+       resctrl_rmid_realloc_threshold = threshold * hw_res->mon_scale;
 
        ret = dom_data_init(r);
        if (ret)
---------------%<---------------

Thank you for the added explanation. From what I can tell this also restores current behavior.

Reinette

author reviewer
#39 lore raw

PATCH v3 20/21 x86/resctrl: Add resctrl_rmid_realloc_limit to abstract x86's boot_cpu_data

In reply to James Morse

resctrl_rmid_realloc_threshold can be set by user-space. The maximum value is specified by the architecture.

Currently max_threshold_occ_write() reads the maximum value from boot_cpu_data.x86_cache_size, which is not portable to another architecture.

Add resctrl_rmid_realloc_limit to describe the maximum size in bytes that user-space can set the threshold to.

---
 arch/x86/kernel/cpu/resctrl/monitor.c  | 9 +++++++--
 arch/x86/kernel/cpu/resctrl/rdtgroup.c | 2 +-
 include/linux/resctrl.h                | 1 +
 3 files changed, 9 insertions(+), 3 deletions(-)
arch/x86/kernel/cpu/resctrl/monitor.c +7 -2
index e91d9a7024a2..3a6555f49720 100644
@@ -64,6 +64,11 @@ unsigned int rdt_mon_features;
  */
 unsigned int resctrl_rmid_realloc_threshold;
 
+/*
+ * This is the maximum value for the reallocation threshold, in bytes.
+ */
+unsigned int resctrl_rmid_realloc_limit;
+
 #define CF(cf)	((unsigned long)(1048576 * (cf) + 0.5))
 
 /*
@@ -744,9 +749,9 @@ int rdt_get_mon_l3_config(struct rdt_resource *r)
 {
 	unsigned int mbm_offset = boot_cpu_data.x86_cache_mbm_width_offset;
 	struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r);
-	unsigned int cl_size = boot_cpu_data.x86_cache_size;
 	int ret;
 
+	resctrl_rmid_realloc_limit = boot_cpu_data.x86_cache_size * 1024;
 	hw_res->mon_scale = boot_cpu_data.x86_cache_occ_scale;
 	r->num_rmid = boot_cpu_data.x86_cache_max_rmid + 1;
 	hw_res->mbm_width = MBM_CNTR_WIDTH_BASE;
@@ -763,7 +768,7 @@ int rdt_get_mon_l3_config(struct rdt_resource *r)
 	 *
 	 * For a 35MB LLC and 56 RMIDs, this is ~1.8% of the LLC.
 	 */
-	resctrl_rmid_realloc_threshold = cl_size * 1024 / r->num_rmid;
+	resctrl_rmid_realloc_threshold = resctrl_rmid_realloc_limit / r->num_rmid;
 
 	ret = dom_data_init(r);
 	if (ret)
arch/x86/kernel/cpu/resctrl/rdtgroup.c +1 -1
index 93b3697027df..f77ee0f13efb 100644
@@ -1059,7 +1059,7 @@ static ssize_t max_threshold_occ_write(struct kernfs_open_file *of,
 	if (ret)
 		return ret;
 
-	if (bytes > (boot_cpu_data.x86_cache_size * 1024))
+	if (bytes > resctrl_rmid_realloc_limit)
 		return -EINVAL;
 
 	resctrl_rmid_realloc_threshold = bytes;
include/linux/resctrl.h +1 -0
index c79a180e578c..fc00bf1bafa7 100644
@@ -249,5 +249,6 @@ void resctrl_arch_reset_rmid(struct rdt_resource *r, struct rdt_domain *d,
 			     u32 rmid, enum resctrl_event_id eventid);
 
 extern unsigned int resctrl_rmid_realloc_threshold;
+extern unsigned int resctrl_rmid_realloc_limit;
 
 #endif /* _RESCTRL_H */
Signature · 1 line
2.30.2
author reviewer
#40 lore raw

PATCH v3 21/21 x86/resctrl: Make resctrl_arch_rmid_read() return values in bytes

In reply to James Morse

resctrl_arch_rmid_read() returns a value in chunks, as read from the hardware. This needs scaling to bytes by mon_scale, as provided by the architecture code.

Now that resctrl_arch_rmid_read() performs the overflow and corrections itself, it may as well return a value in bytes directly. This allows the accesses to the architecture specific 'hw' structure to be removed.

Move the mon_scale conversion into resctrl_arch_rmid_read(). mbm_bw_count() is updated to calculate bandwidth from bytes.

---
 arch/x86/kernel/cpu/resctrl/ctrlmondata.c |  6 ++----
 arch/x86/kernel/cpu/resctrl/internal.h    |  4 ++--
 arch/x86/kernel/cpu/resctrl/monitor.c     | 22 +++++++++-------------
 include/linux/resctrl.h                   |  2 +-
 4 files changed, 14 insertions(+), 20 deletions(-)
arch/x86/kernel/cpu/resctrl/ctrlmondata.c +2 -4
index d3f7eb2ac14b..03fc91d8bc9f 100644
@@ -549,7 +549,6 @@ void mon_event_read(struct rmid_read *rr, struct rdt_resource *r,
 int rdtgroup_mondata_show(struct seq_file *m, void *arg)
 {
 	struct kernfs_open_file *of = m->private;
-	struct rdt_hw_resource *hw_res;
 	u32 resid, evtid, domid;
 	struct rdtgroup *rdtgrp;
 	struct rdt_resource *r;
@@ -569,8 +568,7 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg)
 	domid = md.u.domid;
 	evtid = md.u.evtid;
 
-	hw_res = &rdt_resources_all[resid];
-	r = &hw_res->r_resctrl;
+	r = &rdt_resources_all[resid].r_resctrl;
 	d = rdt_find_domain(r, domid, NULL);
 	if (IS_ERR_OR_NULL(d)) {
 		ret = -ENOENT;
@@ -584,7 +582,7 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg)
 	else if (rr.err == -EINVAL)
 		seq_puts(m, "Unavailable\n");
 	else
-		seq_printf(m, "%llu\n", rr.val * hw_res->mon_scale);
+		seq_printf(m, "%llu\n", rr.val);
 
 out:
 	rdtgroup_kn_unlock(of->kn);
arch/x86/kernel/cpu/resctrl/internal.h +2 -2
index e26a4d67e204..d6ce6ce91885 100644
@@ -279,13 +279,13 @@ struct rftype {
 
 /**
  * struct mbm_state - status for each MBM counter in each domain
- * @prev_bw_chunks: Previous chunks value read when for bandwidth calculation
+ * @prev_bw_bytes: Previous bytes value read when for bandwidth calculation
  * @prev_bw:	The most recent bandwidth in MBps
  * @delta_bw:	Difference between the current and previous bandwidth
  * @delta_comp:	Indicates whether to compute the delta_bw
  */
 struct mbm_state {
-	u64	prev_bw_chunks;
+	u64	prev_bw_bytes;
 	u32	prev_bw;
 	u32	delta_bw;
 	bool	delta_comp;
arch/x86/kernel/cpu/resctrl/monitor.c +9 -13
index 3a6555f49720..437e7db77f93 100644
@@ -186,7 +186,7 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain *d,
 	struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r);
 	struct rdt_hw_domain *hw_dom = resctrl_to_arch_dom(d);
 	struct arch_mbm_state *am;
-	u64 msr_val;
+	u64 msr_val, chunks;
 
 	if (!cpumask_test_cpu(smp_processor_id(), &d->cpu_mask))
 		return -EINVAL;
@@ -211,10 +211,11 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain *d,
 	if (am) {
 		am->chunks += mbm_overflow_count(am->prev_msr, msr_val,
 						 hw_res->mbm_width);
-		*val = get_corrected_mbm_count(rmid, am->chunks);
+		chunks = get_corrected_mbm_count(rmid, am->chunks);
+		*val = chunks * hw_res->mon_scale;
 		am->prev_msr = msr_val;
 	} else {
-		*val = msr_val;
+		*val = msr_val * hw_res->mon_scale;
 	}
 
 	return 0;
@@ -229,7 +230,6 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain *d,
 void __check_limbo(struct rdt_domain *d, bool force_free)
 {
 	struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl;
-	struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r);
 	struct rmid_entry *entry;
 	u32 crmid = 1, nrmid;
 	bool rmid_dirty;
@@ -252,7 +252,6 @@ void __check_limbo(struct rdt_domain *d, bool force_free)
 					   QOS_L3_OCCUP_EVENT_ID, &val)) {
 			rmid_dirty = true;
 		} else {
-			val *= hw_res->mon_scale;
 			rmid_dirty = (val >= resctrl_rmid_realloc_threshold);
 		}
 
@@ -296,7 +295,6 @@ int alloc_rmid(void)
 static void add_rmid_to_limbo(struct rmid_entry *entry)
 {
 	struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl;
-	struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r);
 	struct rdt_domain *d;
 	int cpu, err;
 	u64 val = 0;
@@ -308,7 +306,6 @@ static void add_rmid_to_limbo(struct rmid_entry *entry)
 			err = resctrl_arch_rmid_read(r, d, entry->rmid,
 						     QOS_L3_OCCUP_EVENT_ID,
 						     &val);
-			val *= hw_res->mon_scale;
 			if (err || val <= resctrl_rmid_realloc_threshold)
 				continue;
 		}
@@ -400,15 +397,14 @@ static u64 __mon_event_count(u32 rmid, struct rmid_read *rr)
  */
 static void mbm_bw_count(u32 rmid, struct rmid_read *rr)
 {
-	struct rdt_hw_resource *hw_res = resctrl_to_arch_res(rr->r);
 	struct mbm_state *m = &rr->d->mbm_local[rmid];
-	u64 cur_bw, chunks, cur_chunks;
+	u64 cur_bw, bytes, cur_bytes;
 
-	cur_chunks = rr->val;
-	chunks = cur_chunks - m->prev_bw_chunks;
-	m->prev_bw_chunks = cur_chunks;
+	cur_bytes = rr->val;
+	bytes = cur_bytes - m->prev_bw_bytes;
+	m->prev_bw_bytes = cur_bytes;
 
-	cur_bw = (chunks * hw_res->mon_scale) >> 20;
+	cur_bw = bytes >> 20;
 
 	if (m->delta_comp)
 		m->delta_bw = abs(cur_bw - m->prev_bw);
include/linux/resctrl.h +1 -1
index fc00bf1bafa7..4e0a7a549280 100644
@@ -227,7 +227,7 @@ void resctrl_offline_domain(struct rdt_resource *r, struct rdt_domain *d);
  * @d:			domain that the counter should be read from.
  * @rmid:		rmid of the counter to read.
  * @eventid:		eventid to read, e.g. L3 occupancy.
- * @val:		result of the counter read in chunks.
+ * @val:		result of the counter read in bytes.
  *
  * Return:
  * 0 on success, or -EIO, -EINVAL etc on error.
Signature · 1 line
2.30.2
#41 lore raw
Quoted 84 lines · James Morse

resctrl_arch_rmid_read() returns a value in chunks, as read from the hardware. This needs scaling to bytes by mon_scale, as provided by the architecture code.

Now that resctrl_arch_rmid_read() performs the overflow and corrections itself, it may as well return a value in bytes directly. This allows the accesses to the architecture specific 'hw' structure to be removed.

Move the mon_scale conversion into resctrl_arch_rmid_read(). mbm_bw_count() is updated to calculate bandwidth from bytes.

---
 arch/x86/kernel/cpu/resctrl/ctrlmondata.c |  6 ++----
 arch/x86/kernel/cpu/resctrl/internal.h    |  4 ++--
 arch/x86/kernel/cpu/resctrl/monitor.c     | 22 +++++++++-------------
 include/linux/resctrl.h                   |  2 +-
 4 files changed, 14 insertions(+), 20 deletions(-)
arch/x86/kernel/cpu/resctrl/ctrlmondata.c +2 -4
index d3f7eb2ac14b..03fc91d8bc9f 100644
@@ -549,7 +549,6 @@ void mon_event_read(struct rmid_read *rr, struct rdt_resource *r,
 int rdtgroup_mondata_show(struct seq_file *m, void *arg)
 {
 	struct kernfs_open_file *of = m->private;
-	struct rdt_hw_resource *hw_res;
 	u32 resid, evtid, domid;
 	struct rdtgroup *rdtgrp;
 	struct rdt_resource *r;
@@ -569,8 +568,7 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg)
 	domid = md.u.domid;
 	evtid = md.u.evtid;
 
-	hw_res = &rdt_resources_all[resid];
-	r = &hw_res->r_resctrl;
+	r = &rdt_resources_all[resid].r_resctrl;
 	d = rdt_find_domain(r, domid, NULL);
 	if (IS_ERR_OR_NULL(d)) {
 		ret = -ENOENT;
@@ -584,7 +582,7 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg)
 	else if (rr.err == -EINVAL)
 		seq_puts(m, "Unavailable\n");
 	else
-		seq_printf(m, "%llu\n", rr.val * hw_res->mon_scale);
+		seq_printf(m, "%llu\n", rr.val);
 
 out:
 	rdtgroup_kn_unlock(of->kn);
arch/x86/kernel/cpu/resctrl/internal.h +2 -2
index e26a4d67e204..d6ce6ce91885 100644
@@ -279,13 +279,13 @@ struct rftype {
 
 /**
  * struct mbm_state - status for each MBM counter in each domain
- * @prev_bw_chunks: Previous chunks value read when for bandwidth calculation
+ * @prev_bw_bytes: Previous bytes value read when for bandwidth calculation
  * @prev_bw:	The most recent bandwidth in MBps
  * @delta_bw:	Difference between the current and previous bandwidth
  * @delta_comp:	Indicates whether to compute the delta_bw
  */
 struct mbm_state {
-	u64	prev_bw_chunks;
+	u64	prev_bw_bytes;
 	u32	prev_bw;
 	u32	delta_bw;
 	bool	delta_comp;
arch/x86/kernel/cpu/resctrl/monitor.c +1 -1
index 3a6555f49720..437e7db77f93 100644
@@ -186,7 +186,7 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain *d,
 	struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r);
 	struct rdt_hw_domain *hw_dom = resctrl_to_arch_dom(d);
 	struct arch_mbm_state *am;
-	u64 msr_val;
+	u64 msr_val, chunks;
 
 	if (!cpumask_test_cpu(smp_processor_id(), &d->cpu_mask))
 		return -EINVAL;

arch/x86/kernel/cpu/resctrl/monitor.c int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain *d, · line 215

Quoted 6 lines
arch/x86/kernel/cpu/resctrl/monitor.c +2 -1
@@ -211,10 +211,11 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain *d,
 	if (am) {
 		am->chunks += mbm_overflow_count(am->prev_msr, msr_val,
 						 hw_res->mbm_width);
-		*val = get_corrected_mbm_count(rmid, am->chunks);
+		chunks = get_corrected_mbm_count(rmid, am->chunks);
+		*val = chunks * hw_res->mon_scale;

This can be moved out of the if/else if you make the following change:

arch/x86/kernel/cpu/resctrl/monitor.c int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain *d, · line 218

Quoted 4 lines
arch/x86/kernel/cpu/resctrl/monitor.c +1 -1
 		am->prev_msr = msr_val;
 	} else {
-		*val = msr_val;
+		*val = msr_val * hw_res->mon_scale;

chunks = msr_val;

Quoted 43 lines
arch/x86/kernel/cpu/resctrl/monitor.c +1 -6
 	}
 
 	return 0;
@@ -229,7 +230,6 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain *d,
 void __check_limbo(struct rdt_domain *d, bool force_free)
 {
 	struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl;
-	struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r);
 	struct rmid_entry *entry;
 	u32 crmid = 1, nrmid;
 	bool rmid_dirty;
@@ -252,7 +252,6 @@ void __check_limbo(struct rdt_domain *d, bool force_free)
 					   QOS_L3_OCCUP_EVENT_ID, &val)) {
 			rmid_dirty = true;
 		} else {
-			val *= hw_res->mon_scale;
 			rmid_dirty = (val >= resctrl_rmid_realloc_threshold);
 		}
 
@@ -296,7 +295,6 @@ int alloc_rmid(void)
 static void add_rmid_to_limbo(struct rmid_entry *entry)
 {
 	struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl;
-	struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r);
 	struct rdt_domain *d;
 	int cpu, err;
 	u64 val = 0;
@@ -308,7 +306,6 @@ static void add_rmid_to_limbo(struct rmid_entry *entry)
 			err = resctrl_arch_rmid_read(r, d, entry->rmid,
 						     QOS_L3_OCCUP_EVENT_ID,
 						     &val);
-			val *= hw_res->mon_scale;
 			if (err || val <= resctrl_rmid_realloc_threshold)
 				continue;
 		}
@@ -400,15 +397,14 @@ static u64 __mon_event_count(u32 rmid, struct rmid_read *rr)
  */
 static void mbm_bw_count(u32 rmid, struct rmid_read *rr)
 {
-	struct rdt_hw_resource *hw_res = resctrl_to_arch_res(rr->r);
 	struct mbm_state *m = &rr->d->mbm_local[rmid];
-	u64 cur_bw, chunks, cur_chunks;
+	u64 cur_bw, bytes, cur_bytes;

arch/x86/kernel/cpu/resctrl/monitor.c static u64 __mon_event_count(u32 rmid, struct rmid_read *rr) · line 407

Quoted 10 lines
arch/x86/kernel/cpu/resctrl/monitor.c +4 -4
 
-	cur_chunks = rr->val;
-	chunks = cur_chunks - m->prev_bw_chunks;
-	m->prev_bw_chunks = cur_chunks;
+	cur_bytes = rr->val;
+	bytes = cur_bytes - m->prev_bw_bytes;
+	m->prev_bw_bytes = cur_bytes;
 
-	cur_bw = (chunks * hw_res->mon_scale) >> 20;
+	cur_bw = bytes >> 20;

'bytes / SZ_1M' would be more readable and any decent compiler should optimize a power of 2 divide. But maybe that's a separate change as there are other cases of bytes to MB.

Rob

author reviewer
#42 lore raw

Hi Rob,

Quoted 26 lines · Rob Herring
Quoted 16 lines · James Morse

resctrl_arch_rmid_read() returns a value in chunks, as read from the hardware. This needs scaling to bytes by mon_scale, as provided by the architecture code.

Now that resctrl_arch_rmid_read() performs the overflow and corrections itself, it may as well return a value in bytes directly. This allows the accesses to the architecture specific 'hw' structure to be removed.

Move the mon_scale conversion into resctrl_arch_rmid_read(). mbm_bw_count() is updated to calculate bandwidth from bytes.

arch/x86/kernel/cpu/resctrl/monitor.c +0 -0
index 3a6555f49720..437e7db77f93 100644

arch/x86/kernel/cpu/resctrl/monitor.c int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain *d, · line 215

Quoted 6 lines
arch/x86/kernel/cpu/resctrl/monitor.c +2 -1
@@ -211,10 +211,11 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain *d,
  	if (am) {
  		am->chunks += mbm_overflow_count(am->prev_msr, msr_val,
  						 hw_res->mbm_width);
-		*val = get_corrected_mbm_count(rmid, am->chunks);
+		chunks = get_corrected_mbm_count(rmid, am->chunks);
+		*val = chunks * hw_res->mon_scale;

This can be moved out of the if/else if you make the following change:

Quoted 8 lines

arch/x86/kernel/cpu/resctrl/monitor.c int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain *d, · line 218

Quoted 4 lines
arch/x86/kernel/cpu/resctrl/monitor.c +1 -1
  		am->prev_msr = msr_val;
  	} else {
-		*val = msr_val;
+		*val = msr_val * hw_res->mon_scale;

chunks = msr_val;

Quoted 1 line
arch/x86/kernel/cpu/resctrl/monitor.c +0 -0
  	}

Sure, I guess it makes sense to only set *val in one place.

Quoted 18 lines
Quoted 18 lines
arch/x86/kernel/cpu/resctrl/monitor.c +4 -5
  	return 0;
@@ -400,15 +397,14 @@ static u64 __mon_event_count(u32 rmid, struct rmid_read *rr)
   */
  static void mbm_bw_count(u32 rmid, struct rmid_read *rr)
  {
-	struct rdt_hw_resource *hw_res = resctrl_to_arch_res(rr->r);
  	struct mbm_state *m = &rr->d->mbm_local[rmid];
-	u64 cur_bw, chunks, cur_chunks;
+	u64 cur_bw, bytes, cur_bytes;
 
-	cur_chunks = rr->val;
-	chunks = cur_chunks - m->prev_bw_chunks;
-	m->prev_bw_chunks = cur_chunks;
+	cur_bytes = rr->val;
+	bytes = cur_bytes - m->prev_bw_bytes;
+	m->prev_bw_bytes = cur_bytes;
 
Quoted 6 lines

arch/x86/kernel/cpu/resctrl/monitor.c static u64 __mon_event_count(u32 rmid, struct rmid_read *rr) · line 407

Quoted 2 lines
arch/x86/kernel/cpu/resctrl/monitor.c +1 -1
-	cur_bw = (chunks * hw_res->mon_scale) >> 20;
+	cur_bw = bytes >> 20;

'bytes / SZ_1M' would be more readable and any decent compiler should optimize a power of 2 divide. But maybe that's a separate change as there are other cases of bytes to MB.

I agree its more readable. As I've touched this one, I'll change it.

Thanks,

James

Reviewed-by on the v3 series
#43 lore raw
In reply to James Morse
Quoted 61 lines · James Morse

Changes in this version? Expanded the commit message of patch 12, and made a few things static, as reported by the kbuild robot.

---
The aim of this series is to insert a split between the parts of the monitor code that the architecture must implement, and those that are part of the resctrl filesystem. The eventual aim is to move all filesystem parts out to live in /fs/resctrl, so that resctrl can be wired up for MPAM.

What's MPAM? See the cover letter of a previous series. [1]

The series adds domain online/offline callbacks to allow the filesystem to manage some of its structures itself, then moves all the 'mba_sc' behaviour to be part of the filesystem.
This means another architecture doesn't need to provide an mbps_val array. As its all software, the resctrl filesystem should be able to do this without any help from the architecture code.

Finally __rmid_read() is refactored to be the API call that the architecture provides to read a counter value. All the hardware specific overflow detection, scaling and value correction should occur behind this helper.

This series is based on v5.17-rc1, and can be retrieved from:
git://git.kernel.org/pub/scm/linux/kernel/git/morse/linux.git mpam/resctrl_monitors_in_bytes/v3

[0] git://git.kernel.org/pub/scm/linux/kernel/git/morse/linux.git mpam/resctrl_merge_cdp/v7
[1] https://lore.kernel.org/lkml/[email protected]/

[v1] https://lore.kernel.org/lkml/[email protected]/
[v2] https://lore.kernel.org/lkml/[email protected]/

Thanks,

James Morse (21):
x86/resctrl: Kill off alloc_enabled
x86/resctrl: Merge mon_capable and mon_enabled x86/resctrl: Add domain online callback for resctrl work x86/resctrl: Group struct rdt_hw_domain cleanup x86/resctrl: Add domain offline callback for resctrl work x86/resctrl: Remove set_mba_sc()s control array re-initialisation x86/resctrl: Create mba_sc configuration in the rdt_domain x86/resctrl: Switch over to the resctrl mbps_val list x86/resctrl: Remove architecture copy of mbps_val x86/resctrl: Abstract and use supports_mba_mbps() x86/resctrl: Allow update_mba_bw() to update controls directly x86/resctrl: Calculate bandwidth from the previous __mon_event_count()
chunks
x86/recstrl: Add per-rmid arch private storage for overflow and chunks x86/recstrl: Allow per-rmid arch private storage to be reset x86/resctrl: Abstract __rmid_read()
x86/resctrl: Pass the required parameters into
resctrl_arch_rmid_read()
x86/resctrl: Move mbm_overflow_count() into resctrl_arch_rmid_read() x86/resctrl: Move get_corrected_mbm_count() into
resctrl_arch_rmid_read()
x86/resctrl: Rename and change the units of resctrl_cqm_threshold x86/resctrl: Add resctrl_rmid_realloc_limit to abstract x86's
boot_cpu_data
x86/resctrl: Make resctrl_arch_rmid_read() return values in bytes

Quoted 8 lines
 arch/x86/kernel/cpu/resctrl/core.c        | 117 ++++--------
 arch/x86/kernel/cpu/resctrl/ctrlmondata.c |  75 +++++---
 arch/x86/kernel/cpu/resctrl/internal.h    |  61 +++----
 arch/x86/kernel/cpu/resctrl/monitor.c     | 211 ++++++++++++++--------
 arch/x86/kernel/cpu/resctrl/pseudo_lock.c |   2 +-
 arch/x86/kernel/cpu/resctrl/rdtgroup.c    | 205 +++++++++++++++++----
 include/linux/resctrl.h                   |  62 ++++++-
 7 files changed, 478 insertions(+), 255 deletions(-)
author reviewer
#44 lore raw

Hi Jamie,

Quoted 3 lines · Jamie Iles
Quoted 2 lines · James Morse

Changes in this version? Expanded the commit message of patch 12, and made a few things static, as reported by the kbuild robot.

[...]

Quoted 1 line

Thanks!

James

#45 lore raw
In reply to James Morse

Hi james,

I have done some verification on x86 machine(Intel(R) Xeon(R) Platinum 8269CY), and "CAT, CMT, MBA, MBM"  have been tested,

They all work well.

So please add Tested-by: Xin Hao <[email protected]>

Signature · 2 lines
Best Regards!
Xin Hao
author reviewer
#46 lore raw

Hello!

Quoted 5 lines · Xin Hao

I have done some verification on x86 machine(Intel(R) Xeon(R) Platinum 8269CY), and "CAT, CMT, MBA, MBM"  have been tested,

They all work well.

So please add Tested-by: Xin Hao <[email protected]>

Great, thanks!

James

Reviewed-by Tested-by on the v3 series
#47 lore raw
In reply to James Morse

Hi James,

Quoted 79 lines

Changes in this version? Expanded the commit message of patch 12, and made a few things static, as reported by the kbuild robot.

---
The aim of this series is to insert a split between the parts of the monitor code that the architecture must implement, and those that are part of the resctrl filesystem. The eventual aim is to move all filesystem parts out to live in /fs/resctrl, so that resctrl can be wired up for MPAM.

What's MPAM? See the cover letter of a previous series. [1]

The series adds domain online/offline callbacks to allow the filesystem to manage some of its structures itself, then moves all the 'mba_sc' behaviour to be part of the filesystem.
This means another architecture doesn't need to provide an mbps_val array. As its all software, the resctrl filesystem should be able to do this without any help from the architecture code.

Finally __rmid_read() is refactored to be the API call that the architecture provides to read a counter value. All the hardware specific overflow detection, scaling and value correction should occur behind this helper.

This series is based on v5.17-rc1, and can be retrieved from:
git://git.kernel.org/pub/scm/linux/kernel/git/morse/linux.git
mpam/resctrl_monitors_in_bytes/v3

[0] git://git.kernel.org/pub/scm/linux/kernel/git/morse/linux.git
mpam/resctrl_merge_cdp/v7 [1]
https://lore.kernel.org/lkml/[email protected]
/

[v1]
https://lore.kernel.org/lkml/[email protected]
/
[v2]
https://lore.kernel.org/lkml/[email protected]
/

Thanks,

James Morse (21):
x86/resctrl: Kill off alloc_enabled
x86/resctrl: Merge mon_capable and mon_enabled x86/resctrl: Add domain online callback for resctrl work x86/resctrl: Group struct rdt_hw_domain cleanup x86/resctrl: Add domain offline callback for resctrl work x86/resctrl: Remove set_mba_sc()s control array re-initialisation x86/resctrl: Create mba_sc configuration in the rdt_domain x86/resctrl: Switch over to the resctrl mbps_val list x86/resctrl: Remove architecture copy of mbps_val x86/resctrl: Abstract and use supports_mba_mbps() x86/resctrl: Allow update_mba_bw() to update controls directly x86/resctrl: Calculate bandwidth from the previous __mon_event_count()
chunks
x86/recstrl: Add per-rmid arch private storage for overflow and chunks x86/recstrl: Allow per-rmid arch private storage to be reset x86/resctrl: Abstract __rmid_read()
x86/resctrl: Pass the required parameters into
resctrl_arch_rmid_read()
x86/resctrl: Move mbm_overflow_count() into resctrl_arch_rmid_read() x86/resctrl: Move get_corrected_mbm_count() into
resctrl_arch_rmid_read()
x86/resctrl: Rename and change the units of resctrl_cqm_threshold x86/resctrl: Add resctrl_rmid_realloc_limit to abstract x86's
boot_cpu_data
x86/resctrl: Make resctrl_arch_rmid_read() return values in bytes

 arch/x86/kernel/cpu/resctrl/core.c        | 117 ++++--------
 arch/x86/kernel/cpu/resctrl/ctrlmondata.c |  75 +++++---
 arch/x86/kernel/cpu/resctrl/internal.h    |  61 +++----
 arch/x86/kernel/cpu/resctrl/monitor.c     | 211
++++++++++++++--------
 arch/x86/kernel/cpu/resctrl/pseudo_lock.c |   2 +-
 arch/x86/kernel/cpu/resctrl/rdtgroup.c    | 205
+++++++++++++++++----
 include/linux/resctrl.h                   |  62 ++++++-
 7 files changed, 478 insertions(+), 255 deletions(-)
Quoted 2 lines

--
2.30.2

I tested this patch series on Intel(R) Xeon(R) Gold 6254 CPU with resctrl selftest. It is no problem.