Pin thread to cores sharing L2 cache with the current core (Linux or Android)
cpuinfo_initialize();
cpu_set_t cpu_set;
CPU_ZERO(&cpu_set);
const struct cpuinfo_cache* current_l2 = cpuinfo_get_current_processor()->cache.l2;
for (uint32_t i = 0; i < current_l2->processor_count; i++) {
CPU_SET(cpuinfo_get_processor(current_l2->processor_start + i)->linux_id, &cpu_set);
}
pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpu_set);
Use via pkg-config
If you would like to provide your project’s build environment with the necessary compiler and linker flags in a portable manner, the library by default when built enables CPUINFO_BUILD_PKG_CONFIG and will generate a pkg-config manifest (libcpuinfo.pc). Here are several examples of how to use it:
Command Line
If you used your distro’s package manager to install the library, you can verify that it is available to your build environment like so:
CPU INFOrmation library
cpuinfo is a library to detect essential for performance optimization information about host CPU.
Features
Examples
Log processor name:
Detect if target is a 32-bit or 64-bit ARM system:
Check if the host CPU supports ARM NEON
Check if the host CPU supports x86 AVX
Check if the thread runs on a Cortex-A53 core
Get the size of level 1 data cache on the fastest core in the processor (e.g. big core in big.LITTLE ARM systems):
Pin thread to cores sharing L2 cache with the current core (Linux or Android)
Use via pkg-config
If you would like to provide your project’s build environment with the necessary compiler and linker flags in a portable manner, the library by default when built enables
CPUINFO_BUILD_PKG_CONFIG
and will generate a pkg-config manifest (libcpuinfo.pc). Here are several examples of how to use it:Command Line
If you used your distro’s package manager to install the library, you can verify that it is available to your build environment like so:
If you have installed the library from source into a non-standard prefix, pkg-config may need help finding it:
GNU Autotools
To use with the GNU Autotools include the following snippet in your project’s
configure.ac
:Meson
To use with Meson you just need to add
dependency('libcpuinfo')
as a dependency for your executable.Bazel
This project can be built using Bazel.
You can also use this library as a dependency to your Bazel project. Add to the
WORKSPACE
file:And to your
BUILD
file:CMake
To use with CMake use the FindPkgConfig module. Here is an example:
Makefile
To use within a vanilla makefile, you can call pkg-config directly to supply compiler and linker flags using shell substitution.
Exposed information
Supported environments:
mips ABImips64 ABIMethods
/proc/cpuinfo
on ARMro.chipname
,ro.board.platform
,ro.product.board
,ro.mediatek.platform
,ro.arch
properties (Android)dmesg
) on ARM Linux/proc/cpuinfo
on 32-bit ARM EABI (Linux)FPSID
andWCID
registers (32-bit ARM)getauxval
(Linux/ARM)/proc/self/auxv
(Android/ARM)/proc/cpuinfo
(Linux/pre-ARMv7)sysctlbyname
(Mach)typology
directories (ARM/Linux)cache
directories (Linux)GetLogicalProcessorInformationEx
on ARM64 Windows/proc/cpuinfo
(Linux)host_info
(Mach)GetLogicalProcessorInformationEx
(Windows)