Merge pull request #10 from sp00n/master

Added mitigation for when the mapping of the physical cores to the logical cores has failed
This commit is contained in:
rawhide-kobayashi 2025-04-09 00:28:48 -05:00 committed by GitHub
commit ef97c0c290
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 108 additions and 84 deletions

View File

@ -14,7 +14,7 @@ namespace ryzen_smu_cli
{
if (!IsAdministrator())
{
Console.WriteLine("This application must be run as an administrator.");
Console.Error.WriteLine("This application must be run as an administrator.");
Environment.Exit(1);
}
@ -24,9 +24,9 @@ namespace ryzen_smu_cli
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
Console.WriteLine("If the previous message was unclear, for some reason, ZenStates-Core failed to initialize an instance of the CPU control object.");
Environment.Exit(1);
Console.Error.WriteLine($"Error: {ex.Message}");
Console.Error.WriteLine("If the previous message was unclear, for some reason, ZenStates-Core failed to initialize an instance of the CPU control object.");
Environment.Exit(2);
}
mappedCores = MapLogicalCoresToPhysical();
@ -47,7 +47,7 @@ namespace ryzen_smu_cli
{
if (!IsAdministrator())
{
Console.WriteLine("This application must be run as an administrator.");
Console.Error.WriteLine("This application must be run as an administrator.");
Environment.Exit(1);
}
@ -153,6 +153,11 @@ namespace ryzen_smu_cli
{
Dictionary<int, int> mappedCores = [];
int maxTries = 3;
for (int currentTry = 1; currentTry <= maxTries; currentTry++)
{
mappedCores.Clear();
int logicalCoreIter = 0;
for (var i = 0; i < ryzen.info.topology.physicalCores; i++)
@ -161,7 +166,22 @@ namespace ryzen_smu_cli
if (ryzen.GetPsmMarginSingleCore((uint) (((mapIndex << 8) | ((i % 8) & 0xF)) << 20)) != null)
{
mappedCores.Add(logicalCoreIter, i);
logicalCoreIter += 1;
logicalCoreIter++;
}
}
// The mapped cores should match the amount of physical cores
if (mappedCores.Count == ryzen.info.topology.cores)
{
break;
}
// Something weird is happening if we cannot find the logical cores for all the physical ones even after three attempts
if (currentTry >= maxTries)
{
Console.Error.WriteLine($"Did not find the expected amount of cores for mapping ({ryzen.info.topology.cores} expected but found only {mappedCores.Count})!");
Environment.Exit(8);
}
}
@ -237,16 +257,31 @@ namespace ryzen_smu_cli
private static void ApplyPBOOffset(string offsetArgs)
{
// This checks if the current SKU has a known register for writing PBO offsets
if (ryzen.smu.Rsmu.SMU_MSG_SetDldoPsmMargin != 0)
if (ryzen.smu.Rsmu.SMU_MSG_SetDldoPsmMargin == 0)
{
Console.Error.WriteLine("You have attempted to enable PBO offsets on a CPU that does not support them.");
Environment.Exit(3);
}
string validArgFormat = @"^(-?\d{1,2}(,-?\d{1,2})*|\d{1,2}:-?\d{1,2}(,\d{1,2}:-?\d{1,2})*)$";
if (Regex.IsMatch(offsetArgs, validArgFormat))
if (!Regex.IsMatch(offsetArgs, validArgFormat))
{
Console.Error.WriteLine("Malformed input format for offsets. Please check and try again.");
Environment.Exit(4);
}
string[] arg = offsetArgs.Split(',');
if (arg.Length <= mappedCores.Count)
if (arg.Length > mappedCores.Count)
{
Console.Error.WriteLine("Specified a greater number of offsets than logical cores active in the system. Please check and try again.");
Environment.Exit(5);
}
for (int i = 0; i < arg.Length; i++)
{
// Magic numbers from SMUDebugTool
@ -273,20 +308,12 @@ namespace ryzen_smu_cli
catch (KeyNotFoundException)
{
Console.WriteLine($"Tried to set an offset on logical core {Convert.ToInt32(arg[i].Split(':')[0])}, but there are only {mappedCores.Count} (zero-indexed, as a reminder) logical cores active in the system.");
Console.Error.WriteLine($"Tried to set an offset on logical core {Convert.ToInt32(arg[i].Split(':')[0])}, but there are only {mappedCores.Count} (zero-indexed, as a reminder) logical cores active in the system.");
Environment.Exit(6);
}
}
}
else Console.WriteLine("Specified a greater number of offsets than logical cores active in the system. Please check and try again.");
}
else Console.WriteLine("Malformed input format for offsets. Please check and try again.");
}
else Console.WriteLine("You have attempted to enable PBO offsets on a CPU that does not support them.");
}
private static void ApplyDisableCores(string coreArgs = "Enable")
{
if (!wmiPopulated) PopulateWmiFunctions();
@ -297,8 +324,11 @@ namespace ryzen_smu_cli
var cmdItem = availableCommands.FirstOrDefault(item => item.text.Contains("Software Downcore Config"));
if (cmdItem != null)
{
if ( cmdItem == null ) {
Console.Error.WriteLine("Something has gone terribly wrong, the downcore config option is not present.");
Environment.Exit(7);
}
for (int i = 0; i < ccds.Length; i++)
{
if (coreArgs != "Enable")
@ -322,12 +352,6 @@ namespace ryzen_smu_cli
}
}
else
{
Console.WriteLine("Something has gone terribly wrong, the downcore config option is not present.");
}
}
private static bool IsAdministrator()
{
using (WindowsIdentity identity = WindowsIdentity.GetCurrent())

View File

@ -6,7 +6,7 @@
<RootNamespace>ryzen_smu_cli</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Version>0.1.1</Version>
<Version>0.0.3</Version>
</PropertyGroup>
<PropertyGroup>