arch_topology: Updates to add socket support and fix cluster ids
Subsystems (2)
cover arch_topology: Updates to add socket support and fix cluster ids
Hi All,
This series intends to fix some discrepancies we have in the CPU topology parsing from the device tree /cpu-map node. Also this diverges from the behaviour on a ACPI enabled platform. The expectation is that both DT and ACPI enabled systems must present consistent view of the CPU topology.
Currently we assign generated cluster count as the physical package identifier for each CPU which is wrong. The device tree bindings for CPU topology supports sockets to infer the socket or physical package identifier for a given CPU. Also we don't check if all the cores/threads belong to the same cluster before updating their sibling masks which is fine as we don't set the cluster id yet.
These changes also assigns the cluster identifier as parsed from the device tree cluster nodes within /cpu-map without support for nesting of the clusters. Finally, it also add support for socket nodes in /cpu-map. With this the parsing of exact same information from ACPI PPTT and /cpu-map DT node aligns well.
The only exception is that the last level cache id information can be inferred from the same ACPI PPTT while we need to parse CPU cache nodes in the device tree. llc_id is not handled as part of these changes.
P.S: I have not cc-ed Greg and Rafael so that all the users of arch_topology agree with the changes first before we include them.
Sudeep Holla (4):
arch_topology: Don't set cluster identifier as physical package identifier
arch_topology: Set thread and core siblings only within the cluster
arch_topology: Set cluster identifier in each core/thread from /cpu-map
arch_topology: Add support for parsing sockets in /cpu-map
drivers/base/arch_topology.c | 48 +++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 11 deletions(-)
--
2.36.1
PATCH 1/4 arch_topology: Don't set cluster identifier as physical package identifier
Currently as we parse the CPU topology from /cpu-map node from the device tree, we assign generated cluster count as the physical package identifier for each CPU which is wrong.
The device tree bindings for CPU topology supports sockets to infer the socket or physical package identifier for a given CPU. Since it is fairly new and not support on most of the old and existing systems, we can assume all such systems have single socket/physical package.
Fix the physical package identifier to 0 by removing the assignment of cluster identifier to the same.
--- drivers/base/arch_topology.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/base/arch_topology.c +1 -5
@@ -543,7 +543,6 @@ static int __init parse_cluster(struct device_node *cluster, int depth)bool leaf = true;bool has_cores = false;struct device_node *c; -static int package_id__initdata ;int core_id =0 ;int i, ret;
@@ -582,7 +581,7 @@ static int __init parse_cluster(struct device_node *cluster, int depth) }if (leaf) { - ret =parse_core (c, package_id, core_id++); + ret =parse_core (c,0 , core_id++); }else {pr_err ("%pOF: Non-leaf cluster with core %s\n" , cluster, name);
@@ -599,9 +598,6 @@ static int __init parse_cluster(struct device_node *cluster, int depth)if (leaf && !has_cores)pr_warn ("%pOF: empty cluster\n" , cluster); -if (leaf) - package_id++; -return 0 ; }
Signature · 1 line
2.36.1
PATCH 2/4 arch_topology: Set thread and core siblings only within the cluster
In reply to Sudeep HollaCurrently the cluster identifier is not set on the DT based platforms. The reset or default value is -1 for all the CPUs. Once we assign the cluster identifier values correctly that may result in getting the core siblings wrongs as the core identifiers can be same for 2 different CPUs belonging to 2 different cluster.
So, in order to get the core and thread sibling masks correct, we need to update them only if they belong to same cluster within the socket. Let us skip updation of the thread and core sibling cpumaks if the socket and the cluster identifier doesn't match.
This change won't affect even if the cluster identifiers are not set currently but will avoid any breakage once we set the same correctly.
--- drivers/base/arch_topology.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/base/arch_topology.c +3 -3
@@ -694,11 +694,11 @@ void update_siblings_masks(unsigned int cpuid)cpumask_set_cpu (cpuid, &cpu_topo->llc_sibling); } -if (cpuid_topo->package_id != cpu_topo->package_id) +if (cpuid_topo->package_id != cpu_topo->package_id || + cpuid_topo->cluster_id != cpu_topo->cluster_id)continue ; -if (cpuid_topo->cluster_id == cpu_topo->cluster_id && - cpuid_topo->cluster_id !=-1 ) { +if (cpuid_topo->cluster_id !=-1 ) {cpumask_set_cpu (cpu, &cpuid_topo->cluster_sibling);cpumask_set_cpu (cpuid, &cpu_topo->cluster_sibling); }
Signature · 1 line
2.36.1
PATCH 2/4 arch_topology: Set thread sibling cpumask only within the cluster
Currently the cluster identifier is not set on the DT based platforms. The reset or default value is -1 for all the CPUs. Once we assign the cluster identifier values correctly that imay result in getting the thread siblings wrongs as the core identifiers can be same for 2 different CPUs belonging to 2 different cluster.
So, in order to get the thread sibling cpumasks correct, we need to update them only if the cores they belong are in the same cluster within the socket. Let us skip updation of the thread sibling cpumaks if the cluster identifier doesn't match.
This change won't affect even if the cluster identifiers are not set currently but will avoid any breakage once we set the same correctly.
--- drivers/base/arch_topology.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
I seem to have not included the fix I did after testing the patches. This version is updated to fix the issue with the original 2/4
drivers/base/arch_topology.c +7 -5
@@ -697,15 +697,17 @@ void update_siblings_masks(unsigned int cpuid)if (cpuid_topo->package_id != cpu_topo->package_id)continue ; -if (cpuid_topo->cluster_id == cpu_topo->cluster_id && - cpuid_topo->cluster_id !=-1 ) { +cpumask_set_cpu (cpuid, &cpu_topo->core_sibling); +cpumask_set_cpu (cpu, &cpuid_topo->core_sibling); + +if (cpuid_topo->cluster_id != cpu_topo->cluster_id) +continue ; + +if (cpuid_topo->cluster_id !=-1 ) {cpumask_set_cpu (cpu, &cpuid_topo->cluster_sibling);cpumask_set_cpu (cpuid, &cpu_topo->cluster_sibling); } -cpumask_set_cpu (cpuid, &cpu_topo->core_sibling); -cpumask_set_cpu (cpu, &cpuid_topo->core_sibling); -if (cpuid_topo->core_id != cpu_topo->core_id)continue ;
Signature · 1 line
2.36.1
PATCH 3/4 arch_topology: Set cluster identifier in each core/thread from /cpu-map
In reply to Sudeep HollaLet us set the cluster identifier as parsed from the device tree cluster nodes within /cpu-map.
We don't support nesting of clusters yet as there are no real hardware to support clusters of clusters.
--- drivers/base/arch_topology.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/base/arch_topology.c +8 -5
@@ -491,7 +491,7 @@ static int __init get_cpu_for_node(struct device_node *node) }static int __init parse_core (struct device_node *core,int package_id, -int core_id) +int cluster_id,int core_id) {char name[20 ];bool leaf = true;
@@ -507,6 +507,7 @@ static int __init parse_core(struct device_node *core, int package_id, cpu =get_cpu_for_node (t);if (cpu >=0 ) { cpu_topology[cpu].package_id = package_id; + cpu_topology[cpu].cluster_id = cluster_id; cpu_topology[cpu].core_id = core_id; cpu_topology[cpu].thread_id = i; }else if (cpu != -ENODEV ) {
@@ -528,6 +529,7 @@ static int __init parse_core(struct device_node *core, int package_id, } cpu_topology[cpu].package_id = package_id; + cpu_topology[cpu].cluster_id = cluster_id; cpu_topology[cpu].core_id = core_id; }else if (leaf && cpu != -ENODEV ) {pr_err ("%pOF: Can't get CPU for leaf core\n" , core);
@@ -537,7 +539,8 @@ static int __init parse_core(struct device_node *core, int package_id,return 0 ; } -static int __init parse_cluster (struct device_node *cluster,int depth) +static int __init +parse_cluster (struct device_node *cluster,int cluster_id,int depth) {char name[20 ];bool leaf = true;
@@ -557,7 +560,7 @@ static int __init parse_cluster(struct device_node *cluster, int depth) c =of_get_child_by_name (cluster, name);if (c) { leaf = false; - ret =parse_cluster (c, depth +1 ); + ret =parse_cluster (c, i, depth +1 );of_node_put (c);if (ret !=0 )return ret;
@@ -581,7 +584,7 @@ static int __init parse_cluster(struct device_node *cluster, int depth) }if (leaf) { - ret =parse_core (c,0 , core_id++); + ret =parse_core (c,0 , cluster_id, core_id++); }else {pr_err ("%pOF: Non-leaf cluster with core %s\n" , cluster, name);
@@ -621,7 +624,7 @@ static int __init parse_dt_topology(void)if (!map) goto out; - ret =parse_cluster (map,0 ); + ret =parse_cluster (map,-1 ,0 );if (ret !=0 ) goto out_map;
Signature · 1 line
2.36.1
PATCH 4/4 arch_topology: Add support for parsing sockets in /cpu-map
In reply to Sudeep HollaFinally let us add support for socket nodes in /cpu-map in the device tree. Since this may not be present in all the old platforms and even most of the existing platforms, we need to assume absence of the socket node indicates that it is a single socket system and handle appropriately.
Also it is likely that most single socket systems skip to as the node since it is optional.
--- drivers/base/arch_topology.c | 37 +++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-)
drivers/base/arch_topology.c +32 -5
@@ -539,8 +539,8 @@ static int __init parse_core(struct device_node *core, int package_id,return 0 ; } -static int __init -parse_cluster (struct device_node *cluster,int cluster_id,int depth) +static int __init parse_cluster (struct device_node *cluster,int package_id, +int cluster_id,int depth) {char name[20 ];bool leaf = true;
@@ -560,7 +560,7 @@ parse_cluster(struct device_node *cluster, int cluster_id, int depth) c =of_get_child_by_name (cluster, name);if (c) { leaf = false; - ret =parse_cluster (c, i, depth +1 ); + ret =parse_cluster (c, package_id, i, depth +1 );of_node_put (c);if (ret !=0 )return ret;
@@ -584,7 +584,8 @@ parse_cluster(struct device_node *cluster, int cluster_id, int depth) }if (leaf) { - ret =parse_core (c,0 , cluster_id, core_id++); + ret =parse_core (c, package_id, cluster_id, + core_id++); }else {pr_err ("%pOF: Non-leaf cluster with core %s\n" , cluster, name);
@@ -604,6 +605,32 @@ parse_cluster(struct device_node *cluster, int cluster_id, int depth)return 0 ; } +static int __init parse_socket (struct device_node *socket) +{ +char name[20 ]; +struct device_node *c; +bool has_socket = false; +int package_id =0 , ret; + +do { +snprintf (name,sizeof (name),"socket%d" , package_id); + c =of_get_child_by_name (socket, name); +if (c) { + has_socket = true; + ret =parse_cluster (c, package_id,-1 ,0 ); +of_node_put (c); +if (ret !=0 ) +return ret; + } + package_id++; + }while (c); + +if (!has_socket) + ret =parse_cluster (socket,0 ,-1 ,0 ); + +return ret; +} +static int __init parse_dt_topology (void ) {struct device_node *cn, *map;
@@ -624,7 +651,7 @@ static int __init parse_dt_topology(void)if (!map) goto out; - ret =parse_cluster (map,-1 ,0 ); + ret =parse_socket (map);if (ret !=0 ) goto out_map;
Signature · 1 line
2.36.1