Determining system capabilities
Interrogate the system for processor, cache, and topology information.
Overview
Obtain information about parameters related to processor availability, cache size, and performance-level characteristics on the system by using the sysctlbyname function. These parameters provide details about your system that can aid in tuning performance. For example, you can obtain the count of the highest-performing processor cores to spawn a worker thread for each core. Or you can determine the size of the L2 cache and the number of processor cores that share it to perform software cache-blocking optimization.
Determine processor characteristics
The system enables a processor core when it’s powered on and available for thread scheduling. Each logical processor core executes a software thread that the operating system manages. On systems where the number of logical processor cores exceeds the number of physical processor cores, two or more logical processor cores share a physical core through simultaneous multithreading (SMT). The following parameters provide processor availability information about the system on chip (SoC):
hw.activecpuThe number of enabled logical processor cores in the SoC. This is an alias of
hw.logicalcpu.hw.ncpuThe number of logical processor cores in the SoC. This is an alias of
hw.logicalcpu_max.hw.logicalcpuThe number of enabled logical processor cores in the SoC. This is an alias of
hw.activecpu.hw.logicalcpu_maxThe number of logical processor cores in the SoC. This is an alias of
hw.ncpu.hw.physicalcpuThe number of enabled physical processor cores in the SoC.
hw.physicalcpu_maxThe number of physical processor cores in the SoC.
Determine system topology
The following parameters provide processor core performance-level information. First, determine the number of types of processor cores with hw.nperflevels. Then, for each of the parameters, replace N with a number between 0 and the number of performance levels minus one. Lower values of N indicate higher-performance core types.
hw.nperflevelsThe number of types of general purpose processor cores in the SoC.
hw.perflevelN.cpusperl2For processor cores of performance level N, the number of cores that share an L2 cache.
hw.perflevelN.cpusperl3For processor cores of performance level N, the number of cores that share an L3 cache.
hw.perflevelN.l1dcachesizeFor processor cores of performance level N, the size in bytes of the L1 data cache.
hw.perflevelN.l1icachesizeFor processor cores of performance level N, the size in bytes of the L1 instruction cache.
hw.perflevelN.l2cachesizeFor processor cores of performance level N, the size in bytes of the L2 cache.
hw.perflevelN.l3cachesizeFor processor cores of performance level N, the size in bytes of the L3 cache.
hw.perflevelN.logicalcpuFor processor cores of performance level N, the number of enabled logical cores in the SoC.
hw.perflevelN.logicalcpu_maxFor processor cores of performance level N, the number of logical cores in the SoC.
hw.perflevelN.physicalcpuFor processor cores of performance level N, the number of enabled physical cores in the SoC.
hw.perflevelN.physicalcpu_maxFor processor cores of performance level N, the number of physical cores in the SoC.
Querying the following parameters is equivalent to querying the per-performance-level information for the least performant core. For example, hw.l1dcachesize is equivalent to hw.perflevel[N].l1dcachesize, where N is hw.nperflevels minus one.
hw.l1dcachesizeThe size in bytes of the L1 data cache.
hw.l1icachesizeThe size in bytes of the L1 instruction cache.
hw.l2cachesizeThe size in bytes of the L2 cache.
hw.l3cachesizeThe size in bytes of the L3 cache.
Determine memory sizes
The following parameters provide cache line, memory, and page size information:
hw.cachelinesizeThe size in bytes of the system cache line.
hw.memsizeThe size in bytes of dynamic RAM.
hw.pagesizeThe size in bytes of a virtual memory page.