Sha256: 836fc064b77a21e24629bc0e63ea5764122dd4735983055d959f1d3d40bcb166

Contents?: true

Size: 863 Bytes

Versions: 1

Compression:

Stored size: 863 Bytes

Contents

module CPU
  class MSR
    # Returns true if the msr functionality is already available in the kernel
    # (either compiled into it or via a module).
    def self.available?
      File.exist?('/dev/cpu/0/msr')
    end

    # Loads the msr module and sleeps for a second afterwards.
    def self.load_module
      system "#{CPU.modprobe_path} msr"
      sleep 1
    end

    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

    # Returns the byte at +offset+ as an integer number.
    def [](offset)
      @io.sysseek(offset)
      data, = @io.sysread(8).unpack('q')
      data
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cpu-0.0.0 lib/cpu/msr.rb