PageRenderTime 45ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/scripts/cpu-type.py

https://github.com/billy3321/lazybuntu
Python | 52 lines | 31 code | 8 blank | 13 comment | 15 complexity | aa3e877d4573d8d89edabc819e8e25e0 MD5 | raw file
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # Copyright (C) 2007 洪任諭 Hong Jen Yee (PCMan) <pcman.tw@gmail.com>
  4. # Released under GNU General Public License
  5. # This script is used to detect cpu type for swiftfox
  6. # print 'pentium3', 'pentium-m', 'pentium4', 'prescott',
  7. # 'athlon-xp', 'athlon64' to stdout
  8. # if the cpu is not supported, the program prints nothing
  9. #References:
  10. # http://www.sandpile.org/ia32/cpuid.htm
  11. # http://download.intel.com/design/processor/applnots/24161831.pdf
  12. import sys, os, re
  13. f=open('/proc/cpuinfo', 'r')
  14. info=f.read()
  15. f.close()
  16. match=re.search('vendor_id[^\w]*(\w+)', info)
  17. if not match:
  18. exit(1)
  19. vender=match.group(1)
  20. match=re.search('cpu family[^\d]*(\d+)', info)
  21. if not match:
  22. exit(1)
  23. family=int(match.group(1))
  24. match=re.search('model[^\d]*(\d+)', info)
  25. if not match:
  26. exit(1)
  27. model=int(match.group(1))
  28. if vender=='GenuineIntel': # Intel
  29. if family==6: # Intel P6, P2, P3, PM, Core 2
  30. if model==9 or model==13: #PM
  31. print 'pentium-m'
  32. elif model>=7 and model<=11: # P3
  33. print 'pentium3'
  34. elif model>=14: # CD, C2D
  35. print 'prescott'
  36. elif family==15: # P4 series
  37. print 'pentium4'
  38. elif vender=='AuthenticAMD': # AMD
  39. if family==6: # AMD K7: Athlon, Duron
  40. print 'athlon-xp'
  41. elif family==15 or family==0: # extended family, treated as K8??
  42. # FIXME: I'm not sure if this is correct
  43. # FIXME: 64 bit environment is not currently supported
  44. print 'athlon-64-32bit'