1
0
Fork 0
mirror of https://github.com/anrieff/libcpuid synced 2024-11-30 23:05:48 +00:00
a small C library for x86 CPU detection and feature extraction
Find a file
dependabot[bot] 391b168a49 Bump dawidd6/action-download-artifact from 3 to 6 in /.github/workflows
Bumps [dawidd6/action-download-artifact](https://github.com/dawidd6/action-download-artifact) from 3 to 6.
- [Release notes](https://github.com/dawidd6/action-download-artifact/releases)
- [Commits](https://github.com/dawidd6/action-download-artifact/compare/v3...v6)

---
updated-dependencies:
- dependency-name: dawidd6/action-download-artifact
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-11-26 11:02:16 +01:00
.github/workflows Bump dawidd6/action-download-artifact from 3 to 6 in /.github/workflows 2024-11-26 11:02:16 +01:00
cmake Add cpuid Linux kernel module for ARM CPUs 2024-07-10 20:16:19 +02:00
cpuid_tool Fix a regression in cpuid_tool when ident_required=0 for arg 2024-07-31 16:33:40 +02:00
drivers [CMake] force 'make' usage to build kernel module 2024-10-07 11:07:45 +02:00
libcpuid Fix build error on AArch64 when HWCAP_CPUID is not defined 2024-10-04 12:54:42 +02:00
python Python: Do not fail sanity tests if current CPU is unsupported 2024-09-02 10:27:30 +02:00
tests Tests: fix missing 'arch' field during test creation 2024-08-29 16:44:32 +02:00
utils Move Windows MSR driver to a new directory 2024-07-09 19:02:39 +02:00
.gitignore Document the Python bindings using Sphinx 2024-08-25 12:43:29 +02:00
.readthedocs.yml Python: Refactor the build of the bindings 2024-09-02 10:27:30 +02:00
AUTHORS Moving the repository one level deeper 2008-11-06 18:17:20 +00:00
ChangeLog Release version 0.7.0 2024-08-26 11:05:12 +02:00
cmake-format.py Add config file for cmake-format 2020-05-21 18:42:42 +02:00
CMakeLists.txt Release version 0.7.0 2024-08-26 11:05:12 +02:00
configure.ac Release version 0.7.0 2024-08-26 11:05:12 +02:00
CONTRIBUTING.md Update README.md and add CONTRIBUTING.md 2024-06-30 13:42:24 +02:00
COPYING Moving the repository one level deeper 2008-11-06 18:17:20 +00:00
libcpuid.dsw Remove all trailling spaces 2020-05-09 17:34:07 +02:00
libcpuid.pc.in Incorrect path in .pc file - fixed; Clarified documentation a bit 2008-11-28 16:17:29 +00:00
libcpuid_vc10.sln Remove all trailling spaces 2020-05-09 17:34:07 +02:00
libcpuid_vc71.sln Remove all trailling spaces 2020-05-09 17:34:07 +02:00
Makefile.am Support for hybrid CPU (#166) 2022-09-15 18:37:08 +02:00
Readme.md Add Nix to the list of projects in Readme.md 2024-08-26 14:12:29 +02:00

libcpuid

libcpuid provides CPU identification. Project website is on SourceForge (https://libcpuid.sourceforge.net).

Support

CPU architectures

  • x86:
    • 32-bit CPUs (IA-32, also known as i386, i486, i586 and i686)
    • 64-bit CPUs (x86_64, also known as x64, AMD64, and Intel 64)
  • ARM (since v0.7.0):
    • 32-bit CPUs (ARM32, also known as AArch32)
    • 64-bit CPUs (ARM64, also known as AArch64)

Operating systems

libcpuid support varies depending on the features:

  • build: code build, generate libraries and binaries
  • x86 MSR : access to x86 model-specific registers
  • ARM CPUID : access to ARM registers
Name Build x86 MSR ARM CPUID
DragonFly BSD Build (DragonFly BSD) (cpuctl kernel module)
FreeBSD Build (FreeBSD) ✔️ (cpuctl kernel module) ✔️¹ (cpuid out-of-tree kernel module)
Linux Build (Linux) ✔️ (msr kernel module) ✔️¹ (cpuid out-of-tree kernel module)
macOS Build (macOS)
NetBSD Build (NetBSD)
OpenBSD Build (OpenBSD)
Windows Build (Windows) ✔️ (msr driver)

Legend:

  • ✔️ Supported
  • Likely supported, not heavily tested
  • Not supported
  • ¹ On AArch32 state, the kernel module is required. On AArch64 state, the kernel module is optional, because the kernel can trap the MRS instruction

Getting started

You have two ways to get libcpuid:

  • build it from sources
  • download a pre-compiled binary

Sources

Prerequisites

Using libcpuid requires no dependencies on any of the supported OSes. Building it requires build tool commands to be available, which is a matter of installing a few common packages with related names (e.g. automake, autoconf, libtool, cmake). It also requires a POSIX-compatible shell. On NetBSD, you may need to install one (credits to @brucelilly):

  1. Install a POSIX-compatible shell such as ksh93
pkg_add ast-ksh || pkgin in ast-ksh
  1. Export CONFIG_SHELL with correct path if required:
export CONFIG_SHELL=/usr/pkg/bin/ksh93

Configuring after checkout

Two build systems are supported, use the one you prefer.

By using autotools

Under POSIX systems, where you download the sources, there's no configure script to run. This is because it isn't a good practice to keep such scripts in a source control system. To create it, you need to run the following commands once, after you checkout the libcpuid sources from GitHub:

libtoolize
autoreconf --install

You need to have autoconf, automake and libtool installed.

After that you can run ./configure and make - this will build the library.

make dist will create a tarball (with "configure" inside) with the sources.

By using CMake

CMake options for libcpuid (use cmake -LH to list all options):

  • LIBCPUID_ENABLE_DOCS: enable building documentation by using Doxyen (ON by default)
  • LIBCPUID_ENABLE_TESTS: enable tests targets, like test-fast, test-old and fix-tests (OFF by default)
  • LIBCPUID_BUILD_DEPRECATED: build support of deprecated attributes (ON by default to guarantee backward compatibility)
  • LIBCPUID_BUILD_DRIVERS: enable building kernel drivers (ON by default)
  • LIBCPUID_DRIVER_DEBUG: enable debug mode flr kernel drivers (OFF by default)
  • LIBCPUID_DRIVER_ARM_LINUX_DKMS: use DKMS for CPUID Linux kernel module for ARM (ON by default), switch off to build the kernel module in the build directory

Basic example to build and install libcpuid by using CMake:

cmake -S . -B build -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLIBCPUID_ENABLE_TESTS=ON
cmake --build build
cmake --install build # may need administrative privileges, install under /usr/local by default

Downloads

You can find latest versioned archives here, with binaries for macOS and Windows.

Binary packages

Also, libcpuid is available for following systems in official repositories:

Below, the full lists of repositories:
Packaging status

Build tool

  • Vcpkg: vcpkg install cpuid

Usage

As a software developer

Native C library

For details about the programming API, you might want to take a look at the short tutorial, as well as the full API reference.

Python bindings

The libcpuid library features Python bindings, which can be installed as a library using python -m pip install libcpuid. Visit the documentation at Read the Docs to see how the library is used.

As an end-user

You can use the cpuid_tool command. Pass the --help argument to display usage:

Usage: cpuid_tool [options]

Options:
  -h, --help       - Show this help
  --load=<file>    - Load raw CPUID data from file
  --save=<file>    - Acquire raw CPUID data and write it to file
  --report, --all  - Report all decoded CPU info (w/o clock)
  --clock          - in conjunction to --report: print CPU clock as well
  --clock-rdtsc    - same as --clock, but use RDTSC for clock detection
  --cpulist        - list all known CPUs
  --sgx            - list SGX leaf data, if SGX is supported.
  --hypervisor     - print hypervisor vendor if detected.
  --quiet          - disable warnings
  --outfile=<file> - redirect all output to this file, instead of stdout
  --verbose, -v    - be extra verbose (more keys increase verbosiness level)
  --version        - print library version

Query switches (generate 1 line of output per switch; in order of appearance):
  --cpuid, --architecture, --feature-level, --purpose, --vendorstr, 
  --vendorid, --brandstr, --family, --model, --stepping, --extfamily, 
  --extmodel, --implementer, --variant, --part-num, --revision, --cores, 
  --logical, --total-cpus, --affi-mask, --l1d-cache, --l1i-cache, --cache, 
  --l2-cache, --l3-cache, --l4-cache, --l1d-assoc, --l1i-assoc, --l2-assoc, 
  --l3-assoc, --l4-assoc, --l1d-cacheline, --l1i-cacheline, --l2-cacheline, 
  --l3-cacheline, --l4-cacheline, --l1d-instances, --l1i-instances, 
  --l2-instances, --l3-instances, --l4-instances, --codename, --flags, 
  --clock, --clock-os, --clock-rdtsc, --clock-ic, --rdmsr, --rdmsr-raw, 
  --sse-size

If `-' is used for <file>, then stdin/stdout will be used instead of files.
When no options are present, the program behaves as if it was invoked with
  cpuid_tool "--save=raw.txt --outfile=report.txt --report --verbose"

Contributing

Refer to the dedicated page.

Users

So far, I'm aware of the following projects which utilize libcpuid (listed alphabetically):

We'd love to hear from you if you are also using libcpuid and want your project listed above.