Commit a3bb63ca authored by Valentin Reis's avatar Valentin Reis

Control loop logic change.

parent b624b847
......@@ -139,6 +139,7 @@ class BanditController(object):
self.loss = BasicPowerLoss(0.5)
self.exploration=exploration
self.bandit = EpsGreedyBandit(exploration,len(self.actions))
self.last_e=0
self.n=0
if enforce is not None:
assert(enforce>=0)
......@@ -151,6 +152,14 @@ class BanditController(object):
def planify(self, target, machineinfo, applications):
"""Plan the next action for the control loop."""
current_e = float(machineinfo['energy']['total']['p0'])/(1000*1000) # in joules
if self.last_e==0:
self.last_e=current_e
return([],[])
else:
total_power = current_e - self.last_e
self.last_e = current_e
logger.info("Controller: Reading machineinfo %s." %(str(machineinfo)))
if len(applications)==0:
self.bandit = EpsGreedyBandit(self.exploration,len(self.actions))
self.n=0
......@@ -163,8 +172,6 @@ class BanditController(object):
for a in applications.values():
a.reset_progress()
logger.info("Controller: applications %r" %applications.values())
total_power = float(machineinfo['energy']['energy']['p0'])/(1000*1000) #in joules
logger.info("Controller: Reading machineinfo %s." %(str(machineinfo)))
logger.info("Controller: Reading progress %s and power %s."
%(total_progress,total_power))
loss = self.loss.loss(progress=total_progress,power=total_power)
......
......@@ -231,6 +231,7 @@ class rapl_reader:
ret = dict()
ret['energy'] = dict()
ret['energy']['total'] = self.totalenergy
for k in sorted(e.keys()):
if k != 'time':
ret['energy'][self.shortenkey(k)] = de[k]
......
......@@ -138,6 +138,7 @@ class Daemon(object):
logger.info("sending sensor message: %r", msg)
def do_control(self):
self.do_sensor()
actions, actuators = self.controller.planify(self.target, self.machine_info, self.application_manager.applications)
self.controller.execute(actions, actuators)
self.controller.update(actions, actuators)
......@@ -239,8 +240,8 @@ class Daemon(object):
self.machine_info = self.sensor_manager.do_update()
# setup periodic sensor updates
self.sensor_cb = ioloop.PeriodicCallback(self.do_sensor, self.period / 5)
self.sensor_cb.start()
# self.sensor_cb = ioloop.PeriodicCallback(self.do_sensor, self.period / 5)
# self.sensor_cb.start()
self.control = ioloop.PeriodicCallback(self.do_control, self.period)
self.control.start()
......
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