From 48ec9f518feaadf5ac9e84e71d29b8ba9bdfc84d Mon Sep 17 00:00:00 2001 From: "NGnius (Graham)" Date: Mon, 5 Feb 2024 17:45:35 -0500 Subject: [PATCH] Add on_load and on_unload traits, reduce impact of #123 --- backend/limits_srv/pt_limits_v2.json | 1261 +++++++++++++++++--- backend/src/api/handler.rs | 28 +- backend/src/settings/dev_mode/battery.rs | 14 + backend/src/settings/dev_mode/cpu.rs | 14 + backend/src/settings/dev_mode/gpu.rs | 14 + backend/src/settings/general.rs | 68 +- backend/src/settings/generic/battery.rs | 12 + backend/src/settings/generic/cpu.rs | 16 + backend/src/settings/generic/gpu.rs | 12 + backend/src/settings/generic_amd/cpu.rs | 12 + backend/src/settings/generic_amd/gpu.rs | 12 + backend/src/settings/mod.rs | 4 +- backend/src/settings/steam_deck/battery.rs | 12 + backend/src/settings/steam_deck/cpu.rs | 71 +- backend/src/settings/steam_deck/gpu.rs | 12 + backend/src/settings/traits.rs | 16 +- backend/src/settings/unknown/battery.rs | 12 + backend/src/settings/unknown/cpu.rs | 12 + backend/src/settings/unknown/gpu.rs | 12 + 19 files changed, 1416 insertions(+), 198 deletions(-) diff --git a/backend/limits_srv/pt_limits_v2.json b/backend/limits_srv/pt_limits_v2.json index 0196b5d..a0fc84e 100644 --- a/backend/limits_srv/pt_limits_v2.json +++ b/backend/limits_srv/pt_limits_v2.json @@ -1,155 +1,336 @@ { "configs": [ { - "name": "Steam Deck Custom", + "name": "Devs mode best mode", "conditions": { "dmi": null, - "cpuinfo": "model name\t: AMD Custom APU (0405)|(0932)\n", + "cpuinfo": null, "os": null, "command": null, - "file_exists": "./limits_override.json" + "file_exists": "/etc/powertools_dev_mode" }, "limits": { "cpu": { - "provider": "GabeBoyAdvance", + "provider": "DevMode", "limits": { "cpus": [ { "clock_min": { - "min": 1400, - "max": 3500 + "min": 100, + "max": 5000 }, "clock_max": { - "min": 400, - "max": 3500 + "min": 100, + "max": 4800 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": { + "min": 1000000, + "max": 100000000 + }, + "tdp_boost": { + "min": 1000000, + "max": 110000000 + }, + "tdp_divisor": 1000000, + "tdp_step": 1, + "skip_resume_reclock": false, + "experiments": true }, { "clock_min": { - "min": 1400, - "max": 3500 + "min": 100, + "max": 5000 }, "clock_max": { - "min": 400, - "max": 3500 + "min": 100, + "max": 4800 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": { + "min": 1000000, + "max": 100000000 + }, + "tdp_boost": { + "min": 1000000, + "max": 110000000 + }, + "tdp_divisor": 1000000, + "tdp_step": 1, + "skip_resume_reclock": false, + "experiments": true }, { "clock_min": { - "min": 1400, - "max": 3500 + "min": 100, + "max": 5000 }, "clock_max": { - "min": 400, - "max": 3500 + "min": 100, + "max": 4800 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": { + "min": 1000000, + "max": 100000000 + }, + "tdp_boost": { + "min": 1000000, + "max": 110000000 + }, + "tdp_divisor": 1000000, + "tdp_step": 1, + "skip_resume_reclock": false, + "experiments": true }, { "clock_min": { - "min": 1400, - "max": 3500 + "min": 100, + "max": 5000 }, "clock_max": { - "min": 400, - "max": 3500 + "min": 100, + "max": 4800 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": { + "min": 1000000, + "max": 100000000 + }, + "tdp_boost": { + "min": 1000000, + "max": 110000000 + }, + "tdp_divisor": 1000000, + "tdp_step": 1, + "skip_resume_reclock": false, + "experiments": true }, { "clock_min": { - "min": 1400, - "max": 3500 + "min": 100, + "max": 5000 }, "clock_max": { - "min": 400, - "max": 3500 + "min": 100, + "max": 4800 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": { + "min": 1000000, + "max": 100000000 + }, + "tdp_boost": { + "min": 1000000, + "max": 110000000 + }, + "tdp_divisor": 1000000, + "tdp_step": 1, + "skip_resume_reclock": false, + "experiments": true }, { "clock_min": { - "min": 1400, - "max": 3500 + "min": 100, + "max": 5000 }, "clock_max": { - "min": 400, - "max": 3500 + "min": 100, + "max": 4800 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": { + "min": 1000000, + "max": 100000000 + }, + "tdp_boost": { + "min": 1000000, + "max": 110000000 + }, + "tdp_divisor": 1000000, + "tdp_step": 1, + "skip_resume_reclock": false, + "experiments": true }, { "clock_min": { - "min": 1400, - "max": 3500 + "min": 100, + "max": 5000 }, "clock_max": { - "min": 400, - "max": 3500 + "min": 100, + "max": 4800 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": { + "min": 1000000, + "max": 100000000 + }, + "tdp_boost": { + "min": 1000000, + "max": 110000000 + }, + "tdp_divisor": 1000000, + "tdp_step": 1, + "skip_resume_reclock": false, + "experiments": true }, { "clock_min": { - "min": 1400, - "max": 3500 + "min": 100, + "max": 5000 }, "clock_max": { - "min": 400, - "max": 3500 + "min": 100, + "max": 4800 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": { + "min": 1000000, + "max": 100000000 + }, + "tdp_boost": { + "min": 1000000, + "max": 110000000 + }, + "tdp_divisor": 1000000, + "tdp_step": 1, + "skip_resume_reclock": false, + "experiments": true + }, + { + "clock_min": { + "min": 100, + "max": 5000 + }, + "clock_max": { + "min": 100, + "max": 4800 + }, + "clock_step": 100, + "tdp": { + "min": 1000000, + "max": 100000000 + }, + "tdp_boost": { + "min": 1000000, + "max": 110000000 + }, + "tdp_divisor": 1000000, + "tdp_step": 1, + "skip_resume_reclock": false, + "experiments": true + }, + { + "clock_min": { + "min": 100, + "max": 5000 + }, + "clock_max": { + "min": 100, + "max": 4800 + }, + "clock_step": 100, + "tdp": { + "min": 1000000, + "max": 100000000 + }, + "tdp_boost": { + "min": 1000000, + "max": 110000000 + }, + "tdp_divisor": 1000000, + "tdp_step": 1, + "skip_resume_reclock": false, + "experiments": true + }, + { + "clock_min": { + "min": 100, + "max": 5000 + }, + "clock_max": { + "min": 100, + "max": 4800 + }, + "clock_step": 100, + "tdp": { + "min": 1000000, + "max": 100000000 + }, + "tdp_boost": { + "min": 1000000, + "max": 110000000 + }, + "tdp_divisor": 1000000, + "tdp_step": 1, + "skip_resume_reclock": false, + "experiments": true } ], - "global_governors": true + "global_governors": true, + "extras": { + "experiments": true, + "quirks": [ + "" + ] + } } }, "gpu": { - "provider": "GabeBoyAdvance", + "provider": "DevMode", "limits": { "fast_ppt": { - "min": 1000000, - "max": 30000000 + "min": 3000000, + "max": 11000000 }, - "fast_ppt_default": 15000000, + "fast_ppt_default": 10000000, "slow_ppt": { - "min": 1000000, - "max": 29000000 + "min": 7000000, + "max": 11000000 }, - "slow_ppt_default": 15000000, + "slow_ppt_default": 10000000, "ppt_divisor": 1000000, "ppt_step": 1, - "tdp": null, - "tdp_boost": null, - "tdp_step": null, + "tdp": { + "min": 1000000, + "max": 100000000 + }, + "tdp_boost": { + "min": 1000000, + "max": 110000000 + }, + "tdp_divisor": 1000000, + "tdp_step": 1, "clock_min": { - "min": 400, - "max": 1600 + "min": 100, + "max": 1000 }, "clock_max": { - "min": 400, - "max": 1600 + "min": 100, + "max": 1100 }, "clock_step": 100, - "skip_resume_reclock": false + "memory_clock": { + "min": 100, + "max": 1100 + }, + "memory_clock_step": 100, + "skip_resume_reclock": false, + "extras": { + "experiments": true, + "quirks": [ + "dev" + ] + } } }, "battery": { - "provider": "GabeBoyAdvance", + "provider": "DevMode", "limits": { "charge_rate": { - "min": 250, - "max": 2500 + "min": 0, + "max": 1000 }, "charge_modes": [ "normal", @@ -157,10 +338,16 @@ "idle" ], "charge_limit": { - "min": 10.0, - "max": 90.0 + "min": 1.0, + "max": 99.0 }, - "extra_readouts": false + "extra_readouts": true, + "extras": { + "experiments": true, + "quirks": [ + "" + ] + } } } } @@ -169,7 +356,7 @@ "name": "Steam Deck", "conditions": { "dmi": null, - "cpuinfo": "model name\t: AMD Custom APU (0405)|(0932)\n", + "cpuinfo": "model name\t: AMD Custom APU 0405\n", "os": null, "command": null, "file_exists": null @@ -189,7 +376,12 @@ "max": 3500 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": { @@ -201,7 +393,12 @@ "max": 3500 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": { @@ -213,7 +410,12 @@ "max": 3500 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": { @@ -225,7 +427,12 @@ "max": 3500 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": { @@ -237,7 +444,12 @@ "max": 3500 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": { @@ -249,7 +461,12 @@ "max": 3500 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": { @@ -261,7 +478,12 @@ "max": 3500 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": { @@ -273,10 +495,19 @@ "max": 3500 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false } ], - "global_governors": true + "global_governors": true, + "extras": { + "experiments": false, + "quirks": [] + } } }, "gpu": { @@ -296,6 +527,7 @@ "ppt_step": 1, "tdp": null, "tdp_boost": null, + "tdp_divisor": null, "tdp_step": null, "clock_min": { "min": 400, @@ -306,7 +538,19 @@ "max": 1600 }, "clock_step": 100, - "skip_resume_reclock": false + "memory_clock": { + "min": 400, + "max": 800 + }, + "memory_clock_step": 400, + "skip_resume_reclock": false, + "extras": { + "experiments": false, + "quirks": [ + "pp_dpm_fclk-reversed", + "pp_dpm_fclk-not-updated-on-LCD" + ] + } } }, "battery": { @@ -325,7 +569,237 @@ "min": 10.0, "max": 90.0 }, - "extra_readouts": false + "extra_readouts": false, + "extras": { + "experiments": false, + "quirks": [] + } + } + } + } + }, + { + "name": "Steam Deck OLED", + "conditions": { + "dmi": null, + "cpuinfo": "model name\t: AMD Custom APU 0932\n", + "os": null, + "command": null, + "file_exists": null + }, + "limits": { + "cpu": { + "provider": "GabeBoy", + "limits": { + "cpus": [ + { + "clock_min": { + "min": 1400, + "max": 3500 + }, + "clock_max": { + "min": 400, + "max": 3500 + }, + "clock_step": 100, + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false + }, + { + "clock_min": { + "min": 1400, + "max": 3500 + }, + "clock_max": { + "min": 400, + "max": 3500 + }, + "clock_step": 100, + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false + }, + { + "clock_min": { + "min": 1400, + "max": 3500 + }, + "clock_max": { + "min": 400, + "max": 3500 + }, + "clock_step": 100, + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false + }, + { + "clock_min": { + "min": 1400, + "max": 3500 + }, + "clock_max": { + "min": 400, + "max": 3500 + }, + "clock_step": 100, + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false + }, + { + "clock_min": { + "min": 1400, + "max": 3500 + }, + "clock_max": { + "min": 400, + "max": 3500 + }, + "clock_step": 100, + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false + }, + { + "clock_min": { + "min": 1400, + "max": 3500 + }, + "clock_max": { + "min": 400, + "max": 3500 + }, + "clock_step": 100, + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false + }, + { + "clock_min": { + "min": 1400, + "max": 3500 + }, + "clock_max": { + "min": 400, + "max": 3500 + }, + "clock_step": 100, + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false + }, + { + "clock_min": { + "min": 1400, + "max": 3500 + }, + "clock_max": { + "min": 400, + "max": 3500 + }, + "clock_step": 100, + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false + } + ], + "global_governors": true, + "extras": { + "experiments": false, + "quirks": [] + } + } + }, + "gpu": { + "provider": "GabeBoy", + "limits": { + "fast_ppt": { + "min": 1000000, + "max": 30000000 + }, + "fast_ppt_default": 15000000, + "slow_ppt": { + "min": 1000000, + "max": 29000000 + }, + "slow_ppt_default": 15000000, + "ppt_divisor": 1000000, + "ppt_step": 1, + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "clock_min": { + "min": 400, + "max": 1600 + }, + "clock_max": { + "min": 400, + "max": 1600 + }, + "clock_step": 100, + "memory_clock": { + "min": 400, + "max": 800 + }, + "memory_clock_step": 200, + "skip_resume_reclock": false, + "extras": { + "experiments": false, + "quirks": [ + "pp_dpm_fclk-reversed", + "pp_dpm_fclk-not-updated-on-LCD" + ] + } + } + }, + "battery": { + "provider": "GabeBoy", + "limits": { + "charge_rate": { + "min": 250, + "max": 2500 + }, + "charge_modes": [ + "normal", + "discharge", + "idle" + ], + "charge_limit": { + "min": 10.0, + "max": 90.0 + }, + "extra_readouts": false, + "extras": { + "experiments": false, + "quirks": [] + } } } } @@ -354,7 +828,12 @@ "max": 3700 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": { @@ -366,7 +845,12 @@ "max": 3700 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": { @@ -378,7 +862,12 @@ "max": 3700 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": { @@ -390,10 +879,19 @@ "max": 3700 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false } ], - "global_governors": true + "global_governors": true, + "extras": { + "experiments": false, + "quirks": [] + } } }, "gpu": { @@ -413,6 +911,7 @@ "ppt_step": 1000, "tdp": null, "tdp_boost": null, + "tdp_divisor": null, "tdp_step": null, "clock_min": { "min": 400, @@ -423,7 +922,13 @@ "max": 1100 }, "clock_step": 100, - "skip_resume_reclock": false + "memory_clock": null, + "memory_clock_step": null, + "skip_resume_reclock": false, + "extras": { + "experiments": false, + "quirks": [] + } } }, "battery": { @@ -432,7 +937,11 @@ "charge_rate": null, "charge_modes": [], "charge_limit": null, - "extra_readouts": false + "extra_readouts": false, + "extras": { + "experiments": false, + "quirks": [] + } } } } @@ -461,7 +970,12 @@ "max": 4000 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": { @@ -473,7 +987,12 @@ "max": 4000 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": { @@ -485,7 +1004,12 @@ "max": 4000 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": { @@ -497,7 +1021,12 @@ "max": 4000 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": { @@ -509,7 +1038,12 @@ "max": 4000 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": { @@ -521,7 +1055,12 @@ "max": 4000 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": { @@ -533,7 +1072,12 @@ "max": 4000 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": { @@ -545,7 +1089,12 @@ "max": 4000 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": { @@ -557,7 +1106,12 @@ "max": 4000 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": { @@ -569,7 +1123,12 @@ "max": 4000 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": { @@ -581,7 +1140,12 @@ "max": 4000 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": { @@ -593,10 +1157,19 @@ "max": 4000 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false } ], - "global_governors": true + "global_governors": true, + "extras": { + "experiments": false, + "quirks": [] + } } }, "gpu": { @@ -616,6 +1189,7 @@ "ppt_step": 1000, "tdp": null, "tdp_boost": null, + "tdp_divisor": null, "tdp_step": null, "clock_min": { "min": 400, @@ -626,7 +1200,13 @@ "max": 1600 }, "clock_step": 100, - "skip_resume_reclock": false + "memory_clock": null, + "memory_clock_step": null, + "skip_resume_reclock": false, + "extras": { + "experiments": false, + "quirks": [] + } } }, "battery": { @@ -635,7 +1215,11 @@ "charge_rate": null, "charge_modes": [], "charge_limit": null, - "extra_readouts": false + "extra_readouts": false, + "extras": { + "experiments": false, + "quirks": [] + } } } } @@ -664,7 +1248,12 @@ "max": 4500 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": { @@ -676,7 +1265,12 @@ "max": 4500 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": { @@ -688,7 +1282,12 @@ "max": 4500 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": { @@ -700,7 +1299,12 @@ "max": 4500 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": { @@ -712,7 +1316,12 @@ "max": 4500 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": { @@ -724,7 +1333,12 @@ "max": 4500 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": { @@ -736,7 +1350,12 @@ "max": 4500 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": { @@ -748,7 +1367,12 @@ "max": 4500 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": { @@ -760,7 +1384,12 @@ "max": 4500 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": { @@ -772,7 +1401,12 @@ "max": 4500 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": { @@ -784,7 +1418,12 @@ "max": 4500 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": { @@ -796,7 +1435,12 @@ "max": 4500 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": { @@ -808,7 +1452,12 @@ "max": 4500 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": { @@ -820,7 +1469,12 @@ "max": 4500 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": { @@ -832,7 +1486,12 @@ "max": 4500 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": { @@ -844,10 +1503,19 @@ "max": 4500 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false } ], - "global_governors": true + "global_governors": true, + "extras": { + "experiments": false, + "quirks": [] + } } }, "gpu": { @@ -867,6 +1535,7 @@ "ppt_step": 1000, "tdp": null, "tdp_boost": null, + "tdp_divisor": null, "tdp_step": null, "clock_min": { "min": 400, @@ -877,7 +1546,13 @@ "max": 2200 }, "clock_step": 100, - "skip_resume_reclock": false + "memory_clock": null, + "memory_clock_step": null, + "skip_resume_reclock": false, + "extras": { + "experiments": false, + "quirks": [] + } } }, "battery": { @@ -886,7 +1561,11 @@ "charge_rate": null, "charge_modes": [], "charge_limit": null, - "extra_readouts": false + "extra_readouts": false, + "extras": { + "experiments": false, + "quirks": [] + } } } } @@ -915,7 +1594,12 @@ "max": 4700 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": { @@ -927,7 +1611,12 @@ "max": 4700 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": { @@ -939,7 +1628,12 @@ "max": 4700 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": { @@ -951,7 +1645,12 @@ "max": 4700 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": { @@ -963,7 +1662,12 @@ "max": 4700 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": { @@ -975,7 +1679,12 @@ "max": 4700 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": { @@ -987,7 +1696,12 @@ "max": 4700 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": { @@ -999,7 +1713,12 @@ "max": 4700 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": { @@ -1011,7 +1730,12 @@ "max": 4700 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": { @@ -1023,7 +1747,12 @@ "max": 4700 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": { @@ -1035,7 +1764,12 @@ "max": 4700 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": { @@ -1047,7 +1781,12 @@ "max": 4700 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": { @@ -1059,7 +1798,12 @@ "max": 4700 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": { @@ -1071,7 +1815,12 @@ "max": 4700 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": { @@ -1083,7 +1832,12 @@ "max": 4700 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": { @@ -1095,10 +1849,19 @@ "max": 4700 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false } ], - "global_governors": true + "global_governors": true, + "extras": { + "experiments": false, + "quirks": [] + } } }, "gpu": { @@ -1118,6 +1881,7 @@ "ppt_step": 1000, "tdp": null, "tdp_boost": null, + "tdp_divisor": null, "tdp_step": null, "clock_min": { "min": 400, @@ -1128,7 +1892,13 @@ "max": 2200 }, "clock_step": 100, - "skip_resume_reclock": false + "memory_clock": null, + "memory_clock_step": null, + "skip_resume_reclock": false, + "extras": { + "experiments": false, + "quirks": [] + } } }, "battery": { @@ -1137,7 +1907,11 @@ "charge_rate": null, "charge_modes": [], "charge_limit": null, - "extra_readouts": false + "extra_readouts": false, + "extras": { + "experiments": false, + "quirks": [] + } } } } @@ -1166,7 +1940,12 @@ "max": 5100 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": { @@ -1178,7 +1957,12 @@ "max": 5100 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": { @@ -1190,7 +1974,12 @@ "max": 5100 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": { @@ -1202,7 +1991,12 @@ "max": 5100 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": { @@ -1214,7 +2008,12 @@ "max": 5100 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": { @@ -1226,7 +2025,12 @@ "max": 5100 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": { @@ -1238,7 +2042,12 @@ "max": 5100 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": { @@ -1250,7 +2059,12 @@ "max": 5100 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": { @@ -1262,7 +2076,12 @@ "max": 5100 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": { @@ -1274,7 +2093,12 @@ "max": 5100 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": { @@ -1286,7 +2110,12 @@ "max": 5100 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": { @@ -1298,7 +2127,12 @@ "max": 5100 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": { @@ -1310,7 +2144,12 @@ "max": 5100 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": { @@ -1322,7 +2161,12 @@ "max": 5100 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": { @@ -1334,7 +2178,12 @@ "max": 5100 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": { @@ -1346,10 +2195,19 @@ "max": 5100 }, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false } ], - "global_governors": true + "global_governors": true, + "extras": { + "experiments": false, + "quirks": [] + } } }, "gpu": { @@ -1369,11 +2227,18 @@ "ppt_step": 1000, "tdp": null, "tdp_boost": null, + "tdp_divisor": null, "tdp_step": null, "clock_min": null, "clock_max": null, "clock_step": null, - "skip_resume_reclock": false + "memory_clock": null, + "memory_clock_step": null, + "skip_resume_reclock": false, + "extras": { + "experiments": false, + "quirks": [] + } } }, "battery": { @@ -1382,7 +2247,11 @@ "charge_rate": null, "charge_modes": [], "charge_limit": null, - "extra_readouts": false + "extra_readouts": false, + "extras": { + "experiments": false, + "quirks": [] + } } } } @@ -1405,52 +2274,96 @@ "clock_min": null, "clock_max": null, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": null, "clock_max": null, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": null, "clock_max": null, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": null, "clock_max": null, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": null, "clock_max": null, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": null, "clock_max": null, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": null, "clock_max": null, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false }, { "clock_min": null, "clock_max": null, "clock_step": 100, - "skip_resume_reclock": false + "tdp": null, + "tdp_boost": null, + "tdp_divisor": null, + "tdp_step": null, + "skip_resume_reclock": false, + "experiments": false } ], - "global_governors": true + "global_governors": true, + "extras": { + "experiments": false, + "quirks": [] + } } }, "gpu": { @@ -1464,11 +2377,18 @@ "ppt_step": null, "tdp": null, "tdp_boost": null, + "tdp_divisor": null, "tdp_step": null, "clock_min": null, "clock_max": null, "clock_step": null, - "skip_resume_reclock": false + "memory_clock": null, + "memory_clock_step": null, + "skip_resume_reclock": false, + "extras": { + "experiments": false, + "quirks": [] + } } }, "battery": { @@ -1477,7 +2397,11 @@ "charge_rate": null, "charge_modes": [], "charge_limit": null, - "extra_readouts": false + "extra_readouts": false, + "extras": { + "experiments": false, + "quirks": [] + } } } } @@ -1491,5 +2415,6 @@ "url": "https://git.ngni.us/NG-SD-Plugins/PowerTools/wiki" } ], + "store": "https://powertools.ngni.us", "refresh": "http://limits.ngni.us:45000/powertools/v2" } \ No newline at end of file diff --git a/backend/src/api/handler.rs b/backend/src/api/handler.rs index 194b179..5058eab 100644 --- a/backend/src/api/handler.rs +++ b/backend/src/api/handler.rs @@ -3,7 +3,8 @@ use std::sync::mpsc::{self, Receiver, Sender}; use crate::persist::SettingsJson; use crate::settings::{ - MinMax, OnPowerEvent, OnResume, OnSet, PowerMode, Settings, TBattery, TCpus, TGeneral, TGpu, + MinMax, OnLoad, OnPowerEvent, OnResume, OnSet, OnUnload, PowerMode, Settings, TBattery, TCpus, + TGeneral, TGpu, }; type Callback = Box; @@ -401,13 +402,22 @@ impl ApiMessageHandler { } ApiMessage::LoadSettings(id, name, variant_id, variant_name) => { let path = format!("{}.ron", id); + if let Err(e) = settings.on_unload() { + print_errors("LoadSettings on_unload()", e); + } match settings.load_file(path.into(), id, name, variant_id, variant_name, false) { Ok(success) => log::info!("Loaded settings file? {}", success), Err(e) => log::warn!("Load file err: {}", e), } + if let Err(e) = settings.on_load() { + print_errors("LoadSettings on_load()", e); + } true } ApiMessage::LoadVariant(variant_id, variant_name) => { + if let Err(e) = settings.on_unload() { + print_errors("LoadVariant on_unload()", e); + } let path = settings.general.get_path(); let app_id = settings.general.get_app_id(); match settings.load_file( @@ -421,9 +431,15 @@ impl ApiMessageHandler { Ok(success) => log::info!("Loaded variant settings file? {}", success), Err(e) => log::warn!("Load file err: {}", e), } + if let Err(e) = settings.on_load() { + print_errors("LoadVariant on_load()", e); + } true } ApiMessage::LoadMainSettings => { + if let Err(e) = settings.on_unload() { + print_errors("LoadMainSettings on_unload()", e); + } match settings.load_file( crate::consts::DEFAULT_SETTINGS_FILE.into(), 0, @@ -435,14 +451,23 @@ impl ApiMessageHandler { Ok(success) => log::info!("Loaded main settings file? {}", success), Err(e) => log::warn!("Load file err: {}", e), } + if let Err(e) = settings.on_load() { + print_errors("LoadMainSettings on_load()", e); + } true } ApiMessage::LoadSystemSettings => { + if let Err(e) = settings.on_unload() { + print_errors("LoadSystemSettings on_unload()", e); + } settings.load_system_default( settings.general.get_name().to_owned(), settings.general.get_variant_id(), settings.general.get_variant_info().name, ); + if let Err(e) = settings.on_load() { + print_errors("LoadSystemSettings on_load()", e); + } true } ApiMessage::GetLimits(cb) => { @@ -464,7 +489,6 @@ impl ApiMessageHandler { false } ApiMessage::UploadCurrentVariant(steam_id, steam_username) => { - //TODO let steam_app_id = settings.general.get_app_id(); super::web::upload_settings( steam_app_id, diff --git a/backend/src/settings/dev_mode/battery.rs b/backend/src/settings/dev_mode/battery.rs index a57e736..a0fe208 100644 --- a/backend/src/settings/dev_mode/battery.rs +++ b/backend/src/settings/dev_mode/battery.rs @@ -76,6 +76,20 @@ impl OnResume for Battery { impl crate::settings::OnPowerEvent for Battery {} +impl crate::settings::OnLoad for Battery { + fn on_load(&mut self) -> Result<(), Vec> { + log::debug!("dev_mode_Battery::on_load(self)"); + Ok(()) + } +} + +impl crate::settings::OnUnload for Battery { + fn on_unload(&mut self) -> Result<(), Vec> { + log::debug!("dev_mode_Battery::on_unload(self)"); + Ok(()) + } +} + impl TBattery for Battery { fn limits(&self) -> crate::api::BatteryLimits { log::debug!("dev_mode_Battery::limits(self) -> {{...}}"); diff --git a/backend/src/settings/dev_mode/cpu.rs b/backend/src/settings/dev_mode/cpu.rs index a505b69..059aaa8 100644 --- a/backend/src/settings/dev_mode/cpu.rs +++ b/backend/src/settings/dev_mode/cpu.rs @@ -39,6 +39,20 @@ impl OnResume for Cpus { impl crate::settings::OnPowerEvent for Cpus {} +impl crate::settings::OnLoad for Cpus { + fn on_load(&mut self) -> Result<(), Vec> { + log::debug!("dev_mode_Cpus::on_load(self)"); + Ok(()) + } +} + +impl crate::settings::OnUnload for Cpus { + fn on_unload(&mut self) -> Result<(), Vec> { + log::debug!("dev_mode_Cpus::on_unload(self)"); + Ok(()) + } +} + impl ProviderBuilder, GenericCpusLimit> for Cpus { fn from_json_and_limits( persistent: Vec, diff --git a/backend/src/settings/dev_mode/gpu.rs b/backend/src/settings/dev_mode/gpu.rs index 919d905..c6605a2 100644 --- a/backend/src/settings/dev_mode/gpu.rs +++ b/backend/src/settings/dev_mode/gpu.rs @@ -80,6 +80,20 @@ impl OnResume for Gpu { impl crate::settings::OnPowerEvent for Gpu {} +impl crate::settings::OnLoad for Gpu { + fn on_load(&mut self) -> Result<(), Vec> { + log::debug!("dev_mode_Gpu::on_load(self)"); + Ok(()) + } +} + +impl crate::settings::OnUnload for Gpu { + fn on_unload(&mut self) -> Result<(), Vec> { + log::debug!("dev_mode_Gpu::on_unload(self)"); + Ok(()) + } +} + impl TGpu for Gpu { fn limits(&self) -> crate::api::GpuLimits { log::debug!("dev_mode_Gpu::limits(self) -> {{...}}"); diff --git a/backend/src/settings/general.rs b/backend/src/settings/general.rs index 2a75eae..1cc1a33 100644 --- a/backend/src/settings/general.rs +++ b/backend/src/settings/general.rs @@ -2,7 +2,7 @@ use std::path::PathBuf; //use std::sync::{Arc, Mutex}; //use super::{Battery, Cpus, Gpu}; -use super::{OnResume, OnSet, SettingError}; +use super::{OnLoad, OnPowerEvent, OnResume, OnSet, OnUnload, SettingError}; use super::{TBattery, TCpus, TGeneral, TGpu}; use crate::persist::{FileJson, SettingsJson}; //use crate::utility::unwrap_lock; @@ -51,7 +51,19 @@ impl OnResume for General { } } -impl crate::settings::OnPowerEvent for General {} +impl OnPowerEvent for General {} + +impl OnLoad for General { + fn on_load(&mut self) -> Result<(), Vec> { + Ok(()) + } +} + +impl OnUnload for General { + fn on_unload(&mut self) -> Result<(), Vec> { + Ok(()) + } +} impl TGeneral for General { fn limits(&self) -> crate::api::GeneralLimits { @@ -461,7 +473,7 @@ impl OnResume for Settings { } } -impl crate::settings::OnPowerEvent for Settings { +impl OnPowerEvent for Settings { fn on_power_event(&mut self, new_mode: super::PowerMode) -> Result<(), Vec> { let mut errors = Vec::new(); @@ -486,6 +498,56 @@ impl crate::settings::OnPowerEvent for Settings { } } +impl OnLoad for Settings { + fn on_load(&mut self) -> Result<(), Vec> { + let mut errors = Vec::new(); + + self.general + .on_load() + .unwrap_or_else(|mut e| errors.append(&mut e)); + self.battery + .on_load() + .unwrap_or_else(|mut e| errors.append(&mut e)); + self.cpus + .on_load() + .unwrap_or_else(|mut e| errors.append(&mut e)); + self.gpu + .on_load() + .unwrap_or_else(|mut e| errors.append(&mut e)); + + if errors.is_empty() { + Ok(()) + } else { + Err(errors) + } + } +} + +impl OnUnload for Settings { + fn on_unload(&mut self) -> Result<(), Vec> { + let mut errors = Vec::new(); + + self.general + .on_unload() + .unwrap_or_else(|mut e| errors.append(&mut e)); + self.battery + .on_unload() + .unwrap_or_else(|mut e| errors.append(&mut e)); + self.cpus + .on_unload() + .unwrap_or_else(|mut e| errors.append(&mut e)); + self.gpu + .on_unload() + .unwrap_or_else(|mut e| errors.append(&mut e)); + + if errors.is_empty() { + Ok(()) + } else { + Err(errors) + } + } +} + /*impl Into for Settings { #[inline] fn into(self) -> SettingsJson { diff --git a/backend/src/settings/generic/battery.rs b/backend/src/settings/generic/battery.rs index cfe201a..a046412 100644 --- a/backend/src/settings/generic/battery.rs +++ b/backend/src/settings/generic/battery.rs @@ -132,6 +132,18 @@ impl OnResume for Battery { impl crate::settings::OnPowerEvent for Battery {} +impl crate::settings::OnLoad for Battery { + fn on_load(&mut self) -> Result<(), Vec> { + Ok(()) + } +} + +impl crate::settings::OnUnload for Battery { + fn on_unload(&mut self) -> Result<(), Vec> { + Ok(()) + } +} + impl TBattery for Battery { fn limits(&self) -> crate::api::BatteryLimits { crate::api::BatteryLimits { diff --git a/backend/src/settings/generic/cpu.rs b/backend/src/settings/generic/cpu.rs index 0083028..6142f62 100644 --- a/backend/src/settings/generic/cpu.rs +++ b/backend/src/settings/generic/cpu.rs @@ -176,6 +176,22 @@ impl + AsRef + TCpu + crate::settings::OnPowerEvent> } } +impl + AsRef + TCpu + OnResume + OnSet + crate::settings::OnPowerEvent> + crate::settings::OnLoad for Cpus +{ + fn on_load(&mut self) -> Result<(), Vec> { + Ok(()) + } +} + +impl + AsRef + TCpu + OnResume + OnSet + crate::settings::OnPowerEvent> + crate::settings::OnUnload for Cpus +{ + fn on_unload(&mut self) -> Result<(), Vec> { + Ok(()) + } +} + impl + AsRef + TCpu + OnResume + OnSet + crate::settings::OnPowerEvent> TCpus for Cpus { diff --git a/backend/src/settings/generic/gpu.rs b/backend/src/settings/generic/gpu.rs index 1cc61db..a96bae8 100644 --- a/backend/src/settings/generic/gpu.rs +++ b/backend/src/settings/generic/gpu.rs @@ -138,6 +138,18 @@ impl OnResume for Gpu { impl crate::settings::OnPowerEvent for Gpu {} +impl crate::settings::OnLoad for Gpu { + fn on_load(&mut self) -> Result<(), Vec> { + Ok(()) + } +} + +impl crate::settings::OnUnload for Gpu { + fn on_unload(&mut self) -> Result<(), Vec> { + Ok(()) + } +} + impl TGpu for Gpu { fn limits(&self) -> crate::api::GpuLimits { crate::api::GpuLimits { diff --git a/backend/src/settings/generic_amd/cpu.rs b/backend/src/settings/generic_amd/cpu.rs index 2f618b2..0809ee6 100644 --- a/backend/src/settings/generic_amd/cpu.rs +++ b/backend/src/settings/generic_amd/cpu.rs @@ -43,6 +43,18 @@ impl OnSet for Cpus { impl crate::settings::OnPowerEvent for Cpus {} +impl crate::settings::OnLoad for Cpus { + fn on_load(&mut self) -> Result<(), Vec> { + Ok(()) + } +} + +impl crate::settings::OnUnload for Cpus { + fn on_unload(&mut self) -> Result<(), Vec> { + Ok(()) + } +} + impl TCpus for Cpus { fn limits(&self) -> crate::api::CpusLimits { self.generic.limits() diff --git a/backend/src/settings/generic_amd/gpu.rs b/backend/src/settings/generic_amd/gpu.rs index 4b5066e..265956c 100644 --- a/backend/src/settings/generic_amd/gpu.rs +++ b/backend/src/settings/generic_amd/gpu.rs @@ -312,6 +312,18 @@ impl OnSet for Gpu { impl crate::settings::OnPowerEvent for Gpu {} +impl crate::settings::OnLoad for Gpu { + fn on_load(&mut self) -> Result<(), Vec> { + Ok(()) + } +} + +impl crate::settings::OnUnload for Gpu { + fn on_unload(&mut self) -> Result<(), Vec> { + Ok(()) + } +} + fn bad_gpu_limits() -> crate::api::GpuLimits { crate::api::GpuLimits { fast_ppt_limits: None, diff --git a/backend/src/settings/mod.rs b/backend/src/settings/mod.rs index 91e4662..4e74636 100644 --- a/backend/src/settings/mod.rs +++ b/backend/src/settings/mod.rs @@ -22,8 +22,8 @@ pub use min_max::{min_max_from_json, MinMax}; pub use error::SettingError; pub use traits::{ - OnPowerEvent, OnResume, OnSet, PowerMode, ProviderBuilder, TBattery, TCpu, TCpus, TGeneral, - TGpu, + OnLoad, OnPowerEvent, OnResume, OnSet, OnUnload, PowerMode, ProviderBuilder, TBattery, TCpu, + TCpus, TGeneral, TGpu, }; #[cfg(test)] diff --git a/backend/src/settings/steam_deck/battery.rs b/backend/src/settings/steam_deck/battery.rs index f47d9bd..d48e2a5 100644 --- a/backend/src/settings/steam_deck/battery.rs +++ b/backend/src/settings/steam_deck/battery.rs @@ -743,6 +743,18 @@ impl OnPowerEvent for Battery { } } +impl crate::settings::OnLoad for Battery { + fn on_load(&mut self) -> Result<(), Vec> { + Ok(()) + } +} + +impl crate::settings::OnUnload for Battery { + fn on_unload(&mut self) -> Result<(), Vec> { + Ok(()) + } +} + impl TBattery for Battery { fn limits(&self) -> crate::api::BatteryLimits { crate::api::BatteryLimits { diff --git a/backend/src/settings/steam_deck/cpu.rs b/backend/src/settings/steam_deck/cpu.rs index a1c78b6..de849fb 100644 --- a/backend/src/settings/steam_deck/cpu.rs +++ b/backend/src/settings/steam_deck/cpu.rs @@ -181,6 +181,35 @@ impl ProviderBuilder, GenericCpusLimit> for Cpus { impl crate::settings::OnPowerEvent for Cpus {} +impl crate::settings::OnLoad for Cpus { + fn on_load(&mut self) -> Result<(), Vec> { + let mut errors = Vec::new(); + for cpu in &mut self.cpus { + cpu.on_load().unwrap_or_else(|mut e| errors.append(&mut e)); + } + if errors.is_empty() { + Ok(()) + } else { + Err(errors) + } + } +} + +impl crate::settings::OnUnload for Cpus { + fn on_unload(&mut self) -> Result<(), Vec> { + let mut errors = Vec::new(); + for cpu in &mut self.cpus { + cpu.on_unload() + .unwrap_or_else(|mut e| errors.append(&mut e)); + } + if errors.is_empty() { + Ok(()) + } else { + Err(errors) + } + } +} + impl TCpus for Cpus { fn limits(&self) -> crate::api::CpusLimits { crate::api::CpusLimits { @@ -404,9 +433,6 @@ impl Cpu { ) .unwrap_or_else(|e| errors.push(e)); } - // TODO remove this when it's no longer needed - self.clock_unset_workaround() - .unwrap_or_else(|mut e| errors.append(&mut e)); if errors.is_empty() { Ok(()) } else { @@ -418,14 +444,9 @@ impl Cpu { } // https://github.com/NGnius/PowerTools/issues/107 - fn clock_unset_workaround(&self) -> Result<(), Vec> { - if !self.state.is_resuming { - let mut errors = Vec::new(); - POWER_DPM_FORCE_PERFORMANCE_LEVEL_MGMT.set_cpu(true, self.index); - // always set clock speeds, since it doesn't reset correctly (kernel/hardware bug) - POWER_DPM_FORCE_PERFORMANCE_LEVEL_MGMT.enforce_level(&self.sysfs)?; - // disable manual clock limits - log::debug!("Setting CPU {} to default clockspeed", self.index); + fn clock_unset(&self) -> Result<(), Vec> { + let mut errors = Vec::new(); + if self.state.clock_limits_set && POWER_DPM_FORCE_PERFORMANCE_LEVEL_MGMT.needs_manual() { // max clock self.set_clock_limit( self.index, @@ -445,15 +466,15 @@ impl Cpu { self.reset_clock_limits().unwrap_or_else(|e| errors.push(e)); self.set_confirm().unwrap_or_else(|e| errors.push(e)); - - POWER_DPM_FORCE_PERFORMANCE_LEVEL_MGMT.set_cpu(false, self.index); - if errors.is_empty() { - Ok(()) - } else { - Err(errors) - } - } else { + } + POWER_DPM_FORCE_PERFORMANCE_LEVEL_MGMT.set_cpu(false, self.index); + POWER_DPM_FORCE_PERFORMANCE_LEVEL_MGMT + .enforce_level(&self.sysfs) + .unwrap_or_else(|mut e| errors.append(&mut e)); + if errors.is_empty() { Ok(()) + } else { + Err(errors) } } @@ -639,6 +660,18 @@ impl OnResume for Cpu { } } +impl crate::settings::OnLoad for Cpu { + fn on_load(&mut self) -> Result<(), Vec> { + Ok(()) + } +} + +impl crate::settings::OnUnload for Cpu { + fn on_unload(&mut self) -> Result<(), Vec> { + self.clock_unset() + } +} + impl TCpu for Cpu { fn online(&mut self) -> &mut bool { &mut self.online diff --git a/backend/src/settings/steam_deck/gpu.rs b/backend/src/settings/steam_deck/gpu.rs index 4912713..562923b 100644 --- a/backend/src/settings/steam_deck/gpu.rs +++ b/backend/src/settings/steam_deck/gpu.rs @@ -597,6 +597,18 @@ impl OnResume for Gpu { impl crate::settings::OnPowerEvent for Gpu {} +impl crate::settings::OnLoad for Gpu { + fn on_load(&mut self) -> Result<(), Vec> { + Ok(()) + } +} + +impl crate::settings::OnUnload for Gpu { + fn on_unload(&mut self) -> Result<(), Vec> { + Ok(()) + } +} + impl TGpu for Gpu { fn limits(&self) -> crate::api::GpuLimits { crate::api::GpuLimits { diff --git a/backend/src/settings/traits.rs b/backend/src/settings/traits.rs index f68f5cf..2c8524f 100644 --- a/backend/src/settings/traits.rs +++ b/backend/src/settings/traits.rs @@ -10,6 +10,14 @@ pub trait OnResume { fn on_resume(&self) -> Result<(), Vec>; } +pub trait OnLoad { + fn on_load(&mut self) -> Result<(), Vec>; +} + +pub trait OnUnload { + fn on_unload(&mut self) -> Result<(), Vec>; +} + #[repr(u8)] #[derive(Clone, Copy, Debug)] pub enum PowerMode { @@ -46,7 +54,7 @@ pub trait ProviderBuilder { fn from_limits(limits: L) -> Self; } -pub trait TGpu: OnSet + OnResume + OnPowerEvent + Debug + Send { +pub trait TGpu: OnSet + OnResume + OnPowerEvent + OnLoad + OnUnload + Debug + Send { fn limits(&self) -> crate::api::GpuLimits; fn json(&self) -> crate::persist::GpuJson; @@ -68,7 +76,7 @@ pub trait TGpu: OnSet + OnResume + OnPowerEvent + Debug + Send { } } -pub trait TCpus: OnSet + OnResume + OnPowerEvent + Debug + Send { +pub trait TCpus: OnSet + OnResume + OnPowerEvent + OnLoad + OnUnload + Debug + Send { fn limits(&self) -> crate::api::CpusLimits; fn json(&self) -> Vec; @@ -96,7 +104,7 @@ pub trait TCpu: Debug + Send { fn get_clock_limits(&self) -> Option<&MinMax>; } -pub trait TGeneral: OnSet + OnResume + OnPowerEvent + Debug + Send { +pub trait TGeneral: OnSet + OnResume + OnPowerEvent + OnLoad + OnUnload + Debug + Send { fn limits(&self) -> crate::api::GeneralLimits; fn get_persistent(&self) -> bool; @@ -133,7 +141,7 @@ pub trait TGeneral: OnSet + OnResume + OnPowerEvent + Debug + Send { fn provider(&self) -> crate::persist::DriverJson; } -pub trait TBattery: OnSet + OnResume + OnPowerEvent + Debug + Send { +pub trait TBattery: OnSet + OnResume + OnPowerEvent + OnLoad + OnUnload + Debug + Send { fn limits(&self) -> crate::api::BatteryLimits; fn json(&self) -> crate::persist::BatteryJson; diff --git a/backend/src/settings/unknown/battery.rs b/backend/src/settings/unknown/battery.rs index cdd5c96..ed2cdda 100644 --- a/backend/src/settings/unknown/battery.rs +++ b/backend/src/settings/unknown/battery.rs @@ -56,6 +56,18 @@ impl OnResume for Battery { impl crate::settings::OnPowerEvent for Battery {} +impl crate::settings::OnLoad for Battery { + fn on_load(&mut self) -> Result<(), Vec> { + Ok(()) + } +} + +impl crate::settings::OnUnload for Battery { + fn on_unload(&mut self) -> Result<(), Vec> { + Ok(()) + } +} + impl TBattery for Battery { fn limits(&self) -> crate::api::BatteryLimits { crate::api::BatteryLimits { diff --git a/backend/src/settings/unknown/cpu.rs b/backend/src/settings/unknown/cpu.rs index 2aed5c8..7c1ebd9 100644 --- a/backend/src/settings/unknown/cpu.rs +++ b/backend/src/settings/unknown/cpu.rs @@ -71,6 +71,18 @@ impl OnResume for Cpus { impl crate::settings::OnPowerEvent for Cpus {} +impl crate::settings::OnLoad for Cpus { + fn on_load(&mut self) -> Result<(), Vec> { + Ok(()) + } +} + +impl crate::settings::OnUnload for Cpus { + fn on_unload(&mut self) -> Result<(), Vec> { + Ok(()) + } +} + impl Cpus { pub fn cpu_count() -> Option { let mut data: String = usdpl_back::api::files::read_single(CPU_PRESENT_PATH) diff --git a/backend/src/settings/unknown/gpu.rs b/backend/src/settings/unknown/gpu.rs index 4adcfec..d7c4826 100644 --- a/backend/src/settings/unknown/gpu.rs +++ b/backend/src/settings/unknown/gpu.rs @@ -55,6 +55,18 @@ impl OnResume for Gpu { impl crate::settings::OnPowerEvent for Gpu {} +impl crate::settings::OnLoad for Gpu { + fn on_load(&mut self) -> Result<(), Vec> { + Ok(()) + } +} + +impl crate::settings::OnUnload for Gpu { + fn on_unload(&mut self) -> Result<(), Vec> { + Ok(()) + } +} + impl TGpu for Gpu { fn limits(&self) -> crate::api::GpuLimits { crate::api::GpuLimits {