Module: CPUID::Processor
- Included in:
- CPUID
- Defined in:
- lib/cpuid/processor.rb
Constant Summary collapse
- VENDOR_ID_FN =
0
- SIGNATURE_FEATURES_FN =
1
- SERIAL_NUMBER_FN =
3
- MAX_EXT_FN =
0x80000000
- BRAND_STR_FN_1 =
0x80000002
- BRAND_STR_FN_2 =
0x80000003
- BRAND_STR_FN_3 =
0x80000004
- EXT_L2_FN =
0x80000006
- ADDRESS_SIZE_FN =
0x80000008
Instance Method Summary collapse
-
#amd? ⇒ Boolean
Is the process an AMD-made processor?.
-
#brand_string ⇒ String
Returns the full brand string of the processor.
-
#easy_L2_info ⇒ Object
Access L2 information via the extended function, 0x80000006.
-
#family ⇒ Fixnum
The full family number of the intel processor.
-
#intel? ⇒ Boolean
Is the processor an Intel-made processor?.
-
#model ⇒ Fixnum
The full model number of the intel processor.
-
#model_information ⇒ Hash
Returns the model information of the processor, which can be used for telling individual processors apart.
-
#physical_address_size ⇒ Object
Returns the number of maximum bits this processor can address in physical memory.
-
#processor_serial_number ⇒ String
Access the serial number of the processor.
-
#stepping ⇒ Fixnum
The “stepping” of the processor, in number form.
-
#type ⇒ Fixnum
The “type” of the processor, in number form.
-
#vendor_string ⇒ String
Returns the vendor string, available on all processors.
-
#virtual_address_size ⇒ Object
Returns the number of maximum bits in this processor’s virtual address space.
Instance Method Details
#amd? ⇒ Boolean
Is the process an AMD-made processor?
43 44 45 |
# File 'lib/cpuid/processor.rb', line 43 def amd? vendor_string == "AuthenticAMD" end |
#brand_string ⇒ String
Returns the full brand string of the processor
113 114 115 116 117 |
# File 'lib/cpuid/processor.rb', line 113 def brand_string [BRAND_STR_FN_1, BRAND_STR_FN_2, BRAND_STR_FN_3].map do |fxn| reg_array_to_s(run_function(fxn)) end.join end |
#easy_L2_info ⇒ Object
Access L2 information via the extended function, 0x80000006.
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/cpuid/processor.rb', line 133 def easy_L2_info ecx = run_function(SIGNATURE_FEATURES_FN)[2] assoc_bits = ((ecx >> 12) & 0xF) assoc = {} case assoc_bits when 0x0 assoc[:disabled] = true when 0xF assoc[:fully_associative] = true else assoc[:direct_mapped] = true if assoc_bits & 0x1 > 0 assoc[:sixteen_way] = true if assoc_bits & 0x8 > 0 assoc[:eight_way] = true if assoc_bits & 0x6 > 0 assoc[:four_way] = true if assoc_bits & 0x4 > 0 assoc[:two_way] = true if assoc_bits & 0x2 > 0 end {:line_size => ecx & 0xFF, :cache_size => (ecx >> 16) * 1024, :associativity => assoc} end |
#family ⇒ Fixnum
The full family number of the intel processor.
77 78 79 80 |
# File 'lib/cpuid/processor.rb', line 77 def family ext_family = (signature >> 20) & 0xff (ext_family << 4) | ((signature >> 8) & 0xf) end |
#intel? ⇒ Boolean
Is the processor an Intel-made processor?
37 38 39 |
# File 'lib/cpuid/processor.rb', line 37 def intel? vendor_string == "GenuineIntel" end |
#model ⇒ Fixnum
The full model number of the intel processor.
68 69 70 71 |
# File 'lib/cpuid/processor.rb', line 68 def model ext_model = ((signature >> 16) & 0xf) (ext_model << 4) | ((signature >> 3) & 0xf) end |
#model_information ⇒ Hash
Returns the model information of the processor, which can be used for telling individual processors apart. Note: you will need to use cache information as well to tell some processors apart.
25 26 27 28 29 30 31 32 33 |
# File 'lib/cpuid/processor.rb', line 25 def model_information processor_type = [ "Original OEM Processor", "Intel OverDrive", "Dual Processor" ] {:family => family, :model => model, :type => type, :step => stepping, :model_string => processor_type[type]} end |
#physical_address_size ⇒ Object
Returns the number of maximum bits this processor can address in physical memory
127 128 129 |
# File 'lib/cpuid/processor.rb', line 127 def physical_address_size run_function(ADDRESS_SIZE_FN).first & 0xFF end |
#processor_serial_number ⇒ String
Access the serial number of the processor. Will likely fail, because this feature was only enabled for the Pentium III line of intel processors and some very uncommon other manufacturers.
TODO: raise UnsupportedFunction if PSN is unavailable instead of retrieving PSN = 0
91 92 93 94 |
# File 'lib/cpuid/processor.rb', line 91 def processor_serial_number eax, ebx, ecx, edx = run_function(SERIAL_NUMBER_FN) [signature, edx, ecx].map {|reg| register_to_hex_s(reg)}.join("-") end |
#stepping ⇒ Fixnum
The “stepping” of the processor, in number form. Intel term for differentiating processors.
51 |
# File 'lib/cpuid/processor.rb', line 51 def stepping; signature & 0xF; end |
#type ⇒ Fixnum
The “type” of the processor, in number form. Intel term for differentiating processors. Possible values:
0: Original OEM Processor 1: Intel OverDrive 2: Dual Processor
62 |
# File 'lib/cpuid/processor.rb', line 62 def type; (signature >> 12) & 0x3; end |
#vendor_string ⇒ String
Returns the vendor string, available on all processors. Examples: “GenuineIntel”, “AuthenticAMD”
101 102 103 104 |
# File 'lib/cpuid/processor.rb', line 101 def vendor_string eax, ebx, ecx, edx = run_function(VENDOR_ID_FN) register_to_s(ebx) + register_to_s(edx) + register_to_s(ecx) end |
#virtual_address_size ⇒ Object
Returns the number of maximum bits in this processor’s virtual address space
121 122 123 |
# File 'lib/cpuid/processor.rb', line 121 def virtual_address_size (run_function(ADDRESS_SIZE_FN).first >> 8) & 0xFF end |