- Added resource policies: FIFO and Priority.
git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@1052 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
parent
f7eb44bf64
commit
a9c0ff01d2
|
@ -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 \
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
|
||||
|
||||
#include <sgpemv2/resource_policy_lifo.hh>
|
||||
#include <sgpemv2/resource_policy_fifo.hh>
|
||||
#include <sgpemv2/resource_policy_priority.hh>
|
||||
#include <sgpemv2/default_resource_policy_manager.hh>
|
||||
#include <sgpemv2/resource_policies_gatekeeper.hh>
|
||||
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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 <sgpemv2/resource_policy_fifo.hh>
|
||||
|
||||
|
||||
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()
|
||||
{
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -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 <sgpemv2/resource_policy_priority.hh>
|
||||
#include <sgpemv2/thread.hh>
|
||||
|
||||
// FIXME: remove include
|
||||
#include <iostream>
|
||||
|
||||
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()
|
||||
{
|
||||
}
|
|
@ -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 <sgpemv2/resource_policy.hh>
|
||||
|
||||
#include <sgpemv2/policy_parameters.hh>
|
||||
#include <sgpemv2/user_interrupt_exception.hh>
|
||||
|
||||
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
|
|
@ -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 <sgpemv2/resource_policy.hh>
|
||||
|
||||
#include <sgpemv2/policy_parameters.hh>
|
||||
#include <sgpemv2/user_interrupt_exception.hh>
|
||||
|
||||
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
|
Loading…
Reference in New Issue