コード例 #1
0
        public override void GatherGeneralSystemInformation(ref MachineInformation information)
        {
            information.OperatingSystem = Environment.OSVersion;
            information.Platform        = Expression.Empty() switch
            {
                _ when RuntimeInformation.IsOSPlatform(OSPlatform.Windows) => MachineInformation.Platforms.Windows,
                _ when RuntimeInformation.IsOSPlatform(OSPlatform.Linux) => MachineInformation.Platforms.Linux,
                _ when RuntimeInformation.IsOSPlatform(OSPlatform.OSX) => MachineInformation.Platforms.OSX,
                _ => MachineInformation.Platforms.Unknown
            };
            information.Cpu.LogicalCores        = (uint)Environment.ProcessorCount;
            information.Cpu.LogicalCoresPerNode = information.Cpu.LogicalCores;
            information.Cpu.Nodes        = 1;
            information.Cpu.Architecture = RuntimeInformation.ProcessArchitecture.ToString();
            information.Cpu.Caption      = Environment.GetEnvironmentVariable("PROCESSOR_IDENTIFIER") ?? default;
            information.Cpu.Name         = information.Cpu.Caption;

            var cores = new List <Core>();

            for (var i = 0; i < information.Cpu.LogicalCores; i++)
            {
                cores.Add(new Core
                {
                    Number = (uint)i
                });
            }

            information.Cpu.Cores = cores.AsReadOnly();

            Opcode.Cpuid(out var result, 0, 0);

            var vendorString = string.Format("{0}{1}{2}",
                                             string.Join("", $"{result.ebx:X}".HexStringToString().Reverse()),
                                             string.Join("", $"{result.edx:X}".HexStringToString().Reverse()),
                                             string.Join("", $"{result.ecx:X}".HexStringToString().Reverse()));

            information.Cpu.Vendor = vendorString;
            information.Cpu.MaxCpuIdFeatureLevel = result.eax;

            Opcode.Cpuid(out result, 0x80000000, 0);
            information.Cpu.MaxCpuIdExtendedFeatureLevel = result.eax;
        }
コード例 #2
0
        public override void GatherCpuFeatureFlagInformation(ref MachineInformation information)
        {
            Opcode.Result result;

            if (information.Cpu.MaxCpuIdFeatureLevel >= 1)
            {
                Opcode.Cpuid(out result, 1, 0);
                information.Cpu.FeatureFlagsOne = (CPU.FeatureFlagEDX)result.edx;
                information.Cpu.FeatureFlagsTwo = (CPU.FeatureFlagECX)result.ecx;
            }

            if (information.Cpu.MaxCpuIdFeatureLevel >= 7)
            {
                Opcode.Cpuid(out result, 7, 0);

                information.Cpu.ExtendedFeatureFlagsF7One =
                    (CPU.ExtendedFeatureFlagsF7EBX)result.ebx;
                information.Cpu.ExtendedFeatureFlagsF7Two =
                    (CPU.ExtendedFeatureFlagsF7ECX)result.ecx;
                information.Cpu.ExtendedFeatureFlagsF7Three =
                    (CPU.ExtendedFeatureFlagsF7EDX)result.edx;
            }
        }
