Skip to contentSkip to conversation

lscpu: Fix socket information on aarch64 machine

PATCH Superseded Masayoshi Mizuma 2 participants 10 messages Sep 11, 2020 – Nov 13, 2020 Util-Linux package

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover lscpu: Fix socket information on aarch64 machine

lscpu may show the wrong number of physical sockets on aarch64 machine as 'Socket(s)'.

That is because lscpu uses a sysfs entry (cpu/cpuX/topology/core_siblings) to get the number of sockets. For aarch64, the sysfs entry is set from MPIDR_EL1 register if the machine doesn't have ACPI PPTT. According to ARM Architecture Reference Manual, the register shows the topology as the affinity, but doesn't show the physical socket information.

There're such aarch64 machines because ARM SBBR v1.0 and v1.1 don't require ACPI PPTT. SBBR v1.2 requires ACPI PPTT.

For the aarch64 machine, probably 'Cluster(s)' is good instead of 'Socket(s)' according to linux/arch/arm64/kernel/topology.c:store_cpu_topology().

To get the number of sockets on the machine, SMBIOS Processor information (Type04) is useful for lscpu because the SMBIOS information is a mandatory feature for the aarch64 machine which is based on ARM SBBR v1.0 and newer.

With these patches, lscpu shows as following on the machine:

For unprivileged user:

    $ lscpu 
    Architecture:                    aarch64
    ...
    Socket(s):                       -
    Cluster(s):                      4
    ...

For root:

    # lscpu
    Architecture:                    aarch64
    ...
    Socket(s):                       1
    Cluster(s):                      4

Masayoshi Mizuma (4):
lscpu: use cluster on aarch64 machine which doesn't have ACPI PPTT
lscpu-dmi: split to parse dmi table
lscpu: add helper to get physical sockets
lscpu: show physical socket on aarch64 without ACPI PPTT

 sys-utils/lscpu-dmi.c | 90 +++++++++++++++++++++++++++++++++----------
 sys-utils/lscpu.1     |  3 ++
 sys-utils/lscpu.c     | 75 ++++++++++++++++++++++++++++++++----
 sys-utils/lscpu.h     |  1 +
 4 files changed, 142 insertions(+), 27 deletions(-)
Signature · 1 line
2.27.0
#1 lore raw

PATCH 1/4 lscpu: use cluster on aarch64 machine which doesn't have ACPI PPTT

From: Masayoshi Mizuma <[email protected]>

lscpu may show the wrong number of sockets if the machine is aarch64 and doesn't have ACPI PPTT.

That's because lscpu show the number of sockets by using a sysfs entry (cpu/cpuX/topology/core_siblings). The sysfs entry is set by MPIDR_EL1 register if the machine doesn't have ACPI PPTT. MPIDR_EL1 doesn't show the physical socket information directly. It shows the affinity level.

According to linux/arch/arm64/kernel/topology.c:store_cpu_topology(), the top level of affinity is called as 'Cluster'.

Use Cluster instead of Socket on the machine which doesn't have ACPI PPTT.

Note, ARM SBBR v1.2 requires ACPI PPTT, so this patch is needed for the machine which is based on SBBR v1.0 and v1.1.

---
 sys-utils/lscpu.1 |  3 +++
 sys-utils/lscpu.c | 69 ++++++++++++++++++++++++++++++++++++++++++-----
 2 files changed, 65 insertions(+), 7 deletions(-)
sys-utils/lscpu.1 +3 -0
index 1ef6ce021..928d39dee 100644
@@ -52,6 +52,9 @@ The logical core number.  A core can contain several CPUs.
 .B SOCKET
 The logical socket number.  A socket can contain several cores.
 .TP
+.B CLUSTER
+The logical cluster number.  A cluster can contain several cores.
+.TP
 .B BOOK
 The logical book number.  A book can contain several sockets.
 .TP
sys-utils/lscpu.c +62 -7

156 lines not on this page · raw message

Signature · 1 line
2.27.0
#2 lore raw

PATCH 2/4 lscpu-dmi: split to parse dmi table

In reply to Masayoshi Mizuma

From: Masayoshi Mizuma <[email protected]>

Split out a function to parse dmi table.

---
 sys-utils/lscpu-dmi.c | 60 ++++++++++++++++++++++++++++---------------
 1 file changed, 40 insertions(+), 20 deletions(-)
sys-utils/lscpu-dmi.c +40 -20
index edf0f31e0..64aac99f5 100644
@@ -42,6 +42,12 @@ struct dmi_header
 	uint8_t *data;
 };
 
+struct dmi_info {
+	char *vendor;
+	char *product;
+	char *manufacturer;
+};
+
 static void *get_mem_chunk(size_t base, size_t len, const char *devmem)
 {
 	void *p = NULL;
@@ -95,20 +101,13 @@ static char *dmi_string(const struct dmi_header *dm, uint8_t s)
 	return bp;
 }
 
