Home > coding, hardware > CPU flags explained (linux)

CPU flags explained (linux)

i had to find some cpu flags and their descriptions, so i wrote a little utility script that explains what features your CPU has. It uses your kernel's cpuinfo includes to gather the descriptions and /proc/cpuinfo to get the actual flags. For example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
$ ./cpufeatures.py
                 fpu : Onboard FPU
                 vme : Virtual Mode Extensions
                  de : Debugging Extensions
                 pse : Page Size Extensions
                 tsc : Time Stamp Counter
                 msr : Model-Specific Registers
                 pae : Physical Address Extensions
                 mce : Machine Check Exception
                 cx8 : CMPXCHG8 instruction
                apic : Onboard APIC
                 sep : SYSENTER/SYSEXIT
                mtrr : Memory Type Range Registers
                 pge : Page Global Enable
                 mca : Machine Check Architecture
                cmov : CMOV instructions
                 pat : Page Attribute Table

cpufeatures.py :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/env python
import re

cpuflag_descriptions = {
   # filled during runtime, see readLinuxKernelCPUFeatures
}

def readLinuxKernelCPUFeatures():
   f = open('/usr/src/linux/arch/x86/include/asm/cpufeature.h', 'r')
   lines = f.readlines()
   f.close()
   for line in lines:
      m = re.search('#define X86_FEATURE_([A-Za-z0-9_]*).*\/\* (.*)\*\/', line)
      if m is None:
         continue
      cpuflag_descriptions[m.group(1).lower()] = m.group(2)

def readCPUInfo():
   f = open('/proc/cpuinfo')
   lines = f.readlines()
   f.close()
   return lines

def getCPUInfo():
   result = {}
   lines = readCPUInfo()
   proc = -1
   for line in lines:
      args = map(lambda arg: arg.strip(), line.split(':'))
      if len(args) != 2:
         continue
      if args[0] == 'processor':
         proc = int(args[1])
         result[proc] = {}
         continue
      if args[0] == 'flags':
         args[1] = args[1].split()
      result[proc][args[0]] = args[1]
   return result

def processCPUFlags(cpuinfo, cpu=0):
   flags = cpuinfo[0]['flags']
   for f in flags:
      if not f in cpuflag_descriptions:
         print "%20s : unkown" % (f)
      else:
         print "%20s : %s" % (f, cpuflag_descriptions[f])

def explainCPUFlags():
   cpuinfo = getCPUInfo()
   processCPUFlags(cpuinfo)

readLinuxKernelCPUFeatures()
#print cpuflag_descriptions
explainCPUFlags()
Categories: coding, hardware Tags:
  1. No comments yet.
  1. No trackbacks yet.


1 + = seven