diff -r ff3e6edc7113 -r 0e01b63e1fdc Hardware/CPU/IntelCPU.cs --- a/Hardware/CPU/IntelCPU.cs Wed Feb 03 22:02:58 2010 +0000 +++ b/Hardware/CPU/IntelCPU.cs Thu Feb 04 21:19:27 2010 +0000 @@ -59,9 +59,8 @@ private uint logicalProcessorsPerCore; private uint coreCount; - private PerformanceCounter totalLoadCounter; - private PerformanceCounter[] coreLoadCounters; - + private CPULoad cpuLoad; + private const uint IA32_THERM_STATUS_MSR = 0x019C; private const uint IA32_TEMPERATURE_TARGET = 0x01A2; @@ -133,30 +132,7 @@ default: tjMax = 100; break; } - try { - totalLoadCounter = new PerformanceCounter(); - totalLoadCounter.CategoryName = "Processor"; - totalLoadCounter.CounterName = "% Processor Time"; - totalLoadCounter.InstanceName = "_Total"; - totalLoadCounter.NextValue(); - } catch (Exception) { - totalLoadCounter = null; - } - totalLoad = new Sensor("CPU Total", 0, SensorType.Load, this); - - coreLoadCounters = new PerformanceCounter[ - coreCount * logicalProcessorsPerCore]; - for (int i = 0; i < coreLoadCounters.Length; i++) { - try { - coreLoadCounters[i] = new PerformanceCounter(); - coreLoadCounters[i].CategoryName = "Processor"; - coreLoadCounters[i].CounterName = "% Processor Time"; - coreLoadCounters[i].InstanceName = i.ToString(); - coreLoadCounters[i].NextValue(); - } catch (Exception) { - coreLoadCounters[i] = null; - } - } + totalLoad = new Sensor("CPU Total", 0, SensorType.Load, this); coreTemperatures = new Sensor[coreCount]; coreLoads = new Sensor[coreCount]; @@ -167,6 +143,13 @@ SensorType.Load, this); } + cpuLoad = new CPULoad(coreCount, logicalProcessorsPerCore); + if (cpuLoad.IsAvailable) { + foreach (Sensor sensor in coreLoads) + ActivateSensor(sensor); + ActivateSensor(totalLoad); + } + Update(); } @@ -221,27 +204,11 @@ } } - if (totalLoadCounter != null) { - totalLoad.Value = totalLoadCounter.NextValue(); - ActivateSensor(totalLoad); - } - - for (int i = 0; i < coreLoads.Length; i++) { - float value = 0; - int count = 0; - for (int j = 0; j < logicalProcessorsPerCore; j++) { - PerformanceCounter counter = - coreLoadCounters[logicalProcessorsPerCore * i + j]; - if (counter != null) { - value += counter.NextValue(); - count++; - } - } - if (count > 0) { - value /= count; - coreLoads[i].Value = value; - ActivateSensor(coreLoads[i]); - } + if (cpuLoad.IsAvailable) { + cpuLoad.Update(); + for (int i = 0; i < coreLoads.Length; i++) + coreLoads[i].Value = cpuLoad.GetCoreLoad(i); + totalLoad.Value = cpuLoad.GetTotalLoad(); } }