From 8ad72469f6c9dce122d4c40a6699764c698f86ac Mon Sep 17 00:00:00 2001 From: Lesueur Benjamin Date: Mon, 8 Feb 2021 09:34:17 +0100 Subject: [PATCH] improved Power Profile - implemented profile merger to apply one only profile being the sum of several profiles. - new ProfileMask, ExtGPU for more specific Power Profile behaviors. --- DockerForm/Form1.cs | 35 +++++++++++++++++------------------ DockerForm/PowerProfile.cs | 27 ++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 19 deletions(-) diff --git a/DockerForm/Form1.cs b/DockerForm/Form1.cs index bfbf98e..df1b89c 100644 --- a/DockerForm/Form1.cs +++ b/DockerForm/Form1.cs @@ -85,36 +85,33 @@ private void OnPowerModeChanged(object s, PowerModeChangedEventArgs e) private static void CheckPowerProfiles() { - foreach (PowerProfile profile in ProfileDB.Values) + PowerProfile sum_profile = new PowerProfile(); + foreach (PowerProfile profile in ProfileDB.Values.OrderBy(a => a.ApplyMask)) { bool isOnBattery = (profile.ApplyMask & (byte)ProfileMask.OnBattery) != 0; bool isPluggedIn = (profile.ApplyMask & (byte)ProfileMask.PluggedIn) != 0; - - // if device is plugged in - if (PowerStatus && isPluggedIn) - SetPowerProfile(profile); + bool isExtGPU = (profile.ApplyMask & (byte)ProfileMask.ExtGPU) != 0; // if device is running on battery - if (!PowerStatus && isOnBattery) - SetPowerProfile(profile); + if (!PowerStatus && isOnBattery || PowerStatus && isPluggedIn || DockStatus && isExtGPU) + { + sum_profile.DigestProfile(profile); + sum_profile.ProfileName += profile.ProfileName + ","; + } } + sum_profile.ProfileName = sum_profile.ProfileName.TrimEnd(','); + + SetPowerProfile(sum_profile); } private static void SetPowerProfile(PowerProfile profile, DockerGame game = null) { - string command = "/nologo /min /command=\""; + string command = "/min /nologo /command=\""; if (profile.HasLongPowerMax()) - { - command += "w 0xFEDC59a1 0x8" + profile.GetLongPowerMax().Substring(0, 1) + ";"; - command += "w 0xFEDC59a0 0x8" + profile.GetLongPowerMax().Substring(1) + ";"; - } - + command += "w16 0xFED159a0 0x8" + profile.GetLongPowerMax().Substring(0, 1) + profile.GetLongPowerMax().Substring(1) + ";"; if (profile.HasShortPowerMax()) - { - command += "w 0xFEDC59a5 0x8" + profile.GetShortPowerMax().Substring(0, 1) + ";"; - command += "w 0xFEDC59a4 0x8" + profile.GetShortPowerMax().Substring(1) + ";"; - } + command += "w16 0xFED159a4 0x8" + profile.GetShortPowerMax().Substring(0, 1) + profile.GetShortPowerMax().Substring(1) + ";"; if (profile.HasCPUCore()) command += "wrmsr 0x150 0x80000011 0x" + profile.GetVoltageCPU() + "00000;"; @@ -125,12 +122,14 @@ private static void SetPowerProfile(PowerProfile profile, DockerGame game = null if (profile.HasSystemAgent()) command += "wrmsr 0x150 0x80000411 0x" + profile.GetVoltageSA() + "00000;"; - // power balance if (profile.HasPowerBalanceCPU()) command += "wrmsr 0x642 0x00000000 0x000000" + profile.GetPowerBalanceCPU() + ";"; if (profile.HasPowerBalanceGPU()) command += "wrmsr 0x63a 0x00000000 0x000000" + profile.GetPowerBalanceGPU() + ";"; + if (profile.HasShortPowerMax() && profile.HasLongPowerMax()) + command += "wrmsr 0x610 0x00438" + profile.GetShortPowerMax() + " 0x00dd8" + profile.GetLongPowerMax() + ";"; + command += "rwexit\""; ProcessStartInfo RWInfo = new ProcessStartInfo diff --git a/DockerForm/PowerProfile.cs b/DockerForm/PowerProfile.cs index 6c3610d..bf4d2fb 100644 --- a/DockerForm/PowerProfile.cs +++ b/DockerForm/PowerProfile.cs @@ -13,7 +13,8 @@ namespace DockerForm public enum ProfileMask { OnBattery = 0x01, // 0000 0000 0000 0001 - PluggedIn = 0x02 // 0000 0000 0000 0010 + PluggedIn = 0x02, // 0000 0000 0000 0010 + ExtGPU = 0x04 // 0000 0000 0000 0100 } public static class StringExtension @@ -191,6 +192,30 @@ public void ComputeHex() } } + public void DigestProfile(PowerProfile profile) + { + if (profile.HasLongPowerMax()) + TurboBoostLongPowerMax = profile.TurboBoostLongPowerMax; + if (profile.HasShortPowerMax()) + TurboBoostShortPowerMax = profile.TurboBoostShortPowerMax; + + if (profile.HasCPUCore()) + CPUCore = profile.CPUCore; + if (profile.HasIntelGPU()) + IntelGPU = profile.IntelGPU; + if (profile.HasCPUCache()) + CPUCache = profile.CPUCache; + if (profile.HasSystemAgent()) + SystemAgent = profile.SystemAgent; + + if (profile.HasPowerBalanceCPU()) + PowerBalanceCPU = profile.PowerBalanceCPU; + if (profile.HasPowerBalanceGPU()) + PowerBalanceGPU = profile.PowerBalanceGPU; + + ComputeHex(); + } + public void Dispose() { throw new NotImplementedException();