Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use logical core count #6014

Merged
merged 4 commits into from
Jan 15, 2021
Merged

Use logical core count #6014

merged 4 commits into from
Jan 15, 2021

Conversation

cdmihai
Copy link
Contributor

@cdmihai cdmihai commented Jan 8, 2021

A test started failing after upgrading my machine to 18 cores:

<test name="Microsoft.Build.UnitTests.XMakeAppTests.GatherCommandLineSwitchesMaxCpuCountWithoutArgument" type="Microsoft.Build.UnitTests.XMakeAppTests" method="GatherCommandLineSwitchesMaxCpuCountWithoutArgument" time="0.1018472" result="Fail">
        <failure exception-type="Shouldly.ShouldAssertException">
          <message><![CDATA[Shouldly.ShouldAssertException : parameters[1]\n    should be\n\"32\"\n    but was\n\"36\"\n

So I changed all occurrences of Environment.ProcessorCount to NativeMethodsShared.GetLogicalCoreCount

Copy link
Member

@rainersigwald rainersigwald left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😅 Guess I didn't self-build on that big machine I borrowed to test this.

fyi @mfkl

@@ -1725,7 +1725,7 @@ internal static void GatherCommandLineSwitches(ArrayList commandLineArgs, Comman
if (String.Equals(switchName, "m", StringComparison.OrdinalIgnoreCase) ||
String.Equals(switchName, "maxcpucount", StringComparison.OrdinalIgnoreCase))
{
int numberOfCpus = Environment.ProcessorCount;
int numberOfCpus = NativeMethodsShared.GetLogicalCoreCount();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
int numberOfCpus = NativeMethodsShared.GetLogicalCoreCount();
int numberOfCpus = Environment.ProcessorCount;

The change wave won't apply otherwise. Which actually suggests that we should consider putting all of the logic here into NativeMethodsShared since it can be centralized.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved the xmake logic instead: d5ac55a
I think this is the correct way to do it, didn't realize the thing can return -1 :)

@jeffkl
Copy link
Contributor

jeffkl commented Jan 8, 2021

Where can I get that many cores!?

@Forgind Forgind merged commit 34bbbed into dotnet:master Jan 15, 2021
@cdmihai cdmihai deleted the useLogicalCoreCount branch January 15, 2021 23:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants