Skip to content

Commit

Permalink
Merge pull request #77 from mengmeet/intel
Browse files Browse the repository at this point in the history
Support Set Intel pstate CPU Max Performance Perf
  • Loading branch information
honjow authored May 27, 2024
2 parents 3867cc0 + c7b6a7a commit c0ddae3
Show file tree
Hide file tree
Showing 10 changed files with 161 additions and 28 deletions.
23 changes: 23 additions & 0 deletions backend/cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,29 @@ def get_ryzenadj_info(self):
except Exception as e:
logging.error(e)
return f"get_ryzenadj_info error:\n{e}"

def get_max_perf_pct(self):
max_perf_pct_path = "/sys/devices/system/cpu/intel_pstate/max_perf_pct"
if os.path.exists(max_perf_pct_path):
with open(max_perf_pct_path, "r") as file:
return int(file.read().strip())
else:
return 0

def set_max_perf_pct(self, value: int):
max_perf_pct_path = "/sys/devices/system/cpu/intel_pstate/max_perf_pct"
try:
if value < 10 or value > 100:
return False
if os.path.exists(max_perf_pct_path):
with open(max_perf_pct_path, "w") as file:
file.write(str(value))
return True
else:
return False
except Exception as e:
logging.error(e)
return False


cpuManager = CPUManager()
64 changes: 39 additions & 25 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,176 +43,176 @@ async def get_hasRyzenadj(self):
try:
return cpuManager.get_hasRyzenadj()
except Exception as e:
logging.error(e)
logging.error(e, exc_info=True)
return False

async def get_cpuMaxNum(self):
try:
return cpuManager.get_cpuMaxNum()
except Exception as e:
logging.error(e)
logging.error(e, exc_info=True)
return 0

async def get_isSupportSMT(self):
try:
return cpuManager.get_isSupportSMT()
except Exception as e:
logging.error(e)
logging.error(e, exc_info=True)
return False

async def get_tdpMax(self):
try:
return cpuManager.get_tdpMax()
except Exception as e:
logging.error(e)
logging.error(e, exc_info=True)
return 0

async def get_gpuFreqRange(self):
try:
return gpuManager.get_gpuFreqRange()
except Exception as e:
logging.error(e)
logging.error(e, exc_info=True)
return 0

# 弃用
async def get_cpu_AvailableFreq(self):
try:
return cpuManager.get_cpu_AvailableFreq()
except Exception as e:
logging.error(e)
logging.error(e, exc_info=True)
return []

async def get_language(self):
try:
return sysInfoManager.get_language()
except Exception as e:
logging.error(e)
logging.error(e, exc_info=True)
return ""

async def get_fanRPM(self, index):
try:
return fanManager.get_fanRPM(index)
except Exception as e:
logging.error(e)
logging.error(e, exc_info=True)
return 0

async def get_fanRPMPercent(self, index):
try:
return fanManager.get_fanRPMPercent(index)
except Exception as e:
logging.error(e)
logging.error(e, exc_info=True)
return 0

async def get_fanTemp(self, index):
try:
return fanManager.get_fanTemp(index)
except Exception as e:
logging.error(e)
logging.error(e, exc_info=True)
return 0

async def get_fanIsAuto(self, index):
try:
return fanManager.get_fanIsAuto(index)
except Exception as e:
logging.error(e)
logging.error(e, exc_info=True)
return 0

async def get_fanConfigList(self):
try:
return fanManager.get_fanConfigList()
except Exception as e:
logging.error(e)
logging.error(e, exc_info=True)
return []

async def set_fanAuto(self, index: int, value: bool):
try:
return fanManager.set_fanAuto(index, value)
except Exception as e:
logging.error(e)
logging.error(e, exc_info=True)
return False

async def set_fanPercent(self, index: int, value: int):
try:
return fanManager.set_fanPercent(index, value)
except Exception as e:
logging.error(e)
logging.error(e, exc_info=True)
return False

async def set_gpuAuto(self, value: bool):
try:
return gpuManager.set_gpuAuto(value)
except Exception as e:
logging.error(e)
logging.error(e, exc_info=True)
return False

async def set_gpuAutoFreqRange(self, min: int, max: int):
try:
return gpuManager.set_gpuAutoFreqRange(min, max)
except Exception as e:
logging.error(e)
logging.error(e, exc_info=True)
return False

async def set_gpuFreq(self, value: int):
try:
return gpuManager.set_gpuFreqFix(value)
except Exception as e:
logging.error(e)
logging.error(e, exc_info=True)
return False

async def set_gpuFreqRange(self, value: int, value2: int):
try:
return gpuManager.set_gpuFreqRange(value, value2)
except Exception as e:
logging.error(e)
logging.error(e, exc_info=True)
return False

async def set_cpuTDP(self, value: int):
try:
return cpuManager.set_cpuTDP(value)
except Exception as e:
logging.error(e)
logging.error(e, exc_info=True)
return False

async def set_cpuOnline(self, value: int):
try:
return cpuManager.set_cpuOnline(value)
except Exception as e:
logging.error(e)
logging.error(e, exc_info=True)
return False

async def set_smt(self, value: bool):
try:
return cpuManager.set_smt(value)
except Exception as e:
logging.error(e)
logging.error(e, exc_info=True)
return False

async def set_cpuBoost(self, value: bool):
try:
return cpuManager.set_cpuBoost(value)
except Exception as e:
logging.error(e)
logging.error(e, exc_info=True)
return False

