-
Notifications
You must be signed in to change notification settings - Fork 14
/
sectCPU.go
108 lines (102 loc) · 2.78 KB
/
sectCPU.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package note
import (
"fmt"
"github.com/SUSE/saptune/system"
"strings"
)
// section [cpu]
// GetCPUVal initialise the cpu performance structure with the current
// system settings
func GetCPUVal(key string) (string, string, string) {
var val string
cpuStateDiffer := false
flsVal := ""
info := ""
switch key {
case "force_latency":
val, flsVal, cpuStateDiffer = system.GetFLInfo()
if cpuStateDiffer {
info = "hasDiffs"
}
case "energy_perf_bias":
// cpupower -c all info -b
val = system.GetPerfBias()
case "governor":
// cpupower -c all frequency-info -p
//or better
// cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
newGov := system.GetGovernor()
for k, v := range newGov {
val = val + fmt.Sprintf("%s:%s ", k, v)
}
}
val = strings.TrimSpace(val)
if val == "all:none" {
info = "notSupported"
}
return val, flsVal, info
}
// OptCPUVal optimises the cpu performance structure with the settings
// from the configuration file
func OptCPUVal(key, actval, cfgval string) string {
//ANGI TODO - check cfgval is not a single value like 'performance' but
// cpu0:performance cpu2:powersave
sval := strings.ToLower(cfgval)
rval := ""
val := "0"
switch key {
case "force_latency":
rval = sval
case "energy_perf_bias":
//performance - 0, normal - 6, powersave - 15
switch sval {
case "performance":
val = "0"
case "normal":
val = "6"
case "powersave":
val = "15"
default:
system.WarningLog("wrong selection for energy_perf_bias. Now set to 'performance'")
val = "0"
}
//ANGI TODO - if actval 'all:6', but cfgval 'cpu0:performance cpu1:normal cpu2:powersave'
// - does not work now - check length of both?
// same for governor
for _, entry := range strings.Fields(actval) {
fields := strings.Split(entry, ":")
rval = rval + fmt.Sprintf("%s:%s ", fields[0], val)
}
case "governor":
val = sval
for _, entry := range strings.Fields(actval) {
fields := strings.Split(entry, ":")
rval = rval + fmt.Sprintf("%s:%s ", fields[0], val)
}
}
return strings.TrimSpace(rval)
}
// SetCPUVal applies the settings to the system
func SetCPUVal(key, value, noteID, savedStates, oval string, revert bool) error {
var err error
switch key {
case "force_latency":
if oval != "untouched" {
err = system.SetForceLatency(value, savedStates, revert)
if !revert {
// the cpu state values of the note need to be stored
// after they are set. Special for 'force_latency'
// as we set and handle 2 different sort of values
// the 'force_latency' value and the related
// cpu state values
_, flstates, _ = system.GetFLInfo()
AddParameterNoteValues("fl_states", flstates, noteID)
}
}
case "energy_perf_bias":
err = system.SetPerfBias(value)
case "governor":
err = system.SetGovernor(value)
}
return err
}