- 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:
parent
94f7c1d127
commit
9856a86c87
|
@ -53,7 +53,7 @@ namespace sgpem
|
||||||
|
|
||||||
/// \brief Copy constructor.
|
/// \brief Copy constructor.
|
||||||
/// Performs a deep copy of all structures.
|
/// Performs a deep copy of all structures.
|
||||||
ConcreteEnvironment(const ConcreteEnvironment & c);
|
ConcreteEnvironment(const ConcreteEnvironment& c);
|
||||||
|
|
||||||
|
|
||||||
/// \brief Returns an indexed set of snapshots of the processes
|
/// \brief Returns an indexed set of snapshots of the processes
|
||||||
|
|
|
@ -95,6 +95,7 @@ void
|
||||||
ConcreteHistory::append_new_environment(ConcreteEnvironment* environment)
|
ConcreteHistory::append_new_environment(ConcreteEnvironment* environment)
|
||||||
{
|
{
|
||||||
_snapshots.push_back(environment);
|
_snapshots.push_back(environment);
|
||||||
|
notify_change();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -122,7 +122,7 @@ DynamicProcess::get_state() const
|
||||||
// pass from state_future to state_terminated:
|
// pass from state_future to state_terminated:
|
||||||
|
|
||||||
// (d2)
|
// (d2)
|
||||||
int elapsed_time = get_total_cpu_time() - get_remaining_time();
|
int elapsed_time = get_elapsed_time();
|
||||||
if(result == state_future && next_thread_starts_at > elapsed_time )
|
if(result == state_future && next_thread_starts_at > elapsed_time )
|
||||||
result = state_terminated;
|
result = state_terminated;
|
||||||
|
|
||||||
|
|
|
@ -84,9 +84,9 @@ DynamicSchedulable::get_current_priority() const
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int
|
unsigned int
|
||||||
DynamicSchedulable::get_remaining_time() const
|
DynamicSchedulable::get_elapsed_time() const
|
||||||
{
|
{
|
||||||
return get_total_cpu_time() - _ran_for;
|
return _ran_for;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -68,7 +68,7 @@ namespace sgpem
|
||||||
|
|
||||||
virtual int get_current_priority() const;
|
virtual int get_current_priority() const;
|
||||||
|
|
||||||
virtual unsigned int get_remaining_time() const;
|
virtual unsigned int get_elapsed_time() const;
|
||||||
|
|
||||||
virtual void decrease_remaining_time();
|
virtual void decrease_remaining_time();
|
||||||
|
|
||||||
|
@ -85,8 +85,8 @@ namespace sgpem
|
||||||
* This function returns a reference to the actual schedable object
|
* This function returns a reference to the actual schedable object
|
||||||
* represented, along with its status, by this instance.
|
* represented, along with its status, by this instance.
|
||||||
*/
|
*/
|
||||||
virtual StaticSchedulable& get_core() = 0;
|
virtual StaticSchedulable& get_core() = 0;
|
||||||
virtual const StaticSchedulable& get_core() const = 0;
|
virtual const StaticSchedulable& get_core() const = 0;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int _ran_for;
|
int _ran_for;
|
||||||
|
|
|
@ -67,8 +67,8 @@ namespace sgpem
|
||||||
virtual ~History() = 0;
|
virtual ~History() = 0;
|
||||||
|
|
||||||
virtual size_t get_size() = 0;
|
virtual size_t get_size() = 0;
|
||||||
virtual const Environment& get_last_environment(position index) const = 0;
|
virtual const Environment& get_last_environment() const = 0;
|
||||||
virtual const Environment& get_environment_at() const throw(std::out_of_range) = 0;
|
virtual const Environment& get_environment_at(position index) const throw(std::out_of_range) = 0;
|
||||||
|
|
||||||
virtual void remove(resource_key_t resource_key) = 0;
|
virtual void remove(resource_key_t resource_key) = 0;
|
||||||
virtual void remove(Process& process) = 0;
|
virtual void remove(Process& process) = 0;
|
||||||
|
|
|
@ -57,7 +57,7 @@ namespace sgpem
|
||||||
|
|
||||||
virtual unsigned int get_arrival_time() const = 0;
|
virtual unsigned int get_arrival_time() const = 0;
|
||||||
|
|
||||||
virtual unsigned int get_remaining_time() const = 0;
|
virtual unsigned int get_elapsed_time() const = 0;
|
||||||
|
|
||||||
virtual int get_base_priority() const = 0;
|
virtual int get_base_priority() const = 0;
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,10 @@
|
||||||
// along with SGPEMv2; if not, write to the Free Software
|
// along with SGPEMv2; if not, write to the Free Software
|
||||||
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
|
#include "concrete_environment.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 "policy_manager.hh"
|
||||||
#include "policies_gatekeeper.hh"
|
#include "policies_gatekeeper.hh"
|
||||||
|
@ -34,6 +37,33 @@ using namespace sgpem;
|
||||||
// Explicit template instantiation to allow to export symbols from the DSO.
|
// Explicit template instantiation to allow to export symbols from the DSO.
|
||||||
template class SG_DLLEXPORT Singleton<Scheduler>;
|
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
|
//private constructor. The parameter is discarded
|
||||||
Scheduler::Scheduler()
|
Scheduler::Scheduler()
|
||||||
: _policy_manager(PolicyManager::get_registered_manager())
|
: _policy_manager(PolicyManager::get_registered_manager())
|
||||||
|
@ -71,16 +101,72 @@ 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)
|
||||||
{
|
{
|
||||||
|
// 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
|
try
|
||||||
{
|
{
|
||||||
|
// call the policy to sort the queue
|
||||||
|
// ...
|
||||||
}
|
}
|
||||||
catch( UserInterruptException e )
|
catch( UserInterruptException e )
|
||||||
{
|
{
|
||||||
_policy_manager.init();
|
_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?
|
// Do we need to update something?
|
||||||
|
|
||||||
// Going up unwinding the stack, tell:
|
// Going up unwinding the stack, tell:
|
||||||
|
@ -88,5 +174,6 @@ Scheduler::step_forward(History& history, Policy& cpu_policy) throw(UserInterrup
|
||||||
// - SimulationController that everything stopped
|
// - SimulationController that everything stopped
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
concrete_history.append_new_environment(new_snapshot);
|
||||||
|
}
|
||||||
|
|
|
@ -92,6 +92,7 @@ namespace sgpem
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Scheduler(); //private constructor.
|
Scheduler(); //private constructor.
|
||||||
|
|
||||||
ReadyQueue _ready_queue;
|
ReadyQueue _ready_queue;
|
||||||
PolicyManager& _policy_manager;
|
PolicyManager& _policy_manager;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue