dcavalca / rpms / util-linux

Forked from rpms/util-linux 2 years ago
Clone

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

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