From 34b6f85279812e450635511e31e9b943684afabd Mon Sep 17 00:00:00 2001 From: Maxime Chéramy Date: Wed, 27 May 2015 18:44:27 +0200 Subject: [PATCH] update G-EDF implementation. --- simso/schedulers/EDF.py | 24 ++++++++---------------- simso/schedulers/EDF2.py | 2 +- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/simso/schedulers/EDF.py b/simso/schedulers/EDF.py index 5c7caf5..e5a7b27 100644 --- a/simso/schedulers/EDF.py +++ b/simso/schedulers/EDF.py @@ -7,27 +7,20 @@ from simso.core import Scheduler class EDF(Scheduler): """Earliest Deadline First""" - def init(self): - self.ready_list = [] - def on_activate(self, job): - self.ready_list.append(job) job.cpu.resched() def on_terminated(self, job): - if job in self.ready_list: - self.ready_list.remove(job) - else: - job.cpu.resched() + job.cpu.resched() def schedule(self, cpu): - ready_jobs = [j for j in self.ready_list if j.is_active()] + # List of ready jobs not currently running: + ready_jobs = [t.job for t in self.task_list + if t.is_active() and not t.job.is_running()] if ready_jobs: - # Key explanations: - # First the free processors - # Among the others, get the one with the greatest deadline - # If equal, take the one used to schedule + # Select a free processor or, if none, + # the one with the greatest deadline (self in case of equality): key = lambda x: ( 1 if not x.running else 0, x.running.absolute_deadline if x.running else 0, @@ -35,11 +28,10 @@ class EDF(Scheduler): ) cpu_min = max(self.processors, key=key) + # Select the job with the least priority: job = min(ready_jobs, key=lambda x: x.absolute_deadline) if (cpu_min.running is None or cpu_min.running.absolute_deadline > job.absolute_deadline): - self.ready_list.remove(job) - if cpu_min.running: - self.ready_list.append(cpu_min.running) + print(self.sim.now(), job.name, cpu_min.name) return (job, cpu_min) diff --git a/simso/schedulers/EDF2.py b/simso/schedulers/EDF2.py index 6c0e267..8115c13 100644 --- a/simso/schedulers/EDF2.py +++ b/simso/schedulers/EDF2.py @@ -1,6 +1,6 @@ """ Implementation of the Global-EDF (Earliest Deadline First) for multiprocessor -architectures. +architectures (alternative implementation as the one provided by EDF.py). """ from simso.core import Scheduler -- libgit2 0.26.0