private static unsafe void LoadCpuMaskFromGroupAffinities(ProcessorRelationship *p,
                                                                  ref BitMask cpuMask)
        {
            for (int i = 0; i < p->GroupCount; ++i)
            {
                GroupAffinity *g          = ProcessorRelationship.GetGroup(p, i);
                int            groupIndex = g->Group;

                if (Environment.Is64BitProcess)
                    cpuMask.SetWord64(groupIndex, (ulong)g->Mask); }
Exemplo n.º 2
0
        /// <summary>
        /// Count how many physical cores in total are present.
        /// </summary>
        /// <param name="infoArray">CPU topology info from <see cref="GetList"/>. </param>
        public static int CountNumberOfCores(CpuTopologyInfo[] infoArray)
        {
            // Prevent stack overflow
            if (infoArray.Length > short.MaxValue)
            {
                throw new ArgumentOutOfRangeException(nameof(infoArray));
            }

            var cores = new BitMask(stackalloc ulong[BitMask.GetNumberOfNativeWords(infoArray.Length)]);

            foreach (var item in infoArray)
            {
                cores[item.CoreId] = true;
            }

            return(cores.CountOnBits());
        }