public static CPUID Get(int group, int thread) { if (thread >= 64) { return(null); } var affinity = GroupAffinity.Single((ushort)group, thread); var previousAffinity = ThreadAffinity.Set(affinity); if (previousAffinity == GroupAffinity.Undefined) { return(null); } try { return(new CPUID(group, thread, affinity)); } finally { ThreadAffinity.Set(previousAffinity); } }
private static CpuId[][] GetProcessorThreads() { List <CpuId> threads = new List <CpuId>(); for (int i = 0; i < ThreadAffinity.ProcessorGroupCount; i++) { for (int j = 0; j < 64; j++) { try { if (!ThreadAffinity.IsValid(GroupAffinity.Single((ushort)i, j))) { continue; } var cpuid = CpuId.Get(i, j); if (cpuid != null) { threads.Add(cpuid); } } catch (ArgumentOutOfRangeException) { // All cores found. break; } } } SortedDictionary <uint, List <CpuId> > processors = new SortedDictionary <uint, List <CpuId> >(); foreach (CpuId thread in threads) { processors.TryGetValue(thread.ProcessorId, out List <CpuId> list); if (list == null) { list = new List <CpuId>(); processors.Add(thread.ProcessorId, list); } list.Add(thread); } CpuId[][] processorThreads = new CpuId[processors.Count][]; int index = 0; foreach (List <CpuId> list in processors.Values) { processorThreads[index] = list.ToArray(); index++; } return(processorThreads); }
private static CPUID[][] GetProcessorThreads() { List <CPUID> threads = new List <CPUID>(); for (int i = 0; i < ThreadAffinity.ProcessorGroupCount; i++) { for (int j = 0; j < 64; j++) { try { if (!ThreadAffinity.IsValid(GroupAffinity.Single((ushort)i, j))) { continue; } var cpuid = CPUID.Get(i, j); if (cpuid != null) { threads.Add(cpuid); } } catch { } } } SortedDictionary <uint, List <CPUID> > processors = new SortedDictionary <uint, List <CPUID> >(); foreach (CPUID thread in threads) { processors.TryGetValue(thread.ProcessorId, out List <CPUID> list); if (list == null) { list = new List <CPUID>(); processors.Add(thread.ProcessorId, list); } list.Add(thread); } CPUID[][] processorThreads = new CPUID[processors.Count][]; int index = 0; foreach (List <CPUID> list in processors.Values) { processorThreads[index] = list.ToArray(); index++; } return(processorThreads); }