Blame SOURCES/0053-lscpu-add-helper-to-get-physical-sockets.patch

0e1b67
From 32c4fe66ae9107a7fae556be02c1401e5046071b Mon Sep 17 00:00:00 2001
0e1b67
From: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
0e1b67
Date: Fri, 11 Sep 2020 09:53:27 -0400
0e1b67
Subject: [PATCH 53/55] lscpu: add helper to get physical sockets
0e1b67
0e1b67
Add a helper function, get_number_of_physical_sockets_from_dmi(),
0e1b67
to get physical sockets from DMI table in case of the sysfs for
0e1b67
cpu topology doesn't have the physical socket information.
0e1b67
0e1b67
get_number_of_physical_sockets_from_dmi() parse the DMI table
0e1b67
and counts the number of SMBIOS Processor Information (Type04)
0e1b67
structure.
0e1b67
0e1b67
Note, ARM SBBR v1.0 and newer requires SMBIOS Processor Information
0e1b67
(Type04). And ARM SBBR v1.2 requires ACPI PPTT which has physical socket
0e1b67
information. So the helper function is useful for the machine base on
0e1b67
SBBR v1.0 and v1.1.
0e1b67
0e1b67
Signed-off-by: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
0e1b67
---
0e1b67
 sys-utils/lscpu-dmi.c | 30 ++++++++++++++++++++++++++++++
0e1b67
 sys-utils/lscpu.h     |  1 +
0e1b67
 2 files changed, 31 insertions(+)
0e1b67
0e1b67
diff --git a/sys-utils/lscpu-dmi.c b/sys-utils/lscpu-dmi.c
0e1b67
index 9b57fe9e6..31127f48a 100644
0e1b67
--- a/sys-utils/lscpu-dmi.c
0e1b67
+++ b/sys-utils/lscpu-dmi.c
0e1b67
@@ -46,6 +46,7 @@ struct dmi_info {
0e1b67
 	char *vendor;
0e1b67
 	char *product;
0e1b67
 	char *manufacturer;
0e1b67
+	int sockets;
0e1b67
 };
0e1b67
 
0e1b67
 static int checksum(const uint8_t *buf, size_t len)
0e1b67
@@ -147,6 +148,9 @@ static int parse_dmi_table(uint16_t len, uint16_t num,
0e1b67
 				di->manufacturer = dmi_string(&h, data[0x04]);
0e1b67
 				di->product = dmi_string(&h, data[0x05]);
0e1b67
 				break;
0e1b67
+			case 4:
0e1b67
+				di->sockets++;
0e1b67
+				break;
0e1b67
 			default:
0e1b67
 				break;
0e1b67
 		}
0e1b67
@@ -323,3 +327,29 @@ done:
0e1b67
 	free(buf);
0e1b67
 	return rc < 0 ? HYPER_NONE : rc;
0e1b67
 }
0e1b67
+
0e1b67
+int get_number_of_physical_sockets_from_dmi(void)
0e1b67
+{
0e1b67
+	static char const sys_fw_dmi_tables[] = _PATH_SYS_DMI;
0e1b67
+	struct dmi_info di;
0e1b67
+	struct stat st;
0e1b67
+	uint8_t *data;
0e1b67
+	int rc = -1;
0e1b67
+
0e1b67
+	if (stat(sys_fw_dmi_tables, &st))
0e1b67
+		return rc;
0e1b67
+
0e1b67
+	data = get_mem_chunk(0, st.st_size, sys_fw_dmi_tables);
0e1b67
+	if (!data)
0e1b67
+		return rc;
0e1b67
+
0e1b67
+	memset(&di, 0, sizeof(struct dmi_info));
0e1b67
+	rc = parse_dmi_table(st.st_size, st.st_size/4, data, &di);
0e1b67
+
0e1b67
+	free(data);
0e1b67
+
0e1b67
+	if ((rc < 0) || !di.sockets)
0e1b67
+		return rc;
0e1b67
+	else
0e1b67
+		return di.sockets;
0e1b67
+}
0e1b67
diff --git a/sys-utils/lscpu.h b/sys-utils/lscpu.h
0e1b67
index bffa9df60..b190afd21 100644
0e1b67
--- a/sys-utils/lscpu.h
0e1b67
+++ b/sys-utils/lscpu.h
0e1b67
@@ -186,6 +186,7 @@ struct lscpu_modifier {
0e1b67
 };
0e1b67
 
0e1b67
 extern int read_hypervisor_dmi(void);
0e1b67
+extern int get_number_of_physical_sockets_from_dmi(void);
0e1b67
 extern void arm_cpu_decode(struct lscpu_desc *desc);
0e1b67
 
0e1b67
 #endif /* LSCPU_H */
0e1b67
-- 
0e1b67
2.29.2
0e1b67