示例#1
0
        public GenericCPU(int processorIndex, CPUID[][] cpuid, ISettings settings)
            : base(cpuid[0][0].Name, CreateIdentifier(cpuid[0][0].Vendor,
                                                      processorIndex), settings)
        {
            this.cpuid = cpuid;

            this.brandString = cpuid[0][0].BrandString;

            this.vendor = cpuid[0][0].Vendor;

            this.family   = cpuid[0][0].Family;
            this.familyId = cpuid[0][0].FamilyId;
            this.model    = cpuid[0][0].Model;
            this.stepping = cpuid[0][0].Stepping;

            this.processorIndex = processorIndex;
            this.coreCount      = cpuid.Length;
            this.threadCount    = coreCount * cpuid[0].Length;

            this.is64bit = cpuid[0][0].Is64bit;

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

            if (coreCount > 1)
            {
                totalLoad = new Sensor("CPU Total", 0, SensorType.Load, this, settings);
            }
            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, 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;

            instructionsExtensions = cpuid[0][0].InstructionsExtensions;

            caches = cpuid[0][0].Caches;
        }
示例#2
0
        public GenericCPU(int processorIndex, CPUID[][] cpuid, ISettings settings)
            : base(cpuid[0][0].Name, CreateIdentifier(cpuid[0][0].Vendor,
          processorIndex), settings)
        {
            this.cpuid = cpuid;

            this.vendor = cpuid[0][0].Vendor;

            this.family = cpuid[0][0].Family;
            this.model = cpuid[0][0].Model;
            this.stepping = cpuid[0][0].Stepping;

            this.processorIndex = processorIndex;
            this.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;

            if (coreCount > 1)
                totalLoad = new Sensor("CPU Total", 0, SensorType.Load, this, settings);
            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, 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;
        }