Skip to content

Commit f4e0cd8

Browse files
aeglbp3tk0v
authored andcommitted
x86,fs/resctrl: Handle domain creation/deletion for RDT_RESOURCE_PERF_PKG
The L3 resource has several requirements for domains. There are per-domain structures that hold the 64-bit values of counters, and elements to keep track of the overflow and limbo threads. None of these are needed for the PERF_PKG resource. The hardware counters are wide enough that they do not wrap around for decades. Define a new rdt_perf_pkg_mon_domain structure which just consists of the standard rdt_domain_hdr to keep track of domain id and CPU mask. Update resctrl_online_mon_domain() for RDT_RESOURCE_PERF_PKG. The only action needed for this resource is to create and populate domain directories if a domain is added while resctrl is mounted. Similarly resctrl_offline_mon_domain() only needs to remove domain directories. Signed-off-by: Tony Luck <tony.luck@intel.com> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Reviewed-by: Reinette Chatre <reinette.chatre@intel.com> Link: https://lore.kernel.org/20251217172121.12030-1-tony.luck@intel.com
1 parent 93d9fd8 commit f4e0cd8

4 files changed

Lines changed: 71 additions & 5 deletions

File tree

arch/x86/kernel/cpu/resctrl/core.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,10 @@ static void domain_add_cpu_mon(int cpu, struct rdt_resource *r)
580580
if (!hdr)
581581
l3_mon_domain_setup(cpu, id, r, add_pos);
582582
break;
583+
case RDT_RESOURCE_PERF_PKG:
584+
if (!hdr)
585+
intel_aet_mon_domain_setup(cpu, id, r, add_pos);
586+
break;
583587
default:
584588
pr_warn_once("Unknown resource rid=%d\n", r->rid);
585589
break;
@@ -679,6 +683,19 @@ static void domain_remove_cpu_mon(int cpu, struct rdt_resource *r)
679683
l3_mon_domain_free(hw_dom);
680684
break;
681685
}
686+
case RDT_RESOURCE_PERF_PKG: {
687+
struct rdt_perf_pkg_mon_domain *pkgd;
688+
689+
if (!domain_header_is_valid(hdr, RESCTRL_MON_DOMAIN, RDT_RESOURCE_PERF_PKG))
690+
return;
691+
692+
pkgd = container_of(hdr, struct rdt_perf_pkg_mon_domain, hdr);
693+
resctrl_offline_mon_domain(r, hdr);
694+
list_del_rcu(&hdr->list);
695+
synchronize_rcu();
696+
kfree(pkgd);
697+
break;
698+
}
682699
default:
683700
pr_warn_once("Unknown resource rid=%d\n", r->rid);
684701
break;

arch/x86/kernel/cpu/resctrl/intel_aet.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,20 @@
1414
#include <linux/bits.h>
1515
#include <linux/compiler_types.h>
1616
#include <linux/container_of.h>
17+
#include <linux/cpumask.h>
1718
#include <linux/err.h>
1819
#include <linux/errno.h>
20+
#include <linux/gfp_types.h>
1921
#include <linux/init.h>
2022
#include <linux/intel_pmt_features.h>
2123
#include <linux/intel_vsec.h>
2224
#include <linux/io.h>
2325
#include <linux/printk.h>
26+
#include <linux/rculist.h>
27+
#include <linux/rcupdate.h>
2428
#include <linux/resctrl.h>
2529
#include <linux/resctrl_types.h>
30+
#include <linux/slab.h>
2631
#include <linux/stddef.h>
2732
#include <linux/topology.h>
2833
#include <linux/types.h>
@@ -283,3 +288,27 @@ int intel_aet_read_event(int domid, u32 rmid, void *arch_priv, u64 *val)
283288

284289
return valid ? 0 : -EINVAL;
285290
}
291+
292+
void intel_aet_mon_domain_setup(int cpu, int id, struct rdt_resource *r,
293+
struct list_head *add_pos)
294+
{
295+
struct rdt_perf_pkg_mon_domain *d;
296+
int err;
297+
298+
d = kzalloc_node(sizeof(*d), GFP_KERNEL, cpu_to_node(cpu));
299+
if (!d)
300+
return;
301+
302+
d->hdr.id = id;
303+
d->hdr.type = RESCTRL_MON_DOMAIN;
304+
d->hdr.rid = RDT_RESOURCE_PERF_PKG;
305+
cpumask_set_cpu(cpu, &d->hdr.cpu_mask);
306+
list_add_tail_rcu(&d->hdr.list, add_pos);
307+
308+
err = resctrl_online_mon_domain(r, &d->hdr);
309+
if (err) {
310+
list_del_rcu(&d->hdr.list);
311+
synchronize_rcu();
312+
kfree(d);
313+
}
314+
}

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,14 @@ static inline struct rdt_hw_l3_mon_domain *resctrl_to_arch_mon_dom(struct rdt_l3
8787
return container_of(r, struct rdt_hw_l3_mon_domain, d_resctrl);
8888
}
8989

