Ruby CPUID

Questo programmino è un esperimento nel vero senso del termine. È stato cominciato un po' per sfida durante una discussione sul forum per dimostrare che Ruby può essere un linguaggio più chiaro di Python. Come sempre la discussione non è giunta ad una conclusione ma a questo ci siamo abituati nella sezione Programmazione.

Il programma è estremamente semplice. Non fa altro che interrogare la CPU su cui è in esecuzione tramite l'istruzione assembly cpuid ed interpretare le risposte che questa ritorna ogni volta. Una volta terminate tutte le richieste vengono stampate a video una serie di informazioni che indicano il nome, il produttore ed un elenco di caratteristiche supportate.

La porte più interessante di questo programmino è sicuramente l'estensione scritta in C. Ruby essendo un linguaggio di alto livello non mette a disposizione un costrutto per inviare istruzioni assembly alla CPU. Tramite questa estensione però sono riuscito a definire due nuove funzioni C che potessero essere richiamate in maniera nativa anche da Ruby.

Esempio

Questo è un esempio dell'output che produce sul mio iMac.

Brand: Intel(R) Core(TM)2 Duo CPU     T7700  @ 2.40GHz
Family: 6    Model: 15    Step: 10
Type: Original OEM Processor
Vendor: GenuineIntel
 
Features:
  - x87 FPU on Chip
  - Virtual-8086 Mode Enhancement
  - Debugging Extension
  - Page Size Extension
  - Time Stap Counter
  - RDMSR and WRMSR Support
  - Physical Address Extensions
  - Machine Check Exception
  - CMPXCHG8B
  - APIC on Chip
  - SYSENTER and SYSEXIT
  - Memory Type Range Registers
  - PTE Global Bit
  - Machine Check Architecture
  - Conditional Move/Compare Instruction
  - Page Attribute Table
  - Page Size Extension
  - CFLUSH instruction
  - Debug Store
  - Thermal Monitor and Clock Ctrl
  - MMX Technology
  - FXSAVE/FXRSTORE
  - SSE Extension
  - SSE2 Extension
  - Self Snoop
  - Hyper Threading Technology
  - Thermal Monitor
  - Pend. Brk. EN
 
Extended Features:
  - SSE3 Extensions
  - Monitor/Mwait
  - CPL Qualified Debug Store
  - Virtual Machine Extensions
  - Enhanced SpeedStep Technology
  - Thermal Monitor 2
  - SSSE3 Extensions
  - CMPXCHG16B
  - xTPR Update Control
  - Perf/Debug Capablity MSR
 
Cache and TLBs:
  - Instruction TLB: 4 KByte pages, 4-way set associative, 32 entries
  - Instruction TLB: 2M pages, 4-way, 8 entries or 4M pages, 4-way, 4 entries
  - Instruction TLB: 4 KByte pages, 4-way set associative, 128 entries
  - 64-Byte prefetching
  - Data TLB0: 4 KByte pages, 4-way associative, 16 entries
  - Data TLB0: 4 MByte pages, 4-way set associative, 16 entries
  - 3rd-level cache: 4MB, 16-way set associative, 64-byte line size (Intel Xeon processor MP, Family 0F, Model 06H); 2nd-level cache: 4 MByte, 16-way set associative, 64 byte line size
  - 1st-level instruction cache: 32 KBytes, 8-way set associative, 64 byte line size
  - Data TLB1: 4 KByte pages, 4-way associative, 256 entries
  - 1st-level data cache: 32 KBytes, 8-way set associative, 64 byte line size

Sorgenti

Questo e il file zippato che che contiene il codice sorgente e l'estensione.
ruby-cpuid-1.1.zip b5bea4d0c1e39d79c20cad8437aadc57

Repository

La pagina del progetto su Google Code è http://code.google.com/p/ruby-cpuid/.
Per scaricare l'ultima versione dal repository subversion usate il comando:

svn checkout http://ruby-cpuid.googlecode.com/svn/trunk/ ruby-cpuid-read-only