private void OnCardReadAction(Msr myMsr) { if (OnCardReadEvent != null) { OnCardReadEvent(myMsr); } }
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); } }
public override void TickSpecificLoad(CpuidProcessorInfo info) { var tscSupport = info.IsTimeStampCounterSupported && info.TimeStampCounterFrequency > 0; double newBusClock = 0; foreach (var coreFrequencySensor in _coreFrequenciesSensors) { coreFrequencySensor.SetActive(tscSupport); if (!tscSupport) { continue; } uint eax = 0, edx = 0; if (Msr.ReadTx(IntelCpu.Ia32PerfStatus, ref eax, ref edx, (UIntPtr)(1UL << (int)Cpu.GetCpuidProcessorInfo()[0, 0].ThreadIndex))) { newBusClock = Cpu.GetCpuidProcessorInfo().TimeStampCounterFrequency / Cpu.TimeStampCounterMultiper; switch (Cpu.Microarchitecture) { case MicroArchitecture.Nehalem: { var multiplier = eax & 0xff; coreFrequencySensor.Update((float)(multiplier * newBusClock)); } break; case MicroArchitecture.SandyBridge: case MicroArchitecture.IvyBridge: case MicroArchitecture.Haswell: case MicroArchitecture.Broadwell: case MicroArchitecture.Silvermont: case MicroArchitecture.Skylake: { var multiplier = (eax >> 8) & 0xff; coreFrequencySensor.Update((float)(multiplier * newBusClock)); } break; default: { var multiplier = ((eax >> 8) & 0x1f) + 0.5 * ((eax >> 14) & 1); coreFrequencySensor.Update((float)(multiplier * newBusClock)); } break; } } else { // If IA32_PERF_STATUS is not available, assume TSC frequency coreFrequencySensor.Update((float)Cpu.GetCpuidProcessorInfo().TimeStampCounterFrequency); } } if (newBusClock > 0) { _baseClock.Update((float)newBusClock); } _baseClock.SetActive(newBusClock > 0); IsSensorActive = newBusClock > 0; }
public override void SetOpened(bool opened) { if (_msr == null) { _msr = (Msr)PosCommon; _msr.DataEvent += new DataEventHandler(_msr_DataEvent); _msr.ErrorEvent += new DeviceErrorEventHandler(_msr_ErrorEvent); } if (opened) UpdateUI(); }
public MsrWrapper(Msr pMsr) //string pDeviceName, PosExplorer explorer) { this.msr = pMsr; // Load MSR Filters PosContext.Instance.MsrFilters = new Filters( 1); //this.deviceName = pDeviceName; //posExplorer = explorer; // System.Resources.ResourceManager resources = new System.Resources.ResourceManager("EclipsePos.Hardware.LineDisplayWrapper", Assembly.GetExecutingAssembly()); // healthText = resources.GetString("HealthText"); // Open(); }
public override void SetOpened(bool opened) { if (_msr == null) { _msr = (Msr)PosCommon; _msr.DataEvent += new DataEventHandler(_msr_DataEvent); _msr.ErrorEvent += new DeviceErrorEventHandler(_msr_ErrorEvent); } if (opened) { UpdateUI(); } }
void myExplorer_DeviceAddedEvent(object sender, DeviceChangedEventArgs e) { if (e.Device.Type == "Msr") { myMsr = (Msr)myExplorer.CreateInstance(e.Device); myMsr.Open(); myMsr.Claim(1000); myMsr.DeviceEnabled = true; myMsr.DataEventEnabled = true; myMsr.DecodeData = true; // Update(); myMsr.DataEvent += new DataEventHandler(myMsr_DataEvent); } }
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); }
public void Disconnect() { if (myMsr != null) { try { myMsr.Close(); } catch (PosException) { } finally { myMsr = null; } } }
/// <summary> /// Connect to Msr Device and Get Card Data. /// </summary> public void Connect() { myExplorer = new PosExplorer(); DeviceInfo device = myExplorer.GetDevice("Msr", "MagTekMSR_Encrypted"); //device= myExplorer.GetDevices()[0]; /// <summary> /// To check if device found or not /// </summary> if (device != null) { Disconnect(); myMsr = (Msr)myExplorer.CreateInstance(device); try { myMsr.Open(); if (myMsr.Claimed == false) { myMsr.Claim(1000); } myMsr.DeviceEnabled = true; } catch { } myMsr.DataEventEnabled = true; myMsr.DecodeData = true; myMsr.DataEvent += new DataEventHandler(myMsr_DataEvent); } else { throw new Exception("pos device not founded"); //return; } myExplorer.DeviceAddedEvent += new DeviceChangedEventHandler(myExplorer_DeviceAddedEvent); myExplorer.DeviceRemovedEvent += new DeviceChangedEventHandler(myExplorer_DeviceRemovedEvent); //myMsr.DataEvent += new DataEventHandler(myMsr_DataEvent); }
private float[] GetTjMaxFromMsr() { uint eax = 0, edx = 0; var result = new float[ThreadsCount]; for (uint i = 0; i < ThreadsCount; i++) { if (Msr.ReadTx(Ia32TemperatureTarget, ref eax, ref edx, (UIntPtr)(1UL << (int)i))) { result[i] = (eax >> 16) & 0xFF; } else { result[i] = 100; } } return(result); }
public override void Update(IntelCpu cpu) { uint eax = 0, edx = 0; if (Msr.ReadTx(Ia32PackageThermStatus, ref eax, ref edx, (UIntPtr)(1UL << 0)) && (eax & 0x80000000) != 0) { // From tjMax from at bits 22 -> 16 float deltaT = ((eax & 0x007F0000) >> 16); var tjMax = cpu.GetTjMaxOfThreadAt(0); const float tSlope = 1; Value = tjMax - tSlope * deltaT; SetActive(true); } else { Value = -1; SetActive(false); } AfterUpdate(); }
public override void Update(IntelCpu cpu) { uint eax = 0, edx = 0; if (Msr.ReadTx(Ia32ThermStatusMsr, ref eax, ref edx, _threadMask) && (eax & 0x80000000) != 0) { // From tjMax from at bits 22 -> 16 float deltaT = (eax & 0x007F0000) >> 16; var tjMax = cpu.GetTjMaxOfThreadAt(_threadIndex); const float tSlope = 1; Value = tjMax - tSlope * deltaT; SetActive(true); } else { Value = -1; SetActive(false); } AfterUpdate(); }
void myExplorer_DeviceRemovedEvent(object sender, DeviceChangedEventArgs e) { if (e.Device.Type == "Msr") { try { myMsr.DataEventEnabled = false; myMsr.DeviceEnabled = false; myMsr.Release(); myMsr.Close(); myMsr = null; } catch { } finally { myMsr = null; } } }
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(); }
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; } }
private void ThreadMethod() { HidMsr Msr; IntPtr UnmanagedBuffer = IntPtr.Zero; ManualResetEvent IOComplete = null; try { // Allocate a buffer in unmanaged memory so the garbage collector won't // move it around while we're waiting for async input. Since this is // allocated on the unmanaged heap we must free it before the function returns. UnmanagedBuffer = Marshal.AllocHGlobal(InputReportByteLength); IOComplete = new ManualResetEvent(false); byte[] MsrData = new byte[InputReportByteLength]; NativeMethods.OVERLAPPED Overlapped = new NativeMethods.OVERLAPPED(); Overlapped.Offset = 0; Overlapped.OffsetHigh = 0; Overlapped.hEvent = IOComplete.SafeWaitHandle.DangerousGetHandle(); // We need to wait for either IO to complete or the read to be signaled WaitHandle [] IOCompleteOrThreadTerminating = { IOComplete, ThreadTerminating }; // Signal the openning thread that we're up and running. if (ThreadStarted != null) { ThreadStarted.Set(); } // start reading data from Hid device while (true) { int BytesRead; try { NativeMethods.ReadFile(HidHandle, UnmanagedBuffer, InputReportByteLength, out BytesRead, ref Overlapped); int LastErr = Marshal.GetLastWin32Error(); if (LastErr == NativeMethods.ERROR_IO_PENDING) { // Wait for data or thread termination WaitHandle.WaitAny(IOCompleteOrThreadTerminating); // test for thread termination if (ThreadTerminating.WaitOne(0, false)) { break; } // Cancel any pending IO if we didn't read any data if (!NativeMethods.GetOverlappedResult(HidHandle, ref Overlapped, out BytesRead, false)) { NativeMethods.CancelIo(HidHandle); break; } } } catch (Exception e) { Logger.Error(SOName, "Exception occurred while reading data from the USB port.", e); throw; } // test for thread termination if (ThreadTerminating.WaitOne(0, false)) { break; } // get strong ref to base class Msr = wr.Target as HidMsr; if (Msr == null) { break; } try { if (BytesRead == InputReportByteLength) { // report data Marshal.Copy(UnmanagedBuffer, MsrData, 0, InputReportByteLength); Msr.OnCardSwipe(MsrData); } else { Logger.Error(SOName, "Unexpected number of bytes returned from device."); } } finally { // release strong ref to base class Msr = null; } } } catch (Exception e) { Logger.Error(SOName, "Exception occurred in USB read thread.", e); throw; } finally { // free unmanaged buffer if (UnmanagedBuffer != IntPtr.Zero) { Marshal.FreeHGlobal(UnmanagedBuffer); } if (IOComplete != null) { IOComplete.Close(); } } }