]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
x86,fs/resctrl: Replace architecture event enabled checks
authorTony Luck <tony.luck@intel.com>
Fri, 5 Sep 2025 21:34:01 +0000 (16:34 -0500)
committerBorislav Petkov (AMD) <bp@alien8.de>
Mon, 15 Sep 2025 09:54:14 +0000 (11:54 +0200)
The resctrl file system now has complete knowledge of the status of every
event. So there is no need for per-event function calls to check.

Replace each of the resctrl_arch_is_{event}enabled() calls with
resctrl_is_mon_event_enabled(QOS_{EVENT}).

No functional change.

Signed-off-by: Tony Luck <tony.luck@intel.com>
Signed-off-by: Babu Moger <babu.moger@amd.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Fenghua Yu <fenghuay@nvidia.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Link: https://lore.kernel.org/cover.1757108044.git.babu.moger@amd.com
arch/x86/include/asm/resctrl.h
arch/x86/kernel/cpu/resctrl/core.c
arch/x86/kernel/cpu/resctrl/monitor.c
fs/resctrl/ctrlmondata.c
fs/resctrl/monitor.c
fs/resctrl/rdtgroup.c
include/linux/resctrl.h

index feb93b50e990ac925723f6d0427d2cd3cc151e26..b1dd5d6b87db4e3f31d1bd425842867f3426c508 100644 (file)
@@ -84,21 +84,6 @@ static inline void resctrl_arch_disable_mon(void)
        static_branch_dec_cpuslocked(&rdt_enable_key);
 }
 
-static inline bool resctrl_arch_is_llc_occupancy_enabled(void)
-{
-       return (rdt_mon_features & (1 << QOS_L3_OCCUP_EVENT_ID));
-}
-
-static inline bool resctrl_arch_is_mbm_total_enabled(void)
-{
-       return (rdt_mon_features & (1 << QOS_L3_MBM_TOTAL_EVENT_ID));
-}
-
-static inline bool resctrl_arch_is_mbm_local_enabled(void)
-{
-       return (rdt_mon_features & (1 << QOS_L3_MBM_LOCAL_EVENT_ID));
-}
-
 /*
  * __resctrl_sched_in() - Writes the task's CLOSid/RMID to IA32_PQR_MSR
  *
index 7fcae25874fea17817d2e9607bd58ae2fe464297..1a319ce9328c708554d3c9b8077565a2c3ff8b07 100644 (file)
@@ -402,13 +402,13 @@ static int arch_domain_mbm_alloc(u32 num_rmid, struct rdt_hw_mon_domain *hw_dom)
 {
        size_t tsize;
 
-       if (resctrl_arch_is_mbm_total_enabled()) {
+       if (resctrl_is_mon_event_enabled(QOS_L3_MBM_TOTAL_EVENT_ID)) {
                tsize = sizeof(*hw_dom->arch_mbm_total);
                hw_dom->arch_mbm_total = kcalloc(num_rmid, tsize, GFP_KERNEL);
                if (!hw_dom->arch_mbm_total)
                        return -ENOMEM;
        }
-       if (resctrl_arch_is_mbm_local_enabled()) {
+       if (resctrl_is_mon_event_enabled(QOS_L3_MBM_LOCAL_EVENT_ID)) {
                tsize = sizeof(*hw_dom->arch_mbm_local);
                hw_dom->arch_mbm_local = kcalloc(num_rmid, tsize, GFP_KERNEL);
                if (!hw_dom->arch_mbm_local) {
index c261558276cdd41f03ff046b06ee9d9fcfc3e70a..61d38517e2bf4aa25113b73e88940ed6af0ab447 100644 (file)
@@ -207,11 +207,11 @@ void resctrl_arch_reset_rmid_all(struct rdt_resource *r, struct rdt_mon_domain *
 {
        struct rdt_hw_mon_domain *hw_dom = resctrl_to_arch_mon_dom(d);
 
-       if (resctrl_arch_is_mbm_total_enabled())
+       if (resctrl_is_mon_event_enabled(QOS_L3_MBM_TOTAL_EVENT_ID))
                memset(hw_dom->arch_mbm_total, 0,
                       sizeof(*hw_dom->arch_mbm_total) * r->num_rmid);
 
-       if (resctrl_arch_is_mbm_local_enabled())
+       if (resctrl_is_mon_event_enabled(QOS_L3_MBM_LOCAL_EVENT_ID))
                memset(hw_dom->arch_mbm_local, 0,
                       sizeof(*hw_dom->arch_mbm_local) * r->num_rmid);
 }
index 3c39cfacb2518338e40593ac32245fec62d06aa6..42b281b3852ff838994a17af958541e6edb64e16 100644 (file)
@@ -473,12 +473,12 @@ ssize_t rdtgroup_mba_mbps_event_write(struct kernfs_open_file *of,
        rdt_last_cmd_clear();
 
        if (!strcmp(buf, "mbm_local_bytes")) {
-               if (resctrl_arch_is_mbm_local_enabled())
+               if (resctrl_is_mon_event_enabled(QOS_L3_MBM_LOCAL_EVENT_ID))
                        rdtgrp->mba_mbps_event = QOS_L3_MBM_LOCAL_EVENT_ID;
                else
                        ret = -EINVAL;
        } else if (!strcmp(buf, "mbm_total_bytes")) {
-               if (resctrl_arch_is_mbm_total_enabled())
+               if (resctrl_is_mon_event_enabled(QOS_L3_MBM_TOTAL_EVENT_ID))
                        rdtgrp->mba_mbps_event = QOS_L3_MBM_TOTAL_EVENT_ID;
                else
                        ret = -EINVAL;
index d5bf3e0334b6908ca26f51919c3bf00e35122bc3..b0b1dcc367955c81968e43933084d41df93abc45 100644 (file)
@@ -336,7 +336,7 @@ void free_rmid(u32 closid, u32 rmid)
 
        entry = __rmid_entry(idx);
 
-       if (resctrl_arch_is_llc_occupancy_enabled())
+       if (resctrl_is_mon_event_enabled(QOS_L3_OCCUP_EVENT_ID))
                add_rmid_to_limbo(entry);
        else
                list_add_tail(&entry->list, &rmid_free_lru);
@@ -635,10 +635,10 @@ static void mbm_update(struct rdt_resource *r, struct rdt_mon_domain *d,
         * This is protected from concurrent reads from user as both
         * the user and overflow handler hold the global mutex.
         */
