Skip to content

Commit bb9343c

Browse files
James Morsebp3tk0v
authored andcommitted
x86/resctrl: Use schema type to determine the schema format string
Resctrl's architecture code gets to specify a format string that is used when printing schema entries. This is expected to be one of two values that the filesystem code supports. Setting this format string allows the architecture code to change the ABI resctrl presents to user-space. Instead, use the schema format enum to choose which format string to use. Signed-off-by: James Morse <james.morse@arm.com> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Reviewed-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com> Reviewed-by: Reinette Chatre <reinette.chatre@intel.com> Reviewed-by: Tony Luck <tony.luck@intel.com> Reviewed-by: Fenghua Yu <fenghuay@nvidia.com> Reviewed-by: Babu Moger <babu.moger@amd.com> Tested-by: Carl Worth <carl@os.amperecomputing.com> # arm64 Tested-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com> Tested-by: Peter Newman <peternewman@google.com> Tested-by: Amit Singh Tomar <amitsinght@marvell.com> # arm64 Tested-by: Shanker Donthineni <sdonthineni@nvidia.com> # arm64 Tested-by: Babu Moger <babu.moger@amd.com> Link: https://lore.kernel.org/r/20250311183715.16445-6-james.morse@arm.com
1 parent c24f5ea commit bb9343c

4 files changed

Lines changed: 17 additions & 7 deletions

File tree

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ struct rdt_hw_resource rdt_resources_all[RDT_NUM_RESOURCES] = {
7373
.ctrl_domains = ctrl_domain_init(RDT_RESOURCE_L3),
7474
.mon_domains = mon_domain_init(RDT_RESOURCE_L3),
7575
.schema_fmt = RESCTRL_SCHEMA_BITMAP,
76-
.format_str = "%d=%0*x",
7776
},
7877
.msr_base = MSR_IA32_L3_CBM_BASE,
7978
.msr_update = cat_wrmsr,
@@ -86,7 +85,6 @@ struct rdt_hw_resource rdt_resources_all[RDT_NUM_RESOURCES] = {
8685
.ctrl_scope = RESCTRL_L2_CACHE,
8786
.ctrl_domains = ctrl_domain_init(RDT_RESOURCE_L2),
8887
.schema_fmt = RESCTRL_SCHEMA_BITMAP,
89-
.format_str = "%d=%0*x",
9088
},
9189
.msr_base = MSR_IA32_L2_CBM_BASE,
9290
.msr_update = cat_wrmsr,
@@ -99,7 +97,6 @@ struct rdt_hw_resource rdt_resources_all[RDT_NUM_RESOURCES] = {
9997
.ctrl_scope = RESCTRL_L3_CACHE,
10098
.ctrl_domains = ctrl_domain_init(RDT_RESOURCE_MBA),
10199
.schema_fmt = RESCTRL_SCHEMA_RANGE,
102-
.format_str = "%d=%*u",
103100
},
104101
},
105102
[RDT_RESOURCE_SMBA] =
@@ -110,7 +107,6 @@ struct rdt_hw_resource rdt_resources_all[RDT_NUM_RESOURCES] = {
110107
.ctrl_scope = RESCTRL_L3_CACHE,
111108
.ctrl_domains = ctrl_domain_init(RDT_RESOURCE_SMBA),
112109
.schema_fmt = RESCTRL_SCHEMA_RANGE,
113-
.format_str = "%d=%*u",
114110
},
115111
},
116112
};

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ static void show_doms(struct seq_file *s, struct resctrl_schema *schema, int clo
487487
ctrl_val = resctrl_arch_get_config(r, dom, closid,
488488
schema->conf_type);
489489

490-
seq_printf(s, r->format_str, dom->hdr.id, max_data_width,
490+
seq_printf(s, schema->fmt_str, dom->hdr.id, max_data_width,
491491
ctrl_val);
492492
sep = true;
493493
}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2611,6 +2611,20 @@ static int schemata_list_add(struct rdt_resource *r, enum resctrl_conf_type type
26112611
if (cl > max_name_width)
26122612
max_name_width = cl;
26132613

2614+
switch (r->schema_fmt) {
2615+
case RESCTRL_SCHEMA_BITMAP:
2616+
s->fmt_str = "%d=%0*x";
2617+
break;
2618+
case RESCTRL_SCHEMA_RANGE:
2619+
s->fmt_str = "%d=%0*u";
2620+
break;
2621+
}
2622+
2623+
if (WARN_ON_ONCE(!s->fmt_str)) {
2624+
kfree(s);
2625+
return -EINVAL;
2626+
}
2627+
26142628
INIT_LIST_HEAD(&s->list);
26152629
list_add(&s->list, &resctrl_schema_all);
26162630

include/linux/resctrl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,6 @@ enum resctrl_schema_fmt {
216216
* @name: Name to use in "schemata" file.
217217
* @data_width: Character width of data when displaying
218218
* @default_ctrl: Specifies default cache cbm or memory B/W percent.
219-
* @format_str: Per resource format string to show domain value
220219
* @schema_fmt: Which format string and parser is used for this schema.
221220
* @evt_list: List of monitoring events
222221
* @cdp_capable: Is the CDP feature available on this resource
@@ -235,7 +234,6 @@ struct rdt_resource {
235234
char *name;
236235
int data_width;
237236
u32 default_ctrl;
238-
const char *format_str;
239237
enum resctrl_schema_fmt schema_fmt;
240238
struct list_head evt_list;
241239
bool cdp_capable;
@@ -253,6 +251,7 @@ struct rdt_resource *resctrl_arch_get_resource(enum resctrl_res_level l);
253251
* user-space
254252
* @list: Member of resctrl_schema_all.
255253
* @name: The name to use in the "schemata" file.
254+
* @fmt_str: Format string to show domain value.
256255
* @conf_type: Whether this schema is specific to code/data.
257256
* @res: The resource structure exported by the architecture to describe
258257
* the hardware that is configured by this schema.
@@ -263,6 +262,7 @@ struct rdt_resource *resctrl_arch_get_resource(enum resctrl_res_level l);
263262
struct resctrl_schema {
264263
struct list_head list;
265264
char name[8];
265+
const char *fmt_str;
266266
enum resctrl_conf_type conf_type;
267267
struct rdt_resource *res;
268268
u32 num_closid;

0 commit comments

Comments
 (0)