public inbox for util-linux@vger.kernel.org
 help / color / mirror / Atom feed
From: Jeremy Linton <jeremy.linton@arm.com>
To: Paul Benoit <paul@os.amperecomputing.com>, util-linux@vger.kernel.org
Subject: Re: [PATCH 1/2] lscpu-arm: Allow externally sourced model name.
Date: Fri, 11 Jul 2025 17:22:44 -0500	[thread overview]
Message-ID: <935fd521-508a-4f66-9ece-7ccf2eea61b9@arm.com> (raw)
In-Reply-To: <20250711211648.53361-1-paul@os.amperecomputing.com>

Hi,

On 7/11/25 4:16 PM, Paul Benoit wrote:
> 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?


> 
> 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.
> 
> Signed-off-by: Paul Benoit <paul@os.amperecomputing.com>
> ---
>   sys-utils/lscpu-arm.c | 35 ++++++++++++++++++++++++++++++++---
>   sys-utils/lscpu.h     |  1 +
>   2 files changed, 33 insertions(+), 3 deletions(-)
> 
> diff --git a/sys-utils/lscpu-arm.c b/sys-utils/lscpu-arm.c
> index 8745599d4..a46106bcb 100644
> --- a/sys-utils/lscpu-arm.c
> +++ b/sys-utils/lscpu-arm.c
> @@ -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;
>   }
>   
> diff --git a/sys-utils/lscpu.h b/sys-utils/lscpu.h
> index bd7b64cc5..581602f70 100644
> --- a/sys-utils/lscpu.h
> +++ b/sys-utils/lscpu.h
> @@ -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 */


  parent reply	other threads:[~2025-07-11 22:22 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-11 21:16 [PATCH 1/2] lscpu-arm: Allow externally sourced model name Paul Benoit
2025-07-11 21:16 ` [PATCH 2/2] lscpu-arm: Remove the "Ampere-1a" part Paul Benoit
2025-07-14 12:16   ` Karel Zak
2025-07-14 20:48     ` Jeremy Linton
2025-07-14 22:22       ` Paul Benoit
2025-07-15  9:19       ` Karel Zak
2025-11-07 21:26         ` Paul Benoit
2025-11-07 20:48       ` Paul Benoit
2026-02-11 21:23         ` [PATCH v2 1/2] lscpu-arm: Include the ARM SMC CC SOC_ID name Paul Benoit
2026-02-11 21:23         ` [PATCH v2 2/2] lscpu-arm: Correct Ampere part name strings Paul Benoit
2025-07-11 22:22 ` Jeremy Linton [this message]
2025-11-07 21:45   ` [PATCH 1/2] lscpu-arm: Allow externally sourced model name Paul Benoit
2025-07-14 12:11 ` Karel Zak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=935fd521-508a-4f66-9ece-7ccf2eea61b9@arm.com \
    --to=jeremy.linton@arm.com \
    --cc=paul@os.amperecomputing.com \
    --cc=util-linux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox