- Added a bit of resource policy mamagement. Still far from being usefu.
git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@958 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
parent
980d9b410a
commit
f3dc9b77df
|
@ -157,6 +157,7 @@ src_backend_libbackend_la_SOURCES = \
|
||||||
src/backend/cpu_policy.cc \
|
src/backend/cpu_policy.cc \
|
||||||
src/backend/cpu_policy_exception.cc \
|
src/backend/cpu_policy_exception.cc \
|
||||||
src/backend/cpu_policy_manager.cc \
|
src/backend/cpu_policy_manager.cc \
|
||||||
|
src/backend/default_resource_policy_manager.cc \
|
||||||
src/backend/dynamic_process.cc \
|
src/backend/dynamic_process.cc \
|
||||||
src/backend/dynamic_request.cc \
|
src/backend/dynamic_request.cc \
|
||||||
src/backend/dynamic_resource.cc \
|
src/backend/dynamic_resource.cc \
|
||||||
|
@ -181,6 +182,7 @@ src_backend_libbackend_la_SOURCES = \
|
||||||
src/backend/resource.cc \
|
src/backend/resource.cc \
|
||||||
src/backend/resource_policies_gatekeeper.cc \
|
src/backend/resource_policies_gatekeeper.cc \
|
||||||
src/backend/resource_policy.cc \
|
src/backend/resource_policy.cc \
|
||||||
|
src/backend/resource_policy_lifo.cc \
|
||||||
src/backend/resource_policy_manager.cc \
|
src/backend/resource_policy_manager.cc \
|
||||||
src/backend/schedulable.cc \
|
src/backend/schedulable.cc \
|
||||||
src/backend/scheduler.cc \
|
src/backend/scheduler.cc \
|
||||||
|
@ -209,6 +211,7 @@ pkginclude_HEADERS += \
|
||||||
src/backend/cpu_policy.hh \
|
src/backend/cpu_policy.hh \
|
||||||
src/backend/cpu_policy_exception.hh \
|
src/backend/cpu_policy_exception.hh \
|
||||||
src/backend/cpu_policy_manager.hh \
|
src/backend/cpu_policy_manager.hh \
|
||||||
|
src/backend/default_resource_policy_manager.hh \
|
||||||
src/backend/environment.hh \
|
src/backend/environment.hh \
|
||||||
src/backend/global_preferences.hh \
|
src/backend/global_preferences.hh \
|
||||||
src/backend/history.hh \
|
src/backend/history.hh \
|
||||||
|
@ -227,6 +230,7 @@ pkginclude_HEADERS += \
|
||||||
src/backend/resource.hh \
|
src/backend/resource.hh \
|
||||||
src/backend/resource_policies_gatekeeper.hh \
|
src/backend/resource_policies_gatekeeper.hh \
|
||||||
src/backend/resource_policy.hh \
|
src/backend/resource_policy.hh \
|
||||||
|
src/backend/resource_policy_lifo.hh \
|
||||||
src/backend/resource_policy_manager.hh \
|
src/backend/resource_policy_manager.hh \
|
||||||
src/backend/process.hh \
|
src/backend/process.hh \
|
||||||
src/backend/schedulable.hh \
|
src/backend/schedulable.hh \
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include "simulation_observer.hh"
|
#include "simulation_observer.hh"
|
||||||
#include "scheduler.hh"
|
#include "scheduler.hh"
|
||||||
#include "cpu_policies_gatekeeper.hh"
|
#include "cpu_policies_gatekeeper.hh"
|
||||||
|
#include "resource_policies_gatekeeper.hh"
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
|
@ -38,8 +39,9 @@ using namespace memory;
|
||||||
|
|
||||||
ConcreteSimulation::ConcreteSimulation() :
|
ConcreteSimulation::ConcreteSimulation() :
|
||||||
Simulation(), _state(state_stopped),
|
Simulation(), _state(state_stopped),
|
||||||
_mode(mode_continuous), _policy(NULL)
|
_mode(mode_continuous), _policy(NULL), _resource_policy(NULL)
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ConcreteSimulation::set_mode(const mode new_mode)
|
ConcreteSimulation::set_mode(const mode new_mode)
|
||||||
|
@ -158,7 +160,13 @@ ConcreteSimulation::step()
|
||||||
if (get_policy() == NULL)
|
if (get_policy() == NULL)
|
||||||
{
|
{
|
||||||
stop();
|
stop();
|
||||||
throw NullPolicyException("no policy selected");
|
throw NullPolicyException("no CPU policy selected");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (get_resource_policy() == NULL)
|
||||||
|
{
|
||||||
|
stop();
|
||||||
|
throw NullPolicyException("no resource policy selected");
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
|
@ -166,7 +174,7 @@ ConcreteSimulation::step()
|
||||||
//step forward
|
//step forward
|
||||||
bool yet_to_finish = true;
|
bool yet_to_finish = true;
|
||||||
if (_front == get_history().get_size() - 1)
|
if (_front == get_history().get_size() - 1)
|
||||||
yet_to_finish = Scheduler::get_instance().step_forward(_history, *get_policy());
|
yet_to_finish = Scheduler::get_instance().step_forward(_history, *get_policy(), *get_resource_policy());
|
||||||
_front++;
|
_front++;
|
||||||
return yet_to_finish;
|
return yet_to_finish;
|
||||||
}
|
}
|
||||||
|
@ -239,3 +247,18 @@ ConcreteSimulation::get_policy()
|
||||||
{
|
{
|
||||||
return _policy;
|
return _policy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ConcreteSimulation::set_resource_policy(ResourcePolicy* p)
|
||||||
|
{
|
||||||
|
ResourcePoliciesGatekeeper::get_instance().activate_policy(&_history, p);
|
||||||
|
_resource_policy = p;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ResourcePolicy*
|
||||||
|
ConcreteSimulation::get_resource_policy()
|
||||||
|
{
|
||||||
|
return _resource_policy;
|
||||||
|
}
|
||||||
|
|
|
@ -61,11 +61,14 @@ namespace sgpem
|
||||||
*/
|
*/
|
||||||
void set_policy(CPUPolicy*) throw(CPUPolicyException);
|
void set_policy(CPUPolicy*) throw(CPUPolicyException);
|
||||||
|
|
||||||
|
void set_resource_policy(ResourcePolicy*);
|
||||||
|
|
||||||
ConcreteHistory& get_history();
|
ConcreteHistory& get_history();
|
||||||
|
|
||||||
const ConcreteHistory& get_history() const;
|
const ConcreteHistory& get_history() const;
|
||||||
|
|
||||||
CPUPolicy* get_policy();
|
CPUPolicy* get_policy();
|
||||||
|
ResourcePolicy * get_resource_policy();
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -73,6 +76,7 @@ namespace sgpem
|
||||||
mode _mode;
|
mode _mode;
|
||||||
ConcreteHistory _history;
|
ConcreteHistory _history;
|
||||||
CPUPolicy* _policy;
|
CPUPolicy* _policy;
|
||||||
|
ResourcePolicy* _resource_policy;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,7 @@ static void collect_threads(const std::vector<Process*>& procs, Threads& collect
|
||||||
static void prepare_ready_queue(ConcreteEnvironment& snapshot, const Threads& all_threads);
|
static void prepare_ready_queue(ConcreteEnvironment& snapshot, const Threads& all_threads);
|
||||||
static void terminate_all_requests_of(DynamicThread& thread, ConcreteEnvironment& environment);
|
static void terminate_all_requests_of(DynamicThread& thread, ConcreteEnvironment& environment);
|
||||||
static void update_allocated_requests(DynamicThread& running_thread, ConcreteEnvironment& environment);
|
static void update_allocated_requests(DynamicThread& running_thread, ConcreteEnvironment& environment);
|
||||||
static void raise_new_requests(DynamicThread& running_thread, ConcreteEnvironment& environment);
|
static void raise_new_requests(DynamicThread& running_thread, ConcreteEnvironment& environment, ResourcePolicy& resource_policy);
|
||||||
static void look_for_mutant_request_states(ConcreteEnvironment& environment, unsigned int& alive_threads);
|
static void look_for_mutant_request_states(ConcreteEnvironment& environment, unsigned int& alive_threads);
|
||||||
static void determine_subr_allocable_status(const DynamicRequest& req, DynamicSubRequest& subr,
|
static void determine_subr_allocable_status(const DynamicRequest& req, DynamicSubRequest& subr,
|
||||||
const Resource& res, SubRequestQueue& queue);
|
const Resource& res, SubRequestQueue& queue);
|
||||||
|
@ -152,7 +152,7 @@ update_allocated_requests(DynamicThread& running_thread,
|
||||||
// Remember that a thread may run only if all of its requests are either FUTURE,
|
// Remember that a thread may run only if all of its requests are either FUTURE,
|
||||||
// ALLOCATED or EXHAUSTED.
|
// ALLOCATED or EXHAUSTED.
|
||||||
void
|
void
|
||||||
raise_new_requests(DynamicThread& running_thread, ConcreteEnvironment& environment)
|
raise_new_requests(DynamicThread& running_thread, ConcreteEnvironment& environment, ResourcePolicy& resource_policy)
|
||||||
{
|
{
|
||||||
// Go for all dynamic requests of this thread
|
// Go for all dynamic requests of this thread
|
||||||
Requests& reqs = running_thread.get_dynamic_requests();
|
Requests& reqs = running_thread.get_dynamic_requests();
|
||||||
|
@ -175,7 +175,8 @@ raise_new_requests(DynamicThread& running_thread, ConcreteEnvironment& environme
|
||||||
|
|
||||||
/// TODO: right here, right now we should call the resource policy to
|
/// TODO: right here, right now we should call the resource policy to
|
||||||
/// update the queue. Updates the state of the subrequest depending
|
/// update the queue. Updates the state of the subrequest depending
|
||||||
/// on the position in the queue, as explained before.
|
/// on the position in the queue, as explained before.
|
||||||
|
resource_policy.enforce();
|
||||||
|
|
||||||
// Get the number of places for the corresponding resource
|
// Get the number of places for the corresponding resource
|
||||||
Resource& resource = *environment.get_resources().find(rkey)->second;
|
Resource& resource = *environment.get_resources().find(rkey)->second;
|
||||||
|
@ -378,7 +379,7 @@ Scheduler::get_policy()
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
Scheduler::step_forward(History& history, CPUPolicy& cpu_policy)
|
Scheduler::step_forward(History& history, CPUPolicy& cpu_policy, ResourcePolicy& resource_policy)
|
||||||
throw(UserInterruptException, MalformedPolicyException)
|
throw(UserInterruptException, MalformedPolicyException)
|
||||||
{
|
{
|
||||||
// This very method should be exclusive: no concurrent behaviour, from when we
|
// This very method should be exclusive: no concurrent behaviour, from when we
|
||||||
|
@ -504,7 +505,7 @@ Scheduler::step_forward(History& history, CPUPolicy& cpu_policy)
|
||||||
// * else we've to select another running thread, so we continue down in the method
|
// * else we've to select another running thread, so we continue down in the method
|
||||||
if(running_thread != NULL && running_thread->get_state() == Schedulable::state_running)
|
if(running_thread != NULL && running_thread->get_state() == Schedulable::state_running)
|
||||||
{
|
{
|
||||||
raise_new_requests(*running_thread, *new_snapshot);
|
raise_new_requests(*running_thread, *new_snapshot, resource_policy);
|
||||||
if(running_thread->get_state() != Schedulable::state_blocked)
|
if(running_thread->get_state() != Schedulable::state_blocked)
|
||||||
goto final_cleanup;
|
goto final_cleanup;
|
||||||
else
|
else
|
||||||
|
@ -539,7 +540,7 @@ Scheduler::step_forward(History& history, CPUPolicy& cpu_policy)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now we check if our candidate blocks on a new request
|
// Now we check if our candidate blocks on a new request
|
||||||
raise_new_requests(candidate, *new_snapshot);
|
raise_new_requests(candidate, *new_snapshot, resource_policy);
|
||||||
if(candidate.get_state() != Schedulable::state_blocked)
|
if(candidate.get_state() != Schedulable::state_blocked)
|
||||||
// If we got here, our candidate can run
|
// If we got here, our candidate can run
|
||||||
we_ve_got_a_winner /*!hurrah!*/ = true;
|
we_ve_got_a_winner /*!hurrah!*/ = true;
|
||||||
|
|
|
@ -30,6 +30,7 @@ namespace sgpem
|
||||||
|
|
||||||
#include "history.hh"
|
#include "history.hh"
|
||||||
#include "cpu_policy.hh"
|
#include "cpu_policy.hh"
|
||||||
|
#include "resource_policy.hh"
|
||||||
#include "ready_queue.hh"
|
#include "ready_queue.hh"
|
||||||
#include "user_interrupt_exception.hh"
|
#include "user_interrupt_exception.hh"
|
||||||
#include "malformed_policy_exception.hh"
|
#include "malformed_policy_exception.hh"
|
||||||
|
@ -67,7 +68,7 @@ namespace sgpem
|
||||||
|
|
||||||
\return false If the simulation has ended, true otherwise
|
\return false If the simulation has ended, true otherwise
|
||||||
*/
|
*/
|
||||||
bool step_forward(History& history, CPUPolicy& cpu_policy) throw(UserInterruptException, MalformedPolicyException);
|
bool step_forward(History& history, CPUPolicy& cpu_policy, ResourcePolicy& resource_policy) throw(UserInterruptException, MalformedPolicyException);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Returns the policy that will be used to generate the simulation at the next instant.
|
\brief Returns the policy that will be used to generate the simulation at the next instant.
|
||||||
|
|
|
@ -25,6 +25,7 @@ namespace sgpem
|
||||||
{
|
{
|
||||||
class ConcreteSimulation;
|
class ConcreteSimulation;
|
||||||
class CPUPolicy;
|
class CPUPolicy;
|
||||||
|
class ResourcePolicy;
|
||||||
class SimulationObserver;
|
class SimulationObserver;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,15 +136,24 @@ namespace sgpem
|
||||||
virtual state get_state() const = 0;
|
virtual state get_state() const = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Setup the policy to be used by the system.
|
\brief Setup the CPU policy to be used by the system.
|
||||||
*/
|
*/
|
||||||
virtual void set_policy(CPUPolicy*) = 0;
|
virtual void set_policy(CPUPolicy*) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\return The policy currently in use.
|
\brief Setup the resource policy to be used by the system.
|
||||||
|
*/
|
||||||
|
virtual void set_resource_policy(ResourcePolicy*) = 0;
|
||||||
|
/**
|
||||||
|
\return The CPU policy currently in use.
|
||||||
*/
|
*/
|
||||||
virtual CPUPolicy* get_policy() = 0;
|
virtual CPUPolicy* get_policy() = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
\return The resource policy currently in use.
|
||||||
|
*/
|
||||||
|
virtual ResourcePolicy* get_resource_policy() = 0;
|
||||||
|
|
||||||
virtual History& get_history() = 0;
|
virtual History& get_history() = 0;
|
||||||
|
|
||||||
virtual const History& get_history() const = 0;
|
virtual const History& get_history() const = 0;
|
||||||
|
|
|
@ -29,6 +29,8 @@
|
||||||
#include "backend/serializer.hh"
|
#include "backend/serializer.hh"
|
||||||
#include "backend/process.hh"
|
#include "backend/process.hh"
|
||||||
#include "backend/resource.hh"
|
#include "backend/resource.hh"
|
||||||
|
// FIXME: remove the following and use the gatekeeper
|
||||||
|
#include "backend/resource_policy_lifo.hh"
|
||||||
#include "backend/thread.hh"
|
#include "backend/thread.hh"
|
||||||
#include "backend/request.hh"
|
#include "backend/request.hh"
|
||||||
#include "backend/sub_request.hh"
|
#include "backend/sub_request.hh"
|
||||||
|
@ -760,8 +762,12 @@ TextSimulation::on_set(const Tokens& arguments)
|
||||||
vector<CPUPolicy*> policies = (*it)->get_avail_policies();
|
vector<CPUPolicy*> policies = (*it)->get_avail_policies();
|
||||||
for (CPUPolicyIt it = policies.begin(); it != policies.end(); ++it)
|
for (CPUPolicyIt it = policies.begin(); it != policies.end(); ++it)
|
||||||
{
|
{
|
||||||
if (policy == 0)
|
if (policy == 0)
|
||||||
Simulation::get_instance().set_policy(*it);
|
{
|
||||||
|
Simulation::get_instance().set_policy(*it);
|
||||||
|
// FIXME: dedicate a function to set resource policy
|
||||||
|
Simulation::get_instance().set_resource_policy(new ResourcePolicyLiFo()); // leak leak leak
|
||||||
|
}
|
||||||
|
|
||||||
--policy;
|
--policy;
|
||||||
}
|
}
|
||||||
|
@ -1586,7 +1592,7 @@ operator<<(ostream& os, Schedulable::state state)
|
||||||
switch (state)
|
switch (state)
|
||||||
{
|
{
|
||||||
case Schedulable::state_running:
|
case Schedulable::state_running:
|
||||||
os << _("RUNNING @");
|
os << _(">> RUNNING <<");
|
||||||
break;
|
break;
|
||||||
case Schedulable::state_ready:
|
case Schedulable::state_ready:
|
||||||
os << _("READY");
|
os << _("READY");
|
||||||
|
|
Loading…
Reference in New Issue