diff --git a/Makefile.am b/Makefile.am index ee11a9f..155d47a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -187,8 +187,10 @@ src_backend_libbackend_la_SOURCES = \ src/backend/resource.cc \ src/backend/resource_policies_gatekeeper.cc \ src/backend/resource_policy.cc \ + src/backend/resource_policy_fifo.cc \ src/backend/resource_policy_lifo.cc \ src/backend/resource_policy_manager.cc \ + src/backend/resource_policy_priority.cc \ src/backend/schedulable.cc \ src/backend/schedulable_statistics.cc \ src/backend/scheduler.cc \ @@ -238,8 +240,10 @@ pkginclude_HEADERS += \ src/backend/sgpemv2/resource.hh \ src/backend/sgpemv2/resource_policies_gatekeeper.hh \ src/backend/sgpemv2/resource_policy.hh \ + src/backend/sgpemv2/resource_policy_fifo.hh \ src/backend/sgpemv2/resource_policy_lifo.hh \ src/backend/sgpemv2/resource_policy_manager.hh \ + src/backend/sgpemv2/resource_policy_priority.hh \ src/backend/sgpemv2/process.hh \ src/backend/sgpemv2/schedulable.hh \ src/backend/sgpemv2/schedulable_statistics.hh \ diff --git a/src/backend/default_resource_policy_manager.cc b/src/backend/default_resource_policy_manager.cc index 36156be..0dfb6f5 100644 --- a/src/backend/default_resource_policy_manager.cc +++ b/src/backend/default_resource_policy_manager.cc @@ -20,6 +20,8 @@ #include +#include +#include #include #include @@ -34,6 +36,8 @@ DefaultResourcePolicyManager::DefaultResourcePolicyManager() ResourcePoliciesGatekeeper::get_instance().register_manager(this); // Includes default policies. _policies.push_back(new ResourcePolicyLiFo()); + _policies.push_back(new ResourcePolicyFiFo()); + _policies.push_back(new ResourcePolicyPriority()); } diff --git a/src/backend/resource_policy_fifo.cc b/src/backend/resource_policy_fifo.cc new file mode 100644 index 0000000..14c54ce --- /dev/null +++ b/src/backend/resource_policy_fifo.cc @@ -0,0 +1,91 @@ +// src/backend/resource_policy_fifo.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 + + +using namespace std; +using namespace sgpem; + +ResourcePolicyFiFo::~ResourcePolicyFiFo() +{} + + +PolicyParameters& +ResourcePolicyFiFo::get_parameters() +{ + return _parameters; +} + +void +ResourcePolicyFiFo::configure() + throw(UserInterruptException) +{ +} + +void +ResourcePolicyFiFo::enforce(Environment& environment, Environment::SubRequestQueue& queue, SubRequest& sr) + throw(UserInterruptException) +{ + typedef Environment::SubRequestQueue SubRequestQueue; + + // the last inserted request goes on the last free place. + SubRequestQueue old_queue(queue); + queue.clear(); + + 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) + queue.push_back(*i); + } + + + + typedef SubRequestQueue::iterator It; + for (It i = old_queue.begin(); i != old_queue.end(); i++) + if((**i).get_state() != Request::state_allocated && *i != &sr) + queue.push_back(*i); + queue.push_back(&sr); +} + +Glib::ustring +ResourcePolicyFiFo::get_description() const +{ + return "A resource policy which satisfies earlier requests before older ones."; +} + +Glib::ustring +ResourcePolicyFiFo::get_name() const +{ + return "First In, First Out"; +} + + +void +ResourcePolicyFiFo::activate() +{ +} + +void +ResourcePolicyFiFo::deactivate() +{ +} diff --git a/src/backend/resource_policy_lifo.cc b/src/backend/resource_policy_lifo.cc index 6d3a1f4..9f82ca7 100644 --- a/src/backend/resource_policy_lifo.cc +++ b/src/backend/resource_policy_lifo.cc @@ -45,7 +45,6 @@ ResourcePolicyLiFo::enforce(Environment& environment, Environment::SubRequestQue throw(UserInterruptException) { typedef Environment::SubRequestQueue SubRequestQueue; - printf("\nResourcePolicy 'LiFo' has been called."); // the last inserted request goes on the first free place. SubRequestQueue old_queue(queue); @@ -78,7 +77,6 @@ ResourcePolicyLiFo::enforce(Environment& environment, Environment::SubRequestQue queue.push_back(*i); } } - printf("\nResourcePolicy 'LiFo' has terminated."); } Glib::ustring diff --git a/src/backend/resource_policy_priority.cc b/src/backend/resource_policy_priority.cc new file mode 100644 index 0000000..bbad813 --- /dev/null +++ b/src/backend/resource_policy_priority.cc @@ -0,0 +1,111 @@ +// src/backend/resource_policy_priority.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 + +// FIXME: remove include +#include + +using namespace std; +using namespace sgpem; + +ResourcePolicyPriority::~ResourcePolicyPriority() +{} + + +PolicyParameters& +ResourcePolicyPriority::get_parameters() +{ + return _parameters; +} + +void +ResourcePolicyPriority::configure() + throw(UserInterruptException) +{ +} + +void +ResourcePolicyPriority::enforce(Environment& environment, Environment::SubRequestQueue& queue, SubRequest& sr) + throw(UserInterruptException) +{ + typedef Environment::SubRequestQueue SubRequestQueue; + + // the last inserted request goes on the first free place. + SubRequestQueue old_queue(queue); + queue.clear(); + + 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) + queue.push_back(*i); + } + + + + // 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(); + int pthis = sr.get_request().get_thread().get_current_priority(); + std::cout << "\npthat = " << pthat; + std::cout << "\npthis = " << pthis; + if(!inserted && pthis <= pthat) + { + queue.push_back(&sr); + inserted = true; + } + if (*i != &sr) + queue.push_back(*i); + } + } +} + +Glib::ustring +ResourcePolicyPriority::get_description() const +{ + return "A resource policy which satisfies higher priority requests before lower priority ones."; +} + +Glib::ustring +ResourcePolicyPriority::get_name() const +{ + return "Higher Priority First"; +} + + +void +ResourcePolicyPriority::activate() +{ +} + +void +ResourcePolicyPriority::deactivate() +{ +} diff --git a/src/backend/sgpemv2/resource_policy_fifo.hh b/src/backend/sgpemv2/resource_policy_fifo.hh new file mode 100644 index 0000000..1661c0f --- /dev/null +++ b/src/backend/sgpemv2/resource_policy_fifo.hh @@ -0,0 +1,92 @@ +// src/backend/resource_policy_fifo.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_FIFO_HH +#define RESOURCE_POLICY_FIFO_HH 1 + +#include "config.h" +#include "gettext.h" + +#include "glibmm/ustring.h" + +#include + +#include +#include + +namespace sgpem +{ + class ResourcePolicyFiFo; + + /** \brief + It's a Strategy wich stay for a resource allocating algorithm. + It implements the related resource allocation policy. + */ + class SG_DLLEXPORT ResourcePolicyFiFo : public ResourcePolicy + { + public: + virtual ~ResourcePolicyFiFo(); + + /** + 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 diff --git a/src/backend/sgpemv2/resource_policy_priority.hh b/src/backend/sgpemv2/resource_policy_priority.hh new file mode 100644 index 0000000..7659bab --- /dev/null +++ b/src/backend/sgpemv2/resource_policy_priority.hh @@ -0,0 +1,89 @@ +// src/backend/resource_policy_priority.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_PRIORITY_HH +#define RESOURCE_POLICY_PRIORITY_HH 1 + +#include "config.h" +#include "gettext.h" + +#include "glibmm/ustring.h" + +#include + +#include +#include + +namespace sgpem +{ + class ResourcePolicyPriority; + + /** \brief + It's a Strategy wich stay for a resource allocating algorithm. + It implements the related resource allocation policy. + */ + class SG_DLLEXPORT ResourcePolicyPriority : public ResourcePolicy + { + public: + virtual ~ResourcePolicyPriority(); + + /** + 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. + */ + 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