* [PATCH] use SMBIOS tables on ARM for lscpu
@ 2020-09-24 21:56 Jeffrey Bastian
2020-09-29 11:35 ` Karel Zak
0 siblings, 1 reply; 3+ messages in thread
From: Jeffrey Bastian @ 2020-09-24 21:56 UTC (permalink / raw)
To: util-linux
ARM SBBR (Sever Base Boot Requirements) require SMBIOS tables, and
SMBIOS Type 4 describes the CPU manufacturer and model name (among other
details). If SMBIOS Type 4 is present, use it to extract these strings.
Example output (before and after the patch) on an HP m400, Lenovo HR330A,
and HPE Apollo 70:
[root@hp-m400 ~]# /usr/bin/lscpu | grep -i -e vendor -e model -e stepping
Vendor ID: APM
Model: 1
Model name: X-Gene
Stepping: 0x0
[root@hp-m400 ~]# ./lscpu | grep -i -e vendor -e model -e stepping
Vendor ID: AppliedMicro
Model: 1
Model name: X-Gene
Stepping: 0x0
[root@lenovo-hr330a ~]# /usr/bin/lscpu | grep -i -e vendor -e model -e stepping
Vendor ID: APM
Model: 2
Model name: X-Gene
Stepping: 0x3
[root@lenovo-hr330a ~]# ./lscpu | grep -i -e vendor -e model -e stepping
Vendor ID: Ampere(TM)
Model: 2
Model name: eMAG
Stepping: 0x3
[root@hpe-apollo-70 ~]# /usr/bin/lscpu | grep -i -e vendor -e model -e stepping
Vendor ID: Cavium
Model: 1
Model name: ThunderX2 99xx
Stepping: 0x1
[root@hpe-apollo-70 ~]# ./lscpu | grep -i -e vendor -e model -e stepping
Vendor ID: Cavium Inc.
Model: 1
Model name: Cavium ThunderX2(R) CPU CN9980 v2.1 @ 2.20GHz
Stepping: 0x1
Signed-off-by: Jeffrey Bastian <jbastian@redhat.com>
---
sys-utils/lscpu-arm.c | 88 ++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 87 insertions(+), 1 deletion(-)
diff --git a/sys-utils/lscpu-arm.c b/sys-utils/lscpu-arm.c
index 270866191875..82cc23ca830c 100644
--- a/sys-utils/lscpu-arm.c
+++ b/sys-utils/lscpu-arm.c
@@ -22,7 +22,15 @@
* - Linux kernel: arch/armX/include/asm/cputype.h
* - GCC sources: config/arch/arch-cores.def
* - Ancient wisdom
+ * - SMBIOS tables (if applicable)
*/
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
#include "lscpu.h"
struct id_part {
@@ -202,7 +210,7 @@ static const struct hw_impl hw_implementer[] = {
{ -1, unknown_part, "unknown" },
};
-void arm_cpu_decode(struct lscpu_desc *desc)
+static void _arm_cpu_decode(struct lscpu_desc *desc)
{
int j, impl, part;
const struct id_part *parts = NULL;
@@ -260,3 +268,81 @@ void arm_cpu_decode(struct lscpu_desc *desc)
desc->stepping = xstrdup(buf);
}
}
+
+/* TODO: struct dmi_header, to_dmi_header() and dmi_string() are copied
+ * from lscpu-dmi.c. Move them to a library?
+ */
+struct dmi_header
+{
+ uint8_t type;
+ uint8_t length;
+ uint16_t handle;
+ uint8_t *data;
+};
+
+static void to_dmi_header(struct dmi_header *h, uint8_t *data)
+{
+ h->type = data[0];
+ h->length = data[1];
+ memcpy(&h->handle, data + 2, sizeof(h->handle));
+ h->data = data;
+}
+
+static char *dmi_string(const struct dmi_header *dm, uint8_t s)
+{
+ char *bp = (char *)dm->data;
+
+ if (s == 0)
+ return NULL;
+
+ bp += dm->length;
+ while (s > 1 && *bp)
+ {
+ bp += strlen(bp);
+ bp++;
+ s--;
+ }
+
+ if (!*bp)
+ return NULL;
+
+ return bp;
+}
+
+#define _PATH_SYS_DMI_TYPE4 "/sys/firmware/dmi/entries/4-0/raw"
+#define PROC_MFR_OFFSET 0x07
+#define PROC_VERSION_OFFSET 0x10
+
+static void _arm_cpu_smbios(struct lscpu_desc *desc)
+{
+ uint8_t data[8192];
+ char buf[128];
+ struct dmi_header h;
+ int raw_fd = -1;
+
+ raw_fd = open(_PATH_SYS_DMI_TYPE4, O_RDONLY);
+ if (raw_fd == -1) {
+ return;
+ }
+ read(raw_fd, data, 8192);
+ close(raw_fd);
+
+ to_dmi_header(&h, data);
+
+ strncpy(buf, dmi_string(&h, data[PROC_MFR_OFFSET]), 127);
+ desc->vendor = xstrdup(buf);
+
+ strncpy(buf, dmi_string(&h, data[PROC_VERSION_OFFSET]), 127);
+ desc->modelname = xstrdup(buf);
+}
+
+void arm_cpu_decode(struct lscpu_desc *desc)
+{
+ /* use SMBIOS Type 4 data if available,
+ * else fall back to manual decoding using the tables above */
+ if (access(_PATH_SYS_DMI_TYPE4, R_OK) != -1) {
+ _arm_cpu_smbios(desc);
+ } else {
+ _arm_cpu_decode(desc);
+ }
+}
--
2.26.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] use SMBIOS tables on ARM for lscpu
2020-09-24 21:56 [PATCH] use SMBIOS tables on ARM for lscpu Jeffrey Bastian
@ 2020-09-29 11:35 ` Karel Zak
2020-09-29 21:45 ` Jeffrey Bastian
0 siblings, 1 reply; 3+ messages in thread
From: Karel Zak @ 2020-09-29 11:35 UTC (permalink / raw)
To: Jeffrey Bastian; +Cc: util-linux
On Thu, Sep 24, 2020 at 04:56:17PM -0500, Jeffrey Bastian wrote:
> sys-utils/lscpu-arm.c | 88 ++++++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 87 insertions(+), 1 deletion(-)
Applied, but I did some changes to the code to be more robust and to
avoid dmi_header duplication in lscpu-arm.c and lscpu-dmi.c.
https://github.com/karelzak/util-linux/commit/367c85c472869b75eaf770d4be0b360e30710b95
Please, test it with your environment. I have no any ARM right now.
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] use SMBIOS tables on ARM for lscpu
2020-09-29 11:35 ` Karel Zak
@ 2020-09-29 21:45 ` Jeffrey Bastian
0 siblings, 0 replies; 3+ messages in thread
From: Jeffrey Bastian @ 2020-09-29 21:45 UTC (permalink / raw)
To: Karel Zak; +Cc: util-linux
On Tue, Sep 29, 2020 at 01:35:28PM +0200, Karel Zak wrote:
>On Thu, Sep 24, 2020 at 04:56:17PM -0500, Jeffrey Bastian wrote:
>> sys-utils/lscpu-arm.c | 88 ++++++++++++++++++++++++++++++++++++++++++-
>> 1 file changed, 87 insertions(+), 1 deletion(-)
>
>Applied, but I did some changes to the code to be more robust and to
>avoid dmi_header duplication in lscpu-arm.c and lscpu-dmi.c.
>
>https://github.com/karelzak/util-linux/commit/367c85c472869b75eaf770d4be0b360e30710b95
>
>Please, test it with your environment. I have no any ARM right now.
Thanks! I wasn't sure how you wanted to handle the dmi duplicated code,
but I like what you did.
I tested this on several ARM servers and it worked well. Note the
Amazon AWS m6g.large instance does not have a Type 4 entry in the SMBIOS
tables, so the fall back method was used (and it also works).
[ec2-user@aws-m6g.large ~]$ ls /sys/firmware/dmi/entries/4-0
ls: cannot access '/sys/firmware/dmi/entries/4-0': No such file or directory
[ec2-user@aws-m6g.large ~]$ ./lscpu | grep -e Vendor -e Model -e Stepping
Vendor ID: ARM
Model: 1
Model name: Neoverse-N1
Stepping: r3p1
[root@hp-m400 ~]# ./lscpu | grep -e Vendor -e Model -e Stepping
Vendor ID: AppliedMicro
Model: 1
Model name: X-Gene
Stepping: 0x0
[root@lenovo-hr330a ~]# ./lscpu | grep -e Vendor -e Model -e Stepping
Vendor ID: Ampere(TM)
Model: 2
Model name: eMAG
Stepping: 0x3
[root@hpe-apollo-70 ~]# ./lscpu | grep -e Vendor -e Model -e Stepping
Vendor ID: Cavium Inc.
Model: 1
Model name: Cavium ThunderX2(R) CPU CN9975 v2.1 @ 2.0GHz
Stepping: 0x1
[root@ampere-altra ~]# ./lscpu | grep -e Vendor -e Model -e Stepping
Vendor ID: Ampere(TM)
Model: 1
Model name: Ampere(TM) Altra(TM) Processor
Stepping: 0x3
--
Jeff Bastian
Kernel QE - Hardware Enablement
Red Hat
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-09-29 21:45 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-24 21:56 [PATCH] use SMBIOS tables on ARM for lscpu Jeffrey Bastian
2020-09-29 11:35 ` Karel Zak
2020-09-29 21:45 ` Jeffrey Bastian
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.