Skip to contentSkip to conversation

sparc64: Setup sysfs to mark LDOM sockets, cores and threads correctly

PATCH In review David Ahern 3 participants 5 messages Mar 19, 2015 – Mar 26, 2015 SPARC + UltraSPARC (sparc/sparc64)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

---
 arch/sparc/include/asm/cpudata_64.h  |   3 +-
 arch/sparc/include/asm/topology_64.h |   3 +-
 arch/sparc/kernel/mdesc.c            | 142 +++++++++++++++++++++++++++++------
 arch/sparc/kernel/smp_64.c           |  13 ++++
 4 files changed, 134 insertions(+), 27 deletions(-)
arch/sparc/include/asm/cpudata_64.h +2 -1
index a6e424d185d0..a6cfdabb6054 100644
@@ -24,7 +24,8 @@ typedef struct {
 	unsigned int	icache_line_size;
 	unsigned int	ecache_size;
 	unsigned int	ecache_line_size;
-	int		core_id;
+	unsigned short	sock_id;
+	unsigned short	core_id;
 	int		proc_id;
 } cpuinfo_sparc;
 
arch/sparc/include/asm/topology_64.h +2 -1
index ed8f071132e4..d1761df5cca6 100644
@@ -40,11 +40,12 @@ static inline int pcibus_to_node(struct pci_bus *pbus)
 #ifdef CONFIG_SMP
 #define topology_physical_package_id(cpu)	(cpu_data(cpu).proc_id)
 #define topology_core_id(cpu)			(cpu_data(cpu).core_id)
-#define topology_core_cpumask(cpu)		(&cpu_core_map[cpu])
+#define topology_core_cpumask(cpu)		(&cpu_core_sib_map[cpu])
 #define topology_thread_cpumask(cpu)		(&per_cpu(cpu_sibling_map, cpu))
 #endif /* CONFIG_SMP */
 
 extern cpumask_t cpu_core_map[NR_CPUS];
+extern cpumask_t cpu_core_sib_map[NR_CPUS];
 static inline const struct cpumask *cpu_coregroup_mask(int cpu)
 {
         return &cpu_core_map[cpu];
arch/sparc/kernel/mdesc.c +117 -25

174 lines not on this page · raw message

arch/sparc/kernel/smp_64.c +13 -0
index 61139d9924ca..19cd08d18672 100644
@@ -60,8 +60,12 @@ DEFINE_PER_CPU(cpumask_t, cpu_sibling_map) = CPU_MASK_NONE;
 cpumask_t cpu_core_map[NR_CPUS] __read_mostly  	{ [0 ... NR_CPUS-1] = CPU_MASK_NONE };
 
+cpumask_t cpu_core_sib_map[NR_CPUS] __read_mostly = {
+	[0 ... NR_CPUS-1] = CPU_MASK_NONE };
+
 EXPORT_PER_CPU_SYMBOL(cpu_sibling_map);
 EXPORT_SYMBOL(cpu_core_map);
+EXPORT_SYMBOL(cpu_core_sib_map);
 
 static cpumask_t smp_commenced_mask;
 
@@ -1243,6 +1247,15 @@ void smp_fill_in_sib_core_maps(void)
 		}
 	}
 
+	for_each_present_cpu(i)  {
+		unsigned int j;
+
+		for_each_present_cpu(j)  {
+			if (cpu_data(i).sock_id = cpu_data(j).sock_id)
+				cpumask_set_cpu(j, &cpu_core_sib_map[i]);
+		}
+	}
+
 	for_each_present_cpu(i) {
 		unsigned int j;
 
Signature · 1 line
2.3.0
maintainer
#1 lore raw

From: David Ahern <[email protected]>
Date: Thu, 19 Mar 2015 16:07:10 -0400

Quoted 4 lines

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.

...

Quoted 4 lines

Most of this patch was done by Chris with updates by David.

This is reasonably involved so I'm going to take some time review this.

maintainer
#2 lore raw
In reply to David Ahern

From: David Ahern <[email protected]>
Date: Thu, 19 Mar 2015 16:07:10 -0400

arch/sparc/kernel/mdesc.c static void fill_in_one_cache(cpuinfo_sparc *c, struct mdesc_handle *hp, u64 mp) · line 620

Quoted 5 lines
arch/sparc/kernel/mdesc.c +3 -1
-static void mark_core_ids(struct mdesc_handle *hp, u64 mp, int core_id)
+static void __cpuinit find_back_node_value(struct mdesc_handle *hp, u64 node,
+	       char *srch_val, void(*func)(struct mdesc_handle *, u64, int),
+	       u64 val, int depth)
 {

Function arguments on the second and subsequent line shall start exactly at the first column after the openning parenthesis of the function definition/declaration. You should use the appropriate number of TAB then SPACE characters necessary to do so.

If you are only using TAB characters to indent this kind of thing, it's probably not right.

arch/sparc/kernel/mdesc.c static void fill_in_one_cache(cpuinfo_sparc *c, struct mdesc_handle *hp, u64 mp) · line 625

Quoted 3 lines
arch/sparc/kernel/mdesc.c +3 -0
+	/*since we have estimate of how deep, do recursion sanity check */
+	if (depth = 0)
+		return;

Please capitalize and properly punctuate this. Also put a space after "/*".

arch/sparc/kernel/mdesc.c static void fill_in_one_cache(cpuinfo_sparc *c, struct mdesc_handle *hp, u64 mp) · line 632

Quoted 9 lines
arch/sparc/kernel/mdesc.c +5 -3
+	mdesc_for_each_arc(arc, hp, node, MDESC_ARC_TYPE_BACK) {
+		u64 n = mdesc_arc_target(hp, arc);
+		const char *name = mdesc_node_name(hp, n);
 
-				n_name = mdesc_node_name(hp, n);
-				if (strcmp(n_name, "cpu"))
-					continue;
+	if (!strcmp(srch_val, name))
+		(*func)(hp, n, val);

This needs one more TAB of indentation.

arch/sparc/kernel/mdesc.c static void fill_in_one_cache(cpuinfo_sparc *c, struct mdesc_handle *hp, u64 mp) · line 634

Quoted 1 line
arch/sparc/kernel/mdesc.c +1 -0
+	find_back_node_value(hp, n, srch_val, func, val, depth-1);

This as well. This doesn't look strange in your editor?

Review

Quoted 2 lines
(quoted diff) +2 -0
+static void __cpuinit __mark_core_id(struct mdesc_handle *hp, u64 node,
+		int core_id)

Please fix argument indentation.

Review

Quoted 2 lines
(quoted diff) +2 -0
+static void __cpuinit __mark_sock_id(struct mdesc_handle *hp, u64 node,
+		int sock_id)

Likewise.

arch/sparc/kernel/mdesc.c static void fill_in_one_cache(cpuinfo_sparc *c, struct mdesc_handle *hp, u64 mp) · line 657

Quoted 2 lines
arch/sparc/kernel/mdesc.c +2 -0
+static void __cpuinit mark_core_ids(struct mdesc_handle *hp, u64 mp,
+		int core_id)

Likewise.

arch/sparc/kernel/mdesc.c static void fill_in_one_cache(cpuinfo_sparc *c, struct mdesc_handle *hp, u64 mp) · line 663

Quoted 2 lines
arch/sparc/kernel/mdesc.c +2 -0
+static void __cpuinit mark_sock_ids(struct mdesc_handle *hp, u64 mp,
+		int sock_id)

Likewise.

arch/sparc/kernel/mdesc.c static void fill_in_one_cache(cpuinfo_sparc *c, struct mdesc_handle *hp, u64 mp) · line 679

Quoted 5 lines
arch/sparc/kernel/mdesc.c +5 -0
+	/*
+	 * identify unique cores by looking for cpus backpointed to by
+	 * level 1 instruction caches
+	 */
+

Please capitalize this sentence and format the comment:

	/* Like
	 * this.
	 */

arch/sparc/kernel/mdesc.c static void set_core_ids(struct mdesc_handle *hp) · line 706

Quoted 4 lines
arch/sparc/kernel/mdesc.c +4 -0
+	/*
+	 * identify unique sockets by looking for cpus backpointed to by
+	 * level 3 caches
+	 */

Likewise.

arch/sparc/kernel/mdesc.c static void set_core_ids(struct mdesc_handle *hp) · line 751

Quoted 3 lines
arch/sparc/kernel/mdesc.c +3 -0
+	/* if machine description exposes sockets data use it.
+	 * otherwise fallback to use L3 cache
+	 */

Capitalize and properly punctuate.

arch/sparc/kernel/mdesc.c static void set_core_ids(struct mdesc_handle *hp) · line 759

Quoted 6 lines
arch/sparc/kernel/mdesc.c +6 -0
+		if (sun4v_chip_type = SUN4V_CHIP_SPARC_M7) {
+			pr_warn("Machine description does not contain sockets node. Falling back\n");
+			pr_warn("to identifying CPUs to sockets using L3 cache which is known to\n");
+			pr_warn("be wrong for M7 processors (e.g, lscpu shows wrong number of sockets).\n");
+			pr_warn("Please update the firmware.\n");
+		}

If this isn't going to happen on FCS hardware, I wouldn't even bother with this warning.

Thanks.

#3 lore raw
In reply to David Ahern

Yes. Sorry. You pointed out many of these formatting issues to me in a prior sunvdc patch that I still need to resubmit. David took this and added to it not realizing these issues were there. I will work with David on a resubmission.

So other than that, are you happy with the approach?

-chrish

Quoted 101 lines · David Miller

From: David Ahern <[email protected]>
Date: Thu, 19 Mar 2015 16:07:10 -0400

arch/sparc/kernel/mdesc.c static void fill_in_one_cache(cpuinfo_sparc *c, struct mdesc_handle *hp, u64 mp) · line 620

Quoted 5 lines
arch/sparc/kernel/mdesc.c +3 -1
-static void mark_core_ids(struct mdesc_handle *hp, u64 mp, int core_id)
+static void __cpuinit find_back_node_value(struct mdesc_handle *hp, u64 node,
+	       char *srch_val, void(*func)(struct mdesc_handle *, u64, int),
+	       u64 val, int depth)
  {

Function arguments on the second and subsequent line shall start exactly at the first column after the openning parenthesis of the function definition/declaration. You should use the appropriate number of TAB then SPACE characters necessary to do so.

If you are only using TAB characters to indent this kind of thing, it's probably not right.

arch/sparc/kernel/mdesc.c static void fill_in_one_cache(cpuinfo_sparc *c, struct mdesc_handle *hp, u64 mp) · line 625

Quoted 3 lines
arch/sparc/kernel/mdesc.c +3 -0
+	/*since we have estimate of how deep, do recursion sanity check */
+	if (depth = 0)
+		return;

Please capitalize and properly punctuate this. Also put a space after "/*".

arch/sparc/kernel/mdesc.c static void fill_in_one_cache(cpuinfo_sparc *c, struct mdesc_handle *hp, u64 mp) · line 632

Quoted 9 lines
arch/sparc/kernel/mdesc.c +5 -3
+	mdesc_for_each_arc(arc, hp, node, MDESC_ARC_TYPE_BACK) {
+		u64 n = mdesc_arc_target(hp, arc);
+		const char *name = mdesc_node_name(hp, n);
 
-				n_name = mdesc_node_name(hp, n);
-				if (strcmp(n_name, "cpu"))
-					continue;
+	if (!strcmp(srch_val, name))
+		(*func)(hp, n, val);

This needs one more TAB of indentation.

arch/sparc/kernel/mdesc.c static void fill_in_one_cache(cpuinfo_sparc *c, struct mdesc_handle *hp, u64 mp) · line 634

Quoted 1 line
arch/sparc/kernel/mdesc.c +1 -0
+	find_back_node_value(hp, n, srch_val, func, val, depth-1);

This as well. This doesn't look strange in your editor?

Review

Quoted 2 lines
(quoted diff) +2 -0
+static void __cpuinit __mark_core_id(struct mdesc_handle *hp, u64 node,
+		int core_id)

Please fix argument indentation.

Review

Quoted 2 lines
(quoted diff) +2 -0
+static void __cpuinit __mark_sock_id(struct mdesc_handle *hp, u64 node,
+		int sock_id)

Likewise.

arch/sparc/kernel/mdesc.c static void fill_in_one_cache(cpuinfo_sparc *c, struct mdesc_handle *hp, u64 mp) · line 657

Quoted 2 lines
arch/sparc/kernel/mdesc.c +2 -0
+static void __cpuinit mark_core_ids(struct mdesc_handle *hp, u64 mp,
+		int core_id)

Likewise.

arch/sparc/kernel/mdesc.c static void fill_in_one_cache(cpuinfo_sparc *c, struct mdesc_handle *hp, u64 mp) · line 663

Quoted 2 lines
arch/sparc/kernel/mdesc.c +2 -0
+static void __cpuinit mark_sock_ids(struct mdesc_handle *hp, u64 mp,
+		int sock_id)

Likewise.

arch/sparc/kernel/mdesc.c static void fill_in_one_cache(cpuinfo_sparc *c, struct mdesc_handle *hp, u64 mp) · line 679

Quoted 5 lines
arch/sparc/kernel/mdesc.c +5 -0
+	/*
+	 * identify unique cores by looking for cpus backpointed to by
+	 * level 1 instruction caches
+	 */
+

Please capitalize this sentence and format the comment:

	/* Like
	 * this.
	 */

arch/sparc/kernel/mdesc.c static void set_core_ids(struct mdesc_handle *hp) · line 706

Quoted 4 lines
arch/sparc/kernel/mdesc.c +4 -0
+	/*
+	 * identify unique sockets by looking for cpus backpointed to by
+	 * level 3 caches
+	 */

Likewise.

arch/sparc/kernel/mdesc.c static void set_core_ids(struct mdesc_handle *hp) · line 751

Quoted 3 lines
arch/sparc/kernel/mdesc.c +3 -0
+	/* if machine description exposes sockets data use it.
+	 * otherwise fallback to use L3 cache
+	 */

Capitalize and properly punctuate.

arch/sparc/kernel/mdesc.c static void set_core_ids(struct mdesc_handle *hp) · line 759

Quoted 6 lines
arch/sparc/kernel/mdesc.c +6 -0
+		if (sun4v_chip_type = SUN4V_CHIP_SPARC_M7) {
+			pr_warn("Machine description does not contain sockets node. Falling back\n");
+			pr_warn("to identifying CPUs to sockets using L3 cache which is known to\n");
+			pr_warn("be wrong for M7 processors (e.g, lscpu shows wrong number of sockets).\n");
+			pr_warn("Please update the firmware.\n");
+		}

If this isn't going to happen on FCS hardware, I wouldn't even bother with this warning.

Thanks.
--
To unsubscribe from this list: send the line "unsubscribe sparclinux" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

maintainer
#4 lore raw
In reply to David Ahern

From: chris hyser <[email protected]>
Date: Wed, 25 Mar 2015 18:53:28 -0400

Quoted 6 lines

Yes. Sorry. You pointed out many of these formatting issues to me in a prior sunvdc patch that I still need to resubmit. David took this and added to it not realizing these issues were there. I will work with David on a resubmission.

So other than that, are you happy with the approach?

Yeah it looks basically fine.