public GenericCpu(int processorIndex, CpuId[][] cpuId, ISettings settings) : base(cpuId[0][0].Name, CreateIdentifier(cpuId[0][0].Vendor, processorIndex), settings) { _cpuId = cpuId; _vendor = cpuId[0][0].Vendor; _family = cpuId[0][0].Family; _model = cpuId[0][0].Model; _stepping = cpuId[0][0].Stepping; _processorIndex = processorIndex; _coreCount = cpuId.Length; // check if processor has MSRs if (cpuId[0][0].Data.GetLength(0) > 1 && (cpuId[0][0].Data[1, 3] & 0x20) != 0) { HasModelSpecificRegisters = true; } else { HasModelSpecificRegisters = false; } // check if processor has a TSC if (cpuId[0][0].Data.GetLength(0) > 1 && (cpuId[0][0].Data[1, 3] & 0x10) != 0) { HasTimeStampCounter = true; } else { HasTimeStampCounter = false; } // check if processor supports an invariant TSC if (cpuId[0][0].ExtData.GetLength(0) > 7 && (cpuId[0][0].ExtData[7, 3] & 0x100) != 0) { _isInvariantTimeStampCounter = true; } else { _isInvariantTimeStampCounter = false; } _totalLoad = _coreCount > 1 ? new Sensor("CPU Total", 0, SensorType.Load, this, settings) : null; _coreLoads = new Sensor[_coreCount]; for (int i = 0; i < _coreLoads.Length; i++) { _coreLoads[i] = new Sensor(CoreString(i), i + 1, SensorType.Load, this, settings); } _cpuLoad = new CpuLoad(cpuId); if (_cpuLoad.IsAvailable) { foreach (Sensor sensor in _coreLoads) { ActivateSensor(sensor); } if (_totalLoad != null) { ActivateSensor(_totalLoad); } } if (HasTimeStampCounter) { ulong mask = ThreadAffinity.Set(1UL << cpuId[0][0].Thread); EstimateTimeStampCounterFrequency(out _estimatedTimeStampCounterFrequency, out _estimatedTimeStampCounterFrequencyError); ThreadAffinity.Set(mask); } else { _estimatedTimeStampCounterFrequency = 0; } TimeStampCounterFrequency = _estimatedTimeStampCounterFrequency; }
public GenericCpu(int processorIndex, CpuId[][] cpuId, ISettings settings) : base(cpuId[0][0].Name, CreateIdentifier(cpuId[0][0].Vendor, processorIndex), settings) { _cpuId = cpuId; _vendor = cpuId[0][0].Vendor; _family = cpuId[0][0].Family; _model = cpuId[0][0].Model; _stepping = cpuId[0][0].Stepping; _packageType = cpuId[0][0].PkgType; Index = processorIndex; _coreCount = cpuId.Length; _threadCount = cpuId.Sum(x => x.Length); // Check if processor has MSRs. HasModelSpecificRegisters = cpuId[0][0].Data.GetLength(0) > 1 && (cpuId[0][0].Data[1, 3] & 0x20) != 0; // Check if processor has a TSC. HasTimeStampCounter = cpuId[0][0].Data.GetLength(0) > 1 && (cpuId[0][0].Data[1, 3] & 0x10) != 0; // Check if processor supports an invariant TSC. _isInvariantTimeStampCounter = cpuId[0][0].ExtData.GetLength(0) > 7 && (cpuId[0][0].ExtData[7, 3] & 0x100) != 0; _totalLoad = _coreCount > 1 ? new Sensor("CPU Total", 0, SensorType.Load, this, settings) : null; _cpuLoad = new CpuLoad(cpuId); if (_cpuLoad.IsAvailable) { _threadLoads = new Sensor[_threadCount]; for (int coreIdx = 0; coreIdx < cpuId.Length; coreIdx++) { for (int threadIdx = 0; threadIdx < cpuId[coreIdx].Length; threadIdx++) { int thread = cpuId[coreIdx][threadIdx].Thread; if (thread < _threadLoads.Length) { // Some cores may have 2 threads while others have only one (e.g. P-cores vs E-cores on Intel 12th gen). string sensorName = CoreString(coreIdx) + (cpuId[coreIdx].Length > 1 ? $" Thread #{threadIdx + 1}" : string.Empty); _threadLoads[thread] = new Sensor(sensorName, thread + 1, SensorType.Load, this, settings); ActivateSensor(_threadLoads[thread]); } } } if (_totalLoad != null) { ActivateSensor(_totalLoad); } } if (HasTimeStampCounter) { GroupAffinity previousAffinity = ThreadAffinity.Set(cpuId[0][0].Affinity); EstimateTimeStampCounterFrequency(out _estimatedTimeStampCounterFrequency, out _estimatedTimeStampCounterFrequencyError); ThreadAffinity.Set(previousAffinity); } else { _estimatedTimeStampCounterFrequency = 0; } TimeStampCounterFrequency = _estimatedTimeStampCounterFrequency; }