Skip to content

CPUInfo for ARM and Linux kernels newer than 3.8 #294

Closed

Description

@bluecmd

From #291 it was concluded that the current parsing code is limited to kernels older than 3.8.

Problematic code is:

procfs/cpuinfo.go

Lines 189 to 233 in 7a44272

func parseCPUInfoARM(info []byte) ([]CPUInfo, error) {
scanner := bufio.NewScanner(bytes.NewReader(info))
firstLine := firstNonEmptyLine(scanner)
if !strings.HasPrefix(firstLine, "Processor") || !strings.Contains(firstLine, ":") {
return nil, errors.New("invalid cpuinfo file: " + firstLine)
}
field := strings.SplitN(firstLine, ": ", 2)
commonCPUInfo := CPUInfo{VendorID: field[1]}
cpuinfo := []CPUInfo{}
i := -1
featuresLine := ""
for scanner.Scan() {
line := scanner.Text()
if !strings.Contains(line, ":") {
continue
}
field := strings.SplitN(line, ": ", 2)
switch strings.TrimSpace(field[0]) {
case "processor":
cpuinfo = append(cpuinfo, commonCPUInfo) // start of the next processor
i++
v, err := strconv.ParseUint(field[1], 0, 32)
if err != nil {
return nil, err
}
cpuinfo[i].Processor = uint(v)
case "BogoMIPS":
v, err := strconv.ParseFloat(field[1], 64)
if err != nil {
return nil, err
}
cpuinfo[i].BogoMips = v
case "Features":
featuresLine = line
}
}
fields := strings.SplitN(featuresLine, ": ", 2)
for i := range cpuinfo {
cpuinfo[i].Flags = strings.Fields(fields[1])
}
return cpuinfo, nil
}

This code should be changed to either drop support for older kernels, or be capable of parsing both new and old kernels alike - probably with reduced functionality for the older ones.

Activity

  1. changed the title [-]CPUInfo for ARM and Kernels newer than 3.8[/-] [+]CPUInfo for ARM and kernels newer than 3.8[/+] on May 15, 2020
  2. changed the title [-]CPUInfo for ARM and kernels newer than 3.8[/-] [+]CPUInfo for ARM and Linux kernels newer than 3.8[/+] on May 15, 2020
  3. pgier commented on May 27, 2020

    @pgier
    Contributor

    I believe this is resolved now with the merge of #296

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions