]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
x86/resctrl: Use schema type to determine the schema format string
authorJames Morse <james.morse@arm.com>
Tue, 11 Mar 2025 18:36:50 +0000 (18:36 +0000)
committerBorislav Petkov (AMD) <bp@alien8.de>
Wed, 12 Mar 2025 11:22:33 +0000 (12:22 +0100)
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
arch/x86/kernel/cpu/resctrl/core.c
arch/x86/kernel/cpu/resctrl/ctrlmondata.c
arch/x86/kernel/cpu/resctrl/rdtgroup.c
include/linux/resctrl.h

index e9fe129a02f84eeeacd73535afe9d217a9fae37b..542503a8c953db659612b4bed7c5ca8e30bdf89c 100644 (file)
@@ -73,7 +73,6 @@ struct rdt_hw_resource rdt_resources_all[RDT_NUM_RESOURCES] = {
                        .ctrl_domains           = ctrl_domain_init(RDT_RESOURCE_L3),
                        .mon_domains            = mon_domain_init(RDT_RESOURCE_L3),
                        .schema_fmt             = RESCTRL_SCHEMA_BITMAP,
-                       .format_str             = "%d=%0*x",
                },
                .msr_base               = MSR_IA32_L3_CBM_BASE,
                .msr_update             = cat_wrmsr,
@@ -86,7 +85,6 @@ struct rdt_hw_resource rdt_resources_all[RDT_NUM_RESOURCES] = {
                        .ctrl_scope             = RESCTRL_L2_CACHE,
                        .ctrl_domains           = ctrl_domain_init(RDT_RESOURCE_L2),
                        .schema_fmt             = RESCTRL_SCHEMA_BITMAP,
-                       .format_str             = "%d=%0*x",
                },
                .msr_base               = MSR_IA32_L2_CBM_BASE,
                .msr_update             = cat_wrmsr,
@@ -99,7 +97,6 @@ struct rdt_hw_resource rdt_resources_all[RDT_NUM_RESOURCES] = {
                        .ctrl_scope             = RESCTRL_L3_CACHE,
                        .ctrl_domains           = ctrl_domain_init(RDT_RESOURCE_MBA),
                        .schema_fmt             = RESCTRL_SCHEMA_RANGE,
-                       .format_str             = "%d=%*u",
                },
        },
        [RDT_RESOURCE_SMBA] =
@@ -110,7 +107,6 @@ struct rdt_hw_resource rdt_resources_all[RDT_NUM_RESOURCES] = {
                        .ctrl_scope             = RESCTRL_L3_CACHE,
                        .ctrl_domains           = ctrl_domain_init(RDT_RESOURCE_SMBA),
                        .schema_fmt             = RESCTRL_SCHEMA_RANGE,
-                       .format_str             = "%d=%*u",
                },
        },
 };
index f4334f437ffc7d0ceab01f7ba522ba19b51a4028..c763cb4fb1a887aa73436cc6a316f6009b3b7caa 100644 (file)
@@ -487,7 +487,7 @@ static void show_doms(struct seq_file *s, struct resctrl_schema *schema, int clo
                        ctrl_val = resctrl_arch_get_config(r, dom, closid,
                                                           schema->conf_type);
 
-               seq_printf(s, r->format_str, dom->hdr.id, max_data_width,
+               seq_printf(s, schema->fmt_str, dom->hdr.id, max_data_width,
                           ctrl_val);
                sep = true;
        }
index 3391ac8ecb2def0dff052049742d76b208e33049..e7862d0936c94fc690ee79a51f304bb26bb12183 100644 (file)
@@ -2611,6 +2611,20 @@ static int schemata_list_add(struct rdt_resource *r, enum resctrl_conf_type type
        if (cl > max_name_width)
                max_name_width = cl;
 
+       switch (r->schema_fmt) {
+       case RESCTRL_SCHEMA_BITMAP:
+               s->fmt_str = "%d=%0*x";
+               break;
+       case RESCTRL_SCHEMA_RANGE:
+               s->fmt_str = "%d=%0*u";
+               break;
+       }
+
+       if (WARN_ON_ONCE(!s->fmt_str)) {
+               kfree(s);
+               return -EINVAL;
+       }
+
        INIT_LIST_HEAD(&s->list);
        list_add(&s->list, &resctrl_schema_all);
 
index 3e1a41356b2a79876386b28f0effc67024ed7c85..736b9a9a9464eee79f4d56fb7da1d631d4ae5f74 100644 (file)
@@ -216,7 +216,6 @@ enum resctrl_schema_fmt {
  * @name:              Name to use in "schemata" file.
  * @data_width:                Character width of data when displaying
  * @default_ctrl:      Specifies default cache cbm or memory B/W percent.
- * @format_str:                Per resource format string to show domain value
  * @schema_fmt:                Which format string and parser is used for this schema.
  * @evt_list:          List of monitoring events
  * @cdp_capable:       Is the CDP feature available on this resource
@@ -235,7 +234,6 @@ struct rdt_resource {
        char                    *name;
        int                     data_width;
        u32                     default_ctrl;
-       const char              *format_str;
        enum resctrl_schema_fmt schema_fmt;
        struct list_head        evt_list;
        bool                    cdp_capable;
@@ -253,6 +251,7 @@ struct rdt_resource *resctrl_arch_get_resource(enum resctrl_res_level l);
  *                        user-space
  * @list:      Member of resctrl_schema_all.
  * @name:      The name to use in the "schemata" file.
+ * @fmt_str:   Format string to show domain value.
  * @conf_type: Whether this schema is specific to code/data.
  * @res:       The resource structure exported by the architecture to describe
  *             the hardware that is configured by this schema.
@@ -263,6 +262,7 @@ struct rdt_resource *resctrl_arch_get_resource(enum resctrl_res_level l);
 struct resctrl_schema {
        struct list_head                list;
        char                            name[8];
+       const char                      *fmt_str;
        enum resctrl_conf_type          conf_type;
        struct rdt_resource             *res;
        u32                             num_closid;