async def set_cpuFreq(self, value: int):
try:
return cpuManager.set_cpuFreq(value)
except Exception as e:
logging.error(e)
logging.error(e, exc_info=True)
return False

async def receive_suspendEvent(self):
try:
return True
except Exception as e:
logging.error(e)
logging.error(e, exc_info=True)
return False

async def fix_gpuFreqSlider(self):
try:
return gpuManager.fix_gpuFreqSlider()
except Exception as e:
logging.error(e)
logging.error(e, exc_info=True)
return False

async def update_latest(self):
Expand All @@ -227,3 +227,17 @@ async def get_latest_version(self):

async def get_ryzenadj_info(self):
return cpuManager.get_ryzenadj_info()

async def get_max_perf_pct(self):
try:
return cpuManager.get_max_perf_pct()
except Exception as e:
logging.error(e, exc_info=True)
return 0

async def set_max_perf_pct(self, value: int):
try:
return cpuManager.set_max_perf_pct(value)
except Exception as e:
logging.error(e, exc_info=True)
return False
45 changes: 44 additions & 1 deletion src/components/cpu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,47 @@ const CPUNumComponent: VFC = () => {
);
}

const CPUPerformancePerfComponent: VFC = () => {
const [supportPerf, _] = useState<boolean>(Backend.data.getSupportCPUMaxPct());
const [maxPerf, setMaxPerf] = useState<number>(Settings.appCpuMaxPerfPct());

const refresh = () => {
setMaxPerf(Settings.appCpuMaxPerfPct());
}

useEffect(() => {
PluginManager.listenUpdateComponent(ComponentName.CPU_PERFORMANCE,
[
ComponentName.CPU_PERFORMANCE,
], (_ComponentName, updateType) => {
switch (updateType) {
case (UpdateType.UPDATE): {
refresh();
break;
}
}
})
}, []);

return (
<>
{supportPerf && <PanelSectionRow>
<SlowSliderField
label={localizationManager.getString(localizeStrEnum.CPU_MAX_PERF)}
value={maxPerf}
valueSuffix=" %"
step={1}
max={100}
min={10}
showValue={true}
onChangeEnd={(value: number) => {
Settings.setCpuMaxPerfPct(value);
}}
/>
</PanelSectionRow>}
</>
)
}

const CPUTDPComponent: VFC = () => {
const [tdpEnable, setTDPEnable] = useState<boolean>(Settings.appTDPEnable());
Expand Down Expand Up @@ -197,8 +238,9 @@ const CPUTDPComponent: VFC = () => {
</PanelSectionRow>
{tdpEnable && <PanelSectionRow>
<SlowSliderField
label={localizationManager.getString(localizeStrEnum.WATTS)}
// label={localizationManager.getString(localizeStrEnum.WATTS)}
value={tdp}
valueSuffix=" W"
step={1}
max={enableCustomTDPRange ? customTDPRangeMax : Backend.data.getTDPMax()}
min={enableCustomTDPRange ? customTDPRangeMin : 3}
Expand Down Expand Up @@ -249,6 +291,7 @@ export const CPUComponent: VFC = () => {
<CPUNumComponent />
<CPUTDPComponent />
<CustomTDPComponent />
<CPUPerformancePerfComponent />
</PanelSection>}
</div>
);
Expand Down
1 change: 1 addition & 0 deletions src/i18n/english.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"SMT_DESC":"Enable hyper-threading",
"CPU_NUM":"Number Of CPU Cores",
"CPU_NUM_DESC":"Set the enabled physical core",
"CPU_MAX_PERF":"CPU Maximum Performance",
"TDP":"Thermal Power (TDP) Limit",
"TDP_DESC":"Limits processor power for less total power",
"RYZENADJ_NOT_FOUND":"RyzenAdj Not Detected",
Expand Down
4 changes: 3 additions & 1 deletion src/i18n/localizeMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,5 +154,7 @@ export enum localizeStrEnum {
AUTO_FREQ_TDP_NOTIF = "AUTO_FREQ_TDP_NOTIF",

FORCE_SHOW_TDP = "FORCE_SHOW_TDP",
FORCE_SHOW_TDP_DESC = "FORCE_SHOW_TDP_DESC"
FORCE_SHOW_TDP_DESC = "FORCE_SHOW_TDP_DESC",

CPU_MAX_PERF = "CPU_MAX_PERF"
}
1 change: 1 addition & 0 deletions src/i18n/schinese.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"SMT_DESC":"启用同步多线程",
"CPU_NUM":"核 心 数",
"CPU_NUM_DESC":"设置启用的物理核心数量",
"CPU_MAX_PERF":"最大性能百分比",
"TDP":"热设计功耗 (TDP) 限制",
"TDP_DESC":"限制处理器功耗以降低总功耗",
"RYZENADJ_NOT_FOUND":"未检测到ryzenAdj",
Expand Down
1 change: 1 addition & 0 deletions src/i18n/tchinese.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"SMT_DESC":"啟用多執行續",
"CPU_NUM":"CPU內核數",
"CPU_NUM_DESC":"設置啟用CPU內核數量",
"CPU_MAX_PERF":"最大效能百分比",
"TDP":"散熱設計功率 (TDP) 限制",
"TDP_DESC":"限制處理器功率以降低總功率",
"RYZENADJ_NOT_FOUND":"未檢測到ryzenAdj文件",
Expand Down
Loading

0 comments on commit c0ddae3

Please sign in to comment.