90+
/**
91+
* struct rdt_perf_pkg_mon_domain - CPUs sharing an package scoped resctrl monitor resource
92+
* @hdr: common header for different domain types
93+
*/
94+
struct rdt_perf_pkg_mon_domain {
95+
struct rdt_domain_hdr hdr;
96+
};
97+
9098
/**
9199
* struct msr_param - set a range of MSRs from a domain
92100
* @res: The resource to use
@@ -226,13 +234,18 @@ void resctrl_arch_mbm_cntr_assign_set_one(struct rdt_resource *r);
226234
bool intel_aet_get_events(void);
227235
void __exit intel_aet_exit(void);
228236
int intel_aet_read_event(int domid, u32 rmid, void *arch_priv, u64 *val);
237+
void intel_aet_mon_domain_setup(int cpu, int id, struct rdt_resource *r,
238+
struct list_head *add_pos);
229239
#else
230240
static inline bool intel_aet_get_events(void) { return false; }
231241
static inline void __exit intel_aet_exit(void) { }
232242
static inline int intel_aet_read_event(int domid, u32 rmid, void *arch_priv, u64 *val)
233243
{
234244
return -EINVAL;
235245
}
246+
247+
static inline void intel_aet_mon_domain_setup(int cpu, int id, struct rdt_resource *r,
248+
struct list_head *add_pos) { }
236249
#endif
237250

238251
#endif /* _ASM_X86_RESCTRL_INTERNAL_H */

fs/resctrl/rdtgroup.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4308,18 +4308,20 @@ void resctrl_offline_mon_domain(struct rdt_resource *r, struct rdt_domain_hdr *h
43084308

43094309
mutex_lock(&rdtgroup_mutex);
43104310

4311-
if (!domain_header_is_valid(hdr, RESCTRL_MON_DOMAIN, RDT_RESOURCE_L3))
4312-
goto out_unlock;
4313-
4314-
d = container_of(hdr, struct rdt_l3_mon_domain, hdr);
4315-
43164311
/*
43174312
* If resctrl is mounted, remove all the
43184313
* per domain monitor data directories.
43194314
*/
43204315
if (resctrl_mounted && resctrl_arch_mon_capable())
43214316
rmdir_mondata_subdir_allrdtgrp(r, hdr);
43224317

4318+
if (r->rid != RDT_RESOURCE_L3)
4319+
goto out_unlock;
4320+
4321+
if (!domain_header_is_valid(hdr, RESCTRL_MON_DOMAIN, RDT_RESOURCE_L3))
4322+
goto out_unlock;
4323+
4324+
d = container_of(hdr, struct rdt_l3_mon_domain, hdr);
43234325
if (resctrl_is_mbm_enabled())
43244326
cancel_delayed_work(&d->mbm_over);
43254327
if (resctrl_is_mon_event_enabled(QOS_L3_OCCUP_EVENT_ID) && has_busy_rmid(d)) {
@@ -4416,6 +4418,9 @@ int resctrl_online_mon_domain(struct rdt_resource *r, struct rdt_domain_hdr *hdr
44164418

44174419
mutex_lock(&rdtgroup_mutex);
44184420

4421+
if (r->rid != RDT_RESOURCE_L3)
4422+
goto mkdir;
4423+
44194424
if (!domain_header_is_valid(hdr, RESCTRL_MON_DOMAIN, RDT_RESOURCE_L3))
44204425
goto out_unlock;
44214426

@@ -4433,6 +4438,8 @@ int resctrl_online_mon_domain(struct rdt_resource *r, struct rdt_domain_hdr *hdr
44334438
if (resctrl_is_mon_event_enabled(QOS_L3_OCCUP_EVENT_ID))
44344439
INIT_DELAYED_WORK(&d->cqm_limbo, cqm_handle_limbo);
44354440

4441+
mkdir:
4442+
err = 0;
44364443
/*
44374444
* If the filesystem is not mounted then only the default resource group
44384445
* exists. Creation of its directories is deferred until mount time

0 commit comments

Comments
 (0)