]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
fs/resctrl: Introduce interface to display number of free MBM counters
authorBabu Moger <babu.moger@amd.com>
Fri, 5 Sep 2025 21:34:12 +0000 (16:34 -0500)
committerBorislav Petkov (AMD) <bp@alien8.de>
Mon, 15 Sep 2025 10:16:11 +0000 (12:16 +0200)
Introduce the "available_mbm_cntrs" resctrl file to display the number of
counters available for assignment in each domain when "mbm_event" mode is
enabled.

Signed-off-by: Babu Moger <babu.moger@amd.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Link: https://lore.kernel.org/cover.1757108044.git.babu.moger@amd.com
Documentation/filesystems/resctrl.rst
fs/resctrl/internal.h
fs/resctrl/monitor.c
fs/resctrl/rdtgroup.c

index 4eb27530be6ffe620088c31e42a56fd984368727..446736dbd97f1943ead365a47ef85708a829145e 100644 (file)
@@ -299,6 +299,17 @@ with the following files:
          # cat /sys/fs/resctrl/info/L3_MON/num_mbm_cntrs
          0=32;1=32
 
+"available_mbm_cntrs":
+       The number of counters available for assignment in each domain when mbm_event
+       mode is enabled on the system.
+
+       For example, on a system with 30 available [hardware] assignable counters
+       in each of its L3 domains:
+       ::
+
+         # cat /sys/fs/resctrl/info/L3_MON/available_mbm_cntrs
+         0=30;1=30
+
 "max_threshold_occupancy":
                Read/write file provides the largest value (in
                bytes) at which a previously used LLC_occupancy
index 7a12187eced821db8ad163b795cfe54ff57ab3f2..4f372e80bf373835fc830e3405e315289ffb6374 100644 (file)
@@ -388,6 +388,9 @@ int resctrl_mbm_assign_mode_show(struct kernfs_open_file *of, struct seq_file *s
 
 int resctrl_num_mbm_cntrs_show(struct kernfs_open_file *of, struct seq_file *s, void *v);
 
+int resctrl_available_mbm_cntrs_show(struct kernfs_open_file *of, struct seq_file *s,
+                                    void *v);
+
 #ifdef CONFIG_RESCTRL_FS_PSEUDO_LOCK
 int rdtgroup_locksetup_enter(struct rdtgroup *rdtgrp);
 
index 112979e9c44453894c97acd4308836e5f9ff78fe..1fa82a62b2e570fbd7758089d74465ce5da75762 100644 (file)
@@ -936,6 +936,48 @@ int resctrl_num_mbm_cntrs_show(struct kernfs_open_file *of,
        return 0;
 }
 
+int resctrl_available_mbm_cntrs_show(struct kernfs_open_file *of,
+                                    struct seq_file *s, void *v)
+{
+       struct rdt_resource *r = rdt_kn_parent_priv(of->kn);
+       struct rdt_mon_domain *dom;
+       bool sep = false;
+       u32 cntrs, i;
+       int ret = 0;
+
+       cpus_read_lock();
+       mutex_lock(&rdtgroup_mutex);
+
+       rdt_last_cmd_clear();
+
+       if (!resctrl_arch_mbm_cntr_assign_enabled(r)) {
+               rdt_last_cmd_puts("mbm_event counter assignment mode is not enabled\n");
+               ret = -EINVAL;
+               goto out_unlock;
+       }
+
+       list_for_each_entry(dom, &r->mon_domains, hdr.list) {
+               if (sep)
+                       seq_putc(s, ';');
+
+               cntrs = 0;
+               for (i = 0; i < r->mon.num_mbm_cntrs; i++) {
+                       if (!dom->cntr_cfg[i].rdtgrp)
+                               cntrs++;
+               }
+
+               seq_printf(s, "%d=%u", dom->hdr.id, cntrs);
+               sep = true;
+       }
+       seq_putc(s, '\n');
+
+out_unlock:
+       mutex_unlock(&rdtgroup_mutex);
+       cpus_read_unlock();
+
+       return ret;
+}
+
 /**
  * resctrl_mon_resource_init() - Initialise global monitoring structures.
  *
@@ -983,6 +1025,8 @@ int resctrl_mon_resource_init(void)
                        resctrl_enable_mon_event(QOS_L3_MBM_LOCAL_EVENT_ID);
                resctrl_file_fflags_init("num_mbm_cntrs",
                                         RFTYPE_MON_INFO | RFTYPE_RES_CACHE);
+               resctrl_file_fflags_init("available_mbm_cntrs",
+                                        RFTYPE_MON_INFO | RFTYPE_RES_CACHE);
        }
 
        return 0;
index 61f7b68f22730db8e7aaf3b8ea0effbecbb2c95e..2e1d0a2703da4fd5c11a2a514e1b921fdb9bd12c 100644 (file)
@@ -1822,6 +1822,12 @@ static struct rftype res_common_files[] = {
                .seq_show       = rdt_mon_features_show,
                .fflags         = RFTYPE_MON_INFO,
        },
+       {
+               .name           = "available_mbm_cntrs",
+               .mode           = 0444,
+               .kf_ops         = &rdtgroup_kf_single_ops,
+               .seq_show       = resctrl_available_mbm_cntrs_show,
+       },
        {
                .name           = "num_rmids",
                .mode           = 0444,