Skip to content

Commit

Permalink
Fix MSR write operation not iterating over threads
Browse files Browse the repository at this point in the history
  • Loading branch information
irusanov committed Sep 7, 2020
1 parent 8771d71 commit 9a368d1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
6 changes: 3 additions & 3 deletions SettingsForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@ public bool ApplyTscWorkaround()
if (OPS.Ols.Rdmsr(0xC0010015, ref eax, ref edx) != -1)
{
eax |= 0x200000;
return OPS.Ols.Wrmsr(0xC0010015, eax, edx) != -1;
return OPS.WriteMsr(0xC0010015, eax, edx);
}

SetStatusText($@"Error applying TSC fix!");
Expand All @@ -935,7 +935,7 @@ private bool WritePstateClick(int pstateId, uint eax, uint edx, int numanode = 0

if (!ApplyTscWorkaround()) return false;

if (OPS.Ols.Wrmsr(Convert.ToUInt32(Convert.ToInt64(0xC0010064) + pstateId), eax, edx) != 1)
if (!OPS.WriteMsr(Convert.ToUInt32(Convert.ToInt64(0xC0010064) + pstateId), eax, edx))
{
SetStatusText($@"Error writing PState {pstateId}!");
return false;
Expand Down Expand Up @@ -1081,7 +1081,7 @@ private void ButtonMsrWrite_Click(object sender, EventArgs e)
TryConvertToUint(textBoxMsrEax.Text, out uint eax);
TryConvertToUint(textBoxMsrAddress.Text, out uint msr);

if (OPS.Ols.Wrmsr(msr, eax, edx) != 1)
if (!OPS.WriteMsr(msr, eax, edx))
{
HandleError($@"Error writing MSR {textBoxMsrAddress.Text}!");
return;
Expand Down
14 changes: 14 additions & 0 deletions Utils/Ops.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class Ops : IDisposable
{
private static Mutex amdSmuMutex;
private const ushort SMU_TIMEOUT = 8192;
private readonly int Threads;

public Ops()
{
Expand All @@ -18,6 +19,7 @@ public Ops()
CpuType = GetCPUType(GetPkgType());
Smu = GetMaintainedSettings.GetByType(CpuType);
Smu.Version = GetSmuVersion();
Threads = GetCoreCount()[1];

//if (!SendTestMessage())
// throw new ApplicationException("SMU is not responding");
Expand Down Expand Up @@ -174,6 +176,18 @@ public uint ReadDword(uint value)
return Ols.ReadPciConfigDword(Smu.SMU_PCI_ADDR, (byte)Smu.SMU_OFFSET_DATA);
}

public bool WriteMsr(uint msr, uint eax, uint edx)
{
bool res = true;

for (var i = 0; i < Threads; i++)
{
if (Ols.WrmsrTx(msr, eax, edx, (UIntPtr)(1 << i)) != 1) res = false;
}

return res;
}

public SMU.CpuFamily GetCpuFamily()
{
uint eax = 0, ebx = 0, ecx = 0, edx = 0;
Expand Down

0 comments on commit 9a368d1

Please sign in to comment.