Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 38 additions & 4 deletions cpu/cpu_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,25 @@ func InfoWithContext(ctx context.Context) ([]InfoStat, error) {
if strings.Contains(value, "S390") {
processorName = "S390"
}
case "mvendorid":
if !strings.HasPrefix(value, "0x") {
continue
}

if v, err := strconv.ParseUint(value[2:], 16, 32); err == nil {
switch v {
case 0x31e:
c.VendorID = "Andes"
case 0x029:
c.VendorID = "Microchip"
case 0x127:
c.VendorID = "MIPS"
case 0x489:
c.VendorID = "SiFive"
case 0x5b7:
c.VendorID = "T-Head"
}
}
case "CPU implementer":
if v, err := strconv.ParseUint(value, 0, 8); err == nil {
switch v {
Expand Down Expand Up @@ -256,9 +275,9 @@ func InfoWithContext(ctx context.Context) ([]InfoStat, error) {
c.VendorID = "Ampere"
}
}
case "cpu family":
case "cpu family", "marchid":
c.Family = value
case "model", "CPU part":
case "model", "CPU part", "mimpid":
c.Model = value
// if CPU is arm based, model name is found via model number. refer to: arch/arm64/kernel/cpuinfo.c
if c.VendorID == "ARM" {
Expand All @@ -271,7 +290,7 @@ func InfoWithContext(ctx context.Context) ([]InfoStat, error) {
}
}
}
case "Model Name", "model name", "cpu":
case "Model Name", "model name", "cpu", "uarch":
c.ModelName = value
if strings.Contains(value, "POWER") {
c.Model = strings.Split(value, " ")[0]
Expand Down Expand Up @@ -305,14 +324,19 @@ func InfoWithContext(ctx context.Context) ([]InfoStat, error) {
return ret, err
}
c.CacheSize = int32(t)
case "physical id":
case "physical id", "hart":
c.PhysicalID = value
case "core id":
c.CoreID = value
case "flags", "Features":
c.Flags = strings.FieldsFunc(value, func(r rune) bool {
return r == ',' || r == ' '
})
case "isa", "hart isa":
if len(c.Flags) != 0 || !strings.HasPrefix(value, "rv64") {
continue
}
c.Flags = riscvISAParse(value)
case "microcode":
c.Microcode = value
}
Expand Down Expand Up @@ -495,3 +519,13 @@ func CountsWithContext(ctx context.Context, logical bool) (int, error) {
}
return ret, nil
}

func riscvISAParse(s string) []string {
ext := strings.Split(s, "_")
if len(ext[0]) <= 4 {
return nil
}
// the base extensions must "rv64" prefix
base := strings.Split(ext[0][4:], "")
return append(base, ext[1:]...)
}