Beispiel #1
0
        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;

            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;
            }

            totalLoad = new Sensor("CPU Total", 0, SensorType.Load, this);

            coreTemperatures = new Sensor[coreCount];
            coreLoads        = new Sensor[coreCount];
            for (int i = 0; i < coreTemperatures.Length; i++)
            {
                coreTemperatures[i] = new Sensor("Core #" + (i + 1), i, tjMax,
                                                 SensorType.Temperature, this);
                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);
            }

            Update();
        }
        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)
            {
                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: // Intel Core i7
                    case 0x1E: // Intel Core i5
                        uint eax, edx;
                        if (WinRing0.Rdmsr(IA32_TEMPERATURE_TARGET, out eax, out edx))
                        {
                            tjMax = (eax >> 16) & 0xFF;
                        }
                        else
                        {
                            tjMax = 100;
                        }
                        break;

                    default:
                        tjMax = 100; break;
                    }
                } break;

                default: tjMax = 100; break;
                }

                if (family == 0x06 && model >= 0x1A) // Core i5, i7
                {
                    uint eax, edx;
                    if (WinRing0.Rdmsr(MSR_PLATFORM_INFO, out eax, out edx))
                    {
                        maxNehalemMultiplier = (eax >> 8) & 0xff;
                    }
                }

                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();
        }
Beispiel #3
0
        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 = 80 + 10; break;

                        case 4:
                            tjMax = 90 + 10; break;

                        default:
                            tjMax = 85 + 10; break;
                        }
                        tjMax = 80 + 10; break;

                    case 0x0B: // G0
                        tjMax = 90 + 10; break;

                    case 0x0D: // M0
                        tjMax = 85 + 10; break;

                    default:
                        tjMax = 85 + 10; 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, new ParameterDescription[] {
                        new ParameterDescription(
                            "TjMax", "TjMax temperature of the core.\n" +
                            "Temperature = TjMax - TSlope * Value.", tjMax),
                        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);
                }
            }

            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();
        }