From dbfc7393ed97768c0f8ccccc1d8d27830e658f57 Mon Sep 17 00:00:00 2001 From: tchernobog Date: Wed, 6 Sep 2006 13:04:31 +0000 Subject: [PATCH] - Fix all policies to ensure that the sort *IS* stable - Erase the newly selected running thread from the ready queue as per Marco feedback (or so I believe to have understood...) git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@1024 3ecf2c5c-341e-0410-92b4-d18e462d057c --- plugins/pyloader/src/builtin-policies/fcfs.py | 2 +- plugins/pyloader/src/builtin-policies/rr.py | 2 +- plugins/pyloader/src/builtin-policies/rr_priority.py | 9 +++++---- plugins/pyloader/src/builtin-policies/sjf.py | 2 +- src/backend/scheduler.cc | 1 + 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/plugins/pyloader/src/builtin-policies/fcfs.py b/plugins/pyloader/src/builtin-policies/fcfs.py index 04ed582..7355dce 100644 --- a/plugins/pyloader/src/builtin-policies/fcfs.py +++ b/plugins/pyloader/src/builtin-policies/fcfs.py @@ -42,6 +42,6 @@ the simplest of them all.""" def sort_queue(self, queue): cmpf = lambda a, b: \ - a.get_arrival_time() < \ + a.get_arrival_time() <= \ b.get_arrival_time() self.sort(queue,cmpf) diff --git a/plugins/pyloader/src/builtin-policies/rr.py b/plugins/pyloader/src/builtin-policies/rr.py index a4523cc..4c237bb 100644 --- a/plugins/pyloader/src/builtin-policies/rr.py +++ b/plugins/pyloader/src/builtin-policies/rr.py @@ -45,6 +45,6 @@ priority in account. Use rr_priority for that.""" def sort_queue(self, queue): by_ltime = lambda a, b: \ - a.get_last_acquisition() > \ + a.get_last_acquisition() <= \ b.get_last_acquisition() self.sort(queue,by_ltime) diff --git a/plugins/pyloader/src/builtin-policies/rr_priority.py b/plugins/pyloader/src/builtin-policies/rr_priority.py index 9365fb1..dcc8073 100644 --- a/plugins/pyloader/src/builtin-policies/rr_priority.py +++ b/plugins/pyloader/src/builtin-policies/rr_priority.py @@ -49,12 +49,13 @@ the time slice will have to end before the former can run.""" return self.get_parameters().get_int("Time slice") def sort_queue(self, queue): - by_prio = lambda a, b: \ - a.get_current_priority() < \ - b.get_current_priority() by_ltime = lambda a, b: \ - a.get_last_acquisition() > \ + a.get_last_acquisition() <= \ b.get_last_acquisition() + by_prio = lambda a, b: \ + a.get_current_priority() <= \ + b.get_current_priority() + self.sort(queue,by_ltime) self.sort(queue,by_prio) diff --git a/plugins/pyloader/src/builtin-policies/sjf.py b/plugins/pyloader/src/builtin-policies/sjf.py index 45bb5f8..d954580 100644 --- a/plugins/pyloader/src/builtin-policies/sjf.py +++ b/plugins/pyloader/src/builtin-policies/sjf.py @@ -50,7 +50,7 @@ Time Next in this case.""" def sort_queue(self, queue): cmpf = lambda a, b: \ - a.get_total_cpu_time() - a.get_elapsed_time() < \ + a.get_total_cpu_time() - a.get_elapsed_time() <= \ b.get_total_cpu_time() - b.get_elapsed_time() self.sort(queue,cmpf) diff --git a/src/backend/scheduler.cc b/src/backend/scheduler.cc index b56bb48..221b15b 100644 --- a/src/backend/scheduler.cc +++ b/src/backend/scheduler.cc @@ -634,6 +634,7 @@ Scheduler::step_forward(History& history, CPUPolicy& cpu_policy, ResourcePolicy& { // Fix fields of running thread DynamicThread& new_running = (DynamicThread&) _ready_queue->get_item_at(0); + _ready_queue->erase_first(); new_running.set_state(Schedulable::state_running); // If the new running is different from the old one,