x86/resctrl: Add support for Sub-NUMA cluster (SNC) systems
Subsystems (4)
Tony Luck
maintainerv3 cover x86/resctrl: Add support for Sub-NUMA cluster (SNC) systems
There isn't a simple hardware enumeration to indicate to software that a system is running with Sub-NUMA Clustering enabled.
Compare the number of NUMA nodes with the number of L3 caches to calculate the number of Sub-NUMA nodes per L3 cache.
When Sub-NUMA clustering mode is enabled in BIOS setup, the RMID counters are distributed equally between the SNC nodes within each socket.
E.g. if there are 400 RMID counters, and the system is configured with two SNC nodes per socket, then RMID counter 0..199 are used on SNC node 0 on the socket, and RMID counter 200..399 on SNC node 1.
A model specific MSR (0xca0) can change the configuration of the RMIDs when SNC mode is enabled.
The MSR controls the interpretation of the RMID field in the IA32_PQR_ASSOC MSR so that the appropriate hardware counters within the SNC node are updated. If reconfigured from default, RMIDs are divided evenly across clusters.
Also initialize a per-cpu RMID offset value. Use this to calculate the value to write to the IA32_QM_EVTSEL MSR when reading RMID event values.
N.B. this works well for well-behaved NUMA applications that access memory predominantly from the local memory node. For applications that access memory across multiple nodes it may be necessary for the user to read counters for all SNC nodes on a socket and add the values to get the actual LLC occupancy or memory bandwidth. Perhaps this isn't all that different from applications that span across multiple sockets in a legacy system.
---
Changes since v2:
* Rebased to v6.5-rc1
Peter Newman: Found that I'd reversed the actions writing to the new
MSR to enable/disable RMID remapping for SNC mode.
* Fixed.
Peter Newman: Provided Reviewed-by: and Tested-by: tags
* Included in this series.
Randy Dunlap: Reported a run-on sentence in the documentation.
* Broke the sentence into two as suggested.
Shaopeng Tan: Reported that the CMT resctrl self-test failed
* Added extra patch to the series to make the resctrl test detect when SNC mode is enabled and adjust effective cache size.
* I also patched the rdtgroup_cbm_to_size() function to adjust the cache size reported in the "size" files in resctrl groups when SNC is active.
Shaopeng Tan: Noted the for_each_capable_rdt_resource() macro is no longer used.
* Deleted defintion of this macro.
Tony Luck (8):
x86/resctrl: Refactor in preparation for node-scoped resources x86/resctrl: Remove hard code of RDT_RESOURCE_L3 in monitor.c x86/resctrl: Add a new node-scoped resource to rdt_resources_all[] x86/resctrl: Add code to setup monitoring at L3 or NODE scope. x86/resctrl: Add package scoped resource
x86/resctrl: Update documentation with Sub-NUMA cluster changes x86/resctrl: Determine if Sub-NUMA Cluster is enabled and initialize. selftests/resctrl: Adjust effective L3 cache size when SNC enabled
Documentation/arch/x86/resctrl.rst | 10 +- include/linux/resctrl.h | 5 +- arch/x86/include/asm/resctrl.h | 2 + arch/x86/kernel/cpu/resctrl/internal.h | 20 ++- tools/testing/selftests/resctrl/resctrl.h | 1 + arch/x86/kernel/cpu/resctrl/core.c | 154 ++++++++++++++++++-- arch/x86/kernel/cpu/resctrl/monitor.c | 24 +-- arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 2 +- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 6 +- tools/testing/selftests/resctrl/resctrlfs.c | 57 ++++++++ 10 files changed, 248 insertions(+), 33 deletions(-)
base-commit: 06c2afb862f9da8dc5efa4b6076a0e48c3fbaaa5
Signature · 1 line
2.40.1
Tony Luck
maintainerPATCH v3 1/8 x86/resctrl: Refactor in preparation for node-scoped resources
Sub-NUMA cluster systems provide monitoring resources at the NUMA node scope instead of the L3 cache scope.
Rename the cache_level field in struct rdt_resource to the more generic "scope" and add symbolic names and a helper function.
No functional change.
--- include/linux/resctrl.h | 4 ++-- arch/x86/kernel/cpu/resctrl/internal.h | 5 +++++ arch/x86/kernel/cpu/resctrl/core.c | 17 +++++++++++------ arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 2 +- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 2 +- 5 files changed, 20 insertions(+), 10 deletions(-)
include/linux/resctrl.h +2 -2
@@ -150,7 +150,7 @@ struct resctrl_schema;* @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 level or NUMA node) * @cache: Cache allocation related data * @membw: If the component has bandwidth controls, their properties. * @domains: All domains for this resource
@@ -168,7 +168,7 @@ struct rdt_resource {bool alloc_capable;bool mon_capable;int num_rmid; -int cache_level; +int scope;struct resctrl_cache cache;struct resctrl_membw membw;struct list_head domains;
arch/x86/kernel/cpu/resctrl/internal.h +5 -0
@@ -440,6 +440,11 @@ enum resctrl_res_level { RDT_NUM_RESOURCES, }; +enum resctrl_scope { +SCOPE_L2_CACHE =2 , +SCOPE_L3_CACHE =3 +}; +static inline struct rdt_resource *resctrl_inc (struct rdt_resource *res) {struct rdt_hw_resource *hw_res =resctrl_to_arch_res (res);
arch/x86/kernel/cpu/resctrl/core.c +11 -6
@@ -65,7 +65,7 @@ struct rdt_hw_resource rdt_resources_all[] = { .r_resctrl = { .rid = RDT_RESOURCE_L3, .name = "L3", - .cache_level = 3, + .scope = SCOPE_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 = SCOPE_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 = SCOPE_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 = 3, .domains = domain_init(RDT_RESOURCE_SMBA), .parse_ctrlval = parse_bw, .format_str = "%d=%*u",
@@ -487,6 +487,11 @@ static int arch_domain_mbm_alloc(u32 num_rmid, struct rdt_hw_domain *hw_dom)return 0 ; } +static int get_domain_id (int cpu,enum resctrl_scope scope) +{ +return get_cpu_cacheinfo_id (cpu, scope); +} +/* * domain_add_cpu - Add a cpu to a resource's domain list. *
@@ -502,7 +507,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_domain_id (cpu, r->scope);struct list_head *add_pos =NULL ;struct rdt_hw_domain *hw_dom;struct rdt_domain *d;
@@ -552,7 +557,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_domain_id (cpu, r->scope);struct rdt_hw_domain *hw_dom;struct rdt_domain *d;
arch/x86/kernel/cpu/resctrl/pseudo_lock.c +1 -1
@@ -297,7 +297,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
@@ -1348,7 +1348,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.40.1
Reinette Chatre
maintainerRe: [PATCH v3 1/8] x86/resctrl: Refactor in preparation for node-scoped resources
Hi Tony,
Quoted 5 lines · Tony Luck
Sub-NUMA cluster systems provide monitoring resources at the NUMA node scope instead of the L3 cache scope.
Rename the
cache_levelfield in structrdt_resourceto the more generic "scope" and add symbolic names and a helper function.
Can the changelog elaborate how the helper function is intended to be used? When changelog just states "add a helper function" it is unnecessary since that is clear from the code.
Quoted 6 lines
No functional change.
Signed-off-by Tony Luck <[email protected]>Reviewed-by Peter Newman <[email protected]>---
...
Quoted 32 lines
arch/x86/kernel/cpu/resctrl/core.c +3
-3@@ -65,7 +65,7 @@ struct rdt_hw_resource rdt_resources_all[] = { .r_resctrl = { .rid = RDT_RESOURCE_L3, .name = "L3", - .cache_level = 3, + .scope = SCOPE_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 = SCOPE_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 = SCOPE_L3_CACHE, .domains = domain_init(RDT_RESOURCE_MBA), .parse_ctrlval = parse_bw, .format_str = "%d=%*u",
arch/x86/kernel/cpu/resctrl/core.c struct rdt_hw_resource rdt_resources_all[] = { · line 108
Quoted 5 lines
arch/x86/kernel/cpu/resctrl/core.c +1
-1@@ -105,7 +105,7 @@ struct rdt_hw_resource rdt_resources_all[] = { .r_resctrl = { .rid = RDT_RESOURCE_SMBA, .name = "SMBA", - .cache_level = 3, + .scope = 3,
Should this be SCOPE_L3_CACHE?
Quoted 3 lines
arch/x86/kernel/cpu/resctrl/core.c +0
-0.domains = domain_init(RDT_RESOURCE_SMBA), .parse_ctrlval = parse_bw, .format_str = "%d=%*u",
...
Quoted 18 lines
arch/x86/kernel/cpu/resctrl/pseudo_lock.c +1
-1@@ -297,7 +297,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 +0
-0
arch/x86/kernel/cpu/resctrl/rdtgroup.c unsigned int rdtgroup_cbm_to_size(struct rdt_resource *r, · line 1354
Quoted 8 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +1
-1@@ -1348,7 +1348,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 ; }
The last two hunks are red flags to me. Clearly the "cache_level"->"scope" change is done in preparation for "scope" to be assigned more values than 2 or 3. Yet the code continue to use these values as cache levels, comparing it to cacheinfo->level for which I only expect cache levels 2 or 3 to be valid. The above two hunks thus now have potential for errors when rdt_resource->scope has a value that is not 2 or 3.
Even if these functions may not be called if rdt_resource->scope is not 2 or 3, this change makes the code harder to understand and maintain because now it requires users to know in which flows particular functions can be called and/or when code paths with invalid values are "ok".
Reinette
Tony Luck
maintainerPATCH v3 2/8 x86/resctrl: Remove hard code of RDT_RESOURCE_L3 in monitor.c
In reply to Tony LuckScope of monitoring may be scoped at L3 cache granularity (legacy) or at the node level (systems with Sub NUMA Cluster enabled).
Save the struct rdt_resource pointer that was used to initialize the monitor sections of code and use that value instead of the hard-coded RDT_RESOURCE_L3.
No functional change.
--- arch/x86/kernel/cpu/resctrl/monitor.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)
arch/x86/kernel/cpu/resctrl/monitor.c +11 -7
@@ -30,6 +30,8 @@ struct rmid_entry {struct list_head list; }; +static struct rdt_resource *mon_resource; +/** * @rmid_free_lru A least recently used list of free RMIDs * These RMIDs are guaranteed to have an occupancy less than the
@@ -268,7 +270,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 = mon_resource;struct rmid_entry *entry;u32 crmid =1 , nrmid;bool rmid_dirty;
@@ -333,7 +335,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 = mon_resource;struct rdt_domain *d;int cpu, err;u64 val =0 ;
@@ -645,7 +647,7 @@ void cqm_handle_limbo(struct work_struct *work)mutex_lock (&rdtgroup_mutex); - r = &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl; + r = mon_resource; d = container_of(work, struct rdt_domain, cqm_limbo.work);__check_limbo (d, false);
@@ -681,7 +683,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 = mon_resource; d = container_of(work, struct rdt_domain, mbm_over.work);list_for_each_entry (prgrp, &rdt_all_groups, rdtgroup_list) {
@@ -759,9 +761,9 @@ 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. +* Monitor events can either be part of RDT_RESOURCE_L3 resource, +* or they may be per NUMA node on systems with sub-NUMA cluster +* enabled and are then in the RDT_RESOURCE_NODE resource. */ static void l3_mon_evt_init (struct rdt_resource *r) {
@@ -773,6 +775,8 @@ static void l3_mon_evt_init(struct rdt_resource *r)list_add_tail (&mbm_total_event.list, &r->evt_list);if (is_mbm_local_enabled ())list_add_tail (&mbm_local_event.list, &r->evt_list); + + mon_resource = r; }int __init rdt_get_mon_l3_config (struct rdt_resource *r)
Signature · 1 line
2.40.1
Reinette Chatre
maintainerRe: [PATCH v3 2/8] x86/resctrl: Remove hard code of RDT_RESOURCE_L3 in monitor.c
Hi Tony,
Regarding subject and change: Why is the focus on just monitor.c? Hardcoding of RDT_RESOURCE_L3 as monitoring resource is done elsewhere also (rdtgroup.c:rdt_get_tree()) - why not treat all hardcoding?
On 7/13/2023 9:32 AM, Tony Luck wrote:
...
Quoted 14 lines
arch/x86/kernel/cpu/resctrl/monitor.c +3
-3@@ -759,9 +761,9 @@ 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. +* Monitor events can either be part of RDT_RESOURCE_L3 resource, +* or they may be per NUMA node on systems with sub-NUMA cluster +* enabled and are then in the RDT_RESOURCE_NODE resource. */ static void l3_mon_evt_init (struct rdt_resource *r) {
arch/x86/kernel/cpu/resctrl/monitor.c static void l3_mon_evt_init(struct rdt_resource *r) · line 781
Quoted 7 lines
arch/x86/kernel/cpu/resctrl/monitor.c +2
-0@@ -773,6 +775,8 @@ static void l3_mon_evt_init(struct rdt_resource *r)list_add_tail (&mbm_total_event.list, &r->evt_list);if (is_mbm_local_enabled ())list_add_tail (&mbm_local_event.list, &r->evt_list); + + mon_resource = r; }
This does not seem like the right place for this initialization. mon_evt_init() has a single job that the function comment clearly
states: "Initialize the event list for the resource". What does the global mon_resource have to do with the event list?
Would get_rdt_mon_resources() not be more appropriate?
Although, looking ahead it is not clear to me why this is needed. I'll try to focus my responses to the individual patches in this regard.
arch/x86/kernel/cpu/resctrl/monitor.c static void l3_mon_evt_init(struct rdt_resource *r) · line 782
Quoted 1 line
arch/x86/kernel/cpu/resctrl/monitor.c +0
-0int __init rdt_get_mon_l3_config (struct rdt_resource *r)
Reinette
Tony Luck
maintainerPATCH v3 3/8 x86/resctrl: Add a new node-scoped resource to rdt_resources_all[]
In reply to Tony LuckAdd a placeholder in the array of struct rdt_hw_resource to be used for event monitoring of systems with Sub-NUMA Cluster enabled.
Update get_domain_id() to handle SCOPE_NODE.
--- arch/x86/kernel/cpu/resctrl/internal.h | 4 +++- arch/x86/kernel/cpu/resctrl/core.c | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/resctrl/internal.h +3 -1
@@ -435,6 +435,7 @@ enum resctrl_res_level {RDT_RESOURCE_L2 ,RDT_RESOURCE_MBA ,RDT_RESOURCE_SMBA , +RDT_RESOURCE_NODE ,/* Must be the last */ RDT_NUM_RESOURCES,
@@ -442,7 +443,8 @@ enum resctrl_res_level {enum resctrl_scope {SCOPE_L2_CACHE =2 , -SCOPE_L3_CACHE =3 +SCOPE_L3_CACHE =3 , +SCOPE_NODE , };static inline struct rdt_resource *resctrl_inc (struct rdt_resource *res)
arch/x86/kernel/cpu/resctrl/core.c +12 -0
@@ -112,6 +112,16 @@ struct rdt_hw_resource rdt_resources_all[] = { .fflags = RFTYPE_RES_MB, }, }, + [RDT_RESOURCE_NODE ] = + { + .r_resctrl = { + .rid =RDT_RESOURCE_NODE , + .name ="L3" , + .scope =SCOPE_NODE , + .domains =domain_init (RDT_RESOURCE_NODE ), + .fflags =0 , + }, + }, };/*
@@ -489,6 +499,8 @@ static int arch_domain_mbm_alloc(u32 num_rmid, struct rdt_hw_domain *hw_dom)static int get_domain_id (int cpu,enum resctrl_scope scope) { +if (scope ==SCOPE_NODE ) +return cpu_to_node (cpu);return get_cpu_cacheinfo_id (cpu, scope); }
Signature · 1 line
2.40.1
Reinette Chatre
maintainerRe: [PATCH v3 3/8] x86/resctrl: Add a new node-scoped resource to rdt_resources_all[]
Hi Tony,
Quoted 2 lines · Tony Luck
Add a placeholder in the array of struct
rdt_hw_resourceto be used for event monitoring of systems with Sub-NUMA Cluster enabled.
Could you please elaborate why a new resource is required?
Quoted 23 lines
Update
get_domain_id()to handleSCOPE_NODE.Signed-off-by Tony Luck <[email protected]>Reviewed-by Peter Newman <[email protected]>--- arch/x86/kernel/cpu/resctrl/internal.h | 4 +++- arch/x86/kernel/cpu/resctrl/core.c | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-)arch/x86/kernel/cpu/resctrl/internal.h +1
-0@@ -435,6 +435,7 @@ enum resctrl_res_level {RDT_RESOURCE_L2 ,RDT_RESOURCE_MBA ,RDT_RESOURCE_SMBA , +RDT_RESOURCE_NODE ,/* Must be the last */ RDT_NUM_RESOURCES,
arch/x86/kernel/cpu/resctrl/internal.h enum resctrl_res_level { · line 448
Quoted 7 lines
arch/x86/kernel/cpu/resctrl/internal.h +2
-1@@ -442,7 +443,8 @@ enum resctrl_res_level {enum resctrl_scope {SCOPE_L2_CACHE =2 , -SCOPE_L3_CACHE =3 +SCOPE_L3_CACHE =3 , +SCOPE_NODE , };
A new resource _and_ a new scope is added. Could changelog please explain why this is required?
Quoted 11 lines
arch/x86/kernel/cpu/resctrl/internal.h +0
-0static inline struct rdt_resource *resctrl_inc (struct rdt_resource *res)arch/x86/kernel/cpu/resctrl/core.c +1
-0@@ -112,6 +112,16 @@ struct rdt_hw_resource rdt_resources_all[] = { .fflags = RFTYPE_RES_MB, }, }, + [RDT_RESOURCE_NODE] =
arch/x86/kernel/cpu/resctrl/core.c struct rdt_hw_resource rdt_resources_all[] = { · line 125
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/core.c +9
-0+ { + .r_resctrl = { + .rid = RDT_RESOURCE_NODE, + .name = "L3", + .scope = SCOPE_NODE, + .domains = domain_init(RDT_RESOURCE_NODE), + .fflags = 0, + }, + }, };
So the new resource has the same name, from user perspective, as RDT_RESOURCE_L3. From this perspective it thus seems to be a shadow of RDT_RESOURCE_L3 that is used as alternative for some properties of the actual RDT_RESOURCE_L3? This is starting to look as though this solution is wrenching itself into current architecture.
From what I can tell the monitoring in SNC environment needs a different domain list because of the change in scope. What else is needed in the resource that is different from the existing L3 resource? Could the monitoring scope of a resource not instead be made distinct from its allocation scope? By default monitoring and allocation scope will be the same and thus use the same domain list but when SNC is enabled then monitoring uses a different domain list.
arch/x86/kernel/cpu/resctrl/core.c static int arch_domain_mbm_alloc(u32 num_rmid, struct rdt_hw_domain *hw_dom) · line 506
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/core.c +2
-0/* @@ -489,6 +499,8 @@ static int arch_domain_mbm_alloc(u32 num_rmid, struct rdt_hw_domain *hw_dom)static int get_domain_id (int cpu,enum resctrl_scope scope) { +if (scope ==SCOPE_NODE ) +return cpu_to_node (cpu);return get_cpu_cacheinfo_id (cpu, scope); }
Reinette
Tony Luck
maintainerRe: [PATCH v3 3/8] x86/resctrl: Add a new node-scoped resource to rdt_resources_all[]
Quoted 18 lines · Reinette Chatre
Review
Quoted 11 lines
(quoted diff) +10
-0+ [RDT_RESOURCE_NODE] = + { + .r_resctrl = { + .rid = RDT_RESOURCE_NODE, + .name = "L3", + .scope = SCOPE_NODE, + .domains = domain_init(RDT_RESOURCE_NODE), + .fflags = 0, + }, + }, };So the new resource has the same name, from user perspective, as
RDT_RESOURCE_L3. From this perspective it thus seems to be a shadow ofRDT_RESOURCE_L3that is used as alternative for some properties of the actualRDT_RESOURCE_L3? This is starting to look as though this solution is wrenching itself into current architecture.
Quoted 7 lines
Quoted 1 line
From what I can tell the monitoring in SNC environment needs a different
domain list because of the change in scope. What else is needed in the resource that is different from the existing L3 resource? Could the monitoring scope of a resource not instead be made distinct from its allocation scope? By default monitoring and allocation scope will be the same and thus use the same domain list but when SNC is enabled then monitoring uses a different domain list.
Answering this part first, because my choice here affects a bunch of the code that also raised comments from you.
The crux of the issue is that when SNC mode is enabled the scope for L3 monitoring functions changes to "node" scope, while the scope of L3 control functions (CAT, CDP) remains at L3 cache scope.
My solution was to just create a new resource. But you have an interesing alternate solution. Add an extra domain list to the resource structure to allow creation of distinct domain lists for this case where the scope for control and monitor functions differs.
So change the resource structure like this:
include/linux/resctrl.h +4 -2
@@ -168,10 +168,12 @@ struct rdt_resource {bool alloc_capable;bool mon_capable;int num_rmid; -int cache_level; +int ctrl_scope; +int 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;
and build/use separate domain lists for when this resource is being referenced for allocation/monitoring. E.g. domain_add_cpu() would check "r->alloc_capable" and add a cpu to the ctrl_domains list based on the ctrl_scope value. It would do the same with mon_capable / mon_domains / mon_scope.
If ctrl_scope == mon_scope, just build one list as you suggest above.
Maybe there are more places that walk the list of control domains than walk the list of monitor domains. Need to audit this set:
$ git grep list_for_each.*domains -- arch/x86/kernel/cpu/resctrl
arch/x86/kernel/cpu/resctrl/core.c: list_for_each_entry(d, &r->domains, list) {
arch/x86/kernel/cpu/resctrl/core.c: list_for_each(l, &r->domains) {
arch/x86/kernel/cpu/resctrl/ctrlmondata.c: list_for_each_entry(d, &r->domains, list) {
arch/x86/kernel/cpu/resctrl/ctrlmondata.c: list_for_each_entry(d, &r->domains, list) {
arch/x86/kernel/cpu/resctrl/ctrlmondata.c: list_for_each_entry(dom, &r->domains, list) {
arch/x86/kernel/cpu/resctrl/monitor.c: list_for_each_entry(d, &r->domains, list) {
arch/x86/kernel/cpu/resctrl/pseudo_lock.c: list_for_each_entry(d_i, &r->domains, list) {
arch/x86/kernel/cpu/resctrl/rdtgroup.c: list_for_each_entry(dom, &r->domains, list)
arch/x86/kernel/cpu/resctrl/rdtgroup.c: list_for_each_entry(dom, &r->domains, list) {
arch/x86/kernel/cpu/resctrl/rdtgroup.c: list_for_each_entry(d, &r->domains, list) {
arch/x86/kernel/cpu/resctrl/rdtgroup.c: list_for_each_entry(d, &r->domains, list) {
arch/x86/kernel/cpu/resctrl/rdtgroup.c: list_for_each_entry(dom, &r->domains, list) {
arch/x86/kernel/cpu/resctrl/rdtgroup.c: list_for_each_entry(d, &r->domains, list) {
arch/x86/kernel/cpu/resctrl/rdtgroup.c: list_for_each_entry(d, &r_l->domains, list) {
arch/x86/kernel/cpu/resctrl/rdtgroup.c: list_for_each_entry(d, &r->domains, list) {
arch/x86/kernel/cpu/resctrl/rdtgroup.c: list_for_each_entry(dom, &r->domains, list)
arch/x86/kernel/cpu/resctrl/rdtgroup.c: list_for_each_entry(d, &r->domains, list) {
arch/x86/kernel/cpu/resctrl/rdtgroup.c: list_for_each_entry(dom, &r->domains, list) {
arch/x86/kernel/cpu/resctrl/rdtgroup.c: list_for_each_entry(d, &s->res->domains, list) {
arch/x86/kernel/cpu/resctrl/rdtgroup.c: list_for_each_entry(d, &r->domains, list) {Maybe "domains" can keep its name and make a "list_for_each_monitor_domain()" macro to pick the right list to walk?
I don't think this will reduce the amount of code change in a significant way. But it may be conceptually easier to follow what is going on.
-Tony
Reinette Chatre
maintainerRe: [PATCH v3 3/8] x86/resctrl: Add a new node-scoped resource to rdt_resources_all[]
Hi Tony,
Quoted 27 lines · Tony Luck
Quoted 18 lines · Reinette Chatre
Review
Quoted 11 lines
(quoted diff) +10
-0+ [RDT_RESOURCE_NODE] = + { + .r_resctrl = { + .rid = RDT_RESOURCE_NODE, + .name = "L3", + .scope = SCOPE_NODE, + .domains = domain_init(RDT_RESOURCE_NODE), + .fflags = 0, + }, + }, };So the new resource has the same name, from user perspective, as
RDT_RESOURCE_L3. From this perspective it thus seems to be a shadow ofRDT_RESOURCE_L3that is used as alternative for some properties of the actualRDT_RESOURCE_L3? This is starting to look as though this solution is wrenching itself into current architecture.Quoted 7 lines
Quoted 1 line
From what I can tell the monitoring in SNC environment needs a different
domain list because of the change in scope. What else is needed in the resource that is different from the existing L3 resource? Could the monitoring scope of a resource not instead be made distinct from its allocation scope? By default monitoring and allocation scope will be the same and thus use the same domain list but when SNC is enabled then monitoring uses a different domain list.
Quoted 2 lines
Answering this part first, because my choice here affects a bunch of the code that also raised comments from you.
Indeed.
Quoted 18 lines
The crux of the issue is that when SNC mode is enabled the scope for L3 monitoring functions changes to "node" scope, while the scope of L3 control functions (CAT, CDP) remains at L3 cache scope.
My solution was to just create a new resource. But you have an interesing alternate solution. Add an extra domain list to the resource structure to allow creation of distinct domain lists for this case where the scope for control and monitor functions differs.
So change the resource structure like this:
include/linux/resctrl.h +0
-0
include/linux/resctrl.h struct rdt_resource { · line 172
Quoted 6 lines
include/linux/resctrl.h +2
-1@@ -168,10 +168,12 @@ struct rdt_resource {bool alloc_capable;bool mon_capable;int num_rmid; -int cache_level; +int ctrl_scope; +int mon_scope;
I am not sure about getting rid of cache_level so fast. I see regarding the current problem being solved that ctrl_scope would have the same values as cache_level but I find that adding this level of indirection while keeping the comparison with cacheinfo->level to create a trap for future mistakes.
Quoted 9 lines
include/linux/resctrl.h +2
-1struct 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;
Quoted 7 lines
and build/use separate domain lists for when this resource is being referenced for allocation/monitoring. E.g.
domain_add_cpu()would check "r->alloc_capable" and add a cpu to thectrl_domainslist based on thectrl_scopevalue. It would do the same withmon_capable/mon_domains/mon_scope.If
ctrl_scope==mon_scope, just build one list as you suggest above.
Yes, this is the idea. Thank you for considering it. Something else to consider that may make this even cleaner/simpler would be to review struct rdt_domain and struct rdt_hw_domain members for "monitor" vs "control" usage. These structs could potentially be split further into separate "control" and "monitor" variants. For example, "struct rdt_domain" split into "struct rdt_ctrl_domain" and "struct rdt_mon_domain". If there is a clean split then resctrl can always create two lists with the unnecessary duplication eliminated when two domain lists are created. This would also eliminate the need to scatter ctrl_scope == mon_scope checks throughout.
Quoted 26 lines
Maybe there are more places that walk the list of control domains than walk the list of monitor domains. Need to audit this set:
$ git grep list_for_each.*domains -- arch/x86/kernel/cpu/resctrl arch/x86/kernel/cpu/resctrl/core.c: list_for_each_entry(d, &r->domains, list) { arch/x86/kernel/cpu/resctrl/core.c: list_for_each(l, &r->domains) { arch/x86/kernel/cpu/resctrl/ctrlmondata.c: list_for_each_entry(d, &r->domains, list) { arch/x86/kernel/cpu/resctrl/ctrlmondata.c: list_for_each_entry(d, &r->domains, list) { arch/x86/kernel/cpu/resctrl/ctrlmondata.c: list_for_each_entry(dom, &r->domains, list) { arch/x86/kernel/cpu/resctrl/monitor.c: list_for_each_entry(d, &r->domains, list) { arch/x86/kernel/cpu/resctrl/pseudo_lock.c: list_for_each_entry(d_i, &r->domains, list) { arch/x86/kernel/cpu/resctrl/rdtgroup.c: list_for_each_entry(dom, &r->domains, list) arch/x86/kernel/cpu/resctrl/rdtgroup.c: list_for_each_entry(dom, &r->domains, list) { arch/x86/kernel/cpu/resctrl/rdtgroup.c: list_for_each_entry(d, &r->domains, list) { arch/x86/kernel/cpu/resctrl/rdtgroup.c: list_for_each_entry(d, &r->domains, list) { arch/x86/kernel/cpu/resctrl/rdtgroup.c: list_for_each_entry(dom, &r->domains, list) { arch/x86/kernel/cpu/resctrl/rdtgroup.c: list_for_each_entry(d, &r->domains, list) { arch/x86/kernel/cpu/resctrl/rdtgroup.c: list_for_each_entry(d, &r_l->domains, list) { arch/x86/kernel/cpu/resctrl/rdtgroup.c: list_for_each_entry(d, &r->domains, list) { arch/x86/kernel/cpu/resctrl/rdtgroup.c: list_for_each_entry(dom, &r->domains, list) arch/x86/kernel/cpu/resctrl/rdtgroup.c: list_for_each_entry(d, &r->domains, list) { arch/x86/kernel/cpu/resctrl/rdtgroup.c: list_for_each_entry(dom, &r->domains, list) { arch/x86/kernel/cpu/resctrl/rdtgroup.c: list_for_each_entry(d, &s->res->domains, list) { arch/x86/kernel/cpu/resctrl/rdtgroup.c: list_for_each_entry(d, &r->domains, list) {
Quoted 2 lines
Maybe "domains" can keep its name and make a "
list_for_each_monitor_domain()" macro to pick the right list to walk?
It is not clear to me how "domains" can keep its name. If I understand the macro would be useful if scope always needs to be considered. I wonder if the list walkers may not mostly just walk the appropriate list directly if resctrl always creates separate "control domain" and "monitor domain" lists.
Quoted 3 lines
I don't think this will reduce the amount of code change in a significant way. But it may be conceptually easier to follow what is going on.
Reducing the amount of code changed is not a goal to me. If I understand correctly I think that adapting resctrl to support different monitor and control scope could create a foundation into which SNC can slot in smoothly.
Reinette
Luck, Tony
maintainerRE: [PATCH v3 3/8] x86/resctrl: Add a new node-scoped resource to rdt_resources_all[]
Quoted 9 lines
Yes, this is the idea. Thank you for considering it. Something else to consider that may make this even cleaner/simpler would be to review struct
rdt_domainand structrdt_hw_domainmembers for "monitor" vs "control" usage. These structs could potentially be split further into separate "control" and "monitor" variants. For example, "structrdt_domain" split into "structrdt_ctrl_domain" and "structrdt_mon_domain". If there is a clean split then resctrl can always create two lists with the unnecessary duplication eliminated when two domain lists are created. This would also eliminate the need to scatterctrl_scope==mon_scopechecks throughout.
You might like what I'm doing in the "resctrl2" re-write[1]. Arch independent code that maintains the domain lists for a resource via a cpuhp notifier just has this for the domain structure:
struct resctrl_domain {
struct list_head list;
struct cpumask cpu_mask;
int id;
int cache_size;
};Each module managing a resource decides what extra information it wants to carry in the domain. So the above structure is common to all, but it is followed by whatever the resource module wants. E.g. the CBM masks for each CLOSid for the CAT module. The module tells core code the size to allocate.
"cache_size" is only there because the cache topology bits needed to discover sizes of caches aren't exported. Both the "size" file and pseudo-locking need to know the size.
It's also possible that you may hate it. There is zero sharing of resource structures even if they have the same scope. This is because all modules are independently loadable.
-Tony
[1] WIP snapshot at git://git.kernel.org/pub/scm/linux/kernel/git/aegl/linux.git
branch resctrl2_v65rc1. That doesn't have pseudo-locking, but most of the rest of existing resctrl functionality is there.
Reinette Chatre
maintainerRe: [PATCH v3 3/8] x86/resctrl: Add a new node-scoped resource to rdt_resources_all[]
Hi Tony,
Quoted 21 lines · Tony
Quoted 9 lines
Yes, this is the idea. Thank you for considering it. Something else to consider that may make this even cleaner/simpler would be to review struct
rdt_domainand structrdt_hw_domainmembers for "monitor" vs "control" usage. These structs could potentially be split further into separate "control" and "monitor" variants. For example, "structrdt_domain" split into "structrdt_ctrl_domain" and "structrdt_mon_domain". If there is a clean split then resctrl can always create two lists with the unnecessary duplication eliminated when two domain lists are created. This would also eliminate the need to scatterctrl_scope==mon_scopechecks throughout.You might like what I'm doing in the "resctrl2" re-write[1]. Arch independent code that maintains the domain lists for a resource via a cpuhp notifier just has this for the domain structure:
struct resctrl_domain { struct list_head list; struct cpumask cpu_mask; int id; int cache_size; };
Quoted 4 lines
Each module managing a resource decides what extra information it wants to carry in the domain. So the above structure is common to all, but it is followed by whatever the resource module wants. E.g. the CBM masks for each CLOSid for the CAT module. The module tells core code the size to allocate.
hmmm ... what I am *hearing* you say is that the goodness from the rewrite can be added to resctrl? :)
Quoted 7 lines
"
cache_size" is only there because the cache topology bits needed to discover sizes of caches aren't exported. Both the "size" file and pseudo-locking need to know the size.It's also possible that you may hate it. There is zero sharing of resource structures even if they have the same scope. This is because all modules are independently loadable.
Apologies but I am still unable to understand the problem statement that motivates the rewrite.
Reinette
Tony Luck
maintainerRe: [PATCH v3 3/8] x86/resctrl: Add a new node-scoped resource to rdt_resources_all[]
In reply to Reinette ChatreHere's a quick hack to see how things might look with separate domain lists in the "L3" resource.
For testing purposes on a non-SNC system I set ->mon_scope = MON_SCOPE_NODE, but made domain_add_cpu() allocate the mondomains list based on L3 scope ... just so I could check that I found all the places where monitoring needs to use the mondomains list. The kernel doesn't crash when running tools/testing/selftests/resctrl, and the tests all pass. But that doesn't mean I didn't miss something.
Some restructuring of control vs. monitoing initialization might avoid some of the code I duplicated in domain_add_cpu(). But this is intended just as a "Is this what you meant?" before I dig deeper.
Overall, I think it is a cleaner approach that making a new "L3" resource with different scope just for the SNC monitoring
-Tony
---
include/linux/resctrl.h +8 -2
@@ -151,9 +151,11 @@ struct resctrl_schema;* @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 +* @mon_scope: Scope of this resource if different from cache_level * @cache: Cache allocation related data * @membw: If the component has bandwidth controls, their properties. * @domains: All domains for this resource +* @mondomains: Monitor domains for this resource (if mon_scope != 0) * @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.
@@ -169,9 +171,11 @@ struct rdt_resource {bool mon_capable;int num_rmid;int cache_level; +int mon_scope;struct resctrl_cache cache;struct resctrl_membw membw;struct list_head domains; +struct list_head mondomains;char *name;int data_width;u32 default_ctrl;
@@ -184,6 +188,8 @@ struct rdt_resource {bool cdp_capable; }; +#define MON_SCOPE_NODE 1 +/** * struct resctrl_schema - configuration abilities of a resource presented to * user-space
@@ -217,8 +223,8 @@ 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_domain (struct rdt_resource *r,struct rdt_domain *d,bool mon_setup); +void resctrl_offline_domain (struct rdt_resource *r,struct rdt_domain *d,bool mon_teardown);/** * resctrl_arch_rmid_read() - Read the eventid counter corresponding to rmid
arch/x86/kernel/cpu/resctrl/internal.h +1 -1
@@ -511,7 +511,7 @@ 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 rdt_domain *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);
arch/x86/kernel/cpu/resctrl/core.c +71 -13
174 lines not on this page · raw message
arch/x86/kernel/cpu/resctrl/ctrlmondata.c +3 -1
@@ -545,6 +545,7 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg)struct rdt_resource *r;union mon_data_bits md;struct rdt_domain *d; +struct list_head *h;struct rmid_read rr;int ret =0 ;
@@ -560,7 +561,8 @@ 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 ); + h = r->mon_scope ? &r->mondomains : &r->domains; + d =rdt_find_domain (h, domid,NULL );if (IS_ERR_OR_NULL (d)) { ret = -ENOENT ; goto out;
arch/x86/kernel/cpu/resctrl/monitor.c +3 -1
@@ -335,12 +335,14 @@ 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 list_head *h;int cpu, err;u64 val =0 ; entry->busy =0 ; cpu =get_cpu (); -list_for_each_entry (d, &r->domains, list) { + h = r->mon_scope ? &r->mondomains : &r->domains; +list_for_each_entry (d, h, list) {if (cpumask_test_cpu (cpu, &d->cpu_mask)) { err = resctrl_arch_rmid_read(r, d, entry->rmid, QOS_L3_OCCUP_EVENT_ID,
arch/x86/kernel/cpu/resctrl/rdtgroup.c +16 -8
@@ -1492,11 +1492,13 @@ static 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 list_head *h;bool sep = false;mutex_lock (&rdtgroup_mutex); -list_for_each_entry (dom, &r->domains, list) { + h = r->mon_scope ? &r->mondomains : &r->domains; +list_for_each_entry (dom, h, list) {if (sep)seq_puts (s,";" );
@@ -1599,6 +1601,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 list_head *h;int ret =0 ; next:
@@ -1619,7 +1622,8 @@ static int mon_config_write(struct rdt_resource *r, char *tok, u32 evtid)return -EINVAL ; } -list_for_each_entry (d, &r->domains, list) { + h = r->mon_scope ? &r->mondomains : &r->domains; +list_for_each_entry (d, h, list) {if (d->id == dom_id) { ret =mbm_config_write_domain (r, d, evtid, val);if (ret)
@@ -2465,6 +2469,7 @@ static int rdt_get_tree(struct fs_context *fc)struct rdt_fs_context *ctx =rdt_fc2context (fc);struct rdt_domain *dom;struct rdt_resource *r; +struct list_head *h;int ret;cpus_read_lock ();
@@ -2525,7 +2530,8 @@ 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) + h = r->mon_scope ? &r->mondomains : &r->domains; +list_for_each_entry (dom, h, list)mbm_setup_overflow_handler (dom,MBM_OVERFLOW_INTERVAL ); }
@@ -2917,9 +2923,11 @@ static int mkdir_mondata_subdir_alldom(struct kernfs_node *parent_kn, struct rdtgroup *prgrp) {struct rdt_domain *dom; +struct list_head *h;int ret; -list_for_each_entry (dom, &r->domains, list) { + h = r->mon_scope ? &r->mondomains : &r->domains; +list_for_each_entry (dom, h, list) { ret =mkdir_mondata_subdir (parent_kn, dom, r, prgrp);if (ret)return ret;
@@ -3708,14 +3716,14 @@ 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_domain (struct rdt_resource *r,struct rdt_domain *d,bool mon_teardown) {lockdep_assert_held (&rdtgroup_mutex);if (supports_mba_mbps () && r->rid ==RDT_RESOURCE_MBA )mba_sc_domain_destroy (r, d); -if (!r->mon_capable) +if (!mon_teardown || !r->mon_capable)return ;/*
@@ -3773,7 +3781,7 @@ 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_domain (struct rdt_resource *r,struct rdt_domain *d,bool mon_setup) {int err;
@@ -3783,7 +3791,7 @@ int resctrl_online_domain(struct rdt_resource *r, struct rdt_domain *d)/* RDT_RESOURCE_MBA is never mon_capable */ return mba_sc_domain_allocate (r, d); -if (!r->mon_capable) +if (!mon_setup || !r->mon_capable)return 0 ; err =domain_setup_mon_state (r, d);
Reinette Chatre
maintainerRe: [PATCH v3 3/8] x86/resctrl: Add a new node-scoped resource to rdt_resources_all[]
Hi Tony,
Quoted 10 lines · Tony Luck
Here's a quick hack to see how things might look with separate domain lists in the "L3" resource.
For testing purposes on a non-SNC system I set ->mon_scope =
MON_SCOPE_NODE, but madedomain_add_cpu()allocate the mondomains list based on L3 scope ... just so I could check that I found all the places where monitoring needs to use the mondomains list. The kernel doesn't crash when runningtools/testing/selftests/resctrl, and the tests all pass. But that doesn't mean I didn't miss something.
Quoted 3 lines
Some restructuring of control vs. monitoing initialization might avoid some of the code I duplicated in
domain_add_cpu(). But this is intended just as a "Is this what you meant?" before I dig deeper.
Thank you for considering the approach. I find that this sample move towards the idea while also highlighting what else can be considered. I do not know if you already considered these ideas and found it flawed so I will try to make it explicit so that you can point out to me where things will fall apart.
The sample code introduces a new list "mondomains" that is intended to be used when the monitoring scope is different from the allocation scope. This introduces duplication when the monitoring and allocation scope is different. Each list, "domains" and "mondomains" will host structures that can accommodate both monitoring and allocation data, with the data not relevant to the list going unused as it is unnecessarily duplicated. Additionally this forces significant portions of resctrl to now always consider whether the monitoring and allocation scope is different ... note how this sample now has code like below scattered throughout.
h = r->mon_scope ? &r->mondomains : &r->domains;
I also find the domain_add_cpu() becoming intricate as it needs to navigate all the different scenarios.
This unnecessary duplication, new environment checks needed throughout, and additional code complexities are red flags to me that this solution is not well integrated.
To deal with these complexities I would like to consider if it may make things simpler to always (irrespective of allocation and monitoring scope) maintain allocation and monitoring domain lists. Each list need only carry data appropriate to its use ... the allocation list only has data relevant to allocation, the monitoring list only has data relevant to monitoring. This is the struct rdt_domain related split I mentioned previously.
Code could become something like:
resctrl_online_cpu()
{
...
for_each_alloc_capable_rdt_resource(r)
alloc_domain_add_cpu(...)
for_each_mon_capable_rdt_resource(r)
mon_domain_add_cpu(...)
...
}This would reduce complication in domain_add_cpu() since each domain list only need to concern itself with monitoring or allocation.
Even resctrl_online_domain() can be siplified significantly by making it specific to allocation or monitoring. For example, resctrl_online_mon_domain() would only and always just run the monitoring related code.
With the separate allocation and monitoring domain lists there may no longer be a need for scattering code with checks like:
h = r->mon_scope ? &r->mondomains : &r->domains;
This would be because the code can directly pick the domain list it is operating on.
What do you think? The above is just refactoring of existing code and from what I can tell this would make supporting SNC straight forward.
Reinette
Luck, Tony
maintainerRE: [PATCH v3 3/8] x86/resctrl: Add a new node-scoped resource to rdt_resources_all[]
Quoted 9 lines
To deal with these complexities I would like to consider if it may make things simpler to always (irrespective of allocation and monitoring scope) maintain allocation and monitoring domain lists. Each list need only carry data appropriate to its use ... the allocation list only has data relevant to allocation, the monitoring list only has data relevant to monitoring. This is the struct
rdt_domainrelated split I mentioned previously.Code could become something like:
resctrl_online_cpu()
{
...
for_each_alloc_capable_rdt_resource(r)
alloc_domain_add_cpu(...)
for_each_mon_capable_rdt_resource(r)
mon_domain_add_cpu(...)
...
}Quoted 2 lines
This would reduce complication in
domain_add_cpu()since each domain list only need to concern itself with monitoring or allocation.
This does seem a worthy target.
I started on a patch to so this ... but I'm not sure I have the stamina or the time to see it through.
I split struct rdt_domain into rdt_ctrl_domain and rdt_mon_domain. But that led to also splitting the rdt_hw_domain structure into two, and then splitting the resctrl_to_arch_dom() function, and then another and another.
That process will eventually converge (there are a finite number of lines of code) .... but it will be a big patch. I don't see how to stage it a piece at a time.
-Tony
Tony Luck
maintainerRe: [PATCH v3 3/8] x86/resctrl: Add a new node-scoped resource to rdt_resources_all[]
Quoted 4 lines · Tony
This does seem a worthy target.
I started on a patch to so this ... but I'm not sure I have the stamina or the time to see it through.
I was being a wuss. I came back at this on Friday from a slightly different perspective, and it all came togeteher fairly easily.
New series posted here:
https://lore.kernel.org/all/[email protected]/
-Tony
Tony Luck
maintainerPATCH v3 4/8 x86/resctrl: Add code to setup monitoring at L3 or NODE scope.
In reply to Tony LuckWhen Sub-NUMA cluster is enabled (snc_ways > 1) use the RDT_RESOURCE_NODE instead of RDT_RESOURCE_L3 for all monitoring operations.
The mon_scale and num_rmid values from CPUID(0xf,0x1),(EBX,ECX) must be scaled down by the number of Sub-NUMA Clusters.
A subsequent change will detect sub-NUMA cluster mode and set "snc_ways". For now set to one (meaning each L3 cache spans one node).
--- arch/x86/kernel/cpu/resctrl/internal.h | 7 +++++++ arch/x86/kernel/cpu/resctrl/core.c | 7 ++++++- arch/x86/kernel/cpu/resctrl/monitor.c | 4 ++-- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 2 +- 4 files changed, 16 insertions(+), 4 deletions(-)
arch/x86/kernel/cpu/resctrl/internal.h +7 -0
@@ -430,6 +430,8 @@ DECLARE_STATIC_KEY_FALSE(rdt_alloc_enable_key);extern struct dentry *debugfs_resctrl; +extern int snc_ways; +enum resctrl_res_level {RDT_RESOURCE_L3 ,RDT_RESOURCE_L2 ,
@@ -447,6 +449,11 @@ enum resctrl_scope { SCOPE_NODE, }; +static inline int get_mbm_res_level (void ) +{ +return snc_ways >1 ?RDT_RESOURCE_NODE :RDT_RESOURCE_L3 ; +} +static inline struct rdt_resource *resctrl_inc (struct rdt_resource *res) {struct rdt_hw_resource *hw_res =resctrl_to_arch_res (res);
arch/x86/kernel/cpu/resctrl/core.c +6 -1
@@ -48,6 +48,11 @@ int max_name_width, max_data_width;*/ bool rdt_alloc_capable; +/* +* How many Sub-Numa Cluster nodes share a single L3 cache +*/ +int snc_ways =1 ; +static void mba_wrmsr_intel (struct rdt_domain *d,struct msr_param *m,struct rdt_resource *r);
@@ -831,7 +836,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[get_mbm_res_level ()].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 +2 -2
@@ -787,8 +787,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_ways; + r->num_rmid = (boot_cpu_data.x86_cache_max_rmid +1 ) / snc_ways; 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 +1 -1
@@ -2524,7 +2524,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[get_mbm_res_level ()].r_resctrl;list_for_each_entry (dom, &r->domains, list)mbm_setup_overflow_handler (dom,MBM_OVERFLOW_INTERVAL ); }
Signature · 1 line
2.40.1
Reinette Chatre
maintainerRe: [PATCH v3 4/8] x86/resctrl: Add code to setup monitoring at L3 or NODE scope.
Hi Tony,
Regarding subject: "Add code" is not necessary.
Quoted 2 lines · Tony Luck
When Sub-NUMA cluster is enabled (
snc_ways> 1) use theRDT_RESOURCE_NODEinstead ofRDT_RESOURCE_L3for all monitoring operations.
This duplication of resource does not look right to me. RDT_RESOURCE_NODE now contains the monitoring data for RDT_RESOURCE_L3 with related structures within RDT_RESOURCE_L3 going unused.
Quoted 31 lines
The
mon_scaleandnum_rmidvalues from CPUID(0xf,0x1),(EBX,ECX) must be scaled down by the number of Sub-NUMA Clusters.A subsequent change will detect sub-NUMA cluster mode and set "
snc_ways". For now set to one (meaning each L3 cache spans one node).Signed-off-by Tony Luck <[email protected]>Reviewed-by Peter Newman <[email protected]>--- arch/x86/kernel/cpu/resctrl/internal.h | 7 +++++++ arch/x86/kernel/cpu/resctrl/core.c | 7 ++++++- arch/x86/kernel/cpu/resctrl/monitor.c | 4 ++-- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 2 +- 4 files changed, 16 insertions(+), 4 deletions(-)arch/x86/kernel/cpu/resctrl/internal.h +2
-0@@ -430,6 +430,8 @@ DECLARE_STATIC_KEY_FALSE(rdt_alloc_enable_key);extern struct dentry *debugfs_resctrl; +extern int snc_ways; +enum resctrl_res_level {RDT_RESOURCE_L3 ,RDT_RESOURCE_L2 ,
arch/x86/kernel/cpu/resctrl/internal.h enum resctrl_scope { · line 455
Quoted 7 lines
arch/x86/kernel/cpu/resctrl/internal.h +4
-0@@ -447,6 +449,11 @@ enum resctrl_scope { SCOPE_NODE, }; +static inline int get_mbm_res_level (void ) +{ +return snc_ways >1 ?RDT_RESOURCE_NODE :RDT_RESOURCE_L3 ; +}
Need to return the enum here? It may be simpler for this helper to just return a pointer to the resource. (Although the need for a separate resource is still not clear to me.)
Quoted 9 lines
arch/x86/kernel/cpu/resctrl/internal.h +1
-0+static inline struct rdt_resource *resctrl_inc (struct rdt_resource *res) {struct rdt_hw_resource *hw_res =resctrl_to_arch_res (res);arch/x86/kernel/cpu/resctrl/core.c +0
-0
arch/x86/kernel/cpu/resctrl/core.c int max_name_width, max_data_width; · line 55
Quoted 8 lines
arch/x86/kernel/cpu/resctrl/core.c +5
-0@@ -48,6 +48,11 @@ int max_name_width, max_data_width;*/ bool rdt_alloc_capable; +/* +* How many Sub-Numa Cluster nodes share a single L3 cache +*/ +int snc_ways =1 ; +
Since snc_ways is always used I think the comment should provide more detail on the possible values it may have. For example, to a reader it may not be obvious what the value of snc_ways should be if SNC is disabled. Also, what does "ways" refer to? (Also mentioned later).
Quoted 32 lines
arch/x86/kernel/cpu/resctrl/core.c +1
-1static void mba_wrmsr_intel (struct rdt_domain *d,struct msr_param *m,struct rdt_resource *r);@@ -831,7 +836,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[get_mbm_res_level ()].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 +2
-2@@ -787,8 +787,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_ways; + r->num_rmid = (boot_cpu_data.x86_cache_max_rmid +1 ) / snc_ways; 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 +0
-0
arch/x86/kernel/cpu/resctrl/rdtgroup.c static int rdt_get_tree(struct fs_context *fc) · line 2530
Quoted 8 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +1
-1@@ -2524,7 +2524,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[get_mbm_res_level ()].r_resctrl;list_for_each_entry (dom, &r->domains, list)mbm_setup_overflow_handler (dom,MBM_OVERFLOW_INTERVAL ); }
This final hunk makes me wonder why the monitor.c:mon_resource is necessary at all. A single helper used everywhere may be simpler.
Reinette
Tony Luck
maintainerPATCH v3 5/8 x86/resctrl: Add package scoped resource
In reply to Tony LuckSome Intel features require setting a package scoped model specific register.
Add a new resource that builds domains for each package.
--- include/linux/resctrl.h | 1 + arch/x86/kernel/cpu/resctrl/internal.h | 6 ++++-- arch/x86/kernel/cpu/resctrl/core.c | 23 +++++++++++++++++++---- 3 files changed, 24 insertions(+), 6 deletions(-)
include/linux/resctrl.h +1 -0
@@ -167,6 +167,7 @@ struct rdt_resource {int rid;bool alloc_capable;bool mon_capable; +bool pkg_actions;int num_rmid;int scope;struct resctrl_cache cache;
arch/x86/kernel/cpu/resctrl/internal.h +4 -2
@@ -438,6 +438,7 @@ enum resctrl_res_level {RDT_RESOURCE_MBA ,RDT_RESOURCE_SMBA ,RDT_RESOURCE_NODE , +RDT_RESOURCE_PKG ,/* Must be the last */ RDT_NUM_RESOURCES,
@@ -447,6 +448,7 @@ enum resctrl_scope {SCOPE_L2_CACHE =2 ,SCOPE_L3_CACHE =3 ,SCOPE_NODE , + SCOPE_PKG, };static inline int get_mbm_res_level (void )
@@ -478,9 +480,9 @@ int resctrl_arch_set_cdp_enabled(enum resctrl_res_level l, bool enable); r <= &rdt_resources_all[RDT_NUM_RESOURCES -1 ].r_resctrl; \ r = resctrl_inc(r)) -#define for_each_capable_rdt_resource (r) \ +#define for_each_domain_needed_rdt_resource (r) \ for_each_rdt_resource(r) \ - if (r->alloc_capable || r->mon_capable) + if (r->alloc_capable || r->mon_capable || r->pkg_actions)#define for_each_alloc_capable_rdt_resource (r) \ for_each_rdt_resource(r) \
arch/x86/kernel/cpu/resctrl/core.c +19 -4
@@ -127,6 +127,16 @@ struct rdt_hw_resource rdt_resources_all[] = { .fflags = 0, }, }, + [RDT_RESOURCE_PKG ] = + { + .r_resctrl = { + .rid =RDT_RESOURCE_PKG , + .name ="PKG" , + .scope =SCOPE_PKG , + .domains =domain_init (RDT_RESOURCE_PKG ), + .fflags =0 , + }, + }, };/*
@@ -504,9 +514,14 @@ static int arch_domain_mbm_alloc(u32 num_rmid, struct rdt_hw_domain *hw_dom)static int get_domain_id (int cpu,enum resctrl_scope scope) { -if (scope ==SCOPE_NODE ) +switch (scope) { +case SCOPE_NODE :return cpu_to_node (cpu); -return get_cpu_cacheinfo_id (cpu, scope); +case SCOPE_PKG : +return topology_physical_package_id (cpu); +default : +return get_cpu_cacheinfo_id (cpu, scope); + } }/*
@@ -630,7 +645,7 @@ static int resctrl_online_cpu(unsigned int cpu)struct rdt_resource *r;mutex_lock (&rdtgroup_mutex); -for_each_capable_rdt_resource (r) +for_each_domain_needed_rdt_resource (r)domain_add_cpu (cpu, r);/* The cpu is set in default rdtgroup after online. */ cpumask_set_cpu (cpu, &rdtgroup_default.cpu_mask);
@@ -657,7 +672,7 @@ static int resctrl_offline_cpu(unsigned int cpu)struct rdt_resource *r;mutex_lock (&rdtgroup_mutex); -for_each_capable_rdt_resource (r) +for_each_domain_needed_rdt_resource (r)domain_remove_cpu (cpu, r);list_for_each_entry (rdtgrp, &rdt_all_groups, rdtgroup_list) {if (cpumask_test_and_clear_cpu (cpu, &rdtgrp->cpu_mask)) {
Signature · 1 line
2.40.1
Reinette Chatre
maintainerRe: [PATCH v3 5/8] x86/resctrl: Add package scoped resource
Hi Tony,
Quoted 4 lines · Tony Luck
Some Intel features require setting a package scoped model specific register.
Add a new resource that builds domains for each package.
If I understand correctly the only purpose of this new resource is to know when the first CPU associated with a package comes online. Am I not reading this right? Using a resctrl resource for this purpose seems inappropriate and unnecessary while also making the code very hard to follow.
Reinette
Tony Luck
maintainerRe: [PATCH v3 5/8] x86/resctrl: Add package scoped resource
Quoted 6 lines · Reinette Chatre
Hi Tony,
Quoted 3 lines · Tony Luck
Some Intel features require setting a package scoped model specific register.
Quoted 7 lines
Quoted 1 line
Add a new resource that builds domains for each package.
If I understand correctly the only purpose of this new resource is to know when the first CPU associated with a package comes online. Am I not reading this right? Using a resctrl resource for this purpose seems inappropriate and unnecessary while also making the code very hard to follow.
Reinette,
Yes. You understand.
I agree that this is blatant abuse of the resource structures. I can find another way to perform an action on the first CPU of a package online, and the last CPU of a package offline.
-Tony
Tony Luck
maintainerPATCH v3 6/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.
--- Documentation/arch/x86/resctrl.rst | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
Documentation/arch/x86/resctrl.rst +7 -3
@@ -345,9 +345,13 @@ 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. E.g. on a system with + SNC mode disabled with two L3 domains there will be subdirectories + "mon_L3_00" and "mon_L3_01". The numerical suffix refers to the + L3 cache id. With SNC enabled the directory names are the same, + but the numerical suffix refers to the node id. 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
Signature · 1 line
2.40.1
Tony Luck
maintainerPATCH v3 7/8 x86/resctrl: Determine if Sub-NUMA Cluster is enabled and initialize.
In reply to Tony LuckThere isn't a simple hardware enumeration to indicate to software that a system is running with Sub-NUMA Cluster enabled.
Compare the number of NUMA nodes with the number of L3 caches to calculate the number of Sub-NUMA nodes per L3 cache.
When Sub-NUMA cluster mode is enabled in BIOS setup the RMID counters are distributed equally between the SNC nodes within each socket.
E.g. if there are 400 RMID counters, and the system is configured with two SNC nodes per socket, then RMID counter 0..199 are used on SNC node 0 on the socket, and RMID counter 200..399 on SNC node 1.
A model specific MSR (0xca0) can change the configuration of the RMIDs when SNC mode is enabled.
The MSR controls the interpretation of the RMID field in the IA32_PQR_ASSOC MSR so that the appropriate hardware counters within the SNC node are updated.
Also initialize a per-cpu RMID offset value. Use this to calculate the value to write to the IA32_QM_EVTSEL MSR when reading RMID event values.
N.B. this works well for well-behaved NUMA applications that access memory predominantly from the local memory node. For applications that access memory across multiple nodes it may be necessary for the user to read counters for all SNC nodes on a socket and add the values to get the actual LLC occupancy or memory bandwidth. Perhaps this isn't all that different from applications that span across multiple sockets in a legacy system.
--- arch/x86/include/asm/resctrl.h | 2 + arch/x86/kernel/cpu/resctrl/core.c | 99 +++++++++++++++++++++++++- arch/x86/kernel/cpu/resctrl/monitor.c | 2 +- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 2 +- 4 files changed, 100 insertions(+), 5 deletions(-)
arch/x86/include/asm/resctrl.h +2 -0
@@ -35,6 +35,8 @@ DECLARE_STATIC_KEY_FALSE(rdt_enable_key);DECLARE_STATIC_KEY_FALSE (rdt_alloc_enable_key);DECLARE_STATIC_KEY_FALSE (rdt_mon_enable_key); +DECLARE_PER_CPU (int, rmid_offset); +/* * __resctrl_sched_in() - Writes the task's CLOSid/RMID to IA32_PQR_MSR *
arch/x86/kernel/cpu/resctrl/core.c +96 -3
147 lines not on this page · raw message
arch/x86/kernel/cpu/resctrl/monitor.c +1 -1
@@ -160,7 +160,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 +this_cpu_read (rmid_offset));rdmsrl (MSR_IA32_QM_CTR , msr_val);if (msr_val &RMID_VAL_ERROR )
arch/x86/kernel/cpu/resctrl/rdtgroup.c +1 -1
@@ -1354,7 +1354,7 @@ unsigned int rdtgroup_cbm_to_size(struct rdt_resource *r, } } -return size; +return size / snc_ways; }/**
Signature · 1 line
2.40.1
Reinette Chatre
maintainerRe: [PATCH v3 7/8] x86/resctrl: Determine if Sub-NUMA Cluster is enabled and initialize.
Hi Tony,
Quoted 2 lines · Tony Luck
There isn't a simple hardware enumeration to indicate to software that a system is running with Sub-NUMA Cluster enabled.
This changelog appears to _almost_ be identical to the cover letter. There is no problem with changelog and cover letter being identical but it makes things confusing when there are slight differences between the text. For example, "Sub-NUMA Cluster" vs "Sub-NUMA Clustering". With this difference between the two the reader is left wondering what behind the difference is.
Quoted 73 lines
Compare the number of NUMA nodes with the number of L3 caches to calculate the number of Sub-NUMA nodes per L3 cache.
When Sub-NUMA cluster mode is enabled in BIOS setup the RMID counters are distributed equally between the SNC nodes within each socket.
E.g. if there are 400 RMID counters, and the system is configured with two SNC nodes per socket, then RMID counter 0..199 are used on SNC node 0 on the socket, and RMID counter 200..399 on SNC node 1.
A model specific MSR (
0xca0) can change the configuration of the RMIDs when SNC mode is enabled.The MSR controls the interpretation of the RMID field in the
IA32_PQR_ASSOCMSR so that the appropriate hardware counters within the SNC node are updated.Also initialize a per-cpu RMID offset value. Use this to calculate the value to write to the
IA32_QM_EVTSELMSR when reading RMID event values.N.B. this works well for well-behaved NUMA applications that access memory predominantly from the local memory node. For applications that access memory across multiple nodes it may be necessary for the user to read counters for all SNC nodes on a socket and add the values to get the actual LLC occupancy or memory bandwidth. Perhaps this isn't all that different from applications that span across multiple sockets in a legacy system.
Signed-off-by Tony Luck <[email protected]>Reviewed-by Peter Newman <[email protected]>Tested-by Peter Newman <[email protected]>--- arch/x86/include/asm/resctrl.h | 2 + arch/x86/kernel/cpu/resctrl/core.c | 99 +++++++++++++++++++++++++- arch/x86/kernel/cpu/resctrl/monitor.c | 2 +- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 2 +- 4 files changed, 100 insertions(+), 5 deletions(-)arch/x86/include/asm/resctrl.h +2
-0@@ -35,6 +35,8 @@ DECLARE_STATIC_KEY_FALSE(rdt_enable_key);DECLARE_STATIC_KEY_FALSE (rdt_alloc_enable_key);DECLARE_STATIC_KEY_FALSE (rdt_mon_enable_key); +DECLARE_PER_CPU (int, rmid_offset); +/* * __resctrl_sched_in() - Writes the task's CLOSid/RMID to IA32_PQR_MSR * arch/x86/kernel/cpu/resctrl/core.c +3
-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"
arch/x86/kernel/cpu/resctrl/core.c static int get_domain_id(int cpu, enum resctrl_scope scope) · line 535
Quoted 9 lines
arch/x86/kernel/cpu/resctrl/core.c +6
-0@@ -524,6 +527,39 @@ static int get_domain_id(int cpu, enum resctrl_scope scope) } } +DEFINE_PER_CPU (int, rmid_offset); + +static void set_per_cpu_rmid_offset (int cpu,struct rdt_resource *r) +{ +this_cpu_write (rmid_offset, (cpu_to_node (cpu) % snc_ways) * r->num_rmid); +}
Does this mean that per-cpu data is used as a way to keep "per SNC node" data? Why is it required for this to be per-cpu data instead of, for example, the offset computed when it is needed?
arch/x86/kernel/cpu/resctrl/core.c static int get_domain_id(int cpu, enum resctrl_scope scope) · line 543
Quoted 8 lines
arch/x86/kernel/cpu/resctrl/core.c +8
-0+ +/* +* This MSR provides for configuration of RMIDs on Sub-NUMA Cluster +* systems. +* Bit0 = 1 (default) For legacy configuration +* Bit0 = 0 RMIDs are divided evenly between SNC nodes. +*/ +#define MSR_RMID_SNC_CONFIG 0xCA0
Please move to msr-index.h. For reference:97fa21f65c3e ("x86/resctrl: Move MSR defines into msr-index.h")
Quoted 39 lines
arch/x86/kernel/cpu/resctrl/core.c +22
-3+ +static void snc_add_pkg (void ) +{ +u64 msrval; + +rdmsrl (MSR_RMID_SNC_CONFIG , msrval); + msrval &= ~BIT_ULL (0 ); +wrmsrl (MSR_RMID_SNC_CONFIG , msrval); +} + +static void snc_remove_pkg (void ) +{ +u64 msrval; + +rdmsrl (MSR_RMID_SNC_CONFIG , msrval); + msrval |=BIT_ULL (0 ); +wrmsrl (MSR_RMID_SNC_CONFIG , msrval); +} +/* * domain_add_cpu - Add a cpu to a resource's domain list. * @@ -555,6 +591,8 @@ static void domain_add_cpu(int cpu, struct rdt_resource *r)cpumask_set_cpu (cpu, &d->cpu_mask);if (r->cache.arch_has_per_cpu_cfg)rdt_domain_reconfigure_cdp (r); +if (r->mon_capable) +set_per_cpu_rmid_offset (cpu, r);return ; }@@ -573,11 +611,17 @@ static void domain_add_cpu(int cpu, struct rdt_resource *r)return ; } -if (r->mon_capable &&arch_domain_mbm_alloc (r->num_rmid, hw_dom)) { -domain_free (hw_dom); -return ; +if (r->mon_capable) {
arch/x86/kernel/cpu/resctrl/core.c static void domain_add_cpu(int cpu, struct rdt_resource *r) · line 624
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/core.c +8
-0+if (arch_domain_mbm_alloc (r->num_rmid, hw_dom)) { +domain_free (hw_dom); +return ; + } +set_per_cpu_rmid_offset (cpu, r); } +if (r->pkg_actions) +snc_add_pkg (); +
This seems unnecessary use of a resctrl resource.
Quoted 20 lines
arch/x86/kernel/cpu/resctrl/core.c +6
-0list_add_tail (&d->list, add_pos); err =resctrl_online_domain (r, d);@@ -613,6 +657,9 @@ static void domain_remove_cpu(int cpu, struct rdt_resource *r) d->plr->d =NULL ;domain_free (hw_dom); +if (r->pkg_actions) +snc_remove_pkg (); +return ; }@@ -899,11 +946,57 @@ static __init bool get_rdt_resources(void)return (rdt_mon_capable || rdt_alloc_capable); } +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 ),
arch/x86/kernel/cpu/resctrl/core.c static __init bool get_rdt_resources(void) · line 961
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/core.c +10
-0+ X86_MATCH_INTEL_FAM6_MODEL(EMERALDRAPIDS_X, 0), + {} +}; + +/* +* There isn't a simple enumeration bit to show whether SNC mode +* is enabled. Look at the ratio of number of NUMA nodes to the +* number of distinct L3 caches. Take care to skip memory-only nodes. +*/ +static __init int find_snc_ways (void )
Based on the function comment and function name it is not clear what this function is intended to do. In cache "ways" have a particular meaning, what does "ways" mean in this context?
Quoted 59 lines
arch/x86/kernel/cpu/resctrl/core.c +33
-0+{ +unsigned long *node_caches; +int mem_only_nodes =0 ; +int cpu, node, ret; + +if (!x86_match_cpu (snc_cpu_ids)) +return 1 ; + + node_caches =kcalloc (BITS_TO_LONGS (nr_node_ids),sizeof (*node_caches),GFP_KERNEL ); +if (!node_caches) +return 1 ; + +cpus_read_lock (); +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 + mem_only_nodes++; + } +cpus_read_unlock (); + + ret = (nr_node_ids - mem_only_nodes) /bitmap_weight (node_caches, nr_node_ids); +kfree (node_caches); + +if (ret >1 ) + rdt_resources_all[RDT_RESOURCE_PKG ].r_resctrl.pkg_actions = true; + +return ret; +} +static __init void rdt_init_res_defs_intel (void ) {struct rdt_hw_resource *hw_res;struct rdt_resource *r; + snc_ways =find_snc_ways (); +for_each_rdt_resource (r) { hw_res =resctrl_to_arch_res (r);arch/x86/kernel/cpu/resctrl/monitor.c +1
-1@@ -160,7 +160,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 +this_cpu_read (rmid_offset));rdmsrl (MSR_IA32_QM_CTR , msr_val);if (msr_val &RMID_VAL_ERROR )arch/x86/kernel/cpu/resctrl/rdtgroup.c +0
-0
arch/x86/kernel/cpu/resctrl/rdtgroup.c unsigned int rdtgroup_cbm_to_size(struct rdt_resource *r, · line 1360
Quoted 8 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +1
-1@@ -1354,7 +1354,7 @@ unsigned int rdtgroup_cbm_to_size(struct rdt_resource *r, } } -return size; +return size / snc_ways; }/**
The last hunk does not seem to be covered in the changelog.
Reinette
Tony Luck
maintainerPATCH v3 8/8 selftests/resctrl: Adjust effective L3 cache size when SNC enabled
In reply to Tony LuckSub-NUMA Cluster divides CPUs sharing an L3 cache into separate NUMA nodes. Systems may support splitting into either two or four nodes.
When SNC mode is enabled the effective amount of L3 cache available for allocation is divided by the number of nodes per L3.
Detect which SNC mode is active by comparing the number of CPUs that share a cache with CPU0, with the number of CPUs on node0.
--- tools/testing/selftests/resctrl/resctrl.h | 1 + tools/testing/selftests/resctrl/resctrlfs.c | 57 +++++++++++++++++++++ 2 files changed, 58 insertions(+)
tools/testing/selftests/resctrl/resctrl.h +1 -0
@@ -13,6 +13,7 @@#include <signal.h> #include <dirent.h> #include <stdbool.h> +#include <ctype.h> #include <sys/stat.h> #include <sys/ioctl.h> #include <sys/mount.h>
tools/testing/selftests/resctrl/resctrlfs.c +57 -0
69 lines not on this page · raw message
Signature · 1 line
2.40.1
Hi tony,
I ran selftest/resctrl in my environment,
the test result is "not ok".
Processer in my environment:
Intel(R) Xeon(R) Gold 6254 CPU @ 3.10GHz
kernel:
$ uname -r 6.5.0-rc1+
Result :
Sub-NUMA enable:
xxx@xxx:~/linux_v6.5_rc1l$ sudo make -C tools/testing/selftests/resctrl run_tests make: Entering directory '/.../tools/testing/selftests/resctrl' TAP version 13 1..1 # timeout set to 120 # selftests: resctrl: resctrl_tests # TAP version 13 # # Pass: Check kernel supports resctrl filesystem # # Pass: Check resctrl mountpoint "/sys/fs/resctrl" exists # # resctrl filesystem not mounted # # dmesg: [ 3.060018] resctrl: L3 allocation detected # # dmesg: [ 3.098180] resctrl: MB allocation detected # # dmesg: [ 3.118507] resctrl: L3 monitoring detected # 1..4 # # Starting MBM BW change ... # # Mounting resctrl to "/sys/fs/resctrl" # # Mounting resctrl to "/sys/fs/resctrl" # # Benchmark PID: 14784 # # Writing benchmark parameters to resctrl FS # # Write schema "MB:0=100" to resctrl FS # # Checking for pass/fail # # Fail: Check MBM diff within 5% # # avg_diff_per: 100% # # Span (MB): 250 # # avg_bw_imc: 14185 # # avg_bw_resc: 28389 # not ok 1 MBM: bw change # # Intel MBM may be inaccurate when Sub-NUMA Clustering is enabled. Check BIOS configuration. # # Starting MBA Schemata change ... # # Mounting resctrl to "/sys/fs/resctrl" # # Mounting resctrl to "/sys/fs/resctrl" # # Benchmark PID: 14787 # # Writing benchmark parameters to resctrl FS # # Write schema "MB:0=100" to resctrl FS # # Write schema "MB:0=90" to resctrl FS # # Write schema "MB:0=80" to resctrl FS # # Write schema "MB:0=70" to resctrl FS # # Write schema "MB:0=60" to resctrl FS # # Write schema "MB:0=50" to resctrl FS # # Write schema "MB:0=40" to resctrl FS # # Write schema "MB:0=30" to resctrl FS # # Write schema "MB:0=20" to resctrl FS # # Write schema "MB:0=10" to resctrl FS # # Results are displayed in (MB) # # Fail: Check MBA diff within 5% for schemata 100 # # avg_diff_per: 99% # # avg_bw_imc: 14179 # # avg_bw_resc: 28340 # # Fail: Check MBA diff within 5% for schemata 90 # # avg_diff_per: 100% # # avg_bw_imc: 9244 # # avg_bw_resc: 18497 # # Fail: Check MBA diff within 5% for schemata 80 # # avg_diff_per: 100% # # avg_bw_imc: 9249 # # avg_bw_resc: 18504 # # Fail: Check MBA diff within 5% for schemata 70 # # avg_diff_per: 100% # # avg_bw_imc: 9250 # # avg_bw_resc: 18506 # # Fail: Check MBA diff within 5% for schemata 60 # # avg_diff_per: 100% # # avg_bw_imc: 7521 # # avg_bw_resc: 15055 # # Fail: Check MBA diff within 5% for schemata 50 # # avg_diff_per: 100% # # avg_bw_imc: 7455 # # avg_bw_resc: 14917 # # Fail: Check MBA diff within 5% for schemata 40 # # avg_diff_per: 100% # # avg_bw_imc: 5962 # # avg_bw_resc: 11934 # # Fail: Check MBA diff within 5% for schemata 30 # # avg_diff_per: 100% # # avg_bw_imc: 4208 # # avg_bw_resc: 8436 # # Fail: Check MBA diff within 5% for schemata 20 # # avg_diff_per: 98% # # avg_bw_imc: 2972 # # avg_bw_resc: 5909 # # Fail: Check MBA diff within 5% for schemata 10 # # avg_diff_per: 99% # # avg_bw_imc: 1715 # # avg_bw_resc: 3426 # # Fail: Check schemata change using MBA # # At least one test failed # not ok 2 MBA: schemata change # # Starting CMT test ... # # Mounting resctrl to "/sys/fs/resctrl" # # Mounting resctrl to "/sys/fs/resctrl" # # Cache size :6488064 # # Benchmark PID: 14793 # # Writing benchmark parameters to resctrl FS # # Checking for pass/fail # # Fail: Check cache miss rate within 15% # # Percent diff=91 # # Number of bits: 5 # # Average LLC val: 5640192 # # Cache span (bytes): 2949120 # not ok 3 CMT: test # # Intel CMT may be inaccurate when Sub-NUMA Clustering is enabled. Check BIOS configuration. # # Starting CAT test ... # # Mounting resctrl to "/sys/fs/resctrl" # # Mounting resctrl to "/sys/fs/resctrl" # # Cache size :6488064 # # Writing benchmark parameters to resctrl FS # # Write schema "L3:0=3f" to resctrl FS # # Checking for pass/fail # # Fail: Check cache miss rate within 4% # # Percent diff=6 # # Number of bits: 6 # # Average LLC val: 51475 # # Cache span (lines): 55296 # not ok 4 CAT: test # # Totals: pass:0 fail:4 xfail:0 xpass:0 skip:0 error:0 not ok 1 selftests: resctrl: resctrl_tests # exit=1 make: Leaving directory '/...l/tools/testing/selftests/resctrl'
Sub-NUMA disable:
xxx@xxx:~/linux_v6.5_rc1l$ sudo make -C tools/testing/selftests/resctrl run_tests ... # # Starting CAT test ... # # Mounting resctrl to "/sys/fs/resctrl" # # Mounting resctrl to "/sys/fs/resctrl" # # Cache size :6488064 # # Writing benchmark parameters to resctrl FS # # Write schema "L3:0=3f" to resctrl FS # # Checking for pass/fail # # Fail: Check cache miss rate within 4% # # Percent diff=6 # # Number of bits: 6 # # Average LLC val: 51899 # # Cache span (lines): 55296 # not ok 4 CAT: test # # Totals: pass:3 fail:1 xfail:0 xpass:0 skip:0 error:0 not ok 1 selftests: resctrl: resctrl_tests # exit=1 make: Leaving directory '/.../tools/testing/selftests/resctrl'
Best regards,
Shaopeng TAN
Tony Luck
maintainerQuoted 8 lines · Shaopeng Tan (Fujitsu)
Hi tony,
I ran selftest/resctrl in my environment,
the test result is "not ok".Processer in my environment:
Intel(R) Xeon(R) Gold 6254 CPU @ 3.10GHz
Quoted 8 lines
kernel:
$ uname -r 6.5.0-rc1+Result :
Sub-NUMA enable:xxx@xxx:~/linux_v6.5_rc1l$ sudo make -C tools/testing/selftests/resctrl run_tests make: Entering directory '/.../tools/testing/selftests/resctrl'
I see most tests pass. Just one fail on my most recent run with the v4 patch series:
# # Fail: Check MBA diff within 5% for schemata 10 # # avg_diff_per: 7%
# # avg_bw_imc: 883
# # avg_bw_resc: 815
# # Fail: Check schemata change using MBA
But just missed the 5% target by a small amount,
not the near total failures that you see.
I wonder if there is a cross-SNC node memory
allocation issue. Can you try running the test
bound to a CPU in one node:
$ taskset -c 1 sudo make -C tools/testing/selftests/resctrl run_tests
Try with different "-c" arguments to bind to different nodes. Do you see different results on differnt nodes?
-Tony
Tony Luck
maintainerv4 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 for monitoring features to be used (with the caveat that memory accesses between different SNC NUMA nodes may still not be counted accuratlely.
---
Changes since v3:
Reinette provided the most excellent suggestion that this series could better achieve its objective if it enabled separate domain lists for control & monitoring within a resource, rather than creating a whole new resource to support separte node scope needed for SNC monitoring. Thus all the pre-amble patches from the previous version have gone, replaced by patches 1-4 of this new series.
Note to anyone backporting this to some older Linux kernel version. You may be able to skip parts 2-4. These provide separate domain structures for control and monitor with just the fields needed for each. But this is largely cosmetic.
Of the code from v3 that survived to v4 the following changes have been made (also from Reinette's review of v3).
1) Rename "snc_ways" to "snc_nodes_per_l3_cache" to avoid the confusing use of "ways" which means something entirely different when talking about caches.
2) Move the #define for MSR_RMID_SNC_CONFIG to <asm/msr-index.h> along with all the other RDT MSRs.
3) Don't use a per-CPU variable "rmid_offset". Just calculate value needed at the one place where it is used.
4) Don't create an entire resource structure with package scoped domains just to set the SNC MSR.
5) Add comment in the commit message about adjusting the value shown in the "size" files in each resctrl ctrl_mon directory.
This one not from Reinette:
6) Prevent mounting in "mba_MBps" mode when SNC mode is enabled. This would just be confusing since monitoring is done at the node scope while control is still at package scope.
Tony Luck (7):
x86/resctrl: Create separate domains for control and monitoring x86/resctrl: Split the rdt_domain structures
x86/resctrl: Change monitor code to use rdt_mondomain x86/resctrl: Delete unused fields from struct rdt_domain x86/resctrl: Determine if Sub-NUMA Cluster is enabled and initialize. x86/resctrl: Update documentation with Sub-NUMA cluster changes selftests/resctrl: Adjust effective L3 cache size when SNC enabled
Documentation/arch/x86/resctrl.rst | 10 +- include/linux/resctrl.h | 50 +++- arch/x86/include/asm/msr-index.h | 1 + arch/x86/kernel/cpu/resctrl/internal.h | 40 ++- tools/testing/selftests/resctrl/resctrl.h | 1 + arch/x86/kernel/cpu/resctrl/core.c | 289 ++++++++++++++++---- arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 6 +- arch/x86/kernel/cpu/resctrl/monitor.c | 58 ++-- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 54 ++-- tools/testing/selftests/resctrl/resctrlfs.c | 57 ++++ 10 files changed, 427 insertions(+), 139 deletions(-)
base-commit: fdf0eaf11452d72945af31804e2a1048ee1b574c
Signature · 1 line
2.40.1
Tony Luck
maintainerPATCH v4 1/7 x86/resctrl: Create separate domains for control and monitoring
First step towards supporting resource control where the scope of control operations is not the same as monitor operations.
Add an extra list in the rdt_resource structure. For this will just duplicate the existing list of domains based on the L3 cache scope.
Refactor the domain_add_cpu() and domain_remove() functions to build separate lists for r->alloc_capable and r->mon_capable resources. Note that only the "L3" domain currently supports both types.
Change all places where monitoring functions walk the list of domains to use the new "mondomains" list instead of the old "domains" list.
--- include/linux/resctrl.h | 10 +- arch/x86/kernel/cpu/resctrl/internal.h | 2 +- arch/x86/kernel/cpu/resctrl/core.c | 195 +++++++++++++++------- arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 2 +- arch/x86/kernel/cpu/resctrl/monitor.c | 2 +- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 30 ++-- 6 files changed, 167 insertions(+), 74 deletions(-)
include/linux/resctrl.h +8 -2
@@ -151,9 +151,11 @@ struct resctrl_schema;* @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 +* @mon_scope: Scope of this resource if different from cache_level * @cache: Cache allocation related data * @membw: If the component has bandwidth controls, their properties. * @domains: All domains for this resource +* @mondomains: 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.
@@ -169,9 +171,11 @@ struct rdt_resource {bool mon_capable;int num_rmid;int cache_level; +int mon_scope;struct resctrl_cache cache;struct resctrl_membw membw;struct list_head domains; +struct list_head mondomains;char *name;int data_width;u32 default_ctrl;
@@ -217,8 +221,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 +1 -1
@@ -511,7 +511,7 @@ 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 rdt_domain *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);
arch/x86/kernel/cpu/resctrl/core.c +138 -57
280 lines not on this page · raw message
arch/x86/kernel/cpu/resctrl/ctrlmondata.c +1 -1
@@ -560,7 +560,7 @@ 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 ); + d =rdt_find_domain (&r->mondomains, domid,NULL );if (IS_ERR_OR_NULL (d)) { ret = -ENOENT ; goto out;
arch/x86/kernel/cpu/resctrl/monitor.c +1 -1
@@ -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, list) { +list_for_each_entry (d, &r->mondomains, list) {if (cpumask_test_cpu (cpu, &d->cpu_mask)) { err = resctrl_arch_rmid_read(r, d, entry->rmid, QOS_L3_OCCUP_EVENT_ID,
arch/x86/kernel/cpu/resctrl/rdtgroup.c +18 -12
@@ -1496,7 +1496,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->mondomains, list) {if (sep)seq_puts (s,";" );
@@ -1619,7 +1619,7 @@ static int mon_config_write(struct rdt_resource *r, char *tok, u32 evtid)return -EINVAL ; } -list_for_each_entry (d, &r->domains, list) { +list_for_each_entry (d, &r->mondomains, list) {if (d->id == dom_id) { ret =mbm_config_write_domain (r, d, evtid, val);if (ret)
@@ -2525,7 +2525,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->mondomains, list)mbm_setup_overflow_handler (dom,MBM_OVERFLOW_INTERVAL ); }
@@ -2919,7 +2919,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->mondomains, list) { ret =mkdir_mondata_subdir (parent_kn, dom, r, prgrp);if (ret)return ret;
@@ -3708,15 +3708,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
@@ -3773,18 +3775,22 @@ 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)
Signature · 1 line
2.40.1
Reinette Chatre
maintainerRe: [PATCH v4 1/7] x86/resctrl: Create separate domains for control and monitoring
Hi Tony,
Quoted 2 lines · Tony Luck
First step towards supporting resource control where the scope of control operations is not the same as monitor operations.
Each changelog should stand on its own merit. This changelog appears to be written as a continuation of the cover letter.
Please do ensure that each patch first establishes the context before it describes the problem and solution. For example, as a context this changelog can start by describing what the resctrl domains list represents.
Quoted 4 lines
Add an extra list in the
rdt_resourcestructure. For this will just duplicate the existing list of domains based on the L3 cache scope.
The above paragraph does not make this change appealing at all.
Quoted 1 line
Refactor the
domain_add_cpu()anddomain_remove()functions to
domain_remove() -> domain_remove_cpu()
Quoted 3 lines
build separate lists for
r->alloc_capableandr->mon_capableresources. Note that only the "L3" domain currently supports both types.
"L3" domain -> "L3" resource?
Quoted 4 lines
Change all places where monitoring functions walk the list of domains to use the new "mondomains" list instead of the old "domains" list.
I would not refer to it as "the old domains list" as it creates impression that this is being replaced. The changelog makes no mention that domains list will remain and be dedicated to control domains. I think this is important to include in description of this change.
Quoted 16 lines
Signed-off-by Tony Luck <[email protected]>--- include/linux/resctrl.h | 10 +- arch/x86/kernel/cpu/resctrl/internal.h | 2 +- arch/x86/kernel/cpu/resctrl/core.c | 195 +++++++++++++++------- arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 2 +- arch/x86/kernel/cpu/resctrl/monitor.c | 2 +- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 30 ++-- 6 files changed, 167 insertions(+), 74 deletions(-)include/linux/resctrl.h +0
-0
include/linux/resctrl.h struct resctrl_schema; · line 154
Quoted 4 lines
include/linux/resctrl.h +1
-0@@ -151,9 +151,11 @@ struct resctrl_schema;* @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 +* @mon_scope: Scope of this resource if different from cache_level
I think this addition should be deferred. As it is here it the "if different from cache_level" also creates many questions (when will it be different? how will it be determined that the scope is different in order to know that mon_scope should be used?)
Looking ahead on how mon_scope is used there does not seem to be an "if" involved at all ... mon_scope is always the monitoring scope.
include/linux/resctrl.h struct resctrl_schema; · line 157
Quoted 3 lines
include/linux/resctrl.h +0
-0* @cache: Cache allocation related data * @membw: If the component has bandwidth controls, their properties. * @domains: All domains for this resource
A change to the domains comment would also help - to highlight that it is now dedicated to control domains.
Quoted 16 lines
include/linux/resctrl.h +3
-0+* @mondomains: 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. @@ -169,9 +171,11 @@ struct rdt_resource {bool mon_capable;int num_rmid;int cache_level; +int mon_scope;struct resctrl_cache cache;struct resctrl_membw membw;struct list_head domains; +struct list_head mondomains;char *name;int data_width;u32 default_ctrl;
...
include/linux/resctrl.h void rdt_ctrl_update(void *arg) · line 391
Quoted 8 lines
include/linux/resctrl.h +2
-1@@ -384,14 +386,15 @@ void rdt_ctrl_update(void *arg) }/* -* rdt_find_domain - Find a domain in a resource that matches input resource id +* rdt_find_domain - Find a domain in one of the lists for a resource that +* matches input resource id *
This change makes the function more vague. I think original summary is still accurate, how the list is used can be describe in the details below. I see more changes to this function is upcoming and I will comment more at those sites.
Quoted 61 lines
include/linux/resctrl.h +40
-2* 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. */ -struct rdt_domain *rdt_find_domain (struct rdt_resource *r,int id, +struct rdt_domain *rdt_find_domain (struct list_head *h,int id,struct list_head **pos) {struct rdt_domain *d;@@ -400,7 +403,7 @@ struct rdt_domain *rdt_find_domain(struct rdt_resource *r, int id,if (id <0 )return ERR_PTR (-ENODEV ); -list_for_each (l, &r->domains) { +list_for_each (l, h) { d = list_entry(l, struct rdt_domain, list);/* When id is found, return its domain. */ if (id == d->id)@@ -487,6 +490,94 @@ static int arch_domain_mbm_alloc(u32 num_rmid, struct rdt_hw_domain *hw_dom)return 0 ; } +static void domain_add_cpu_ctrl (int cpu,struct rdt_resource *r) +{ +int id =get_cpu_cacheinfo_id (cpu, r->cache_level); +struct list_head *add_pos =NULL ; +struct rdt_hw_domain *hw_dom; +struct rdt_domain *d; +int err; + + d =rdt_find_domain (&r->domains, id, &add_pos); +if (IS_ERR (d)) { +pr_warn ("Couldn't find cache id for CPU %d\n" , cpu); +return ; + } + +if (d) { +cpumask_set_cpu (cpu, &d->cpu_mask); +if (r->cache.arch_has_per_cpu_cfg) +rdt_domain_reconfigure_cdp (r); +return ; + } + + hw_dom =kzalloc_node (sizeof (*hw_dom),GFP_KERNEL ,cpu_to_node (cpu)); +if (!hw_dom) +return ; + + d = &hw_dom->d_resctrl; + d->id = id; +cpumask_set_cpu (cpu, &d->cpu_mask); + +rdt_domain_reconfigure_cdp (r); + +if (domain_setup_ctrlval (r, d)) { +domain_free (hw_dom); +return ; + } + +list_add_tail (&d->list, add_pos); +
include/linux/resctrl.h static int arch_domain_mbm_alloc(u32 num_rmid, struct rdt_hw_domain *hw_dom) · line 540
Quoted 10 lines
include/linux/resctrl.h +10
-0+ err =resctrl_online_ctrl_domain (r, d); +if (err) { +list_del (&d->list); +domain_free (hw_dom); + } +} + +static void domain_add_cpu_mon (int cpu,struct rdt_resource *r) +{ +int id =get_cpu_cacheinfo_id (cpu, r->mon_scope);
Using a different scope variable but continuing to treat it as a cache level creates unnecessary confusion at this point.
include/linux/resctrl.h static int arch_domain_mbm_alloc(u32 num_rmid, struct rdt_hw_domain *hw_dom) · line 548
Quoted 8 lines
include/linux/resctrl.h +8
-0+struct list_head *add_pos =NULL ; +struct rdt_hw_domain *hw_dom; +struct rdt_domain *d; +int err; + + d =rdt_find_domain (&r->mondomains, id, &add_pos); +if (IS_ERR (d)) { +pr_warn ("Couldn't find cache id for CPU %d\n" , cpu);
Note for future change ... this continues to refer to monitor scope as a cache id. I did not see this changed in the later patch that actually changes how scope is used.
include/linux/resctrl.h static int arch_domain_mbm_alloc(u32 num_rmid, struct rdt_hw_domain *hw_dom) · line 555
Quoted 7 lines
include/linux/resctrl.h +7
-0+return ; + } + +if (d) { +cpumask_set_cpu (cpu, &d->cpu_mask); +if (r->cache.arch_has_per_cpu_cfg) +rdt_domain_reconfigure_cdp (r);
Copy & paste error?
Quoted 73 lines
include/linux/resctrl.h +25
-41+return ; + } + + hw_dom =kzalloc_node (sizeof (*hw_dom),GFP_KERNEL ,cpu_to_node (cpu)); +if (!hw_dom) +return ; + + d = &hw_dom->d_resctrl; + d->id = id; +cpumask_set_cpu (cpu, &d->cpu_mask); + +if (arch_domain_mbm_alloc (r->num_rmid, hw_dom)) { +domain_free (hw_dom); +return ; + } + +list_add_tail (&d->list, add_pos); + + err =resctrl_online_mon_domain (r, d); +if (err) { +list_del (&d->list); +domain_free (hw_dom); + } +} +/* * domain_add_cpu - Add a cpu to a resource's domain list. * @@ -502,61 +593,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); -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); -return ; - } - -if (d) { -cpumask_set_cpu (cpu, &d->cpu_mask); -if (r->cache.arch_has_per_cpu_cfg) -rdt_domain_reconfigure_cdp (r); -return ; - } - - hw_dom =kzalloc_node (sizeof (*hw_dom),GFP_KERNEL ,cpu_to_node (cpu)); -if (!hw_dom) -return ; - - d = &hw_dom->d_resctrl; - d->id = id; -cpumask_set_cpu (cpu, &d->cpu_mask); - -rdt_domain_reconfigure_cdp (r); - -if (r->alloc_capable &&domain_setup_ctrlval (r, d)) { -domain_free (hw_dom); -return ; - } - -if (r->mon_capable &&arch_domain_mbm_alloc (r->num_rmid, hw_dom)) { -domain_free (hw_dom); -return ; - } - -list_add_tail (&d->list, add_pos); -
include/linux/resctrl.h static int arch_domain_mbm_alloc(u32 num_rmid, struct rdt_hw_domain *hw_dom) · line 600
Quoted 10 lines
include/linux/resctrl.h +4
-5- err =resctrl_online_domain (r, d); -if (err) { -list_del (&d->list); -domain_free (hw_dom); - } +if (r->alloc_capable) +domain_add_cpu_ctrl (cpu, r); +if (r->mon_capable) +domain_add_cpu_mon (cpu, r); }
A resource could be both alloc and mon capable ... both domain_add_cpu_ctrl() and domain_add_cpu_mon() can fail. Should domain_add_cpu_mon() still be run for a CPU if domain_add_cpu_ctrl() failed?
Looking ahead the CPU should probably also not be added to the default groups mask if a failure occurred.
Quoted 22 lines
include/linux/resctrl.h +3
-3-static void domain_remove_cpu (int cpu,struct rdt_resource *r) +static void domain_remove_cpu_ctrl (int cpu,struct rdt_resource *r) {int id =get_cpu_cacheinfo_id (cpu, r->cache_level);struct rdt_hw_domain *hw_dom;struct rdt_domain *d; - d =rdt_find_domain (r, id,NULL ); + d =rdt_find_domain (&r->domains, id,NULL );if (IS_ERR_OR_NULL (d)) {pr_warn ("Couldn't find cache id for CPU %d\n" , cpu);return ;@@ -565,7 +614,7 @@ static void domain_remove_cpu(int cpu, struct rdt_resource *r)cpumask_clear_cpu (cpu, &d->cpu_mask);if (cpumask_empty (&d->cpu_mask)) { -resctrl_offline_domain (r, d); +resctrl_offline_ctrl_domain (r, d);list_del (&d->list);/*
include/linux/resctrl.h static void domain_remove_cpu(int cpu, struct rdt_resource *r) · line 634
Quoted 8 lines
include/linux/resctrl.h +5
-0@@ -578,6 +627,30 @@ 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_cpu_cacheinfo_id (cpu, r->cache_level);
Introducing mon_scope can really be deferred ... here the monitoring code is not using mon_scope anyway.
Quoted 12 lines
include/linux/resctrl.h +12
-0+struct rdt_hw_domain *hw_dom; +struct rdt_domain *d; + + d =rdt_find_domain (&r->mondomains, id,NULL ); +if (IS_ERR_OR_NULL (d)) { +pr_warn ("Couldn't find cache id for CPU %d\n" , cpu); +return ; + } + hw_dom =resctrl_to_arch_dom (d); + +cpumask_clear_cpu (cpu, &d->cpu_mask); +if (cpumask_empty (&d->cpu_mask)) {
include/linux/resctrl.h static void domain_remove_cpu(int cpu, struct rdt_resource *r) · line 656
Quoted 10 lines
include/linux/resctrl.h +7
-0+resctrl_offline_mon_domain (r, d); +list_del (&d->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) {
Reinette
Tony Luck
maintainerRe: [PATCH v4 1/7] x86/resctrl: Create separate domains for control and monitoring
Quoted 36 lines · Reinette Chatre
Hi Tony,
Quoted 2 lines · Tony Luck
First step towards supporting resource control where the scope of control operations is not the same as monitor operations.
Each changelog should stand on its own merit. This changelog appears to be written as a continuation of the cover letter.
Please do ensure that each patch first establishes the context before it describes the problem and solution. For example, as a context this changelog can start by describing what the resctrl domains list represents.
Quoted 4 lines
Add an extra list in the
rdt_resourcestructure. For this will just duplicate the existing list of domains based on the L3 cache scope.The above paragraph does not make this change appealing at all.
Quoted 1 line
Refactor the
domain_add_cpu()anddomain_remove()functions to
domain_remove()->domain_remove_cpu()Quoted 3 lines
build separate lists for
r->alloc_capableandr->mon_capableresources. Note that only the "L3" domain currently supports both types."L3" domain -> "L3" resource?
Quoted 4 lines
Change all places where monitoring functions walk the list of domains to use the new "mondomains" list instead of the old "domains" list.
Quoted 5 lines
I would not refer to it as "the old domains list" as it creates impression that this is being replaced. The changelog makes no mention that domains list will remain and be dedicated to control domains. I think this is important to include in description of this change.
I've rewritten the entire commit message incorporating your suggestions. V6 will be posted soon (after I get some time on an SNC SPR to check that it all works!)
Quoted 12 lines
Quoted 12 lines
Signed-off-by Tony Luck <[email protected]>--- include/linux/resctrl.h | 10 +- arch/x86/kernel/cpu/resctrl/internal.h | 2 +- arch/x86/kernel/cpu/resctrl/core.c | 195 +++++++++++++++------- arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 2 +- arch/x86/kernel/cpu/resctrl/monitor.c | 2 +- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 30 ++-- 6 files changed, 167 insertions(+), 74 deletions(-)
Quoted 14 lines
include/linux/resctrl.h struct resctrl_schema; · line 154
Quoted 9 lines
include/linux/resctrl.h +1
-0@@ -151,9 +151,11 @@ struct resctrl_schema;* @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 +* @mon_scope: Scope of this resource if different from cache_level I think this addition should be deferred. As it is here it the "if different from
cache_level" also creates many questions (when will it be different? how will it be determined that the scope is different in order to know thatmon_scopeshould be used?)
I've gone in a different direction. V6 renames "cache_level" to "ctrl_scope". I think this makes intent clear from step #1.
Quoted 3 lines
Looking ahead on how
mon_scopeis used there does not seem to be an "if" involved at all ...mon_scopeis always the monitoring scope.
Dropped the "if different" comment. You are correct that this is unconditionally the monitor scope.
Quoted 7 lines
include/linux/resctrl.h struct resctrl_schema; · line 157
Quoted 4 lines
include/linux/resctrl.h +0
-0* @cache: Cache allocation related data * @membw: If the component has bandwidth controls, their properties. * @domains: All domains for this resource A change to the domains comment would also help - to highlight that it is now dedicated to control domains.
Done.
Quoted 23 lines
Quoted 17 lines
include/linux/resctrl.h +3
-0+* @mondomains: 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. @@ -169,9 +171,11 @@ struct rdt_resource {bool mon_capable;int num_rmid;int cache_level; +int mon_scope;struct resctrl_cache cache;struct resctrl_membw membw;struct list_head domains; +struct list_head mondomains;char *name;int data_width;u32 default_ctrl;...
Quoted 3 lines
include/linux/resctrl.h +0
-0@@ -384,14 +386,15 @@ void rdt_ctrl_update(void *arg) }
Quoted 10 lines
include/linux/resctrl.h void rdt_ctrl_update(void *arg) · line 391
Quoted 5 lines
include/linux/resctrl.h +2
-1/* -* rdt_find_domain - Find a domain in a resource that matches input resource id +* rdt_find_domain - Find a domain in one of the lists for a resource that +* matches input resource id * This change makes the function more vague. I think original summary is still accurate, how the list is used can be describe in the details below. I see more changes to this function is upcoming and I will comment more at those sites.
Re-worked this based on your other suggestions to have separate find* functions for ctrl and mon cases calling to common __rdt_find_domain().
Quoted 76 lines
Quoted 62 lines
include/linux/resctrl.h +40
-2* 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. */ -struct rdt_domain *rdt_find_domain (struct rdt_resource *r,int id, +struct rdt_domain *rdt_find_domain (struct list_head *h,int id,struct list_head **pos) {struct rdt_domain *d;@@ -400,7 +403,7 @@ struct rdt_domain *rdt_find_domain(struct rdt_resource *r, int id,if (id <0 )return ERR_PTR (-ENODEV ); -list_for_each (l, &r->domains) { +list_for_each (l, h) { d = list_entry(l, struct rdt_domain, list);/* When id is found, return its domain. */ if (id == d->id)@@ -487,6 +490,94 @@ static int arch_domain_mbm_alloc(u32 num_rmid, struct rdt_hw_domain *hw_dom)return 0 ; } +static void domain_add_cpu_ctrl (int cpu,struct rdt_resource *r) +{ +int id =get_cpu_cacheinfo_id (cpu, r->cache_level); +struct list_head *add_pos =NULL ; +struct rdt_hw_domain *hw_dom; +struct rdt_domain *d; +int err; + + d =rdt_find_domain (&r->domains, id, &add_pos); +if (IS_ERR (d)) { +pr_warn ("Couldn't find cache id for CPU %d\n" , cpu); +return ; + } + +if (d) { +cpumask_set_cpu (cpu, &d->cpu_mask); +if (r->cache.arch_has_per_cpu_cfg) +rdt_domain_reconfigure_cdp (r); +return ; + } + + hw_dom =kzalloc_node (sizeof (*hw_dom),GFP_KERNEL ,cpu_to_node (cpu)); +if (!hw_dom) +return ; + + d = &hw_dom->d_resctrl; + d->id = id; +cpumask_set_cpu (cpu, &d->cpu_mask); + +rdt_domain_reconfigure_cdp (r); + +if (domain_setup_ctrlval (r, d)) { +domain_free (hw_dom); +return ; + } + +list_add_tail (&d->list, add_pos); +include/linux/resctrl.h static int arch_domain_mbm_alloc(u32 num_rmid, struct rdt_hw_domain *hw_dom) · line 540
Quoted 10 lines
include/linux/resctrl.h +10
-0+ err =resctrl_online_ctrl_domain (r, d); +if (err) { +list_del (&d->list); +domain_free (hw_dom); + } +} + +static void domain_add_cpu_mon (int cpu,struct rdt_resource *r) +{ +int id =get_cpu_cacheinfo_id (cpu, r->mon_scope);Using a different scope variable but continuing to treat it as a cache level creates unnecessary confusion at this point.
Quoted 12 lines
include/linux/resctrl.h static int arch_domain_mbm_alloc(u32 num_rmid, struct rdt_hw_domain *hw_dom) · line 548
Quoted 8 lines
include/linux/resctrl.h +8
-0+struct list_head *add_pos =NULL ; +struct rdt_hw_domain *hw_dom; +struct rdt_domain *d; +int err; + + d =rdt_find_domain (&r->mondomains, id, &add_pos); +if (IS_ERR (d)) { +pr_warn ("Couldn't find cache id for CPU %d\n" , cpu);Note for future change ... this continues to refer to monitor scope as a cache id. I did not see this changed in the later patch that actually changes how scope is used.
Changed all these messages to refer to scope instead of cache id.
Quoted 10 lines
include/linux/resctrl.h static int arch_domain_mbm_alloc(u32 num_rmid, struct rdt_hw_domain *hw_dom) · line 555
Quoted 8 lines
include/linux/resctrl.h +7
-0+return ; + } + +if (d) { +cpumask_set_cpu (cpu, &d->cpu_mask); +if (r->cache.arch_has_per_cpu_cfg) +rdt_domain_reconfigure_cdp (r);Copy & paste error?
Indeed yes. This code isn't appropriate for the monitor case. Deleted.
Quoted 90 lines
Quoted 74 lines
include/linux/resctrl.h +25
-41+return ; + } + + hw_dom =kzalloc_node (sizeof (*hw_dom),GFP_KERNEL ,cpu_to_node (cpu)); +if (!hw_dom) +return ; + + d = &hw_dom->d_resctrl; + d->id = id; +cpumask_set_cpu (cpu, &d->cpu_mask); + +if (arch_domain_mbm_alloc (r->num_rmid, hw_dom)) { +domain_free (hw_dom); +return ; + } + +list_add_tail (&d->list, add_pos); + + err =resctrl_online_mon_domain (r, d); +if (err) { +list_del (&d->list); +domain_free (hw_dom); + } +} +/* * domain_add_cpu - Add a cpu to a resource's domain list. * @@ -502,61 +593,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); -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); -return ; - } - -if (d) { -cpumask_set_cpu (cpu, &d->cpu_mask); -if (r->cache.arch_has_per_cpu_cfg) -rdt_domain_reconfigure_cdp (r); -return ; - } - - hw_dom =kzalloc_node (sizeof (*hw_dom),GFP_KERNEL ,cpu_to_node (cpu)); -if (!hw_dom) -return ; - - d = &hw_dom->d_resctrl; - d->id = id; -cpumask_set_cpu (cpu, &d->cpu_mask); - -rdt_domain_reconfigure_cdp (r); - -if (r->alloc_capable &&domain_setup_ctrlval (r, d)) { -domain_free (hw_dom); -return ; - } - -if (r->mon_capable &&arch_domain_mbm_alloc (r->num_rmid, hw_dom)) { -domain_free (hw_dom); -return ; - } - -list_add_tail (&d->list, add_pos); -include/linux/resctrl.h static int arch_domain_mbm_alloc(u32 num_rmid, struct rdt_hw_domain *hw_dom) · line 600
Quoted 10 lines
include/linux/resctrl.h +4
-5- err =resctrl_online_domain (r, d); -if (err) { -list_del (&d->list); -domain_free (hw_dom); - } +if (r->alloc_capable) +domain_add_cpu_ctrl (cpu, r); +if (r->mon_capable) +domain_add_cpu_mon (cpu, r); }A resource could be both alloc and mon capable ... both
domain_add_cpu_ctrl()anddomain_add_cpu_mon()can fail. Shoulddomain_add_cpu_mon()still be run for a CPU ifdomain_add_cpu_ctrl()failed?
Quoted 2 lines
Looking ahead the CPU should probably also not be added to the default groups mask if a failure occurred.
Existing code doesn't do anything for the case where a CPU can't be added to a domain (probably the only real error case is failure to allocate memory for the domain structure).
May be something to tackle in a future series if anyone thinks this is a serious problem and has suggestions on what to do. It seems like a catastrophic problem to not have some CPUs in some/all domains of some resources. Maybe this should disable mounting resctrl filesystem completely?
Quoted 24 lines
Quoted 24 lines
include/linux/resctrl.h +3
-3-static void domain_remove_cpu (int cpu,struct rdt_resource *r) +static void domain_remove_cpu_ctrl (int cpu,struct rdt_resource *r) {int id =get_cpu_cacheinfo_id (cpu, r->cache_level);struct rdt_hw_domain *hw_dom;struct rdt_domain *d; - d =rdt_find_domain (r, id,NULL ); + d =rdt_find_domain (&r->domains, id,NULL );if (IS_ERR_OR_NULL (d)) {pr_warn ("Couldn't find cache id for CPU %d\n" , cpu);return ;@@ -565,7 +614,7 @@ static void domain_remove_cpu(int cpu, struct rdt_resource *r)cpumask_clear_cpu (cpu, &d->cpu_mask);if (cpumask_empty (&d->cpu_mask)) { -resctrl_offline_domain (r, d); +resctrl_offline_ctrl_domain (r, d);list_del (&d->list);/* @@ -578,6 +627,30 @@ static void domain_remove_cpu(int cpu, struct rdt_resource *r)
Quoted 10 lines
include/linux/resctrl.h static void domain_remove_cpu(int cpu, struct rdt_resource *r) · line 634
Quoted 7 lines
include/linux/resctrl.h +5
-0return ; } +} + +static void domain_remove_cpu_mon (int cpu,struct rdt_resource *r) +{ +int id =get_cpu_cacheinfo_id (cpu, r->cache_level);Introducing
mon_scopecan really be deferred ... here the monitoring code is not usingmon_scopeanyway.
Not deferring. But I did fix this to use r->mon_scope. Good catch.
Quoted 21 lines
Quoted 21 lines
include/linux/resctrl.h +19
-0+struct rdt_hw_domain *hw_dom; +struct rdt_domain *d; + + d =rdt_find_domain (&r->mondomains, id,NULL ); +if (IS_ERR_OR_NULL (d)) { +pr_warn ("Couldn't find cache id for CPU %d\n" , cpu); +return ; + } + hw_dom =resctrl_to_arch_dom (d); + +cpumask_clear_cpu (cpu, &d->cpu_mask); +if (cpumask_empty (&d->cpu_mask)) { +resctrl_offline_mon_domain (r, d); +list_del (&d->list); + +domain_free (hw_dom); + +return ; + }
Quoted 4 lines
include/linux/resctrl.h static void domain_remove_cpu(int cpu, struct rdt_resource *r) · line 656
Quoted 2 lines
include/linux/resctrl.h +0
-0if (r == &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl) {if (is_mbm_enabled () && cpu == d->mbm_work_cpu) {Reinette
-Tony
Reinette Chatre
maintainerRe: [PATCH v4 1/7] x86/resctrl: Create separate domains for control and monitoring
Hi Tony,
Quoted 13 lines · Tony Luck
Quoted 11 lines · Reinette Chatre
Quoted 3 lines · Tony Luck
Change all places where monitoring functions walk the list of domains to use the new "mondomains" list instead of the old "domains" list.
I would not refer to it as "the old domains list" as it creates impression that this is being replaced. The changelog makes no mention that domains list will remain and be dedicated to control domains. I think this is important to include in description of this change.
Quoted 3 lines
I've rewritten the entire commit message incorporating your suggestions. V6 will be posted soon (after I get some time on an SNC SPR to check that it all works!)
I seem to have missed v5.
Quoted 28 lines
Quoted 13 lines
Quoted 13 lines
Signed-off-by Tony Luck <[email protected]>--- include/linux/resctrl.h | 10 +- arch/x86/kernel/cpu/resctrl/internal.h | 2 +- arch/x86/kernel/cpu/resctrl/core.c | 195 +++++++++++++++------- arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 2 +- arch/x86/kernel/cpu/resctrl/monitor.c | 2 +- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 30 ++-- 6 files changed, 167 insertions(+), 74 deletions(-)Quoted 14 lines
include/linux/resctrl.h struct resctrl_schema; · line 154
Quoted 9 lines
include/linux/resctrl.h +1
-0@@ -151,9 +151,11 @@ struct resctrl_schema;* @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 +* @mon_scope: Scope of this resource if different from cache_level I think this addition should be deferred. As it is here it the "if different from
cache_level" also creates many questions (when will it be different? how will it be determined that the scope is different in order to know thatmon_scopeshould be used?)
Quoted 3 lines
I've gone in a different direction. V6 renames "
cache_level" to "ctrl_scope". I think this makes intent clear from step #1.
This change is not clear to me. Previously you changed this name but kept using it in code specific to cache levels. It is not clear to me how this time's rename would be different.
...
Quoted 61 lines
Quoted 61 lines
Quoted 45 lines
include/linux/resctrl.h +0
-41@@ -502,61 +593,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); -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); -return ; - } - -if (d) { -cpumask_set_cpu (cpu, &d->cpu_mask); -if (r->cache.arch_has_per_cpu_cfg) -rdt_domain_reconfigure_cdp (r); -return ; - } - - hw_dom =kzalloc_node (sizeof (*hw_dom),GFP_KERNEL ,cpu_to_node (cpu)); -if (!hw_dom) -return ; - - d = &hw_dom->d_resctrl; - d->id = id; -cpumask_set_cpu (cpu, &d->cpu_mask); - -rdt_domain_reconfigure_cdp (r); - -if (r->alloc_capable &&domain_setup_ctrlval (r, d)) { -domain_free (hw_dom); -return ; - } - -if (r->mon_capable &&arch_domain_mbm_alloc (r->num_rmid, hw_dom)) { -domain_free (hw_dom); -return ; - } - -list_add_tail (&d->list, add_pos); -include/linux/resctrl.h static int arch_domain_mbm_alloc(u32 num_rmid, struct rdt_hw_domain *hw_dom) · line 600
Quoted 10 lines
include/linux/resctrl.h +4
-5- err =resctrl_online_domain (r, d); -if (err) { -list_del (&d->list); -domain_free (hw_dom); - } +if (r->alloc_capable) +domain_add_cpu_ctrl (cpu, r); +if (r->mon_capable) +domain_add_cpu_mon (cpu, r); }A resource could be both alloc and mon capable ... both
domain_add_cpu_ctrl()anddomain_add_cpu_mon()can fail. Shoulddomain_add_cpu_mon()still be run for a CPU ifdomain_add_cpu_ctrl()failed?
Quoted 6 lines
Quoted 2 lines
Looking ahead the CPU should probably also not be added to the default groups mask if a failure occurred.
Existing code doesn't do anything for the case where a CPU can't be added to a domain (probably the only real error case is failure to allocate memory for the domain structure).
Is my statement about CPU being added to default group mask incorrect? Seems like a potential issue related to domain's CPU mask also.
Please see my earlier question. Existing code does not proceed with monitor initialization if control initialization fails and undoes control initialization if monitor initialization fails.
Quoted 6 lines
May be something to tackle in a future series if anyone thinks this is a serious problem and has suggestions on what to do. It seems like a catastrophic problem to not have some CPUs in some/all domains of some resources. Maybe this should disable mounting resctrl filesystem completely?
It is not clear to me how this is catastrophic but I do not think resctrl should claim support for a resource on a CPU if it was not able to complete initialization
Reinette
Tony Luck
maintainerRe: [PATCH v4 1/7] x86/resctrl: Create separate domains for control and monitoring
Quoted 16 lines · Reinette Chatre
Hi Tony,
Quoted 13 lines · Tony Luck
Quoted 11 lines · Reinette Chatre
Quoted 3 lines · Tony Luck
Change all places where monitoring functions walk the list of domains to use the new "mondomains" list instead of the old "domains" list.
I would not refer to it as "the old domains list" as it creates impression that this is being replaced. The changelog makes no mention that domains list will remain and be dedicated to control domains. I think this is important to include in description of this change.
Quoted 5 lines
Quoted 3 lines
I've rewritten the entire commit message incorporating your suggestions. V6 will be posted soon (after I get some time on an SNC SPR to check that it all works!)
I seem to have missed v5.
I simply can't count. You are correct that next version to be posted will be v5.
Quoted 28 lines
Quoted 28 lines
Quoted 27 lines
Quoted 18 lines
Signed-off-by Tony Luck <[email protected]>--- include/linux/resctrl.h | 10 +- arch/x86/kernel/cpu/resctrl/internal.h | 2 +- arch/x86/kernel/cpu/resctrl/core.c | 195 +++++++++++++++------- arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 2 +- arch/x86/kernel/cpu/resctrl/monitor.c | 2 +- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 30 ++-- 6 files changed, 167 insertions(+), 74 deletions(-)include/linux/resctrl.h +0
-0include/linux/resctrl.h struct resctrl_schema; · line 154
Quoted 4 lines
include/linux/resctrl.h +1
-0@@ -151,9 +151,11 @@ struct resctrl_schema;* @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 +* @mon_scope: Scope of this resource if different from cache_level I think this addition should be deferred. As it is here it the "if different from
cache_level" also creates many questions (when will it be different? how will it be determined that the scope is different in order to know thatmon_scopeshould be used?)
Quoted 7 lines
Quoted 3 lines
I've gone in a different direction. V6 renames "
cache_level" to "ctrl_scope". I think this makes intent clear from step #1.This change is not clear to me. Previously you changed this name but kept using it in code specific to cache levels. It is not clear to me how this time's rename would be different.
The current "cache_level" field in the structure is describing the scope of each instance using the cache level (2 or 3) as the method to describe which CPUs are considered part of a group. Currently the scope is the same for both control and monitor resources.
Would you like to see patches in this progrssion:
1) Rename "cache_level" to "scope". With commit comment that future patches are going to base the scope on NUMA nodes in addtion to sharing caches at particular levels, and will split into separate control and monitor scope.
2) Split the "scope" field from first patch into "ctrl_scope" and "mon_scope" (also with the addition of the new list for the mon_scope).
3) Add "node" as a new option for scope in addtion to L3 and L2 cache.
Quoted 70 lines
...
Quoted 61 lines
Quoted 61 lines
Quoted 45 lines
include/linux/resctrl.h +0
-41@@ -502,61 +593,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); -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); -return ; - } - -if (d) { -cpumask_set_cpu (cpu, &d->cpu_mask); -if (r->cache.arch_has_per_cpu_cfg) -rdt_domain_reconfigure_cdp (r); -return ; - } - - hw_dom =kzalloc_node (sizeof (*hw_dom),GFP_KERNEL ,cpu_to_node (cpu)); -if (!hw_dom) -return ; - - d = &hw_dom->d_resctrl; - d->id = id; -cpumask_set_cpu (cpu, &d->cpu_mask); - -rdt_domain_reconfigure_cdp (r); - -if (r->alloc_capable &&domain_setup_ctrlval (r, d)) { -domain_free (hw_dom); -return ; - } - -if (r->mon_capable &&arch_domain_mbm_alloc (r->num_rmid, hw_dom)) { -domain_free (hw_dom); -return ; - } - -list_add_tail (&d->list, add_pos); -include/linux/resctrl.h static int arch_domain_mbm_alloc(u32 num_rmid, struct rdt_hw_domain *hw_dom) · line 600
Quoted 10 lines
include/linux/resctrl.h +4
-5- err =resctrl_online_domain (r, d); -if (err) { -list_del (&d->list); -domain_free (hw_dom); - } +if (r->alloc_capable) +domain_add_cpu_ctrl (cpu, r); +if (r->mon_capable) +domain_add_cpu_mon (cpu, r); }A resource could be both alloc and mon capable ... both
domain_add_cpu_ctrl()anddomain_add_cpu_mon()can fail. Shoulddomain_add_cpu_mon()still be run for a CPU ifdomain_add_cpu_ctrl()failed?Quoted 6 lines
Quoted 2 lines
Looking ahead the CPU should probably also not be added to the default groups mask if a failure occurred.
Existing code doesn't do anything for the case where a CPU can't be added to a domain (probably the only real error case is failure to allocate memory for the domain structure).
Quoted 7 lines
Is my statement about CPU being added to default group mask incorrect? Seems like a potential issue related to domain's CPU mask also.
Please see my earlier question. Existing code does not proceed with monitor initialization if control initialization fails and undoes control initialization if monitor initialization fails.
Existing code silently continues if a domain structure cannot be allocated to add a CPU to a domain:
503 static void domain_add_cpu(int cpu, struct rdt_resource *r) 504 {
505 int id = get_cpu_cacheinfo_id(cpu, r->cache_level); 506 struct list_head *add_pos = NULL; 507 struct rdt_hw_domain *hw_dom; 508 struct rdt_domain *d; 509 int err;
...
523
524 hw_dom = kzalloc_node(sizeof(*hw_dom), GFP_KERNEL, cpu_to_node(cpu));
525 if (!hw_dom)
526 return;
527
Quoted 11 lines
Quoted 7 lines
May be something to tackle in a future series if anyone thinks this is a serious problem and has suggestions on what to do. It seems like a catastrophic problem to not have some CPUs in some/all domains of some resources. Maybe this should disable mounting resctrl filesystem completely?
It is not clear to me how this is catastrophic but I do not think resctrl should claim support for a resource on a CPU if it was not able to complete initialization
That's the status quo. See above code snippet.
-Tony
Reinette Chatre
maintainerRe: [PATCH v4 1/7] x86/resctrl: Create separate domains for control and monitoring
Hi Tony,
Quoted 58 lines · Tony Luck
Quoted 16 lines · Reinette Chatre
Hi Tony,
Quoted 13 lines · Tony Luck
Quoted 11 lines · Reinette Chatre
Quoted 3 lines · Tony Luck
Change all places where monitoring functions walk the list of domains to use the new "mondomains" list instead of the old "domains" list.
I would not refer to it as "the old domains list" as it creates impression that this is being replaced. The changelog makes no mention that domains list will remain and be dedicated to control domains. I think this is important to include in description of this change.
Quoted 5 lines
Quoted 3 lines
I've rewritten the entire commit message incorporating your suggestions. V6 will be posted soon (after I get some time on an SNC SPR to check that it all works!)
I seem to have missed v5.
I simply can't count. You are correct that next version to be posted will be v5.
Quoted 32 lines
Quoted 31 lines
Quoted 13 lines
Quoted 13 lines
Signed-off-by Tony Luck <[email protected]>--- include/linux/resctrl.h | 10 +- arch/x86/kernel/cpu/resctrl/internal.h | 2 +- arch/x86/kernel/cpu/resctrl/core.c | 195 +++++++++++++++------- arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 2 +- arch/x86/kernel/cpu/resctrl/monitor.c | 2 +- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 30 ++-- 6 files changed, 167 insertions(+), 74 deletions(-)Quoted 14 lines
include/linux/resctrl.h struct resctrl_schema; · line 154
Quoted 9 lines
include/linux/resctrl.h +1
-0@@ -151,9 +151,11 @@ struct resctrl_schema;* @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 +* @mon_scope: Scope of this resource if different from cache_level I think this addition should be deferred. As it is here it the "if different from
cache_level" also creates many questions (when will it be different? how will it be determined that the scope is different in order to know thatmon_scopeshould be used?)I've gone in a different direction. V6 renames "
cache_level" to "ctrl_scope". I think this makes intent clear from step #1.
Quoted 8 lines
Quoted 3 lines
This change is not clear to me. Previously you changed this name but kept using it in code specific to cache levels. It is not clear to me how this time's rename would be different.
The current "
cache_level" field in the structure is describing the scope of each instance using the cache level (2 or 3) as the method to describe which CPUs are considered part of a group. Currently the scope is the same for both control and monitor resources.
Right.
Quoted 8 lines
Would you like to see patches in this progrssion:
1) Rename "
cache_level" to "scope". With commit comment that future patches are going to base the scope on NUMA nodes in addtion to sharing caches at particular levels, and will split into separate control and monitor scope.
Quoted 5 lines
2) Split the "scope" field from first patch into "
ctrl_scope" and "mon_scope" (also with the addition of the new list for themon_scope).3) Add "node" as a new option for scope in addtion to L3 and L2 cache.
hmmm - my comment cannot be addressed through patch re-ordering. If I understand correctly you plan to change the name of "cache_level" to "ctrl_scope". My comment is that this obfuscates the code as long as you use this variable to compare against data that can only represent cache levels. This just repeats what I wrote in
https://lore.kernel.org/lkml/[email protected]/
Quoted 89 lines
Quoted 70 lines
...
Quoted 61 lines
Quoted 61 lines
Quoted 45 lines
include/linux/resctrl.h +0
-41@@ -502,61 +593,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); -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); -return ; - } - -if (d) { -cpumask_set_cpu (cpu, &d->cpu_mask); -if (r->cache.arch_has_per_cpu_cfg) -rdt_domain_reconfigure_cdp (r); -return ; - } - - hw_dom =kzalloc_node (sizeof (*hw_dom),GFP_KERNEL ,cpu_to_node (cpu)); -if (!hw_dom) -return ; - - d = &hw_dom->d_resctrl; - d->id = id; -cpumask_set_cpu (cpu, &d->cpu_mask); - -rdt_domain_reconfigure_cdp (r); - -if (r->alloc_capable &&domain_setup_ctrlval (r, d)) { -domain_free (hw_dom); -return ; - } - -if (r->mon_capable &&arch_domain_mbm_alloc (r->num_rmid, hw_dom)) { -domain_free (hw_dom); -return ; - } - -list_add_tail (&d->list, add_pos); -include/linux/resctrl.h static int arch_domain_mbm_alloc(u32 num_rmid, struct rdt_hw_domain *hw_dom) · line 600
Quoted 10 lines
include/linux/resctrl.h +4
-5- err =resctrl_online_domain (r, d); -if (err) { -list_del (&d->list); -domain_free (hw_dom); - } +if (r->alloc_capable) +domain_add_cpu_ctrl (cpu, r); +if (r->mon_capable) +domain_add_cpu_mon (cpu, r); }A resource could be both alloc and mon capable ... both
domain_add_cpu_ctrl()anddomain_add_cpu_mon()can fail. Shoulddomain_add_cpu_mon()still be run for a CPU ifdomain_add_cpu_ctrl()failed?Quoted 6 lines
Quoted 2 lines
Looking ahead the CPU should probably also not be added to the default groups mask if a failure occurred.
Existing code doesn't do anything for the case where a CPU can't be added to a domain (probably the only real error case is failure to allocate memory for the domain structure).
Quoted 7 lines
Is my statement about CPU being added to default group mask incorrect? Seems like a potential issue related to domain's CPU mask also.
Please see my earlier question. Existing code does not proceed with monitor initialization if control initialization fails and undoes control initialization if monitor initialization fails.
Existing code silently continues if a domain structure cannot be allocated to add a CPU to a domain:
503 static void
domain_add_cpu(int cpu, struct rdt_resource *r)504 {505 int id = get_cpu_cacheinfo_id(cpu, r->cache_level); 506 struct list_head *add_pos = NULL; 507 struct rdt_hw_domain *hw_dom; 508 struct rdt_domain *d; 509 int err;
Quoted 8 lines
...
523
524hw_dom=kzalloc_node(sizeof(*hw_dom), GFP_KERNEL, cpu_to_node(cpu));
525 if (!hw_dom)
526 return;
527
Right ... and if it returns silently as above it runs:
static int resctrl_online_cpu(unsigned int cpu)
{
for_each_capable_rdt_resource(r) domain_add_cpu(cpu, r); >>>>> cpumask_set_cpu(cpu, &rdtgroup_default.cpu_mask); <<<<<<<<
}
Also, note within domain_add_cpu():
static void domain_add_cpu(int cpu, struct rdt_resource *r) {
...
if (r->alloc_capable && domain_setup_ctrlval(r, d)) {
domain_free(hw_dom);
return;
}
if (r->mon_capable && arch_domain_mbm_alloc(r->num_rmid, hw_dom)) {
domain_free(hw_dom);
return;
}
...
}The above is the other item that I've been trying to discuss with you. Note that existing resctrl will not initialize monitoring if control could not be initialized.
Compare with this submission:
if (r->alloc_capable) domain_add_cpu_ctrl(cpu, r); if (r->mon_capable) domain_add_cpu_mon(cpu, r);
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
May be something to tackle in a future series if anyone thinks this is a serious problem and has suggestions on what to do. It seems like a catastrophic problem to not have some CPUs in some/all domains of some resources. Maybe this should disable mounting resctrl filesystem completely?
Quoted 5 lines
Quoted 3 lines
It is not clear to me how this is catastrophic but I do not think resctrl should claim support for a resource on a CPU if it was not able to complete initialization
That's the status quo. See above code snippet.
Could you please elaborate what you mean with status quo?
Reinette
Tony Luck
maintainerRe: [PATCH v4 1/7] x86/resctrl: Create separate domains for control and monitoring
Quoted 86 lines · Reinette Chatre
Hi Tony,
Quoted 58 lines · Tony Luck
Quoted 16 lines · Reinette Chatre
Hi Tony,
Quoted 13 lines · Tony Luck
Quoted 11 lines · Reinette Chatre
Quoted 3 lines · Tony Luck
Change all places where monitoring functions walk the list of domains to use the new "mondomains" list instead of the old "domains" list.
I would not refer to it as "the old domains list" as it creates impression that this is being replaced. The changelog makes no mention that domains list will remain and be dedicated to control domains. I think this is important to include in description of this change.
Quoted 5 lines
Quoted 3 lines
I've rewritten the entire commit message incorporating your suggestions. V6 will be posted soon (after I get some time on an SNC SPR to check that it all works!)
I seem to have missed v5.
I simply can't count. You are correct that next version to be posted will be v5.
Quoted 32 lines
Quoted 31 lines
Quoted 13 lines
Quoted 13 lines
Signed-off-by Tony Luck <[email protected]>--- include/linux/resctrl.h | 10 +- arch/x86/kernel/cpu/resctrl/internal.h | 2 +- arch/x86/kernel/cpu/resctrl/core.c | 195 +++++++++++++++------- arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 2 +- arch/x86/kernel/cpu/resctrl/monitor.c | 2 +- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 30 ++-- 6 files changed, 167 insertions(+), 74 deletions(-)Quoted 14 lines
include/linux/resctrl.h struct resctrl_schema; · line 154
Quoted 9 lines
include/linux/resctrl.h +1
-0@@ -151,9 +151,11 @@ struct resctrl_schema;* @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 +* @mon_scope: Scope of this resource if different from cache_level I think this addition should be deferred. As it is here it the "if different from
cache_level" also creates many questions (when will it be different? how will it be determined that the scope is different in order to know thatmon_scopeshould be used?)I've gone in a different direction. V6 renames "
cache_level" to "ctrl_scope". I think this makes intent clear from step #1.Quoted 8 lines
Quoted 3 lines
This change is not clear to me. Previously you changed this name but kept using it in code specific to cache levels. It is not clear to me how this time's rename would be different.
The current "
cache_level" field in the structure is describing the scope of each instance using the cache level (2 or 3) as the method to describe which CPUs are considered part of a group. Currently the scope is the same for both control and monitor resources.Right.
Quoted 8 lines
Would you like to see patches in this progrssion:
1) Rename "
cache_level" to "scope". With commit comment that future patches are going to base the scope on NUMA nodes in addtion to sharing caches at particular levels, and will split into separate control and monitor scope.Quoted 5 lines
2) Split the "scope" field from first patch into "
ctrl_scope" and "mon_scope" (also with the addition of the new list for themon_scope).3) Add "node" as a new option for scope in addtion to L3 and L2 cache.
Quoted 6 lines
hmmm - my comment cannot be addressed through patch re-ordering. If I understand correctly you plan to change the name of "
cache_level" to "ctrl_scope". My comment is that this obfuscates the code as long as you use this variable to compare against data that can only represent cache levels. This just repeats what I wrote in
https://lore.kernel.org/lkml/[email protected]/
I'm proposing more than just re-ordering. The above sequence is a couple of extra patches in the series.
Existing state of code:
There is a single field named "cache_level" that describes how CPUs are assigned to domains based on their sharing of a cache at a particular level. Hard-coded values of "2" and "3" are used to describe the level. This is just a scope description of which CPUs are grouped together. But it is limited to just doing so based on which caches are shared by those CPUs.
Step 1:
Change the name of the field s/cache_level/scope/. Provide an enum with values RESCTRL_L3_CACHE, RESCTRL_L2_CACHE aand use those througout code instead of 3, 2, and implictly passing the resctrl scope to functions like get_cpu_cacheinfo_id()
Add get_domain_id_from_scope() function that takes the enum values for scope and converts to "3", "2" to pass to get_cpu_cacheinfo_id().
No functional change. Just broadening the meaning of the field so that it can in future patches to describe scopes that aren't a function of sharing a cache of a particular level.
Step 2:
Break the single list of domains into two separate lists. One for control domains, one for monitor domains. Change the name of the "scope" field to "ctrl"scope", add a new field "mon_scope".
Step 3:
Add RESCTRL_NODE as a new option in the enum for how CPUs are grouped into domains.
Quoted 153 lines
Quoted 91 lines
Quoted 72 lines
...
Quoted 61 lines
Quoted 61 lines
Quoted 45 lines
include/linux/resctrl.h +0
-41@@ -502,61 +593,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); -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); -return ; - } - -if (d) { -cpumask_set_cpu (cpu, &d->cpu_mask); -if (r->cache.arch_has_per_cpu_cfg) -rdt_domain_reconfigure_cdp (r); -return ; - } - - hw_dom =kzalloc_node (sizeof (*hw_dom),GFP_KERNEL ,cpu_to_node (cpu)); -if (!hw_dom) -return ; - - d = &hw_dom->d_resctrl; - d->id = id; -cpumask_set_cpu (cpu, &d->cpu_mask); - -rdt_domain_reconfigure_cdp (r); - -if (r->alloc_capable &&domain_setup_ctrlval (r, d)) { -domain_free (hw_dom); -return ; - } - -if (r->mon_capable &&arch_domain_mbm_alloc (r->num_rmid, hw_dom)) { -domain_free (hw_dom); -return ; - } - -list_add_tail (&d->list, add_pos); -include/linux/resctrl.h static int arch_domain_mbm_alloc(u32 num_rmid, struct rdt_hw_domain *hw_dom) · line 600
Quoted 10 lines
include/linux/resctrl.h +4
-5- err =resctrl_online_domain (r, d); -if (err) { -list_del (&d->list); -domain_free (hw_dom); - } +if (r->alloc_capable) +domain_add_cpu_ctrl (cpu, r); +if (r->mon_capable) +domain_add_cpu_mon (cpu, r); }A resource could be both alloc and mon capable ... both
domain_add_cpu_ctrl()anddomain_add_cpu_mon()can fail. Shoulddomain_add_cpu_mon()still be run for a CPU ifdomain_add_cpu_ctrl()failed?Quoted 6 lines
Quoted 2 lines
Looking ahead the CPU should probably also not be added to the default groups mask if a failure occurred.
Existing code doesn't do anything for the case where a CPU can't be added to a domain (probably the only real error case is failure to allocate memory for the domain structure).
Quoted 7 lines
Is my statement about CPU being added to default group mask incorrect? Seems like a potential issue related to domain's CPU mask also.
Please see my earlier question. Existing code does not proceed with monitor initialization if control initialization fails and undoes control initialization if monitor initialization fails.
Existing code silently continues if a domain structure cannot be allocated to add a CPU to a domain:
503 static void
domain_add_cpu(int cpu, struct rdt_resource *r)504 {505 int id = get_cpu_cacheinfo_id(cpu, r->cache_level); 506 struct list_head *add_pos = NULL; 507 struct rdt_hw_domain *hw_dom; 508 struct rdt_domain *d; 509 int err;Quoted 8 lines
...
523
524hw_dom=kzalloc_node(sizeof(*hw_dom), GFP_KERNEL, cpu_to_node(cpu));
525 if (!hw_dom)
526 return;
527Right ... and if it returns silently as above it runs:
static int
resctrl_online_cpu(unsigned int cpu)
{for_each_capable_rdt_resource(r) domain_add_cpu(cpu, r); >>>>> cpumask_set_cpu(cpu, &rdtgroup_default.cpu_mask); <<<<<<<<}
Also, note within
domain_add_cpu():static void
domain_add_cpu(int cpu, struct rdt_resource *r){... if (r->alloc_capable && domain_setup_ctrlval(r, d)) { domain_free(hw_dom); return; } if (r->mon_capable && arch_domain_mbm_alloc(r->num_rmid, hw_dom)) { domain_free(hw_dom); return; } ... }The above is the other item that I've been trying to discuss with you. Note that existing resctrl will not initialize monitoring if control could not be initialized.
Compare with this submission:if (r->alloc_capable) domain_add_cpu_ctrl(cpu, r); if (r->mon_capable) domain_add_cpu_mon(cpu, r);Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
May be something to tackle in a future series if anyone thinks this is a serious problem and has suggestions on what to do. It seems like a catastrophic problem to not have some CPUs in some/all domains of some resources. Maybe this should disable mounting resctrl filesystem completely?
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
It is not clear to me how this is catastrophic but I do not think resctrl should claim support for a resource on a CPU if it was not able to complete initialization
That's the status quo. See above code snippet.
Could you please elaborate what you mean with status quo?
Status quo. System may be booting and add a bunch of CPUs to the first domain for a resource. When it finds a CPU from a different domain it calls domain_add_cpu(), but for some reason the allocation of a rdt_hw_domain fails here:
524 hw_dom = kzalloc_node(sizeof(*hw_dom), GFP_KERNEL, cpu_to_node(cpu));
525 if (!hw_dom)
526 return;
domain_add_cpu() returns with no message to the console, no error code. System boots, but this CPU is missing from the domain (likely the whole domain is missing as the same allocation will most likely fail for the remainder of the CPUs in this domain). Only indication to user is when they read the schemata file and see something like this:
$ cat /sys/fs/resctrl/schemata
MB:0= 100
L3:0=7fff;1=7fff(assuming that all domains were successfully allocated for L3, and the failure described above happened on the allocation for the second domain of the MB resource.)
-Tony
Reinette Chatre
maintainerRe: [PATCH v4 1/7] x86/resctrl: Create separate domains for control and monitoring
Quoted 113 lines · Tony Luck
Quoted 86 lines · Reinette Chatre
Hi Tony,
Quoted 58 lines · Tony Luck
Quoted 16 lines · Reinette Chatre
Hi Tony,
Quoted 13 lines · Tony Luck
Quoted 11 lines · Reinette Chatre
Quoted 3 lines · Tony Luck
Change all places where monitoring functions walk the list of domains to use the new "mondomains" list instead of the old "domains" list.
I would not refer to it as "the old domains list" as it creates impression that this is being replaced. The changelog makes no mention that domains list will remain and be dedicated to control domains. I think this is important to include in description of this change.
Quoted 5 lines
Quoted 3 lines
I've rewritten the entire commit message incorporating your suggestions. V6 will be posted soon (after I get some time on an SNC SPR to check that it all works!)
I seem to have missed v5.
I simply can't count. You are correct that next version to be posted will be v5.
Quoted 32 lines
Quoted 31 lines
Quoted 13 lines
Quoted 13 lines
Signed-off-by Tony Luck <[email protected]>--- include/linux/resctrl.h | 10 +- arch/x86/kernel/cpu/resctrl/internal.h | 2 +- arch/x86/kernel/cpu/resctrl/core.c | 195 +++++++++++++++------- arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 2 +- arch/x86/kernel/cpu/resctrl/monitor.c | 2 +- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 30 ++-- 6 files changed, 167 insertions(+), 74 deletions(-)Quoted 14 lines
include/linux/resctrl.h struct resctrl_schema; · line 154
Quoted 9 lines
include/linux/resctrl.h +1
-0@@ -151,9 +151,11 @@ struct resctrl_schema;* @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 +* @mon_scope: Scope of this resource if different from cache_level I think this addition should be deferred. As it is here it the "if different from
cache_level" also creates many questions (when will it be different? how will it be determined that the scope is different in order to know thatmon_scopeshould be used?)I've gone in a different direction. V6 renames "
cache_level" to "ctrl_scope". I think this makes intent clear from step #1.Quoted 8 lines
Quoted 3 lines
This change is not clear to me. Previously you changed this name but kept using it in code specific to cache levels. It is not clear to me how this time's rename would be different.
The current "
cache_level" field in the structure is describing the scope of each instance using the cache level (2 or 3) as the method to describe which CPUs are considered part of a group. Currently the scope is the same for both control and monitor resources.Right.
Quoted 8 lines
Would you like to see patches in this progrssion:
1) Rename "
cache_level" to "scope". With commit comment that future patches are going to base the scope on NUMA nodes in addtion to sharing caches at particular levels, and will split into separate control and monitor scope.Quoted 5 lines
2) Split the "scope" field from first patch into "
ctrl_scope" and "mon_scope" (also with the addition of the new list for themon_scope).3) Add "node" as a new option for scope in addtion to L3 and L2 cache.
Quoted 6 lines
hmmm - my comment cannot be addressed through patch re-ordering. If I understand correctly you plan to change the name of "
cache_level" to "ctrl_scope". My comment is that this obfuscates the code as long as you use this variable to compare against data that can only represent cache levels. This just repeats what I wrote in
https://lore.kernel.org/lkml/[email protected]/I'm proposing more than just re-ordering. The above sequence is a couple of extra patches in the series.
Existing state of code:
There is a single field named "
cache_level" that describes how CPUs are assigned to domains based on their sharing of a cache at a particular level. Hard-coded values of "2" and "3" are used to describe the level. This is just a scope description of which CPUs are grouped together. But it is limited to just doing so based on which caches are shared by those CPUs.Step 1:
Change the name of the field s/cache_level/scope/. Provide an enum with values
RESCTRL_L3_CACHE,RESCTRL_L2_CACHEaand use those througout code instead of 3, 2, and implictly passing the resctrl scope to functions likeget_cpu_cacheinfo_id()
Quoted 7 lines
Add
get_domain_id_from_scope()function that takes the enum values for scope and converts to "3", "2" to pass toget_cpu_cacheinfo_id().No functional change. Just broadening the meaning of the field so that it can in future patches to describe scopes that aren't a function of sharing a cache of a particular level.
Right. So if I understand you are planning the same change as you did in V3, like below, and my original comment still stands.
@@ -1348,7 +1348,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;
}
Quoted 134 lines
Quoted 134 lines
Quoted 87 lines
Quoted 68 lines
Quoted 61 lines
Quoted 61 lines
Quoted 45 lines
include/linux/resctrl.h +0
-41@@ -502,61 +593,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); -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); -return ; - } - -if (d) { -cpumask_set_cpu (cpu, &d->cpu_mask); -if (r->cache.arch_has_per_cpu_cfg) -rdt_domain_reconfigure_cdp (r); -return ; - } - - hw_dom =kzalloc_node (sizeof (*hw_dom),GFP_KERNEL ,cpu_to_node (cpu)); -if (!hw_dom) -return ; - - d = &hw_dom->d_resctrl; - d->id = id; -cpumask_set_cpu (cpu, &d->cpu_mask); - -rdt_domain_reconfigure_cdp (r); - -if (r->alloc_capable &&domain_setup_ctrlval (r, d)) { -domain_free (hw_dom); -return ; - } - -if (r->mon_capable &&arch_domain_mbm_alloc (r->num_rmid, hw_dom)) { -domain_free (hw_dom); -return ; - } - -list_add_tail (&d->list, add_pos); -include/linux/resctrl.h static int arch_domain_mbm_alloc(u32 num_rmid, struct rdt_hw_domain *hw_dom) · line 600
Quoted 10 lines
include/linux/resctrl.h +4
-5- err =resctrl_online_domain (r, d); -if (err) { -list_del (&d->list); -domain_free (hw_dom); - } +if (r->alloc_capable) +domain_add_cpu_ctrl (cpu, r); +if (r->mon_capable) +domain_add_cpu_mon (cpu, r); }A resource could be both alloc and mon capable ... both
domain_add_cpu_ctrl()anddomain_add_cpu_mon()can fail. Shoulddomain_add_cpu_mon()still be run for a CPU ifdomain_add_cpu_ctrl()failed?Quoted 6 lines
Quoted 2 lines
Looking ahead the CPU should probably also not be added to the default groups mask if a failure occurred.
Existing code doesn't do anything for the case where a CPU can't be added to a domain (probably the only real error case is failure to allocate memory for the domain structure).
Quoted 7 lines
Is my statement about CPU being added to default group mask incorrect? Seems like a potential issue related to domain's CPU mask also.
Please see my earlier question. Existing code does not proceed with monitor initialization if control initialization fails and undoes control initialization if monitor initialization fails.
Existing code silently continues if a domain structure cannot be allocated to add a CPU to a domain:
503 static void
domain_add_cpu(int cpu, struct rdt_resource *r)504 {505 int id = get_cpu_cacheinfo_id(cpu, r->cache_level); 506 struct list_head *add_pos = NULL; 507 struct rdt_hw_domain *hw_dom; 508 struct rdt_domain *d; 509 int err;Quoted 8 lines
...
523
524hw_dom=kzalloc_node(sizeof(*hw_dom), GFP_KERNEL, cpu_to_node(cpu));
525 if (!hw_dom)
526 return;
527Right ... and if it returns silently as above it runs:
static int
resctrl_online_cpu(unsigned int cpu)
{for_each_capable_rdt_resource(r) domain_add_cpu(cpu, r); >>>>> cpumask_set_cpu(cpu, &rdtgroup_default.cpu_mask); <<<<<<<<}
Also, note within
domain_add_cpu():static void
domain_add_cpu(int cpu, struct rdt_resource *r){... if (r->alloc_capable && domain_setup_ctrlval(r, d)) { domain_free(hw_dom); return; } if (r->mon_capable && arch_domain_mbm_alloc(r->num_rmid, hw_dom)) { domain_free(hw_dom); return; } ... }The above is the other item that I've been trying to discuss with you. Note that existing resctrl will not initialize monitoring if control could not be initialized.
Compare with this submission:
Quoted 6 lines
Quoted 6 lines
if (r->alloc_capable) domain_add_cpu_ctrl(cpu, r); if (r->mon_capable) domain_add_cpu_mon(cpu, r);
I'll stop trying
Reinette
Tony Luck
maintainerRe: [PATCH v4 1/7] x86/resctrl: Create separate domains for control and monitoring
Quoted 127 lines · Reinette Chatre
Quoted 113 lines · Tony Luck
Quoted 86 lines · Reinette Chatre
Hi Tony,
Quoted 58 lines · Tony Luck
Quoted 16 lines · Reinette Chatre
Hi Tony,
Quoted 13 lines · Tony Luck
Quoted 11 lines · Reinette Chatre
Quoted 3 lines · Tony Luck
Change all places where monitoring functions walk the list of domains to use the new "mondomains" list instead of the old "domains" list.
I would not refer to it as "the old domains list" as it creates impression that this is being replaced. The changelog makes no mention that domains list will remain and be dedicated to control domains. I think this is important to include in description of this change.
Quoted 5 lines
Quoted 3 lines
I've rewritten the entire commit message incorporating your suggestions. V6 will be posted soon (after I get some time on an SNC SPR to check that it all works!)
I seem to have missed v5.
I simply can't count. You are correct that next version to be posted will be v5.
Quoted 32 lines
Quoted 31 lines
Quoted 13 lines
Quoted 13 lines
Signed-off-by Tony Luck <[email protected]>--- include/linux/resctrl.h | 10 +- arch/x86/kernel/cpu/resctrl/internal.h | 2 +- arch/x86/kernel/cpu/resctrl/core.c | 195 +++++++++++++++------- arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 2 +- arch/x86/kernel/cpu/resctrl/monitor.c | 2 +- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 30 ++-- 6 files changed, 167 insertions(+), 74 deletions(-)Quoted 14 lines
include/linux/resctrl.h struct resctrl_schema; · line 154
Quoted 9 lines
include/linux/resctrl.h +1
-0@@ -151,9 +151,11 @@ struct resctrl_schema;* @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 +* @mon_scope: Scope of this resource if different from cache_level I think this addition should be deferred. As it is here it the "if different from
cache_level" also creates many questions (when will it be different? how will it be determined that the scope is different in order to know thatmon_scopeshould be used?)I've gone in a different direction. V6 renames "
cache_level" to "ctrl_scope". I think this makes intent clear from step #1.Quoted 8 lines
Quoted 3 lines
This change is not clear to me. Previously you changed this name but kept using it in code specific to cache levels. It is not clear to me how this time's rename would be different.
The current "
cache_level" field in the structure is describing the scope of each instance using the cache level (2 or 3) as the method to describe which CPUs are considered part of a group. Currently the scope is the same for both control and monitor resources.Right.
Quoted 8 lines
Would you like to see patches in this progrssion:
1) Rename "
cache_level" to "scope". With commit comment that future patches are going to base the scope on NUMA nodes in addtion to sharing caches at particular levels, and will split into separate control and monitor scope.Quoted 5 lines
2) Split the "scope" field from first patch into "
ctrl_scope" and "mon_scope" (also with the addition of the new list for themon_scope).3) Add "node" as a new option for scope in addtion to L3 and L2 cache.
Quoted 6 lines
hmmm - my comment cannot be addressed through patch re-ordering. If I understand correctly you plan to change the name of "
cache_level" to "ctrl_scope". My comment is that this obfuscates the code as long as you use this variable to compare against data that can only represent cache levels. This just repeats what I wrote in
https://lore.kernel.org/lkml/[email protected]/I'm proposing more than just re-ordering. The above sequence is a couple of extra patches in the series.
Existing state of code:
There is a single field named "
cache_level" that describes how CPUs are assigned to domains based on their sharing of a cache at a particular level. Hard-coded values of "2" and "3" are used to describe the level. This is just a scope description of which CPUs are grouped together. But it is limited to just doing so based on which caches are shared by those CPUs.Step 1:
Change the name of the field s/cache_level/scope/. Provide an enum with values
RESCTRL_L3_CACHE,RESCTRL_L2_CACHEaand use those througout code instead of 3, 2, and implictly passing the resctrl scope to functions likeget_cpu_cacheinfo_id()Quoted 7 lines
Add
get_domain_id_from_scope()function that takes the enum values for scope and converts to "3", "2" to pass toget_cpu_cacheinfo_id().No functional change. Just broadening the meaning of the field so that it can in future patches to describe scopes that aren't a function of sharing a cache of a particular level.
Right. So if I understand you are planning the same change as you did in V3, like below, and my original comment still stands.
Quoted 8 lines
@@ -1348,7 +1348,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;
No. I heard your complaint about mixing "scope" and "cache_level". Latest version of that code looks like this:
1341 unsigned int rdtgroup_cbm_to_size(struct rdt_resource *r,
1342 struct rdt_domain *d, unsigned long cbm)
1343 {
1344 struct cpu_cacheinfo *ci; 1345 unsigned int size = 0; 1346 int cache_level; 1347 int num_b, i;
1348
1349 switch (r->ctrl_scope) {
1350 case RESCTRL_L3_CACHE:
1351 cache_level = 3;
1352 break;
1353 case RESCTRL_L2_CACHE:
1354 cache_level = 2;
1355 break;
1356 default:
1357 WARN_ON_ONCE(1);
1358 return size;
1359 }
1360
1361 num_b = bitmap_weight(&cbm, r->cache.cbm_len);
1362 ci = get_cpu_cacheinfo(cpumask_any(&d->cpu_mask));
1363 for (i = 0; i < ci->num_leaves; i++) {1364 if (ci->info_list[i].level == cache_level) {
1365 size = ci->info_list[i].size / r->cache.cbm_len * num_b;
1366 break;
1367 }
1368 }
1369
1370 return size / snc_nodes_per_l3_cache;
1371 }
Quoted 137 lines
}Quoted 134 lines
Quoted 134 lines
Quoted 87 lines
Quoted 68 lines
Quoted 61 lines
Quoted 61 lines
Quoted 45 lines
include/linux/resctrl.h +0
-41@@ -502,61 +593,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); -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); -return ; - } - -if (d) { -cpumask_set_cpu (cpu, &d->cpu_mask); -if (r->cache.arch_has_per_cpu_cfg) -rdt_domain_reconfigure_cdp (r); -return ; - } - - hw_dom =kzalloc_node (sizeof (*hw_dom),GFP_KERNEL ,cpu_to_node (cpu)); -if (!hw_dom) -return ; - - d = &hw_dom->d_resctrl; - d->id = id; -cpumask_set_cpu (cpu, &d->cpu_mask); - -rdt_domain_reconfigure_cdp (r); - -if (r->alloc_capable &&domain_setup_ctrlval (r, d)) { -domain_free (hw_dom); -return ; - } - -if (r->mon_capable &&arch_domain_mbm_alloc (r->num_rmid, hw_dom)) { -domain_free (hw_dom); -return ; - } - -list_add_tail (&d->list, add_pos); -include/linux/resctrl.h static int arch_domain_mbm_alloc(u32 num_rmid, struct rdt_hw_domain *hw_dom) · line 600
Quoted 10 lines
include/linux/resctrl.h +4
-5- err =resctrl_online_domain (r, d); -if (err) { -list_del (&d->list); -domain_free (hw_dom); - } +if (r->alloc_capable) +domain_add_cpu_ctrl (cpu, r); +if (r->mon_capable) +domain_add_cpu_mon (cpu, r); }A resource could be both alloc and mon capable ... both
domain_add_cpu_ctrl()anddomain_add_cpu_mon()can fail. Shoulddomain_add_cpu_mon()still be run for a CPU ifdomain_add_cpu_ctrl()failed?Quoted 6 lines
Quoted 2 lines
Looking ahead the CPU should probably also not be added to the default groups mask if a failure occurred.
Existing code doesn't do anything for the case where a CPU can't be added to a domain (probably the only real error case is failure to allocate memory for the domain structure).
Quoted 7 lines
Is my statement about CPU being added to default group mask incorrect? Seems like a potential issue related to domain's CPU mask also.
Please see my earlier question. Existing code does not proceed with monitor initialization if control initialization fails and undoes control initialization if monitor initialization fails.
Existing code silently continues if a domain structure cannot be allocated to add a CPU to a domain:
503 static void
domain_add_cpu(int cpu, struct rdt_resource *r)504 {505 int id = get_cpu_cacheinfo_id(cpu, r->cache_level); 506 struct list_head *add_pos = NULL; 507 struct rdt_hw_domain *hw_dom; 508 struct rdt_domain *d; 509 int err;Quoted 8 lines
...
523
524hw_dom=kzalloc_node(sizeof(*hw_dom), GFP_KERNEL, cpu_to_node(cpu));
525 if (!hw_dom)
526 return;
527Right ... and if it returns silently as above it runs:
static int
resctrl_online_cpu(unsigned int cpu)
{for_each_capable_rdt_resource(r) domain_add_cpu(cpu, r); >>>>> cpumask_set_cpu(cpu, &rdtgroup_default.cpu_mask); <<<<<<<<}
Also, note within
domain_add_cpu():static void
domain_add_cpu(int cpu, struct rdt_resource *r){... if (r->alloc_capable && domain_setup_ctrlval(r, d)) { domain_free(hw_dom); return; } if (r->mon_capable && arch_domain_mbm_alloc(r->num_rmid, hw_dom)) { domain_free(hw_dom); return; } ... }The above is the other item that I've been trying to discuss with you. Note that existing resctrl will not initialize monitoring if control could not be initialized.
Compare with this submission:
Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
if (r->alloc_capable) domain_add_cpu_ctrl(cpu, r); if (r->mon_capable) domain_add_cpu_mon(cpu, r);I'll stop trying
I'll see what I can do to improve the error handling.
-Tony
Tony Luck
maintainerRe: [PATCH v4 1/7] x86/resctrl: Create separate domains for control and monitoring
Trimming to the core of the discussion.
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
if (r->alloc_capable && domain_setup_ctrlval(r, d)) { domain_free(hw_dom); return; } if (r->mon_capable && arch_domain_mbm_alloc(r->num_rmid, hw_dom)) { domain_free(hw_dom); return; }
In the current code the control and monitor functions share a domain structure. So enabling one without the other would lead to a whole slew of complications. Various other bits of code would need to change to make run-time checks that the control/monitor pieces of the shared domain structure had been completely set up. So the existing code takes the easy path out and says "if I can't have both, I'll take have neither".
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
The above is the other item that I've been trying to discuss with you. Note that existing resctrl will not initialize monitoring if control could not be initialized.
Compare with this submission:if (r->alloc_capable) domain_add_cpu_ctrl(cpu, r); if (r->mon_capable) domain_add_cpu_mon(cpu, r);
With the updates I'm making, there are separate domain structures for control and monitor. They don't have to be tied together. It's possible for initialization to fail on one, but the other remain completely functional (without adding "is this completely setup" checks to other code).
The question is what should the code do? Should it allow a partial success (now that is possible)? Or should it maintain legacy behavior and block use of both control and monitor for domain if either fails to allocate necessary memory to operate?
I'm generally in favor of legacy semantics. But it seems weird to make the code deliberately worse to preserve this particular behavior. Especially as it adds complexity to the code for a case that in practice is never going to happen.
-Tony
Tony Luck
maintainerPATCH v4 2/7 x86/resctrl: Split the rdt_domain structures
In reply to Tony LuckThe rdt_domain and rdt_hw_domain structures contain an amalgam of fields used by control and monitoring features. Now that there are separate domain lists for control/monitoring these can be divided between two structures.
First step: Add new domain structures for monitoring with the fields that are needed. Leave these fields in the legacy structure so compilation won't fail. They will be deleted once all the monitoring code has been converted to use the new structure.
--- include/linux/resctrl.h | 28 +++++++++++++++++++++++++- arch/x86/kernel/cpu/resctrl/internal.h | 17 +++++++++++++++- 2 files changed, 43 insertions(+), 2 deletions(-)
include/linux/resctrl.h +27 -1
@@ -53,7 +53,7 @@ struct resctrl_staged_config { };/** -* struct rdt_domain - group of CPUs sharing a resctrl resource +* struct rdt_domain - group of CPUs sharing a resctrl control resource * @list: all instances of this resource * @id: unique id for this instance * @cpu_mask: which CPUs share this resource
@@ -86,6 +86,32 @@ struct rdt_domain {u32 *mbps_val; }; +/** +* struct rdt_mondomain - group of CPUs sharing a resctrl monitor resource +* @list: all instances of this resource +* @id: unique id for this instance +* @cpu_mask: which CPUs share this resource +* @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 +* @mbm_over: worker to periodically read MBM h/w counters +* @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 +*/ +struct rdt_mondomain { +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; +}; +/** * struct resctrl_cache - Cache allocation related data * @cbm_len: Length of the cache bit mask
arch/x86/kernel/cpu/resctrl/internal.h +16 -1
@@ -320,7 +320,7 @@ struct arch_mbm_state {/** * struct rdt_hw_domain - Arch private attributes of a set of CPUs that share -* a resource +* a control resource * @d_resctrl: Properties exposed to the resctrl file system * @ctrl_val: array of cache or mem ctrl values (indexed by CLOSID) * @arch_mbm_total: arch private state for MBM total bandwidth
@@ -335,6 +335,21 @@ struct rdt_hw_domain {struct arch_mbm_state *arch_mbm_local; }; +/** +* struct rdt_hw_mondomain - Arch private attributes of a set of CPUs that share +* a monitor resource +* @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_mondomain { +struct rdt_mondomain 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) { return container_of(r, struct rdt_hw_domain, d_resctrl);
Signature · 1 line
2.40.1
Tony Luck
maintainerPATCH v4 3/7 x86/resctrl: Change monitor code to use rdt_mondomain
In reply to Tony LuckA few functions need to be duplicated to provide versions to operate on control and monitor domains respectively. But most of the changes are just fixing argument and return value types.
--- include/linux/resctrl.h | 10 +++--- arch/x86/kernel/cpu/resctrl/internal.h | 21 +++++++----- arch/x86/kernel/cpu/resctrl/core.c | 40 ++++++++++++++--------- arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 4 +-- arch/x86/kernel/cpu/resctrl/monitor.c | 38 ++++++++++----------- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 24 +++++++------- 6 files changed, 75 insertions(+), 62 deletions(-)
include/linux/resctrl.h +5 -5
@@ -248,9 +248,9 @@ 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_ctrl_domain (struct rdt_resource *r,struct rdt_domain *d); -int resctrl_online_mon_domain (struct rdt_resource *r,struct rdt_domain *d); +int resctrl_online_mon_domain (struct rdt_resource *r,struct rdt_mondomain *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); +void resctrl_offline_mon_domain (struct rdt_resource *r,struct rdt_mondomain *d);/** * resctrl_arch_rmid_read() - Read the eventid counter corresponding to rmid
@@ -266,7 +266,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_mondomain *d,u32 rmid,enum resctrl_event_id eventid,u64 *val);/**
@@ -279,7 +279,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_mondomain *d,u32 rmid,enum resctrl_event_id eventid);/**
@@ -291,7 +291,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_mondomain *d);extern unsigned int resctrl_rmid_realloc_threshold;extern unsigned int resctrl_rmid_realloc_limit;
arch/x86/kernel/cpu/resctrl/internal.h +13 -8
@@ -106,7 +106,7 @@ union mon_data_bits {struct rmid_read {struct rdtgroup *rgrp;struct rdt_resource *r; -struct rdt_domain *d; +struct rdt_mondomain *d;enum resctrl_event_id evtid;bool first;int err;
@@ -355,6 +355,11 @@ static inline struct rdt_hw_domain *resctrl_to_arch_dom(struct rdt_domain *r) return container_of(r, struct rdt_hw_domain, d_resctrl); } +static inline struct rdt_hw_mondomain *resctrl_to_arch_mondom (struct rdt_mondomain *r) +{ + return container_of(r, struct rdt_hw_mondomain, d_resctrl); +} +/** * struct msr_param - set a range of MSRs from a domain * @res: The resource to use
@@ -526,8 +531,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 list_head *h,int id, -struct list_head **pos); +void *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,
@@ -556,17 +561,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_mondomain *d,struct rdtgroup *rdtgrp,int evtid,int first); -void mbm_setup_overflow_handler (struct rdt_domain *dom, +void mbm_setup_overflow_handler (struct rdt_mondomain *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_mondomain *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_mondomain *d); +void __check_limbo (struct rdt_mondomain *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 +24 -16
@@ -393,9 +393,12 @@ void rdt_ctrl_update(void *arg)* 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. +* +* N.B. Returned value may be either a pointer to "struct rdt_domain" or +* to "struct rdt_mondomain" depending on which domain list is scanned. */ -struct rdt_domain *rdt_find_domain (struct list_head *h,int id, -struct list_head **pos) +void *rdt_find_domain (struct list_head *h,int id, +struct list_head **pos) {struct rdt_domain *d;struct list_head *l;
@@ -434,10 +437,15 @@ static void setup_default_ctrlval(struct rdt_resource *r, u32 *dc) }static void domain_free (struct rdt_hw_domain *hw_dom) +{ +kfree (hw_dom->ctrl_val); +kfree (hw_dom); +} + +static void mondomain_free (struct rdt_hw_mondomain *hw_dom) {kfree (hw_dom->arch_mbm_total);kfree (hw_dom->arch_mbm_local); -kfree (hw_dom->ctrl_val);kfree (hw_dom); }
@@ -467,7 +475,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_mondomain *hw_dom) {size_t tsize;
@@ -539,8 +547,8 @@ static void domain_add_cpu_mon(int cpu, struct rdt_resource *r) {int id =get_cpu_cacheinfo_id (cpu, r->mon_scope);struct list_head *add_pos =NULL ; -struct rdt_hw_domain *hw_dom; -struct rdt_domain *d; +struct rdt_hw_mondomain *hw_mondom; +struct rdt_mondomain *d;int err; d =rdt_find_domain (&r->mondomains, id, &add_pos);
@@ -556,16 +564,16 @@ static void domain_add_cpu_mon(int cpu, struct rdt_resource *r)return ; } - hw_dom =kzalloc_node (sizeof (*hw_dom),GFP_KERNEL ,cpu_to_node (cpu)); -if (!hw_dom) + hw_mondom =kzalloc_node (sizeof (*hw_mondom),GFP_KERNEL ,cpu_to_node (cpu)); +if (!hw_mondom)return ; - d = &hw_dom->d_resctrl; + d = &hw_mondom->d_resctrl; d->id = id;cpumask_set_cpu (cpu, &d->cpu_mask); -if (arch_domain_mbm_alloc (r->num_rmid, hw_dom)) { -domain_free (hw_dom); +if (arch_domain_mbm_alloc (r->num_rmid, hw_mondom)) { +mondomain_free (hw_mondom);return ; }
@@ -574,7 +582,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->list); -domain_free (hw_dom); +mondomain_free (hw_mondom); } }
@@ -632,22 +640,22 @@ 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_cpu_cacheinfo_id (cpu, r->cache_level); -struct rdt_hw_domain *hw_dom; -struct rdt_domain *d; +struct rdt_hw_mondomain *hw_mondom; +struct rdt_mondomain *d; d =rdt_find_domain (&r->mondomains, id,NULL );if (IS_ERR_OR_NULL (d)) {pr_warn ("Couldn't find cache id for CPU %d\n" , cpu);return ; } - hw_dom =resctrl_to_arch_dom (d); + hw_mondom =resctrl_to_arch_mondom (d);cpumask_clear_cpu (cpu, &d->cpu_mask);if (cpumask_empty (&d->cpu_mask)) {resctrl_offline_mon_domain (r, d);list_del (&d->list); -domain_free (hw_dom); +mondomain_free (hw_mondom);return ; }
arch/x86/kernel/cpu/resctrl/ctrlmondata.c +2 -2
@@ -521,7 +521,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_mondomain *d,struct rdtgroup *rdtgrp,int evtid,int first) {/*
@@ -544,7 +544,7 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg)struct rdtgroup *rdtgrp;struct rdt_resource *r;union mon_data_bits md; -struct rdt_domain *d; +struct rdt_mondomain *d;struct rmid_read rr;int ret =0 ;
arch/x86/kernel/cpu/resctrl/monitor.c +19 -19
@@ -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_mondomain *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_mondomain *d,u32 rmid,enum resctrl_event_id eventid) { -struct rdt_hw_domain *hw_dom =resctrl_to_arch_dom (d); +struct rdt_hw_mondomain *hw_dom =resctrl_to_arch_mondom (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_mondomain *d) { -struct rdt_hw_domain *hw_dom =resctrl_to_arch_dom (d); +struct rdt_hw_mondomain *hw_dom =resctrl_to_arch_mondom (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_mondomain *d,u32 rmid,enum resctrl_event_id eventid,u64 *val) {struct rdt_hw_resource *hw_res =resctrl_to_arch_res (r); -struct rdt_hw_domain *hw_dom =resctrl_to_arch_dom (d); +struct rdt_hw_mondomain *hw_dom =resctrl_to_arch_mondom (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_mondomain *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_mondomain *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_mondomain *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_mondomain *d,u32 rmid,enum resctrl_event_id evtid) {switch (evtid) {
@@ -516,7 +516,7 @@ 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_mondomain *dom_mbm) {u32 closid, rmid, cur_msr_val, new_msr_val;struct mbm_state *pmbm_data, *cmbm_data;
@@ -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_mondomain *d,int rmid) {struct rmid_read rr;
@@ -641,12 +641,12 @@ void cqm_handle_limbo(struct work_struct *work)unsigned long delay =msecs_to_jiffies (CQM_LIMBOCHECK_INTERVAL );int cpu =smp_processor_id ();struct rdt_resource *r; -struct rdt_domain *d; +struct rdt_mondomain *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_mondomain, 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_mondomain *dom,unsigned long delay_ms) {unsigned long delay =msecs_to_jiffies (delay_ms);int cpu;
@@ -674,7 +674,7 @@ void mbm_handle_overflow(struct work_struct *work)int cpu =smp_processor_id ();struct list_head *head;struct rdt_resource *r; -struct rdt_domain *d; +struct rdt_mondomain *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_mondomain, 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_mondomain *dom,unsigned long delay_ms) {unsigned long delay =msecs_to_jiffies (delay_ms);int cpu;
arch/x86/kernel/cpu/resctrl/rdtgroup.c +12 -12
@@ -1483,7 +1483,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_mondomain *d,struct mon_config_info *mon_info) {smp_call_function_any (&d->cpu_mask, mon_event_config_read, mon_info,1 ); }
@@ -1491,7 +1491,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_mondomain *dom;bool sep = false;mutex_lock (&rdtgroup_mutex);
@@ -1548,7 +1548,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_mondomain *d,u32 evtid,u32 val) {struct mon_config_info mon_info = {0 };int ret =0 ;
@@ -1598,7 +1598,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_mondomain *d;int ret =0 ; next:
@@ -2463,7 +2463,7 @@ static void schemata_list_destroy(void)static int rdt_get_tree (struct fs_context *fc) {struct rdt_fs_context *ctx =rdt_fc2context (fc); -struct rdt_domain *dom; +struct rdt_mondomain *dom;struct rdt_resource *r;int ret;
@@ -2845,7 +2845,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_mondomain *d,struct rdt_resource *r,struct rdtgroup *prgrp) {union mon_data_bits priv;
@@ -2894,7 +2894,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_mondomain *d) {struct kernfs_node *parent_kn;struct rdtgroup *prgrp, *crgrp;
@@ -2916,7 +2916,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_mondomain *dom;int ret;list_for_each_entry (dom, &r->mondomains, list) {
@@ -3701,7 +3701,7 @@ static int __init rdtgroup_setup_root(void)return ret; } -static void domain_destroy_mon_state (struct rdt_domain *d) +static void domain_destroy_mon_state (struct rdt_mondomain *d) {bitmap_free (d->rmid_busy_llc);kfree (d->mbm_total);
@@ -3716,7 +3716,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_mondomain *d) {lockdep_assert_held (&rdtgroup_mutex);
@@ -3745,7 +3745,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_mondomain *d) {size_t tsize;
@@ -3786,7 +3786,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_mondomain *d) {int err;
Signature · 1 line
2.40.1
Reinette Chatre
maintainerRe: [PATCH v4 3/7] x86/resctrl: Change monitor code to use rdt_mondomain
Hi Tony,
Quoted 3 lines · Tony Luck
A few functions need to be duplicated to provide versions to operate on control and monitor domains respectively. But most of the changes are just fixing argument and return value types.
Could you please add some context in support of this change?
I do not think "duplicated" is appropriate though. Functions are not duplicated but instead made to be dedicated to either control or monitoring domains, no?
...
Quoted 9 lines
arch/x86/kernel/cpu/resctrl/core.c +1
-0@@ -393,9 +393,12 @@ void rdt_ctrl_update(void *arg)* 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. +*
arch/x86/kernel/cpu/resctrl/core.c void rdt_ctrl_update(void *arg) · line 404
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/core.c +4
-2+* N.B. Returned value may be either a pointer to "struct rdt_domain" or +* to "struct rdt_mondomain" depending on which domain list is scanned. */ -struct rdt_domain *rdt_find_domain (struct list_head *h,int id, -struct list_head **pos) +void *rdt_find_domain (struct list_head *h,int id, +struct list_head **pos) {struct rdt_domain *d;struct list_head *l;
I do not think that void pointers should be passed around. How about two new functions dedicated to the different domain types with the void pointer handling contained in a static function? For example,
static void *__rdt_find_domain(struct list_head *h, int id, struct list_head **pos)
struct rdt_mondomain *rdt_find_mondomain(struct rdt_resource *r, int id, struct list_head **pos) struct rdt_domain *rdt_find_ctrldomain(struct rdt_resource *r, int id, struct list_head **pos)
rdt_find_mondomain() and rdt_find_ctrldomain() would be what callers use while they can be wrappers of __rdt_find_domain().
Quoted 27 lines
arch/x86/kernel/cpu/resctrl/core.c +7
-2@@ -434,10 +437,15 @@ static void setup_default_ctrlval(struct rdt_resource *r, u32 *dc) }static void domain_free (struct rdt_hw_domain *hw_dom) +{ +kfree (hw_dom->ctrl_val); +kfree (hw_dom); +} + +static void mondomain_free (struct rdt_hw_mondomain *hw_dom) {kfree (hw_dom->arch_mbm_total);kfree (hw_dom->arch_mbm_local); -kfree (hw_dom->ctrl_val);kfree (hw_dom); }@@ -467,7 +475,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_mondomain *hw_dom) {size_t tsize;
arch/x86/kernel/cpu/resctrl/core.c static void domain_add_cpu_mon(int cpu, struct rdt_resource *r) · line 553
Quoted 9 lines
arch/x86/kernel/cpu/resctrl/core.c +2
-2@@ -539,8 +547,8 @@ static void domain_add_cpu_mon(int cpu, struct rdt_resource *r) {int id =get_cpu_cacheinfo_id (cpu, r->mon_scope);struct list_head *add_pos =NULL ; -struct rdt_hw_domain *hw_dom; -struct rdt_domain *d; +struct rdt_hw_mondomain *hw_mondom; +struct rdt_mondomain *d;int err;
Please ensure that reverse fir tree order is maintained in all these changes.
Reinette
Tony Luck
maintainerRe: [PATCH v4 3/7] x86/resctrl: Change monitor code to use rdt_mondomain
Quoted 7 lines · Reinette Chatre
Hi Tony,
Quoted 3 lines · Tony Luck
A few functions need to be duplicated to provide versions to operate on control and monitor domains respectively. But most of the changes are just fixing argument and return value types.
Quoted 5 lines
Could you please add some context in support of this change?
I do not think "duplicated" is appropriate though. Functions are not duplicated but instead made to be dedicated to either control or monitoring domains, no?
Commit comment rewritten based on these suggestions
Quoted 27 lines
...
Quoted 9 lines
arch/x86/kernel/cpu/resctrl/core.c +1
-0@@ -393,9 +393,12 @@ void rdt_ctrl_update(void *arg)* 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. +* arch/x86/kernel/cpu/resctrl/core.c void rdt_ctrl_update(void *arg) · line 404
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/core.c +4
-2+* N.B. Returned value may be either a pointer to "struct rdt_domain" or +* to "struct rdt_mondomain" depending on which domain list is scanned. */ -struct rdt_domain *rdt_find_domain (struct list_head *h,int id, -struct list_head **pos) +void *rdt_find_domain (struct list_head *h,int id, +struct list_head **pos) {struct rdt_domain *d;struct list_head *l;I do not think that void pointers should be passed around. How about two new functions dedicated to the different domain types with the void pointer handling contained in a static function? For example,
Quoted 7 lines
static void *__rdt_find_domain(struct
list_head*h, int id, structlist_head**pos)struct
rdt_mondomain*rdt_find_mondomain(structrdt_resource*r, int id, structlist_head**pos) structrdt_domain*rdt_find_ctrldomain(structrdt_resource*r, int id, structlist_head**pos)
rdt_find_mondomain()andrdt_find_ctrldomain()would be what callers use while they can be wrappers of__rdt_find_domain().
Good suggestion. Initial bits are in patch 1. Types changed later after struct rdt_mondomain is added.
Quoted 28 lines
Quoted 28 lines
arch/x86/kernel/cpu/resctrl/core.c +7
-2@@ -434,10 +437,15 @@ static void setup_default_ctrlval(struct rdt_resource *r, u32 *dc) }static void domain_free (struct rdt_hw_domain *hw_dom) +{ +kfree (hw_dom->ctrl_val); +kfree (hw_dom); +} + +static void mondomain_free (struct rdt_hw_mondomain *hw_dom) {kfree (hw_dom->arch_mbm_total);kfree (hw_dom->arch_mbm_local); -kfree (hw_dom->ctrl_val);kfree (hw_dom); }@@ -467,7 +475,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_mondomain *hw_dom) {size_t tsize;
Quoted 12 lines
arch/x86/kernel/cpu/resctrl/core.c static void domain_add_cpu_mon(int cpu, struct rdt_resource *r) · line 553
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/core.c +2
-2@@ -539,8 +547,8 @@ static void domain_add_cpu_mon(int cpu, struct rdt_resource *r) {int id =get_cpu_cacheinfo_id (cpu, r->mon_scope);struct list_head *add_pos =NULL ; -struct rdt_hw_domain *hw_dom; -struct rdt_domain *d; +struct rdt_hw_mondomain *hw_mondom; +struct rdt_mondomain *d;int err;Please ensure that reverse fir tree order is maintained in all these changes.
Oops. Fixed this one and looked around for any others introduced by me.
Quoted 2 lines
Reinette
-Tony
Tony Luck
maintainerPATCH v4 4/7 x86/resctrl: Delete unused fields from struct rdt_domain
In reply to Tony LuckNow that all the monitoring functions use struct rdt_mondomain the monitor fields can be dropped from the structure used for control operations.
--- include/linux/resctrl.h | 14 -------------- arch/x86/kernel/cpu/resctrl/internal.h | 4 ---- 2 files changed, 18 deletions(-)
include/linux/resctrl.h +0 -14
@@ -57,13 +57,6 @@ struct resctrl_staged_config {* @list: all instances of this resource * @id: unique id for this instance * @cpu_mask: which CPUs share this resource -* @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 -* @mbm_over: worker to periodically read MBM h/w counters -* @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
@@ -74,13 +67,6 @@ struct rdt_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;struct pseudo_lock_region *plr;struct resctrl_staged_config staged_config[CDP_NUM_TYPES ];u32 *mbps_val;
arch/x86/kernel/cpu/resctrl/internal.h +0 -4
@@ -323,16 +323,12 @@ struct arch_mbm_state {* a control resource * @d_resctrl: Properties exposed to the resctrl file system * @ctrl_val: array of cache or mem ctrl values (indexed by CLOSID) -* @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 arch_mbm_state *arch_mbm_total; -struct arch_mbm_state *arch_mbm_local; };/**
Signature · 1 line
2.40.1
Reinette Chatre
maintainerRe: [PATCH v4 4/7] x86/resctrl: Delete unused fields from struct rdt_domain
Hi Tony,
Quoted 3 lines · Tony Luck
Now that all the monitoring functions use struct
rdt_mondomainthe monitor fields can be dropped from the structure used for control operations.
Please provide some context for this patch so that it can stand by itself when merged.
Note that two structures are changed in the patch.
Reinette
Tony Luck
maintainerRe: [PATCH v4 4/7] x86/resctrl: Delete unused fields from struct rdt_domain
Quoted 7 lines · Reinette Chatre
Hi Tony,
Quoted 3 lines · Tony Luck
Now that all the monitoring functions use struct
rdt_mondomainthe monitor fields can be dropped from the structure used for control operations.
Quoted 6 lines
Please provide some context for this patch so that it can stand by itself when merged.
Note that two structures are changed in the patch.
Reinette
Commit comment rewritten.
-Tony
Tony Luck
maintainerPATCH v4 5/7 x86/resctrl: Determine if Sub-NUMA Cluster is enabled and initialize.
In reply to Tony LuckThere isn't a simple hardware enumeration to indicate to software that a system is running with Sub-NUMA Cluster enabled.
Compare the number of NUMA nodes with the number of L3 caches to calculate the number of Sub-NUMA nodes per L3 cache.
When Sub-NUMA cluster mode is enabled in BIOS setup the RMID counters are distributed equally between the SNC nodes within each socket.
E.g. if there are 400 RMID counters, and the system is configured with two SNC nodes per socket, then RMID counter 0..199 are used on SNC node 0 on the socket, and RMID counter 200..399 on SNC node 1.
A model specific MSR (0xca0) can change the configuration of the RMIDs when SNC mode is enabled.
The MSR controls the interpretation of the RMID field in the IA32_PQR_ASSOC MSR so that the appropriate hardware counters within the SNC node are updated.
To read the RMID counters an offset must be used to get data from the physical counter associated with the SNC node. As in the example above with 400 RMID counters Linux sees only 200 counters. No special action is needed to read a counter from the first SNC node on a socket. But to read a Linux visible counter 50 on the second SNC node the kernel must load 250 into the QM_EVTSEL MSR.
N.B. this works well for well-behaved NUMA applications that access memory predominantly from the local memory node. For applications that access memory across multiple nodes it may be necessary for the user to read counters for all SNC nodes on a socket and add the values to get the actual LLC occupancy or memory bandwidth. Perhaps this isn't all that different from applications that span across multiple sockets in a legacy system.
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. Adjust the value reported in the resctrl "size" file accordingly.
Mounting the file system with the "mba_MBps" option is disabled when SNC mode is enabled. This is because the measurement of bandwidth is per SNC node, while the MBA throttling controls are still at the L3 cache scope.
--- include/linux/resctrl.h | 2 + arch/x86/include/asm/msr-index.h | 1 + arch/x86/kernel/cpu/resctrl/internal.h | 2 + arch/x86/kernel/cpu/resctrl/core.c | 82 +++++++++++++++++++++++++- arch/x86/kernel/cpu/resctrl/monitor.c | 18 +++++- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 4 +- 6 files changed, 103 insertions(+), 6 deletions(-)
include/linux/resctrl.h +2 -0
@@ -200,6 +200,8 @@ struct rdt_resource {bool cdp_capable; }; +#define MON_SCOPE_NODE 100 +/** * struct resctrl_schema - configuration abilities of a resource presented to * user-space
arch/x86/include/asm/msr-index.h +1 -0
@@ -1087,6 +1087,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/internal.h +2 -0
@@ -446,6 +446,8 @@ DECLARE_STATIC_KEY_FALSE(rdt_alloc_enable_key);extern struct dentry *debugfs_resctrl; +extern int snc_nodes_per_l3_cache; +enum resctrl_res_level {RDT_RESOURCE_L3 ,RDT_RESOURCE_L2 ,
arch/x86/kernel/cpu/resctrl/core.c +81 -1
129 lines not on this page · raw message
arch/x86/kernel/cpu/resctrl/monitor.c +15 -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 =get_cpu (); +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,9 +168,11 @@ 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); +put_cpu (); +if (msr_val &RMID_VAL_ERROR )return -EIO ;if (msr_val &RMID_VAL_UNAVAIL )
@@ -783,8 +795,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 +2 -2
@@ -1354,7 +1354,7 @@ unsigned int rdtgroup_cbm_to_size(struct rdt_resource *r, } } -return size; +return size / snc_nodes_per_l3_cache; }/**
@@ -2587,7 +2587,7 @@ static int rdt_parse_param(struct fs_context *fc, struct fs_parameter *param) ctx->enable_cdpl2 = true;return 0 ;case Opt_mba_mbps: -if (!supports_mba_mbps ()) +if (!supports_mba_mbps () || snc_nodes_per_l3_cache >1 )return -EINVAL ; ctx->enable_mba_mbps = true;return 0 ;
Signature · 1 line
2.40.1
Reinette Chatre
maintainerRe: [PATCH v4 5/7] x86/resctrl: Determine if Sub-NUMA Cluster is enabled and initialize.
Hi Tony,
Quoted 42 lines · Tony Luck
There isn't a simple hardware enumeration to indicate to software that a system is running with Sub-NUMA Cluster enabled.
Compare the number of NUMA nodes with the number of L3 caches to calculate the number of Sub-NUMA nodes per L3 cache.
When Sub-NUMA cluster mode is enabled in BIOS setup the RMID counters are distributed equally between the SNC nodes within each socket.
E.g. if there are 400 RMID counters, and the system is configured with two SNC nodes per socket, then RMID counter 0..199 are used on SNC node 0 on the socket, and RMID counter 200..399 on SNC node 1.
A model specific MSR (
0xca0) can change the configuration of the RMIDs when SNC mode is enabled.The MSR controls the interpretation of the RMID field in the
IA32_PQR_ASSOCMSR so that the appropriate hardware counters within the SNC node are updated.To read the RMID counters an offset must be used to get data from the physical counter associated with the SNC node. As in the example above with 400 RMID counters Linux sees only 200 counters. No special action is needed to read a counter from the first SNC node on a socket. But to read a Linux visible counter 50 on the second SNC node the kernel must load 250 into the
QM_EVTSELMSR.N.B. this works well for well-behaved NUMA applications that access memory predominantly from the local memory node. For applications that access memory across multiple nodes it may be necessary for the user to read counters for all SNC nodes on a socket and add the values to get the actual LLC occupancy or memory bandwidth. Perhaps this isn't all that different from applications that span across multiple sockets in a legacy system.
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. Adjust the value reported in the resctrl "size" file accordingly.
Quoted 5 lines
Mounting the file system with the "
mba_MBps" option is disabled when SNC mode is enabled. This is because the measurement of bandwidth is per SNC node, while the MBA throttling controls are still at the L3 cache scope.
I'm counting four logical changes in this changelog. Can they be separate patches?
Quoted 15 lines
Signed-off-by Tony Luck <[email protected]>--- include/linux/resctrl.h | 2 + arch/x86/include/asm/msr-index.h | 1 + arch/x86/kernel/cpu/resctrl/internal.h | 2 + arch/x86/kernel/cpu/resctrl/core.c | 82 +++++++++++++++++++++++++- arch/x86/kernel/cpu/resctrl/monitor.c | 18 +++++- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 4 +- 6 files changed, 103 insertions(+), 6 deletions(-)include/linux/resctrl.h +0
-0
include/linux/resctrl.h struct rdt_resource { · line 204
Quoted 5 lines
include/linux/resctrl.h +2
-0@@ -200,6 +200,8 @@ struct rdt_resource {bool cdp_capable; }; +#define MON_SCOPE_NODE 100 +
Could you please add a comment to explain what this constant represents and how it is used?
Quoted 33 lines
include/linux/resctrl.h +0
-0/** * struct resctrl_schema - configuration abilities of a resource presented to * user-space arch/x86/include/asm/msr-index.h +1
-0@@ -1087,6 +1087,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/internal.h +2
-0@@ -446,6 +446,8 @@ DECLARE_STATIC_KEY_FALSE(rdt_alloc_enable_key);extern struct dentry *debugfs_resctrl; +extern int snc_nodes_per_l3_cache; +enum resctrl_res_level {RDT_RESOURCE_L3 ,RDT_RESOURCE_L2 ,arch/x86/kernel/cpu/resctrl/core.c +0
-0
arch/x86/kernel/cpu/resctrl/core.c line 25
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/core.c +2
-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>
What does this include provide?
Quoted 37 lines
arch/x86/kernel/cpu/resctrl/core.c +16
-1+#include <asm/cpu_device_id.h> #include <asm/intel-family.h> #include <asm/resctrl.h> #include "internal.h" @@ -48,6 +51,13 @@ 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. +*/ +int snc_nodes_per_l3_cache =1 ; +static void mba_wrmsr_intel (struct rdt_domain *d,struct msr_param *m,struct rdt_resource *r);@@ -543,9 +553,16 @@ static void domain_add_cpu_ctrl(int cpu, struct rdt_resource *r) } } +static int get_mon_scope_id (int cpu,int scope) +{ +if (scope ==MON_SCOPE_NODE ) +return cpu_to_node (cpu); +return get_cpu_cacheinfo_id (cpu, scope); +} +static void domain_add_cpu_mon (int cpu,struct rdt_resource *r) { -int id =get_cpu_cacheinfo_id (cpu, r->mon_scope); +int id =get_mon_scope_id (cpu, r->mon_scope);struct list_head *add_pos =NULL ;struct rdt_hw_mondomain *hw_mondom;struct rdt_mondomain *d;
arch/x86/kernel/cpu/resctrl/core.c static void clear_closid_rmid(int cpu) · line 714
Quoted 6 lines
arch/x86/kernel/cpu/resctrl/core.c +3
-0@@ -692,11 +709,28 @@ static void clear_closid_rmid(int cpu)wrmsr (MSR_IA32_PQR_ASSOC ,0 ,0 ); } +static void snc_remap_rmids (int cpu) +{ +u64 val;
No need for tab here.
arch/x86/kernel/cpu/resctrl/core.c static void clear_closid_rmid(int cpu) · line 723
Quoted 9 lines
arch/x86/kernel/cpu/resctrl/core.c +9
-0+ +/* 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); +}
Could you please document snc_remap_rmids() with information on what the bit in the register means and what the above function does?
Quoted 14 lines
arch/x86/kernel/cpu/resctrl/core.c +5
-0+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. */
arch/x86/kernel/cpu/resctrl/core.c static __init bool get_rdt_resources(void) · line 987
Quoted 3 lines
arch/x86/kernel/cpu/resctrl/core.c +0
-0@@ -951,11 +985,57 @@ static __init bool get_rdt_resources(void)return (rdt_mon_capable || rdt_alloc_capable); }
I think it will help to add a comment like:
"CPUs that support the model specific MSR_RMID_SNC_CONFIG register."
Quoted 24 lines
arch/x86/kernel/cpu/resctrl/core.c +24
-0+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 ), + {} +}; + +/* +* There isn't a simple enumeration bit to show whether SNC mode +* is enabled. Look at the ratio of number of NUMA nodes to the +* number of distinct L3 caches. Take care to skip memory-only nodes. +*/ +static __init int get_snc_config (void ) +{ +unsigned long *node_caches; +int mem_only_nodes =0 ; +int cpu, node, ret; + +if (!x86_match_cpu (snc_cpu_ids)) +return 1 ; + + node_caches =kcalloc (BITS_TO_LONGS (nr_node_ids),sizeof (*node_caches),GFP_KERNEL ); +if (!node_caches) +return 1 ;
arch/x86/kernel/cpu/resctrl/core.c static __init bool get_rdt_resources(void) · line 1021
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/core.c +10
-0+ +cpus_read_lock (); +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 + mem_only_nodes++; + } +cpus_read_unlock ();
I am not familiar with the numa code at all so please correct me where I am wrong. I do see that nr_node_ids is initialized with __init code so it should be accurate at this point. It looks to me like this initialization assumes that at least one CPU per node will be online at the time it is run. It is not clear to me that this assumption would always be true.
Quoted 25 lines
arch/x86/kernel/cpu/resctrl/core.c +12
-0+ + ret = (nr_node_ids - mem_only_nodes) /bitmap_weight (node_caches, nr_node_ids); +kfree (node_caches); + +if (ret >1 ) + rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl.mon_scope =MON_SCOPE_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 =get_snc_config (); +for_each_rdt_resource (r) { hw_res =resctrl_to_arch_res (r);arch/x86/kernel/cpu/resctrl/monitor.c +0
-0
arch/x86/kernel/cpu/resctrl/monitor.c static inline struct rmid_entry *__rmid_entry(u32 rmid) · line 152
Quoted 5 lines
arch/x86/kernel/cpu/resctrl/monitor.c +2
-0@@ -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 =get_cpu ();
I do not think it is necessary to disable preemption here. Also please note that James is working on changes to not have this code block. Could just smp_processor_id() do?
Quoted 16 lines
arch/x86/kernel/cpu/resctrl/monitor.c +8
-0+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,9 +168,11 @@ 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.
arch/x86/kernel/cpu/resctrl/monitor.c static int __rmid_read(u32 rmid, enum resctrl_event_id eventid, u64 *val) · line 178
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/monitor.c +3
-1*/ -wrmsr (MSR_IA32_QM_EVTSEL , eventid, rmid); +wrmsr (MSR_IA32_QM_EVTSEL , eventid, rmid + rmid_offset);rdmsrl (MSR_IA32_QM_CTR , msr_val); +put_cpu (); +if (msr_val &RMID_VAL_ERROR )return -EIO ;if (msr_val &RMID_VAL_UNAVAIL )
Reinette
Tony Luck
maintainerRe: [PATCH v4 5/7] x86/resctrl: Determine if Sub-NUMA Cluster is enabled and initialize.
Quoted 45 lines · Reinette Chatre
Hi Tony,
Quoted 42 lines · Tony Luck
There isn't a simple hardware enumeration to indicate to software that a system is running with Sub-NUMA Cluster enabled.
Compare the number of NUMA nodes with the number of L3 caches to calculate the number of Sub-NUMA nodes per L3 cache.
When Sub-NUMA cluster mode is enabled in BIOS setup the RMID counters are distributed equally between the SNC nodes within each socket.
E.g. if there are 400 RMID counters, and the system is configured with two SNC nodes per socket, then RMID counter 0..199 are used on SNC node 0 on the socket, and RMID counter 200..399 on SNC node 1.
A model specific MSR (
0xca0) can change the configuration of the RMIDs when SNC mode is enabled.The MSR controls the interpretation of the RMID field in the
IA32_PQR_ASSOCMSR so that the appropriate hardware counters within the SNC node are updated.To read the RMID counters an offset must be used to get data from the physical counter associated with the SNC node. As in the example above with 400 RMID counters Linux sees only 200 counters. No special action is needed to read a counter from the first SNC node on a socket. But to read a Linux visible counter 50 on the second SNC node the kernel must load 250 into the
QM_EVTSELMSR.N.B. this works well for well-behaved NUMA applications that access memory predominantly from the local memory node. For applications that access memory across multiple nodes it may be necessary for the user to read counters for all SNC nodes on a socket and add the values to get the actual LLC occupancy or memory bandwidth. Perhaps this isn't all that different from applications that span across multiple sockets in a legacy system.
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. Adjust the value reported in the resctrl "size" file accordingly.
Quoted 8 lines
Quoted 5 lines
Mounting the file system with the "
mba_MBps" option is disabled when SNC mode is enabled. This is because the measurement of bandwidth is per SNC node, while the MBA throttling controls are still at the L3 cache scope.I'm counting four logical changes in this changelog. Can they be separate patches?
Split into three parts. I couln't quite see how to get to four.
Quoted 19 lines
Quoted 19 lines
Signed-off-by Tony Luck <[email protected]>--- include/linux/resctrl.h | 2 + arch/x86/include/asm/msr-index.h | 1 + arch/x86/kernel/cpu/resctrl/internal.h | 2 + arch/x86/kernel/cpu/resctrl/core.c | 82 +++++++++++++++++++++++++- arch/x86/kernel/cpu/resctrl/monitor.c | 18 +++++- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 4 +- 6 files changed, 103 insertions(+), 6 deletions(-)include/linux/resctrl.h +0
-0@@ -200,6 +200,8 @@ struct rdt_resource {bool cdp_capable; };
Quoted 5 lines
include/linux/resctrl.h struct rdt_resource { · line 204
Quoted 2 lines
include/linux/resctrl.h +2
-0+#define MON_SCOPE_NODE 100 +Could you please add a comment to explain what this constant represents and how it is used?
This is gone in V6. It's become part of an "enum" for each of the scope options.
Quoted 37 lines
Quoted 37 lines
include/linux/resctrl.h +0
-0/** * struct resctrl_schema - configuration abilities of a resource presented to * user-space arch/x86/include/asm/msr-index.h +1
-0@@ -1087,6 +1087,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/internal.h +2
-0@@ -446,6 +446,8 @@ DECLARE_STATIC_KEY_FALSE(rdt_alloc_enable_key);extern struct dentry *debugfs_resctrl; +extern int snc_nodes_per_l3_cache; +enum resctrl_res_level {RDT_RESOURCE_L3 ,RDT_RESOURCE_L2 ,arch/x86/kernel/cpu/resctrl/core.c +0
-0@@ -16,11 +16,14 @@#define pr_fmt (fmt) "resctrl: " fmt
Quoted 9 lines
arch/x86/kernel/cpu/resctrl/core.c line 25
Quoted 7 lines
arch/x86/kernel/cpu/resctrl/core.c +2
-0+#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> What does this include provide?
This header provides the defintion of struct x86_cpu_id.
Quoted 41 lines
Quoted 41 lines
arch/x86/kernel/cpu/resctrl/core.c +16
-1+#include <asm/cpu_device_id.h> #include <asm/intel-family.h> #include <asm/resctrl.h> #include "internal.h" @@ -48,6 +51,13 @@ 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. +*/ +int snc_nodes_per_l3_cache =1 ; +static void mba_wrmsr_intel (struct rdt_domain *d,struct msr_param *m,struct rdt_resource *r);@@ -543,9 +553,16 @@ static void domain_add_cpu_ctrl(int cpu, struct rdt_resource *r) } } +static int get_mon_scope_id (int cpu,int scope) +{ +if (scope ==MON_SCOPE_NODE ) +return cpu_to_node (cpu); +return get_cpu_cacheinfo_id (cpu, scope); +} +static void domain_add_cpu_mon (int cpu,struct rdt_resource *r) { -int id =get_cpu_cacheinfo_id (cpu, r->mon_scope); +int id =get_mon_scope_id (cpu, r->mon_scope);struct list_head *add_pos =NULL ;struct rdt_hw_mondomain *hw_mondom;struct rdt_mondomain *d;@@ -692,11 +709,28 @@ static void clear_closid_rmid(int cpu)wrmsr (MSR_IA32_PQR_ASSOC ,0 ,0 ); }
Quoted 5 lines
arch/x86/kernel/cpu/resctrl/core.c static void clear_closid_rmid(int cpu) · line 714
Quoted 3 lines
arch/x86/kernel/cpu/resctrl/core.c +3
-0+static void snc_remap_rmids (int cpu) +{ +u64 val;No need for tab here.
Turned into a <SPACE>
Quoted 14 lines
arch/x86/kernel/cpu/resctrl/core.c static void clear_closid_rmid(int cpu) · line 723
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/core.c +9
-0+ +/* 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); +}Could you please document
snc_remap_rmids()with information on what the bit in the register means and what the above function does?
Added header comment for this function describing the MSR and the function.
Quoted 6 lines
Quoted 6 lines
arch/x86/kernel/cpu/resctrl/core.c +1
-0+static int resctrl_online_cpu (unsigned int cpu) {struct rdt_resource *r;
Quoted 15 lines
arch/x86/kernel/cpu/resctrl/core.c static __init bool get_rdt_resources(void) · line 987
Quoted 12 lines
arch/x86/kernel/cpu/resctrl/core.c +4
-0mutex_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. */ @@ -951,11 +985,57 @@ static __init bool get_rdt_resources(void)return (rdt_mon_capable || rdt_alloc_capable); }I think it will help to add a comment like:
"CPUs that support the model specificMSR_RMID_SNC_CONFIGregister."
Done.
Quoted 33 lines
Quoted 33 lines
arch/x86/kernel/cpu/resctrl/core.c +32
-0+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 ), + {} +}; + +/* +* There isn't a simple enumeration bit to show whether SNC mode +* is enabled. Look at the ratio of number of NUMA nodes to the +* number of distinct L3 caches. Take care to skip memory-only nodes. +*/ +static __init int get_snc_config (void ) +{ +unsigned long *node_caches; +int mem_only_nodes =0 ; +int cpu, node, ret; + +if (!x86_match_cpu (snc_cpu_ids)) +return 1 ; + + node_caches =kcalloc (BITS_TO_LONGS (nr_node_ids),sizeof (*node_caches),GFP_KERNEL ); +if (!node_caches) +return 1 ; + +cpus_read_lock (); +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 + mem_only_nodes++;
Quoted 8 lines
arch/x86/kernel/cpu/resctrl/core.c static __init bool get_rdt_resources(void) · line 1021
Quoted 2 lines
arch/x86/kernel/cpu/resctrl/core.c +2
-0+ } +cpus_read_unlock ();I am not familiar with the numa code at all so please correct me where I am wrong. I do see that
nr_node_idsis initialized with__initcode so it should be accurate at this point. It looks to me like this initialization assumes that at least one CPU per node will be online at the time it is run. It is not clear to me that this assumption would always be true.
Resctrl initialization is kicked off as a late_initcall(). So all CPUs and devices are fully initialized before this code runs.
Resctrl can't be moved to an "init" state before CPUs are brought online because it makes a call to cpuhp_setup_state() to get callbacks for online/offline CPU events ... that call can't be done early.
Quoted 27 lines
Quoted 27 lines
arch/x86/kernel/cpu/resctrl/core.c +12
-0+ + ret = (nr_node_ids - mem_only_nodes) /bitmap_weight (node_caches, nr_node_ids); +kfree (node_caches); + +if (ret >1 ) + rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl.mon_scope =MON_SCOPE_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 =get_snc_config (); +for_each_rdt_resource (r) { hw_res =resctrl_to_arch_res (r);arch/x86/kernel/cpu/resctrl/monitor.c +0
-0@@ -148,8 +148,18 @@ static inline struct rmid_entry *__rmid_entry(u32 rmid)
Quoted 8 lines
arch/x86/kernel/cpu/resctrl/monitor.c static inline struct rmid_entry *__rmid_entry(u32 rmid) · line 152
Quoted 4 lines
arch/x86/kernel/cpu/resctrl/monitor.c +2
-0static 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 =get_cpu ();I do not think it is necessary to disable preemption here. Also please note that James is working on changes to not have this code block. Could just
smp_processor_id()do?
Not needed to disable pre-emption - because it is already disabled ... call sequence to get to here comes through smp_call_function_single() which does it's own get_cpu()). Will change this code to use smp_processor_id()
Quoted 22 lines
Quoted 22 lines
arch/x86/kernel/cpu/resctrl/monitor.c +9
-1+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,9 +168,11 @@ 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);
Quoted 7 lines
arch/x86/kernel/cpu/resctrl/monitor.c static int __rmid_read(u32 rmid, enum resctrl_event_id eventid, u64 *val) · line 178
Quoted 5 lines
arch/x86/kernel/cpu/resctrl/monitor.c +2
-0+put_cpu (); +if (msr_val &RMID_VAL_ERROR )return -EIO ;if (msr_val &RMID_VAL_UNAVAIL )Reinette
-Tony
Reinette Chatre
maintainerRe: [PATCH v4 5/7] x86/resctrl: Determine if Sub-NUMA Cluster is enabled and initialize.
Hi Tony,
Quoted 2 lines · Tony Luck
Quoted 1 line · Reinette Chatre
On 7/22/2023 12:07 PM, Tony Luck wrote:
...
Quoted 41 lines
Quoted 32 lines
Quoted 32 lines
arch/x86/kernel/cpu/resctrl/core.c +32
-0+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 ), + {} +}; + +/* +* There isn't a simple enumeration bit to show whether SNC mode +* is enabled. Look at the ratio of number of NUMA nodes to the +* number of distinct L3 caches. Take care to skip memory-only nodes. +*/ +static __init int get_snc_config (void ) +{ +unsigned long *node_caches; +int mem_only_nodes =0 ; +int cpu, node, ret; + +if (!x86_match_cpu (snc_cpu_ids)) +return 1 ; + + node_caches =kcalloc (BITS_TO_LONGS (nr_node_ids),sizeof (*node_caches),GFP_KERNEL ); +if (!node_caches) +return 1 ; + +cpus_read_lock (); +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 + mem_only_nodes++;Quoted 8 lines
arch/x86/kernel/cpu/resctrl/core.c static __init bool get_rdt_resources(void) · line 1021
Quoted 2 lines
arch/x86/kernel/cpu/resctrl/core.c +2
-0+ } +cpus_read_unlock ();I am not familiar with the numa code at all so please correct me where I am wrong. I do see that
nr_node_idsis initialized with__initcode so it should be accurate at this point. It looks to me like this initialization assumes that at least one CPU per node will be online at the time it is run. It is not clear to me that this assumption would always be true.
Quoted 6 lines
Resctrl initialization is kicked off as a
late_initcall(). So all CPUs and devices are fully initialized before this code runs.Resctrl can't be moved to an "init" state before CPUs are brought online because it makes a call to
cpuhp_setup_state()to get callbacks for online/offline CPU events ... that call can't be done early.
Apologies but this is not so obvious to me. From what I understand a system need not be booted with all CPUs online. CPUs can be brought online at any time.
Quoted 10 lines
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/core.c static __init bool get_rdt_resources(void) · line 1031
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/core.c +10
-0+ + ret = (nr_node_ids - mem_only_nodes) /bitmap_weight (node_caches, nr_node_ids); +kfree (node_caches); + +if (ret >1 ) + rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl.mon_scope =MON_SCOPE_NODE ; + +return ret; +} +
Reinette
Tony Luck
maintainerRe: [PATCH v4 5/7] x86/resctrl: Determine if Sub-NUMA Cluster is enabled and initialize.
Quoted 52 lines · Reinette Chatre
Hi Tony,
Quoted 2 lines · Tony Luck
Quoted 1 line · Reinette Chatre
On 7/22/2023 12:07 PM, Tony Luck wrote:
...
Quoted 44 lines
Quoted 32 lines
Quoted 32 lines
arch/x86/kernel/cpu/resctrl/core.c +32
-0+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 ), + {} +}; + +/* +* There isn't a simple enumeration bit to show whether SNC mode +* is enabled. Look at the ratio of number of NUMA nodes to the +* number of distinct L3 caches. Take care to skip memory-only nodes. +*/ +static __init int get_snc_config (void ) +{ +unsigned long *node_caches; +int mem_only_nodes =0 ; +int cpu, node, ret; + +if (!x86_match_cpu (snc_cpu_ids)) +return 1 ; + + node_caches =kcalloc (BITS_TO_LONGS (nr_node_ids),sizeof (*node_caches),GFP_KERNEL ); +if (!node_caches) +return 1 ; + +cpus_read_lock (); +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 + mem_only_nodes++;Quoted 8 lines
arch/x86/kernel/cpu/resctrl/core.c static __init bool get_rdt_resources(void) · line 1021
Quoted 2 lines
arch/x86/kernel/cpu/resctrl/core.c +2
-0+ } +cpus_read_unlock ();I am not familiar with the numa code at all so please correct me where I am wrong. I do see that
nr_node_idsis initialized with__initcode so it should be accurate at this point. It looks to me like this initialization assumes that at least one CPU per node will be online at the time it is run. It is not clear to me that this assumption would always be true.Resctrl initialization is kicked off as a
late_initcall(). So all CPUs and devices are fully initialized before this code runs.
Quoted 7 lines
Quoted 3 lines
Resctrl can't be moved to an "init" state before CPUs are brought online because it makes a call to
cpuhp_setup_state()to get callbacks for online/offline CPU events ... that call can't be done early.Apologies but this is not so obvious to me. From what I understand a system need not be booted with all CPUs online. CPUs can be brought online at any time.
So you are concerned about the case where the system was booted with a maxcpus=N boot argument, and additional CPUs are brought online later?
My code will fail to detect SNC mode if someone does that. I don't see any possible way to recover from this in a safe way later when additional CPUs are brought online. Those CPUs could be brought online in any order by the user, and there is no way to know when they are all done. Without an explicit enumeration of SNC mode there is no fool-proof way to detect SNC mode in the face of CPU hot plug post-boot.
I could add a pr_warn() into this code:
915 static int __init nrcpus(char *str)
916 {
917 int nr_cpus;
918
919 if (get_option(&str, &nr_cpus) && nr_cpus > 0 && nr_cpus < nr_cpu_ids)
920 set_nr_cpu_ids(nr_cpus);
921
922 return 0;
923 }
924
925 early_param("nr_cpus", nrcpus);
But this feels like a "user shot themself in the foot" case. I don't think it necessary to add checks and warnings for every possible strange way a user could configure a system.
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/core.c static __init bool get_rdt_resources(void) · line 1031
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/core.c +10
-0+ + ret = (nr_node_ids - mem_only_nodes) /bitmap_weight (node_caches, nr_node_ids); +kfree (node_caches); + +if (ret >1 ) + rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl.mon_scope =MON_SCOPE_NODE ; + +return ret; +} +
-Tony
Tony Luck
maintainerPATCH v4 6/7 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.
--- Documentation/arch/x86/resctrl.rst | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
Documentation/arch/x86/resctrl.rst +7 -3
@@ -345,9 +345,13 @@ 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. E.g. on a system with + SNC mode disabled with two L3 domains there will be subdirectories + "mon_L3_00" and "mon_L3_01". The numerical suffix refers to the + L3 cache id. With SNC enabled the directory names are the same, + but the numerical suffix refers to the node id. 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
Signature · 1 line
2.40.1
Reinette Chatre
maintainerRe: [PATCH v4 6/7] x86/resctrl: Update documentation with Sub-NUMA cluster changes
Hi Tony,
Quoted 21 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.
Signed-off-by Tony Luck <[email protected]>Reviewed-by Peter Newman <[email protected]>--- Documentation/arch/x86/resctrl.rst | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)Documentation/arch/x86/resctrl.rst +0
-3@@ -345,9 +345,13 @@ 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
Documentation/arch/x86/resctrl.rst When control is enabled all CTRL_MON groups will also contain: · line 357
Quoted 10 lines
Documentation/arch/x86/resctrl.rst +7
-0+ 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. E.g. on a system with + SNC mode disabled with two L3 domains there will be subdirectories + "mon_L3_00" and "mon_L3_01". The numerical suffix refers to the + L3 cache id. With SNC enabled the directory names are the same, + but the numerical suffix refers to the node id. 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
I think it would be helpful to add a modified version of the snippet (from previous patch changelog) regarding well-behaved NUMA apps. With the above it may be confusing that a single cache allocation has multiple cache occupancy counters.
This also changes the meaning of the numbers in the directory names. The documentation already provides guidance on how to find the cache ID of a logical CPU (see section "Cache IDs"). I think it will be helpful to add a snippet that makes it clear to users how to map a CPU to its node ID.
Reinette
Tony Luck
maintainerRe: [PATCH v4 6/7] x86/resctrl: Update documentation with Sub-NUMA cluster changes
Quoted 40 lines · Reinette Chatre
Hi Tony,
Quoted 21 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.
Signed-off-by Tony Luck <[email protected]>Reviewed-by Peter Newman <[email protected]>--- Documentation/arch/x86/resctrl.rst | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)Documentation/arch/x86/resctrl.rst +0
-3@@ -345,9 +345,13 @@ 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 theseDocumentation/arch/x86/resctrl.rst When control is enabled all CTRL_MON groups will also contain: · line 357
Quoted 10 lines
Documentation/arch/x86/resctrl.rst +7
-0+ 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. E.g. on a system with + SNC mode disabled with two L3 domains there will be subdirectories + "mon_L3_00" and "mon_L3_01". The numerical suffix refers to the + L3 cache id. With SNC enabled the directory names are the same, + but the numerical suffix refers to the node id. 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 forI think it would be helpful to add a modified version of the snippet (from previous patch changelog) regarding well-behaved NUMA apps. With the above it may be confusing that a single cache allocation has multiple cache occupancy counters.
Quoted 5 lines
This also changes the meaning of the numbers in the directory names. The documentation already provides guidance on how to find the cache ID of a logical CPU (see section "Cache IDs"). I think it will be helpful to add a snippet that makes it clear to users how to map a CPU to its node ID.
Added extra details as suggested.
Quoted 2 lines
Reinette
-Tony
Tony Luck
maintainerPATCH v4 7/7 selftests/resctrl: Adjust effective L3 cache size when SNC enabled
In reply to Tony LuckSub-NUMA Cluster divides CPUs sharing an L3 cache into separate NUMA nodes. Systems may support splitting into either two or four nodes.
When SNC mode is enabled the effective amount of L3 cache available for allocation is divided by the number of nodes per L3.
Detect which SNC mode is active by comparing the number of CPUs that share a cache with CPU0, with the number of CPUs on node0.
--- tools/testing/selftests/resctrl/resctrl.h | 1 + tools/testing/selftests/resctrl/resctrlfs.c | 57 +++++++++++++++++++++ 2 files changed, 58 insertions(+)
tools/testing/selftests/resctrl/resctrl.h +1 -0
@@ -13,6 +13,7 @@#include <signal.h> #include <dirent.h> #include <stdbool.h> +#include <ctype.h> #include <sys/stat.h> #include <sys/ioctl.h> #include <sys/mount.h>
tools/testing/selftests/resctrl/resctrlfs.c +57 -0
69 lines not on this page · raw message
Signature · 1 line
2.40.1
Reinette Chatre
maintainerRe: [PATCH v4 7/7] selftests/resctrl: Adjust effective L3 cache size when SNC enabled
Hi Tony,
Quoted 11 lines · Tony Luck
Sub-NUMA Cluster divides CPUs sharing an L3 cache into separate NUMA nodes. Systems may support splitting into either two or four nodes.
When SNC mode is enabled the effective amount of L3 cache available for allocation is divided by the number of nodes per L3.
Detect which SNC mode is active by comparing the number of CPUs that share a cache with CPU0, with the number of CPUs on node0.
This does not seem to be the case when looking at
https://lore.kernel.org/all/TYAPR01MB6330A4EB3633B791939EA45E8B39A@TYAPR01MB6330.jpnprd01.prod.outlook.com/
Quoted 85 lines
Signed-off-by Tony Luck <[email protected]>--- tools/testing/selftests/resctrl/resctrl.h | 1 + tools/testing/selftests/resctrl/resctrlfs.c | 57 +++++++++++++++++++++ 2 files changed, 58 insertions(+)tools/testing/selftests/resctrl/resctrl.h +1
-0@@ -13,6 +13,7 @@#include <signal.h> #include <dirent.h> #include <stdbool.h> +#include <ctype.h> #include <sys/stat.h> #include <sys/ioctl.h> #include <sys/mount.h> tools/testing/selftests/resctrl/resctrlfs.c +55
-0@@ -130,6 +130,61 @@ int get_resource_id(int cpu_no, int *resource_id)return 0 ; } +/* +* Count number of CPUs in a /sys bit map +*/ +static int count_sys_bitmap_bits (char *name) +{ +FILE *fp =fopen (name,"r" ); +int count =0 , c; + +if (!fp) +return 0 ; + +while ((c =fgetc (fp)) !=EOF ) { +if (!isxdigit (c)) +continue ; +switch (c) { +case 'f' : + count++; +case '7' :case 'b' :case 'd' :case 'e' : + count++; +case '3' :case '5' :case '6' :case '9' :case 'a' :case 'c' : + count++; +case '1' :case '2' :case '4' :case '8' : + count++; + } + } +fclose (fp); + +return count; +} + +/* +* Detect SNC by compating #CPUs in node0 with #CPUs sharing LLC with CPU0 +* Try to get this right, even if a few CPUs are offline so that the number +* of CPUs in node0 is not exactly half or a quarter of the CPUs sharing the +* LLC of CPU0. +*/ +static int snc_ways (void ) +{ +int node_cpus, cache_cpus; + + node_cpus =count_sys_bitmap_bits ("/sys/devices/system/node/node0/cpumap" ); + cache_cpus =count_sys_bitmap_bits ("/sys/devices/system/cpu/cpu0/cache/index3/shared_cpu_map" ); + +if (!node_cpus || !cache_cpus) { +fprintf (stderr,"Warning could not determine Sub-NUMA Cluster mode\n" ); +return 1 ; + } + +if (4 * node_cpus >= cache_cpus) +return 4 ; +else if (2 * node_cpus >= cache_cpus) +return 2 ; +return 1 ; +} +/* * get_cache_size - Get cache size for a specified CPU * @cpu_no: CPU number
tools/testing/selftests/resctrl/resctrlfs.c int get_cache_size(int cpu_no, char *cache_type, unsigned long *cache_size) · line 252
Quoted 8 lines
tools/testing/selftests/resctrl/resctrlfs.c +2
-0@@ -190,6 +245,8 @@ int get_cache_size(int cpu_no, char *cache_type, unsigned long *cache_size)break ; } +if (cache_num ==3 ) + *cache_size /=snc_ways ();return 0 ; }
I am surprised that this small change is sufficient. The resctrl selftests are definitely not NUMA aware and the CAT and CMT tests are not taking that into account when picking CPUs to run on. From what I understand LLC occupancy counters need to be added in this scenario but I do not see that done either.
Reinette
Tony Luck
maintainerRe: [PATCH v4 7/7] selftests/resctrl: Adjust effective L3 cache size when SNC enabled
Quoted 9 lines · Reinette Chatre
Hi Tony,
Quoted 6 lines · Tony Luck
Sub-NUMA Cluster divides CPUs sharing an L3 cache into separate NUMA nodes. Systems may support splitting into either two or four nodes.
When SNC mode is enabled the effective amount of L3 cache available for allocation is divided by the number of nodes per L3.
Quoted 8 lines
Quoted 5 lines
Detect which SNC mode is active by comparing the number of CPUs that share a cache with CPU0, with the number of CPUs on node0.
This does not seem to be the case when looking at
https://lore.kernel.org/all/TYAPR01MB6330A4EB3633B791939EA45E8B39A@TYAPR01MB6330.jpnprd01.prod.outlook.com/
Correct. I'll drop the "Closes:" tag. I'm not sure what the status is. Shaopeng didn't respond to my suggestion to try "taskset(1)" when running the tests to check if NUMA effects are causing the test to fail.
Quoted 89 lines
Quoted 89 lines
Signed-off-by Tony Luck <[email protected]>--- tools/testing/selftests/resctrl/resctrl.h | 1 + tools/testing/selftests/resctrl/resctrlfs.c | 57 +++++++++++++++++++++ 2 files changed, 58 insertions(+)tools/testing/selftests/resctrl/resctrl.h +1
-0@@ -13,6 +13,7 @@#include <signal.h> #include <dirent.h> #include <stdbool.h> +#include <ctype.h> #include <sys/stat.h> #include <sys/ioctl.h> #include <sys/mount.h> tools/testing/selftests/resctrl/resctrlfs.c +55
-0@@ -130,6 +130,61 @@ int get_resource_id(int cpu_no, int *resource_id)return 0 ; } +/* +* Count number of CPUs in a /sys bit map +*/ +static int count_sys_bitmap_bits (char *name) +{ +FILE *fp =fopen (name,"r" ); +int count =0 , c; + +if (!fp) +return 0 ; + +while ((c =fgetc (fp)) !=EOF ) { +if (!isxdigit (c)) +continue ; +switch (c) { +case 'f' : + count++; +case '7' :case 'b' :case 'd' :case 'e' : + count++; +case '3' :case '5' :case '6' :case '9' :case 'a' :case 'c' : + count++; +case '1' :case '2' :case '4' :case '8' : + count++; + } + } +fclose (fp); + +return count; +} + +/* +* Detect SNC by compating #CPUs in node0 with #CPUs sharing LLC with CPU0 +* Try to get this right, even if a few CPUs are offline so that the number +* of CPUs in node0 is not exactly half or a quarter of the CPUs sharing the +* LLC of CPU0. +*/ +static int snc_ways (void ) +{ +int node_cpus, cache_cpus; + + node_cpus =count_sys_bitmap_bits ("/sys/devices/system/node/node0/cpumap" ); + cache_cpus =count_sys_bitmap_bits ("/sys/devices/system/cpu/cpu0/cache/index3/shared_cpu_map" ); + +if (!node_cpus || !cache_cpus) { +fprintf (stderr,"Warning could not determine Sub-NUMA Cluster mode\n" ); +return 1 ; + } + +if (4 * node_cpus >= cache_cpus) +return 4 ; +else if (2 * node_cpus >= cache_cpus) +return 2 ; +return 1 ; +} +/* * get_cache_size - Get cache size for a specified CPU * @cpu_no: CPU number @@ -190,6 +245,8 @@ int get_cache_size(int cpu_no, char *cache_type, unsigned long *cache_size)break ; }
Quoted 11 lines
tools/testing/selftests/resctrl/resctrlfs.c int get_cache_size(int cpu_no, char *cache_type, unsigned long *cache_size) · line 252
Quoted 5 lines
tools/testing/selftests/resctrl/resctrlfs.c +2
-0+if (cache_num ==3 ) + *cache_size /=snc_ways ();return 0 ; }I am surprised that this small change is sufficient. The resctrl selftests are definitely not NUMA aware and the CAT and CMT tests are not taking that into account when picking CPUs to run on. From what I understand LLC occupancy counters need to be added in this scenario but I do not see that done either.
This is a first step (the tests are definitely going to fail if they have incorrect information about the cache size).
For a fully reliable set of tests some major surgery will be required to bind to CPUs and memory to control allocation and access.
Quoted 2 lines
Reinette
-Tony
Reinette Chatre
maintainerRe: [PATCH v4 7/7] selftests/resctrl: Adjust effective L3 cache size when SNC enabled
Hi Tony,
Quoted 4 lines · Tony Luck
Quoted 3 lines · Reinette Chatre
Hi Tony,
On 7/22/2023 12:07 PM, Tony Luck wrote:
...
Quoted 16 lines
Quoted 4 lines
Quoted 4 lines
(quoted diff) +0
-0@@ -190,6 +245,8 @@ int get_cache_size(int cpu_no, char *cache_type, unsigned long *cache_size) break; }Quoted 11 lines
tools/testing/selftests/resctrl/resctrlfs.c int get_cache_size(int cpu_no, char *cache_type, unsigned long *cache_size) · line 252
Quoted 5 lines
tools/testing/selftests/resctrl/resctrlfs.c +2
-0+if (cache_num ==3 ) + *cache_size /=snc_ways ();return 0 ; }I am surprised that this small change is sufficient. The resctrl selftests are definitely not NUMA aware and the CAT and CMT tests are not taking that into account when picking CPUs to run on. From what I understand LLC occupancy counters need to be added in this scenario but I do not see that done either.
Quoted 6 lines
This is a first step (the tests are definitely going to fail if they have incorrect information about the cache size).
For a fully reliable set of tests some major surgery will be required to bind to CPUs and memory to control allocation and access.
What is the plan for making the tests more reliable? What is the use of this patch if it is just the first step?
Reinette
Tony Luck
maintainerRe: [PATCH v4 7/7] selftests/resctrl: Adjust effective L3 cache size when SNC enabled
Quoted 29 lines · Reinette Chatre
Hi Tony,
Quoted 4 lines · Tony Luck
Quoted 3 lines · Reinette Chatre
Hi Tony,
On 7/22/2023 12:07 PM, Tony Luck wrote:
...
Quoted 19 lines
Quoted 4 lines
Quoted 4 lines
(quoted diff) +0
-0@@ -190,6 +245,8 @@ int get_cache_size(int cpu_no, char *cache_type, unsigned long *cache_size) break; }Quoted 11 lines
tools/testing/selftests/resctrl/resctrlfs.c int get_cache_size(int cpu_no, char *cache_type, unsigned long *cache_size) · line 252
Quoted 5 lines
tools/testing/selftests/resctrl/resctrlfs.c +2
-0+if (cache_num ==3 ) + *cache_size /=snc_ways ();return 0 ; }I am surprised that this small change is sufficient. The resctrl selftests are definitely not NUMA aware and the CAT and CMT tests are not taking that into account when picking CPUs to run on. From what I understand LLC occupancy counters need to be added in this scenario but I do not see that done either.
This is a first step (the tests are definitely going to fail if they have incorrect information about the cache size).
Quoted 6 lines
Quoted 3 lines
For a fully reliable set of tests some major surgery will be required to bind to CPUs and memory to control allocation and access.
What is the plan for making the tests more reliable? What is the use of this patch if it is just the first step?
Reinette,
I have no immediate plan to re-architect the the resctrl self-tests. If you feel this step towards a solution is useless unless it is part of a complete solution, then I can drop it from this series.
-Tony
Re: [PATCH v4 0/7] Add support for Sub-NUMA cluster (SNC) systems
In reply to Tony LuckQuoted 14 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 for monitoring features to be used (with the caveat that memory accesses between different SNC NUMA nodes may still not be counted accuratlely.
Signed-off-by Tony Luck <[email protected]>---
Quoted 8 lines
Changes since v3:
Reinette provided the most excellent suggestion that this series could better achieve its objective if it enabled separate domain lists for control & monitoring within a resource, rather than creating a whole new resource to support separte node scope needed for SNC monitoring. Thus all the pre-amble patches from the previous version have gone, replaced by patches 1-4 of this new series.
[This comment is unrelated to Sub-NUMA support so please disregard if this is the wrong place to make these comments]
I think that the resctrl interface for RISC-V CBQRI could also benefit from separate domain lists for control and monitoring.
For example, the bandwidth controller QoS register [1] interface allows a device to implement both bandwidth usage monitoring and bandwidth allocation. The resctrl proof-of-concept [2] had to awkwardly create two domains for each memory controller in our example SoC, one that would contain the MBA resource and one that would contain the L3 resource to represent MBM files like local_bytes.
This resulted in a very odd looking schemata that would be hard to the user to understand:
# cat /sys/fs/resctrl/schemata MB:4= 80;6= 80;8= 80 L2:0=0fff;1=0fff L3:2=ffff;3=0000;5=0000;7=0000
Where:
Domain 0 is L2 cache controller 0 capacity allocation Domain 1 is L2 cache controller 1 capacity allocation Domain 2 is L3 cache controller capacity allocation
Domain 4 is Memory controller 0 bandwidth allocation Domain 6 is Memory controller 1 bandwidth allocation Domain 8 is Memory controller 2 bandwidth allocation
Domain 3 is Memory controller 0 bandwidth monitoring Domain 5 is Memory controller 1 bandwidth monitoring Domain 7 is Memory controller 2 bandwidth monitoring
But there is no value of having the domains created for the purposes of bandwidth monitoring in schemata.
I've not yet fully understood how the new approach in this patch series could help the situation for CBQRI, but I thought I would mention that separate lists for control and monitoring might be useful.
Thanks,
Drew
[1] https://github.com/riscv-non-isa/riscv-cbqri/blob/main/qos_bandwidth.adoc
[2] https://lore.kernel.org/linux-riscv/[email protected]/
Tony Luck
maintainerRe: [PATCH v4 0/7] Add support for Sub-NUMA cluster (SNC) systems
Quoted 28 lines · Drew Fustini
I think that the resctrl interface for RISC-V CBQRI could also benefit from separate domain lists for control and monitoring.
For example, the bandwidth controller QoS register [1] interface allows a device to implement both bandwidth usage monitoring and bandwidth allocation. The resctrl proof-of-concept [2] had to awkwardly create two domains for each memory controller in our example SoC, one that would contain the MBA resource and one that would contain the L3 resource to represent MBM files like
local_bytes.This resulted in a very odd looking schemata that would be hard to the user to understand:
# cat /sys/fs/resctrl/schemata MB:4= 80;6= 80;8= 80 L2:0=0fff;1=0fff L3:2=ffff;3=0000;5=0000;7=0000Where:
Domain 0 is L2 cache controller 0 capacity allocation Domain 1 is L2 cache controller 1 capacity allocation Domain 2 is L3 cache controller capacity allocation
Domain 4 is Memory controller 0 bandwidth allocation Domain 6 is Memory controller 1 bandwidth allocation Domain 8 is Memory controller 2 bandwidth allocation
Quoted 6 lines
Domain 3 is Memory controller 0 bandwidth monitoring Domain 5 is Memory controller 1 bandwidth monitoring Domain 7 is Memory controller 2 bandwidth monitoring
But there is no value of having the domains created for the purposes of bandwidth monitoring in schemata.
There's certainly no value in exposing those domain numbers in the schemata file. There should also be some way for users to decode the ids. On x86 the "id" is exposed in sysfs. Though the user does need to work to get all the details:
$ cat /sys/devices/system/cpu/cpu36/cache/index3/level 3 $ cat /sys/devices/system/cpu/cpu36/cache/index3/id 1 $ cat /sys/devices/system/cpu/cpu36/cache/index3/shared_cpu_list 36-71,108-143
This shows the L3 cachce with id "1" is shared by CPUs 36-71,108-143
X86 also has independent domain numbers for each resource. So the L2 ones count 0, 1, 2, ... and so do the L3 ones: 0, 1, 2 and the MBA ones: 0, 1, 2
That fits well with the /sys decoding ... but maybe your approach of not repeating domain numbers across different resources is less confusing?
Note that in my resctrl re-write where each resource is handled by a separate loadable module it may be hard for you to keep the unique domain scheme as resource modules are unaware of each other. Though perhaps its just an arch specific hook to provide domain numbers.
Quoted 3 lines
I've not yet fully understood how the new approach in this patch series could help the situation for CBQRI, but I thought I would mention that separate lists for control and monitoring might be useful.
Good. It's nice to know there's potentially another use case for this split besides SNC.
-Tony
Reinette Chatre
maintainerRe: [PATCH v4 0/7] Add support for Sub-NUMA cluster (SNC) systems
In reply to Tony LuckHi Tony,
Quoted 9 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 for monitoring features to be used (with the caveat that memory accesses between different SNC NUMA nodes may still not be counted accuratlely.
accuratlely. -> accurately).
Is there any guidance on the scenarios under which memory accesses may not be counted accurately, how users can detect when this is the case, or any techniques users can use to avoid this?
Since this question has come up during this series I do think it will help to document the impact of SNC on CAT.
Reinette
Tony Luck
maintainerv5 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 for monitoring features to be used (with the caveat that memory accesses between different SNC NUMA nodes may still not be counted accuratlely.
Note that this patch series improves resctrl reporting considerably on systems with SNC enabled, but there will still be some anomalies for processes accessing memory from other sub-NUMA nodes.
Changes since v4:
Rebased to upstream v6.5
Addressed problems reported by Reinette in follow-up messages to v4 posting:
https://lore.kernel.org/r/[email protected]
Broke the patch series into a (hopefully) more logical progression.
First two patches are infrastructure changes to allow resctrl domains to have scopes that are not defined by which CPUs share a particular cache instance, and to allow resources to have different scope for control an monitor features.
Patch 3 cleans up some loose ends from the first two patches by adding a new variant of the rdt_domain structure with just monitoring fields, and removing the monitor fields from the original rdt_domain structure since it is now only used for control features.
Patch 4 adds "node" as a scope option.
Patch 5 adjusts all code paths that need to be aware of SNC mode.
Patch 6 detects SNC mode, modifies the MSR that adjusts interpretation of physical RMID counters.
Patch 7 updates documentation.
Patch 8 does a partial update for the resctrl selftests.
Tony Luck (8):
x86/resctrl: Prepare for new domain scope
x86/resctrl: Prepare for different scope for control/monitor
operations
x86/resctrl: Split the rdt_domain structure 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 selftests/resctrl: Adjust effective L3 cache size when SNC enabled
Documentation/arch/x86/resctrl.rst | 25 +- include/linux/resctrl.h | 64 ++-- arch/x86/include/asm/msr-index.h | 1 + arch/x86/kernel/cpu/resctrl/internal.h | 42 ++- tools/testing/selftests/resctrl/resctrl.h | 1 + arch/x86/kernel/cpu/resctrl/core.c | 321 ++++++++++++++++---- arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 6 +- arch/x86/kernel/cpu/resctrl/monitor.c | 58 ++-- arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 15 +- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 69 +++-- tools/testing/selftests/resctrl/resctrlfs.c | 57 ++++ 11 files changed, 508 insertions(+), 151 deletions(-)
base-commit: 2dde18cd1d8fac735875f2e4987f11817cc0bc2c
Signature · 1 line
2.41.0
Tony Luck
maintainerPATCH v5 1/8 x86/resctrl: Prepare for new domain scope
Legacy resctrl features operated 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.
No functional change.
--- include/linux/resctrl.h | 9 ++++++-- arch/x86/kernel/cpu/resctrl/core.c | 27 ++++++++++++++++++----- arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 15 ++++++++++++- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 15 ++++++++++++- 4 files changed, 56 insertions(+), 10 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_L3_CACHE , +RESCTRL_L2_CACHE , +}; +/** * 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 +21 -6
@@ -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",
@@ -487,6 +487,21 @@ 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_L3_CACHE : +return get_cpu_cacheinfo_id (cpu,3 ); +case RESCTRL_L2_CACHE : +return get_cpu_cacheinfo_id (cpu,2 ); +default : +WARN_ON_ONCE (1 ); +break ; + } + +return -1 ; +} +/* * domain_add_cpu - Add a cpu to a resource's domain list. *
@@ -502,7 +517,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_domain_id_from_scope (cpu, r->scope);struct list_head *add_pos =NULL ;struct rdt_hw_domain *hw_dom;struct rdt_domain *d;
@@ -552,7 +567,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_domain_id_from_scope (cpu, r->scope);struct rdt_hw_domain *hw_dom;struct rdt_domain *d;
arch/x86/kernel/cpu/resctrl/pseudo_lock.c +14 -1
@@ -279,6 +279,7 @@ static void pseudo_lock_region_clear(struct pseudo_lock_region *plr)static int pseudo_lock_region_init (struct pseudo_lock_region *plr) {struct cpu_cacheinfo *ci; +int cache_level;int ret;int i;
@@ -296,8 +297,20 @@ static int pseudo_lock_region_init(struct pseudo_lock_region *plr) plr->size =rdtgroup_cbm_to_size (plr->s->res, plr->d, plr->cbm); +switch (plr->s->res->scope) { +case RESCTRL_L3_CACHE : + cache_level =3 ; +break ; +case RESCTRL_L2_CACHE : + cache_level =2 ; +break ; +default : +WARN_ON_ONCE (1 ); +return -ENODEV ; + } +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 == cache_level) { plr->line_size = ci->info_list[i].coherency_line_size;return 0 ; }
arch/x86/kernel/cpu/resctrl/rdtgroup.c +14 -1
@@ -1343,12 +1343,25 @@ unsigned int rdtgroup_cbm_to_size(struct rdt_resource *r, {struct cpu_cacheinfo *ci;unsigned int size =0 ; +int cache_level;int num_b, i; +switch (r->scope) { +case RESCTRL_L3_CACHE : + cache_level =3 ; +break ; +case RESCTRL_L2_CACHE : + cache_level =2 ; +break ; +default : +WARN_ON_ONCE (1 ); +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 == cache_level) { size = ci->info_list[i].size / r->cache.cbm_len * num_b;break ; }
Signature · 1 line
2.41.0
Re: [PATCH v5 1/8] x86/resctrl: Prepare for new domain scope
Hello,
Quoted 12 lines · Tony Luck
arch/x86/kernel/cpu/resctrl/core.c +4
-0@@ -487,6 +487,21 @@ 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_L3_CACHE :
arch/x86/kernel/cpu/resctrl/core.c static int arch_domain_mbm_alloc(u32 num_rmid, struct rdt_hw_domain *hw_dom) · line 503
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/core.c +10
-0+return get_cpu_cacheinfo_id (cpu,3 ); +case RESCTRL_L2_CACHE : +return get_cpu_cacheinfo_id (cpu,2 ); +default : +WARN_ON_ONCE (1 ); +break ; + } + +return -1 ; +}
Is there some reason the "return -1" is outside of the default switch case?
Other switch statements in this patch do have returns inside the default case, is this one different in some way?
Signature · 2 lines
Kind regards Maciej Wieczór-Retman
Luck, Tony
maintainerRE: [PATCH v5 1/8] x86/resctrl: Prepare for new domain scope
Quoted 18 lines
Quoted 4 lines
arch/x86/kernel/cpu/resctrl/core.c +4
-0+static int get_domain_id_from_scope (int cpu,enum resctrl_scope scope) +{ +switch (scope) { +case RESCTRL_L3_CACHE :arch/x86/kernel/cpu/resctrl/core.c static int arch_domain_mbm_alloc(u32 num_rmid, struct rdt_hw_domain *hw_dom) · line 503
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/core.c +10
-0+return get_cpu_cacheinfo_id (cpu,3 ); +case RESCTRL_L2_CACHE : +return get_cpu_cacheinfo_id (cpu,2 ); +default : +WARN_ON_ONCE (1 ); +break ; + } + +return -1 ; +}Is there some reason the "return -1" is outside of the default switch case?
Quoted 2 lines
Other switch statements in this patch do have returns inside the default case, is this one different in some way?
I've sometimes had compilers complain about code written:
static int get_domain_id_from_scope(int cpu, enum resctrl_scope scope)
{
switch (scope) {
case RESCTRL_L3_CACHE:
return get_cpu_cacheinfo_id(cpu, 3);
case RESCTRL_L2_CACHE:
return get_cpu_cacheinfo_id(cpu, 2);
default:
WARN_ON_ONCE(1);
return -1;
}
}because they failed to notice that every path in the switch does a "return and they issue a warning that the function has no return value because they don't realize that the end of the function can't be reached.
So it's defensive programming against possible complier issues.
-Tony
Re: [PATCH v5 1/8] x86/resctrl: Prepare for new domain scope
Quoted 36 lines · Tony
Quoted 18 lines
Quoted 4 lines
arch/x86/kernel/cpu/resctrl/core.c +4
-0+static int get_domain_id_from_scope (int cpu,enum resctrl_scope scope) +{ +switch (scope) { +case RESCTRL_L3_CACHE :arch/x86/kernel/cpu/resctrl/core.c static int arch_domain_mbm_alloc(u32 num_rmid, struct rdt_hw_domain *hw_dom) · line 503
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/core.c +10
-0+return get_cpu_cacheinfo_id (cpu,3 ); +case RESCTRL_L2_CACHE : +return get_cpu_cacheinfo_id (cpu,2 ); +default : +WARN_ON_ONCE (1 ); +break ; + } + +return -1 ; +}Is there some reason the "return -1" is outside of the default switch case?
Quoted 2 lines
Other switch statements in this patch do have returns inside the default case, is this one different in some way?
I've sometimes had compilers complain about code written:
static int
get_domain_id_from_scope(int cpu, enum resctrl_scope scope){ switch (scope) { case RESCTRL_L3_CACHE: return get_cpu_cacheinfo_id(cpu, 3); case RESCTRL_L2_CACHE: return get_cpu_cacheinfo_id(cpu, 2); default: WARN_ON_ONCE(1); return -1; } }
Quoted 5 lines
because they failed to notice that every path in the switch does a "return and they issue a warning that the function has no return value because they don't realize that the end of the function can't be reached.
So it's defensive programming against possible complier issues.
I recall getting that error somewhere while playing around with a language server protocol for neovim a while ago but I tried to cause it today with gcc and clang and with some different flags and coulnd't. Are there some particular compilers or compiler flags that trigger that?
Signature · 2 lines
Kind regards Maciej Wieczór-Retman
Luck, Tony
maintainerRE: [PATCH v5 1/8] x86/resctrl: Prepare for new domain scope
Quoted 19 lines
Quoted 19 lines
I've sometimes had compilers complain about code written:
static int
get_domain_id_from_scope(int cpu, enum resctrl_scope scope){ switch (scope) { case RESCTRL_L3_CACHE: return get_cpu_cacheinfo_id(cpu, 3); case RESCTRL_L2_CACHE: return get_cpu_cacheinfo_id(cpu, 2); default: WARN_ON_ONCE(1); return -1; } }because they failed to notice that every path in the switch does a "return and they issue a warning that the function has no return value because they don't realize that the end of the function can't be reached.
Quoted 7 lines
Quoted 1 line
So it's defensive programming against possible complier issues.
I recall getting that error somewhere while playing around with a language server protocol for neovim a while ago but I tried to cause it today with gcc and clang and with some different flags and coulnd't. Are there some particular compilers or compiler flags that trigger that?
I think I saw this from an lkp report using clang. But it's quite possible that the exact code construct was different in some way.
-Tony
Reinette Chatre
maintainerRe: [PATCH v5 1/8] x86/resctrl: Prepare for new domain scope
In reply to Tony LuckHi Tony,
Quoted 1 line · Tony Luck
Legacy resctrl features operated on subsets of CPUs in the system with
What is a "legacy" resctrl feature? I am not aware of anything in resctrl that distinguishes a feature as legacy. Could "resctrl resource" be more appropriate to match the resctrl implementation?
Please use "operate on" instead of "operated on".
Quoted 24 lines
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.No functional change.
Signed-off-by Tony Luck <[email protected]>--- include/linux/resctrl.h | 9 ++++++-- arch/x86/kernel/cpu/resctrl/core.c | 27 ++++++++++++++++++----- arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 15 ++++++++++++- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 15 ++++++++++++- 4 files changed, 56 insertions(+), 10 deletions(-)include/linux/resctrl.h +0
-0
include/linux/resctrl.h struct resctrl_membw { · line 150
Quoted 7 lines
include/linux/resctrl.h +4
-0@@ -144,13 +144,18 @@ struct resctrl_membw {struct rdt_parse_data ;struct resctrl_schema ; +enum resctrl_scope { +RESCTRL_L3_CACHE , +RESCTRL_L2_CACHE , +};
I'm curious why L3 appears before L2? This is not a big deal but I think the additional indirection that this introduces is not necessary. As you had in an earlier version this could be RESCTRL_L2_CACHE = 2 and then the value can just be used directly (after ensuring it is used in a valid context).
Quoted 69 lines
include/linux/resctrl.h +3
-2+/** * 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 +8
-4@@ -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",@@ -487,6 +487,21 @@ 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_L3_CACHE :
arch/x86/kernel/cpu/resctrl/core.c static int arch_domain_mbm_alloc(u32 num_rmid, struct rdt_hw_domain *hw_dom) · line 503
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/core.c +10
-0+return get_cpu_cacheinfo_id (cpu,3 ); +case RESCTRL_L2_CACHE : +return get_cpu_cacheinfo_id (cpu,2 ); +default : +WARN_ON_ONCE (1 ); +break ; + } + +return -1 ; +}
Looking ahead at the next patch some members of rdt_resources_all[] are left with a default "0" initialization of mon_scope that is a valid scope of RESCTRL_L3_CACHE in this implementation that would not be caught with defensive code like above. For the above to catch a case like this I think that there should be some default initialization - but if you do move to something like you had in v3 then this may not be necessary. If the L2 scope is 2, L3 scope is 3, node scope is 4, then no initialization will be zero and the above default can more accurately catch failure cases.
Quoted 39 lines
arch/x86/kernel/cpu/resctrl/core.c +3
-2+/* * domain_add_cpu - Add a cpu to a resource's domain list. * @@ -502,7 +517,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_domain_id_from_scope (cpu, r->scope);struct list_head *add_pos =NULL ;struct rdt_hw_domain *hw_dom;struct rdt_domain *d;@@ -552,7 +567,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_domain_id_from_scope (cpu, r->scope);struct rdt_hw_domain *hw_dom;struct rdt_domain *d;arch/x86/kernel/cpu/resctrl/pseudo_lock.c +2
-0@@ -279,6 +279,7 @@ static void pseudo_lock_region_clear(struct pseudo_lock_region *plr)static int pseudo_lock_region_init (struct pseudo_lock_region *plr) {struct cpu_cacheinfo *ci; +int cache_level;int ret;int i;@@ -296,8 +297,20 @@ static int pseudo_lock_region_init(struct pseudo_lock_region *plr) plr->size =rdtgroup_cbm_to_size (plr->s->res, plr->d, plr->cbm); +switch (plr->s->res->scope) {
arch/x86/kernel/cpu/resctrl/pseudo_lock.c static int pseudo_lock_region_init(struct pseudo_lock_region *plr) · line 310
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/pseudo_lock.c +10
-0+case RESCTRL_L3_CACHE : + cache_level =3 ; +break ; +case RESCTRL_L2_CACHE : + cache_level =2 ; +break ; +default : +WARN_ON_ONCE (1 ); +return -ENODEV ; + }
I think this can be simplified without the indirection - a simplified WARN can just test for valid values of plr->s->res->scope directly (exit on failure) and then it can be used directly in the code below when the enum value corresponds to a cache level.
Quoted 20 lines
arch/x86/kernel/cpu/resctrl/pseudo_lock.c +2
-1+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 == cache_level) { plr->line_size = ci->info_list[i].coherency_line_size;return 0 ; }arch/x86/kernel/cpu/resctrl/rdtgroup.c +3
-0@@ -1343,12 +1343,25 @@ unsigned int rdtgroup_cbm_to_size(struct rdt_resource *r, {struct cpu_cacheinfo *ci;unsigned int size =0 ; +int cache_level;int num_b, i; +switch (r->scope) { +case RESCTRL_L3_CACHE :
arch/x86/kernel/cpu/resctrl/rdtgroup.c unsigned int rdtgroup_cbm_to_size(struct rdt_resource *r, · line 1360
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +10
-0+ cache_level =3 ; +break ; +case RESCTRL_L2_CACHE : + cache_level =2 ; +break ; +default : +WARN_ON_ONCE (1 ); +return size; + } +
Same here.
arch/x86/kernel/cpu/resctrl/rdtgroup.c unsigned int rdtgroup_cbm_to_size(struct rdt_resource *r, · line 1367
Quoted 8 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +1
-1num_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 == cache_level) { size = ci->info_list[i].size / r->cache.cbm_len * num_b;break ; }
Reinette
Tony Luck
maintainerRe: [PATCH v5 1/8] x86/resctrl: Prepare for new domain scope
Quoted 8 lines · Reinette Chatre
Hi Tony,
Quoted 1 line · Tony Luck
Legacy resctrl features operated on subsets of CPUs in the system with
What is a "legacy" resctrl feature? I am not aware of anything in resctrl that distinguishes a feature as legacy. Could "resctrl resource" be more appropriate to match the resctrl implementation?
Ok. Will change.
Quoted 2 lines
Please use "operate on" instead of "operated on".
Ditto.
Quoted 28 lines
Quoted 28 lines
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.No functional change.
Signed-off-by Tony Luck <[email protected]>--- include/linux/resctrl.h | 9 ++++++-- arch/x86/kernel/cpu/resctrl/core.c | 27 ++++++++++++++++++----- arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 15 ++++++++++++- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 15 ++++++++++++- 4 files changed, 56 insertions(+), 10 deletions(-)include/linux/resctrl.h +0
-0@@ -144,13 +144,18 @@ struct resctrl_membw {struct rdt_parse_data ;struct resctrl_schema ;
Quoted 10 lines
include/linux/resctrl.h struct resctrl_membw { · line 150
Quoted 4 lines
include/linux/resctrl.h +4
-0+enum resctrl_scope { +RESCTRL_L3_CACHE , +RESCTRL_L2_CACHE , +};I'm curious why L3 appears before L2? This is not a big deal but I think the additional indirection that this introduces is not necessary. As you had in an earlier version this could be
RESCTRL_L2_CACHE= 2 and then the value can just be used directly (after ensuring it is used in a valid context).
I appear to have misundertood your earlier comments. I thought you didn't like my use of RESCTRL_L2_CACHE = 2, and RESCTRL_L3_CACHE = 3 so that the could be passed directly to get_cpu_cacheinfo_id().
But I see now the issue was "after ensuring it is used in a valid context". Are you looking for something like this:
enum resctrl_scope {
RESCTRL_UNINITIALIZED_SCOPE = 0,
RESCTRL_L2_CACHE = 2,
RESCTRL_L3_CACHE = 3,
RESCTRL_L3_NODE = 4,
};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);
case RESCTRL_NODE:
return cpu_to_node(cpu);
default:
case RESCTRL_UNINITIALIZED_SCOPE:
WARN_ON_ONCE(1);
return -1;
}
return -1;
}Quoted 82 lines
Quoted 70 lines
include/linux/resctrl.h +3
-2+/** * 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 +8
-4@@ -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",@@ -487,6 +487,21 @@ 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_L3_CACHE :arch/x86/kernel/cpu/resctrl/core.c static int arch_domain_mbm_alloc(u32 num_rmid, struct rdt_hw_domain *hw_dom) · line 503
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/core.c +10
-0+return get_cpu_cacheinfo_id (cpu,3 ); +case RESCTRL_L2_CACHE : +return get_cpu_cacheinfo_id (cpu,2 ); +default : +WARN_ON_ONCE (1 ); +break ; + } + +return -1 ; +}Looking ahead at the next patch some members of rdt_resources_all[]
Quoted 8 lines
are left with a default "0" initialization of
mon_scopethat is a valid scope ofRESCTRL_L3_CACHEin this implementation that would not be caught with defensive code like above. For the above to catch a case like this I think that there should be some default initialization - but if you do move to something like you had in v3 then this may not be necessary. If the L2 scope is 2, L3 scope is 3, node scope is 4, then no initialization will be zero and the above default can more accurately catch failure cases.
See above (with a defensive enum constant that has the value 0).
Quoted 39 lines
Quoted 39 lines
arch/x86/kernel/cpu/resctrl/core.c +3
-2+/* * domain_add_cpu - Add a cpu to a resource's domain list. * @@ -502,7 +517,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_domain_id_from_scope (cpu, r->scope);struct list_head *add_pos =NULL ;struct rdt_hw_domain *hw_dom;struct rdt_domain *d;@@ -552,7 +567,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_domain_id_from_scope (cpu, r->scope);struct rdt_hw_domain *hw_dom;struct rdt_domain *d;arch/x86/kernel/cpu/resctrl/pseudo_lock.c +1
-0@@ -279,6 +279,7 @@ static void pseudo_lock_region_clear(struct pseudo_lock_region *plr)static int pseudo_lock_region_init (struct pseudo_lock_region *plr) {struct cpu_cacheinfo *ci; +int cache_level;int ret;int i;@@ -296,8 +297,20 @@ static int pseudo_lock_region_init(struct pseudo_lock_region *plr) plr->size =rdtgroup_cbm_to_size (plr->s->res, plr->d, plr->cbm);
Quoted 16 lines
arch/x86/kernel/cpu/resctrl/pseudo_lock.c static int pseudo_lock_region_init(struct pseudo_lock_region *plr) · line 310
Quoted 11 lines
arch/x86/kernel/cpu/resctrl/pseudo_lock.c +11
-0+switch (plr->s->res->scope) { +case RESCTRL_L3_CACHE : + cache_level =3 ; +break ; +case RESCTRL_L2_CACHE : + cache_level =2 ; +break ; +default : +WARN_ON_ONCE (1 ); +return -ENODEV ; + }I think this can be simplified without the indirection - a simplified WARN can just test for valid values of
plr->s->res->scopedirectly (exit on failure) and then it can be used directly in the code below when the enum value corresponds to a cache level.
Is this what you want here?
if (plr->s->res->scope != RESCTRL_L2_CACHE &&
plr->s->res->scope != RESCTRL_L3_CACHE) {
WARN_ON_ONCE(1);
return -ENODEV;
}Quoted 5 lines
arch/x86/kernel/cpu/resctrl/pseudo_lock.c static int pseudo_lock_region_init(struct pseudo_lock_region *plr) · line 313
Quoted 5 lines
arch/x86/kernel/cpu/resctrl/pseudo_lock.c +2
-1+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 == cache_level) {
then drop this change to keep using plr->s->res->cache_level (and delete the now unused local variable cache_level).
Quoted 14 lines
Quoted 14 lines
arch/x86/kernel/cpu/resctrl/pseudo_lock.c +0
-0plr->line_size = ci->info_list[i].coherency_line_size;return 0 ; }arch/x86/kernel/cpu/resctrl/rdtgroup.c +1
-0@@ -1343,12 +1343,25 @@ unsigned int rdtgroup_cbm_to_size(struct rdt_resource *r, {struct cpu_cacheinfo *ci;unsigned int size =0 ; +int cache_level;int num_b, i;
Quoted 14 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c unsigned int rdtgroup_cbm_to_size(struct rdt_resource *r, · line 1360
Quoted 12 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +12
-0+switch (r->scope) { +case RESCTRL_L3_CACHE : + cache_level =3 ; +break ; +case RESCTRL_L2_CACHE : + cache_level =2 ; +break ; +default : +WARN_ON_ONCE (1 ); +return size; + } +Same here.
If above it what you want, will do it here too.
Quoted 12 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c unsigned int rdtgroup_cbm_to_size(struct rdt_resource *r, · line 1367
Quoted 9 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +1
-1num_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 == cache_level) { size = ci->info_list[i].size / r->cache.cbm_len * num_b;break ; }Reinette
-Tony
Reinette Chatre
maintainerRe: [PATCH v5 1/8] x86/resctrl: Prepare for new domain scope
Hi Tony,
Quoted 2 lines · Tony Luck
Quoted 1 line · Reinette Chatre
On 8/29/2023 4:44 PM, Tony Luck wrote:
...
Quoted 19 lines
Quoted 8 lines
Quoted 8 lines
include/linux/resctrl.h +0
-0@@ -144,13 +144,18 @@ struct resctrl_membw {struct rdt_parse_data ;struct resctrl_schema ;Quoted 10 lines
include/linux/resctrl.h struct resctrl_membw { · line 150
Quoted 4 lines
include/linux/resctrl.h +4
-0+enum resctrl_scope { +RESCTRL_L3_CACHE , +RESCTRL_L2_CACHE , +};I'm curious why L3 appears before L2? This is not a big deal but I think the additional indirection that this introduces is not necessary. As you had in an earlier version this could be
RESCTRL_L2_CACHE= 2 and then the value can just be used directly (after ensuring it is used in a valid context).
Quoted 6 lines
I appear to have misundertood your earlier comments. I thought you didn't like my use of
RESCTRL_L2_CACHE= 2, andRESCTRL_L3_CACHE= 3 so that the could be passed directly toget_cpu_cacheinfo_id().But I see now the issue was "after ensuring it is used in a valid context". Are you looking for something like this:
Indeed. My concern with the earlier version was seeing a variable that may contain any scope be used in a context where it can only represent a cache level.
Quoted 7 lines
enum resctrl_scope {
RESCTRL_UNINITIALIZED_SCOPE = 0,
RESCTRL_L2_CACHE = 2,
RESCTRL_L3_CACHE = 3,
RESCTRL_L3_NODE = 4,
};I do not think RESCTRL_UNINITIALIZED_SCOPE is required (perhaps getting too defensive?) but adding it would surely not do harm and indeed make it obvious how the uninitialized case is handled. I am not familiar with customs in this regard and would be ok either way. You can decide what works best for you.
About the new name RESCTRL_L3_NODE. It is not clear to me why "L3" is in the name.
Quoted 9 lines
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); case RESCTRL_NODE: return cpu_to_node(cpu);
(oh - maybe the earlier RESCTRL_L3_NODE was a typo?)
Quoted 9 lines
default: case RESCTRL_UNINITIALIZED_SCOPE: WARN_ON_ONCE(1); return -1; } return -1; }
I'll leave it to you to decide if you want to use RESCTRL_UNINITIALIZED_SCOPE. If you do decide to keep it could you please let the "default" case be the last one?
Quoted 149 lines
Quoted 82 lines
Quoted 70 lines
include/linux/resctrl.h +3
-2+/** * 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 +8
-4@@ -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",@@ -487,6 +487,21 @@ 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_L3_CACHE :arch/x86/kernel/cpu/resctrl/core.c static int arch_domain_mbm_alloc(u32 num_rmid, struct rdt_hw_domain *hw_dom) · line 503
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/core.c +10
-0+return get_cpu_cacheinfo_id (cpu,3 ); +case RESCTRL_L2_CACHE : +return get_cpu_cacheinfo_id (cpu,2 ); +default : +WARN_ON_ONCE (1 ); +break ; + } + +return -1 ; +}Looking ahead at the next patch some members of rdt_resources_all[]
Quoted 8 lines
are left with a default "0" initialization of
mon_scopethat is a valid scope ofRESCTRL_L3_CACHEin this implementation that would not be caught with defensive code like above. For the above to catch a case like this I think that there should be some default initialization - but if you do move to something like you had in v3 then this may not be necessary. If the L2 scope is 2, L3 scope is 3, node scope is 4, then no initialization will be zero and the above default can more accurately catch failure cases.See above (with a defensive enum constant that has the value 0).
Quoted 39 lines
Quoted 39 lines
arch/x86/kernel/cpu/resctrl/core.c +3
-2+/* * domain_add_cpu - Add a cpu to a resource's domain list. * @@ -502,7 +517,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_domain_id_from_scope (cpu, r->scope);struct list_head *add_pos =NULL ;struct rdt_hw_domain *hw_dom;struct rdt_domain *d;@@ -552,7 +567,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_domain_id_from_scope (cpu, r->scope);struct rdt_hw_domain *hw_dom;struct rdt_domain *d;arch/x86/kernel/cpu/resctrl/pseudo_lock.c +1
-0@@ -279,6 +279,7 @@ static void pseudo_lock_region_clear(struct pseudo_lock_region *plr)static int pseudo_lock_region_init (struct pseudo_lock_region *plr) {struct cpu_cacheinfo *ci; +int cache_level;int ret;int i;@@ -296,8 +297,20 @@ static int pseudo_lock_region_init(struct pseudo_lock_region *plr) plr->size =rdtgroup_cbm_to_size (plr->s->res, plr->d, plr->cbm);Quoted 16 lines
arch/x86/kernel/cpu/resctrl/pseudo_lock.c static int pseudo_lock_region_init(struct pseudo_lock_region *plr) · line 310
Quoted 11 lines
arch/x86/kernel/cpu/resctrl/pseudo_lock.c +11
-0+switch (plr->s->res->scope) { +case RESCTRL_L3_CACHE : + cache_level =3 ; +break ; +case RESCTRL_L2_CACHE : + cache_level =2 ; +break ; +default : +WARN_ON_ONCE (1 ); +return -ENODEV ; + }I think this can be simplified without the indirection - a simplified WARN can just test for valid values of
plr->s->res->scopedirectly (exit on failure) and then it can be used directly in the code below when the enum value corresponds to a cache level.
Quoted 7 lines
Is this what you want here?
if (plr->s->res->scope != RESCTRL_L2_CACHE && plr->s->res->scope != RESCTRL_L3_CACHE) { WARN_ON_ONCE(1); return -ENODEV; }
Something like this, yes. It could be simplified more with a:
/* Just to get line length shorter: */ enum resctrl_scope scope = plr->s->res->scope; /* or cache_level? */ if (WARN_ON_ONCE(scope != RESCTRL_L2_CACHE && scope != RESCTRL_L3_CACHE)) return -ENODEV;
Reinette
Moger, Babu
reviewerRe: [PATCH v5 1/8] x86/resctrl: Prepare for new domain scope
In reply to Tony LuckHi Tony,
Quoted 25 lines · Tony Luck
Legacy resctrl features operated 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.No functional change.
Signed-off-by Tony Luck <[email protected]>--- include/linux/resctrl.h | 9 ++++++-- arch/x86/kernel/cpu/resctrl/core.c | 27 ++++++++++++++++++----- arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 15 ++++++++++++- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 15 ++++++++++++- 4 files changed, 56 insertions(+), 10 deletions(-)include/linux/resctrl.h +0
-0
include/linux/resctrl.h struct resctrl_membw { · line 150
Quoted 7 lines
include/linux/resctrl.h +4
-0@@ -144,13 +144,18 @@ struct resctrl_membw {struct rdt_parse_data ;struct resctrl_schema ; +enum resctrl_scope { +RESCTRL_L3_CACHE , +RESCTRL_L2_CACHE , +};
How about?
enum resctrl_scope {
RESCTRL_L2_CACHE = 2,
RESCTRL_L3_CACHE,
};I think this will simplify lot of your code below. You can directly use scope as it is done now.
Quoted 70 lines
include/linux/resctrl.h +3
-2+/** * 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 +9
-4@@ -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",@@ -487,6 +487,21 @@ 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_L3_CACHE : +return get_cpu_cacheinfo_id (cpu,3 );
arch/x86/kernel/cpu/resctrl/core.c static int arch_domain_mbm_alloc(u32 num_rmid, struct rdt_hw_domain *hw_dom) · line 504
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/core.c +10
-0+case RESCTRL_L2_CACHE : +return get_cpu_cacheinfo_id (cpu,2 ); +default : +WARN_ON_ONCE (1 ); +break ; + } + +return -1 ; +} +
You may not need this code with new definition of resctrl_scope.
arch/x86/kernel/cpu/resctrl/core.c static int arch_domain_mbm_alloc(u32 num_rmid, struct rdt_hw_domain *hw_dom) · line 520
Quoted 9 lines
arch/x86/kernel/cpu/resctrl/core.c +1
-1/* * domain_add_cpu - Add a cpu to a resource's domain list. * @@ -502,7 +517,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_domain_id_from_scope (cpu, r->scope);
You can directly call
int id = get_cpu_cacheinfo_id(cpu, r->scope);
Quoted 29 lines
arch/x86/kernel/cpu/resctrl/core.c +1
-1struct list_head *add_pos =NULL ;struct rdt_hw_domain *hw_dom;struct rdt_domain *d;@@ -552,7 +567,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_domain_id_from_scope (cpu, r->scope);struct rdt_hw_domain *hw_dom;struct rdt_domain *d;arch/x86/kernel/cpu/resctrl/pseudo_lock.c +2
-0@@ -279,6 +279,7 @@ static void pseudo_lock_region_clear(struct pseudo_lock_region *plr)static int pseudo_lock_region_init (struct pseudo_lock_region *plr) {struct cpu_cacheinfo *ci; +int cache_level;int ret;int i;@@ -296,8 +297,20 @@ static int pseudo_lock_region_init(struct pseudo_lock_region *plr) plr->size =rdtgroup_cbm_to_size (plr->s->res, plr->d, plr->cbm); +switch (plr->s->res->scope) {
arch/x86/kernel/cpu/resctrl/pseudo_lock.c static int pseudo_lock_region_init(struct pseudo_lock_region *plr) · line 310
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/pseudo_lock.c +10
-0+case RESCTRL_L3_CACHE : + cache_level =3 ; +break ; +case RESCTRL_L2_CACHE : + cache_level =2 ; +break ; +default : +WARN_ON_ONCE (1 ); +return -ENODEV ; + }
Again this may not be required.
Quoted 19 lines
arch/x86/kernel/cpu/resctrl/pseudo_lock.c +2
-1+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 == cache_level) { plr->line_size = ci->info_list[i].coherency_line_size;return 0 ; }arch/x86/kernel/cpu/resctrl/rdtgroup.c +2
-0@@ -1343,12 +1343,25 @@ unsigned int rdtgroup_cbm_to_size(struct rdt_resource *r, {struct cpu_cacheinfo *ci;unsigned int size =0 ; +int cache_level;int num_b, i; +switch (r->scope) {
arch/x86/kernel/cpu/resctrl/rdtgroup.c unsigned int rdtgroup_cbm_to_size(struct rdt_resource *r, · line 1359
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +10
-0+case RESCTRL_L3_CACHE : + cache_level =3 ; +break ; +case RESCTRL_L2_CACHE : + cache_level =2 ; +break ; +default : +WARN_ON_ONCE (1 ); +return size; + }
Again this may not be required.
Quoted 9 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +2
-1+ 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 == cache_level) { size = ci->info_list[i].size / r->cache.cbm_len * num_b;break ; }
Signature · 2 lines
Thanks Babu Moger
Luck, Tony
maintainerRE: [PATCH v5 1/8] x86/resctrl: Prepare for new domain scope
Quoted 11 lines
include/linux/resctrl.h struct resctrl_membw { · line 150
Quoted 4 lines
include/linux/resctrl.h +4
-0+enum resctrl_scope { +RESCTRL_L3_CACHE , +RESCTRL_L2_CACHE , +};How about?
enum resctrl_scope { RESCTRL_L2_CACHE = 2, RESCTRL_L3_CACHE, };
Babu. Thanks for the review.
Reinette made the same observation. I'm updating the
patch to do this. With small extra defensive step to explicitly define
RESCTRL_L3_CACHE = 3,
rather than relying on the compiler picking the next integer ... just in case somebody adds another enum between the L2 and L3 lines.
-Tony
Tony Luck
maintainerPATCH v5 2/8 x86/resctrl: Prepare for different scope for control/monitor operations
In reply to Tony LuckExisting resctrl assumes that control and monitor operations on a resource are performed at the same scope.
Prepare for systems that use different scope (specifically L3 scope for cache control and NODE scope for cache occupancy and memory bandwidth monitoring).
Create separate domain lists for control and monitor operations.
No important functional change. But 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 | 16 +- arch/x86/kernel/cpu/resctrl/internal.h | 6 +- arch/x86/kernel/cpu/resctrl/core.c | 227 +++++++++++++++------- arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 2 +- arch/x86/kernel/cpu/resctrl/monitor.c | 2 +- arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 2 +- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 32 +-- 7 files changed, 199 insertions(+), 88 deletions(-)
include/linux/resctrl.h +11 -5
@@ -155,10 +155,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 +* @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.
@@ -173,10 +175,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 mondomains;char *name;int data_width;u32 default_ctrl;
@@ -222,8 +226,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 +4 -2
@@ -511,8 +511,10 @@ 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 *rdt_find_ctrldomain (struct list_head *h,int id, +struct list_head **pos); +struct rdt_domain *rdt_find_mondomain (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,
arch/x86/kernel/cpu/resctrl/core.c +162 -65
327 lines not on this page · raw message
arch/x86/kernel/cpu/resctrl/ctrlmondata.c +1 -1
@@ -560,7 +560,7 @@ 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 ); + d =rdt_find_mondomain (&r->mondomains, domid,NULL );if (IS_ERR_OR_NULL (d)) { ret = -ENOENT ; goto out;
arch/x86/kernel/cpu/resctrl/monitor.c +1 -1
@@ -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, list) { +list_for_each_entry (d, &r->mondomains, list) {if (cpumask_test_cpu (cpu, &d->cpu_mask)) { err = resctrl_arch_rmid_read(r, d, entry->rmid, QOS_L3_OCCUP_EVENT_ID,
arch/x86/kernel/cpu/resctrl/pseudo_lock.c +1 -1
@@ -297,7 +297,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); -switch (plr->s->res->scope) { +switch (plr->s->res->ctrl_scope) {case RESCTRL_L3_CACHE : cache_level =3 ;break ;
arch/x86/kernel/cpu/resctrl/rdtgroup.c +19 -13
@@ -1346,7 +1346,7 @@ unsigned int rdtgroup_cbm_to_size(struct rdt_resource *r,int cache_level;int num_b, i; -switch (r->scope) { +switch (r->ctrl_scope) {case RESCTRL_L3_CACHE : cache_level =3 ;break ;
@@ -1509,7 +1509,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->mondomains, list) {if (sep)seq_puts (s,";" );
@@ -1632,7 +1632,7 @@ static int mon_config_write(struct rdt_resource *r, char *tok, u32 evtid)return -EINVAL ; } -list_for_each_entry (d, &r->domains, list) { +list_for_each_entry (d, &r->mondomains, list) {if (d->id == dom_id) { ret =mbm_config_write_domain (r, d, evtid, val);if (ret)
@@ -2538,7 +2538,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->mondomains, list)mbm_setup_overflow_handler (dom,MBM_OVERFLOW_INTERVAL ); }
@@ -2932,7 +2932,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->mondomains, list) { ret =mkdir_mondata_subdir (parent_kn, dom, r, prgrp);if (ret)return ret;
@@ -3721,15 +3721,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
@@ -3786,18 +3788,22 @@ 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)
Signature · 1 line
2.41.0
Reinette Chatre
maintainerRe: [PATCH v5 2/8] x86/resctrl: Prepare for different scope for control/monitor operations
Hi Tony,
Quoted 1 line · Tony Luck
Existing resctrl assumes that control and monitor operations on a
Please remove "Existing", it can just be "resctrl assumes ..."
Quoted 46 lines
resource are performed at the same scope.
Prepare for systems that use different scope (specifically L3 scope for cache control and NODE scope for cache occupancy and memory bandwidth monitoring).
Create separate domain lists for control and monitor operations.
No important functional change. But 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.
Signed-off-by Tony Luck <[email protected]>--- include/linux/resctrl.h | 16 +- arch/x86/kernel/cpu/resctrl/internal.h | 6 +- arch/x86/kernel/cpu/resctrl/core.c | 227 +++++++++++++++------- arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 2 +- arch/x86/kernel/cpu/resctrl/monitor.c | 2 +- arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 2 +- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 32 +-- 7 files changed, 199 insertions(+), 88 deletions(-)include/linux/resctrl.h +4
-2@@ -155,10 +155,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 +* @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.
include/linux/resctrl.h struct rdt_resource { · line 183
Quoted 10 lines
include/linux/resctrl.h +3
-1@@ -173,10 +175,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 mondomains;
kerneldoc is "mon_domains" while member is "mondomains". I do think to be consistent with other members that "mon_domains" would be appropriate. I also think it will be very helpful it domains is renamed to "ctrl_domains" to more accurately match "ctrl_scope" and what it represents.
Quoted 21 lines
include/linux/resctrl.h +4
-2char *name;int data_width;u32 default_ctrl;@@ -222,8 +226,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 +0
-0
arch/x86/kernel/cpu/resctrl/internal.h void rdtgroup_kn_unlock(struct kernfs_node *kn); · line 517
Quoted 9 lines
arch/x86/kernel/cpu/resctrl/internal.h +4
-2@@ -511,8 +511,10 @@ 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 *rdt_find_ctrldomain (struct list_head *h,int id, +struct list_head **pos); +struct rdt_domain *rdt_find_mondomain (struct list_head *h,int id, +struct list_head **pos);
This is not what I expected after our previous discussion. It should not be necessary for caller to be aware of the different lists. It looks to me like the original parameters of (struct rdt_resource *r, int id, struct list_head **pos) can be maintained.
Quoted 8 lines
arch/x86/kernel/cpu/resctrl/internal.h +0
-0ssize_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,arch/x86/kernel/cpu/resctrl/core.c +0
-0
arch/x86/kernel/cpu/resctrl/core.c static void · line 61
Quoted 6 lines
arch/x86/kernel/cpu/resctrl/core.c +1
-1@@ -57,7 +57,7 @@ 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 domain_init (id, field) LIST_HEAD_INIT(rdt_resources_all[id].r_resctrl.field)
It may make the code easier to read if this is split into a "mon_domain_init()" and "ctrl_domain_init()"
Quoted 118 lines
arch/x86/kernel/cpu/resctrl/core.c +34
-13struct rdt_hw_resource rdt_resources_all[] = { [RDT_RESOURCE_L3] =@@ -65,8 +65,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, + .domains = domain_init(RDT_RESOURCE_L3, domains), + .mondomains = domain_init(RDT_RESOURCE_L3, mondomains), .parse_ctrlval = parse_cbm, .format_str = "%d=%0*x", .fflags = RFTYPE_RES_CACHE,@@ -79,8 +81,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, + .domains = domain_init(RDT_RESOURCE_L2, domains), .parse_ctrlval = parse_cbm, .format_str = "%d=%0*x", .fflags = RFTYPE_RES_CACHE,@@ -93,8 +95,8 @@ struct rdt_hw_resource rdt_resources_all[] = { .r_resctrl = { .rid = RDT_RESOURCE_MBA, .name = "MB", - .scope = RESCTRL_L3_CACHE, - .domains = domain_init(RDT_RESOURCE_MBA), + .ctrl_scope = RESCTRL_L3_CACHE, + .domains = domain_init(RDT_RESOURCE_MBA, domains), .parse_ctrlval = parse_bw, .format_str = "%d=%*u", .fflags = RFTYPE_RES_MB,@@ -105,8 +107,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, + .domains = domain_init(RDT_RESOURCE_SMBA, domains), .parse_ctrlval = parse_bw, .format_str = "%d=%*u", .fflags = RFTYPE_RES_MB,@@ -384,15 +386,16 @@ void rdt_ctrl_update(void *arg) }/* -* rdt_find_domain - Find a domain in a resource that matches input resource id +* __rdt_find_domain - Find a domain in either the list of control or +* monitor domains that matches input resource id * * 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. */ -struct rdt_domain *rdt_find_domain (struct rdt_resource *r,int id, -struct list_head **pos) +static void *__rdt_find_domain (struct list_head *h,int id, +struct list_head **pos) {struct rdt_domain *d;struct list_head *l;@@ -400,7 +403,7 @@ struct rdt_domain *rdt_find_domain(struct rdt_resource *r, int id,if (id <0 )return ERR_PTR (-ENODEV ); -list_for_each (l, &r->domains) { +list_for_each (l, h) { d = list_entry(l, struct rdt_domain, list);/* When id is found, return its domain. */ if (id == d->id)@@ -416,6 +419,18 @@ struct rdt_domain *rdt_find_domain(struct rdt_resource *r, int id,return NULL ; } +struct rdt_domain *rdt_find_ctrldomain (struct list_head *h,int id, +struct list_head **pos) +{ +return __rdt_find_domain (h, id, pos); +} + +struct rdt_domain *rdt_find_mondomain (struct list_head *h,int id, +struct list_head **pos) +{ +return __rdt_find_domain (h, id, pos); +} +static void setup_default_ctrlval (struct rdt_resource *r,u32 *dc) {struct rdt_hw_resource *hw_res =resctrl_to_arch_res (r);@@ -431,10 +446,15 @@ static void setup_default_ctrlval(struct rdt_resource *r, u32 *dc) }static void domain_free (struct rdt_hw_domain *hw_dom) +{ +kfree (hw_dom->ctrl_val); +kfree (hw_dom); +} + +static void mondomain_free (struct rdt_hw_domain *hw_dom) {kfree (hw_dom->arch_mbm_total);kfree (hw_dom->arch_mbm_local); -kfree (hw_dom->ctrl_val);kfree (hw_dom); }@@ -502,6 +522,93 @@ static int get_domain_id_from_scope(int cpu, enum resctrl_scope scope)return -1 ; } +static void domain_add_cpu_ctrl (int cpu,struct rdt_resource *r)
arch/x86/kernel/cpu/resctrl/core.c static int get_domain_id_from_scope(int cpu, enum resctrl_scope scope) · line 535
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/core.c +10
-0+{ +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 *d; +int err; + + d =rdt_find_ctrldomain (&r->domains, id, &add_pos); +if (IS_ERR (d)) { +pr_warn ("Couldn't find scope id=%d for CPU %d\n" , id, cpu);
I am not sure here ... this generates identical error messages for control and monitor domain. How will the user know what failed? Also, how does printing id help? If I understand correctly it can only be -1 when the above prints.
Quoted 29 lines
arch/x86/kernel/cpu/resctrl/core.c +29
-0+return ; + } + +if (d) { +cpumask_set_cpu (cpu, &d->cpu_mask); +if (r->cache.arch_has_per_cpu_cfg) +rdt_domain_reconfigure_cdp (r); +return ; + } + + hw_dom =kzalloc_node (sizeof (*hw_dom),GFP_KERNEL ,cpu_to_node (cpu)); +if (!hw_dom) +return ; + + d = &hw_dom->d_resctrl; + d->id = id; +cpumask_set_cpu (cpu, &d->cpu_mask); + +rdt_domain_reconfigure_cdp (r); + +if (domain_setup_ctrlval (r, d)) { +domain_free (hw_dom); +return ; + } + +list_add_tail (&d->list, add_pos); + + err =resctrl_online_ctrl_domain (r, d); +if (err) {
arch/x86/kernel/cpu/resctrl/core.c static int get_domain_id_from_scope(int cpu, enum resctrl_scope scope) · line 574
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/core.c +10
-0+list_del (&d->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 rdt_hw_domain *hw_mondom; +struct list_head *add_pos =NULL ;
Please maintain reverse fir ordering. Please check all code.
arch/x86/kernel/cpu/resctrl/core.c static int get_domain_id_from_scope(int cpu, enum resctrl_scope scope) · line 586
Quoted 12 lines
arch/x86/kernel/cpu/resctrl/core.c +12
-0+struct rdt_domain *d; +int err; + + d =rdt_find_mondomain (&r->mondomains, id, &add_pos); +if (IS_ERR (d)) { +pr_warn ("Couldn't find scope id=%d for CPU %d\n" , id, cpu); +return ; + } + +if (d) { +cpumask_set_cpu (cpu, &d->cpu_mask); +
This is an unnecessary empty line that distracts from how the rest of the function looks.
Quoted 18 lines
arch/x86/kernel/cpu/resctrl/core.c +18
-0+return ; + } + + hw_mondom =kzalloc_node (sizeof (*hw_mondom),GFP_KERNEL ,cpu_to_node (cpu)); +if (!hw_mondom) +return ; + + d = &hw_mondom->d_resctrl; + d->id = id; +cpumask_set_cpu (cpu, &d->cpu_mask); + +if (arch_domain_mbm_alloc (r->num_rmid, hw_mondom)) { +mondomain_free (hw_mondom); +return ; + } + +list_add_tail (&d->list, add_pos); +
arch/x86/kernel/cpu/resctrl/core.c static int get_domain_id_from_scope(int cpu, enum resctrl_scope scope) · line 614
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/core.c +7
-0+ err =resctrl_online_mon_domain (r, d); +if (err) { +list_del (&d->list); +mondomain_free (hw_mondom); + } +} +/* * domain_add_cpu - Add a cpu to a resource's domain list. *
Note that this leaves the comments about list management here while all the list management code is moved away.
Quoted 94 lines
arch/x86/kernel/cpu/resctrl/core.c +19
-51@@ -517,70 +624,28 @@ static int get_domain_id_from_scope(int cpu, enum resctrl_scope scope)*/ static void domain_add_cpu (int cpu,struct rdt_resource *r) { -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); -return ; - } - -if (d) { -cpumask_set_cpu (cpu, &d->cpu_mask); -if (r->cache.arch_has_per_cpu_cfg) -rdt_domain_reconfigure_cdp (r); -return ; - } - - hw_dom =kzalloc_node (sizeof (*hw_dom),GFP_KERNEL ,cpu_to_node (cpu)); -if (!hw_dom) -return ; - - d = &hw_dom->d_resctrl; - d->id = id; -cpumask_set_cpu (cpu, &d->cpu_mask); - -rdt_domain_reconfigure_cdp (r); - -if (r->alloc_capable &&domain_setup_ctrlval (r, d)) { -domain_free (hw_dom); -return ; - } - -if (r->mon_capable &&arch_domain_mbm_alloc (r->num_rmid, hw_dom)) { -domain_free (hw_dom); -return ; - } - -list_add_tail (&d->list, add_pos); - - err =resctrl_online_domain (r, d); -if (err) { -list_del (&d->list); -domain_free (hw_dom); - } +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 (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->scope); +int id =get_domain_id_from_scope (cpu, r->ctrl_scope);struct rdt_hw_domain *hw_dom;struct rdt_domain *d; - d =rdt_find_domain (r, id,NULL ); + d =rdt_find_ctrldomain (&r->domains, id,NULL );if (IS_ERR_OR_NULL (d)) { -pr_warn ("Couldn't find cache id for CPU %d\n" , cpu); +pr_warn ("Couldn't find scope id=%d for CPU %d\n" , id, cpu);return ; } hw_dom =resctrl_to_arch_dom (d);cpumask_clear_cpu (cpu, &d->cpu_mask);if (cpumask_empty (&d->cpu_mask)) { -resctrl_offline_domain (r, d); +resctrl_offline_ctrl_domain (r, d);list_del (&d->list);/* @@ -593,6 +658,30 @@ 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_mondom; +struct rdt_domain *d; + + d =rdt_find_mondomain (&r->mondomains, id,NULL ); +if (IS_ERR_OR_NULL (d)) {
arch/x86/kernel/cpu/resctrl/core.c static void domain_remove_cpu(int cpu, struct rdt_resource *r) · line 680
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/core.c +10
-0+pr_warn ("Couldn't find scope id=%d for CPU %d\n" , id, cpu); +return ; + } + hw_mondom =resctrl_to_arch_dom (d); + +cpumask_clear_cpu (cpu, &d->cpu_mask); +if (cpumask_empty (&d->cpu_mask)) { +resctrl_offline_mon_domain (r, d); +list_del (&d->list); +
This is an awkward empty line.
arch/x86/kernel/cpu/resctrl/core.c static void domain_remove_cpu(int cpu, struct rdt_resource *r) · line 687
Quoted 7 lines
arch/x86/kernel/cpu/resctrl/core.c +4
-0+mondomain_free (hw_mondom); + +return ; + }if (r == &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl) {if (is_mbm_enabled () && cpu == d->mbm_work_cpu) {
...
Reinette
Tony Luck
maintainerRe: [PATCH v5 2/8] x86/resctrl: Prepare for different scope for control/monitor operations
Quoted 6 lines · Reinette Chatre
Hi Tony,
Quoted 1 line · Tony Luck
Existing resctrl assumes that control and monitor operations on a
Please remove "Existing", it can just be "resctrl assumes ..."
Will do.
Quoted 55 lines
Quoted 55 lines
resource are performed at the same scope.
Prepare for systems that use different scope (specifically L3 scope for cache control and NODE scope for cache occupancy and memory bandwidth monitoring).
Create separate domain lists for control and monitor operations.
No important functional change. But 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.
Signed-off-by Tony Luck <[email protected]>--- include/linux/resctrl.h | 16 +- arch/x86/kernel/cpu/resctrl/internal.h | 6 +- arch/x86/kernel/cpu/resctrl/core.c | 227 +++++++++++++++------- arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 2 +- arch/x86/kernel/cpu/resctrl/monitor.c | 2 +- arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 2 +- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 32 +-- 7 files changed, 199 insertions(+), 88 deletions(-)include/linux/resctrl.h +6
-3@@ -155,10 +155,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 +* @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. @@ -173,10 +175,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;
Quoted 8 lines
include/linux/resctrl.h struct rdt_resource { · line 183
Quoted 2 lines
include/linux/resctrl.h +1
-0struct list_head domains; +struct list_head mondomains;kerneldoc is "
mon_domains" while member is "mondomains". I do think to be consistent with other members that "mon_domains" would be appropriate. I also think it will be very helpful it domains is renamed to "ctrl_domains" to more accurately match "ctrl_scope" and what it represents.
Next version will use "mon_domains" (and "mon_" in all the associated functions and macros). I'm also changing to "ctrl_" as suggested.
Quoted 27 lines
Quoted 27 lines
include/linux/resctrl.h +4
-2char *name;int data_width;u32 default_ctrl;@@ -222,8 +226,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 +1
-2@@ -511,8 +511,10 @@ 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 *rdt_find_ctrldomain(struct list_head *h, int id,
Quoted 8 lines
arch/x86/kernel/cpu/resctrl/internal.h void rdtgroup_kn_unlock(struct kernfs_node *kn); · line 517
Quoted 3 lines
arch/x86/kernel/cpu/resctrl/internal.h +3
-0+ struct list_head **pos); +struct rdt_domain *rdt_find_mondomain (struct list_head *h,int id, +struct list_head **pos);This is not what I expected after our previous discussion. It should not be necessary for caller to be aware of the different lists. It looks to me like the original parameters of (struct
rdt_resource*r, int id, structlist_head**pos) can be maintained.
Discussed in other e-mail. There is now a "struct rdt_domain_hdr" embedded in the control and monitor versions of the domain structure. rdt_find_domain() operates on that, and callers user container_of() to get to the enclosing structure.
Quoted 12 lines
Quoted 12 lines
arch/x86/kernel/cpu/resctrl/internal.h +0
-0ssize_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,arch/x86/kernel/cpu/resctrl/core.c +0
-0@@ -57,7 +57,7 @@ static void mba_wrmsr_amd(struct rdt_domain *d, struct msr_param *m, struct rdt_resource *r);
Quoted 6 lines
arch/x86/kernel/cpu/resctrl/core.c static void · line 61
Quoted 3 lines
arch/x86/kernel/cpu/resctrl/core.c +1
-1-#define domain_init (id) LIST_HEAD_INIT(rdt_resources_all[id].r_resctrl.domains) +#define domain_init (id, field) LIST_HEAD_INIT(rdt_resources_all[id].r_resctrl.field)It may make the code easier to read if this is split into a "
mon_domain_init()" and "ctrl_domain_init()"
Done
Quoted 118 lines
Quoted 118 lines
arch/x86/kernel/cpu/resctrl/core.c +33
-13struct rdt_hw_resource rdt_resources_all[] = { [RDT_RESOURCE_L3] =@@ -65,8 +65,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, + .domains = domain_init(RDT_RESOURCE_L3, domains), + .mondomains = domain_init(RDT_RESOURCE_L3, mondomains), .parse_ctrlval = parse_cbm, .format_str = "%d=%0*x", .fflags = RFTYPE_RES_CACHE,@@ -79,8 +81,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, + .domains = domain_init(RDT_RESOURCE_L2, domains), .parse_ctrlval = parse_cbm, .format_str = "%d=%0*x", .fflags = RFTYPE_RES_CACHE,@@ -93,8 +95,8 @@ struct rdt_hw_resource rdt_resources_all[] = { .r_resctrl = { .rid = RDT_RESOURCE_MBA, .name = "MB", - .scope = RESCTRL_L3_CACHE, - .domains = domain_init(RDT_RESOURCE_MBA), + .ctrl_scope = RESCTRL_L3_CACHE, + .domains = domain_init(RDT_RESOURCE_MBA, domains), .parse_ctrlval = parse_bw, .format_str = "%d=%*u", .fflags = RFTYPE_RES_MB,@@ -105,8 +107,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, + .domains = domain_init(RDT_RESOURCE_SMBA, domains), .parse_ctrlval = parse_bw, .format_str = "%d=%*u", .fflags = RFTYPE_RES_MB,@@ -384,15 +386,16 @@ void rdt_ctrl_update(void *arg) }/* -* rdt_find_domain - Find a domain in a resource that matches input resource id +* __rdt_find_domain - Find a domain in either the list of control or +* monitor domains that matches input resource id * * 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. */ -struct rdt_domain *rdt_find_domain (struct rdt_resource *r,int id, -struct list_head **pos) +static void *__rdt_find_domain (struct list_head *h,int id, +struct list_head **pos) {struct rdt_domain *d;struct list_head *l;@@ -400,7 +403,7 @@ struct rdt_domain *rdt_find_domain(struct rdt_resource *r, int id,if (id <0 )return ERR_PTR (-ENODEV ); -list_for_each (l, &r->domains) { +list_for_each (l, h) { d = list_entry(l, struct rdt_domain, list);/* When id is found, return its domain. */ if (id == d->id)@@ -416,6 +419,18 @@ struct rdt_domain *rdt_find_domain(struct rdt_resource *r, int id,return NULL ; } +struct rdt_domain *rdt_find_ctrldomain (struct list_head *h,int id, +struct list_head **pos) +{ +return __rdt_find_domain (h, id, pos); +} + +struct rdt_domain *rdt_find_mondomain (struct list_head *h,int id, +struct list_head **pos) +{ +return __rdt_find_domain (h, id, pos); +} +static void setup_default_ctrlval (struct rdt_resource *r,u32 *dc) {struct rdt_hw_resource *hw_res =resctrl_to_arch_res (r);@@ -431,10 +446,15 @@ static void setup_default_ctrlval(struct rdt_resource *r, u32 *dc) }static void domain_free (struct rdt_hw_domain *hw_dom) +{ +kfree (hw_dom->ctrl_val); +kfree (hw_dom); +} + +static void mondomain_free (struct rdt_hw_domain *hw_dom) {kfree (hw_dom->arch_mbm_total);kfree (hw_dom->arch_mbm_local); -kfree (hw_dom->ctrl_val);kfree (hw_dom); }@@ -502,6 +522,93 @@ static int get_domain_id_from_scope(int cpu, enum resctrl_scope scope)return -1 ; }
Quoted 16 lines
arch/x86/kernel/cpu/resctrl/core.c static int get_domain_id_from_scope(int cpu, enum resctrl_scope scope) · line 535
Quoted 11 lines
arch/x86/kernel/cpu/resctrl/core.c +11
-0+static void domain_add_cpu_ctrl (int cpu,struct rdt_resource *r) +{ +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 *d; +int err; + + d =rdt_find_ctrldomain (&r->domains, id, &add_pos); +if (IS_ERR (d)) { +pr_warn ("Couldn't find scope id=%d for CPU %d\n" , id, cpu);I am not sure here ... this generates identical error messages for control and monitor domain. How will the user know what failed? Also, how does printing id help? If I understand correctly it can only be -1 when the above prints.
Improved error messages in next version. Separate ones for failure in get_domain_id_from_scope() and rdt_find_domain(). Each have "control" or "monitor" in the message to help the user pinpoint exactly what went wrong.
Quoted 33 lines
Quoted 33 lines
arch/x86/kernel/cpu/resctrl/core.c +33
-0+return ; + } + +if (d) { +cpumask_set_cpu (cpu, &d->cpu_mask); +if (r->cache.arch_has_per_cpu_cfg) +rdt_domain_reconfigure_cdp (r); +return ; + } + + hw_dom =kzalloc_node (sizeof (*hw_dom),GFP_KERNEL ,cpu_to_node (cpu)); +if (!hw_dom) +return ; + + d = &hw_dom->d_resctrl; + d->id = id; +cpumask_set_cpu (cpu, &d->cpu_mask); + +rdt_domain_reconfigure_cdp (r); + +if (domain_setup_ctrlval (r, d)) { +domain_free (hw_dom); +return ; + } + +list_add_tail (&d->list, add_pos); + + err =resctrl_online_ctrl_domain (r, d); +if (err) { +list_del (&d->list); +domain_free (hw_dom); + } +}
Quoted 8 lines
arch/x86/kernel/cpu/resctrl/core.c static int get_domain_id_from_scope(int cpu, enum resctrl_scope scope) · line 574
Quoted 6 lines
arch/x86/kernel/cpu/resctrl/core.c +6
-0+ +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_domain *hw_mondom; +struct list_head *add_pos =NULL ;Please maintain reverse fir ordering. Please check all code.
I believe I got them all (for functions that are touched by this series - there are a handful of places in resctrl code that don't have reverse fir ordering - I didn't touch those).
Quoted 7 lines
Quoted 7 lines
arch/x86/kernel/cpu/resctrl/core.c +7
-0+struct rdt_domain *d; +int err; + + d =rdt_find_mondomain (&r->mondomains, id, &add_pos); +if (IS_ERR (d)) { +pr_warn ("Couldn't find scope id=%d for CPU %d\n" , id, cpu); +return ;
Quoted 8 lines
arch/x86/kernel/cpu/resctrl/core.c static int get_domain_id_from_scope(int cpu, enum resctrl_scope scope) · line 545
Quoted 5 lines
arch/x86/kernel/cpu/resctrl/core.c +5
-0+ } + +if (d) { +cpumask_set_cpu (cpu, &d->cpu_mask); +This is an unnecessary empty line that distracts from how the rest of the function looks.
Deleted it.
Quoted 24 lines
Quoted 24 lines
arch/x86/kernel/cpu/resctrl/core.c +23
-0+return ; + } + + hw_mondom =kzalloc_node (sizeof (*hw_mondom),GFP_KERNEL ,cpu_to_node (cpu)); +if (!hw_mondom) +return ; + + d = &hw_mondom->d_resctrl; + d->id = id; +cpumask_set_cpu (cpu, &d->cpu_mask); + +if (arch_domain_mbm_alloc (r->num_rmid, hw_mondom)) { +mondomain_free (hw_mondom); +return ; + } + +list_add_tail (&d->list, add_pos); + + err =resctrl_online_mon_domain (r, d); +if (err) { +list_del (&d->list); +mondomain_free (hw_mondom); + }
Quoted 8 lines
arch/x86/kernel/cpu/resctrl/core.c static int get_domain_id_from_scope(int cpu, enum resctrl_scope scope) · line 614
Quoted 5 lines
arch/x86/kernel/cpu/resctrl/core.c +2
-0+} +/* * domain_add_cpu - Add a cpu to a resource's domain list. * Note that this leaves the comments about list management here while all the list management code is moved away.
Moved the comment in front of rdt_find_domain() which does most of the work. Small edit in the comment to say that callers do the rest.
Quoted 99 lines
Quoted 99 lines
arch/x86/kernel/cpu/resctrl/core.c +23
-51@@ -517,70 +624,28 @@ static int get_domain_id_from_scope(int cpu, enum resctrl_scope scope)*/ static void domain_add_cpu (int cpu,struct rdt_resource *r) { -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); -return ; - } - -if (d) { -cpumask_set_cpu (cpu, &d->cpu_mask); -if (r->cache.arch_has_per_cpu_cfg) -rdt_domain_reconfigure_cdp (r); -return ; - } - - hw_dom =kzalloc_node (sizeof (*hw_dom),GFP_KERNEL ,cpu_to_node (cpu)); -if (!hw_dom) -return ; - - d = &hw_dom->d_resctrl; - d->id = id; -cpumask_set_cpu (cpu, &d->cpu_mask); - -rdt_domain_reconfigure_cdp (r); - -if (r->alloc_capable &&domain_setup_ctrlval (r, d)) { -domain_free (hw_dom); -return ; - } - -if (r->mon_capable &&arch_domain_mbm_alloc (r->num_rmid, hw_dom)) { -domain_free (hw_dom); -return ; - } - -list_add_tail (&d->list, add_pos); - - err =resctrl_online_domain (r, d); -if (err) { -list_del (&d->list); -domain_free (hw_dom); - } +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 (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->scope); +int id =get_domain_id_from_scope (cpu, r->ctrl_scope);struct rdt_hw_domain *hw_dom;struct rdt_domain *d; - d =rdt_find_domain (r, id,NULL ); + d =rdt_find_ctrldomain (&r->domains, id,NULL );if (IS_ERR_OR_NULL (d)) { -pr_warn ("Couldn't find cache id for CPU %d\n" , cpu); +pr_warn ("Couldn't find scope id=%d for CPU %d\n" , id, cpu);return ; } hw_dom =resctrl_to_arch_dom (d);cpumask_clear_cpu (cpu, &d->cpu_mask);if (cpumask_empty (&d->cpu_mask)) { -resctrl_offline_domain (r, d); +resctrl_offline_ctrl_domain (r, d);list_del (&d->list);/* @@ -593,6 +658,30 @@ 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_mondom; +struct rdt_domain *d; + + d =rdt_find_mondomain (&r->mondomains, id,NULL ); +if (IS_ERR_OR_NULL (d)) { +pr_warn ("Couldn't find scope id=%d for CPU %d\n" , id, cpu); +return ; + } + hw_mondom =resctrl_to_arch_dom (d);
Quoted 8 lines
arch/x86/kernel/cpu/resctrl/core.c static void domain_remove_cpu(int cpu, struct rdt_resource *r) · line 680
Quoted 6 lines
arch/x86/kernel/cpu/resctrl/core.c +6
-0+ +cpumask_clear_cpu (cpu, &d->cpu_mask); +if (cpumask_empty (&d->cpu_mask)) { +resctrl_offline_mon_domain (r, d); +list_del (&d->list); +This is an awkward empty line.
Deleted it.
Quoted 12 lines
arch/x86/kernel/cpu/resctrl/core.c static void domain_remove_cpu(int cpu, struct rdt_resource *r) · line 687
Quoted 8 lines
arch/x86/kernel/cpu/resctrl/core.c +4
-0+mondomain_free (hw_mondom); + +return ; + }if (r == &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl) {if (is_mbm_enabled () && cpu == d->mbm_work_cpu) {...
Reinette
Moger, Babu
reviewerRe: [PATCH v5 2/8] x86/resctrl: Prepare for different scope for control/monitor operations
In reply to Tony LuckHi Tony,
Quoted 10 lines · Tony Luck
Existing resctrl assumes that control and monitor operations on a resource are performed at the same scope.
Prepare for systems that use different scope (specifically L3 scope for cache control and NODE scope for cache occupancy and memory bandwidth monitoring).
Create separate domain lists for control and monitor operations.
No important functional change. But note that errors during
Its better to remove the line "No important functional change."
Quoted 37 lines
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.
Signed-off-by Tony Luck <[email protected]>--- include/linux/resctrl.h | 16 +- arch/x86/kernel/cpu/resctrl/internal.h | 6 +- arch/x86/kernel/cpu/resctrl/core.c | 227 +++++++++++++++------- arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 2 +- arch/x86/kernel/cpu/resctrl/monitor.c | 2 +- arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 2 +- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 32 +-- 7 files changed, 199 insertions(+), 88 deletions(-)include/linux/resctrl.h +4
-2@@ -155,10 +155,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 +* @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.
include/linux/resctrl.h struct rdt_resource { · line 183
Quoted 10 lines
include/linux/resctrl.h +3
-1@@ -173,10 +175,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 mondomains;
For consistancy, its better to rename it to mon_domains(to be inline with mon_scope, mon_capable).
Quoted 21 lines
include/linux/resctrl.h +4
-2char *name;int data_width;u32 default_ctrl;@@ -222,8 +226,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 +0
-0
arch/x86/kernel/cpu/resctrl/internal.h void rdtgroup_kn_unlock(struct kernfs_node *kn); · line 517
Quoted 9 lines
arch/x86/kernel/cpu/resctrl/internal.h +4
-2@@ -511,8 +511,10 @@ 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 *rdt_find_ctrldomain (struct list_head *h,int id, +struct list_head **pos); +struct rdt_domain *rdt_find_mondomain (struct list_head *h,int id, +struct list_head **pos);
For consistancy, it is better to rename to rdt_find_ctrl_domain and rdt_find_mon_domain respectively.
Quoted 111 lines
arch/x86/kernel/cpu/resctrl/internal.h +0
-0ssize_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,arch/x86/kernel/cpu/resctrl/core.c +28
-13@@ -57,7 +57,7 @@ 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 domain_init (id, field) LIST_HEAD_INIT(rdt_resources_all[id].r_resctrl.field)struct rdt_hw_resource rdt_resources_all[] = { [RDT_RESOURCE_L3] =@@ -65,8 +65,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, + .domains = domain_init(RDT_RESOURCE_L3, domains), + .mondomains = domain_init(RDT_RESOURCE_L3, mondomains), .parse_ctrlval = parse_cbm, .format_str = "%d=%0*x", .fflags = RFTYPE_RES_CACHE,@@ -79,8 +81,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, + .domains = domain_init(RDT_RESOURCE_L2, domains), .parse_ctrlval = parse_cbm, .format_str = "%d=%0*x", .fflags = RFTYPE_RES_CACHE,@@ -93,8 +95,8 @@ struct rdt_hw_resource rdt_resources_all[] = { .r_resctrl = { .rid = RDT_RESOURCE_MBA, .name = "MB", - .scope = RESCTRL_L3_CACHE, - .domains = domain_init(RDT_RESOURCE_MBA), + .ctrl_scope = RESCTRL_L3_CACHE, + .domains = domain_init(RDT_RESOURCE_MBA, domains), .parse_ctrlval = parse_bw, .format_str = "%d=%*u", .fflags = RFTYPE_RES_MB,@@ -105,8 +107,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, + .domains = domain_init(RDT_RESOURCE_SMBA, domains), .parse_ctrlval = parse_bw, .format_str = "%d=%*u", .fflags = RFTYPE_RES_MB,@@ -384,15 +386,16 @@ void rdt_ctrl_update(void *arg) }/* -* rdt_find_domain - Find a domain in a resource that matches input resource id +* __rdt_find_domain - Find a domain in either the list of control or +* monitor domains that matches input resource id * * 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. */ -struct rdt_domain *rdt_find_domain (struct rdt_resource *r,int id, -struct list_head **pos) +static void *__rdt_find_domain (struct list_head *h,int id, +struct list_head **pos) {struct rdt_domain *d;struct list_head *l;@@ -400,7 +403,7 @@ struct rdt_domain *rdt_find_domain(struct rdt_resource *r, int id,if (id <0 )return ERR_PTR (-ENODEV ); -list_for_each (l, &r->domains) { +list_for_each (l, h) { d = list_entry(l, struct rdt_domain, list);/* When id is found, return its domain. */ if (id == d->id)@@ -416,6 +419,18 @@ struct rdt_domain *rdt_find_domain(struct rdt_resource *r, int id,return NULL ; } +struct rdt_domain *rdt_find_ctrldomain (struct list_head *h,int id, +struct list_head **pos) +{ +return __rdt_find_domain (h, id, pos); +} + +struct rdt_domain *rdt_find_mondomain (struct list_head *h,int id, +struct list_head **pos) +{ +return __rdt_find_domain (h, id, pos); +} +static void setup_default_ctrlval (struct rdt_resource *r,u32 *dc) {struct rdt_hw_resource *hw_res =resctrl_to_arch_res (r);
arch/x86/kernel/cpu/resctrl/core.c static void setup_default_ctrlval(struct rdt_resource *r, u32 *dc) · line 454
Quoted 9 lines
arch/x86/kernel/cpu/resctrl/core.c +6
-0@@ -431,10 +446,15 @@ static void setup_default_ctrlval(struct rdt_resource *r, u32 *dc) }static void domain_free (struct rdt_hw_domain *hw_dom) +{ +kfree (hw_dom->ctrl_val); +kfree (hw_dom); +} + +static void mondomain_free (struct rdt_hw_domain *hw_dom)
Its better to rename to mon_domain_free
Quoted 364 lines
arch/x86/kernel/cpu/resctrl/core.c +128
-52{kfree (hw_dom->arch_mbm_total);kfree (hw_dom->arch_mbm_local); -kfree (hw_dom->ctrl_val);kfree (hw_dom); }@@ -502,6 +522,93 @@ static int get_domain_id_from_scope(int cpu, enum resctrl_scope scope)return -1 ; } +static void domain_add_cpu_ctrl (int cpu,struct rdt_resource *r) +{ +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 *d; +int err; + + d =rdt_find_ctrldomain (&r->domains, id, &add_pos); +if (IS_ERR (d)) { +pr_warn ("Couldn't find scope id=%d for CPU %d\n" , id, cpu); +return ; + } + +if (d) { +cpumask_set_cpu (cpu, &d->cpu_mask); +if (r->cache.arch_has_per_cpu_cfg) +rdt_domain_reconfigure_cdp (r); +return ; + } + + hw_dom =kzalloc_node (sizeof (*hw_dom),GFP_KERNEL ,cpu_to_node (cpu)); +if (!hw_dom) +return ; + + d = &hw_dom->d_resctrl; + d->id = id; +cpumask_set_cpu (cpu, &d->cpu_mask); + +rdt_domain_reconfigure_cdp (r); + +if (domain_setup_ctrlval (r, d)) { +domain_free (hw_dom); +return ; + } + +list_add_tail (&d->list, add_pos); + + err =resctrl_online_ctrl_domain (r, d); +if (err) { +list_del (&d->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 rdt_hw_domain *hw_mondom; +struct list_head *add_pos =NULL ; +struct rdt_domain *d; +int err; + + d =rdt_find_mondomain (&r->mondomains, id, &add_pos); +if (IS_ERR (d)) { +pr_warn ("Couldn't find scope id=%d for CPU %d\n" , id, cpu); +return ; + } + +if (d) { +cpumask_set_cpu (cpu, &d->cpu_mask); + +return ; + } + + hw_mondom =kzalloc_node (sizeof (*hw_mondom),GFP_KERNEL ,cpu_to_node (cpu)); +if (!hw_mondom) +return ; + + d = &hw_mondom->d_resctrl; + d->id = id; +cpumask_set_cpu (cpu, &d->cpu_mask); + +if (arch_domain_mbm_alloc (r->num_rmid, hw_mondom)) { +mondomain_free (hw_mondom); +return ; + } + +list_add_tail (&d->list, add_pos); + + err =resctrl_online_mon_domain (r, d); +if (err) { +list_del (&d->list); +mondomain_free (hw_mondom); + } +} +/* * domain_add_cpu - Add a cpu to a resource's domain list. * @@ -517,70 +624,28 @@ static int get_domain_id_from_scope(int cpu, enum resctrl_scope scope)*/ static void domain_add_cpu (int cpu,struct rdt_resource *r) { -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); -return ; - } - -if (d) { -cpumask_set_cpu (cpu, &d->cpu_mask); -if (r->cache.arch_has_per_cpu_cfg) -rdt_domain_reconfigure_cdp (r); -return ; - } - - hw_dom =kzalloc_node (sizeof (*hw_dom),GFP_KERNEL ,cpu_to_node (cpu)); -if (!hw_dom) -return ; - - d = &hw_dom->d_resctrl; - d->id = id; -cpumask_set_cpu (cpu, &d->cpu_mask); - -rdt_domain_reconfigure_cdp (r); - -if (r->alloc_capable &&domain_setup_ctrlval (r, d)) { -domain_free (hw_dom); -return ; - } - -if (r->mon_capable &&arch_domain_mbm_alloc (r->num_rmid, hw_dom)) { -domain_free (hw_dom); -return ; - } - -list_add_tail (&d->list, add_pos); - - err =resctrl_online_domain (r, d); -if (err) { -list_del (&d->list); -domain_free (hw_dom); - } +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 (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->scope); +int id =get_domain_id_from_scope (cpu, r->ctrl_scope);struct rdt_hw_domain *hw_dom;struct rdt_domain *d; - d =rdt_find_domain (r, id,NULL ); + d =rdt_find_ctrldomain (&r->domains, id,NULL );if (IS_ERR_OR_NULL (d)) { -pr_warn ("Couldn't find cache id for CPU %d\n" , cpu); +pr_warn ("Couldn't find scope id=%d for CPU %d\n" , id, cpu);return ; } hw_dom =resctrl_to_arch_dom (d);cpumask_clear_cpu (cpu, &d->cpu_mask);if (cpumask_empty (&d->cpu_mask)) { -resctrl_offline_domain (r, d); +resctrl_offline_ctrl_domain (r, d);list_del (&d->list);/* @@ -593,6 +658,30 @@ 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_mondom; +struct rdt_domain *d; + + d =rdt_find_mondomain (&r->mondomains, id,NULL ); +if (IS_ERR_OR_NULL (d)) { +pr_warn ("Couldn't find scope id=%d for CPU %d\n" , id, cpu); +return ; + } + hw_mondom =resctrl_to_arch_dom (d); + +cpumask_clear_cpu (cpu, &d->cpu_mask); +if (cpumask_empty (&d->cpu_mask)) { +resctrl_offline_mon_domain (r, d); +list_del (&d->list); + +mondomain_free (hw_mondom); + +return ; + }if (r == &rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl) {if (is_mbm_enabled () && cpu == d->mbm_work_cpu) {@@ -607,6 +696,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 +1
-1@@ -560,7 +560,7 @@ 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 ); + d =rdt_find_mondomain (&r->mondomains, domid,NULL );if (IS_ERR_OR_NULL (d)) { ret = -ENOENT ; goto out;arch/x86/kernel/cpu/resctrl/monitor.c +1
-1@@ -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, list) { +list_for_each_entry (d, &r->mondomains, list) {if (cpumask_test_cpu (cpu, &d->cpu_mask)) { err = resctrl_arch_rmid_read(r, d, entry->rmid, QOS_L3_OCCUP_EVENT_ID,arch/x86/kernel/cpu/resctrl/pseudo_lock.c +1
-1@@ -297,7 +297,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); -switch (plr->s->res->scope) { +switch (plr->s->res->ctrl_scope) {case RESCTRL_L3_CACHE : cache_level =3 ;break ;arch/x86/kernel/cpu/resctrl/rdtgroup.c +19
-13@@ -1346,7 +1346,7 @@ unsigned int rdtgroup_cbm_to_size(struct rdt_resource *r,int cache_level;int num_b, i; -switch (r->scope) { +switch (r->ctrl_scope) {case RESCTRL_L3_CACHE : cache_level =3 ;break ;@@ -1509,7 +1509,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->mondomains, list) {if (sep)seq_puts (s,";" );@@ -1632,7 +1632,7 @@ static int mon_config_write(struct rdt_resource *r, char *tok, u32 evtid)return -EINVAL ; } -list_for_each_entry (d, &r->domains, list) { +list_for_each_entry (d, &r->mondomains, list) {if (d->id == dom_id) { ret =mbm_config_write_domain (r, d, evtid, val);if (ret)@@ -2538,7 +2538,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->mondomains, list)mbm_setup_overflow_handler (dom,MBM_OVERFLOW_INTERVAL ); }@@ -2932,7 +2932,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->mondomains, list) { ret =mkdir_mondata_subdir (parent_kn, dom, r, prgrp);if (ret)return ret;@@ -3721,15 +3721,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 @@ -3786,18 +3788,22 @@ 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)
Signature · 2 lines
Thanks Babu Moger
Luck, Tony
maintainerRE: [PATCH v5 2/8] x86/resctrl: Prepare for different scope for control/monitor operations
Quoted 5 lines
Quoted 3 lines
Create separate domain lists for control and monitor operations.
No important functional change. But note that errors during
Its better to remove the line "No important functional change."
Will drop it.
Quoted 5 lines
include/linux/resctrl.h struct rdt_resource { · line 183
Quoted 2 lines
include/linux/resctrl.h +1
-0struct list_head domains; +struct list_head mondomains;For consistancy, its better to rename it to
mon_domains(to be inline with mon_scope, mon_capable).
Again, you are thinking like Reinette! You'll be a resctrl maintainer soon.
Quoted 7 lines
arch/x86/kernel/cpu/resctrl/internal.h void rdtgroup_kn_unlock(struct kernfs_node *kn); · line 517
Quoted 4 lines
arch/x86/kernel/cpu/resctrl/internal.h +4
-0+struct rdt_domain *rdt_find_ctrldomain (struct list_head *h,int id, +struct list_head **pos); +struct rdt_domain *rdt_find_mondomain (struct list_head *h,int id, +struct list_head **pos);For consistancy, it is better to rename to
rdt_find_ctrl_domainandrdt_find_mon_domainrespectively.
Agreed.
Thanks for the review.
-Tony
Tony Luck
maintainerPATCH v5 3/8 x86/resctrl: Split the rdt_domain structure
In reply to Tony LuckThe same rdt_domain structure is used for both control an 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.
Create a new rdt_mondomain structure tailored explicitly for use in monitor parts of the core. Slim down the rdt_domain structure by removing the unused monitor fields.
Similar breakout of struct rdt_hw_mondomain from struct rdt_hw_domain.
--- include/linux/resctrl.h | 46 +++++++++++++++-------- arch/x86/kernel/cpu/resctrl/internal.h | 38 +++++++++++++------ arch/x86/kernel/cpu/resctrl/core.c | 18 ++++----- arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 4 +- arch/x86/kernel/cpu/resctrl/monitor.c | 40 ++++++++++---------- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 24 ++++++------ 6 files changed, 101 insertions(+), 69 deletions(-)
include/linux/resctrl.h +31 -15
@@ -53,7 +53,29 @@ struct resctrl_staged_config { };/** -* struct rdt_domain - group of CPUs sharing a resctrl resource +* struct rdt_domain - group of CPUs sharing a resctrl control resource +* @list: all instances of this resource +* @id: unique id for this instance +* @cpu_mask: which CPUs share this resource +* @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 { +// First three fields must match struct rdt_mondomain below. +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; +}; + +/** +* struct rdt_mondomain - group of CPUs sharing a resctrl monitor resource * @list: all instances of this resource * @id: unique id for this instance * @cpu_mask: which CPUs share this resource
@@ -64,16 +86,13 @@ struct resctrl_staged_config {* @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_mondomain { +// First three fields must match struct rdt_domain above. 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;
@@ -81,9 +100,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; };/**
@@ -227,9 +243,9 @@ 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_ctrl_domain (struct rdt_resource *r,struct rdt_domain *d); -int resctrl_online_mon_domain (struct rdt_resource *r,struct rdt_domain *d); +int resctrl_online_mon_domain (struct rdt_resource *r,struct rdt_mondomain *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); +void resctrl_offline_mon_domain (struct rdt_resource *r,struct rdt_mondomain *d);/** * resctrl_arch_rmid_read() - Read the eventid counter corresponding to rmid
@@ -245,7 +261,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_mondomain *d,u32 rmid,enum resctrl_event_id eventid,u64 *val);/**
@@ -258,7 +274,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_mondomain *d,u32 rmid,enum resctrl_event_id eventid);/**
@@ -270,7 +286,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_mondomain *d);extern unsigned int resctrl_rmid_realloc_threshold;extern unsigned int resctrl_rmid_realloc_limit;
arch/x86/kernel/cpu/resctrl/internal.h +27 -11
@@ -106,7 +106,7 @@ union mon_data_bits {struct rmid_read {struct rdtgroup *rgrp;struct rdt_resource *r; -struct rdt_domain *d; +struct rdt_mondomain *d;enum resctrl_event_id evtid;bool first;int err;
@@ -320,17 +320,28 @@ struct arch_mbm_state {/** * struct rdt_hw_domain - Arch private attributes of a set of CPUs that share -* a resource +* a control resource * @d_resctrl: Properties exposed to the resctrl file system * @ctrl_val: array of cache or mem ctrl values (indexed by CLOSID) -* @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_mondomain - Arch private attributes of a set of CPUs that share +* a monitor resource +* @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_mondomain { +struct rdt_mondomain d_resctrl;struct arch_mbm_state *arch_mbm_total;struct arch_mbm_state *arch_mbm_local; };
@@ -340,6 +351,11 @@ static inline struct rdt_hw_domain *resctrl_to_arch_dom(struct rdt_domain *r) return container_of(r, struct rdt_hw_domain, d_resctrl); } +static inline struct rdt_hw_mondomain *resctrl_to_arch_mondom (struct rdt_mondomain *r) +{ + return container_of(r, struct rdt_hw_mondomain, d_resctrl); +} +/** * struct msr_param - set a range of MSRs from a domain * @res: The resource to use
@@ -513,8 +529,8 @@ int rdtgroup_kn_mode_restore(struct rdtgroup *r, const char *name, umode_t mask);struct rdt_domain *rdt_find_ctrldomain (struct list_head *h,int id,struct list_head **pos); -struct rdt_domain *rdt_find_mondomain (struct list_head *h,int id, -struct list_head **pos); +struct rdt_mondomain *rdt_find_mondomain (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,
@@ -543,17 +559,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_mondomain *d,struct rdtgroup *rdtgrp,int evtid,int first); -void mbm_setup_overflow_handler (struct rdt_domain *dom, +void mbm_setup_overflow_handler (struct rdt_mondomain *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_mondomain *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_mondomain *d); +void __check_limbo (struct rdt_mondomain *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 +9 -9
@@ -425,8 +425,8 @@ struct rdt_domain *rdt_find_ctrldomain(struct list_head *h, int id,return __rdt_find_domain (h, id, pos); } -struct rdt_domain *rdt_find_mondomain (struct list_head *h,int id, -struct list_head **pos) +struct rdt_mondomain *rdt_find_mondomain (struct list_head *h,int id, +struct list_head **pos) {return __rdt_find_domain (h, id, pos); }
@@ -451,7 +451,7 @@ static void domain_free(struct rdt_hw_domain *hw_dom)kfree (hw_dom); } -static void mondomain_free (struct rdt_hw_domain *hw_dom) +static void mondomain_free (struct rdt_hw_mondomain *hw_dom) {kfree (hw_dom->arch_mbm_total);kfree (hw_dom->arch_mbm_local);
@@ -484,7 +484,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_mondomain *hw_dom) {size_t tsize;
@@ -570,9 +570,9 @@ static void domain_add_cpu_ctrl(int cpu, struct rdt_resource *r)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_domain *hw_mondom; +struct rdt_hw_mondomain *hw_mondom;struct list_head *add_pos =NULL ; -struct rdt_domain *d; +struct rdt_mondomain *d;int err; d =rdt_find_mondomain (&r->mondomains, id, &add_pos);
@@ -663,15 +663,15 @@ 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_mondom; -struct rdt_domain *d; +struct rdt_hw_mondomain *hw_mondom; +struct rdt_mondomain *d; d =rdt_find_mondomain (&r->mondomains, id,NULL );if (IS_ERR_OR_NULL (d)) {pr_warn ("Couldn't find scope id=%d for CPU %d\n" , id, cpu);return ; } - hw_mondom =resctrl_to_arch_dom (d); + hw_mondom =resctrl_to_arch_mondom (d);cpumask_clear_cpu (cpu, &d->cpu_mask);if (cpumask_empty (&d->cpu_mask)) {
arch/x86/kernel/cpu/resctrl/ctrlmondata.c +2 -2
@@ -521,7 +521,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_mondomain *d,struct rdtgroup *rdtgrp,int evtid,int first) {/*
@@ -544,7 +544,7 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg)struct rdtgroup *rdtgrp;struct rdt_resource *r;union mon_data_bits md; -struct rdt_domain *d; +struct rdt_mondomain *d;struct rmid_read rr;int ret =0 ;
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_mondomain *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_mondomain *d,u32 rmid,enum resctrl_event_id eventid) { -struct rdt_hw_domain *hw_dom =resctrl_to_arch_dom (d); +struct rdt_hw_mondomain *hw_dom =resctrl_to_arch_mondom (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_mondomain *d) { -struct rdt_hw_domain *hw_dom =resctrl_to_arch_dom (d); +struct rdt_hw_mondomain *hw_dom =resctrl_to_arch_mondom (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_mondomain *d,u32 rmid,enum resctrl_event_id eventid,u64 *val) {struct rdt_hw_resource *hw_res =resctrl_to_arch_res (r); -struct rdt_hw_domain *hw_dom =resctrl_to_arch_dom (d); +struct rdt_hw_mondomain *hw_mondom =resctrl_to_arch_mondom (d);struct arch_mbm_state *am;u64 msr_val, chunks;int ret;
@@ -245,7 +245,7 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain *d,if (ret)return ret; - am =get_arch_mbm_state (hw_dom, rmid, eventid); + am =get_arch_mbm_state (hw_mondom, rmid, eventid);if (am) { am->chunks +=mbm_overflow_count (am->prev_msr, msr_val, hw_res->mbm_width);
@@ -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_mondomain *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_mondomain *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_mondomain *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_mondomain *d,u32 rmid,enum resctrl_event_id evtid) {switch (evtid) {
@@ -516,7 +516,7 @@ 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_mondomain *dom_mbm) {u32 closid, rmid, cur_msr_val, new_msr_val;struct mbm_state *pmbm_data, *cmbm_data;
@@ -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_mondomain *d,int rmid) {struct rmid_read rr;
@@ -641,12 +641,12 @@ void cqm_handle_limbo(struct work_struct *work)unsigned long delay =msecs_to_jiffies (CQM_LIMBOCHECK_INTERVAL );int cpu =smp_processor_id ();struct rdt_resource *r; -struct rdt_domain *d; +struct rdt_mondomain *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_mondomain, 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_mondomain *dom,unsigned long delay_ms) {unsigned long delay =msecs_to_jiffies (delay_ms);int cpu;
@@ -674,7 +674,7 @@ void mbm_handle_overflow(struct work_struct *work)int cpu =smp_processor_id ();struct list_head *head;struct rdt_resource *r; -struct rdt_domain *d; +struct rdt_mondomain *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_mondomain, 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_mondomain *dom,unsigned long delay_ms) {unsigned long delay =msecs_to_jiffies (delay_ms);int cpu;
arch/x86/kernel/cpu/resctrl/rdtgroup.c +12 -12
@@ -1496,7 +1496,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_mondomain *d,struct mon_config_info *mon_info) {smp_call_function_any (&d->cpu_mask, mon_event_config_read, mon_info,1 ); }
@@ -1504,7 +1504,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_mondomain *dom;bool sep = false;mutex_lock (&rdtgroup_mutex);
@@ -1561,7 +1561,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_mondomain *d,u32 evtid,u32 val) {struct mon_config_info mon_info = {0 };int ret =0 ;
@@ -1611,7 +1611,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_mondomain *d;int ret =0 ; next:
@@ -2476,7 +2476,7 @@ static void schemata_list_destroy(void)static int rdt_get_tree (struct fs_context *fc) {struct rdt_fs_context *ctx =rdt_fc2context (fc); -struct rdt_domain *dom; +struct rdt_mondomain *dom;struct rdt_resource *r;int ret;
@@ -2858,7 +2858,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_mondomain *d,struct rdt_resource *r,struct rdtgroup *prgrp) {union mon_data_bits priv;
@@ -2907,7 +2907,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_mondomain *d) {struct kernfs_node *parent_kn;struct rdtgroup *prgrp, *crgrp;
@@ -2929,7 +2929,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_mondomain *dom;int ret;list_for_each_entry (dom, &r->mondomains, list) {
@@ -3714,7 +3714,7 @@ static int __init rdtgroup_setup_root(void)return ret; } -static void domain_destroy_mon_state (struct rdt_domain *d) +static void domain_destroy_mon_state (struct rdt_mondomain *d) {bitmap_free (d->rmid_busy_llc);kfree (d->mbm_total);
@@ -3729,7 +3729,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_mondomain *d) {lockdep_assert_held (&rdtgroup_mutex);
@@ -3758,7 +3758,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_mondomain *d) {size_t tsize;
@@ -3799,7 +3799,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_mondomain *d) {int err;
Signature · 1 line
2.41.0
Reinette Chatre
maintainerRe: [PATCH v5 3/8] x86/resctrl: Split the rdt_domain structure
Hi Tony,
Subject:
x86/resctrl: Split the rdt_domain and rdt_hw_domain structures
Quoted 1 line · Tony Luck
The same
rdt_domainstructure is used for both control an monitor
"control an monitor" -> "control and monitor"
Quoted 8 lines
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.
Create a new
rdt_mondomainstructure tailored explicitly for use in monitor parts of the core. Slim down therdt_domainstructure by removing the unused monitor fields.
Similar to the previous patch I think it will make the code easier to understand if the naming is clear for both monitoring and control structured. Why not rdt_mondomain and rdt_ctrldomain instead?
Quoted 1 line
Similar breakout of struct
rdt_hw_mondomainfrom structrdt_hw_domain.
rdt_hw_mondomain and rdt_hw_ctrldomain?
Quoted 22 lines
Signed-off-by Tony Luck <[email protected]>--- include/linux/resctrl.h | 46 +++++++++++++++-------- arch/x86/kernel/cpu/resctrl/internal.h | 38 +++++++++++++------ arch/x86/kernel/cpu/resctrl/core.c | 18 ++++----- arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 4 +- arch/x86/kernel/cpu/resctrl/monitor.c | 40 ++++++++++---------- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 24 ++++++------ 6 files changed, 101 insertions(+), 69 deletions(-)include/linux/resctrl.h +2
-1@@ -53,7 +53,29 @@ struct resctrl_staged_config { };/** -* struct rdt_domain - group of CPUs sharing a resctrl resource +* struct rdt_domain - group of CPUs sharing a resctrl control resource +* @list: all instances of this resource
include/linux/resctrl.h struct resctrl_staged_config { · line 67
Quoted 10 lines
include/linux/resctrl.h +10
-0+* @id: unique id for this instance +* @cpu_mask: which CPUs share this resource +* @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 { +// First three fields must match struct rdt_mondomain below.
Please avoid comments within declarations. Even so, could you please elaborate what the above means? Why do the first three fields have to match? I understand there is common code, for example, __rdt_find_domain() that operated on the same members of the two structs but does that require the members be in the same position in the struct?
I understand that a comment may be required if position in the struct is important but I cannot see that it is.
Quoted 17 lines
include/linux/resctrl.h +11
-0+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; +}; + +/** +* struct rdt_mondomain - group of CPUs sharing a resctrl monitor resource * @list: all instances of this resource * @id: unique id for this instance * @cpu_mask: which CPUs share this resource @@ -64,16 +86,13 @@ struct resctrl_staged_config {* @cqm_limbo: worker to periodically read CQM h/w counters * @mbm_work_cpu: worker CPU for MBM h/w counters
include/linux/resctrl.h struct resctrl_staged_config { · line 91
Quoted 10 lines
include/linux/resctrl.h +2
-6* @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_mondomain { +// First three fields must match struct rdt_domain above.
Same comment.
Quoted 17 lines
include/linux/resctrl.h +1
-3struct list_head list;int id;struct cpumask cpu_mask; +unsigned long *rmid_busy_llc;struct mbm_state *mbm_total;struct mbm_state *mbm_local;@@ -81,9 +100,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; };/**
...
Quoted 14 lines
arch/x86/kernel/cpu/resctrl/ctrlmondata.c +1
-1@@ -521,7 +521,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_mondomain *d,struct rdtgroup *rdtgrp,int evtid,int first) {/*
arch/x86/kernel/cpu/resctrl/ctrlmondata.c int rdtgroup_mondata_show(struct seq_file *m, void *arg) · line 547
Quoted 5 lines
arch/x86/kernel/cpu/resctrl/ctrlmondata.c +1
-1@@ -544,7 +544,7 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg)struct rdtgroup *rdtgrp;struct rdt_resource *r;union mon_data_bits md; -struct rdt_domain *d; +struct rdt_mondomain *d;
Reverse fir order.
Quoted 42 lines
arch/x86/kernel/cpu/resctrl/ctrlmondata.c +0
-0struct rmid_read rr;int ret =0 ;arch/x86/kernel/cpu/resctrl/monitor.c +5
-5@@ -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_mondomain *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_mondomain *d,u32 rmid,enum resctrl_event_id eventid) { -struct rdt_hw_domain *hw_dom =resctrl_to_arch_dom (d); +struct rdt_hw_mondomain *hw_dom =resctrl_to_arch_mondom (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_mondomain *d) { -struct rdt_hw_domain *hw_dom =resctrl_to_arch_dom (d); +struct rdt_hw_mondomain *hw_dom =resctrl_to_arch_mondom (d);if (is_mbm_total_enabled ()) memset(hw_dom->arch_mbm_total, 0,
arch/x86/kernel/cpu/resctrl/monitor.c static u64 mbm_overflow_count(u64 prev_msr, u64 cur_msr, unsigned int width) · line 236
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/monitor.c +2
-2@@ -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_mondomain *d,u32 rmid,enum resctrl_event_id eventid,u64 *val) {struct rdt_hw_resource *hw_res =resctrl_to_arch_res (r); -struct rdt_hw_domain *hw_dom =resctrl_to_arch_dom (d); +struct rdt_hw_mondomain *hw_mondom =resctrl_to_arch_mondom (d);
Reverse fir.
Quoted 67 lines
arch/x86/kernel/cpu/resctrl/monitor.c +7
-7struct arch_mbm_state *am;u64 msr_val, chunks;int ret;@@ -245,7 +245,7 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain *d,if (ret)return ret; - am =get_arch_mbm_state (hw_dom, rmid, eventid); + am =get_arch_mbm_state (hw_mondom, rmid, eventid);if (am) { am->chunks +=mbm_overflow_count (am->prev_msr, msr_val, hw_res->mbm_width);@@ -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_mondomain *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_mondomain *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_mondomain *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_mondomain *d,u32 rmid,enum resctrl_event_id evtid) {switch (evtid) {@@ -516,7 +516,7 @@ 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_mondomain *dom_mbm) {u32 closid, rmid, cur_msr_val, new_msr_val;struct mbm_state *pmbm_data, *cmbm_data;@@ -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_mondomain *d,int rmid) {struct rmid_read rr;
arch/x86/kernel/cpu/resctrl/monitor.c void cqm_handle_limbo(struct work_struct *work) · line 644
Quoted 5 lines
arch/x86/kernel/cpu/resctrl/monitor.c +1
-1@@ -641,12 +641,12 @@ void cqm_handle_limbo(struct work_struct *work)unsigned long delay =msecs_to_jiffies (CQM_LIMBOCHECK_INTERVAL );int cpu =smp_processor_id ();struct rdt_resource *r; -struct rdt_domain *d; +struct rdt_mondomain *d;
Reverse fir (Please check all code).
Reinette
Tony Luck
maintainerRe: [PATCH v5 3/8] x86/resctrl: Split the rdt_domain structure
Quoted 10 lines · Reinette Chatre
Review
Quoted 2 lines
(quoted diff) +2
-0+struct rdt_domain { + // First three fields must match struct rdt_mondomain below.Please avoid comments within declarations. Even so, could you please elaborate what the above means? Why do the first three fields have to match? I understand there is common code, for example,
__rdt_find_domain()that operated on the same members of the two structs but does that require the members be in the same position in the struct?
I understand that a comment may be required if position in the struct is important but I cannot see that it is.
[Just replying to this one point in your message to get guidance. I'll address all the rest in other replies]
I'm wrong about the first *three* fields ... but the first *two* fields (the "list" and the "id") do need to be at the same offsets in different structures if a common routine is going to be used to access those fields.
If the "id" were at offset 0x10 in the control version of the domain structure, and at offset 0x20 in the monitor version of the domain structure, there would be no hope for a common routine to access the "id" field when searching a list that could be either control or monitor domains.
I'm looking at making this far more explicit with a new patch between 0001 and 0002 that pulls the two fields into a common substructure that will be included in each of the control and monitor versions of the structure.
Patch included below.
But this seems like it is a lot of churn to avoid having separate functions to search control and monitor lists. Each a clone of the existing ~24 line rdt_find_domain() with just the type changed for the return value and the list travsersal.
What do you think?
-Tony
commit 08992b4be1f53a3144f8aadd821f815a40a05e75
Author: Tony Luck <[email protected]> Date: Tue Sep 26 11:07:12 2023 -0700
x86/resctrl: Prepare to split rdt_domain structure
The 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 the "list" and "id" fields into their own structure within the rdt_domain structure.
include/linux/resctrl.h +11 -3
@@ -53,9 +53,18 @@ 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 +*/ +struct rdt_domain_hdr { +struct list_head list; +int id; +}; + +/** +* struct rdt_domain - group of CPUs sharing a resctrl resource +* @hdr: common header for different domain types * @cpu_mask: which CPUs share this resource * @rmid_busy_llc: bitmap of which limbo RMIDs are above threshold * @mbm_total: saved state for MBM total bandwidth
@@ -71,8 +80,7 @@ struct resctrl_staged_config {* by closid */ struct rdt_domain { -struct list_head list; -int id; +struct rdt_domain_hdr hdr;struct cpumask cpu_mask;unsigned long *rmid_busy_llc;struct mbm_state *mbm_total;
arch/x86/kernel/cpu/resctrl/core.c +8 -8
@@ -352,7 +352,7 @@ 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))return d;
@@ -401,12 +401,12 @@ struct rdt_domain *rdt_find_domain(struct rdt_resource *r, int id,return ERR_PTR (-ENODEV );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 ; }
@@ -544,7 +544,7 @@ static void domain_add_cpu(int cpu, struct rdt_resource *r)return ; d = &hw_dom->d_resctrl; - d->id = id; + d->hdr.id = id;cpumask_set_cpu (cpu, &d->cpu_mask);rdt_domain_reconfigure_cdp (r);
@@ -559,11 +559,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); } }
@@ -587,7 +587,7 @@ static void domain_remove_cpu(int cpu, struct rdt_resource *r)cpumask_clear_cpu (cpu, &d->cpu_mask);if (cpumask_empty (&d->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 +8 -8
@@ -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 ; }
@@ -144,7 +144,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 ; }
@@ -224,8 +224,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))
@@ -316,7 +316,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];
@@ -464,7 +464,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,";" );
@@ -474,7 +474,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; }
@@ -503,7 +503,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 {
arch/x86/kernel/cpu/resctrl/monitor.c +1 -1
@@ -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, list) { +list_for_each_entry (d, &r->domains, hdr.list) {if (cpumask_test_cpu (cpu, &d->cpu_mask)) { err = resctrl_arch_rmid_read(r, d, entry->rmid, QOS_L3_OCCUP_EVENT_ID,
arch/x86/kernel/cpu/resctrl/pseudo_lock.c +1 -1
@@ -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, 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);
arch/x86/kernel/cpu/resctrl/rdtgroup.c +22 -22
168 lines not on this page · raw message
Reinette Chatre
maintainerRe: [PATCH v5 3/8] x86/resctrl: Split the rdt_domain structure
Hi Tony,
Quoted 31 lines · Tony Luck
Quoted 10 lines · Reinette Chatre
Review
Quoted 2 lines
(quoted diff) +2
-0+struct rdt_domain { + // First three fields must match struct rdt_mondomain below.Please avoid comments within declarations. Even so, could you please elaborate what the above means? Why do the first three fields have to match? I understand there is common code, for example,
__rdt_find_domain()that operated on the same members of the two structs but does that require the members be in the same position in the struct?
I understand that a comment may be required if position in the struct is important but I cannot see that it is.[Just replying to this one point in your message to get guidance. I'll address all the rest in other replies]
I'm wrong about the first *three* fields ... but the first *two* fields (the "list" and the "id") do need to be at the same offsets in different structures if a common routine is going to be used to access those fields.
If the "id" were at offset
0x10in the control version of the domain structure, and at offset0x20in the monitor version of the domain structure, there would be no hope for a common routine to access the "id" field when searching a list that could be either control or monitor domains.I'm looking at making this far more explicit with a new patch between 0001 and 0002 that pulls the two fields into a common substructure that will be included in each of the control and monitor versions of the structure.
Quoted 6 lines
Patch included below.
But this seems like it is a lot of churn to avoid having separate functions to search control and monitor lists. Each a clone of the existing ~24 line
rdt_find_domain()with just the type changed for the return value and the list travsersal.
Yes. Sorry, I did not realize this implication during the earlier discussions.
Quoted 3 lines
What do you think?
It sounds to me as though you are advocating for open coding rdt_find_ctrl_domain() and rdt_find_mon_domain()? That sounds good to me.
Sorry for the noise.
Reinette
Luck, Tony
maintainerRE: [PATCH v5 3/8] x86/resctrl: Split the rdt_domain structure
Quoted 9 lines
Quoted 4 lines
But this seems like it is a lot of churn to avoid having separate functions to search control and monitor lists. Each a clone of the existing ~24 line
rdt_find_domain()with just the type changed for the return value and the list travsersal.Yes. Sorry, I did not realize this implication during the earlier discussions.
Quoted 1 line
Quoted 6 lines
Quoted 2 lines
What do you think?
It sounds to me as though you are advocating for open coding
rdt_find_ctrl_domain()andrdt_find_mon_domain()? That sounds good to me.
Reinette,
While there is some churn, it maybe isn't all that bad. I also ran the open coding case and having a pair of 24-line functions one after the other with just two trivial lines changed between them is unlikely to get past the x86 maintainers without running this same conversation again.
-Tony
Reinette Chatre
maintainerRe: [PATCH v5 3/8] x86/resctrl: Split the rdt_domain structure
Hi Tony,
Quoted 16 lines · Tony
Quoted 9 lines
Quoted 4 lines
But this seems like it is a lot of churn to avoid having separate functions to search control and monitor lists. Each a clone of the existing ~24 line
rdt_find_domain()with just the type changed for the return value and the list travsersal.Yes. Sorry, I did not realize this implication during the earlier discussions.
Quoted 1 line
Quoted 6 lines
Quoted 2 lines
What do you think?
It sounds to me as though you are advocating for open coding
rdt_find_ctrl_domain()andrdt_find_mon_domain()? That sounds good to me.
Quoted 7 lines
Reinette,
While there is some churn, it maybe isn't all that bad. I also ran the open coding case and having a pair of 24-line functions one after the other with just two trivial lines changed between them is unlikely to get past the x86 maintainers without running this same conversation again.
I expect you are right and your proposal makes the code cleaner. Could the list_entry() call within rdt_find_domain() instead extract a pointer to a struct rdt_domain_hdr? To me that would make it most generic and avoid using wrong type for a pointer. I do think that may have been what you intended by moving id in there though ...
Reinette
Luck, Tony
maintainerRE: [PATCH v5 3/8] x86/resctrl: Split the rdt_domain structure
Quoted 5 lines
I expect you are right and your proposal makes the code cleaner. Could the
list_entry()call withinrdt_find_domain()instead extract a pointer to a structrdt_domain_hdr? To me that would make it most generic and avoid using wrong type for a pointer. I do think that may have been what you intended by moving id in there though ...
Reinette,
Exactly my thoughts! The function currently looks like this (though I expect my mail client may mess up the formatting):
struct rdt_domain_hdr *rdt_find_domain(struct list_head *h, int id,
struct list_head **pos)
{
struct rdt_domain_hdr *d;
struct list_head *l;
if (id < 0)
return ERR_PTR(-ENODEV);
list_for_each(l, h) {
d = list_entry(l, struct rdt_domain_hdr, list);
/* When id is found, return its domain. */
if (id == d->id)
return d;
/* Stop searching when finding id's position in sorted list. */
if (id < d->id)
break;
}
if (pos)
*pos = l;
return NULL;
}and a typical caller does this:
struct rdt_domain_hdr *hdr;
struct rdt_mon_domain *d;
hdr = rdt_find_domain(&r->mon_domains, id, &add_pos);
if (IS_ERR(hdr)) {
pr_warn("Couldn't find monitor scope id=%d for CPU %d\n", id, cpu);
return;
}
d = container_of(hdr, struct rdt_mon_domain, hdr);-Tony
Reinette Chatre
maintainerRe: [PATCH v5 3/8] x86/resctrl: Split the rdt_domain structure
Hi Tony,
Quoted 38 lines · Tony
Quoted 5 lines
I expect you are right and your proposal makes the code cleaner. Could the
list_entry()call withinrdt_find_domain()instead extract a pointer to a structrdt_domain_hdr? To me that would make it most generic and avoid using wrong type for a pointer. I do think that may have been what you intended by moving id in there though ...Reinette,
Exactly my thoughts! The function currently looks like this (though I expect my mail client may mess up the formatting):
struct
rdt_domain_hdr*rdt_find_domain(structlist_head*h, int id,
structlist_head**pos){ struct rdt_domain_hdr *d; struct list_head *l; if (id < 0) return ERR_PTR(-ENODEV); list_for_each(l, h) { d = list_entry(l, struct rdt_domain_hdr, list); /* When id is found, return its domain. */ if (id == d->id) return d; /* Stop searching when finding id's position in sorted list. */ if (id < d->id) break; } if (pos) *pos = l; return NULL; }and a typical caller does this:
Quoted 13 lines
struct rdt_domain_hdr *hdr;
struct rdt_mon_domain *d;
hdr = rdt_find_domain(&r->mon_domains, id, &add_pos);
if (IS_ERR(hdr)) {
pr_warn("Couldn't find monitor scope id=%d for CPU %d\n", id, cpu);
return;
}
d = container_of(hdr, struct rdt_mon_domain, hdr);This looks very good to me. Thank you very much for creating a solution that integrates well.
Reinette
Tony Luck
maintainerRe: [PATCH v5 3/8] x86/resctrl: Split the rdt_domain structure
In reply to Reinette ChatreQuoted 5 lines · Reinette Chatre
Hi Tony,
Subject:
x86/resctrl: Split the
rdt_domainandrdt_hw_domainstructures
Fixed subject as suggested.
Quoted 6 lines · Tony Luck
Quoted 1 line
The same
rdt_domainstructure is used for both control an monitor"control an monitor" -> "control and monitor"
Fixed.
Quoted 10 lines
Quoted 9 lines
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.
Create a new
rdt_mondomainstructure tailored explicitly for use in monitor parts of the core. Slim down therdt_domainstructure by removing the unused monitor fields.
Quoted 4 lines
Similar to the previous patch I think it will make the code easier to understand if the naming is clear for both monitoring and control structured. Why not
rdt_mondomainandrdt_ctrldomaininstead?
Done.
Quoted 5 lines
Quoted 3 lines
Similar breakout of struct
rdt_hw_mondomainfrom structrdt_hw_domain.
rdt_hw_mondomainandrdt_hw_ctrldomain?
Yes. rdt_hw_domain is split two ways and each gets an appropriate name. I added an extra "_" to match shape of other names. So these are now "rdt_hw_ctrl_domain" and "rdt_hw_mon_domain"
Quoted 33 lines
Quoted 22 lines
Signed-off-by Tony Luck <[email protected]>--- include/linux/resctrl.h | 46 +++++++++++++++-------- arch/x86/kernel/cpu/resctrl/internal.h | 38 +++++++++++++------ arch/x86/kernel/cpu/resctrl/core.c | 18 ++++----- arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 4 +- arch/x86/kernel/cpu/resctrl/monitor.c | 40 ++++++++++---------- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 24 ++++++------ 6 files changed, 101 insertions(+), 69 deletions(-)include/linux/resctrl.h +2
-1@@ -53,7 +53,29 @@ struct resctrl_staged_config { };/** -* struct rdt_domain - group of CPUs sharing a resctrl resource +* struct rdt_domain - group of CPUs sharing a resctrl control resource +* @list: all instances of this resource include/linux/resctrl.h struct resctrl_staged_config { · line 67
Quoted 10 lines
include/linux/resctrl.h +10
-0+* @id: unique id for this instance +* @cpu_mask: which CPUs share this resource +* @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 { +// First three fields must match struct rdt_mondomain below.
Quoted 7 lines
Please avoid comments within declarations. Even so, could you please elaborate what the above means? Why do the first three fields have to match? I understand there is common code, for example,
__rdt_find_domain()that operated on the same members of the two structs but does that require the members be in the same position in the struct?
I understand that a comment may be required if position in the struct is important but I cannot see that it is.
Discussed in other e-mail thread. Comments go away. The TWO (not three) fields that must be common are now in an embedded "rdt_domain_hdr" structure.
Quoted 22 lines
Quoted 22 lines
include/linux/resctrl.h +11
-3+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; +}; + +/** +* struct rdt_mondomain - group of CPUs sharing a resctrl monitor resource * @list: all instances of this resource * @id: unique id for this instance * @cpu_mask: which CPUs share this resource @@ -64,16 +86,13 @@ struct resctrl_staged_config {* @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
Quoted 8 lines
include/linux/resctrl.h struct resctrl_staged_config { · line 91
Quoted 6 lines
include/linux/resctrl.h +2
-3-* specified control values for mba_sc in MBps, indexed -* by closid */ -struct rdt_domain { +struct rdt_mondomain { +// First three fields must match struct rdt_domain above. Same comment.
Same solution.
Quoted 28 lines
Quoted 18 lines
include/linux/resctrl.h +1
-3struct list_head list;int id;struct cpumask cpu_mask; +unsigned long *rmid_busy_llc;struct mbm_state *mbm_total;struct mbm_state *mbm_local;@@ -81,9 +100,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; };/** ...
Quoted 7 lines
arch/x86/kernel/cpu/resctrl/ctrlmondata.c +0
-0@@ -521,7 +521,7 @@ int rdtgroup_schemata_show(struct kernfs_open_file *of, }
Quoted 14 lines
arch/x86/kernel/cpu/resctrl/ctrlmondata.c int rdtgroup_mondata_show(struct seq_file *m, void *arg) · line 547
Quoted 12 lines
arch/x86/kernel/cpu/resctrl/ctrlmondata.c +2
-2void mon_event_read (struct rmid_read *rr,struct rdt_resource *r, -struct rdt_domain *d,struct rdtgroup *rdtgrp, +struct rdt_mondomain *d,struct rdtgroup *rdtgrp,int evtid,int first) {/* @@ -544,7 +544,7 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg)struct rdtgroup *rdtgrp;struct rdt_resource *r;union mon_data_bits md; -struct rdt_domain *d; +struct rdt_mondomain *d;Reverse fir order.
Fixed.
Quoted 46 lines
Quoted 46 lines
arch/x86/kernel/cpu/resctrl/ctrlmondata.c +0
-0struct rmid_read rr;int ret =0 ;arch/x86/kernel/cpu/resctrl/monitor.c +5
-5@@ -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_mondomain *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_mondomain *d,u32 rmid,enum resctrl_event_id eventid) { -struct rdt_hw_domain *hw_dom =resctrl_to_arch_dom (d); +struct rdt_hw_mondomain *hw_dom =resctrl_to_arch_mondom (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_mondomain *d) { -struct rdt_hw_domain *hw_dom =resctrl_to_arch_dom (d); +struct rdt_hw_mondomain *hw_dom =resctrl_to_arch_mondom (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; }
Quoted 9 lines
arch/x86/kernel/cpu/resctrl/monitor.c static u64 mbm_overflow_count(u64 prev_msr, u64 cur_msr, unsigned int width) · line 236
Quoted 7 lines
arch/x86/kernel/cpu/resctrl/monitor.c +2
-2-int resctrl_arch_rmid_read (struct rdt_resource *r,struct rdt_domain *d, +int resctrl_arch_rmid_read (struct rdt_resource *r,struct rdt_mondomain *d,u32 rmid,enum resctrl_event_id eventid,u64 *val) {struct rdt_hw_resource *hw_res =resctrl_to_arch_res (r); -struct rdt_hw_domain *hw_dom =resctrl_to_arch_dom (d); +struct rdt_hw_mondomain *hw_mondom =resctrl_to_arch_mondom (d);Reverse fir.
Fixed.
Quoted 67 lines
Quoted 67 lines
arch/x86/kernel/cpu/resctrl/monitor.c +7
-7struct arch_mbm_state *am;u64 msr_val, chunks;int ret;@@ -245,7 +245,7 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain *d,if (ret)return ret; - am =get_arch_mbm_state (hw_dom, rmid, eventid); + am =get_arch_mbm_state (hw_mondom, rmid, eventid);if (am) { am->chunks +=mbm_overflow_count (am->prev_msr, msr_val, hw_res->mbm_width);@@ -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_mondomain *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_mondomain *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_mondomain *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_mondomain *d,u32 rmid,enum resctrl_event_id evtid) {switch (evtid) {@@ -516,7 +516,7 @@ 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_mondomain *dom_mbm) {u32 closid, rmid, cur_msr_val, new_msr_val;struct mbm_state *pmbm_data, *cmbm_data;@@ -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_mondomain *d,int rmid) {struct rmid_read rr;
Quoted 8 lines
arch/x86/kernel/cpu/resctrl/monitor.c void cqm_handle_limbo(struct work_struct *work) · line 644
Quoted 6 lines
arch/x86/kernel/cpu/resctrl/monitor.c +1
-1@@ -641,12 +641,12 @@ void cqm_handle_limbo(struct work_struct *work)unsigned long delay =msecs_to_jiffies (CQM_LIMBOCHECK_INTERVAL );int cpu =smp_processor_id ();struct rdt_resource *r; -struct rdt_domain *d; +struct rdt_mondomain *d;Reverse fir (Please check all code).
Fixed. (I wrote a simple awk script to find these (as I'm obviously bad at noticing them). Included at end of this message).
Quoted 2 lines
Reinette
#!/usr/bin/awk -f
BEGIN {
keyw["bool"] = 1
keyw["char"] = 1
keyw["enum"] = 1
keyw["int"] = 1
keyw["long"] = 1
keyw["short"] = 1
keyw["static"] = 1
keyw["struct"] = 1
keyw["u16"] = 1
keyw["u32"] = 1
keyw["u64"] = 1
keyw["u8"] = 1
keyw["unsigned"] = 1
keyw["void"] = 1
}{
source[NR] = $0
if ($0 == "{") {
infunction = NR
skip
}
if ($0 == "}") {
infunction = 0
skip
}
if (infunction && ($1 in keyw)) {
inlocals++
if (inlocals > 1 && length(source[NR - 1]) < length)
badfir = 1
skip
}
if (inlocals && NF == 0) {
if (badfir) {
print "==== BAD FIR ===="
for (i = infunction - 2; i < NR; i++)
printf("%4d: %s\n", i, source[i])
}
inlocals = 0
badfir = 0
}
}Reinette Chatre
maintainerRe: [PATCH v5 3/8] x86/resctrl: Split the rdt_domain structure
Hi Tony,
Quoted 11 lines · Tony Luck
Quoted 6 lines · Reinette Chatre
Quoted 1 line · Tony Luck
Similar breakout of struct
rdt_hw_mondomainfrom structrdt_hw_domain.
rdt_hw_mondomainandrdt_hw_ctrldomain?Yes.
rdt_hw_domainis split two ways and each gets an appropriate name. I added an extra "_" to match shape of other names. So these are now "rdt_hw_ctrl_domain" and "rdt_hw_mon_domain"
Thank you for adding the extra "_", it looks good.
...
Quoted 9 lines
Quoted 8 lines
arch/x86/kernel/cpu/resctrl/monitor.c void cqm_handle_limbo(struct work_struct *work) · line 644
Quoted 6 lines
arch/x86/kernel/cpu/resctrl/monitor.c +1
-1@@ -641,12 +641,12 @@ void cqm_handle_limbo(struct work_struct *work)unsigned long delay =msecs_to_jiffies (CQM_LIMBOCHECK_INTERVAL );int cpu =smp_processor_id ();struct rdt_resource *r; -struct rdt_domain *d; +struct rdt_mondomain *d;Reverse fir (Please check all code).
Quoted 3 lines
Fixed. (I wrote a simple awk script to find these (as I'm obviously bad at noticing them). Included at end of this message).
Thank you very much for sharing your script.
Reinette
Tony Luck
maintainerPATCH v5 4/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 "node" as a new option for domain scope.
--- include/linux/resctrl.h | 1 + arch/x86/kernel/cpu/resctrl/core.c | 2 ++ 2 files changed, 3 insertions(+)
include/linux/resctrl.h +1 -0
@@ -163,6 +163,7 @@ struct resctrl_schema;enum resctrl_scope {RESCTRL_L3_CACHE ,RESCTRL_L2_CACHE , +RESCTRL_NODE , };/**
arch/x86/kernel/cpu/resctrl/core.c +2 -0
@@ -514,6 +514,8 @@ static int get_domain_id_from_scope(int cpu, enum resctrl_scope scope)return get_cpu_cacheinfo_id (cpu,3 );case RESCTRL_L2_CACHE :return get_cpu_cacheinfo_id (cpu,2 ); +case RESCTRL_NODE : +return cpu_to_node (cpu);default :WARN_ON_ONCE (1 );break ;
Signature · 1 line
2.41.0
Reinette Chatre
maintainerRe: [PATCH v5 4/8] x86/resctrl: Add node-scope to the options for feature scope
Hi Tony,
Quoted 2 lines · Tony Luck
Currently supported resctrl features are all domain scoped the same as the scope of the L2 or L3 caches.
fyi ... this patch series seems to use the terms "resctrl feature" and "resctrl resource" interchangeably and it is not always clear if the terms mean something different.
Quoted 2 lines
Add "node" as a new option for domain scope.
Could the commit message please get a snippet about what "node" represents and why this new scope is needed?
Quoted 23 lines
Signed-off-by Tony Luck <[email protected]>--- include/linux/resctrl.h | 1 + arch/x86/kernel/cpu/resctrl/core.c | 2 ++ 2 files changed, 3 insertions(+)include/linux/resctrl.h +1
-0@@ -163,6 +163,7 @@ struct resctrl_schema;enum resctrl_scope {RESCTRL_L3_CACHE ,RESCTRL_L2_CACHE , +RESCTRL_NODE , };/** arch/x86/kernel/cpu/resctrl/core.c +0
-0
arch/x86/kernel/cpu/resctrl/core.c static int get_domain_id_from_scope(int cpu, enum resctrl_scope scope) · line 521
Quoted 8 lines
arch/x86/kernel/cpu/resctrl/core.c +2
-0@@ -514,6 +514,8 @@ static int get_domain_id_from_scope(int cpu, enum resctrl_scope scope)return get_cpu_cacheinfo_id (cpu,3 );case RESCTRL_L2_CACHE :return get_cpu_cacheinfo_id (cpu,2 ); +case RESCTRL_NODE : +return cpu_to_node (cpu);default :WARN_ON_ONCE (1 );break ;
Reinette
Tony Luck
maintainerRe: [PATCH v5 4/8] x86/resctrl: Add node-scope to the options for feature scope
Quoted 9 lines · Reinette Chatre
Hi Tony,
Quoted 2 lines · Tony Luck
Currently supported resctrl features are all domain scoped the same as the scope of the L2 or L3 caches.
fyi ... this patch series seems to use the terms "resctrl feature" and "resctrl resource" interchangeably and it is not always clear if the terms mean something different.
I think a "resctrl feature" is a h/w control or monitor feature. A "resctrl resource" is "struct rdt_resource" (which may have more than one "resctrl feature" attached to it. E.g. the RDT_RESOURCE_L3 resource has L3 CAT, MBM, CQM attached).
Quoted 6 lines
Quoted 3 lines
Add "node" as a new option for domain scope.
Could the commit message please get a snippet about what "node" represents and why this new scope is needed?
Yes. I've added a note.
Quoted 35 lines
Quoted 24 lines
Signed-off-by Tony Luck <[email protected]>--- include/linux/resctrl.h | 1 + arch/x86/kernel/cpu/resctrl/core.c | 2 ++ 2 files changed, 3 insertions(+)include/linux/resctrl.h +1
-0@@ -163,6 +163,7 @@ struct resctrl_schema;enum resctrl_scope {RESCTRL_L3_CACHE ,RESCTRL_L2_CACHE , +RESCTRL_NODE , };/** arch/x86/kernel/cpu/resctrl/core.c +0
-0arch/x86/kernel/cpu/resctrl/core.c static int get_domain_id_from_scope(int cpu, enum resctrl_scope scope) · line 521
Quoted 8 lines
arch/x86/kernel/cpu/resctrl/core.c +2
-0@@ -514,6 +514,8 @@ static int get_domain_id_from_scope(int cpu, enum resctrl_scope scope)return get_cpu_cacheinfo_id (cpu,3 );case RESCTRL_L2_CACHE :return get_cpu_cacheinfo_id (cpu,2 ); +case RESCTRL_NODE : +return cpu_to_node (cpu);default :WARN_ON_ONCE (1 );break ;Reinette
Reinette Chatre
maintainerRe: [PATCH v5 4/8] x86/resctrl: Add node-scope to the options for feature scope
Hi Tony,
Quoted 7 lines · Tony Luck
Quoted 6 lines · Reinette Chatre
Hi Tony,
Quoted 2 lines · Tony Luck
Currently supported resctrl features are all domain scoped the same as the scope of the L2 or L3 caches.
Quoted 8 lines
Quoted 3 lines
fyi ... this patch series seems to use the terms "resctrl feature" and "resctrl resource" interchangeably and it is not always clear if the terms mean something different.
I think a "resctrl feature" is a h/w control or monitor feature. A "resctrl resource" is "struct
rdt_resource" (which may have more than one "resctrl feature" attached to it. E.g. theRDT_RESOURCE_L3resource has L3 CAT, MBM, CQM attached).
Please keep in mind that in resctrl documentation (Documentation/arch/x86/resctrl.rst) L3_MON is described as a resource. The main message is just to ensure that it is clear what is meant with particular terms and then be consistent in their use.
Reinette
Tony Luck
maintainerPATCH v5 5/8 x86/resctrl: Introduce snc_nodes_per_l3_cache
In reply to Tony LuckIntel Sub-NUMA Cluster 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.
A later patch will detect SNC mode and set snc_nodes_per_l3_cache to the appropriate value. For now it remains at the default "1" to indicate SNC mode is not active.
Code that needs to take action when SNC is enabled is:
1) The number of logical RMIDs available for use is the number of physical RMIDs divided by the number of SNC nodes.
2) Likewise the "mon_scale" value must be adjusted for the number of SNC nodes.
3) When reading an RMID counter code must adjust from the logical RMID used to the physical RMID value that must be loaded 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 adjusted.
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.
--- arch/x86/kernel/cpu/resctrl/internal.h | 2 ++ arch/x86/kernel/cpu/resctrl/core.c | 7 +++++++ arch/x86/kernel/cpu/resctrl/monitor.c | 16 +++++++++++++--- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 4 ++-- 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 int snc_nodes_per_l3_cache; +enum resctrl_res_level {RDT_RESOURCE_L3 ,RDT_RESOURCE_L2 ,
arch/x86/kernel/cpu/resctrl/core.c +7 -0
@@ -48,6 +48,13 @@ 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. +*/ +int snc_nodes_per_l3_cache =1 ; +static void mba_wrmsr_intel (struct rdt_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 +2 -2
@@ -1367,7 +1367,7 @@ unsigned int rdtgroup_cbm_to_size(struct rdt_resource *r, } } -return size; +return size / snc_nodes_per_l3_cache; }/**
@@ -2600,7 +2600,7 @@ static int rdt_parse_param(struct fs_context *fc, struct fs_parameter *param) ctx->enable_cdpl2 = true;return 0 ;case Opt_mba_mbps: -if (!supports_mba_mbps ()) +if (!supports_mba_mbps () || snc_nodes_per_l3_cache >1 )return -EINVAL ; ctx->enable_mba_mbps = true;return 0 ;
Signature · 1 line
2.41.0
Reinette Chatre
maintainerRe: [PATCH v5 5/8] x86/resctrl: Introduce snc_nodes_per_l3_cache
Hi Tony,
On 8/29/2023 4:44 PM, Tony Luck wrote:
Could the commit message please provide a brief overview of what SNC is before jumping to the things needed to support it?
Quoted 1 line
Intel Sub-NUMA Cluster mode requires several changes in resctrl
I think the intention is to introduce the acronym here so maybe:
"Intel Sub-NUMA Cluster (SNC) ..."
Quoted 6 lines
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.
Quoted 7 lines
A later patch will detect SNC mode and set
snc_nodes_per_l3_cacheto the appropriate value. For now it remains at the default "1" to indicate SNC mode is not active.Code that needs to take action when SNC is enabled is:
1) The number of logical RMIDs available for use is the number of physical RMIDs divided by the number of SNC nodes.
Could this maybe be "... number of SNC nodes per L3 cache" to be specific? Even so, this jumps into supporting logical RMIDs and physical RMIDs without introducing what logical vs physical means. Is this something that can be added to the intro of this commit message?
Quoted 10 lines
2) Likewise the "
mon_scale" value must be adjusted for the number of SNC nodes.
3) When reading an RMID counter code must adjust from the logical RMID used to the physical RMID value that must be loaded into theIA32_QM_EVTSELMSR.
4) The L3 cache is divided between the SNC nodes. So the value reported in the resctrl "size" file is adjusted.
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.
This motivation for disabling is not clear to me. Why is only mba_MBps impacted? MBA is also at the L3 scope and it is not disabled. Neither is cache allocation that remains at L3 scope with its monitoring moving to node scope.
Quoted 27 lines
Signed-off-by Tony Luck <[email protected]>--- arch/x86/kernel/cpu/resctrl/internal.h | 2 ++ arch/x86/kernel/cpu/resctrl/core.c | 7 +++++++ arch/x86/kernel/cpu/resctrl/monitor.c | 16 +++++++++++++--- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 4 ++-- 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 int snc_nodes_per_l3_cache; +enum resctrl_res_level {RDT_RESOURCE_L3 ,RDT_RESOURCE_L2 ,arch/x86/kernel/cpu/resctrl/core.c +0
-0
arch/x86/kernel/cpu/resctrl/core.c int max_name_width, max_data_width; · line 55
Quoted 8 lines
arch/x86/kernel/cpu/resctrl/core.c +5
-0@@ -48,6 +48,13 @@ 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. +*/
There is some extra space available to make the lines longer.
Quoted 12 lines
arch/x86/kernel/cpu/resctrl/core.c +2
-0+int snc_nodes_per_l3_cache =1 ; +static void mba_wrmsr_intel (struct rdt_domain *d,struct msr_param *m,struct rdt_resource *r);arch/x86/kernel/cpu/resctrl/monitor.c +0
-0@@ -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)
arch/x86/kernel/cpu/resctrl/monitor.c static inline struct rmid_entry *__rmid_entry(u32 rmid) · line 159
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/monitor.c +7
-0{ +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 +*/
Please end sentence with a period.
Quoted 40 lines
arch/x86/kernel/cpu/resctrl/monitor.c +6
-3+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 +1
-1@@ -1367,7 +1367,7 @@ unsigned int rdtgroup_cbm_to_size(struct rdt_resource *r, } } -return size; +return size / snc_nodes_per_l3_cache; }/**
arch/x86/kernel/cpu/resctrl/rdtgroup.c static int rdt_parse_param(struct fs_context *fc, struct fs_parameter *param) · line 2606
Quoted 8 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +1
-1@@ -2600,7 +2600,7 @@ static int rdt_parse_param(struct fs_context *fc, struct fs_parameter *param) ctx->enable_cdpl2 = true;return 0 ;case Opt_mba_mbps: -if (!supports_mba_mbps ()) +if (!supports_mba_mbps () || snc_nodes_per_l3_cache >1 )return -EINVAL ; ctx->enable_mba_mbps = true;return 0 ;
Reinette
Tony Luck
maintainerRe: [PATCH v5 5/8] x86/resctrl: Introduce snc_nodes_per_l3_cache
Quoted 6 lines · Reinette Chatre
Hi Tony,
On 8/29/2023 4:44 PM, Tony Luck wrote:
Could the commit message please provide a brief overview of what SNC is before jumping to the things needed to support it?
Ok. Added an overview.
Quoted 5 lines
Quoted 2 lines
Intel Sub-NUMA Cluster mode requires several changes in resctrl
I think the intention is to introduce the acronym here so maybe:
"Intel Sub-NUMA Cluster (SNC) ..."
Commit now starts with this definiton.
Quoted 11 lines
Quoted 11 lines
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.A later patch will detect SNC mode and set
snc_nodes_per_l3_cacheto the appropriate value. For now it remains at the default "1" to indicate SNC mode is not active.
Quoted 8 lines
Quoted 3 lines
Code that needs to take action when SNC is enabled is:
1) The number of logical RMIDs available for use is the number of physical RMIDs divided by the number of SNC nodes.Could this maybe be "... number of SNC nodes per L3 cache" to be specific? Even so, this jumps into supporting logical RMIDs and physical RMIDs without introducing what logical vs physical means. Is this something that can be added to the intro of this commit message?
Added that to be specific. Also added more preamble text to set up context.
Quoted 12 lines
Quoted 11 lines
2) Likewise the "
mon_scale" value must be adjusted for the number of SNC nodes.
3) When reading an RMID counter code must adjust from the logical RMID used to the physical RMID value that must be loaded into theIA32_QM_EVTSELMSR.
4) The L3 cache is divided between the SNC nodes. So the value reported in the resctrl "size" file is adjusted.
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.
Quoted 4 lines
This motivation for disabling is not clear to me. Why is only
mba_MBpsimpacted? MBA is also at the L3 scope and it is not disabled. Neither is cache allocation that remains at L3 scope with its monitoring moving to node scope.
Added text for why (essentially the s/w feedback loop now has independent MBM inputs from each SNC node, but still only one MBA control at L3 cache scope. The feedback code can't do any thing useful if one SNC node says "I'm running too fast" while another node sharing same L3 says "I'm running too slow".
Quoted 31 lines
Quoted 31 lines
Signed-off-by Tony Luck <[email protected]>--- arch/x86/kernel/cpu/resctrl/internal.h | 2 ++ arch/x86/kernel/cpu/resctrl/core.c | 7 +++++++ arch/x86/kernel/cpu/resctrl/monitor.c | 16 +++++++++++++--- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 4 ++-- 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 int snc_nodes_per_l3_cache; +enum resctrl_res_level {RDT_RESOURCE_L3 ,RDT_RESOURCE_L2 ,arch/x86/kernel/cpu/resctrl/core.c +0
-0@@ -48,6 +48,13 @@ int max_name_width, max_data_width;*/ bool rdt_alloc_capable;
Quoted 7 lines
arch/x86/kernel/cpu/resctrl/core.c int max_name_width, max_data_width; · line 55
Quoted 5 lines
arch/x86/kernel/cpu/resctrl/core.c +5
-0+/* +* Number of SNC nodes that share each L3 cache. +* Default is 1 for systems that do not support +* SNC, or have SNC disabled. +*/ There is some extra space available to make the lines longer.
Re-formatted to use longer lines.
Quoted 19 lines
Quoted 19 lines
arch/x86/kernel/cpu/resctrl/core.c +2
-0+int snc_nodes_per_l3_cache =1 ; +static void mba_wrmsr_intel (struct rdt_domain *d,struct msr_param *m,struct rdt_resource *r);arch/x86/kernel/cpu/resctrl/monitor.c +3
-0@@ -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;
Quoted 6 lines
arch/x86/kernel/cpu/resctrl/monitor.c static inline struct rmid_entry *__rmid_entry(u32 rmid) · line 159
Quoted 4 lines
arch/x86/kernel/cpu/resctrl/monitor.c +4
-0+/* +* When SNC mode is on, need to compute the offset to read the +* physical RMID counter for the node to which this CPU belongs +*/ Please end sentence with a period.
Added period.
Quoted 52 lines
Quoted 41 lines
arch/x86/kernel/cpu/resctrl/monitor.c +6
-3+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 +1
-1@@ -1367,7 +1367,7 @@ unsigned int rdtgroup_cbm_to_size(struct rdt_resource *r, } } -return size; +return size / snc_nodes_per_l3_cache; }/** arch/x86/kernel/cpu/resctrl/rdtgroup.c static int rdt_parse_param(struct fs_context *fc, struct fs_parameter *param) · line 2606
Quoted 8 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +1
-1@@ -2600,7 +2600,7 @@ static int rdt_parse_param(struct fs_context *fc, struct fs_parameter *param) ctx->enable_cdpl2 = true;return 0 ;case Opt_mba_mbps: -if (!supports_mba_mbps ()) +if (!supports_mba_mbps () || snc_nodes_per_l3_cache >1 )return -EINVAL ; ctx->enable_mba_mbps = true;return 0 ;Reinette
Tony Luck
maintainerPATCH v5 6/8 x86/resctrl: Sub NUMA Cluster detection and enable
In reply to Tony LuckThere isn't a simple h/w bit that indicates whether a CPU is running in Sub NUMA Cluster 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.
--- arch/x86/include/asm/msr-index.h | 1 + arch/x86/kernel/cpu/resctrl/core.c | 68 ++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+)
arch/x86/include/asm/msr-index.h +1 -0
@@ -1100,6 +1100,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 +68 -0
101 lines not on this page · raw message
Signature · 1 line
2.41.0
Reinette Chatre
maintainerRe: [PATCH v5 6/8] x86/resctrl: Sub NUMA Cluster detection and enable
Hi Tony,
Quoted 2 lines · Tony Luck
There isn't a simple h/w bit that indicates whether a CPU is running in Sub NUMA Cluster mode. Infer the state by comparing
Sub NUMA Cluster (SNC)
Quoted 4 lines
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.
Can it be explained how RMID counters are reconfigured when the MSR is updated?
Quoted 39 lines
Signed-off-by Tony Luck <[email protected]>--- arch/x86/include/asm/msr-index.h | 1 + arch/x86/kernel/cpu/resctrl/core.c | 68 ++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+)arch/x86/include/asm/msr-index.h +1
-0@@ -1100,6 +1100,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 +3
-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"
arch/x86/kernel/cpu/resctrl/core.c static void clear_closid_rmid(int cpu) · line 735
Quoted 9 lines
arch/x86/kernel/cpu/resctrl/core.c +6
-0@@ -724,11 +727,34 @@ 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. +* Clearing bit 0 reconfigures the RMID counters for use +* in Sub NUMA Cluster mode. +*/
I think I missed where "legacy mode" and "Sub NUMA Cluster mode" are explained.
arch/x86/kernel/cpu/resctrl/core.c static void clear_closid_rmid(int cpu) · line 740
Quoted 5 lines
arch/x86/kernel/cpu/resctrl/core.c +5
-0+static void snc_remap_rmids (int cpu) +{ +u64 val; + +/* Only need to enable once per package */
Sentence end with period.
arch/x86/kernel/cpu/resctrl/core.c static void clear_closid_rmid(int cpu) · line 743
Quoted 3 lines
arch/x86/kernel/cpu/resctrl/core.c +3
-0+if (cpumask_first (topology_core_cpumask (cpu)) != cpu) +return ; +
This is an area I am not familiar with. The above code seems to assume that CPUs are onlined in a particular numerical order. For example, if I understand correctly, if CPUs are onlined from higher number to lower number then the above code may end up running on every CPU online.
Quoted 20 lines
arch/x86/kernel/cpu/resctrl/core.c +9
-0+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. */ @@ -983,11 +1009,53 @@ static __init bool get_rdt_resources(void)return (rdt_mon_capable || rdt_alloc_capable); }
arch/x86/kernel/cpu/resctrl/core.c static __init bool get_rdt_resources(void) · line 1020
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/core.c +9
-0+/* 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 ), + {} +}; + +static __init int get_snc_config (void )
Could this function please get a comment about what it does? The first paragraph from the commit message should be ok.
arch/x86/kernel/cpu/resctrl/core.c static __init bool get_rdt_resources(void) · line 1029
Quoted 9 lines
arch/x86/kernel/cpu/resctrl/core.c +9
-0+{ +unsigned long *node_caches; +int mem_only_nodes =0 ; +int cpu, node, ret; + +if (!x86_match_cpu (snc_cpu_ids)) +return 1 ; + + node_caches =kcalloc (BITS_TO_LONGS (nr_node_ids),sizeof (*node_caches),GFP_KERNEL );
How about bitmap_zalloc()?
Quoted 4 lines
arch/x86/kernel/cpu/resctrl/core.c +4
-0+if (!node_caches) +return 1 ; + +cpus_read_lock ();
arch/x86/kernel/cpu/resctrl/core.c static __init bool get_rdt_resources(void) · line 1043
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/core.c +10
-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); +else + mem_only_nodes++; + } +cpus_read_unlock (); + + ret = (nr_node_ids - mem_only_nodes) /bitmap_weight (node_caches, nr_node_ids);
My static checker complains about the above line risking
a "divide by zero" that may be the case if the bitmap_weight() returns zero. You may need to ensure this is safe here before more static checkers start analyzing this code.
arch/x86/kernel/cpu/resctrl/core.c static __init bool get_rdt_resources(void) · line 1050
Quoted 7 lines
arch/x86/kernel/cpu/resctrl/core.c +7
-0+kfree (node_caches); + +if (ret >1 ) + rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl.mon_scope =RESCTRL_NODE ; + +return ret; +}
As discussed there are scenarios where the above may not provide the correct value. Could you please document the assumptions of this code to highlight this to x86 maintainers for their opinions?
arch/x86/kernel/cpu/resctrl/core.c static __init bool get_rdt_resources(void) · line 1061
Quoted 11 lines
arch/x86/kernel/cpu/resctrl/core.c +3
-0+static __init void rdt_init_res_defs_intel (void ) {struct rdt_hw_resource *hw_res;struct rdt_resource *r; + snc_nodes_per_l3_cache =get_snc_config (); +for_each_rdt_resource (r) { hw_res =resctrl_to_arch_res (r);
Reinette
Tony Luck
maintainerRe: [PATCH v5 6/8] x86/resctrl: Sub NUMA Cluster detection and enable
Quoted 7 lines · Reinette Chatre
Hi Tony,
Quoted 2 lines · Tony Luck
There isn't a simple h/w bit that indicates whether a CPU is running in Sub NUMA Cluster mode. Infer the state by comparing
Sub NUMA Cluster (SNC)
Fixed.
Quoted 8 lines
Quoted 5 lines
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.Can it be explained how RMID counters are reconfigured when the MSR is updated?
Added some in previous patch (which implements the changes needed by the reconfuration). Small note in ths patch to refer to that.
Quoted 42 lines
Quoted 42 lines
Signed-off-by Tony Luck <[email protected]>--- arch/x86/include/asm/msr-index.h | 1 + arch/x86/kernel/cpu/resctrl/core.c | 68 ++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+)arch/x86/include/asm/msr-index.h +1
-0@@ -1100,6 +1100,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 +3
-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" @@ -724,11 +727,34 @@ static void clear_closid_rmid(int cpu)wrmsr (MSR_IA32_PQR_ASSOC ,0 ,0 ); }
Quoted 9 lines
arch/x86/kernel/cpu/resctrl/core.c static void clear_closid_rmid(int cpu) · line 735
Quoted 6 lines
arch/x86/kernel/cpu/resctrl/core.c +6
-0+/* +* The power-on reset value of MSR_RMID_SNC_CONFIG is 0x1 +* which indicates that RMIDs are configured in legacy mode. +* Clearing bit 0 reconfigures the RMID counters for use +* in Sub NUMA Cluster mode. +*/ I think I missed where "legacy mode" and "Sub NUMA Cluster mode" are explained.
Updated this comment to cover this better.
Quoted 8 lines
arch/x86/kernel/cpu/resctrl/core.c static void clear_closid_rmid(int cpu) · line 740
Quoted 6 lines
arch/x86/kernel/cpu/resctrl/core.c +5
-0+static void snc_remap_rmids (int cpu) +{ +u64 val; + +/* Only need to enable once per package */ Sentence end with period.
Period added.
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/core.c static void clear_closid_rmid(int cpu) · line 743
Quoted 4 lines
arch/x86/kernel/cpu/resctrl/core.c +3
-0+if (cpumask_first (topology_core_cpumask (cpu)) != cpu) +return ; +This is an area I am not familiar with. The above code seems to assume that CPUs are onlined in a particular numerical order. For example, if I understand correctly, if CPUs are onlined from higher number to lower number then the above code may end up running on every CPU online.
This sent me on a voyage of exploration into early Linux bringup. There's a CONFIG_HOTPLUG_PARALLEL option to bring CPUs up in parallel. I have it set on my kernel, but I still see the "announce_cpu()" console messages show up in monotonic increasing order:
[ 3.148423] smpboot: x86: Booting SMP configuration: [ 3.148940] .... node #0, CPUs: #1 #2 #3 #4 #5 #6 #7 and so on
But, without solving this mystery, I realized this doesn't matter. Whatever order the CPUs come online was all completed long before resctrl is initialized:
late_initcall(resctrl_late_init);
So the order that resctrl sees CPUs is dependent on the callbacks from the registration with cpuhp_setup_state(). That happens with:
/*
* Try to call the startup callback for each present cpu
* depending on the hotplug state of the cpu.
*/
for_each_present_cpu(cpu) {which is going to call in increasing numerical order as the bitmap of present CPUs is traversed.
If someone changed this, the only ill effect on the code I'm adding would be to set the MSR multiple times (which is inefficient, but won't break anything).
Quoted 22 lines
Quoted 22 lines
arch/x86/kernel/cpu/resctrl/core.c +9
-0+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. */ @@ -983,11 +1009,53 @@ static __init bool get_rdt_resources(void)return (rdt_mon_capable || rdt_alloc_capable); }
Quoted 12 lines
arch/x86/kernel/cpu/resctrl/core.c static __init bool get_rdt_resources(void) · line 1020
Quoted 9 lines
arch/x86/kernel/cpu/resctrl/core.c +9
-0+/* 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 ), + {} +}; + +static __init int get_snc_config (void )Could this function please get a comment about what it does? The first paragraph from the commit message should be ok.
Comment added. Also renamed to snc_get_config() so that these SNC related functions use the same naming convention.
Quoted 12 lines
arch/x86/kernel/cpu/resctrl/core.c static __init bool get_rdt_resources(void) · line 1029
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/core.c +9
-0+{ +unsigned long *node_caches; +int mem_only_nodes =0 ; +int cpu, node, ret; + +if (!x86_match_cpu (snc_cpu_ids)) +return 1 ; + + node_caches =kcalloc (BITS_TO_LONGS (nr_node_ids),sizeof (*node_caches),GFP_KERNEL );How about
bitmap_zalloc()?
Excellent! Now using it.
Quoted 12 lines
Quoted 12 lines
arch/x86/kernel/cpu/resctrl/core.c +11
-0+if (!node_caches) +return 1 ; + +cpus_read_lock (); +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 + mem_only_nodes++; + }
Quoted 8 lines
arch/x86/kernel/cpu/resctrl/core.c static __init bool get_rdt_resources(void) · line 1043
Quoted 3 lines
arch/x86/kernel/cpu/resctrl/core.c +3
-0+cpus_read_unlock (); + + ret = (nr_node_ids - mem_only_nodes) /bitmap_weight (node_caches, nr_node_ids);My static checker complains about the above line risking
a "divide by zero" that may be the case if thebitmap_weight()returns zero. You may need to ensure this is safe here before more static checkers start analyzing this code.
Added defensive code that checks result of bitmap_weight() for a zero return. If it does (somehow ... that means there are no nodes with CPUs that have an L3 cache!) then the code will assume SNC is not enabled.
Quoted 12 lines
arch/x86/kernel/cpu/resctrl/core.c static __init bool get_rdt_resources(void) · line 1050
Quoted 8 lines
arch/x86/kernel/cpu/resctrl/core.c +7
-0+kfree (node_caches); + +if (ret >1 ) + rdt_resources_all[RDT_RESOURCE_L3 ].r_resctrl.mon_scope =RESCTRL_NODE ; + +return ret; +}As discussed there are scenarios where the above may not provide the correct value. Could you please document the assumptions of this code to highlight this to x86 maintainers for their opinions?
Added a note that booting with maxcpus=N boot parameter will break this check in ways that cannot be worked around. Early boot code doesn't have to worry about user taking CPUs offline, because it runs before users can do that.
Quoted 14 lines
arch/x86/kernel/cpu/resctrl/core.c static __init bool get_rdt_resources(void) · line 1061
Quoted 11 lines
arch/x86/kernel/cpu/resctrl/core.c +3
-0+static __init void rdt_init_res_defs_intel (void ) {struct rdt_hw_resource *hw_res;struct rdt_resource *r; + snc_nodes_per_l3_cache =get_snc_config (); +for_each_rdt_resource (r) { hw_res =resctrl_to_arch_res (r);Reinette
Reinette Chatre
maintainerRe: [PATCH v5 6/8] x86/resctrl: Sub NUMA Cluster detection and enable
Hi Tony,
Quoted 37 lines · Tony Luck
Quoted 11 lines · Reinette Chatre
arch/x86/kernel/cpu/resctrl/core.c static void clear_closid_rmid(int cpu) · line 743
Quoted 3 lines · Tony Luck
arch/x86/kernel/cpu/resctrl/core.c +3
-0+if (cpumask_first (topology_core_cpumask (cpu)) != cpu) +return ; +This is an area I am not familiar with. The above code seems to assume that CPUs are onlined in a particular numerical order. For example, if I understand correctly, if CPUs are onlined from higher number to lower number then the above code may end up running on every CPU online.
This sent me on a voyage of exploration into early Linux bringup. There's a
CONFIG_HOTPLUG_PARALLELoption to bring CPUs up in parallel. I have it set on my kernel, but I still see the "announce_cpu()" console messages show up in monotonic increasing order:[ 3.148423] smpboot: x86: Booting SMP configuration: [ 3.148940] .... node #0, CPUs: #1 #2 #3 #4 #5 #6 #7 and so onBut, without solving this mystery, I realized this doesn't matter. Whatever order the CPUs come online was all completed long before resctrl is initialized:
late_initcall(resctrl_late_init);So the order that resctrl sees CPUs is dependent on the callbacks from the registration with
cpuhp_setup_state(). That happens with:/* * Try to call the startup callback for each present cpu * depending on the hotplug state of the cpu. */ for_each_present_cpu(cpu) {
Quoted 8 lines
which is going to call in increasing numerical order as the bitmap of present CPUs is traversed.
If someone changed this, the only ill effect on the code I'm adding would be to set the MSR multiple times (which is inefficient, but won't break anything).
Thank you very much for investigating this.
Reinette
Moger, Babu
reviewerRe: [PATCH v5 6/8] x86/resctrl: Sub NUMA Cluster detection and enable
In reply to Tony LuckHi Tony,
Quoted 30 lines · Tony Luck
There isn't a simple h/w bit that indicates whether a CPU is running in Sub NUMA Cluster 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.Signed-off-by Tony Luck <[email protected]>--- arch/x86/include/asm/msr-index.h | 1 + arch/x86/kernel/cpu/resctrl/core.c | 68 ++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+)arch/x86/include/asm/msr-index.h +1
-0@@ -1100,6 +1100,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 +0
-0
arch/x86/kernel/cpu/resctrl/core.c line 24
Quoted 9 lines
arch/x86/kernel/cpu/resctrl/core.c +2
-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>
I didnt see the need for this include.
Quoted 6 lines
arch/x86/kernel/cpu/resctrl/core.c +1
-0+#include <asm/cpu_device_id.h> #include <asm/intel-family.h> #include <asm/resctrl.h> #include "internal.h"
arch/x86/kernel/cpu/resctrl/core.c static void clear_closid_rmid(int cpu) · line 736
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/core.c +7
-0@@ -724,11 +727,34 @@ 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. +* Clearing bit 0 reconfigures the RMID counters for use +* in Sub NUMA Cluster mode. +*/ +static void snc_remap_rmids (int cpu)
While adding the new functions, i see that new function names start with resctrl_ prefix. However, we are all not very consistent. Can ypu rename this function to resctrl_snc_remap_rmids?
Quoted 27 lines
arch/x86/kernel/cpu/resctrl/core.c +16
-0+{ +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. */ @@ -983,11 +1009,53 @@ static __init bool get_rdt_resources(void)return (rdt_mon_capable || rdt_alloc_capable); }
arch/x86/kernel/cpu/resctrl/core.c static __init bool get_rdt_resources(void) · line 1020
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/core.c +9
-0+/* 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 ), + {} +}; + +static __init int get_snc_config (void )
Same comment as above.
Quoted 41 lines
arch/x86/kernel/cpu/resctrl/core.c +33
-0+{ +unsigned long *node_caches; +int mem_only_nodes =0 ; +int cpu, node, ret; + +if (!x86_match_cpu (snc_cpu_ids)) +return 1 ; + + node_caches =kcalloc (BITS_TO_LONGS (nr_node_ids),sizeof (*node_caches),GFP_KERNEL ); +if (!node_caches) +return 1 ; + +cpus_read_lock (); +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 + mem_only_nodes++; + } +cpus_read_unlock (); + + ret = (nr_node_ids - mem_only_nodes) /bitmap_weight (node_caches, nr_node_ids); +kfree (node_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 =get_snc_config (); +for_each_rdt_resource (r) { hw_res =resctrl_to_arch_res (r);
Signature · 2 lines
Thanks Babu Moger
Luck, Tony
maintainerRE: [PATCH v5 6/8] x86/resctrl: Sub NUMA Cluster detection and enable
Quoted 3 lines
Quoted 1 line
+#include <
linux/mod_devicetable.h>I didn't see the need for this include.
struct x86_cpu_id is defined in this #include file.
Quoted 5 lines
Quoted 1 line
+static void
snc_remap_rmids(int cpu)While adding the new functions, i see that new function names start with
resctrl_prefix. However, we are all not very consistent. Can ypu rename this function toresctrl_snc_remap_rmids?
I try to put a subsystem prefix on any global symbols to avoid random conflicts in other parts of the kernel. But I'm less sure of the value for static functions and variables that are only visible inside a single ".c" file.
If it must have a prefix, should it be "intel_" rather than "resctrl_" to indicate that it is an Intel specific function?
Quoted 3 lines
Quoted 1 line
+static
__initintget_snc_config(void)Same comment as above.
Same answer.
Reinette: Any opinions on these?
-Tony
Moger, Babu
reviewerRe: [PATCH v5 6/8] x86/resctrl: Sub NUMA Cluster detection and enable
Quoted 5 lines · Tony
Quoted 3 lines
Quoted 1 line
+#include <
linux/mod_devicetable.h>I didn't see the need for this include.
struct
x86_cpu_idis defined in this #include file.
Actually, the file <asm/cpu_device_id.h> already includes the above file.
Quoted 7 lines
Quoted 6 lines
Quoted 2 lines
+static void
snc_remap_rmids(int cpu)While adding the new functions, i see that new function names start with
resctrl_prefix. However, we are all not very consistent. Can ypu rename this function toresctrl_snc_remap_rmids?
Quoted 7 lines
I try to put a subsystem prefix on any global symbols to avoid random conflicts in other parts of the kernel. But I'm less sure of the value for static functions and variables that are only visible inside a single ".c" file.
If it must have a prefix, should it be "
intel_" rather than "resctrl_" to indicate that it is an Intel specific function?
If you add it it should be resctrl_.
Thanks
Babu
Quoted 12 lines
Quoted 5 lines
Quoted 3 lines
+static
__initintget_snc_config(void)Same comment as above.
Same answer.
Reinette: Any opinions on these?
-Tony
Luck, Tony
maintainerRE: [PATCH v5 6/8] x86/resctrl: Sub NUMA Cluster detection and enable
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
+#include <
linux/mod_devicetable.h>I didn't see the need for this include.
struct
x86_cpu_idis defined in this #include file.Actually, the file <
asm/cpu_device_id.h> already includes the above file.
It does today. Will it include it next week when somebody has to re-arrange things to resolve some #include dependency?
I thought there was a guideline somewhere that says to #include the files that define the things you use. Not just rely on chains of #includes. But some simple grep's haven't found that written in Documentation/*
-Tony
Moger, Babu
reviewerRe: [PATCH v5 6/8] x86/resctrl: Sub NUMA Cluster detection and enable
Quoted 8 lines · Tony
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
+#include <
linux/mod_devicetable.h>I didn't see the need for this include.
struct
x86_cpu_idis defined in this #include file.Actually, the file <
asm/cpu_device_id.h> already includes the above file.
Quoted 7 lines
It does today. Will it include it next week when somebody has to re-arrange things to resolve some #include dependency?
I thought there was a guideline somewhere that says to #include the files that define the things you use. Not just rely on chains of #includes. But some simple grep's haven't found that written in
Documentation/*
Yea. correct. There is no guidelines. Lets keep the #include <linux/mod_devicetable.h>
Signature · 2 lines
Thanks Babu Moger