From 2c9c5ec4987333c18d1456d6c15ab9efefe5f2fe Mon Sep 17 00:00:00 2001 From: matrevis Date: Wed, 13 Sep 2006 01:28:22 +0000 Subject: [PATCH] - I forgot to include the policy. git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@1124 3ecf2c5c-341e-0410-92b4-d18e462d057c --- .../resource_policy_priority_inheritance.cc | 119 ++++++++++++++++++ .../resource_policy_priority_inheritance.hh | 92 ++++++++++++++ 2 files changed, 211 insertions(+) create mode 100644 src/backend/resource_policy_priority_inheritance.cc create mode 100644 src/backend/sgpemv2/resource_policy_priority_inheritance.hh diff --git a/src/backend/resource_policy_priority_inheritance.cc b/src/backend/resource_policy_priority_inheritance.cc new file mode 100644 index 0000000..f52067f --- /dev/null +++ b/src/backend/resource_policy_priority_inheritance.cc @@ -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 +#include + +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() +{ +} diff --git a/src/backend/sgpemv2/resource_policy_priority_inheritance.hh b/src/backend/sgpemv2/resource_policy_priority_inheritance.hh new file mode 100644 index 0000000..b07cf85 --- /dev/null +++ b/src/backend/sgpemv2/resource_policy_priority_inheritance.hh @@ -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 + +#include +#include + +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