Skip to content

Environment.ProcessorCount returns bad value in NUMA environment #41902

@rainersigwald

Description

@rainersigwald

This may be entirely attributable to #13691 but I'm not sure, so I'm filing it.

Description

On a Standard_F72s_v2 VM, which has 72 logical processors, Environment.ProcessorCount returns 36.

using System;

namespace proccount
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(System.Environment.ProcessorCount);
        }
    }
}
$ dotnet run
36

Configuration

$ dotnet --info
.NET SDK (reflecting any global.json):
 Version:   5.0.100-rc.1.20452.6
 Commit:    31c7208879

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19041
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Users\raines.NTDEV\Downloads\dotnet-sdk-5.0.100-rc.1.20452.6-win-x64\sdk\5.0.100-rc.1.20452.6\

Host (useful for support):
  Version: 5.0.0-rc.1.20451.14
  Commit:  38017c3935

.NET SDKs installed:
  5.0.100-rc.1.20452.6 [C:\Users\raines.NTDEV\Downloads\dotnet-sdk-5.0.100-rc.1.20452.6-win-x64\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 5.0.0-rc.1.20451.17 [C:\Users\raines.NTDEV\Downloads\dotnet-sdk-5.0.100-rc.1.20452.6-win-x64\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 5.0.0-rc.1.20451.14 [C:\Users\raines.NTDEV\Downloads\dotnet-sdk-5.0.100-rc.1.20452.6-win-x64\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 5.0.0-rc.1.20452.2 [C:\Users\raines.NTDEV\Downloads\dotnet-sdk-5.0.100-rc.1.20452.6-win-x64\shared\Microsoft.WindowsDesktop.App]

Regression?

Not from 3.1.

Other information

I think what's being returned is the number of available cores in the current NUMA node:

https://github.com/dotnet/coreclr/blob/db8fc1b420be60f6a2afb153dd9e645ec231ec82/src/classlibnative/bcltype/system.cpp#L339-L342

That condition looks backward to me: if you can use use all CPU groups, shouldn't you do so rather than only the current group? But maybe I'm misunderstanding the intention.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions