Class: CPU::MSR
- Inherits:
-
Object
- Object
- CPU::MSR
- Defined in:
- lib/cpu/msr.rb
Class Method Summary collapse
-
.available? ⇒ Boolean
Returns true if the msr functionality is already available in the kernel (either compiled into it or via a module).
-
.load_module ⇒ Object
Loads the msr module and sleeps for a second afterwards.
Instance Method Summary collapse
-
#[](offset) ⇒ Object
Returns the byte at
offset
as an integer number. -
#initialize(processor_id) ⇒ MSR
constructor
Create a new wrapper for the msr kernel file associated with
processor_id
.
Constructor Details
#initialize(processor_id) ⇒ MSR
Create a new wrapper for the msr kernel file associated with processor_id
.
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/cpu/msr.rb', line 17 def initialize(processor_id) self.class.available? or self.class.load_module begin name = '/dev/cpu/%d/msr' % processor_id @io = IO.new IO.sysopen(name, 'rb') rescue Errno::ENOENT raise InvalidProcessorIdError, "'#{processor_id}' is not a valid processor_id on this machine" rescue StandardError => e raise NoSampleDataError, "could not read temperature from #{name}: #{e}" end end |
Class Method Details
.available? ⇒ Boolean
Returns true if the msr functionality is already available in the kernel (either compiled into it or via a module).
5 6 7 |
# File 'lib/cpu/msr.rb', line 5 def self.available? File.exist?('/dev/cpu/0/msr') end |
.load_module ⇒ Object
Loads the msr module and sleeps for a second afterwards.
10 11 12 13 |
# File 'lib/cpu/msr.rb', line 10 def self.load_module system "#{CPU.modprobe_path} msr" sleep 1 end |
Instance Method Details
#[](offset) ⇒ Object
Returns the byte at offset
as an integer number.
30 31 32 33 34 |
# File 'lib/cpu/msr.rb', line 30 def [](offset) @io.sysseek(offset) data, = @io.sysread(8).unpack('q') data end |