Enabled windows ProcessorAffinity support#629
Conversation
nchapagain001
left a comment
There was a problem hiding this comment.
Let's make changes directly in CreateProcessWithAffinity() to allow windows process affinity. Users shouldn't have to make additional call for the same thing.
There was a problem hiding this comment.
Pull request overview
This PR enables CPU affinity support for Virtual Client processes on Windows by using the Process.ProcessorAffinity API. The implementation follows a different approach than Linux: Windows applies affinity immediately after starting the process (creating a small ~1ms timing window), while Linux uses numactl to wrap the process execution command (zero timing window). The Windows implementation is limited to 64 cores due to processor group constraints.
Changes:
- Added
WindowsProcessAffinityConfigurationclass to handle Windows-specific CPU affinity using bitmask-based ProcessorAffinity API - Created
ApplyAffinityextension method forIProcessProxyto apply Windows affinity after process start - Added comprehensive unit and functional tests for Windows affinity support
- Provided example executor (
ExampleWorkloadWithAffinityExecutor) and profile demonstrating CPU affinity usage - Updated documentation to explain CPU affinity support and platform differences
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/VirtualClient/VirtualClient.Common/ProcessAffinity/WindowsProcessAffinityConfiguration.cs | Core implementation of Windows CPU affinity using ProcessorAffinity bitmask, includes reflection-based approach to access underlying process |
| src/VirtualClient/VirtualClient.Common/ProcessAffinity/ProcessAffinityConfiguration.cs | Updated factory method to support Windows platform in addition to Linux |
| src/VirtualClient/VirtualClient.Core/ProcessExtensions.cs | Added ApplyAffinity extension method for applying Windows affinity to running processes |
| src/VirtualClient/VirtualClient.TestFramework/InMemoryProcess.cs | Added OnApplyAffinity delegate to support testing affinity application |
| src/VirtualClient/VirtualClient.Common.UnitTests/ProcessAffinity/WindowsProcessAffinityConfigurationTests.cs | Unit tests for Windows affinity configuration including bitmask calculation and validation |
| src/VirtualClient/VirtualClient.Core.UnitTests/ProcessExtensionsAffinityTests.cs | Unit tests for process extension methods, verifying Windows throws on pre-start affinity methods |
| src/VirtualClient/VirtualClient.Actions/Examples/ExampleWorkloadWithAffinityExecutor.cs | Reference implementation showing how to use CPU affinity in workload executors (contains critical bug in Linux command construction) |
| src/VirtualClient/VirtualClient.Actions.FunctionalTests/ExampleWorkloadWithAffinityProfileTests.cs | Functional tests for the example affinity workload on both Linux and Windows platforms |
| src/VirtualClient/VirtualClient.Main/profiles/PERF-CPU-EXAMPLE-AFFINITY.json | Example profile demonstrating CPU affinity configuration |
| website/docs/developing/0030-workload-onboarding.md | Documentation for CPU affinity feature including core specification formats and platform differences |
| website/docs/developing/0010-develop-guide.md | Updated developer guide to reference CPU affinity support |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/VirtualClient/VirtualClient.Actions/Examples/ExampleWorkloadWithAffinityExecutor.cs
Show resolved
Hide resolved
src/VirtualClient/VirtualClient.Common/ProcessAffinity/WindowsProcessAffinityConfiguration.cs
Outdated
Show resolved
Hide resolved
...rtualClient/VirtualClient.Actions.FunctionalTests/ExampleWorkloadWithAffinityProfileTests.cs
Outdated
Show resolved
Hide resolved
We cannot do that because for windows we can only apply the affinity once the process is started, In the executor there is explicit calls for StartAndWait after process creation so we need to call Start then apply affinity and call WaitAsync. |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 12 out of 12 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This PR enables CPU affinity support for Virtual Client process on windows, by setting affinity via Process.ProcessorAffinity API.
Why Different Approaches for Windows vs. Linux?
-On Linux, we use numactl to wrap the process execution command.
-Windows doesn't have a built-in numactl equivalent, the Process.ProcessorAffinity property is the standard .NET approach which leverages the existing process management infrastructure.
process.Start();
process.ProcessorAffinity = affinityMask;
Limitations for Windows:
Set thread group + CPU mask > Create thread in a group > Query group topology > Multi‑group thread affinity