Compare commits

...

5 Commits
v0.60 ... v0.61

Author SHA1 Message Date
Serge
51cd700e25 Improved GPU restart 2023-05-12 15:51:57 +02:00
Serge
7484253007 Merge branch 'main' of https://github.com/seerge/g-helper 2023-05-12 14:06:19 +02:00
Serge
f5cf768017 Display workaround 2023-05-12 14:06:15 +02:00
Serge
ca57669596 NV Clocks tweaks 2023-05-11 19:38:53 +02:00
Serge
35f1a3a25b Clock tweak 2023-05-11 11:18:42 +02:00
10 changed files with 146 additions and 38 deletions

View File

@@ -327,7 +327,7 @@ namespace Starlight.AnimeMatrix
int second = DateTime.Now.Second;
if (CultureInfo.CurrentCulture.DateTimeFormat.ShortTimePattern.Contains("H"))
PresentTextDiagonal(DateTime.Now.ToString("H" + ((second % 2 == 0) ? ":" : " ") + "mm"));
PresentTextDiagonal(DateTime.Now.ToString(" H" + ((second % 2 == 0) ? ":" : " ") + "mm"));
else
PresentTextDiagonal(DateTime.Now.ToString("h" + ((second % 2 == 0) ? ":" : " ") + "mmtt"));
}

View File

@@ -146,15 +146,23 @@ namespace GHelper
if (gpu_boost < 0) gpu_boost = ASUSWmi.MaxGPUBoost;
if (gpu_temp < 0) gpu_temp = ASUSWmi.MaxGPUTemp;
if (core == -1) core = 0;
if (memory == 1) memory = 0;
if (memory == -1) memory = 0;
if (readClocks)
//if (readClocks)
//{
int status = nvControl.GetClocks(out int current_core, out int current_memory);
if (status != -1)
{
nvControl.GetClocks(out core, out memory, out string gpuTitle);
labelGPU.Text = gpuTitle;
core = current_core;
memory = current_memory;
}
labelGPU.Text = nvControl.FullName;
//}
trackGPUCore.Value = Math.Max(Math.Min(core, NvidiaGpuControl.MaxCoreOffset), NvidiaGpuControl.MinCoreOffset);
trackGPUMemory.Value = Math.Max(Math.Min(memory, NvidiaGpuControl.MaxMemoryOffset), NvidiaGpuControl.MinMemoryOffset);

View File

@@ -16,7 +16,7 @@
<PlatformTarget>AnyCPU</PlatformTarget>
<ProduceReferenceAssembly>False</ProduceReferenceAssembly>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<AssemblyVersion>0.60</AssemblyVersion>
<AssemblyVersion>0.61</AssemblyVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">

View File

