66 lines
2.0 KiB
Diff
66 lines
2.0 KiB
Diff
commit 9e1fd818c15d3fd2f64cf594c3abb5df0885b1e0
|
|
Author: Tobias Klauser <tklauser@distanz.ch>
|
|
Date: Wed Jul 22 11:52:26 2020 +0200
|
|
|
|
Add CPUInfo parsing for RISCV
|
|
|
|
Currently only 64-bit RISCV is supported (GOARCH=riscv64) by the Go
|
|
compiler, but the cpuinfo format would be the same for 32-bit RISCV.
|
|
|
|
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
|
|
|
|
---
|
|
Rebased on node-exporter 1.0.1 by laokz <zhangkai@iscas.ac.cn>
|
|
|
|
diff --git a/vendor/github.com/prometheus/procfs/cpuinfo.go b/vendor/github.com/prometheus/procfs/cpuinfo.go
|
|
index 935157e..b9fb589 100644
|
|
--- a/vendor/github.com/prometheus/procfs/cpuinfo.go
|
|
+++ b/vendor/github.com/prometheus/procfs/cpuinfo.go
|
|
@@ -407,6 +407,46 @@ func parseCPUInfoPPC(info []byte) ([]CPUInfo, error) {
|
|
return cpuinfo, nil
|
|
}
|
|
|
|
+func parseCPUInfoRISCV(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)
|
|
+ v, err := strconv.ParseUint(field[1], 0, 32)
|
|
+ if err != nil {
|
|
+ return nil, err
|
|
+ }
|
|
+ firstcpu := CPUInfo{Processor: uint(v)}
|
|
+ cpuinfo := []CPUInfo{firstcpu}
|
|
+ i := 0
|
|
+
|
|
+ for scanner.Scan() {
|
|
+ line := scanner.Text()
|
|
+ if !strings.Contains(line, ":") {
|
|
+ continue
|
|
+ }
|
|
+ field := strings.SplitN(line, ": ", 2)
|
|
+ switch strings.TrimSpace(field[0]) {
|
|
+ case "processor":
|
|
+ v, err := strconv.ParseUint(field[1], 0, 32)
|
|
+ if err != nil {
|
|
+ return nil, err
|
|
+ }
|
|
+ i = int(v)
|
|
+ cpuinfo = append(cpuinfo, CPUInfo{}) // start of the next processor
|
|
+ cpuinfo[i].Processor = uint(v)
|
|
+ case "hart":
|
|
+ cpuinfo[i].CoreID = field[1]
|
|
+ case "isa":
|
|
+ cpuinfo[i].ModelName = field[1]
|
|
+ }
|
|
+ }
|
|
+ return cpuinfo, nil
|
|
+}
|
|
+
|
|
// firstNonEmptyLine advances the scanner to the first non-empty line
|
|
// and returns the contents of that line
|
|
func firstNonEmptyLine(scanner *bufio.Scanner) string {
|