Skip to content

Commit

Permalink
tools/x86: Add a kcpuid tool to show raw CPU features
Browse files Browse the repository at this point in the history
End users frequently want to know what features their processor
supports, independent of what the kernel supports.

/proc/cpuinfo is great. It is omnipresent and since it is provided by
the kernel it is always as up to date as the kernel. But, it could be
ambiguous about processor features which can be disabled by the kernel
at boot-time or compile-time.

There are some user space tools showing more raw features, but they are
not bound with kernel, and go with distros. Many end users are still
using old distros with new kernels (upgraded by themselves), and may
not upgrade the distros only to get a newer tool.

So here arise the need for a new tool, which
  * shows raw CPU features read from the CPUID instruction
  * will be easier to update compared to existing userspace
    tooling (perhaps distributed like perf)
  * inherits "modern" kernel development process, in contrast to some
    of the existing userspace CPUID tools which are still being developed
    without git and distributed in tarballs from non-https sites.
  * Can produce output consistent with /proc/cpuinfo to make comparison
    easier.

The CPUID leaf definitions are kept in an .csv file which allows for
updating only that file to add support for new feature leafs.

This is based on prototype code from Borislav Petkov
(http://sr71.net/~dave/intel/stupid-cpuid.c).

 [ bp:
   - Massage, add #define _GNU_SOURCE to fix implicit declaration of
     function ‘strcasestr' warning
   - remove superfluous newlines
   - fallback to cpuid.csv in the current dir if none found
   - fix typos
   - move comments over the lines instead of sideways. ]

Originally-from: Borislav Petkov <[email protected]>
Suggested-by: Dave Hansen <[email protected]>
Suggested-by: Borislav Petkov <[email protected]>
Signed-off-by: Feng Tang <[email protected]>
Signed-off-by: Borislav Petkov <[email protected]>
Link: https://lkml.kernel.org/r/[email protected]
  • Loading branch information
ftang1 authored and suryasaimadhu committed Mar 8, 2021
1 parent a38fd87 commit c6b2f24
Show file tree
Hide file tree
Showing 3 changed files with 1,059 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tools/arch/x86/kcpuid/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# SPDX-License-Identifier: GPL-2.0
# Makefile for x86/kcpuid tool

kcpuid : kcpuid.c

CFLAGS = -Wextra

BINDIR ?= /usr/sbin

HWDATADIR ?= /usr/share/misc/

override CFLAGS += -O2 -Wall -I../../../include

%: %.c
$(CC) $(CFLAGS) -o $@ $< $(LDFLAGS)

.PHONY : clean
clean :
@rm -f kcpuid

install : kcpuid
install -d $(DESTDIR)$(BINDIR)
install -m 755 -p kcpuid $(DESTDIR)$(BINDIR)/kcpuid
install -m 444 -p cpuid.csv $(HWDATADIR)/cpuid.csv
Loading

0 comments on commit c6b2f24

Please sign in to comment.