Skip to content

Commit 08bb266

Browse files
committed
[cpu][mac] change not return error even if cpu.frequency errors
Backport of shirou#1192. sysctl hw.cpufrequency does not return anything on macOS M1. This causes cpu.Info() to return an error every time it is called on macOS M1. A partial fix of this issue is to ignore errors, and leave the frequency field with its default value.
1 parent b1d3204 commit 08bb266

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

cpu/cpu_darwin.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,9 @@ func Info() ([]InfoStat, error) {
6969
// Use the rated frequency of the CPU. This is a static value and does not
7070
// account for low power or Turbo Boost modes.
7171
cpuFrequency, err := unix.SysctlUint64("hw.cpufrequency")
72-
if err != nil {
73-
return ret, err
72+
if err == nil {
73+
c.Mhz = float64(cpuFrequency) / 1000000.0
7474
}
75-
c.Mhz = float64(cpuFrequency) / 1000000.0
7675

7776
return append(ret, c), nil
7877
}

0 commit comments

Comments
 (0)