| commit | 58870cb25ec9d088cb316b32a12c37f1e4ce7a94 | [log] [tgz] |
|---|---|---|
| author | fbarchard <fbarchard@google.com> | Wed Jan 14 09:57:04 2026 -0800 |
| committer | Copybara-Service <copybara-worker@google.com> | Wed Jan 14 10:09:40 2026 -0800 |
| tree | 0587a365d0fb969a8b0921c6a110eb52212b3faa | |
| parent | fbfe5ddc75d0f8b80491a4a91d40bafb12da1a0b [diff] |
Add ARM Cortex A520 little core uarch (#367) Example Samsung S24 sm-s921u SoC name: Unknown Microarchitectures: 1x Cortex-X4 5x Cortex-A720 2x Cortex-A520 Cores: 0: 1 processor (0), ARM Cortex-X4 1: 1 processor (1), ARM Cortex-A720 2: 1 processor (2), ARM Cortex-A720 3: 1 processor (3), ARM Cortex-A720 4: 1 processor (4), ARM Cortex-A720 5: 1 processor (5), ARM Cortex-A720 6: 1 processor (6), ARM Cortex-A520 7: 1 processor (7), ARM Cortex-A520 Clusters: 0: 1 processor (0), 0: 1 core (0), ARM Cortex-X4 1: 3 processors (1-3), 1: 3 cores (1-3), ARM Cortex-A720 2: 2 processors (4-5), 2: 2 cores (4-5), ARM Cortex-A720 3: 2 processors (6-7), 3: 2 cores (6-7), ARM Cortex-A520 Logical processors (System ID): 0 (7) 1 (2) 2 (3) 3 (4) 4 (5) 5 (6) 6 (0) 7 (1) GitOrigin-RevId: c4b4f4bf08c0cf486fc3111d0244ebf2a48ad01b Change-Id: I63adcc520b0b9d1061eadd706fcdd7f19bcec297
cpuinfo is a library to detect essential for performance optimization information about host CPU.
Log processor name:
cpuinfo_initialize(); printf("Running on %s CPU\n", cpuinfo_get_package(0)->name);
Detect if target is a 32-bit or 64-bit ARM system:
#if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64 /* 32-bit ARM-specific code here */ #endif
Check if the host CPU supports ARM NEON
cpuinfo_initialize(); if (cpuinfo_has_arm_neon()) { neon_implementation(arguments); }
Check if the host CPU supports x86 AVX
cpuinfo_initialize(); if (cpuinfo_has_x86_avx()) { avx_implementation(arguments); }
Check if the thread runs on a Cortex-A53 core
cpuinfo_initialize(); switch (cpuinfo_get_current_core()->uarch) { case cpuinfo_uarch_cortex_a53: cortex_a53_implementation(arguments); break; default: generic_implementation(arguments); break; }
Get the size of level 1 data cache on the fastest core in the processor (e.g. big core in big.LITTLE ARM systems):
cpuinfo_initialize(); const size_t l1_size = cpuinfo_get_processor(0)->cache.l1d->size;
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);
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:
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:
$ pkg-config --cflags --libs libcpuinfo -I/usr/include/x86_64-linux-gnu/ -L/lib/x86_64-linux-gnu/ -lcpuinfo
If you have installed the library from source into a non-standard prefix, pkg-config may need help finding it:
$ PKG_CONFIG_PATH="/home/me/projects/cpuinfo/prefix/lib/pkgconfig/:$PKG_CONFIG_PATH" pkg-config --cflags --libs libcpuinfo -I/home/me/projects/cpuinfo/prefix/include -L/home/me/projects/cpuinfo/prefix/lib -lcpuinfo
To use with the GNU Autotools include the following snippet in your project's configure.ac:
# CPU INFOrmation library... PKG_CHECK_MODULES( [libcpuinfo], [libcpuinfo], [], [AC_MSG_ERROR([libcpuinfo missing...])]) YOURPROJECT_CXXFLAGS="$YOURPROJECT_CXXFLAGS $libcpuinfo_CFLAGS" YOURPROJECT_LIBS="$YOURPROJECT_LIBS $libcpuinfo_LIBS"
To use with Meson you just need to add dependency('libcpuinfo') as a dependency for your executable.
project( 'MyCpuInfoProject', 'cpp', meson_version: '>=0.55.0' ) executable( 'MyCpuInfoExecutable', sources: 'main.cpp', dependencies: dependency('libcpuinfo') )
This project can be built using Bazel.
You can also use this library as a dependency to your Bazel project. Add to your MODULE.bazel file:
# fetch cpuinfo from Bazel Central Registry: https://registry.bazel.build/modules/cpuinfo bazel_dep(name = "cpuinfo", version = "0.0.0-20250925-877328f") # Optional: Override it with some specific commit hash git_override( module_name = "cpuinfo", commit = "<replace_with_commit_hash>" remote = "https://github.com/pytorch/cpuinfo.git", )
And to your BUILD file:
cc_binary( name = "cpuinfo_test", srcs = [ # ... ], deps = [ "@cpuinfo", ], )
To use with CMake use the FindPkgConfig module. Here is an example:
cmake_minimum_required(VERSION 3.6) project("MyCpuInfoProject") find_package(PkgConfig) pkg_check_modules(CpuInfo REQUIRED IMPORTED_TARGET libcpuinfo) add_executable(${PROJECT_NAME} main.cpp) target_link_libraries(${PROJECT_NAME} PkgConfig::CpuInfo)
To use within a vanilla makefile, you can call pkg-config directly to supply compiler and linker flags using shell substitution.
CFLAGS=-g3 -Wall -Wextra -Werror ... LDFLAGS=-lfoo ... ... CFLAGS+= $(pkg-config --cflags libcpuinfo) LDFLAGS+= $(pkg-config --libs libcpuinfo)
/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 and WCID 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)