P_EDF2.py 1.99 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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
"""
Partitionned EDF without the helping class.

Use EDF_mono.
"""
from simso.core import Scheduler
from simso.core.Scheduler import SchedulerInfo
from EDF_mono import EDF_mono


class P_EDF2(Scheduler):
    def init(self):
        # Mapping processor to scheduler.
        self.map_cpu_sched = {}
        # Mapping task to scheduler.
        self.map_task_sched = {}

        cpus = []
        for cpu in self.processors:
            # Append the processor to a list with an initial utilization of 0.
            cpus.append([cpu, 0])

            # Instantiate a scheduler.
            sched = EDF_mono(self.sim, SchedulerInfo("EDF_mono", EDF_mono))
            sched.add_processor(cpu)
            sched.init()

            # Affect the scheduler to the processor.
            self.map_cpu_sched[cpu.identifier] = sched

        # First Fit
        for task in self.task_list:
            j = 0
            # Find a processor with free space.
            while cpus[j][1] + float(task.wcet) / task.period > 1.0:
                j += 1
                if j >= len(self.processors):
                    print("oops bin packing failed.")
                    return

            # Get the scheduler for this processor.
            sched = self.map_cpu_sched[cpus[j][0].identifier]

            # Affect it to the task.
            self.map_task_sched[task.identifier] = sched
            sched.add_task(task)

            # Put the task on that processor.
            task.cpu = cpus[j][0]
            self.sim.logger.log("task " + task.name + " on " + task.cpu.name)

            # Update utilization.
            cpus[j][1] += float(task.wcet) / task.period

    def get_lock(self):
        # No lock mechanism is needed.
        return True

    def schedule(self, cpu):
        return self.map_cpu_sched[cpu.identifier].schedule(cpu)

    def on_activate(self, job):
        self.map_task_sched[job.task.identifier].on_activate(job)

    def on_terminated(self, job):
        self.map_task_sched[job.task.identifier].on_terminated(job)