* [PATCH 1/2] lscpu: get the processor information by DMI
@ 2021-06-15 10:06 Huang Shijie
2021-06-15 10:06 ` [RFC PATCH 2/2] lscpu: add bios_family Huang Shijie
2021-06-16 9:17 ` [PATCH 1/2] lscpu: get the processor information by DMI Karel Zak
0 siblings, 2 replies; 3+ messages in thread
From: Huang Shijie @ 2021-06-15 10:06 UTC (permalink / raw)
To: util-linux
Cc: patches, zwang, mas, ilkka, jeremy.linton, jbastian, m.mizuma,
Huang Shijie
The patch :367c85c47286 ("lscpu: use SMBIOS tables on ARM for lscpu")
relies on the existence of "/sys/firmware/dmi/entries/4-0/raw",
which may not exist in standard linux kernel.
But "/sys/firmware/dmi/tables/DMI" should exist and can provide the required
processor information.
This patch uses "/sys/firmware/dmi/tables/DMI"
to get the processor information:
Before this patch, in Ampere Altra platform, the lscpu output is:
---------------------------------------------
Architecture: aarch64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 160
On-line CPU(s) list: 0-159
Vendor ID: ARM
Model name: Neoverse-N1
Model: 1
Thread(s) per core: 1
Core(s) per socket: 80
Socket(s): 2
........................................
---------------------------------------------
After this patch, we can use get the lscpu output
in Ampere Altra platform:
---------------------------------------------
Architecture: aarch64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 160
On-line CPU(s) list: 0-159
Vendor ID: ARM
BIOS Vendor ID: Ampere(R)
Model name: Neoverse-N1
BIOS Model name: Ampere(R) Altra(R) Processor Q00-00 CPU @ 3.0GHz
Model: 1
Thread(s) per core: 1
Core(s) per socket: 80
Socket(s): 2
........................................
---------------------------------------------
Signed-off-by: Huang Shijie <shijie@os.amperecomputing.com>
---
sys-utils/lscpu-arm.c | 2 ++
sys-utils/lscpu-dmi.c | 39 +++++++++++++++++++++++++++++++++++++++
sys-utils/lscpu.h | 7 +++++++
3 files changed, 48 insertions(+)
diff --git a/sys-utils/lscpu-arm.c b/sys-utils/lscpu-arm.c
index 230eb5fdd..885aadc36 100644
--- a/sys-utils/lscpu-arm.c
+++ b/sys-utils/lscpu-arm.c
@@ -361,6 +361,8 @@ static void arm_decode(struct lscpu_cxt *cxt, struct lscpu_cputype *ct)
/* use SMBIOS Type 4 data if available */
if (!cxt->noalive && access(_PATH_SYS_DMI_TYPE4, R_OK) == 0)
arm_smbios_decode(ct);
+ else if (!cxt->noalive && access(_PATH_SYS_DMI, R_OK) == 0)
+ dmi_decode_cputype(ct);
arm_ids_decode(ct);
arm_rXpY_decode(ct);
diff --git a/sys-utils/lscpu-dmi.c b/sys-utils/lscpu-dmi.c
index e7ffa88d3..d05380891 100644
--- a/sys-utils/lscpu-dmi.c
+++ b/sys-utils/lscpu-dmi.c
@@ -67,6 +67,13 @@ int parse_dmi_table(uint16_t len, uint16_t num,
di->product = dmi_string(&h, data[0x05]);
break;
case 4:
+ /* Get the first processor information */
+ if (di->sockets == 0) {
+ di->processor_manufacturer = dmi_string(&h, data[0x7]);
+ di->processor_version = dmi_string(&h, data[0x10]);
+ di->current_speed = *((uint16_t *)(&data[0x16]));
+ di->part_num = dmi_string(&h, data[0x22]);
+ }
di->sockets++;
break;
default:
@@ -81,6 +88,38 @@ done:
return rc;
}
+int dmi_decode_cputype(struct lscpu_cputype *ct)
+{
+ static char const sys_fw_dmi_tables[] = _PATH_SYS_DMI;
+ struct dmi_info di = { };
+ struct stat st;
+ uint8_t *data;
+ int rc = 0;
+ char buf[100] = { };
+
+ 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;
+
+ rc = parse_dmi_table(st.st_size, st.st_size/4, data, &di);
+ if (rc < 0) {
+ free(data);
+ return rc;
+ }
+
+ ct->bios_vendor = xstrdup(di.processor_manufacturer);
+
+ sprintf(buf, "%s %s CPU @ %d.%dGHz", di.processor_version, di.part_num,
+ di.current_speed/1000, (di.current_speed % 1000) / 100);
+ ct->bios_modelname = xstrdup(buf);
+
+ free(data);
+ return 0;
+}
+
size_t get_number_of_physical_sockets_from_dmi(void)
{
static char const sys_fw_dmi_tables[] = _PATH_SYS_DMI;
diff --git a/sys-utils/lscpu.h b/sys-utils/lscpu.h
index 62f532581..4dc8e0a23 100644
--- a/sys-utils/lscpu.h
+++ b/sys-utils/lscpu.h
@@ -316,6 +316,12 @@ struct dmi_info {
char *product;
char *manufacturer;
int sockets;
+
+ /* Processor Information */
+ char *processor_manufacturer;
+ char *processor_version;
+ uint16_t current_speed;
+ char *part_num;
};
@@ -323,4 +329,5 @@ void to_dmi_header(struct lscpu_dmi_header *h, uint8_t *data);
char *dmi_string(const struct lscpu_dmi_header *dm, uint8_t s);
int parse_dmi_table(uint16_t len, uint16_t num, uint8_t *data, struct dmi_info *di);
size_t get_number_of_physical_sockets_from_dmi(void);
+int dmi_decode_cputype(struct lscpu_cputype *);
#endif /* LSCPU_H */
--
2.30.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [RFC PATCH 2/2] lscpu: add bios_family
2021-06-15 10:06 [PATCH 1/2] lscpu: get the processor information by DMI Huang Shijie
@ 2021-06-15 10:06 ` Huang Shijie
2021-06-16 9:17 ` [PATCH 1/2] lscpu: get the processor information by DMI Karel Zak
1 sibling, 0 replies; 3+ messages in thread
From: Huang Shijie @ 2021-06-15 10:06 UTC (permalink / raw)
To: util-linux
Cc: patches, zwang, mas, ilkka, jeremy.linton, jbastian, m.mizuma,
Huang Shijie
In the arm platform, we do not have the "CPU family" as X86.
In the linux kernel, it is hardcode to set the "CPU architecuture:8"
which should be changed for arm v9 in future.
This patch adds "bios_family" field, which we can get from the DMI table.
In the ampere Altra platform, we can get the new lscpu output:
----------------------------------------------------------------
Architecture: aarch64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 160
On-line CPU(s) list: 0-159
Vendor ID: ARM
BIOS Vendor ID: Ampere(R)
Model name: Neoverse-N1
BIOS Model name: Ampere(R) Altra(R) Processor Q00-00 CPU @ 3.0GHz
BIOS CPU family: 257
Model: 1
Thread(s) per core: 1
----------------------------------------------------------------
Signed-off-by: Huang Shijie <shijie@os.amperecomputing.com>
---
This patch is just RFC, if it is not proper, we can drop it.
---
sys-utils/lscpu-cputype.c | 1 +
sys-utils/lscpu-dmi.c | 10 ++++++++++
sys-utils/lscpu.c | 2 ++
sys-utils/lscpu.h | 2 ++
4 files changed, 15 insertions(+)
diff --git a/sys-utils/lscpu-cputype.c b/sys-utils/lscpu-cputype.c
index d5ca8e1f1..d5f0eb7d6 100644
--- a/sys-utils/lscpu-cputype.c
+++ b/sys-utils/lscpu-cputype.c
@@ -81,6 +81,7 @@ void lscpu_unref_cputype(struct lscpu_cputype *ct)
free(ct->model);
free(ct->modelname);
free(ct->bios_modelname);
+ free(ct->bios_family);
free(ct->revision); /* alternative for model (ppc) */
free(ct->stepping);
free(ct->bogomips);
diff --git a/sys-utils/lscpu-dmi.c b/sys-utils/lscpu-dmi.c
index d05380891..ef82cf828 100644
--- a/sys-utils/lscpu-dmi.c
+++ b/sys-utils/lscpu-dmi.c
@@ -73,6 +73,11 @@ int parse_dmi_table(uint16_t len, uint16_t num,
di->processor_version = dmi_string(&h, data[0x10]);
di->current_speed = *((uint16_t *)(&data[0x16]));
di->part_num = dmi_string(&h, data[0x22]);
+
+ if (data[0x6] == 0xfe)
+ di->processor_family = *((uint16_t *)(&data[0x28]));
+ else
+ di->processor_family = data[0x6];
}
di->sockets++;
break;
@@ -116,6 +121,11 @@ int dmi_decode_cputype(struct lscpu_cputype *ct)
di.current_speed/1000, (di.current_speed % 1000) / 100);
ct->bios_modelname = xstrdup(buf);
+ /* Get CPU family */
+ memset(buf, 0, sizeof(buf));
+ sprintf(buf, "%d", di.processor_family);
+ ct->bios_family = xstrdup(buf);
+
free(data);
return 0;
}
diff --git a/sys-utils/lscpu.c b/sys-utils/lscpu.c
index 5a99a9a5b..827e84a6d 100644
--- a/sys-utils/lscpu.c
+++ b/sys-utils/lscpu.c
@@ -863,6 +863,8 @@ print_summary_cputype(struct lscpu_cxt *cxt,
sec = add_summary_s(tb, sec, _("Model name:"), ct->modelname);
if (ct->bios_modelname)
add_summary_s(tb, sec, _("BIOS Model name:"), ct->bios_modelname);
+ if (ct->bios_family)
+ add_summary_s(tb, sec, _("BIOS CPU family:"), ct->bios_family);
if (ct->machinetype)
add_summary_s(tb, sec, _("Machine type:"), ct->machinetype);
if (ct->family)
diff --git a/sys-utils/lscpu.h b/sys-utils/lscpu.h
index 4dc8e0a23..79477b469 100644
--- a/sys-utils/lscpu.h
+++ b/sys-utils/lscpu.h
@@ -65,6 +65,7 @@ struct lscpu_cputype {
char *model;
char *modelname;
char *bios_modelname; /* aarch64 */
+ char *bios_family; /* aarch64 */
char *revision; /* alternative for model (ppc) */
char *stepping;
char *bogomips;
@@ -318,6 +319,7 @@ struct dmi_info {
int sockets;
/* Processor Information */
+ uint16_t processor_family;
char *processor_manufacturer;
char *processor_version;
uint16_t current_speed;
--
2.30.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 1/2] lscpu: get the processor information by DMI
2021-06-15 10:06 [PATCH 1/2] lscpu: get the processor information by DMI Huang Shijie
2021-06-15 10:06 ` [RFC PATCH 2/2] lscpu: add bios_family Huang Shijie
@ 2021-06-16 9:17 ` Karel Zak
1 sibling, 0 replies; 3+ messages in thread
From: Karel Zak @ 2021-06-16 9:17 UTC (permalink / raw)
To: Huang Shijie
Cc: util-linux, patches, zwang, mas, ilkka, jeremy.linton, jbastian,
m.mizuma
On Tue, Jun 15, 2021 at 10:06:38AM +0000, Huang Shijie wrote:
> sys-utils/lscpu-arm.c | 2 ++
> sys-utils/lscpu-dmi.c | 39 +++++++++++++++++++++++++++++++++++++++
> sys-utils/lscpu.h | 7 +++++++
> 3 files changed, 48 insertions(+)
Applied (both patches), thanks.
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-06-16 9:18 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-15 10:06 [PATCH 1/2] lscpu: get the processor information by DMI Huang Shijie
2021-06-15 10:06 ` [RFC PATCH 2/2] lscpu: add bios_family Huang Shijie
2021-06-16 9:17 ` [PATCH 1/2] lscpu: get the processor information by DMI Karel Zak
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).