-static int hypervisor_from_dmi_table(uint32_t base, uint16_t len,
-				uint16_t num, const char *devmem)
+static int parse_dmi_table(uint16_t len, uint16_t num,
+				uint8_t *data,
+				struct dmi_info *di)
 {
-	uint8_t *buf;
-	uint8_t *data;
+	uint8_t *buf = data;
+	int rc = -1;
 	int i = 0;
-	char *vendor = NULL;
-	char *product = NULL;
-	char *manufacturer = NULL;
-	int rc = HYPER_NONE;
-
-	data = buf = get_mem_chunk(base, len, devmem);
-	if (!buf)
-		goto done;
 
 	 /* 4 is the length of an SMBIOS structure header */
 	while (i < num && data + 4 <= buf + len) {
@@ -132,11 +131,11 @@ static int hypervisor_from_dmi_table(uint32_t base, uint16_t len,
 		next += 2;
 		switch (h.type) {
 			case 0:
-				vendor = dmi_string(&h, data[0x04]);
+				di->vendor = dmi_string(&h, data[0x04]);
 				break;
 			case 1:
-				manufacturer = dmi_string(&h, data[0x04]);
-				product = dmi_string(&h, data[0x05]);
+				di->manufacturer = dmi_string(&h, data[0x04]);
+				di->product = dmi_string(&h, data[0x05]);
 				break;
 			default:
 				break;
@@ -145,15 +144,36 @@ static int hypervisor_from_dmi_table(uint32_t base, uint16_t len,
 		data = next;
 		i++;
 	}
-	if (manufacturer && !strcmp(manufacturer, "innotek GmbH"))
+	rc = 0;
+done:
+	return rc;
+}
+
+static int hypervisor_from_dmi_table(uint32_t base, uint16_t len,
+				uint16_t num, const char *devmem)
+{
+	uint8_t *data;
+	int rc = HYPER_NONE;
+	struct dmi_info di;
+
+	data = get_mem_chunk(base, len, devmem);
+	if (!data)
+		return rc;
+
+	memset(&di, 0, sizeof(struct dmi_info));
+	rc = parse_dmi_table(len, num, data, &di);
+	if (rc < 0)
+		goto done;
+
+	if (di.manufacturer && !strcmp(di.manufacturer, "innotek GmbH"))
 		rc = HYPER_INNOTEK;
-	else if (manufacturer && strstr(manufacturer, "HITACHI") &&
-					product && strstr(product, "LPAR"))
+	else if (di.manufacturer && strstr(di.manufacturer, "HITACHI") &&
+					di.product && strstr(di.product, "LPAR"))
 		rc = HYPER_HITACHI;
-	else if (vendor && !strcmp(vendor, "Parallels"))
+	else if (di.vendor && !strcmp(di.vendor, "Parallels"))
 		rc = HYPER_PARALLELS;
 done:
-	free(buf);
+	free(data);
 	return rc;
 }
 
Signature · 1 line
2.27.0
#3 lore raw

PATCH 3/4 lscpu: add helper to get physical sockets

In reply to Masayoshi Mizuma

From: Masayoshi Mizuma <[email protected]>

Add a helper function, get_number_of_physical_sockets_from_dmi(), to get physical sockets from DMI table in case of the sysfs for cpu topology doesn't have the physical socket information.

get_number_of_physical_sockets_from_dmi() parse the DMI table and counts the number of SMBIOS Processor Information (Type04) structure.

Note, ARM SBBR v1.0 and newer requires SMBIOS Processor Information (Type04). And ARM SBBR v1.2 requires ACPI PPTT which has physical socket information. So the helper function is useful for the machine base on SBBR v1.0 and v1.1.

---
 sys-utils/lscpu-dmi.c | 30 ++++++++++++++++++++++++++++++
 sys-utils/lscpu.h     |  1 +
 2 files changed, 31 insertions(+)
sys-utils/lscpu-dmi.c +30 -0
index 64aac99f5..21c557aeb 100644
@@ -46,6 +46,7 @@ struct dmi_info {
 	char *vendor;
 	char *product;
 	char *manufacturer;
+	int sockets;
 };
 
 static void *get_mem_chunk(size_t base, size_t len, const char *devmem)
@@ -137,6 +138,9 @@ static int parse_dmi_table(uint16_t len, uint16_t num,
 				di->manufacturer = dmi_string(&h, data[0x04]);
 				di->product = dmi_string(&h, data[0x05]);
 				break;
+			case 4:
+				di->sockets++;
+				break;
 			default:
 				break;
 		}
@@ -330,3 +334,29 @@ int read_hypervisor_dmi(void)
 
 	return rc < 0 ? HYPER_NONE : rc;
 }
+
+int get_number_of_physical_sockets_from_dmi(void)
+{
+	static char const sys_fw_dmi_tables[] = _PATH_SYS_DMI;
+	struct dmi_info di;
+	struct stat st;
+	uint8_t *data;
+	int rc = -1;
+
+	if (stat(sys_fw_dmi_tables, &st))
+		return rc;
+
+	data = get_mem_chunk(0, st.st_size, sys_fw_dmi_tables);
+	if (!data)
+		return rc;
+
+	memset(&di, 0, sizeof(struct dmi_info));
+	rc = parse_dmi_table(st.st_size, st.st_size/4, data, &di);
+
+	free(data);
+
+	if ((rc < 0) || !di.sockets)
+		return rc;
+	else
+		return di.sockets;
+}
sys-utils/lscpu.h +1 -0
index 13af2ad0a..4475a3d27 100644
@@ -209,6 +209,7 @@ struct lscpu_modifier {
 };
 
 extern int read_hypervisor_dmi(void);
+extern int get_number_of_physical_sockets_from_dmi(void);
 extern void arm_cpu_decode(struct lscpu_desc *desc);
 
 #endif /* LSCPU_H */
Signature · 1 line
2.27.0
#4 lore raw

PATCH 4/4 lscpu: show physical socket on aarch64 without ACPI PPTT

In reply to Masayoshi Mizuma

From: Masayoshi Mizuma <[email protected]>

Show the number of physical socket even if the sysfs doesn't have the physical socket information.
Note, lscpu cannot show the number of socket info for unprivileged users because it needs to access the DMI table.

---
 sys-utils/lscpu.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
sys-utils/lscpu.c +8 -2
index 8c823c170..3e7da2eac 100644
@@ -2182,9 +2182,15 @@ print_summary(struct lscpu_desc *desc, struct lscpu_modifier *mod)
 				add_summary_n(tb, _("Book(s):"), books_per_drawer ?: desc->nbooks);
 			}
 		} else {
-			if (is_cluster)
+			if (is_cluster) {
+				int sockets = get_number_of_physical_sockets_from_dmi();
+
+				if (sockets > 0)
+					add_summary_n(tb, _("Socket(s):"), sockets);
+				else
+					add_summary_s(tb, _("Socket(s):"), "-");
 				add_summary_n(tb, _("Cluster(s):"), desc->nsockets);
-			else
+			} else
 				add_summary_n(tb, _("Socket(s):"),
 						sockets_per_book ?: desc->nsockets);
 		}
Signature · 1 line
2.27.0
maintainer
#5 lore raw
In reply to Masayoshi Mizuma
Quoted 2 lines · Masayoshi Mizuma

lscpu may show the wrong number of physical sockets on aarch64 machine as 'Socket(s)'.

I'm working on new lscpu (to make it more extendible and ready for systems with different CPUs types on the same board). I'll apply your changes later. Thanks!

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com
#6 lore raw
Quoted 7 lines · Karel Zak
Quoted 2 lines · Masayoshi Mizuma

lscpu may show the wrong number of physical sockets on aarch64 machine as 'Socket(s)'.

I'm working on new lscpu (to make it more extendible and ready for systems with different CPUs types on the same board). I'll apply your changes later. Thanks!

Great, thanks!

- Masa

#7 lore raw
Quoted 10 lines · Masayoshi Mizuma
Quoted 7 lines · Karel Zak
Quoted 2 lines · Masayoshi Mizuma

lscpu may show the wrong number of physical sockets on aarch64 machine as 'Socket(s)'.

I'm working on new lscpu (to make it more extendible and ready for systems with different CPUs types on the same board). I'll apply your changes later. Thanks!

Great, thanks!

Hi Karel,

Could you apply the patches?
Let me know if I should rebase the patches to the latest lscpu and resend them.

Thanks!
Masa

maintainer
#8 lore raw
Quoted 10 lines · Masayoshi Mizuma
Quoted 9 lines · Masayoshi Mizuma
Quoted 7 lines · Karel Zak
Quoted 2 lines · Masayoshi Mizuma

lscpu may show the wrong number of physical sockets on aarch64 machine as 'Socket(s)'.

I'm working on new lscpu (to make it more extendible and ready for systems with different CPUs types on the same board). I'll apply your changes later. Thanks!

Quoted 6 lines
Quoted 1 line

Great, thanks!

Hi Karel,

Could you apply the patches?
Let me know if I should rebase the patches to the latest lscpu and resend them.

I'd already merged.

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com
maintainer
#9 lore raw
Quoted 11 lines · Karel Zak
Quoted 10 lines · Masayoshi Mizuma
Quoted 9 lines · Masayoshi Mizuma
Quoted 7 lines · Karel Zak
Quoted 2 lines · Masayoshi Mizuma

lscpu may show the wrong number of physical sockets on aarch64 machine as 'Socket(s)'.

I'm working on new lscpu (to make it more extendible and ready for systems with different CPUs types on the same board). I'll apply your changes later. Thanks!

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

Great, thanks!

Hi Karel,

Could you apply the patches?
Let me know if I should rebase the patches to the latest lscpu and resend them.

I'd already merged.

Ah, no, this is not merged. If you have time than go ahead and port it to the new code.

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com