Commit 233f10e3 authored by Kazutomo Yoshii's avatar Kazutomo Yoshii Committed by Valentin Reis

[feature] adds power capping via msr-safe

parent a4c6197c
Pipeline #7735 passed with stages
in 11 minutes and 24 seconds
......@@ -50,7 +50,7 @@ def main(argv=None):
}
if args.print_defaults:
print defaults
print(defaults)
return(0)
if args.configuration:
......@@ -66,6 +66,10 @@ def main(argv=None):
"environment variable",
default=os.environ.get('NRM_LOG',
'/tmp/nrm.log'))
parser.add_argument(
'--msr_safe',
help="Whether to use msr_safe instead of RAPL",
default=True)
parser.add_argument(
'--hwloc',
help="Path to the hwloc to use. This path can be "
......
......@@ -8,22 +8,52 @@
# SPDX-License-Identifier: BSD-3-Clause
###############################################################################
""" Msr Module:
This module provides the interfaces to read and write msr through msr_safe
kernel module.
""" Msr Module: This module provides the interfaces to read and write msr
through the msr_safe kernel module.
Note: msr_safe kernel module needs to be installed on your machine for this
module to work. To run with root privileges change 'msr_safe' in
get_file_name() function to 'msr'.
Note: the msr_safe kernel module needs to
be installed on your machine for this module to work.
"""
import os
import math
import sys
import errno
import struct
_msr_unit_location = 0x00000606
_msr_powerlimit_location = 0x00000610
class Msr:
# set power limits for a specific cpu. writes are in effect
# for all cpus on the same package.
def set_powerlimit(self, cpu, watts):
unit = math.sqrt(float(self.read(cpu, _msr_unit_location) & 0xf))
limit = self.read(cpu, _msr_powerlimit_location)
self.write(cpu, _msr_powerlimit_location,
self._insertbits(limit, 0, 14, watts / unit))
# for debugging purposes:
def _extractbits(self, val, l, h):
w = h - l + 1
if (w < 1):
return (0)
val = long(val) >> l
m = (long(1) << w) - 1
val = val & m
return (val)
def _insertbits(self, val, l, h, newval):
w = h - l + 1
if w < 1:
return (0)
m = (long(1) << w) - 1
newval = long(newval) & m
m = (long(1) << (h + 1)) - 1 - ((long(1) << l) - 1)
m = ~m
return (long(val) & m) | (newval << l)
# get msr file name for the cpu
def get_file_name(self, cpu):
return '/dev/cpu/%d/msr_safe' % cpu
......
......@@ -298,7 +298,7 @@ class Daemon(object):
downstream_event_uri=downstream_event_param,
)
self.application_manager = ApplicationManager()
self.sensor_manager = SensorManager()
self.sensor_manager = SensorManager(use_msr_safe=self.config.msr_safe)
pa = PowerActuator(self.sensor_manager)
self.controller = Controller([pa])
......
......@@ -28,12 +28,14 @@ import coolr.clr_misc
class SensorManager:
"""Performs sensor reading and basic data aggregation."""
def __init__(self):
def __init__(self, use_msr_safe):
self.use_msr_safe = use_msr_safe
self.nodeconfig = coolr.clr_nodeinfo.nodeconfig()
self.nodename = self.nodeconfig.nodename
self.cputopology = coolr.clr_nodeinfo.cputopology()
self.coretemp = coolr.clr_hwmon.coretemp_reader()
self.rapl = coolr.clr_rapl.rapl_reader()
self.msr = coolr.msr.Msr()
def start(self):
self.rapl.start_energy_counter()
......@@ -53,8 +55,12 @@ class SensorManager:
# only return enabled domains
return {k: pl[k] for k in pl if pl[k]['enabled']}
def set_powerlimit(self, domain, value):
self.rapl.set_powerlimit(value, domain)
# id is either a domain or a cpuid
def set_powerlimit(self, id, value):
if self.use_msr_safe:
self.msr.set_powerlimit(id, value)
else:
self.rapl.set_powerlimit(value, id)
def calc_difference(self, start, end):
diff = dict()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment