- Fix compilation
git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@712 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
parent
5ab575dffd
commit
b7d61d5c56
|
@ -21,10 +21,7 @@
|
||||||
#include "concrete_environment.hh"
|
#include "concrete_environment.hh"
|
||||||
#include "concrete_history.hh"
|
#include "concrete_history.hh"
|
||||||
#include "policy.hh"
|
#include "policy.hh"
|
||||||
#include "schedulable.hh"
|
|
||||||
#include "scheduler.hh"
|
#include "scheduler.hh"
|
||||||
#include "policy_manager.hh"
|
|
||||||
#include "policies_gatekeeper.hh"
|
|
||||||
#include "user_interrupt_exception.hh"
|
#include "user_interrupt_exception.hh"
|
||||||
|
|
||||||
// Do not include full template definition in the header file
|
// Do not include full template definition in the header file
|
||||||
|
@ -59,21 +56,6 @@ collect_threads(const std::vector<Process*>& procs,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
free_all_resources_of(DynamicThread& ended_thread)
|
|
||||||
{
|
|
||||||
typedef std::vector<DynamicRequest*> Requests;
|
|
||||||
typedef std::vector<DynamicSubRequest*> SubRequests;
|
|
||||||
Requests& reqs = ended_thread.get_dynamic_requests();
|
|
||||||
|
|
||||||
for(Requests::iterator it = reqs.begin(); it != reqs.end(); it++)
|
|
||||||
{
|
|
||||||
// FIXME : write me
|
|
||||||
// Where is "state_fulfilled" or similar in Request::state?
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---------------------------------------------------------
|
// ---------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
@ -81,16 +63,15 @@ free_all_resources_of(DynamicThread& ended_thread)
|
||||||
|
|
||||||
//private constructor. The parameter is discarded
|
//private constructor. The parameter is discarded
|
||||||
Scheduler::Scheduler()
|
Scheduler::Scheduler()
|
||||||
: _policy_manager(PolicyManager::get_registered_manager())
|
: _ready_queue(NULL), _policy(NULL)
|
||||||
{
|
{}
|
||||||
_policy_manager.init();
|
|
||||||
}
|
|
||||||
|
|
||||||
ReadyQueue*
|
ReadyQueue*
|
||||||
Scheduler::get_ready_queue()
|
Scheduler::get_ready_queue()
|
||||||
{
|
{
|
||||||
// FIXME return the correct queue accordingly to the value returned by Policy::wants()
|
// FIXME return the correct queue accordingly to the value returned by Policy::wants()
|
||||||
return &_ready_queue;
|
return _ready_queue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -116,133 +97,149 @@ Scheduler::get_policy()
|
||||||
void
|
void
|
||||||
Scheduler::step_forward(History& history, Policy& cpu_policy) throw(UserInterruptException)
|
Scheduler::step_forward(History& history, Policy& cpu_policy) throw(UserInterruptException)
|
||||||
{
|
{
|
||||||
// This very method should be exclusive: no concurrent behaviour, from when we
|
// This very method should be exclusive: no concurrent behaviour, from when we
|
||||||
// store a readyqueue and policy pointer for the user-policy to retrieve, to when
|
// store a readyqueue and policy pointer for the user-policy to retrieve, to when
|
||||||
// the policy returns
|
// the policy returns
|
||||||
// TODO: restrict this area to maximise parallelism
|
// TODO: restrict this area to maximise parallelism
|
||||||
Glib::Mutex::Lock lock(_mutex);
|
Glib::Mutex::Lock lock(_mutex);
|
||||||
|
|
||||||
// NOTE: Be sure to read the *ORIGINAL* documentation in the design document for this method!
|
// NOTE: Be sure to read the *ORIGINAL* documentation in the design document for this method!
|
||||||
|
|
||||||
// FIXME: handle me! I'm not just a pretty boolean, I want to be *USED*! *EXPLOITED*!
|
// FIXME: handle me! I'm not just a pretty boolean, I want to be *USED*! *EXPLOITED*!
|
||||||
// *RAPED*! *MAKE ME BLEED*!
|
// *RAPED*! *MAKE ME BLEED*!
|
||||||
bool simulation_ended = true; // Assume we've finished. Then prove me wrong.
|
bool simulation_ended = true; // Assume we've finished. Then prove me wrong.
|
||||||
|
|
||||||
ConcreteHistory& concrete_history = (ConcreteHistory&) history;
|
ConcreteHistory& concrete_history = (ConcreteHistory&) history;
|
||||||
|
|
||||||
// Use an auto_ptr since we've some exceptions in the coming...
|
// Use an auto_ptr since we've some exceptions in the coming...
|
||||||
auto_ptr<ConcreteEnvironment> new_snapshot(new ConcreteEnvironment(concrete_history.get_last_environment()));
|
auto_ptr<ConcreteEnvironment> new_snapshot(new ConcreteEnvironment(concrete_history.get_last_environment()));
|
||||||
|
|
||||||
typedef std::vector<DynamicProcess*> Processes;
|
typedef std::vector<DynamicProcess*> Processes;
|
||||||
typedef std::vector<DynamicRequest*> Requests;
|
typedef std::vector<DynamicRequest*> Requests;
|
||||||
typedef std::vector<DynamicSubRequest*> SubRequests;
|
typedef std::vector<DynamicSubRequest*> SubRequests;
|
||||||
typedef std::vector<DynamicThread*> Threads;
|
typedef std::vector<DynamicThread*> Threads;
|
||||||
|
|
||||||
Threads all_threads;
|
Threads all_threads;
|
||||||
DynamicThread* running_thread = NULL;
|
DynamicThread* running_thread = NULL;
|
||||||
|
|
||||||
collect_threads(new_snapshot->get_processes(), all_threads);
|
collect_threads(new_snapshot->get_processes(), all_threads);
|
||||||
|
|
||||||
// designer + implementer (Matteo) comment follows:
|
// designer + implementer (Matteo) comment follows:
|
||||||
|
|
||||||
for(Threads::iterator it = all_threads.begin(); it != all_threads.end(); it++)
|
for(Threads::iterator it = all_threads.begin(); it != all_threads.end(); it++)
|
||||||
{
|
{
|
||||||
DynamicThread& current = **it;
|
DynamicThread& current = **it;
|
||||||
|
|
||||||
// 1. mark future threads as ready, if appropriate
|
// 1. mark future threads as ready, if appropriate
|
||||||
if(current.get_state() == Schedulable::state_future)
|
if(current.get_state() == Schedulable::state_future)
|
||||||
{
|
{
|
||||||
Process& parent = current.get_process();
|
Process& parent = current.get_process();
|
||||||
if(parent.get_elapsed_time() == current.get_arrival_time())
|
if(parent.get_elapsed_time() == current.get_arrival_time())
|
||||||
current.set_state(Schedulable::state_ready);
|
current.set_state(Schedulable::state_ready);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save the current running thread for future usage, if it hasn't ended
|
// Save the current running thread for future usage, if it hasn't ended
|
||||||
// its allotted time
|
// its allotted time
|
||||||
if(current.get_state() == Schedulable::state_running)
|
if(current.get_state() == Schedulable::state_running)
|
||||||
{
|
{
|
||||||
// increasing the time elapsed of the running thread + process
|
// increasing the time elapsed of the running thread + process
|
||||||
// should be done here as the first thing, instead than
|
// should be done here as the first thing, instead than
|
||||||
// directly after selecting them
|
// directly after selecting them
|
||||||
running_thread->decrease_remaining_time();
|
running_thread->decrease_remaining_time();
|
||||||
|
|
||||||
running_thread = ¤t; // Even if we change its state to terminated
|
running_thread = ¤t; // Even if we change its state to terminated
|
||||||
// 2. mark threads that used all their allotted time as terminated
|
// 2. mark threads that used all their allotted time as terminated
|
||||||
if(current.get_total_cpu_time() - current.get_elapsed_time() == 0)
|
if(current.get_total_cpu_time() - current.get_elapsed_time() == 0)
|
||||||
current.set_state(Schedulable::state_terminated);
|
current.set_state(Schedulable::state_terminated);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. check for simulation termination (we can directly use threads
|
// 3. check for simulation termination (we can directly use threads
|
||||||
// for this check, since processes' state is based upon threads' one)
|
// for this check, since processes' state is based upon threads' one)
|
||||||
if( /* we still think that */ simulation_ended &&
|
if( /* we still think that */ simulation_ended &&
|
||||||
(current.get_state() & (Schedulable::state_blocked |
|
(current.get_state() & (Schedulable::state_blocked |
|
||||||
Schedulable::state_terminated)) == 0)
|
Schedulable::state_terminated)) == 0)
|
||||||
simulation_ended = false;
|
simulation_ended = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ---------- FIXME ----------------
|
// ---------- FIXME ----------------
|
||||||
// What to do now if the simulation ended?
|
// What to do now if the simulation ended?
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 4a. Requests for the running thread exhausted
|
// 4a. Requests for the running thread exhausted
|
||||||
if(running_thread != NULL) {
|
if(running_thread != NULL) {
|
||||||
Requests& reqs = running_thread->get_dynamic_requests();
|
Requests& reqs = running_thread->get_dynamic_requests();
|
||||||
if(running_thread->get_state() == Schedulable::state_terminated)
|
if(running_thread->get_state() == Schedulable::state_terminated)
|
||||||
{
|
{
|
||||||
// for(Requests::iterator it = reqs.begin();
|
// for(Requests::iterator it = reqs.begin();
|
||||||
|
}
|
||||||
|
|
||||||
// FIXME we lack a way to tell and/or remember for how
|
// FIXME we lack a way to tell and/or remember for how
|
||||||
// much a subrequest has been being fulfilled
|
// much a subrequest has been being fulfilled
|
||||||
// THIS MEANS this part is NOT complete
|
// THIS MEANS this part is NOT complete
|
||||||
// We should check if a request has been fulfilled
|
// We should check if a request has been fulfilled
|
||||||
|
|
||||||
// FIXME If a request was being fulfilled to the running thread,
|
// FIXME If a request was being fulfilled to the running thread,
|
||||||
// we should decrease the request remaining time here.
|
// we should decrease the request remaining time here.
|
||||||
|
|
||||||
// This is why we kept a ref to the old running thread,
|
// This is why we kept a ref to the old running thread,
|
||||||
// even if it was terminated
|
// even if it was terminated
|
||||||
|
|
||||||
free_all_resources_of(*running_thread); // this function isn't complete
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// /
|
// /
|
||||||
// /
|
// /
|
||||||
// /
|
// /
|
||||||
// (I'M HERE) < * * * * * * * * * * *
|
// (I'M HERE) < * * * * * * * * * * *
|
||||||
// \
|
// \
|
||||||
// \
|
// \
|
||||||
// \
|
// \
|
||||||
//
|
//
|
||||||
// (is it visible enough for you?)
|
// (is it visible enough for you?)
|
||||||
|
|
||||||
|
|
||||||
ReadyQueue& ready_queue = new_snapshot->get_sorted_queue();
|
ReadyQueue& ready_queue = new_snapshot->get_sorted_queue();
|
||||||
prepare_ready_queue(ready_queue);
|
prepare_ready_queue(ready_queue);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// ?. Use the policy to sort the queue
|
// Temporarily set the _ready_queue param and the _policy one for
|
||||||
|
// use from external plugins
|
||||||
|
_policy = &cpu_policy;
|
||||||
|
_ready_queue = &new_snapshot->get_sorted_queue();
|
||||||
|
|
||||||
|
|
||||||
// FIXME: how does it get the queue?
|
// ?. Use the policy to sort the queue
|
||||||
cpu_policy.sort_queue();
|
|
||||||
}
|
|
||||||
catch(UserInterruptException& e)
|
|
||||||
{
|
|
||||||
_policy_manager.init();
|
|
||||||
// ^^^^^
|
|
||||||
// Do we need to update something else?
|
|
||||||
|
|
||||||
// Going up unwinding the stack, tell:
|
// FIXME: how does it get the queue?
|
||||||
// - the user that the policy sucks
|
cpu_policy.sort_queue();
|
||||||
// - SimulationController that everything stopped
|
}
|
||||||
throw;
|
catch(UserInterruptException& e)
|
||||||
}
|
{
|
||||||
|
_policy = NULL;
|
||||||
|
_ready_queue = NULL;
|
||||||
|
// ^^^^^
|
||||||
|
// Do we need to update something else?
|
||||||
|
|
||||||
|
// Going up unwinding the stack, tell:
|
||||||
|
// - the user that the policy sucks
|
||||||
|
// - SimulationController that everything stopped
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
// append the new snapshot...
|
// append the new snapshot...
|
||||||
// ...and remember to release the auto_ptr!
|
// ...and remember to release the auto_ptr!
|
||||||
concrete_history.append_new_environment(new_snapshot.release());
|
concrete_history.append_new_environment(new_snapshot.release());
|
||||||
|
_policy = NULL;
|
||||||
|
_ready_queue = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
Scheduler::prepare_ready_queue(ReadyQueue& queue)
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,8 +92,8 @@ namespace sgpem
|
||||||
|
|
||||||
Scheduler(); //private constructor.
|
Scheduler(); //private constructor.
|
||||||
|
|
||||||
ReadyQueue _ready_queue;
|
ReadyQueue* _ready_queue;
|
||||||
PolicyManager& _policy_manager;
|
Policy* _policy;
|
||||||
};
|
};
|
||||||
|
|
||||||
}//~ namespace sgpem
|
}//~ namespace sgpem
|
||||||
|
|
Loading…
Reference in New Issue