-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Handle RequestCores returning 0 in TaskHostFactory tasks #125276
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -541,16 +541,21 @@ private bool ExecuteInternal() | |||||||||||||||
| else | ||||||||||||||||
| { | ||||||||||||||||
| int allowedParallelism = DisableParallelAot ? 1 : Math.Min(_assembliesToCompile.Count, Environment.ProcessorCount); | ||||||||||||||||
| int coresAcquired = 0; | ||||||||||||||||
| IBuildEngine9? be9 = BuildEngine as IBuildEngine9; | ||||||||||||||||
| try | ||||||||||||||||
| { | ||||||||||||||||
| if (be9 is not null) | ||||||||||||||||
| allowedParallelism = be9.RequestCores(allowedParallelism); | ||||||||||||||||
| } | ||||||||||||||||
| catch (NotImplementedException) | ||||||||||||||||
| if (be9 is not null) | ||||||||||||||||
| { | ||||||||||||||||
| // RequestCores is not implemented in TaskHostFactory | ||||||||||||||||
| be9 = null; | ||||||||||||||||
| try | ||||||||||||||||
| { | ||||||||||||||||
| coresAcquired = be9.RequestCores(allowedParallelism); | ||||||||||||||||
| if (coresAcquired > 0) | ||||||||||||||||
| allowedParallelism = coresAcquired; | ||||||||||||||||
| } | ||||||||||||||||
| catch | ||||||||||||||||
| { | ||||||||||||||||
| // RequestCores may not be supported in all host environments | ||||||||||||||||
|
Comment on lines
+554
to
+556
|
||||||||||||||||
| catch | |
| { | |
| // RequestCores may not be supported in all host environments | |
| catch (Exception ex) | |
| { | |
| // RequestCores may not be supported in all host environments | |
| Log?.LogMessage(MessageImportance.Low, $"RequestCores failed; falling back to default parallelism. Exception: {ex}"); |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -154,16 +154,21 @@ public override bool Execute() | |||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // Generate source file(s) containing each resource's byte data and size | ||||||||||||||||||||||||
| int allowedParallelism = Math.Max(Math.Min(bundledResources.Count, Environment.ProcessorCount), 1); | ||||||||||||||||||||||||
| int coresAcquired = 0; | ||||||||||||||||||||||||
| IBuildEngine9? be9 = BuildEngine as IBuildEngine9; | ||||||||||||||||||||||||
| try | ||||||||||||||||||||||||
| { | ||||||||||||||||||||||||
| if (be9 is not null) | ||||||||||||||||||||||||
| allowedParallelism = be9.RequestCores(allowedParallelism); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| catch (NotImplementedException) | ||||||||||||||||||||||||
| if (be9 is not null) | ||||||||||||||||||||||||
| { | ||||||||||||||||||||||||
| // RequestCores is not implemented in TaskHostFactory | ||||||||||||||||||||||||
| be9 = null; | ||||||||||||||||||||||||
| try | ||||||||||||||||||||||||
| { | ||||||||||||||||||||||||
| coresAcquired = be9.RequestCores(allowedParallelism); | ||||||||||||||||||||||||
| if (coresAcquired > 0) | ||||||||||||||||||||||||
| allowedParallelism = coresAcquired; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| catch | ||||||||||||||||||||||||
| { | ||||||||||||||||||||||||
| // RequestCores may not be supported in all host environments | ||||||||||||||||||||||||
|
Comment on lines
+167
to
+169
|
||||||||||||||||||||||||
| catch | |
| { | |
| // RequestCores may not be supported in all host environments | |
| catch (Exception ex) | |
| { | |
| // RequestCores may not be supported in all host environments | |
| Log.LogMessage( | |
| MessageImportance.Low, | |
| "RequestCores({0}) failed: {1}", | |
| allowedParallelism, | |
| ex.Message); |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -74,16 +74,21 @@ public override bool Execute() | |||||||||||||||||||||
| Log.LogMessage(MessageImportance.High, "IL stripping assemblies"); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| int allowedParallelism = DisableParallelStripping ? 1 : Math.Min(Assemblies.Length, Environment.ProcessorCount); | ||||||||||||||||||||||
| int coresAcquired = 0; | ||||||||||||||||||||||
| IBuildEngine9? be9 = BuildEngine as IBuildEngine9; | ||||||||||||||||||||||
| try | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| if (be9 is not null) | ||||||||||||||||||||||
| allowedParallelism = be9.RequestCores(allowedParallelism); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| catch (NotImplementedException) | ||||||||||||||||||||||
| if (be9 is not null) | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| // RequestCores is not implemented in TaskHostFactory | ||||||||||||||||||||||
| be9 = null; | ||||||||||||||||||||||
| try | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| coresAcquired = be9.RequestCores(allowedParallelism); | ||||||||||||||||||||||
| if (coresAcquired > 0) | ||||||||||||||||||||||
| allowedParallelism = coresAcquired; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| catch | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| // RequestCores may not be supported in all host environments | ||||||||||||||||||||||
|
Comment on lines
+87
to
+89
|
||||||||||||||||||||||
| catch | |
| { | |
| // RequestCores may not be supported in all host environments | |
| catch (Exception ex) | |
| { | |
| // RequestCores may not be supported in all host environments | |
| Log.LogMessage( | |
| MessageImportance.Low, | |
| "RequestCores failed; falling back to default parallelism. Exception: {0}", | |
| ex); |
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -131,16 +131,21 @@ private bool ExecuteActual() | |||||||||||||||
| Directory.CreateDirectory(_tempPath); | ||||||||||||||||
|
|
||||||||||||||||
| int allowedParallelism = DisableParallelCompile ? 1 : Math.Min(SourceFiles.Length, Environment.ProcessorCount); | ||||||||||||||||
| int coresAcquired = 0; | ||||||||||||||||
| IBuildEngine9? be9 = BuildEngine as IBuildEngine9; | ||||||||||||||||
| try | ||||||||||||||||
| { | ||||||||||||||||
| if (be9 is not null) | ||||||||||||||||
| allowedParallelism = be9.RequestCores(allowedParallelism); | ||||||||||||||||
| } | ||||||||||||||||
| catch (NotImplementedException) | ||||||||||||||||
| if (be9 is not null) | ||||||||||||||||
| { | ||||||||||||||||
| // RequestCores is not implemented in TaskHostFactory | ||||||||||||||||
| be9 = null; | ||||||||||||||||
| try | ||||||||||||||||
| { | ||||||||||||||||
| coresAcquired = be9.RequestCores(allowedParallelism); | ||||||||||||||||
| if (coresAcquired > 0) | ||||||||||||||||
| allowedParallelism = coresAcquired; | ||||||||||||||||
| } | ||||||||||||||||
| catch | ||||||||||||||||
| { | ||||||||||||||||
| // RequestCores may not be supported in all host environments | ||||||||||||||||
|
Comment on lines
+144
to
+146
|
||||||||||||||||
| catch | |
| { | |
| // RequestCores may not be supported in all host environments | |
| catch (Exception ex) | |
| { | |
| // RequestCores may not be supported in all host environments | |
| Log.LogMessage(MessageImportance.Low, $"RequestCores({allowedParallelism}) failed, falling back to default parallelism. Exception: {ex.Message}"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This
RequestCores/ReleaseCores+ fallback pattern is now duplicated across several tasks (EmccCompile, ILStrip, EmitBundleBase, MonoAOTCompiler). Since these task projects already compile insrc/tasks/Common/Utils.cs, consider extracting a small shared helper (e.g., a method that returns(allowedParallelism, coresAcquired)and handles the fallback) to reduce future drift and make it easier to adjust behavior consistently if MSBuild changes again.