Skip to content

Commit

Permalink
improved Power Profile
Browse files Browse the repository at this point in the history
- implemented profile merger to apply one only profile being the sum of several profiles.
- new ProfileMask, ExtGPU for more specific Power Profile behaviors.
  • Loading branch information
Lesueur Benjamin committed Feb 8, 2021
1 parent 041ccae commit 8ad7246
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 19 deletions.
35 changes: 17 additions & 18 deletions DockerForm/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;";
Expand All @@ -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
Expand Down
27 changes: 26 additions & 1 deletion DockerForm/PowerProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 8ad7246

Please sign in to comment.