[PATCH v19 13/20] x86/resctrl: Handle removing directories in Sub-NUMA Cluster (SNC) mode

From: Tony Luck
Date: Tue May 28 2024 - 18:22:09 EST


In SNC mode there are multiple subdirectories in each L3 level monitor
directory (one for each SNC node). If all the CPUs in an SNC node are
taken offline, just remove the SNC directory for that node. In
non-SNC mode, or when the last SNC node directory is removed, also
remove the L3 monitor directory.

Signed-off-by: Tony Luck <tony.luck@xxxxxxxxx>
---
arch/x86/kernel/cpu/resctrl/rdtgroup.c | 39 ++++++++++++++++++++++----
1 file changed, 33 insertions(+), 6 deletions(-)

diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
index 6a5c35a176d5..cdcae13d6c6d 100644
--- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c
+++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
@@ -3011,17 +3011,44 @@ static int mon_addfile(struct kernfs_node *parent_kn, const char *name,
* and monitor groups with given domain id.
*/
static void rmdir_mondata_subdir_allrdtgrp(struct rdt_resource *r,
- unsigned int dom_id)
+ struct rdt_mon_domain *d)
{
struct rdtgroup *prgrp, *crgrp;
+ bool remove_all = true;
+ struct kernfs_node *kn;
+ char subname[32];
char name[32];

+ sprintf(name, "mon_%s_%02d", r->name, d->ci->id);
+ if (r->mon_scope != RESCTRL_L3_CACHE) {
+ /*
+ * SNC mode: If the last domain is being removed, the count of
+ * CPUs sharing the L3 cache should be 1 (current CPU).
+ */
+ if (cpumask_weight(&d->ci->shared_cpu_map) > 1) {
+ remove_all = false;
+ sprintf(subname, "mon_sub_%s_%02d", r->name, d->hdr.id);
+ }
+ }
+
list_for_each_entry(prgrp, &rdt_all_groups, rdtgroup_list) {
- sprintf(name, "mon_%s_%02d", r->name, dom_id);
- kernfs_remove_by_name(prgrp->mon.mon_data_kn, name);
+ if (remove_all) {
+ kernfs_remove_by_name(prgrp->mon.mon_data_kn, name);
+ } else {
+ kn = kernfs_find_and_get(prgrp->mon.mon_data_kn, name);
+ if (kn)
+ kernfs_remove_by_name(kn, subname);
+ }

- list_for_each_entry(crgrp, &prgrp->mon.crdtgrp_list, mon.crdtgrp_list)
- kernfs_remove_by_name(crgrp->mon.mon_data_kn, name);
+ list_for_each_entry(crgrp, &prgrp->mon.crdtgrp_list, mon.crdtgrp_list) {
+ if (remove_all) {
+ kernfs_remove_by_name(crgrp->mon.mon_data_kn, name);
+ } else {
+ kn = kernfs_find_and_get(crgrp->mon.mon_data_kn, name);
+ if (kn)
+ kernfs_remove_by_name(kn, subname);
+ }
+ }
}
}

@@ -3984,7 +4011,7 @@ void resctrl_offline_mon_domain(struct rdt_resource *r, struct rdt_mon_domain *d
* per domain monitor data directories.
*/
if (resctrl_mounted && resctrl_arch_mon_capable())
- rmdir_mondata_subdir_allrdtgrp(r, d->hdr.id);
+ rmdir_mondata_subdir_allrdtgrp(r, d);

if (is_mbm_enabled())
cancel_delayed_work(&d->mbm_over);
--
2.45.0