Commit 35d19623 authored by Sridutt Bhalachandra's avatar Sridutt Bhalachandra

[Feature] Added power policy initialization

Added initialization of power policy using the manifest file and fixed
appropriate TODOs in `PowerPolicyManager` (PPM) Class using container
information (except adding new power policies). Also, fixed PPM to use None
instead of NONE

See Issue #10
parent f41ef987
......@@ -65,6 +65,7 @@ class ContainerManager(object):
container_powerpolicy['policy'] = None
container_powerpolicy['damper'] = None
container_powerpolicy['slowdown'] = None
container_powerpolicy['manager'] = None
# TODO: Application library to load must be set during configuration
applicationpreloadlibrary = ''
......
......@@ -3,6 +3,7 @@ from __future__ import print_function
from applications import ApplicationManager
from containers import ContainerManager
from controller import Controller, ApplicationActuator, PowerActuator
from powerpolicy import PowerPolicyManager
from functools import partial
import json
import logging
......@@ -80,6 +81,12 @@ class Daemon(object):
logger.info("new container required: %r", msg)
container = self.container_manager.create(msg)
if container.powerpolicy['policy']:
container.powerpolicy['manager'] = PowerPolicyManager(
container.resources['cpus'],
container.powerpolicy['policy'],
container.powerpolicy['damper'],
container.powerpolicy['slowdown'])
# TODO: obviously we need to send more info than that
update = {'type': 'container',
'event': 'start',
......
......@@ -28,19 +28,21 @@
for supported power contols and related information.
"""
import ddcmpolicy
import logging
logger = logging.getLogger('nrm')
class PowerPolicyManager:
""" Used for power policy application """
def __init__(self, ncpus=0, policy='NONE', damper=0.1, slowdown=1.1):
def __init__(self, cpus=None, policy=None, damper=0.1, slowdown=1.1):
self.cpus = cpus
self.policy = policy
self.damper = damper
self.slowdown = slowdown
# TODO: Need to set this based on container configuration
self.ncpus = ncpus
# Intiliaze all power interfaces
self.ddcmpolicy = ddcmpolicy.DDCMPolicy()
......@@ -48,32 +50,35 @@ class PowerPolicyManager:
self.maxdclevel = self.ddcmpolicy.maxdclevel
# TODO: Need to set this value when DVFS policies are added
self.maxfreqlevel = -1
# TODO: Need to only allow power changes to cpus in container
self.dclevel = dict.fromkeys(range(0, self.ncpus), self.maxdclevel)
self.freqlevel = dict.fromkeys(range(0, self.ncpus), self.maxfreqlevel)
self.dclevel = dict.fromkeys(self.cpus, self.maxdclevel)
self.freqlevel = dict.fromkeys(self.cpus, self.maxfreqlevel)
# Book-keeping
self.damperexits = 0
self.slowdownexits = 0
self.prevtolalphasetime = 10000.0 # Random large value
self.prevtolalphasetime = 10000.0 # Any large value
def run_policy(self, cpu, startcompute, endcompute, startbarrier,
endbarrier):
# Select and invoke appropriate power policy
# TODO: Need to add a better policy selection logic in addition to user
# specified
ret, value = self.invoke_policy(cpu, self.policy, self.dclevel[cpu],
self.freqlevel[cpu], startcompute,
endcompute, startbarrier, endbarrier)
if self.policy == 'DDCM' and ret in ['DDCM', 'SLOWDOWN']:
self.dclevel[cpu] = value
# Run only if policy is specified
if self.policy:
if cpu not in self.cpus:
logger.info("""Attempt to change power of cpu not in container
: %r""", cpu)
return
# Select and invoke appropriate power policy
# TODO: Need to add a better policy selection logic in addition to
# user specified using manifest file
ret, value = self.invoke_policy(cpu, self.policy,
self.dclevel[cpu],
self.freqlevel[cpu], startcompute,
endcompute, startbarrier,
endbarrier)
if self.policy == 'DDCM' and ret in ['DDCM', 'SLOWDOWN']:
self.dclevel[cpu] = value
def invoke_policy(self, cpu, policy, dclevel, freqlevel, startcompute,
endcompute, startbarrier, endbarrier):
# Run with no policy
if policy == "NONE":
return 'NONE', -1
# Calculate time spent in computation, barrier in current phase along
# with total phase time
computetime = endcompute - startcompute
......
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