From 102439862ef65b1e9cb69c6150a7f7c8246770d6 Mon Sep 17 00:00:00 2001 From: Yalcin Ozbek Date: Sat, 5 Nov 2022 02:36:48 +0300 Subject: [PATCH 1/4] feat: Setting the model name for arm based CPUs - Added arm model and model name as map. - The modelName is set again according to the model value when the model name is empty. - Based on lscpu source code.. https://github.com/util-linux/util-linux/blob/master/sys-utils/lscpu-arm.c --- Signed-off-by: Yalcin Ozbek --- cpu/cpu_linux.go | 75 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/cpu/cpu_linux.go b/cpu/cpu_linux.go index 4f26230d6..63de828ea 100644 --- a/cpu/cpu_linux.go +++ b/cpu/cpu_linux.go @@ -17,6 +17,71 @@ import ( var ClocksPerSec = float64(100) +var armModelToModelName = map[uint64]string{ + 0x810: "ARM810", + 0x920: "ARM920", + 0x922: "ARM922", + 0x926: "ARM926", + 0x940: "ARM940", + 0x946: "ARM946", + 0x966: "ARM966", + 0xa20: "ARM1020", + 0xa22: "ARM1022", + 0xa26: "ARM1026", + 0xb02: "ARM11 MPCore", + 0xb36: "ARM1136", + 0xb56: "ARM1156", + 0xb76: "ARM1176", + 0xc05: "Cortex-A5", + 0xc07: "Cortex-A7", + 0xc08: "Cortex-A8", + 0xc09: "Cortex-A9", + 0xc0d: "Cortex-A17", + 0xc0f: "Cortex-A15", + 0xc0e: "Cortex-A17", + 0xc14: "Cortex-R4", + 0xc15: "Cortex-R5", + 0xc17: "Cortex-R7", + 0xc18: "Cortex-R8", + 0xc20: "Cortex-M0", + 0xc21: "Cortex-M1", + 0xc23: "Cortex-M3", + 0xc24: "Cortex-M4", + 0xc27: "Cortex-M7", + 0xc60: "Cortex-M0+", + 0xd01: "Cortex-A32", + 0xd02: "Cortex-A34", + 0xd03: "Cortex-A53", + 0xd04: "Cortex-A35", + 0xd05: "Cortex-A55", + 0xd06: "Cortex-A65", + 0xd07: "Cortex-A57", + 0xd08: "Cortex-A72", + 0xd09: "Cortex-A73", + 0xd0a: "Cortex-A75", + 0xd0b: "Cortex-A76", + 0xd0c: "Neoverse-N1", + 0xd0d: "Cortex-A77", + 0xd0e: "Cortex-A76AE", + 0xd13: "Cortex-R52", + 0xd20: "Cortex-M23", + 0xd21: "Cortex-M33", + 0xd40: "Neoverse-V1", + 0xd41: "Cortex-A78", + 0xd42: "Cortex-A78AE", + 0xd43: "Cortex-A65AE", + 0xd44: "Cortex-X1", + 0xd46: "Cortex-A510", + 0xd47: "Cortex-A710", + 0xd48: "Cortex-X2", + 0xd49: "Neoverse-N2", + 0xd4a: "Neoverse-E1", + 0xd4b: "Cortex-A78C", + 0xd4c: "Cortex-X1C", + 0xd4d: "Cortex-A715", + 0xd4e: "Cortex-X3", +} + func init() { clkTck, err := sysconf.Sysconf(sysconf.SC_CLK_TCK) // ignore errors @@ -179,6 +244,16 @@ func InfoWithContext(ctx context.Context) ([]InfoStat, error) { c.Model = value case "model name", "cpu": c.ModelName = value + if c.ModelName == "" { + if v, err := strconv.ParseUint(c.Model, 0, 16); err == nil { + modelName, isThereModel := armModelToModelName[v] + if !isThereModel { + c.ModelName = "Undefined" + } else { + c.ModelName = modelName + } + } + } if strings.Contains(value, "POWER8") || strings.Contains(value, "POWER7") { c.Model = strings.Split(value, " ")[0] From 13f00fde466f0e786b71796837a41eceeacd0ac4 Mon Sep 17 00:00:00 2001 From: Yalcin Ozbek Date: Sat, 5 Nov 2022 15:06:30 +0300 Subject: [PATCH 2/4] code review fix Signed-off-by: Yalcin Ozbek --- cpu/cpu_linux.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cpu/cpu_linux.go b/cpu/cpu_linux.go index 63de828ea..597777cf8 100644 --- a/cpu/cpu_linux.go +++ b/cpu/cpu_linux.go @@ -244,13 +244,13 @@ func InfoWithContext(ctx context.Context) ([]InfoStat, error) { c.Model = value case "model name", "cpu": c.ModelName = value - if c.ModelName == "" { + if c.VendorID == "ARM" && c.ModelName == "" { if v, err := strconv.ParseUint(c.Model, 0, 16); err == nil { - modelName, isThereModel := armModelToModelName[v] - if !isThereModel { - c.ModelName = "Undefined" - } else { + modelName, exist := armModelToModelName[v] + if exist { c.ModelName = modelName + } else { + c.ModelName = "Undefined" } } } From 4314a0567bd072dc4f9893300b26be535b0c407c Mon Sep 17 00:00:00 2001 From: Yalcin Ozbek Date: Sat, 5 Nov 2022 16:37:04 +0300 Subject: [PATCH 3/4] the code has been moved outside the loop. Signed-off-by: Yalcin Ozbek --- cpu/cpu_linux.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/cpu/cpu_linux.go b/cpu/cpu_linux.go index 597777cf8..165a34dde 100644 --- a/cpu/cpu_linux.go +++ b/cpu/cpu_linux.go @@ -244,16 +244,6 @@ func InfoWithContext(ctx context.Context) ([]InfoStat, error) { c.Model = value case "model name", "cpu": c.ModelName = value - if c.VendorID == "ARM" && c.ModelName == "" { - if v, err := strconv.ParseUint(c.Model, 0, 16); err == nil { - modelName, exist := armModelToModelName[v] - if exist { - c.ModelName = modelName - } else { - c.ModelName = "Undefined" - } - } - } if strings.Contains(value, "POWER8") || strings.Contains(value, "POWER7") { c.Model = strings.Split(value, " ")[0] @@ -299,6 +289,16 @@ func InfoWithContext(ctx context.Context) ([]InfoStat, error) { finishCPUInfo(&c) ret = append(ret, c) } + if c.VendorID == "ARM" && c.ModelName == "" { + if v, err := strconv.ParseUint(c.Model, 0, 16); err == nil { + modelName, exist := armModelToModelName[v] + if exist { + c.ModelName = modelName + } else { + c.ModelName = "Undefined" + } + } + } return ret, nil } From 8bf7f37fca1ae3b633e78ff5181851d9ec76a6a7 Mon Sep 17 00:00:00 2001 From: Yalcin Ozbek Date: Sat, 5 Nov 2022 16:40:39 +0300 Subject: [PATCH 4/4] the code has been moved before append Signed-off-by: Yalcin Ozbek --- cpu/cpu_linux.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cpu/cpu_linux.go b/cpu/cpu_linux.go index 165a34dde..44bf1ce4f 100644 --- a/cpu/cpu_linux.go +++ b/cpu/cpu_linux.go @@ -285,10 +285,6 @@ func InfoWithContext(ctx context.Context) ([]InfoStat, error) { c.Microcode = value } } - if c.CPU >= 0 { - finishCPUInfo(&c) - ret = append(ret, c) - } if c.VendorID == "ARM" && c.ModelName == "" { if v, err := strconv.ParseUint(c.Model, 0, 16); err == nil { modelName, exist := armModelToModelName[v] @@ -299,6 +295,10 @@ func InfoWithContext(ctx context.Context) ([]InfoStat, error) { } } } + if c.CPU >= 0 { + finishCPUInfo(&c) + ret = append(ret, c) + } return ret, nil }