RFC: Adding a hw.features[2] sysctl

Peter Wemm peter at wemm.org
Sat Jan 12 23:10:35 PST 2008

On Jan 12, 2008 10:44 PM, Kostik Belousov <kostikbel at gmail.com> wrote:
> On Sat, Jan 12, 2008 at 11:16:27PM -0500, Joe Marcus Clarke wrote:
> > I find it would be useful to have the list of CPU features available via
> > a sysctl.  Currently, he only ways to get this information are to have
> > linprocfs mounted, or parse dmesg.boot (if it exists).  Attached are
> Not quite true, since the raw CPU capabilities are accessible using
> the cpuid instruction, both to the kernel- and user-mode.
> > patches to add hw.features and hw.features2 sysctls for i386 and amd64
> > (where a list of CPU features is applicable).  The results are identical
> > to the Features and Features2 strings from dmesg:
> >
> > hw.features2: 0x41d<SSE3,RSVD2,MON,DS_CPL,CNXT-ID>
> > hw.features:
> >
> > Comments?
> The only part that I do not fully agree is to dedicate 1Kb of the kernel
> memory to the strings that could be reconstructed in the usermode and
> are relatively rare used.
> I would suggest either export only bitmask of the cpu features and do
> the formatting in the sysctl(8), or implement the user-mode utility that
> would pretty-print results of the cpuid execution, like cpuid from ports.
> The first option could be preferable, since kernel might disable some
> features, that is not reflected in the output of cpuid instruction.
> Example of this would be identcpu.c, line 860 (HTT on AMD).

It just so happens I wrote almost exactly this program a few weeks ago
for somebody at work:

peter at daintree[11:05pm]~-101> ./is64bit
CPU: AMD Athlon(tm) 64 Processor 3200+
Stepping = 8
AMD Features=0xe0500800<SYSCALL,NX,MMX+,LM,3DNow!+,3DNow!>
64 bit capable: Yes
64 bit OS: Yes

peter at overcee[11:06pm]~-306> ./is64bit
CPU: AMD Athlon(tm) 64 X2 Dual Core Processor 6000+
Stepping = 3
AMD Features=0xea500800<SYSCALL,NX,MMX+,FFXSR,RDTSCP,LM,3DNow!+,3DNow!>
AMD Features2=0x1f<LAHF,CMP,SVM,ExtAPIC,CR8>
Cores per package: 2
64 bit capable: Yes
64 bit OS: Yes

It is a 32 bit 4.x 'run everywhere' binary.  They wanted it for
surveying machines to see which could be upgraded to a 64 bit OS.

It runs silently returns status code based on 64-bit-ness if you give
it the -q flag.

It is a 100% cut/paste from identcpu etc.

Peter Wemm - peter at wemm.org; peter at FreeBSD.org; peter at yahoo-inc.com
"All of this is for nothing if we don't go to the stars" - JMS/B5

More information about the freebsd-current mailing list