add automatic msr module loading

This commit is contained in:
erpalma
2018-04-07 19:09:06 +02:00
parent 0466866f5f
commit 5022a86156

View File

@@ -4,6 +4,7 @@ import ConfigParser
import glob import glob
import os import os
import struct import struct
import subprocess
from collections import defaultdict from collections import defaultdict
from periphery import MMIO from periphery import MMIO
@@ -21,7 +22,10 @@ def writemsr(msr, val):
os.write(f, struct.pack('Q', val)) os.write(f, struct.pack('Q', val))
os.close(f) os.close(f)
if not n: if not n:
raise OSError("msr module not loaded (run modprobe msr)") try:
subprocess.check_call(('modprobe', 'msr'))
except subprocess.CalledProcessError:
raise OSError("Unable to load msr module.")
def is_on_battery(): def is_on_battery():