mirror of
https://github.com/openhardwaremonitor/openhardwaremonitor
synced 2025-08-29 13:28:04 +00:00
Added support for the Global\\Access_PCI mutex to synchronize the PCI bus access for reading AMD temperature sensors.
This commit is contained in:
parent
e82b9d7da2
commit
0751abb5c5
@ -4,7 +4,7 @@
|
|||||||
License, v. 2.0. If a copy of the MPL was not distributed with this
|
License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
Copyright (C) 2009-2010 Michael Möller <mmoeller@openhardwaremonitor.org>
|
Copyright (C) 2009-2020 Michael Möller <mmoeller@openhardwaremonitor.org>
|
||||||
Copyright (C) 2010 Paul Werelds <paul@werelds.net>
|
Copyright (C) 2010 Paul Werelds <paul@werelds.net>
|
||||||
|
|
||||||
*/
|
*/
|
||||||
@ -102,6 +102,8 @@ namespace OpenHardwareMonitor.Hardware.CPU {
|
|||||||
public override void Update() {
|
public override void Update() {
|
||||||
base.Update();
|
base.Update();
|
||||||
|
|
||||||
|
if (Ring0.WaitPciBusMutex(10)) {
|
||||||
|
|
||||||
if (miscellaneousControlAddress != Ring0.InvalidPciAddress) {
|
if (miscellaneousControlAddress != Ring0.InvalidPciAddress) {
|
||||||
for (uint i = 0; i < coreTemperatures.Length; i++) {
|
for (uint i = 0; i < coreTemperatures.Length; i++) {
|
||||||
if (Ring0.WritePciConfig(
|
if (Ring0.WritePciConfig(
|
||||||
@ -122,6 +124,9 @@ namespace OpenHardwareMonitor.Hardware.CPU {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ring0.ReleasePciBusMutex();
|
||||||
|
}
|
||||||
|
|
||||||
if (HasTimeStampCounter) {
|
if (HasTimeStampCounter) {
|
||||||
double newBusClock = 0;
|
double newBusClock = 0;
|
||||||
|
|
||||||
|
@ -311,11 +311,22 @@ namespace OpenHardwareMonitor.Hardware.CPU {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private bool ReadSmuRegister(uint address, out uint value) {
|
private bool ReadSmuRegister(uint address, out uint value) {
|
||||||
|
if (Ring0.WaitPciBusMutex(10)) {
|
||||||
|
|
||||||
if (!Ring0.WritePciConfig(0, 0xB8, address)) {
|
if (!Ring0.WritePciConfig(0, 0xB8, address)) {
|
||||||
value = 0;
|
value = 0;
|
||||||
|
|
||||||
|
Ring0.ReleasePciBusMutex();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
var result = Ring0.ReadPciConfig(0, 0xBC, out value);
|
||||||
|
|
||||||
|
Ring0.ReleasePciBusMutex();
|
||||||
|
return result;
|
||||||
|
} else {
|
||||||
|
value = 0;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return Ring0.ReadPciConfig(0, 0xBC, out value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Update() {
|
public override void Update() {
|
||||||
|
@ -160,10 +160,12 @@ namespace OpenHardwareMonitor.Hardware.CPU {
|
|||||||
CultureInfo.InvariantCulture));
|
CultureInfo.InvariantCulture));
|
||||||
r.AppendLine();
|
r.AppendLine();
|
||||||
|
|
||||||
|
if (Ring0.WaitPciBusMutex(100)) {
|
||||||
r.AppendLine("SMN Registers");
|
r.AppendLine("SMN Registers");
|
||||||
r.AppendLine();
|
r.AppendLine();
|
||||||
r.AppendLine(" Register Value");
|
r.AppendLine(" Register Value");
|
||||||
var registers = GetSmnRegisters();
|
var registers = GetSmnRegisters();
|
||||||
|
|
||||||
for (int i = 0; i < registers.Count; i++)
|
for (int i = 0; i < registers.Count; i++)
|
||||||
if (ReadSmnRegister(registers[i], out uint value)) {
|
if (ReadSmnRegister(registers[i], out uint value)) {
|
||||||
r.Append(" ");
|
r.Append(" ");
|
||||||
@ -174,6 +176,9 @@ namespace OpenHardwareMonitor.Hardware.CPU {
|
|||||||
}
|
}
|
||||||
r.AppendLine();
|
r.AppendLine();
|
||||||
|
|
||||||
|
Ring0.ReleasePciBusMutex();
|
||||||
|
}
|
||||||
|
|
||||||
return r.ToString();
|
return r.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -195,6 +200,8 @@ namespace OpenHardwareMonitor.Hardware.CPU {
|
|||||||
public override void Update() {
|
public override void Update() {
|
||||||
base.Update();
|
base.Update();
|
||||||
|
|
||||||
|
if (Ring0.WaitPciBusMutex(10)) {
|
||||||
|
|
||||||
uint value;
|
uint value;
|
||||||
if (ReadSmnRegister(FAMILY_17H_M01H_THM_TCON_TEMP, out value)) {
|
if (ReadSmnRegister(FAMILY_17H_M01H_THM_TCON_TEMP, out value)) {
|
||||||
float temperature = ((value >> 21) & 0x7FF) / 8.0f;
|
float temperature = ((value >> 21) & 0x7FF) / 8.0f;
|
||||||
@ -243,6 +250,9 @@ namespace OpenHardwareMonitor.Hardware.CPU {
|
|||||||
ActivateSensor(ccdAvgTemperature);
|
ActivateSensor(ccdAvgTemperature);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ring0.ReleasePciBusMutex();
|
||||||
|
}
|
||||||
|
|
||||||
if (energyUnitMultiplier != 0 &&
|
if (energyUnitMultiplier != 0 &&
|
||||||
Ring0.Rdmsr(MSR_PKG_ENERGY_STAT, out uint energyConsumed, out _))
|
Ring0.Rdmsr(MSR_PKG_ENERGY_STAT, out uint energyConsumed, out _))
|
||||||
{
|
{
|
||||||
|
@ -22,6 +22,7 @@ namespace OpenHardwareMonitor.Hardware {
|
|||||||
private static KernelDriver driver;
|
private static KernelDriver driver;
|
||||||
private static string fileName;
|
private static string fileName;
|
||||||
private static Mutex isaBusMutex;
|
private static Mutex isaBusMutex;
|
||||||
|
private static Mutex pciBusMutex;
|
||||||
private static readonly StringBuilder report = new StringBuilder();
|
private static readonly StringBuilder report = new StringBuilder();
|
||||||
|
|
||||||
private const uint OLS_TYPE = 40000;
|
private const uint OLS_TYPE = 40000;
|
||||||
@ -196,12 +197,21 @@ namespace OpenHardwareMonitor.Hardware {
|
|||||||
if (!driver.IsOpen)
|
if (!driver.IsOpen)
|
||||||
driver = null;
|
driver = null;
|
||||||
|
|
||||||
string mutexName = "Global\\Access_ISABUS.HTP.Method";
|
string isaMutexName = "Global\\Access_ISABUS.HTP.Method";
|
||||||
try {
|
try {
|
||||||
isaBusMutex = new Mutex(false, mutexName);
|
isaBusMutex = new Mutex(false, isaMutexName);
|
||||||
} catch (UnauthorizedAccessException) {
|
} catch (UnauthorizedAccessException) {
|
||||||
try {
|
try {
|
||||||
isaBusMutex = Mutex.OpenExisting(mutexName, MutexRights.Synchronize);
|
isaBusMutex = Mutex.OpenExisting(isaMutexName, MutexRights.Synchronize);
|
||||||
|
} catch { }
|
||||||
|
}
|
||||||
|
|
||||||
|
string pciMutexName = "Global\\Access_PCI";
|
||||||
|
try {
|
||||||
|
pciBusMutex = new Mutex(false, pciMutexName);
|
||||||
|
} catch (UnauthorizedAccessException) {
|
||||||
|
try {
|
||||||
|
pciBusMutex = Mutex.OpenExisting(pciMutexName, MutexRights.Synchronize);
|
||||||
} catch { }
|
} catch { }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -229,6 +239,11 @@ namespace OpenHardwareMonitor.Hardware {
|
|||||||
isaBusMutex = null;
|
isaBusMutex = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (pciBusMutex != null) {
|
||||||
|
pciBusMutex.Close();
|
||||||
|
pciBusMutex = null;
|
||||||
|
}
|
||||||
|
|
||||||
// try to delete temporary driver file again if failed during open
|
// try to delete temporary driver file again if failed during open
|
||||||
if (fileName != null && File.Exists(fileName)) {
|
if (fileName != null && File.Exists(fileName)) {
|
||||||
try {
|
try {
|
||||||
@ -266,6 +281,21 @@ namespace OpenHardwareMonitor.Hardware {
|
|||||||
isaBusMutex.ReleaseMutex();
|
isaBusMutex.ReleaseMutex();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool WaitPciBusMutex(int millisecondsTimeout) {
|
||||||
|
if (pciBusMutex == null)
|
||||||
|
return true;
|
||||||
|
try {
|
||||||
|
return pciBusMutex.WaitOne(millisecondsTimeout, false);
|
||||||
|
} catch (AbandonedMutexException) { return true; }
|
||||||
|
catch (InvalidOperationException) { return false; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void ReleasePciBusMutex() {
|
||||||
|
if (pciBusMutex == null)
|
||||||
|
return;
|
||||||
|
pciBusMutex.ReleaseMutex();
|
||||||
|
}
|
||||||
|
|
||||||
public static bool Rdmsr(uint index, out uint eax, out uint edx) {
|
public static bool Rdmsr(uint index, out uint eax, out uint edx) {
|
||||||
if (driver == null) {
|
if (driver == null) {
|
||||||
eax = 0;
|
eax = 0;
|
||||||
|
@ -10,5 +10,5 @@
|
|||||||
|
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
|
||||||
[assembly: AssemblyVersion("0.9.3.3")]
|
[assembly: AssemblyVersion("0.9.3.4")]
|
||||||
[assembly: AssemblyInformationalVersion("0.9.3.3 Alpha")]
|
[assembly: AssemblyInformationalVersion("0.9.3.4 Alpha")]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user