Пример #1
0
        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
        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);
        }