Skip to content

Commit acd173f

Browse files
committed
remove cpuinfo format detection
CPU detection is now done using compiler tags, so the manual detection is no longer needed. Signed-off-by: Paul Gier <[email protected]>
1 parent d0b675d commit acd173f

File tree

6 files changed

+0
-62
lines changed

6 files changed

+0
-62
lines changed

cpuinfo.go

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"bufio"
2020
"bytes"
2121
"errors"
22-
"fmt"
2322
"regexp"
2423
"strconv"
2524
"strings"
@@ -57,52 +56,18 @@ type CPUInfo struct {
5756
PowerManagement string
5857
}
5958

60-
const (
61-
platformX86 = "x86"
62-
platformARM = "arm"
63-
platformS390X = "s390x"
64-
platformPPC = "ppc"
65-
platformUnknown = "unknown"
66-
)
67-
6859
var (
69-
cpuinfoX86Regexp = regexp.MustCompile(`(?m)^\s*processor\s*:\s*\d+\s*vendor`)
70-
cpuinfoARMRegexp = regexp.MustCompile(`^\s*Processor\s*:\s*ARM`)
71-
cpuinfoS390XRegexp = regexp.MustCompile(`^\s*vendor_id\s*:\s*IBM/S390`)
72-
cpuinfoPPCRegexp = regexp.MustCompile(`(?m)^\s*processor\s*:\s*\d+\s+cpu\s+:\s+POWER`)
73-
7460
cpuinfoClockRegexp = regexp.MustCompile(`([\d.]+)`)
7561
cpuinfoS390XProcessorRegexp = regexp.MustCompile(`^processor\s+(\d+):.*`)
7662
)
7763

78-
// cpuinfoDetectFormat attempts to determine the format used by the cpuinfo.
79-
// This format corresponds to the platform generating the /proc/cpuinfo file.
80-
// Returns "unknown"
81-
func cpuinfoDetectFormat(info []byte) string {
82-
switch {
83-
case cpuinfoX86Regexp.Match(info):
84-
return platformX86
85-
case cpuinfoARMRegexp.Match(info):
86-
return platformARM
87-
case cpuinfoPPCRegexp.Match(info):
88-
return platformPPC
89-
case cpuinfoS390XRegexp.Match(info):
90-
return platformS390X
91-
}
92-
return platformUnknown
93-
}
94-
9564
// CPUInfo returns information about current system CPUs.
9665
// See https://www.kernel.org/doc/Documentation/filesystems/proc.txt
9766
func (fs FS) CPUInfo() ([]CPUInfo, error) {
9867
data, err := util.ReadFileNoStat(fs.proc.Path("cpuinfo"))
9968
if err != nil {
10069
return nil, err
10170
}
102-
if format := cpuinfoDetectFormat(data); format != expectedPlatform {
103-
return nil, fmt.Errorf("unable to parse CPU info, expected format %v, found: %v",
104-
expectedPlatform, format)
105-
}
10671
return parseCPUInfo(data)
10772
}
10873

cpuinfo_amd64.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,4 @@
1616

1717
package procfs
1818

19-
const expectedPlatform = platformX86
20-
2119
var parseCPUInfo = parseCPUInfoX86

cpuinfo_arm64.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,4 @@
1616

1717
package procfs
1818

19-
const expectedPlatform = platformARM
20-
2119
var parseCPUInfo = parseCPUInfoARM

cpuinfo_ppc64.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,4 @@
1616

1717
package procfs
1818

19-
const expectedPlatform = platformPPC
20-
2119
var parseCPUInfo = parseCPUInfoPPC

cpuinfo_s390x.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,4 @@
1616

1717
package procfs
1818

19-
const expectedPlatform = platformS390X
20-
2119
var parseCPUInfo = parseCPUInfoS390x

cpuinfo_test.go

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -110,25 +110,6 @@ machine : CHRP IBM,8233-E8B
110110
`
111111
)
112112

113-
func TestCPUInfoDetectFormat(t *testing.T) {
114-
cpuinfoX86Bytes := []byte("processor : 0\nvendor_id : GenuineIntel")
115-
if want, have := platformX86, cpuinfoDetectFormat(cpuinfoX86Bytes); want != have {
116-
t.Errorf("want cpuinfo format %v, have %v", want, have)
117-
}
118-
cpuinfoArm7Bytes := []byte(cpuinfoArm7)
119-
if want, have := platformARM, cpuinfoDetectFormat(cpuinfoArm7Bytes); want != have {
120-
t.Errorf("want cpuinfo format %v, have %v", want, have)
121-
}
122-
cpuinfoS390xBytes := []byte(cpuinfoS390x)
123-
if want, have := platformS390X, cpuinfoDetectFormat(cpuinfoS390xBytes); want != have {
124-
t.Errorf("want cpuinfo format %v, have %v", want, have)
125-
}
126-
cpuinfoPpc64Bytes := []byte(cpuinfoPpc64)
127-
if want, have := platformPPC, cpuinfoDetectFormat(cpuinfoPpc64Bytes); want != have {
128-
t.Errorf("want cpuinfo format %v, have %v", want, have)
129-
}
130-
}
131-
132113
func TestCPUInfoX86(t *testing.T) {
133114
cpuinfo, err := getProcFixtures(t).CPUInfo()
134115
if err != nil {

0 commit comments

Comments
 (0)