4

I'm using Windows Server 2016 with 72 cores. I see that there are 2 groups of processors. my .net app will use one or the other groups. I need to be able to force my app to use the Group of my choice. I see a code example below but I am unable to make it work. I might be passing the wrong variables. I want the app to pick group 1 and all the processors then group 2 and all the processors.

my question is how do i force my .net app to use group 1 or group 2? i am not sure if the link below will work.

https://gist.github.com/alexandrnikitin/babfa4781c68f1664d4a81339fe3a0aa

I did try adding this to my config but the app only uses group 0 but i do show all the cores with this code. I know an option is to go to the bios and choose flatten but i'm not sure that is the right way to do things.

   <Thread_UseAllCpuGroups enabled="true"/>  
      <GCCpuGroup enabled="true"/>  
      <gcServer enabled="true"/> 
Andre DeMattia
  • 631
  • 9
  • 23
  • You cannot flaten 72 cores into one group. The limit for one CPU group is 64. HP has a BIOS feature to set the CPU group to clustered which is unfortunately turned on by default. This creates two groups for machines with < 64 cores which is in my opinion nonsense. The setting you are showing will use all cores from all groups but in the text you mention that you want to start each instance in a separate group. It is still unclear to me what you are trying to achieve. – Alois Kraus Jun 30 '17 at 21:06
  • Hi my goal is to force my .net app to chose the group that i want. I have 10 apps running i want 5 on one group and 5 on the other. My question is how do i force this? the link has code that shows you can pick the group but when i use the code passing 1,0 it doesn't appear to work. maybe i'm passing the values wrong or the code doesn't work – Andre DeMattia Jun 30 '17 at 21:21
  • 1
    I'm reopening the question. I thought that it was about running on more than 1 group, not about picking the group you want to run on. My bad. – Kevin Gosse Jun 30 '17 at 21:30

1 Answers1

1

The posted examply only sets current thread to a CPU processor group. But you want to set it for all threads of a process. You need to call SetProcessAffinityMask for your process.

There is no need to PInvoke to SetProcessAffinityMask because the Process class already has a property ProcessorAffinity which lets you set it directly.

class Program
{
    static void SetProcessAffinity(ulong groupMask)
    {
        Process.GetCurrentProcess().ProcessorAffinity = new IntPtr((long)groupMask);
    }
    static void Main(string[] args)
    {
        SetProcessAffinity(1);    // group 0
        // binary literals are a C# 7 feature for which you need VS 2017 or later.
        SetProcessAffinity(0b11); // Both groups 0 and 1 
        SetProcessAffinity(0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111); // for all cpu groups all 64 bits enabled
    }
}
Alois Kraus
  • 13,229
  • 1
  • 38
  • 64
  • thank you so much. can you show me what it looks like without the binary literals? i'm still on 2016, – Andre DeMattia Jul 01 '17 at 15:46
  • also what would it look like if i wanted group 1 only. – Andre DeMattia Jul 01 '17 at 15:54
  • Do I need to set this in the configuration to use all cores? – Andre DeMattia Jul 01 '17 at 16:06
  • @Andre: No you do not need these appsettings since they are only necessary if you want to let your threads trun on all CPU groups. But you want to run only on group 0 or 1. To do that you need to call SetProcessAffinity(1) or SetProcessAffinity(2) to set bit 0 or bit 1. – Alois Kraus Jul 01 '17 at 21:15
  • 2
    This answer is misleading. @AndreDeMattia wanted to assign a process to a specific processor group as the system has more than 64 logical processors and Windows has created more than 1 processor group with a max of 64 logical processors per processor group. The processor groups are typically aligned to the NUMA architecture of the machine. The .NET Process.ProcessorAffinity is only able to set the thread affinity for the process and not change the processor group affinity. – Craig Nicholson Dec 28 '18 at 15:24