Vixen
02b45cc4
csharp
public sealed class WindowsProcessorTopology

Processor counts, performance classes and thread affinity, from the Windows scheduler.

No guide page documents this yet — the page shows what the code says about itself.

Remarks

This is the Windows half of what docs/plan/03 deferred out of Vixen.Core.Threading: the job scheduler wanted to pin its workers and there was no platform layer to ask. TrySetAffinity is that answer, and it is a Try because it stays one on the platforms — a browser, a container under a CPU quota, macOS — that will not do it.

Groups, not a mask. Windows numbers logical processors within groups of at most 64, because an affinity mask is one machine word. Below 64 processors there is one group and the distinction is invisible; above it, SetThreadAffinityMask can only address the group the thread already happens to be in, which on a dual-socket machine is half of it. SetThreadGroupAffinity addresses all of them, so that is what is used, and a flat processor index is mapped onto (group, bit) here.

Efficiency classes are relative, not absolute. Windows reports a number per core where higher is faster and the scale means nothing between machines. A homogeneous machine reports the same number for every core, which is why this reports Unknown and 0 performance cores there rather than calling every core a performance core — the contract's question is whether the platform distinguishes, and on that machine it does not.

Fields and properties (4)

  • public int AvailableProcessors
  • public int PhysicalCores

    How many physical cores there are, or AvailableProcessors where the platform does not distinguish.

  • public int PerformanceCores

    How many performance cores there are, or 0 where the platform does not say.

  • public bool SupportsAffinity

    Always : Windows has always allowed it.

Methods (4)

  • public WindowsProcessorTopology()

    Reads the machine's topology, once.

  • public ProcessorClass ClassOf(int processor)

    What kind of core a logical processor sits on.

  • public bool TrySetAffinity(int processor)

    Pins the calling thread to one logical processor.

  • public void ClearAffinity()

    Undoes a previous TrySetAffinity for the calling thread.

Used by (1)

  • WindowsPlatformSupplementVixen.Platform.Windows