- Defaults to thread view.

- Enforcing resource policy the old way.


git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@1016 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
matrevis 2006-09-06 00:29:11 +00:00
parent 2b9942bbec
commit 68d5f30f64
5 changed files with 72 additions and 12 deletions

View File

@ -31,8 +31,6 @@ DefaultResourcePolicyManager DefaultResourcePolicyManager::_default_instance;
DefaultResourcePolicyManager::DefaultResourcePolicyManager() DefaultResourcePolicyManager::DefaultResourcePolicyManager()
{ {
ResourcePolicy * lifo = new ResourcePolicyLiFo();
_policies.push_back(lifo);
ResourcePoliciesGatekeeper::get_instance().register_manager(this); ResourcePoliciesGatekeeper::get_instance().register_manager(this);
// Includes default policies. // Includes default policies.
_policies.push_back(new ResourcePolicyLiFo()); _policies.push_back(new ResourcePolicyLiFo());

View File

@ -54,10 +54,30 @@ ResourcePolicyLiFo::enforce(Environment& environment, Environment::SubRequestQue
typedef SubRequestQueue::iterator It; typedef SubRequestQueue::iterator It;
for (It i = old_queue.begin(); i != old_queue.end(); i++) for (It i = old_queue.begin(); i != old_queue.end(); i++)
{ {
// just rebuilds the queue by now. // allocated ones remain allocated
if((**i).get_state() == Request::state_allocated)
queue.push_back(*i); queue.push_back(*i);
} }
bool inserted = false;
typedef SubRequestQueue::iterator It;
for (It i = old_queue.begin(); i != old_queue.end(); i++)
{
// allocated ones remain allocated
if((**i).get_state() != Request::state_allocated)
{
// non-allocated ones go after the newly arrived
if(!inserted)
{
queue.push_back(&sr);
inserted = true;
}
if (*i != &sr)
queue.push_back(*i);
}
}
printf("\nResourcePolicy 'LiFo' has terminated."); printf("\nResourcePolicy 'LiFo' has terminated.");
} }

View File

@ -69,6 +69,8 @@ static void raise_new_requests(DynamicThread& running_thread, ConcreteEnvironmen
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);
static void determine_subr_allocable_status(const Resource& res, SubRequestQueue& queue);
// --------------------------------------------------------- // ---------------------------------------------------------
@ -185,14 +187,21 @@ 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(environment, queue, cur_subr); resource_policy.enforce(environment, queue, cur_subr);
// 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;
// WARNING: adding a new request may require updating the status of ALL other
// requests in the queue
determine_subr_allocable_status(resource, queue);
// after that, check if it is globally allocable.
// See if the subrequest is allocable or unallocable, and set its state. // See if the subrequest is allocable or unallocable, and set its state.
// It's important that the subrequest has already been added to the queue. // It's important that the subrequest has already been added to the queue.
determine_subr_allocable_status(cur_req, cur_subr, resource, queue); // determine_subr_allocable_status(cur_req, cur_subr, resource, queue);
} //~ for(over subrequests) } //~ for(over subrequests)
} //~ if(request is future and is time to allocate it) } //~ if(request is future and is time to allocate it)
@ -214,9 +223,10 @@ raise_new_requests(DynamicThread& running_thread, ConcreteEnvironment& environme
case Request::state_allocable: case Request::state_allocable:
for(Iseq<SubRequests::const_iterator> it_dsrs = const_iseq(subreqs); it_dsrs; ++it_dsrs) for(Iseq<SubRequests::const_iterator> it_dsrs = const_iseq(subreqs); it_dsrs; ++it_dsrs)
{ {
DynamicSubRequest& subreq = **it_dsrs; DynamicSubRequest& subreq = **it_dsrs;
assert(subreq.get_state() == Request::state_allocable); assert(subreq.get_state() == Request::state_allocable);
/*
// Move this request up the queue, to the back of the allocated // Move this request up the queue, to the back of the allocated
// subrequests. This is mainly for display. :-) // subrequests. This is mainly for display. :-)
// The rest of the queue sorting business is up to the resource policy. // The rest of the queue sorting business is up to the resource policy.
@ -229,7 +239,7 @@ raise_new_requests(DynamicThread& running_thread, ConcreteEnvironment& environme
SubRequestQueue::iterator this_subreq = find(alloc_it, queue.end(), &subreq); SubRequestQueue::iterator this_subreq = find(alloc_it, queue.end(), &subreq);
assert(this_subreq != queue.end()); assert(this_subreq != queue.end());
swap(*alloc_it, *this_subreq); swap(*alloc_it, *this_subreq);
*/
subreq.set_state(Request::state_allocated); subreq.set_state(Request::state_allocated);
} }
break; break;
@ -258,8 +268,11 @@ determine_subr_allocable_status(const DynamicRequest& req, DynamicSubRequest& su
unsigned int total_places = res.get_places(); unsigned int total_places = res.get_places();
unsigned int free_places = total_places; unsigned int free_places = total_places;
unsigned int needed_places = 0; unsigned int needed_places = 0;
unsigned int position_in_queue = 0;
bool too_far_in_the_queue = false;
for(Iseq<SubRequestQueue::const_iterator> queue_it = const_iseq(queue); for(Iseq<SubRequestQueue::const_iterator> queue_it = const_iseq(queue);
queue_it && free_places >= needed_places; queue_it++) queue_it && free_places >= needed_places; queue_it++, position_in_queue++)
{ {
SubRequest& sr = **queue_it; SubRequest& sr = **queue_it;
if(sr.get_state() == Request::state_allocated) if(sr.get_state() == Request::state_allocated)
@ -270,16 +283,20 @@ determine_subr_allocable_status(const DynamicRequest& req, DynamicSubRequest& su
// Okay, this won't win a beauty contest... // Okay, this won't win a beauty contest...
if(&sr.get_request() == &req) if(&sr.get_request() == &req)
needed_places++; needed_places++;
// Well, and what about this, then?
if(&sr == &subr && position_in_queue + 1 > total_places)
too_far_in_the_queue = true;
} //~ for(over subrequest queue) } //~ for(over subrequest queue)
// If the number of places this thread need for a resource are // If the number of places this thread need for a resource are
// less or equal the places left free, it's allocable. // less or equal the places left free, it's allocable.
if(needed_places <= free_places) if(needed_places <= free_places && !too_far_in_the_queue)
subr.set_state(Request::state_allocable); subr.set_state(Request::state_allocable);
else else
{ {
subr.set_state(Request::state_unallocable); subr.set_state(Request::state_unallocable);
/*
// Okay, this is difficult to understand, so read carefully: // Okay, this is difficult to understand, so read carefully:
// when we make a subrequest unallocable, it means that the // when we make a subrequest unallocable, it means that the
// whole request is unallocable. However, it may happen that // whole request is unallocable. However, it may happen that
@ -296,10 +313,32 @@ determine_subr_allocable_status(const DynamicRequest& req, DynamicSubRequest& su
if(&x.get_request() == &req && x.get_state() == Request::state_allocable) if(&x.get_request() == &req && x.get_state() == Request::state_allocable)
x.set_state(Request::state_unallocable); x.set_state(Request::state_unallocable);
} }
*/
} }
} }
// The following loop updates the states of the subrequests depending
// on their position in the queue
void
determine_subr_allocable_status(const Resource& res, SubRequestQueue& queue)
{
unsigned int total_places = res.get_places();
unsigned int position_in_queue = 0;
for(Iseq<SubRequestQueue::const_iterator> queue_it = const_iseq(queue);
queue_it; queue_it++, position_in_queue++)
{
DynamicSubRequest& sr = (DynamicSubRequest&) **queue_it;
if (sr.get_state() == Request::state_allocated)
continue;
if(position_in_queue + 1 > total_places)
sr.set_state(Request::state_unallocable);
else
sr.set_state(Request::state_allocable);
} //~ for(over subrequest queue)
}
// This function checks if there are some allocable or unallocable // This function checks if there are some allocable or unallocable
// requests that should change their state according to the previous // requests that should change their state according to the previous
// step of the simulation. It also put previously blocked threads // step of the simulation. It also put previously blocked threads
@ -333,7 +372,8 @@ look_for_mutant_request_states(ConcreteEnvironment& environment,
// Update the state of the subrequest, either from allocable to // Update the state of the subrequest, either from allocable to
// unallocable or vice-versa // unallocable or vice-versa
determine_subr_allocable_status(req, subr, *res_it->second, queue); // determine_subr_allocable_status(req, subr, *res_it->second, queue);
determine_subr_allocable_status(*res_it->second, queue);
// TODO: The following is a moderately expensive operation // TODO: The following is a moderately expensive operation
// to do here. See if we can move it somewhere else. // to do here. See if we can move it somewhere else.

View File

@ -532,6 +532,7 @@ GuiBuilder::GuiBuilder(const std::string& gladefile)
_refXml->get_widget("SimulationScrolledWindow", simulation_window); _refXml->get_widget("SimulationScrolledWindow", simulation_window);
SimulationWidget& simulation_widget = *manage(new SimulationWidget(Simulation::get_instance())); SimulationWidget& simulation_widget = *manage(new SimulationWidget(Simulation::get_instance()));
simulation_window->add(simulation_widget); simulation_window->add(simulation_widget);
simulation_widget.set_show_threads(true);
simulation_widget.show(); simulation_widget.show();
// Why this works, and SimulationWidget doesn't ?? // Why this works, and SimulationWidget doesn't ??

View File

@ -11,6 +11,7 @@ using namespace sgpem;
add(_holt_widget); add(_holt_widget);
_holt_widget.set_scaling_mode(CairoWidget::scaling_min); _holt_widget.set_scaling_mode(CairoWidget::scaling_min);
_holt_widget.show(); _holt_widget.show();
_holt_widget.set_show_threads(true);
//set_keep_above(); //set_keep_above();
} }