From: chris hyser Date: Wed, 22 Apr 2015 16:28:31 +0000 (-0400) Subject: sparc64: Setup sysfs to mark LDOM sockets, cores and threads correctly X-Git-Tag: v4.1.12-92~283^2^2~18 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=bb97a3e11e1b98e03471fc06881b1c8520cb1d28;p=users%2Fjedix%2Flinux-maple.git sparc64: Setup sysfs to mark LDOM sockets, cores and threads correctly commit 5f4826a362405748bbf73957027b77993e61e1af Author: chris hyser Date: Tue Apr 21 10:31:38 2015 -0400 sparc64: Setup sysfs to mark LDOM sockets, cores and threads correctly The current sparc kernel has no representation for sockets though tools like lscpu can pull this from sysfs. This patch walks the machine description cache and socket hierarchy and marks sockets as well as cores and threads such that a representative sysfs is created by drivers/base/topology.c. Before this patch: $ lscpu Architecture: sparc64 CPU op-mode(s): 32-bit, 64-bit Byte Order: Big Endian CPU(s): 1024 On-line CPU(s) list: 0-1023 Thread(s) per core: 8 Core(s) per socket: 1 <--- wrong Socket(s): 128 <--- wrong NUMA node(s): 4 NUMA node0 CPU(s): 0-255 NUMA node1 CPU(s): 256-511 NUMA node2 CPU(s): 512-767 NUMA node3 CPU(s): 768-1023 After this patch: $ lscpu Architecture: sparc64 CPU op-mode(s): 32-bit, 64-bit Byte Order: Big Endian CPU(s): 1024 On-line CPU(s) list: 0-1023 Thread(s) per core: 8 Core(s) per socket: 32 Socket(s): 4 NUMA node(s): 4 NUMA node0 CPU(s): 0-255 NUMA node1 CPU(s): 256-511 NUMA node2 CPU(s): 512-767 NUMA node3 CPU(s): 768-1023 Most of this patch was done by Chris with updates by David. Signed-off-by: Chris Hyser Signed-off-by: David Ahern Signed-off-by: David S. Miller (cherry picked from commit acc455cffa75070d55e74fc7802b49edbc080e92) Conflicts: arch/sparc/include/asm/cpudata_64.h arch/sparc/kernel/mdesc.c arch/sparc/kernel/smp_64.c Signed-off-by: Allen Pais (cherry picked from commit bd1039234cf41d0afd35f8e9a302eac9c344d18d) --- diff --git a/arch/sparc/kernel/mdesc.c b/arch/sparc/kernel/mdesc.c index eca49856ae49..fdf011d90777 100644 --- a/arch/sparc/kernel/mdesc.c +++ b/arch/sparc/kernel/mdesc.c @@ -759,28 +759,66 @@ static void set_sock_ids(struct mdesc_handle *hp) static void __cpuinit set_sock_ids(struct mdesc_handle *hp) { - int idx; u64 mp; + int idx = 1; + int fnd = 0; - idx = 1; - - /* - * identify unique sockets by looking for cpus backpointed to by - * level 3 caches + /* Identify unique sockets by looking for cpus backpointed to by + * shared level n caches. */ mdesc_for_each_node_by_name(hp, mp, "cache") { - const u64 *level; + const u64 *cur_lvl; - level = mdesc_get_property(hp, mp, "level", NULL); - if (*level != 3) + cur_lvl = mdesc_get_property(hp, mp, "level", NULL); + if (*cur_lvl != level) continue; mark_sock_ids(hp, mp, idx); + idx++; + fnd = 1; + } + return fnd; +} +static void set_sock_ids_by_socket(struct mdesc_handle *hp, u64 mp) +{ + int idx = 1; + + mdesc_for_each_node_by_name(hp, mp, "socket") { + u64 a; + + mdesc_for_each_arc(a, hp, mp, MDESC_ARC_TYPE_FWD) { + u64 t = mdesc_arc_target(hp, a); + const char *name; + const u64 *id; + + name = mdesc_node_name(hp, t); + if (strcmp(name, "cpu")) + continue; + + id = mdesc_get_property(hp, t, "id", NULL); + if (*id < num_possible_cpus()) + cpu_data(*id).sock_id = idx; + } idx++; } } +static void set_sock_ids(struct mdesc_handle *hp) +{ + u64 mp; + + /* If machine description exposes sockets data use it. + * Otherwise fallback to use shared L3 or L2 caches. + */ + mp = mdesc_node_by_name(hp, MDESC_NODE_NULL, "sockets"); + if (mp != MDESC_NODE_NULL) + return set_sock_ids_by_socket(hp, mp); + + if (!set_sock_ids_by_cache(hp, 3)) + set_sock_ids_by_cache(hp, 2); +} + static void mark_proc_ids(struct mdesc_handle *hp, u64 mp, int proc_id) { u64 a;