@@ -31,6 +31,8 @@ public class NvidiaGpuControl : IGpuControl
public bool IsNvidia => IsValid;
public string FullName => _internalGpu!.FullName;
public int? GetCurrentTemperature()
{
if (!IsValid)
@@ -49,12 +51,10 @@ public class NvidiaGpuControl : IGpuControl
}
public int GetClocks(out int core, out int memory, out string gpu)
public int GetClocks(out int core, out int memory)
{
PhysicalGPU internalGpu = _internalGpu!;
gpu = internalGpu.FullName;
//Logger.WriteLine(internalGpu.FullName);
//Logger.WriteLine(internalGpu.ArchitectInformation.ToString());
@@ -63,12 +63,12 @@ public class NvidiaGpuControl : IGpuControl
IPerformanceStates20Info states = GPUApi.GetPerformanceStates20(internalGpu.Handle);
core = states.Clocks[PerformanceStateId.P0_3DPerformance][0].FrequencyDeltaInkHz.DeltaValue / 1000;
memory = states.Clocks[PerformanceStateId.P0_3DPerformance][1].FrequencyDeltaInkHz.DeltaValue / 1000;
Logger.WriteLine($"GET GPU Clock offsets : {core}, {memory}");
Logger.WriteLine($"GET GPU CLOCKS: {core}, {memory}");
return 0;
} catch (Exception ex)
{
Logger.WriteLine(ex.Message);
Logger.WriteLine("GET GPU CLOCKS:" + ex.Message);
core = memory = 0;
return -1;
}
@@ -90,7 +90,7 @@ public class NvidiaGpuControl : IGpuControl
}
public bool RestartGPU()
public bool RestartGPUPnP()
{
if (!IsValid) return false;
@@ -99,13 +99,30 @@ public class NvidiaGpuControl : IGpuControl
{
PhysicalGPU internalGpu = _internalGpu!;
var pnpDeviceId = internalGpu.BusInformation.PCIIdentifiers.ToString();
Logger.WriteLine("Device ID:"+ pnpDeviceId);
Logger.WriteLine("Device ID:" + pnpDeviceId);
RunCMD("pnputil", $"/disable-device /deviceid \"{pnpDeviceId}\"");
Thread.Sleep(3000);
RunCMD("pnputil", $"/enable-device /deviceid \"{pnpDeviceId}\"");
Thread.Sleep(2000);
return true;
}
catch (Exception ex)
{
Logger.WriteLine(ex.ToString());
return false;
}
}
public bool RestartGPU()
{
try
{
string script = @"$device = Get-PnpDevice | Where-Object { $_.FriendlyName -imatch 'NVIDIA' -and $_.Class -eq 'Display' }; Disable-PnpDevice $device.InstanceId -Confirm:$false; Start-Sleep -Seconds 2; Enable-PnpDevice $device.InstanceId -Confirm:$false";
Logger.WriteLine(script);
RunCMD("powershell", script);
Thread.Sleep(2000);
return true;
}
catch (Exception ex )
{
Logger.WriteLine(ex.ToString());
@@ -141,12 +158,12 @@ public class NvidiaGpuControl : IGpuControl
try
{
Logger.WriteLine($"SET GPU Clock : {core}, {memory}");
Logger.WriteLine($"SET GPU CLOCKS: {core}, {memory}");
GPUApi.SetPerformanceStates20(internalGpu.Handle, overclock);
}
catch (Exception ex)
{
Logger.WriteLine(ex.Message);
Logger.WriteLine("SET GPU CLOCKS: "+ex.Message);
return -1;
}

View File

@@ -647,6 +647,8 @@ public class NativeMethods
//Logger.WriteLine(screen.DeviceName);
count++;
}
if (displayNum > 0 && count == 0) laptopScreen = defaultDevice;
}
catch (Exception ex)
{

View File

@@ -0,0 +1,38 @@
using System.Text.RegularExpressions;
using System.Text;
namespace GHelper
{
public static class OptimizationService
{
public static void SetChargeLimit (int newValue)
{
// Set the path to the .ini file
string path = @"C:\ProgramData\ASUS\ASUS System Control Interface\ASUSOptimization\Customization.ini";
// Make a backup copy of the INI file
string backupPath = path + ".bak";
File.Copy(path, backupPath, true);
string fileContents = File.ReadAllText(path, Encoding.Unicode);
// Find the section [BatteryHealthCharging]
string sectionPattern = @"\[BatteryHealthCharging\]\s*(version=\d+)?\s+value=(\d+)";
Match sectionMatch = Regex.Match(fileContents, sectionPattern);
if (sectionMatch.Success)
{
// Replace the value with the new value
string oldValueString = sectionMatch.Groups[2].Value;
int oldValue = int.Parse(oldValueString);
string newSection = sectionMatch.Value.Replace($"value={oldValue}", $"value={newValue}");
// Replace the section in the file contents
fileContents = fileContents.Replace(sectionMatch.Value, newSection);
File.WriteAllText(path, fileContents, Encoding.Unicode);
}
}
}
}

View File

@@ -291,16 +291,19 @@ namespace GHelper
{
settingsForm.Show();
settingsForm.Activate();
settingsForm.VisualiseGPUMode();
if (action == "gpu")
switch (action)
{
Startup.ReScheduleAdmin();
settingsForm.FansToggle();
case "gpu":
Startup.ReScheduleAdmin();
settingsForm.FansToggle();
break;
case "gpurestart":
settingsForm.RestartGPU(false);
break;
}
}
settingsForm.VisualiseGPUMode();
}
static void TrayIcon_MouseClick(object? sender, MouseEventArgs e)

View File

