コード例 #1
0
ファイル: X86CpuIdFactory.cs プロジェクト: jcurl/CpuId
        private BasicCpu GetLocalCpuNode()
        {
            if (CpuIdLib.hascpuid() == 0)
            {
                throw new PlatformNotSupportedException("CPUID instruction not supported");
            }

            CpuIdLib.CpuIdInfo[] data = new CpuIdLib.CpuIdInfo[MaxCpuLeaves];
            int r = CpuIdLib.iddump(data, Marshal.SizeOf(data[0]) * data.Length);

            return(new BasicCpu(data, 0, r));
        }
コード例 #2
0
        public override CpuIdRegister GetCpuId(int function, int subfunction)
        {
            CpuIdRegister result = base.GetCpuId(function, subfunction);

            if (result == null)
            {
                // It's not cached, so query the CPU for it. Note, we assume that each EAX/ECX pair always returns the
                // same result for the same CPU core/thread.
                CpuIdLib.cpuid(function, subfunction, out int eax, out int ebx, out int ecx, out int edx);
                result = new CpuIdRegister(function, subfunction, new int[] { eax, ebx, ecx, edx });
                AddRegister(result);
            }

            return(result);
        }
コード例 #3
0
ファイル: X86CpuIdFactory.cs プロジェクト: jcurl/CpuId
        private IEnumerable <BasicCpu> GetLocalCpuNodes()
        {
            if (CpuIdLib.hascpuid() == 0)
            {
                throw new PlatformNotSupportedException("CPUID instruction not supported");
            }

            CpuIdLib.CpuIdInfo[] data = new CpuIdLib.CpuIdInfo[MaxCpuLeaves * MaxCpus];
            int r = CpuIdLib.iddumpall(data, Marshal.SizeOf(data[0]) * data.Length);

            // Each CPU has the first element with EAX=0xFFFFFFFF and the CPU number as ECX. This isn't captured by the
            // CPUID instruction, but a part of the library to allow separating the CPU information
            List <BasicCpu> cpus     = new List <BasicCpu>();
            int             cpustart = 0;

            for (int i = 0; i < r; i++)
            {
                if (data[i].veax == -1)
                {
                    // Describes the start of a CPU node.
                    if (i - cpustart > 0)
                    {
                        // Process the data that we had.
                        BasicCpu cpu = new BasicCpu(data, cpustart + 1, i - cpustart - 1);
                        cpus.Add(cpu);
                    }
                    cpustart = i;
                }
            }
            if (r - cpustart > 0)
            {
                // Process the data that we had.
                BasicCpu cpu = new BasicCpu(data, cpustart + 1, r - cpustart - 1);
                cpus.Add(cpu);
            }

            return(cpus);
        }