diff --git a/src/BenchmarkDotNet/Extensions/ProcessExtensions.cs b/src/BenchmarkDotNet/Extensions/ProcessExtensions.cs index 0f5f2e5c5f..32ab982cd7 100644 --- a/src/BenchmarkDotNet/Extensions/ProcessExtensions.cs +++ b/src/BenchmarkDotNet/Extensions/ProcessExtensions.cs @@ -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) diff --git a/tests/BenchmarkDotNet.IntegrationTests/ProcessPropertiesTests.cs b/tests/BenchmarkDotNet.IntegrationTests/ProcessPropertiesTests.cs index a03194dc6f..82eeb073b4 100644 --- a/tests/BenchmarkDotNet.IntegrationTests/ProcessPropertiesTests.cs +++ b/tests/BenchmarkDotNet.IntegrationTests/ProcessPropertiesTests.cs @@ -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}"); } } }