Skip to content

Commit e3d5138

Browse files
James Morsebp3tk0v
authored andcommitted
x86/resctrl: Move rdt_find_domain() to be visible to arch and fs code
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
1 parent 8079565 commit e3d5138

4 files changed

Lines changed: 41 additions & 37 deletions

File tree

arch/x86/kernel/cpu/resctrl/core.c

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -394,36 +394,6 @@ void rdt_ctrl_update(void *arg)
394394
hw_res->msr_update(m);
395395
}
396396

397-
/*
398-
* rdt_find_domain - Search for a domain id in a resource domain list.
399-
*
400-
* Search the domain list to find the domain id. If the domain id is
401-
* found, return the domain. NULL otherwise. If the domain id is not
402-
* found (and NULL returned) then the first domain with id bigger than
403-
* the input id can be returned to the caller via @pos.
404-
*/
405-
struct rdt_domain_hdr *rdt_find_domain(struct list_head *h, int id,
406-
struct list_head **pos)
407-
{
408-
struct rdt_domain_hdr *d;
409-
struct list_head *l;
410-
411-
list_for_each(l, h) {
412-
d = list_entry(l, struct rdt_domain_hdr, list);
413-
/* When id is found, return its domain. */
414-
if (id == d->id)
415-
return d;
416-
/* Stop searching when finding id's position in sorted list. */
417-
if (id < d->id)
418-
break;
419-
}
420-
421-
if (pos)
422-
*pos = l;
423-
424-
return NULL;
425-
}
426-
427397
static void setup_default_ctrlval(struct rdt_resource *r, u32 *dc)
428398
{
429399
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)
534504
return;
535505
}
536506

537-
hdr = rdt_find_domain(&r->ctrl_domains, id, &add_pos);
507+
hdr = resctrl_find_domain(&r->ctrl_domains, id, &add_pos);
538508
if (hdr) {
539509
if (WARN_ON_ONCE(hdr->type != RESCTRL_CTRL_DOMAIN))
540510
return;
@@ -589,7 +559,7 @@ static void domain_add_cpu_mon(int cpu, struct rdt_resource *r)
589559
return;
590560
}
591561

592-
hdr = rdt_find_domain(&r->mon_domains, id, &add_pos);
562+
hdr = resctrl_find_domain(&r->mon_domains, id, &add_pos);
593563
if (hdr) {
594564
if (WARN_ON_ONCE(hdr->type != RESCTRL_MON_DOMAIN))
595565
return;
@@ -654,7 +624,7 @@ static void domain_remove_cpu_ctrl(int cpu, struct rdt_resource *r)
654624
return;
655625
}
656626

657-
hdr = rdt_find_domain(&r->ctrl_domains, id, NULL);
627+
hdr = resctrl_find_domain(&r->ctrl_domains, id, NULL);
658628
if (!hdr) {
659629
pr_warn("Can't find control domain for id=%d for CPU %d for resource %s\n",
660630
id, cpu, r->name);
@@ -700,7 +670,7 @@ static void domain_remove_cpu_mon(int cpu, struct rdt_resource *r)
700670
return;
701671
}
702672

703-
hdr = rdt_find_domain(&r->mon_domains, id, NULL);
673+
hdr = resctrl_find_domain(&r->mon_domains, id, NULL);
704674
if (!hdr) {
705675
pr_warn("Can't find monitor domain for id=%d for CPU %d for resource %s\n",
706676
id, cpu, r->name);

arch/x86/kernel/cpu/resctrl/ctrlmondata.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,28 @@ int rdtgroup_mba_mbps_event_show(struct kernfs_open_file *of,
610610
return ret;
611611
}
612612

613+
struct rdt_domain_hdr *resctrl_find_domain(struct list_head *h, int id,
614+
struct list_head **pos)
615+
{
616+
struct rdt_domain_hdr *d;
617+
struct list_head *l;
618+
619+
list_for_each(l, h) {
620+
d = list_entry(l, struct rdt_domain_hdr, list);
621+
/* When id is found, return its domain. */
622+
if (id == d->id)
623+
return d;
624+
/* Stop searching when finding id's position in sorted list. */
625+
if (id < d->id)
626+
break;
627+
}
628+
629+
if (pos)
630+
*pos = l;
631+
632+
return NULL;
633+
}
634+
613635
void mon_event_read(struct rmid_read *rr, struct rdt_resource *r,
614636
struct rdt_mon_domain *d, struct rdtgroup *rdtgrp,
615637
cpumask_t *cpumask, int evtid, int first)
@@ -695,7 +717,7 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg)
695717
* This file provides data from a single domain. Search
696718
* the resource to find the domain with "domid".
697719
*/
698-
hdr = rdt_find_domain(&r->mon_domains, domid, NULL);
720+
hdr = resctrl_find_domain(&r->mon_domains, domid, NULL);
699721
if (!hdr || WARN_ON_ONCE(hdr->type != RESCTRL_MON_DOMAIN)) {
700722
ret = -ENOENT;
701723
goto out;

arch/x86/kernel/cpu/resctrl/internal.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -581,8 +581,6 @@ void rdtgroup_kn_unlock(struct kernfs_node *kn);
581581
int rdtgroup_kn_mode_restrict(struct rdtgroup *r, const char *name);
582582
int rdtgroup_kn_mode_restore(struct rdtgroup *r, const char *name,
583583
umode_t mask);
584-
struct rdt_domain_hdr *rdt_find_domain(struct list_head *h, int id,
585-
struct list_head **pos);
586584
ssize_t rdtgroup_schemata_write(struct kernfs_open_file *of,
587585
char *buf, size_t nbytes, loff_t off);
588586
int rdtgroup_schemata_show(struct kernfs_open_file *of,

include/linux/resctrl.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,20 @@ static inline void resctrl_arch_rmid_read_context_check(void)
372372
might_sleep();
373373
}
374374

375+
/**
376+
* resctrl_find_domain() - Search for a domain id in a resource domain list.
377+
* @h: The domain list to search.
378+
* @id: The domain id to search for.
379+
* @pos: A pointer to position in the list id should be inserted.
380+
*
381+
* Search the domain list to find the domain id. If the domain id is
382+
* found, return the domain. NULL otherwise. If the domain id is not
383+
* found (and NULL returned) then the first domain with id bigger than
384+
* the input id can be returned to the caller via @pos.
385+
*/
386+
struct rdt_domain_hdr *resctrl_find_domain(struct list_head *h, int id,
387+
struct list_head **pos);
388+
375389
/**
376390
* resctrl_arch_reset_rmid() - Reset any private state associated with rmid
377391
* and eventid.

0 commit comments

Comments
 (0)