Skip to content

Commit

Permalink
Increase max supported affinity from 31 to 64 (#2211) (#2228)
Browse files Browse the repository at this point in the history
  • Loading branch information
Donis- authored Dec 16, 2022
1 parent a6ef739 commit bf8b531
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/BenchmarkDotNet/Extensions/ProcessExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ internal static string ToPresentation(this IntPtr processorAffinity, int process

private static IntPtr FixAffinity(IntPtr processorAffinity)
{
int cpuMask = (1 << Environment.ProcessorCount) - 1;
// Max supported affinity without CPU groups is 64
long cpuMask = Environment.ProcessorCount >= 64 ? unchecked((long)0xFFFF_FFFF_FFFF_FFFF) : (1L << Environment.ProcessorCount) - 1;

return RuntimeInformation.Is64BitPlatform()
? new IntPtr(processorAffinity.ToInt64() & cpuMask)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void Ensure()
{
if (Process.GetCurrentProcess().ProcessorAffinity != Value)
{
throw new InvalidOperationException("Did not set custom affinity");
throw new InvalidOperationException($"Did not set custom affinity {Process.GetCurrentProcess().ProcessorAffinity} != {Value}");
}
}
}
Expand Down

0 comments on commit bf8b531

Please sign in to comment.