Skip to main content

Module affinity

Module affinity 

Source
Expand description

CPU affinity pinning for workers.

Why: on SMT-enabled CPUs (Zen 4 is 6 physical × 2 SMT = 12 logical), unpinned workers can land on SMT siblings of the main submitter thread and steal its cycles. That’s exactly how the previous InferencePool attempt regressed on 6T. Pinning each worker to a distinct physical core eliminates SMT contention.

Policies (env YSCV_POOL_AFFINITY):

  • none — no pinning, workers float (previous behavior).
  • big — big / performance cores only (ARM big.LITTLE, Intel P-cores). Fallback to physical on symmetric CPUs.
  • physical — one worker per physical core, one SMT sibling per core left idle for the submitter. Default on Zen 4 and other symmetric SMT CPUs.

Linux uses sched_setaffinity; macOS uses thread_policy_set with THREAD_AFFINITY_POLICY. Other OSes fall through as a no-op.

Enums§

AffinityPolicy

Functions§

pin_current_thread
Pin the current thread to cpu_id. No-op on unsupported platforms.
policy_from_env
Parses YSCV_POOL_AFFINITY env; default is physical.
resolve_pinning
Returns a list of CPU IDs to pin nthreads workers to, sized exactly nthreads. If topology info is unavailable or policy is none, returns an empty vec (caller should skip pinning).