コード例 #3
0
        private CPUID(int group, int thread, GroupAffinity affinity)
        {
            this.group    = group;
            this.thread   = thread;
            this.affinity = affinity;

            uint maxCpuid    = 0;
            uint maxCpuidExt = 0;

            uint eax, ebx, ecx, edx;

            Opcode.Cpuid(CPUID_0, 0, out eax, out ebx, out ecx, out edx);
            if (eax > 0)
            {
                maxCpuid = eax;
            }
            else
            {
                return;
            }

            StringBuilder vendorBuilder = new StringBuilder();

            AppendRegister(vendorBuilder, ebx);
            AppendRegister(vendorBuilder, edx);
            AppendRegister(vendorBuilder, ecx);
            string cpuVendor = vendorBuilder.ToString();

            switch (cpuVendor)
            {
            case "GenuineIntel":
                vendor = Vendor.Intel;
                break;

            case "AuthenticAMD":
                vendor = Vendor.AMD;
                break;

            default:
                vendor = Vendor.Unknown;
                break;
            }
            eax = ebx = ecx = edx = 0;
            Opcode.Cpuid(CPUID_EXT, 0, out eax, out ebx, out ecx, out edx);
            if (eax > CPUID_EXT)
            {
                maxCpuidExt = eax - CPUID_EXT;
            }
            else
            {
                return;
            }

            maxCpuid    = Math.Min(maxCpuid, 1024);
            maxCpuidExt = Math.Min(maxCpuidExt, 1024);

            cpuidData = new uint[maxCpuid + 1, 4];
            for (uint i = 0; i < (maxCpuid + 1); i++)
            {
                Opcode.Cpuid(CPUID_0 + i, 0,
                             out cpuidData[i, 0], out cpuidData[i, 1],
                             out cpuidData[i, 2], out cpuidData[i, 3]);
            }

            cpuidExtData = new uint[maxCpuidExt + 1, 4];
            for (uint i = 0; i < (maxCpuidExt + 1); i++)
            {
                Opcode.Cpuid(CPUID_EXT + i, 0,
                             out cpuidExtData[i, 0], out cpuidExtData[i, 1],
                             out cpuidExtData[i, 2], out cpuidExtData[i, 3]);
            }

            StringBuilder nameBuilder = new StringBuilder();

            for (uint i = 2; i <= 4; i++)
            {
                Opcode.Cpuid(CPUID_EXT + i, 0, out eax, out ebx, out ecx, out edx);
                AppendRegister(nameBuilder, eax);
                AppendRegister(nameBuilder, ebx);
                AppendRegister(nameBuilder, ecx);
                AppendRegister(nameBuilder, edx);
            }
            nameBuilder.Replace('\0', ' ');
            cpuBrandString = nameBuilder.ToString().Trim();
            nameBuilder.Replace("Dual-Core Processor", "");
            nameBuilder.Replace("Triple-Core Processor", "");
            nameBuilder.Replace("Quad-Core Processor", "");
            nameBuilder.Replace("Six-Core Processor", "");
            nameBuilder.Replace("Eight-Core Processor", "");
            nameBuilder.Replace("Dual Core Processor", "");
            nameBuilder.Replace("Quad Core Processor", "");
            nameBuilder.Replace("12-Core Processor", "");
            nameBuilder.Replace("16-Core Processor", "");
            nameBuilder.Replace("24-Core Processor", "");
            nameBuilder.Replace("32-Core Processor", "");
            nameBuilder.Replace("64-Core Processor", "");
            nameBuilder.Replace("6-Core Processor", "");
            nameBuilder.Replace("8-Core Processor", "");
            nameBuilder.Replace("with Radeon Vega Mobile Gfx", "");
            nameBuilder.Replace("w/ Radeon Vega Mobile Gfx", "");
            nameBuilder.Replace("with Radeon Vega Graphics", "");
            nameBuilder.Replace("APU with Radeon(tm) HD Graphics", "");
            nameBuilder.Replace("APU with Radeon(TM) HD Graphics", "");
            nameBuilder.Replace("APU with AMD Radeon R2 Graphics", "");
            nameBuilder.Replace("APU with AMD Radeon R3 Graphics", "");
            nameBuilder.Replace("APU with AMD Radeon R4 Graphics", "");
            nameBuilder.Replace("APU with AMD Radeon R5 Graphics", "");
            nameBuilder.Replace("APU with Radeon(tm) R3", "");
            nameBuilder.Replace("RADEON R2, 4 COMPUTE CORES 2C+2G", "");
            nameBuilder.Replace("RADEON R4, 5 COMPUTE CORES 2C+3G", "");
            nameBuilder.Replace("RADEON R5, 5 COMPUTE CORES 2C+3G", "");
            nameBuilder.Replace("RADEON R5, 10 COMPUTE CORES 4C+6G", "");
            nameBuilder.Replace("RADEON R7, 10 COMPUTE CORES 4C+6G", "");
            nameBuilder.Replace("RADEON R7, 12 COMPUTE CORES 4C+8G", "");
            nameBuilder.Replace("Radeon R5, 6 Compute Cores 2C+4G", "");
            nameBuilder.Replace("Radeon R5, 8 Compute Cores 4C+4G", "");
            nameBuilder.Replace("Radeon R6, 10 Compute Cores 4C+6G", "");
            nameBuilder.Replace("Radeon R7, 10 Compute Cores 4C+6G", "");
            nameBuilder.Replace("Radeon R7, 12 Compute Cores 4C+8G", "");
            nameBuilder.Replace("R5, 10 Compute Cores 4C+6G", "");
            nameBuilder.Replace("R7, 12 COMPUTE CORES 4C+8G", "");
            nameBuilder.Replace("(R)", " ");
            nameBuilder.Replace("(TM)", " ");
            nameBuilder.Replace("(tm)", " ");
            nameBuilder.Replace("CPU", " ");

            for (int i = 0; i < 10; i++)
            {
                nameBuilder.Replace("  ", " ");
            }
            name = nameBuilder.ToString();
            if (name.Contains("@"))
            {
                name = name.Remove(name.LastIndexOf('@'));
            }
            name = name.Trim();

            this.family = ((cpuidData[1, 0] & 0x0FF00000) >> 20) +
                          ((cpuidData[1, 0] & 0x0F00) >> 8);
            this.model = ((cpuidData[1, 0] & 0x0F0000) >> 12) +
                         ((cpuidData[1, 0] & 0xF0) >> 4);
            this.stepping = (cpuidData[1, 0] & 0x0F);

            this.apicId = (cpuidData[1, 1] >> 24) & 0xFF;

            switch (vendor)
            {
            case Vendor.Intel:
                uint maxCoreAndThreadIdPerPackage = (cpuidData[1, 1] >> 16) & 0xFF;
                uint maxCoreIdPerPackage;
                if (maxCpuid >= 4)
                {
                    maxCoreIdPerPackage = ((cpuidData[4, 0] >> 26) & 0x3F) + 1;
                }
                else
                {
                    maxCoreIdPerPackage = 1;
                }
                threadMaskWith =
                    NextLog2(maxCoreAndThreadIdPerPackage / maxCoreIdPerPackage);
                coreMaskWith = NextLog2(maxCoreIdPerPackage);
                break;

            case Vendor.AMD:
                if (this.family == 0x17)
                {
                    coreMaskWith   = (cpuidExtData[8, 2] >> 12) & 0xF;
                    threadMaskWith =
                        NextLog2(((cpuidExtData[0x1E, 1] >> 8) & 0xFF) + 1);
                }
                else
                {
                    uint corePerPackage;
                    if (maxCpuidExt >= 8)
                    {
                        corePerPackage = (cpuidExtData[8, 2] & 0xFF) + 1;
                    }
                    else
                    {
                        corePerPackage = 1;
                    }
                    coreMaskWith   = NextLog2(corePerPackage);
                    threadMaskWith = 0;
                }
                break;

            default:
                threadMaskWith = 0;
                coreMaskWith   = 0;
                break;
            }

            processorId = (apicId >> (int)(coreMaskWith + threadMaskWith));
            coreId      = ((apicId >> (int)(threadMaskWith))
                           - (processorId << (int)(coreMaskWith)));
            threadId = apicId
                       - (processorId << (int)(coreMaskWith + threadMaskWith))
                       - (coreId << (int)(threadMaskWith));
        }
