- Start implementing Scheduler::step_forward(). Whoohooo!

- Changed Schedulable::get_remaining_time() in get_elapsed_time()


git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@702 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
tchernobog 2006-07-03 21:55:09 +00:00
parent 94f7c1d127
commit 9856a86c87
9 changed files with 102 additions and 13 deletions

View file

@ -18,7 +18,10 @@
// along with SGPEMv2; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "concrete_environment.hh"
#include "concrete_history.hh"
#include "policy.hh"
#include "schedulable.hh"
#include "scheduler.hh"
#include "policy_manager.hh"
#include "policies_gatekeeper.hh"
@ -34,6 +37,33 @@ using namespace sgpem;
// Explicit template instantiation to allow to export symbols from the DSO.
template class SG_DLLEXPORT Singleton<Scheduler>;
// ------------------ Static helper functions --------------
// Collects all threads of an environment into a single vector
static void
collect_threads(const std::vector<Process*>& procs,
std::vector<DynamicThread*>& collected_threads)
{
typedef std::vector<Process*> Processes;
typedef std::vector<Thread*> Threads;
collected_threads.clear();
for(Processes::const_iterator it1 = procs.begin(); it1 != procs.end(); it1++)
{
const Threads& ts = (*it1)->get_threads();
for(Threads::const_iterator it2 = ts.begin(); it2 != ts.end(); it2++)
collected_threads.push_back((DynamicThread*) *it2);
}
}
// ---------------------------------------------------------
//private constructor. The parameter is discarded
Scheduler::Scheduler()
: _policy_manager(PolicyManager::get_registered_manager())
@ -71,16 +101,72 @@ Scheduler::get_policy()
void
Scheduler::step_forward(History& history, Policy& cpu_policy) throw(UserInterruptException)
{
// 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*!
// *RAPED*! *MAKE ME BLEED*!
bool simulation_ended = true; // Assume we've finished. Then prove me wrong.
ConcreteHistory& concrete_history = (ConcreteHistory&) history;
ConcreteEnvironment* new_snapshot = new ConcreteEnvironment(concrete_history.get_last_environment());
typedef std::vector<DynamicProcess*> Processes;
typedef std::vector<DynamicThread*> Threads;
Threads all_threads;
collect_threads(new_snapshot->get_processes(), all_threads);
// designer + implementer (Matteo) comment follows:
// FIXME: decreasing the time elapsed of the running thread + process
// should maybe be done here as the first thing, instead than
// directly when selecting them
// 1. mark future threads as ready, if appropriate
// 2. mark ended threads as terminated
for(Threads::iterator it = all_threads.begin(); it != all_threads.end(); it++)
{
if((*it)->get_state() == Schedulable::state_future)
{
Process& parent = (*it)->get_process();
if(parent.get_elapsed_time() == (*it)->get_arrival_time())
(*it)->set_state(Schedulable::state_ready);
}
if((*it)->get_total_cpu_time() - (*it)->get_elapsed_time() == 0)
(*it)->set_state(Schedulable::state_terminated);
// 3. check for simulation termination (we can directly use threads)
// for this check, since processes' state is based upon theirs)
if(simulation_ended &&
((*it)->get_state() & (Schedulable::state_blocked |
Schedulable::state_terminated)) == 0)
simulation_ended = false;
}
// /
// /
// /
// (I'M HERE) < * * * * * * * * * * *
// \
// \
// \
//
// (is it visible enough for you?)
try
{
// call the policy to sort the queue
// ...
}
catch( UserInterruptException e )
{
_policy_manager.init();
//TODO Do we need to perform some cleanup operation here?
//TODO Do we need to perform some other cleanup operation here?
delete new_snapshot;
// Do we need to update something?
// Going up unwinding the stack, tell:
@ -88,5 +174,6 @@ Scheduler::step_forward(History& history, Policy& cpu_policy) throw(UserInterrup
// - SimulationController that everything stopped
throw;
}
concrete_history.append_new_environment(new_snapshot);
}