Add GPU PPT power settings

This commit is contained in:
NGnius (Graham) 2022-04-29 21:16:10 -04:00
parent 891e7d82ca
commit 135d15268f
2 changed files with 137 additions and 0 deletions

12
main.py
View file

@ -77,6 +77,15 @@ class Plugin:
freq = int(freq_maybe) freq = int(freq_maybe)
return self.SCALING_FREQUENCIES.index(freq) return self.SCALING_FREQUENCIES.index(freq)
# GPU stuff
async def set_gpu_power(self, value: int, power_number: int) -> bool:
write_to_sys(gpu_power_path(power_number), value)
return True
async def get_gpu_power(self, power_number: int) -> int:
return int(read_from_sys(gpu_power_path(power_number), amount=-1).strip())
# Fan stuff # Fan stuff
async def set_fan_tick(self, tick: int): async def set_fan_tick(self, tick: int):
@ -139,6 +148,9 @@ def cpu_freq_scaling_path(cpu_number: int) -> str:
def cpu_governor_scaling_path(cpu_number: int) -> str: def cpu_governor_scaling_path(cpu_number: int) -> str:
return f"/sys/devices/system/cpu/cpu{cpu_number}/cpufreq/scaling_governor" return f"/sys/devices/system/cpu/cpu{cpu_number}/cpufreq/scaling_governor"
def gpu_power_path(power_number: int) -> str:
return f"/sys/class/hwmon/hwmon4/power{power_number}_cap"
def write_to_sys(path, value: int): def write_to_sys(path, value: int):
with open(path, mode="w") as f: with open(path, mode="w") as f:
f.write(str(value)) f.write(str(value))

View file

@ -38,6 +38,14 @@
return call_plugin_method("get_max_boost", {}); return call_plugin_method("get_max_boost", {});
} }
function setGPUPower(value, index) {
return call_plugin_method("set_gpu_power", {"value": value, "power_number": index});
}
function getGPUPower(index) {
return call_plugin_method("get_gpu_power", {"power_number": index});
}
function setFanTick(tick) { function setFanTick(tick) {
return call_plugin_method("set_fan_tick", {"tick": tick}); return call_plugin_method("set_fan_tick", {"tick": tick});
} }
@ -66,6 +74,7 @@
setToggleState(document.getElementById("smtToggle"), await getSMT()); setToggleState(document.getElementById("smtToggle"), await getSMT());
selectNotch("cpuThreadsNotch", await getCPUs() - 1, 8); selectNotch("cpuThreadsNotch", await getCPUs() - 1, 8);
selectNotch("frequencyNotch", await getMaxBoost(), 3); selectNotch("frequencyNotch", await getMaxBoost(), 3);
await onReadyGPU();
selectNotch("fanNotch", await getFanTick(), 8); selectNotch("fanNotch", await getFanTick(), 8);
await updateBatteryStats(); await updateBatteryStats();
// this is unimportant; always do it last // this is unimportant; always do it last
@ -128,6 +137,56 @@
selectNotch(ROOT_ID, index, 8); selectNotch(ROOT_ID, index, 8);
} }
async function onReadyGPU() {
let power1_cap = await getGPUPower(1);
let power2_cap = await getGPUPower(2);
if (power1_cap <= 0) {
selectNotch("slowPPTNotch", 0, 3);
document.getElementById("slowPPTAutoDefault").innerText = "Default";
} else if (power1_cap > 15000000) {
selectNotch("slowPPTNotch", 2, 3);
document.getElementById("slowPPTAutoDefault").innerText = "Default";
} else {
selectNotch("slowPPTNotch", 1, 3);
}
if (power2_cap <= 0) {
selectNotch("fastPPTNotch", 0, 3);
document.getElementById("fastPPTAutoDefault").innerText = "Default";
} else if (power2_cap > 15000000) {
selectNotch("fastPPTNotch", 2, 3);
document.getElementById("fastPPTAutoDefault").innerText = "Default";
} else {
selectNotch("fastPPTNotch", 1, 3);
}
}
async function onSetSlowPPTNotch(index) {
const ROOT_ID = "slowPPTNotch";
document.getElementById("slowPPTAutoDefault").innerText = "Default";
if (index == 0) {
await setGPUPower(0, 1);
} else if (index == 1) {
await setGPUPower(15000000, 1);
} else {
await setGPUPower(29000000, 1);
}
selectNotch(ROOT_ID, index, 3);
}
async function onSetFastPPTNotch(index) {
const ROOT_ID = "fastPPTNotch";
document.getElementById("fastPPTAutoDefault").innerText = "Default";
if (index == 0) {
await setGPUPower(0, 2);
} else if (index == 1) {
await setGPUPower(15000000, 2);
} else {
await setGPUPower(30000000, 2);
}
selectNotch(ROOT_ID, index, 3);
}
function selectNotch(rootId, index, elements) { function selectNotch(rootId, index, elements) {
// WARNING: this yeets any style in div of slider // WARNING: this yeets any style in div of slider
const ENABLED_CLASS = "gamepadslider_TickActive_j418S"; const ENABLED_CLASS = "gamepadslider_TickActive_j418S";
@ -159,6 +218,8 @@
<style type="text/css" media="screen"></style> <style type="text/css" media="screen"></style>
</head> </head>
<body onload="onReady()" style="/*margin:0px;padding:0px;*/"> <body onload="onReady()" style="/*margin:0px;padding:0px;*/">
<!-- CPU -->
<!-- SMT toggle switch, roughly copied from https://github.com/SteamDeckHomebrew/ExtraSettingsPlugin/blob/main/main_view.html --> <!-- SMT toggle switch, roughly copied from https://github.com/SteamDeckHomebrew/ExtraSettingsPlugin/blob/main/main_view.html -->
<!-- Due to a bug in MangoHud, this has been hidden for now --> <!-- Due to a bug in MangoHud, this has been hidden for now -->
<div class="quickaccessmenu_TabGroupPanel_1QO7b Panel Focusable" style="/*display:none;*/"> <div class="quickaccessmenu_TabGroupPanel_1QO7b Panel Focusable" style="/*display:none;*/">
@ -287,6 +348,70 @@
</div> </div>
</div> </div>
<!-- GPU -->
<!-- SlowPPT power limit (number 1) -->
<div class="gamepaddialog_Field_eKmEX gamepaddialog_WithFirstRow_2bDqk gamepaddialog_WithChildrenBelow_37xzV gamepaddialog_InlineWrapShiftsChildrenBelow_3LCXh gamepaddialog_WithBottomSeparator_3YKpU gamepaddialog_ChildrenWidthFixed_ljcbL gamepaddialog_ExtraPaddingOnChildrenBelow_3nLNL gamepaddialog_StandardPadding_xIITX gamepaddialog_HighlightOnFocus_2HFrm Panel Focusable">
<div class="gamepaddialog_FieldLabelRow_2VcTl">
<div class="gamepaddialog_FieldLabel_3jMlJ">GPU SlowPPT Power</div>
</div>
<div class="gamepaddialog_FieldChildren_2rhav">
<div id="slowPPTNotch" class="gamepadslider_SliderControlAndNotches_23hjX Focusable" tabindex="0" style="--normalized-slider-value:0.33;">
<div class="gamepadslider_SliderControl_1udlG">
<div class="gamepadslider_SliderTrack_2_vG6 gamepadslider_SliderHasNotches_1Lr71 "></div>
<div class="gamepadslider_SliderHandleContainer_8xNY6">
<div class="gamepadslider_SliderHandle_11PBf"></div>
</div>
</div>
<div class="gamepadslider_SliderNotchContainer_2yM7S Panel Focusable">
<div class="gamepadslider_SliderNotch_LYPXt">
<div id="slowPPTNotch0" class="gamepadslider_SliderNotchTick_u8QEa gamepadslider_TickActive_j418S" onclick='onSetSlowPPTNotch(0)'></div>
<div class="gamepadslider_SliderNotchLabel_dbACW">0</div>
</div>
<div class="gamepadslider_SliderNotch_LYPXt">
<div id="slowPPTNotch1" class="gamepadslider_SliderNotchTick_u8QEa gamepadslider_TickActive_j418S" onclick='onSetSlowPPTNotch(1)'></div>
<div class="gamepadslider_SliderNotchLabel_dbACW" id="slowPPTAutoDefault">Auto</div>
</div>
<div class="gamepadslider_SliderNotch_LYPXt">
<div id="slowPPTNotch2" class="gamepadslider_SliderNotchTick_u8QEa gamepadslider_TickActive_j418S" onclick='onSetSlowPPTNotch(2)'></div>
<div class="gamepadslider_SliderNotchLabel_dbACW">Max</div>
</div>
</div>
</div>
</div>
</div>
<!-- FastPPT power limit (number 2) -->
<div class="gamepaddialog_Field_eKmEX gamepaddialog_WithFirstRow_2bDqk gamepaddialog_WithChildrenBelow_37xzV gamepaddialog_InlineWrapShiftsChildrenBelow_3LCXh gamepaddialog_WithBottomSeparator_3YKpU gamepaddialog_ChildrenWidthFixed_ljcbL gamepaddialog_ExtraPaddingOnChildrenBelow_3nLNL gamepaddialog_StandardPadding_xIITX gamepaddialog_HighlightOnFocus_2HFrm Panel Focusable">
<div class="gamepaddialog_FieldLabelRow_2VcTl">
<div class="gamepaddialog_FieldLabel_3jMlJ">GPU FastPPT Power</div>
</div>
<div class="gamepaddialog_FieldChildren_2rhav">
<div id="fastPPTNotch" class="gamepadslider_SliderControlAndNotches_23hjX Focusable" tabindex="0" style="--normalized-slider-value:0.33;">
<div class="gamepadslider_SliderControl_1udlG">
<div class="gamepadslider_SliderTrack_2_vG6 gamepadslider_SliderHasNotches_1Lr71 "></div>
<div class="gamepadslider_SliderHandleContainer_8xNY6">
<div class="gamepadslider_SliderHandle_11PBf"></div>
</div>
</div>
<div class="gamepadslider_SliderNotchContainer_2yM7S Panel Focusable">
<div class="gamepadslider_SliderNotch_LYPXt">
<div id="fastPPTNotch0" class="gamepadslider_SliderNotchTick_u8QEa gamepadslider_TickActive_j418S" onclick='onSetFastPPTNotch(0)'></div>
<div class="gamepadslider_SliderNotchLabel_dbACW">0</div>
</div>
<div class="gamepadslider_SliderNotch_LYPXt">
<div id="fastPPTNotch1" class="gamepadslider_SliderNotchTick_u8QEa gamepadslider_TickActive_j418S" onclick='onSetFastPPTNotch(1)'></div>
<div class="gamepadslider_SliderNotchLabel_dbACW" id="fastPPTAutoDefault">Auto</div>
</div>
<div class="gamepadslider_SliderNotch_LYPXt">
<div id="fastPPTNotch2" class="gamepadslider_SliderNotchTick_u8QEa gamepadslider_TickActive_j418S" onclick='onSetFastPPTNotch(2)'></div>
<div class="gamepadslider_SliderNotchLabel_dbACW">Max</div>
</div>
</div>
</div>
</div>
</div>
<!-- Fan RPM selector --> <!-- Fan RPM selector -->
<!-- TODO: Make this non-notched slider when PluginLoader PR#41 is merged --> <!-- TODO: Make this non-notched slider when PluginLoader PR#41 is merged -->
<div class="gamepaddialog_Field_eKmEX gamepaddialog_WithFirstRow_2bDqk gamepaddialog_WithChildrenBelow_37xzV gamepaddialog_InlineWrapShiftsChildrenBelow_3LCXh gamepaddialog_WithBottomSeparator_3YKpU gamepaddialog_ChildrenWidthFixed_ljcbL gamepaddialog_ExtraPaddingOnChildrenBelow_3nLNL gamepaddialog_StandardPadding_xIITX gamepaddialog_HighlightOnFocus_2HFrm Panel Focusable"> <div class="gamepaddialog_Field_eKmEX gamepaddialog_WithFirstRow_2bDqk gamepaddialog_WithChildrenBelow_37xzV gamepaddialog_InlineWrapShiftsChildrenBelow_3LCXh gamepaddialog_WithBottomSeparator_3YKpU gamepaddialog_ChildrenWidthFixed_ljcbL gamepaddialog_ExtraPaddingOnChildrenBelow_3nLNL gamepaddialog_StandardPadding_xIITX gamepaddialog_HighlightOnFocus_2HFrm Panel Focusable">