From 22af0b9cddbc7fe37f5c326afaf758d52a07dac0 Mon Sep 17 00:00:00 2001 From: tchernobog Date: Tue, 4 Jul 2006 23:09:10 +0000 Subject: [PATCH] - Add method to set a request state - Work on step_forward() a little more - Add extra check inside dynamic_thread()::decrease_remaining_time() git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@717 3ecf2c5c-341e-0410-92b4-d18e462d057c --- src/backend/dynamic_request.cc | 9 ++++++ src/backend/dynamic_request.hh | 1 + src/backend/dynamic_thread.cc | 5 ++- src/backend/dynamic_thread.hh | 2 +- src/backend/scheduler.cc | 56 +++++++++++++++++++++------------- 5 files changed, 49 insertions(+), 24 deletions(-) diff --git a/src/backend/dynamic_request.cc b/src/backend/dynamic_request.cc index ae926d6..4a7bd30 100644 --- a/src/backend/dynamic_request.cc +++ b/src/backend/dynamic_request.cc @@ -90,6 +90,15 @@ DynamicRequest::get_state() const } +Request::state +DynamicRequest::set_state(state new_state) +{ + state temp = _state; + _state = new_state; + return temp; +} + + void DynamicRequest::serialize(SerializeVisitor& translator) const { diff --git a/src/backend/dynamic_request.hh b/src/backend/dynamic_request.hh index 48fe48a..ac6381f 100644 --- a/src/backend/dynamic_request.hh +++ b/src/backend/dynamic_request.hh @@ -53,6 +53,7 @@ namespace sgpem unsigned int get_instant() const; state get_state() const; + state set_state(state new_state); void serialize(SerializeVisitor& translator) const; diff --git a/src/backend/dynamic_thread.cc b/src/backend/dynamic_thread.cc index ed57beb..63032bb 100644 --- a/src/backend/dynamic_thread.cc +++ b/src/backend/dynamic_thread.cc @@ -122,7 +122,10 @@ DynamicThread::get_elapsed_time() const void DynamicThread::decrease_remaining_time() { - _ran_for++; + // strict check for us to better debug scheduler + assert(_ran_for < get_total_cpu_time()); + if(_ran_for < get_total_cpu_time()) + _ran_for++; } int diff --git a/src/backend/dynamic_thread.hh b/src/backend/dynamic_thread.hh index 5aef98c..a9de32d 100644 --- a/src/backend/dynamic_thread.hh +++ b/src/backend/dynamic_thread.hh @@ -77,7 +77,7 @@ namespace sgpem std::vector _dynamic_requests; DynamicProcess* _parent; - int _ran_for; + unsigned int _ran_for; int _last_acquisition; int _last_release; }; diff --git a/src/backend/scheduler.cc b/src/backend/scheduler.cc index 65c6523..793e801 100644 --- a/src/backend/scheduler.cc +++ b/src/backend/scheduler.cc @@ -68,7 +68,7 @@ static void prepare_ready_queue(ConcreteEnvironment& snapshot, it != all_threads.end(); it++) { if((*it)->get_state() == Schedulable::state_ready) - all_threads.push_back(*it); + queue.append(**it); } } @@ -178,21 +178,28 @@ Scheduler::step_forward(History& history, Policy& cpu_policy) throw(UserInterrup Schedulable::state_terminated)) == 0) simulation_ended = false; } - - - // ---------- FIXME ---------------- - // What to do now if the simulation ended? - - - // 4a. Requests for the running thread exhausted + // 4a. Look for exhausted requests for the running thread if(running_thread != NULL) { Requests& reqs = running_thread->get_dynamic_requests(); - if(running_thread->get_state() == Schedulable::state_terminated) + bool running_terminated = running_thread->get_state() == Schedulable::state_terminated; + + for(Requests::iterator it = reqs.begin(); it != reqs.end(); it++) { - // for(Requests::iterator it = reqs.begin(); - } - + DynamicRequest& rq = **it; + if(rq.get_state() == Request::state_allocated) + /* decrease remaining time for request */; + + // ASK MARCO : can we implement request::decrease_remaining_time() as + // a function that calls decrease_remaining_time() on all its subrequests, + // that in turn never go with a remaining time < 0? + + // If the running thread terminated uncoditionally put them in exhausted state + if(running_terminated /* || rq.get_remaining_time() == 0 */ ) + rq.set_state(Request::state_exhausted); + } + + // FIXME we lack a way to tell and/or remember for how // much a subrequest has been being fulfilled // THIS MEANS this part is NOT complete @@ -205,18 +212,23 @@ Scheduler::step_forward(History& history, Policy& cpu_policy) throw(UserInterrup // even if it was terminated - } + } //~ if running_thread != NULL + + + // ---------- FIXME ---------------- + // What to do now if the simulation ended? - // / - // / - // / - // (I'M HERE) < * * * * * * * * * * * - // \ - // \ - // \ - // - // (is it visible enough for you?) + /* / + * / + * / + * (I'M HERE) < * * * * * * * * * * * + * \ + * \ + * \ + * + * (is it visible enough for you?) + */ prepare_ready_queue(*new_snapshot, all_threads);