Blog posts by @retrage

mirror of https://retrage.github.io/

/proc/cpuinfoのflagsについて調べてみた。

Linuxのprocfsが提供する情報の一つに、/proc/cpuinfoというのがあります。

 

これは名前そのまま、CPUの情報を見ることができます。

$ cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 58
model name : Intel(R) Core(TM) i7-3820QM CPU @ 2.70GHz
stepping : 9
microcode : 0x15
cpu MHz : 2693.498
cache size : 8192 KB
physical id : 0
siblings : 1
core id : 0
cpu cores : 1
apicid : 0
initial apicid : 0
fpu : yes
fpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology tsc_reliable nonstop_tsc aperfmperf pni pclmulqdq vmx ssse3 cx16 pcid sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm ida arat epb pln pts dtherm tpr_shadow vnmi ept vpid fsgsbase tsc_adjust smep
bogomips : 5386.99
clflush size : 64
cache_alignment : 64
address sizes : 42 bits physical, 48 bits virtual
power management: 

このcpuinfoのflagを見ることで、CPUの拡張機能についてみることができます。

で、実際のところこのflagsの情報がどのように提供されているかx86の場合について調べてみました。

最初にLinux kernel(4.0)を見てみます。

x86では

arch/x86/include/asm/cpufeature.h

Linux/arch/x86/include/asm/cpufeature.h - Linux Cross Reference - Free Electrons

に書かれているようです。 

25行目以降に

#define X86_FEATURE_FPU         ( 0*32+ 0) /* Onboard FPU */
#define X86_FEATURE_VME ( 0*32+ 1) /* Virtual Mode Extensions */
#define X86_FEATURE_DE ( 0*32+ 2) /* Debugging Extensions */
(以下略)

といった形でマクロがコメントとともに宣言されています。どうやら何らかの値がflagsに対応しているようです。

実際にその値を提供しているのが、"CPUID"という命令のようです。

CPUIDは後期のi486から現在までのどのCPUの形式であるか、どのような機能があるかを提供する命令だそうです。細かい話はIntelx86のマニュアルを見ると書いてあります。

CPUID - Wikipedia

 

あとでちょっとIntelのマニュアルを見てみようと思います。