Skip to contentSkip to conversation

lscpu-arm: Allow externally sourced model name.

PATCH In review Paul Benoit 3 participants 14 messages Jul 11, 2025 – May 20 Util-Linux package

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 lscpu-arm: Allow externally sourced model name.

When there isn't an entry for the model name in the id_part table(s), attempt to get the machine name from /sys/bus/soc/devices/soc0/machine to use as the model name. This mechanism allows lscpu to use the model/machine name provided via the ARM SMC support code rather than via hard-coded lscpu tables.

This code was tested by removing the "Ampere-1a" entry from the ampere-part table and verifying that lscpu displayed the correct machine name obtained via the ARM SMC interface to Trusted Firmware. The "Ampere-1a" entry will be permanently removed by a separate patch.

---
 sys-utils/lscpu-arm.c | 35 ++++++++++++++++++++++++++++++++---
 sys-utils/lscpu.h     |  1 +
 2 files changed, 33 insertions(+), 3 deletions(-)
sys-utils/lscpu-arm.c +32 -3
index 8745599d4..a46106bcb 100644
@@ -388,7 +388,10 @@ int is_arm(struct lscpu_cxt *cxt)
 static int arm_ids_decode(struct lscpu_cputype *ct)
 {
 	int impl, part, j;
+	unsigned int i;
 	const struct id_part *parts = NULL;
+	FILE *fd;
+	char machinename[BUFSIZ] = "";
 
 	impl = parse_implementer_id(ct);
 	if (impl <= 0)
@@ -406,11 +409,11 @@ static int arm_ids_decode(struct lscpu_cputype *ct)
 
 	/* decode model */
 	if (!parts)
-		goto done;
+		goto try_machinename;
 
 	part = parse_model_id(ct);
 	if (part <= 0)
-		goto done;
+		goto try_machinename;
 
 	for (j = 0; parts[j].id != -1; j++) {
 		if (parts[j].id == part) {
@@ -419,7 +422,33 @@ static int arm_ids_decode(struct lscpu_cputype *ct)
 			break;
 		}
 	}
-done:
+
+try_machinename:
+
+	/*
+	 * If the Model name was not found in the lscpu 'id_part' tables, see
+	 * if there is a Machine name associated with the SOC.  This name may
+	 * have been set via either SOC specific support code, or obtained
+	 * via an ARM SMC CC call into Trusted Firmware.
+	 */
+	if (!ct->modelname) {
+		fd = ul_path_fopen(NULL, "r", _PATH_SOC_MACHINENAME);
+		if (fd) {
+			if (!fgets(machinename, sizeof(machinename), fd))
+				machinename[0] = '\0';
+			fclose(fd);
+
+			/* Replace newline with string terminator */
+			for (i = 0; i < strlen(machinename); i++) {
+				if (machinename[i] == '\n')
+					machinename[i] = '\0';
+			}
+
+			if (strnlen(machinename, sizeof(machinename)))
+				ct->modelname = xstrdup(machinename);
+		}
+	}
+
 	return 0;
 }
 
sys-utils/lscpu.h +1 -0
index bd7b64cc5..581602f70 100644
@@ -46,6 +46,7 @@ UL_DEBUG_DECLARE_MASK(lscpu);
 #define _PATH_SYS_NODE		_PATH_SYS_SYSTEM "/node"
 #define _PATH_SYS_DMI		"/sys/firmware/dmi/tables/DMI"
 #define _PATH_ACPI_PPTT		"/sys/firmware/acpi/tables/PPTT"
