Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CPUInfo for ARM and Linux kernels newer than 3.8 #294

Closed
bluecmd opened this issue May 15, 2020 · 1 comment · May be fixed by #297
Closed

CPUInfo for ARM and Linux kernels newer than 3.8 #294

bluecmd opened this issue May 15, 2020 · 1 comment · May be fixed by #297

Comments

@bluecmd
Copy link
Contributor

bluecmd commented May 15, 2020

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.

@bluecmd bluecmd changed the title CPUInfo for ARM and Kernels newer than 3.8 CPUInfo for ARM and kernels newer than 3.8 May 15, 2020
@bluecmd bluecmd changed the title CPUInfo for ARM and kernels newer than 3.8 CPUInfo for ARM and Linux kernels newer than 3.8 May 15, 2020
kadern0 added a commit to kadern0/procfs that referenced this issue May 18, 2020
kadern0 added a commit to kadern0/procfs that referenced this issue May 18, 2020
Fixes issue prometheus#294

Signed-off-by: kadern0 <kaderno@gmail.com>
kadern0 added a commit to kadern0/procfs that referenced this issue May 19, 2020
Fixes issue prometheus#294

Signed-off-by: kadern0 <kaderno@gmail.com>
discordianfish pushed a commit that referenced this issue May 21, 2020
Fixes issue #294

Signed-off-by: kadern0 <kaderno@gmail.com>
@pgier
Copy link
Collaborator

pgier commented May 27, 2020

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

@pgier pgier closed this as completed May 27, 2020
remijouannet pushed a commit to remijouannet/procfs that referenced this issue Oct 20, 2022
Fixes issue prometheus#294

Signed-off-by: kadern0 <kaderno@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants