diff options
author | Riku Voipio | 2018-01-18 15:57:51 +0100 |
---|---|---|
committer | Riku Voipio | 2018-01-19 16:14:19 +0100 |
commit | 744d62ee0c54963539832ec5943f3d25e0fccfbd (patch) | |
tree | 002f7ca68cde9ac816d388477e6777abab8f093a /sys-utils/lscpu.c | |
parent | sfdisk: add hint about udev and flock to the man page (diff) | |
download | kernel-qcow2-util-linux-744d62ee0c54963539832ec5943f3d25e0fccfbd.tar.gz kernel-qcow2-util-linux-744d62ee0c54963539832ec5943f3d25e0fccfbd.tar.xz kernel-qcow2-util-linux-744d62ee0c54963539832ec5943f3d25e0fccfbd.zip |
lscpu: Decode ARM CPUs
Since the kernel developers have refused to make /proc/cpuinfo user
understandable, implement mapping in userspace. lscpu is available for
most users via util-linux, so store the information here.
Signed-off-by: Riku Voipio <riku.voipio@iki.fi>
Diffstat (limited to 'sys-utils/lscpu.c')
-rw-r--r-- | sys-utils/lscpu.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/sys-utils/lscpu.c b/sys-utils/lscpu.c index 10c20aa16..93e699cde 100644 --- a/sys-utils/lscpu.c +++ b/sys-utils/lscpu.c @@ -68,6 +68,7 @@ #include "closestream.h" #include "optutils.h" #include "lscpu.h" +#include "lscpu-arm.h" #define CACHE_MAX 100 @@ -539,6 +540,48 @@ static void read_physical_info_powerpc( #endif static void +arm_cpu_decode(struct lscpu_desc *desc) +{ + int j, impl, part; + const struct id_part *parts = NULL; + char buf[8]; + if (desc->vendor == NULL || desc->model == NULL) + return; + if ((strncmp(desc->vendor,"0x",2) || + strncmp(desc->model,"0x",2) )) + return; + + impl=(int)strtol(desc->vendor, NULL, 0); + part=(int)strtol(desc->model, NULL, 0); + + for (j = 0; hw_implementer[j].id != -1; j++) { + if (hw_implementer[j].id == impl) { + parts = hw_implementer[j].parts; + desc->vendor = (char *)hw_implementer[j].name; + break; + } + } + if ( parts == NULL) + return; + + for (j = 0; parts[j].id != -1; j++) { + if (parts[j].id == part) { + desc->modelname = (char *)parts[j].name; + break; + } + } + + /* Print out the rXpY string for ARM cores */ + if (impl == 0x41 && desc->revision != NULL && + desc->stepping != NULL) { + int revision = atoi(desc->revision); + int variant = (int)strtol(desc->stepping, NULL, 0); + snprintf(buf, sizeof(buf), "r%dp%d", variant, revision ); + desc->stepping=xstrdup(buf); + } +} + +static void read_basicinfo(struct lscpu_desc *desc, struct lscpu_modifier *mod) { FILE *fp = path_fopen("r", 1, _PATH_PROC_CPUINFO); @@ -555,11 +598,14 @@ read_basicinfo(struct lscpu_desc *desc, struct lscpu_modifier *mod) while (fgets(buf, sizeof(buf), fp) != NULL) { if (lookup(buf, "vendor", &desc->vendor)) ; else if (lookup(buf, "vendor_id", &desc->vendor)) ; + else if (lookup(buf, "CPU implementer", &desc->vendor)) ; /* ARM and aarch64 */ else if (lookup(buf, "family", &desc->family)) ; else if (lookup(buf, "cpu family", &desc->family)) ; else if (lookup(buf, "model", &desc->model)) ; + else if (lookup(buf, "CPU part", &desc->model)) ; /* ARM and aarch64 */ else if (lookup(buf, "model name", &desc->modelname)) ; else if (lookup(buf, "stepping", &desc->stepping)) ; + else if (lookup(buf, "CPU variant", &desc->stepping)) ; /* aarch64 */ else if (lookup(buf, "cpu MHz", &desc->mhz)) ; else if (lookup(buf, "cpu MHz dynamic", &desc->dynamic_mhz)) ; /* s390 */ else if (lookup(buf, "cpu MHz static", &desc->static_mhz)) ; /* s390 */ @@ -2207,6 +2253,7 @@ int main(int argc, char *argv[]) read_nodes(desc); read_hypervisor(desc, mod); + arm_cpu_decode(desc); switch(mod->mode) { case OUTPUT_SUMMARY: |