private void WinbondFintekExit() { WinRing0.WriteIoPortByte(registerPort, 0xAA); }
// SMSC private void SMSCEnter() { WinRing0.WriteIoPortByte(registerPort, 0x55); }
public override void Update() { for (int i = 0; i < coreTemperatures.Length; i++) { uint eax, edx; if (WinRing0.RdmsrTx( IA32_THERM_STATUS_MSR, out eax, out edx, (UIntPtr)(1L << cpuid[i][0].Thread))) { // if reading is valid if ((eax & 0x80000000) != 0) { // get the dist from tjMax from bits 22:16 float deltaT = ((eax & 0x007F0000) >> 16); float tjMax = coreTemperatures[i].Parameters[0].Value; float tSlope = coreTemperatures[i].Parameters[1].Value; coreTemperatures[i].Value = tjMax - tSlope * deltaT; ActivateSensor(coreTemperatures[i]); } else { DeactivateSensor(coreTemperatures[i]); } } } if (cpuLoad.IsAvailable) { cpuLoad.Update(); for (int i = 0; i < coreLoads.Length; i++) { coreLoads[i].Value = cpuLoad.GetCoreLoad(i); } if (totalLoad != null) { totalLoad.Value = cpuLoad.GetTotalLoad(); } } if (hasTSC) { uint lsb, msb; WinRing0.RdtscTx(out lsb, out msb, (UIntPtr)1); long time = Stopwatch.GetTimestamp(); ulong timeStampCount = ((ulong)msb << 32) | lsb; double delta = ((double)(time - lastTime)) / Stopwatch.Frequency; if (delta > 0.5) { double maxClock; if (invariantTSC) { maxClock = (timeStampCount - lastTimeStampCount) / (1e6 * delta); } else { maxClock = estimatedMaxClock; } double busClock = 0; uint eax, edx; for (int i = 0; i < coreClocks.Length; i++) { System.Threading.Thread.Sleep(1); if (WinRing0.RdmsrTx(IA32_PERF_STATUS, out eax, out edx, (UIntPtr)(1L << cpuid[i][0].Thread))) { if (maxNehalemMultiplier > 0) // Core i3, i5, i7 { uint nehalemMultiplier = eax & 0xff; coreClocks[i].Value = (float)(nehalemMultiplier * maxClock / maxNehalemMultiplier); busClock = (float)(maxClock / maxNehalemMultiplier); } else // Core 2 { uint multiplier = (eax >> 8) & 0x1f; uint maxMultiplier = (edx >> 8) & 0x1f; // factor = multiplier * 2 to handle non integer multipliers uint factor = (multiplier << 1) | ((eax >> 14) & 1); uint maxFactor = (maxMultiplier << 1) | ((edx >> 14) & 1); if (maxFactor > 0) { coreClocks[i].Value = (float)(factor * maxClock / maxFactor); busClock = (float)(2 * maxClock / maxFactor); } } } else // Intel Pentium 4 // if IA32_PERF_STATUS is not available, assume maxClock { coreClocks[i].Value = (float)maxClock; } } if (busClock > 0) { this.busClock.Value = (float)busClock; ActivateSensor(this.busClock); } } lastTimeStampCount = timeStampCount; lastTime = time; } }
public CPUGroup() { if (!WinRing0.IsAvailable) { return; } if (WinRing0.IsCpuid()) { uint maxCPUID = 0; uint maxCPUID_EXT = 0; uint eax, ebx, ecx, edx; if (WinRing0.Cpuid(CPUID, out eax, out ebx, out ecx, out edx)) { maxCPUID = eax; StringBuilder vendorBuilder = new StringBuilder(); AppendRegister(vendorBuilder, ebx); AppendRegister(vendorBuilder, edx); AppendRegister(vendorBuilder, ecx); cpuVendor = vendorBuilder.ToString(); eax = ebx = ecx = edx = 0; if (WinRing0.Cpuid(CPUID_EXT, out eax, out ebx, out ecx, out edx)) { maxCPUID_EXT = eax - CPUID_EXT; } } if (maxCPUID == 0 || maxCPUID_EXT == 0) { return; } cpuidData = new uint[maxCPUID + 1, 4]; for (uint i = 0; i < (maxCPUID + 1); i++) { WinRing0.Cpuid(CPUID + i, out cpuidData[i, 0], out cpuidData[i, 1], out cpuidData[i, 2], out cpuidData[i, 3]); } cpuidExtData = new uint[maxCPUID_EXT + 1, 4]; for (uint i = 0; i < (maxCPUID_EXT + 1); i++) { WinRing0.Cpuid(CPUID_EXT + i, out cpuidExtData[i, 0], out cpuidExtData[i, 1], out cpuidExtData[i, 2], out cpuidExtData[i, 3]); } StringBuilder nameBuilder = new StringBuilder(); for (uint i = 2; i <= 4; i++) { if (WinRing0.Cpuid(CPUID_EXT + i, out eax, out ebx, out ecx, out edx)) { AppendRegister(nameBuilder, eax); AppendRegister(nameBuilder, ebx); AppendRegister(nameBuilder, ecx); AppendRegister(nameBuilder, edx); } } nameBuilder.Replace('\0', ' '); cpuBrandString = nameBuilder.ToString().Trim(); nameBuilder.Replace("(R)", " "); nameBuilder.Replace("(TM)", " "); nameBuilder.Replace("(tm)", " "); nameBuilder.Replace("CPU", ""); for (int i = 0; i < 10; i++) { nameBuilder.Replace(" ", " "); } string name = nameBuilder.ToString(); if (name.Contains("@")) { name = name.Remove(name.LastIndexOf('@')); } name = name.Trim(); this.family = ((cpuidData[1, 0] & 0x0FF00000) >> 20) + ((cpuidData[1, 0] & 0x0F00) >> 8); this.model = ((cpuidData[1, 0] & 0x0F0000) >> 12) + ((cpuidData[1, 0] & 0xF0) >> 4); this.stepping = (cpuidData[1, 0] & 0x0F); switch (cpuVendor) { case "GenuineIntel": // check if processor supports a digital thermal sensor if (maxCPUID >= 6 && (cpuidData[6, 0] & 1) != 0) { hardware.Add(new IntelCPU(name, family, model, stepping, cpuidData, cpuidExtData)); } break; case "AuthenticAMD": // check if processor supports a digital thermal sensor if (maxCPUID_EXT >= 7 && (cpuidExtData[7, 3] & 1) != 0) { switch (family) { case 0x0F: hardware.Add(new AMD0FCPU(name, family, model, stepping, cpuidData, cpuidExtData)); break; case 0x10: hardware.Add(new AMD10CPU(name, family, model, stepping, cpuidData, cpuidExtData)); break; default: break; } } break; default: break; } } }
private byte ReadByte(byte register) { WinRing0.WriteIoPortByte( (ushort)(address + ADDRESS_REGISTER_OFFSET), register); return(WinRing0.ReadIoPortByte((ushort)(address + DATA_REGISTER_OFFSET))); }
public IntelCPU(string name, uint family, uint model, uint stepping, uint[,] cpuidData, uint[,] cpuidExtData) { this.name = name; this.icon = Utilities.EmbeddedResources.GetImage("cpu.png"); logicalProcessors = 0; if (cpuidData.GetLength(0) > 0x0B) { uint eax, ebx, ecx, edx; WinRing0.CpuidEx(0x0B, 0, out eax, out ebx, out ecx, out edx); logicalProcessorsPerCore = ebx & 0xFF; if (logicalProcessorsPerCore > 0) { WinRing0.CpuidEx(0x0B, 1, out eax, out ebx, out ecx, out edx); logicalProcessors = ebx & 0xFF; } } if (logicalProcessors <= 0 && cpuidData.GetLength(0) > 0x04) { logicalProcessors = ((cpuidData[4, 0] >> 26) & 0x3F) + 1; logicalProcessorsPerCore = 1; } if (logicalProcessors <= 0) { logicalProcessors = 1; logicalProcessorsPerCore = 1; } coreCount = logicalProcessors / logicalProcessorsPerCore; // check if processor supports a digital thermal sensor if (cpuidData.GetLength(0) > 6 && (cpuidData[6, 0] & 1) != 0) { switch (family) { case 0x06: { switch (model) { case 0x0F: // Intel Core 65nm switch (stepping) { case 0x06: // B2 switch (coreCount) { case 2: tjMax = 80; break; case 4: tjMax = 90; break; default: tjMax = 85; break; } tjMax = 80; break; case 0x0B: // G0 tjMax = 90; break; case 0x0D: // M0 tjMax = 85; break; default: tjMax = 85; break; } break; case 0x17: // Intel Core 45nm tjMax = 100; break; case 0x1C: // Intel Atom tjMax = 90; break; case 0x1A: uint eax = 0, edx = 0; if (WinRing0.RdmsrPx( IA32_TEMPERATURE_TARGET, ref eax, ref edx, (UIntPtr)1)) { tjMax = (eax >> 16) & 0xFF; } else { tjMax = 100; } break; default: tjMax = 100; break; } } break; default: tjMax = 100; break; } coreTemperatures = new Sensor[coreCount]; for (int i = 0; i < coreTemperatures.Length; i++) { coreTemperatures[i] = new Sensor("Core #" + (i + 1), i, tjMax, SensorType.Temperature, this); } } else { coreTemperatures = new Sensor[0]; } totalLoad = new Sensor("CPU Total", 0, SensorType.Load, this); coreLoads = new Sensor[coreCount]; for (int i = 0; i < coreLoads.Length; i++) { coreLoads[i] = new Sensor("Core #" + (i + 1), i + 1, SensorType.Load, this); } cpuLoad = new CPULoad(coreCount, logicalProcessorsPerCore); if (cpuLoad.IsAvailable) { foreach (Sensor sensor in coreLoads) { ActivateSensor(sensor); } ActivateSensor(totalLoad); } lastCount = 0; lastTime = 0; busClock = new Sensor("Bus Speed", 0, SensorType.Clock, this); coreClocks = new Sensor[coreCount]; for (int i = 0; i < coreClocks.Length; i++) { coreClocks[i] = new Sensor("Core #" + (i + 1), i + 1, SensorType.Clock, this); ActivateSensor(coreClocks[i]); } Update(); }
public void Update() { if (!WinRing0.WaitIsaBusMutex(10)) { return; } for (int i = 0; i < voltages.Length; i++) { int value = ReadByte((byte)(VOLTAGE_BASE_REG + i)); voltages[i] = 0.008f * value; } for (int i = 0; i < temperatures.Length; i++) { switch (chip) { case Chip.F71858: { int tableMode = 0x3 & ReadByte(TEMPERATURE_CONFIG_REG); int high = ReadByte((byte)(TEMPERATURE_BASE_REG + 2 * i)); int low = ReadByte((byte)(TEMPERATURE_BASE_REG + 2 * i + 1)); if (high != 0xbb && high != 0xcc) { int bits = 0; switch (tableMode) { case 0: bits = 0; break; case 1: bits = 0; break; case 2: bits = (high & 0x80) << 8; break; case 3: bits = (low & 0x01) << 15; break; } bits |= high << 7; bits |= (low & 0xe0) >> 1; short value = (short)(bits & 0xfff0); temperatures[i] = value / 128.0f; } else { temperatures[i] = null; } } break; default: { sbyte value = (sbyte)ReadByte((byte)( TEMPERATURE_BASE_REG + 2 * (i + 1))); if (value < sbyte.MaxValue && value > 0) { temperatures[i] = value; } else { temperatures[i] = null; } } break; } } for (int i = 0; i < fans.Length; i++) { int value = ReadByte(FAN_TACHOMETER_REG[i]) << 8; value |= ReadByte((byte)(FAN_TACHOMETER_REG[i] + 1)); if (value > 0) { fans[i] = (value < 0x0fff) ? 1.5e6f / value : 0; } else { fans[i] = null; } } WinRing0.ReleaseIsaBusMutex(); }
private void Select(byte logicalDeviceNumber) { WinRing0.WriteIoPortByte(registerPort, DEVCIE_SELECT_REGISTER); WinRing0.WriteIoPortByte(valuePort, logicalDeviceNumber); }
public void KeyUp(char key) { WinRing0.KeyUp(key);//松开 }
public IntelCPU(string name, uint family, uint model, uint stepping, uint[,] cpuidData, uint[,] cpuidExtData) { this.name = name; this.icon = Utilities.EmbeddedResources.GetImage("cpu.png"); this.family = family; this.model = model; this.stepping = stepping; logicalProcessors = 0; if (cpuidData.GetLength(0) > 0x0B) { uint eax, ebx, ecx, edx; WinRing0.CpuidEx(0x0B, 0, out eax, out ebx, out ecx, out edx); logicalProcessorsPerCore = ebx & 0xFF; if (logicalProcessorsPerCore > 0) { WinRing0.CpuidEx(0x0B, 1, out eax, out ebx, out ecx, out edx); logicalProcessors = ebx & 0xFF; } } if (logicalProcessors <= 0 && cpuidData.GetLength(0) > 0x04) { uint coresPerPackage = ((cpuidData[4, 0] >> 26) & 0x3F) + 1; uint logicalPerPackage = (cpuidData[1, 1] >> 16) & 0xFF; logicalProcessorsPerCore = logicalPerPackage / coresPerPackage; logicalProcessors = logicalPerPackage; } if (logicalProcessors <= 0 && cpuidData.GetLength(0) > 0x01) { uint logicalPerPackage = (cpuidData[1, 1] >> 16) & 0xFF; logicalProcessorsPerCore = logicalPerPackage; logicalProcessors = logicalPerPackage; } if (logicalProcessors <= 0) { logicalProcessors = 1; logicalProcessorsPerCore = 1; } IntPtr processMask, systemMask; GetProcessAffinityMask(Process.GetCurrentProcess().Handle, out processMask, out systemMask); affinityMask = (ulong)systemMask; // correct values in case HypeThreading is disabled if (logicalProcessorsPerCore > 1) { ulong affinity = affinityMask; int availableLogicalProcessors = 0; while (affinity != 0) { if ((affinity & 0x1) > 0) { availableLogicalProcessors++; } affinity >>= 1; } while (logicalProcessorsPerCore > 1 && availableLogicalProcessors < logicalProcessors) { logicalProcessors >>= 1; logicalProcessorsPerCore >>= 1; } } coreCount = logicalProcessors / logicalProcessorsPerCore; float[] tjMax; switch (family) { case 0x06: { switch (model) { case 0x0F: // Intel Core (65nm) switch (stepping) { case 0x06: // B2 switch (coreCount) { case 2: tjMax = Floats(80 + 10); break; case 4: tjMax = Floats(90 + 10); break; default: tjMax = Floats(85 + 10); break; } tjMax = Floats(80 + 10); break; case 0x0B: // G0 tjMax = Floats(90 + 10); break; case 0x0D: // M0 tjMax = Floats(85 + 10); break; default: tjMax = Floats(85 + 10); break; } break; case 0x17: // Intel Core (45nm) tjMax = Floats(100); break; case 0x1C: // Intel Atom tjMax = Floats(90); break; case 0x1A: // Intel Core i7 LGA1366 (45nm) case 0x1E: // Intel Core i5, i7 LGA1156 (45nm) case 0x25: // Intel Core i3, i5, i7 LGA1156 (32nm) uint eax, edx; tjMax = new float[coreCount]; for (int i = 0; i < coreCount; i++) { if (WinRing0.RdmsrTx(IA32_TEMPERATURE_TARGET, out eax, out edx, (UIntPtr)( 1 << (int)(logicalProcessorsPerCore * i)))) { tjMax[i] = (eax >> 16) & 0xFF; } else { tjMax[i] = 100; } } if (WinRing0.Rdmsr(MSR_PLATFORM_INFO, out eax, out edx)) { maxNehalemMultiplier = (eax >> 8) & 0xff; } break; default: tjMax = Floats(100); break; } } break; default: tjMax = Floats(100); break; } // check if processor supports a digital thermal sensor if (cpuidData.GetLength(0) > 6 && (cpuidData[6, 0] & 1) != 0) { coreTemperatures = new Sensor[coreCount]; for (int i = 0; i < coreTemperatures.Length; i++) { coreTemperatures[i] = new Sensor(CoreString(i), i, tjMax[i], SensorType.Temperature, this, new ParameterDescription[] { new ParameterDescription( "TjMax", "TjMax temperature of the core.\n" + "Temperature = TjMax - TSlope * Value.", tjMax[i]), new ParameterDescription( "TSlope", "Temperature slope of the digital thermal sensor.\n" + "Temperature = TjMax - TSlope * Value.", 1) }); } } else { coreTemperatures = new Sensor[0]; } if (coreCount > 1) { totalLoad = new Sensor("CPU Total", 0, SensorType.Load, this); } else { totalLoad = null; } coreLoads = new Sensor[coreCount]; for (int i = 0; i < coreLoads.Length; i++) { coreLoads[i] = new Sensor(CoreString(i), i + 1, SensorType.Load, this); } cpuLoad = new CPULoad(coreCount, logicalProcessorsPerCore); if (cpuLoad.IsAvailable) { foreach (Sensor sensor in coreLoads) { ActivateSensor(sensor); } if (totalLoad != null) { ActivateSensor(totalLoad); } } // check if processor has TSC if (cpuidData.GetLength(0) > 1 && (cpuidData[1, 3] & 0x10) != 0) { hasTSC = true; } else { hasTSC = false; } // check if processor supports invariant TSC if (cpuidExtData.GetLength(0) > 7 && (cpuidExtData[7, 3] & 0x100) != 0) { invariantTSC = true; } else { invariantTSC = false; } // preload the function EstimateMaxClock(0); EstimateMaxClock(0); // estimate the max clock in MHz estimatedMaxClock = 1e-6 * EstimateMaxClock(0.01); lastTimeStampCount = 0; lastTime = 0; busClock = new Sensor("Bus Speed", 0, SensorType.Clock, this); coreClocks = new Sensor[coreCount]; for (int i = 0; i < coreClocks.Length; i++) { coreClocks[i] = new Sensor(CoreString(i), i + 1, SensorType.Clock, this); if (hasTSC) { ActivateSensor(coreClocks[i]); } } Update(); }
public void KeyDown(char key) { WinRing0.KeyDown(key);//按下 }
public bool Initialize(EnumWindowsType winType) { return(WinRing0.init()); }
public AMD0FCPU(int processorIndex, CPUID[][] cpuid) { this.processorIndex = processorIndex; this.name = cpuid[0][0].Name; this.icon = Utilities.EmbeddedResources.GetImage("cpu.png"); int coreCount = cpuid.Length; totalLoad = new Sensor("CPU Total", 0, SensorType.Load, this); float offset = -49.0f; // AM2+ 65nm +21 offset uint model = cpuid[0][0].Model; if (model >= 0x69 && model != 0xc1 && model != 0x6c && model != 0x7c) { offset += 21; } // check if processor supports a digital thermal sensor if (cpuid[0][0].ExtData.GetLength(0) > 7 && (cpuid[0][0].ExtData[7, 3] & 1) != 0) { coreTemperatures = new Sensor[coreCount]; for (int i = 0; i < coreCount; i++) { coreTemperatures[i] = new Sensor("Core #" + (i + 1), i, null, SensorType.Temperature, this, new ParameterDescription[] { new ParameterDescription("Offset", "Temperature offset of the thermal sensor.\n" + "Temperature = Value + Offset.", offset) }); } } else { coreTemperatures = new Sensor[0]; } coreLoads = new Sensor[coreCount]; for (int i = 0; i < coreCount; i++) { coreLoads[i] = new Sensor("Core #" + (i + 1), i + 1, SensorType.Load, this); } cpuLoad = new CPULoad(cpuid); if (cpuLoad.IsAvailable) { foreach (Sensor sensor in coreLoads) { ActivateSensor(sensor); } ActivateSensor(totalLoad); } pciAddress = WinRing0.FindPciDeviceById(PCI_AMD_VENDOR_ID, PCI_AMD_0FH_MISCELLANEOUS_DEVICE_ID, (byte)processorIndex); Update(); }
private void SMSCExit() { WinRing0.WriteIoPortByte(registerPort, 0xAA); }
public CPUID(int thread) { this.thread = thread; uint eax, ebx, ecx, edx; UIntPtr mask = (UIntPtr)(1L << thread); if (WinRing0.CpuidTx(CPUID_0, 0, out eax, out ebx, out ecx, out edx, mask)) { maxCpuid = eax; StringBuilder vendorBuilder = new StringBuilder(); AppendRegister(vendorBuilder, ebx); AppendRegister(vendorBuilder, edx); AppendRegister(vendorBuilder, ecx); string cpuVendor = vendorBuilder.ToString(); switch (cpuVendor) { case "GenuineIntel": vendor = Vendor.Intel; break; case "AuthenticAMD": vendor = Vendor.AMD; break; default: vendor = Vendor.Unknown; break; } eax = ebx = ecx = edx = 0; if (WinRing0.CpuidTx(CPUID_EXT, 0, out eax, out ebx, out ecx, out edx, mask)) { maxCpuidExt = eax - CPUID_EXT; } } else { throw new ArgumentException(); } if (maxCpuid == 0 || maxCpuidExt == 0) { return; } cpuidData = new uint[maxCpuid + 1, 4]; for (uint i = 0; i < (maxCpuid + 1); i++) { WinRing0.CpuidTx(CPUID_0 + i, 0, out cpuidData[i, 0], out cpuidData[i, 1], out cpuidData[i, 2], out cpuidData[i, 3], mask); } cpuidExtData = new uint[maxCpuidExt + 1, 4]; for (uint i = 0; i < (maxCpuidExt + 1); i++) { WinRing0.CpuidTx(CPUID_EXT + i, 0, out cpuidExtData[i, 0], out cpuidExtData[i, 1], out cpuidExtData[i, 2], out cpuidExtData[i, 3], mask); } StringBuilder nameBuilder = new StringBuilder(); for (uint i = 2; i <= 4; i++) { if (WinRing0.CpuidTx(CPUID_EXT + i, 0, out eax, out ebx, out ecx, out edx, mask)) { AppendRegister(nameBuilder, eax); AppendRegister(nameBuilder, ebx); AppendRegister(nameBuilder, ecx); AppendRegister(nameBuilder, edx); } } nameBuilder.Replace('\0', ' '); cpuBrandString = nameBuilder.ToString().Trim(); nameBuilder.Replace("(R)", " "); nameBuilder.Replace("(TM)", " "); nameBuilder.Replace("(tm)", " "); nameBuilder.Replace("CPU", ""); for (int i = 0; i < 10; i++) { nameBuilder.Replace(" ", " "); } name = nameBuilder.ToString(); if (name.Contains("@")) { name = name.Remove(name.LastIndexOf('@')); } name = name.Trim(); this.family = ((cpuidData[1, 0] & 0x0FF00000) >> 20) + ((cpuidData[1, 0] & 0x0F00) >> 8); this.model = ((cpuidData[1, 0] & 0x0F0000) >> 12) + ((cpuidData[1, 0] & 0xF0) >> 4); this.stepping = (cpuidData[1, 0] & 0x0F); this.apicId = (cpuidData[1, 1] >> 24) & 0xFF; switch (vendor) { case Vendor.Intel: uint maxCoreAndThreadIdPerPackage = (cpuidData[1, 1] >> 16) & 0xFF; uint maxCoreIdPerPackage; if (maxCpuid >= 4) { maxCoreIdPerPackage = ((cpuidData[4, 0] >> 26) & 0x3F) + 1; } else { maxCoreIdPerPackage = 1; } threadMaskWith = (uint)Math.Ceiling(Math.Log( maxCoreAndThreadIdPerPackage / maxCoreIdPerPackage, 2)); coreMaskWith = (uint)Math.Ceiling(Math.Log(maxCoreIdPerPackage, 2)); break; case Vendor.AMD: uint corePerPackage; if (maxCpuidExt >= 8) { corePerPackage = (cpuidExtData[8, 2] & 0xFF) + 1; } else { corePerPackage = 1; } threadMaskWith = 0; coreMaskWith = (uint)Math.Ceiling(Math.Log(corePerPackage, 2)); break; default: threadMaskWith = 0; coreMaskWith = 0; break; } processorId = (uint)(apicId >> (int)(coreMaskWith + threadMaskWith)); coreId = (uint)((apicId >> (int)(threadMaskWith)) - (processorId << (int)(coreMaskWith))); threadId = apicId - (processorId << (int)(coreMaskWith + threadMaskWith)) - (coreId << (int)(threadMaskWith)); }
private byte ReadByte(byte register) { WinRing0.WriteIoPortByte(registerPort, register); return(WinRing0.ReadIoPortByte(valuePort)); }
public IntelCPU(string name, uint family, uint model, uint stepping, uint[,] cpuidData, uint[,] cpuidExtData) { this.name = name; this.icon = Utilities.EmbeddedResources.GetImage("cpu.png"); this.family = family; this.model = model; this.stepping = stepping; logicalProcessors = 0; if (cpuidData.GetLength(0) > 0x0B) { uint eax, ebx, ecx, edx; WinRing0.CpuidEx(0x0B, 0, out eax, out ebx, out ecx, out edx); logicalProcessorsPerCore = ebx & 0xFF; if (logicalProcessorsPerCore > 0) { WinRing0.CpuidEx(0x0B, 1, out eax, out ebx, out ecx, out edx); logicalProcessors = ebx & 0xFF; } } if (logicalProcessors <= 0 && cpuidData.GetLength(0) > 0x04) { uint coresPerPackage = ((cpuidData[4, 0] >> 26) & 0x3F) + 1; uint logicalPerPackage = (cpuidData[1, 1] >> 16) & 0xFF; logicalProcessorsPerCore = logicalPerPackage / coresPerPackage; logicalProcessors = logicalPerPackage; } if (logicalProcessors <= 0 && cpuidData.GetLength(0) > 0x01) { uint logicalPerPackage = (cpuidData[1, 1] >> 16) & 0xFF; logicalProcessorsPerCore = logicalPerPackage; logicalProcessors = logicalPerPackage; } if (logicalProcessors <= 0) { logicalProcessors = 1; logicalProcessorsPerCore = 1; } coreCount = logicalProcessors / logicalProcessorsPerCore; switch (family) { case 0x06: { switch (model) { case 0x0F: // Intel Core (65nm) switch (stepping) { case 0x06: // B2 switch (coreCount) { case 2: tjMax = 80; break; case 4: tjMax = 90; break; default: tjMax = 85; break; } tjMax = 80; break; case 0x0B: // G0 tjMax = 90; break; case 0x0D: // M0 tjMax = 85; break; default: tjMax = 85; break; } break; case 0x17: // Intel Core (45nm) tjMax = 100; break; case 0x1C: // Intel Atom tjMax = 90; break; case 0x1A: // Intel Core i7 LGA1366 (45nm) case 0x1E: // Intel Core i5, i7 LGA1156 (45nm) case 0x25: // Intel Core i3, i5, i7 LGA1156 (32nm) uint eax, edx; if (WinRing0.Rdmsr(IA32_TEMPERATURE_TARGET, out eax, out edx)) { tjMax = (eax >> 16) & 0xFF; } else { tjMax = 100; } if (WinRing0.Rdmsr(MSR_PLATFORM_INFO, out eax, out edx)) { maxNehalemMultiplier = (eax >> 8) & 0xff; } break; default: tjMax = 100; break; } } break; default: tjMax = 100; break; } // check if processor supports a digital thermal sensor if (cpuidData.GetLength(0) > 6 && (cpuidData[6, 0] & 1) != 0) { coreTemperatures = new Sensor[coreCount]; for (int i = 0; i < coreTemperatures.Length; i++) { coreTemperatures[i] = new Sensor(CoreString(i), i, tjMax, SensorType.Temperature, this); } } else { coreTemperatures = new Sensor[0]; } if (coreCount > 1) { totalLoad = new Sensor("CPU Total", 0, SensorType.Load, this); } else { totalLoad = null; } coreLoads = new Sensor[coreCount]; for (int i = 0; i < coreLoads.Length; i++) { coreLoads[i] = new Sensor(CoreString(i), i + 1, SensorType.Load, this); } cpuLoad = new CPULoad(coreCount, logicalProcessorsPerCore); if (cpuLoad.IsAvailable) { foreach (Sensor sensor in coreLoads) { ActivateSensor(sensor); } if (totalLoad != null) { ActivateSensor(totalLoad); } } lastCount = 0; lastTime = 0; busClock = new Sensor("Bus Speed", 0, SensorType.Clock, this); coreClocks = new Sensor[coreCount]; for (int i = 0; i < coreClocks.Length; i++) { coreClocks[i] = new Sensor(CoreString(i), i + 1, SensorType.Clock, this); ActivateSensor(coreClocks[i]); } Update(); }
internal void IT87Exit() { WinRing0.WriteIoPortByte(registerPort, CONFIGURATION_CONTROL_REGISTER); WinRing0.WriteIoPortByte(valuePort, 0x02); }
public IntelCPU(int processorIndex, CPUID[][] cpuid) { this.processorIndex = processorIndex; this.cpuid = cpuid; this.coreCount = cpuid.Length; this.name = cpuid[0][0].Name; this.icon = Utilities.EmbeddedResources.GetImage("cpu.png"); this.family = cpuid[0][0].Family; this.model = cpuid[0][0].Model; this.stepping = cpuid[0][0].Stepping; float[] tjMax; switch (family) { case 0x06: { switch (model) { case 0x0F: // Intel Core (65nm) switch (stepping) { case 0x06: // B2 switch (coreCount) { case 2: tjMax = Floats(80 + 10); break; case 4: tjMax = Floats(90 + 10); break; default: tjMax = Floats(85 + 10); break; } tjMax = Floats(80 + 10); break; case 0x0B: // G0 tjMax = Floats(90 + 10); break; case 0x0D: // M0 tjMax = Floats(85 + 10); break; default: tjMax = Floats(85 + 10); break; } break; case 0x17: // Intel Core (45nm) tjMax = Floats(100); break; case 0x1C: // Intel Atom (45nm) switch (stepping) { case 0x02: // C0 tjMax = Floats(90); break; case 0x0A: // A0, B0 tjMax = Floats(100); break; default: tjMax = Floats(90); break; } break; case 0x1A: // Intel Core i7 LGA1366 (45nm) case 0x1E: // Intel Core i5, i7 LGA1156 (45nm) case 0x25: // Intel Core i3, i5, i7 LGA1156 (32nm) case 0x2C: // Intel Core i7 LGA1366 (32nm) 6 Core uint eax, edx; tjMax = new float[coreCount]; for (int i = 0; i < coreCount; i++) { if (WinRing0.RdmsrTx(IA32_TEMPERATURE_TARGET, out eax, out edx, (UIntPtr)(1L << cpuid[i][0].Thread))) { tjMax[i] = (eax >> 16) & 0xFF; } else { tjMax[i] = 100; } } if (WinRing0.Rdmsr(MSR_PLATFORM_INFO, out eax, out edx)) { maxNehalemMultiplier = (eax >> 8) & 0xff; } break; default: tjMax = Floats(100); break; } } break; default: tjMax = Floats(100); break; } // check if processor supports a digital thermal sensor if (cpuid[0][0].Data.GetLength(0) > 6 && (cpuid[0][0].Data[6, 0] & 1) != 0) { coreTemperatures = new Sensor[coreCount]; for (int i = 0; i < coreTemperatures.Length; i++) { coreTemperatures[i] = new Sensor(CoreString(i), i, tjMax[i], SensorType.Temperature, this, new ParameterDescription[] { new ParameterDescription( "TjMax [°C]", "TjMax temperature of the core.\n" + "Temperature = TjMax - TSlope * Value.", tjMax[i]), new ParameterDescription("TSlope [°C]", "Temperature slope of the digital thermal sensor.\n" + "Temperature = TjMax - TSlope * Value.", 1) }); } } else { coreTemperatures = new Sensor[0]; } if (coreCount > 1) { totalLoad = new Sensor("CPU Total", 0, SensorType.Load, this); } else { totalLoad = null; } coreLoads = new Sensor[coreCount]; for (int i = 0; i < coreLoads.Length; i++) { coreLoads[i] = new Sensor(CoreString(i), i + 1, SensorType.Load, this); } cpuLoad = new CPULoad(cpuid); if (cpuLoad.IsAvailable) { foreach (Sensor sensor in coreLoads) { ActivateSensor(sensor); } if (totalLoad != null) { ActivateSensor(totalLoad); } } // check if processor has TSC if (cpuid[0][0].Data.GetLength(0) > 1 && (cpuid[0][0].Data[1, 3] & 0x10) != 0) { hasTSC = true; } else { hasTSC = false; } // check if processor supports invariant TSC if (cpuid[0][0].ExtData.GetLength(0) > 7 && (cpuid[0][0].ExtData[7, 3] & 0x100) != 0) { invariantTSC = true; } else { invariantTSC = false; } // preload the function EstimateMaxClock(0); EstimateMaxClock(0); // estimate the max clock in MHz List <double> estimatedMaxClocks = new List <double>(3); for (int i = 0; i < 3; i++) { estimatedMaxClocks.Add(1e-6 * EstimateMaxClock(0.025)); } estimatedMaxClocks.Sort(); estimatedMaxClock = estimatedMaxClocks[1]; lastTimeStampCount = 0; lastTime = 0; busClock = new Sensor("Bus Speed", 0, SensorType.Clock, this); coreClocks = new Sensor[coreCount]; for (int i = 0; i < coreClocks.Length; i++) { coreClocks[i] = new Sensor(CoreString(i), i + 1, SensorType.Clock, this); if (hasTSC) { ActivateSensor(coreClocks[i]); } } Update(); }
private void WinbondFintekEnter() { WinRing0.WriteIoPortByte(registerPort, 0x87); WinRing0.WriteIoPortByte(registerPort, 0x87); }
public void Update() { for (int i = 0; i < coreTemperatures.Length; i++) { uint eax = 0, edx = 0; if (WinRing0.RdmsrPx( IA32_THERM_STATUS_MSR, ref eax, ref edx, (UIntPtr)(1 << (int)(logicalProcessorsPerCore * i)))) { // if reading is valid if ((eax & 0x80000000) != 0) { // get the dist from tjMax from bits 22:16 coreTemperatures[i].Value = tjMax - ((eax & 0x007F0000) >> 16); ActivateSensor(coreTemperatures[i]); } else { DeactivateSensor(coreTemperatures[i]); } } } if (cpuLoad.IsAvailable) { cpuLoad.Update(); for (int i = 0; i < coreLoads.Length; i++) { coreLoads[i].Value = cpuLoad.GetCoreLoad(i); } totalLoad.Value = cpuLoad.GetTotalLoad(); } uint lsb = 0, msb = 0; bool valid = WinRing0.RdtscPx(ref lsb, ref msb, (UIntPtr)1); long time = Stopwatch.GetTimestamp(); ulong count = ((ulong)msb << 32) | lsb; double delta = ((double)(time - lastTime)) / Stopwatch.Frequency; if (valid && delta > 0.5) { double maxClock = (float)((count - lastCount) / (1e6 * delta)); double busClock = 0; uint eax, edx; for (int i = 0; i < coreClocks.Length; i++) { eax = 0; edx = 0; System.Threading.Thread.Sleep(1); if (WinRing0.RdmsrPx(IA32_PERF_STATUS, ref eax, ref edx, (UIntPtr)(1 << (int)(logicalProcessorsPerCore * i)))) { uint multiplier = (eax >> 8) & 0x1f; uint maxMultiplier = (edx >> 8) & 0x1f; // factor = multiplier * 2 to handle non integer multipliers uint factor = (multiplier << 1) | ((eax >> 14) & 1); uint maxFactor = (maxMultiplier << 1) | ((edx >> 14) & 1); if (maxFactor > 0) { coreClocks[i].Value = (float)(factor * maxClock / maxFactor); busClock = (float)(2 * maxClock / maxFactor); } } else { // if IA32_PERF_STATUS is not available, assume maxClock coreClocks[i].Value = (float)maxClock; } } if (busClock > 0) { this.busClock.Value = (float)busClock; ActivateSensor(this.busClock); } } lastCount = count; lastTime = time; }