- I forgot to include the policy.

git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@1124 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
matrevis 2006-09-13 01:28:22 +00:00
parent 43bd4369ed
commit 2c9c5ec498
2 changed files with 211 additions and 0 deletions

View File

@ -0,0 +1,119 @@
// src/backend/resource_policy_priority_inheritance.cc - Copyright 2005, 2006, University
// of Padova, dept. of Pure and Applied
// Mathematics
//
// This file is part of SGPEMv2.
//
// This is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// SGPEMv2 is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with SGPEMv2; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include <sgpemv2/resource_policy_priority_inheritance.hh>
#include <sgpemv2/thread.hh>
using namespace std;
using namespace sgpem;
ResourcePolicyPriorityInheritance::~ResourcePolicyPriorityInheritance()
{}
PolicyParameters&
ResourcePolicyPriorityInheritance::get_parameters()
{
return _parameters;
}
void
ResourcePolicyPriorityInheritance::configure()
throw(UserInterruptException)
{
}
void
ResourcePolicyPriorityInheritance::enforce(Environment& environment, Environment::SubRequestQueue& queue, SubRequest& sr)
throw(UserInterruptException)
{
typedef Environment::SubRequestQueue SubRequestQueue;
SubRequestQueue old_queue(queue);
queue.clear();
// the priority may only rise!
int pmax = sr.get_request().get_thread().get_current_priority();
typedef SubRequestQueue::iterator It;
for (It i = old_queue.begin(); i != old_queue.end(); i++)
{
// determine the max priority
int pthat = (**i).get_request().get_thread().get_current_priority();
if (pthat < pmax)
pmax = pthat;
// allocated ones remain allocated
if((**i).get_state() == Request::state_allocated)
queue.push_back(*i);
}
int pthis = sr.get_request().get_thread().get_current_priority();
// assume they are ordered by priority.
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 with lower priority go after the newly arrived
int pthat = (**i).get_request().get_thread().get_current_priority();
if(!inserted && pthis <= pthat)
{
queue.push_back(&sr);
inserted = true;
}
if (*i != &sr)
queue.push_back(*i);
}
else
{
// increase the priority of a the thread to the maximum priority of any process waiting
int push = pmax - (**i).get_request().get_thread().get_current_priority();
(**i).get_request().get_thread().set_priority_push(push);
}
}
}
Glib::ustring
ResourcePolicyPriorityInheritance::get_description() const
{
return "A resource policy which solves the priority inversion problem by raising the priority of a thread to the maximum relative to the queue.";
}
Glib::ustring
ResourcePolicyPriorityInheritance::get_name() const
{
return "Basic Priority Inheritance Protocol";
}
void
ResourcePolicyPriorityInheritance::activate()
{
}
void
ResourcePolicyPriorityInheritance::deactivate()
{
}

View File

@ -0,0 +1,92 @@
// src/backend/resource_policy_priority_inheritance.hh - Copyright 2005, 2006, University
// of Padova, dept. of Pure and Applied
// Mathematics
//
// This file is part of SGPEMv2.
//
// This is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// SGPEMv2 is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with SGPEMv2; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#ifndef RESOURCE_POLICY_INHERITANCE_HH
#define RESOURCE_POLICY_INHERITANCE_HH 1
#include "config.h"
#include "gettext.h"
#include "glibmm/ustring.h"
#include <sgpemv2/resource_policy.hh>
#include <sgpemv2/policy_parameters.hh>
#include <sgpemv2/user_interrupt_exception.hh>
namespace sgpem
{
class ResourcePolicyPriorityInheritance;
/** \brief
It's a Strategy wich stay for a resource allocating algorithm.
It implements the related resource allocation policy.
*/
class SG_DLLEXPORT ResourcePolicyPriorityInheritance : public ResourcePolicy
{
public:
virtual ~ResourcePolicyPriorityInheritance();
/**
Initialize the inner components of the policy.
Because it's a pure virtual method, must be re-implemented
in concrete derived classes.
*/
virtual void configure() throw(UserInterruptException);
/**
Mixes the queues.
Because it's a pure virtual method, must be re-implemented
in concrete derived classes.
*/
virtual void enforce(Environment& environment, Environment::SubRequestQueue& queue, SubRequest& sr) throw(UserInterruptException);
/**
Gets a string description of the policy.
Because it's a pure virtual method, must be re-implemented
in concrete derived classes.
\return String description of the policy.
*/
virtual Glib::ustring get_description() const;
virtual Glib::ustring get_name() const;
virtual void activate();
virtual void deactivate();
/**
Gets the parameters related with this policy.
\return The policy parameters.
*/
PolicyParameters& get_parameters();
protected:
PolicyParameters _parameters;
};
}//~ namespace sgpem
#endif