Skip to content

Commit 1c29068

Browse files
James Morsesuryasaimadhu
authored andcommitted
x86/resctrl: Pass the schema to resctrl filesystem functions
Once the CDP resources are merged, there will be two struct resctrl_schema for one struct rdt_resource. CDP becomes a type of configuration that belongs to the schema. Helpers like rdtgroup_cbm_overlaps() need access to the schema to query the configuration (or configurations) based on schema properties. Change these functions to take a struct schema instead of the struct rdt_resource. All the modified functions are part of the filesystem code that will move to /fs/resctrl once it is possible to support a second architecture. Signed-off-by: James Morse <james.morse@arm.com> Signed-off-by: Borislav Petkov <bp@suse.de> Reviewed-by: Jamie Iles <jamie@nuviainc.com> Reviewed-by: Reinette Chatre <reinette.chatre@intel.com> Tested-by: Babu Moger <babu.moger@amd.com> Link: https://lkml.kernel.org/r/20210728170637.25610-10-james.morse@arm.com
1 parent eb6f318 commit 1c29068

File tree

4 files changed

+29
-22
lines changed

4 files changed

+29
-22
lines changed

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

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,10 @@ static bool bw_validate(char *buf, unsigned long *data, struct rdt_resource *r)
5757
return true;
5858
}
5959

