x86/resctrl: Add support for Sub-NUMA cluster (SNC) systems
Subsystems (4)
Moger, Babu
reviewerRe: [PATCH v11 1/8] x86/resctrl: Prepare for new domain scope
In reply to Tony LuckHi Tony,
Quoted 117 lines · Tony Luck
Resctrl resources operate on subsets of CPUs in the system with the defining attribute of each subset being an instance of a particular level of cache. E.g. all CPUs sharing an L3 cache would be part of the same domain.
In preparation for features that are scoped at the NUMA node level change the code from explicit references to "
cache_level" to a more generic scope. At this point the only options for this scope are groups of CPUs that share an L2 cache or L3 cache.Clean up the error handling when looking up domains. Report invalid id's before calling
rdt_find_domain()in preparation for better messages when scope can be other than cache scope. This means thatrdt_find_domain()will never return an error. So remove checks for error from the callsites.Signed-off-by Tony Luck <[email protected]>---
Changes since v10:
Reinette: Move a blank line indomain_add_cpu()
Reniette: Fix warning message indomain_remove_cpu()include/linux/resctrl.h | 9 +++-- arch/x86/kernel/cpu/resctrl/core.c | 42 +++++++++++++++-------- arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 2 +- arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 6 +++- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 5 ++- 5 files changed, 45 insertions(+), 19 deletions(-)include/linux/resctrl.h +7
-2@@ -144,13 +144,18 @@ struct resctrl_membw {struct rdt_parse_data ;struct resctrl_schema ; +enum resctrl_scope { +RESCTRL_L2_CACHE =2 , +RESCTRL_L3_CACHE =3 , +}; +/** * struct rdt_resource - attributes of a resctrl resource * @rid: The index of the resource * @alloc_capable: Is allocation available on this machine * @mon_capable: Is monitor feature available on this machine * @num_rmid: Number of RMIDs available -* @cache_level: Which cache level defines scope of this resource +* @scope: Scope of this resource * @cache: Cache allocation related data * @membw: If the component has bandwidth controls, their properties. * @domains: All domains for this resource @@ -168,7 +173,7 @@ struct rdt_resource {bool alloc_capable;bool mon_capable;int num_rmid; -int cache_level; +enum resctrl_scope scope;struct resctrl_cache cache;struct resctrl_membw membw;struct list_head domains;arch/x86/kernel/cpu/resctrl/core.c +6
-7@@ -65,7 +65,7 @@ struct rdt_hw_resource rdt_resources_all[] = { .r_resctrl = { .rid = RDT_RESOURCE_L3, .name = "L3", - .cache_level = 3, + .scope = RESCTRL_L3_CACHE, .domains = domain_init(RDT_RESOURCE_L3), .parse_ctrlval = parse_cbm, .format_str = "%d=%0*x",@@ -79,7 +79,7 @@ struct rdt_hw_resource rdt_resources_all[] = { .r_resctrl = { .rid = RDT_RESOURCE_L2, .name = "L2", - .cache_level = 2, + .scope = RESCTRL_L2_CACHE, .domains = domain_init(RDT_RESOURCE_L2), .parse_ctrlval = parse_cbm, .format_str = "%d=%0*x",@@ -93,7 +93,7 @@ struct rdt_hw_resource rdt_resources_all[] = { .r_resctrl = { .rid = RDT_RESOURCE_MBA, .name = "MB", - .cache_level = 3, + .scope = RESCTRL_L3_CACHE, .domains = domain_init(RDT_RESOURCE_MBA), .parse_ctrlval = parse_bw, .format_str = "%d=%*u",@@ -105,7 +105,7 @@ struct rdt_hw_resource rdt_resources_all[] = { .r_resctrl = { .rid = RDT_RESOURCE_SMBA, .name = "SMBA", - .cache_level = 3, + .scope = RESCTRL_L3_CACHE, .domains = domain_init(RDT_RESOURCE_SMBA), .parse_ctrlval = parse_bw, .format_str = "%d=%*u",@@ -401,9 +401,6 @@ struct rdt_domain *rdt_find_domain(struct rdt_resource *r, int id,struct rdt_domain *d;struct list_head *l; -if (id <0 ) -return ERR_PTR (-ENODEV ); -list_for_each (l, &r->domains) { d = list_entry(l, struct rdt_domain, list);/* When id is found, return its domain. */ @@ -491,6 +488,19 @@ static int arch_domain_mbm_alloc(u32 num_rmid, struct rdt_hw_domain *hw_dom)return 0 ; } +static int get_domain_id_from_scope (int cpu,enum resctrl_scope scope) +{
arch/x86/kernel/cpu/resctrl/core.c static int arch_domain_mbm_alloc(u32 num_rmid, struct rdt_hw_domain *hw_dom) · line 502
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/core.c +10
-0+switch (scope) { +case RESCTRL_L2_CACHE : +case RESCTRL_L3_CACHE : +return get_cpu_cacheinfo_id (cpu, scope); +default : +break ; + } + +return -EINVAL ; +}
This function is meanigfull when you introduce node scope RESCTRL_NODE.
Can you please move this to patch 5?
Thanks
Babu
Quoted 108 lines
arch/x86/kernel/cpu/resctrl/core.c +12
-7+/* * domain_add_cpu - Add a cpu to a resource's domain list. * @@ -506,18 +516,19 @@ static int arch_domain_mbm_alloc(u32 num_rmid, struct rdt_hw_domain *hw_dom)*/ static void domain_add_cpu (int cpu,struct rdt_resource *r) { -int id =get_cpu_cacheinfo_id (cpu, r->cache_level); +int id =get_domain_id_from_scope (cpu, r->scope);struct list_head *add_pos =NULL ;struct rdt_hw_domain *hw_dom;struct rdt_domain *d;int err; - d =rdt_find_domain (r, id, &add_pos); -if (IS_ERR (d)) { -pr_warn ("Couldn't find cache id for CPU %d\n" , cpu); +if (id <0 ) { +pr_warn_once ("Can't find domain id for CPU:%d scope:%d for resource %s\n" , + cpu, r->scope, r->name);return ; } + d =rdt_find_domain (r, id, &add_pos);if (d) {cpumask_set_cpu (cpu, &d->cpu_mask);if (r->cache.arch_has_per_cpu_cfg)@@ -556,13 +567,16 @@ static void domain_add_cpu(int cpu, struct rdt_resource *r)static void domain_remove_cpu (int cpu,struct rdt_resource *r) { -int id =get_cpu_cacheinfo_id (cpu, r->cache_level); +int id =get_domain_id_from_scope (cpu, r->scope);struct rdt_hw_domain *hw_dom;struct rdt_domain *d; +if (id <0 ) +return ; + d =rdt_find_domain (r, id,NULL ); -if (IS_ERR_OR_NULL (d)) { -pr_warn ("Couldn't find cache id for CPU %d\n" , cpu); +if (!d) { +pr_warn ("Couldn't find domain with id=%d for CPU %d\n" , id, cpu);return ; } hw_dom =resctrl_to_arch_dom (d);arch/x86/kernel/cpu/resctrl/ctrlmondata.c +1
-1@@ -563,7 +563,7 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg) r = &rdt_resources_all[resid].r_resctrl; d =rdt_find_domain (r, domid,NULL ); -if (IS_ERR_OR_NULL (d)) { +if (!d) { ret = -ENOENT ; goto out; }arch/x86/kernel/cpu/resctrl/pseudo_lock.c +5
-1@@ -292,10 +292,14 @@ static void pseudo_lock_region_clear(struct pseudo_lock_region *plr)*/ static int pseudo_lock_region_init (struct pseudo_lock_region *plr) { +enum resctrl_scope scope = plr->s->res->scope;struct cpu_cacheinfo *ci;int ret;int i; +if (WARN_ON_ONCE (scope !=RESCTRL_L2_CACHE && scope !=RESCTRL_L3_CACHE )) +return -ENODEV ; +/* Pick the first cpu we find that is associated with the cache. */ plr->cpu =cpumask_first (&plr->d->cpu_mask);@@ -311,7 +315,7 @@ static int pseudo_lock_region_init(struct pseudo_lock_region *plr) plr->size =rdtgroup_cbm_to_size (plr->s->res, plr->d, plr->cbm);for (i =0 ; i < ci->num_leaves; i++) { -if (ci->info_list[i].level == plr->s->res->cache_level) { +if (ci->info_list[i].level == scope) { plr->line_size = ci->info_list[i].coherency_line_size;return 0 ; }arch/x86/kernel/cpu/resctrl/rdtgroup.c +4
-1@@ -1413,10 +1413,13 @@ unsigned int rdtgroup_cbm_to_size(struct rdt_resource *r,unsigned int size =0 ;int num_b, i; +if (WARN_ON_ONCE (r->scope !=RESCTRL_L2_CACHE && r->scope !=RESCTRL_L3_CACHE )) +return size; + num_b =bitmap_weight (&cbm, r->cache.cbm_len); ci =get_cpu_cacheinfo (cpumask_any (&d->cpu_mask));for (i =0 ; i < ci->num_leaves; i++) { -if (ci->info_list[i].level == r->cache_level) { +if (ci->info_list[i].level == r->scope) { size = ci->info_list[i].size / r->cache.cbm_len * num_b;break ; }
Signature · 2 lines
Thanks Babu Moger
Luck, Tony
maintainerRE: [PATCH v11 1/8] x86/resctrl: Prepare for new domain scope
Quoted 15 lines
arch/x86/kernel/cpu/resctrl/core.c static int arch_domain_mbm_alloc(u32 num_rmid, struct rdt_hw_domain *hw_dom) · line 502
Quoted 12 lines
arch/x86/kernel/cpu/resctrl/core.c +12
-0+static int get_domain_id_from_scope (int cpu,enum resctrl_scope scope) +{ +switch (scope) { +case RESCTRL_L2_CACHE : +case RESCTRL_L3_CACHE : +return get_cpu_cacheinfo_id (cpu, scope); +default : +break ; + } + +return -EINVAL ; +}This function is meanigfull when you introduce node scope
RESCTRL_NODE.
Quoted 1 line
Can you please move this to patch 5?
Code has been this way since v5. I'll note your opinion and if others agree I'll move it. But I think this is a reasonable part of the first step moving away from purely cache scope for domains.
-Tony
Re: [PATCH v11 1/8] x86/resctrl: Prepare for new domain scope
In reply to Tony LuckHi Tony,
arch/x86/kernel/cpu/resctrl/core.c static void domain_add_cpu(int cpu, struct rdt_resource *r) · line 576
Quoted 12 lines · Tony Luck
arch/x86/kernel/cpu/resctrl/core.c +4
-1@@ -556,13 +567,16 @@ static void domain_add_cpu(int cpu, struct rdt_resource *r)static void domain_remove_cpu (int cpu,struct rdt_resource *r) { -int id =get_cpu_cacheinfo_id (cpu, r->cache_level); +int id =get_domain_id_from_scope (cpu, r->scope);struct rdt_hw_domain *hw_dom;struct rdt_domain *d; +if (id <0 ) +return ; +
Apologies for this late comment to this code that has been like this for a few versions. Something must have gone really wrong if id < 0 so I do not think a silent failure is ideal. Could the same warning as above be included here? That is:
pr_warn_once("Can't find domain id for CPU:%d scope:%d for resource %s\n",
cpu, r->scope, r->name);If you agree, please do ensure that this change propagates to domain_remove_cpu_ctrl() and domain_remove_cpu_mon() in patches that follow, in which case the text is expected to adjust to "Can't find control domain id" and "Can't find monitor domain id" respectively. (btw ... is the switching between "Can't" and "Couldn't" intentional?)
With this change please feel free to include:
Reinette
Tony Luck
maintainerPATCH v11 2/8 x86/resctrl: Prepare to split rdt_domain structure
In reply to Tony LuckThe rdt_domain structure is used for both control and monitor features. It is about to be split into separate structures for these two usages because the scope for control and monitoring features for a resource will be different for future resources.
To allow for common code that scans a list of domains looking for a specific domain id, move all the common fields ("list", "id", "cpu_mask") into their own structure within the rdt_domain structure.
--- include/linux/resctrl.h | 16 ++++-- arch/x86/kernel/cpu/resctrl/core.c | 26 +++++----- arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 22 ++++----- arch/x86/kernel/cpu/resctrl/monitor.c | 10 ++-- arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 14 +++--- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 60 +++++++++++------------ 6 files changed, 78 insertions(+), 70 deletions(-)
include/linux/resctrl.h +12 -4
@@ -53,10 +53,20 @@ struct resctrl_staged_config { };/** -* struct rdt_domain - group of CPUs sharing a resctrl resource +* struct rdt_domain_hdr - common header for different domain types * @list: all instances of this resource * @id: unique id for this instance * @cpu_mask: which CPUs share this resource +*/ +struct rdt_domain_hdr { +struct list_head list; +int id; +struct cpumask cpu_mask; +}; + +/** +* struct rdt_domain - group of CPUs sharing a resctrl resource +* @hdr: common header for different domain types * @rmid_busy_llc: bitmap of which limbo RMIDs are above threshold * @mbm_total: saved state for MBM total bandwidth * @mbm_local: saved state for MBM local bandwidth
@@ -71,9 +81,7 @@ struct resctrl_staged_config {* by closid */ struct rdt_domain { -struct list_head list; -int id; -struct cpumask cpu_mask; +struct rdt_domain_hdr hdr;unsigned long *rmid_busy_llc;struct mbm_state *mbm_total;struct mbm_state *mbm_local;
arch/x86/kernel/cpu/resctrl/core.c +13 -13
@@ -356,9 +356,9 @@ struct rdt_domain *get_domain_from_cpu(int cpu, struct rdt_resource *r) {struct rdt_domain *d; -list_for_each_entry (d, &r->domains, list) { +list_for_each_entry (d, &r->domains, hdr.list) {/* Find the domain that contains this CPU */ -if (cpumask_test_cpu (cpu, &d->cpu_mask)) +if (cpumask_test_cpu (cpu, &d->hdr.cpu_mask))return d; }
@@ -402,12 +402,12 @@ struct rdt_domain *rdt_find_domain(struct rdt_resource *r, int id,struct list_head *l;list_for_each (l, &r->domains) { - d = list_entry(l, struct rdt_domain, list); + d = list_entry(l, struct rdt_domain, hdr.list);/* When id is found, return its domain. */ -if (id == d->id) +if (id == d->hdr.id)return d;/* Stop searching when finding id's position in sorted list. */ -if (id < d->id) +if (id < d->hdr.id)break ; }
@@ -530,7 +530,7 @@ static void domain_add_cpu(int cpu, struct rdt_resource *r) d =rdt_find_domain (r, id, &add_pos);if (d) { -cpumask_set_cpu (cpu, &d->cpu_mask); +cpumask_set_cpu (cpu, &d->hdr.cpu_mask);if (r->cache.arch_has_per_cpu_cfg)rdt_domain_reconfigure_cdp (r);return ;
@@ -541,8 +541,8 @@ static void domain_add_cpu(int cpu, struct rdt_resource *r)return ; d = &hw_dom->d_resctrl; - d->id = id; -cpumask_set_cpu (cpu, &d->cpu_mask); + d->hdr.id = id; +cpumask_set_cpu (cpu, &d->hdr.cpu_mask);rdt_domain_reconfigure_cdp (r);
@@ -556,11 +556,11 @@ static void domain_add_cpu(int cpu, struct rdt_resource *r)return ; } -list_add_tail (&d->list, add_pos); +list_add_tail (&d->hdr.list, add_pos); err =resctrl_online_domain (r, d);if (err) { -list_del (&d->list); +list_del (&d->hdr.list);domain_free (hw_dom); } }
@@ -581,10 +581,10 @@ static void domain_remove_cpu(int cpu, struct rdt_resource *r) } hw_dom =resctrl_to_arch_dom (d); -cpumask_clear_cpu (cpu, &d->cpu_mask); -if (cpumask_empty (&d->cpu_mask)) { +cpumask_clear_cpu (cpu, &d->hdr.cpu_mask); +if (cpumask_empty (&d->hdr.cpu_mask)) {resctrl_offline_domain (r, d); -list_del (&d->list); +list_del (&d->hdr.list);/* * rdt_domain "d" is going to be freed below, so clear
arch/x86/kernel/cpu/resctrl/ctrlmondata.c +11 -11
@@ -67,7 +67,7 @@ int parse_bw(struct rdt_parse_data *data, struct resctrl_schema *s, cfg = &d->staged_config[s->conf_type];if (cfg->have_new_ctrl) { -rdt_last_cmd_printf ("Duplicate domain %d\n" , d->id); +rdt_last_cmd_printf ("Duplicate domain %d\n" , d->hdr.id);return -EINVAL ; }
@@ -146,7 +146,7 @@ int parse_cbm(struct rdt_parse_data *data, struct resctrl_schema *s, cfg = &d->staged_config[s->conf_type];if (cfg->have_new_ctrl) { -rdt_last_cmd_printf ("Duplicate domain %d\n" , d->id); +rdt_last_cmd_printf ("Duplicate domain %d\n" , d->hdr.id);return -EINVAL ; }
@@ -226,8 +226,8 @@ static int parse_line(char *line, struct resctrl_schema *s,return -EINVAL ; } dom =strim (dom); -list_for_each_entry (d, &r->domains, list) { -if (d->id == dom_id) { +list_for_each_entry (d, &r->domains, hdr.list) { +if (d->hdr.id == dom_id) { data.buf = dom; data.rdtgrp = rdtgrp;if (r->parse_ctrlval (&data, s, d))
@@ -274,7 +274,7 @@ static bool apply_config(struct rdt_hw_domain *hw_dom,struct rdt_domain *dom = &hw_dom->d_resctrl;if (cfg->new_ctrl != hw_dom->ctrl_val[idx]) { -cpumask_set_cpu (cpumask_any (&dom->cpu_mask), cpu_mask); +cpumask_set_cpu (cpumask_any (&dom->hdr.cpu_mask), cpu_mask); hw_dom->ctrl_val[idx] = cfg->new_ctrl;return true;
@@ -291,7 +291,7 @@ int resctrl_arch_update_one(struct rdt_resource *r, struct rdt_domain *d,u32 idx =get_config_index (closid, t);struct msr_param msr_param; -if (!cpumask_test_cpu (smp_processor_id (), &d->cpu_mask)) +if (!cpumask_test_cpu (smp_processor_id (), &d->hdr.cpu_mask))return -EINVAL ; hw_dom->ctrl_val[idx] = cfg_val;
@@ -318,7 +318,7 @@ int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid)return -ENOMEM ; msr_param.res =NULL ; -list_for_each_entry (d, &r->domains, list) { +list_for_each_entry (d, &r->domains, hdr.list) { hw_dom =resctrl_to_arch_dom (d);for (t =0 ; t <CDP_NUM_TYPES ; t++) { cfg = &hw_dom->d_resctrl.staged_config[t];
@@ -466,7 +466,7 @@ static void show_doms(struct seq_file *s, struct resctrl_schema *schema, int clou32 ctrl_val;seq_printf (s,"%*s:" , max_name_width, schema->name); -list_for_each_entry (dom, &r->domains, list) { +list_for_each_entry (dom, &r->domains, hdr.list) {if (sep)seq_puts (s,";" );
@@ -476,7 +476,7 @@ static void show_doms(struct seq_file *s, struct resctrl_schema *schema, int clo ctrl_val =resctrl_arch_get_config (r, dom, closid, schema->conf_type); -seq_printf (s, r->format_str, dom->id, max_data_width, +seq_printf (s, r->format_str, dom->hdr.id, max_data_width, ctrl_val); sep = true; }
@@ -505,7 +505,7 @@ int rdtgroup_schemata_show(struct kernfs_open_file *of, }else {seq_printf (s,"%s:%d=%x\n" , rdtgrp->plr->s->res->name, - rdtgrp->plr->d->id, + rdtgrp->plr->d->hdr.id, rdtgrp->plr->cbm); } }else {
@@ -536,7 +536,7 @@ void mon_event_read(struct rmid_read *rr, struct rdt_resource *r, rr->val =0 ; rr->first = first; -smp_call_function_any (&d->cpu_mask, mon_event_count, rr,1 ); +smp_call_function_any (&d->hdr.cpu_mask, mon_event_count, rr,1 ); }int rdtgroup_mondata_show (struct seq_file *m,void *arg)
arch/x86/kernel/cpu/resctrl/monitor.c +5 -5
@@ -238,7 +238,7 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain *d,u64 msr_val, chunks;int ret; -if (!cpumask_test_cpu (smp_processor_id (), &d->cpu_mask)) +if (!cpumask_test_cpu (smp_processor_id (), &d->hdr.cpu_mask))return -EINVAL ; ret =__rmid_read (rmid, eventid, &msr_val);
@@ -340,8 +340,8 @@ static void add_rmid_to_limbo(struct rmid_entry *entry) entry->busy =0 ; cpu =get_cpu (); -list_for_each_entry (d, &r->domains, list) { -if (cpumask_test_cpu (cpu, &d->cpu_mask)) { +list_for_each_entry (d, &r->domains, hdr.list) { +if (cpumask_test_cpu (cpu, &d->hdr.cpu_mask)) { err =resctrl_arch_rmid_read (r, d, entry->rmid,QOS_L3_OCCUP_EVENT_ID , &val);
@@ -661,7 +661,7 @@ void cqm_setup_limbo_handler(struct rdt_domain *dom, unsigned long delay_ms)unsigned long delay =msecs_to_jiffies (delay_ms);int cpu; - cpu =cpumask_any (&dom->cpu_mask); + cpu =cpumask_any (&dom->hdr.cpu_mask); dom->cqm_work_cpu = cpu;schedule_delayed_work_on (cpu, &dom->cqm_limbo, delay);
@@ -708,7 +708,7 @@ void mbm_setup_overflow_handler(struct rdt_domain *dom, unsigned long delay_ms)if (!static_branch_likely (&rdt_mon_enable_key))return ; - cpu =cpumask_any (&dom->cpu_mask); + cpu =cpumask_any (&dom->hdr.cpu_mask); dom->mbm_work_cpu = cpu;schedule_delayed_work_on (cpu, &dom->mbm_over, delay); }
arch/x86/kernel/cpu/resctrl/pseudo_lock.c +7 -7
@@ -221,7 +221,7 @@ static int pseudo_lock_cstates_constrain(struct pseudo_lock_region *plr)int cpu;int ret; -for_each_cpu (cpu, &plr->d->cpu_mask) { +for_each_cpu (cpu, &plr->d->hdr.cpu_mask) { pm_req =kzalloc (sizeof (*pm_req),GFP_KERNEL );if (!pm_req) {rdt_last_cmd_puts ("Failure to allocate memory for PM QoS\n" );
@@ -301,7 +301,7 @@ static int pseudo_lock_region_init(struct pseudo_lock_region *plr)return -ENODEV ;/* Pick the first cpu we find that is associated with the cache. */ - plr->cpu =cpumask_first (&plr->d->cpu_mask); + plr->cpu =cpumask_first (&plr->d->hdr.cpu_mask);if (!cpu_online (plr->cpu)) { rdt_last_cmd_printf("CPU %u associated with cache not online\n",
@@ -856,10 +856,10 @@ bool rdtgroup_pseudo_locked_in_hierarchy(struct rdt_domain *d)* associated with them. */ for_each_alloc_capable_rdt_resource (r) { -list_for_each_entry (d_i, &r->domains, list) { +list_for_each_entry (d_i, &r->domains, hdr.list) {if (d_i->plr)cpumask_or (cpu_with_psl, cpu_with_psl, - &d_i->cpu_mask); + &d_i->hdr.cpu_mask); } }
@@ -867,7 +867,7 @@ bool rdtgroup_pseudo_locked_in_hierarchy(struct rdt_domain *d)* Next test if new pseudo-locked region would intersect with * existing region. */ -if (cpumask_intersects (&d->cpu_mask, cpu_with_psl)) +if (cpumask_intersects (&d->hdr.cpu_mask, cpu_with_psl)) ret = true;free_cpumask_var (cpu_with_psl);
@@ -1199,7 +1199,7 @@ static int pseudo_lock_measure_cycles(struct rdtgroup *rdtgrp, int sel) } plr->thread_done =0 ; - cpu =cpumask_first (&plr->d->cpu_mask); + cpu =cpumask_first (&plr->d->hdr.cpu_mask);if (!cpu_online (cpu)) { ret = -ENODEV ; goto out;
@@ -1529,7 +1529,7 @@ static int pseudo_lock_dev_mmap(struct file *filp, struct vm_area_struct *vma)* may be scheduled elsewhere and invalidate entries in the * pseudo-locked region. */ -if (!cpumask_subset (current->cpus_ptr, &plr->d->cpu_mask)) { +if (!cpumask_subset (current->cpus_ptr, &plr->d->hdr.cpu_mask)) {mutex_unlock (&rdtgroup_mutex);return -EINVAL ; }
arch/x86/kernel/cpu/resctrl/rdtgroup.c +30 -30
220 lines not on this page · raw message
Signature · 1 line
2.41.0
Moger, Babu
reviewerRe: [PATCH v11 2/8] x86/resctrl: Prepare to split rdt_domain structure
Hi Tony,
Sorry for the late review. The patches look good for the most part. But we can simplify a little more. Please see my comments below.
Quoted 28 lines · Tony Luck
The
rdt_domainstructure is used for both control and monitor features. It is about to be split into separate structures for these two usages because the scope for control and monitoring features for a resource will be different for future resources.To allow for common code that scans a list of domains looking for a specific domain id, move all the common fields ("list", "id", "
cpu_mask") into their own structure within therdt_domainstructure.Signed-off-by Tony Luck <[email protected]>--- include/linux/resctrl.h | 16 ++++-- arch/x86/kernel/cpu/resctrl/core.c | 26 +++++----- arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 22 ++++----- arch/x86/kernel/cpu/resctrl/monitor.c | 10 ++-- arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 14 +++--- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 60 +++++++++++------------ 6 files changed, 78 insertions(+), 70 deletions(-)include/linux/resctrl.h +0
-1@@ -53,10 +53,20 @@ struct resctrl_staged_config { };/** -* struct rdt_domain - group of CPUs sharing a resctrl resource
include/linux/resctrl.h struct resctrl_staged_config { · line 65
Quoted 10 lines
include/linux/resctrl.h +7
-0+* struct rdt_domain_hdr - common header for different domain types * @list: all instances of this resource * @id: unique id for this instance * @cpu_mask: which CPUs share this resource +*/ +struct rdt_domain_hdr { +struct list_head list; +int id; +struct cpumask cpu_mask; +};
I like the idea of separating the domains, one for control and another for monitor. I have some comments on how it can be done to simplify the code. Adding the hdr adds a little complexity to the code.
How about converting the current rdt_domain to explicitly to rdt_mon_domain?
Something like this.
struct rdt_mon_domain {
struct list_head list;
int id;
struct cpumask cpu_mask;
unsigned long *rmid_busy_llc;
struct mbm_state *mbm_total;
struct mbm_state *mbm_local;
struct delayed_work mbm_over;
struct delayed_work cqm_limbo;
int mbm_work_cpu;
int cqm_work_cpu;
};Then introduce rdt_ctrl_domain to which separates into two doamins.
struct rdt_ctrl_domain {
struct list_head list;
int id;
struct cpumask cpu_mask;
struct pseudo_lock_region *plr;
struct resctrl_staged_config staged_config[CDP_NUM_TYPES];
u32 *mbps_val;
};I feel this will be easy to understand and makes the code simpler. Changes will be minimal.
Thanks
Babu
Quoted 547 lines
include/linux/resctrl.h +5
-3+ +/** +* struct rdt_domain - group of CPUs sharing a resctrl resource +* @hdr: common header for different domain types * @rmid_busy_llc: bitmap of which limbo RMIDs are above threshold * @mbm_total: saved state for MBM total bandwidth * @mbm_local: saved state for MBM local bandwidth @@ -71,9 +81,7 @@ struct resctrl_staged_config {* by closid */ struct rdt_domain { -struct list_head list; -int id; -struct cpumask cpu_mask; +struct rdt_domain_hdr hdr;unsigned long *rmid_busy_llc;struct mbm_state *mbm_total;struct mbm_state *mbm_local;arch/x86/kernel/cpu/resctrl/core.c +13
-13@@ -356,9 +356,9 @@ struct rdt_domain *get_domain_from_cpu(int cpu, struct rdt_resource *r) {struct rdt_domain *d; -list_for_each_entry (d, &r->domains, list) { +list_for_each_entry (d, &r->domains, hdr.list) {/* Find the domain that contains this CPU */ -if (cpumask_test_cpu (cpu, &d->cpu_mask)) +if (cpumask_test_cpu (cpu, &d->hdr.cpu_mask))return d; }@@ -402,12 +402,12 @@ struct rdt_domain *rdt_find_domain(struct rdt_resource *r, int id,struct list_head *l;list_for_each (l, &r->domains) { - d = list_entry(l, struct rdt_domain, list); + d = list_entry(l, struct rdt_domain, hdr.list);/* When id is found, return its domain. */ -if (id == d->id) +if (id == d->hdr.id)return d;/* Stop searching when finding id's position in sorted list. */ -if (id < d->id) +if (id < d->hdr.id)break ; }@@ -530,7 +530,7 @@ static void domain_add_cpu(int cpu, struct rdt_resource *r) d =rdt_find_domain (r, id, &add_pos);if (d) { -cpumask_set_cpu (cpu, &d->cpu_mask); +cpumask_set_cpu (cpu, &d->hdr.cpu_mask);if (r->cache.arch_has_per_cpu_cfg)rdt_domain_reconfigure_cdp (r);return ;@@ -541,8 +541,8 @@ static void domain_add_cpu(int cpu, struct rdt_resource *r)return ; d = &hw_dom->d_resctrl; - d->id = id; -cpumask_set_cpu (cpu, &d->cpu_mask); + d->hdr.id = id; +cpumask_set_cpu (cpu, &d->hdr.cpu_mask);rdt_domain_reconfigure_cdp (r);@@ -556,11 +556,11 @@ static void domain_add_cpu(int cpu, struct rdt_resource *r)return ; } -list_add_tail (&d->list, add_pos); +list_add_tail (&d->hdr.list, add_pos); err =resctrl_online_domain (r, d);if (err) { -list_del (&d->list); +list_del (&d->hdr.list);domain_free (hw_dom); } }@@ -581,10 +581,10 @@ static void domain_remove_cpu(int cpu, struct rdt_resource *r) } hw_dom =resctrl_to_arch_dom (d); -cpumask_clear_cpu (cpu, &d->cpu_mask); -if (cpumask_empty (&d->cpu_mask)) { +cpumask_clear_cpu (cpu, &d->hdr.cpu_mask); +if (cpumask_empty (&d->hdr.cpu_mask)) {resctrl_offline_domain (r, d); -list_del (&d->list); +list_del (&d->hdr.list);/* * rdt_domain "d" is going to be freed below, so clear arch/x86/kernel/cpu/resctrl/ctrlmondata.c +11
-11@@ -67,7 +67,7 @@ int parse_bw(struct rdt_parse_data *data, struct resctrl_schema *s, cfg = &d->staged_config[s->conf_type];if (cfg->have_new_ctrl) { -rdt_last_cmd_printf ("Duplicate domain %d\n" , d->id); +rdt_last_cmd_printf ("Duplicate domain %d\n" , d->hdr.id);return -EINVAL ; }@@ -146,7 +146,7 @@ int parse_cbm(struct rdt_parse_data *data, struct resctrl_schema *s, cfg = &d->staged_config[s->conf_type];if (cfg->have_new_ctrl) { -rdt_last_cmd_printf ("Duplicate domain %d\n" , d->id); +rdt_last_cmd_printf ("Duplicate domain %d\n" , d->hdr.id);return -EINVAL ; }@@ -226,8 +226,8 @@ static int parse_line(char *line, struct resctrl_schema *s,return -EINVAL ; } dom =strim (dom); -list_for_each_entry (d, &r->domains, list) { -if (d->id == dom_id) { +list_for_each_entry (d, &r->domains, hdr.list) { +if (d->hdr.id == dom_id) { data.buf = dom; data.rdtgrp = rdtgrp;if (r->parse_ctrlval (&data, s, d))@@ -274,7 +274,7 @@ static bool apply_config(struct rdt_hw_domain *hw_dom,struct rdt_domain *dom = &hw_dom->d_resctrl;if (cfg->new_ctrl != hw_dom->ctrl_val[idx]) { -cpumask_set_cpu (cpumask_any (&dom->cpu_mask), cpu_mask); +cpumask_set_cpu (cpumask_any (&dom->hdr.cpu_mask), cpu_mask); hw_dom->ctrl_val[idx] = cfg->new_ctrl;return true;@@ -291,7 +291,7 @@ int resctrl_arch_update_one(struct rdt_resource *r, struct rdt_domain *d,u32 idx =get_config_index (closid, t);struct msr_param msr_param; -if (!cpumask_test_cpu (smp_processor_id (), &d->cpu_mask)) +if (!cpumask_test_cpu (smp_processor_id (), &d->hdr.cpu_mask))return -EINVAL ; hw_dom->ctrl_val[idx] = cfg_val;@@ -318,7 +318,7 @@ int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid)return -ENOMEM ; msr_param.res =NULL ; -list_for_each_entry (d, &r->domains, list) { +list_for_each_entry (d, &r->domains, hdr.list) { hw_dom =resctrl_to_arch_dom (d);for (t =0 ; t <CDP_NUM_TYPES ; t++) { cfg = &hw_dom->d_resctrl.staged_config[t];@@ -466,7 +466,7 @@ static void show_doms(struct seq_file *s, struct resctrl_schema *schema, int clou32 ctrl_val;seq_printf (s,"%*s:" , max_name_width, schema->name); -list_for_each_entry (dom, &r->domains, list) { +list_for_each_entry (dom, &r->domains, hdr.list) {if (sep)seq_puts (s,";" );@@ -476,7 +476,7 @@ static void show_doms(struct seq_file *s, struct resctrl_schema *schema, int clo ctrl_val =resctrl_arch_get_config (r, dom, closid, schema->conf_type); -seq_printf (s, r->format_str, dom->id, max_data_width, +seq_printf (s, r->format_str, dom->hdr.id, max_data_width, ctrl_val); sep = true; }@@ -505,7 +505,7 @@ int rdtgroup_schemata_show(struct kernfs_open_file *of, }else {seq_printf (s,"%s:%d=%x\n" , rdtgrp->plr->s->res->name, - rdtgrp->plr->d->id, + rdtgrp->plr->d->hdr.id, rdtgrp->plr->cbm); } }else {@@ -536,7 +536,7 @@ void mon_event_read(struct rmid_read *rr, struct rdt_resource *r, rr->val =0 ; rr->first = first; -smp_call_function_any (&d->cpu_mask, mon_event_count, rr,1 ); +smp_call_function_any (&d->hdr.cpu_mask, mon_event_count, rr,1 ); }int rdtgroup_mondata_show (struct seq_file *m,void *arg)arch/x86/kernel/cpu/resctrl/monitor.c +5
-5@@ -238,7 +238,7 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain *d,u64 msr_val, chunks;int ret; -if (!cpumask_test_cpu (smp_processor_id (), &d->cpu_mask)) +if (!cpumask_test_cpu (smp_processor_id (), &d->hdr.cpu_mask))return -EINVAL ; ret =__rmid_read (rmid, eventid, &msr_val);@@ -340,8 +340,8 @@ static void add_rmid_to_limbo(struct rmid_entry *entry) entry->busy =0 ; cpu =get_cpu (); -list_for_each_entry (d, &r->domains, list) { -if (cpumask_test_cpu (cpu, &d->cpu_mask)) { +list_for_each_entry (d, &r->domains, hdr.list) { +if (cpumask_test_cpu (cpu, &d->hdr.cpu_mask)) { err =resctrl_arch_rmid_read (r, d, entry->rmid,QOS_L3_OCCUP_EVENT_ID , &val);@@ -661,7 +661,7 @@ void cqm_setup_limbo_handler(struct rdt_domain *dom, unsigned long delay_ms)unsigned long delay =msecs_to_jiffies (delay_ms);int cpu; - cpu =cpumask_any (&dom->cpu_mask); + cpu =cpumask_any (&dom->hdr.cpu_mask); dom->cqm_work_cpu = cpu;schedule_delayed_work_on (cpu, &dom->cqm_limbo, delay);@@ -708,7 +708,7 @@ void mbm_setup_overflow_handler(struct rdt_domain *dom, unsigned long delay_ms)if (!static_branch_likely (&rdt_mon_enable_key))return ; - cpu =cpumask_any (&dom->cpu_mask); + cpu =cpumask_any (&dom->hdr.cpu_mask); dom->mbm_work_cpu = cpu;schedule_delayed_work_on (cpu, &dom->mbm_over, delay); }arch/x86/kernel/cpu/resctrl/pseudo_lock.c +7
-7@@ -221,7 +221,7 @@ static int pseudo_lock_cstates_constrain(struct pseudo_lock_region *plr)int cpu;int ret; -for_each_cpu (cpu, &plr->d->cpu_mask) { +for_each_cpu (cpu, &plr->d->hdr.cpu_mask) { pm_req =kzalloc (sizeof (*pm_req),GFP_KERNEL );if (!pm_req) {rdt_last_cmd_puts ("Failure to allocate memory for PM QoS\n" );@@ -301,7 +301,7 @@ static int pseudo_lock_region_init(struct pseudo_lock_region *plr)return -ENODEV ;/* Pick the first cpu we find that is associated with the cache. */ - plr->cpu =cpumask_first (&plr->d->cpu_mask); + plr->cpu =cpumask_first (&plr->d->hdr.cpu_mask);if (!cpu_online (plr->cpu)) { rdt_last_cmd_printf("CPU %u associated with cache not online\n",@@ -856,10 +856,10 @@ bool rdtgroup_pseudo_locked_in_hierarchy(struct rdt_domain *d)* associated with them. */ for_each_alloc_capable_rdt_resource (r) { -list_for_each_entry (d_i, &r->domains, list) { +list_for_each_entry (d_i, &r->domains, hdr.list) {if (d_i->plr)cpumask_or (cpu_with_psl, cpu_with_psl, - &d_i->cpu_mask); + &d_i->hdr.cpu_mask); } }@@ -867,7 +867,7 @@ bool rdtgroup_pseudo_locked_in_hierarchy(struct rdt_domain *d)* Next test if new pseudo-locked region would intersect with * existing region. */ -if (cpumask_intersects (&d->cpu_mask, cpu_with_psl)) +if (cpumask_intersects (&d->hdr.cpu_mask, cpu_with_psl)) ret = true;free_cpumask_var (cpu_with_psl);@@ -1199,7 +1199,7 @@ static int pseudo_lock_measure_cycles(struct rdtgroup *rdtgrp, int sel) } plr->thread_done =0 ; - cpu =cpumask_first (&plr->d->cpu_mask); + cpu =cpumask_first (&plr->d->hdr.cpu_mask);if (!cpu_online (cpu)) { ret = -ENODEV ; goto out;@@ -1529,7 +1529,7 @@ static int pseudo_lock_dev_mmap(struct file *filp, struct vm_area_struct *vma)* may be scheduled elsewhere and invalidate entries in the * pseudo-locked region. */ -if (!cpumask_subset (current->cpus_ptr, &plr->d->cpu_mask)) { +if (!cpumask_subset (current->cpus_ptr, &plr->d->hdr.cpu_mask)) {mutex_unlock (&rdtgroup_mutex);return -EINVAL ; }arch/x86/kernel/cpu/resctrl/rdtgroup.c +30
-30@@ -91,7 +91,7 @@ void rdt_staged_configs_clear(void)lockdep_assert_held (&rdtgroup_mutex);for_each_alloc_capable_rdt_resource (r) { -list_for_each_entry (dom, &r->domains, list) +list_for_each_entry (dom, &r->domains, hdr.list)memset (dom->staged_config,0 ,sizeof (dom->staged_config)); } }@@ -295,7 +295,7 @@ static int rdtgroup_cpus_show(struct kernfs_open_file *of,rdt_last_cmd_puts ("Cache domain offline\n" ); ret = -ENODEV ; }else { - mask = &rdtgrp->plr->d->cpu_mask; + mask = &rdtgrp->plr->d->hdr.cpu_mask;seq_printf (s,is_cpu_list (of) ?"%*pbl\n" :"%*pb\n" ,cpumask_pr_args (mask));@@ -984,12 +984,12 @@ static int rdt_bit_usage_show(struct kernfs_open_file *of,mutex_lock (&rdtgroup_mutex); hw_shareable = r->cache.shareable_bits; -list_for_each_entry (dom, &r->domains, list) { +list_for_each_entry (dom, &r->domains, hdr.list) {if (sep)seq_putc (seq,';' ); sw_shareable =0 ; exclusive =0 ; -seq_printf (seq,"%d=" , dom->id); +seq_printf (seq,"%d=" , dom->hdr.id);for (i =0 ; i <closids_supported (); i++) {if (!closid_allocated (i))continue ;@@ -1302,7 +1302,7 @@ static bool rdtgroup_mode_test_exclusive(struct rdtgroup *rdtgrp)if (r->rid ==RDT_RESOURCE_MBA || r->rid ==RDT_RESOURCE_SMBA )continue ; has_cache = true; -list_for_each_entry (d, &r->domains, list) { +list_for_each_entry (d, &r->domains, hdr.list) { ctrl =resctrl_arch_get_config (r, d, closid, s->conf_type);if (rdtgroup_cbm_overlaps (s, d, ctrl, closid, false)) {@@ -1417,7 +1417,7 @@ unsigned int rdtgroup_cbm_to_size(struct rdt_resource *r,return size; num_b =bitmap_weight (&cbm, r->cache.cbm_len); - ci =get_cpu_cacheinfo (cpumask_any (&d->cpu_mask)); + ci =get_cpu_cacheinfo (cpumask_any (&d->hdr.cpu_mask));for (i =0 ; i < ci->num_leaves; i++) {if (ci->info_list[i].level == r->scope) { size = ci->info_list[i].size / r->cache.cbm_len * num_b;@@ -1465,7 +1465,7 @@ static int rdtgroup_size_show(struct kernfs_open_file *of, size =rdtgroup_cbm_to_size (rdtgrp->plr->s->res, rdtgrp->plr->d, rdtgrp->plr->cbm); -seq_printf (s,"%d=%u\n" , rdtgrp->plr->d->id, size); +seq_printf (s,"%d=%u\n" , rdtgrp->plr->d->hdr.id, size); } goto out; }@@ -1477,7 +1477,7 @@ static int rdtgroup_size_show(struct kernfs_open_file *of, type = schema->conf_type; sep = false;seq_printf (s,"%*s:" , max_name_width, schema->name); -list_for_each_entry (d, &r->domains, list) { +list_for_each_entry (d, &r->domains, hdr.list) {if (sep)seq_putc (s,';' );if (rdtgrp->mode ==RDT_MODE_PSEUDO_LOCKSETUP ) {@@ -1495,7 +1495,7 @@ static int rdtgroup_size_show(struct kernfs_open_file *of,else size =rdtgroup_cbm_to_size (r, d, ctrl); } -seq_printf (s,"%d=%u" , d->id, size); +seq_printf (s,"%d=%u" , d->hdr.id, size); sep = true; }seq_putc (s,'\n' );@@ -1555,7 +1555,7 @@ static void mon_event_config_read(void *info)static void mondata_config_read (struct rdt_domain *d,struct mon_config_info *mon_info) { -smp_call_function_any (&d->cpu_mask, mon_event_config_read, mon_info,1 ); +smp_call_function_any (&d->hdr.cpu_mask, mon_event_config_read, mon_info,1 ); }static int mbm_config_show (struct seq_file *s,struct rdt_resource *r,u32 evtid)@@ -1566,7 +1566,7 @@ static int mbm_config_show(struct seq_file *s, struct rdt_resource *r, u32 evtidmutex_lock (&rdtgroup_mutex); -list_for_each_entry (dom, &r->domains, list) { +list_for_each_entry (dom, &r->domains, hdr.list) {if (sep)seq_puts (s,";" );@@ -1574,7 +1574,7 @@ static int mbm_config_show(struct seq_file *s, struct rdt_resource *r, u32 evtid mon_info.evtid = evtid;mondata_config_read (dom, &mon_info); -seq_printf (s,"%d=0x%02x" , dom->id, mon_info.mon_config); +seq_printf (s,"%d=0x%02x" , dom->hdr.id, mon_info.mon_config); sep = true; }seq_puts (s,"\n" );@@ -1646,7 +1646,7 @@ static int mbm_config_write_domain(struct rdt_resource *r,* are scoped at the domain level. Writing any of these MSRs * on one CPU is observed by all the CPUs in the domain. */ -smp_call_function_any (&d->cpu_mask, mon_event_config_write, +smp_call_function_any (&d->hdr.cpu_mask, mon_event_config_write, &mon_info,1 );/* @@ -1689,8 +1689,8 @@ static int mon_config_write(struct rdt_resource *r, char *tok, u32 evtid)return -EINVAL ; } -list_for_each_entry (d, &r->domains, list) { -if (d->id == dom_id) { +list_for_each_entry (d, &r->domains, hdr.list) { +if (d->hdr.id == dom_id) { ret =mbm_config_write_domain (r, d, evtid, val);if (ret)return -EINVAL ;@@ -2232,14 +2232,14 @@ static int set_cache_qos_cfg(int level, bool enable)return -ENOMEM ; r_l = &rdt_resources_all[level].r_resctrl; -list_for_each_entry (d, &r_l->domains, list) { +list_for_each_entry (d, &r_l->domains, hdr.list) {if (r_l->cache.arch_has_per_cpu_cfg)/* Pick all the CPUs in the domain instance */ -for_each_cpu (cpu, &d->cpu_mask) +for_each_cpu (cpu, &d->hdr.cpu_mask)cpumask_set_cpu (cpu, cpu_mask);else /* Pick one CPU from each domain instance to update MSR */ -cpumask_set_cpu (cpumask_any (&d->cpu_mask), cpu_mask); +cpumask_set_cpu (cpumask_any (&d->hdr.cpu_mask), cpu_mask); }/* Update QOS_CFG MSR on all the CPUs in cpu_mask */ @@ -2268,7 +2268,7 @@ void rdt_domain_reconfigure_cdp(struct rdt_resource *r)static int mba_sc_domain_allocate (struct rdt_resource *r,struct rdt_domain *d) {u32 num_closid =resctrl_arch_get_num_closid (r); -int cpu =cpumask_any (&d->cpu_mask); +int cpu =cpumask_any (&d->hdr.cpu_mask);int i; d->mbps_val = kcalloc_node(num_closid, sizeof(*d->mbps_val),@@ -2317,7 +2317,7 @@ static int set_mba_sc(bool mba_sc) r->membw.mba_sc = mba_sc; -list_for_each_entry (d, &r->domains, list) { +list_for_each_entry (d, &r->domains, hdr.list) {for (i =0 ; i < num_closid; i++) d->mbps_val[i] =MBA_MAX_MBPS ; }@@ -2653,7 +2653,7 @@ static int rdt_get_tree(struct fs_context *fc)if (is_mbm_enabled ()) { r = &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl; -list_for_each_entry (dom, &r->domains, list) +list_for_each_entry (dom, &r->domains, hdr.list)mbm_setup_overflow_handler (dom,MBM_OVERFLOW_INTERVAL ); }@@ -2780,9 +2780,9 @@ static int reset_all_ctrls(struct rdt_resource *r)* CBMs in all domains to the maximum mask value. Pick one CPU * from each domain to update the MSRs below. */ -list_for_each_entry (d, &r->domains, list) { +list_for_each_entry (d, &r->domains, hdr.list) { hw_dom =resctrl_to_arch_dom (d); -cpumask_set_cpu (cpumask_any (&d->cpu_mask), cpu_mask); +cpumask_set_cpu (cpumask_any (&d->hdr.cpu_mask), cpu_mask);for (i =0 ; i < hw_res->num_closid; i++) hw_dom->ctrl_val[i] = r->default_ctrl;@@ -2986,7 +2986,7 @@ static int mkdir_mondata_subdir(struct kernfs_node *parent_kn,char name[32 ];int ret; -sprintf (name,"mon_%s_%02d" , r->name, d->id); +sprintf (name,"mon_%s_%02d" , r->name, d->hdr.id);/* create the directory */ kn =kernfs_create_dir (parent_kn, name, parent_kn->mode, prgrp);if (IS_ERR (kn))@@ -3002,7 +3002,7 @@ static int mkdir_mondata_subdir(struct kernfs_node *parent_kn, } priv.u.rid = r->rid; - priv.u.domid = d->id; + priv.u.domid = d->hdr.id;list_for_each_entry (mevt, &r->evt_list, list) { priv.u.evtid = mevt->evtid; ret =mon_addfile (kn, mevt->name, priv.priv);@@ -3050,7 +3050,7 @@ static int mkdir_mondata_subdir_alldom(struct kernfs_node *parent_kn,struct rdt_domain *dom;int ret; -list_for_each_entry (dom, &r->domains, list) { +list_for_each_entry (dom, &r->domains, hdr.list) { ret =mkdir_mondata_subdir (parent_kn, dom, r, prgrp);if (ret)return ret;@@ -3209,7 +3209,7 @@ static int __init_one_rdt_domain(struct rdt_domain *d, struct resctrl_schema *s,*/ tmp_cbm = cfg->new_ctrl;if (bitmap_weight (&tmp_cbm, r->cache.cbm_len) < r->cache.min_cbm_bits) { -rdt_last_cmd_printf ("No space on %s:%d\n" , s->name, d->id); +rdt_last_cmd_printf ("No space on %s:%d\n" , s->name, d->hdr.id);return -ENOSPC ; } cfg->have_new_ctrl = true;@@ -3232,7 +3232,7 @@ static int rdtgroup_init_cat(struct resctrl_schema *s, u32 closid)struct rdt_domain *d;int ret; -list_for_each_entry (d, &s->res->domains, list) { +list_for_each_entry (d, &s->res->domains, hdr.list) { ret =__init_one_rdt_domain (d, s, closid);if (ret <0 )return ret;@@ -3247,7 +3247,7 @@ static void rdtgroup_init_mba(struct rdt_resource *r, u32 closid)struct resctrl_staged_config *cfg;struct rdt_domain *d; -list_for_each_entry (d, &r->domains, list) { +list_for_each_entry (d, &r->domains, hdr.list) {if (is_mba_sc (r)) { d->mbps_val[closid] =MBA_MAX_MBPS ;continue ;@@ -3864,7 +3864,7 @@ void resctrl_offline_domain(struct rdt_resource *r, struct rdt_domain *d)* per domain monitor data directories. */ if (static_branch_unlikely (&rdt_mon_enable_key)) -rmdir_mondata_subdir_allrdtgrp (r, d->id); +rmdir_mondata_subdir_allrdtgrp (r, d->hdr.id);if (is_mbm_enabled ())cancel_delayed_work (&d->mbm_over);
Signature · 2 lines
Thanks Babu Moger
Tony Luck
maintainerRe: [PATCH v11 2/8] x86/resctrl: Prepare to split rdt_domain structure
Quoted 79 lines · Babu
Hi Tony,
Sorry for the late review. The patches look good for the most part. But we can simplify a little more. Please see my comments below.
Quoted 28 lines · Tony Luck
The
rdt_domainstructure is used for both control and monitor features. It is about to be split into separate structures for these two usages because the scope for control and monitoring features for a resource will be different for future resources.To allow for common code that scans a list of domains looking for a specific domain id, move all the common fields ("list", "id", "
cpu_mask") into their own structure within therdt_domainstructure.Signed-off-by Tony Luck <[email protected]>--- include/linux/resctrl.h | 16 ++++-- arch/x86/kernel/cpu/resctrl/core.c | 26 +++++----- arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 22 ++++----- arch/x86/kernel/cpu/resctrl/monitor.c | 10 ++-- arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 14 +++--- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 60 +++++++++++------------ 6 files changed, 78 insertions(+), 70 deletions(-)include/linux/resctrl.h +0
-1@@ -53,10 +53,20 @@ struct resctrl_staged_config { };/** -* struct rdt_domain - group of CPUs sharing a resctrl resource include/linux/resctrl.h struct resctrl_staged_config { · line 65
Quoted 10 lines
include/linux/resctrl.h +7
-0+* struct rdt_domain_hdr - common header for different domain types * @list: all instances of this resource * @id: unique id for this instance * @cpu_mask: which CPUs share this resource +*/ +struct rdt_domain_hdr { +struct list_head list; +int id; +struct cpumask cpu_mask; +};I like the idea of separating the domains, one for control and another for monitor. I have some comments on how it can be done to simplify the code. Adding the hdr adds a little complexity to the code.
How about converting the current
rdt_domainto explicitly tordt_mon_domain?Something like this.
struct rdt_mon_domain { struct list_head list; int id; struct cpumask cpu_mask; unsigned long *rmid_busy_llc; struct mbm_state *mbm_total; struct mbm_state *mbm_local; struct delayed_work mbm_over; struct delayed_work cqm_limbo; int mbm_work_cpu; int cqm_work_cpu; };Then introduce
rdt_ctrl_domainto which separates into two doamins.struct rdt_ctrl_domain { struct list_head list; int id; struct cpumask cpu_mask; struct pseudo_lock_region *plr; struct resctrl_staged_config staged_config[CDP_NUM_TYPES]; u32 *mbps_val; };
Quoted 2 lines
I feel this will be easy to understand and makes the code simpler. Changes will be minimal.
Babu,
I went in this direction because of rdt_find_domain() which is used to search either of the "ctrl" or "mon" lists. So it needs to be sure that the "list" and "id" fields are at identical offsets in both the rdt_ctrl_domain and rdt_mon_domain structures. Best way to guarantee[1] that is to create the "hdr" entry (which later acquired the cpu_mask field as a common element after a comment from Reinette).
One way to avoid this would be to essentially duplicate rdt_find_domain() into rdt_find_ctrl_domain() and rdt_find_mon_domain() ... but I fear the function is just big enough to get complaints that the two copies should somehow be merged.
-Tony
[1] In v5 I tried using a comment in each to say they must be the same, but Reinette didn't like comments within declarations:
https://lore.kernel.org/all/[email protected]/
Moger, Babu
reviewerRe: [PATCH v11 2/8] x86/resctrl: Prepare to split rdt_domain structure
Quoted 92 lines · Tony Luck
Quoted 79 lines · Babu
Hi Tony,
Sorry for the late review. The patches look good for the most part. But we can simplify a little more. Please see my comments below.
Quoted 28 lines · Tony Luck
The
rdt_domainstructure is used for both control and monitor features. It is about to be split into separate structures for these two usages because the scope for control and monitoring features for a resource will be different for future resources.To allow for common code that scans a list of domains looking for a specific domain id, move all the common fields ("list", "id", "
cpu_mask") into their own structure within therdt_domainstructure.Signed-off-by Tony Luck <[email protected]>--- include/linux/resctrl.h | 16 ++++-- arch/x86/kernel/cpu/resctrl/core.c | 26 +++++----- arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 22 ++++----- arch/x86/kernel/cpu/resctrl/monitor.c | 10 ++-- arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 14 +++--- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 60 +++++++++++------------ 6 files changed, 78 insertions(+), 70 deletions(-)include/linux/resctrl.h +0
-1@@ -53,10 +53,20 @@ struct resctrl_staged_config { };/** -* struct rdt_domain - group of CPUs sharing a resctrl resource include/linux/resctrl.h struct resctrl_staged_config { · line 65
Quoted 10 lines
include/linux/resctrl.h +7
-0+* struct rdt_domain_hdr - common header for different domain types * @list: all instances of this resource * @id: unique id for this instance * @cpu_mask: which CPUs share this resource +*/ +struct rdt_domain_hdr { +struct list_head list; +int id; +struct cpumask cpu_mask; +};I like the idea of separating the domains, one for control and another for monitor. I have some comments on how it can be done to simplify the code. Adding the hdr adds a little complexity to the code.
How about converting the current
rdt_domainto explicitly tordt_mon_domain?Something like this.
struct rdt_mon_domain { struct list_head list; int id; struct cpumask cpu_mask; unsigned long *rmid_busy_llc; struct mbm_state *mbm_total; struct mbm_state *mbm_local; struct delayed_work mbm_over; struct delayed_work cqm_limbo; int mbm_work_cpu; int cqm_work_cpu; };Then introduce
rdt_ctrl_domainto which separates into two doamins.struct rdt_ctrl_domain { struct list_head list; int id; struct cpumask cpu_mask; struct pseudo_lock_region *plr; struct resctrl_staged_config staged_config[CDP_NUM_TYPES]; u32 *mbps_val; };Quoted 2 lines
I feel this will be easy to understand and makes the code simpler. Changes will be minimal.
Babu,
I went in this direction because of
rdt_find_domain()which is used to search either of the "ctrl" or "mon" lists. So it needs to be sure that the "list" and "id" fields are at identical offsets in both therdt_ctrl_domainandrdt_mon_domainstructures. Best way to guarantee[1] that is to create the "hdr" entry (which later acquired thecpu_maskfield as a common element after a comment from Reinette).
Quoted 2 lines
One way to avoid this would be to essentially duplicate
rdt_find_domain()intordt_find_ctrl_domain()andrdt_find_mon_domain()
It could been solved by passing a flag(0 or mon and 1 for ctrl) as we know where this is being called.
Quoted 2 lines
... but I fear the function is just big enough to get complaints that the two copies should somehow be merged.
Ok. That is fine. Lets go with current implementation. Thanks for showing the discussion.
Quoted 6 lines
-Tony
[1] In v5 I tried using a comment in each to say they must be the same, but Reinette didn't like comments within declarations:
https://lore.kernel.org/all/[email protected]/
Signature · 2 lines
Thanks Babu Moger
Re: [PATCH v11 2/8] x86/resctrl: Prepare to split rdt_domain structure
In reply to Tony LuckHi Tony,
Quoted 11 lines · Tony Luck
The
rdt_domainstructure is used for both control and monitor features. It is about to be split into separate structures for these two usages because the scope for control and monitoring features for a resource will be different for future resources.To allow for common code that scans a list of domains looking for a specific domain id, move all the common fields ("list", "id", "
cpu_mask") into their own structure within therdt_domainstructure.Signed-off-by Tony Luck <[email protected]>---
Reinette
Tony Luck
maintainerPATCH v11 3/8 x86/resctrl: Prepare for different scope for control/monitor operations
In reply to Tony LuckResctrl assumes that control and monitor operations on a resource are performed at the same scope.
Prepare for systems that use different scope (specifically Intel needs to split the RDT_RESOURCE_L3 resource to use L3 scope for cache control and NODE scope for cache occupancy and memory bandwidth monitoring).
Create separate domain lists for control and monitor operations.
Note that errors during initialization of either control or monitor functions on a domain would previously result in that domain being excluded from both control and monitor operations. Now the domains are allocated independently it is no longer required to disable both control and monitor operations if either fail.
---
Changes since v10:
Reinette: Took your rewritten comment for rdt_find_domain()
Reinette: Fixed error handling in domain_add_cpu_mon(),
domain_remove_cpu_{ctrl,mon}()Tony: s/domain_add_cpu - Add a cpu/domain_add_cpu - Add a CPU/
include/linux/resctrl.h | 25 ++- arch/x86/kernel/cpu/resctrl/internal.h | 6 +- arch/x86/kernel/cpu/resctrl/core.c | 202 ++++++++++++++++------ arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 12 +- arch/x86/kernel/cpu/resctrl/monitor.c | 4 +- arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 4 +- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 55 +++--- 7 files changed, 213 insertions(+), 95 deletions(-)
include/linux/resctrl.h +19 -6
@@ -52,15 +52,22 @@ struct resctrl_staged_config {bool have_new_ctrl; }; +enum resctrl_domain_type { +RESCTRL_CTRL_DOMAIN , +RESCTRL_MON_DOMAIN , +}; +/** * struct rdt_domain_hdr - common header for different domain types * @list: all instances of this resource * @id: unique id for this instance +* @type: type of this instance * @cpu_mask: which CPUs share this resource */ struct rdt_domain_hdr {struct list_head list;int id; +enum resctrl_domain_type type;struct cpumask cpu_mask; };
@@ -163,10 +170,12 @@ enum resctrl_scope {* @alloc_capable: Is allocation available on this machine * @mon_capable: Is monitor feature available on this machine * @num_rmid: Number of RMIDs available -* @scope: Scope of this resource +* @ctrl_scope: Scope of this resource for control functions +* @mon_scope: Scope of this resource for monitor functions * @cache: Cache allocation related data * @membw: If the component has bandwidth controls, their properties. -* @domains: All domains for this resource +* @ctrl_domains: Control domains for this resource +* @mon_domains: Monitor domains for this resource * @name: Name to use in "schemata" file. * @data_width: Character width of data when displaying * @default_ctrl: Specifies default cache cbm or memory B/W percent.
@@ -181,10 +190,12 @@ struct rdt_resource {bool alloc_capable;bool mon_capable;int num_rmid; -enum resctrl_scope scope; +enum resctrl_scope ctrl_scope; +enum resctrl_scope mon_scope;struct resctrl_cache cache;struct resctrl_membw membw; -struct list_head domains; +struct list_head ctrl_domains; +struct list_head mon_domains;char *name;int data_width;u32 default_ctrl;
@@ -230,8 +241,10 @@ int resctrl_arch_update_one(struct rdt_resource *r, struct rdt_domain *d,u32 resctrl_arch_get_config (struct rdt_resource *r,struct rdt_domain *d,u32 closid,enum resctrl_conf_type type); -int resctrl_online_domain (struct rdt_resource *r,struct rdt_domain *d); -void resctrl_offline_domain (struct rdt_resource *r,struct rdt_domain *d); +int resctrl_online_ctrl_domain (struct rdt_resource *r,struct rdt_domain *d); +int resctrl_online_mon_domain (struct rdt_resource *r,struct rdt_domain *d); +void resctrl_offline_ctrl_domain (struct rdt_resource *r,struct rdt_domain *d); +void resctrl_offline_mon_domain (struct rdt_resource *r,struct rdt_domain *d);/** * resctrl_arch_rmid_read() - Read the eventid counter corresponding to rmid
arch/x86/kernel/cpu/resctrl/internal.h +3 -3
@@ -520,8 +520,8 @@ 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 *rdt_find_domain (struct rdt_resource *r,int id, -struct list_head **pos); +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,
@@ -540,7 +540,7 @@ int rdt_pseudo_lock_init(void);void rdt_pseudo_lock_release (void );int rdtgroup_pseudo_lock_create (struct rdtgroup *rdtgrp);void rdtgroup_pseudo_lock_remove (struct rdtgroup *rdtgrp); -struct rdt_domain *get_domain_from_cpu (int cpu,struct rdt_resource *r); +struct rdt_domain *get_ctrl_domain_from_cpu (int cpu,struct rdt_resource *r);int closids_supported (void );void closid_free (int closid);int alloc_rmid (void );
arch/x86/kernel/cpu/resctrl/core.c +150 -52
328 lines not on this page · raw message
arch/x86/kernel/cpu/resctrl/ctrlmondata.c +7 -5
@@ -226,7 +226,7 @@ static int parse_line(char *line, struct resctrl_schema *s,return -EINVAL ; } dom =strim (dom); -list_for_each_entry (d, &r->domains, hdr.list) { +list_for_each_entry (d, &r->ctrl_domains, hdr.list) {if (d->hdr.id == dom_id) { data.buf = dom; data.rdtgrp = rdtgrp;
@@ -318,7 +318,7 @@ int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid)return -ENOMEM ; msr_param.res =NULL ; -list_for_each_entry (d, &r->domains, hdr.list) { +list_for_each_entry (d, &r->ctrl_domains, hdr.list) { hw_dom =resctrl_to_arch_dom (d);for (t =0 ; t <CDP_NUM_TYPES ; t++) { cfg = &hw_dom->d_resctrl.staged_config[t];
@@ -466,7 +466,7 @@ static void show_doms(struct seq_file *s, struct resctrl_schema *schema, int clou32 ctrl_val;seq_printf (s,"%*s:" , max_name_width, schema->name); -list_for_each_entry (dom, &r->domains, hdr.list) { +list_for_each_entry (dom, &r->ctrl_domains, hdr.list) {if (sep)seq_puts (s,";" );
@@ -542,6 +542,7 @@ void mon_event_read(struct rmid_read *rr, struct rdt_resource *r,int rdtgroup_mondata_show (struct seq_file *m,void *arg) {struct kernfs_open_file *of = m->private; +struct rdt_domain_hdr *hdr;u32 resid, evtid, domid;struct rdtgroup *rdtgrp;struct rdt_resource *r;
@@ -562,11 +563,12 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg) evtid = md.u.evtid; r = &rdt_resources_all[resid].r_resctrl; - d =rdt_find_domain (r, domid,NULL ); -if (!d) { + hdr =rdt_find_domain (&r->mon_domains, domid,NULL ); +if (!hdr ||WARN_ON_ONCE (hdr->type !=RESCTRL_MON_DOMAIN )) { ret = -ENOENT ; goto out; } + d = container_of(hdr, struct rdt_domain, hdr);mon_event_read (&rr, r, d, rdtgrp, evtid, false);
arch/x86/kernel/cpu/resctrl/monitor.c +2 -2
@@ -340,7 +340,7 @@ static void add_rmid_to_limbo(struct rmid_entry *entry) entry->busy =0 ; cpu =get_cpu (); -list_for_each_entry (d, &r->domains, hdr.list) { +list_for_each_entry (d, &r->mon_domains, hdr.list) {if (cpumask_test_cpu (cpu, &d->hdr.cpu_mask)) { err = resctrl_arch_rmid_read(r, d, entry->rmid, QOS_L3_OCCUP_EVENT_ID,
@@ -535,7 +535,7 @@ static void update_mba_bw(struct rdtgroup *rgrp, struct rdt_domain *dom_mbm) rmid = rgrp->mon.rmid; pmbm_data = &dom_mbm->mbm_local[rmid]; - dom_mba =get_domain_from_cpu (smp_processor_id (), r_mba); + dom_mba =get_ctrl_domain_from_cpu (smp_processor_id (), r_mba);if (!dom_mba) {pr_warn_once ("Failure to get domain for MBA update\n" );return ;
arch/x86/kernel/cpu/resctrl/pseudo_lock.c +2 -2
@@ -292,7 +292,7 @@ static void pseudo_lock_region_clear(struct pseudo_lock_region *plr)*/ static int pseudo_lock_region_init (struct pseudo_lock_region *plr) { -enum resctrl_scope scope = plr->s->res->scope; +enum resctrl_scope scope = plr->s->res->ctrl_scope;struct cpu_cacheinfo *ci;int ret;int i;
@@ -856,7 +856,7 @@ bool rdtgroup_pseudo_locked_in_hierarchy(struct rdt_domain *d)* associated with them. */ for_each_alloc_capable_rdt_resource (r) { -list_for_each_entry (d_i, &r->domains, hdr.list) { +list_for_each_entry (d_i, &r->ctrl_domains, hdr.list) {if (d_i->plr)cpumask_or (cpu_with_psl, cpu_with_psl, &d_i->hdr.cpu_mask);
arch/x86/kernel/cpu/resctrl/rdtgroup.c +30 -25
170 lines not on this page · raw message
Signature · 1 line
2.41.0
Reinette Chatre
maintainerRe: [PATCH v11 3/8] x86/resctrl: Prepare for different scope for control/monitor operations
Hi Tony,
On 11/9/2023 3:09 PM, Tony Luck wrote:
...
Quoted 6 lines
arch/x86/kernel/cpu/resctrl/core.c +4
-0+static void domain_remove_cpu_ctrl (int cpu,struct rdt_resource *r) +{ +int id =get_domain_id_from_scope (cpu, r->ctrl_scope);struct rdt_hw_domain *hw_dom; +struct rdt_domain_hdr *hdr;struct rdt_domain *d;
arch/x86/kernel/cpu/resctrl/core.c static void domain_add_cpu(int cpu, struct rdt_resource *r) · line 632
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/core.c +3
-3if (id <0 )return ; - d =rdt_find_domain (r, id,NULL ); -if (!d) { -pr_warn ("Couldn't find domain with id=%d for CPU %d\n" , id, cpu); + hdr =rdt_find_domain (&r->ctrl_domains, id,NULL ); +if (!hdr) { +pr_warn ("Couldn't find control scope id=%d for CPU %d\n" , id, cpu);
This error message seems strange to me. Shouldn't this just be "Couldn't find control domain with id=..."? Also, can the resource name be added in error message to help user dig into cause of error?
Quoted 27 lines
arch/x86/kernel/cpu/resctrl/core.c +13
-1return ; } + +if (WARN_ON_ONCE (hdr->type !=RESCTRL_CTRL_DOMAIN )) +return ; + + d = container_of(hdr, struct rdt_domain, hdr); hw_dom =resctrl_to_arch_dom (d);cpumask_clear_cpu (cpu, &d->hdr.cpu_mask);if (cpumask_empty (&d->hdr.cpu_mask)) { -resctrl_offline_domain (r, d); +resctrl_offline_ctrl_domain (r, d);list_del (&d->hdr.list);/* @@ -596,6 +654,38 @@ static void domain_remove_cpu(int cpu, struct rdt_resource *r)return ; } +} + +static void domain_remove_cpu_mon (int cpu,struct rdt_resource *r) +{ +int id =get_domain_id_from_scope (cpu, r->mon_scope); +struct rdt_hw_domain *hw_dom; +struct rdt_domain_hdr *hdr;
arch/x86/kernel/cpu/resctrl/core.c static void domain_remove_cpu(int cpu, struct rdt_resource *r) · line 673
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/core.c +10
-0+struct rdt_domain *d; + +if (id <0 ) +return ; + + hdr =rdt_find_domain (&r->mon_domains, id,NULL ); +if (!hdr) { +pr_warn ("Couldn't find monitor scope id=%d for CPU %d\n" , id, cpu); +return ; + }
Similar to above, can this be "Couldn't find monitor domain with id..."? Can resource name be added here also?
The rest of the patch looks good to me.
Reinette
Tony Luck
maintainerPATCH v11 4/8 x86/resctrl: Split the rdt_domain and rdt_hw_domain structures
In reply to Tony LuckThe same rdt_domain structure is used for both control and monitor functions. But this results in wasted memory as some of the fields are only used by control functions, while most are only used for monitor functions.
Split into separate rdt_ctrl_domain and rdt_mon_domain structures with just the fields required for control and monitoring respectively.
Similar split of the rdt_hw_domain structure into rdt_hw_ctrl_domain and rdt_hw_mon_domain.
---
Changes since v10:
Reinette: Remove struct cpumask cpu_mask; that had snuck bac into the
defintion of "struct rdt_domain"
include/linux/resctrl.h | 48 +++++++------ arch/x86/kernel/cpu/resctrl/internal.h | 60 ++++++++++------ arch/x86/kernel/cpu/resctrl/core.c | 87 ++++++++++++----------- arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 32 ++++----- arch/x86/kernel/cpu/resctrl/monitor.c | 40 +++++------ arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 6 +- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 62 ++++++++-------- 7 files changed, 182 insertions(+), 153 deletions(-)
include/linux/resctrl.h +28 -20
@@ -72,7 +72,23 @@ struct rdt_domain_hdr { };/** -* struct rdt_domain - group of CPUs sharing a resctrl resource +* struct rdt_ctrl_domain - group of CPUs sharing a resctrl control resource +* @hdr: common header for different domain types +* @plr: pseudo-locked region (if any) associated with domain +* @staged_config: parsed configuration to be applied +* @mbps_val: When mba_sc is enabled, this holds the array of user +* specified control values for mba_sc in MBps, indexed +* by closid +*/ +struct rdt_ctrl_domain { +struct rdt_domain_hdr hdr; +struct pseudo_lock_region *plr; +struct resctrl_staged_config staged_config[CDP_NUM_TYPES ]; +u32 *mbps_val; +}; + +/** +* struct rdt_mon_domain - group of CPUs sharing a resctrl monitor resource * @hdr: common header for different domain types * @rmid_busy_llc: bitmap of which limbo RMIDs are above threshold * @mbm_total: saved state for MBM total bandwidth
@@ -81,13 +97,8 @@ struct rdt_domain_hdr {* @cqm_limbo: worker to periodically read CQM h/w counters * @mbm_work_cpu: worker CPU for MBM h/w counters * @cqm_work_cpu: worker CPU for CQM h/w counters -* @plr: pseudo-locked region (if any) associated with domain -* @staged_config: parsed configuration to be applied -* @mbps_val: When mba_sc is enabled, this holds the array of user -* specified control values for mba_sc in MBps, indexed -* by closid */ -struct rdt_domain { +struct rdt_mon_domain {struct rdt_domain_hdr hdr;unsigned long *rmid_busy_llc;struct mbm_state *mbm_total;
@@ -96,9 +107,6 @@ struct rdt_domain {struct delayed_work cqm_limbo;int mbm_work_cpu;int cqm_work_cpu; -struct pseudo_lock_region *plr; -struct resctrl_staged_config staged_config[CDP_NUM_TYPES ]; -u32 *mbps_val; };/**
@@ -202,7 +210,7 @@ struct rdt_resource {const char *format_str;int (*parse_ctrlval)(struct rdt_parse_data *data,struct resctrl_schema *s, -struct rdt_domain *d); +struct rdt_ctrl_domain *d);struct list_head evt_list;unsigned long fflags;bool cdp_capable;
@@ -236,15 +244,15 @@ int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid);* Update the ctrl_val and apply this config right now. * Must be called on one of the domain's CPUs. */ -int resctrl_arch_update_one (struct rdt_resource *r,struct rdt_domain *d, +int resctrl_arch_update_one (struct rdt_resource *r,struct rdt_ctrl_domain *d,u32 closid,enum resctrl_conf_type t,u32 cfg_val); -u32 resctrl_arch_get_config (struct rdt_resource *r,struct rdt_domain *d, +u32 resctrl_arch_get_config (struct rdt_resource *r,struct rdt_ctrl_domain *d,u32 closid,enum resctrl_conf_type type); -int resctrl_online_ctrl_domain (struct rdt_resource *r,struct rdt_domain *d); -int resctrl_online_mon_domain (struct rdt_resource *r,struct rdt_domain *d); -void resctrl_offline_ctrl_domain (struct rdt_resource *r,struct rdt_domain *d); -void resctrl_offline_mon_domain (struct rdt_resource *r,struct rdt_domain *d); +int resctrl_online_ctrl_domain (struct rdt_resource *r,struct rdt_ctrl_domain *d); +int resctrl_online_mon_domain (struct rdt_resource *r,struct rdt_mon_domain *d); +void resctrl_offline_ctrl_domain (struct rdt_resource *r,struct rdt_ctrl_domain *d); +void resctrl_offline_mon_domain (struct rdt_resource *r,struct rdt_mon_domain *d);/** * resctrl_arch_rmid_read() - Read the eventid counter corresponding to rmid
@@ -260,7 +268,7 @@ void resctrl_offline_mon_domain(struct rdt_resource *r, struct rdt_domain *d);* Return: * 0 on success, or -EIO, -EINVAL etc on error. */ -int resctrl_arch_rmid_read (struct rdt_resource *r,struct rdt_domain *d, +int resctrl_arch_rmid_read (struct rdt_resource *r,struct rdt_mon_domain *d,u32 rmid,enum resctrl_event_id eventid,u64 *val);/**
@@ -273,7 +281,7 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain *d,* * This can be called from any CPU. */ -void resctrl_arch_reset_rmid (struct rdt_resource *r,struct rdt_domain *d, +void resctrl_arch_reset_rmid (struct rdt_resource *r,struct rdt_mon_domain *d,u32 rmid,enum resctrl_event_id eventid);/**
@@ -285,7 +293,7 @@ void resctrl_arch_reset_rmid(struct rdt_resource *r, struct rdt_domain *d,* * This can be called from any CPU. */ -void resctrl_arch_reset_rmid_all (struct rdt_resource *r,struct rdt_domain *d); +void resctrl_arch_reset_rmid_all (struct rdt_resource *r,struct rdt_mon_domain *d);extern unsigned int resctrl_rmid_realloc_threshold;extern unsigned int resctrl_rmid_realloc_limit;
arch/x86/kernel/cpu/resctrl/internal.h +38 -22
131 lines not on this page · raw message
arch/x86/kernel/cpu/resctrl/core.c +46 -41
246 lines not on this page · raw message
arch/x86/kernel/cpu/resctrl/ctrlmondata.c +16 -16
@@ -58,7 +58,7 @@ static bool bw_validate(char *buf, unsigned long *data, struct rdt_resource *r) }int parse_bw (struct rdt_parse_data *data,struct resctrl_schema *s, -struct rdt_domain *d) +struct rdt_ctrl_domain *d) {struct resctrl_staged_config *cfg;u32 closid = data->rdtgrp->closid;
@@ -137,7 +137,7 @@ static bool cbm_validate(char *buf, u32 *data, struct rdt_resource *r)* resource type. */ int parse_cbm (struct rdt_parse_data *data,struct resctrl_schema *s, -struct rdt_domain *d) +struct rdt_ctrl_domain *d) {struct rdtgroup *rdtgrp = data->rdtgrp;struct resctrl_staged_config *cfg;
@@ -206,8 +206,8 @@ static int parse_line(char *line, struct resctrl_schema *s,struct resctrl_staged_config *cfg;struct rdt_resource *r = s->res;struct rdt_parse_data data; +struct rdt_ctrl_domain *d;char *dom =NULL , *id; -struct rdt_domain *d;unsigned long dom_id; if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP &&
@@ -267,11 +267,11 @@ static u32 get_config_index(u32 closid, enum resctrl_conf_type type) } } -static bool apply_config (struct rdt_hw_domain *hw_dom, +static bool apply_config (struct rdt_hw_ctrl_domain *hw_dom,struct resctrl_staged_config *cfg,u32 idx,cpumask_var_t cpu_mask) { -struct rdt_domain *dom = &hw_dom->d_resctrl; +struct rdt_ctrl_domain *dom = &hw_dom->d_resctrl;if (cfg->new_ctrl != hw_dom->ctrl_val[idx]) {cpumask_set_cpu (cpumask_any (&dom->hdr.cpu_mask), cpu_mask);
@@ -283,11 +283,11 @@ static bool apply_config(struct rdt_hw_domain *hw_dom,return false; } -int resctrl_arch_update_one (struct rdt_resource *r,struct rdt_domain *d, +int resctrl_arch_update_one (struct rdt_resource *r,struct rdt_ctrl_domain *d,u32 closid,enum resctrl_conf_type t,u32 cfg_val) { +struct rdt_hw_ctrl_domain *hw_dom =resctrl_to_arch_ctrl_dom (d);struct rdt_hw_resource *hw_res =resctrl_to_arch_res (r); -struct rdt_hw_domain *hw_dom =resctrl_to_arch_dom (d);u32 idx =get_config_index (closid, t);struct msr_param msr_param;
@@ -307,11 +307,11 @@ int resctrl_arch_update_one(struct rdt_resource *r, struct rdt_domain *d,int resctrl_arch_update_domains (struct rdt_resource *r,u32 closid) {struct resctrl_staged_config *cfg; -struct rdt_hw_domain *hw_dom; +struct rdt_hw_ctrl_domain *hw_dom;struct msr_param msr_param; +struct rdt_ctrl_domain *d;enum resctrl_conf_type t;cpumask_var_t cpu_mask; -struct rdt_domain *d;u32 idx;if (!zalloc_cpumask_var (&cpu_mask,GFP_KERNEL ))
@@ -319,7 +319,7 @@ int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid) msr_param.res =NULL ;list_for_each_entry (d, &r->ctrl_domains, hdr.list) { - hw_dom =resctrl_to_arch_dom (d); + hw_dom =resctrl_to_arch_ctrl_dom (d);for (t =0 ; t <CDP_NUM_TYPES ; t++) { cfg = &hw_dom->d_resctrl.staged_config[t];if (!cfg->have_new_ctrl)
@@ -449,10 +449,10 @@ ssize_t rdtgroup_schemata_write(struct kernfs_open_file *of,return ret ?: nbytes; } -u32 resctrl_arch_get_config (struct rdt_resource *r,struct rdt_domain *d, +u32 resctrl_arch_get_config (struct rdt_resource *r,struct rdt_ctrl_domain *d,u32 closid,enum resctrl_conf_type type) { -struct rdt_hw_domain *hw_dom =resctrl_to_arch_dom (d); +struct rdt_hw_ctrl_domain *hw_dom =resctrl_to_arch_ctrl_dom (d);u32 idx =get_config_index (closid, type);return hw_dom->ctrl_val[idx];
@@ -461,7 +461,7 @@ u32 resctrl_arch_get_config(struct rdt_resource *r, struct rdt_domain *d,static void show_doms (struct seq_file *s,struct resctrl_schema *schema,int closid) {struct rdt_resource *r = schema->res; -struct rdt_domain *dom; +struct rdt_ctrl_domain *dom;bool sep = false;u32 ctrl_val;
@@ -523,7 +523,7 @@ int rdtgroup_schemata_show(struct kernfs_open_file *of, }void mon_event_read (struct rmid_read *rr,struct rdt_resource *r, -struct rdt_domain *d,struct rdtgroup *rdtgrp, +struct rdt_mon_domain *d,struct rdtgroup *rdtgrp,int evtid,int first) {/*
@@ -543,11 +543,11 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg) {struct kernfs_open_file *of = m->private;struct rdt_domain_hdr *hdr; +struct rdt_mon_domain *d;u32 resid, evtid, domid;struct rdtgroup *rdtgrp;struct rdt_resource *r;union mon_data_bits md; -struct rdt_domain *d;struct rmid_read rr;int ret =0 ;
@@ -568,7 +568,7 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg) ret = -ENOENT ; goto out; } - d = container_of(hdr, struct rdt_domain, hdr); + d = container_of(hdr, struct rdt_mon_domain, hdr);mon_event_read (&rr, r, d, rdtgrp, evtid, false);
arch/x86/kernel/cpu/resctrl/monitor.c +20 -20
@@ -170,7 +170,7 @@ static int __rmid_read(u32 rmid, enum resctrl_event_id eventid, u64 *val)return 0 ; } -static struct arch_mbm_state *get_arch_mbm_state (struct rdt_hw_domain *hw_dom, +static struct arch_mbm_state *get_arch_mbm_state (struct rdt_hw_mon_domain *hw_dom,u32 rmid,enum resctrl_event_id eventid) {
@@ -189,10 +189,10 @@ static struct arch_mbm_state *get_arch_mbm_state(struct rdt_hw_domain *hw_dom,return NULL ; } -void resctrl_arch_reset_rmid (struct rdt_resource *r,struct rdt_domain *d, +void resctrl_arch_reset_rmid (struct rdt_resource *r,struct rdt_mon_domain *d,u32 rmid,enum resctrl_event_id eventid) { -struct rdt_hw_domain *hw_dom =resctrl_to_arch_dom (d); +struct rdt_hw_mon_domain *hw_dom =resctrl_to_arch_mon_dom (d);struct arch_mbm_state *am; am =get_arch_mbm_state (hw_dom, rmid, eventid);
@@ -208,9 +208,9 @@ void resctrl_arch_reset_rmid(struct rdt_resource *r, struct rdt_domain *d,* Assumes that hardware counters are also reset and thus that there is * no need to record initial non-zero counts. */ -void resctrl_arch_reset_rmid_all (struct rdt_resource *r,struct rdt_domain *d) +void resctrl_arch_reset_rmid_all (struct rdt_resource *r,struct rdt_mon_domain *d) { -struct rdt_hw_domain *hw_dom =resctrl_to_arch_dom (d); +struct rdt_hw_mon_domain *hw_dom =resctrl_to_arch_mon_dom (d);if (is_mbm_total_enabled ()) memset(hw_dom->arch_mbm_total, 0,
@@ -229,11 +229,11 @@ static u64 mbm_overflow_count(u64 prev_msr, u64 cur_msr, unsigned int width)return chunks >> shift; } -int resctrl_arch_rmid_read (struct rdt_resource *r,struct rdt_domain *d, +int resctrl_arch_rmid_read (struct rdt_resource *r,struct rdt_mon_domain *d,u32 rmid,enum resctrl_event_id eventid,u64 *val) { +struct rdt_hw_mon_domain *hw_dom =resctrl_to_arch_mon_dom (d);struct rdt_hw_resource *hw_res =resctrl_to_arch_res (r); -struct rdt_hw_domain *hw_dom =resctrl_to_arch_dom (d);struct arch_mbm_state *am;u64 msr_val, chunks;int ret;
@@ -266,7 +266,7 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain *d,* decrement the count. If the busy count gets to zero on an RMID, we * free the RMID */ -void __check_limbo (struct rdt_domain *d,bool force_free) +void __check_limbo (struct rdt_mon_domain *d,bool force_free) {struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl;struct rmid_entry *entry;
@@ -305,7 +305,7 @@ void __check_limbo(struct rdt_domain *d, bool force_free) } } -bool has_busy_rmid (struct rdt_resource *r,struct rdt_domain *d) +bool has_busy_rmid (struct rdt_resource *r,struct rdt_mon_domain *d) {return find_first_bit (d->rmid_busy_llc, r->num_rmid) != r->num_rmid; }
@@ -334,7 +334,7 @@ int alloc_rmid(void)static void add_rmid_to_limbo (struct rmid_entry *entry) {struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl; -struct rdt_domain *d; +struct rdt_mon_domain *d;int cpu, err;u64 val =0 ;
@@ -383,7 +383,7 @@ void free_rmid(u32 rmid)list_add_tail (&entry->list, &rmid_free_lru); } -static struct mbm_state *get_mbm_state (struct rdt_domain *d,u32 rmid, +static struct mbm_state *get_mbm_state (struct rdt_mon_domain *d,u32 rmid,enum resctrl_event_id evtid) {switch (evtid) {
@@ -516,13 +516,13 @@ void mon_event_count(void *info)* throttle MSRs already have low percentage values. To avoid * unnecessarily restricting such rdtgroups, we also increase the bandwidth. */ -static void update_mba_bw (struct rdtgroup *rgrp,struct rdt_domain *dom_mbm) +static void update_mba_bw (struct rdtgroup *rgrp,struct rdt_mon_domain *dom_mbm) {u32 closid, rmid, cur_msr_val, new_msr_val;struct mbm_state *pmbm_data, *cmbm_data; +struct rdt_ctrl_domain *dom_mba;u32 cur_bw, delta_bw, user_bw;struct rdt_resource *r_mba; -struct rdt_domain *dom_mba;struct list_head *head;struct rdtgroup *entry;
@@ -600,7 +600,7 @@ static void update_mba_bw(struct rdtgroup *rgrp, struct rdt_domain *dom_mbm) } } -static void mbm_update (struct rdt_resource *r,struct rdt_domain *d,int rmid) +static void mbm_update (struct rdt_resource *r,struct rdt_mon_domain *d,int rmid) {struct rmid_read rr;
@@ -640,13 +640,13 @@ void cqm_handle_limbo(struct work_struct *work) {unsigned long delay =msecs_to_jiffies (CQM_LIMBOCHECK_INTERVAL );int cpu =smp_processor_id (); +struct rdt_mon_domain *d;struct rdt_resource *r; -struct rdt_domain *d;mutex_lock (&rdtgroup_mutex); r = &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl; - d = container_of(work, struct rdt_domain, cqm_limbo.work); + d = container_of(work, struct rdt_mon_domain, cqm_limbo.work);__check_limbo (d, false);
@@ -656,7 +656,7 @@ void cqm_handle_limbo(struct work_struct *work)mutex_unlock (&rdtgroup_mutex); } -void cqm_setup_limbo_handler (struct rdt_domain *dom,unsigned long delay_ms) +void cqm_setup_limbo_handler (struct rdt_mon_domain *dom,unsigned long delay_ms) {unsigned long delay =msecs_to_jiffies (delay_ms);int cpu;
@@ -672,9 +672,9 @@ void mbm_handle_overflow(struct work_struct *work)unsigned long delay =msecs_to_jiffies (MBM_OVERFLOW_INTERVAL );struct rdtgroup *prgrp, *crgrp;int cpu =smp_processor_id (); +struct rdt_mon_domain *d;struct list_head *head;struct rdt_resource *r; -struct rdt_domain *d;mutex_lock (&rdtgroup_mutex);
@@ -682,7 +682,7 @@ void mbm_handle_overflow(struct work_struct *work) goto out_unlock; r = &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl; - d = container_of(work, struct rdt_domain, mbm_over.work); + d = container_of(work, struct rdt_mon_domain, mbm_over.work);list_for_each_entry (prgrp, &rdt_all_groups, rdtgroup_list) {mbm_update (r, d, prgrp->mon.rmid);
@@ -701,7 +701,7 @@ void mbm_handle_overflow(struct work_struct *work)mutex_unlock (&rdtgroup_mutex); } -void mbm_setup_overflow_handler (struct rdt_domain *dom,unsigned long delay_ms) +void mbm_setup_overflow_handler (struct rdt_mon_domain *dom,unsigned long delay_ms) {unsigned long delay =msecs_to_jiffies (delay_ms);int cpu;
arch/x86/kernel/cpu/resctrl/pseudo_lock.c +3 -3
@@ -814,7 +814,7 @@ int rdtgroup_locksetup_exit(struct rdtgroup *rdtgrp)* Return: true if @cbm overlaps with pseudo-locked region on @d, false * otherwise. */ -bool rdtgroup_cbm_overlaps_pseudo_locked (struct rdt_domain *d,unsigned long cbm) +bool rdtgroup_cbm_overlaps_pseudo_locked (struct rdt_ctrl_domain *d,unsigned long cbm) {unsigned int cbm_len;unsigned long cbm_b;
@@ -841,11 +841,11 @@ bool rdtgroup_cbm_overlaps_pseudo_locked(struct rdt_domain *d, unsigned long cbm* if it is not possible to test due to memory allocation issue, * false otherwise. */ -bool rdtgroup_pseudo_locked_in_hierarchy (struct rdt_domain *d) +bool rdtgroup_pseudo_locked_in_hierarchy (struct rdt_ctrl_domain *d) { +struct rdt_ctrl_domain *d_i;cpumask_var_t cpu_with_psl;struct rdt_resource *r; -struct rdt_domain *d_i;bool ret = false;if (!zalloc_cpumask_var (&cpu_with_psl,GFP_KERNEL ))
arch/x86/kernel/cpu/resctrl/rdtgroup.c +31 -31
252 lines not on this page · raw message
Signature · 1 line
2.41.0
Re: [PATCH v11 4/8] x86/resctrl: Split the rdt_domain and rdt_hw_domain structures
Hi Tony,
Quoted 8 lines · Tony Luck
The same
rdt_domainstructure is used for both control and monitor functions. But this results in wasted memory as some of the fields are only used by control functions, while most are only used for monitor functions.Split into separate
rdt_ctrl_domainandrdt_mon_domainstructures with just the fields required for control and monitoring respectively.
Quoted 6 lines
Similar split of the
rdt_hw_domainstructure intordt_hw_ctrl_domainandrdt_hw_mon_domain.Reviewed-by Peter Newman <[email protected]>Signed-off-by Tony Luck <[email protected]>---
Reinette
Tony Luck
maintainerPATCH v11 5/8 x86/resctrl: Add node-scope to the options for feature scope
In reply to Tony LuckCurrently supported resctrl features are all domain scoped the same as the scope of the L2 or L3 caches.
Add RESCTRL_NODE as a new option for features that are scoped at the same granularity as NUMA nodes. This is needed for Intel's Sub-NUMA Cluster (SNC) feature where monitoring features are node scoped.
--- include/linux/resctrl.h | 1 + arch/x86/kernel/cpu/resctrl/core.c | 2 ++ 2 files changed, 3 insertions(+)
include/linux/resctrl.h +1 -0
@@ -170,6 +170,7 @@ struct resctrl_schema;enum resctrl_scope {RESCTRL_L2_CACHE =2 ,RESCTRL_L3_CACHE =3 , +RESCTRL_NODE , };/**
arch/x86/kernel/cpu/resctrl/core.c +2 -0
@@ -502,6 +502,8 @@ static int get_domain_id_from_scope(int cpu, enum resctrl_scope scope)case RESCTRL_L2_CACHE :case RESCTRL_L3_CACHE :return get_cpu_cacheinfo_id (cpu, scope); +case RESCTRL_NODE : +return cpu_to_node (cpu);default :break ; }
Signature · 1 line
2.41.0
Re: [PATCH v11 5/8] x86/resctrl: Add node-scope to the options for feature scope
Hi Tony,
Quoted 10 lines · Tony Luck
Currently supported resctrl features are all domain scoped the same as the scope of the L2 or L3 caches.
Add
RESCTRL_NODEas a new option for features that are scoped at the same granularity as NUMA nodes. This is needed for Intel's Sub-NUMA Cluster (SNC) feature where monitoring features are node scoped.Reviewed-by Peter Newman <[email protected]>Signed-off-by Tony Luck <[email protected]>---
Please follow guidance in section "Ordering of commit tags" from Documentation/process/maintainer-tip.rst
With that addressed (thus adding Reviewed-by tags after your author SOB):
Reinette
Tony Luck
maintainerPATCH v11 6/8 x86/resctrl: Introduce snc_nodes_per_l3_cache
In reply to Tony LuckIntel Sub-NUMA Cluster (SNC) is a feature that subdivides the CPU cores and memory controllers on a socket into two or more groups. These are presented to the operating system as NUMA nodes.
This may enable some workloads to have slightly lower latency to memory as the memory controller(s) in an SNC node are electrically closer to the CPU cores on that SNC node. This cost may be offset by lower bandwidth since the memory accesses for each core can only be interleaved between the memory controllers on the same SNC node.
Resctrl monitoring on an Intel system depends upon attaching RMIDs to tasks to track L3 cache occupancy and memory bandwidth. There is an MSR that controls how the RMIDs are shared between SNC nodes.
The default mode divides them numerically. E.g. when there are two SNC nodes on a socket the lower number half of the RMIDs are given to the first node, the remainder to the second node. This would be difficult to use with the Linux resctrl interface as specific RMID values assigned to resctrl groups are not visible to users.
The other mode divides the RMIDs and renumbers the ones on the second SNC node to start from zero.
Even with this renumbering SNC mode requires several changes in resctrl behavior for correct operation.
Add a global integer "snc_nodes_per_l3_cache" that will show how many SNC nodes share each L3 cache. When this is "1", SNC mode is either not implemented, or not enabled, but all places that need to check it are updated to take appropriate action when SNC mode is enabled.
Code that needs to take action when SNC is enabled is:
1) The number of logical RMIDs per L3 cache available for use is the number of physical RMIDs divided by the number of SNC nodes.
2) Likewise the "mon_scale" value must be divided by the number of SNC nodes.
3) The RMID renumbering operates when using the value from the IA32_PQR_ASSOC MSR to count accesses by a task. When reading an RMID counter, code must adjust from the logical RMID used to the physical RMID value for the SNC node that it wishes to read and load the adjusted value into the IA32_QM_EVTSEL MSR.
4) The L3 cache is divided between the SNC nodes. So the value reported in the resctrl "size" file is divided by the number of SNC nodes because the effective amount of cache that can be allocated is reduced by that factor.
5) The "-o mba_MBps" mount option must be disabled in SNC mode because the monitoring is being done per SNC node, while the bandwidth allocation is still done at the L3 cache scope. Trying to use this feedback loop might result in contradictory changes to the throttling level coming from each of the SNC node bandwidth measurements.
--- arch/x86/kernel/cpu/resctrl/internal.h | 2 ++ arch/x86/kernel/cpu/resctrl/core.c | 6 ++++++ arch/x86/kernel/cpu/resctrl/monitor.c | 16 +++++++++++++--- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 5 +++-- 4 files changed, 24 insertions(+), 5 deletions(-)
arch/x86/kernel/cpu/resctrl/internal.h +2 -0
@@ -446,6 +446,8 @@ DECLARE_STATIC_KEY_FALSE(rdt_alloc_enable_key);extern struct dentry *debugfs_resctrl; +extern unsigned int snc_nodes_per_l3_cache; +enum resctrl_res_level {RDT_RESOURCE_L3 ,RDT_RESOURCE_L2 ,
arch/x86/kernel/cpu/resctrl/core.c +6 -0
@@ -48,6 +48,12 @@ int max_name_width, max_data_width;*/ bool rdt_alloc_capable; +/* +* Number of SNC nodes that share each L3 cache. Default is 1 for +* systems that do not support SNC, or have SNC disabled. +*/ +unsigned int snc_nodes_per_l3_cache =1 ; +static void mba_wrmsr_intel (struct rdt_ctrl_domain *d,struct msr_param *m,struct rdt_resource *r);
arch/x86/kernel/cpu/resctrl/monitor.c +13 -3
@@ -148,8 +148,18 @@ static inline struct rmid_entry *__rmid_entry(u32 rmid)static int __rmid_read (u32 rmid,enum resctrl_event_id eventid,u64 *val) { +struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl; +int cpu =smp_processor_id (); +int rmid_offset =0 ;u64 msr_val; +/* +* When SNC mode is on, need to compute the offset to read the +* physical RMID counter for the node to which this CPU belongs. +*/ +if (snc_nodes_per_l3_cache >1 ) + rmid_offset = (cpu_to_node (cpu) % snc_nodes_per_l3_cache) * r->num_rmid; +/* * As per the SDM, when IA32_QM_EVTSEL.EvtID (bits 7:0) is configured * with a valid event code for supported resource type and the bits
@@ -158,7 +168,7 @@ static int __rmid_read(u32 rmid, enum resctrl_event_id eventid, u64 *val)* IA32_QM_CTR.Error (bit 63) and IA32_QM_CTR.Unavailable (bit 62) * are error bits. */ -wrmsr (MSR_IA32_QM_EVTSEL , eventid, rmid); +wrmsr (MSR_IA32_QM_EVTSEL , eventid, rmid + rmid_offset);rdmsrl (MSR_IA32_QM_CTR , msr_val);if (msr_val &RMID_VAL_ERROR )
@@ -783,8 +793,8 @@ int __init rdt_get_mon_l3_config(struct rdt_resource *r)int ret; resctrl_rmid_realloc_limit = boot_cpu_data.x86_cache_size *1024 ; - hw_res->mon_scale = boot_cpu_data.x86_cache_occ_scale; - r->num_rmid = boot_cpu_data.x86_cache_max_rmid +1 ; + hw_res->mon_scale = boot_cpu_data.x86_cache_occ_scale / snc_nodes_per_l3_cache; + r->num_rmid = (boot_cpu_data.x86_cache_max_rmid +1 ) / snc_nodes_per_l3_cache; hw_res->mbm_width =MBM_CNTR_WIDTH_BASE ;if (mbm_offset >0 && mbm_offset <=MBM_CNTR_WIDTH_OFFSET_MAX )
arch/x86/kernel/cpu/resctrl/rdtgroup.c +3 -2
@@ -1425,7 +1425,7 @@ unsigned int rdtgroup_cbm_to_size(struct rdt_resource *r, } } -return size; +return size / snc_nodes_per_l3_cache; }/*
@@ -2298,7 +2298,8 @@ static bool supports_mba_mbps(void)struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_MBA ].r_resctrl;return (is_mbm_local_enabled () && - r->alloc_capable &&is_mba_linear ()); + r->alloc_capable &&is_mba_linear () && + snc_nodes_per_l3_cache ==1 ); }/*
Signature · 1 line
2.41.0
Re: [PATCH v11 6/8] x86/resctrl: Introduce snc_nodes_per_l3_cache
Hi Tony,
Quoted 43 lines · Tony Luck
Intel Sub-NUMA Cluster (SNC) is a feature that subdivides the CPU cores and memory controllers on a socket into two or more groups. These are presented to the operating system as NUMA nodes.
This may enable some workloads to have slightly lower latency to memory as the memory controller(s) in an SNC node are electrically closer to the CPU cores on that SNC node. This cost may be offset by lower bandwidth since the memory accesses for each core can only be interleaved between the memory controllers on the same SNC node.
Resctrl monitoring on an Intel system depends upon attaching RMIDs to tasks to track L3 cache occupancy and memory bandwidth. There is an MSR that controls how the RMIDs are shared between SNC nodes.
The default mode divides them numerically. E.g. when there are two SNC nodes on a socket the lower number half of the RMIDs are given to the first node, the remainder to the second node. This would be difficult to use with the Linux resctrl interface as specific RMID values assigned to resctrl groups are not visible to users.
The other mode divides the RMIDs and renumbers the ones on the second SNC node to start from zero.
Even with this renumbering SNC mode requires several changes in resctrl behavior for correct operation.
Add a global integer "
snc_nodes_per_l3_cache" that will show how many SNC nodes share each L3 cache. When this is "1", SNC mode is either not implemented, or not enabled, but all places that need to check it are updated to take appropriate action when SNC mode is enabled.Code that needs to take action when SNC is enabled is:
1) The number of logical RMIDs per L3 cache available for use is the number of physical RMIDs divided by the number of SNC nodes.
2) Likewise the "mon_scale" value must be divided by the number of SNC nodes.
3) The RMID renumbering operates when using the value from theIA32_PQR_ASSOCMSR to count accesses by a task. When reading an RMID counter, code must adjust from the logical RMID used to the physical RMID value for the SNC node that it wishes to read and load the adjusted value into theIA32_QM_EVTSELMSR.
4) The L3 cache is divided between the SNC nodes. So the value reported in the resctrl "size" file is divided by the number of SNC
Quoted 9 lines
nodes because the effective amount of cache that can be allocated is reduced by that factor.
5) The "-omba_MBps" mount option must be disabled in SNC mode because the monitoring is being done per SNC node, while the bandwidth allocation is still done at the L3 cache scope. Trying to use this feedback loop might result in contradictory changes to the throttling level coming from each of the SNC node bandwidth measurements.
The latter part of this changelog stopped being in imperative mood. To reduce confusion I slightly reworked it below to address the parts I noticed. I often get it wrong myself so please check again.
Add a global integer "snc_nodes_per_l3_cache" that shows how many SNC nodes share each L3 cache. When "snc_nodes_per_l3_cache" is "1", SNC mode is either not implemented, or not enabled.
Update all places to take appropriate action when SNC mode is enabled:
1) The number of logical RMIDs per L3 cache available for use is the number of physical RMIDs divided by the number of SNC nodes.
2) Likewise the "mon_scale" value must be divided by the number of SNC nodes.
3) The RMID renumbering operates when using the value from the IA32_PQR_ASSOC MSR to count accesses by a task. When reading an RMID counter, adjust from the logical RMID to the physical RMID value for the SNC node that it wishes to read and load the adjusted value into the IA32_QM_EVTSEL MSR.
4) Divide the L3 cache between the SNC nodes. Divide the value reported in the resctrl "size" file by the number of SNC nodes because the effective amount of cache that can be allocated is reduced by that factor.
5) Disable the "-o mba_MBps" mount option in SNC mode because the monitoring is being done per SNC node, while the bandwidth allocation is still done at the L3 cache scope. Trying to use this feedback loop might result in contradictory changes to the throttling level coming from each of the SNC node bandwidth measurements.
Quoted 3 lines
Reviewed-by Peter Newman <[email protected]>Signed-off-by Tony Luck <[email protected]>---
(same comment as previous patch about commit tag ordering)
Reinette
Tony Luck
maintainerPATCH v11 7/8 x86/resctrl: Sub NUMA Cluster detection and enable
In reply to Tony LuckThere isn't a simple hardware bit that indicates whether a CPU is running in Sub NUMA Cluster (SNC) mode. Infer the state by comparing the ratio of NUMA nodes to L3 cache instances.
When SNC mode is detected, reconfigure the RMID counters by updating the MSR_RMID_SNC_CONFIG MSR on each socket as CPUs are seen.
Clearing bit zero of the MSR divides the RMIDs and renumbers the ones on the second SNC node to start from zero.
---
Changes since v10:
Reinette: Revert two places where I'd globally swapped "h/w" for
"hardware" in comments for functions that were not touched by this patch.
arch/x86/include/asm/msr-index.h | 1 + arch/x86/kernel/cpu/resctrl/core.c | 96 ++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+)
arch/x86/include/asm/msr-index.h +1 -0
@@ -1109,6 +1109,7 @@#define MSR_IA32_QM_CTR 0xc8e#define MSR_IA32_PQR_ASSOC 0xc8f#define MSR_IA32_L3_CBM_BASE 0xc90 +#define MSR_RMID_SNC_CONFIG 0xca0#define MSR_IA32_L2_CBM_BASE 0xd10#define MSR_IA32_MBA_THRTL_BASE 0xd50
arch/x86/kernel/cpu/resctrl/core.c +96 -0
129 lines not on this page · raw message
Signature · 1 line
2.41.0
Re: [PATCH v11 7/8] x86/resctrl: Sub NUMA Cluster detection and enable
Hi Tony,
Quoted 7 lines · Tony Luck
There isn't a simple hardware bit that indicates whether a CPU is running in Sub NUMA Cluster (SNC) mode. Infer the state by comparing the ratio of NUMA nodes to L3 cache instances.
When SNC mode is detected, reconfigure the RMID counters by updating the
MSR_RMID_SNC_CONFIGMSR on each socket as CPUs are seen.
Quoted 6 lines
Clearing bit zero of the MSR divides the RMIDs and renumbers the ones on the second SNC node to start from zero.
Reviewed-by Peter Newman <[email protected]>Signed-off-by Tony Luck <[email protected]>---
(note ordering of commit tags)
Reinette
Tony Luck
maintainerPATCH v11 8/8 x86/resctrl: Update documentation with Sub-NUMA cluster changes
In reply to Tony LuckWith Sub-NUMA Cluster mode enabled the scope of monitoring resources is per-NODE instead of per-L3 cache. Suffixes of directories with "L3" in their name refer to Sub-NUMA nodes instead of L3 cache ids.
Users should be aware that SNC mode also affects the amount of L3 cache available for allocation within each SNC node.
--- Documentation/arch/x86/resctrl.rst | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-)
Documentation/arch/x86/resctrl.rst +20 -3
@@ -366,9 +366,9 @@ When control is enabled all CTRL_MON groups will also contain: When monitoring is enabled all MON groups will also contain: "mon_data": - This contains a set of files organized by L3 domain and by - RDT event. E.g. on a system with two L3 domains there will - be subdirectories "mon_L3_00" and "mon_L3_01". Each of these + This contains a set of files organized by L3 domain or by NUMA + node (depending on whether Sub-NUMA Cluster (SNC) mode is disabled + or enabled respectively) and by RDT event. Each of these directories have one file per event (e.g. "llc_occupancy", "mbm_total_bytes", and "mbm_local_bytes"). In a MON group these files provide a read out of the current value of the event for
@@ -478,6 +478,23 @@ if non-contiguous 1s value is supported. On a system with a 20-bit mask each bit represents 5% of the capacity of the cache. You could partition the cache into four equal parts with masks: 0x1f, 0x3e0, 0x7c00, 0xf8000. +Notes on Sub-NUMA Cluster mode +============================== +When SNC mode is enabled Linux may load balance tasks between Sub-NUMA +nodes much more readily than between regular NUMA nodes since the CPUs +on Sub-NUMA nodes share the same L3 cache and the system may report +the NUMA distance between Sub-NUMA nodes with a lower value than used +for regular NUMA nodes. Users who do not bind tasks to the CPUs of a +specific Sub-NUMA node must read the "llc_occupancy", "mbm_total_bytes", +and "mbm_local_bytes" for all Sub-NUMA nodes where the tasks may execute +to get the full view of traffic for which the tasks were the source. + +The cache allocation feature still provides the same number of +bits in a mask to control allocation into the L3 cache. But each +of those ways has its capacity reduced because the cache is divided +between the SNC nodes. The values reported in the resctrl +"size" files are adjusted accordingly. + Memory bandwidth Allocation and monitoring ==========================================
Signature · 1 line
2.41.0
Randy Dunlap
reviewerRe: [PATCH v11 8/8] x86/resctrl: Update documentation with Sub-NUMA cluster changes
Hi Tony,
If you make any updates to this:
(but not critical)
Quoted 18 lines · Tony Luck
With Sub-NUMA Cluster mode enabled the scope of monitoring resources is per-NODE instead of per-L3 cache. Suffixes of directories with "L3" in their name refer to Sub-NUMA nodes instead of L3 cache ids.
Users should be aware that SNC mode also affects the amount of L3 cache available for allocation within each SNC node.
Reviewed-by Peter Newman <[email protected]>Signed-off-by Tony Luck <[email protected]>--- Documentation/arch/x86/resctrl.rst | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-)Documentation/arch/x86/resctrl.rst +0
-0
Documentation/arch/x86/resctrl.rst When control is enabled all CTRL_MON groups will also contain: · line 372
Quoted 10 lines
Documentation/arch/x86/resctrl.rst +3
-3@@ -366,9 +366,9 @@ When control is enabled all CTRL_MON groups will also contain: When monitoring is enabled all MON groups will also contain: "mon_data": - This contains a set of files organized by L3 domain and by - RDT event. E.g. on a system with two L3 domains there will - be subdirectories "mon_L3_00" and "mon_L3_01". Each of these + This contains a set of files organized by L3 domain or by NUMA + node (depending on whether Sub-NUMA Cluster (SNC) mode is disabled + or enabled respectively) and by RDT event. Each of these directories have one file per event (e.g. "llc_occupancy",
has
Quoted 9 lines
Documentation/arch/x86/resctrl.rst +3
-0"mbm_total_bytes", and "mbm_local_bytes"). In a MON group these files provide a read out of the current value of the event for@@ -478,6 +478,23 @@ if non-contiguous 1s value is supported. On a system with a 20-bit mask each bit represents 5% of the capacity of the cache. You could partition the cache into four equal parts with masks: 0x1f, 0x3e0, 0x7c00, 0xf8000. +Notes on Sub-NUMA Cluster mode +============================== +When SNC mode is enabled Linux may load balance tasks between Sub-NUMA
Documentation/arch/x86/resctrl.rst if non-contiguous 1s value is supported. On a system with a 20-bit mask · line 493
Quoted 10 lines
Documentation/arch/x86/resctrl.rst +10
-0+nodes much more readily than between regular NUMA nodes since the CPUs +on Sub-NUMA nodes share the same L3 cache and the system may report +the NUMA distance between Sub-NUMA nodes with a lower value than used +for regular NUMA nodes. Users who do not bind tasks to the CPUs of a +specific Sub-NUMA node must read the "llc_occupancy", "mbm_total_bytes", +and "mbm_local_bytes" for all Sub-NUMA nodes where the tasks may execute +to get the full view of traffic for which the tasks were the source. + +The cache allocation feature still provides the same number of +bits in a mask to control allocation into the L3 cache. But each
cache, but each
Quoted 7 lines
Documentation/arch/x86/resctrl.rst +4
-0+of those ways has its capacity reduced because the cache is divided +between the SNC nodes. The values reported in the resctrl +"size" files are adjusted accordingly. + Memory bandwidth Allocation and monitoring ==========================================
Signature · 1 line
~Randy
Re: [PATCH v11 8/8] x86/resctrl: Update documentation with Sub-NUMA cluster changes
In reply to Tony LuckHi Tony,
Quoted 10 lines · Tony Luck
With Sub-NUMA Cluster mode enabled the scope of monitoring resources is per-NODE instead of per-L3 cache. Suffixes of directories with "L3" in their name refer to Sub-NUMA nodes instead of L3 cache ids.
Users should be aware that SNC mode also affects the amount of L3 cache available for allocation within each SNC node.
Reviewed-by Peter Newman <[email protected]>Signed-off-by Tony Luck <[email protected]>---
(note about order of commit tags)
Reinette
RE: [PATCH v11 0/8] Add support for Sub-NUMA cluster (SNC) systems
In reply to Tony LuckHello Tony,
I ran resctrl selftest on Intel(R) Xeon(R) Gold 6254 CPU. Everything looks good.
Best regards,
Shaopeng TAN
Luck, Tony
maintainerRE: [PATCH v11 0/8] Add support for Sub-NUMA cluster (SNC) systems
Quoted 5 lines
I ran resctrl selftest on Intel(R) Xeon(R) Gold 6254 CPU. Everything looks good.
Reviewed-by Shaopeng Tan <[email protected]>Tested-by Shaopeng Tan <[email protected]>
Shaopeng TAN,
Thanks for your patience, and for testing this latest version.
-Tony
Tony Luck
maintainerv12 cover Add support for Sub-NUMA cluster (SNC) systems
In reply to Tony LuckThe Sub-NUMA cluster feature on some Intel processors partitions the CPUs that share an L3 cache into two or more sets. This plays havoc with the Resource Director Technology (RDT) monitoring features. Prior to this patch Intel has advised that SNC and RDT are incompatible.
Some of these CPU support an MSR that can partition the RMID counters in the same way. This allows monitoring features to be used. With the caveat that users must be aware that Linux may migrate tasks more frequently between SNC nodes than between "regular" NUMA nodes, so reading counters from all SNC nodes may be needed to get a complete picture of activity for tasks.
Cache and memory bandwidth allocation features continue to operate at the scope of the L3 cache.
Changes since v11:
Global: (comment from Reinette)
Reorder tags with Signed-off-by: first, then Reviewed/Tested
Patch1: (comment from Reinette)
Add error message to domain_remove_cpu() [matching the one in domain_add_cpu()] for the case where get_cpu_cacheinfo_id() failed to find a cache ID for the current CPU.
Patch3: (comment from Reinette)
When splitting the domain_add_cpu() and domain_remove_cpu() functions add "control" and "monitor" to the warning messages. Fix the:
pr_warn("Couldn't find control scope id=%d for CPU %d\n", id, cpu);
message:
s/Couldn't/Can't/
s/control scope/control domain with/
Add resource name.
Ditto for similar monitor message.
Patch6: (comment from Reinette)
Used Reinette's rewrite into imperative mood for latter part of commit message.
Patch8: (comment from Randy)
s/have/has/ s/cache. But/cache, but/
Added Reinette's "Reviewed-by:" to all patches except patch 3.
Added Shaopeng Tan's Reviewed and Tested to all patches.
Rebased to v6.7-rc3
Tony Luck (8):
x86/resctrl: Prepare for new domain scope x86/resctrl: Prepare to split rdt_domain structure x86/resctrl: Prepare for different scope for control/monitor
operations
x86/resctrl: Split the rdt_domain and rdt_hw_domain structures x86/resctrl: Add node-scope to the options for feature scope x86/resctrl: Introduce snc_nodes_per_l3_cache x86/resctrl: Sub NUMA Cluster detection and enable x86/resctrl: Update documentation with Sub-NUMA cluster changes
Documentation/arch/x86/resctrl.rst | 25 +- include/linux/resctrl.h | 85 +++-- arch/x86/include/asm/msr-index.h | 1 + arch/x86/kernel/cpu/resctrl/internal.h | 66 ++-- arch/x86/kernel/cpu/resctrl/core.c | 411 +++++++++++++++++----- arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 58 +-- arch/x86/kernel/cpu/resctrl/monitor.c | 68 ++-- arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 26 +- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 149 ++++---- 9 files changed, 607 insertions(+), 282 deletions(-)
base-commit: 2cc14f52aeb78ce3f29677c2de1f06c0e91471ab
Signature · 1 line
2.41.0
Tony Luck
maintainerPATCH v12 1/8 x86/resctrl: Prepare for new domain scope
Resctrl resources operate on subsets of CPUs in the system with the defining attribute of each subset being an instance of a particular level of cache. E.g. all CPUs sharing an L3 cache would be part of the same domain.
In preparation for features that are scoped at the NUMA node level change the code from explicit references to "cache_level" to a more generic scope. At this point the only options for this scope are groups of CPUs that share an L2 cache or L3 cache.
Clean up the error handling when looking up domains. Report invalid id's before calling rdt_find_domain() in preparation for better messages when scope can be other than cache scope. This means that rdt_find_domain() will never return an error. So remove checks for error from the callsites.
--- include/linux/resctrl.h | 9 ++++- arch/x86/kernel/cpu/resctrl/core.c | 45 ++++++++++++++++------- arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 2 +- arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 6 ++- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 5 ++- 5 files changed, 48 insertions(+), 19 deletions(-)
include/linux/resctrl.h +7 -2
@@ -144,13 +144,18 @@ struct resctrl_membw {struct rdt_parse_data ;struct resctrl_schema ; +enum resctrl_scope { +RESCTRL_L2_CACHE =2 , +RESCTRL_L3_CACHE =3 , +}; +/** * struct rdt_resource - attributes of a resctrl resource * @rid: The index of the resource * @alloc_capable: Is allocation available on this machine * @mon_capable: Is monitor feature available on this machine * @num_rmid: Number of RMIDs available -* @cache_level: Which cache level defines scope of this resource +* @scope: Scope of this resource * @cache: Cache allocation related data * @membw: If the component has bandwidth controls, their properties. * @domains: All domains for this resource
@@ -168,7 +173,7 @@ struct rdt_resource {bool alloc_capable;bool mon_capable;int num_rmid; -int cache_level; +enum resctrl_scope scope;struct resctrl_cache cache;struct resctrl_membw membw;struct list_head domains;
arch/x86/kernel/cpu/resctrl/core.c +31 -14
105 lines not on this page · raw message
arch/x86/kernel/cpu/resctrl/ctrlmondata.c +1 -1
@@ -563,7 +563,7 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg) r = &rdt_resources_all[resid].r_resctrl; d =rdt_find_domain (r, domid,NULL ); -if (IS_ERR_OR_NULL (d)) { +if (!d) { ret = -ENOENT ; goto out; }
arch/x86/kernel/cpu/resctrl/pseudo_lock.c +5 -1
@@ -292,10 +292,14 @@ static void pseudo_lock_region_clear(struct pseudo_lock_region *plr)*/ static int pseudo_lock_region_init (struct pseudo_lock_region *plr) { +enum resctrl_scope scope = plr->s->res->scope;struct cpu_cacheinfo *ci;int ret;int i; +if (WARN_ON_ONCE (scope !=RESCTRL_L2_CACHE && scope !=RESCTRL_L3_CACHE )) +return -ENODEV ; +/* Pick the first cpu we find that is associated with the cache. */ plr->cpu =cpumask_first (&plr->d->cpu_mask);
@@ -311,7 +315,7 @@ static int pseudo_lock_region_init(struct pseudo_lock_region *plr) plr->size =rdtgroup_cbm_to_size (plr->s->res, plr->d, plr->cbm);for (i =0 ; i < ci->num_leaves; i++) { -if (ci->info_list[i].level == plr->s->res->cache_level) { +if (ci->info_list[i].level == scope) { plr->line_size = ci->info_list[i].coherency_line_size;return 0 ; }
arch/x86/kernel/cpu/resctrl/rdtgroup.c +4 -1
@@ -1413,10 +1413,13 @@ unsigned int rdtgroup_cbm_to_size(struct rdt_resource *r,unsigned int size =0 ;int num_b, i; +if (WARN_ON_ONCE (r->scope !=RESCTRL_L2_CACHE && r->scope !=RESCTRL_L3_CACHE )) +return size; + num_b =bitmap_weight (&cbm, r->cache.cbm_len); ci =get_cpu_cacheinfo (cpumask_any (&d->cpu_mask));for (i =0 ; i < ci->num_leaves; i++) { -if (ci->info_list[i].level == r->cache_level) { +if (ci->info_list[i].level == r->scope) { size = ci->info_list[i].size / r->cache.cbm_len * num_b;break ; }
Signature · 1 line
2.41.0
Tony Luck
maintainerPATCH v12 2/8 x86/resctrl: Prepare to split rdt_domain structure
In reply to Tony LuckThe rdt_domain structure is used for both control and monitor features. It is about to be split into separate structures for these two usages because the scope for control and monitoring features for a resource will be different for future resources.
To allow for common code that scans a list of domains looking for a specific domain id, move all the common fields ("list", "id", "cpu_mask") into their own structure within the rdt_domain structure.
--- include/linux/resctrl.h | 16 ++++-- arch/x86/kernel/cpu/resctrl/core.c | 26 +++++----- arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 22 ++++----- arch/x86/kernel/cpu/resctrl/monitor.c | 10 ++-- arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 14 +++--- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 60 +++++++++++------------ 6 files changed, 78 insertions(+), 70 deletions(-)
include/linux/resctrl.h +12 -4
@@ -53,10 +53,20 @@ struct resctrl_staged_config { };/** -* struct rdt_domain - group of CPUs sharing a resctrl resource +* struct rdt_domain_hdr - common header for different domain types * @list: all instances of this resource * @id: unique id for this instance * @cpu_mask: which CPUs share this resource +*/ +struct rdt_domain_hdr { +struct list_head list; +int id; +struct cpumask cpu_mask; +}; + +/** +* struct rdt_domain - group of CPUs sharing a resctrl resource +* @hdr: common header for different domain types * @rmid_busy_llc: bitmap of which limbo RMIDs are above threshold * @mbm_total: saved state for MBM total bandwidth * @mbm_local: saved state for MBM local bandwidth
@@ -71,9 +81,7 @@ struct resctrl_staged_config {* by closid */ struct rdt_domain { -struct list_head list; -int id; -struct cpumask cpu_mask; +struct rdt_domain_hdr hdr;unsigned long *rmid_busy_llc;struct mbm_state *mbm_total;struct mbm_state *mbm_local;
arch/x86/kernel/cpu/resctrl/core.c +13 -13
@@ -356,9 +356,9 @@ struct rdt_domain *get_domain_from_cpu(int cpu, struct rdt_resource *r) {struct rdt_domain *d; -list_for_each_entry (d, &r->domains, list) { +list_for_each_entry (d, &r->domains, hdr.list) {/* Find the domain that contains this CPU */ -if (cpumask_test_cpu (cpu, &d->cpu_mask)) +if (cpumask_test_cpu (cpu, &d->hdr.cpu_mask))return d; }
@@ -402,12 +402,12 @@ struct rdt_domain *rdt_find_domain(struct rdt_resource *r, int id,struct list_head *l;list_for_each (l, &r->domains) { - d = list_entry(l, struct rdt_domain, list); + d = list_entry(l, struct rdt_domain, hdr.list);/* When id is found, return its domain. */ -if (id == d->id) +if (id == d->hdr.id)return d;/* Stop searching when finding id's position in sorted list. */ -if (id < d->id) +if (id < d->hdr.id)break ; }
@@ -530,7 +530,7 @@ static void domain_add_cpu(int cpu, struct rdt_resource *r) d =rdt_find_domain (r, id, &add_pos);if (d) { -cpumask_set_cpu (cpu, &d->cpu_mask); +cpumask_set_cpu (cpu, &d->hdr.cpu_mask);if (r->cache.arch_has_per_cpu_cfg)rdt_domain_reconfigure_cdp (r);return ;
@@ -541,8 +541,8 @@ static void domain_add_cpu(int cpu, struct rdt_resource *r)return ; d = &hw_dom->d_resctrl; - d->id = id; -cpumask_set_cpu (cpu, &d->cpu_mask); + d->hdr.id = id; +cpumask_set_cpu (cpu, &d->hdr.cpu_mask);rdt_domain_reconfigure_cdp (r);
@@ -556,11 +556,11 @@ static void domain_add_cpu(int cpu, struct rdt_resource *r)return ; } -list_add_tail (&d->list, add_pos); +list_add_tail (&d->hdr.list, add_pos); err =resctrl_online_domain (r, d);if (err) { -list_del (&d->list); +list_del (&d->hdr.list);domain_free (hw_dom); } }
@@ -584,10 +584,10 @@ static void domain_remove_cpu(int cpu, struct rdt_resource *r) } hw_dom =resctrl_to_arch_dom (d); -cpumask_clear_cpu (cpu, &d->cpu_mask); -if (cpumask_empty (&d->cpu_mask)) { +cpumask_clear_cpu (cpu, &d->hdr.cpu_mask); +if (cpumask_empty (&d->hdr.cpu_mask)) {resctrl_offline_domain (r, d); -list_del (&d->list); +list_del (&d->hdr.list);/* * rdt_domain "d" is going to be freed below, so clear
arch/x86/kernel/cpu/resctrl/ctrlmondata.c +11 -11
@@ -67,7 +67,7 @@ int parse_bw(struct rdt_parse_data *data, struct resctrl_schema *s, cfg = &d->staged_config[s->conf_type];if (cfg->have_new_ctrl) { -rdt_last_cmd_printf ("Duplicate domain %d\n" , d->id); +rdt_last_cmd_printf ("Duplicate domain %d\n" , d->hdr.id);return -EINVAL ; }
@@ -146,7 +146,7 @@ int parse_cbm(struct rdt_parse_data *data, struct resctrl_schema *s, cfg = &d->staged_config[s->conf_type];if (cfg->have_new_ctrl) { -rdt_last_cmd_printf ("Duplicate domain %d\n" , d->id); +rdt_last_cmd_printf ("Duplicate domain %d\n" , d->hdr.id);return -EINVAL ; }
@@ -226,8 +226,8 @@ static int parse_line(char *line, struct resctrl_schema *s,return -EINVAL ; } dom =strim (dom); -list_for_each_entry (d, &r->domains, list) { -if (d->id == dom_id) { +list_for_each_entry (d, &r->domains, hdr.list) { +if (d->hdr.id == dom_id) { data.buf = dom; data.rdtgrp = rdtgrp;if (r->parse_ctrlval (&data, s, d))
@@ -274,7 +274,7 @@ static bool apply_config(struct rdt_hw_domain *hw_dom,struct rdt_domain *dom = &hw_dom->d_resctrl;if (cfg->new_ctrl != hw_dom->ctrl_val[idx]) { -cpumask_set_cpu (cpumask_any (&dom->cpu_mask), cpu_mask); +cpumask_set_cpu (cpumask_any (&dom->hdr.cpu_mask), cpu_mask); hw_dom->ctrl_val[idx] = cfg->new_ctrl;return true;
@@ -291,7 +291,7 @@ int resctrl_arch_update_one(struct rdt_resource *r, struct rdt_domain *d,u32 idx =get_config_index (closid, t);struct msr_param msr_param; -if (!cpumask_test_cpu (smp_processor_id (), &d->cpu_mask)) +if (!cpumask_test_cpu (smp_processor_id (), &d->hdr.cpu_mask))return -EINVAL ; hw_dom->ctrl_val[idx] = cfg_val;
@@ -318,7 +318,7 @@ int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid)return -ENOMEM ; msr_param.res =NULL ; -list_for_each_entry (d, &r->domains, list) { +list_for_each_entry (d, &r->domains, hdr.list) { hw_dom =resctrl_to_arch_dom (d);for (t =0 ; t <CDP_NUM_TYPES ; t++) { cfg = &hw_dom->d_resctrl.staged_config[t];
@@ -466,7 +466,7 @@ static void show_doms(struct seq_file *s, struct resctrl_schema *schema, int clou32 ctrl_val;seq_printf (s,"%*s:" , max_name_width, schema->name); -list_for_each_entry (dom, &r->domains, list) { +list_for_each_entry (dom, &r->domains, hdr.list) {if (sep)seq_puts (s,";" );
@@ -476,7 +476,7 @@ static void show_doms(struct seq_file *s, struct resctrl_schema *schema, int clo ctrl_val =resctrl_arch_get_config (r, dom, closid, schema->conf_type); -seq_printf (s, r->format_str, dom->id, max_data_width, +seq_printf (s, r->format_str, dom->hdr.id, max_data_width, ctrl_val); sep = true; }
@@ -505,7 +505,7 @@ int rdtgroup_schemata_show(struct kernfs_open_file *of, }else {seq_printf (s,"%s:%d=%x\n" , rdtgrp->plr->s->res->name, - rdtgrp->plr->d->id, + rdtgrp->plr->d->hdr.id, rdtgrp->plr->cbm); } }else {
@@ -536,7 +536,7 @@ void mon_event_read(struct rmid_read *rr, struct rdt_resource *r, rr->val =0 ; rr->first = first; -smp_call_function_any (&d->cpu_mask, mon_event_count, rr,1 ); +smp_call_function_any (&d->hdr.cpu_mask, mon_event_count, rr,1 ); }int rdtgroup_mondata_show (struct seq_file *m,void *arg)
arch/x86/kernel/cpu/resctrl/monitor.c +5 -5
@@ -238,7 +238,7 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain *d,u64 msr_val, chunks;int ret; -if (!cpumask_test_cpu (smp_processor_id (), &d->cpu_mask)) +if (!cpumask_test_cpu (smp_processor_id (), &d->hdr.cpu_mask))return -EINVAL ; ret =__rmid_read (rmid, eventid, &msr_val);
@@ -340,8 +340,8 @@ static void add_rmid_to_limbo(struct rmid_entry *entry) entry->busy =0 ; cpu =get_cpu (); -list_for_each_entry (d, &r->domains, list) { -if (cpumask_test_cpu (cpu, &d->cpu_mask)) { +list_for_each_entry (d, &r->domains, hdr.list) { +if (cpumask_test_cpu (cpu, &d->hdr.cpu_mask)) { err =resctrl_arch_rmid_read (r, d, entry->rmid,QOS_L3_OCCUP_EVENT_ID , &val);
@@ -661,7 +661,7 @@ void cqm_setup_limbo_handler(struct rdt_domain *dom, unsigned long delay_ms)unsigned long delay =msecs_to_jiffies (delay_ms);int cpu; - cpu =cpumask_any (&dom->cpu_mask); + cpu =cpumask_any (&dom->hdr.cpu_mask); dom->cqm_work_cpu = cpu;schedule_delayed_work_on (cpu, &dom->cqm_limbo, delay);
@@ -708,7 +708,7 @@ void mbm_setup_overflow_handler(struct rdt_domain *dom, unsigned long delay_ms)if (!static_branch_likely (&rdt_mon_enable_key))return ; - cpu =cpumask_any (&dom->cpu_mask); + cpu =cpumask_any (&dom->hdr.cpu_mask); dom->mbm_work_cpu = cpu;schedule_delayed_work_on (cpu, &dom->mbm_over, delay); }
arch/x86/kernel/cpu/resctrl/pseudo_lock.c +7 -7
@@ -221,7 +221,7 @@ static int pseudo_lock_cstates_constrain(struct pseudo_lock_region *plr)int cpu;int ret; -for_each_cpu (cpu, &plr->d->cpu_mask) { +for_each_cpu (cpu, &plr->d->hdr.cpu_mask) { pm_req =kzalloc (sizeof (*pm_req),GFP_KERNEL );if (!pm_req) {rdt_last_cmd_puts ("Failure to allocate memory for PM QoS\n" );
@@ -301,7 +301,7 @@ static int pseudo_lock_region_init(struct pseudo_lock_region *plr)return -ENODEV ;/* Pick the first cpu we find that is associated with the cache. */ - plr->cpu =cpumask_first (&plr->d->cpu_mask); + plr->cpu =cpumask_first (&plr->d->hdr.cpu_mask);if (!cpu_online (plr->cpu)) { rdt_last_cmd_printf("CPU %u associated with cache not online\n",
@@ -856,10 +856,10 @@ bool rdtgroup_pseudo_locked_in_hierarchy(struct rdt_domain *d)* associated with them. */ for_each_alloc_capable_rdt_resource (r) { -list_for_each_entry (d_i, &r->domains, list) { +list_for_each_entry (d_i, &r->domains, hdr.list) {if (d_i->plr)cpumask_or (cpu_with_psl, cpu_with_psl, - &d_i->cpu_mask); + &d_i->hdr.cpu_mask); } }
@@ -867,7 +867,7 @@ bool rdtgroup_pseudo_locked_in_hierarchy(struct rdt_domain *d)* Next test if new pseudo-locked region would intersect with * existing region. */ -if (cpumask_intersects (&d->cpu_mask, cpu_with_psl)) +if (cpumask_intersects (&d->hdr.cpu_mask, cpu_with_psl)) ret = true;free_cpumask_var (cpu_with_psl);
@@ -1199,7 +1199,7 @@ static int pseudo_lock_measure_cycles(struct rdtgroup *rdtgrp, int sel) } plr->thread_done =0 ; - cpu =cpumask_first (&plr->d->cpu_mask); + cpu =cpumask_first (&plr->d->hdr.cpu_mask);if (!cpu_online (cpu)) { ret = -ENODEV ; goto out;
@@ -1529,7 +1529,7 @@ static int pseudo_lock_dev_mmap(struct file *filp, struct vm_area_struct *vma)* may be scheduled elsewhere and invalidate entries in the * pseudo-locked region. */ -if (!cpumask_subset (current->cpus_ptr, &plr->d->cpu_mask)) { +if (!cpumask_subset (current->cpus_ptr, &plr->d->hdr.cpu_mask)) {mutex_unlock (&rdtgroup_mutex);return -EINVAL ; }
arch/x86/kernel/cpu/resctrl/rdtgroup.c +30 -30
220 lines not on this page · raw message
Signature · 1 line
2.41.0
Tony Luck
maintainerPATCH v12 3/8 x86/resctrl: Prepare for different scope for control/monitor operations
In reply to Tony LuckResctrl assumes that control and monitor operations on a resource are performed at the same scope.
Prepare for systems that use different scope (specifically Intel needs to split the RDT_RESOURCE_L3 resource to use L3 scope for cache control and NODE scope for cache occupancy and memory bandwidth monitoring).
Create separate domain lists for control and monitor operations.
Note that errors during initialization of either control or monitor functions on a domain would previously result in that domain being excluded from both control and monitor operations. Now the domains are allocated independently it is no longer required to disable both control and monitor operations if either fail.
--- include/linux/resctrl.h | 25 ++- arch/x86/kernel/cpu/resctrl/internal.h | 6 +- arch/x86/kernel/cpu/resctrl/core.c | 211 ++++++++++++++++------ arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 12 +- arch/x86/kernel/cpu/resctrl/monitor.c | 4 +- arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 4 +- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 55 +++--- 7 files changed, 220 insertions(+), 97 deletions(-)
include/linux/resctrl.h +19 -6
@@ -52,15 +52,22 @@ struct resctrl_staged_config {bool have_new_ctrl; }; +enum resctrl_domain_type { +RESCTRL_CTRL_DOMAIN , +RESCTRL_MON_DOMAIN , +}; +/** * struct rdt_domain_hdr - common header for different domain types * @list: all instances of this resource * @id: unique id for this instance +* @type: type of this instance * @cpu_mask: which CPUs share this resource */ struct rdt_domain_hdr {struct list_head list;int id; +enum resctrl_domain_type type;struct cpumask cpu_mask; };
@@ -163,10 +170,12 @@ enum resctrl_scope {* @alloc_capable: Is allocation available on this machine * @mon_capable: Is monitor feature available on this machine * @num_rmid: Number of RMIDs available -* @scope: Scope of this resource +* @ctrl_scope: Scope of this resource for control functions +* @mon_scope: Scope of this resource for monitor functions * @cache: Cache allocation related data * @membw: If the component has bandwidth controls, their properties. -* @domains: All domains for this resource +* @ctrl_domains: Control domains for this resource +* @mon_domains: Monitor domains for this resource * @name: Name to use in "schemata" file. * @data_width: Character width of data when displaying * @default_ctrl: Specifies default cache cbm or memory B/W percent.
@@ -181,10 +190,12 @@ struct rdt_resource {bool alloc_capable;bool mon_capable;int num_rmid; -enum resctrl_scope scope; +enum resctrl_scope ctrl_scope; +enum resctrl_scope mon_scope;struct resctrl_cache cache;struct resctrl_membw membw; -struct list_head domains; +struct list_head ctrl_domains; +struct list_head mon_domains;char *name;int data_width;u32 default_ctrl;
@@ -230,8 +241,10 @@ int resctrl_arch_update_one(struct rdt_resource *r, struct rdt_domain *d,u32 resctrl_arch_get_config (struct rdt_resource *r,struct rdt_domain *d,u32 closid,enum resctrl_conf_type type); -int resctrl_online_domain (struct rdt_resource *r,struct rdt_domain *d); -void resctrl_offline_domain (struct rdt_resource *r,struct rdt_domain *d); +int resctrl_online_ctrl_domain (struct rdt_resource *r,struct rdt_domain *d); +int resctrl_online_mon_domain (struct rdt_resource *r,struct rdt_domain *d); +void resctrl_offline_ctrl_domain (struct rdt_resource *r,struct rdt_domain *d); +void resctrl_offline_mon_domain (struct rdt_resource *r,struct rdt_domain *d);/** * resctrl_arch_rmid_read() - Read the eventid counter corresponding to rmid
arch/x86/kernel/cpu/resctrl/internal.h +3 -3
@@ -520,8 +520,8 @@ 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 *rdt_find_domain (struct rdt_resource *r,int id, -struct list_head **pos); +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,
@@ -540,7 +540,7 @@ int rdt_pseudo_lock_init(void);void rdt_pseudo_lock_release (void );int rdtgroup_pseudo_lock_create (struct rdtgroup *rdtgrp);void rdtgroup_pseudo_lock_remove (struct rdtgroup *rdtgrp); -struct rdt_domain *get_domain_from_cpu (int cpu,struct rdt_resource *r); +struct rdt_domain *get_ctrl_domain_from_cpu (int cpu,struct rdt_resource *r);int closids_supported (void );void closid_free (int closid);int alloc_rmid (void );
arch/x86/kernel/cpu/resctrl/core.c +157 -54
338 lines not on this page · raw message
arch/x86/kernel/cpu/resctrl/ctrlmondata.c +7 -5
@@ -226,7 +226,7 @@ static int parse_line(char *line, struct resctrl_schema *s,return -EINVAL ; } dom =strim (dom); -list_for_each_entry (d, &r->domains, hdr.list) { +list_for_each_entry (d, &r->ctrl_domains, hdr.list) {if (d->hdr.id == dom_id) { data.buf = dom; data.rdtgrp = rdtgrp;
@@ -318,7 +318,7 @@ int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid)return -ENOMEM ; msr_param.res =NULL ; -list_for_each_entry (d, &r->domains, hdr.list) { +list_for_each_entry (d, &r->ctrl_domains, hdr.list) { hw_dom =resctrl_to_arch_dom (d);for (t =0 ; t <CDP_NUM_TYPES ; t++) { cfg = &hw_dom->d_resctrl.staged_config[t];
@@ -466,7 +466,7 @@ static void show_doms(struct seq_file *s, struct resctrl_schema *schema, int clou32 ctrl_val;seq_printf (s,"%*s:" , max_name_width, schema->name); -list_for_each_entry (dom, &r->domains, hdr.list) { +list_for_each_entry (dom, &r->ctrl_domains, hdr.list) {if (sep)seq_puts (s,";" );
@@ -542,6 +542,7 @@ void mon_event_read(struct rmid_read *rr, struct rdt_resource *r,int rdtgroup_mondata_show (struct seq_file *m,void *arg) {struct kernfs_open_file *of = m->private; +struct rdt_domain_hdr *hdr;u32 resid, evtid, domid;struct rdtgroup *rdtgrp;struct rdt_resource *r;
@@ -562,11 +563,12 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg) evtid = md.u.evtid; r = &rdt_resources_all[resid].r_resctrl; - d =rdt_find_domain (r, domid,NULL ); -if (!d) { + hdr =rdt_find_domain (&r->mon_domains, domid,NULL ); +if (!hdr ||WARN_ON_ONCE (hdr->type !=RESCTRL_MON_DOMAIN )) { ret = -ENOENT ; goto out; } + d = container_of(hdr, struct rdt_domain, hdr);mon_event_read (&rr, r, d, rdtgrp, evtid, false);
arch/x86/kernel/cpu/resctrl/monitor.c +2 -2
@@ -340,7 +340,7 @@ static void add_rmid_to_limbo(struct rmid_entry *entry) entry->busy =0 ; cpu =get_cpu (); -list_for_each_entry (d, &r->domains, hdr.list) { +list_for_each_entry (d, &r->mon_domains, hdr.list) {if (cpumask_test_cpu (cpu, &d->hdr.cpu_mask)) { err = resctrl_arch_rmid_read(r, d, entry->rmid, QOS_L3_OCCUP_EVENT_ID,
@@ -535,7 +535,7 @@ static void update_mba_bw(struct rdtgroup *rgrp, struct rdt_domain *dom_mbm) rmid = rgrp->mon.rmid; pmbm_data = &dom_mbm->mbm_local[rmid]; - dom_mba =get_domain_from_cpu (smp_processor_id (), r_mba); + dom_mba =get_ctrl_domain_from_cpu (smp_processor_id (), r_mba);if (!dom_mba) {pr_warn_once ("Failure to get domain for MBA update\n" );return ;
arch/x86/kernel/cpu/resctrl/pseudo_lock.c +2 -2
@@ -292,7 +292,7 @@ static void pseudo_lock_region_clear(struct pseudo_lock_region *plr)*/ static int pseudo_lock_region_init (struct pseudo_lock_region *plr) { -enum resctrl_scope scope = plr->s->res->scope; +enum resctrl_scope scope = plr->s->res->ctrl_scope;struct cpu_cacheinfo *ci;int ret;int i;
@@ -856,7 +856,7 @@ bool rdtgroup_pseudo_locked_in_hierarchy(struct rdt_domain *d)* associated with them. */ for_each_alloc_capable_rdt_resource (r) { -list_for_each_entry (d_i, &r->domains, hdr.list) { +list_for_each_entry (d_i, &r->ctrl_domains, hdr.list) {if (d_i->plr)cpumask_or (cpu_with_psl, cpu_with_psl, &d_i->hdr.cpu_mask);
arch/x86/kernel/cpu/resctrl/rdtgroup.c +30 -25
170 lines not on this page · raw message
Signature · 1 line
2.41.0
Re: [PATCH v12 3/8] x86/resctrl: Prepare for different scope for control/monitor operations
Hi Tony,
Quoted 15 lines · Tony Luck
Resctrl assumes that control and monitor operations on a resource are performed at the same scope.
Prepare for systems that use different scope (specifically Intel needs to split the
RDT_RESOURCE_L3resource to use L3 scope for cache control and NODE scope for cache occupancy and memory bandwidth monitoring).Create separate domain lists for control and monitor operations.
Note that errors during initialization of either control or monitor functions on a domain would previously result in that domain being excluded from both control and monitor operations. Now the domains are allocated independently it is no longer required to disable both control and monitor operations if either fail.
Quoted 4 lines
Signed-off-by Tony Luck <[email protected]>Reviewed-by Shaopeng Tan <[email protected]>Tested-by Shaopeng Tan <[email protected]>---
According to Documentation/process/maintainer-tip.rst the "Tested-by" tag should go before the "Reviewed-by" tag. Please check the whole series.
Reinette
Tony Luck
maintainerPATCH v12 4/8 x86/resctrl: Split the rdt_domain and rdt_hw_domain structures
In reply to Tony LuckThe same rdt_domain structure is used for both control and monitor functions. But this results in wasted memory as some of the fields are only used by control functions, while most are only used for monitor functions.
Split into separate rdt_ctrl_domain and rdt_mon_domain structures with just the fields required for control and monitoring respectively.
Similar split of the rdt_hw_domain structure into rdt_hw_ctrl_domain and rdt_hw_mon_domain.
--- include/linux/resctrl.h | 48 +++++++------ arch/x86/kernel/cpu/resctrl/internal.h | 60 ++++++++++------ arch/x86/kernel/cpu/resctrl/core.c | 87 ++++++++++++----------- arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 32 ++++----- arch/x86/kernel/cpu/resctrl/monitor.c | 40 +++++------ arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 6 +- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 62 ++++++++-------- 7 files changed, 182 insertions(+), 153 deletions(-)
include/linux/resctrl.h +28 -20
@@ -72,7 +72,23 @@ struct rdt_domain_hdr { };/** -* struct rdt_domain - group of CPUs sharing a resctrl resource +* struct rdt_ctrl_domain - group of CPUs sharing a resctrl control resource +* @hdr: common header for different domain types +* @plr: pseudo-locked region (if any) associated with domain +* @staged_config: parsed configuration to be applied +* @mbps_val: When mba_sc is enabled, this holds the array of user +* specified control values for mba_sc in MBps, indexed +* by closid +*/ +struct rdt_ctrl_domain { +struct rdt_domain_hdr hdr; +struct pseudo_lock_region *plr; +struct resctrl_staged_config staged_config[CDP_NUM_TYPES ]; +u32 *mbps_val; +}; + +/** +* struct rdt_mon_domain - group of CPUs sharing a resctrl monitor resource * @hdr: common header for different domain types * @rmid_busy_llc: bitmap of which limbo RMIDs are above threshold * @mbm_total: saved state for MBM total bandwidth
@@ -81,13 +97,8 @@ struct rdt_domain_hdr {* @cqm_limbo: worker to periodically read CQM h/w counters * @mbm_work_cpu: worker CPU for MBM h/w counters * @cqm_work_cpu: worker CPU for CQM h/w counters -* @plr: pseudo-locked region (if any) associated with domain -* @staged_config: parsed configuration to be applied -* @mbps_val: When mba_sc is enabled, this holds the array of user -* specified control values for mba_sc in MBps, indexed -* by closid */ -struct rdt_domain { +struct rdt_mon_domain {struct rdt_domain_hdr hdr;unsigned long *rmid_busy_llc;struct mbm_state *mbm_total;
@@ -96,9 +107,6 @@ struct rdt_domain {struct delayed_work cqm_limbo;int mbm_work_cpu;int cqm_work_cpu; -struct pseudo_lock_region *plr; -struct resctrl_staged_config staged_config[CDP_NUM_TYPES ]; -u32 *mbps_val; };/**
@@ -202,7 +210,7 @@ struct rdt_resource {const char *format_str;int (*parse_ctrlval)(struct rdt_parse_data *data,struct resctrl_schema *s, -struct rdt_domain *d); +struct rdt_ctrl_domain *d);struct list_head evt_list;unsigned long fflags;bool cdp_capable;
@@ -236,15 +244,15 @@ int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid);* Update the ctrl_val and apply this config right now. * Must be called on one of the domain's CPUs. */ -int resctrl_arch_update_one (struct rdt_resource *r,struct rdt_domain *d, +int resctrl_arch_update_one (struct rdt_resource *r,struct rdt_ctrl_domain *d,u32 closid,enum resctrl_conf_type t,u32 cfg_val); -u32 resctrl_arch_get_config (struct rdt_resource *r,struct rdt_domain *d, +u32 resctrl_arch_get_config (struct rdt_resource *r,struct rdt_ctrl_domain *d,u32 closid,enum resctrl_conf_type type); -int resctrl_online_ctrl_domain (struct rdt_resource *r,struct rdt_domain *d); -int resctrl_online_mon_domain (struct rdt_resource *r,struct rdt_domain *d); -void resctrl_offline_ctrl_domain (struct rdt_resource *r,struct rdt_domain *d); -void resctrl_offline_mon_domain (struct rdt_resource *r,struct rdt_domain *d); +int resctrl_online_ctrl_domain (struct rdt_resource *r,struct rdt_ctrl_domain *d); +int resctrl_online_mon_domain (struct rdt_resource *r,struct rdt_mon_domain *d); +void resctrl_offline_ctrl_domain (struct rdt_resource *r,struct rdt_ctrl_domain *d); +void resctrl_offline_mon_domain (struct rdt_resource *r,struct rdt_mon_domain *d);/** * resctrl_arch_rmid_read() - Read the eventid counter corresponding to rmid
@@ -260,7 +268,7 @@ void resctrl_offline_mon_domain(struct rdt_resource *r, struct rdt_domain *d);* Return: * 0 on success, or -EIO, -EINVAL etc on error. */ -int resctrl_arch_rmid_read (struct rdt_resource *r,struct rdt_domain *d, +int resctrl_arch_rmid_read (struct rdt_resource *r,struct rdt_mon_domain *d,u32 rmid,enum resctrl_event_id eventid,u64 *val);/**
@@ -273,7 +281,7 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain *d,* * This can be called from any CPU. */ -void resctrl_arch_reset_rmid (struct rdt_resource *r,struct rdt_domain *d, +void resctrl_arch_reset_rmid (struct rdt_resource *r,struct rdt_mon_domain *d,u32 rmid,enum resctrl_event_id eventid);/**
@@ -285,7 +293,7 @@ void resctrl_arch_reset_rmid(struct rdt_resource *r, struct rdt_domain *d,* * This can be called from any CPU. */ -void resctrl_arch_reset_rmid_all (struct rdt_resource *r,struct rdt_domain *d); +void resctrl_arch_reset_rmid_all (struct rdt_resource *r,struct rdt_mon_domain *d);extern unsigned int resctrl_rmid_realloc_threshold;extern unsigned int resctrl_rmid_realloc_limit;
arch/x86/kernel/cpu/resctrl/internal.h +38 -22
131 lines not on this page · raw message
arch/x86/kernel/cpu/resctrl/core.c +46 -41
246 lines not on this page · raw message
arch/x86/kernel/cpu/resctrl/ctrlmondata.c +16 -16
@@ -58,7 +58,7 @@ static bool bw_validate(char *buf, unsigned long *data, struct rdt_resource *r) }int parse_bw (struct rdt_parse_data *data,struct resctrl_schema *s, -struct rdt_domain *d) +struct rdt_ctrl_domain *d) {struct resctrl_staged_config *cfg;u32 closid = data->rdtgrp->closid;
@@ -137,7 +137,7 @@ static bool cbm_validate(char *buf, u32 *data, struct rdt_resource *r)* resource type. */ int parse_cbm (struct rdt_parse_data *data,struct resctrl_schema *s, -struct rdt_domain *d) +struct rdt_ctrl_domain *d) {struct rdtgroup *rdtgrp = data->rdtgrp;struct resctrl_staged_config *cfg;
@@ -206,8 +206,8 @@ static int parse_line(char *line, struct resctrl_schema *s,struct resctrl_staged_config *cfg;struct rdt_resource *r = s->res;struct rdt_parse_data data; +struct rdt_ctrl_domain *d;char *dom =NULL , *id; -struct rdt_domain *d;unsigned long dom_id; if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP &&
@@ -267,11 +267,11 @@ static u32 get_config_index(u32 closid, enum resctrl_conf_type type) } } -static bool apply_config (struct rdt_hw_domain *hw_dom, +static bool apply_config (struct rdt_hw_ctrl_domain *hw_dom,struct resctrl_staged_config *cfg,u32 idx,cpumask_var_t cpu_mask) { -struct rdt_domain *dom = &hw_dom->d_resctrl; +struct rdt_ctrl_domain *dom = &hw_dom->d_resctrl;if (cfg->new_ctrl != hw_dom->ctrl_val[idx]) {cpumask_set_cpu (cpumask_any (&dom->hdr.cpu_mask), cpu_mask);
@@ -283,11 +283,11 @@ static bool apply_config(struct rdt_hw_domain *hw_dom,return false; } -int resctrl_arch_update_one (struct rdt_resource *r,struct rdt_domain *d, +int resctrl_arch_update_one (struct rdt_resource *r,struct rdt_ctrl_domain *d,u32 closid,enum resctrl_conf_type t,u32 cfg_val) { +struct rdt_hw_ctrl_domain *hw_dom =resctrl_to_arch_ctrl_dom (d);struct rdt_hw_resource *hw_res =resctrl_to_arch_res (r); -struct rdt_hw_domain *hw_dom =resctrl_to_arch_dom (d);u32 idx =get_config_index (closid, t);struct msr_param msr_param;
@@ -307,11 +307,11 @@ int resctrl_arch_update_one(struct rdt_resource *r, struct rdt_domain *d,int resctrl_arch_update_domains (struct rdt_resource *r,u32 closid) {struct resctrl_staged_config *cfg; -struct rdt_hw_domain *hw_dom; +struct rdt_hw_ctrl_domain *hw_dom;struct msr_param msr_param; +struct rdt_ctrl_domain *d;enum resctrl_conf_type t;cpumask_var_t cpu_mask; -struct rdt_domain *d;u32 idx;if (!zalloc_cpumask_var (&cpu_mask,GFP_KERNEL ))
@@ -319,7 +319,7 @@ int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid) msr_param.res =NULL ;list_for_each_entry (d, &r->ctrl_domains, hdr.list) { - hw_dom =resctrl_to_arch_dom (d); + hw_dom =resctrl_to_arch_ctrl_dom (d);for (t =0 ; t <CDP_NUM_TYPES ; t++) { cfg = &hw_dom->d_resctrl.staged_config[t];if (!cfg->have_new_ctrl)
@@ -449,10 +449,10 @@ ssize_t rdtgroup_schemata_write(struct kernfs_open_file *of,return ret ?: nbytes; } -u32 resctrl_arch_get_config (struct rdt_resource *r,struct rdt_domain *d, +u32 resctrl_arch_get_config (struct rdt_resource *r,struct rdt_ctrl_domain *d,u32 closid,enum resctrl_conf_type type) { -struct rdt_hw_domain *hw_dom =resctrl_to_arch_dom (d); +struct rdt_hw_ctrl_domain *hw_dom =resctrl_to_arch_ctrl_dom (d);u32 idx =get_config_index (closid, type);return hw_dom->ctrl_val[idx];
@@ -461,7 +461,7 @@ u32 resctrl_arch_get_config(struct rdt_resource *r, struct rdt_domain *d,static void show_doms (struct seq_file *s,struct resctrl_schema *schema,int closid) {struct rdt_resource *r = schema->res; -struct rdt_domain *dom; +struct rdt_ctrl_domain *dom;bool sep = false;u32 ctrl_val;
@@ -523,7 +523,7 @@ int rdtgroup_schemata_show(struct kernfs_open_file *of, }void mon_event_read (struct rmid_read *rr,struct rdt_resource *r, -struct rdt_domain *d,struct rdtgroup *rdtgrp, +struct rdt_mon_domain *d,struct rdtgroup *rdtgrp,int evtid,int first) {/*
@@ -543,11 +543,11 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg) {struct kernfs_open_file *of = m->private;struct rdt_domain_hdr *hdr; +struct rdt_mon_domain *d;u32 resid, evtid, domid;struct rdtgroup *rdtgrp;struct rdt_resource *r;union mon_data_bits md; -struct rdt_domain *d;struct rmid_read rr;int ret =0 ;
@@ -568,7 +568,7 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg) ret = -ENOENT ; goto out; } - d = container_of(hdr, struct rdt_domain, hdr); + d = container_of(hdr, struct rdt_mon_domain, hdr);mon_event_read (&rr, r, d, rdtgrp, evtid, false);
arch/x86/kernel/cpu/resctrl/monitor.c +20 -20
@@ -170,7 +170,7 @@ static int __rmid_read(u32 rmid, enum resctrl_event_id eventid, u64 *val)return 0 ; } -static struct arch_mbm_state *get_arch_mbm_state (struct rdt_hw_domain *hw_dom, +static struct arch_mbm_state *get_arch_mbm_state (struct rdt_hw_mon_domain *hw_dom,u32 rmid,enum resctrl_event_id eventid) {
@@ -189,10 +189,10 @@ static struct arch_mbm_state *get_arch_mbm_state(struct rdt_hw_domain *hw_dom,return NULL ; } -void resctrl_arch_reset_rmid (struct rdt_resource *r,struct rdt_domain *d, +void resctrl_arch_reset_rmid (struct rdt_resource *r,struct rdt_mon_domain *d,u32 rmid,enum resctrl_event_id eventid) { -struct rdt_hw_domain *hw_dom =resctrl_to_arch_dom (d); +struct rdt_hw_mon_domain *hw_dom =resctrl_to_arch_mon_dom (d);struct arch_mbm_state *am; am =get_arch_mbm_state (hw_dom, rmid, eventid);
@@ -208,9 +208,9 @@ void resctrl_arch_reset_rmid(struct rdt_resource *r, struct rdt_domain *d,* Assumes that hardware counters are also reset and thus that there is * no need to record initial non-zero counts. */ -void resctrl_arch_reset_rmid_all (struct rdt_resource *r,struct rdt_domain *d) +void resctrl_arch_reset_rmid_all (struct rdt_resource *r,struct rdt_mon_domain *d) { -struct rdt_hw_domain *hw_dom =resctrl_to_arch_dom (d); +struct rdt_hw_mon_domain *hw_dom =resctrl_to_arch_mon_dom (d);if (is_mbm_total_enabled ()) memset(hw_dom->arch_mbm_total, 0,
@@ -229,11 +229,11 @@ static u64 mbm_overflow_count(u64 prev_msr, u64 cur_msr, unsigned int width)return chunks >> shift; } -int resctrl_arch_rmid_read (struct rdt_resource *r,struct rdt_domain *d, +int resctrl_arch_rmid_read (struct rdt_resource *r,struct rdt_mon_domain *d,u32 rmid,enum resctrl_event_id eventid,u64 *val) { +struct rdt_hw_mon_domain *hw_dom =resctrl_to_arch_mon_dom (d);struct rdt_hw_resource *hw_res =resctrl_to_arch_res (r); -struct rdt_hw_domain *hw_dom =resctrl_to_arch_dom (d);struct arch_mbm_state *am;u64 msr_val, chunks;int ret;
@@ -266,7 +266,7 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain *d,* decrement the count. If the busy count gets to zero on an RMID, we * free the RMID */ -void __check_limbo (struct rdt_domain *d,bool force_free) +void __check_limbo (struct rdt_mon_domain *d,bool force_free) {struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl;struct rmid_entry *entry;
@@ -305,7 +305,7 @@ void __check_limbo(struct rdt_domain *d, bool force_free) } } -bool has_busy_rmid (struct rdt_resource *r,struct rdt_domain *d) +bool has_busy_rmid (struct rdt_resource *r,struct rdt_mon_domain *d) {return find_first_bit (d->rmid_busy_llc, r->num_rmid) != r->num_rmid; }
@@ -334,7 +334,7 @@ int alloc_rmid(void)static void add_rmid_to_limbo (struct rmid_entry *entry) {struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl; -struct rdt_domain *d; +struct rdt_mon_domain *d;int cpu, err;u64 val =0 ;
@@ -383,7 +383,7 @@ void free_rmid(u32 rmid)list_add_tail (&entry->list, &rmid_free_lru); } -static struct mbm_state *get_mbm_state (struct rdt_domain *d,u32 rmid, +static struct mbm_state *get_mbm_state (struct rdt_mon_domain *d,u32 rmid,enum resctrl_event_id evtid) {switch (evtid) {
@@ -516,13 +516,13 @@ void mon_event_count(void *info)* throttle MSRs already have low percentage values. To avoid * unnecessarily restricting such rdtgroups, we also increase the bandwidth. */ -static void update_mba_bw (struct rdtgroup *rgrp,struct rdt_domain *dom_mbm) +static void update_mba_bw (struct rdtgroup *rgrp,struct rdt_mon_domain *dom_mbm) {u32 closid, rmid, cur_msr_val, new_msr_val;struct mbm_state *pmbm_data, *cmbm_data; +struct rdt_ctrl_domain *dom_mba;u32 cur_bw, delta_bw, user_bw;struct rdt_resource *r_mba; -struct rdt_domain *dom_mba;struct list_head *head;struct rdtgroup *entry;
@@ -600,7 +600,7 @@ static void update_mba_bw(struct rdtgroup *rgrp, struct rdt_domain *dom_mbm) } } -static void mbm_update (struct rdt_resource *r,struct rdt_domain *d,int rmid) +static void mbm_update (struct rdt_resource *r,struct rdt_mon_domain *d,int rmid) {struct rmid_read rr;
@@ -640,13 +640,13 @@ void cqm_handle_limbo(struct work_struct *work) {unsigned long delay =msecs_to_jiffies (CQM_LIMBOCHECK_INTERVAL );int cpu =smp_processor_id (); +struct rdt_mon_domain *d;struct rdt_resource *r; -struct rdt_domain *d;mutex_lock (&rdtgroup_mutex); r = &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl; - d = container_of(work, struct rdt_domain, cqm_limbo.work); + d = container_of(work, struct rdt_mon_domain, cqm_limbo.work);__check_limbo (d, false);
@@ -656,7 +656,7 @@ void cqm_handle_limbo(struct work_struct *work)mutex_unlock (&rdtgroup_mutex); } -void cqm_setup_limbo_handler (struct rdt_domain *dom,unsigned long delay_ms) +void cqm_setup_limbo_handler (struct rdt_mon_domain *dom,unsigned long delay_ms) {unsigned long delay =msecs_to_jiffies (delay_ms);int cpu;
@@ -672,9 +672,9 @@ void mbm_handle_overflow(struct work_struct *work)unsigned long delay =msecs_to_jiffies (MBM_OVERFLOW_INTERVAL );struct rdtgroup *prgrp, *crgrp;int cpu =smp_processor_id (); +struct rdt_mon_domain *d;struct list_head *head;struct rdt_resource *r; -struct rdt_domain *d;mutex_lock (&rdtgroup_mutex);
@@ -682,7 +682,7 @@ void mbm_handle_overflow(struct work_struct *work) goto out_unlock; r = &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl; - d = container_of(work, struct rdt_domain, mbm_over.work); + d = container_of(work, struct rdt_mon_domain, mbm_over.work);list_for_each_entry (prgrp, &rdt_all_groups, rdtgroup_list) {mbm_update (r, d, prgrp->mon.rmid);
@@ -701,7 +701,7 @@ void mbm_handle_overflow(struct work_struct *work)mutex_unlock (&rdtgroup_mutex); } -void mbm_setup_overflow_handler (struct rdt_domain *dom,unsigned long delay_ms) +void mbm_setup_overflow_handler (struct rdt_mon_domain *dom,unsigned long delay_ms) {unsigned long delay =msecs_to_jiffies (delay_ms);int cpu;
arch/x86/kernel/cpu/resctrl/pseudo_lock.c +3 -3
@@ -814,7 +814,7 @@ int rdtgroup_locksetup_exit(struct rdtgroup *rdtgrp)* Return: true if @cbm overlaps with pseudo-locked region on @d, false * otherwise. */ -bool rdtgroup_cbm_overlaps_pseudo_locked (struct rdt_domain *d,unsigned long cbm) +bool rdtgroup_cbm_overlaps_pseudo_locked (struct rdt_ctrl_domain *d,unsigned long cbm) {unsigned int cbm_len;unsigned long cbm_b;
@@ -841,11 +841,11 @@ bool rdtgroup_cbm_overlaps_pseudo_locked(struct rdt_domain *d, unsigned long cbm* if it is not possible to test due to memory allocation issue, * false otherwise. */ -bool rdtgroup_pseudo_locked_in_hierarchy (struct rdt_domain *d) +bool rdtgroup_pseudo_locked_in_hierarchy (struct rdt_ctrl_domain *d) { +struct rdt_ctrl_domain *d_i;cpumask_var_t cpu_with_psl;struct rdt_resource *r; -struct rdt_domain *d_i;bool ret = false;if (!zalloc_cpumask_var (&cpu_with_psl,GFP_KERNEL ))
arch/x86/kernel/cpu/resctrl/rdtgroup.c +31 -31
252 lines not on this page · raw message
Signature · 1 line
2.41.0
Tony Luck
maintainerPATCH v12 5/8 x86/resctrl: Add node-scope to the options for feature scope
In reply to Tony LuckCurrently supported resctrl features are all domain scoped the same as the scope of the L2 or L3 caches.
Add RESCTRL_NODE as a new option for features that are scoped at the same granularity as NUMA nodes. This is needed for Intel's Sub-NUMA Cluster (SNC) feature where monitoring features are node scoped.
--- include/linux/resctrl.h | 1 + arch/x86/kernel/cpu/resctrl/core.c | 2 ++ 2 files changed, 3 insertions(+)
include/linux/resctrl.h +1 -0
@@ -170,6 +170,7 @@ struct resctrl_schema;enum resctrl_scope {RESCTRL_L2_CACHE =2 ,RESCTRL_L3_CACHE =3 , +RESCTRL_NODE , };/**
arch/x86/kernel/cpu/resctrl/core.c +2 -0
@@ -502,6 +502,8 @@ static int get_domain_id_from_scope(int cpu, enum resctrl_scope scope)case RESCTRL_L2_CACHE :case RESCTRL_L3_CACHE :return get_cpu_cacheinfo_id (cpu, scope); +case RESCTRL_NODE : +return cpu_to_node (cpu);default :break ; }
Signature · 1 line
2.41.0
Tony Luck
maintainerPATCH v12 6/8 x86/resctrl: Introduce snc_nodes_per_l3_cache
In reply to Tony LuckIntel Sub-NUMA Cluster (SNC) is a feature that subdivides the CPU cores and memory controllers on a socket into two or more groups. These are presented to the operating system as NUMA nodes.
This may enable some workloads to have slightly lower latency to memory as the memory controller(s) in an SNC node are electrically closer to the CPU cores on that SNC node. This cost may be offset by lower bandwidth since the memory accesses for each core can only be interleaved between the memory controllers on the same SNC node.
Resctrl monitoring on an Intel system depends upon attaching RMIDs to tasks to track L3 cache occupancy and memory bandwidth. There is an MSR that controls how the RMIDs are shared between SNC nodes.
The default mode divides them numerically. E.g. when there are two SNC nodes on a socket the lower number half of the RMIDs are given to the first node, the remainder to the second node. This would be difficult to use with the Linux resctrl interface as specific RMID values assigned to resctrl groups are not visible to users.
The other mode divides the RMIDs and renumbers the ones on the second SNC node to start from zero.
Even with this renumbering SNC mode requires several changes in resctrl behavior for correct operation.
Add a global integer "snc_nodes_per_l3_cache" that shows how many SNC nodes share each L3 cache. When "snc_nodes_per_l3_cache" is "1", SNC mode is either not implemented, or not enabled.
Update all places to take appropriate action when SNC mode is enabled:
1) The number of logical RMIDs per L3 cache available for use is the number of physical RMIDs divided by the number of SNC nodes.
2) Likewise the "mon_scale" value must be divided by the number of SNC nodes.
3) The RMID renumbering operates when using the value from the IA32_PQR_ASSOC MSR to count accesses by a task. When reading an RMID counter, adjust from the logical RMID to the physical RMID value for the SNC node that it wishes to read and load the adjusted value into the IA32_QM_EVTSEL MSR.
4) Divide the L3 cache between the SNC nodes. Divide the value reported in the resctrl "size" file by the number of SNC nodes because the effective amount of cache that can be allocated is reduced by that factor.
5) Disable the "-o mba_MBps" mount option in SNC mode because the monitoring is being done per SNC node, while the bandwidth allocation is still done at the L3 cache scope. Trying to use this feedback loop might result in contradictory changes to the throttling level coming from each of the SNC node bandwidth measurements.
--- arch/x86/kernel/cpu/resctrl/internal.h | 2 ++ arch/x86/kernel/cpu/resctrl/core.c | 6 ++++++ arch/x86/kernel/cpu/resctrl/monitor.c | 16 +++++++++++++--- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 5 +++-- 4 files changed, 24 insertions(+), 5 deletions(-)
arch/x86/kernel/cpu/resctrl/internal.h +2 -0
@@ -446,6 +446,8 @@ DECLARE_STATIC_KEY_FALSE(rdt_alloc_enable_key);extern struct dentry *debugfs_resctrl; +extern unsigned int snc_nodes_per_l3_cache; +enum resctrl_res_level {RDT_RESOURCE_L3 ,RDT_RESOURCE_L2 ,
arch/x86/kernel/cpu/resctrl/core.c +6 -0
@@ -48,6 +48,12 @@ int max_name_width, max_data_width;*/ bool rdt_alloc_capable; +/* +* Number of SNC nodes that share each L3 cache. Default is 1 for +* systems that do not support SNC, or have SNC disabled. +*/ +unsigned int snc_nodes_per_l3_cache =1 ; +static void mba_wrmsr_intel (struct rdt_ctrl_domain *d,struct msr_param *m,struct rdt_resource *r);
arch/x86/kernel/cpu/resctrl/monitor.c +13 -3
@@ -148,8 +148,18 @@ static inline struct rmid_entry *__rmid_entry(u32 rmid)static int __rmid_read (u32 rmid,enum resctrl_event_id eventid,u64 *val) { +struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl; +int cpu =smp_processor_id (); +int rmid_offset =0 ;u64 msr_val; +/* +* When SNC mode is on, need to compute the offset to read the +* physical RMID counter for the node to which this CPU belongs. +*/ +if (snc_nodes_per_l3_cache >1 ) + rmid_offset = (cpu_to_node (cpu) % snc_nodes_per_l3_cache) * r->num_rmid; +/* * As per the SDM, when IA32_QM_EVTSEL.EvtID (bits 7:0) is configured * with a valid event code for supported resource type and the bits
@@ -158,7 +168,7 @@ static int __rmid_read(u32 rmid, enum resctrl_event_id eventid, u64 *val)* IA32_QM_CTR.Error (bit 63) and IA32_QM_CTR.Unavailable (bit 62) * are error bits. */ -wrmsr (MSR_IA32_QM_EVTSEL , eventid, rmid); +wrmsr (MSR_IA32_QM_EVTSEL , eventid, rmid + rmid_offset);rdmsrl (MSR_IA32_QM_CTR , msr_val);if (msr_val &RMID_VAL_ERROR )
@@ -783,8 +793,8 @@ int __init rdt_get_mon_l3_config(struct rdt_resource *r)int ret; resctrl_rmid_realloc_limit = boot_cpu_data.x86_cache_size *1024 ; - hw_res->mon_scale = boot_cpu_data.x86_cache_occ_scale; - r->num_rmid = boot_cpu_data.x86_cache_max_rmid +1 ; + hw_res->mon_scale = boot_cpu_data.x86_cache_occ_scale / snc_nodes_per_l3_cache; + r->num_rmid = (boot_cpu_data.x86_cache_max_rmid +1 ) / snc_nodes_per_l3_cache; hw_res->mbm_width =MBM_CNTR_WIDTH_BASE ;if (mbm_offset >0 && mbm_offset <=MBM_CNTR_WIDTH_OFFSET_MAX )
arch/x86/kernel/cpu/resctrl/rdtgroup.c +3 -2
@@ -1425,7 +1425,7 @@ unsigned int rdtgroup_cbm_to_size(struct rdt_resource *r, } } -return size; +return size / snc_nodes_per_l3_cache; }/*
@@ -2298,7 +2298,8 @@ static bool supports_mba_mbps(void)struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_MBA ].r_resctrl;return (is_mbm_local_enabled () && - r->alloc_capable &&is_mba_linear ()); + r->alloc_capable &&is_mba_linear () && + snc_nodes_per_l3_cache ==1 ); }/*
Signature · 1 line
2.41.0
Tony Luck
maintainerPATCH v12 7/8 x86/resctrl: Sub NUMA Cluster detection and enable
In reply to Tony LuckThere isn't a simple hardware bit that indicates whether a CPU is running in Sub NUMA Cluster (SNC) mode. Infer the state by comparing the ratio of NUMA nodes to L3 cache instances.
When SNC mode is detected, reconfigure the RMID counters by updating the MSR_RMID_SNC_CONFIG MSR on each socket as CPUs are seen.
Clearing bit zero of the MSR divides the RMIDs and renumbers the ones on the second SNC node to start from zero.
--- arch/x86/include/asm/msr-index.h | 1 + arch/x86/kernel/cpu/resctrl/core.c | 96 ++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+)
arch/x86/include/asm/msr-index.h +1 -0
@@ -1111,6 +1111,7 @@#define MSR_IA32_QM_CTR 0xc8e#define MSR_IA32_PQR_ASSOC 0xc8f#define MSR_IA32_L3_CBM_BASE 0xc90 +#define MSR_RMID_SNC_CONFIG 0xca0#define MSR_IA32_L2_CBM_BASE 0xd10#define MSR_IA32_MBA_THRTL_BASE 0xd50
arch/x86/kernel/cpu/resctrl/core.c +96 -0
129 lines not on this page · raw message
Signature · 1 line
2.41.0
Re: [PATCH v12 7/8] x86/resctrl: Sub NUMA Cluster detection and enable
Hi Tony,
Quoted 129 lines · Tony Luck
There isn't a simple hardware bit that indicates whether a CPU is running in Sub NUMA Cluster (SNC) mode. Infer the state by comparing the ratio of NUMA nodes to L3 cache instances.
When SNC mode is detected, reconfigure the RMID counters by updating the
MSR_RMID_SNC_CONFIGMSR on each socket as CPUs are seen.Clearing bit zero of the MSR divides the RMIDs and renumbers the ones on the second SNC node to start from zero.
Signed-off-by Tony Luck <[email protected]>Reviewed-by Peter Newman <[email protected]>Reviewed-by Reinette Chatre <[email protected]>Reviewed-by Shaopeng Tan <[email protected]>Tested-by Shaopeng Tan <[email protected]>--- arch/x86/include/asm/msr-index.h | 1 + arch/x86/kernel/cpu/resctrl/core.c | 96 ++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+)arch/x86/include/asm/msr-index.h +1
-0@@ -1111,6 +1111,7 @@#define MSR_IA32_QM_CTR 0xc8e#define MSR_IA32_PQR_ASSOC 0xc8f#define MSR_IA32_L3_CBM_BASE 0xc90 +#define MSR_RMID_SNC_CONFIG 0xca0#define MSR_IA32_L2_CBM_BASE 0xd10#define MSR_IA32_MBA_THRTL_BASE 0xd50arch/x86/kernel/cpu/resctrl/core.c +65
-0@@ -16,11 +16,14 @@#define pr_fmt (fmt) "resctrl: " fmt +#include <linux/cpu.h> #include <linux/slab.h> #include <linux/err.h> #include <linux/cacheinfo.h> #include <linux/cpuhotplug.h> +#include <linux/mod_devicetable.h> +#include <asm/cpu_device_id.h> #include <asm/intel-family.h> #include <asm/resctrl.h> #include "internal.h" @@ -740,11 +743,42 @@ static void clear_closid_rmid(int cpu)wrmsr (MSR_IA32_PQR_ASSOC ,0 ,0 ); } +/* +* The power-on reset value of MSR_RMID_SNC_CONFIG is 0x1 +* which indicates that RMIDs are configured in legacy mode. +* This mode is incompatible with Linux resctrl semantics +* as RMIDs are partitioned between SNC nodes, which requires +* a user to know which RMID is allocated to a task. +* Clearing bit 0 reconfigures the RMID counters for use +* in Sub NUMA Cluster mode. This mode is better for Linux. +* The RMID space is divided between all SNC nodes with the +* RMIDs renumbered to start from zero in each node when +* couning operations from tasks. Code to read the counters +* must adjust RMID counter numbers based on SNC node. See +* __rmid_read() for code that does this. +*/ +static void snc_remap_rmids (int cpu) +{ +u64 val; + +/* Only need to enable once per package. */ +if (cpumask_first (topology_core_cpumask (cpu)) != cpu) +return ; + +rdmsrl (MSR_RMID_SNC_CONFIG , val); + val &= ~BIT_ULL (0 ); +wrmsrl (MSR_RMID_SNC_CONFIG , val); +} +static int resctrl_online_cpu (unsigned int cpu) {struct rdt_resource *r;mutex_lock (&rdtgroup_mutex); + +if (snc_nodes_per_l3_cache >1 ) +snc_remap_rmids (cpu); +for_each_capable_rdt_resource (r)domain_add_cpu (cpu, r);/* The cpu is set in default rdtgroup after online. */ @@ -999,11 +1033,73 @@ static __init bool get_rdt_resources(void)return (rdt_mon_capable || rdt_alloc_capable); } +/* CPU models that support MSR_RMID_SNC_CONFIG */ +static const struct x86_cpu_id snc_cpu_ids[]__initconst = { +X86_MATCH_INTEL_FAM6_MODEL (ICELAKE_X ,0 ), +X86_MATCH_INTEL_FAM6_MODEL (SAPPHIRERAPIDS_X ,0 ), +X86_MATCH_INTEL_FAM6_MODEL (EMERALDRAPIDS_X ,0 ), +X86_MATCH_INTEL_FAM6_MODEL (GRANITERAPIDS_X ,0 ), + {} +}; + +/* +* There isn't a simple hardware bit that indicates whether a CPU is running +* in Sub NUMA Cluster (SNC) mode. Infer the state by comparing the +* ratio of NUMA nodes to L3 cache instances. +* It is not possible to accurately determine SNC state if the system is +* booted with a maxcpus=N parameter. That distorts the ratio of SNC nodes +* to L3 caches. It will be OK if system is booted with hyperthreading +* disabled (since this doesn't affect the ratio). +*/ +static __init int snc_get_config (void ) +{ +unsigned long *node_caches; +int mem_only_nodes =0 ; +int cpu, node, ret; +int num_l3_caches; + +if (!x86_match_cpu (snc_cpu_ids)) +return 1 ; + + node_caches =bitmap_zalloc (nr_node_ids,GFP_KERNEL ); +if (!node_caches) +return 1 ;
arch/x86/kernel/cpu/resctrl/core.c static __init bool get_rdt_resources(void) · line 1076
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/core.c +10
-0+ +cpus_read_lock (); + +if (num_online_cpus () !=num_present_cpus ()) +pr_warn ("Some CPUs offline, SNC detection may be incorrect\n" ); + +for_each_node (node) { + cpu =cpumask_first (cpumask_of_node (node)); +if (cpu < nr_cpu_ids) +set_bit (get_cpu_cacheinfo_id (cpu,3 ), node_caches);
Are we sure get_cpu_cacheinfo_id() is an valid index here? Looking at the function it could be -1 or larger than nr_node_ids.
Fam
Quoted 31 lines
arch/x86/kernel/cpu/resctrl/core.c +21
-0+else + mem_only_nodes++; + } +cpus_read_unlock (); + + num_l3_caches =bitmap_weight (node_caches, nr_node_ids); +kfree (node_caches); + +if (!num_l3_caches) +return 1 ; + + ret = (nr_node_ids - mem_only_nodes) / num_l3_caches; + +if (ret >1 ) + rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl.mon_scope =RESCTRL_NODE ; + +return ret; +} +static __init void rdt_init_res_defs_intel (void ) {struct rdt_hw_resource *hw_res;struct rdt_resource *r; + snc_nodes_per_l3_cache =snc_get_config (); +for_each_rdt_resource (r) { hw_res =resctrl_to_arch_res (r);Signature · 1 line
2.41.
Tony Luck
maintainerRe: [PATCH v12 7/8] x86/resctrl: Sub NUMA Cluster detection and enable
Quoted 18 lines · Fam Zheng
Quoted 18 lines
(quoted diff) +18
-0+static __init int snc_get_config(void) +{ + unsigned long *node_caches; + int mem_only_nodes = 0; + int cpu, node, ret; + int num_l3_caches; + + if (!x86_match_cpu(snc_cpu_ids)) + return 1; + + node_caches = bitmap_zalloc(nr_node_ids, GFP_KERNEL); + if (!node_caches) + return 1; + + cpus_read_lock(); + + if (num_online_cpus() != num_present_cpus()) + pr_warn("Some CPUs offline, SNC detection may be incorrect\n");
Quoted 8 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+ + for_each_node(node) { + cpu = cpumask_first(cpumask_of_node(node)); + if (cpu < nr_cpu_ids) + set_bit(get_cpu_cacheinfo_id(cpu, 3), node_caches);Are we sure
get_cpu_cacheinfo_id()is an valid index here? Looking at the function it could be -1 or larger thannr_node_ids.
Fam,
Return -1 is possible (in the case where first CPU on a node doesn't have an L3 cache). Larger than nr_node_ids seems a bit more speculative. It would mean a system with multiple L3 cache instances per node. I suppose that's theoretically possible. In the limit case every CPU may have its own personal L3 cache, but still have multiple CPUs grouped together on a node.
Patch below (to be folded into part7 of next version). Increases the size of the bitmap. Checks for get_cpu_cacheinfo_id() returning -1. Patch just ignores the node in this case. I'm never quite sure how much code to add for "Can't happen" scenarios.
-Tony
arch/x86/kernel/cpu/resctrl/core.c +8 -4
@@ -1056,12 +1056,13 @@ static __init int snc_get_config(void)unsigned long *node_caches;int mem_only_nodes =0 ;int cpu, node, ret; +int cache_id;int num_l3_caches;if (!x86_match_cpu (snc_cpu_ids))return 1 ; - node_caches =bitmap_zalloc (nr_node_ids,GFP_KERNEL ); + node_caches =bitmap_zalloc (num_online_cpus (),GFP_KERNEL );if (!node_caches)return 1 ;
@@ -1072,10 +1073,13 @@ static __init int snc_get_config(void)for_each_node (node) { cpu =cpumask_first (cpumask_of_node (node)); -if (cpu < nr_cpu_ids) -set_bit (get_cpu_cacheinfo_id (cpu,3 ), node_caches); -else +if (cpu < nr_cpu_ids) { + cache_id =get_cpu_cacheinfo_id (cpu,3 ); +if (cache_id !=-1 ) +set_bit (cache_id, node_caches); + }else { mem_only_nodes++; + } }cpus_read_unlock ();
Signature · 1 line
2.41.0
Reinette Chatre
maintainerRe: [PATCH v12 7/8] x86/resctrl: Sub NUMA Cluster detection and enable
Hi Tony,
Quoted 37 lines · Tony Luck
Quoted 18 lines · Fam Zheng
Quoted 18 lines
(quoted diff) +18
-0+static __init int snc_get_config(void) +{ + unsigned long *node_caches; + int mem_only_nodes = 0; + int cpu, node, ret; + int num_l3_caches; + + if (!x86_match_cpu(snc_cpu_ids)) + return 1; + + node_caches = bitmap_zalloc(nr_node_ids, GFP_KERNEL); + if (!node_caches) + return 1; + + cpus_read_lock(); + + if (num_online_cpus() != num_present_cpus()) + pr_warn("Some CPUs offline, SNC detection may be incorrect\n");Quoted 8 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+ + for_each_node(node) { + cpu = cpumask_first(cpumask_of_node(node)); + if (cpu < nr_cpu_ids) + set_bit(get_cpu_cacheinfo_id(cpu, 3), node_caches);Are we sure
get_cpu_cacheinfo_id()is an valid index here? Looking at the function it could be -1 or larger thannr_node_ids.Fam,
Return -1 is possible (in the case where first CPU on a node doesn't have an L3 cache). Larger than
nr_node_idsseems a bit more speculative. It would mean a system with multiple L3 cache instances per node. I suppose that's theoretically possible. In the limit case every CPU may have its own personal L3 cache, but still have multiple CPUs grouped together on a node.
Quoted 5 lines
Patch below (to be folded into part7 of next version). Increases the size of the bitmap. Checks for
get_cpu_cacheinfo_id()returning -1. Patch just ignores the node in this case. I'm never quite sure how much code to add for "Can't happen" scenarios.
Thank you.
arch/x86/kernel/cpu/resctrl/core.c static __init int snc_get_config(void) · line 1060
Quoted 13 lines
(quoted diff) +0
-1-Tonyarch/x86/kernel/cpu/resctrl/core.c +1
-0@@ -1056,12 +1056,13 @@ static __init int snc_get_config(void)unsigned long *node_caches;int mem_only_nodes =0 ;int cpu, node, ret; +int cache_id;int num_l3_caches;
Please do maintain reverse fir order.
arch/x86/kernel/cpu/resctrl/core.c static __init int snc_get_config(void) · line 1062
Quoted 3 lines
arch/x86/kernel/cpu/resctrl/core.c +0
-0if (!x86_match_cpu (snc_cpu_ids))return 1 ;
I understand and welcome this change as motivated by robustness. Apart from that, with this being a model specific feature for this particular group of systems, it it not clear to me in which scenarios this could run on a system where a present CPU does not have access to L3 cache.
arch/x86/kernel/cpu/resctrl/core.c static __init int snc_get_config(void) · line 1065
Quoted 3 lines
arch/x86/kernel/cpu/resctrl/core.c +1
-1- node_caches =bitmap_zalloc (nr_node_ids,GFP_KERNEL ); + node_caches =bitmap_zalloc (num_online_cpus (),GFP_KERNEL );
Please do take care to take new bitmap size into account in all places. From what I can tell there is a later bitmap_weight() call that still uses nr_node_ids as size.
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/core.c +0
-3if (!node_caches)return 1 ;@@ -1072,10 +1073,13 @@ static __init int snc_get_config(void)for_each_node (node) { cpu =cpumask_first (cpumask_of_node (node)); -if (cpu < nr_cpu_ids) -set_bit (get_cpu_cacheinfo_id (cpu,3 ), node_caches); -else
arch/x86/kernel/cpu/resctrl/core.c static __init int snc_get_config(void) · line 1085
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/core.c +6
-0+if (cpu < nr_cpu_ids) { + cache_id =get_cpu_cacheinfo_id (cpu,3 ); +if (cache_id !=-1 ) +set_bit (cache_id, node_caches); + }else { mem_only_nodes++; + } }cpus_read_unlock ();
Could this code be made even more robust by checking the computed snc_nodes_per_l3_cache against the limited actually possible values? Forcing it to 1 if something went wrong?
Reinette
Tony Luck
maintainerRe: [PATCH v12 7/8] x86/resctrl: Sub NUMA Cluster detection and enable
Quoted 13 lines · Reinette Chatre
Hi Tony,
arch/x86/kernel/cpu/resctrl/core.c static __init int snc_get_config(void) · line 1060
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/core.c +1
-0@@ -1056,12 +1056,13 @@ static __init int snc_get_config(void)unsigned long *node_caches;int mem_only_nodes =0 ;int cpu, node, ret; +int cache_id;int num_l3_caches;Please do maintain reverse fir order.
Fixed.
Quoted 9 lines
arch/x86/kernel/cpu/resctrl/core.c static __init int snc_get_config(void) · line 1062
Quoted 4 lines
arch/x86/kernel/cpu/resctrl/core.c +0
-0if (!x86_match_cpu (snc_cpu_ids))return 1 ;I understand and welcome this change as motivated by robustness. Apart from that, with this being a model specific feature for this particular group of systems, it it not clear to me in which scenarios this could run on a system where a present CPU does not have access to L3 cache.
Agreed that on these systems there should always be an L3 cache. Should I drop the check for "-1"?
Quoted 7 lines
arch/x86/kernel/cpu/resctrl/core.c static __init int snc_get_config(void) · line 1063
Quoted 3 lines
arch/x86/kernel/cpu/resctrl/core.c +1
-1- node_caches =bitmap_zalloc (nr_node_ids,GFP_KERNEL ); + node_caches =bitmap_zalloc (num_online_cpus (),GFP_KERNEL );Please do take care to take new bitmap size into account in all places. From what I can tell there is a later
bitmap_weight()call that still usesnr_node_idsas size.
Oops. I was also using num_online_cpus() before cpus_read_lock(), so things could theoretically change before the bitmap_weight() call. I switched to using num_present_cpus() in both places.
Quoted 16 lines
Quoted 16 lines
arch/x86/kernel/cpu/resctrl/core.c +5
-3if (!node_caches)return 1 ;@@ -1072,10 +1073,13 @@ static __init int snc_get_config(void)for_each_node (node) { cpu =cpumask_first (cpumask_of_node (node)); -if (cpu < nr_cpu_ids) -set_bit (get_cpu_cacheinfo_id (cpu,3 ), node_caches); -else +if (cpu < nr_cpu_ids) { + cache_id =get_cpu_cacheinfo_id (cpu,3 ); +if (cache_id !=-1 ) +set_bit (cache_id, node_caches); + }else { mem_only_nodes++;
Quoted 8 lines
arch/x86/kernel/cpu/resctrl/core.c static __init int snc_get_config(void) · line 1085
Quoted 4 lines
arch/x86/kernel/cpu/resctrl/core.c +1
-0+ } }cpus_read_unlock ();Could this code be made even more robust by checking the computed
snc_nodes_per_l3_cacheagainst the limited actually possible values? Forcing it to 1 if something went wrong?
Added a couple of extra sanity checks. See updated incremental patch below.
-Tony
arch/x86/kernel/cpu/resctrl/core.c +23 -6
@@ -1057,11 +1057,12 @@ static __init int snc_get_config(void)int mem_only_nodes =0 ;int cpu, node, ret;int num_l3_caches; +int cache_id;if (!x86_match_cpu (snc_cpu_ids))return 1 ; - node_caches =bitmap_zalloc (nr_node_ids,GFP_KERNEL ); + node_caches =bitmap_zalloc (num_present_cpus (),GFP_KERNEL );if (!node_caches)return 1 ;
@@ -1072,23 +1073,39 @@ static __init int snc_get_config(void)for_each_node (node) { cpu =cpumask_first (cpumask_of_node (node)); -if (cpu < nr_cpu_ids) -set_bit (get_cpu_cacheinfo_id (cpu,3 ), node_caches); -else +if (cpu < nr_cpu_ids) { + cache_id =get_cpu_cacheinfo_id (cpu,3 ); +if (cache_id !=-1 ) +set_bit (cache_id, node_caches); + }else { mem_only_nodes++; + } }cpus_read_unlock (); - num_l3_caches =bitmap_weight (node_caches, nr_node_ids); + num_l3_caches =bitmap_weight (node_caches,num_present_cpus ());kfree (node_caches);if (!num_l3_caches)return 1 ; +/* sanity check #1: Number of CPU nodes must be multiple of num_l3_caches */ +if ((nr_node_ids - mem_only_nodes) % num_l3_caches) +return 1 ; + ret = (nr_node_ids - mem_only_nodes) / num_l3_caches; -if (ret >1 ) +/* sanity check #2: Only valid results are 1, 2, 4 */ +switch (ret) { +case 1 : +break ; +case 2 : +case 4 : rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl.mon_scope =RESCTRL_NODE ; +break ; +default : +return 1 ; + }return ret; }
Signature · 1 line
2.41.0
Reinette Chatre
maintainerRe: [PATCH v12 7/8] x86/resctrl: Sub NUMA Cluster detection and enable
Hi Tony,
Quoted 1 line · Tony Luck
On Thu, Nov 30, 2023 at 01:47:10PM -0800, Reinette Chatre wrote:
...
Quoted 10 lines
Quoted 7 lines
Review
Quoted 2 lines
(quoted diff) +0
-0if (!x86_match_cpu(snc_cpu_ids)) return 1;I understand and welcome this change as motivated by robustness. Apart from that, with this being a model specific feature for this particular group of systems, it it not clear to me in which scenarios this could run on a system where a present CPU does not have access to L3 cache.
Agreed that on these systems there should always be an L3 cache. Should I drop the check for "-1"?
Please do keep it. I welcome the additional robustness. The static checker I tried did not complain about this but I expect that it is something that could trigger checks.
Quoted 9 lines
Quoted 8 lines
Review
Quoted 4 lines
(quoted diff) +1
-1- node_caches = bitmap_zalloc(nr_node_ids, GFP_KERNEL); + node_caches = bitmap_zalloc(num_online_cpus(), GFP_KERNEL);Please do take care to take new bitmap size into account in all places. From what I can tell there is a later
bitmap_weight()call that still usesnr_node_idsas size.
Quoted 3 lines
Oops. I was also using
num_online_cpus()beforecpus_read_lock(), so things could theoretically change before thebitmap_weight()call. I switched to usingnum_present_cpus()in both places.
Thanks for catching this. I am not sure if num_present_cpus() is the right choice. I found its comment to say "If HOTPLUG is enabled, then cpu_present_mask varies dynamically ...". num_possible_cpus() seems more appropriate when looking for something that does not change while not holding the hotplug lock. Reading its description more closely also makes me wonder if the later
num_online_cpus() != num_present_cpus() should also maybe be num_online_cpus() != num_possible_cpus() ?
It seems to more closely match the intention.
Quoted 25 lines
Quoted 16 lines
Quoted 16 lines
arch/x86/kernel/cpu/resctrl/core.c +5
-3if (!node_caches)return 1 ;@@ -1072,10 +1073,13 @@ static __init int snc_get_config(void)for_each_node (node) { cpu =cpumask_first (cpumask_of_node (node)); -if (cpu < nr_cpu_ids) -set_bit (get_cpu_cacheinfo_id (cpu,3 ), node_caches); -else +if (cpu < nr_cpu_ids) { + cache_id =get_cpu_cacheinfo_id (cpu,3 ); +if (cache_id !=-1 ) +set_bit (cache_id, node_caches); + }else { mem_only_nodes++;Quoted 8 lines
arch/x86/kernel/cpu/resctrl/core.c static __init int snc_get_config(void) · line 1085
Quoted 4 lines
arch/x86/kernel/cpu/resctrl/core.c +1
-0+ } }cpus_read_unlock ();Could this code be made even more robust by checking the computed
snc_nodes_per_l3_cacheagainst the limited actually possible values? Forcing it to 1 if something went wrong?
Quoted 2 lines
Added a couple of extra sanity checks. See updated incremental patch below.
Thank you very much. The additional checks look good to me.
Reinette
Tony Luck
maintainerRe: [PATCH v12 7/8] x86/resctrl: Sub NUMA Cluster detection and enable
Quoted 31 lines · Reinette Chatre
Hi Tony,
Quoted 1 line · Tony Luck
On Thu, Nov 30, 2023 at 01:47:10PM -0800, Reinette Chatre wrote:
...
Quoted 10 lines
Quoted 7 lines
Review
Quoted 2 lines
(quoted diff) +0
-0if (!x86_match_cpu(snc_cpu_ids)) return 1;I understand and welcome this change as motivated by robustness. Apart from that, with this being a model specific feature for this particular group of systems, it it not clear to me in which scenarios this could run on a system where a present CPU does not have access to L3 cache.
Agreed that on these systems there should always be an L3 cache. Should I drop the check for "-1"?
Please do keep it. I welcome the additional robustness. The static checker I tried did not complain about this but I expect that it is something that could trigger checks.
Quoted 9 lines
Quoted 8 lines
Review
Quoted 4 lines
(quoted diff) +1
-1- node_caches = bitmap_zalloc(nr_node_ids, GFP_KERNEL); + node_caches = bitmap_zalloc(num_online_cpus(), GFP_KERNEL);Please do take care to take new bitmap size into account in all places. From what I can tell there is a later
bitmap_weight()call that still usesnr_node_idsas size.
Quoted 7 lines
Quoted 3 lines
Oops. I was also using
num_online_cpus()beforecpus_read_lock(), so things could theoretically change before thebitmap_weight()call. I switched to usingnum_present_cpus()in both places.Thanks for catching this. I am not sure if
num_present_cpus()is the right choice. I found its comment to say "If HOTPLUG is enabled, thencpu_present_maskvaries dynamically ...".num_possible_cpus()seems more appropriate when looking
I can size the bitmask based on num_possible_cpus().
Quoted 6 lines
for something that does not change while not holding the hotplug lock. Reading its description more closely also makes me wonder if the later
num_online_cpus() != num_present_cpus() should also maybe be num_online_cpus() != num_possible_cpus() ?It seems to more closely match the intention.
This seems problematic. On a system that does support physical CPU hotplug num_possible_cpus() may be some very large number. Reserving space for CPUs that can be added later. None of those CPUs can be online (obviously!). So this test would fail on such a system.
Quoted 25 lines
Quoted 25 lines
Quoted 24 lines
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/core.c +0
-3if (!node_caches)return 1 ;@@ -1072,10 +1073,13 @@ static __init int snc_get_config(void)for_each_node (node) { cpu =cpumask_first (cpumask_of_node (node)); -if (cpu < nr_cpu_ids) -set_bit (get_cpu_cacheinfo_id (cpu,3 ), node_caches); -else arch/x86/kernel/cpu/resctrl/core.c static __init int snc_get_config(void) · line 1085
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/core.c +6
-0+if (cpu < nr_cpu_ids) { + cache_id =get_cpu_cacheinfo_id (cpu,3 ); +if (cache_id !=-1 ) +set_bit (cache_id, node_caches); + }else { mem_only_nodes++; + } }cpus_read_unlock ();Could this code be made even more robust by checking the computed
snc_nodes_per_l3_cacheagainst the limited actually possible values? Forcing it to 1 if something went wrong?
Quoted 6 lines
Quoted 2 lines
Added a couple of extra sanity checks. See updated incremental patch below.
Thank you very much. The additional checks look good to me.
Reinette
Thanks for looking at this. I'm applying changes to my local tree. I'll give folks a little more time to find additonal issues in v12 and post v13 next week.
-Tony
Reinette Chatre
maintainerRe: [PATCH v12 7/8] x86/resctrl: Sub NUMA Cluster detection and enable
Hi Tony,
Quoted 13 lines · Tony Luck
Quoted 11 lines · Reinette Chatre
Hi Tony,
Quoted 1 line · Tony Luck
On Thu, Nov 30, 2023 at 01:47:10PM -0800, Reinette Chatre wrote:
for something that does not change while not holding the hotplug lock. Reading its description more closely also makes me wonder if the later
num_online_cpus() != num_present_cpus() should also maybe be num_online_cpus() != num_possible_cpus() ?It seems to more closely match the intention.
Quoted 4 lines
This seems problematic. On a system that does support physical CPU hotplug
num_possible_cpus()may be some very large number. Reserving space for CPUs that can be added later. None of those CPUs can be online (obviously!). So this test would fail on such a system.
Thank you for clarifying. It was not obvious to me how these bitmaps are different with physical hotplug.
Reinette
Tony Luck
maintainerPATCH v12 8/8 x86/resctrl: Update documentation with Sub-NUMA cluster changes
In reply to Tony LuckWith Sub-NUMA Cluster mode enabled the scope of monitoring resources is per-NODE instead of per-L3 cache. Suffixes of directories with "L3" in their name refer to Sub-NUMA nodes instead of L3 cache ids.
Users should be aware that SNC mode also affects the amount of L3 cache available for allocation within each SNC node.
--- Documentation/arch/x86/resctrl.rst | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-)
Documentation/arch/x86/resctrl.rst +21 -4
@@ -366,10 +366,10 @@ When control is enabled all CTRL_MON groups will also contain: When monitoring is enabled all MON groups will also contain: "mon_data": - This contains a set of files organized by L3 domain and by - RDT event. E.g. on a system with two L3 domains there will - be subdirectories "mon_L3_00" and "mon_L3_01". Each of these - directories have one file per event (e.g. "llc_occupancy", + This contains a set of files organized by L3 domain or by NUMA + node (depending on whether Sub-NUMA Cluster (SNC) mode is disabled + or enabled respectively) and by RDT event. Each of these + directories has one file per event (e.g. "llc_occupancy", "mbm_total_bytes", and "mbm_local_bytes"). In a MON group these files provide a read out of the current value of the event for all tasks in the group. In CTRL_MON groups these files provide
@@ -478,6 +478,23 @@ if non-contiguous 1s value is supported. On a system with a 20-bit mask each bit represents 5% of the capacity of the cache. You could partition the cache into four equal parts with masks: 0x1f, 0x3e0, 0x7c00, 0xf8000. +Notes on Sub-NUMA Cluster mode +============================== +When SNC mode is enabled Linux may load balance tasks between Sub-NUMA +nodes much more readily than between regular NUMA nodes since the CPUs +on Sub-NUMA nodes share the same L3 cache and the system may report +the NUMA distance between Sub-NUMA nodes with a lower value than used +for regular NUMA nodes. Users who do not bind tasks to the CPUs of a +specific Sub-NUMA node must read the "llc_occupancy", "mbm_total_bytes", +and "mbm_local_bytes" for all Sub-NUMA nodes where the tasks may execute +to get the full view of traffic for which the tasks were the source. + +The cache allocation feature still provides the same number of +bits in a mask to control allocation into the L3 cache, but each +of those ways has its capacity reduced because the cache is divided +between the SNC nodes. The values reported in the resctrl +"size" files are adjusted accordingly. + Memory bandwidth Allocation and monitoring ==========================================
Signature · 1 line
2.41.0
Moger, Babu
reviewerRe: [PATCH v12 8/8] x86/resctrl: Update documentation with Sub-NUMA cluster changes
Quoted 36 lines · Tony Luck
With Sub-NUMA Cluster mode enabled the scope of monitoring resources is per-NODE instead of per-L3 cache. Suffixes of directories with "L3" in their name refer to Sub-NUMA nodes instead of L3 cache ids.
Users should be aware that SNC mode also affects the amount of L3 cache available for allocation within each SNC node.
Signed-off-by Tony Luck <[email protected]>Reviewed-by Peter Newman <[email protected]>Reviewed-by Reinette Chatre <[email protected]>Reviewed-by Shaopeng Tan <[email protected]>Tested-by Shaopeng Tan <[email protected]>--- Documentation/arch/x86/resctrl.rst | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-)Documentation/arch/x86/resctrl.rst +4
-4@@ -366,10 +366,10 @@ When control is enabled all CTRL_MON groups will also contain: When monitoring is enabled all MON groups will also contain: "mon_data": - This contains a set of files organized by L3 domain and by - RDT event. E.g. on a system with two L3 domains there will - be subdirectories "mon_L3_00" and "mon_L3_01". Each of these - directories have one file per event (e.g. "llc_occupancy", + This contains a set of files organized by L3 domain or by NUMA + node (depending on whether Sub-NUMA Cluster (SNC) mode is disabled + or enabled respectively) and by RDT event. Each of these + directories has one file per event (e.g. "llc_occupancy", "mbm_total_bytes", and "mbm_local_bytes"). In a MON group these files provide a read out of the current value of the event for all tasks in the group. In CTRL_MON groups these files provide
Documentation/arch/x86/resctrl.rst if non-contiguous 1s value is supported. On a system with a 20-bit mask · line 483
Quoted 6 lines
Documentation/arch/x86/resctrl.rst +3
-0@@ -478,6 +478,23 @@ if non-contiguous 1s value is supported. On a system with a 20-bit mask each bit represents 5% of the capacity of the cache. You could partition the cache into four equal parts with masks: 0x1f, 0x3e0, 0x7c00, 0xf8000. +Notes on Sub-NUMA Cluster mode +============================== +When SNC mode is enabled Linux may load balance tasks between Sub-NUMA
enabled, Linux
Thanks
Babu
Quoted 17 lines
Documentation/arch/x86/resctrl.rst +14
-0+nodes much more readily than between regular NUMA nodes since the CPUs +on Sub-NUMA nodes share the same L3 cache and the system may report +the NUMA distance between Sub-NUMA nodes with a lower value than used +for regular NUMA nodes. Users who do not bind tasks to the CPUs of a +specific Sub-NUMA node must read the "llc_occupancy", "mbm_total_bytes", +and "mbm_local_bytes" for all Sub-NUMA nodes where the tasks may execute +to get the full view of traffic for which the tasks were the source. + +The cache allocation feature still provides the same number of +bits in a mask to control allocation into the L3 cache, but each +of those ways has its capacity reduced because the cache is divided +between the SNC nodes. The values reported in the resctrl +"size" files are adjusted accordingly. + Memory bandwidth Allocation and monitoring ==========================================
Signature · 2 lines
Thanks Babu Moger
Luck, Tony
maintainerRE: [PATCH v12 8/8] x86/resctrl: Update documentation with Sub-NUMA cluster changes
Quoted 5 lines
Documentation/arch/x86/resctrl.rst if non-contiguous 1s value is supported. On a system with a 20-bit mask · line 483
Quoted 3 lines
Documentation/arch/x86/resctrl.rst +3
-0+Notes on Sub-NUMA Cluster mode +============================== +When SNC mode is enabled Linux may load balance tasks between Sub-NUMAenabled, Linux
Babu,
Thanks. I've added that "," ready for next version.
-Tony
Tony Luck
maintainerv13 cover Add support for Sub-NUMA cluster (SNC) systems
In reply to Tony LuckThe Sub-NUMA cluster feature on some Intel processors partitions the CPUs that share an L3 cache into two or more sets. This plays havoc with the Resource Director Technology (RDT) monitoring features. Prior to this patch Intel has advised that SNC and RDT are incompatible.
Some of these CPU support an MSR that can partition the RMID counters in the same way. This allows monitoring features to be used. With the caveat that users must be aware that Linux may migrate tasks more frequently between SNC nodes than between "regular" NUMA nodes, so reading counters from all SNC nodes may be needed to get a complete picture of activity for tasks.
Cache and memory bandwidth allocation features continue to operate at the scope of the L3 cache.
Changes since v12:
All:
Reinette - put commit tags in right order for TIP (Tested-by before Reviewed-by)
Patch 7:
Fam Zheng - Check for -1 return from get_cpu_cacheinfo_id() and increase size of bitmap tracking # of L3 instances. Reinette - Add extra sanity checks. Note that this patch has some additional tweaks beyond the e-mail discussion.
1) "3" is a valid return in addition to 1, 2, 4
2) Added a warning if the sanity checks fail that prints number of CPU nodes and number of L3 cache instances that were found.
Patch 8:
Babu - Fix grammar with an additional comma.
Tony Luck (8):
x86/resctrl: Prepare for new domain scope x86/resctrl: Prepare to split rdt_domain structure x86/resctrl: Prepare for different scope for control/monitor
operations
x86/resctrl: Split the rdt_domain and rdt_hw_domain structures x86/resctrl: Add node-scope to the options for feature scope x86/resctrl: Introduce snc_nodes_per_l3_cache x86/resctrl: Sub NUMA Cluster detection and enable x86/resctrl: Update documentation with Sub-NUMA cluster changes
Documentation/arch/x86/resctrl.rst | 25 +- include/linux/resctrl.h | 85 +++-- arch/x86/include/asm/msr-index.h | 1 + arch/x86/kernel/cpu/resctrl/internal.h | 66 ++-- arch/x86/kernel/cpu/resctrl/core.c | 433 +++++++++++++++++----- arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 58 +-- arch/x86/kernel/cpu/resctrl/monitor.c | 68 ++-- arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 26 +- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 149 ++++---- 9 files changed, 629 insertions(+), 282 deletions(-)
base-commit: 2cc14f52aeb78ce3f29677c2de1f06c0e91471ab
Signature · 1 line
2.41.0
Tony Luck
maintainerPATCH v13 1/8 x86/resctrl: Prepare for new domain scope
Resctrl resources operate on subsets of CPUs in the system with the defining attribute of each subset being an instance of a particular level of cache. E.g. all CPUs sharing an L3 cache would be part of the same domain.
In preparation for features that are scoped at the NUMA node level change the code from explicit references to "cache_level" to a more generic scope. At this point the only options for this scope are groups of CPUs that share an L2 cache or L3 cache.
Clean up the error handling when looking up domains. Report invalid id's before calling rdt_find_domain() in preparation for better messages when scope can be other than cache scope. This means that rdt_find_domain() will never return an error. So remove checks for error from the callsites.
--- include/linux/resctrl.h | 9 ++++- arch/x86/kernel/cpu/resctrl/core.c | 45 ++++++++++++++++------- arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 2 +- arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 6 ++- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 5 ++- 5 files changed, 48 insertions(+), 19 deletions(-)
include/linux/resctrl.h +7 -2
@@ -144,13 +144,18 @@ struct resctrl_membw {struct rdt_parse_data ;struct resctrl_schema ; +enum resctrl_scope { +RESCTRL_L2_CACHE =2 , +RESCTRL_L3_CACHE =3 , +}; +/** * struct rdt_resource - attributes of a resctrl resource * @rid: The index of the resource * @alloc_capable: Is allocation available on this machine * @mon_capable: Is monitor feature available on this machine * @num_rmid: Number of RMIDs available -* @cache_level: Which cache level defines scope of this resource +* @scope: Scope of this resource * @cache: Cache allocation related data * @membw: If the component has bandwidth controls, their properties. * @domains: All domains for this resource
@@ -168,7 +173,7 @@ struct rdt_resource {bool alloc_capable;bool mon_capable;int num_rmid; -int cache_level; +enum resctrl_scope scope;struct resctrl_cache cache;struct resctrl_membw membw;struct list_head domains;
arch/x86/kernel/cpu/resctrl/core.c +31 -14
105 lines not on this page · raw message
arch/x86/kernel/cpu/resctrl/ctrlmondata.c +1 -1
@@ -563,7 +563,7 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg) r = &rdt_resources_all[resid].r_resctrl; d =rdt_find_domain (r, domid,NULL ); -if (IS_ERR_OR_NULL (d)) { +if (!d) { ret = -ENOENT ; goto out; }
arch/x86/kernel/cpu/resctrl/pseudo_lock.c +5 -1
@@ -292,10 +292,14 @@ static void pseudo_lock_region_clear(struct pseudo_lock_region *plr)*/ static int pseudo_lock_region_init (struct pseudo_lock_region *plr) { +enum resctrl_scope scope = plr->s->res->scope;struct cpu_cacheinfo *ci;int ret;int i; +if (WARN_ON_ONCE (scope !=RESCTRL_L2_CACHE && scope !=RESCTRL_L3_CACHE )) +return -ENODEV ; +/* Pick the first cpu we find that is associated with the cache. */ plr->cpu =cpumask_first (&plr->d->cpu_mask);
@@ -311,7 +315,7 @@ static int pseudo_lock_region_init(struct pseudo_lock_region *plr) plr->size =rdtgroup_cbm_to_size (plr->s->res, plr->d, plr->cbm);for (i =0 ; i < ci->num_leaves; i++) { -if (ci->info_list[i].level == plr->s->res->cache_level) { +if (ci->info_list[i].level == scope) { plr->line_size = ci->info_list[i].coherency_line_size;return 0 ; }
arch/x86/kernel/cpu/resctrl/rdtgroup.c +4 -1
@@ -1413,10 +1413,13 @@ unsigned int rdtgroup_cbm_to_size(struct rdt_resource *r,unsigned int size =0 ;int num_b, i; +if (WARN_ON_ONCE (r->scope !=RESCTRL_L2_CACHE && r->scope !=RESCTRL_L3_CACHE )) +return size; + num_b =bitmap_weight (&cbm, r->cache.cbm_len); ci =get_cpu_cacheinfo (cpumask_any (&d->cpu_mask));for (i =0 ; i < ci->num_leaves; i++) { -if (ci->info_list[i].level == r->cache_level) { +if (ci->info_list[i].level == r->scope) { size = ci->info_list[i].size / r->cache.cbm_len * num_b;break ; }
Signature · 1 line
2.41.0
Re: [PATCH v13 1/8] x86/resctrl: Prepare for new domain scope
Quoted 15 lines · Tony Luck
Resctrl resources operate on subsets of CPUs in the system with the defining attribute of each subset being an instance of a particular level of cache. E.g. all CPUs sharing an L3 cache would be part of the same domain.
In preparation for features that are scoped at the NUMA node level change the code from explicit references to "
cache_level" to a more generic scope. At this point the only options for this scope are groups of CPUs that share an L2 cache or L3 cache.Clean up the error handling when looking up domains. Report invalid id's before calling
rdt_find_domain()in preparation for better messages when scope can be other than cache scope. This means thatrdt_find_domain()will never return an error. So remove checks for error from the callsites.
Quoted 4 lines
Signed-off-by Tony Luck<[email protected]>Tested-by Shaopeng Tan<[email protected]>Reviewed-by Reinette Chatre<[email protected]>Reviewed-by Shaopeng Tan<[email protected]>
Quoted 218 lines
--- include/linux/resctrl.h | 9 ++++- arch/x86/kernel/cpu/resctrl/core.c | 45 ++++++++++++++++------- arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 2 +- arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 6 ++- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 5 ++- 5 files changed, 48 insertions(+), 19 deletions(-)include/linux/resctrl.h +7
-2@@ -144,13 +144,18 @@ struct resctrl_membw {struct rdt_parse_data ;struct resctrl_schema ; +enum resctrl_scope { +RESCTRL_L2_CACHE =2 , +RESCTRL_L3_CACHE =3 , +}; +/** * struct rdt_resource - attributes of a resctrl resource * @rid: The index of the resource * @alloc_capable: Is allocation available on this machine * @mon_capable: Is monitor feature available on this machine * @num_rmid: Number of RMIDs available -* @cache_level: Which cache level defines scope of this resource +* @scope: Scope of this resource * @cache: Cache allocation related data * @membw: If the component has bandwidth controls, their properties. * @domains: All domains for this resource @@ -168,7 +173,7 @@ struct rdt_resource {bool alloc_capable;bool mon_capable;int num_rmid; -int cache_level; +enum resctrl_scope scope;struct resctrl_cache cache;struct resctrl_membw membw;struct list_head domains;arch/x86/kernel/cpu/resctrl/core.c +31
-14@@ -65,7 +65,7 @@ struct rdt_hw_resource rdt_resources_all[] = { .r_resctrl = { .rid = RDT_RESOURCE_L3, .name = "L3", - .cache_level = 3, + .scope = RESCTRL_L3_CACHE, .domains = domain_init(RDT_RESOURCE_L3), .parse_ctrlval = parse_cbm, .format_str = "%d=%0*x",@@ -79,7 +79,7 @@ struct rdt_hw_resource rdt_resources_all[] = { .r_resctrl = { .rid = RDT_RESOURCE_L2, .name = "L2", - .cache_level = 2, + .scope = RESCTRL_L2_CACHE, .domains = domain_init(RDT_RESOURCE_L2), .parse_ctrlval = parse_cbm, .format_str = "%d=%0*x",@@ -93,7 +93,7 @@ struct rdt_hw_resource rdt_resources_all[] = { .r_resctrl = { .rid = RDT_RESOURCE_MBA, .name = "MB", - .cache_level = 3, + .scope = RESCTRL_L3_CACHE, .domains = domain_init(RDT_RESOURCE_MBA), .parse_ctrlval = parse_bw, .format_str = "%d=%*u",@@ -105,7 +105,7 @@ struct rdt_hw_resource rdt_resources_all[] = { .r_resctrl = { .rid = RDT_RESOURCE_SMBA, .name = "SMBA", - .cache_level = 3, + .scope = RESCTRL_L3_CACHE, .domains = domain_init(RDT_RESOURCE_SMBA), .parse_ctrlval = parse_bw, .format_str = "%d=%*u",@@ -401,9 +401,6 @@ struct rdt_domain *rdt_find_domain(struct rdt_resource *r, int id,struct rdt_domain *d;struct list_head *l; -if (id <0 ) -return ERR_PTR (-ENODEV ); -list_for_each (l, &r->domains) { d = list_entry(l, struct rdt_domain, list);/* When id is found, return its domain. */ @@ -491,6 +488,19 @@ static int arch_domain_mbm_alloc(u32 num_rmid, struct rdt_hw_domain *hw_dom)return 0 ; } +static int get_domain_id_from_scope (int cpu,enum resctrl_scope scope) +{ +switch (scope) { +case RESCTRL_L2_CACHE : +case RESCTRL_L3_CACHE : +return get_cpu_cacheinfo_id (cpu, scope); +default : +break ; + } + +return -EINVAL ; +} +/* * domain_add_cpu - Add a cpu to a resource's domain list. * @@ -506,18 +516,19 @@ static int arch_domain_mbm_alloc(u32 num_rmid, struct rdt_hw_domain *hw_dom)*/ static void domain_add_cpu (int cpu,struct rdt_resource *r) { -int id =get_cpu_cacheinfo_id (cpu, r->cache_level); +int id =get_domain_id_from_scope (cpu, r->scope);struct list_head *add_pos =NULL ;struct rdt_hw_domain *hw_dom;struct rdt_domain *d;int err; - d =rdt_find_domain (r, id, &add_pos); -if (IS_ERR (d)) { -pr_warn ("Couldn't find cache id for CPU %d\n" , cpu); +if (id <0 ) { +pr_warn_once ("Can't find domain id for CPU:%d scope:%d for resource %s\n" , + cpu, r->scope, r->name);return ; } + d =rdt_find_domain (r, id, &add_pos);if (d) {cpumask_set_cpu (cpu, &d->cpu_mask);if (r->cache.arch_has_per_cpu_cfg)@@ -556,13 +567,19 @@ static void domain_add_cpu(int cpu, struct rdt_resource *r)static void domain_remove_cpu (int cpu,struct rdt_resource *r) { -int id =get_cpu_cacheinfo_id (cpu, r->cache_level); +int id =get_domain_id_from_scope (cpu, r->scope);struct rdt_hw_domain *hw_dom;struct rdt_domain *d; +if (id <0 ) { +pr_warn_once ("Can't find domain id for CPU:%d scope:%d for resource %s\n" , + cpu, r->scope, r->name); +return ; + } + d =rdt_find_domain (r, id,NULL ); -if (IS_ERR_OR_NULL (d)) { -pr_warn ("Couldn't find cache id for CPU %d\n" , cpu); +if (!d) { +pr_warn ("Couldn't find domain with id=%d for CPU %d\n" , id, cpu);return ; } hw_dom =resctrl_to_arch_dom (d);arch/x86/kernel/cpu/resctrl/ctrlmondata.c +1
-1@@ -563,7 +563,7 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg) r = &rdt_resources_all[resid].r_resctrl; d =rdt_find_domain (r, domid,NULL ); -if (IS_ERR_OR_NULL (d)) { +if (!d) { ret = -ENOENT ; goto out; }arch/x86/kernel/cpu/resctrl/pseudo_lock.c +5
-1@@ -292,10 +292,14 @@ static void pseudo_lock_region_clear(struct pseudo_lock_region *plr)*/ static int pseudo_lock_region_init (struct pseudo_lock_region *plr) { +enum resctrl_scope scope = plr->s->res->scope;struct cpu_cacheinfo *ci;int ret;int i; +if (WARN_ON_ONCE (scope !=RESCTRL_L2_CACHE && scope !=RESCTRL_L3_CACHE )) +return -ENODEV ; +/* Pick the first cpu we find that is associated with the cache. */ plr->cpu =cpumask_first (&plr->d->cpu_mask);@@ -311,7 +315,7 @@ static int pseudo_lock_region_init(struct pseudo_lock_region *plr) plr->size =rdtgroup_cbm_to_size (plr->s->res, plr->d, plr->cbm);for (i =0 ; i < ci->num_leaves; i++) { -if (ci->info_list[i].level == plr->s->res->cache_level) { +if (ci->info_list[i].level == scope) { plr->line_size = ci->info_list[i].coherency_line_size;return 0 ; }arch/x86/kernel/cpu/resctrl/rdtgroup.c +4
-1@@ -1413,10 +1413,13 @@ unsigned int rdtgroup_cbm_to_size(struct rdt_resource *r,unsigned int size =0 ;int num_b, i; +if (WARN_ON_ONCE (r->scope !=RESCTRL_L2_CACHE && r->scope !=RESCTRL_L3_CACHE )) +return size; + num_b =bitmap_weight (&cbm, r->cache.cbm_len); ci =get_cpu_cacheinfo (cpumask_any (&d->cpu_mask));for (i =0 ; i < ci->num_leaves; i++) { -if (ci->info_list[i].level == r->cache_level) { +if (ci->info_list[i].level == r->scope) { size = ci->info_list[i].size / r->cache.cbm_len * num_b;break ; }
Tony Luck
maintainerPATCH v13 2/8 x86/resctrl: Prepare to split rdt_domain structure
In reply to Tony LuckThe rdt_domain structure is used for both control and monitor features. It is about to be split into separate structures for these two usages because the scope for control and monitoring features for a resource will be different for future resources.
To allow for common code that scans a list of domains looking for a specific domain id, move all the common fields ("list", "id", "cpu_mask") into their own structure within the rdt_domain structure.
--- include/linux/resctrl.h | 16 ++++-- arch/x86/kernel/cpu/resctrl/core.c | 26 +++++----- arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 22 ++++----- arch/x86/kernel/cpu/resctrl/monitor.c | 10 ++-- arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 14 +++--- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 60 +++++++++++------------ 6 files changed, 78 insertions(+), 70 deletions(-)
include/linux/resctrl.h +12 -4
@@ -53,10 +53,20 @@ struct resctrl_staged_config { };/** -* struct rdt_domain - group of CPUs sharing a resctrl resource +* struct rdt_domain_hdr - common header for different domain types * @list: all instances of this resource * @id: unique id for this instance * @cpu_mask: which CPUs share this resource +*/ +struct rdt_domain_hdr { +struct list_head list; +int id; +struct cpumask cpu_mask; +}; + +/** +* struct rdt_domain - group of CPUs sharing a resctrl resource +* @hdr: common header for different domain types * @rmid_busy_llc: bitmap of which limbo RMIDs are above threshold * @mbm_total: saved state for MBM total bandwidth * @mbm_local: saved state for MBM local bandwidth
@@ -71,9 +81,7 @@ struct resctrl_staged_config {* by closid */ struct rdt_domain { -struct list_head list; -int id; -struct cpumask cpu_mask; +struct rdt_domain_hdr hdr;unsigned long *rmid_busy_llc;struct mbm_state *mbm_total;struct mbm_state *mbm_local;
arch/x86/kernel/cpu/resctrl/core.c +13 -13
@@ -356,9 +356,9 @@ struct rdt_domain *get_domain_from_cpu(int cpu, struct rdt_resource *r) {struct rdt_domain *d; -list_for_each_entry (d, &r->domains, list) { +list_for_each_entry (d, &r->domains, hdr.list) {/* Find the domain that contains this CPU */ -if (cpumask_test_cpu (cpu, &d->cpu_mask)) +if (cpumask_test_cpu (cpu, &d->hdr.cpu_mask))return d; }
@@ -402,12 +402,12 @@ struct rdt_domain *rdt_find_domain(struct rdt_resource *r, int id,struct list_head *l;list_for_each (l, &r->domains) { - d = list_entry(l, struct rdt_domain, list); + d = list_entry(l, struct rdt_domain, hdr.list);/* When id is found, return its domain. */ -if (id == d->id) +if (id == d->hdr.id)return d;/* Stop searching when finding id's position in sorted list. */ -if (id < d->id) +if (id < d->hdr.id)break ; }
@@ -530,7 +530,7 @@ static void domain_add_cpu(int cpu, struct rdt_resource *r) d =rdt_find_domain (r, id, &add_pos);if (d) { -cpumask_set_cpu (cpu, &d->cpu_mask); +cpumask_set_cpu (cpu, &d->hdr.cpu_mask);if (r->cache.arch_has_per_cpu_cfg)rdt_domain_reconfigure_cdp (r);return ;
@@ -541,8 +541,8 @@ static void domain_add_cpu(int cpu, struct rdt_resource *r)return ; d = &hw_dom->d_resctrl; - d->id = id; -cpumask_set_cpu (cpu, &d->cpu_mask); + d->hdr.id = id; +cpumask_set_cpu (cpu, &d->hdr.cpu_mask);rdt_domain_reconfigure_cdp (r);
@@ -556,11 +556,11 @@ static void domain_add_cpu(int cpu, struct rdt_resource *r)return ; } -list_add_tail (&d->list, add_pos); +list_add_tail (&d->hdr.list, add_pos); err =resctrl_online_domain (r, d);if (err) { -list_del (&d->list); +list_del (&d->hdr.list);domain_free (hw_dom); } }
@@ -584,10 +584,10 @@ static void domain_remove_cpu(int cpu, struct rdt_resource *r) } hw_dom =resctrl_to_arch_dom (d); -cpumask_clear_cpu (cpu, &d->cpu_mask); -if (cpumask_empty (&d->cpu_mask)) { +cpumask_clear_cpu (cpu, &d->hdr.cpu_mask); +if (cpumask_empty (&d->hdr.cpu_mask)) {resctrl_offline_domain (r, d); -list_del (&d->list); +list_del (&d->hdr.list);/* * rdt_domain "d" is going to be freed below, so clear
arch/x86/kernel/cpu/resctrl/ctrlmondata.c +11 -11
@@ -67,7 +67,7 @@ int parse_bw(struct rdt_parse_data *data, struct resctrl_schema *s, cfg = &d->staged_config[s->conf_type];if (cfg->have_new_ctrl) { -rdt_last_cmd_printf ("Duplicate domain %d\n" , d->id); +rdt_last_cmd_printf ("Duplicate domain %d\n" , d->hdr.id);return -EINVAL ; }
@@ -146,7 +146,7 @@ int parse_cbm(struct rdt_parse_data *data, struct resctrl_schema *s, cfg = &d->staged_config[s->conf_type];if (cfg->have_new_ctrl) { -rdt_last_cmd_printf ("Duplicate domain %d\n" , d->id); +rdt_last_cmd_printf ("Duplicate domain %d\n" , d->hdr.id);return -EINVAL ; }
@@ -226,8 +226,8 @@ static int parse_line(char *line, struct resctrl_schema *s,return -EINVAL ; } dom =strim (dom); -list_for_each_entry (d, &r->domains, list) { -if (d->id == dom_id) { +list_for_each_entry (d, &r->domains, hdr.list) { +if (d->hdr.id == dom_id) { data.buf = dom; data.rdtgrp = rdtgrp;if (r->parse_ctrlval (&data, s, d))
@@ -274,7 +274,7 @@ static bool apply_config(struct rdt_hw_domain *hw_dom,struct rdt_domain *dom = &hw_dom->d_resctrl;if (cfg->new_ctrl != hw_dom->ctrl_val[idx]) { -cpumask_set_cpu (cpumask_any (&dom->cpu_mask), cpu_mask); +cpumask_set_cpu (cpumask_any (&dom->hdr.cpu_mask), cpu_mask); hw_dom->ctrl_val[idx] = cfg->new_ctrl;return true;
@@ -291,7 +291,7 @@ int resctrl_arch_update_one(struct rdt_resource *r, struct rdt_domain *d,u32 idx =get_config_index (closid, t);struct msr_param msr_param; -if (!cpumask_test_cpu (smp_processor_id (), &d->cpu_mask)) +if (!cpumask_test_cpu (smp_processor_id (), &d->hdr.cpu_mask))return -EINVAL ; hw_dom->ctrl_val[idx] = cfg_val;
@@ -318,7 +318,7 @@ int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid)return -ENOMEM ; msr_param.res =NULL ; -list_for_each_entry (d, &r->domains, list) { +list_for_each_entry (d, &r->domains, hdr.list) { hw_dom =resctrl_to_arch_dom (d);for (t =0 ; t <CDP_NUM_TYPES ; t++) { cfg = &hw_dom->d_resctrl.staged_config[t];
@@ -466,7 +466,7 @@ static void show_doms(struct seq_file *s, struct resctrl_schema *schema, int clou32 ctrl_val;seq_printf (s,"%*s:" , max_name_width, schema->name); -list_for_each_entry (dom, &r->domains, list) { +list_for_each_entry (dom, &r->domains, hdr.list) {if (sep)seq_puts (s,";" );
@@ -476,7 +476,7 @@ static void show_doms(struct seq_file *s, struct resctrl_schema *schema, int clo ctrl_val =resctrl_arch_get_config (r, dom, closid, schema->conf_type); -seq_printf (s, r->format_str, dom->id, max_data_width, +seq_printf (s, r->format_str, dom->hdr.id, max_data_width, ctrl_val); sep = true; }
@@ -505,7 +505,7 @@ int rdtgroup_schemata_show(struct kernfs_open_file *of, }else {seq_printf (s,"%s:%d=%x\n" , rdtgrp->plr->s->res->name, - rdtgrp->plr->d->id, + rdtgrp->plr->d->hdr.id, rdtgrp->plr->cbm); } }else {
@@ -536,7 +536,7 @@ void mon_event_read(struct rmid_read *rr, struct rdt_resource *r, rr->val =0 ; rr->first = first; -smp_call_function_any (&d->cpu_mask, mon_event_count, rr,1 ); +smp_call_function_any (&d->hdr.cpu_mask, mon_event_count, rr,1 ); }int rdtgroup_mondata_show (struct seq_file *m,void *arg)
arch/x86/kernel/cpu/resctrl/monitor.c +5 -5
@@ -238,7 +238,7 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain *d,u64 msr_val, chunks;int ret; -if (!cpumask_test_cpu (smp_processor_id (), &d->cpu_mask)) +if (!cpumask_test_cpu (smp_processor_id (), &d->hdr.cpu_mask))return -EINVAL ; ret =__rmid_read (rmid, eventid, &msr_val);
@@ -340,8 +340,8 @@ static void add_rmid_to_limbo(struct rmid_entry *entry) entry->busy =0 ; cpu =get_cpu (); -list_for_each_entry (d, &r->domains, list) { -if (cpumask_test_cpu (cpu, &d->cpu_mask)) { +list_for_each_entry (d, &r->domains, hdr.list) { +if (cpumask_test_cpu (cpu, &d->hdr.cpu_mask)) { err =resctrl_arch_rmid_read (r, d, entry->rmid,QOS_L3_OCCUP_EVENT_ID , &val);
@@ -661,7 +661,7 @@ void cqm_setup_limbo_handler(struct rdt_domain *dom, unsigned long delay_ms)unsigned long delay =msecs_to_jiffies (delay_ms);int cpu; - cpu =cpumask_any (&dom->cpu_mask); + cpu =cpumask_any (&dom->hdr.cpu_mask); dom->cqm_work_cpu = cpu;schedule_delayed_work_on (cpu, &dom->cqm_limbo, delay);
@@ -708,7 +708,7 @@ void mbm_setup_overflow_handler(struct rdt_domain *dom, unsigned long delay_ms)if (!static_branch_likely (&rdt_mon_enable_key))return ; - cpu =cpumask_any (&dom->cpu_mask); + cpu =cpumask_any (&dom->hdr.cpu_mask); dom->mbm_work_cpu = cpu;schedule_delayed_work_on (cpu, &dom->mbm_over, delay); }
arch/x86/kernel/cpu/resctrl/pseudo_lock.c +7 -7
@@ -221,7 +221,7 @@ static int pseudo_lock_cstates_constrain(struct pseudo_lock_region *plr)int cpu;int ret; -for_each_cpu (cpu, &plr->d->cpu_mask) { +for_each_cpu (cpu, &plr->d->hdr.cpu_mask) { pm_req =kzalloc (sizeof (*pm_req),GFP_KERNEL );if (!pm_req) {rdt_last_cmd_puts ("Failure to allocate memory for PM QoS\n" );
@@ -301,7 +301,7 @@ static int pseudo_lock_region_init(struct pseudo_lock_region *plr)return -ENODEV ;/* Pick the first cpu we find that is associated with the cache. */ - plr->cpu =cpumask_first (&plr->d->cpu_mask); + plr->cpu =cpumask_first (&plr->d->hdr.cpu_mask);if (!cpu_online (plr->cpu)) { rdt_last_cmd_printf("CPU %u associated with cache not online\n",
@@ -856,10 +856,10 @@ bool rdtgroup_pseudo_locked_in_hierarchy(struct rdt_domain *d)* associated with them. */ for_each_alloc_capable_rdt_resource (r) { -list_for_each_entry (d_i, &r->domains, list) { +list_for_each_entry (d_i, &r->domains, hdr.list) {if (d_i->plr)cpumask_or (cpu_with_psl, cpu_with_psl, - &d_i->cpu_mask); + &d_i->hdr.cpu_mask); } }
@@ -867,7 +867,7 @@ bool rdtgroup_pseudo_locked_in_hierarchy(struct rdt_domain *d)* Next test if new pseudo-locked region would intersect with * existing region. */ -if (cpumask_intersects (&d->cpu_mask, cpu_with_psl)) +if (cpumask_intersects (&d->hdr.cpu_mask, cpu_with_psl)) ret = true;free_cpumask_var (cpu_with_psl);
@@ -1199,7 +1199,7 @@ static int pseudo_lock_measure_cycles(struct rdtgroup *rdtgrp, int sel) } plr->thread_done =0 ; - cpu =cpumask_first (&plr->d->cpu_mask); + cpu =cpumask_first (&plr->d->hdr.cpu_mask);if (!cpu_online (cpu)) { ret = -ENODEV ; goto out;
@@ -1529,7 +1529,7 @@ static int pseudo_lock_dev_mmap(struct file *filp, struct vm_area_struct *vma)* may be scheduled elsewhere and invalidate entries in the * pseudo-locked region. */ -if (!cpumask_subset (current->cpus_ptr, &plr->d->cpu_mask)) { +if (!cpumask_subset (current->cpus_ptr, &plr->d->hdr.cpu_mask)) {mutex_unlock (&rdtgroup_mutex);return -EINVAL ; }
arch/x86/kernel/cpu/resctrl/rdtgroup.c +30 -30
220 lines not on this page · raw message
Signature · 1 line
2.41.0
Re: [PATCH v13 2/8] x86/resctrl: Prepare to split rdt_domain structure
Quoted 5 lines · Tony Luck
The
rdt_domainstructure is used for both control and monitor features. It is about to be split into separate structures for these two usages because the scope for control and monitoring features for a resource will be different for future resources.
Quoted 8 lines
To allow for common code that scans a list of domains looking for a specific domain id, move all the common fields ("list", "id", "
cpu_mask") into their own structure within therdt_domainstructure.Signed-off-by Tony Luck<[email protected]>Tested-by Shaopeng Tan<[email protected]>Reviewed-by Reinette Chatre<[email protected]>Reviewed-by Shaopeng Tan<[email protected]>
Quoted 575 lines
--- include/linux/resctrl.h | 16 ++++-- arch/x86/kernel/cpu/resctrl/core.c | 26 +++++----- arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 22 ++++----- arch/x86/kernel/cpu/resctrl/monitor.c | 10 ++-- arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 14 +++--- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 60 +++++++++++------------ 6 files changed, 78 insertions(+), 70 deletions(-)include/linux/resctrl.h +12
-4@@ -53,10 +53,20 @@ struct resctrl_staged_config { };/** -* struct rdt_domain - group of CPUs sharing a resctrl resource +* struct rdt_domain_hdr - common header for different domain types * @list: all instances of this resource * @id: unique id for this instance * @cpu_mask: which CPUs share this resource +*/ +struct rdt_domain_hdr { +struct list_head list; +int id; +struct cpumask cpu_mask; +}; + +/** +* struct rdt_domain - group of CPUs sharing a resctrl resource +* @hdr: common header for different domain types * @rmid_busy_llc: bitmap of which limbo RMIDs are above threshold * @mbm_total: saved state for MBM total bandwidth * @mbm_local: saved state for MBM local bandwidth @@ -71,9 +81,7 @@ struct resctrl_staged_config {* by closid */ struct rdt_domain { -struct list_head list; -int id; -struct cpumask cpu_mask; +struct rdt_domain_hdr hdr;unsigned long *rmid_busy_llc;struct mbm_state *mbm_total;struct mbm_state *mbm_local;arch/x86/kernel/cpu/resctrl/core.c +13
-13@@ -356,9 +356,9 @@ struct rdt_domain *get_domain_from_cpu(int cpu, struct rdt_resource *r) {struct rdt_domain *d; -list_for_each_entry (d, &r->domains, list) { +list_for_each_entry (d, &r->domains, hdr.list) {/* Find the domain that contains this CPU */ -if (cpumask_test_cpu (cpu, &d->cpu_mask)) +if (cpumask_test_cpu (cpu, &d->hdr.cpu_mask))return d; }@@ -402,12 +402,12 @@ struct rdt_domain *rdt_find_domain(struct rdt_resource *r, int id,struct list_head *l;list_for_each (l, &r->domains) { - d = list_entry(l, struct rdt_domain, list); + d = list_entry(l, struct rdt_domain, hdr.list);/* When id is found, return its domain. */ -if (id == d->id) +if (id == d->hdr.id)return d;/* Stop searching when finding id's position in sorted list. */ -if (id < d->id) +if (id < d->hdr.id)break ; }@@ -530,7 +530,7 @@ static void domain_add_cpu(int cpu, struct rdt_resource *r) d =rdt_find_domain (r, id, &add_pos);if (d) { -cpumask_set_cpu (cpu, &d->cpu_mask); +cpumask_set_cpu (cpu, &d->hdr.cpu_mask);if (r->cache.arch_has_per_cpu_cfg)rdt_domain_reconfigure_cdp (r);return ;@@ -541,8 +541,8 @@ static void domain_add_cpu(int cpu, struct rdt_resource *r)return ; d = &hw_dom->d_resctrl; - d->id = id; -cpumask_set_cpu (cpu, &d->cpu_mask); + d->hdr.id = id; +cpumask_set_cpu (cpu, &d->hdr.cpu_mask);rdt_domain_reconfigure_cdp (r);@@ -556,11 +556,11 @@ static void domain_add_cpu(int cpu, struct rdt_resource *r)return ; } -list_add_tail (&d->list, add_pos); +list_add_tail (&d->hdr.list, add_pos); err =resctrl_online_domain (r, d);if (err) { -list_del (&d->list); +list_del (&d->hdr.list);domain_free (hw_dom); } }@@ -584,10 +584,10 @@ static void domain_remove_cpu(int cpu, struct rdt_resource *r) } hw_dom =resctrl_to_arch_dom (d); -cpumask_clear_cpu (cpu, &d->cpu_mask); -if (cpumask_empty (&d->cpu_mask)) { +cpumask_clear_cpu (cpu, &d->hdr.cpu_mask); +if (cpumask_empty (&d->hdr.cpu_mask)) {resctrl_offline_domain (r, d); -list_del (&d->list); +list_del (&d->hdr.list);/* * rdt_domain "d" is going to be freed below, so clear arch/x86/kernel/cpu/resctrl/ctrlmondata.c +11
-11@@ -67,7 +67,7 @@ int parse_bw(struct rdt_parse_data *data, struct resctrl_schema *s, cfg = &d->staged_config[s->conf_type];if (cfg->have_new_ctrl) { -rdt_last_cmd_printf ("Duplicate domain %d\n" , d->id); +rdt_last_cmd_printf ("Duplicate domain %d\n" , d->hdr.id);return -EINVAL ; }@@ -146,7 +146,7 @@ int parse_cbm(struct rdt_parse_data *data, struct resctrl_schema *s, cfg = &d->staged_config[s->conf_type];if (cfg->have_new_ctrl) { -rdt_last_cmd_printf ("Duplicate domain %d\n" , d->id); +rdt_last_cmd_printf ("Duplicate domain %d\n" , d->hdr.id);return -EINVAL ; }@@ -226,8 +226,8 @@ static int parse_line(char *line, struct resctrl_schema *s,return -EINVAL ; } dom =strim (dom); -list_for_each_entry (d, &r->domains, list) { -if (d->id == dom_id) { +list_for_each_entry (d, &r->domains, hdr.list) { +if (d->hdr.id == dom_id) { data.buf = dom; data.rdtgrp = rdtgrp;if (r->parse_ctrlval (&data, s, d))@@ -274,7 +274,7 @@ static bool apply_config(struct rdt_hw_domain *hw_dom,struct rdt_domain *dom = &hw_dom->d_resctrl;if (cfg->new_ctrl != hw_dom->ctrl_val[idx]) { -cpumask_set_cpu (cpumask_any (&dom->cpu_mask), cpu_mask); +cpumask_set_cpu (cpumask_any (&dom->hdr.cpu_mask), cpu_mask); hw_dom->ctrl_val[idx] = cfg->new_ctrl;return true;@@ -291,7 +291,7 @@ int resctrl_arch_update_one(struct rdt_resource *r, struct rdt_domain *d,u32 idx =get_config_index (closid, t);struct msr_param msr_param; -if (!cpumask_test_cpu (smp_processor_id (), &d->cpu_mask)) +if (!cpumask_test_cpu (smp_processor_id (), &d->hdr.cpu_mask))return -EINVAL ; hw_dom->ctrl_val[idx] = cfg_val;@@ -318,7 +318,7 @@ int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid)return -ENOMEM ; msr_param.res =NULL ; -list_for_each_entry (d, &r->domains, list) { +list_for_each_entry (d, &r->domains, hdr.list) { hw_dom =resctrl_to_arch_dom (d);for (t =0 ; t <CDP_NUM_TYPES ; t++) { cfg = &hw_dom->d_resctrl.staged_config[t];@@ -466,7 +466,7 @@ static void show_doms(struct seq_file *s, struct resctrl_schema *schema, int clou32 ctrl_val;seq_printf (s,"%*s:" , max_name_width, schema->name); -list_for_each_entry (dom, &r->domains, list) { +list_for_each_entry (dom, &r->domains, hdr.list) {if (sep)seq_puts (s,";" );@@ -476,7 +476,7 @@ static void show_doms(struct seq_file *s, struct resctrl_schema *schema, int clo ctrl_val =resctrl_arch_get_config (r, dom, closid, schema->conf_type); -seq_printf (s, r->format_str, dom->id, max_data_width, +seq_printf (s, r->format_str, dom->hdr.id, max_data_width, ctrl_val); sep = true; }@@ -505,7 +505,7 @@ int rdtgroup_schemata_show(struct kernfs_open_file *of, }else {seq_printf (s,"%s:%d=%x\n" , rdtgrp->plr->s->res->name, - rdtgrp->plr->d->id, + rdtgrp->plr->d->hdr.id, rdtgrp->plr->cbm); } }else {@@ -536,7 +536,7 @@ void mon_event_read(struct rmid_read *rr, struct rdt_resource *r, rr->val =0 ; rr->first = first; -smp_call_function_any (&d->cpu_mask, mon_event_count, rr,1 ); +smp_call_function_any (&d->hdr.cpu_mask, mon_event_count, rr,1 ); }int rdtgroup_mondata_show (struct seq_file *m,void *arg)arch/x86/kernel/cpu/resctrl/monitor.c +5
-5@@ -238,7 +238,7 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain *d,u64 msr_val, chunks;int ret; -if (!cpumask_test_cpu (smp_processor_id (), &d->cpu_mask)) +if (!cpumask_test_cpu (smp_processor_id (), &d->hdr.cpu_mask))return -EINVAL ; ret =__rmid_read (rmid, eventid, &msr_val);@@ -340,8 +340,8 @@ static void add_rmid_to_limbo(struct rmid_entry *entry) entry->busy =0 ; cpu =get_cpu (); -list_for_each_entry (d, &r->domains, list) { -if (cpumask_test_cpu (cpu, &d->cpu_mask)) { +list_for_each_entry (d, &r->domains, hdr.list) { +if (cpumask_test_cpu (cpu, &d->hdr.cpu_mask)) { err =resctrl_arch_rmid_read (r, d, entry->rmid,QOS_L3_OCCUP_EVENT_ID , &val);@@ -661,7 +661,7 @@ void cqm_setup_limbo_handler(struct rdt_domain *dom, unsigned long delay_ms)unsigned long delay =msecs_to_jiffies (delay_ms);int cpu; - cpu =cpumask_any (&dom->cpu_mask); + cpu =cpumask_any (&dom->hdr.cpu_mask); dom->cqm_work_cpu = cpu;schedule_delayed_work_on (cpu, &dom->cqm_limbo, delay);@@ -708,7 +708,7 @@ void mbm_setup_overflow_handler(struct rdt_domain *dom, unsigned long delay_ms)if (!static_branch_likely (&rdt_mon_enable_key))return ; - cpu =cpumask_any (&dom->cpu_mask); + cpu =cpumask_any (&dom->hdr.cpu_mask); dom->mbm_work_cpu = cpu;schedule_delayed_work_on (cpu, &dom->mbm_over, delay); }arch/x86/kernel/cpu/resctrl/pseudo_lock.c +7
-7@@ -221,7 +221,7 @@ static int pseudo_lock_cstates_constrain(struct pseudo_lock_region *plr)int cpu;int ret; -for_each_cpu (cpu, &plr->d->cpu_mask) { +for_each_cpu (cpu, &plr->d->hdr.cpu_mask) { pm_req =kzalloc (sizeof (*pm_req),GFP_KERNEL );if (!pm_req) {rdt_last_cmd_puts ("Failure to allocate memory for PM QoS\n" );@@ -301,7 +301,7 @@ static int pseudo_lock_region_init(struct pseudo_lock_region *plr)return -ENODEV ;/* Pick the first cpu we find that is associated with the cache. */ - plr->cpu =cpumask_first (&plr->d->cpu_mask); + plr->cpu =cpumask_first (&plr->d->hdr.cpu_mask);if (!cpu_online (plr->cpu)) { rdt_last_cmd_printf("CPU %u associated with cache not online\n",@@ -856,10 +856,10 @@ bool rdtgroup_pseudo_locked_in_hierarchy(struct rdt_domain *d)* associated with them. */ for_each_alloc_capable_rdt_resource (r) { -list_for_each_entry (d_i, &r->domains, list) { +list_for_each_entry (d_i, &r->domains, hdr.list) {if (d_i->plr)cpumask_or (cpu_with_psl, cpu_with_psl, - &d_i->cpu_mask); + &d_i->hdr.cpu_mask); } }@@ -867,7 +867,7 @@ bool rdtgroup_pseudo_locked_in_hierarchy(struct rdt_domain *d)* Next test if new pseudo-locked region would intersect with * existing region. */ -if (cpumask_intersects (&d->cpu_mask, cpu_with_psl)) +if (cpumask_intersects (&d->hdr.cpu_mask, cpu_with_psl)) ret = true;free_cpumask_var (cpu_with_psl);@@ -1199,7 +1199,7 @@ static int pseudo_lock_measure_cycles(struct rdtgroup *rdtgrp, int sel) } plr->thread_done =0 ; - cpu =cpumask_first (&plr->d->cpu_mask); + cpu =cpumask_first (&plr->d->hdr.cpu_mask);if (!cpu_online (cpu)) { ret = -ENODEV ; goto out;@@ -1529,7 +1529,7 @@ static int pseudo_lock_dev_mmap(struct file *filp, struct vm_area_struct *vma)* may be scheduled elsewhere and invalidate entries in the * pseudo-locked region. */ -if (!cpumask_subset (current->cpus_ptr, &plr->d->cpu_mask)) { +if (!cpumask_subset (current->cpus_ptr, &plr->d->hdr.cpu_mask)) {mutex_unlock (&rdtgroup_mutex);return -EINVAL ; }arch/x86/kernel/cpu/resctrl/rdtgroup.c +30
-30@@ -91,7 +91,7 @@ void rdt_staged_configs_clear(void)lockdep_assert_held (&rdtgroup_mutex);for_each_alloc_capable_rdt_resource (r) { -list_for_each_entry (dom, &r->domains, list) +list_for_each_entry (dom, &r->domains, hdr.list)memset (dom->staged_config,0 ,sizeof (dom->staged_config)); } }@@ -295,7 +295,7 @@ static int rdtgroup_cpus_show(struct kernfs_open_file *of,rdt_last_cmd_puts ("Cache domain offline\n" ); ret = -ENODEV ; }else { - mask = &rdtgrp->plr->d->cpu_mask; + mask = &rdtgrp->plr->d->hdr.cpu_mask;seq_printf (s,is_cpu_list (of) ?"%*pbl\n" :"%*pb\n" ,cpumask_pr_args (mask));@@ -984,12 +984,12 @@ static int rdt_bit_usage_show(struct kernfs_open_file *of,mutex_lock (&rdtgroup_mutex); hw_shareable = r->cache.shareable_bits; -list_for_each_entry (dom, &r->domains, list) { +list_for_each_entry (dom, &r->domains, hdr.list) {if (sep)seq_putc (seq,';' ); sw_shareable =0 ; exclusive =0 ; -seq_printf (seq,"%d=" , dom->id); +seq_printf (seq,"%d=" , dom->hdr.id);for (i =0 ; i <closids_supported (); i++) {if (!closid_allocated (i))continue ;@@ -1302,7 +1302,7 @@ static bool rdtgroup_mode_test_exclusive(struct rdtgroup *rdtgrp)if (r->rid ==RDT_RESOURCE_MBA || r->rid ==RDT_RESOURCE_SMBA )continue ; has_cache = true; -list_for_each_entry (d, &r->domains, list) { +list_for_each_entry (d, &r->domains, hdr.list) { ctrl =resctrl_arch_get_config (r, d, closid, s->conf_type);if (rdtgroup_cbm_overlaps (s, d, ctrl, closid, false)) {@@ -1417,7 +1417,7 @@ unsigned int rdtgroup_cbm_to_size(struct rdt_resource *r,return size; num_b =bitmap_weight (&cbm, r->cache.cbm_len); - ci =get_cpu_cacheinfo (cpumask_any (&d->cpu_mask)); + ci =get_cpu_cacheinfo (cpumask_any (&d->hdr.cpu_mask));for (i =0 ; i < ci->num_leaves; i++) {if (ci->info_list[i].level == r->scope) { size = ci->info_list[i].size / r->cache.cbm_len * num_b;@@ -1465,7 +1465,7 @@ static int rdtgroup_size_show(struct kernfs_open_file *of, size =rdtgroup_cbm_to_size (rdtgrp->plr->s->res, rdtgrp->plr->d, rdtgrp->plr->cbm); -seq_printf (s,"%d=%u\n" , rdtgrp->plr->d->id, size); +seq_printf (s,"%d=%u\n" , rdtgrp->plr->d->hdr.id, size); } goto out; }@@ -1477,7 +1477,7 @@ static int rdtgroup_size_show(struct kernfs_open_file *of, type = schema->conf_type; sep = false;seq_printf (s,"%*s:" , max_name_width, schema->name); -list_for_each_entry (d, &r->domains, list) { +list_for_each_entry (d, &r->domains, hdr.list) {if (sep)seq_putc (s,';' );if (rdtgrp->mode ==RDT_MODE_PSEUDO_LOCKSETUP ) {@@ -1495,7 +1495,7 @@ static int rdtgroup_size_show(struct kernfs_open_file *of,else size =rdtgroup_cbm_to_size (r, d, ctrl); } -seq_printf (s,"%d=%u" , d->id, size); +seq_printf (s,"%d=%u" , d->hdr.id, size); sep = true; }seq_putc (s,'\n' );@@ -1555,7 +1555,7 @@ static void mon_event_config_read(void *info)static void mondata_config_read (struct rdt_domain *d,struct mon_config_info *mon_info) { -smp_call_function_any (&d->cpu_mask, mon_event_config_read, mon_info,1 ); +smp_call_function_any (&d->hdr.cpu_mask, mon_event_config_read, mon_info,1 ); }static int mbm_config_show (struct seq_file *s,struct rdt_resource *r,u32 evtid)@@ -1566,7 +1566,7 @@ static int mbm_config_show(struct seq_file *s, struct rdt_resource *r, u32 evtidmutex_lock (&rdtgroup_mutex); -list_for_each_entry (dom, &r->domains, list) { +list_for_each_entry (dom, &r->domains, hdr.list) {if (sep)seq_puts (s,";" );@@ -1574,7 +1574,7 @@ static int mbm_config_show(struct seq_file *s, struct rdt_resource *r, u32 evtid mon_info.evtid = evtid;mondata_config_read (dom, &mon_info); -seq_printf (s,"%d=0x%02x" , dom->id, mon_info.mon_config); +seq_printf (s,"%d=0x%02x" , dom->hdr.id, mon_info.mon_config); sep = true; }seq_puts (s,"\n" );@@ -1646,7 +1646,7 @@ static int mbm_config_write_domain(struct rdt_resource *r,* are scoped at the domain level. Writing any of these MSRs * on one CPU is observed by all the CPUs in the domain. */ -smp_call_function_any (&d->cpu_mask, mon_event_config_write, +smp_call_function_any (&d->hdr.cpu_mask, mon_event_config_write, &mon_info,1 );/* @@ -1689,8 +1689,8 @@ static int mon_config_write(struct rdt_resource *r, char *tok, u32 evtid)return -EINVAL ; } -list_for_each_entry (d, &r->domains, list) { -if (d->id == dom_id) { +list_for_each_entry (d, &r->domains, hdr.list) { +if (d->hdr.id == dom_id) { ret =mbm_config_write_domain (r, d, evtid, val);if (ret)return -EINVAL ;@@ -2232,14 +2232,14 @@ static int set_cache_qos_cfg(int level, bool enable)return -ENOMEM ; r_l = &rdt_resources_all[level].r_resctrl; -list_for_each_entry (d, &r_l->domains, list) { +list_for_each_entry (d, &r_l->domains, hdr.list) {if (r_l->cache.arch_has_per_cpu_cfg)/* Pick all the CPUs in the domain instance */ -for_each_cpu (cpu, &d->cpu_mask) +for_each_cpu (cpu, &d->hdr.cpu_mask)cpumask_set_cpu (cpu, cpu_mask);else /* Pick one CPU from each domain instance to update MSR */ -cpumask_set_cpu (cpumask_any (&d->cpu_mask), cpu_mask); +cpumask_set_cpu (cpumask_any (&d->hdr.cpu_mask), cpu_mask); }/* Update QOS_CFG MSR on all the CPUs in cpu_mask */ @@ -2268,7 +2268,7 @@ void rdt_domain_reconfigure_cdp(struct rdt_resource *r)static int mba_sc_domain_allocate (struct rdt_resource *r,struct rdt_domain *d) {u32 num_closid =resctrl_arch_get_num_closid (r); -int cpu =cpumask_any (&d->cpu_mask); +int cpu =cpumask_any (&d->hdr.cpu_mask);int i; d->mbps_val = kcalloc_node(num_closid, sizeof(*d->mbps_val),@@ -2317,7 +2317,7 @@ static int set_mba_sc(bool mba_sc) r->membw.mba_sc = mba_sc; -list_for_each_entry (d, &r->domains, list) { +list_for_each_entry (d, &r->domains, hdr.list) {for (i =0 ; i < num_closid; i++) d->mbps_val[i] =MBA_MAX_MBPS ; }@@ -2653,7 +2653,7 @@ static int rdt_get_tree(struct fs_context *fc)if (is_mbm_enabled ()) { r = &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl; -list_for_each_entry (dom, &r->domains, list) +list_for_each_entry (dom, &r->domains, hdr.list)mbm_setup_overflow_handler (dom,MBM_OVERFLOW_INTERVAL ); }@@ -2780,9 +2780,9 @@ static int reset_all_ctrls(struct rdt_resource *r)* CBMs in all domains to the maximum mask value. Pick one CPU * from each domain to update the MSRs below. */ -list_for_each_entry (d, &r->domains, list) { +list_for_each_entry (d, &r->domains, hdr.list) { hw_dom =resctrl_to_arch_dom (d); -cpumask_set_cpu (cpumask_any (&d->cpu_mask), cpu_mask); +cpumask_set_cpu (cpumask_any (&d->hdr.cpu_mask), cpu_mask);for (i =0 ; i < hw_res->num_closid; i++) hw_dom->ctrl_val[i] = r->default_ctrl;@@ -2986,7 +2986,7 @@ static int mkdir_mondata_subdir(struct kernfs_node *parent_kn,char name[32 ];int ret; -sprintf (name,"mon_%s_%02d" , r->name, d->id); +sprintf (name,"mon_%s_%02d" , r->name, d->hdr.id);/* create the directory */ kn =kernfs_create_dir (parent_kn, name, parent_kn->mode, prgrp);if (IS_ERR (kn))@@ -3002,7 +3002,7 @@ static int mkdir_mondata_subdir(struct kernfs_node *parent_kn, } priv.u.rid = r->rid; - priv.u.domid = d->id; + priv.u.domid = d->hdr.id;list_for_each_entry (mevt, &r->evt_list, list) { priv.u.evtid = mevt->evtid; ret =mon_addfile (kn, mevt->name, priv.priv);@@ -3050,7 +3050,7 @@ static int mkdir_mondata_subdir_alldom(struct kernfs_node *parent_kn,struct rdt_domain *dom;int ret; -list_for_each_entry (dom, &r->domains, list) { +list_for_each_entry (dom, &r->domains, hdr.list) { ret =mkdir_mondata_subdir (parent_kn, dom, r, prgrp);if (ret)return ret;@@ -3209,7 +3209,7 @@ static int __init_one_rdt_domain(struct rdt_domain *d, struct resctrl_schema *s,*/ tmp_cbm = cfg->new_ctrl;if (bitmap_weight (&tmp_cbm, r->cache.cbm_len) < r->cache.min_cbm_bits) { -rdt_last_cmd_printf ("No space on %s:%d\n" , s->name, d->id); +rdt_last_cmd_printf ("No space on %s:%d\n" , s->name, d->hdr.id);return -ENOSPC ; } cfg->have_new_ctrl = true;@@ -3232,7 +3232,7 @@ static int rdtgroup_init_cat(struct resctrl_schema *s, u32 closid)struct rdt_domain *d;int ret; -list_for_each_entry (d, &s->res->domains, list) { +list_for_each_entry (d, &s->res->domains, hdr.list) { ret =__init_one_rdt_domain (d, s, closid);if (ret <0 )return ret;@@ -3247,7 +3247,7 @@ static void rdtgroup_init_mba(struct rdt_resource *r, u32 closid)struct resctrl_staged_config *cfg;struct rdt_domain *d; -list_for_each_entry (d, &r->domains, list) { +list_for_each_entry (d, &r->domains, hdr.list) {if (is_mba_sc (r)) { d->mbps_val[closid] =MBA_MAX_MBPS ;continue ;@@ -3864,7 +3864,7 @@ void resctrl_offline_domain(struct rdt_resource *r, struct rdt_domain *d)* per domain monitor data directories. */ if (static_branch_unlikely (&rdt_mon_enable_key)) -rmdir_mondata_subdir_allrdtgrp (r, d->id); +rmdir_mondata_subdir_allrdtgrp (r, d->hdr.id);if (is_mbm_enabled ())cancel_delayed_work (&d->mbm_over);
Tony Luck
maintainerPATCH v13 3/8 x86/resctrl: Prepare for different scope for control/monitor operations
In reply to Tony LuckResctrl assumes that control and monitor operations on a resource are performed at the same scope.
Prepare for systems that use different scope (specifically Intel needs to split the RDT_RESOURCE_L3 resource to use L3 scope for cache control and NODE scope for cache occupancy and memory bandwidth monitoring).
Create separate domain lists for control and monitor operations.
Note that errors during initialization of either control or monitor functions on a domain would previously result in that domain being excluded from both control and monitor operations. Now the domains are allocated independently it is no longer required to disable both control and monitor operations if either fail.
--- include/linux/resctrl.h | 25 ++- arch/x86/kernel/cpu/resctrl/internal.h | 6 +- arch/x86/kernel/cpu/resctrl/core.c | 211 ++++++++++++++++------ arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 12 +- arch/x86/kernel/cpu/resctrl/monitor.c | 4 +- arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 4 +- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 55 +++--- 7 files changed, 220 insertions(+), 97 deletions(-)
include/linux/resctrl.h +19 -6
@@ -52,15 +52,22 @@ struct resctrl_staged_config {bool have_new_ctrl; }; +enum resctrl_domain_type { +RESCTRL_CTRL_DOMAIN , +RESCTRL_MON_DOMAIN , +}; +/** * struct rdt_domain_hdr - common header for different domain types * @list: all instances of this resource * @id: unique id for this instance +* @type: type of this instance * @cpu_mask: which CPUs share this resource */ struct rdt_domain_hdr {struct list_head list;int id; +enum resctrl_domain_type type;struct cpumask cpu_mask; };
@@ -163,10 +170,12 @@ enum resctrl_scope {* @alloc_capable: Is allocation available on this machine * @mon_capable: Is monitor feature available on this machine * @num_rmid: Number of RMIDs available -* @scope: Scope of this resource +* @ctrl_scope: Scope of this resource for control functions +* @mon_scope: Scope of this resource for monitor functions * @cache: Cache allocation related data * @membw: If the component has bandwidth controls, their properties. -* @domains: All domains for this resource +* @ctrl_domains: Control domains for this resource +* @mon_domains: Monitor domains for this resource * @name: Name to use in "schemata" file. * @data_width: Character width of data when displaying * @default_ctrl: Specifies default cache cbm or memory B/W percent.
@@ -181,10 +190,12 @@ struct rdt_resource {bool alloc_capable;bool mon_capable;int num_rmid; -enum resctrl_scope scope; +enum resctrl_scope ctrl_scope; +enum resctrl_scope mon_scope;struct resctrl_cache cache;struct resctrl_membw membw; -struct list_head domains; +struct list_head ctrl_domains; +struct list_head mon_domains;char *name;int data_width;u32 default_ctrl;
@@ -230,8 +241,10 @@ int resctrl_arch_update_one(struct rdt_resource *r, struct rdt_domain *d,u32 resctrl_arch_get_config (struct rdt_resource *r,struct rdt_domain *d,u32 closid,enum resctrl_conf_type type); -int resctrl_online_domain (struct rdt_resource *r,struct rdt_domain *d); -void resctrl_offline_domain (struct rdt_resource *r,struct rdt_domain *d); +int resctrl_online_ctrl_domain (struct rdt_resource *r,struct rdt_domain *d); +int resctrl_online_mon_domain (struct rdt_resource *r,struct rdt_domain *d); +void resctrl_offline_ctrl_domain (struct rdt_resource *r,struct rdt_domain *d); +void resctrl_offline_mon_domain (struct rdt_resource *r,struct rdt_domain *d);/** * resctrl_arch_rmid_read() - Read the eventid counter corresponding to rmid
arch/x86/kernel/cpu/resctrl/internal.h +3 -3
@@ -520,8 +520,8 @@ 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 *rdt_find_domain (struct rdt_resource *r,int id, -struct list_head **pos); +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,
@@ -540,7 +540,7 @@ int rdt_pseudo_lock_init(void);void rdt_pseudo_lock_release (void );int rdtgroup_pseudo_lock_create (struct rdtgroup *rdtgrp);void rdtgroup_pseudo_lock_remove (struct rdtgroup *rdtgrp); -struct rdt_domain *get_domain_from_cpu (int cpu,struct rdt_resource *r); +struct rdt_domain *get_ctrl_domain_from_cpu (int cpu,struct rdt_resource *r);int closids_supported (void );void closid_free (int closid);int alloc_rmid (void );
arch/x86/kernel/cpu/resctrl/core.c +157 -54
338 lines not on this page · raw message
arch/x86/kernel/cpu/resctrl/ctrlmondata.c +7 -5
@@ -226,7 +226,7 @@ static int parse_line(char *line, struct resctrl_schema *s,return -EINVAL ; } dom =strim (dom); -list_for_each_entry (d, &r->domains, hdr.list) { +list_for_each_entry (d, &r->ctrl_domains, hdr.list) {if (d->hdr.id == dom_id) { data.buf = dom; data.rdtgrp = rdtgrp;
@@ -318,7 +318,7 @@ int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid)return -ENOMEM ; msr_param.res =NULL ; -list_for_each_entry (d, &r->domains, hdr.list) { +list_for_each_entry (d, &r->ctrl_domains, hdr.list) { hw_dom =resctrl_to_arch_dom (d);for (t =0 ; t <CDP_NUM_TYPES ; t++) { cfg = &hw_dom->d_resctrl.staged_config[t];
@@ -466,7 +466,7 @@ static void show_doms(struct seq_file *s, struct resctrl_schema *schema, int clou32 ctrl_val;seq_printf (s,"%*s:" , max_name_width, schema->name); -list_for_each_entry (dom, &r->domains, hdr.list) { +list_for_each_entry (dom, &r->ctrl_domains, hdr.list) {if (sep)seq_puts (s,";" );
@@ -542,6 +542,7 @@ void mon_event_read(struct rmid_read *rr, struct rdt_resource *r,int rdtgroup_mondata_show (struct seq_file *m,void *arg) {struct kernfs_open_file *of = m->private; +struct rdt_domain_hdr *hdr;u32 resid, evtid, domid;struct rdtgroup *rdtgrp;struct rdt_resource *r;
@@ -562,11 +563,12 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg) evtid = md.u.evtid; r = &rdt_resources_all[resid].r_resctrl; - d =rdt_find_domain (r, domid,NULL ); -if (!d) { + hdr =rdt_find_domain (&r->mon_domains, domid,NULL ); +if (!hdr ||WARN_ON_ONCE (hdr->type !=RESCTRL_MON_DOMAIN )) { ret = -ENOENT ; goto out; } + d = container_of(hdr, struct rdt_domain, hdr);mon_event_read (&rr, r, d, rdtgrp, evtid, false);
arch/x86/kernel/cpu/resctrl/monitor.c +2 -2
@@ -340,7 +340,7 @@ static void add_rmid_to_limbo(struct rmid_entry *entry) entry->busy =0 ; cpu =get_cpu (); -list_for_each_entry (d, &r->domains, hdr.list) { +list_for_each_entry (d, &r->mon_domains, hdr.list) {if (cpumask_test_cpu (cpu, &d->hdr.cpu_mask)) { err = resctrl_arch_rmid_read(r, d, entry->rmid, QOS_L3_OCCUP_EVENT_ID,
@@ -535,7 +535,7 @@ static void update_mba_bw(struct rdtgroup *rgrp, struct rdt_domain *dom_mbm) rmid = rgrp->mon.rmid; pmbm_data = &dom_mbm->mbm_local[rmid]; - dom_mba =get_domain_from_cpu (smp_processor_id (), r_mba); + dom_mba =get_ctrl_domain_from_cpu (smp_processor_id (), r_mba);if (!dom_mba) {pr_warn_once ("Failure to get domain for MBA update\n" );return ;
arch/x86/kernel/cpu/resctrl/pseudo_lock.c +2 -2
@@ -292,7 +292,7 @@ static void pseudo_lock_region_clear(struct pseudo_lock_region *plr)*/ static int pseudo_lock_region_init (struct pseudo_lock_region *plr) { -enum resctrl_scope scope = plr->s->res->scope; +enum resctrl_scope scope = plr->s->res->ctrl_scope;struct cpu_cacheinfo *ci;int ret;int i;
@@ -856,7 +856,7 @@ bool rdtgroup_pseudo_locked_in_hierarchy(struct rdt_domain *d)* associated with them. */ for_each_alloc_capable_rdt_resource (r) { -list_for_each_entry (d_i, &r->domains, hdr.list) { +list_for_each_entry (d_i, &r->ctrl_domains, hdr.list) {if (d_i->plr)cpumask_or (cpu_with_psl, cpu_with_psl, &d_i->hdr.cpu_mask);
arch/x86/kernel/cpu/resctrl/rdtgroup.c +30 -25
170 lines not on this page · raw message
Signature · 1 line
2.41.0
Re: [PATCH v13 3/8] x86/resctrl: Prepare for different scope for control/monitor operations
Quoted 15 lines · Tony Luck
Resctrl assumes that control and monitor operations on a resource are performed at the same scope.
Prepare for systems that use different scope (specifically Intel needs to split the
RDT_RESOURCE_L3resource to use L3 scope for cache control and NODE scope for cache occupancy and memory bandwidth monitoring).Create separate domain lists for control and monitor operations.
Note that errors during initialization of either control or monitor functions on a domain would previously result in that domain being excluded from both control and monitor operations. Now the domains are allocated independently it is no longer required to disable both control and monitor operations if either fail.
Quoted 4 lines
Signed-off-by Tony Luck<[email protected]>Tested-by Shaopeng Tan<[email protected]>Reviewed-by Shaopeng Tan<[email protected]>Reviewed-by Reinette Chatre<[email protected]>
Quoted 738 lines
--- include/linux/resctrl.h | 25 ++- arch/x86/kernel/cpu/resctrl/internal.h | 6 +- arch/x86/kernel/cpu/resctrl/core.c | 211 ++++++++++++++++------ arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 12 +- arch/x86/kernel/cpu/resctrl/monitor.c | 4 +- arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 4 +- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 55 +++--- 7 files changed, 220 insertions(+), 97 deletions(-)include/linux/resctrl.h +19
-6@@ -52,15 +52,22 @@ struct resctrl_staged_config {bool have_new_ctrl; }; +enum resctrl_domain_type { +RESCTRL_CTRL_DOMAIN , +RESCTRL_MON_DOMAIN , +}; +/** * struct rdt_domain_hdr - common header for different domain types * @list: all instances of this resource * @id: unique id for this instance +* @type: type of this instance * @cpu_mask: which CPUs share this resource */ struct rdt_domain_hdr {struct list_head list;int id; +enum resctrl_domain_type type;struct cpumask cpu_mask; };@@ -163,10 +170,12 @@ enum resctrl_scope {* @alloc_capable: Is allocation available on this machine * @mon_capable: Is monitor feature available on this machine * @num_rmid: Number of RMIDs available -* @scope: Scope of this resource +* @ctrl_scope: Scope of this resource for control functions +* @mon_scope: Scope of this resource for monitor functions * @cache: Cache allocation related data * @membw: If the component has bandwidth controls, their properties. -* @domains: All domains for this resource +* @ctrl_domains: Control domains for this resource +* @mon_domains: Monitor domains for this resource * @name: Name to use in "schemata" file. * @data_width: Character width of data when displaying * @default_ctrl: Specifies default cache cbm or memory B/W percent. @@ -181,10 +190,12 @@ struct rdt_resource {bool alloc_capable;bool mon_capable;int num_rmid; -enum resctrl_scope scope; +enum resctrl_scope ctrl_scope; +enum resctrl_scope mon_scope;struct resctrl_cache cache;struct resctrl_membw membw; -struct list_head domains; +struct list_head ctrl_domains; +struct list_head mon_domains;char *name;int data_width;u32 default_ctrl;@@ -230,8 +241,10 @@ int resctrl_arch_update_one(struct rdt_resource *r, struct rdt_domain *d,u32 resctrl_arch_get_config (struct rdt_resource *r,struct rdt_domain *d,u32 closid,enum resctrl_conf_type type); -int resctrl_online_domain (struct rdt_resource *r,struct rdt_domain *d); -void resctrl_offline_domain (struct rdt_resource *r,struct rdt_domain *d); +int resctrl_online_ctrl_domain (struct rdt_resource *r,struct rdt_domain *d); +int resctrl_online_mon_domain (struct rdt_resource *r,struct rdt_domain *d); +void resctrl_offline_ctrl_domain (struct rdt_resource *r,struct rdt_domain *d); +void resctrl_offline_mon_domain (struct rdt_resource *r,struct rdt_domain *d);/** * resctrl_arch_rmid_read() - Read the eventid counter corresponding to rmid arch/x86/kernel/cpu/resctrl/internal.h +3
-3@@ -520,8 +520,8 @@ 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 *rdt_find_domain (struct rdt_resource *r,int id, -struct list_head **pos); +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,@@ -540,7 +540,7 @@ int rdt_pseudo_lock_init(void);void rdt_pseudo_lock_release (void );int rdtgroup_pseudo_lock_create (struct rdtgroup *rdtgrp);void rdtgroup_pseudo_lock_remove (struct rdtgroup *rdtgrp); -struct rdt_domain *get_domain_from_cpu (int cpu,struct rdt_resource *r); +struct rdt_domain *get_ctrl_domain_from_cpu (int cpu,struct rdt_resource *r);int closids_supported (void );void closid_free (int closid);int alloc_rmid (void );arch/x86/kernel/cpu/resctrl/core.c +8
-5@@ -57,7 +57,8 @@ static void mba_wrmsr_amd(struct rdt_domain *d, struct msr_param *m, struct rdt_resource *r); -#define domain_init (id) LIST_HEAD_INIT(rdt_resources_all[id].r_resctrl.domains) +#define ctrl_domain_init (id) LIST_HEAD_INIT(rdt_resources_all[id].r_resctrl.ctrl_domains) +#define mon_domain_init (id) LIST_HEAD_INIT(rdt_resources_all[id].r_resctrl.mon_domains)struct rdt_hw_resource rdt_resources_all[] = { [RDT_RESOURCE_L3] =@@ -65,8 +66,10 @@ struct rdt_hw_resource rdt_resources_all[] = { .r_resctrl = { .rid = RDT_RESOURCE_L3, .name = "L3", - .scope = RESCTRL_L3_CACHE, - .domains = domain_init(RDT_RESOURCE_L3), + .ctrl_scope = RESCTRL_L3_CACHE, + .mon_scope = RESCTRL_L3_CACHE, + .ctrl_domains = ctrl_domain_init(RDT_RESOURCE_L3), + .mon_domains = mon_domain_init(RDT_RESOURCE_L3), .parse_ctrlval = parse_cbm, .format_str = "%d=%0*x", .fflags = RFTYPE_RES_CACHE, @@ -79,8 +82,8 @@ struct rdt_hw_resource rdt_resources_all[] = { .r_resctrl = { .rid = RDT_RESOURCE_L2, .name = "L2", - .scope = RESCTRL_L2_CACHE, - .domains = domain_init(RDT_RESOURCE_L2), + .ctrl_scope = RESCTRL_L2_CACHE, + .ctrl_domains = ctrl_domain_init(RDT_RESOURCE_L2), .parse_ctrlval = parse_cbm, .format_str = "%d=%0*x", .fflags = RFTYPE_RES_CACHE, @@ -93,8 +96,8 @@ struct
rdt_hw_resourcerdt_resources_all[] = { .r_resctrl = { .rid =RDT_RESOURCE_MBA, .name = "MB",arch/x86/kernel/cpu/resctrl/core.c +149
-49- .scope = RESCTRL_L3_CACHE, - .domains = domain_init(RDT_RESOURCE_MBA), + .ctrl_scope = RESCTRL_L3_CACHE, + .ctrl_domains = ctrl_domain_init(RDT_RESOURCE_MBA), .parse_ctrlval = parse_bw, .format_str = "%d=%*u", .fflags = RFTYPE_RES_MB,@@ -105,8 +108,8 @@ struct rdt_hw_resource rdt_resources_all[] = { .r_resctrl = { .rid = RDT_RESOURCE_SMBA, .name = "SMBA", - .scope = RESCTRL_L3_CACHE, - .domains = domain_init(RDT_RESOURCE_SMBA), + .ctrl_scope = RESCTRL_L3_CACHE, + .ctrl_domains = ctrl_domain_init(RDT_RESOURCE_SMBA), .parse_ctrlval = parse_bw, .format_str = "%d=%*u", .fflags = RFTYPE_RES_MB,@@ -352,11 +355,11 @@ cat_wrmsr(struct rdt_domain *d, struct msr_param *m, struct rdt_resource *r)wrmsrl (hw_res->msr_base + i, hw_dom->ctrl_val[i]); } -struct rdt_domain *get_domain_from_cpu (int cpu,struct rdt_resource *r) +struct rdt_domain *get_ctrl_domain_from_cpu (int cpu,struct rdt_resource *r) {struct rdt_domain *d; -list_for_each_entry (d, &r->domains, hdr.list) { +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;@@ -378,7 +381,7 @@ void rdt_ctrl_update(void *arg)int cpu =smp_processor_id ();struct rdt_domain *d; - d =get_domain_from_cpu (cpu, r); + d =get_ctrl_domain_from_cpu (cpu, r);if (d) { hw_res->msr_update (d, m, r);return ;@@ -388,26 +391,26 @@ void rdt_ctrl_update(void *arg) }/* -* rdt_find_domain - Find a domain in a resource that matches input resource id +* rdt_find_domain - Search for a domain id in a resource domain list. * -* Search resource r's domain list to find the resource id. If the resource -* id is found in a domain, return the domain. Otherwise, if requested by -* caller, return the first domain whose id is bigger than the input id. -* The domain list is sorted by id in ascending order. +* 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 *rdt_find_domain (struct rdt_resource *r,int id, -struct list_head **pos) +struct rdt_domain_hdr *rdt_find_domain (struct list_head *h,int id, +struct list_head **pos) { -struct rdt_domain *d; +struct rdt_domain_hdr *d;struct list_head *l; -list_for_each (l, &r->domains) { - d = list_entry(l, struct rdt_domain, hdr.list); +list_for_each (l, h) { + d = list_entry(l, struct rdt_domain_hdr, list);/* When id is found, return its domain. */ -if (id == d->hdr.id) +if (id == d->id)return d;/* Stop searching when finding id's position in sorted list. */ -if (id < d->hdr.id) +if (id < d->id)break ; }@@ -501,35 +504,28 @@ static int get_domain_id_from_scope(int cpu, enum resctrl_scope scope)return -EINVAL ; } -/* -* domain_add_cpu - Add a cpu to a resource's domain list. -* -* If an existing domain in the resource r's domain list matches the cpu's -* resource id, add the cpu in the domain. -* -* Otherwise, a new domain is allocated and inserted into the right position -* in the domain list sorted by id in ascending order. -* -* The order in the domain list is visible to users when we print entries -* in the schemata file and schemata input is validated to have the same order -* as this list. -*/ -static void domain_add_cpu (int cpu,struct rdt_resource *r) +static void domain_add_cpu_ctrl (int cpu,struct rdt_resource *r) { -int id =get_domain_id_from_scope (cpu, r->scope); +int id =get_domain_id_from_scope (cpu, r->ctrl_scope);struct list_head *add_pos =NULL ;struct rdt_hw_domain *hw_dom; +struct rdt_domain_hdr *hdr;struct rdt_domain *d;int err;if (id <0 ) { -pr_warn_once ("Can't find domain id for CPU:%d scope:%d for resource %s\n" , - cpu, r->scope, r->name); +pr_warn_once ("Can't find control domain id for CPU:%d scope:%d for resource %s\n" , + cpu, r->ctrl_scope, r->name);return ; } - d =rdt_find_domain (r, id, &add_pos); -if (d) { + hdr =rdt_find_domain (&r->ctrl_domains, id, &add_pos); +if (hdr) { +if (WARN_ON_ONCE (hdr->type !=RESCTRL_CTRL_DOMAIN )) +return ; + + d = container_of(hdr, struct rdt_domain, hdr); +cpumask_set_cpu (cpu, &d->hdr.cpu_mask);if (r->cache.arch_has_per_cpu_cfg)rdt_domain_reconfigure_cdp (r);@@ -542,51 +538,114 @@ static void domain_add_cpu(int cpu, struct rdt_resource *r) d = &hw_dom->d_resctrl; d->hdr.id = id; + d->hdr.type =RESCTRL_CTRL_DOMAIN ;cpumask_set_cpu (cpu, &d->hdr.cpu_mask);rdt_domain_reconfigure_cdp (r); -if (r->alloc_capable &&domain_setup_ctrlval (r, d)) { +if (domain_setup_ctrlval (r, d)) {domain_free (hw_dom);return ; } -if (r->mon_capable &&arch_domain_mbm_alloc (r->num_rmid, hw_dom)) { +list_add_tail (&d->hdr.list, add_pos); + + err =resctrl_online_ctrl_domain (r, d); +if (err) { +list_del (&d->hdr.list); +domain_free (hw_dom); + } +} + +static void domain_add_cpu_mon (int cpu,struct rdt_resource *r) +{ +int id =get_domain_id_from_scope (cpu, r->mon_scope); +struct list_head *add_pos =NULL ; +struct rdt_hw_domain *hw_dom; +struct rdt_domain_hdr *hdr; +struct rdt_domain *d; +int err; + +if (id <0 ) { +pr_warn_once ("Can't find monitor domain id for CPU:%d scope:%d for resource %s\n" , + cpu, r->mon_scope, r->name); +return ; + } + + hdr =rdt_find_domain (&r->mon_domains, id, &add_pos); +if (hdr) { +if (WARN_ON_ONCE (hdr->type !=RESCTRL_MON_DOMAIN )) +return ; + + d = container_of(hdr, struct rdt_domain, hdr); + +cpumask_set_cpu (cpu, &d->hdr.cpu_mask); +return ; + } + + hw_dom =kzalloc_node (sizeof (*hw_dom),GFP_KERNEL ,cpu_to_node (cpu)); +if (!hw_dom) +return ; + + d = &hw_dom->d_resctrl; + d->hdr.id = id; + d->hdr.type =RESCTRL_MON_DOMAIN ; +cpumask_set_cpu (cpu, &d->hdr.cpu_mask); + +if (arch_domain_mbm_alloc (r->num_rmid, hw_dom)) {domain_free (hw_dom);return ; }list_add_tail (&d->hdr.list, add_pos); - err =resctrl_online_domain (r, d); + err =resctrl_online_mon_domain (r, d);if (err) {list_del (&d->hdr.list);domain_free (hw_dom); } } -static void domain_remove_cpu (int cpu,struct rdt_resource *r) +/* +* domain_add_cpu - Add a CPU to either/both resource's domain lists. +*/ +static void domain_add_cpu (int cpu,struct rdt_resource *r) { -int id =get_domain_id_from_scope (cpu, r->scope); +if (r->alloc_capable) +domain_add_cpu_ctrl (cpu, r); +if (r->mon_capable) +domain_add_cpu_mon (cpu, r); +} + +static void domain_remove_cpu_ctrl (int cpu,struct rdt_resource *r) +{ +int id =get_domain_id_from_scope (cpu, r->ctrl_scope);struct rdt_hw_domain *hw_dom; +struct rdt_domain_hdr *hdr;struct rdt_domain *d;if (id <0 ) { -pr_warn_once ("Can't find domain id for CPU:%d scope:%d for resource %s\n" , - cpu, r->scope, r->name); +pr_warn_once ("Can't find control domain id for CPU:%d scope:%d for resource %s\n" , + cpu, r->ctrl_scope, r->name);return ; } - d =rdt_find_domain (r, id,NULL ); -if (!d) { -pr_warn ("Couldn't find domain with id=%d for CPU %d\n" , id, cpu); + hdr =rdt_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);return ; } + +if (WARN_ON_ONCE (hdr->type !=RESCTRL_CTRL_DOMAIN )) +return ; + + d = container_of(hdr, struct rdt_domain, hdr); hw_dom =resctrl_to_arch_dom (d);cpumask_clear_cpu (cpu, &d->hdr.cpu_mask);if (cpumask_empty (&d->hdr.cpu_mask)) { -resctrl_offline_domain (r, d); +resctrl_offline_ctrl_domain (r, d);list_del (&d->hdr.list);/* @@ -599,6 +658,42 @@ static void domain_remove_cpu(int cpu, struct rdt_resource *r)return ; } +} + +static void domain_remove_cpu_mon (int cpu,struct rdt_resource *r) +{ +int id =get_domain_id_from_scope (cpu, r->mon_scope); +struct rdt_hw_domain *hw_dom; +struct rdt_domain_hdr *hdr; +struct rdt_domain *d; + +if (id <0 ) { +pr_warn_once ("Can't find monitor domain id for CPU:%d scope:%d for resource %s\n" , + cpu, r->mon_scope, r->name); +return ; + } + + hdr =rdt_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); +return ; + } + +if (WARN_ON_ONCE (hdr->type !=RESCTRL_MON_DOMAIN )) +return ; + + d = container_of(hdr, struct rdt_domain, hdr); + hw_dom =resctrl_to_arch_dom (d); + +cpumask_clear_cpu (cpu, &d->hdr.cpu_mask); +if (cpumask_empty (&d->hdr.cpu_mask)) { +resctrl_offline_mon_domain (r, d); +list_del (&d->hdr.list); +domain_free (hw_dom); + +return ; + }if (r == &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl) {if (is_mbm_enabled () && cpu == d->mbm_work_cpu) {@@ -613,6 +708,14 @@ static void domain_remove_cpu(int cpu, struct rdt_resource *r) } } +static void domain_remove_cpu (int cpu,struct rdt_resource *r) +{ +if (r->alloc_capable) +domain_remove_cpu_ctrl (cpu, r); +if (r->mon_capable) +domain_remove_cpu_mon (cpu, r); +} +static void clear_closid_rmid (int cpu) {struct resctrl_pqr_state *state =this_cpu_ptr (&pqr_state);arch/x86/kernel/cpu/resctrl/ctrlmondata.c +7
-5@@ -226,7 +226,7 @@ static int parse_line(char *line, struct resctrl_schema *s,return -EINVAL ; } dom =strim (dom); -list_for_each_entry (d, &r->domains, hdr.list) { +list_for_each_entry (d, &r->ctrl_domains, hdr.list) {if (d->hdr.id == dom_id) { data.buf = dom; data.rdtgrp = rdtgrp;@@ -318,7 +318,7 @@ int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid)return -ENOMEM ; msr_param.res =NULL ; -list_for_each_entry (d, &r->domains, hdr.list) { +list_for_each_entry (d, &r->ctrl_domains, hdr.list) { hw_dom =resctrl_to_arch_dom (d);for (t =0 ; t <CDP_NUM_TYPES ; t++) { cfg = &hw_dom->d_resctrl.staged_config[t];@@ -466,7 +466,7 @@ static void show_doms(struct seq_file *s, struct resctrl_schema *schema, int clou32 ctrl_val;seq_printf (s,"%*s:" , max_name_width, schema->name); -list_for_each_entry (dom, &r->domains, hdr.list) { +list_for_each_entry (dom, &r->ctrl_domains, hdr.list) {if (sep)seq_puts (s,";" );@@ -542,6 +542,7 @@ void mon_event_read(struct rmid_read *rr, struct rdt_resource *r,int rdtgroup_mondata_show (struct seq_file *m,void *arg) {struct kernfs_open_file *of = m->private; +struct rdt_domain_hdr *hdr;u32 resid, evtid, domid;struct rdtgroup *rdtgrp;struct rdt_resource *r;@@ -562,11 +563,12 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg) evtid = md.u.evtid; r = &rdt_resources_all[resid].r_resctrl; - d =rdt_find_domain (r, domid,NULL ); -if (!d) { + hdr =rdt_find_domain (&r->mon_domains, domid,NULL ); +if (!hdr ||WARN_ON_ONCE (hdr->type !=RESCTRL_MON_DOMAIN )) { ret = -ENOENT ; goto out; } + d = container_of(hdr, struct rdt_domain, hdr);mon_event_read (&rr, r, d, rdtgrp, evtid, false);arch/x86/kernel/cpu/resctrl/monitor.c +2
-2@@ -340,7 +340,7 @@ static void add_rmid_to_limbo(struct rmid_entry *entry) entry->busy =0 ; cpu =get_cpu (); -list_for_each_entry (d, &r->domains, hdr.list) { +list_for_each_entry (d, &r->mon_domains, hdr.list) {if (cpumask_test_cpu (cpu, &d->hdr.cpu_mask)) { err = resctrl_arch_rmid_read(r, d, entry->rmid, QOS_L3_OCCUP_EVENT_ID,@@ -535,7 +535,7 @@ static void update_mba_bw(struct rdtgroup *rgrp, struct rdt_domain *dom_mbm) rmid = rgrp->mon.rmid; pmbm_data = &dom_mbm->mbm_local[rmid]; - dom_mba =get_domain_from_cpu (smp_processor_id (), r_mba); + dom_mba =get_ctrl_domain_from_cpu (smp_processor_id (), r_mba);if (!dom_mba) {pr_warn_once ("Failure to get domain for MBA update\n" );return ;arch/x86/kernel/cpu/resctrl/pseudo_lock.c +2
-2@@ -292,7 +292,7 @@ static void pseudo_lock_region_clear(struct pseudo_lock_region *plr)*/ static int pseudo_lock_region_init (struct pseudo_lock_region *plr) { -enum resctrl_scope scope = plr->s->res->scope; +enum resctrl_scope scope = plr->s->res->ctrl_scope;struct cpu_cacheinfo *ci;int ret;int i;@@ -856,7 +856,7 @@ bool rdtgroup_pseudo_locked_in_hierarchy(struct rdt_domain *d)* associated with them. */ for_each_alloc_capable_rdt_resource (r) { -list_for_each_entry (d_i, &r->domains, hdr.list) { +list_for_each_entry (d_i, &r->ctrl_domains, hdr.list) {if (d_i->plr)cpumask_or (cpu_with_psl, cpu_with_psl, &d_i->hdr.cpu_mask);arch/x86/kernel/cpu/resctrl/rdtgroup.c +30
-25@@ -91,7 +91,7 @@ void rdt_staged_configs_clear(void)lockdep_assert_held (&rdtgroup_mutex);for_each_alloc_capable_rdt_resource (r) { -list_for_each_entry (dom, &r->domains, hdr.list) +list_for_each_entry (dom, &r->ctrl_domains, hdr.list)memset (dom->staged_config,0 ,sizeof (dom->staged_config)); } }@@ -984,7 +984,7 @@ static int rdt_bit_usage_show(struct kernfs_open_file *of,mutex_lock (&rdtgroup_mutex); hw_shareable = r->cache.shareable_bits; -list_for_each_entry (dom, &r->domains, hdr.list) { +list_for_each_entry (dom, &r->ctrl_domains, hdr.list) {if (sep)seq_putc (seq,';' ); sw_shareable =0 ;@@ -1302,7 +1302,7 @@ static bool rdtgroup_mode_test_exclusive(struct rdtgroup *rdtgrp)if (r->rid ==RDT_RESOURCE_MBA || r->rid ==RDT_RESOURCE_SMBA )continue ; has_cache = true; -list_for_each_entry (d, &r->domains, hdr.list) { +list_for_each_entry (d, &r->ctrl_domains, hdr.list) { ctrl =resctrl_arch_get_config (r, d, closid, s->conf_type);if (rdtgroup_cbm_overlaps (s, d, ctrl, closid, false)) {@@ -1413,13 +1413,13 @@ unsigned int rdtgroup_cbm_to_size(struct rdt_resource *r,unsigned int size =0 ;int num_b, i; -if (WARN_ON_ONCE (r->scope !=RESCTRL_L2_CACHE && r->scope !=RESCTRL_L3_CACHE )) +if (WARN_ON_ONCE (r->ctrl_scope !=RESCTRL_L2_CACHE && r->ctrl_scope !=RESCTRL_L3_CACHE ))return size; num_b =bitmap_weight (&cbm, r->cache.cbm_len); ci =get_cpu_cacheinfo (cpumask_any (&d->hdr.cpu_mask));for (i =0 ; i < ci->num_leaves; i++) { -if (ci->info_list[i].level == r->scope) { +if (ci->info_list[i].level == r->ctrl_scope) { size = ci->info_list[i].size / r->cache.cbm_len * num_b;break ; }@@ -1477,7 +1477,7 @@ static int rdtgroup_size_show(struct kernfs_open_file *of, type = schema->conf_type; sep = false;seq_printf (s,"%*s:" , max_name_width, schema->name); -list_for_each_entry (d, &r->domains, hdr.list) { +list_for_each_entry (d, &r->ctrl_domains, hdr.list) {if (sep)seq_putc (s,';' );if (rdtgrp->mode ==RDT_MODE_PSEUDO_LOCKSETUP ) {@@ -1566,7 +1566,7 @@ static int mbm_config_show(struct seq_file *s, struct rdt_resource *r, u32 evtidmutex_lock (&rdtgroup_mutex); -list_for_each_entry (dom, &r->domains, hdr.list) { +list_for_each_entry (dom, &r->mon_domains, hdr.list) {if (sep)seq_puts (s,";" );@@ -1689,7 +1689,7 @@ static int mon_config_write(struct rdt_resource *r, char *tok, u32 evtid)return -EINVAL ; } -list_for_each_entry (d, &r->domains, hdr.list) { +list_for_each_entry (d, &r->mon_domains, hdr.list) {if (d->hdr.id == dom_id) { ret =mbm_config_write_domain (r, d, evtid, val);if (ret)@@ -2232,7 +2232,7 @@ static int set_cache_qos_cfg(int level, bool enable)return -ENOMEM ; r_l = &rdt_resources_all[level].r_resctrl; -list_for_each_entry (d, &r_l->domains, hdr.list) { +list_for_each_entry (d, &r_l->ctrl_domains, hdr.list) {if (r_l->cache.arch_has_per_cpu_cfg)/* Pick all the CPUs in the domain instance */ for_each_cpu (cpu, &d->hdr.cpu_mask)@@ -2317,7 +2317,7 @@ static int set_mba_sc(bool mba_sc) r->membw.mba_sc = mba_sc; -list_for_each_entry (d, &r->domains, hdr.list) { +list_for_each_entry (d, &r->ctrl_domains, hdr.list) {for (i =0 ; i < num_closid; i++) d->mbps_val[i] =MBA_MAX_MBPS ; }@@ -2653,7 +2653,7 @@ static int rdt_get_tree(struct fs_context *fc)if (is_mbm_enabled ()) { r = &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl; -list_for_each_entry (dom, &r->domains, hdr.list) +list_for_each_entry (dom, &r->mon_domains, hdr.list)mbm_setup_overflow_handler (dom,MBM_OVERFLOW_INTERVAL ); }@@ -2777,10 +2777,10 @@ static int reset_all_ctrls(struct rdt_resource *r)/* * Disable resource control for this resource by setting all -* CBMs in all domains to the maximum mask value. Pick one CPU +* CBMs in all ctrl_domains to the maximum mask value. Pick one CPU * from each domain to update the MSRs below. */ -list_for_each_entry (d, &r->domains, hdr.list) { +list_for_each_entry (d, &r->ctrl_domains, hdr.list) { hw_dom =resctrl_to_arch_dom (d);cpumask_set_cpu (cpumask_any (&d->hdr.cpu_mask), cpu_mask);@@ -3050,7 +3050,7 @@ static int mkdir_mondata_subdir_alldom(struct kernfs_node *parent_kn,struct rdt_domain *dom;int ret; -list_for_each_entry (dom, &r->domains, hdr.list) { +list_for_each_entry (dom, &r->mon_domains, hdr.list) { ret =mkdir_mondata_subdir (parent_kn, dom, r, prgrp);if (ret)return ret;@@ -3232,7 +3232,7 @@ static int rdtgroup_init_cat(struct resctrl_schema *s, u32 closid)struct rdt_domain *d;int ret; -list_for_each_entry (d, &s->res->domains, hdr.list) { +list_for_each_entry (d, &s->res->ctrl_domains, hdr.list) { ret =__init_one_rdt_domain (d, s, closid);if (ret <0 )return ret;@@ -3247,7 +3247,7 @@ static void rdtgroup_init_mba(struct rdt_resource *r, u32 closid)struct resctrl_staged_config *cfg;struct rdt_domain *d; -list_for_each_entry (d, &r->domains, hdr.list) { +list_for_each_entry (d, &r->ctrl_domains, hdr.list) {if (is_mba_sc (r)) { d->mbps_val[closid] =MBA_MAX_MBPS ;continue ;@@ -3849,15 +3849,17 @@ static void domain_destroy_mon_state(struct rdt_domain *d)kfree (d->mbm_local); } -void resctrl_offline_domain (struct rdt_resource *r,struct rdt_domain *d) +void resctrl_offline_ctrl_domain (struct rdt_resource *r,struct rdt_domain *d) {lockdep_assert_held (&rdtgroup_mutex);if (supports_mba_mbps () && r->rid ==RDT_RESOURCE_MBA )mba_sc_domain_destroy (r, d); +} -if (!r->mon_capable) -return ; +void resctrl_offline_mon_domain (struct rdt_resource *r,struct rdt_domain *d) +{ +lockdep_assert_held (&rdtgroup_mutex);/* * If resctrl is mounted, remove all the @@ -3914,18 +3916,21 @@ static int domain_setup_mon_state(struct rdt_resource *r, struct rdt_domain *d)return 0 ; } -int resctrl_online_domain (struct rdt_resource *r,struct rdt_domain *d) +int resctrl_online_ctrl_domain (struct rdt_resource *r,struct rdt_domain *d) { -int err; -lockdep_assert_held (&rdtgroup_mutex);if (supports_mba_mbps () && r->rid ==RDT_RESOURCE_MBA ) -/* RDT_RESOURCE_MBA is never mon_capable */ return mba_sc_domain_allocate (r, d); -if (!r->mon_capable) -return 0 ; +return 0 ; +} + +int resctrl_online_mon_domain (struct rdt_resource *r,struct rdt_domain *d) +{ +int err; + +lockdep_assert_held (&rdtgroup_mutex); err =domain_setup_mon_state (r, d);if (err)
Tony Luck
maintainerPATCH v13 4/8 x86/resctrl: Split the rdt_domain and rdt_hw_domain structures
In reply to Tony LuckThe same rdt_domain structure is used for both control and monitor functions. But this results in wasted memory as some of the fields are only used by control functions, while most are only used for monitor functions.
Split into separate rdt_ctrl_domain and rdt_mon_domain structures with just the fields required for control and monitoring respectively.
Similar split of the rdt_hw_domain structure into rdt_hw_ctrl_domain and rdt_hw_mon_domain.
--- include/linux/resctrl.h | 48 +++++++------ arch/x86/kernel/cpu/resctrl/internal.h | 60 ++++++++++------ arch/x86/kernel/cpu/resctrl/core.c | 87 ++++++++++++----------- arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 32 ++++----- arch/x86/kernel/cpu/resctrl/monitor.c | 40 +++++------ arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 6 +- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 62 ++++++++-------- 7 files changed, 182 insertions(+), 153 deletions(-)
include/linux/resctrl.h +28 -20
@@ -72,7 +72,23 @@ struct rdt_domain_hdr { };/** -* struct rdt_domain - group of CPUs sharing a resctrl resource +* struct rdt_ctrl_domain - group of CPUs sharing a resctrl control resource +* @hdr: common header for different domain types +* @plr: pseudo-locked region (if any) associated with domain +* @staged_config: parsed configuration to be applied +* @mbps_val: When mba_sc is enabled, this holds the array of user +* specified control values for mba_sc in MBps, indexed +* by closid +*/ +struct rdt_ctrl_domain { +struct rdt_domain_hdr hdr; +struct pseudo_lock_region *plr; +struct resctrl_staged_config staged_config[CDP_NUM_TYPES ]; +u32 *mbps_val; +}; + +/** +* struct rdt_mon_domain - group of CPUs sharing a resctrl monitor resource * @hdr: common header for different domain types * @rmid_busy_llc: bitmap of which limbo RMIDs are above threshold * @mbm_total: saved state for MBM total bandwidth
@@ -81,13 +97,8 @@ struct rdt_domain_hdr {* @cqm_limbo: worker to periodically read CQM h/w counters * @mbm_work_cpu: worker CPU for MBM h/w counters * @cqm_work_cpu: worker CPU for CQM h/w counters -* @plr: pseudo-locked region (if any) associated with domain -* @staged_config: parsed configuration to be applied -* @mbps_val: When mba_sc is enabled, this holds the array of user -* specified control values for mba_sc in MBps, indexed -* by closid */ -struct rdt_domain { +struct rdt_mon_domain {struct rdt_domain_hdr hdr;unsigned long *rmid_busy_llc;struct mbm_state *mbm_total;
@@ -96,9 +107,6 @@ struct rdt_domain {struct delayed_work cqm_limbo;int mbm_work_cpu;int cqm_work_cpu; -struct pseudo_lock_region *plr; -struct resctrl_staged_config staged_config[CDP_NUM_TYPES ]; -u32 *mbps_val; };/**
@@ -202,7 +210,7 @@ struct rdt_resource {const char *format_str;int (*parse_ctrlval)(struct rdt_parse_data *data,struct resctrl_schema *s, -struct rdt_domain *d); +struct rdt_ctrl_domain *d);struct list_head evt_list;unsigned long fflags;bool cdp_capable;
@@ -236,15 +244,15 @@ int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid);* Update the ctrl_val and apply this config right now. * Must be called on one of the domain's CPUs. */ -int resctrl_arch_update_one (struct rdt_resource *r,struct rdt_domain *d, +int resctrl_arch_update_one (struct rdt_resource *r,struct rdt_ctrl_domain *d,u32 closid,enum resctrl_conf_type t,u32 cfg_val); -u32 resctrl_arch_get_config (struct rdt_resource *r,struct rdt_domain *d, +u32 resctrl_arch_get_config (struct rdt_resource *r,struct rdt_ctrl_domain *d,u32 closid,enum resctrl_conf_type type); -int resctrl_online_ctrl_domain (struct rdt_resource *r,struct rdt_domain *d); -int resctrl_online_mon_domain (struct rdt_resource *r,struct rdt_domain *d); -void resctrl_offline_ctrl_domain (struct rdt_resource *r,struct rdt_domain *d); -void resctrl_offline_mon_domain (struct rdt_resource *r,struct rdt_domain *d); +int resctrl_online_ctrl_domain (struct rdt_resource *r,struct rdt_ctrl_domain *d); +int resctrl_online_mon_domain (struct rdt_resource *r,struct rdt_mon_domain *d); +void resctrl_offline_ctrl_domain (struct rdt_resource *r,struct rdt_ctrl_domain *d); +void resctrl_offline_mon_domain (struct rdt_resource *r,struct rdt_mon_domain *d);/** * resctrl_arch_rmid_read() - Read the eventid counter corresponding to rmid
@@ -260,7 +268,7 @@ void resctrl_offline_mon_domain(struct rdt_resource *r, struct rdt_domain *d);* Return: * 0 on success, or -EIO, -EINVAL etc on error. */ -int resctrl_arch_rmid_read (struct rdt_resource *r,struct rdt_domain *d, +int resctrl_arch_rmid_read (struct rdt_resource *r,struct rdt_mon_domain *d,u32 rmid,enum resctrl_event_id eventid,u64 *val);/**
@@ -273,7 +281,7 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain *d,* * This can be called from any CPU. */ -void resctrl_arch_reset_rmid (struct rdt_resource *r,struct rdt_domain *d, +void resctrl_arch_reset_rmid (struct rdt_resource *r,struct rdt_mon_domain *d,u32 rmid,enum resctrl_event_id eventid);/**
@@ -285,7 +293,7 @@ void resctrl_arch_reset_rmid(struct rdt_resource *r, struct rdt_domain *d,* * This can be called from any CPU. */ -void resctrl_arch_reset_rmid_all (struct rdt_resource *r,struct rdt_domain *d); +void resctrl_arch_reset_rmid_all (struct rdt_resource *r,struct rdt_mon_domain *d);extern unsigned int resctrl_rmid_realloc_threshold;extern unsigned int resctrl_rmid_realloc_limit;
arch/x86/kernel/cpu/resctrl/internal.h +38 -22
131 lines not on this page · raw message
arch/x86/kernel/cpu/resctrl/core.c +46 -41
246 lines not on this page · raw message
arch/x86/kernel/cpu/resctrl/ctrlmondata.c +16 -16
@@ -58,7 +58,7 @@ static bool bw_validate(char *buf, unsigned long *data, struct rdt_resource *r) }int parse_bw (struct rdt_parse_data *data,struct resctrl_schema *s, -struct rdt_domain *d) +struct rdt_ctrl_domain *d) {struct resctrl_staged_config *cfg;u32 closid = data->rdtgrp->closid;
@@ -137,7 +137,7 @@ static bool cbm_validate(char *buf, u32 *data, struct rdt_resource *r)* resource type. */ int parse_cbm (struct rdt_parse_data *data,struct resctrl_schema *s, -struct rdt_domain *d) +struct rdt_ctrl_domain *d) {struct rdtgroup *rdtgrp = data->rdtgrp;struct resctrl_staged_config *cfg;
@@ -206,8 +206,8 @@ static int parse_line(char *line, struct resctrl_schema *s,struct resctrl_staged_config *cfg;struct rdt_resource *r = s->res;struct rdt_parse_data data; +struct rdt_ctrl_domain *d;char *dom =NULL , *id; -struct rdt_domain *d;unsigned long dom_id; if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP &&
@@ -267,11 +267,11 @@ static u32 get_config_index(u32 closid, enum resctrl_conf_type type) } } -static bool apply_config (struct rdt_hw_domain *hw_dom, +static bool apply_config (struct rdt_hw_ctrl_domain *hw_dom,struct resctrl_staged_config *cfg,u32 idx,cpumask_var_t cpu_mask) { -struct rdt_domain *dom = &hw_dom->d_resctrl; +struct rdt_ctrl_domain *dom = &hw_dom->d_resctrl;if (cfg->new_ctrl != hw_dom->ctrl_val[idx]) {cpumask_set_cpu (cpumask_any (&dom->hdr.cpu_mask), cpu_mask);
@@ -283,11 +283,11 @@ static bool apply_config(struct rdt_hw_domain *hw_dom,return false; } -int resctrl_arch_update_one (struct rdt_resource *r,struct rdt_domain *d, +int resctrl_arch_update_one (struct rdt_resource *r,struct rdt_ctrl_domain *d,u32 closid,enum resctrl_conf_type t,u32 cfg_val) { +struct rdt_hw_ctrl_domain *hw_dom =resctrl_to_arch_ctrl_dom (d);struct rdt_hw_resource *hw_res =resctrl_to_arch_res (r); -struct rdt_hw_domain *hw_dom =resctrl_to_arch_dom (d);u32 idx =get_config_index (closid, t);struct msr_param msr_param;
@@ -307,11 +307,11 @@ int resctrl_arch_update_one(struct rdt_resource *r, struct rdt_domain *d,int resctrl_arch_update_domains (struct rdt_resource *r,u32 closid) {struct resctrl_staged_config *cfg; -struct rdt_hw_domain *hw_dom; +struct rdt_hw_ctrl_domain *hw_dom;struct msr_param msr_param; +struct rdt_ctrl_domain *d;enum resctrl_conf_type t;cpumask_var_t cpu_mask; -struct rdt_domain *d;u32 idx;if (!zalloc_cpumask_var (&cpu_mask,GFP_KERNEL ))
@@ -319,7 +319,7 @@ int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid) msr_param.res =NULL ;list_for_each_entry (d, &r->ctrl_domains, hdr.list) { - hw_dom =resctrl_to_arch_dom (d); + hw_dom =resctrl_to_arch_ctrl_dom (d);for (t =0 ; t <CDP_NUM_TYPES ; t++) { cfg = &hw_dom->d_resctrl.staged_config[t];if (!cfg->have_new_ctrl)
@@ -449,10 +449,10 @@ ssize_t rdtgroup_schemata_write(struct kernfs_open_file *of,return ret ?: nbytes; } -u32 resctrl_arch_get_config (struct rdt_resource *r,struct rdt_domain *d, +u32 resctrl_arch_get_config (struct rdt_resource *r,struct rdt_ctrl_domain *d,u32 closid,enum resctrl_conf_type type) { -struct rdt_hw_domain *hw_dom =resctrl_to_arch_dom (d); +struct rdt_hw_ctrl_domain *hw_dom =resctrl_to_arch_ctrl_dom (d);u32 idx =get_config_index (closid, type);return hw_dom->ctrl_val[idx];
@@ -461,7 +461,7 @@ u32 resctrl_arch_get_config(struct rdt_resource *r, struct rdt_domain *d,static void show_doms (struct seq_file *s,struct resctrl_schema *schema,int closid) {struct rdt_resource *r = schema->res; -struct rdt_domain *dom; +struct rdt_ctrl_domain *dom;bool sep = false;u32 ctrl_val;
@@ -523,7 +523,7 @@ int rdtgroup_schemata_show(struct kernfs_open_file *of, }void mon_event_read (struct rmid_read *rr,struct rdt_resource *r, -struct rdt_domain *d,struct rdtgroup *rdtgrp, +struct rdt_mon_domain *d,struct rdtgroup *rdtgrp,int evtid,int first) {/*
@@ -543,11 +543,11 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg) {struct kernfs_open_file *of = m->private;struct rdt_domain_hdr *hdr; +struct rdt_mon_domain *d;u32 resid, evtid, domid;struct rdtgroup *rdtgrp;struct rdt_resource *r;union mon_data_bits md; -struct rdt_domain *d;struct rmid_read rr;int ret =0 ;
@@ -568,7 +568,7 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg) ret = -ENOENT ; goto out; } - d = container_of(hdr, struct rdt_domain, hdr); + d = container_of(hdr, struct rdt_mon_domain, hdr);mon_event_read (&rr, r, d, rdtgrp, evtid, false);
arch/x86/kernel/cpu/resctrl/monitor.c +20 -20
@@ -170,7 +170,7 @@ static int __rmid_read(u32 rmid, enum resctrl_event_id eventid, u64 *val)return 0 ; } -static struct arch_mbm_state *get_arch_mbm_state (struct rdt_hw_domain *hw_dom, +static struct arch_mbm_state *get_arch_mbm_state (struct rdt_hw_mon_domain *hw_dom,u32 rmid,enum resctrl_event_id eventid) {
@@ -189,10 +189,10 @@ static struct arch_mbm_state *get_arch_mbm_state(struct rdt_hw_domain *hw_dom,return NULL ; } -void resctrl_arch_reset_rmid (struct rdt_resource *r,struct rdt_domain *d, +void resctrl_arch_reset_rmid (struct rdt_resource *r,struct rdt_mon_domain *d,u32 rmid,enum resctrl_event_id eventid) { -struct rdt_hw_domain *hw_dom =resctrl_to_arch_dom (d); +struct rdt_hw_mon_domain *hw_dom =resctrl_to_arch_mon_dom (d);struct arch_mbm_state *am; am =get_arch_mbm_state (hw_dom, rmid, eventid);
@@ -208,9 +208,9 @@ void resctrl_arch_reset_rmid(struct rdt_resource *r, struct rdt_domain *d,* Assumes that hardware counters are also reset and thus that there is * no need to record initial non-zero counts. */ -void resctrl_arch_reset_rmid_all (struct rdt_resource *r,struct rdt_domain *d) +void resctrl_arch_reset_rmid_all (struct rdt_resource *r,struct rdt_mon_domain *d) { -struct rdt_hw_domain *hw_dom =resctrl_to_arch_dom (d); +struct rdt_hw_mon_domain *hw_dom =resctrl_to_arch_mon_dom (d);if (is_mbm_total_enabled ()) memset(hw_dom->arch_mbm_total, 0,
@@ -229,11 +229,11 @@ static u64 mbm_overflow_count(u64 prev_msr, u64 cur_msr, unsigned int width)return chunks >> shift; } -int resctrl_arch_rmid_read (struct rdt_resource *r,struct rdt_domain *d, +int resctrl_arch_rmid_read (struct rdt_resource *r,struct rdt_mon_domain *d,u32 rmid,enum resctrl_event_id eventid,u64 *val) { +struct rdt_hw_mon_domain *hw_dom =resctrl_to_arch_mon_dom (d);struct rdt_hw_resource *hw_res =resctrl_to_arch_res (r); -struct rdt_hw_domain *hw_dom =resctrl_to_arch_dom (d);struct arch_mbm_state *am;u64 msr_val, chunks;int ret;
@@ -266,7 +266,7 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain *d,* decrement the count. If the busy count gets to zero on an RMID, we * free the RMID */ -void __check_limbo (struct rdt_domain *d,bool force_free) +void __check_limbo (struct rdt_mon_domain *d,bool force_free) {struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl;struct rmid_entry *entry;
@@ -305,7 +305,7 @@ void __check_limbo(struct rdt_domain *d, bool force_free) } } -bool has_busy_rmid (struct rdt_resource *r,struct rdt_domain *d) +bool has_busy_rmid (struct rdt_resource *r,struct rdt_mon_domain *d) {return find_first_bit (d->rmid_busy_llc, r->num_rmid) != r->num_rmid; }
@@ -334,7 +334,7 @@ int alloc_rmid(void)static void add_rmid_to_limbo (struct rmid_entry *entry) {struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl; -struct rdt_domain *d; +struct rdt_mon_domain *d;int cpu, err;u64 val =0 ;
@@ -383,7 +383,7 @@ void free_rmid(u32 rmid)list_add_tail (&entry->list, &rmid_free_lru); } -static struct mbm_state *get_mbm_state (struct rdt_domain *d,u32 rmid, +static struct mbm_state *get_mbm_state (struct rdt_mon_domain *d,u32 rmid,enum resctrl_event_id evtid) {switch (evtid) {
@@ -516,13 +516,13 @@ void mon_event_count(void *info)* throttle MSRs already have low percentage values. To avoid * unnecessarily restricting such rdtgroups, we also increase the bandwidth. */ -static void update_mba_bw (struct rdtgroup *rgrp,struct rdt_domain *dom_mbm) +static void update_mba_bw (struct rdtgroup *rgrp,struct rdt_mon_domain *dom_mbm) {u32 closid, rmid, cur_msr_val, new_msr_val;struct mbm_state *pmbm_data, *cmbm_data; +struct rdt_ctrl_domain *dom_mba;u32 cur_bw, delta_bw, user_bw;struct rdt_resource *r_mba; -struct rdt_domain *dom_mba;struct list_head *head;struct rdtgroup *entry;
@@ -600,7 +600,7 @@ static void update_mba_bw(struct rdtgroup *rgrp, struct rdt_domain *dom_mbm) } } -static void mbm_update (struct rdt_resource *r,struct rdt_domain *d,int rmid) +static void mbm_update (struct rdt_resource *r,struct rdt_mon_domain *d,int rmid) {struct rmid_read rr;
@@ -640,13 +640,13 @@ void cqm_handle_limbo(struct work_struct *work) {unsigned long delay =msecs_to_jiffies (CQM_LIMBOCHECK_INTERVAL );int cpu =smp_processor_id (); +struct rdt_mon_domain *d;struct rdt_resource *r; -struct rdt_domain *d;mutex_lock (&rdtgroup_mutex); r = &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl; - d = container_of(work, struct rdt_domain, cqm_limbo.work); + d = container_of(work, struct rdt_mon_domain, cqm_limbo.work);__check_limbo (d, false);
@@ -656,7 +656,7 @@ void cqm_handle_limbo(struct work_struct *work)mutex_unlock (&rdtgroup_mutex); } -void cqm_setup_limbo_handler (struct rdt_domain *dom,unsigned long delay_ms) +void cqm_setup_limbo_handler (struct rdt_mon_domain *dom,unsigned long delay_ms) {unsigned long delay =msecs_to_jiffies (delay_ms);int cpu;
@@ -672,9 +672,9 @@ void mbm_handle_overflow(struct work_struct *work)unsigned long delay =msecs_to_jiffies (MBM_OVERFLOW_INTERVAL );struct rdtgroup *prgrp, *crgrp;int cpu =smp_processor_id (); +struct rdt_mon_domain *d;struct list_head *head;struct rdt_resource *r; -struct rdt_domain *d;mutex_lock (&rdtgroup_mutex);
@@ -682,7 +682,7 @@ void mbm_handle_overflow(struct work_struct *work) goto out_unlock; r = &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl; - d = container_of(work, struct rdt_domain, mbm_over.work); + d = container_of(work, struct rdt_mon_domain, mbm_over.work);list_for_each_entry (prgrp, &rdt_all_groups, rdtgroup_list) {mbm_update (r, d, prgrp->mon.rmid);
@@ -701,7 +701,7 @@ void mbm_handle_overflow(struct work_struct *work)mutex_unlock (&rdtgroup_mutex); } -void mbm_setup_overflow_handler (struct rdt_domain *dom,unsigned long delay_ms) +void mbm_setup_overflow_handler (struct rdt_mon_domain *dom,unsigned long delay_ms) {unsigned long delay =msecs_to_jiffies (delay_ms);int cpu;
arch/x86/kernel/cpu/resctrl/pseudo_lock.c +3 -3
@@ -814,7 +814,7 @@ int rdtgroup_locksetup_exit(struct rdtgroup *rdtgrp)* Return: true if @cbm overlaps with pseudo-locked region on @d, false * otherwise. */ -bool rdtgroup_cbm_overlaps_pseudo_locked (struct rdt_domain *d,unsigned long cbm) +bool rdtgroup_cbm_overlaps_pseudo_locked (struct rdt_ctrl_domain *d,unsigned long cbm) {unsigned int cbm_len;unsigned long cbm_b;
@@ -841,11 +841,11 @@ bool rdtgroup_cbm_overlaps_pseudo_locked(struct rdt_domain *d, unsigned long cbm* if it is not possible to test due to memory allocation issue, * false otherwise. */ -bool rdtgroup_pseudo_locked_in_hierarchy (struct rdt_domain *d) +bool rdtgroup_pseudo_locked_in_hierarchy (struct rdt_ctrl_domain *d) { +struct rdt_ctrl_domain *d_i;cpumask_var_t cpu_with_psl;struct rdt_resource *r; -struct rdt_domain *d_i;bool ret = false;if (!zalloc_cpumask_var (&cpu_with_psl,GFP_KERNEL ))
arch/x86/kernel/cpu/resctrl/rdtgroup.c +31 -31
252 lines not on this page · raw message
Signature · 1 line
2.41.0
Re: [PATCH v13 4/8] x86/resctrl: Split the rdt_domain and rdt_hw_domain structures
Quoted 8 lines · Tony Luck
The same
rdt_domainstructure is used for both control and monitor functions. But this results in wasted memory as some of the fields are only used by control functions, while most are only used for monitor functions.Split into separate
rdt_ctrl_domainandrdt_mon_domainstructures with just the fields required for control and monitoring respectively.
Quoted 8 lines
Similar split of the
rdt_hw_domainstructure intordt_hw_ctrl_domainandrdt_hw_mon_domain.Signed-off-by Tony Luck<[email protected]>Tested-by Shaopeng Tan<[email protected]>Reviewed-by Peter Newman<[email protected]>Reviewed-by Reinette Chatre<[email protected]>Reviewed-by Shaopeng Tan<[email protected]>
Quoted 1,148 lines
--- include/linux/resctrl.h | 48 +++++++------ arch/x86/kernel/cpu/resctrl/internal.h | 60 ++++++++++------ arch/x86/kernel/cpu/resctrl/core.c | 87 ++++++++++++----------- arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 32 ++++----- arch/x86/kernel/cpu/resctrl/monitor.c | 40 +++++------ arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 6 +- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 62 ++++++++-------- 7 files changed, 182 insertions(+), 153 deletions(-)include/linux/resctrl.h +28
-20@@ -72,7 +72,23 @@ struct rdt_domain_hdr { };/** -* struct rdt_domain - group of CPUs sharing a resctrl resource +* struct rdt_ctrl_domain - group of CPUs sharing a resctrl control resource +* @hdr: common header for different domain types +* @plr: pseudo-locked region (if any) associated with domain +* @staged_config: parsed configuration to be applied +* @mbps_val: When mba_sc is enabled, this holds the array of user +* specified control values for mba_sc in MBps, indexed +* by closid +*/ +struct rdt_ctrl_domain { +struct rdt_domain_hdr hdr; +struct pseudo_lock_region *plr; +struct resctrl_staged_config staged_config[CDP_NUM_TYPES ]; +u32 *mbps_val; +}; + +/** +* struct rdt_mon_domain - group of CPUs sharing a resctrl monitor resource * @hdr: common header for different domain types * @rmid_busy_llc: bitmap of which limbo RMIDs are above threshold * @mbm_total: saved state for MBM total bandwidth @@ -81,13 +97,8 @@ struct rdt_domain_hdr {* @cqm_limbo: worker to periodically read CQM h/w counters * @mbm_work_cpu: worker CPU for MBM h/w counters * @cqm_work_cpu: worker CPU for CQM h/w counters -* @plr: pseudo-locked region (if any) associated with domain -* @staged_config: parsed configuration to be applied -* @mbps_val: When mba_sc is enabled, this holds the array of user -* specified control values for mba_sc in MBps, indexed -* by closid */ -struct rdt_domain { +struct rdt_mon_domain {struct rdt_domain_hdr hdr;unsigned long *rmid_busy_llc;struct mbm_state *mbm_total;@@ -96,9 +107,6 @@ struct rdt_domain {struct delayed_work cqm_limbo;int mbm_work_cpu;int cqm_work_cpu; -struct pseudo_lock_region *plr; -struct resctrl_staged_config staged_config[CDP_NUM_TYPES ]; -u32 *mbps_val; };/** @@ -202,7 +210,7 @@ struct rdt_resource {const char *format_str;int (*parse_ctrlval)(struct rdt_parse_data *data,struct resctrl_schema *s, -struct rdt_domain *d); +struct rdt_ctrl_domain *d);struct list_head evt_list;unsigned long fflags;bool cdp_capable;@@ -236,15 +244,15 @@ int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid);* Update the ctrl_val and apply this config right now. * Must be called on one of the domain's CPUs. */ -int resctrl_arch_update_one (struct rdt_resource *r,struct rdt_domain *d, +int resctrl_arch_update_one (struct rdt_resource *r,struct rdt_ctrl_domain *d,u32 closid,enum resctrl_conf_type t,u32 cfg_val); -u32 resctrl_arch_get_config (struct rdt_resource *r,struct rdt_domain *d, +u32 resctrl_arch_get_config (struct rdt_resource *r,struct rdt_ctrl_domain *d,u32 closid,enum resctrl_conf_type type); -int resctrl_online_ctrl_domain (struct rdt_resource *r,struct rdt_domain *d); -int resctrl_online_mon_domain (struct rdt_resource *r,struct rdt_domain *d); -void resctrl_offline_ctrl_domain (struct rdt_resource *r,struct rdt_domain *d); -void resctrl_offline_mon_domain (struct rdt_resource *r,struct rdt_domain *d); +int resctrl_online_ctrl_domain (struct rdt_resource *r,struct rdt_ctrl_domain *d); +int resctrl_online_mon_domain (struct rdt_resource *r,struct rdt_mon_domain *d); +void resctrl_offline_ctrl_domain (struct rdt_resource *r,struct rdt_ctrl_domain *d); +void resctrl_offline_mon_domain (struct rdt_resource *r,struct rdt_mon_domain *d);/** * resctrl_arch_rmid_read() - Read the eventid counter corresponding to rmid @@ -260,7 +268,7 @@ void resctrl_offline_mon_domain(struct rdt_resource *r, struct rdt_domain *d);* Return: * 0 on success, or -EIO, -EINVAL etc on error. */ -int resctrl_arch_rmid_read (struct rdt_resource *r,struct rdt_domain *d, +int resctrl_arch_rmid_read (struct rdt_resource *r,struct rdt_mon_domain *d,u32 rmid,enum resctrl_event_id eventid,u64 *val);/** @@ -273,7 +281,7 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain *d,* * This can be called from any CPU. */ -void resctrl_arch_reset_rmid (struct rdt_resource *r,struct rdt_domain *d, +void resctrl_arch_reset_rmid (struct rdt_resource *r,struct rdt_mon_domain *d,u32 rmid,enum resctrl_event_id eventid);/** @@ -285,7 +293,7 @@ void resctrl_arch_reset_rmid(struct rdt_resource *r, struct rdt_domain *d,* * This can be called from any CPU. */ -void resctrl_arch_reset_rmid_all (struct rdt_resource *r,struct rdt_domain *d); +void resctrl_arch_reset_rmid_all (struct rdt_resource *r,struct rdt_mon_domain *d);extern unsigned int resctrl_rmid_realloc_threshold;extern unsigned int resctrl_rmid_realloc_limit;arch/x86/kernel/cpu/resctrl/internal.h +38
-22@@ -107,7 +107,7 @@ union mon_data_bits {struct rmid_read {struct rdtgroup *rgrp;struct rdt_resource *r; -struct rdt_domain *d; +struct rdt_mon_domain *d;enum resctrl_event_id evtid;bool first;int err;@@ -192,7 +192,7 @@ struct mongroup {*/ struct pseudo_lock_region {struct resctrl_schema *s; -struct rdt_domain *d; +struct rdt_ctrl_domain *d;u32 cbm;wait_queue_head_t lock_thread_wq;int thread_done;@@ -319,25 +319,41 @@ struct arch_mbm_state { };/** -* struct rdt_hw_domain - Arch private attributes of a set of CPUs that share -* a resource +* struct rdt_hw_ctrl_domain - Arch private attributes of a set of CPUs that share +* a resource for a control function * @d_resctrl: Properties exposed to the resctrl file system * @ctrl_val: array of cache or mem ctrl values (indexed by CLOSID) +* +* Members of this structure are accessed via helpers that provide abstraction. +*/ +struct rdt_hw_ctrl_domain { +struct rdt_ctrl_domain d_resctrl; +u32 *ctrl_val; +}; + +/** +* struct rdt_hw_mon_domain - Arch private attributes of a set of CPUs that share +* a resource for a monitor function +* @d_resctrl: Properties exposed to the resctrl file system * @arch_mbm_total: arch private state for MBM total bandwidth * @arch_mbm_local: arch private state for MBM local bandwidth * * Members of this structure are accessed via helpers that provide abstraction. */ -struct rdt_hw_domain { -struct rdt_domain d_resctrl; -u32 *ctrl_val; +struct rdt_hw_mon_domain { +struct rdt_mon_domain d_resctrl;struct arch_mbm_state *arch_mbm_total;struct arch_mbm_state *arch_mbm_local; }; -static inline struct rdt_hw_domain *resctrl_to_arch_dom (struct rdt_domain *r) +static inline struct rdt_hw_ctrl_domain *resctrl_to_arch_ctrl_dom (struct rdt_ctrl_domain *r) +{ + return container_of(r, struct rdt_hw_ctrl_domain, d_resctrl); +} + +static inline struct rdt_hw_mon_domain *resctrl_to_arch_mon_dom (struct rdt_mon_domain *r) { - return container_of(r, struct rdt_hw_domain, d_resctrl); + return container_of(r, struct rdt_hw_mon_domain, d_resctrl); }/** @@ -405,7 +421,7 @@ struct rdt_hw_resource {struct rdt_resource r_resctrl;u32 num_closid;unsigned int msr_base; -void (*msr_update) (struct rdt_domain *d,struct msr_param *m, +void (*msr_update) (struct rdt_ctrl_domain *d,struct msr_param *m,struct rdt_resource *r);unsigned int mon_scale;unsigned int mbm_width;@@ -418,9 +434,9 @@ static inline struct rdt_hw_resource *resctrl_to_arch_res(struct rdt_resource *r }int parse_cbm (struct rdt_parse_data *data,struct resctrl_schema *s, -struct rdt_domain *d); +struct rdt_ctrl_domain *d);int parse_bw (struct rdt_parse_data *data,struct resctrl_schema *s, -struct rdt_domain *d); +struct rdt_ctrl_domain *d);extern struct mutex rdtgroup_mutex;@@ -526,21 +542,21 @@ 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,struct seq_file *s,void *v); -bool rdtgroup_cbm_overlaps (struct resctrl_schema *s,struct rdt_domain *d, +bool rdtgroup_cbm_overlaps (struct resctrl_schema *s,struct rdt_ctrl_domain *d,unsigned long cbm,int closid,bool exclusive); -unsigned int rdtgroup_cbm_to_size (struct rdt_resource *r,struct rdt_domain *d, +unsigned int rdtgroup_cbm_to_size (struct rdt_resource *r,struct rdt_ctrl_domain *d,unsigned long cbm);enum rdtgrp_mode rdtgroup_mode_by_closid (int closid);int rdtgroup_tasks_assigned (struct rdtgroup *r);int rdtgroup_locksetup_enter (struct rdtgroup *rdtgrp);int rdtgroup_locksetup_exit (struct rdtgroup *rdtgrp); -bool rdtgroup_cbm_overlaps_pseudo_locked (struct rdt_domain *d,unsigned long cbm); -bool rdtgroup_pseudo_locked_in_hierarchy (struct rdt_domain *d); +bool rdtgroup_cbm_overlaps_pseudo_locked (struct rdt_ctrl_domain *d,unsigned long cbm); +bool rdtgroup_pseudo_locked_in_hierarchy (struct rdt_ctrl_domain *d);int rdt_pseudo_lock_init (void );void rdt_pseudo_lock_release (void );int rdtgroup_pseudo_lock_create (struct rdtgroup *rdtgrp);void rdtgroup_pseudo_lock_remove (struct rdtgroup *rdtgrp); -struct rdt_domain *get_ctrl_domain_from_cpu (int cpu,struct rdt_resource *r); +struct rdt_ctrl_domain *get_ctrl_domain_from_cpu (int cpu,struct rdt_resource *r);int closids_supported (void );void closid_free (int closid);int alloc_rmid (void );@@ -550,17 +566,17 @@ bool __init rdt_cpu_has(int flag);void mon_event_count (void *info);int rdtgroup_mondata_show (struct seq_file *m,void *arg);void mon_event_read (struct rmid_read *rr,struct rdt_resource *r, -struct rdt_domain *d,struct rdtgroup *rdtgrp, +struct rdt_mon_domain *d,struct rdtgroup *rdtgrp,int evtid,int first); -void mbm_setup_overflow_handler (struct rdt_domain *dom, +void mbm_setup_overflow_handler (struct rdt_mon_domain *dom,unsigned long delay_ms);void mbm_handle_overflow (struct work_struct *work);void __init intel_rdt_mbm_apply_quirk (void );bool is_mba_sc (struct rdt_resource *r); -void cqm_setup_limbo_handler (struct rdt_domain *dom,unsigned long delay_ms); +void cqm_setup_limbo_handler (struct rdt_mon_domain *dom,unsigned long delay_ms);void cqm_handle_limbo (struct work_struct *work); -bool has_busy_rmid (struct rdt_resource *r,struct rdt_domain *d); -void __check_limbo (struct rdt_domain *d,bool force_free); +bool has_busy_rmid (struct rdt_resource *r,struct rdt_mon_domain *d); +void __check_limbo (struct rdt_mon_domain *d,bool force_free);void rdt_domain_reconfigure_cdp (struct rdt_resource *r);void __init thread_throttle_mode_init (void );void __init mbm_config_rftype_init (const char *config);arch/x86/kernel/cpu/resctrl/core.c +46
-41@@ -49,12 +49,12 @@ int max_name_width, max_data_width;bool rdt_alloc_capable;static void -mba_wrmsr_intel (struct rdt_domain *d,struct msr_param *m, +mba_wrmsr_intel (struct rdt_ctrl_domain *d,struct msr_param *m,struct rdt_resource *r);static void -cat_wrmsr (struct rdt_domain *d,struct msr_param *m,struct rdt_resource *r); +cat_wrmsr (struct rdt_ctrl_domain *d,struct msr_param *m,struct rdt_resource *r);static void -mba_wrmsr_amd (struct rdt_domain *d,struct msr_param *m, +mba_wrmsr_amd (struct rdt_ctrl_domain *d,struct msr_param *m,struct rdt_resource *r);#define ctrl_domain_init (id) LIST_HEAD_INIT(rdt_resources_all[id].r_resctrl.ctrl_domains)@@ -307,11 +307,11 @@ static void rdt_get_cdp_l2_config(void) }static void -mba_wrmsr_amd (struct rdt_domain *d,struct msr_param *m,struct rdt_resource *r) +mba_wrmsr_amd (struct rdt_ctrl_domain *d,struct msr_param *m,struct rdt_resource *r) { -unsigned int i; -struct rdt_hw_domain *hw_dom =resctrl_to_arch_dom (d); +struct rdt_hw_ctrl_domain *hw_dom =resctrl_to_arch_ctrl_dom (d);struct rdt_hw_resource *hw_res =resctrl_to_arch_res (r); +unsigned int i;for (i = m->low; i < m->high; i++)wrmsrl (hw_res->msr_base + i, hw_dom->ctrl_val[i]);@@ -332,12 +332,12 @@ static u32 delay_bw_map(unsigned long bw, struct rdt_resource *r) }static void -mba_wrmsr_intel (struct rdt_domain *d,struct msr_param *m, +mba_wrmsr_intel (struct rdt_ctrl_domain *d,struct msr_param *m,struct rdt_resource *r) { -unsigned int i; -struct rdt_hw_domain *hw_dom =resctrl_to_arch_dom (d); +struct rdt_hw_ctrl_domain *hw_dom =resctrl_to_arch_ctrl_dom (d);struct rdt_hw_resource *hw_res =resctrl_to_arch_res (r); +unsigned int i;/* Write the delay values for mba. */ for (i = m->low; i < m->high; i++)@@ -345,19 +345,19 @@ mba_wrmsr_intel(struct rdt_domain *d, struct msr_param *m, }static void -cat_wrmsr (struct rdt_domain *d,struct msr_param *m,struct rdt_resource *r) +cat_wrmsr (struct rdt_ctrl_domain *d,struct msr_param *m,struct rdt_resource *r) { -unsigned int i; -struct rdt_hw_domain *hw_dom =resctrl_to_arch_dom (d); +struct rdt_hw_ctrl_domain *hw_dom =resctrl_to_arch_ctrl_dom (d);struct rdt_hw_resource *hw_res =resctrl_to_arch_res (r); +unsigned int i;for (i = m->low; i < m->high; i++)wrmsrl (hw_res->msr_base + i, hw_dom->ctrl_val[i]); } -struct rdt_domain *get_ctrl_domain_from_cpu (int cpu,struct rdt_resource *r) +struct rdt_ctrl_domain *get_ctrl_domain_from_cpu (int cpu,struct rdt_resource *r) { -struct rdt_domain *d; +struct rdt_ctrl_domain *d;list_for_each_entry (d, &r->ctrl_domains, hdr.list) {/* Find the domain that contains this CPU */ @@ -379,7 +379,7 @@ void rdt_ctrl_update(void *arg)struct rdt_hw_resource *hw_res =resctrl_to_arch_res (m->res);struct rdt_resource *r = m->res;int cpu =smp_processor_id (); -struct rdt_domain *d; +struct rdt_ctrl_domain *d; d =get_ctrl_domain_from_cpu (cpu, r);if (d) {@@ -434,18 +434,23 @@ static void setup_default_ctrlval(struct rdt_resource *r, u32 *dc) *dc = r->default_ctrl; } -static void domain_free (struct rdt_hw_domain *hw_dom) +static void ctrl_domain_free (struct rdt_hw_ctrl_domain *hw_dom) +{ +kfree (hw_dom->ctrl_val); +kfree (hw_dom); +} + +static void mon_domain_free (struct rdt_hw_mon_domain *hw_dom) {kfree (hw_dom->arch_mbm_total);kfree (hw_dom->arch_mbm_local); -kfree (hw_dom->ctrl_val);kfree (hw_dom); } -static int domain_setup_ctrlval (struct rdt_resource *r,struct rdt_domain *d) +static int domain_setup_ctrlval (struct rdt_resource *r,struct rdt_ctrl_domain *d) { +struct rdt_hw_ctrl_domain *hw_dom =resctrl_to_arch_ctrl_dom (d);struct rdt_hw_resource *hw_res =resctrl_to_arch_res (r); -struct rdt_hw_domain *hw_dom =resctrl_to_arch_dom (d);struct msr_param m;u32 *dc;@@ -468,7 +473,7 @@ static int domain_setup_ctrlval(struct rdt_resource *r, struct rdt_domain *d)* @num_rmid: The size of the MBM counter array * @hw_dom: The domain that owns the allocated arrays */ -static int arch_domain_mbm_alloc (u32 num_rmid,struct rdt_hw_domain *hw_dom) +static int arch_domain_mbm_alloc (u32 num_rmid,struct rdt_hw_mon_domain *hw_dom) {size_t tsize;@@ -507,10 +512,10 @@ static int get_domain_id_from_scope(int cpu, enum resctrl_scope scope)static void domain_add_cpu_ctrl (int cpu,struct rdt_resource *r) {int id =get_domain_id_from_scope (cpu, r->ctrl_scope); +struct rdt_hw_ctrl_domain *hw_dom;struct list_head *add_pos =NULL ; -struct rdt_hw_domain *hw_dom;struct rdt_domain_hdr *hdr; -struct rdt_domain *d; +struct rdt_ctrl_domain *d;int err;if (id <0 ) {@@ -524,7 +529,7 @@ static void domain_add_cpu_ctrl(int cpu, struct rdt_resource *r)if (WARN_ON_ONCE (hdr->type !=RESCTRL_CTRL_DOMAIN ))return ; - d = container_of(hdr, struct rdt_domain, hdr); + d = container_of(hdr, struct rdt_ctrl_domain, hdr);cpumask_set_cpu (cpu, &d->hdr.cpu_mask);if (r->cache.arch_has_per_cpu_cfg)@@ -544,7 +549,7 @@ static void domain_add_cpu_ctrl(int cpu, struct rdt_resource *r)rdt_domain_reconfigure_cdp (r);if (domain_setup_ctrlval (r, d)) { -domain_free (hw_dom); +ctrl_domain_free (hw_dom);return ; }@@ -553,17 +558,17 @@ static void domain_add_cpu_ctrl(int cpu, struct rdt_resource *r) err =resctrl_online_ctrl_domain (r, d);if (err) {list_del (&d->hdr.list); -domain_free (hw_dom); +ctrl_domain_free (hw_dom); } }static void domain_add_cpu_mon (int cpu,struct rdt_resource *r) {int id =get_domain_id_from_scope (cpu, r->mon_scope); +struct rdt_hw_mon_domain *hw_dom;struct list_head *add_pos =NULL ; -struct rdt_hw_domain *hw_dom;struct rdt_domain_hdr *hdr; -struct rdt_domain *d; +struct rdt_mon_domain *d;int err;if (id <0 ) {@@ -577,7 +582,7 @@ static void domain_add_cpu_mon(int cpu, struct rdt_resource *r)if (WARN_ON_ONCE (hdr->type !=RESCTRL_MON_DOMAIN ))return ; - d = container_of(hdr, struct rdt_domain, hdr); + d = container_of(hdr, struct rdt_mon_domain, hdr);cpumask_set_cpu (cpu, &d->hdr.cpu_mask);return ;@@ -593,7 +598,7 @@ static void domain_add_cpu_mon(int cpu, struct rdt_resource *r)cpumask_set_cpu (cpu, &d->hdr.cpu_mask);if (arch_domain_mbm_alloc (r->num_rmid, hw_dom)) { -domain_free (hw_dom); +mon_domain_free (hw_dom);return ; }@@ -602,7 +607,7 @@ static void domain_add_cpu_mon(int cpu, struct rdt_resource *r) err =resctrl_online_mon_domain (r, d);if (err) {list_del (&d->hdr.list); -domain_free (hw_dom); +mon_domain_free (hw_dom); } }@@ -620,9 +625,9 @@ static void domain_add_cpu(int cpu, struct rdt_resource *r)static void domain_remove_cpu_ctrl (int cpu,struct rdt_resource *r) {int id =get_domain_id_from_scope (cpu, r->ctrl_scope); -struct rdt_hw_domain *hw_dom; +struct rdt_hw_ctrl_domain *hw_dom;struct rdt_domain_hdr *hdr; -struct rdt_domain *d; +struct rdt_ctrl_domain *d;if (id <0 ) { pr_warn_once("Can't find control domain id for CPU:%d scope:%d for resource %s\n",@@ -640,8 +645,8 @@ static void domain_remove_cpu_ctrl(int cpu, struct rdt_resource *r)if (WARN_ON_ONCE (hdr->type !=RESCTRL_CTRL_DOMAIN ))return ; - d = container_of(hdr, struct rdt_domain, hdr); - hw_dom =resctrl_to_arch_dom (d); + d = container_of(hdr, struct rdt_ctrl_domain, hdr); + hw_dom =resctrl_to_arch_ctrl_dom (d);cpumask_clear_cpu (cpu, &d->hdr.cpu_mask);if (cpumask_empty (&d->hdr.cpu_mask)) {@@ -649,12 +654,12 @@ static void domain_remove_cpu_ctrl(int cpu, struct rdt_resource *r)list_del (&d->hdr.list);/* -* rdt_domain "d" is going to be freed below, so clear +* rdt_ctrl_domain "d" is going to be freed below, so clear * its pointer from pseudo_lock_region struct. */ if (d->plr) d->plr->d =NULL ; -domain_free (hw_dom); +ctrl_domain_free (hw_dom);return ; }@@ -663,9 +668,9 @@ static void domain_remove_cpu_ctrl(int cpu, struct rdt_resource *r)static void domain_remove_cpu_mon (int cpu,struct rdt_resource *r) {int id =get_domain_id_from_scope (cpu, r->mon_scope); -struct rdt_hw_domain *hw_dom; +struct rdt_hw_mon_domain *hw_dom;struct rdt_domain_hdr *hdr; -struct rdt_domain *d; +struct rdt_mon_domain *d;if (id <0 ) { pr_warn_once("Can't find monitor domain id for CPU:%d scope:%d for resource %s\n",@@ -683,14 +688,14 @@ static void domain_remove_cpu_mon(int cpu, struct rdt_resource *r)if (WARN_ON_ONCE (hdr->type !=RESCTRL_MON_DOMAIN ))return ; - d = container_of(hdr, struct rdt_domain, hdr); - hw_dom =resctrl_to_arch_dom (d); + d = container_of(hdr, struct rdt_mon_domain, hdr); + hw_dom =resctrl_to_arch_mon_dom (d);cpumask_clear_cpu (cpu, &d->hdr.cpu_mask);if (cpumask_empty (&d->hdr.cpu_mask)) {resctrl_offline_mon_domain (r, d);list_del (&d->hdr.list); -domain_free (hw_dom); +mon_domain_free (hw_dom);return ; }arch/x86/kernel/cpu/resctrl/ctrlmondata.c +16
-16@@ -58,7 +58,7 @@ static bool bw_validate(char *buf, unsigned long *data, struct rdt_resource *r) }int parse_bw (struct rdt_parse_data *data,struct resctrl_schema *s, -struct rdt_domain *d) +struct rdt_ctrl_domain *d) {struct resctrl_staged_config *cfg;u32 closid = data->rdtgrp->closid;@@ -137,7 +137,7 @@ static bool cbm_validate(char *buf, u32 *data, struct rdt_resource *r)* resource type. */ int parse_cbm (struct rdt_parse_data *data,struct resctrl_schema *s, -struct rdt_domain *d) +struct rdt_ctrl_domain *d) {struct rdtgroup *rdtgrp = data->rdtgrp;struct resctrl_staged_config *cfg;@@ -206,8 +206,8 @@ static int parse_line(char *line, struct resctrl_schema *s,struct resctrl_staged_config *cfg;struct rdt_resource *r = s->res;struct rdt_parse_data data; +struct rdt_ctrl_domain *d;char *dom =NULL , *id; -struct rdt_domain *d;unsigned long dom_id; if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP &&@@ -267,11 +267,11 @@ static u32 get_config_index(u32 closid, enum resctrl_conf_type type) } } -static bool apply_config (struct rdt_hw_domain *hw_dom, +static bool apply_config (struct rdt_hw_ctrl_domain *hw_dom,struct resctrl_staged_config *cfg,u32 idx,cpumask_var_t cpu_mask) { -struct rdt_domain *dom = &hw_dom->d_resctrl; +struct rdt_ctrl_domain *dom = &hw_dom->d_resctrl;if (cfg->new_ctrl != hw_dom->ctrl_val[idx]) {cpumask_set_cpu (cpumask_any (&dom->hdr.cpu_mask), cpu_mask);@@ -283,11 +283,11 @@ static bool apply_config(struct rdt_hw_domain *hw_dom,return false; } -int resctrl_arch_update_one (struct rdt_resource *r,struct rdt_domain *d, +int resctrl_arch_update_one (struct rdt_resource *r,struct rdt_ctrl_domain *d,u32 closid,enum resctrl_conf_type t,u32 cfg_val) { +struct rdt_hw_ctrl_domain *hw_dom =resctrl_to_arch_ctrl_dom (d);struct rdt_hw_resource *hw_res =resctrl_to_arch_res (r); -struct rdt_hw_domain *hw_dom =resctrl_to_arch_dom (d);u32 idx =get_config_index (closid, t);struct msr_param msr_param;@@ -307,11 +307,11 @@ int resctrl_arch_update_one(struct rdt_resource *r, struct rdt_domain *d,int resctrl_arch_update_domains (struct rdt_resource *r,u32 closid) {struct resctrl_staged_config *cfg; -struct rdt_hw_domain *hw_dom; +struct rdt_hw_ctrl_domain *hw_dom;struct msr_param msr_param; +struct rdt_ctrl_domain *d;enum resctrl_conf_type t;cpumask_var_t cpu_mask; -struct rdt_domain *d;u32 idx;if (!zalloc_cpumask_var (&cpu_mask,GFP_KERNEL ))@@ -319,7 +319,7 @@ int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid) msr_param.res =NULL ;list_for_each_entry (d, &r->ctrl_domains, hdr.list) { - hw_dom =resctrl_to_arch_dom (d); + hw_dom =resctrl_to_arch_ctrl_dom (d);for (t =0 ; t <CDP_NUM_TYPES ; t++) { cfg = &hw_dom->d_resctrl.staged_config[t];if (!cfg->have_new_ctrl)@@ -449,10 +449,10 @@ ssize_t rdtgroup_schemata_write(struct kernfs_open_file *of,return ret ?: nbytes; } -u32 resctrl_arch_get_config (struct rdt_resource *r,struct rdt_domain *d, +u32 resctrl_arch_get_config (struct rdt_resource *r,struct rdt_ctrl_domain *d,u32 closid,enum resctrl_conf_type type) { -struct rdt_hw_domain *hw_dom =resctrl_to_arch_dom (d); +struct rdt_hw_ctrl_domain *hw_dom =resctrl_to_arch_ctrl_dom (d);u32 idx =get_config_index (closid, type);return hw_dom->ctrl_val[idx];@@ -461,7 +461,7 @@ u32 resctrl_arch_get_config(struct rdt_resource *r, struct rdt_domain *d,static void show_doms (struct seq_file *s,struct resctrl_schema *schema,int closid) {struct rdt_resource *r = schema->res; -struct rdt_domain *dom; +struct rdt_ctrl_domain *dom;bool sep = false;u32 ctrl_val;@@ -523,7 +523,7 @@ int rdtgroup_schemata_show(struct kernfs_open_file *of, }void mon_event_read (struct rmid_read *rr,struct rdt_resource *r, -struct rdt_domain *d,struct rdtgroup *rdtgrp, +struct rdt_mon_domain *d,struct rdtgroup *rdtgrp,int evtid,int first) {/* @@ -543,11 +543,11 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg) {struct kernfs_open_file *of = m->private;struct rdt_domain_hdr *hdr; +struct rdt_mon_domain *d;u32 resid, evtid, domid;struct rdtgroup *rdtgrp;struct rdt_resource *r;union mon_data_bits md; -struct rdt_domain *d;struct rmid_read rr;int ret =0 ;@@ -568,7 +568,7 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg) ret = -ENOENT ; goto out; } - d = container_of(hdr, struct rdt_domain, hdr); + d = container_of(hdr, struct rdt_mon_domain, hdr);mon_event_read (&rr, r, d, rdtgrp, evtid, false);arch/x86/kernel/cpu/resctrl/monitor.c +20
-20@@ -170,7 +170,7 @@ static int __rmid_read(u32 rmid, enum resctrl_event_id eventid, u64 *val)return 0 ; } -static struct arch_mbm_state *get_arch_mbm_state (struct rdt_hw_domain *hw_dom, +static struct arch_mbm_state *get_arch_mbm_state (struct rdt_hw_mon_domain *hw_dom,u32 rmid,enum resctrl_event_id eventid) {@@ -189,10 +189,10 @@ static struct arch_mbm_state *get_arch_mbm_state(struct rdt_hw_domain *hw_dom,return NULL ; } -void resctrl_arch_reset_rmid (struct rdt_resource *r,struct rdt_domain *d, +void resctrl_arch_reset_rmid (struct rdt_resource *r,struct rdt_mon_domain *d,u32 rmid,enum resctrl_event_id eventid) { -struct rdt_hw_domain *hw_dom =resctrl_to_arch_dom (d); +struct rdt_hw_mon_domain *hw_dom =resctrl_to_arch_mon_dom (d);struct arch_mbm_state *am; am =get_arch_mbm_state (hw_dom, rmid, eventid);@@ -208,9 +208,9 @@ void resctrl_arch_reset_rmid(struct rdt_resource *r, struct rdt_domain *d,* Assumes that hardware counters are also reset and thus that there is * no need to record initial non-zero counts. */ -void resctrl_arch_reset_rmid_all (struct rdt_resource *r,struct rdt_domain *d) +void resctrl_arch_reset_rmid_all (struct rdt_resource *r,struct rdt_mon_domain *d) { -struct rdt_hw_domain *hw_dom =resctrl_to_arch_dom (d); +struct rdt_hw_mon_domain *hw_dom =resctrl_to_arch_mon_dom (d);if (is_mbm_total_enabled ()) memset(hw_dom->arch_mbm_total, 0,@@ -229,11 +229,11 @@ static u64 mbm_overflow_count(u64 prev_msr, u64 cur_msr, unsigned int width)return chunks >> shift; } -int resctrl_arch_rmid_read (struct rdt_resource *r,struct rdt_domain *d, +int resctrl_arch_rmid_read (struct rdt_resource *r,struct rdt_mon_domain *d,u32 rmid,enum resctrl_event_id eventid,u64 *val) { +struct rdt_hw_mon_domain *hw_dom =resctrl_to_arch_mon_dom (d);struct rdt_hw_resource *hw_res =resctrl_to_arch_res (r); -struct rdt_hw_domain *hw_dom =resctrl_to_arch_dom (d);struct arch_mbm_state *am;u64 msr_val, chunks;int ret;@@ -266,7 +266,7 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain *d,* decrement the count. If the busy count gets to zero on an RMID, we * free the RMID */ -void __check_limbo (struct rdt_domain *d,bool force_free) +void __check_limbo (struct rdt_mon_domain *d,bool force_free) {struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl;struct rmid_entry *entry;@@ -305,7 +305,7 @@ void __check_limbo(struct rdt_domain *d, bool force_free) } } -bool has_busy_rmid (struct rdt_resource *r,struct rdt_domain *d) +bool has_busy_rmid (struct rdt_resource *r,struct rdt_mon_domain *d) {return find_first_bit (d->rmid_busy_llc, r->num_rmid) != r->num_rmid; }@@ -334,7 +334,7 @@ int alloc_rmid(void)static void add_rmid_to_limbo (struct rmid_entry *entry) {struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl; -struct rdt_domain *d; +struct rdt_mon_domain *d;int cpu, err;u64 val =0 ;@@ -383,7 +383,7 @@ void free_rmid(u32 rmid)list_add_tail (&entry->list, &rmid_free_lru); } -static struct mbm_state *get_mbm_state (struct rdt_domain *d,u32 rmid, +static struct mbm_state *get_mbm_state (struct rdt_mon_domain *d,u32 rmid,enum resctrl_event_id evtid) {switch (evtid) {@@ -516,13 +516,13 @@ void mon_event_count(void *info)* throttle MSRs already have low percentage values. To avoid * unnecessarily restricting such rdtgroups, we also increase the bandwidth. */ -static void update_mba_bw (struct rdtgroup *rgrp,struct rdt_domain *dom_mbm) +static void update_mba_bw (struct rdtgroup *rgrp,struct rdt_mon_domain *dom_mbm) {u32 closid, rmid, cur_msr_val, new_msr_val;struct mbm_state *pmbm_data, *cmbm_data; +struct rdt_ctrl_domain *dom_mba;u32 cur_bw, delta_bw, user_bw;struct rdt_resource *r_mba; -struct rdt_domain *dom_mba;struct list_head *head;struct rdtgroup *entry;@@ -600,7 +600,7 @@ static void update_mba_bw(struct rdtgroup *rgrp, struct rdt_domain *dom_mbm) } } -static void mbm_update (struct rdt_resource *r,struct rdt_domain *d,int rmid) +static void mbm_update (struct rdt_resource *r,struct rdt_mon_domain *d,int rmid) {struct rmid_read rr;@@ -640,13 +640,13 @@ void cqm_handle_limbo(struct work_struct *work) {unsigned long delay =msecs_to_jiffies (CQM_LIMBOCHECK_INTERVAL );int cpu =smp_processor_id (); +struct rdt_mon_domain *d;struct rdt_resource *r; -struct rdt_domain *d;mutex_lock (&rdtgroup_mutex); r = &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl; - d = container_of(work, struct rdt_domain, cqm_limbo.work); + d = container_of(work, struct rdt_mon_domain, cqm_limbo.work);__check_limbo (d, false);@@ -656,7 +656,7 @@ void cqm_handle_limbo(struct work_struct *work)mutex_unlock (&rdtgroup_mutex); } -void cqm_setup_limbo_handler (struct rdt_domain *dom,unsigned long delay_ms) +void cqm_setup_limbo_handler (struct rdt_mon_domain *dom,unsigned long delay_ms) {unsigned long delay =msecs_to_jiffies (delay_ms);int cpu;@@ -672,9 +672,9 @@ void mbm_handle_overflow(struct work_struct *work)unsigned long delay =msecs_to_jiffies (MBM_OVERFLOW_INTERVAL );struct rdtgroup *prgrp, *crgrp;int cpu =smp_processor_id (); +struct rdt_mon_domain *d;struct list_head *head;struct rdt_resource *r; -struct rdt_domain *d;mutex_lock (&rdtgroup_mutex);@@ -682,7 +682,7 @@ void mbm_handle_overflow(struct work_struct *work) goto out_unlock; r = &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl; - d = container_of(work, struct rdt_domain, mbm_over.work); + d = container_of(work, struct rdt_mon_domain, mbm_over.work);list_for_each_entry (prgrp, &rdt_all_groups, rdtgroup_list) {mbm_update (r, d, prgrp->mon.rmid);@@ -701,7 +701,7 @@ void mbm_handle_overflow(struct work_struct *work)mutex_unlock (&rdtgroup_mutex); } -void mbm_setup_overflow_handler (struct rdt_domain *dom,unsigned long delay_ms) +void mbm_setup_overflow_handler (struct rdt_mon_domain *dom,unsigned long delay_ms) {unsigned long delay =msecs_to_jiffies (delay_ms);int cpu;arch/x86/kernel/cpu/resctrl/pseudo_lock.c +3
-3@@ -814,7 +814,7 @@ int rdtgroup_locksetup_exit(struct rdtgroup *rdtgrp)* Return: true if @cbm overlaps with pseudo-locked region on @d, false * otherwise. */ -bool rdtgroup_cbm_overlaps_pseudo_locked (struct rdt_domain *d,unsigned long cbm) +bool rdtgroup_cbm_overlaps_pseudo_locked (struct rdt_ctrl_domain *d,unsigned long cbm) {unsigned int cbm_len;unsigned long cbm_b;@@ -841,11 +841,11 @@ bool rdtgroup_cbm_overlaps_pseudo_locked(struct rdt_domain *d, unsigned long cbm* if it is not possible to test due to memory allocation issue, * false otherwise. */ -bool rdtgroup_pseudo_locked_in_hierarchy (struct rdt_domain *d) +bool rdtgroup_pseudo_locked_in_hierarchy (struct rdt_ctrl_domain *d) { +struct rdt_ctrl_domain *d_i;cpumask_var_t cpu_with_psl;struct rdt_resource *r; -struct rdt_domain *d_i;bool ret = false;if (!zalloc_cpumask_var (&cpu_with_psl,GFP_KERNEL ))arch/x86/kernel/cpu/resctrl/rdtgroup.c +31
-31@@ -85,8 +85,8 @@ void rdt_last_cmd_printf(const char *fmt, ...)void rdt_staged_configs_clear (void ) { +struct rdt_ctrl_domain *dom;struct rdt_resource *r; -struct rdt_domain *dom;lockdep_assert_held (&rdtgroup_mutex);@@ -976,7 +976,7 @@ static int rdt_bit_usage_show(struct kernfs_open_file *of,unsigned long sw_shareable =0 , hw_shareable =0 ;unsigned long exclusive =0 , pseudo_locked =0 ;struct rdt_resource *r = s->res; -struct rdt_domain *dom; +struct rdt_ctrl_domain *dom;int i, hwb, swb, excl, psl;enum rdtgrp_mode mode;bool sep = false;@@ -1205,7 +1205,7 @@ static int rdt_has_sparse_bitmasks_show(struct kernfs_open_file *of,* * Return: false if CBM does not overlap, true if it does. */ -static bool __rdtgroup_cbm_overlaps (struct rdt_resource *r,struct rdt_domain *d, +static bool __rdtgroup_cbm_overlaps (struct rdt_resource *r,struct rdt_ctrl_domain *d,unsigned long cbm,int closid,enum resctrl_conf_type type,bool exclusive) {@@ -1260,7 +1260,7 @@ static bool __rdtgroup_cbm_overlaps(struct rdt_resource *r, struct rdt_domain *d* * Return: true if CBM overlap detected, false if there is no overlap */ -bool rdtgroup_cbm_overlaps (struct resctrl_schema *s,struct rdt_domain *d, +bool rdtgroup_cbm_overlaps (struct resctrl_schema *s,struct rdt_ctrl_domain *d,unsigned long cbm,int closid,bool exclusive) {enum resctrl_conf_type peer_type =resctrl_peer_type (s->conf_type);@@ -1291,10 +1291,10 @@ bool rdtgroup_cbm_overlaps(struct resctrl_schema *s, struct rdt_domain *d,static bool rdtgroup_mode_test_exclusive (struct rdtgroup *rdtgrp) {int closid = rdtgrp->closid; +struct rdt_ctrl_domain *d;struct resctrl_schema *s;struct rdt_resource *r;bool has_cache = false; -struct rdt_domain *d;u32 ctrl;list_for_each_entry (s, &resctrl_schema_all, list) {@@ -1407,7 +1407,7 @@ static ssize_t rdtgroup_mode_write(struct kernfs_open_file *of,* bitmap functions work correctly. */ unsigned int rdtgroup_cbm_to_size (struct rdt_resource *r, -struct rdt_domain *d,unsigned long cbm) +struct rdt_ctrl_domain *d,unsigned long cbm) {struct cpu_cacheinfo *ci;unsigned int size =0 ;@@ -1439,9 +1439,9 @@ static int rdtgroup_size_show(struct kernfs_open_file *of, {struct resctrl_schema *schema;enum resctrl_conf_type type; +struct rdt_ctrl_domain *d;struct rdtgroup *rdtgrp;struct rdt_resource *r; -struct rdt_domain *d;unsigned int size;int ret =0 ;u32 closid;@@ -1553,7 +1553,7 @@ static void mon_event_config_read(void *info) mon_info->mon_config = msrval &MAX_EVT_CONFIG_BITS ; } -static void mondata_config_read (struct rdt_domain *d,struct mon_config_info *mon_info) +static void mondata_config_read (struct rdt_mon_domain *d,struct mon_config_info *mon_info) {smp_call_function_any (&d->hdr.cpu_mask, mon_event_config_read, mon_info,1 ); }@@ -1561,7 +1561,7 @@ static void mondata_config_read(struct rdt_domain *d, struct mon_config_info *mostatic int mbm_config_show (struct seq_file *s,struct rdt_resource *r,u32 evtid) {struct mon_config_info mon_info = {0 }; -struct rdt_domain *dom; +struct rdt_mon_domain *dom;bool sep = false;mutex_lock (&rdtgroup_mutex);@@ -1618,7 +1618,7 @@ static void mon_event_config_write(void *info) }static int mbm_config_write_domain (struct rdt_resource *r, -struct rdt_domain *d,u32 evtid,u32 val) +struct rdt_mon_domain *d,u32 evtid,u32 val) {struct mon_config_info mon_info = {0 };int ret =0 ;@@ -1668,7 +1668,7 @@ static int mon_config_write(struct rdt_resource *r, char *tok, u32 evtid) {char *dom_str =NULL , *id_str;unsigned long dom_id, val; -struct rdt_domain *d; +struct rdt_mon_domain *d;int ret =0 ; next:@@ -2216,9 +2216,9 @@ static inline bool is_mba_linear(void)static int set_cache_qos_cfg (int level,bool enable) {void (*update)(void *arg); +struct rdt_ctrl_domain *d;struct rdt_resource *r_l;cpumask_var_t cpu_mask; -struct rdt_domain *d;int cpu;if (level ==RDT_RESOURCE_L3 )@@ -2265,7 +2265,7 @@ void rdt_domain_reconfigure_cdp(struct rdt_resource *r)l3_qos_cfg_update (&hw_res->cdp_enabled); } -static int mba_sc_domain_allocate (struct rdt_resource *r,struct rdt_domain *d) +static int mba_sc_domain_allocate (struct rdt_resource *r,struct rdt_ctrl_domain *d) {u32 num_closid =resctrl_arch_get_num_closid (r);int cpu =cpumask_any (&d->hdr.cpu_mask);@@ -2283,7 +2283,7 @@ static int mba_sc_domain_allocate(struct rdt_resource *r, struct rdt_domain *d) }static void mba_sc_domain_destroy (struct rdt_resource *r, -struct rdt_domain *d) +struct rdt_ctrl_domain *d) {kfree (d->mbps_val); d->mbps_val =NULL ;@@ -2309,7 +2309,7 @@ static int set_mba_sc(bool mba_sc) {struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_MBA ].r_resctrl;u32 num_closid =resctrl_arch_get_num_closid (r); -struct rdt_domain *d; +struct rdt_ctrl_domain *d;int i;if (!supports_mba_mbps () || mba_sc ==is_mba_sc (r))@@ -2578,7 +2578,7 @@ static int rdt_get_tree(struct fs_context *fc) {struct rdt_fs_context *ctx =rdt_fc2context (fc);unsigned long flags =RFTYPE_CTRL_BASE ; -struct rdt_domain *dom; +struct rdt_mon_domain *dom;struct rdt_resource *r;int ret;@@ -2762,10 +2762,10 @@ static int rdt_init_fs_context(struct fs_context *fc)static int reset_all_ctrls (struct rdt_resource *r) {struct rdt_hw_resource *hw_res =resctrl_to_arch_res (r); -struct rdt_hw_domain *hw_dom; +struct rdt_hw_ctrl_domain *hw_dom;struct msr_param msr_param; +struct rdt_ctrl_domain *d;cpumask_var_t cpu_mask; -struct rdt_domain *d;int i;if (!zalloc_cpumask_var (&cpu_mask,GFP_KERNEL ))@@ -2781,7 +2781,7 @@ static int reset_all_ctrls(struct rdt_resource *r)* from each domain to update the MSRs below. */ list_for_each_entry (d, &r->ctrl_domains, hdr.list) { - hw_dom =resctrl_to_arch_dom (d); + hw_dom =resctrl_to_arch_ctrl_dom (d);cpumask_set_cpu (cpumask_any (&d->hdr.cpu_mask), cpu_mask);for (i =0 ; i < hw_res->num_closid; i++)@@ -2976,7 +2976,7 @@ static void rmdir_mondata_subdir_allrdtgrp(struct rdt_resource *r, }static int mkdir_mondata_subdir (struct kernfs_node *parent_kn, -struct rdt_domain *d, +struct rdt_mon_domain *d,struct rdt_resource *r,struct rdtgroup *prgrp) {union mon_data_bits priv;@@ -3025,7 +3025,7 @@ static int mkdir_mondata_subdir(struct kernfs_node *parent_kn,* and "monitor" groups with given domain id. */ static void mkdir_mondata_subdir_allrdtgrp (struct rdt_resource *r, -struct rdt_domain *d) +struct rdt_mon_domain *d) {struct kernfs_node *parent_kn;struct rdtgroup *prgrp, *crgrp;@@ -3047,7 +3047,7 @@ static int mkdir_mondata_subdir_alldom(struct kernfs_node *parent_kn,struct rdt_resource *r, struct rdtgroup *prgrp) { - struct rdt_domain *dom; + struct rdt_mon_domain *dom;int ret;list_for_each_entry (dom, &r->mon_domains, hdr.list) {@@ -3149,7 +3149,7 @@ static u32 cbm_ensure_valid(u32 _val, struct rdt_resource *r)* Set the RDT domain up to start off with all usable allocations. That is, * all shareable and unused bits. All-zero CBM is invalid. */ -static int __init_one_rdt_domain (struct rdt_domain *d,struct resctrl_schema *s, +static int __init_one_rdt_domain (struct rdt_ctrl_domain *d,struct resctrl_schema *s,u32 closid) {enum resctrl_conf_type peer_type =resctrl_peer_type (s->conf_type);@@ -3229,7 +3229,7 @@ static int __init_one_rdt_domain(struct rdt_domain *d, struct resctrl_schema *s,*/ static int rdtgroup_init_cat (struct resctrl_schema *s,u32 closid) { -struct rdt_domain *d; +struct rdt_ctrl_domain *d;int ret;list_for_each_entry (d, &s->res->ctrl_domains, hdr.list) {@@ -3245,7 +3245,7 @@ static int rdtgroup_init_cat(struct resctrl_schema *s, u32 closid)static void rdtgroup_init_mba (struct rdt_resource *r,u32 closid) {struct resctrl_staged_config *cfg; -struct rdt_domain *d; +struct rdt_ctrl_domain *d;list_for_each_entry (d, &r->ctrl_domains, hdr.list) {if (is_mba_sc (r)) {@@ -3842,14 +3842,14 @@ static void __init rdtgroup_setup_default(void)mutex_unlock (&rdtgroup_mutex); } -static void domain_destroy_mon_state (struct rdt_domain *d) +static void domain_destroy_mon_state (struct rdt_mon_domain *d) {bitmap_free (d->rmid_busy_llc);kfree (d->mbm_total);kfree (d->mbm_local); } -void resctrl_offline_ctrl_domain (struct rdt_resource *r,struct rdt_domain *d) +void resctrl_offline_ctrl_domain (struct rdt_resource *r,struct rdt_ctrl_domain *d) {lockdep_assert_held (&rdtgroup_mutex);@@ -3857,7 +3857,7 @@ void resctrl_offline_ctrl_domain(struct rdt_resource *r, struct rdt_domain *d)mba_sc_domain_destroy (r, d); } -void resctrl_offline_mon_domain (struct rdt_resource *r,struct rdt_domain *d) +void resctrl_offline_mon_domain (struct rdt_resource *r,struct rdt_mon_domain *d) {lockdep_assert_held (&rdtgroup_mutex);@@ -3886,7 +3886,7 @@ void resctrl_offline_mon_domain(struct rdt_resource *r, struct rdt_domain *d)domain_destroy_mon_state (d); } -static int domain_setup_mon_state (struct rdt_resource *r,struct rdt_domain *d) +static int domain_setup_mon_state (struct rdt_resource *r,struct rdt_mon_domain *d) {size_t tsize;@@ -3916,7 +3916,7 @@ static int domain_setup_mon_state(struct rdt_resource *r, struct rdt_domain *d)return 0 ; } -int resctrl_online_ctrl_domain (struct rdt_resource *r,struct rdt_domain *d) +int resctrl_online_ctrl_domain (struct rdt_resource *r,struct rdt_ctrl_domain *d) {lockdep_assert_held (&rdtgroup_mutex);@@ -3926,7 +3926,7 @@ int resctrl_online_ctrl_domain(struct rdt_resource *r, struct rdt_domain *d)return 0 ; } -int resctrl_online_mon_domain (struct rdt_resource *r,struct rdt_domain *d) +int resctrl_online_mon_domain (struct rdt_resource *r,struct rdt_mon_domain *d) {int err;
Tony Luck
maintainerPATCH v13 5/8 x86/resctrl: Add node-scope to the options for feature scope
In reply to Tony LuckCurrently supported resctrl features are all domain scoped the same as the scope of the L2 or L3 caches.
Add RESCTRL_NODE as a new option for features that are scoped at the same granularity as NUMA nodes. This is needed for Intel's Sub-NUMA Cluster (SNC) feature where monitoring features are node scoped.
--- include/linux/resctrl.h | 1 + arch/x86/kernel/cpu/resctrl/core.c | 2 ++ 2 files changed, 3 insertions(+)
include/linux/resctrl.h +1 -0
@@ -170,6 +170,7 @@ struct resctrl_schema;enum resctrl_scope {RESCTRL_L2_CACHE =2 ,RESCTRL_L3_CACHE =3 , +RESCTRL_NODE , };/**
arch/x86/kernel/cpu/resctrl/core.c +2 -0
@@ -502,6 +502,8 @@ static int get_domain_id_from_scope(int cpu, enum resctrl_scope scope)case RESCTRL_L2_CACHE :case RESCTRL_L3_CACHE :return get_cpu_cacheinfo_id (cpu, scope); +case RESCTRL_NODE : +return cpu_to_node (cpu);default :break ; }
Signature · 1 line
2.41.0
Re: [PATCH v13 5/8] x86/resctrl: Add node-scope to the options for feature scope
Quoted 7 lines · Tony Luck
Currently supported resctrl features are all domain scoped the same as the scope of the L2 or L3 caches.
Add
RESCTRL_NODEas a new option for features that are scoped at the same granularity as NUMA nodes. This is needed for Intel's Sub-NUMA Cluster (SNC) feature where monitoring features are node scoped.
Quoted 5 lines
Signed-off-by Tony Luck<[email protected]>Tested-by Shaopeng Tan<[email protected]>Reviewed-by Peter Newman<[email protected]>Reviewed-by Reinette Chatre<[email protected]>Reviewed-by Shaopeng Tan<[email protected]>
Quoted 30 lines
--- include/linux/resctrl.h | 1 + arch/x86/kernel/cpu/resctrl/core.c | 2 ++ 2 files changed, 3 insertions(+)include/linux/resctrl.h +1
-0@@ -170,6 +170,7 @@ struct resctrl_schema;enum resctrl_scope {RESCTRL_L2_CACHE =2 ,RESCTRL_L3_CACHE =3 , +RESCTRL_NODE , };/** arch/x86/kernel/cpu/resctrl/core.c +2
-0@@ -502,6 +502,8 @@ static int get_domain_id_from_scope(int cpu, enum resctrl_scope scope)case RESCTRL_L2_CACHE :case RESCTRL_L3_CACHE :return get_cpu_cacheinfo_id (cpu, scope); +case RESCTRL_NODE : +return cpu_to_node (cpu);default :break ; }
Tony Luck
maintainerPATCH v13 6/8 x86/resctrl: Introduce snc_nodes_per_l3_cache
In reply to Tony LuckIntel Sub-NUMA Cluster (SNC) is a feature that subdivides the CPU cores and memory controllers on a socket into two or more groups. These are presented to the operating system as NUMA nodes.
This may enable some workloads to have slightly lower latency to memory as the memory controller(s) in an SNC node are electrically closer to the CPU cores on that SNC node. This cost may be offset by lower bandwidth since the memory accesses for each core can only be interleaved between the memory controllers on the same SNC node.
Resctrl monitoring on an Intel system depends upon attaching RMIDs to tasks to track L3 cache occupancy and memory bandwidth. There is an MSR that controls how the RMIDs are shared between SNC nodes.
The default mode divides them numerically. E.g. when there are two SNC nodes on a socket the lower number half of the RMIDs are given to the first node, the remainder to the second node. This would be difficult to use with the Linux resctrl interface as specific RMID values assigned to resctrl groups are not visible to users.
The other mode divides the RMIDs and renumbers the ones on the second SNC node to start from zero.
Even with this renumbering SNC mode requires several changes in resctrl behavior for correct operation.
Add a global integer "snc_nodes_per_l3_cache" that shows how many SNC nodes share each L3 cache. When "snc_nodes_per_l3_cache" is "1", SNC mode is either not implemented, or not enabled.
Update all places to take appropriate action when SNC mode is enabled:
1) The number of logical RMIDs per L3 cache available for use is the number of physical RMIDs divided by the number of SNC nodes.
2) Likewise the "mon_scale" value must be divided by the number of SNC nodes.
3) The RMID renumbering operates when using the value from the IA32_PQR_ASSOC MSR to count accesses by a task. When reading an RMID counter, adjust from the logical RMID to the physical RMID value for the SNC node that it wishes to read and load the adjusted value into the IA32_QM_EVTSEL MSR.
4) Divide the L3 cache between the SNC nodes. Divide the value reported in the resctrl "size" file by the number of SNC nodes because the effective amount of cache that can be allocated is reduced by that factor.
5) Disable the "-o mba_MBps" mount option in SNC mode because the monitoring is being done per SNC node, while the bandwidth allocation is still done at the L3 cache scope. Trying to use this feedback loop might result in contradictory changes to the throttling level coming from each of the SNC node bandwidth measurements.
--- arch/x86/kernel/cpu/resctrl/internal.h | 2 ++ arch/x86/kernel/cpu/resctrl/core.c | 6 ++++++ arch/x86/kernel/cpu/resctrl/monitor.c | 16 +++++++++++++--- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 5 +++-- 4 files changed, 24 insertions(+), 5 deletions(-)
arch/x86/kernel/cpu/resctrl/internal.h +2 -0
@@ -446,6 +446,8 @@ DECLARE_STATIC_KEY_FALSE(rdt_alloc_enable_key);extern struct dentry *debugfs_resctrl; +extern unsigned int snc_nodes_per_l3_cache; +enum resctrl_res_level {RDT_RESOURCE_L3 ,RDT_RESOURCE_L2 ,
arch/x86/kernel/cpu/resctrl/core.c +6 -0
@@ -48,6 +48,12 @@ int max_name_width, max_data_width;*/ bool rdt_alloc_capable; +/* +* Number of SNC nodes that share each L3 cache. Default is 1 for +* systems that do not support SNC, or have SNC disabled. +*/ +unsigned int snc_nodes_per_l3_cache =1 ; +static void mba_wrmsr_intel (struct rdt_ctrl_domain *d,struct msr_param *m,struct rdt_resource *r);
arch/x86/kernel/cpu/resctrl/monitor.c +13 -3
@@ -148,8 +148,18 @@ static inline struct rmid_entry *__rmid_entry(u32 rmid)static int __rmid_read (u32 rmid,enum resctrl_event_id eventid,u64 *val) { +struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl; +int cpu =smp_processor_id (); +int rmid_offset =0 ;u64 msr_val; +/* +* When SNC mode is on, need to compute the offset to read the +* physical RMID counter for the node to which this CPU belongs. +*/ +if (snc_nodes_per_l3_cache >1 ) + rmid_offset = (cpu_to_node (cpu) % snc_nodes_per_l3_cache) * r->num_rmid; +/* * As per the SDM, when IA32_QM_EVTSEL.EvtID (bits 7:0) is configured * with a valid event code for supported resource type and the bits
@@ -158,7 +168,7 @@ static int __rmid_read(u32 rmid, enum resctrl_event_id eventid, u64 *val)* IA32_QM_CTR.Error (bit 63) and IA32_QM_CTR.Unavailable (bit 62) * are error bits. */ -wrmsr (MSR_IA32_QM_EVTSEL , eventid, rmid); +wrmsr (MSR_IA32_QM_EVTSEL , eventid, rmid + rmid_offset);rdmsrl (MSR_IA32_QM_CTR , msr_val);if (msr_val &RMID_VAL_ERROR )
@@ -783,8 +793,8 @@ int __init rdt_get_mon_l3_config(struct rdt_resource *r)int ret; resctrl_rmid_realloc_limit = boot_cpu_data.x86_cache_size *1024 ; - hw_res->mon_scale = boot_cpu_data.x86_cache_occ_scale; - r->num_rmid = boot_cpu_data.x86_cache_max_rmid +1 ; + hw_res->mon_scale = boot_cpu_data.x86_cache_occ_scale / snc_nodes_per_l3_cache; + r->num_rmid = (boot_cpu_data.x86_cache_max_rmid +1 ) / snc_nodes_per_l3_cache; hw_res->mbm_width =MBM_CNTR_WIDTH_BASE ;if (mbm_offset >0 && mbm_offset <=MBM_CNTR_WIDTH_OFFSET_MAX )
arch/x86/kernel/cpu/resctrl/rdtgroup.c +3 -2
@@ -1425,7 +1425,7 @@ unsigned int rdtgroup_cbm_to_size(struct rdt_resource *r, } } -return size; +return size / snc_nodes_per_l3_cache; }/*
@@ -2298,7 +2298,8 @@ static bool supports_mba_mbps(void)struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_MBA ].r_resctrl;return (is_mbm_local_enabled () && - r->alloc_capable &&is_mba_linear ()); + r->alloc_capable &&is_mba_linear () && + snc_nodes_per_l3_cache ==1 ); }/*
Signature · 1 line
2.41.0
Re: [PATCH v13 6/8] x86/resctrl: Introduce snc_nodes_per_l3_cache
Quoted 51 lines · Tony Luck
Intel Sub-NUMA Cluster (SNC) is a feature that subdivides the CPU cores and memory controllers on a socket into two or more groups. These are presented to the operating system as NUMA nodes.
This may enable some workloads to have slightly lower latency to memory as the memory controller(s) in an SNC node are electrically closer to the CPU cores on that SNC node. This cost may be offset by lower bandwidth since the memory accesses for each core can only be interleaved between the memory controllers on the same SNC node.
Resctrl monitoring on an Intel system depends upon attaching RMIDs to tasks to track L3 cache occupancy and memory bandwidth. There is an MSR that controls how the RMIDs are shared between SNC nodes.
The default mode divides them numerically. E.g. when there are two SNC nodes on a socket the lower number half of the RMIDs are given to the first node, the remainder to the second node. This would be difficult to use with the Linux resctrl interface as specific RMID values assigned to resctrl groups are not visible to users.
The other mode divides the RMIDs and renumbers the ones on the second SNC node to start from zero.
Even with this renumbering SNC mode requires several changes in resctrl behavior for correct operation.
Add a global integer "
snc_nodes_per_l3_cache" that shows how many SNC nodes share each L3 cache. When "snc_nodes_per_l3_cache" is "1", SNC mode is either not implemented, or not enabled.Update all places to take appropriate action when SNC mode is enabled:
1) The number of logical RMIDs per L3 cache available for use is the number of physical RMIDs divided by the number of SNC nodes.
2) Likewise the "mon_scale" value must be divided by the number of SNC nodes.
3) The RMID renumbering operates when using the value from theIA32_PQR_ASSOCMSR to count accesses by a task. When reading an RMID counter, adjust from the logical RMID to the physical RMID value for the SNC node that it wishes to read and load the adjusted value into theIA32_QM_EVTSELMSR.
4) Divide the L3 cache between the SNC nodes. Divide the value reported in the resctrl "size" file by the number of SNC nodes because the effective amount of cache that can be allocated is reduced by that factor.
5) Disable the "-omba_MBps" mount option in SNC mode because the monitoring is being done per SNC node, while the bandwidth allocation is still done at the L3 cache scope. Trying to use this feedback loop might result in contradictory changes to the throttling level coming from each of the SNC node bandwidth measurements.
Quoted 5 lines
Signed-off-by Tony Luck<[email protected]>Tested-by Shaopeng Tan<[email protected]>Reviewed-by Peter Newman<[email protected]>Reviewed-by Reinette Chatre<[email protected]>Reviewed-by Shaopeng Tan<[email protected]>
Quoted 103 lines
--- arch/x86/kernel/cpu/resctrl/internal.h | 2 ++ arch/x86/kernel/cpu/resctrl/core.c | 6 ++++++ arch/x86/kernel/cpu/resctrl/monitor.c | 16 +++++++++++++--- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 5 +++-- 4 files changed, 24 insertions(+), 5 deletions(-)arch/x86/kernel/cpu/resctrl/internal.h +2
-0@@ -446,6 +446,8 @@ DECLARE_STATIC_KEY_FALSE(rdt_alloc_enable_key);extern struct dentry *debugfs_resctrl; +extern unsigned int snc_nodes_per_l3_cache; +enum resctrl_res_level {RDT_RESOURCE_L3 ,RDT_RESOURCE_L2 ,arch/x86/kernel/cpu/resctrl/core.c +6
-0@@ -48,6 +48,12 @@ int max_name_width, max_data_width;*/ bool rdt_alloc_capable; +/* +* Number of SNC nodes that share each L3 cache. Default is 1 for +* systems that do not support SNC, or have SNC disabled. +*/ +unsigned int snc_nodes_per_l3_cache =1 ; +static void mba_wrmsr_intel (struct rdt_ctrl_domain *d,struct msr_param *m,struct rdt_resource *r);arch/x86/kernel/cpu/resctrl/monitor.c +13
-3@@ -148,8 +148,18 @@ static inline struct rmid_entry *__rmid_entry(u32 rmid)static int __rmid_read (u32 rmid,enum resctrl_event_id eventid,u64 *val) { +struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl; +int cpu =smp_processor_id (); +int rmid_offset =0 ;u64 msr_val; +/* +* When SNC mode is on, need to compute the offset to read the +* physical RMID counter for the node to which this CPU belongs. +*/ +if (snc_nodes_per_l3_cache >1 ) + rmid_offset = (cpu_to_node (cpu) % snc_nodes_per_l3_cache) * r->num_rmid; +/* * As per the SDM, when IA32_QM_EVTSEL.EvtID (bits 7:0) is configured * with a valid event code for supported resource type and the bits @@ -158,7 +168,7 @@ static int __rmid_read(u32 rmid, enum resctrl_event_id eventid, u64 *val)* IA32_QM_CTR.Error (bit 63) and IA32_QM_CTR.Unavailable (bit 62) * are error bits. */ -wrmsr (MSR_IA32_QM_EVTSEL , eventid, rmid); +wrmsr (MSR_IA32_QM_EVTSEL , eventid, rmid + rmid_offset);rdmsrl (MSR_IA32_QM_CTR , msr_val);if (msr_val &RMID_VAL_ERROR )@@ -783,8 +793,8 @@ int __init rdt_get_mon_l3_config(struct rdt_resource *r)int ret; resctrl_rmid_realloc_limit = boot_cpu_data.x86_cache_size *1024 ; - hw_res->mon_scale = boot_cpu_data.x86_cache_occ_scale; - r->num_rmid = boot_cpu_data.x86_cache_max_rmid +1 ; + hw_res->mon_scale = boot_cpu_data.x86_cache_occ_scale / snc_nodes_per_l3_cache; + r->num_rmid = (boot_cpu_data.x86_cache_max_rmid +1 ) / snc_nodes_per_l3_cache; hw_res->mbm_width =MBM_CNTR_WIDTH_BASE ;if (mbm_offset >0 && mbm_offset <=MBM_CNTR_WIDTH_OFFSET_MAX )arch/x86/kernel/cpu/resctrl/rdtgroup.c +3
-2@@ -1425,7 +1425,7 @@ unsigned int rdtgroup_cbm_to_size(struct rdt_resource *r, } } -return size; +return size / snc_nodes_per_l3_cache; }/* @@ -2298,7 +2298,8 @@ static bool supports_mba_mbps(void)struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_MBA ].r_resctrl;return (is_mbm_local_enabled () && - r->alloc_capable &&is_mba_linear ()); + r->alloc_capable &&is_mba_linear () && + snc_nodes_per_l3_cache ==1 ); }/*
Tony Luck
maintainerPATCH v13 7/8 x86/resctrl: Sub NUMA Cluster detection and enable
In reply to Tony LuckThere isn't a simple hardware bit that indicates whether a CPU is running in Sub NUMA Cluster (SNC) mode. Infer the state by comparing the ratio of NUMA nodes to L3 cache instances.
When SNC mode is detected, reconfigure the RMID counters by updating the MSR_RMID_SNC_CONFIG MSR on each socket as CPUs are seen.
Clearing bit zero of the MSR divides the RMIDs and renumbers the ones on the second SNC node to start from zero.
--- arch/x86/include/asm/msr-index.h | 1 + arch/x86/kernel/cpu/resctrl/core.c | 118 +++++++++++++++++++++++++++++ 2 files changed, 119 insertions(+)
arch/x86/include/asm/msr-index.h +1 -0
@@ -1111,6 +1111,7 @@#define MSR_IA32_QM_CTR 0xc8e#define MSR_IA32_PQR_ASSOC 0xc8f#define MSR_IA32_L3_CBM_BASE 0xc90 +#define MSR_RMID_SNC_CONFIG 0xca0#define MSR_IA32_L2_CBM_BASE 0xd10#define MSR_IA32_MBA_THRTL_BASE 0xd50
arch/x86/kernel/cpu/resctrl/core.c +118 -0
151 lines not on this page · raw message
Signature · 1 line
2.41.0
Re: [PATCH v13 7/8] x86/resctrl: Sub NUMA Cluster detection and enable
Quoted 7 lines · Tony Luck
There isn't a simple hardware bit that indicates whether a CPU is running in Sub NUMA Cluster (SNC) mode. Infer the state by comparing the ratio of NUMA nodes to L3 cache instances.
When SNC mode is detected, reconfigure the RMID counters by updating the
MSR_RMID_SNC_CONFIGMSR on each socket as CPUs are seen.
Quoted 8 lines
Clearing bit zero of the MSR divides the RMIDs and renumbers the ones on the second SNC node to start from zero.
Signed-off-by Tony Luck<[email protected]>Tested-by Shaopeng Tan<[email protected]>Reviewed-by Peter Newman<[email protected]>Reviewed-by Reinette Chatre<[email protected]>Reviewed-by Shaopeng Tan<[email protected]>
Quoted 175 lines
--- arch/x86/include/asm/msr-index.h | 1 + arch/x86/kernel/cpu/resctrl/core.c | 118 +++++++++++++++++++++++++++++ 2 files changed, 119 insertions(+)arch/x86/include/asm/msr-index.h +1
-0@@ -1111,6 +1111,7 @@#define MSR_IA32_QM_CTR 0xc8e#define MSR_IA32_PQR_ASSOC 0xc8f#define MSR_IA32_L3_CBM_BASE 0xc90 +#define MSR_RMID_SNC_CONFIG 0xca0#define MSR_IA32_L2_CBM_BASE 0xd10#define MSR_IA32_MBA_THRTL_BASE 0xd50arch/x86/kernel/cpu/resctrl/core.c +118
-0@@ -16,11 +16,14 @@#define pr_fmt (fmt) "resctrl: " fmt +#include <linux/cpu.h> #include <linux/slab.h> #include <linux/err.h> #include <linux/cacheinfo.h> #include <linux/cpuhotplug.h> +#include <linux/mod_devicetable.h> +#include <asm/cpu_device_id.h> #include <asm/intel-family.h> #include <asm/resctrl.h> #include "internal.h" @@ -740,11 +743,42 @@ static void clear_closid_rmid(int cpu)wrmsr (MSR_IA32_PQR_ASSOC ,0 ,0 ); } +/* +* The power-on reset value of MSR_RMID_SNC_CONFIG is 0x1 +* which indicates that RMIDs are configured in legacy mode. +* This mode is incompatible with Linux resctrl semantics +* as RMIDs are partitioned between SNC nodes, which requires +* a user to know which RMID is allocated to a task. +* Clearing bit 0 reconfigures the RMID counters for use +* in Sub NUMA Cluster mode. This mode is better for Linux. +* The RMID space is divided between all SNC nodes with the +* RMIDs renumbered to start from zero in each node when +* couning operations from tasks. Code to read the counters +* must adjust RMID counter numbers based on SNC node. See +* __rmid_read() for code that does this. +*/ +static void snc_remap_rmids (int cpu) +{ +u64 val; + +/* Only need to enable once per package. */ +if (cpumask_first (topology_core_cpumask (cpu)) != cpu) +return ; + +rdmsrl (MSR_RMID_SNC_CONFIG , val); + val &= ~BIT_ULL (0 ); +wrmsrl (MSR_RMID_SNC_CONFIG , val); +} +static int resctrl_online_cpu (unsigned int cpu) {struct rdt_resource *r;mutex_lock (&rdtgroup_mutex); + +if (snc_nodes_per_l3_cache >1 ) +snc_remap_rmids (cpu); +for_each_capable_rdt_resource (r)domain_add_cpu (cpu, r);/* The cpu is set in default rdtgroup after online. */ @@ -999,11 +1033,95 @@ static __init bool get_rdt_resources(void)return (rdt_mon_capable || rdt_alloc_capable); } +/* CPU models that support MSR_RMID_SNC_CONFIG */ +static const struct x86_cpu_id snc_cpu_ids[]__initconst = { +X86_MATCH_INTEL_FAM6_MODEL (ICELAKE_X ,0 ), +X86_MATCH_INTEL_FAM6_MODEL (SAPPHIRERAPIDS_X ,0 ), +X86_MATCH_INTEL_FAM6_MODEL (EMERALDRAPIDS_X ,0 ), +X86_MATCH_INTEL_FAM6_MODEL (GRANITERAPIDS_X ,0 ), + {} +}; + +/* +* There isn't a simple hardware bit that indicates whether a CPU is running +* in Sub NUMA Cluster (SNC) mode. Infer the state by comparing the +* ratio of NUMA nodes to L3 cache instances. +* It is not possible to accurately determine SNC state if the system is +* booted with a maxcpus=N parameter. That distorts the ratio of SNC nodes +* to L3 caches. It will be OK if system is booted with hyperthreading +* disabled (since this doesn't affect the ratio). +*/ +static __init int snc_get_config (void ) +{ +unsigned long *node_caches; +int mem_only_nodes =0 ; +int cpu, node, ret; +int num_l3_caches; +int cache_id; + +if (!x86_match_cpu (snc_cpu_ids)) +return 1 ; + + node_caches =bitmap_zalloc (num_possible_cpus (),GFP_KERNEL ); +if (!node_caches) +return 1 ; + +cpus_read_lock (); + +if (num_online_cpus () !=num_present_cpus ()) +pr_warn ("Some CPUs offline, SNC detection may be incorrect\n" ); + +for_each_node (node) { + cpu =cpumask_first (cpumask_of_node (node)); +if (cpu < nr_cpu_ids) { + cache_id =get_cpu_cacheinfo_id (cpu,3 ); +if (cache_id !=-1 ) +set_bit (cache_id, node_caches); + }else { + mem_only_nodes++; + } + } +cpus_read_unlock (); + + num_l3_caches =bitmap_weight (node_caches,num_possible_cpus ()); +kfree (node_caches); + +if (!num_l3_caches) + goto insane; + +/* sanity check #1: Number of CPU nodes must be multiple of num_l3_caches */ +if ((nr_node_ids - mem_only_nodes) % num_l3_caches) + goto insane; + + ret = (nr_node_ids - mem_only_nodes) / num_l3_caches; + +/* sanity check #2: Only valid results are 1, 2, 3, 4 */ +switch (ret) { +case 1 : +break ; +case 2 : +case 3 : +case 4 : + rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl.mon_scope =RESCTRL_NODE ; +break ; +default : + goto insane; + } + +return ret; +insane: +pr_warn ("SNC insanity: CPU nodes = %d num_l3_caches = %d\n" , + (nr_node_ids - mem_only_nodes), num_l3_caches); +return 1 ; +} +static __init void rdt_init_res_defs_intel (void ) {struct rdt_hw_resource *hw_res;struct rdt_resource *r; + snc_nodes_per_l3_cache =snc_get_config (); +for_each_rdt_resource (r) { hw_res =resctrl_to_arch_res (r);
Tony Luck
maintainerPATCH v13 8/8 x86/resctrl: Update documentation with Sub-NUMA cluster changes
In reply to Tony LuckWith Sub-NUMA Cluster mode enabled the scope of monitoring resources is per-NODE instead of per-L3 cache. Suffixes of directories with "L3" in their name refer to Sub-NUMA nodes instead of L3 cache ids.
Users should be aware that SNC mode also affects the amount of L3 cache available for allocation within each SNC node.
--- Documentation/arch/x86/resctrl.rst | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-)
Documentation/arch/x86/resctrl.rst +21 -4
@@ -366,10 +366,10 @@ When control is enabled all CTRL_MON groups will also contain: When monitoring is enabled all MON groups will also contain: "mon_data": - This contains a set of files organized by L3 domain and by - RDT event. E.g. on a system with two L3 domains there will - be subdirectories "mon_L3_00" and "mon_L3_01". Each of these - directories have one file per event (e.g. "llc_occupancy", + This contains a set of files organized by L3 domain or by NUMA + node (depending on whether Sub-NUMA Cluster (SNC) mode is disabled + or enabled respectively) and by RDT event. Each of these + directories has one file per event (e.g. "llc_occupancy", "mbm_total_bytes", and "mbm_local_bytes"). In a MON group these files provide a read out of the current value of the event for all tasks in the group. In CTRL_MON groups these files provide
@@ -478,6 +478,23 @@ if non-contiguous 1s value is supported. On a system with a 20-bit mask each bit represents 5% of the capacity of the cache. You could partition the cache into four equal parts with masks: 0x1f, 0x3e0, 0x7c00, 0xf8000. +Notes on Sub-NUMA Cluster mode +============================== +When SNC mode is enabled, Linux may load balance tasks between Sub-NUMA +nodes much more readily than between regular NUMA nodes since the CPUs +on Sub-NUMA nodes share the same L3 cache and the system may report +the NUMA distance between Sub-NUMA nodes with a lower value than used +for regular NUMA nodes. Users who do not bind tasks to the CPUs of a +specific Sub-NUMA node must read the "llc_occupancy", "mbm_total_bytes", +and "mbm_local_bytes" for all Sub-NUMA nodes where the tasks may execute +to get the full view of traffic for which the tasks were the source. + +The cache allocation feature still provides the same number of +bits in a mask to control allocation into the L3 cache, but each +of those ways has its capacity reduced because the cache is divided +between the SNC nodes. The values reported in the resctrl +"size" files are adjusted accordingly. + Memory bandwidth Allocation and monitoring ==========================================
Signature · 1 line
2.41.0
Re: [PATCH v13 8/8] x86/resctrl: Update documentation with Sub-NUMA cluster changes
Quoted 4 lines · Tony Luck
With Sub-NUMA Cluster mode enabled the scope of monitoring resources is per-NODE instead of per-L3 cache. Suffixes of directories with "L3" in their name refer to Sub-NUMA nodes instead of L3 cache ids.
Quoted 8 lines
Users should be aware that SNC mode also affects the amount of L3 cache available for allocation within each SNC node.
Signed-off-by Tony Luck<[email protected]>Tested-by Shaopeng Tan<[email protected]>Reviewed-by Peter Newman<[email protected]>Reviewed-by Reinette Chatre<[email protected]>Reviewed-by Shaopeng Tan<[email protected]>
Quoted 47 lines
--- Documentation/arch/x86/resctrl.rst | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-)Documentation/arch/x86/resctrl.rst +21
-4@@ -366,10 +366,10 @@ When control is enabled all CTRL_MON groups will also contain: When monitoring is enabled all MON groups will also contain: "mon_data": - This contains a set of files organized by L3 domain and by - RDT event. E.g. on a system with two L3 domains there will - be subdirectories "mon_L3_00" and "mon_L3_01". Each of these - directories have one file per event (e.g. "llc_occupancy", + This contains a set of files organized by L3 domain or by NUMA + node (depending on whether Sub-NUMA Cluster (SNC) mode is disabled + or enabled respectively) and by RDT event. Each of these + directories has one file per event (e.g. "llc_occupancy", "mbm_total_bytes", and "mbm_local_bytes"). In a MON group these files provide a read out of the current value of the event for all tasks in the group. In CTRL_MON groups these files provide@@ -478,6 +478,23 @@ if non-contiguous 1s value is supported. On a system with a 20-bit mask each bit represents 5% of the capacity of the cache. You could partition the cache into four equal parts with masks: 0x1f, 0x3e0, 0x7c00, 0xf8000. +Notes on Sub-NUMA Cluster mode +============================== +When SNC mode is enabled, Linux may load balance tasks between Sub-NUMA +nodes much more readily than between regular NUMA nodes since the CPUs +on Sub-NUMA nodes share the same L3 cache and the system may report +the NUMA distance between Sub-NUMA nodes with a lower value than used +for regular NUMA nodes. Users who do not bind tasks to the CPUs of a +specific Sub-NUMA node must read the "llc_occupancy", "mbm_total_bytes", +and "mbm_local_bytes" for all Sub-NUMA nodes where the tasks may execute +to get the full view of traffic for which the tasks were the source. + +The cache allocation feature still provides the same number of +bits in a mask to control allocation into the L3 cache, but each +of those ways has its capacity reduced because the cache is divided +between the SNC nodes. The values reported in the resctrl +"size" files are adjusted accordingly. + Memory bandwidth Allocation and monitoring ==========================================
Re: [PATCH v13 0/8] Add support for Sub-NUMA cluster (SNC) systems
In reply to Tony LuckHi Tony,
Tested the series on AMD system. Just ran few basic tests. Everything looking good.
Thanks
Babu
Quoted 61 lines · Tony Luck
The Sub-NUMA cluster feature on some Intel processors partitions the CPUs that share an L3 cache into two or more sets. This plays havoc with the Resource Director Technology (RDT) monitoring features. Prior to this patch Intel has advised that SNC and RDT are incompatible.
Some of these CPU support an MSR that can partition the RMID counters in the same way. This allows monitoring features to be used. With the caveat that users must be aware that Linux may migrate tasks more frequently between SNC nodes than between "regular" NUMA nodes, so reading counters from all SNC nodes may be needed to get a complete picture of activity for tasks.
Cache and memory bandwidth allocation features continue to operate at the scope of the L3 cache.
Signed-off-by Tony Luck <[email protected]>Changes since v12:
All:
Reinette - put commit tags in right order for TIP (Tested-by before Reviewed-by)Patch 7:
Fam Zheng - Check for -1 return fromget_cpu_cacheinfo_id()and increase size of bitmap tracking # of L3 instances. Reinette - Add extra sanity checks. Note that this patch has some additional tweaks beyond the e-mail discussion.
1) "3" is a valid return in addition to 1, 2, 4
2) Added a warning if the sanity checks fail that prints number of CPU nodes and number of L3 cache instances that were found.Patch 8:
Babu - Fix grammar with an additional comma.Tony Luck (8):
x86/resctrl: Prepare for new domain scope x86/resctrl: Prepare to splitrdt_domainstructure x86/resctrl: Prepare for different scope for control/monitor
operations
x86/resctrl: Split therdt_domainandrdt_hw_domainstructures x86/resctrl: Add node-scope to the options for feature scope x86/resctrl: Introducesnc_nodes_per_l3_cachex86/resctrl: Sub NUMA Cluster detection and enable x86/resctrl: Update documentation with Sub-NUMA cluster changesDocumentation/arch/x86/resctrl.rst | 25 +- include/linux/resctrl.h | 85 +++-- arch/x86/include/asm/msr-index.h | 1 + arch/x86/kernel/cpu/resctrl/internal.h | 66 ++-- arch/x86/kernel/cpu/resctrl/core.c | 433 +++++++++++++++++----- arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 58 +-- arch/x86/kernel/cpu/resctrl/monitor.c | 68 ++-- arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 26 +- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 149 ++++---- 9 files changed, 629 insertions(+), 282 deletions(-)base-commit:
2cc14f52aeb78ce3f29677c2de1f06c0e91471ab
Luck, Tony
maintainerRE: [PATCH v13 0/8] Add support for Sub-NUMA cluster (SNC) systems
Quoted 2 lines
Tested the series on AMD system. Just ran few basic tests. Everything looking good.
Babu,
Thanks for testing. I'll add your Tested-by tag if[1] I make a v14.
-Tony
[1] realistically not if, but when :-(
Tony Luck
maintainerRe: [PATCH v13 0/8] Add support for Sub-NUMA cluster (SNC) systems
In reply to Tony LuckOn Mon, Dec 04, 2023 at 10:53:49AM -0800, Tony Luck wrote:
Boris: I've collected "Reviewed-by:" from Reinette for all patches. Babu sent a Tested-by for the series, and Reviewed-by for each patch just now.
So it's ready to got into your to-be-reviewed queue.
Thanks
-Tony
Quoted 64 lines
The Sub-NUMA cluster feature on some Intel processors partitions the CPUs that share an L3 cache into two or more sets. This plays havoc with the Resource Director Technology (RDT) monitoring features. Prior to this patch Intel has advised that SNC and RDT are incompatible.
Some of these CPU support an MSR that can partition the RMID counters in the same way. This allows monitoring features to be used. With the caveat that users must be aware that Linux may migrate tasks more frequently between SNC nodes than between "regular" NUMA nodes, so reading counters from all SNC nodes may be needed to get a complete picture of activity for tasks.
Cache and memory bandwidth allocation features continue to operate at the scope of the L3 cache.
Signed-off-by Tony Luck <[email protected]>Changes since v12:
All:
Reinette - put commit tags in right order for TIP (Tested-by before Reviewed-by)Patch 7:
Fam Zheng - Check for -1 return fromget_cpu_cacheinfo_id()and increase size of bitmap tracking # of L3 instances. Reinette - Add extra sanity checks. Note that this patch has some additional tweaks beyond the e-mail discussion.
1) "3" is a valid return in addition to 1, 2, 4
2) Added a warning if the sanity checks fail that prints number of CPU nodes and number of L3 cache instances that were found.Patch 8:
Babu - Fix grammar with an additional comma.Tony Luck (8):
x86/resctrl: Prepare for new domain scope x86/resctrl: Prepare to splitrdt_domainstructure x86/resctrl: Prepare for different scope for control/monitor
operations
x86/resctrl: Split therdt_domainandrdt_hw_domainstructures x86/resctrl: Add node-scope to the options for feature scope x86/resctrl: Introducesnc_nodes_per_l3_cachex86/resctrl: Sub NUMA Cluster detection and enable x86/resctrl: Update documentation with Sub-NUMA cluster changesDocumentation/arch/x86/resctrl.rst | 25 +- include/linux/resctrl.h | 85 +++-- arch/x86/include/asm/msr-index.h | 1 + arch/x86/kernel/cpu/resctrl/internal.h | 66 ++-- arch/x86/kernel/cpu/resctrl/core.c | 433 +++++++++++++++++----- arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 58 +-- arch/x86/kernel/cpu/resctrl/monitor.c | 68 ++-- arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 26 +- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 149 ++++---- 9 files changed, 629 insertions(+), 282 deletions(-)base-commit:
2cc14f52aeb78ce3f29677c2de1f06c0e91471abSignature · 1 line
2.41.0
Tony Luck
maintainerv14 cover Add support for Sub-NUMA cluster (SNC) systems
In reply to Tony LuckThe Sub-NUMA cluster feature on some Intel processors partitions the CPUs that share an L3 cache into two or more sets. This plays havoc with the Resource Director Technology (RDT) monitoring features. Prior to this patch Intel has advised that SNC and RDT are incompatible.
Some of these CPU support an MSR that can partition the RMID counters in the same way. This allows monitoring features to be used. With the caveat that users must be aware that Linux may migrate tasks more frequently between SNC nodes than between "regular" NUMA nodes, so reading counters from all SNC nodes may be needed to get a complete picture of activity for tasks.
Cache and memory bandwidth allocation features continue to operate at the scope of the L3 cache.
---
Changes since v13:
Rebase to tip x86/cache
fc747eebef73 ("x86/resctrl: Remove redundant variable in mbm_config_write_domain()")
Applied all Reviewed and Tested tags
Tony Luck (8):
x86/resctrl: Prepare for new domain scope x86/resctrl: Prepare to split rdt_domain structure x86/resctrl: Prepare for different scope for control/monitor
operations
x86/resctrl: Split the rdt_domain and rdt_hw_domain structures x86/resctrl: Add node-scope to the options for feature scope x86/resctrl: Introduce snc_nodes_per_l3_cache x86/resctrl: Sub NUMA Cluster detection and enable x86/resctrl: Update documentation with Sub-NUMA cluster changes
Documentation/arch/x86/resctrl.rst | 25 +- include/linux/resctrl.h | 85 +++-- arch/x86/include/asm/msr-index.h | 1 + arch/x86/kernel/cpu/resctrl/internal.h | 66 ++-- arch/x86/kernel/cpu/resctrl/core.c | 433 +++++++++++++++++----- arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 58 +-- arch/x86/kernel/cpu/resctrl/monitor.c | 68 ++-- arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 26 +- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 149 ++++---- 9 files changed, 629 insertions(+), 282 deletions(-)
base-commit: fc747eebef734563cf68a512f57937c8f231834a
Signature · 1 line
2.43.0
Tony Luck
maintainerPATCH v14 1/8 x86/resctrl: Prepare for new domain scope
Resctrl resources operate on subsets of CPUs in the system with the defining attribute of each subset being an instance of a particular level of cache. E.g. all CPUs sharing an L3 cache would be part of the same domain.
In preparation for features that are scoped at the NUMA node level change the code from explicit references to "cache_level" to a more generic scope. At this point the only options for this scope are groups of CPUs that share an L2 cache or L3 cache.
Clean up the error handling when looking up domains. Report invalid id's before calling rdt_find_domain() in preparation for better messages when scope can be other than cache scope. This means that rdt_find_domain() will never return an error. So remove checks for error from the callsites.
--- include/linux/resctrl.h | 9 ++++- arch/x86/kernel/cpu/resctrl/core.c | 45 ++++++++++++++++------- arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 2 +- arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 6 ++- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 5 ++- 5 files changed, 48 insertions(+), 19 deletions(-)
include/linux/resctrl.h +7 -2
@@ -144,13 +144,18 @@ struct resctrl_membw {struct rdt_parse_data ;struct resctrl_schema ; +enum resctrl_scope { +RESCTRL_L2_CACHE =2 , +RESCTRL_L3_CACHE =3 , +}; +/** * struct rdt_resource - attributes of a resctrl resource * @rid: The index of the resource * @alloc_capable: Is allocation available on this machine * @mon_capable: Is monitor feature available on this machine * @num_rmid: Number of RMIDs available -* @cache_level: Which cache level defines scope of this resource +* @scope: Scope of this resource * @cache: Cache allocation related data * @membw: If the component has bandwidth controls, their properties. * @domains: All domains for this resource
@@ -168,7 +173,7 @@ struct rdt_resource {bool alloc_capable;bool mon_capable;int num_rmid; -int cache_level; +enum resctrl_scope scope;struct resctrl_cache cache;struct resctrl_membw membw;struct list_head domains;
arch/x86/kernel/cpu/resctrl/core.c +31 -14
105 lines not on this page · raw message
arch/x86/kernel/cpu/resctrl/ctrlmondata.c +1 -1
@@ -563,7 +563,7 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg) r = &rdt_resources_all[resid].r_resctrl; d =rdt_find_domain (r, domid,NULL ); -if (IS_ERR_OR_NULL (d)) { +if (!d) { ret = -ENOENT ; goto out; }
arch/x86/kernel/cpu/resctrl/pseudo_lock.c +5 -1
@@ -292,10 +292,14 @@ static void pseudo_lock_region_clear(struct pseudo_lock_region *plr)*/ static int pseudo_lock_region_init (struct pseudo_lock_region *plr) { +enum resctrl_scope scope = plr->s->res->scope;struct cpu_cacheinfo *ci;int ret;int i; +if (WARN_ON_ONCE (scope !=RESCTRL_L2_CACHE && scope !=RESCTRL_L3_CACHE )) +return -ENODEV ; +/* Pick the first cpu we find that is associated with the cache. */ plr->cpu =cpumask_first (&plr->d->cpu_mask);
@@ -311,7 +315,7 @@ static int pseudo_lock_region_init(struct pseudo_lock_region *plr) plr->size =rdtgroup_cbm_to_size (plr->s->res, plr->d, plr->cbm);for (i =0 ; i < ci->num_leaves; i++) { -if (ci->info_list[i].level == plr->s->res->cache_level) { +if (ci->info_list[i].level == scope) { plr->line_size = ci->info_list[i].coherency_line_size;return 0 ; }
arch/x86/kernel/cpu/resctrl/rdtgroup.c +4 -1
@@ -1413,10 +1413,13 @@ unsigned int rdtgroup_cbm_to_size(struct rdt_resource *r,unsigned int size =0 ;int num_b, i; +if (WARN_ON_ONCE (r->scope !=RESCTRL_L2_CACHE && r->scope !=RESCTRL_L3_CACHE )) +return size; + num_b =bitmap_weight (&cbm, r->cache.cbm_len); ci =get_cpu_cacheinfo (cpumask_any (&d->cpu_mask));for (i =0 ; i < ci->num_leaves; i++) { -if (ci->info_list[i].level == r->cache_level) { +if (ci->info_list[i].level == r->scope) { size = ci->info_list[i].size / r->cache.cbm_len * num_b;break ; }
Signature · 1 line
2.43.0
Tony Luck
maintainerPATCH v14 2/8 x86/resctrl: Prepare to split rdt_domain structure
In reply to Tony LuckThe rdt_domain structure is used for both control and monitor features. It is about to be split into separate structures for these two usages because the scope for control and monitoring features for a resource will be different for future resources.
To allow for common code that scans a list of domains looking for a specific domain id, move all the common fields ("list", "id", "cpu_mask") into their own structure within the rdt_domain structure.
--- include/linux/resctrl.h | 16 ++++-- arch/x86/kernel/cpu/resctrl/core.c | 26 +++++----- arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 22 ++++----- arch/x86/kernel/cpu/resctrl/monitor.c | 10 ++-- arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 14 +++--- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 60 +++++++++++------------ 6 files changed, 78 insertions(+), 70 deletions(-)
include/linux/resctrl.h +12 -4
@@ -53,10 +53,20 @@ struct resctrl_staged_config { };/** -* struct rdt_domain - group of CPUs sharing a resctrl resource +* struct rdt_domain_hdr - common header for different domain types * @list: all instances of this resource * @id: unique id for this instance * @cpu_mask: which CPUs share this resource +*/ +struct rdt_domain_hdr { +struct list_head list; +int id; +struct cpumask cpu_mask; +}; + +/** +* struct rdt_domain - group of CPUs sharing a resctrl resource +* @hdr: common header for different domain types * @rmid_busy_llc: bitmap of which limbo RMIDs are above threshold * @mbm_total: saved state for MBM total bandwidth * @mbm_local: saved state for MBM local bandwidth
@@ -71,9 +81,7 @@ struct resctrl_staged_config {* by closid */ struct rdt_domain { -struct list_head list; -int id; -struct cpumask cpu_mask; +struct rdt_domain_hdr hdr;unsigned long *rmid_busy_llc;struct mbm_state *mbm_total;struct mbm_state *mbm_local;
arch/x86/kernel/cpu/resctrl/core.c +13 -13
@@ -354,9 +354,9 @@ struct rdt_domain *get_domain_from_cpu(int cpu, struct rdt_resource *r) {struct rdt_domain *d; -list_for_each_entry (d, &r->domains, list) { +list_for_each_entry (d, &r->domains, hdr.list) {/* Find the domain that contains this CPU */ -if (cpumask_test_cpu (cpu, &d->cpu_mask)) +if (cpumask_test_cpu (cpu, &d->hdr.cpu_mask))return d; }
@@ -400,12 +400,12 @@ struct rdt_domain *rdt_find_domain(struct rdt_resource *r, int id,struct list_head *l;list_for_each (l, &r->domains) { - d = list_entry(l, struct rdt_domain, list); + d = list_entry(l, struct rdt_domain, hdr.list);/* When id is found, return its domain. */ -if (id == d->id) +if (id == d->hdr.id)return d;/* Stop searching when finding id's position in sorted list. */ -if (id < d->id) +if (id < d->hdr.id)break ; }
@@ -528,7 +528,7 @@ static void domain_add_cpu(int cpu, struct rdt_resource *r) d =rdt_find_domain (r, id, &add_pos);if (d) { -cpumask_set_cpu (cpu, &d->cpu_mask); +cpumask_set_cpu (cpu, &d->hdr.cpu_mask);if (r->cache.arch_has_per_cpu_cfg)rdt_domain_reconfigure_cdp (r);return ;
@@ -539,8 +539,8 @@ static void domain_add_cpu(int cpu, struct rdt_resource *r)return ; d = &hw_dom->d_resctrl; - d->id = id; -cpumask_set_cpu (cpu, &d->cpu_mask); + d->hdr.id = id; +cpumask_set_cpu (cpu, &d->hdr.cpu_mask);rdt_domain_reconfigure_cdp (r);
@@ -554,11 +554,11 @@ static void domain_add_cpu(int cpu, struct rdt_resource *r)return ; } -list_add_tail (&d->list, add_pos); +list_add_tail (&d->hdr.list, add_pos); err =resctrl_online_domain (r, d);if (err) { -list_del (&d->list); +list_del (&d->hdr.list);domain_free (hw_dom); } }
@@ -582,10 +582,10 @@ static void domain_remove_cpu(int cpu, struct rdt_resource *r) } hw_dom =resctrl_to_arch_dom (d); -cpumask_clear_cpu (cpu, &d->cpu_mask); -if (cpumask_empty (&d->cpu_mask)) { +cpumask_clear_cpu (cpu, &d->hdr.cpu_mask); +if (cpumask_empty (&d->hdr.cpu_mask)) {resctrl_offline_domain (r, d); -list_del (&d->list); +list_del (&d->hdr.list);/* * rdt_domain "d" is going to be freed below, so clear
arch/x86/kernel/cpu/resctrl/ctrlmondata.c +11 -11
@@ -67,7 +67,7 @@ int parse_bw(struct rdt_parse_data *data, struct resctrl_schema *s, cfg = &d->staged_config[s->conf_type];if (cfg->have_new_ctrl) { -rdt_last_cmd_printf ("Duplicate domain %d\n" , d->id); +rdt_last_cmd_printf ("Duplicate domain %d\n" , d->hdr.id);return -EINVAL ; }
@@ -146,7 +146,7 @@ int parse_cbm(struct rdt_parse_data *data, struct resctrl_schema *s, cfg = &d->staged_config[s->conf_type];if (cfg->have_new_ctrl) { -rdt_last_cmd_printf ("Duplicate domain %d\n" , d->id); +rdt_last_cmd_printf ("Duplicate domain %d\n" , d->hdr.id);return -EINVAL ; }
@@ -226,8 +226,8 @@ static int parse_line(char *line, struct resctrl_schema *s,return -EINVAL ; } dom =strim (dom); -list_for_each_entry (d, &r->domains, list) { -if (d->id == dom_id) { +list_for_each_entry (d, &r->domains, hdr.list) { +if (d->hdr.id == dom_id) { data.buf = dom; data.rdtgrp = rdtgrp;if (r->parse_ctrlval (&data, s, d))
@@ -274,7 +274,7 @@ static bool apply_config(struct rdt_hw_domain *hw_dom,struct rdt_domain *dom = &hw_dom->d_resctrl;if (cfg->new_ctrl != hw_dom->ctrl_val[idx]) { -cpumask_set_cpu (cpumask_any (&dom->cpu_mask), cpu_mask); +cpumask_set_cpu (cpumask_any (&dom->hdr.cpu_mask), cpu_mask); hw_dom->ctrl_val[idx] = cfg->new_ctrl;return true;
@@ -291,7 +291,7 @@ int resctrl_arch_update_one(struct rdt_resource *r, struct rdt_domain *d,u32 idx =get_config_index (closid, t);struct msr_param msr_param; -if (!cpumask_test_cpu (smp_processor_id (), &d->cpu_mask)) +if (!cpumask_test_cpu (smp_processor_id (), &d->hdr.cpu_mask))return -EINVAL ; hw_dom->ctrl_val[idx] = cfg_val;
@@ -318,7 +318,7 @@ int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid)return -ENOMEM ; msr_param.res =NULL ; -list_for_each_entry (d, &r->domains, list) { +list_for_each_entry (d, &r->domains, hdr.list) { hw_dom =resctrl_to_arch_dom (d);for (t =0 ; t <CDP_NUM_TYPES ; t++) { cfg = &hw_dom->d_resctrl.staged_config[t];
@@ -466,7 +466,7 @@ static void show_doms(struct seq_file *s, struct resctrl_schema *schema, int clou32 ctrl_val;seq_printf (s,"%*s:" , max_name_width, schema->name); -list_for_each_entry (dom, &r->domains, list) { +list_for_each_entry (dom, &r->domains, hdr.list) {if (sep)seq_puts (s,";" );
@@ -476,7 +476,7 @@ static void show_doms(struct seq_file *s, struct resctrl_schema *schema, int clo ctrl_val =resctrl_arch_get_config (r, dom, closid, schema->conf_type); -seq_printf (s, r->format_str, dom->id, max_data_width, +seq_printf (s, r->format_str, dom->hdr.id, max_data_width, ctrl_val); sep = true; }
@@ -505,7 +505,7 @@ int rdtgroup_schemata_show(struct kernfs_open_file *of, }else {seq_printf (s,"%s:%d=%x\n" , rdtgrp->plr->s->res->name, - rdtgrp->plr->d->id, + rdtgrp->plr->d->hdr.id, rdtgrp->plr->cbm); } }else {
@@ -536,7 +536,7 @@ void mon_event_read(struct rmid_read *rr, struct rdt_resource *r, rr->val =0 ; rr->first = first; -smp_call_function_any (&d->cpu_mask, mon_event_count, rr,1 ); +smp_call_function_any (&d->hdr.cpu_mask, mon_event_count, rr,1 ); }int rdtgroup_mondata_show (struct seq_file *m,void *arg)
arch/x86/kernel/cpu/resctrl/monitor.c +5 -5
@@ -238,7 +238,7 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain *d,u64 msr_val, chunks;int ret; -if (!cpumask_test_cpu (smp_processor_id (), &d->cpu_mask)) +if (!cpumask_test_cpu (smp_processor_id (), &d->hdr.cpu_mask))return -EINVAL ; ret =__rmid_read (rmid, eventid, &msr_val);
@@ -340,8 +340,8 @@ static void add_rmid_to_limbo(struct rmid_entry *entry) entry->busy =0 ; cpu =get_cpu (); -list_for_each_entry (d, &r->domains, list) { -if (cpumask_test_cpu (cpu, &d->cpu_mask)) { +list_for_each_entry (d, &r->domains, hdr.list) { +if (cpumask_test_cpu (cpu, &d->hdr.cpu_mask)) { err =resctrl_arch_rmid_read (r, d, entry->rmid,QOS_L3_OCCUP_EVENT_ID , &val);
@@ -639,7 +639,7 @@ void cqm_setup_limbo_handler(struct rdt_domain *dom, unsigned long delay_ms)unsigned long delay =msecs_to_jiffies (delay_ms);int cpu; - cpu =cpumask_any (&dom->cpu_mask); + cpu =cpumask_any (&dom->hdr.cpu_mask); dom->cqm_work_cpu = cpu;schedule_delayed_work_on (cpu, &dom->cqm_limbo, delay);
@@ -686,7 +686,7 @@ void mbm_setup_overflow_handler(struct rdt_domain *dom, unsigned long delay_ms)if (!static_branch_likely (&rdt_mon_enable_key))return ; - cpu =cpumask_any (&dom->cpu_mask); + cpu =cpumask_any (&dom->hdr.cpu_mask); dom->mbm_work_cpu = cpu;schedule_delayed_work_on (cpu, &dom->mbm_over, delay); }
arch/x86/kernel/cpu/resctrl/pseudo_lock.c +7 -7
@@ -221,7 +221,7 @@ static int pseudo_lock_cstates_constrain(struct pseudo_lock_region *plr)int cpu;int ret; -for_each_cpu (cpu, &plr->d->cpu_mask) { +for_each_cpu (cpu, &plr->d->hdr.cpu_mask) { pm_req =kzalloc (sizeof (*pm_req),GFP_KERNEL );if (!pm_req) {rdt_last_cmd_puts ("Failure to allocate memory for PM QoS\n" );
@@ -301,7 +301,7 @@ static int pseudo_lock_region_init(struct pseudo_lock_region *plr)return -ENODEV ;/* Pick the first cpu we find that is associated with the cache. */ - plr->cpu =cpumask_first (&plr->d->cpu_mask); + plr->cpu =cpumask_first (&plr->d->hdr.cpu_mask);if (!cpu_online (plr->cpu)) { rdt_last_cmd_printf("CPU %u associated with cache not online\n",
@@ -856,10 +856,10 @@ bool rdtgroup_pseudo_locked_in_hierarchy(struct rdt_domain *d)* associated with them. */ for_each_alloc_capable_rdt_resource (r) { -list_for_each_entry (d_i, &r->domains, list) { +list_for_each_entry (d_i, &r->domains, hdr.list) {if (d_i->plr)cpumask_or (cpu_with_psl, cpu_with_psl, - &d_i->cpu_mask); + &d_i->hdr.cpu_mask); } }
@@ -867,7 +867,7 @@ bool rdtgroup_pseudo_locked_in_hierarchy(struct rdt_domain *d)* Next test if new pseudo-locked region would intersect with * existing region. */ -if (cpumask_intersects (&d->cpu_mask, cpu_with_psl)) +if (cpumask_intersects (&d->hdr.cpu_mask, cpu_with_psl)) ret = true;free_cpumask_var (cpu_with_psl);
@@ -1199,7 +1199,7 @@ static int pseudo_lock_measure_cycles(struct rdtgroup *rdtgrp, int sel) } plr->thread_done =0 ; - cpu =cpumask_first (&plr->d->cpu_mask); + cpu =cpumask_first (&plr->d->hdr.cpu_mask);if (!cpu_online (cpu)) { ret = -ENODEV ; goto out;
@@ -1529,7 +1529,7 @@ static int pseudo_lock_dev_mmap(struct file *filp, struct vm_area_struct *vma)* may be scheduled elsewhere and invalidate entries in the * pseudo-locked region. */ -if (!cpumask_subset (current->cpus_ptr, &plr->d->cpu_mask)) { +if (!cpumask_subset (current->cpus_ptr, &plr->d->hdr.cpu_mask)) {mutex_unlock (&rdtgroup_mutex);return -EINVAL ; }
arch/x86/kernel/cpu/resctrl/rdtgroup.c +30 -30
220 lines not on this page · raw message
Signature · 1 line
2.43.0
Tony Luck
maintainerPATCH v14 3/8 x86/resctrl: Prepare for different scope for control/monitor operations
In reply to Tony LuckResctrl assumes that control and monitor operations on a resource are performed at the same scope.
Prepare for systems that use different scope (specifically Intel needs to split the RDT_RESOURCE_L3 resource to use L3 scope for cache control and NODE scope for cache occupancy and memory bandwidth monitoring).
Create separate domain lists for control and monitor operations.
Note that errors during initialization of either control or monitor functions on a domain would previously result in that domain being excluded from both control and monitor operations. Now the domains are allocated independently it is no longer required to disable both control and monitor operations if either fail.
--- include/linux/resctrl.h | 25 ++- arch/x86/kernel/cpu/resctrl/internal.h | 6 +- arch/x86/kernel/cpu/resctrl/core.c | 211 ++++++++++++++++------ arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 12 +- arch/x86/kernel/cpu/resctrl/monitor.c | 4 +- arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 4 +- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 55 +++--- 7 files changed, 220 insertions(+), 97 deletions(-)
include/linux/resctrl.h +19 -6
@@ -52,15 +52,22 @@ struct resctrl_staged_config {bool have_new_ctrl; }; +enum resctrl_domain_type { +RESCTRL_CTRL_DOMAIN , +RESCTRL_MON_DOMAIN , +}; +/** * struct rdt_domain_hdr - common header for different domain types * @list: all instances of this resource * @id: unique id for this instance +* @type: type of this instance * @cpu_mask: which CPUs share this resource */ struct rdt_domain_hdr {struct list_head list;int id; +enum resctrl_domain_type type;struct cpumask cpu_mask; };
@@ -163,10 +170,12 @@ enum resctrl_scope {* @alloc_capable: Is allocation available on this machine * @mon_capable: Is monitor feature available on this machine * @num_rmid: Number of RMIDs available -* @scope: Scope of this resource +* @ctrl_scope: Scope of this resource for control functions +* @mon_scope: Scope of this resource for monitor functions * @cache: Cache allocation related data * @membw: If the component has bandwidth controls, their properties. -* @domains: All domains for this resource +* @ctrl_domains: Control domains for this resource +* @mon_domains: Monitor domains for this resource * @name: Name to use in "schemata" file. * @data_width: Character width of data when displaying * @default_ctrl: Specifies default cache cbm or memory B/W percent.
@@ -181,10 +190,12 @@ struct rdt_resource {bool alloc_capable;bool mon_capable;int num_rmid; -enum resctrl_scope scope; +enum resctrl_scope ctrl_scope; +enum resctrl_scope mon_scope;struct resctrl_cache cache;struct resctrl_membw membw; -struct list_head domains; +struct list_head ctrl_domains; +struct list_head mon_domains;char *name;int data_width;u32 default_ctrl;
@@ -230,8 +241,10 @@ int resctrl_arch_update_one(struct rdt_resource *r, struct rdt_domain *d,u32 resctrl_arch_get_config (struct rdt_resource *r,struct rdt_domain *d,u32 closid,enum resctrl_conf_type type); -int resctrl_online_domain (struct rdt_resource *r,struct rdt_domain *d); -void resctrl_offline_domain (struct rdt_resource *r,struct rdt_domain *d); +int resctrl_online_ctrl_domain (struct rdt_resource *r,struct rdt_domain *d); +int resctrl_online_mon_domain (struct rdt_resource *r,struct rdt_domain *d); +void resctrl_offline_ctrl_domain (struct rdt_resource *r,struct rdt_domain *d); +void resctrl_offline_mon_domain (struct rdt_resource *r,struct rdt_domain *d);/** * resctrl_arch_rmid_read() - Read the eventid counter corresponding to rmid
arch/x86/kernel/cpu/resctrl/internal.h +3 -3
@@ -518,8 +518,8 @@ 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 *rdt_find_domain (struct rdt_resource *r,int id, -struct list_head **pos); +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,
@@ -538,7 +538,7 @@ int rdt_pseudo_lock_init(void);void rdt_pseudo_lock_release (void );int rdtgroup_pseudo_lock_create (struct rdtgroup *rdtgrp);void rdtgroup_pseudo_lock_remove (struct rdtgroup *rdtgrp); -struct rdt_domain *get_domain_from_cpu (int cpu,struct rdt_resource *r); +struct rdt_domain *get_ctrl_domain_from_cpu (int cpu,struct rdt_resource *r);int closids_supported (void );void closid_free (int closid);int alloc_rmid (void );
arch/x86/kernel/cpu/resctrl/core.c +157 -54
338 lines not on this page · raw message
arch/x86/kernel/cpu/resctrl/ctrlmondata.c +7 -5
@@ -226,7 +226,7 @@ static int parse_line(char *line, struct resctrl_schema *s,return -EINVAL ; } dom =strim (dom); -list_for_each_entry (d, &r->domains, hdr.list) { +list_for_each_entry (d, &r->ctrl_domains, hdr.list) {if (d->hdr.id == dom_id) { data.buf = dom; data.rdtgrp = rdtgrp;
@@ -318,7 +318,7 @@ int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid)return -ENOMEM ; msr_param.res =NULL ; -list_for_each_entry (d, &r->domains, hdr.list) { +list_for_each_entry (d, &r->ctrl_domains, hdr.list) { hw_dom =resctrl_to_arch_dom (d);for (t =0 ; t <CDP_NUM_TYPES ; t++) { cfg = &hw_dom->d_resctrl.staged_config[t];
@@ -466,7 +466,7 @@ static void show_doms(struct seq_file *s, struct resctrl_schema *schema, int clou32 ctrl_val;seq_printf (s,"%*s:" , max_name_width, schema->name); -list_for_each_entry (dom, &r->domains, hdr.list) { +list_for_each_entry (dom, &r->ctrl_domains, hdr.list) {if (sep)seq_puts (s,";" );
@@ -542,6 +542,7 @@ void mon_event_read(struct rmid_read *rr, struct rdt_resource *r,int rdtgroup_mondata_show (struct seq_file *m,void *arg) {struct kernfs_open_file *of = m->private; +struct rdt_domain_hdr *hdr;u32 resid, evtid, domid;struct rdtgroup *rdtgrp;struct rdt_resource *r;
@@ -562,11 +563,12 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg) evtid = md.u.evtid; r = &rdt_resources_all[resid].r_resctrl; - d =rdt_find_domain (r, domid,NULL ); -if (!d) { + hdr =rdt_find_domain (&r->mon_domains, domid,NULL ); +if (!hdr ||WARN_ON_ONCE (hdr->type !=RESCTRL_MON_DOMAIN )) { ret = -ENOENT ; goto out; } + d = container_of(hdr, struct rdt_domain, hdr);mon_event_read (&rr, r, d, rdtgrp, evtid, false);
arch/x86/kernel/cpu/resctrl/monitor.c +2 -2
@@ -340,7 +340,7 @@ static void add_rmid_to_limbo(struct rmid_entry *entry) entry->busy =0 ; cpu =get_cpu (); -list_for_each_entry (d, &r->domains, hdr.list) { +list_for_each_entry (d, &r->mon_domains, hdr.list) {if (cpumask_test_cpu (cpu, &d->hdr.cpu_mask)) { err = resctrl_arch_rmid_read(r, d, entry->rmid, QOS_L3_OCCUP_EVENT_ID,
@@ -532,7 +532,7 @@ static void update_mba_bw(struct rdtgroup *rgrp, struct rdt_domain *dom_mbm) rmid = rgrp->mon.rmid; pmbm_data = &dom_mbm->mbm_local[rmid]; - dom_mba =get_domain_from_cpu (smp_processor_id (), r_mba); + dom_mba =get_ctrl_domain_from_cpu (smp_processor_id (), r_mba);if (!dom_mba) {pr_warn_once ("Failure to get domain for MBA update\n" );return ;
arch/x86/kernel/cpu/resctrl/pseudo_lock.c +2 -2
@@ -292,7 +292,7 @@ static void pseudo_lock_region_clear(struct pseudo_lock_region *plr)*/ static int pseudo_lock_region_init (struct pseudo_lock_region *plr) { -enum resctrl_scope scope = plr->s->res->scope; +enum resctrl_scope scope = plr->s->res->ctrl_scope;struct cpu_cacheinfo *ci;int ret;int i;
@@ -856,7 +856,7 @@ bool rdtgroup_pseudo_locked_in_hierarchy(struct rdt_domain *d)* associated with them. */ for_each_alloc_capable_rdt_resource (r) { -list_for_each_entry (d_i, &r->domains, hdr.list) { +list_for_each_entry (d_i, &r->ctrl_domains, hdr.list) {if (d_i->plr)cpumask_or (cpu_with_psl, cpu_with_psl, &d_i->hdr.cpu_mask);
arch/x86/kernel/cpu/resctrl/rdtgroup.c +30 -25
170 lines not on this page · raw message
Signature · 1 line
2.43.0
Tony Luck
maintainerPATCH v14 4/8 x86/resctrl: Split the rdt_domain and rdt_hw_domain structures
In reply to Tony LuckThe same rdt_domain structure is used for both control and monitor functions. But this results in wasted memory as some of the fields are only used by control functions, while most are only used for monitor functions.
Split into separate rdt_ctrl_domain and rdt_mon_domain structures with just the fields required for control and monitoring respectively.
Similar split of the rdt_hw_domain structure into rdt_hw_ctrl_domain and rdt_hw_mon_domain.
--- include/linux/resctrl.h | 48 +++++++------ arch/x86/kernel/cpu/resctrl/internal.h | 60 ++++++++++------ arch/x86/kernel/cpu/resctrl/core.c | 87 ++++++++++++----------- arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 32 ++++----- arch/x86/kernel/cpu/resctrl/monitor.c | 40 +++++------ arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 6 +- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 62 ++++++++-------- 7 files changed, 182 insertions(+), 153 deletions(-)
include/linux/resctrl.h +28 -20
@@ -72,7 +72,23 @@ struct rdt_domain_hdr { };/** -* struct rdt_domain - group of CPUs sharing a resctrl resource +* struct rdt_ctrl_domain - group of CPUs sharing a resctrl control resource +* @hdr: common header for different domain types +* @plr: pseudo-locked region (if any) associated with domain +* @staged_config: parsed configuration to be applied +* @mbps_val: When mba_sc is enabled, this holds the array of user +* specified control values for mba_sc in MBps, indexed +* by closid +*/ +struct rdt_ctrl_domain { +struct rdt_domain_hdr hdr; +struct pseudo_lock_region *plr; +struct resctrl_staged_config staged_config[CDP_NUM_TYPES ]; +u32 *mbps_val; +}; + +/** +* struct rdt_mon_domain - group of CPUs sharing a resctrl monitor resource * @hdr: common header for different domain types * @rmid_busy_llc: bitmap of which limbo RMIDs are above threshold * @mbm_total: saved state for MBM total bandwidth
@@ -81,13 +97,8 @@ struct rdt_domain_hdr {* @cqm_limbo: worker to periodically read CQM h/w counters * @mbm_work_cpu: worker CPU for MBM h/w counters * @cqm_work_cpu: worker CPU for CQM h/w counters -* @plr: pseudo-locked region (if any) associated with domain -* @staged_config: parsed configuration to be applied -* @mbps_val: When mba_sc is enabled, this holds the array of user -* specified control values for mba_sc in MBps, indexed -* by closid */ -struct rdt_domain { +struct rdt_mon_domain {struct rdt_domain_hdr hdr;unsigned long *rmid_busy_llc;struct mbm_state *mbm_total;
@@ -96,9 +107,6 @@ struct rdt_domain {struct delayed_work cqm_limbo;int mbm_work_cpu;int cqm_work_cpu; -struct pseudo_lock_region *plr; -struct resctrl_staged_config staged_config[CDP_NUM_TYPES ]; -u32 *mbps_val; };/**
@@ -202,7 +210,7 @@ struct rdt_resource {const char *format_str;int (*parse_ctrlval)(struct rdt_parse_data *data,struct resctrl_schema *s, -struct rdt_domain *d); +struct rdt_ctrl_domain *d);struct list_head evt_list;unsigned long fflags;bool cdp_capable;
@@ -236,15 +244,15 @@ int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid);* Update the ctrl_val and apply this config right now. * Must be called on one of the domain's CPUs. */ -int resctrl_arch_update_one (struct rdt_resource *r,struct rdt_domain *d, +int resctrl_arch_update_one (struct rdt_resource *r,struct rdt_ctrl_domain *d,u32 closid,enum resctrl_conf_type t,u32 cfg_val); -u32 resctrl_arch_get_config (struct rdt_resource *r,struct rdt_domain *d, +u32 resctrl_arch_get_config (struct rdt_resource *r,struct rdt_ctrl_domain *d,u32 closid,enum resctrl_conf_type type); -int resctrl_online_ctrl_domain (struct rdt_resource *r,struct rdt_domain *d); -int resctrl_online_mon_domain (struct rdt_resource *r,struct rdt_domain *d); -void resctrl_offline_ctrl_domain (struct rdt_resource *r,struct rdt_domain *d); -void resctrl_offline_mon_domain (struct rdt_resource *r,struct rdt_domain *d); +int resctrl_online_ctrl_domain (struct rdt_resource *r,struct rdt_ctrl_domain *d); +int resctrl_online_mon_domain (struct rdt_resource *r,struct rdt_mon_domain *d); +void resctrl_offline_ctrl_domain (struct rdt_resource *r,struct rdt_ctrl_domain *d); +void resctrl_offline_mon_domain (struct rdt_resource *r,struct rdt_mon_domain *d);/** * resctrl_arch_rmid_read() - Read the eventid counter corresponding to rmid
@@ -260,7 +268,7 @@ void resctrl_offline_mon_domain(struct rdt_resource *r, struct rdt_domain *d);* Return: * 0 on success, or -EIO, -EINVAL etc on error. */ -int resctrl_arch_rmid_read (struct rdt_resource *r,struct rdt_domain *d, +int resctrl_arch_rmid_read (struct rdt_resource *r,struct rdt_mon_domain *d,u32 rmid,enum resctrl_event_id eventid,u64 *val);/**
@@ -273,7 +281,7 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain *d,* * This can be called from any CPU. */ -void resctrl_arch_reset_rmid (struct rdt_resource *r,struct rdt_domain *d, +void resctrl_arch_reset_rmid (struct rdt_resource *r,struct rdt_mon_domain *d,u32 rmid,enum resctrl_event_id eventid);/**
@@ -285,7 +293,7 @@ void resctrl_arch_reset_rmid(struct rdt_resource *r, struct rdt_domain *d,* * This can be called from any CPU. */ -void resctrl_arch_reset_rmid_all (struct rdt_resource *r,struct rdt_domain *d); +void resctrl_arch_reset_rmid_all (struct rdt_resource *r,struct rdt_mon_domain *d);extern unsigned int resctrl_rmid_realloc_threshold;extern unsigned int resctrl_rmid_realloc_limit;
arch/x86/kernel/cpu/resctrl/internal.h +38 -22
131 lines not on this page · raw message
arch/x86/kernel/cpu/resctrl/core.c +46 -41
246 lines not on this page · raw message
arch/x86/kernel/cpu/resctrl/ctrlmondata.c +16 -16
@@ -58,7 +58,7 @@ static bool bw_validate(char *buf, unsigned long *data, struct rdt_resource *r) }int parse_bw (struct rdt_parse_data *data,struct resctrl_schema *s, -struct rdt_domain *d) +struct rdt_ctrl_domain *d) {struct resctrl_staged_config *cfg;u32 closid = data->rdtgrp->closid;
@@ -137,7 +137,7 @@ static bool cbm_validate(char *buf, u32 *data, struct rdt_resource *r)* resource type. */ int parse_cbm (struct rdt_parse_data *data,struct resctrl_schema *s, -struct rdt_domain *d) +struct rdt_ctrl_domain *d) {struct rdtgroup *rdtgrp = data->rdtgrp;struct resctrl_staged_config *cfg;
@@ -206,8 +206,8 @@ static int parse_line(char *line, struct resctrl_schema *s,struct resctrl_staged_config *cfg;struct rdt_resource *r = s->res;struct rdt_parse_data data; +struct rdt_ctrl_domain *d;char *dom =NULL , *id; -struct rdt_domain *d;unsigned long dom_id; if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP &&
@@ -267,11 +267,11 @@ static u32 get_config_index(u32 closid, enum resctrl_conf_type type) } } -static bool apply_config (struct rdt_hw_domain *hw_dom, +static bool apply_config (struct rdt_hw_ctrl_domain *hw_dom,struct resctrl_staged_config *cfg,u32 idx,cpumask_var_t cpu_mask) { -struct rdt_domain *dom = &hw_dom->d_resctrl; +struct rdt_ctrl_domain *dom = &hw_dom->d_resctrl;if (cfg->new_ctrl != hw_dom->ctrl_val[idx]) {cpumask_set_cpu (cpumask_any (&dom->hdr.cpu_mask), cpu_mask);
@@ -283,11 +283,11 @@ static bool apply_config(struct rdt_hw_domain *hw_dom,return false; } -int resctrl_arch_update_one (struct rdt_resource *r,struct rdt_domain *d, +int resctrl_arch_update_one (struct rdt_resource *r,struct rdt_ctrl_domain *d,u32 closid,enum resctrl_conf_type t,u32 cfg_val) { +struct rdt_hw_ctrl_domain *hw_dom =resctrl_to_arch_ctrl_dom (d);struct rdt_hw_resource *hw_res =resctrl_to_arch_res (r); -struct rdt_hw_domain *hw_dom =resctrl_to_arch_dom (d);u32 idx =get_config_index (closid, t);struct msr_param msr_param;
@@ -307,11 +307,11 @@ int resctrl_arch_update_one(struct rdt_resource *r, struct rdt_domain *d,int resctrl_arch_update_domains (struct rdt_resource *r,u32 closid) {struct resctrl_staged_config *cfg; -struct rdt_hw_domain *hw_dom; +struct rdt_hw_ctrl_domain *hw_dom;struct msr_param msr_param; +struct rdt_ctrl_domain *d;enum resctrl_conf_type t;cpumask_var_t cpu_mask; -struct rdt_domain *d;u32 idx;if (!zalloc_cpumask_var (&cpu_mask,GFP_KERNEL ))
@@ -319,7 +319,7 @@ int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid) msr_param.res =NULL ;list_for_each_entry (d, &r->ctrl_domains, hdr.list) { - hw_dom =resctrl_to_arch_dom (d); + hw_dom =resctrl_to_arch_ctrl_dom (d);for (t =0 ; t <CDP_NUM_TYPES ; t++) { cfg = &hw_dom->d_resctrl.staged_config[t];if (!cfg->have_new_ctrl)
@@ -449,10 +449,10 @@ ssize_t rdtgroup_schemata_write(struct kernfs_open_file *of,return ret ?: nbytes; } -u32 resctrl_arch_get_config (struct rdt_resource *r,struct rdt_domain *d, +u32 resctrl_arch_get_config (struct rdt_resource *r,struct rdt_ctrl_domain *d,u32 closid,enum resctrl_conf_type type) { -struct rdt_hw_domain *hw_dom =resctrl_to_arch_dom (d); +struct rdt_hw_ctrl_domain *hw_dom =resctrl_to_arch_ctrl_dom (d);u32 idx =get_config_index (closid, type);return hw_dom->ctrl_val[idx];
@@ -461,7 +461,7 @@ u32 resctrl_arch_get_config(struct rdt_resource *r, struct rdt_domain *d,static void show_doms (struct seq_file *s,struct resctrl_schema *schema,int closid) {struct rdt_resource *r = schema->res; -struct rdt_domain *dom; +struct rdt_ctrl_domain *dom;bool sep = false;u32 ctrl_val;
@@ -523,7 +523,7 @@ int rdtgroup_schemata_show(struct kernfs_open_file *of, }void mon_event_read (struct rmid_read *rr,struct rdt_resource *r, -struct rdt_domain *d,struct rdtgroup *rdtgrp, +struct rdt_mon_domain *d,struct rdtgroup *rdtgrp,int evtid,int first) {/*
@@ -543,11 +543,11 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg) {struct kernfs_open_file *of = m->private;struct rdt_domain_hdr *hdr; +struct rdt_mon_domain *d;u32 resid, evtid, domid;struct rdtgroup *rdtgrp;struct rdt_resource *r;union mon_data_bits md; -struct rdt_domain *d;struct rmid_read rr;int ret =0 ;
@@ -568,7 +568,7 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg) ret = -ENOENT ; goto out; } - d = container_of(hdr, struct rdt_domain, hdr); + d = container_of(hdr, struct rdt_mon_domain, hdr);mon_event_read (&rr, r, d, rdtgrp, evtid, false);
arch/x86/kernel/cpu/resctrl/monitor.c +20 -20
@@ -170,7 +170,7 @@ static int __rmid_read(u32 rmid, enum resctrl_event_id eventid, u64 *val)return 0 ; } -static struct arch_mbm_state *get_arch_mbm_state (struct rdt_hw_domain *hw_dom, +static struct arch_mbm_state *get_arch_mbm_state (struct rdt_hw_mon_domain *hw_dom,u32 rmid,enum resctrl_event_id eventid) {
@@ -189,10 +189,10 @@ static struct arch_mbm_state *get_arch_mbm_state(struct rdt_hw_domain *hw_dom,return NULL ; } -void resctrl_arch_reset_rmid (struct rdt_resource *r,struct rdt_domain *d, +void resctrl_arch_reset_rmid (struct rdt_resource *r,struct rdt_mon_domain *d,u32 rmid,enum resctrl_event_id eventid) { -struct rdt_hw_domain *hw_dom =resctrl_to_arch_dom (d); +struct rdt_hw_mon_domain *hw_dom =resctrl_to_arch_mon_dom (d);struct arch_mbm_state *am; am =get_arch_mbm_state (hw_dom, rmid, eventid);
@@ -208,9 +208,9 @@ void resctrl_arch_reset_rmid(struct rdt_resource *r, struct rdt_domain *d,* Assumes that hardware counters are also reset and thus that there is * no need to record initial non-zero counts. */ -void resctrl_arch_reset_rmid_all (struct rdt_resource *r,struct rdt_domain *d) +void resctrl_arch_reset_rmid_all (struct rdt_resource *r,struct rdt_mon_domain *d) { -struct rdt_hw_domain *hw_dom =resctrl_to_arch_dom (d); +struct rdt_hw_mon_domain *hw_dom =resctrl_to_arch_mon_dom (d);if (is_mbm_total_enabled ()) memset(hw_dom->arch_mbm_total, 0,
@@ -229,11 +229,11 @@ static u64 mbm_overflow_count(u64 prev_msr, u64 cur_msr, unsigned int width)return chunks >> shift; } -int resctrl_arch_rmid_read (struct rdt_resource *r,struct rdt_domain *d, +int resctrl_arch_rmid_read (struct rdt_resource *r,struct rdt_mon_domain *d,u32 rmid,enum resctrl_event_id eventid,u64 *val) { +struct rdt_hw_mon_domain *hw_dom =resctrl_to_arch_mon_dom (d);struct rdt_hw_resource *hw_res =resctrl_to_arch_res (r); -struct rdt_hw_domain *hw_dom =resctrl_to_arch_dom (d);struct arch_mbm_state *am;u64 msr_val, chunks;int ret;
@@ -266,7 +266,7 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain *d,* decrement the count. If the busy count gets to zero on an RMID, we * free the RMID */ -void __check_limbo (struct rdt_domain *d,bool force_free) +void __check_limbo (struct rdt_mon_domain *d,bool force_free) {struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl;struct rmid_entry *entry;
@@ -305,7 +305,7 @@ void __check_limbo(struct rdt_domain *d, bool force_free) } } -bool has_busy_rmid (struct rdt_resource *r,struct rdt_domain *d) +bool has_busy_rmid (struct rdt_resource *r,struct rdt_mon_domain *d) {return find_first_bit (d->rmid_busy_llc, r->num_rmid) != r->num_rmid; }
@@ -334,7 +334,7 @@ int alloc_rmid(void)static void add_rmid_to_limbo (struct rmid_entry *entry) {struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl; -struct rdt_domain *d; +struct rdt_mon_domain *d;int cpu, err;u64 val =0 ;
@@ -383,7 +383,7 @@ void free_rmid(u32 rmid)list_add_tail (&entry->list, &rmid_free_lru); } -static struct mbm_state *get_mbm_state (struct rdt_domain *d,u32 rmid, +static struct mbm_state *get_mbm_state (struct rdt_mon_domain *d,u32 rmid,enum resctrl_event_id evtid) {switch (evtid) {
@@ -513,12 +513,12 @@ void mon_event_count(void *info)* throttle MSRs already have low percentage values. To avoid * unnecessarily restricting such rdtgroups, we also increase the bandwidth. */ -static void update_mba_bw (struct rdtgroup *rgrp,struct rdt_domain *dom_mbm) +static void update_mba_bw (struct rdtgroup *rgrp,struct rdt_mon_domain *dom_mbm) {u32 closid, rmid, cur_msr_val, new_msr_val;struct mbm_state *pmbm_data, *cmbm_data; +struct rdt_ctrl_domain *dom_mba;struct rdt_resource *r_mba; -struct rdt_domain *dom_mba;struct list_head *head;struct rdtgroup *entry;u32 cur_bw, user_bw;
@@ -578,7 +578,7 @@ static void update_mba_bw(struct rdtgroup *rgrp, struct rdt_domain *dom_mbm)resctrl_arch_update_one (r_mba, dom_mba, closid,CDP_NONE , new_msr_val); } -static void mbm_update (struct rdt_resource *r,struct rdt_domain *d,int rmid) +static void mbm_update (struct rdt_resource *r,struct rdt_mon_domain *d,int rmid) {struct rmid_read rr;
@@ -618,13 +618,13 @@ void cqm_handle_limbo(struct work_struct *work) {unsigned long delay =msecs_to_jiffies (CQM_LIMBOCHECK_INTERVAL );int cpu =smp_processor_id (); +struct rdt_mon_domain *d;struct rdt_resource *r; -struct rdt_domain *d;mutex_lock (&rdtgroup_mutex); r = &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl; - d = container_of(work, struct rdt_domain, cqm_limbo.work); + d = container_of(work, struct rdt_mon_domain, cqm_limbo.work);__check_limbo (d, false);
@@ -634,7 +634,7 @@ void cqm_handle_limbo(struct work_struct *work)mutex_unlock (&rdtgroup_mutex); } -void cqm_setup_limbo_handler (struct rdt_domain *dom,unsigned long delay_ms) +void cqm_setup_limbo_handler (struct rdt_mon_domain *dom,unsigned long delay_ms) {unsigned long delay =msecs_to_jiffies (delay_ms);int cpu;
@@ -650,9 +650,9 @@ void mbm_handle_overflow(struct work_struct *work)unsigned long delay =msecs_to_jiffies (MBM_OVERFLOW_INTERVAL );struct rdtgroup *prgrp, *crgrp;int cpu =smp_processor_id (); +struct rdt_mon_domain *d;struct list_head *head;struct rdt_resource *r; -struct rdt_domain *d;mutex_lock (&rdtgroup_mutex);
@@ -660,7 +660,7 @@ void mbm_handle_overflow(struct work_struct *work) goto out_unlock; r = &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl; - d = container_of(work, struct rdt_domain, mbm_over.work); + d = container_of(work, struct rdt_mon_domain, mbm_over.work);list_for_each_entry (prgrp, &rdt_all_groups, rdtgroup_list) {mbm_update (r, d, prgrp->mon.rmid);
@@ -679,7 +679,7 @@ void mbm_handle_overflow(struct work_struct *work)mutex_unlock (&rdtgroup_mutex); } -void mbm_setup_overflow_handler (struct rdt_domain *dom,unsigned long delay_ms) +void mbm_setup_overflow_handler (struct rdt_mon_domain *dom,unsigned long delay_ms) {unsigned long delay =msecs_to_jiffies (delay_ms);int cpu;
arch/x86/kernel/cpu/resctrl/pseudo_lock.c +3 -3
@@ -814,7 +814,7 @@ int rdtgroup_locksetup_exit(struct rdtgroup *rdtgrp)* Return: true if @cbm overlaps with pseudo-locked region on @d, false * otherwise. */ -bool rdtgroup_cbm_overlaps_pseudo_locked (struct rdt_domain *d,unsigned long cbm) +bool rdtgroup_cbm_overlaps_pseudo_locked (struct rdt_ctrl_domain *d,unsigned long cbm) {unsigned int cbm_len;unsigned long cbm_b;
@@ -841,11 +841,11 @@ bool rdtgroup_cbm_overlaps_pseudo_locked(struct rdt_domain *d, unsigned long cbm* if it is not possible to test due to memory allocation issue, * false otherwise. */ -bool rdtgroup_pseudo_locked_in_hierarchy (struct rdt_domain *d) +bool rdtgroup_pseudo_locked_in_hierarchy (struct rdt_ctrl_domain *d) { +struct rdt_ctrl_domain *d_i;cpumask_var_t cpu_with_psl;struct rdt_resource *r; -struct rdt_domain *d_i;bool ret = false;if (!zalloc_cpumask_var (&cpu_with_psl,GFP_KERNEL ))
arch/x86/kernel/cpu/resctrl/rdtgroup.c +31 -31
252 lines not on this page · raw message
Signature · 1 line
2.43.0
Tony Luck
maintainerPATCH v14 5/8 x86/resctrl: Add node-scope to the options for feature scope
In reply to Tony LuckCurrently supported resctrl features are all domain scoped the same as the scope of the L2 or L3 caches.
Add RESCTRL_NODE as a new option for features that are scoped at the same granularity as NUMA nodes. This is needed for Intel's Sub-NUMA Cluster (SNC) feature where monitoring features are node scoped.
--- include/linux/resctrl.h | 1 + arch/x86/kernel/cpu/resctrl/core.c | 2 ++ 2 files changed, 3 insertions(+)
include/linux/resctrl.h +1 -0
@@ -170,6 +170,7 @@ struct resctrl_schema;enum resctrl_scope {RESCTRL_L2_CACHE =2 ,RESCTRL_L3_CACHE =3 , +RESCTRL_NODE , };/**
arch/x86/kernel/cpu/resctrl/core.c +2 -0
@@ -500,6 +500,8 @@ static int get_domain_id_from_scope(int cpu, enum resctrl_scope scope)case RESCTRL_L2_CACHE :case RESCTRL_L3_CACHE :return get_cpu_cacheinfo_id (cpu, scope); +case RESCTRL_NODE : +return cpu_to_node (cpu);default :break ; }
Signature · 1 line
2.43.0
Tony Luck
maintainerPATCH v14 6/8 x86/resctrl: Introduce snc_nodes_per_l3_cache
In reply to Tony LuckIntel Sub-NUMA Cluster (SNC) is a feature that subdivides the CPU cores and memory controllers on a socket into two or more groups. These are presented to the operating system as NUMA nodes.
This may enable some workloads to have slightly lower latency to memory as the memory controller(s) in an SNC node are electrically closer to the CPU cores on that SNC node. This cost may be offset by lower bandwidth since the memory accesses for each core can only be interleaved between the memory controllers on the same SNC node.
Resctrl monitoring on an Intel system depends upon attaching RMIDs to tasks to track L3 cache occupancy and memory bandwidth. There is an MSR that controls how the RMIDs are shared between SNC nodes.
The default mode divides them numerically. E.g. when there are two SNC nodes on a socket the lower number half of the RMIDs are given to the first node, the remainder to the second node. This would be difficult to use with the Linux resctrl interface as specific RMID values assigned to resctrl groups are not visible to users.
The other mode divides the RMIDs and renumbers the ones on the second SNC node to start from zero.
Even with this renumbering SNC mode requires several changes in resctrl behavior for correct operation.
Add a global integer "snc_nodes_per_l3_cache" that shows how many SNC nodes share each L3 cache. When "snc_nodes_per_l3_cache" is "1", SNC mode is either not implemented, or not enabled.
Update all places to take appropriate action when SNC mode is enabled:
1) The number of logical RMIDs per L3 cache available for use is the number of physical RMIDs divided by the number of SNC nodes.
2) Likewise the "mon_scale" value must be divided by the number of SNC nodes.
3) The RMID renumbering operates when using the value from the IA32_PQR_ASSOC MSR to count accesses by a task. When reading an RMID counter, adjust from the logical RMID to the physical RMID value for the SNC node that it wishes to read and load the adjusted value into the IA32_QM_EVTSEL MSR.
4) Divide the L3 cache between the SNC nodes. Divide the value reported in the resctrl "size" file by the number of SNC nodes because the effective amount of cache that can be allocated is reduced by that factor.
5) Disable the "-o mba_MBps" mount option in SNC mode because the monitoring is being done per SNC node, while the bandwidth allocation is still done at the L3 cache scope. Trying to use this feedback loop might result in contradictory changes to the throttling level coming from each of the SNC node bandwidth measurements.
--- arch/x86/kernel/cpu/resctrl/internal.h | 2 ++ arch/x86/kernel/cpu/resctrl/core.c | 6 ++++++ arch/x86/kernel/cpu/resctrl/monitor.c | 16 +++++++++++++--- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 5 +++-- 4 files changed, 24 insertions(+), 5 deletions(-)
arch/x86/kernel/cpu/resctrl/internal.h +2 -0
@@ -444,6 +444,8 @@ DECLARE_STATIC_KEY_FALSE(rdt_alloc_enable_key);extern struct dentry *debugfs_resctrl; +extern unsigned int snc_nodes_per_l3_cache; +enum resctrl_res_level {RDT_RESOURCE_L3 ,RDT_RESOURCE_L2 ,
arch/x86/kernel/cpu/resctrl/core.c +6 -0
@@ -48,6 +48,12 @@ int max_name_width, max_data_width;*/ bool rdt_alloc_capable; +/* +* Number of SNC nodes that share each L3 cache. Default is 1 for +* systems that do not support SNC, or have SNC disabled. +*/ +unsigned int snc_nodes_per_l3_cache =1 ; +static void mba_wrmsr_intel (struct rdt_ctrl_domain *d,struct msr_param *m,struct rdt_resource *r);
arch/x86/kernel/cpu/resctrl/monitor.c +13 -3
@@ -148,8 +148,18 @@ static inline struct rmid_entry *__rmid_entry(u32 rmid)static int __rmid_read (u32 rmid,enum resctrl_event_id eventid,u64 *val) { +struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl; +int cpu =smp_processor_id (); +int rmid_offset =0 ;u64 msr_val; +/* +* When SNC mode is on, need to compute the offset to read the +* physical RMID counter for the node to which this CPU belongs. +*/ +if (snc_nodes_per_l3_cache >1 ) + rmid_offset = (cpu_to_node (cpu) % snc_nodes_per_l3_cache) * r->num_rmid; +/* * As per the SDM, when IA32_QM_EVTSEL.EvtID (bits 7:0) is configured * with a valid event code for supported resource type and the bits
@@ -158,7 +168,7 @@ static int __rmid_read(u32 rmid, enum resctrl_event_id eventid, u64 *val)* IA32_QM_CTR.Error (bit 63) and IA32_QM_CTR.Unavailable (bit 62) * are error bits. */ -wrmsr (MSR_IA32_QM_EVTSEL , eventid, rmid); +wrmsr (MSR_IA32_QM_EVTSEL , eventid, rmid + rmid_offset);rdmsrl (MSR_IA32_QM_CTR , msr_val);if (msr_val &RMID_VAL_ERROR )
@@ -761,8 +771,8 @@ int __init rdt_get_mon_l3_config(struct rdt_resource *r)int ret; resctrl_rmid_realloc_limit = boot_cpu_data.x86_cache_size *1024 ; - hw_res->mon_scale = boot_cpu_data.x86_cache_occ_scale; - r->num_rmid = boot_cpu_data.x86_cache_max_rmid +1 ; + hw_res->mon_scale = boot_cpu_data.x86_cache_occ_scale / snc_nodes_per_l3_cache; + r->num_rmid = (boot_cpu_data.x86_cache_max_rmid +1 ) / snc_nodes_per_l3_cache; hw_res->mbm_width =MBM_CNTR_WIDTH_BASE ;if (mbm_offset >0 && mbm_offset <=MBM_CNTR_WIDTH_OFFSET_MAX )
arch/x86/kernel/cpu/resctrl/rdtgroup.c +3 -2
@@ -1425,7 +1425,7 @@ unsigned int rdtgroup_cbm_to_size(struct rdt_resource *r, } } -return size; +return size / snc_nodes_per_l3_cache; }/*
@@ -2293,7 +2293,8 @@ static bool supports_mba_mbps(void)struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_MBA ].r_resctrl;return (is_mbm_local_enabled () && - r->alloc_capable &&is_mba_linear ()); + r->alloc_capable &&is_mba_linear () && + snc_nodes_per_l3_cache ==1 ); }/*
Signature · 1 line
2.43.0
Tony Luck
maintainerPATCH v14 7/8 x86/resctrl: Sub NUMA Cluster detection and enable
In reply to Tony LuckThere isn't a simple hardware bit that indicates whether a CPU is running in Sub NUMA Cluster (SNC) mode. Infer the state by comparing the ratio of NUMA nodes to L3 cache instances.
When SNC mode is detected, reconfigure the RMID counters by updating the MSR_RMID_SNC_CONFIG MSR on each socket as CPUs are seen.
Clearing bit zero of the MSR divides the RMIDs and renumbers the ones on the second SNC node to start from zero.
--- arch/x86/include/asm/msr-index.h | 1 + arch/x86/kernel/cpu/resctrl/core.c | 118 +++++++++++++++++++++++++++++ 2 files changed, 119 insertions(+)
arch/x86/include/asm/msr-index.h +1 -0
@@ -1119,6 +1119,7 @@#define MSR_IA32_QM_CTR 0xc8e#define MSR_IA32_PQR_ASSOC 0xc8f#define MSR_IA32_L3_CBM_BASE 0xc90 +#define MSR_RMID_SNC_CONFIG 0xca0#define MSR_IA32_L2_CBM_BASE 0xd10#define MSR_IA32_MBA_THRTL_BASE 0xd50
arch/x86/kernel/cpu/resctrl/core.c +118 -0
151 lines not on this page · raw message
Signature · 1 line
2.43.0
Tony Luck
maintainerPATCH v14 8/8 x86/resctrl: Update documentation with Sub-NUMA cluster changes
In reply to Tony LuckWith Sub-NUMA Cluster mode enabled the scope of monitoring resources is per-NODE instead of per-L3 cache. Suffixes of directories with "L3" in their name refer to Sub-NUMA nodes instead of L3 cache ids.
Users should be aware that SNC mode also affects the amount of L3 cache available for allocation within each SNC node.
--- Documentation/arch/x86/resctrl.rst | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-)
Documentation/arch/x86/resctrl.rst +21 -4
@@ -366,10 +366,10 @@ When control is enabled all CTRL_MON groups will also contain: When monitoring is enabled all MON groups will also contain: "mon_data": - This contains a set of files organized by L3 domain and by - RDT event. E.g. on a system with two L3 domains there will - be subdirectories "mon_L3_00" and "mon_L3_01". Each of these - directories have one file per event (e.g. "llc_occupancy", + This contains a set of files organized by L3 domain or by NUMA + node (depending on whether Sub-NUMA Cluster (SNC) mode is disabled + or enabled respectively) and by RDT event. Each of these + directories has one file per event (e.g. "llc_occupancy", "mbm_total_bytes", and "mbm_local_bytes"). In a MON group these files provide a read out of the current value of the event for all tasks in the group. In CTRL_MON groups these files provide
@@ -478,6 +478,23 @@ if non-contiguous 1s value is supported. On a system with a 20-bit mask each bit represents 5% of the capacity of the cache. You could partition the cache into four equal parts with masks: 0x1f, 0x3e0, 0x7c00, 0xf8000. +Notes on Sub-NUMA Cluster mode +============================== +When SNC mode is enabled, Linux may load balance tasks between Sub-NUMA +nodes much more readily than between regular NUMA nodes since the CPUs +on Sub-NUMA nodes share the same L3 cache and the system may report +the NUMA distance between Sub-NUMA nodes with a lower value than used +for regular NUMA nodes. Users who do not bind tasks to the CPUs of a +specific Sub-NUMA node must read the "llc_occupancy", "mbm_total_bytes", +and "mbm_local_bytes" for all Sub-NUMA nodes where the tasks may execute +to get the full view of traffic for which the tasks were the source. + +The cache allocation feature still provides the same number of +bits in a mask to control allocation into the L3 cache, but each +of those ways has its capacity reduced because the cache is divided +between the SNC nodes. The values reported in the resctrl +"size" files are adjusted accordingly. + Memory bandwidth Allocation and monitoring ==========================================
Signature · 1 line
2.43.0
Tony Luck
maintainerRe: [PATCH v14 0/8] Add support for Sub-NUMA cluster (SNC) systems
In reply to Tony LuckI've been wondering whether the SNC patches were creating way too much infrastructure that isn't generally useful. Specifically the capability for a reactrl resource to have different scope for monitoring and control functions.
That seems like a very strange thing.
History here is that Intel CMT, MBM and L3 CAT features arrived in quick succession, closely followed by MBA and then L2 CAT. At the time it made sense for the "L3" resource to cover all of CMT, MBM and L3 CAT.
That became slightly odd when MBA (another L3 scoped resource) was added. It was given its own "struct rdt_resource". AMD later added SMBA as yet another L3-scoped resource with its own "struct resource".
I wondered how the SNC series would look if I went back to an approach from one of the earlier versions. In that one I created a new resource for SNC monitoring that was NODE scoped. And then made all the CMT and MBM code switch over to using that one when SNC was enabled. That was a bit hacky, and I moved from there to the dual domain lists per resource.
I just tried out an approach the split the RDT_RESOURCE_L3 resource into separate resources, one for control, one for monitoring.
It makes the code much simpler:
8 files changed, 235 insertions(+), 30 deletions(-) [1]
vs.
9 files changed, 629 insertions(+), 282 deletions(-)
Tradeoffs:
The complex series (posted as v14) cleanly split the "rdt_domain" structure into two. So it no longer carried all the fields needed for both control and monitor, even though only one set was ever used. But the cost was a lot of code churn that may never be useful for anything other than SNC.
On non-SNC systems the new series produces separate linked lists of domains for L3 control & monitor, even though the lists are the same, and the domain structures still carry all fields for both control and monitor functions.
Question: Does anyone think that single domain with different scope for control and monitor is inherently more useful than two separate domains?
While I get this sorted out, maybe Boris should take James next set of MPAM patches as they are, instead of on top of the complex SNC series.
-Tony
[1] I'll post this set just as soon as I can get time on and SNC machine to make sure they actually work.
Tony Luck
maintainercover Add support for Sub-NUMA cluster (SNC) systems
In reply to Tony LuckThis is the re-worked version of this series that I promised to post yesterday. Check that e-mail for the arguments for this alternate approach.
https://lore.kernel.org/all/ZbhLRDvZrxBZDv2j@agluck-desk3/
Apologies to Drew Fustini who I'd somehow dropped from later versions of this series. Drew: you had made a comment at one point that having different scopes within a single resource may be useful on RISC-V. Version 14 included that, but it's gone here. Maybe multiple resctrl "struct resource" for a single h/w entity like L3 as I'm doing in this version could work for you too?
Patches 1-5 are almost completely rewritten based around the new idea to give CMT and MBM their own "resource" instead of sharing one with L3 CAT. This removes the need for separate domain lists, and thus most of the churn of the previous version of this series.
Patches 6-8 are largely unchanged. But I removed all the Reviewed and Tested tags since they are now built on a completely different base.
Patches are against tip x86/cache:
fc747eebef73 ("x86/resctrl: Remove redundant variable in mbm_config_write_domain()")
Re-work doesn't affect the v14 cover letter, so pasting it here:
The Sub-NUMA cluster feature on some Intel processors partitions the CPUs that share an L3 cache into two or more sets. This plays havoc with the Resource Director Technology (RDT) monitoring features. Prior to this patch Intel has advised that SNC and RDT are incompatible.
Some of these CPU support an MSR that can partition the RMID counters in the same way. This allows monitoring features to be used. With the caveat that users must be aware that Linux may migrate tasks more frequently between SNC nodes than between "regular" NUMA nodes, so reading counters from all SNC nodes may be needed to get a complete picture of activity for tasks.
Cache and memory bandwidth allocation features continue to operate at the scope of the L3 cache.
Tony Luck (8):
x86/resctrl: Split the RDT_RESOURCE_L3 resource x86/resctrl: Move all monitoring functions to RDT_RESOURCE_L3_MON x86/resctrl: Prepare for non-cache-scoped resources x86/resctrl: Add helper function to look up domain_id from scope x86/resctrl: Add "NODE" as an option for resource scope x86/resctrl: Introduce snc_nodes_per_l3_cache x86/resctrl: Sub NUMA Cluster detection and enable x86/resctrl: Update documentation with Sub-NUMA cluster changes
Documentation/arch/x86/resctrl.rst | 25 ++- include/linux/resctrl.h | 10 +- arch/x86/include/asm/msr-index.h | 1 + arch/x86/kernel/cpu/resctrl/internal.h | 3 + arch/x86/kernel/cpu/resctrl/core.c | 181 +++++++++++++++++++++- arch/x86/kernel/cpu/resctrl/monitor.c | 28 ++-- arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 6 +- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 12 +- 8 files changed, 236 insertions(+), 30 deletions(-)
base-commit: fc747eebef734563cf68a512f57937c8f231834a
Signature · 1 line
2.43.0
Tony Luck
maintainerPATCH v3 1/8 x86/resctrl: Split the RDT_RESOURCE_L3 resource
The RDT_RESOURCE_L3 is unique in that it is used for both monitoring an control functions. This made sense while both uses had the same scope. But systems with Sub-NUMA clustering enabled do not follow this pattern.
Create a new resource: RDT_RESOURCE_L3_MON ready to take over the monitoring functions.
--- arch/x86/kernel/cpu/resctrl/internal.h | 1 + arch/x86/kernel/cpu/resctrl/core.c | 10 ++++++++++ 2 files changed, 11 insertions(+)
arch/x86/kernel/cpu/resctrl/internal.h +1 -0
@@ -429,6 +429,7 @@ DECLARE_STATIC_KEY_FALSE(rdt_alloc_enable_key);extern struct dentry *debugfs_resctrl;enum resctrl_res_level { +RDT_RESOURCE_L3_MON ,RDT_RESOURCE_L3 ,RDT_RESOURCE_L2 ,RDT_RESOURCE_MBA ,
arch/x86/kernel/cpu/resctrl/core.c +10 -0
@@ -60,6 +60,16 @@ mba_wrmsr_amd(struct rdt_domain *d, struct msr_param *m,#define domain_init (id) LIST_HEAD_INIT(rdt_resources_all[id].r_resctrl.domains)struct rdt_hw_resource rdt_resources_all[] = { + [RDT_RESOURCE_L3_MON ] = + { + .r_resctrl = { + .rid =RDT_RESOURCE_L3_MON , + .name ="L3" , + .cache_level =3 , + .domains =domain_init (RDT_RESOURCE_L3_MON ), + .fflags =RFTYPE_RES_CACHE , + }, + }, [RDT_RESOURCE_L3 ] = { .r_resctrl = {
Signature · 1 line
2.43.0
Moger, Babu
reviewerRe: [PATCH v15-RFC 1/8] x86/resctrl: Split the RDT_RESOURCE_L3 resource
Hi Tony,
Quoted 2 lines · Tony Luck
The
RDT_RESOURCE_L3is unique in that it is used for both monitoring an control functions. This made sense while both uses had the same
an/and
Quoted 17 lines
scope. But systems with Sub-NUMA clustering enabled do not follow this pattern.
Create a new resource:
RDT_RESOURCE_L3_MONready to take over the monitoring functions.Signed-off-by Tony Luck <[email protected]>--- arch/x86/kernel/cpu/resctrl/internal.h | 1 + arch/x86/kernel/cpu/resctrl/core.c | 10 ++++++++++ 2 files changed, 11 insertions(+)arch/x86/kernel/cpu/resctrl/internal.h +0
-0
arch/x86/kernel/cpu/resctrl/internal.h DECLARE_STATIC_KEY_FALSE(rdt_alloc_enable_key); · line 433
Quoted 5 lines
arch/x86/kernel/cpu/resctrl/internal.h +1
-0@@ -429,6 +429,7 @@ DECLARE_STATIC_KEY_FALSE(rdt_alloc_enable_key);extern struct dentry *debugfs_resctrl;enum resctrl_res_level { +RDT_RESOURCE_L3_MON ,RDT_RESOURCE_L3 ,
How about?RDT_RESOURCE_L3,RDT_RESOURCE_L3_MON,
Quoted 7 lines
arch/x86/kernel/cpu/resctrl/internal.h +0
-0RDT_RESOURCE_L2 , RDT_RESOURCE_MBA,arch/x86/kernel/cpu/resctrl/core.c +0
-0
arch/x86/kernel/cpu/resctrl/core.c mba_wrmsr_amd(struct rdt_domain *d, struct msr_param *m, · line 67
Quoted 8 lines
arch/x86/kernel/cpu/resctrl/core.c +5
-0@@ -60,6 +60,16 @@ mba_wrmsr_amd(struct rdt_domain *d, struct msr_param *m,#define domain_init (id) LIST_HEAD_INIT(rdt_resources_all[id].r_resctrl.domains)struct rdt_hw_resource rdt_resources_all[] = { + [RDT_RESOURCE_L3_MON ] = + { + .r_resctrl = { + .rid =RDT_RESOURCE_L3_MON , + .name ="L3" ,
L3_MON ?
Quoted 8 lines
arch/x86/kernel/cpu/resctrl/core.c +5
-0+ .cache_level = 3, + .domains = domain_init(RDT_RESOURCE_L3_MON), + .fflags = RFTYPE_RES_CACHE, + }, + }, [RDT_RESOURCE_L3 ] = { .r_resctrl = {
Signature · 2 lines
Thanks Babu Moger
Tony Luck
maintainerRe: [PATCH v15-RFC 1/8] x86/resctrl: Split the RDT_RESOURCE_L3 resource
Quoted 7 lines · Babu
arch/x86/kernel/cpu/resctrl/internal.h DECLARE_STATIC_KEY_FALSE(rdt_alloc_enable_key); · line 433
Quoted 3 lines
enum
resctrl_res_level{arch/x86/kernel/cpu/resctrl/internal.h +1
-0+RDT_RESOURCE_L3_MON , RDT_RESOURCE_L3,How about?
RDT_RESOURCE_L3,RDT_RESOURCE_L3_MON,
Does the order matter? I put the L3_MON one first because historically cache occupancy was the first resctrl tool. But if you have a better argument for the order, then I can change it.
Quoted 9 lines
Quoted 9 lines
arch/x86/kernel/cpu/resctrl/internal.h +0
-0RDT_RESOURCE_L2 , RDT_RESOURCE_MBA,arch/x86/kernel/cpu/resctrl/core.c +0
-0@@ -60,6 +60,16 @@ mba_wrmsr_amd(struct rdt_domain *d, struct msr_param *m,#define domain_init (id) LIST_HEAD_INIT(rdt_resources_all[id].r_resctrl.domains)
Quoted 8 lines
arch/x86/kernel/cpu/resctrl/core.c mba_wrmsr_amd(struct rdt_domain *d, struct msr_param *m, · line 67
Quoted 6 lines
arch/x86/kernel/cpu/resctrl/core.c +5
-0struct rdt_hw_resource rdt_resources_all[] = { + [RDT_RESOURCE_L3_MON ] = + { + .r_resctrl = { + .rid =RDT_RESOURCE_L3_MON , + .name ="L3" ,
L3_MON?
That was my first choice too. But I found:
$ ls /sys/fs/resctrl/info L3 L3_MON_MON last_cmd_status MB
This would be easy to fix ... just change this code to not append an extra "_MON" to the directory name:
for_each_mon_capable_rdt_resource(r) {
fflags = r->fflags | RFTYPE_MON_INFO;
sprintf(name, "%s_MON", r->name);
ret = rdtgroup_mkdir_info_resdir(r, name, fflags);
if (ret)
goto out_destroy;
}But I also saw this:
$ ls /sys/fs/resctrl/mon_data/ mon_L3_MON_00 mon_L3_MON_01
which didn't seem to have an easy fix. So I took the easy route and left the ".name" field as "L3_MON".
-Tony
Moger, Babu
reviewerRe: [PATCH v15-RFC 1/8] x86/resctrl: Split the RDT_RESOURCE_L3 resource
Quoted 9 lines · Tony Luck
Quoted 7 lines · Babu
arch/x86/kernel/cpu/resctrl/internal.h DECLARE_STATIC_KEY_FALSE(rdt_alloc_enable_key); · line 433
Quoted 3 lines
enum
resctrl_res_level{arch/x86/kernel/cpu/resctrl/internal.h +1
-0+RDT_RESOURCE_L3_MON , RDT_RESOURCE_L3,How about?
RDT_RESOURCE_L3,RDT_RESOURCE_L3_MON,
Quoted 3 lines
Does the order matter? I put the
L3_MONone first because historically cache occupancy was the first resctrl tool. But if you have a better argument for the order, then I can change it.
That is fine. No need to change.
Quoted 35 lines
Quoted 10 lines
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/internal.h +0
-0RDT_RESOURCE_L2 , RDT_RESOURCE_MBA,arch/x86/kernel/cpu/resctrl/core.c +0
-0@@ -60,6 +60,16 @@ mba_wrmsr_amd(struct rdt_domain *d, struct msr_param *m,#define domain_init (id) LIST_HEAD_INIT(rdt_resources_all[id].r_resctrl.domains)Quoted 8 lines
arch/x86/kernel/cpu/resctrl/core.c mba_wrmsr_amd(struct rdt_domain *d, struct msr_param *m, · line 67
Quoted 6 lines
arch/x86/kernel/cpu/resctrl/core.c +5
-0struct rdt_hw_resource rdt_resources_all[] = { + [RDT_RESOURCE_L3_MON ] = + { + .r_resctrl = { + .rid =RDT_RESOURCE_L3_MON , + .name ="L3" ,
L3_MON?That was my first choice too. But I found:
$ ls /sys/fs/resctrl/info L3 L3_MON_MON last_cmd_status MBThis would be easy to fix ... just change this code to not append an extra "
_MON" to the directory name:for_each_mon_capable_rdt_resource(r) { fflags = r->fflags | RFTYPE_MON_INFO; sprintf(name, "%s_MON", r->name); ret = rdtgroup_mkdir_info_resdir(r, name, fflags); if (ret) goto out_destroy; }
Quoted 7 lines
But I also saw this:
$ ls /sys/fs/resctrl/mon_data/ mon_L3_MON_00 mon_L3_MON_01which didn't seem to have an easy fix. So I took the easy route and left the ".name" field as "
L3_MON".
Ok. Sounds good.
Signature · 2 lines
Thanks Babu Moger
Tony Luck
maintainerPATCH v3 2/8 x86/resctrl: Move all monitoring functions to RDT_RESOURCE_L3_MON
In reply to Tony LuckSwitch over all places that setup and use monitoring funtions to use the new resource structure.
--- arch/x86/kernel/cpu/resctrl/core.c | 6 ++++-- arch/x86/kernel/cpu/resctrl/monitor.c | 12 ++++-------- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 2 +- 3 files changed, 9 insertions(+), 11 deletions(-)
arch/x86/kernel/cpu/resctrl/core.c +4 -2
@@ -591,11 +591,13 @@ static void domain_remove_cpu(int cpu, struct rdt_resource *r)return ; } -if (r == &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl) { +if (r == &rdt_resources_all[RDT_RESOURCE_L3_MON ].r_resctrl) {if (is_mbm_enabled () && cpu == d->mbm_work_cpu) {cancel_delayed_work (&d->mbm_over);mbm_setup_overflow_handler (d,0 ); } + } +if (r == &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl) {if (is_llc_occupancy_enabled () && cpu == d->cqm_work_cpu &&has_busy_rmid (r, d)) {cancel_delayed_work (&d->cqm_limbo);
@@ -826,7 +828,7 @@ static __init bool get_rdt_alloc_resources(void)static __init bool get_rdt_mon_resources (void ) { -struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl; +struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3_MON ].r_resctrl;if (rdt_cpu_has (X86_FEATURE_CQM_OCCUP_LLC )) rdt_mon_features |= (1 <<QOS_L3_OCCUP_EVENT_ID );
arch/x86/kernel/cpu/resctrl/monitor.c +4 -8
@@ -268,7 +268,7 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain *d,*/ void __check_limbo (struct rdt_domain *d,bool force_free) { -struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl; +struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3_MON ].r_resctrl;struct rmid_entry *entry;u32 crmid =1 , nrmid;bool rmid_dirty;
@@ -333,7 +333,7 @@ int alloc_rmid(void)static void add_rmid_to_limbo (struct rmid_entry *entry) { -struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl; +struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3_MON ].r_resctrl;struct rdt_domain *d;int cpu, err;u64 val =0 ;
@@ -623,7 +623,7 @@ void cqm_handle_limbo(struct work_struct *work)mutex_lock (&rdtgroup_mutex); - r = &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl; + r = &rdt_resources_all[RDT_RESOURCE_L3_MON ].r_resctrl; d = container_of(work, struct rdt_domain, cqm_limbo.work);__check_limbo (d, false);
@@ -659,7 +659,7 @@ void mbm_handle_overflow(struct work_struct *work)if (!static_branch_likely (&rdt_mon_enable_key)) goto out_unlock; - r = &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl; + r = &rdt_resources_all[RDT_RESOURCE_L3_MON ].r_resctrl; d = container_of(work, struct rdt_domain, mbm_over.work);list_for_each_entry (prgrp, &rdt_all_groups, rdtgroup_list) {
@@ -736,10 +736,6 @@ static struct mon_evt mbm_local_event = {/* * Initialize the event list for the resource. -* -* Note that MBM events are also part of RDT_RESOURCE_L3 resource -* because as per the SDM the total and local memory bandwidth -* are enumerated as part of L3 monitoring. */ static void l3_mon_evt_init (struct rdt_resource *r) {
arch/x86/kernel/cpu/resctrl/rdtgroup.c +1 -1
@@ -2644,7 +2644,7 @@ static int rdt_get_tree(struct fs_context *fc)static_branch_enable_cpuslocked (&rdt_enable_key);if (is_mbm_enabled ()) { - r = &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl; + r = &rdt_resources_all[RDT_RESOURCE_L3_MON ].r_resctrl;list_for_each_entry (dom, &r->domains, list)mbm_setup_overflow_handler (dom,MBM_OVERFLOW_INTERVAL ); }
Signature · 1 line
2.43.0
Moger, Babu
reviewerRe: [PATCH v15-RFC 2/8] x86/resctrl: Move all monitoring functions to RDT_RESOURCE_L3_MON
Tony,
Quoted 1 line · Tony Luck
Switch over all places that setup and use monitoring funtions to
functions?
Quoted 15 lines
use the new resource structure.
Signed-off-by Tony Luck <[email protected]>--- arch/x86/kernel/cpu/resctrl/core.c | 6 ++++-- arch/x86/kernel/cpu/resctrl/monitor.c | 12 ++++-------- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 2 +- 3 files changed, 9 insertions(+), 11 deletions(-)arch/x86/kernel/cpu/resctrl/core.c +0
-0@@ -591,11 +591,13 @@ static void domain_remove_cpu(int cpu, struct rdt_resource *r)return ;
arch/x86/kernel/cpu/resctrl/core.c static void domain_remove_cpu(int cpu, struct rdt_resource *r) · line 600
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/core.c +3
-1} -if (r == &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl) { +if (r == &rdt_resources_all[RDT_RESOURCE_L3_MON ].r_resctrl) {if (is_mbm_enabled () && cpu == d->mbm_work_cpu) {cancel_delayed_work (&d->mbm_over);mbm_setup_overflow_handler (d,0 ); } + } +if (r == &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl) {
RDT_RESOURCE_L3_MON?
Quoted 76 lines
arch/x86/kernel/cpu/resctrl/core.c +1
-1if (is_llc_occupancy_enabled () && cpu == d->cqm_work_cpu &&has_busy_rmid (r, d)) {cancel_delayed_work (&d->cqm_limbo);@@ -826,7 +828,7 @@ static __init bool get_rdt_alloc_resources(void)static __init bool get_rdt_mon_resources (void ) { -struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl; +struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3_MON ].r_resctrl;if (rdt_cpu_has (X86_FEATURE_CQM_OCCUP_LLC )) rdt_mon_features |= (1 <<QOS_L3_OCCUP_EVENT_ID );arch/x86/kernel/cpu/resctrl/monitor.c +4
-8@@ -268,7 +268,7 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain *d,*/ void __check_limbo (struct rdt_domain *d,bool force_free) { -struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl; +struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3_MON ].r_resctrl;struct rmid_entry *entry;u32 crmid =1 , nrmid;bool rmid_dirty;@@ -333,7 +333,7 @@ int alloc_rmid(void)static void add_rmid_to_limbo (struct rmid_entry *entry) { -struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl; +struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3_MON ].r_resctrl;struct rdt_domain *d;int cpu, err;u64 val =0 ;@@ -623,7 +623,7 @@ void cqm_handle_limbo(struct work_struct *work)mutex_lock (&rdtgroup_mutex); - r = &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl; + r = &rdt_resources_all[RDT_RESOURCE_L3_MON ].r_resctrl; d = container_of(work, struct rdt_domain, cqm_limbo.work);__check_limbo (d, false);@@ -659,7 +659,7 @@ void mbm_handle_overflow(struct work_struct *work)if (!static_branch_likely (&rdt_mon_enable_key)) goto out_unlock; - r = &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl; + r = &rdt_resources_all[RDT_RESOURCE_L3_MON ].r_resctrl; d = container_of(work, struct rdt_domain, mbm_over.work);list_for_each_entry (prgrp, &rdt_all_groups, rdtgroup_list) {@@ -736,10 +736,6 @@ static struct mon_evt mbm_local_event = {/* * Initialize the event list for the resource. -* -* Note that MBM events are also part of RDT_RESOURCE_L3 resource -* because as per the SDM the total and local memory bandwidth -* are enumerated as part of L3 monitoring. */ static void l3_mon_evt_init (struct rdt_resource *r) {arch/x86/kernel/cpu/resctrl/rdtgroup.c +1
-1@@ -2644,7 +2644,7 @@ static int rdt_get_tree(struct fs_context *fc)static_branch_enable_cpuslocked (&rdt_enable_key);if (is_mbm_enabled ()) { - r = &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl; + r = &rdt_resources_all[RDT_RESOURCE_L3_MON ].r_resctrl;list_for_each_entry (dom, &r->domains, list)mbm_setup_overflow_handler (dom,MBM_OVERFLOW_INTERVAL ); }
Signature · 2 lines
Thanks Babu Moger
Tony Luck
maintainerRe: [PATCH v15-RFC 2/8] x86/resctrl: Move all monitoring functions to RDT_RESOURCE_L3_MON
Quoted 6 lines · Babu
Tony,
Quoted 1 line · Tony Luck
Switch over all places that setup and use monitoring funtions to
functions?
Yes. Will fix.
Quoted 17 lines
Quoted 17 lines
use the new resource structure.
Signed-off-by Tony Luck <[email protected]>--- arch/x86/kernel/cpu/resctrl/core.c | 6 ++++-- arch/x86/kernel/cpu/resctrl/monitor.c | 12 ++++-------- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 2 +- 3 files changed, 9 insertions(+), 11 deletions(-)arch/x86/kernel/cpu/resctrl/core.c +0
-0@@ -591,11 +591,13 @@ static void domain_remove_cpu(int cpu, struct rdt_resource *r)return ; }
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/core.c static void domain_remove_cpu(int cpu, struct rdt_resource *r) · line 600
Quoted 8 lines
arch/x86/kernel/cpu/resctrl/core.c +3
-1-if (r == &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl) { +if (r == &rdt_resources_all[RDT_RESOURCE_L3_MON ].r_resctrl) {if (is_mbm_enabled () && cpu == d->mbm_work_cpu) {cancel_delayed_work (&d->mbm_over);mbm_setup_overflow_handler (d,0 ); } + } +if (r == &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl) {
RDT_RESOURCE_L3_MON?
Good catch.
-Tony
Tony Luck
maintainerPATCH v3 3/8 x86/resctrl: Prepare for non-cache-scoped resources
In reply to Tony LuckNot all resources are scoped in line with some level of hardware cache.
Prepare by renaming the "cache_level" field to "scope" and change the type to an enum to ease adding new scopes.
--- include/linux/resctrl.h | 9 +++++++-- arch/x86/kernel/cpu/resctrl/core.c | 14 +++++++------- arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 2 +- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 2 +- 4 files changed, 16 insertions(+), 11 deletions(-)
include/linux/resctrl.h +7 -2
@@ -144,13 +144,18 @@ struct resctrl_membw {struct rdt_parse_data ;struct resctrl_schema ; +enum resctrl_scope { +RESCTRL_L2_CACHE =2 , +RESCTRL_L3_CACHE =3 , +}; +/** * struct rdt_resource - attributes of a resctrl resource * @rid: The index of the resource * @alloc_capable: Is allocation available on this machine * @mon_capable: Is monitor feature available on this machine * @num_rmid: Number of RMIDs available -* @cache_level: Which cache level defines scope of this resource +* @scope: Hardware scope for this resource * @cache: Cache allocation related data * @membw: If the component has bandwidth controls, their properties. * @domains: All domains for this resource
@@ -168,7 +173,7 @@ struct rdt_resource {bool alloc_capable;bool mon_capable;int num_rmid; -int cache_level; +enum resctrl_scope scope;struct resctrl_cache cache;struct resctrl_membw membw;struct list_head domains;
arch/x86/kernel/cpu/resctrl/core.c +7 -7
@@ -65,7 +65,7 @@ struct rdt_hw_resource rdt_resources_all[] = { .r_resctrl = { .rid = RDT_RESOURCE_L3_MON, .name = "L3", - .cache_level = 3, + .scope = RESCTRL_L3_CACHE, .domains = domain_init(RDT_RESOURCE_L3_MON), .fflags = RFTYPE_RES_CACHE, },
@@ -75,7 +75,7 @@ struct rdt_hw_resource rdt_resources_all[] = { .r_resctrl = { .rid = RDT_RESOURCE_L3, .name = "L3", - .cache_level = 3, + .scope = RESCTRL_L3_CACHE, .domains = domain_init(RDT_RESOURCE_L3), .parse_ctrlval = parse_cbm, .format_str = "%d=%0*x",
@@ -89,7 +89,7 @@ struct rdt_hw_resource rdt_resources_all[] = { .r_resctrl = { .rid = RDT_RESOURCE_L2, .name = "L2", - .cache_level = 2, + .scope = RESCTRL_L2_CACHE, .domains = domain_init(RDT_RESOURCE_L2), .parse_ctrlval = parse_cbm, .format_str = "%d=%0*x",
@@ -103,7 +103,7 @@ struct rdt_hw_resource rdt_resources_all[] = { .r_resctrl = { .rid = RDT_RESOURCE_MBA, .name = "MB", - .cache_level = 3, + .scope = RESCTRL_L3_CACHE, .domains = domain_init(RDT_RESOURCE_MBA), .parse_ctrlval = parse_bw, .format_str = "%d=%*u",
@@ -115,7 +115,7 @@ struct rdt_hw_resource rdt_resources_all[] = { .r_resctrl = { .rid = RDT_RESOURCE_SMBA, .name = "SMBA", - .cache_level = 3, + .scope = RESCTRL_L3_CACHE, .domains = domain_init(RDT_RESOURCE_SMBA), .parse_ctrlval = parse_bw, .format_str = "%d=%*u",
@@ -514,7 +514,7 @@ static int arch_domain_mbm_alloc(u32 num_rmid, struct rdt_hw_domain *hw_dom)*/ static void domain_add_cpu (int cpu,struct rdt_resource *r) { -int id =get_cpu_cacheinfo_id (cpu, r->cache_level); +int id =get_cpu_cacheinfo_id (cpu, r->scope);struct list_head *add_pos =NULL ;struct rdt_hw_domain *hw_dom;struct rdt_domain *d;
@@ -564,7 +564,7 @@ static void domain_add_cpu(int cpu, struct rdt_resource *r)static void domain_remove_cpu (int cpu,struct rdt_resource *r) { -int id =get_cpu_cacheinfo_id (cpu, r->cache_level); +int id =get_cpu_cacheinfo_id (cpu, r->scope);struct rdt_hw_domain *hw_dom;struct rdt_domain *d;
arch/x86/kernel/cpu/resctrl/pseudo_lock.c +1 -1
@@ -311,7 +311,7 @@ static int pseudo_lock_region_init(struct pseudo_lock_region *plr) plr->size =rdtgroup_cbm_to_size (plr->s->res, plr->d, plr->cbm);for (i =0 ; i < ci->num_leaves; i++) { -if (ci->info_list[i].level == plr->s->res->cache_level) { +if (ci->info_list[i].level == plr->s->res->scope) { plr->line_size = ci->info_list[i].coherency_line_size;return 0 ; }
arch/x86/kernel/cpu/resctrl/rdtgroup.c +1 -1
@@ -1416,7 +1416,7 @@ unsigned int rdtgroup_cbm_to_size(struct rdt_resource *r, num_b =bitmap_weight (&cbm, r->cache.cbm_len); ci =get_cpu_cacheinfo (cpumask_any (&d->cpu_mask));for (i =0 ; i < ci->num_leaves; i++) { -if (ci->info_list[i].level == r->cache_level) { +if (ci->info_list[i].level == r->scope) { size = ci->info_list[i].size / r->cache.cbm_len * num_b;break ; }
Signature · 1 line
2.43.0
Moger, Babu
reviewerRe: [PATCH v15-RFC 3/8] x86/resctrl: Prepare for non-cache-scoped resources
Hi Tony,
Quoted 1 line · Tony Luck
Not all resources are scoped in line with some level of hardware cache.
same level?
Thanks
Babu
Quoted 138 lines
Prepare by renaming the "
cache_level" field to "scope" and change the type to an enum to ease adding new scopes.Signed-off-by Tony Luck <[email protected]>--- include/linux/resctrl.h | 9 +++++++-- arch/x86/kernel/cpu/resctrl/core.c | 14 +++++++------- arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 2 +- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 2 +- 4 files changed, 16 insertions(+), 11 deletions(-)include/linux/resctrl.h +7
-2@@ -144,13 +144,18 @@ struct resctrl_membw {struct rdt_parse_data ;struct resctrl_schema ; +enum resctrl_scope { +RESCTRL_L2_CACHE =2 , +RESCTRL_L3_CACHE =3 , +}; +/** * struct rdt_resource - attributes of a resctrl resource * @rid: The index of the resource * @alloc_capable: Is allocation available on this machine * @mon_capable: Is monitor feature available on this machine * @num_rmid: Number of RMIDs available -* @cache_level: Which cache level defines scope of this resource +* @scope: Hardware scope for this resource * @cache: Cache allocation related data * @membw: If the component has bandwidth controls, their properties. * @domains: All domains for this resource @@ -168,7 +173,7 @@ struct rdt_resource {bool alloc_capable;bool mon_capable;int num_rmid; -int cache_level; +enum resctrl_scope scope;struct resctrl_cache cache;struct resctrl_membw membw;struct list_head domains;arch/x86/kernel/cpu/resctrl/core.c +7
-7@@ -65,7 +65,7 @@ struct rdt_hw_resource rdt_resources_all[] = { .r_resctrl = { .rid = RDT_RESOURCE_L3_MON, .name = "L3", - .cache_level = 3, + .scope = RESCTRL_L3_CACHE, .domains = domain_init(RDT_RESOURCE_L3_MON), .fflags = RFTYPE_RES_CACHE, },@@ -75,7 +75,7 @@ struct rdt_hw_resource rdt_resources_all[] = { .r_resctrl = { .rid = RDT_RESOURCE_L3, .name = "L3", - .cache_level = 3, + .scope = RESCTRL_L3_CACHE, .domains = domain_init(RDT_RESOURCE_L3), .parse_ctrlval = parse_cbm, .format_str = "%d=%0*x",@@ -89,7 +89,7 @@ struct rdt_hw_resource rdt_resources_all[] = { .r_resctrl = { .rid = RDT_RESOURCE_L2, .name = "L2", - .cache_level = 2, + .scope = RESCTRL_L2_CACHE, .domains = domain_init(RDT_RESOURCE_L2), .parse_ctrlval = parse_cbm, .format_str = "%d=%0*x",@@ -103,7 +103,7 @@ struct rdt_hw_resource rdt_resources_all[] = { .r_resctrl = { .rid = RDT_RESOURCE_MBA, .name = "MB", - .cache_level = 3, + .scope = RESCTRL_L3_CACHE, .domains = domain_init(RDT_RESOURCE_MBA), .parse_ctrlval = parse_bw, .format_str = "%d=%*u",@@ -115,7 +115,7 @@ struct rdt_hw_resource rdt_resources_all[] = { .r_resctrl = { .rid = RDT_RESOURCE_SMBA, .name = "SMBA", - .cache_level = 3, + .scope = RESCTRL_L3_CACHE, .domains = domain_init(RDT_RESOURCE_SMBA), .parse_ctrlval = parse_bw, .format_str = "%d=%*u",@@ -514,7 +514,7 @@ static int arch_domain_mbm_alloc(u32 num_rmid, struct rdt_hw_domain *hw_dom)*/ static void domain_add_cpu (int cpu,struct rdt_resource *r) { -int id =get_cpu_cacheinfo_id (cpu, r->cache_level); +int id =get_cpu_cacheinfo_id (cpu, r->scope);struct list_head *add_pos =NULL ;struct rdt_hw_domain *hw_dom;struct rdt_domain *d;@@ -564,7 +564,7 @@ static void domain_add_cpu(int cpu, struct rdt_resource *r)static void domain_remove_cpu (int cpu,struct rdt_resource *r) { -int id =get_cpu_cacheinfo_id (cpu, r->cache_level); +int id =get_cpu_cacheinfo_id (cpu, r->scope);struct rdt_hw_domain *hw_dom;struct rdt_domain *d;arch/x86/kernel/cpu/resctrl/pseudo_lock.c +1
-1@@ -311,7 +311,7 @@ static int pseudo_lock_region_init(struct pseudo_lock_region *plr) plr->size =rdtgroup_cbm_to_size (plr->s->res, plr->d, plr->cbm);for (i =0 ; i < ci->num_leaves; i++) { -if (ci->info_list[i].level == plr->s->res->cache_level) { +if (ci->info_list[i].level == plr->s->res->scope) { plr->line_size = ci->info_list[i].coherency_line_size;return 0 ; }arch/x86/kernel/cpu/resctrl/rdtgroup.c +1
-1@@ -1416,7 +1416,7 @@ unsigned int rdtgroup_cbm_to_size(struct rdt_resource *r, num_b =bitmap_weight (&cbm, r->cache.cbm_len); ci =get_cpu_cacheinfo (cpumask_any (&d->cpu_mask));for (i =0 ; i < ci->num_leaves; i++) { -if (ci->info_list[i].level == r->cache_level) { +if (ci->info_list[i].level == r->scope) { size = ci->info_list[i].size / r->cache.cbm_len * num_b;break ; }
Signature · 2 lines
Thanks Babu Moger
Tony Luck
maintainerRe: [PATCH v15-RFC 3/8] x86/resctrl: Prepare for non-cache-scoped resources
Quoted 6 lines · Babu
Hi Tony,
Quoted 1 line · Tony Luck
Not all resources are scoped in line with some level of hardware cache.
same level?
No. "same" isn't what I meant here. If I shuffle this around:
Not all resources are scoped to match the scope of a hardware cache level.
Is that more clear?
-Tony
Moger, Babu
reviewerRe: [PATCH v15-RFC 3/8] x86/resctrl: Prepare for non-cache-scoped resources
Quoted 6 lines · Tony Luck
Quoted 5 lines · Babu
Hi Tony,
Quoted 1 line · Tony Luck
Not all resources are scoped in line with some level of hardware cache.
Quoted 8 lines
Quoted 1 line
same level?
No. "same" isn't what I meant here. If I shuffle this around:
Not all resources are scoped to match the scope of a hardware cache level.
Is that more clear?
Sure. Looks good.
Signature · 2 lines
Thanks Babu Moger
Tony Luck
maintainerPATCH v3 4/8 x86/resctrl: Add helper function to look up domain_id from scope
In reply to Tony LuckPrepare for more options for scope of resources. Add some diagnostic messages if lookup fails.
--- arch/x86/kernel/cpu/resctrl/core.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-)
arch/x86/kernel/cpu/resctrl/core.c +27 -2
@@ -499,6 +499,19 @@ static int arch_domain_mbm_alloc(u32 num_rmid, struct rdt_hw_domain *hw_dom)return 0 ; } +static int get_domain_id_from_scope (int cpu,enum resctrl_scope scope) +{ +switch (scope) { +case RESCTRL_L2_CACHE : +case RESCTRL_L3_CACHE : +return get_cpu_cacheinfo_id (cpu, scope); +default : +break ; + } + +return -EINVAL ; +} +/* * domain_add_cpu - Add a cpu to a resource's domain list. *
@@ -514,12 +527,18 @@ static int arch_domain_mbm_alloc(u32 num_rmid, struct rdt_hw_domain *hw_dom)*/ static void domain_add_cpu (int cpu,struct rdt_resource *r) { -int id =get_cpu_cacheinfo_id (cpu, r->scope); +int id =get_domain_id_from_scope (cpu, r->scope);struct list_head *add_pos =NULL ;struct rdt_hw_domain *hw_dom;struct rdt_domain *d;int err; +if (id <0 ) { +pr_warn_once ("Can't find domain id for CPU:%d scope:%d for resource %s\n" , + cpu, r->scope, r->name); +return ; + } + d =rdt_find_domain (r, id, &add_pos);if (IS_ERR (d)) {pr_warn ("Couldn't find cache id for CPU %d\n" , cpu);
@@ -564,10 +583,16 @@ static void domain_add_cpu(int cpu, struct rdt_resource *r)static void domain_remove_cpu (int cpu,struct rdt_resource *r) { -int id =get_cpu_cacheinfo_id (cpu, r->scope); +int id =get_domain_id_from_scope (cpu, r->scope);struct rdt_hw_domain *hw_dom;struct rdt_domain *d; +if (id <0 ) { +pr_warn_once ("Can't find domain id for CPU:%d scope:%d for resource %s\n" , + cpu, r->scope, r->name); +return ; + } + d =rdt_find_domain (r, id,NULL );if (IS_ERR_OR_NULL (d)) {pr_warn ("Couldn't find cache id for CPU %d\n" , cpu);
Signature · 1 line
2.43.0
Moger, Babu
reviewerRe: [PATCH v15-RFC 4/8] x86/resctrl: Add helper function to look up domain_id from scope
Hi Tony,
Quoted 36 lines · Tony Luck
Prepare for more options for scope of resources. Add some diagnostic messages if lookup fails.
Signed-off-by Tony Luck <[email protected]>--- arch/x86/kernel/cpu/resctrl/core.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-)arch/x86/kernel/cpu/resctrl/core.c +13
-0@@ -499,6 +499,19 @@ static int arch_domain_mbm_alloc(u32 num_rmid, struct rdt_hw_domain *hw_dom)return 0 ; } +static int get_domain_id_from_scope (int cpu,enum resctrl_scope scope) +{ +switch (scope) { +case RESCTRL_L2_CACHE : +case RESCTRL_L3_CACHE : +return get_cpu_cacheinfo_id (cpu, scope); +default : +break ; + } + +return -EINVAL ; +} +/* * domain_add_cpu - Add a cpu to a resource's domain list. * @@ -514,12 +527,18 @@ static int arch_domain_mbm_alloc(u32 num_rmid, struct rdt_hw_domain *hw_dom)*/ static void domain_add_cpu (int cpu,struct rdt_resource *r) {
arch/x86/kernel/cpu/resctrl/core.c static int arch_domain_mbm_alloc(u32 num_rmid, struct rdt_hw_domain *hw_dom) · line 538
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/core.c +4
-1-int id =get_cpu_cacheinfo_id (cpu, r->scope); +int id =get_domain_id_from_scope (cpu, r->scope);struct list_head *add_pos =NULL ;struct rdt_hw_domain *hw_dom;struct rdt_domain *d;int err; +if (id <0 ) { +pr_warn_once ("Can't find domain id for CPU:%d scope:%d for resource %s\n" , + cpu, r->scope, r->name);
Will it be good to move pr_warn_once inside get_domain_id_from_scope instead of repeating during every call?
Quoted 8 lines
arch/x86/kernel/cpu/resctrl/core.c +3
-0+return ; + } + d =rdt_find_domain (r, id, &add_pos);if (IS_ERR (d)) {pr_warn ("Couldn't find cache id for CPU %d\n" , cpu);@@ -564,10 +583,16 @@ static void domain_add_cpu(int cpu, struct rdt_resource *r)
arch/x86/kernel/cpu/resctrl/core.c static void domain_add_cpu(int cpu, struct rdt_resource *r) · line 592
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/core.c +4
-1static void domain_remove_cpu (int cpu,struct rdt_resource *r) { -int id =get_cpu_cacheinfo_id (cpu, r->scope); +int id =get_domain_id_from_scope (cpu, r->scope);struct rdt_hw_domain *hw_dom;struct rdt_domain *d; +if (id <0 ) { +pr_warn_once ("Can't find domain id for CPU:%d scope:%d for resource %s\n" , + cpu, r->scope, r->name);
Same comment as above. Will it be good to move pr_warn_once inside get_domain_id_from_scope ?
Quoted 6 lines
arch/x86/kernel/cpu/resctrl/core.c +3
-0+return ; + } + d =rdt_find_domain (r, id,NULL );if (IS_ERR_OR_NULL (d)) {pr_warn ("Couldn't find cache id for CPU %d\n" , cpu);
Signature · 2 lines
Thanks Babu Moger
Tony Luck
maintainerRe: [PATCH v15-RFC 4/8] x86/resctrl: Add helper function to look up domain_id from scope
Quoted 6 lines · Babu
arch/x86/kernel/cpu/resctrl/core.c static int arch_domain_mbm_alloc(u32 num_rmid, struct rdt_hw_domain *hw_dom) · line 538
Quoted 3 lines
arch/x86/kernel/cpu/resctrl/core.c +3
-0+if (id <0 ) { +pr_warn_once ("Can't find domain id for CPU:%d scope:%d for resource %s\n" , + cpu, r->scope, r->name);Will it be good to move
pr_warn_onceinsideget_domain_id_from_scopeinstead of repeating during every call?
Yes. Will move from here to get_domain_id_from_scope().
Quoted 6 lines
arch/x86/kernel/cpu/resctrl/core.c static int arch_domain_mbm_alloc(u32 num_rmid, struct rdt_hw_domain *hw_dom) · line 538
Quoted 3 lines
arch/x86/kernel/cpu/resctrl/core.c +3
-0+if (id <0 ) { +pr_warn_once ("Can't find domain id for CPU:%d scope:%d for resource %s\n" , + cpu, r->scope, r->name);Same comment as above. Will it be good to move
pr_warn_onceinsideget_domain_id_from_scope?
Moved this one too.
Thanks
-Tony
Tony Luck
maintainerPATCH v3 5/8 x86/resctrl: Add "NODE" as an option for resource scope
In reply to Tony LuckAdd RESCTRL_NODE to the enum, and to the helper function that looks up a domain id from a scope.
There are a couple of places where the scope must be a cache scope. Add some defensive WARN_ON checks to those.
--- include/linux/resctrl.h | 1 + arch/x86/kernel/cpu/resctrl/core.c | 3 +++ arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 4 ++++ arch/x86/kernel/cpu/resctrl/rdtgroup.c | 3 +++ 4 files changed, 11 insertions(+)
include/linux/resctrl.h +1 -0
@@ -147,6 +147,7 @@ struct resctrl_schema;enum resctrl_scope {RESCTRL_L2_CACHE =2 ,RESCTRL_L3_CACHE =3 , +RESCTRL_NODE , };/**
arch/x86/kernel/cpu/resctrl/core.c +3 -0
@@ -505,6 +505,9 @@ static int get_domain_id_from_scope(int cpu, enum resctrl_scope scope)case RESCTRL_L2_CACHE :case RESCTRL_L3_CACHE :return get_cpu_cacheinfo_id (cpu, scope); +case RESCTRL_NODE : +return cpu_to_node (cpu); +default :break ; }
arch/x86/kernel/cpu/resctrl/pseudo_lock.c +4 -0
@@ -292,10 +292,14 @@ static void pseudo_lock_region_clear(struct pseudo_lock_region *plr)*/ static int pseudo_lock_region_init (struct pseudo_lock_region *plr) { +enum resctrl_scope scope = plr->s->res->scope;struct cpu_cacheinfo *ci;int ret;int i; +if (WARN_ON_ONCE (scope !=RESCTRL_L2_CACHE && scope !=RESCTRL_L3_CACHE )) +return -ENODEV ; +/* Pick the first cpu we find that is associated with the cache. */ plr->cpu =cpumask_first (&plr->d->cpu_mask);
arch/x86/kernel/cpu/resctrl/rdtgroup.c +3 -0
@@ -1413,6 +1413,9 @@ unsigned int rdtgroup_cbm_to_size(struct rdt_resource *r,unsigned int size =0 ;int num_b, i; +if (WARN_ON_ONCE (r->scope !=RESCTRL_L2_CACHE && r->scope !=RESCTRL_L3_CACHE )) +return size; + num_b =bitmap_weight (&cbm, r->cache.cbm_len); ci =get_cpu_cacheinfo (cpumask_any (&d->cpu_mask));for (i =0 ; i < ci->num_leaves; i++) {
Signature · 1 line
2.43.0