]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
x86/resctrl: Move rdt_find_domain() to be visible to arch and fs code
authorJames Morse <james.morse@arm.com>
Tue, 11 Mar 2025 18:36:57 +0000 (18:36 +0000)
committerBorislav Petkov (AMD) <bp@alien8.de>
Wed, 12 Mar 2025 11:22:56 +0000 (12:22 +0100)
rdt_find_domain() finds a domain given a resource and a cache-id.  This is
used by both the architecture code and the filesystem code.

After the filesystem code moves to live in /fs/, this helper is either
duplicated by all architectures, or needs exposing by the filesystem code.

Add the declaration to the global header file. As it's now globally visible,
and has only a handful of callers, swap the 'rdt' for 'resctrl'. Move the
function to live with its caller in ctrlmondata.c as the filesystem code will
not have anything corresponding to core.c.

Signed-off-by: James Morse <james.morse@arm.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>
Reviewed-by: Babu Moger <babu.moger@amd.com>
Reviewed-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com>
Tested-by: Peter Newman <peternewman@google.com>
Tested-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.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-13-james.morse@arm.com
arch/x86/kernel/cpu/resctrl/core.c
arch/x86/kernel/cpu/resctrl/ctrlmondata.c
arch/x86/kernel/cpu/resctrl/internal.h
include/linux/resctrl.h

index 212995149eace466574b73e7f40034d338723228..850cb8643c4a5893a14d1bebad4046a2fd995b3c 100644 (file)
@@ -394,36 +394,6 @@ void rdt_ctrl_update(void *arg)
        hw_res->msr_update(m);
 }
 
-/*
- * rdt_find_domain - Search for a domain id in a resource domain list.
- *
- * Search the domain list to find the domain id. If the domain id is
- * found, return the domain. NULL otherwise.  If the domain id is not
- * found (and NULL returned) then the first domain with id bigger than
- * the input id can be returned to the caller via @pos.
- */
-struct rdt_domain_hdr *rdt_find_domain(struct list_head *h, int id,
-                                      struct list_head **pos)
-{
-       struct rdt_domain_hdr *d;
-       struct list_head *l;
-
-       list_for_each(l, h) {
-               d = list_entry(l, struct rdt_domain_hdr, list);
-               /* When id is found, return its domain. */
-               if (id == d->id)
-                       return d;
-               /* Stop searching when finding id's position in sorted list. */
-               if (id < d->id)
-                       break;
-       }
-
-       if (pos)
-               *pos = l;
-
-       return NULL;
-}
-
 static void setup_default_ctrlval(struct rdt_resource *r, u32 *dc)
 {
        struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r);
@@ -534,7 +504,7 @@ static void domain_add_cpu_ctrl(int cpu, struct rdt_resource *r)
                return;
        }
 
-       hdr = rdt_find_domain(&r->ctrl_domains, id, &add_pos);
+       hdr = resctrl_find_domain(&r->ctrl_domains, id, &add_pos);
        if (hdr) {
                if (WARN_ON_ONCE(hdr->type != RESCTRL_CTRL_DOMAIN))
                        return;
@@ -589,7 +559,7 @@ static void domain_add_cpu_mon(int cpu, struct rdt_resource *r)
                return;
        }
 
-       hdr = rdt_find_domain(&r->mon_domains, id, &add_pos);
+       hdr = resctrl_find_domain(&r->mon_domains, id, &add_pos);
        if (hdr) {
                if (WARN_ON_ONCE(hdr->type != RESCTRL_MON_DOMAIN))
                        return;
@@ -654,7 +624,7 @@ static void domain_remove_cpu_ctrl(int cpu, struct rdt_resource *r)
                return;
        }
 
-       hdr = rdt_find_domain(&r->ctrl_domains, id, NULL);
+       hdr = resctrl_find_domain(&r->ctrl_domains, id, NULL);
        if (!hdr) {
                pr_warn("Can't find control domain for id=%d for CPU %d for resource %s\n",
                        id, cpu, r->name);
@@ -700,7 +670,7 @@ static void domain_remove_cpu_mon(int cpu, struct rdt_resource *r)
                return;
        }
 
-       hdr = rdt_find_domain(&r->mon_domains, id, NULL);
+       hdr = resctrl_find_domain(&r->mon_domains, id, NULL);
        if (!hdr) {
                pr_warn("Can't find monitor domain for id=%d for CPU %d for resource %s\n",
                        id, cpu, r->name);
index 5d87f279085f78243a400d3664587cdcf6a8550b..763317ea22565ac407f3e0df0deb26ee876ed753 100644 (file)
@@ -610,6 +610,28 @@ int rdtgroup_mba_mbps_event_show(struct kernfs_open_file *of,
        return ret;
 }
 
+struct rdt_domain_hdr *resctrl_find_domain(struct list_head *h, int id,
+                                          struct list_head **pos)
+{
+       struct rdt_domain_hdr *d;
+       struct list_head *l;
+
+       list_for_each(l, h) {
+               d = list_entry(l, struct rdt_domain_hdr, list);
+               /* When id is found, return its domain. */
+               if (id == d->id)
+                       return d;
+               /* Stop searching when finding id's position in sorted list. */
+               if (id < d->id)
+                       break;
+       }
+
+       if (pos)
+               *pos = l;
+
+       return NULL;
+}
+
 void mon_event_read(struct rmid_read *rr, struct rdt_resource *r,
                    struct rdt_mon_domain *d, struct rdtgroup *rdtgrp,
                    cpumask_t *cpumask, int evtid, int first)
@@ -695,7 +717,7 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg)
                 * This file provides data from a single domain. Search
                 * the resource to find the domain with "domid".
                 */
-               hdr = rdt_find_domain(&r->mon_domains, domid, NULL);
+               hdr = resctrl_find_domain(&r->mon_domains, domid, NULL);
                if (!hdr || WARN_ON_ONCE(hdr->type != RESCTRL_MON_DOMAIN)) {
                        ret = -ENOENT;
                        goto out;
index 8291f1b599812b51a15f3452e03665c66f64eca7..da73404183da257fedef6a27a0faeb140ae65712 100644 (file)
@@ -581,8 +581,6 @@ void rdtgroup_kn_unlock(struct kernfs_node *kn);
 int rdtgroup_kn_mode_restrict(struct rdtgroup *r, const char *name);
 int rdtgroup_kn_mode_restore(struct rdtgroup *r, const char *name,
                             umode_t mask);
-struct rdt_domain_hdr *rdt_find_domain(struct list_head *h, int id,
-                                      struct list_head **pos);
 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,
index f1979e375da9afc4ab73e1a24fb7c4ba2994d3e4..93d9a435f035f67d173abef9f56cdbf38a9b43f3 100644 (file)
@@ -372,6 +372,20 @@ static inline void resctrl_arch_rmid_read_context_check(void)
                might_sleep();
 }
 
+/**
+ * resctrl_find_domain() - Search for a domain id in a resource domain list.
+ * @h:         The domain list to search.
+ * @id:                The domain id to search for.
+ * @pos:       A pointer to position in the list id should be inserted.
+ *
+ * Search the domain list to find the domain id. If the domain id is
+ * found, return the domain. NULL otherwise.  If the domain id is not
+ * found (and NULL returned) then the first domain with id bigger than
+ * the input id can be returned to the caller via @pos.
+ */
+struct rdt_domain_hdr *resctrl_find_domain(struct list_head *h, int id,
+                                          struct list_head **pos);
+
 /**
  * resctrl_arch_reset_rmid() - Reset any private state associated with rmid
  *                            and eventid.