コード例 #4
0
        private void GetCommonCpuInformation(ref MachineInformation information)
        {
            information.OperatingSystem = Environment.OSVersion;
            information.Platform        = Expression.Empty() switch
            {
                _ when RuntimeInformation.IsOSPlatform(OSPlatform.Windows) => MachineInformation.Platforms.Windows,
                _ when RuntimeInformation.IsOSPlatform(OSPlatform.Linux) => MachineInformation.Platforms.Linux,
                _ when RuntimeInformation.IsOSPlatform(OSPlatform.OSX) => MachineInformation.Platforms.OSX,
                _ => MachineInformation.Platforms.Unknown
            };
            information.Cpu.LogicalCores        = (uint)Environment.ProcessorCount;
            information.Cpu.LogicalCoresPerNode = information.Cpu.LogicalCores;
            information.Cpu.Nodes        = 1;
            information.Cpu.Architecture = RuntimeInformation.ProcessArchitecture.ToString();
            information.Cpu.Caption      = Environment.GetEnvironmentVariable("PROCESSOR_IDENTIFIER") ?? default;
            information.Cpu.Name         = information.Cpu.Caption;

            var cores = new List <Core>();

            for (var i = 0; i < information.Cpu.LogicalCores; i++)
            {
                cores.Add(new Core
                {
                    Number = (uint)i
                });
            }

            information.Cpu.Cores = cores.AsReadOnly();

            if (RuntimeInformation.ProcessArchitecture != Architecture.X86 &&
                RuntimeInformation.ProcessArchitecture != Architecture.X64)
            {
                return;
            }

            Opcode.Cpuid(out var result, 0, 0);

            var vendorString = string.Format("{0}{1}{2}",
                                             string.Join("", $"{result.ebx:X}".HexStringToString().Reverse()),
                                             string.Join("", $"{result.edx:X}".HexStringToString().Reverse()),
                                             string.Join("", $"{result.ecx:X}".HexStringToString().Reverse()));

            information.Cpu.Vendor = vendorString;
            information.Cpu.MaxCpuIdFeatureLevel = result.eax;

            if (information.Cpu.MaxCpuIdFeatureLevel >= 1)
            {
                Opcode.Cpuid(out result, 1, 0);

                information.Cpu.Stepping = result.eax & 0xF;

                var familyId = (result.eax & 0xF00) >> 8;

                if (familyId == 6 || familyId == 15)
                {
                    information.Cpu.Model = (((result.eax & 0xF0000) >> 16) << 4) + ((result.eax & 0xF0) >> 4);
                }
                else
                {
                    information.Cpu.Model = (result.eax & 0xF0) >> 4;
                }

                if (familyId == 15)
                {
                    information.Cpu.Family = ((result.eax & 0xFF00000) >> 20) + familyId;
                }
                else
                {
                    information.Cpu.Family = familyId;
                }

                information.Cpu.Type =
                    (CPU.ProcessorType)((result.eax & 0b11000000000000) >> 12);
                information.Cpu.FeatureFlagsOne = (CPU.FeatureFlagEDX)result.edx;
                information.Cpu.FeatureFlagsTwo = (CPU.FeatureFlagECX)result.ecx;
            }

            if (information.Cpu.MaxCpuIdFeatureLevel >= 7)
            {
                Opcode.Cpuid(out result, 7, 0);

                information.Cpu.ExtendedFeatureFlagsF7One =
                    (CPU.ExtendedFeatureFlagsF7EBX)result.ebx;
                information.Cpu.ExtendedFeatureFlagsF7Two =
                    (CPU.ExtendedFeatureFlagsF7ECX)result.ecx;
                information.Cpu.ExtendedFeatureFlagsF7Three =
                    (CPU.ExtendedFeatureFlagsF7EDX)result.edx;
            }

            Opcode.Cpuid(out result, 0x80000000, 0);

            information.Cpu.MaxCpuIdExtendedFeatureLevel = result.eax;
        }