-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcpu_online.go
59 lines (47 loc) · 947 Bytes
/
cpu_online.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package intelpower
import (
"os"
"path"
)
// IsOfflineAvailable - Returns cpu offline availability
func (cpu *CPU) IsOfflineAvailable() (bool, error) {
_, err := os.Stat(path.Join(cpu.cpuRoot, "online"))
if err != nil {
if os.IsNotExist(err) {
return false, nil
}
return false, err
}
return true, nil
}
// IsOnline - Returns current cpu online status
func (cpu *CPU) IsOnline() (bool, error) {
canBeOffline, err := cpu.IsOfflineAvailable()
if err != nil {
return false, err
}
if !canBeOffline {
return true, nil
}
resp, err := cpu.pwr.cmdRead(cpu.cpuRoot, "online")
if err != nil {
return false, err
}
online := false
if resp == "1" {
online = true
}
return online, nil
}
// SetOnline - Sets cpu online status
func (cpu *CPU) SetOnline(online bool) error {
stat := "1"
if !online {
stat = "0"
}
err := cpu.pwr.cmdWrite(stat, cpu.cpuRoot, "online")
if err != nil {
return err
}
return nil
}