Improve CPU/GPU frequency setting

This commit is contained in:
Kamil Trzciński 2022-11-20 19:00:53 +01:00
parent b9d871f6ec
commit a1a438c3f8
2 changed files with 52 additions and 13 deletions

View file

@ -188,17 +188,17 @@ namespace PowerControl.Helpers.GPU
get { return getValue(Message.PPSMC_MSG_GetFclkFrequency); }
}
const uint MIN_CPU_CLOCK = 800;
const uint MIN_CPU_CLOCK = 1400;
const uint MAX_CPU_CLOCK = 3500;
public uint MinCPUClock
{
set { setValue(Message.PPSMC_MSG_SetSoftMinCclk, value, MIN_CPU_CLOCK, MAX_CPU_CLOCK); }
set { setCPUValue(Message.PPSMC_MSG_SetSoftMinCclk, value, MIN_CPU_CLOCK, MAX_CPU_CLOCK); }
}
public uint MaxCPUClock
{
set { setValue(Message.PPSMC_MSG_SetSoftMaxCclk, value, MIN_CPU_CLOCK, MAX_CPU_CLOCK); }
set { setCPUValue(Message.PPSMC_MSG_SetSoftMaxCclk, value, MIN_CPU_CLOCK, MAX_CPU_CLOCK); }
}
const uint MIN_GFX_CLOCK = 200;
@ -238,15 +238,24 @@ namespace PowerControl.Helpers.GPU
}
}
private void setCPUValue(Message msg, uint value, uint min = UInt32.MinValue, uint max = UInt32.MaxValue)
{
// TODO: Hardcode CPUs
for (uint i = 0; i < 4; i++)
{
setValue(msg, value | (i << 20), min, max, (1 << 20) - 1);
}
}
private uint getValue(Message msg)
{
this.smu.SendMsg(msg, 0, out var value);
return value;
}
private void setValue(Message msg, uint value, uint min = UInt32.MinValue, uint max = UInt32.MaxValue)
private void setValue(Message msg, uint value, uint min = UInt32.MinValue, uint max = UInt32.MaxValue, uint clampMask = uint.MaxValue)
{
this.smu.SendMsg(msg, Math.Clamp(value, min, max));
this.smu.SendMsg(msg, Math.Clamp(value & clampMask, min, max) | (value & ~clampMask));
}
private readonly Message[] ValuesGetters = new Message[]

View file

@ -192,12 +192,12 @@ namespace PowerControl
},
new Menu.MenuItemWithOptions()
{
Name = "GPU Min",
Options = { "200MHz", "400MHz", "800MHz", "1200MHz", "1600MHz" },
Name = "GPU",
Options = { "Default", "400MHz", "800MHz", "1200MHz", "1600MHz" },
ApplyDelay = 1000,
Visible = VangoghGPU.IsSupported,
ActiveOption = "?",
ResetValue = () => { return "200MHz"; },
ResetValue = () => { return "Default"; },
ApplyValue = delegate(object selected)
{
using (var sd = VangoghGPU.Open())
@ -205,19 +205,25 @@ namespace PowerControl
if (sd is null)
return null;
if (selected.ToString() == "Default")
{
sd.HardMinGfxClock = 200;
return selected;
}
sd.HardMinGfxClock = uint.Parse(selected.ToString().Replace("MHz", ""));
return sd.GfxClock.ToString() + "MHz";
return selected;
}
}
},
new Menu.MenuItemWithOptions()
{
Name = "CPU Max",
Options = { "800MHz", "2000MHz", "3000MHz", "3500MHz" },
Name = "CPU",
Options = { "Default", "Power-Save", "Balanced", "Max" },
ApplyDelay = 1000,
ActiveOption = "?",
Visible = VangoghGPU.IsSupported,
ResetValue = () => { return "3500MHz"; },
ResetValue = () => { return "Default"; },
ApplyValue = delegate(object selected)
{
using (var sd = VangoghGPU.Open())
@ -225,7 +231,31 @@ namespace PowerControl
if (sd is null)
return null;
sd.MaxCPUClock = uint.Parse(selected.ToString().Replace("MHz", ""));
switch(selected.ToString())
{
case "Default":
sd.MinCPUClock = 1400;
sd.MaxCPUClock = 3500;
break;
case "Power-Save":
sd.MinCPUClock = 1400;
sd.MaxCPUClock = 1800;
break;
case "Balanced":
sd.MinCPUClock = 2200;
sd.MaxCPUClock = 2800;
break;
case "Max":
sd.MinCPUClock = 3000;
sd.MaxCPUClock = 3500;
break;
default:
return null;
}
return selected;
}
}