Vixen
02b45cc4
csharp
public sealed class MacOSProcessorTopology

Processor counts and performance classes, from sysctl.

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

Remarks

Affinity is not supported here, and that is Apple's decision rather than an omission. macOS has thread_policy_set with THREAD_AFFINITY_POLICY, which was always documented as a hint about which threads share cache rather than a request for a processor, and which is unimplemented on Apple silicon. What the system offers instead is quality-of-service classes: a thread declares whether it is user-interactive or background and the scheduler chooses the core, which on a machine with two kinds of core it is in a much better position to do than we are. SupportsAffinity reports , and docs/plan/03's deferred pinning work has its answer on this platform: do not.

Performance levels, not core numbers. hw.nperflevels is 2 on Apple silicon and absent on Intel, and level 0 is the fastest. That gives the counts, which is what sizing a worker pool needs. What it does not give is a map from a logical processor index to a level — the kernel does not publish one, because the index is not something a process is meant to act on. ClassOf answers from the counts in index order, which is the documented layout of hw.perflevel* and is advisory in the strict sense: nothing here can pin a thread to act on it anyway.

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 . See the remarks on this class.

Methods (4)

  • public MacOSProcessorTopology()

    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)

    Always . See the remarks on this class.

  • public void ClearAffinity()

    Does nothing: nothing here ever set an affinity to undo.

Used by (2)

  • MacOSPlatformSupplementVixen.Platform.MacOS
  • MacOSSupplementTestsVixen.Platform.MacOS.Tests