@@ -825,6 +825,15 @@ namespace GHelper.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to Something is using dGPU and preventing Eco mode. Restart dGPU in device manager? * Please proceed on your own risk..
/// </summary>
internal static string RestartGPU {
get {
return ResourceManager.GetString("RestartGPU", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to RPM.
/// </summary>

View File

@@ -372,6 +372,9 @@
<data name="Quit" xml:space="preserve">
<value>Quit</value>
</data>
<data name="RestartGPU" xml:space="preserve">
<value>Something is using dGPU and preventing Eco mode. Restart dGPU in device manager? * Please proceed on your own risk.</value>
</data>
<data name="RPM" xml:space="preserve">
<value>RPM</value>
</data>

View File

@@ -1056,17 +1056,18 @@ namespace GHelper
//if ((gpu_core > -5 && gpu_core < 5) && (gpu_memory > -5 && gpu_memory < 5)) launchAsAdmin = false;
if (Program.wmi.DeviceGet(ASUSWmi.GPUEco) == 1) return;
if (HardwareControl.GpuControl is null) return;
if (!HardwareControl.GpuControl!.IsNvidia) return;
if (Program.wmi.DeviceGet(ASUSWmi.GPUEco) == 1) return;
using NvidiaGpuControl nvControl = (NvidiaGpuControl)HardwareControl.GpuControl;
try
{
int getStatus = nvControl.GetClocks(out int current_core, out int current_memory, out string gpuName);
if (getStatus == -1) return;
if (Math.Abs(gpu_core - current_core) < 5 && Math.Abs(gpu_memory - current_memory) < 5) return;
int getStatus = nvControl.GetClocks(out int current_core, out int current_memory);
if (getStatus != -1)
{
if (Math.Abs(gpu_core - current_core) < 5 && Math.Abs(gpu_memory - current_memory) < 5) return;
}
int setStatus = nvControl.SetClocks(gpu_core, gpu_memory);
if (launchAsAdmin && setStatus == -1) Program.RunAsAdmin("gpu");
@@ -1453,19 +1454,43 @@ namespace GHelper
}
public bool RestartGPU()
public void RestartGPU(bool confirm = true)
{
if (HardwareControl.GpuControl is null) return false;
if (!HardwareControl.GpuControl!.IsNvidia) return false;
if (HardwareControl.GpuControl is null) return;
if (!HardwareControl.GpuControl!.IsNvidia) return;
DialogResult dialogResult = MessageBox.Show("Something is using dGPU and blocking Eco mode. Restart dGPU in a device manager and try to set Eco again?", Properties.Strings.EcoMode, MessageBoxButtons.YesNo);
if (dialogResult == DialogResult.No) return false;
if (confirm)
{
DialogResult dialogResult = MessageBox.Show(Properties.Strings.RestartGPU, Properties.Strings.EcoMode, MessageBoxButtons.YesNo);
if (dialogResult == DialogResult.No) return;
}
Program.RunAsAdmin();
Program.RunAsAdmin("gpurestart");
Logger.WriteLine("Trying to restart GPU");
var nvControl = (NvidiaGpuControl)HardwareControl.GpuControl;
return nvControl.RestartGPU();
if (!Program.IsUserAdministrator()) return;
Logger.WriteLine("Trying to restart dGPU");
Task.Run(async () =>
{
Program.settingsForm.BeginInvoke(delegate
{
labelTipGPU.Text = "Restarting GPU ...";
ButtonEnabled(buttonOptimized, false);
ButtonEnabled(buttonEco, false);
ButtonEnabled(buttonStandard, false);
ButtonEnabled(buttonUltimate, false);
});
var nvControl = (NvidiaGpuControl)HardwareControl.GpuControl;
bool status = nvControl.RestartGPU();
Program.settingsForm.BeginInvoke(delegate
{
labelTipGPU.Text = status ? "GPU Restarted, you can try Eco mode again" : "Failed to restart GPU";
InitGPUMode();
});
});
}
@@ -1489,13 +1514,14 @@ namespace GHelper
string[] tokill = { "EADesktop", "RadeonSoftware" };
foreach (string kill in tokill)
foreach (var process in Process.GetProcessesByName(kill)) process.Kill();
}
}
//if (eco == 1) status = 0; else
status = Program.wmi.SetGPUEco(eco);
if (status == 0 && eco == 1 && hardWay)
{
if (RestartGPU()) Program.wmi.SetGPUEco(1);
RestartGPU();
}
await Task.Delay(TimeSpan.FromMilliseconds(500));
@@ -1507,7 +1533,7 @@ namespace GHelper
if (eco == 0)
{
await Task.Delay(TimeSpan.FromMilliseconds(1000));
await Task.Delay(TimeSpan.FromMilliseconds(3000));
HardwareControl.RecreateGpuControl();
SetGPUClocks(false);
}
@@ -1668,6 +1694,8 @@ namespace GHelper
sliderBattery.Value = limit;
Program.wmi.DeviceSet(ASUSWmi.BatteryLimit, limit, "BatteryLimit");
OptimizationService.SetChargeLimit(limit);
Program.config.setConfig("charge_limit", limit);
}