-       if (resctrl_arch_is_mbm_total_enabled())
+       if (resctrl_is_mon_event_enabled(QOS_L3_MBM_TOTAL_EVENT_ID))
                mbm_update_one_event(r, d, closid, rmid, QOS_L3_MBM_TOTAL_EVENT_ID);
 
-       if (resctrl_arch_is_mbm_local_enabled())
+       if (resctrl_is_mon_event_enabled(QOS_L3_MBM_LOCAL_EVENT_ID))
                mbm_update_one_event(r, d, closid, rmid, QOS_L3_MBM_LOCAL_EVENT_ID);
 }
 
@@ -877,6 +877,12 @@ void resctrl_enable_mon_event(enum resctrl_event_id eventid)
        mon_event_all[eventid].enabled = true;
 }
 
+bool resctrl_is_mon_event_enabled(enum resctrl_event_id eventid)
+{
+       return eventid >= QOS_FIRST_EVENT && eventid < QOS_NUM_EVENTS &&
+              mon_event_all[eventid].enabled;
+}
+
 /**
  * resctrl_mon_resource_init() - Initialise global monitoring structures.
  *
@@ -912,9 +918,9 @@ int resctrl_mon_resource_init(void)
                                         RFTYPE_MON_INFO | RFTYPE_RES_CACHE);
        }
 
-       if (resctrl_arch_is_mbm_local_enabled())
+       if (resctrl_is_mon_event_enabled(QOS_L3_MBM_LOCAL_EVENT_ID))
                mba_mbps_default_event = QOS_L3_MBM_LOCAL_EVENT_ID;
-       else if (resctrl_arch_is_mbm_total_enabled())
+       else if (resctrl_is_mon_event_enabled(QOS_L3_MBM_TOTAL_EVENT_ID))
                mba_mbps_default_event = QOS_L3_MBM_TOTAL_EVENT_ID;
 
        return 0;
index ab943a5907c5c6ecb8d92623b48e3109f815d367..2ca8e66c0d2042df8b32b5159c2cfd64dc25a87e 100644 (file)
@@ -123,8 +123,8 @@ void rdt_staged_configs_clear(void)
 
 static bool resctrl_is_mbm_enabled(void)
 {
-       return (resctrl_arch_is_mbm_total_enabled() ||
-               resctrl_arch_is_mbm_local_enabled());
+       return (resctrl_is_mon_event_enabled(QOS_L3_MBM_TOTAL_EVENT_ID) ||
+               resctrl_is_mon_event_enabled(QOS_L3_MBM_LOCAL_EVENT_ID));
 }
 
 static bool resctrl_is_mbm_event(int e)
@@ -196,7 +196,7 @@ static int closid_alloc(void)
        lockdep_assert_held(&rdtgroup_mutex);
 
        if (IS_ENABLED(CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID) &&
-           resctrl_arch_is_llc_occupancy_enabled()) {
+           resctrl_is_mon_event_enabled(QOS_L3_OCCUP_EVENT_ID)) {
                cleanest_closid = resctrl_find_cleanest_closid();
                if (cleanest_closid < 0)
                        return cleanest_closid;
@@ -4048,7 +4048,7 @@ void resctrl_offline_mon_domain(struct rdt_resource *r, struct rdt_mon_domain *d
 
        if (resctrl_is_mbm_enabled())
                cancel_delayed_work(&d->mbm_over);
-       if (resctrl_arch_is_llc_occupancy_enabled() && has_busy_rmid(d)) {
+       if (resctrl_is_mon_event_enabled(QOS_L3_OCCUP_EVENT_ID) && has_busy_rmid(d)) {
                /*
                 * When a package is going down, forcefully
                 * decrement rmid->ebusy. There is no way to know
@@ -4084,12 +4084,12 @@ static int domain_setup_mon_state(struct rdt_resource *r, struct rdt_mon_domain
        u32 idx_limit = resctrl_arch_system_num_rmid_idx();
        size_t tsize;
 
-       if (resctrl_arch_is_llc_occupancy_enabled()) {
+       if (resctrl_is_mon_event_enabled(QOS_L3_OCCUP_EVENT_ID)) {
                d->rmid_busy_llc = bitmap_zalloc(idx_limit, GFP_KERNEL);
                if (!d->rmid_busy_llc)
                        return -ENOMEM;
        }
-       if (resctrl_arch_is_mbm_total_enabled()) {
+       if (resctrl_is_mon_event_enabled(QOS_L3_MBM_TOTAL_EVENT_ID)) {
                tsize = sizeof(*d->mbm_total);
                d->mbm_total = kcalloc(idx_limit, tsize, GFP_KERNEL);
                if (!d->mbm_total) {
@@ -4097,7 +4097,7 @@ static int domain_setup_mon_state(struct rdt_resource *r, struct rdt_mon_domain
                        return -ENOMEM;
                }
        }
-       if (resctrl_arch_is_mbm_local_enabled()) {
+       if (resctrl_is_mon_event_enabled(QOS_L3_MBM_LOCAL_EVENT_ID)) {
                tsize = sizeof(*d->mbm_local);
                d->mbm_local = kcalloc(idx_limit, tsize, GFP_KERNEL);
                if (!d->mbm_local) {
@@ -4142,7 +4142,7 @@ int resctrl_online_mon_domain(struct rdt_resource *r, struct rdt_mon_domain *d)
                                           RESCTRL_PICK_ANY_CPU);
        }
 
-       if (resctrl_arch_is_llc_occupancy_enabled())
+       if (resctrl_is_mon_event_enabled(QOS_L3_OCCUP_EVENT_ID))
                INIT_DELAYED_WORK(&d->cqm_limbo, cqm_handle_limbo);
 
        /*
@@ -4217,7 +4217,7 @@ void resctrl_offline_cpu(unsigned int cpu)
                        cancel_delayed_work(&d->mbm_over);
                        mbm_setup_overflow_handler(d, 0, cpu);
                }
-               if (resctrl_arch_is_llc_occupancy_enabled() &&
+               if (resctrl_is_mon_event_enabled(QOS_L3_OCCUP_EVENT_ID) &&
                    cpu == d->cqm_work_cpu && has_busy_rmid(d)) {
                        cancel_delayed_work(&d->cqm_limbo);
                        cqm_setup_limbo_handler(d, 0, cpu);
index 2944042bd84c5d4d9e21ae552b54531290c691aa..40aba6b5d4f080ffcfa866ec0eff472d85ddeaee 100644 (file)
@@ -372,6 +372,8 @@ int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid);
 
 void resctrl_enable_mon_event(enum resctrl_event_id eventid);
 
+bool resctrl_is_mon_event_enabled(enum resctrl_event_id eventid);
+
 bool resctrl_arch_is_evt_configurable(enum resctrl_event_id evt);
 
 /**