-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcpu_governor.go
More file actions
51 lines (41 loc) · 1.19 KB
/
Copy pathcpu_governor.go
File metadata and controls
51 lines (41 loc) · 1.19 KB
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
package intelpower
import (
"strings"
)
type CPUGovernor string
const (
CPUGovernorOnDemand = CPUGovernor("ondemand")
CPUGovernorPowersave = CPUGovernor("powersave")
CPUGovernorConservative = CPUGovernor("conservative")
CPUGovernorUserspace = CPUGovernor("userspace")
CPUGovernorPerformance = CPUGovernor("performance")
)
// GetAvailableGovernors - Returns available governors
func (cpu *CPU) GetAvailableGovernors() ([]CPUGovernor, error) {
resp, err := cpu.pwr.cmdRead(cpu.cpuRoot, "cpufreq", "scaling_available_governors")
if err != nil {
return nil, err
}
govs := strings.Split(resp, " ")
governors := make([]CPUGovernor, len(govs))
for i, gov := range govs {
governors[i] = CPUGovernor(gov)
}
return governors, nil
}
// GetGovernor - Returns current governor
func (cpu *CPU) GetGovernor() (CPUGovernor, error) {
resp, err := cpu.pwr.cmdRead(cpu.cpuRoot, "cpufreq", "scaling_governor")
if err != nil {
return "", err
}
return CPUGovernor(resp), nil
}
// SetGovernor - Sets governor
func (cpu *CPU) SetGovernor(governor CPUGovernor) error {
err := cpu.pwr.cmdWrite(string(governor), cpu.cpuRoot, "cpufreq", "scaling_governor")
if err != nil {
return err
}
return nil
}