Skip to content

Commit 52a4edb

Browse files
author
James Morse
committed
arm_mpam: resctrl: Pick the caches we will use as resctrl resources
Systems with MPAM support may have a variety of control types at any point of their system layout. We can only expose certain types of control, and only if they exist at particular locations. Start with the well-known caches. These have to be depth 2 or 3 and support MPAM's cache portion bitmap controls, with a number of portions fewer than resctrl's limit. Tested-by: Gavin Shan <gshan@redhat.com> Tested-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com> Tested-by: Peter Newman <peternewman@google.com> Tested-by: Zeng Heng <zengheng4@huawei.com> Tested-by: Punit Agrawal <punit.agrawal@oss.qualcomm.com> Tested-by: Jesse Chick <jessechick@os.amperecomputing.com> Reviewed-by: Zeng Heng <zengheng4@huawei.com> Reviewed-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com> Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com> Reviewed-by: Gavin Shan <gshan@redhat.com> Co-developed-by: Ben Horgan <ben.horgan@arm.com> Signed-off-by: Ben Horgan <ben.horgan@arm.com> Signed-off-by: James Morse <james.morse@arm.com>
1 parent 09e61da commit 52a4edb

1 file changed

Lines changed: 89 additions & 2 deletions

File tree

drivers/resctrl/mpam_resctrl.c

Lines changed: 89 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,95 @@ struct rdt_resource *resctrl_arch_get_resource(enum resctrl_res_level l)
6565
return &mpam_resctrl_controls[l].resctrl_res;
6666
}
6767

68+
static bool cache_has_usable_cpor(struct mpam_class *class)
69+
{
70+
struct mpam_props *cprops = &class->props;
71+
72+
if (!mpam_has_feature(mpam_feat_cpor_part, cprops))
73+
return false;
74+
75+
/* resctrl uses u32 for all bitmap configurations */
76+
return class->props.cpbm_wd <= 32;
77+
}
78+
79+
/* Test whether we can export MPAM_CLASS_CACHE:{2,3}? */
80+
static void mpam_resctrl_pick_caches(void)
81+
{
82+
struct mpam_class *class;
83+
struct mpam_resctrl_res *res;
84+
85+
lockdep_assert_cpus_held();
86+
87+
guard(srcu)(&mpam_srcu);
88+
list_for_each_entry_srcu(class, &mpam_classes, classes_list,
89+
srcu_read_lock_held(&mpam_srcu)) {
90+
if (class->type != MPAM_CLASS_CACHE) {
91+
pr_debug("class %u is not a cache\n", class->level);
92+
continue;
93+
}
94+
95+
if (class->level != 2 && class->level != 3) {
96+
pr_debug("class %u is not L2 or L3\n", class->level);
97+
continue;
98+
}
99+
100+
if (!cache_has_usable_cpor(class)) {
101+
pr_debug("class %u cache misses CPOR\n", class->level);
102+
continue;
103+
}
104+
105+
if (!cpumask_equal(&class->affinity, cpu_possible_mask)) {
106+
pr_debug("class %u has missing CPUs, mask %*pb != %*pb\n", class->level,
107+
cpumask_pr_args(&class->affinity),
108+
cpumask_pr_args(cpu_possible_mask));
109+
continue;
110+
}
111+
112+
if (class->level == 2)
113+
res = &mpam_resctrl_controls[RDT_RESOURCE_L2];
114+
else
115+
res = &mpam_resctrl_controls[RDT_RESOURCE_L3];
116+
res->class = class;
117+
}
118+
}
119+
68120
static int mpam_resctrl_control_init(struct mpam_resctrl_res *res)
69121
{
70-
/* TODO: initialise the resctrl resources */
122+
struct mpam_class *class = res->class;
123+
struct rdt_resource *r = &res->resctrl_res;
124+
125+
switch (r->rid) {
126+
case RDT_RESOURCE_L2:
127+
case RDT_RESOURCE_L3:
128+
r->schema_fmt = RESCTRL_SCHEMA_BITMAP;
129+
r->cache.arch_has_sparse_bitmasks = true;
130+
131+
r->cache.cbm_len = class->props.cpbm_wd;
132+
/* mpam_devices will reject empty bitmaps */
133+
r->cache.min_cbm_bits = 1;
134+
135+
if (r->rid == RDT_RESOURCE_L2) {
136+
r->name = "L2";
137+
r->ctrl_scope = RESCTRL_L2_CACHE;
138+
r->cdp_capable = true;
139+
} else {
140+
r->name = "L3";
141+
r->ctrl_scope = RESCTRL_L3_CACHE;
142+
r->cdp_capable = true;
143+
}
144+
145+
/*
146+
* Which bits are shared with other ...things... Unknown
147+
* devices use partid-0 which uses all the bitmap fields. Until
148+
* we have configured the SMMU and GIC not to do this 'all the
149+
* bits' is the correct answer here.
150+
*/
151+
r->cache.shareable_bits = resctrl_get_default_ctrl(r);
152+
r->alloc_capable = true;
153+
break;
154+
default:
155+
return -EINVAL;
156+
}
71157

72158
return 0;
73159
}
@@ -292,7 +378,8 @@ int mpam_resctrl_setup(void)
292378
res->resctrl_res.rid = rid;
293379
}
294380

295-
/* TODO: pick MPAM classes to map to resctrl resources */
381+
/* Find some classes to use for controls */
382+
mpam_resctrl_pick_caches();
296383

297384
/* Initialise the resctrl structures from the classes */
298385
for_each_mpam_resctrl_control(res, rid) {

0 commit comments

Comments
 (0)