# Easy way to get cpu features



## Freddie (Jan 21, 2010)

I was wondering if there is an easy way to get certain cpu features like SSE2 or MMX without coding cpuid in assembler?

thx
Freddie


----------



## Freddie (Jan 21, 2010)

*Forgot to add*

I've noticed the in the kernel initcpu.c file that there are cpu_feature flags, but is this exposed to userland in one way or another?


----------



## aragon (Jan 21, 2010)

The only way I know is via linprocfs(8) and text processing proc/cpuinfo.

Or to do something similar to /var/run/dmesg.boot.


----------



## DutchDaemon (Jan 21, 2010)

Freddie, do you mean how to use those features, or how to get an overview of the features? They will always be printed in dmesg (so [cmd=]dmesg -a[/cmd] or /var/run/dmesg.boot), e.g.


```
# grep Features /var/run/dmesg.boot
  Features=0xbfebfbff<FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CLFLUSH,DTS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE>
  Features2=0xe3bd<SSE3,DTES64,MON,DS_CPL,VMX,EST,TM2,SSSE3,CX16,xTPR,PDCM>
  AMD Features=0x20100800<SYSCALL,NX,LM>
  AMD Features2=0x1<LAHF>
```


----------



## dennylin93 (Jan 21, 2010)

Freddie said:
			
		

> I was wondering if there is an easy way to get certain cpu features like SSE2 or MMX without coding cpuid in assembler?
> 
> thx
> Freddie



You can set the CPU type to native for GCC 4.2 and above: Intel 386 and AMD x86-64 Options.


----------



## Freddie (Jan 21, 2010)

DutchDaemon: Yes, I mean getting an overview of those features. I found a thread on the freebsd-current@freebsd.org mailing list about implementing a function that can fetch the cpu features, but it looks like it has not been implemented (yet)

http://www.mailinglistarchive.com/freebsd-current@freebsd.org/msg15695.html

So it looks like parsing the /var/run/dmesg.boot manually is the way forward?


----------



## DutchDaemon (Jan 21, 2010)

Looks like it, unless someone knows which call harvests these data and prints them to dmesg and how to use it as a separate cli utility


----------



## expl (Jan 21, 2010)

There is some limited information available via sysctl. On FreeBSD however it is even more limited, there is only "hw.instruction_sse" flag that will then in return state that MMX is also available. I have seen several libraries and utilities that had to check CPU features at some step and most either parsed dmesg.boot or had an internal CPU feature database, since all other methods are not portable.


----------



## Freddie (Jan 21, 2010)

Perhaps I can add a feature request to the FreeBSD team to expose more cpu features via sysctl? Does anybody know where this can be done?

Freddie


----------



## expl (Jan 21, 2010)

Freddie said:
			
		

> Perhaps I can add a feature request to the FreeBSD team to expose more cpu features via sysctl? Does anybody know where this can be done?
> 
> Freddie



My guess would be http://lists.freebsd.org/mailman/listinfo/freebsd-hackers


----------



## madevil (Jul 19, 2011)

Gwenole Beauchesne <gb.public@free.fr> made a tool for this, but the original site seems unavailable, there are other sites though: 
http://www.sourcefiles.org/System/Administration/Miscellaneous/
look for cpuinfo-1.0-20070715.tar.bz2

I haven't checked myself on freebsd amd64, it goes just fine on snow leopard, but I had it built on leopard so... I'll just try and get back later...


----------



## DutchDaemon (Jul 19, 2011)

There's also devel/cpuflags


```
$ cpuflags                                                                                                               
Unknown machine - please send cpuflags details to [edit]
OS		: 'FreeBSD'
hw.model	: 'Intel Core2 Duo CPU     T7500  @ 2.20GHz'
hw.machine	: 'amd64'
hw.machine_arch : 'amd64'
cpu details	:
CPU: Intel(R) Core(TM)2 Duo CPU     T7500  @ 2.20GHz (2194.52-MHz K8-class CPU)
  Origin = "GenuineIntel"  Id = 0x6fb  Family = 6  Model = f  Stepping = 11
  Features=0xbfebfbff<FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CLFLUSH,DTS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE>
  Features2=0xe3bd<SSE3,DTES64,MON,DS_CPL,VMX,EST,TM2,SSSE3,CX16,xTPR,PDCM>
  AMD Features=0x20100800<SYSCALL,NX,LM>
  AMD Features2=0x1<LAHF>
  TSC: P-state invariant
-msse3 -mfpmath=sse
```

Most of this is already in dmesg.


----------



## graudeejs (Jul 19, 2011)

BTW, here's article, that explains most of dmesg CPU Features


----------



## xibo (Jul 22, 2011)

cpuctl(4)


----------



## madevil (Jul 23, 2011)

hey... nevermind... I just tought you guys would appreciate such program, I know there must be like 20+ out there. besides anyone could actually go ahead read the product # on the box in which your PC's CPU came and then look it up on the proper mfg's page...

the author of the app I posted above (of whom there is like no more info of whatsoever he's doing right know, perhaps vacations?) is also the author of stuf such like NSPluginWrapper, SheepShaver, Basilisk II JIT... just to mention a few.

I'm not taking any credits on that... is quite hard to find it anyways... kindda rare piece of soft.. .I can be wrong thogh... so as by the freebsd style... nevermind.


----------



## madevil (Jul 23, 2011)

sorry... I just got kindda touchy on the subject, I expected someone would find it interesting like I did... don't get me wrong, I don't want to get banned, sorry... just realized I was shouting...


----------

