Exemplo n.º 1
0
        private void InitializePowerSensors()
        {
            _energyUnitMultiplier = 0f;
            uint eax = 0, edx = 0;

            if (Msr.Read(MsrRaplPowerUnit, ref eax, ref edx))
            {
                switch (Cpu.Microarchitecture)
                {
                case MicroArchitecture.Silvermont:
                case MicroArchitecture.Airmont:
                    _energyUnitMultiplier = 1.0e-6f * (1 << (int)((eax >> 8) & 0x1F));
                    break;

                default:
                    _energyUnitMultiplier = 1.0f / (1 << (int)((eax >> 8) & 0x1F));
                    break;
                }
            }

            if (_energyUnitMultiplier != 0)
            {
                _powerSensors[0] = new SensorElementIntelCpuPower("package", MsrPkgEneryStatus);
                _powerSensors[1] = new SensorElementIntelCpuPower("cores", MsrPp0EneryStatus);
                _powerSensors[2] = new SensorElementIntelCpuPower("graphics", MsrPp1EneryStatus);
                _powerSensors[3] = new SensorElementIntelCpuPower("dram", MsrDramEnergyStatus);
            }
        }
Exemplo n.º 2
0
        public SensorElementIntelCpuPower(string id, uint powerType)
        {
            _powerNameId  = id;
            _powerTypeMsr = powerType;

            uint eax = 0, edx = 0;

            if (!Msr.Read(_powerTypeMsr, ref eax, ref edx))
            {
                SetActive(false);
                return;
            }

            _lastEnergyTime     = DateTime.UtcNow;
            _lastEnergyConsumed = eax;
            SetActive(true);
        }
Exemplo n.º 3
0
        public override void Update(float energyUnitMultiplier)
        {
            uint eax = 0, edx = 0;

            if (!Msr.Read(_powerTypeMsr, ref eax, ref edx))
            {
                return;
            }

            var time           = DateTime.UtcNow;
            var energyConsumed = eax;
            var deltaTime      = (float)(time - _lastEnergyTime).TotalSeconds;

            if (deltaTime < 0.01)
            {
                return;
            }

            Value               = energyUnitMultiplier *unchecked (energyConsumed - _lastEnergyConsumed) / deltaTime;
            _lastEnergyTime     = time;
            _lastEnergyConsumed = energyConsumed;
            AfterUpdate();
        }
Exemplo n.º 4
0
        private void DetectTimeStampCounterMultiper()
        {
            switch (Microarchitecture)
            {
            case MicroArchitecture.NetBurst:
            case MicroArchitecture.Atom:
            case MicroArchitecture.Core: {
                uint eax = 0, edx = 0;
                if (Msr.Read(Ia32PerfStatus, ref eax, ref edx))
                {
                    TimeStampCounterMultiper = ((edx >> 8) & 0x1f) + 0.5 * ((edx >> 14) & 1);
                }
            }
            break;

            case MicroArchitecture.Nehalem:
            case MicroArchitecture.SandyBridge:
            case MicroArchitecture.IvyBridge:
            case MicroArchitecture.Haswell:
            case MicroArchitecture.Broadwell:
            case MicroArchitecture.Silvermont:
            case MicroArchitecture.Skylake:
            case MicroArchitecture.Airmont:
            case MicroArchitecture.KabyLake: {
                uint eax = 0, edx = 0;
                if (Msr.Read(MsrPlatformInfo, ref eax, ref edx))
                {
                    TimeStampCounterMultiper = (eax >> 8) & 0xff;
                }
            }
            break;

            default:
                TimeStampCounterMultiper = 0;
                break;
            }
        }