+#define _PATH_SOC_MACHINENAME	"/sys/bus/soc/devices/soc0/machine"
 
 struct lscpu_cache {
 	int		id;		/* unique identifier */
Signature · 1 line
2.48.1
#1 lore raw

PATCH 2/2 lscpu-arm: Remove the "Ampere-1a" part.

Remove the "Ampere-1a" part. On newer Ampere Computing systems, the system/model name will be obtained from /sys/bus/soc/devices/soc0/machine, that is populated with the ARM SMC CC SOC_ID Name.

---
 sys-utils/lscpu-arm.c | 1 -
 1 file changed, 1 deletion(-)
sys-utils/lscpu-arm.c +0 -1
index 8745599d4..4ea555d86 100644
@@ -268,7 +268,6 @@ static const struct id_part hisi_part[] = {
 
 static const struct id_part ampere_part[] = {
     { 0xac3, "Ampere-1" },
-    { 0xac4, "Ampere-1a" },
     { -1, "unknown" },
 };
 
Signature · 1 line
2.48.1
maintainer
#2 lore raw

Re: [PATCH 2/2] lscpu-arm: Remove the "Ampere-1a" part.

Quoted 3 lines · Paul Benoit

Remove the "Ampere-1a" part. On newer Ampere Computing systems, the system/model name will be obtained from /sys/bus/soc/devices/soc0/machine, that is populated with the ARM SMC CC SOC_ID Name.

If I understand correctly, there are old systems without /sys/.../soc0/machine, right? The change will remove Ampere-1a from the lscpu output. This sounds backward incompatible.

Karel

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

Re: [PATCH 2/2] lscpu-arm: Remove the "Ampere-1a" part.

Quoted 8 lines · Karel Zak
Quoted 3 lines · Paul Benoit

Remove the "Ampere-1a" part. On newer Ampere Computing systems, the system/model name will be obtained from /sys/bus/soc/devices/soc0/machine, that is populated with the ARM SMC CC SOC_ID Name.

If I understand correctly, there are old systems without /sys/.../soc0/machine, right? The change will remove Ampere-1a from the lscpu output. This sounds backward incompatible.

Thats a good point, but as I understand it, Ampere hasn't been happy with the string that is there.

If its OK to break whatever scripts/etc might depend on it at the moment, why not just update the string.

Then invert the check so that the /sys/bus entry is preferred?

#4 lore raw

Re: [PATCH 2/2] lscpu-arm: Remove the "Ampere-1a" part.

Quoted 6 lines · Jeremy Linton
Quoted 5 lines · Karel Zak
Quoted 3 lines · Paul Benoit

Remove the "Ampere-1a" part.  On newer Ampere Computing systems, the system/model name will be obtained from /sys/bus/soc/devices/soc0/ machine, that is populated with the ARM SMC CC SOC_ID Name.

Quoted 6 lines
Quoted 3 lines

If I understand correctly, there are old systems without /sys/.../soc0/machine, right? The change will remove Ampere-1a from the lscpu output. This sounds backward incompatible.

Thats a good point, but as I understand it, Ampere hasn't been happy with the string that is there.

Hi Jeremy and Karel,

While I haven't personally been part of those discussions, that's also my understanding of the situation.

Quoted 2 lines

If its OK to break whatever scripts/etc might depend on it at the moment, why not just update the string.

That's becoming even more tempting given the valid issues that you and Karel have identified with my patch. Though, the nice thing about lscpu picking up the Model name, from somewhere like /sys/bus/soc/devices/soc0/, is that lscpu will be able to output the model name of newly released processors without/before them needing to be added to the lscpu part(s) table. That assumes a kernel where either the ARM SMC CC SOC_ID (Name) handling code, or the support code for a specific SOC, set the Model name from which /sys/bus/soc/devices/soc0/ gets set.

Quoted 2 lines

Then invert the check so that the /sys/bus entry is preferred?

That's the way I had originally coded things, but I was concerned about the change in behavior of having the /sys/bus/soc/devices/soc0/ value override the established part(s) table names for non-Ampere processors.

maintainer
#5 lore raw

Re: [PATCH 2/2] lscpu-arm: Remove the "Ampere-1a" part.

In reply to Jeremy Linton
Quoted 6 lines · Jeremy Linton
Quoted 5 lines · Karel Zak
Quoted 3 lines · Paul Benoit

Remove the "Ampere-1a" part. On newer Ampere Computing systems, the system/model name will be obtained from /sys/bus/soc/devices/soc0/machine, that is populated with the ARM SMC CC SOC_ID Name.

Quoted 6 lines
Quoted 3 lines

If I understand correctly, there are old systems without /sys/.../soc0/machine, right? The change will remove Ampere-1a from the lscpu output. This sounds backward incompatible.

Thats a good point, but as I understand it, Ampere hasn't been happy with the string that is there.

We can update the string to make them happy.

Quoted 4 lines

If its OK to break whatever scripts/etc might depend on it at the moment, why not just update the string.

Then invert the check so that the /sys/bus entry is preferred?

I still do not understand how a per-CPU identifier can be replaced by one soc0 path. What if there is soc1, soc2, etc.?

Anyway, using /sys/bus as the primary source and the hardcoded id_part[] array as a fallback seems better than removing anything from id_part[] and relying on /sys/bus only.

Karel

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

Re: [PATCH 2/2] lscpu-arm: Remove the "Ampere-1a" part.

Quoted 16 lines · Karel Zak
Quoted 6 lines · Jeremy Linton
Quoted 5 lines · Karel Zak
Quoted 3 lines · Paul Benoit

Remove the "Ampere-1a" part. On newer Ampere Computing systems, the system/model name will be obtained from /sys/bus/soc/devices/soc0/machine, that is populated with the ARM SMC CC SOC_ID Name.

Quoted 6 lines
Quoted 3 lines

If I understand correctly, there are old systems without /sys/.../soc0/machine, right? The change will remove Ampere-1a from the lscpu output. This sounds backward incompatible.

Thats a good point, but as I understand it, Ampere hasn't been happy with the string that is there.

We can update the string to make them happy.

Quoted 7 lines
Quoted 4 lines

If its OK to break whatever scripts/etc might depend on it at the moment, why not just update the string.

Then invert the check so that the /sys/bus entry is preferred?

I still do not understand how a per-CPU identifier can be replaced by one soc0 path. What if there is soc1, soc2, etc.?

Yes, I agree that /sys/bus/soc/devices/soc0/machine shouldn't be used for processors/cpus in soc1..socn unless all physical SOCs are mapped by soc0. My recollection is that I only saw the one /sys/bus/devices/soc0 on an SMC compliant system with 2 SOCs. The smccc_soc_init routine is what calls soc_device_register once. The support code for other ARM SOCs call soc_device_register from a *_probe routine (run once per SOC?). As per my other reply in this thread today, /sys/bus/soc/devices/soc0/machine will only be used for a SMC CC compliant SOC.

Quoted 7 lines

Anyway, using /sys/bus as the primary source and the hardcoded id_part[] array as a fallback seems better than removing anything from id_part[] and relying on /sys/bus only.

Karel

#7 lore raw

Re: [PATCH 2/2] lscpu-arm: Remove the "Ampere-1a" part.

In reply to Jeremy Linton

Thanks for your input Jeremy and Karel.

I apologize for taking so long to get back to this project.

Quoted 6 lines · Jeremy Linton
Quoted 5 lines · Karel Zak
Quoted 3 lines · Paul Benoit

Remove the "Ampere-1a" part.  On newer Ampere Computing systems, the system/model name will be obtained from /sys/bus/soc/devices/soc0/ machine, that is populated with the ARM SMC CC SOC_ID Name.

Quoted 7 lines
Quoted 3 lines

If I understand correctly, there are old systems without /sys/.../soc0/machine, right? The change will remove Ampere-1a from the lscpu output. This sounds backward incompatible.

Thats a good point, but as I understand it, Ampere hasn't been happy with the string that is there.

If its OK to break whatever scripts/etc might depend on it at the moment, why not just update the string.

For SOCs using SMC CC compliant firmware, I do like that having lscpu use /sys/bus/soc/devices/soc0/machine means that the name for a new SMC SOC would be displayed without needing to update the lscpu part(s) table. Though, I'm concerned that the SMC CC SOC_ID Name won't always be a direct mapping to a processor/cpu name. Especially for a SOC that contains a mix of BIG/little, performance/efficiency, and/or special purpose cores. When all the cores of a SOC are the same, then it is probably ok to equate the SMC CC SOC_ID Name with the processor/cpu part name.

For SMC CC compliant SOCs, perhaps it makes more sense to have lscpu display the /sys/bus/soc/devices/soc0/machine value as a new "SOC_ID Name" value in a manner similar to the "BIOS Model name"? Would changes be required to lscpu to select such a "SOC_ID Name" field from the lscpu command line, or would it be sufficient to only display this SOC_ID Name field in lscpu modes where the detailed/complete cpu/processor information is displayed? If lscpu were to display the /sys/bus/soc/devices/soc0/machines value as "SOC_ID Name", then the Ampere cpus/processor names would need to continue to come from the lscpu part(s) table. Though, The existing names in the "ampere_part" table would still need to change.

Quoted 2 lines

Then invert the check so that the /sys/bus entry is preferred?

Prior to my V1 lscpu patch, when I first made some lscpu changes as a way to test the SMC CC SOC_ID Name kernel changes, I had originally been checking for /sys/bus/soc/devices/soc0/machine before looking for an entry in the part(s) table. My concern with that was for the non-SMC SOCs, for which there was both a part(s) table entry and /sys/bus/soc/devices/soc0/machine was set. If the string in the part(s) table was not the same as the /sys/bus/soc/devices/soc0/machine string, lscpu would then be displaying a different string than it had in the past. That is why my V1 patch switched to using the /sys/bus/soc/devices/soc0/machine value only if there wasn't an entry in the part(s) table. A way to reduce the risk, of now using /sys/bus/soc/devices/soc0/machine instead of the part(s) table entry for a non-SMC SOC, would be for lscpu to only use the /sys/bus/soc/devices/soc0/machine value if the value of /sys/devices/soc0/soc_id starts with "jep106:". Documentation/ABI/testing/sysfs-devices-soc in the Linux kernel tree says
"On many of ARM based silicon with SMCCC v1.2+ compliant firmware this will contain the SOC ID appended to the family attribute to ensure there is no conflict in this namespace across various vendors. The format is "jep106:XXYY:ZZZZ" where XX is identity code, YY is continuation code and ZZZZ is the SOC ID."

A search of the Linux kernel code confirms that only drivers/firmware/smccc/soc_id.c is generating/using the "jep106:" string.

#8 lore raw

PATCH v2 1/2 lscpu-arm: Include the ARM SMC CC SOC_ID name.

On ARM SMC CC 1.6 compliant systems, output the optional SMC CC SOC_ID name if available.

Vendor ID:                   Ampere
  BIOS Vendor ID:            Ampere (R)
  Model name:                Ampere-1a
    SMCCC SOC_ID name:       AmpereOne (R) A192-32X
    BIOS Model name:         AmpereOne (R) A192-32X CPU @ 3.2GH
---
 sys-utils/lscpu-arm.c | 38 ++++++++++++++++++++++++++++++++++++++
 sys-utils/lscpu.c     |  2 ++
 sys-utils/lscpu.h     |  4 ++++
 3 files changed, 44 insertions(+)
sys-utils/lscpu-arm.c +38 -0
index ed255a3c7..f388080ad 100644
@@ -11,6 +11,7 @@
  * The information here is gathered from
  *  - ARM manuals
  *  - Linux kernel: arch/armX/include/asm/cputype.h
+ *  - Linux kernel: Documentation/ABI/testing/sysfs-devices-soc
  *  - GCC sources: config/arch/arch-cores.def
  *  - Ancient wisdom
  *  - SMBIOS tables (if applicable)
@@ -460,6 +461,41 @@ static int arm_rXpY_decode(struct lscpu_cputype *ct)
 	return 0;
 }
 
+static void on_smc_platform_get_socidname(struct lscpu_cputype *ct)
+{
+	char *machinename = NULL;
+	char *soc_id_jep106_id_str = NULL;
+
+	/* On systems that support SMC CC (Secure Monitor Call Calling
+	 * Convention, get the SOC_ID name.  The Linux kernel obtains it from
+	 * Trusted Firmware via an SMC CC call, and sets
+	 * /sys/bus/soc/devices/soc0/machine _PATH_SOC_ID to this value.  lscpu
+	 * will obtain the value from there.
+	 *
+	 * Documentation/ABI/testing/sysfs-devices-soc, in the Linux kernel
+	 * source tree, gives insight into detecting a SMC CC compliant system
+	 * by checking that start of the _PATH_SOC_ID value for "jep106:".
+	 */
+	ul_path_read_string(NULL, &soc_id_jep106_id_str, _PATH_SOC_ID);
+
+	if (soc_id_jep106_id_str) {
+		if (strncmp(soc_id_jep106_id_str, "jep106:", 7) == 0) {
+			ul_path_read_string(NULL, &machinename,
+					    _PATH_SOC_MACHINENAME);
+			if (machinename) {
+				if (strnlen(machinename, sizeof(machinename))) {
+					free(ct->socid_name);
+					ct->socid_name = xstrdup(machinename);
+				}
+
+				free(machinename);
+			}
+		}
+
+		free(soc_id_jep106_id_str);
+	}
+}
+
 static void arm_decode(struct lscpu_cxt *cxt, struct lscpu_cputype *ct)
 {
 	if (is_live(cxt) && access(_PATH_SYS_DMI, R_OK) == 0)
@@ -468,6 +504,8 @@ static void arm_decode(struct lscpu_cxt *cxt, struct lscpu_cputype *ct)
 	arm_ids_decode(ct);
 	arm_rXpY_decode(ct);
 
+	on_smc_platform_get_socidname(ct);
+
 	if (is_live(cxt) && cxt->is_cluster)
 		ct->nr_socket_on_cluster = get_number_of_physical_sockets_from_dmi();
 }
sys-utils/lscpu.c +2 -0
index 4556aa6df..cd2d00312 100644
@@ -895,6 +895,8 @@ print_summary_cputype(struct lscpu_cxt *cxt,
 		     struct libscols_line *sec)
 {
 	sec = add_summary_s(tb, sec, _("Model name:"), ct->modelname ? ct->modelname : "-");
+	if (ct->socid_name)
+		add_summary_s(tb, sec, _("SMCCC SOC_ID name:"), ct->socid_name);
 	if (ct->bios_modelname)
 		add_summary_s(tb, sec, _("BIOS Model name:"), ct->bios_modelname);
 	if (ct->bios_family)
sys-utils/lscpu.h +4 -0
index 0fae5d29e..b8011bc55 100644
@@ -46,6 +46,8 @@ UL_DEBUG_DECLARE_MASK(lscpu);
 #define _PATH_SYS_NODE		_PATH_SYS_SYSTEM "/node"
 #define _PATH_SYS_DMI		"/sys/firmware/dmi/tables/DMI"
 #define _PATH_ACPI_PPTT		"/sys/firmware/acpi/tables/PPTT"
+#define _PATH_SOC_ID		"/sys/devices/soc0/soc_id"
+#define _PATH_SOC_MACHINENAME	"/sys/devices/soc0/machine"
 
 struct lscpu_cache {
 	int		id;		/* unique identifier */
@@ -119,6 +121,8 @@ struct lscpu_cputype {
 	size_t nr_socket_on_cluster; /* the number of sockets if the is_cluster is 1 */
 
 	char	*isa;	/* loongarch */
+
+	char	*socid_name;	/* aarch64 */
 };
 
 /* dispatching modes */
Signature · 1 line
2.48.1
#9 lore raw

Re: [PATCH v2 1/2] lscpu-arm: Include the ARM SMC CC SOC_ID name.

Hi,

I'm checking in to see if there are any comments on v2 of my patch set. Since it been a while since I sent the patches, below is a reminder of where things stand after the maintainer comments and my responses on v1.

v2 is no longer using the SMC CC SOC_ID Name as a proxy/override for entries in the CPU parts table(s). While it would be nice to not have to update the CPU parts tables when new SMC CC compliant SoCs are created, it would only have worked if all CPUs of a given SoC are of the same type.

v2 will display the optional SMC CC SOC_ID name in a manner similar to how the "BIOS Model name" is displayed. the "SMCCC SOC_ID name" and "BIOS Model name" strings will not necessarily be similar as the SoC and system/firmware may be produced by different companies/ organizations.

v2 corrects the names of the 2 existing entries in the Ampere Computing cpu part table.

Regards,
Paul

Quoted 114 lines · Paul Benoit

On ARM SMC CC 1.6 compliant systems, output the optional SMC CC SOC_ID name if available.

Vendor ID: Ampere

   BIOS Vendor ID:            Ampere (R)
   Model name:                Ampere-1a
     SMCCC SOC_ID name:       AmpereOne (R) A192-32X
     BIOS Model name:         AmpereOne (R) A192-32X CPU @ 3.2GH
---
  sys-utils/lscpu-arm.c | 38 ++++++++++++++++++++++++++++++++++++++
  sys-utils/lscpu.c     |  2 ++
  sys-utils/lscpu.h     |  4 ++++
  3 files changed, 44 insertions(+)
sys-utils/lscpu-arm.c +38 -0
index ed255a3c7..f388080ad 100644
@@ -11,6 +11,7 @@
   * The information here is gathered from
   *  - ARM manuals
   *  - Linux kernel: arch/armX/include/asm/cputype.h
+ *  - Linux kernel: Documentation/ABI/testing/sysfs-devices-soc
   *  - GCC sources: config/arch/arch-cores.def
   *  - Ancient wisdom
   *  - SMBIOS tables (if applicable)
@@ -460,6 +461,41 @@ static int arm_rXpY_decode(struct lscpu_cputype *ct)
  	return 0;
  }
 
+static void on_smc_platform_get_socidname(struct lscpu_cputype *ct)
+{
+	char *machinename = NULL;
+	char *soc_id_jep106_id_str = NULL;
+
+	/* On systems that support SMC CC (Secure Monitor Call Calling
+	 * Convention, get the SOC_ID name.  The Linux kernel obtains it from
+	 * Trusted Firmware via an SMC CC call, and sets
+	 * /sys/bus/soc/devices/soc0/machine _PATH_SOC_ID to this value.  lscpu
+	 * will obtain the value from there.
+	 *
+	 * Documentation/ABI/testing/sysfs-devices-soc, in the Linux kernel
+	 * source tree, gives insight into detecting a SMC CC compliant system
+	 * by checking that start of the _PATH_SOC_ID value for "jep106:".
+	 */
+	ul_path_read_string(NULL, &soc_id_jep106_id_str, _PATH_SOC_ID);
+
+	if (soc_id_jep106_id_str) {
+		if (strncmp(soc_id_jep106_id_str, "jep106:", 7) == 0) {
+			ul_path_read_string(NULL, &machinename,
+					    _PATH_SOC_MACHINENAME);
+			if (machinename) {
+				if (strnlen(machinename, sizeof(machinename))) {
+					free(ct->socid_name);
+					ct->socid_name = xstrdup(machinename);
+				}
+
+				free(machinename);
+			}
+		}
+
+		free(soc_id_jep106_id_str);
+	}
+}
+
  static void arm_decode(struct lscpu_cxt *cxt, struct lscpu_cputype *ct)
  {
  	if (is_live(cxt) && access(_PATH_SYS_DMI, R_OK) == 0)
@@ -468,6 +504,8 @@ static void arm_decode(struct lscpu_cxt *cxt, struct lscpu_cputype *ct)
  	arm_ids_decode(ct);
  	arm_rXpY_decode(ct);
 
+	on_smc_platform_get_socidname(ct);
+
  	if (is_live(cxt) && cxt->is_cluster)
  		ct->nr_socket_on_cluster = get_number_of_physical_sockets_from_dmi();
  }
sys-utils/lscpu.c +2 -0
index 4556aa6df..cd2d00312 100644
@@ -895,6 +895,8 @@ print_summary_cputype(struct lscpu_cxt *cxt,
  		     struct libscols_line *sec)
  {
  	sec = add_summary_s(tb, sec, _("Model name:"), ct->modelname ? ct->modelname : "-");
+	if (ct->socid_name)
+		add_summary_s(tb, sec, _("SMCCC SOC_ID name:"), ct->socid_name);
  	if (ct->bios_modelname)
  		add_summary_s(tb, sec, _("BIOS Model name:"), ct->bios_modelname);
  	if (ct->bios_family)
sys-utils/lscpu.h +4 -0
index 0fae5d29e..b8011bc55 100644
@@ -46,6 +46,8 @@ UL_DEBUG_DECLARE_MASK(lscpu);
  #define _PATH_SYS_NODE		_PATH_SYS_SYSTEM "/node"
  #define _PATH_SYS_DMI		"/sys/firmware/dmi/tables/DMI"
  #define _PATH_ACPI_PPTT		"/sys/firmware/acpi/tables/PPTT"
+#define _PATH_SOC_ID		"/sys/devices/soc0/soc_id"
+#define _PATH_SOC_MACHINENAME	"/sys/devices/soc0/machine"
 
  struct lscpu_cache {
  	int		id;		/* unique identifier */
@@ -119,6 +121,8 @@ struct lscpu_cputype {
  	size_t nr_socket_on_cluster; /* the number of sockets if the is_cluster is 1 */
 
  	char	*isa;	/* loongarch */
+
+	char	*socid_name;	/* aarch64 */
  };
 
  /* dispatching modes */
#10 lore raw

PATCH v2 2/2 lscpu-arm: Correct Ampere part name strings.

In reply to Paul Benoit

Change "Ampere-1" to "Ampere1", and "Ampere-1a" to "Ampere1a" in the ampere_part table.

---
 sys-utils/lscpu-arm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
sys-utils/lscpu-arm.c +2 -2
index f388080ad..0b0935402 100644
@@ -276,8 +276,8 @@ static const struct id_part hisi_part[] = {
 };
 
 static const struct id_part ampere_part[] = {
-    { 0xac3, "Ampere-1" },
-    { 0xac4, "Ampere-1a" },
+    { 0xac3, "Ampere1" },
+    { 0xac4, "Ampere1a" },
     { -1, "unknown" },
 };
 
Signature · 1 line
2.48.1
#11 lore raw
In reply to Paul Benoit

Hi,

Quoted 5 lines · Paul Benoit

When there isn't an entry for the model name in the id_part table(s), attempt to get the machine name from /sys/bus/soc/devices/soc0/machine to use as the model name. This mechanism allows lscpu to use the model/machine name provided via the ARM SMC support code rather than via hard-coded lscpu tables.

Since this is suppose to be synced with the DMI data, and is sourced from the firmware would it make more sense to replace the BIOS name with it?

Quoted 88 lines

This code was tested by removing the "Ampere-1a" entry from the ampere-part table and verifying that lscpu displayed the correct machine name obtained via the ARM SMC interface to Trusted Firmware. The "Ampere-1a" entry will be permanently removed by a separate patch.

---
  sys-utils/lscpu-arm.c | 35 ++++++++++++++++++++++++++++++++---
  sys-utils/lscpu.h     |  1 +
  2 files changed, 33 insertions(+), 3 deletions(-)
sys-utils/lscpu-arm.c +32 -3
index 8745599d4..a46106bcb 100644
@@ -388,7 +388,10 @@ int is_arm(struct lscpu_cxt *cxt)
  static int arm_ids_decode(struct lscpu_cputype *ct)
  {
  	int impl, part, j;
+	unsigned int i;
  	const struct id_part *parts = NULL;
+	FILE *fd;
+	char machinename[BUFSIZ] = "";
 
  	impl = parse_implementer_id(ct);
  	if (impl <= 0)
@@ -406,11 +409,11 @@ static int arm_ids_decode(struct lscpu_cputype *ct)
 
  	/* decode model */
  	if (!parts)
-		goto done;
+		goto try_machinename;
 
  	part = parse_model_id(ct);
  	if (part <= 0)
-		goto done;
+		goto try_machinename;
 
  	for (j = 0; parts[j].id != -1; j++) {
  		if (parts[j].id == part) {
@@ -419,7 +422,33 @@ static int arm_ids_decode(struct lscpu_cputype *ct)
  			break;
  		}
  	}
-done:
+
+try_machinename:
+
+	/*
+	 * If the Model name was not found in the lscpu 'id_part' tables, see
+	 * if there is a Machine name associated with the SOC.  This name may
+	 * have been set via either SOC specific support code, or obtained
+	 * via an ARM SMC CC call into Trusted Firmware.
+	 */
+	if (!ct->modelname) {
+		fd = ul_path_fopen(NULL, "r", _PATH_SOC_MACHINENAME);
+		if (fd) {
+			if (!fgets(machinename, sizeof(machinename), fd))
+				machinename[0] = '\0';
+			fclose(fd);
+
+			/* Replace newline with string terminator */
+			for (i = 0; i < strlen(machinename); i++) {
+				if (machinename[i] == '\n')
+					machinename[i] = '\0';
+			}
+
+			if (strnlen(machinename, sizeof(machinename)))
+				ct->modelname = xstrdup(machinename);
+		}
+	}
+
  	return 0;
  }
 
sys-utils/lscpu.h +1 -0
index bd7b64cc5..581602f70 100644
@@ -46,6 +46,7 @@ UL_DEBUG_DECLARE_MASK(lscpu);
  #define _PATH_SYS_NODE		_PATH_SYS_SYSTEM "/node"
  #define _PATH_SYS_DMI		"/sys/firmware/dmi/tables/DMI"
  #define _PATH_ACPI_PPTT		"/sys/firmware/acpi/tables/PPTT"
+#define _PATH_SOC_MACHINENAME	"/sys/bus/soc/devices/soc0/machine"
 
  struct lscpu_cache {
  	int		id;		/* unique identifier */
#12 lore raw
Quoted 10 lines · Jeremy Linton

Hi,

Quoted 5 lines · Paul Benoit

When there isn't an entry for the model name in the id_part table(s), attempt to get the machine name from /sys/bus/soc/devices/soc0/machine to use as the model name.  This mechanism allows lscpu to use the model/machine name provided via the ARM SMC support code rather than via hard-coded lscpu tables.

Since this is suppose to be synced with the DMI data, and is sourced from the firmware would it make more sense to replace the BIOS name with it?

I was recently reminded that the SMC CC SOC_ID Name (/sys/bus/soc/devices/soc0/machine) and BIOS name could be from 2 different organizations, and may not always resemble each other.

Quoted 87 lines
Quoted 86 lines

This code was tested by removing the "Ampere-1a" entry from the ampere-part table and verifying that lscpu displayed the correct machine name obtained via the ARM SMC interface to Trusted Firmware.  The "Ampere-1a" entry will be permanently removed by a separate patch.

---
  sys-utils/lscpu-arm.c | 35 ++++++++++++++++++++++++++++++++--- sys-utils/lscpu.h     |  1 +

  2 files changed, 33 insertions(+), 3 deletions(-)
sys-utils/lscpu-arm.c +10 -3
index 8745599d4..a46106bcb 100644
@@ -388,7 +388,10 @@ int is_arm(struct lscpu_cxt *cxt)
   static int arm_ids_decode(struct lscpu_cputype *ct)
   {
       int impl, part, j;
+    unsigned int i;
       const struct id_part *parts = NULL;
+    FILE *fd;
+    char machinename[BUFSIZ] = "";
       impl = parse_implementer_id(ct);
       if (impl <= 0)
@@ -406,11 +409,11 @@ static int arm_ids_decode(struct lscpu_cputype *ct)
       /* decode model */
       if (!parts)
-        goto done;
+        goto try_machinename;
       part = parse_model_id(ct);
       if (part <= 0)
-        goto done;
+        goto try_machinename;
       for (j = 0; parts[j].id != -1; j++) {
           if (parts[j].id == part) {
@@ -419,7 +422,33 @@ static int arm_ids_decode(struct lscpu_cputype *ct)
               break;
           }
       }
-done:
+
+try_machinename:
+
+    /*
+     * If the Model name was not found in the lscpu 'id_part' tables, 

see
+     * if there is a Machine name associated with the SOC.  This name may
+     * have been set via either SOC specific support code, or obtained +     * via an ARM SMC CC call into Trusted Firmware.
+     */
+    if (!ct->modelname) {
+        fd = ul_path_fopen(NULL, "r", _PATH_SOC_MACHINENAME); +        if (fd) {
+            if (!fgets(machinename, sizeof(machinename), fd)) +                machinename[0] = '\0';
+            fclose(fd);

sys-utils/lscpu-arm.c +12 -0
+
+            /* Replace newline with string terminator */
+            for (i = 0; i < strlen(machinename); i++) {
+                if (machinename[i] == '\n')
+                    machinename[i] = '\0';
+            }
+
+            if (strnlen(machinename, sizeof(machinename)))
+                ct->modelname = xstrdup(machinename);
+        }
+    }
+

      return 0;
  }

sys-utils/lscpu.h +1 -0
index bd7b64cc5..581602f70 100644
@@ -46,6 +46,7 @@ UL_DEBUG_DECLARE_MASK(lscpu);
   #define _PATH_SYS_NODE        _PATH_SYS_SYSTEM "/node"
   #define _PATH_SYS_DMI        "/sys/firmware/dmi/tables/DMI"
   #define _PATH_ACPI_PPTT        "/sys/firmware/acpi/tables/PPTT"
+#define _PATH_SOC_MACHINENAME    "/sys/bus/soc/devices/soc0/machine"
   struct lscpu_cache {

      int        id;        /* unique identifier */

maintainer
#13 lore raw
In reply to Paul Benoit

Hi Paul,

Quoted 2 lines · Paul Benoit

When there isn't an entry for the model name in the id_part table(s), attempt to get the machine name from /sys/bus/soc/devices/soc0/machine

How is it supposed to work on a system with multiple CPU types (more CPU models) if it reads all from the same path?

Quoted 11 lines
sys-utils/lscpu-arm.c +11 -0
+	/*
+	 * If the Model name was not found in the lscpu 'id_part' tables, see
+	 * if there is a Machine name associated with the SOC.  This name may
+	 * have been set via either SOC specific support code, or obtained
+	 * via an ARM SMC CC call into Trusted Firmware.
+	 */
+	if (!ct->modelname) {
+		fd = ul_path_fopen(NULL, "r", _PATH_SOC_MACHINENAME);
+		if (fd) {
+			if (!fgets(machinename, sizeof(machinename), fd))
+				machinename[0] = '\0';

sys-utils/lscpu-arm.c static int arm_ids_decode(struct lscpu_cputype *ct) · line 448

Quoted 10 lines
sys-utils/lscpu-arm.c +10 -0
+			fclose(fd);
+
+			/* Replace newline with string terminator */
+			for (i = 0; i < strlen(machinename); i++) {
+				if (machinename[i] == '\n')
+					machinename[i] = '\0';
+			}
+
+			if (strnlen(machinename, sizeof(machinename)))
+				ct->modelname = xstrdup(machinename);
    if (!ct->modelname)
        ul_path_read_string(NULL, &ct->modelname, _PATH_SOC_MACHINENAME);

This should be enough, it reads the string, removes \n and strdup() the result.

Karel

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