Skip to content

Commit 126d96d

Browse files
Decodetalkersdeepin-bot[bot]
authored andcommitted
feat: betterperformancelogic
Issue: linuxdeepin/developer-center#6514 Log:
1 parent f6141b0 commit 126d96d

6 files changed

Lines changed: 38 additions & 6 deletions

File tree

system/power1/cpu_handler.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const (
2626
globalAvailableGovernorFileName = "scaling_available_governors"
2727
globalBoostFilePath = "/sys/devices/system/cpu/cpufreq/boost"
2828
globalDefaultPath = "/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor"
29+
globalDefaultDriverPath = "/sys/devices/system/cpu/cpu0/cpufreq/scaling_driver"
2930
_isHuaWei = `dmidecode -t 1 | awk "/Product Name:/{print $NF}" | cut -d ":" -f 2`
3031
)
3132

@@ -103,13 +104,11 @@ func getIsBalanceSupported(isPstate bool) bool {
103104
}
104105
}
105106

106-
// TODO: 之后是否需要判断boost 的逻辑需要讨论
107107
func getIsHighPerformanceSupported(isPstate bool) bool {
108-
cpus := CpuHandlers{}
109108
if isPstate {
110109
return strv.Strv(getSupportGovernors()).Contains("performance")
111110
}
112-
return cpus.IsBoostFileExist() && strv.Strv(getSupportGovernors()).Contains("performance")
111+
return strv.Strv(getSupportGovernors()).Contains("performance")
113112
}
114113

115114
func getIsPowerSaveSupported(isPstate bool) bool {
@@ -340,6 +339,22 @@ func (cpus *CpuHandlers) getCpuGovernorPath(isPstate bool) string {
340339
return path
341340
}
342341

342+
func cpuHasPstate() bool {
343+
if !dutils.IsFileExist(globalDefaultDriverPath) {
344+
return false
345+
}
346+
driverData, err := os.ReadFile(globalDefaultDriverPath)
347+
if err != nil {
348+
return false
349+
}
350+
driver := string(driverData)
351+
return driverHasPstate(driver) && dutils.IsFileExist(pstateConfPath)
352+
}
353+
354+
func driverHasPstate(driver string) bool {
355+
return strings.Contains(driver, "pstate")
356+
}
357+
343358
// 通过写文件的返回情况,获取非scaling_available_governors的值是否支持
344359
func (cpus *CpuHandlers) tryWriteGovernor(lines []string, isPstate bool) []string {
345360
path := cpus.getCpuGovernorPath(isPstate)

system/power1/cpu_handler_test.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,25 @@
55
package power
66

77
import (
8-
"testing"
9-
108
"github.com/stretchr/testify/assert"
9+
"os"
10+
"testing"
1111
)
1212

13+
func Test_IsPstate(t *testing.T) {
14+
driverData, _ := os.ReadFile("./testdata/scaling_driver_intel_pstate")
15+
driver := string(driverData)
16+
assert.Equal(t, driverHasPstate(driver), true)
17+
18+
driverData, _ = os.ReadFile("./testdata/scaling_driver_amd_pstate")
19+
driver = string(driverData)
20+
assert.Equal(t, driverHasPstate(driver), true)
21+
22+
driverData, _ = os.ReadFile("./testdata/scaling_driver_intel_cpufreq")
23+
driver = string(driverData)
24+
assert.Equal(t, driverHasPstate(driver), false)
25+
}
26+
1327
func Test_GetGovernor(t *testing.T) {
1428
expectGovernor := "performance"
1529
cpu := CpuHandler{}

system/power1/manager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ func newManager(service *dbusutil.Service) (*Manager, error) {
151151
}
152152
// check pstate , if has pstate, it is intel pstate mode , then
153153
// we need another logic
154-
m.hasPstate = (dutils.IsFileExist(intelPstatePath) || dutils.IsFileExist(amdPstatePath)) && dutils.IsFileExist(pstateConfPath) // check if amd is used
154+
m.hasPstate = cpuHasPstate() // check if amd is used
155155
m.hasAmddpm = dutils.IsFileExist(amdGPUPath)
156156

157157
m.refreshSystemPowerPerformance()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
amd_pstatepp
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
intel_cpufreq
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
intel_pstate

0 commit comments

Comments
 (0)