Class: CPU::MSR

Inherits:
Object
  • Object
show all
Defined in:
lib/cpu/msr.rb

Class Method Summary collapse

Instance Method Summary collapse

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
# File 'lib/cpu/msr.rb', line 17

def initialize(processor_id)
  self.class.available? or self.class.load_module
  begin
    @io = IO.new IO.sysopen('/dev/cpu/%d/msr' % processor_id, 'rb')
  rescue Errno::ENOENT
    raise InvalidProcessorIdError, "'#{processor_id}' is not a valid processor_id on this machine"
  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).

Returns:

  • (Boolean)


5
6
7
# File 'lib/cpu/msr.rb', line 5

def self.available?
  File.exist?('/dev/cpu/0/msr')
end

.load_moduleObject

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.



27
28
29
30
31
# File 'lib/cpu/msr.rb', line 27

def [](offset)
  @io.sysseek(offset)
  data, = @io.sysread(8).unpack('q')
  data
end