60-
int parse_bw(struct rdt_parse_data *data, struct rdt_resource *r,
60+
int parse_bw(struct rdt_parse_data *data, struct resctrl_schema *s,
6161
struct rdt_domain *d)
6262
{
63+
struct rdt_resource *r = s->res;
6364
unsigned long bw_val;
6465

6566
if (d->have_new_ctrl) {
@@ -125,10 +126,11 @@ static bool cbm_validate(char *buf, u32 *data, struct rdt_resource *r)
125126
* Read one cache bit mask (hex). Check that it is valid for the current
126127
* resource type.
127128
*/
128-
int parse_cbm(struct rdt_parse_data *data, struct rdt_resource *r,
129+
int parse_cbm(struct rdt_parse_data *data, struct resctrl_schema *s,
129130
struct rdt_domain *d)
130131
{
131132
struct rdtgroup *rdtgrp = data->rdtgrp;
133+
struct rdt_resource *r = s->res;
132134
u32 cbm_val;
133135

134136
if (d->have_new_ctrl) {
@@ -160,12 +162,12 @@ int parse_cbm(struct rdt_parse_data *data, struct rdt_resource *r,
160162
* The CBM may not overlap with the CBM of another closid if
161163
* either is exclusive.
162164
*/
163-
if (rdtgroup_cbm_overlaps(r, d, cbm_val, rdtgrp->closid, true)) {
165+
if (rdtgroup_cbm_overlaps(s, d, cbm_val, rdtgrp->closid, true)) {
164166
rdt_last_cmd_puts("Overlaps with exclusive group\n");
165167
return -EINVAL;
166168
}
167169

168-
if (rdtgroup_cbm_overlaps(r, d, cbm_val, rdtgrp->closid, false)) {
170+
if (rdtgroup_cbm_overlaps(s, d, cbm_val, rdtgrp->closid, false)) {
169171
if (rdtgrp->mode == RDT_MODE_EXCLUSIVE ||
170172
rdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP) {
171173
rdt_last_cmd_puts("Overlaps with other group\n");
@@ -185,9 +187,10 @@ int parse_cbm(struct rdt_parse_data *data, struct rdt_resource *r,
185187
* separated by ";". The "id" is in decimal, and must match one of
186188
* the "id"s for this resource.
187189
*/
188-
static int parse_line(char *line, struct rdt_resource *r,
190+
static int parse_line(char *line, struct resctrl_schema *s,
189191
struct rdtgroup *rdtgrp)
190192
{
193+
struct rdt_resource *r = s->res;
191194
struct rdt_parse_data data;
192195
char *dom = NULL, *id;
193196
struct rdt_domain *d;
@@ -213,7 +216,7 @@ static int parse_line(char *line, struct rdt_resource *r,
213216
if (d->id == dom_id) {
214217
data.buf = dom;
215218
data.rdtgrp = rdtgrp;
216-
if (r->parse_ctrlval(&data, r, d))
219+
if (r->parse_ctrlval(&data, s, d))
217220
return -EINVAL;
218221
if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP) {
219222
/*
@@ -292,7 +295,7 @@ static int rdtgroup_parse_resource(char *resname, char *tok,
292295
list_for_each_entry(s, &resctrl_schema_all, list) {
293296
r = s->res;
294297
if (!strcmp(resname, r->name) && rdtgrp->closid < s->num_closid)
295-
return parse_line(tok, r, rdtgrp);
298+
return parse_line(tok, s, rdtgrp);
296299
}
297300
rdt_last_cmd_printf("Unknown or unsupported resource name '%s'\n", resname);
298301
return -EINVAL;
@@ -377,8 +380,9 @@ ssize_t rdtgroup_schemata_write(struct kernfs_open_file *of,
377380
return ret ?: nbytes;
378381
}
379382

380-
static void show_doms(struct seq_file *s, struct rdt_resource *r, int closid)
383+
static void show_doms(struct seq_file *s, struct resctrl_schema *schema, int closid)
381384
{
385+
struct rdt_resource *r = schema->res;
382386
struct rdt_hw_domain *hw_dom;
383387
struct rdt_domain *dom;
384388
bool sep = false;
@@ -429,9 +433,8 @@ int rdtgroup_schemata_show(struct kernfs_open_file *of,
429433
} else {
430434
closid = rdtgrp->closid;
431435
list_for_each_entry(schema, &resctrl_schema_all, list) {
432-
r = schema->res;
433436
if (closid < schema->num_closid)
434-
show_doms(s, r, closid);
437+
show_doms(s, schema, closid);
435438
}
436439
}
437440
} else {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,9 +401,9 @@ static inline struct rdt_hw_resource *resctrl_to_arch_res(struct rdt_resource *r
401401
return container_of(r, struct rdt_hw_resource, r_resctrl);
402402
}
403403

404-
int parse_cbm(struct rdt_parse_data *data, struct rdt_resource *r,
404+
int parse_cbm(struct rdt_parse_data *data, struct resctrl_schema *s,
405405
struct rdt_domain *d);
406-
int parse_bw(struct rdt_parse_data *data, struct rdt_resource *r,
406+
int parse_bw(struct rdt_parse_data *data, struct resctrl_schema *s,
407407
struct rdt_domain *d);
408408

409409
extern struct mutex rdtgroup_mutex;
@@ -505,7 +505,7 @@ ssize_t rdtgroup_schemata_write(struct kernfs_open_file *of,
505505
char *buf, size_t nbytes, loff_t off);
506506
int rdtgroup_schemata_show(struct kernfs_open_file *of,
507507
struct seq_file *s, void *v);
508-
bool rdtgroup_cbm_overlaps(struct rdt_resource *r, struct rdt_domain *d,
508+
bool rdtgroup_cbm_overlaps(struct resctrl_schema *s, struct rdt_domain *d,
509509
unsigned long cbm, int closid, bool exclusive);
510510
unsigned int rdtgroup_cbm_to_size(struct rdt_resource *r, struct rdt_domain *d,
511511
unsigned long cbm);

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,7 +1221,7 @@ static bool __rdtgroup_cbm_overlaps(struct rdt_resource *r, struct rdt_domain *d
12211221

12221222
/**
12231223
* rdtgroup_cbm_overlaps - Does CBM overlap with other use of hardware
1224-
* @r: Resource to which domain instance @d belongs.
1224+
* @s: Schema for the resource to which domain instance @d belongs.
12251225
* @d: The domain instance for which @closid is being tested.
12261226
* @cbm: Capacity bitmask being tested.
12271227
* @closid: Intended closid for @cbm.
@@ -1239,9 +1239,10 @@ static bool __rdtgroup_cbm_overlaps(struct rdt_resource *r, struct rdt_domain *d
12391239
*
12401240
* Return: true if CBM overlap detected, false if there is no overlap
12411241
*/
1242-
bool rdtgroup_cbm_overlaps(struct rdt_resource *r, struct rdt_domain *d,
1242+
bool rdtgroup_cbm_overlaps(struct resctrl_schema *s, struct rdt_domain *d,
12431243
unsigned long cbm, int closid, bool exclusive)
12441244
{
1245+
struct rdt_resource *r = s->res;
12451246
struct rdt_resource *r_cdp;
12461247
struct rdt_domain *d_cdp;
12471248

@@ -1282,7 +1283,8 @@ static bool rdtgroup_mode_test_exclusive(struct rdtgroup *rdtgrp)
12821283
has_cache = true;
12831284
list_for_each_entry(d, &r->domains, list) {
12841285
hw_dom = resctrl_to_arch_dom(d);
1285-
if (rdtgroup_cbm_overlaps(r, d, hw_dom->ctrl_val[closid],
1286+
if (rdtgroup_cbm_overlaps(s, d,
1287+
hw_dom->ctrl_val[closid],
12861288
rdtgrp->closid, false)) {
12871289
rdt_last_cmd_puts("Schemata overlaps\n");
12881290
return false;
@@ -2712,11 +2714,12 @@ static u32 cbm_ensure_valid(u32 _val, struct rdt_resource *r)
27122714
* Set the RDT domain up to start off with all usable allocations. That is,
27132715
* all shareable and unused bits. All-zero CBM is invalid.
27142716
*/
2715-
static int __init_one_rdt_domain(struct rdt_domain *d, struct rdt_resource *r,
2717+
static int __init_one_rdt_domain(struct rdt_domain *d, struct resctrl_schema *s,
27162718
u32 closid)
27172719
{
27182720
struct rdt_resource *r_cdp = NULL;
27192721
struct rdt_domain *d_cdp = NULL;
2722+
struct rdt_resource *r = s->res;
27202723
u32 used_b = 0, unused_b = 0;
27212724
unsigned long tmp_cbm;
27222725
enum rdtgrp_mode mode;
@@ -2786,13 +2789,13 @@ static int __init_one_rdt_domain(struct rdt_domain *d, struct rdt_resource *r,
27862789
* If there are no more shareable bits available on any domain then
27872790
* the entire allocation will fail.
27882791
*/
2789-
static int rdtgroup_init_cat(struct rdt_resource *r, u32 closid)
2792+
static int rdtgroup_init_cat(struct resctrl_schema *s, u32 closid)
27902793
{
27912794
struct rdt_domain *d;
27922795
int ret;
27932796

2794-
list_for_each_entry(d, &r->domains, list) {
2795-
ret = __init_one_rdt_domain(d, r, closid);
2797+
list_for_each_entry(d, &s->res->domains, list) {
2798+
ret = __init_one_rdt_domain(d, s, closid);
27962799
if (ret < 0)
27972800
return ret;
27982801
}
@@ -2823,7 +2826,7 @@ static int rdtgroup_init_alloc(struct rdtgroup *rdtgrp)
28232826
if (r->rid == RDT_RESOURCE_MBA) {
28242827
rdtgroup_init_mba(r);
28252828
} else {
2826-
ret = rdtgroup_init_cat(r, rdtgrp->closid);
2829+
ret = rdtgroup_init_cat(s, rdtgrp->closid);
28272830
if (ret < 0)
28282831
return ret;
28292832
}

include/linux/resctrl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ struct resctrl_membw {
121121
};
122122

123123
struct rdt_parse_data;
124+
struct resctrl_schema;
124125

125126
/**
126127
* struct rdt_resource - attributes of a resctrl resource
@@ -158,7 +159,7 @@ struct rdt_resource {
158159
u32 default_ctrl;
159160
const char *format_str;
160161
int (*parse_ctrlval)(struct rdt_parse_data *data,
161-
struct rdt_resource *r,
162+
struct resctrl_schema *s,
162163
struct rdt_domain *d);
163164
struct list_head evt_list;
164165
unsigned long fflags;

0 commit comments

Comments
 (0)