Skip to content

Conversation

@RakeshwarK
Copy link
Contributor

@RakeshwarK RakeshwarK commented Jan 29, 2026

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:

  1. Affinity is applied immediately after Start(), creating a small timing window (~<1ms) where the process may run on unintended cores. The impact can be negligible for most workloads.
  • Alternative approach: Windows Job Objects could theoretically eliminate this by creating the process in CREATE_SUSPENDED state and assigning it to a Job Object with affinity constraints and resuming the process. But we must bypass .NET's Process class and manually manage the process lifecycle.
  1. Process.ProcessorAffinity is an affinity mask interface that only targets a single processor group (the process’s primary group), and a processor group has a maximum of 64 logical processors.
  • Alternative approach: To pin a workload on a >64 core machine, we must control threads, not just the process, and we must control which group(s) the workload uses and explicitly place threads across groups. This requires group‑aware APIs built on the GROUP_AFFINITY structure.
    Set thread group + CPU mask > Create thread in a group > Query group topology > Multi‑group thread affinity

@RakeshwarK RakeshwarK changed the title Enable defining specific logical processors against which to run a given process fo Windows Enabled windows ProcessorAffinity support Jan 29, 2026
@RakeshwarK RakeshwarK marked this pull request as ready for review January 29, 2026 20:35
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.

1 participant