Skip to contentSkip to conversation

tools/x86: add kcpuid tool to show raw CPU features

RFC PATCH New Feng Tang 1 participant 1 message Jul 21, 2020

lore
Share & tools
lore

Feng Tang

author
#0 lore raw

RFC PATCH 1/1 tools/x86: add kcpuid tool to show raw CPU features

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 can 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
1. Can make up for the ambiguity of cpuinfo
2. Be easier to obtain updates for compared to existing userspace tooling (perhaps distributed like perf(1))
3. 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.
4. Can produce output consistent with /proc/cpuinfo to make comparison easier
5. Being in-kernel, could leverage kernel enabling, and even theoretically consume arch/x86/boot/cpustr.h so it could pick up new features directly from one-line X86_FEATURE_* definitions.

This RFC is an early prototype, and would get community's opinion on whether it's the right thing to do, and what functions it should also support.

Current version only shows limited number of cpu features, and can also dump all raw cpuid leaf data. Some todos are:
1. Parse all cpu raw features
2. Run cpuid with specific parameters from user input

This is based on the prototype code from Borislav Petkov [1]

output of the tool
------------------

	CPUID leafs total: 28

	cpu family	: 6
	model		: 13
	stepping	: 7

	CPU features
	------------
	 sse3
	 pclmlqdq
	 dtes64
	 mwait
	 ds_cpl
	 vmx
	 smx
	 eist
	 tm2
	 ssse3
	 cx16
	 pctxid
	 dca
	 sse4_1
	 sse4_2
	 x2apic
	 tsc_deadline_timer
	 aes
	 xsave
	 osxsave
	 avx
	 fpu
	 ...

[1] http://sr71.net/~dave/intel/stupid-cpuid.c

---
 tools/arch/x86/tools/kcpuid/Makefile |  21 ++
 tools/arch/x86/tools/kcpuid/kcpuid.c | 422 +++++++++++++++++++++++++++++++++++
 2 files changed, 443 insertions(+)
 create mode 100644 tools/arch/x86/tools/kcpuid/Makefile
 create mode 100644 tools/arch/x86/tools/kcpuid/kcpuid.c
tools/arch/x86/tools/kcpuid/Makefile new file +21 -0
new file mode 100644
index 0000000..21453e5
@@ -0,0 +1,21 @@
+# SPDX-License-Identifier: GPL-2.0
+# Makefile for x86/kcpuid tool
+
+kcpuid : kcpuid.c
+
+CFLAGS =  -Wextra
+
+BINDIR ?= /usr/sbin
+
+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
tools/arch/x86/tools/kcpuid/kcpuid.c new file +422 -0

422 lines not on this page · raw message

Signature · 1 line
2.7.4