]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
x86/resctrl: Add write option to "mba_MBps_event" file
authorTony Luck <tony.luck@intel.com>
Fri, 6 Dec 2024 16:31:47 +0000 (08:31 -0800)
committerBorislav Petkov (AMD) <bp@alien8.de>
Thu, 12 Dec 2024 10:27:37 +0000 (11:27 +0100)
The "mba_MBps" mount option provides an alternate method to control memory
bandwidth. Instead of specifying allowable bandwidth as a percentage of
maximum possible, the user provides a MiB/s limit value.

There is a file in each CTRL_MON group directory that shows the event
currently in use.

Allow writing that file to choose a different event.

A user can choose any of the memory bandwidth monitoring events listed in
/sys/fs/resctrl/info/L3_mon/mon_features independently for each CTRL_MON group
by writing to each of the "mba_MBps_event" files.

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>
Tested-by: Babu Moger <babu.moger@amd.com>
Link: https://lore.kernel.org/r/20241206163148.83828-8-tony.luck@intel.com
arch/x86/kernel/cpu/resctrl/ctrlmondata.c
arch/x86/kernel/cpu/resctrl/internal.h
arch/x86/kernel/cpu/resctrl/rdtgroup.c

index 5fa37b4ecc7a44d94653446d20ef2ca5da9a9f61..536351159cc23ca60855e1fdc969c4917c2b1376 100644 (file)
@@ -518,6 +518,46 @@ static int smp_mon_event_count(void *arg)
        return 0;
 }
 
+ssize_t rdtgroup_mba_mbps_event_write(struct kernfs_open_file *of,
+                                     char *buf, size_t nbytes, loff_t off)
+{
+       struct rdtgroup *rdtgrp;
+       int ret = 0;
+
+       /* Valid input requires a trailing newline */
+       if (nbytes == 0 || buf[nbytes - 1] != '\n')
+               return -EINVAL;
+       buf[nbytes - 1] = '\0';
+
+       rdtgrp = rdtgroup_kn_lock_live(of->kn);
+       if (!rdtgrp) {
+               rdtgroup_kn_unlock(of->kn);
+               return -ENOENT;
+       }
+       rdt_last_cmd_clear();
+
+       if (!strcmp(buf, "mbm_local_bytes")) {
+               if (is_mbm_local_enabled())
+                       rdtgrp->mba_mbps_event = QOS_L3_MBM_LOCAL_EVENT_ID;
+               else
+                       ret = -EINVAL;
+       } else if (!strcmp(buf, "mbm_total_bytes")) {
+               if (is_mbm_total_enabled())
+                       rdtgrp->mba_mbps_event = QOS_L3_MBM_TOTAL_EVENT_ID;
+               else
+                       ret = -EINVAL;
+       } else {
+               ret = -EINVAL;
+       }
+
+       if (ret)
+               rdt_last_cmd_printf("Unsupported event id '%s'\n", buf);
+
+       rdtgroup_kn_unlock(of->kn);
+
+       return ret ?: nbytes;
+}
+
 int rdtgroup_mba_mbps_event_show(struct kernfs_open_file *of,
                                 struct seq_file *s, void *v)
 {
index 1bd61edbaf12d1749a8a19e27d2eb97023eee132..20c898f09b7e7044f033923a5acd8f928791c54f 100644 (file)
@@ -610,6 +610,8 @@ ssize_t rdtgroup_schemata_write(struct kernfs_open_file *of,
                                char *buf, size_t nbytes, loff_t off);
 int rdtgroup_schemata_show(struct kernfs_open_file *of,
                           struct seq_file *s, void *v);
+ssize_t rdtgroup_mba_mbps_event_write(struct kernfs_open_file *of,
+                                     char *buf, size_t nbytes, loff_t off);
 int rdtgroup_mba_mbps_event_show(struct kernfs_open_file *of,
                                 struct seq_file *s, void *v);
 bool rdtgroup_cbm_overlaps(struct resctrl_schema *s, struct rdt_ctrl_domain *d,
index 6eb930b8bdfd9918ba6d3b1d31e7d60ba23a512a..6419e04d8a7b2b1c6a895e252716e7d2958a7f23 100644 (file)
@@ -1952,8 +1952,9 @@ static struct rftype res_common_files[] = {
        },
        {
                .name           = "mba_MBps_event",
-               .mode           = 0444,
+               .mode           = 0644,
                .kf_ops         = &rdtgroup_kf_single_ops,
+               .write          = rdtgroup_mba_mbps_event_write,
                .seq_show       = rdtgroup_mba_mbps_event_show,
        },
        {