Exemple #1
0
        public void Update()
        {
            uint eax = 0, edx = 0;

            for (int i = 0; i < coreTemperatures.Length; i++)
            {
                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();
            }
        }
        public void Update()
        {
            if (pciAddress != 0xFFFFFFFF)
            {
                uint value;
                if (WinRing0.ReadPciConfigDwordEx(pciAddress,
                                                  REPORTED_TEMPERATURE_CONTROL_REGISTER, out value))
                {
                    coreTemperature.Value = ((value >> 21) & 0x7FF) / 8.0f;
                    ActivateSensor(coreTemperature);
                }
                else
                {
                    DeactivateSensor(coreTemperature);
                }
            }

            if (cpuLoad.IsAvailable)
            {
                cpuLoad.Update();
                for (int i = 0; i < coreLoads.Length; i++)
                {
                    coreLoads[i].Value = cpuLoad.GetCoreLoad(i);
                }
                totalLoad.Value = cpuLoad.GetTotalLoad();
            }
        }
        public void Update()
        {
            if (pciAddress != 0xFFFFFFFF)
            {
                for (uint i = 0; i < coreTemperatures.Length; i++)
                {
                    if (WinRing0.WritePciConfigDwordEx(
                            pciAddress, THERMTRIP_STATUS_REGISTER,
                            i > 0 ? THERM_SENSE_CORE_SEL_CPU1 : THERM_SENSE_CORE_SEL_CPU0))
                    {
                        uint value;
                        if (WinRing0.ReadPciConfigDwordEx(
                                pciAddress, THERMTRIP_STATUS_REGISTER, out value))
                        {
                            coreTemperatures[i].Value = ((value >> 16) & 0xFF) + offset;
                            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();
            }
        }
Exemple #4
0
        public override void Update()
        {
            if (sensorConfig.GetSensorEvaluate(totalLoad.IdentifierString) ||
                sensorConfig.GetSensorEvaluate(maxLoad.IdentifierString) ||
                coreLoads.Any(sensor => sensorConfig.GetSensorEvaluate(sensor.IdentifierString)))
            {
                if (HasTimeStampCounter && isInvariantTimeStampCounter)
                {
                    // make sure always the same thread is used
                    var previousAffinity = ThreadAffinity.Set(cpuid[0][0].Affinity);

                    // read time before and after getting the TSC to estimate the error
                    long  firstTime      = Stopwatch.GetTimestamp();
                    ulong timeStampCount = Opcode.Rdtsc();
                    long  time           = Stopwatch.GetTimestamp();

                    // restore the thread affinity mask
                    ThreadAffinity.Set(previousAffinity);

                    double delta = ((double)(time - lastTime)) / Stopwatch.Frequency;
                    double error = ((double)(time - firstTime)) / Stopwatch.Frequency;

                    // only use data if they are measured accuarte enough (max 0.1ms delay)
                    if (error < 1E-04)
                    {
                        // ignore the first reading because there are no initial values
                        // ignore readings with too large or too small time window
                        if (lastTime != 0 && delta > 0.5 && delta < 2)
                        {
                            // update the TSC frequency with the new value
                            TimeStampCounterFrequency =
                                (timeStampCount - lastTimeStampCount) / (1e6 * delta);
                        }

                        lastTimeStampCount = timeStampCount;
                        lastTime           = time;
                    }
                }
            }

            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 (maxLoad != null)
                {
                    maxLoad.Value = cpuLoad.GetMaxLoad();
                }
            }
        }
        public override void Update()
        {
            if (HasTimeStampCounter && isInvariantTimeStampCounter)
            {
                // make sure always the same thread is used
                var mask = ThreadAffinity.Set(1UL << cpuid[0][0].Thread);

                // read time before and after getting the TSC to estimate the error
                var firstTime      = Stopwatch.GetTimestamp();
                var timeStampCount = Opcode.Rdtsc();
                var time           = Stopwatch.GetTimestamp();

                // restore the thread affinity mask
                ThreadAffinity.Set(mask);

                var delta = ((double)(time - lastTime)) / Stopwatch.Frequency;
                var error = ((double)(time - firstTime)) / Stopwatch.Frequency;

                // only use data if they are measured accuarte enough (max 0.1ms delay)
                if (error < 0.0001)
                {
                    // ignore the first reading because there are no initial values
                    // ignore readings with too large or too small time window
                    if (lastTime != 0 && delta > 0.5 && delta < 2)
                    {
                        // update the TSC frequency with the new value
                        TimeStampCounterFrequency =
                            (timeStampCount - lastTimeStampCount) / (1e6 * delta);
                    }

                    lastTimeStampCount = timeStampCount;
                    lastTime           = time;
                }
            }

            if (cpuLoad.IsAvailable)
            {
                cpuLoad.Update();
                for (var i = 0; i < coreLoads.Length; i++)
                {
                    coreLoads[i].Value = cpuLoad.GetCoreLoad(i);
                }
                if (totalLoad != null)
                {
                    totalLoad.Value = cpuLoad.GetTotalLoad();
                }
            }
        }
Exemple #6
0
        public override void Update()
        {
            if (hasTimeStampCounter)
            {
                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)
                {
                    if (isInvariantTimeStampCounter)
                    {
                        timeStampCounterFrequency =
                            (timeStampCount - lastTimeStampCount) / (1e6 * delta);
                    }
                    else
                    {
                        timeStampCounterFrequency = estimatedTimeStampCounterFrequency;
                    }

                    lastTimeStampCount = timeStampCount;
                    lastTime           = time;
                }
            }

            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();
                }
            }
        }
        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 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)(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, msb;
            bool   valid = WinRing0.RdtscTx(out lsb, out 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 = (count - lastCount) / (1e6 * delta);
                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)(1 << (int)(logicalProcessorsPerCore * i))))
                    {
                        if (model < 0x1A) // 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 // Core i5, i7
                        {
                            uint nehalemMultiplier = eax & 0xff;
                            if (maxNehalemMultiplier > 0)
                            {
                                coreClocks[i].Value =
                                    (float)(nehalemMultiplier * maxClock / maxNehalemMultiplier);
                                busClock = (float)(maxClock / maxNehalemMultiplier);
                            }
                        }
                    }
                    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);
                }
            }
            lastCount = count;
            lastTime  = time;
        }