Re: [PATCH v6 30/42] x86/resctrl: Claim get_{mon,ctrl}_domain_from_cpu() helpers for resctrl
From: James Morse
Date: Fri Feb 28 2025 - 14:53:54 EST
Hi Reinette,
On 20/02/2025 04:08, Reinette Chatre wrote:
> On 2/7/25 10:18 AM, James Morse wrote:
>> get_{mon,ctrl}_domain_from_cpu() are handy helpers that both the arch
>> code and resctrl need to use. Rename them to have a resctrl_ prefix
>> and move them to a header file.
>> diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h
>> index 29415d023aab..511dab4ffcdc 100644
>> --- a/include/linux/resctrl.h
>> +++ b/include/linux/resctrl.h
>> @@ -3,6 +3,7 @@
>> #define _RESCTRL_H
>>
>> #include <linux/cacheinfo.h>
>> +#include <linux/cpu.h>
>> #include <linux/kernel.h>
>> #include <linux/list.h>
>> #include <linux/pid.h>
>> @@ -399,6 +400,42 @@ static inline u32 resctrl_get_config_index(u32 closid,
>> }
>> }
>>
>> +/*
>> + * Caller must hold the cpuhp read lock to prevent the struct rdt_domain from
> struct rdt_domain has since been split into struct rdt_ctrl_domain and struct rdt_mon_domain.
> I assume this comment covers both helpers so perhaps this can be "to prevent the domain
> from ..."?
Makes sense - thanks!
>> + * being freed.
>> + */
>> +static inline struct rdt_ctrl_domain *
>> +resctrl_get_ctrl_domain_from_cpu(int cpu, struct rdt_resource *r)
>> +{
>> + struct rdt_ctrl_domain *d;
>> +
>> + lockdep_assert_cpus_held();
>> +
>> + list_for_each_entry(d, &r->ctrl_domains, hdr.list) {
>> + /* Find the domain that contains this CPU */
>> + if (cpumask_test_cpu(cpu, &d->hdr.cpu_mask))
>> + return d;
>> + }
>> +
>> + return NULL;
>> +}
>> +
>> +static inline struct rdt_mon_domain *
>> +resctrl_get_mon_domain_from_cpu(int cpu, struct rdt_resource *r)
>> +{
>> + struct rdt_mon_domain *d;
>> +
>> + lockdep_assert_cpus_held();
>> +
>> + list_for_each_entry(d, &r->mon_domains, hdr.list) {
>> + /* Find the domain that contains this CPU */
>> + if (cpumask_test_cpu(cpu, &d->hdr.cpu_mask))
>> + return d;
>> + }
>> +
>> + return NULL;
>> +}
>> +
>
> Similar to previous requests, could you please provide a motivation for
> the switch to inline?
Hmmm, this has diverged over time. x86 is now using its get_domain_id_from_scope() and
resctrl_find_domain() to cover this. I can probably do away with MPAMs use of these...
~
This gets replaced by a patch that moves them to live next to their callers which lets
them be static, and makes the automated move feasible.
Thanks,
James