CC_EDF.py 1.07 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
"""
Cycle-Conserving EDF. A DVFS variant of EDF (uniprocessor).
"""
from simso.core import Scheduler


class CC_EDF(Scheduler):
    def init(self):
        self.ready_list = []

        self.ui = {}
        for task in self.task_list:
            self.ui[task] = float(task.wcet) / task.period

        self.adjust_speed()

    def adjust_speed(self):
        # Compute processor speed
        utilization = min(1.0, sum(self.ui.values()))
        self.processors[0].set_speed(utilization)

    def on_activate(self, job):
        self.ui[job.task] = job.wcet / job.period
        self.ready_list.append(job)
        self.adjust_speed()
        job.cpu.resched()

    def on_terminated(self, job):
        self.ui[job.task] = job.actual_computation_time / job.period
        self.ready_list.remove(job)
        self.adjust_speed()
        job.cpu.resched()

    def schedule(self, cpu):
        if self.ready_list:
            # job with the highest priority
            job = min(self.ready_list, key=lambda x: x.absolute_deadline)
        else:
            job = None

        return (job, cpu)