- Make libpyloader a loadable plugin (warning: won't work
on Window$ unless you change the string "libpyloader" to "pyloader" into main.cc) - Fix Makefile to support module creation and loading - 2DO: - Add a class into backend to load and manage plugins - Install plugins into separate directory - Remove hardcoded paths git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@458 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
parent
38f7b84909
commit
56534edb6c
15 changed files with 187 additions and 215 deletions
|
@ -1,71 +0,0 @@
|
|||
// src/backend/dummy_policy.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 "dummy_policy.hh"
|
||||
|
||||
using namespace std;
|
||||
using namespace sgpem;
|
||||
|
||||
DummyPolicy::~DummyPolicy()
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
DummyPolicy::configure()
|
||||
{
|
||||
_id = 100;
|
||||
_parameters.clear();
|
||||
_parameters.register_int("var1", 0, 10, true, 5);
|
||||
_parameters.register_int("var2", -100, +100, false);
|
||||
_parameters.register_float("kernel", 0, 10, true, 3.1415);
|
||||
_parameters.register_float("multiplier", -100000, 100000, true, 1000);
|
||||
_parameters.register_string("che_ne_so", true);
|
||||
|
||||
}
|
||||
|
||||
Glib::ustring
|
||||
DummyPolicy::get_description() const
|
||||
{
|
||||
return "This is a dummy policy implemented in C++. It is just needed as a debug stub.";
|
||||
}
|
||||
|
||||
bool
|
||||
DummyPolicy::is_pre_emptive() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
int
|
||||
DummyPolicy::get_time_slice() const
|
||||
{
|
||||
return _time_slice;
|
||||
}
|
||||
|
||||
void
|
||||
DummyPolicy::set_time_slice( const int& i)
|
||||
{
|
||||
_time_slice = i;
|
||||
}
|
||||
|
||||
void
|
||||
DummyPolicy::sort_queue(sgpem::Scheduler::event) const
|
||||
{
|
||||
return;
|
||||
}
|
|
@ -1,56 +0,0 @@
|
|||
// src/backend/dummy_policy.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 DUMMYPOLICY_HH
|
||||
#define DUMMYPOLICY_HH 1
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "glibmm/ustring.h"
|
||||
|
||||
#include "policy.hh"
|
||||
|
||||
namespace sgpem
|
||||
{
|
||||
class DummyPolicy;
|
||||
|
||||
/** \brief This is a trivial policy for demostration purposes only
|
||||
*
|
||||
* This trivial schedulation policy was needed during initial development
|
||||
* as stub. It is now maintained as an example of how built-in policy can
|
||||
* be implemented in C++.
|
||||
*/
|
||||
class SG_DLLEXPORT DummyPolicy : public Policy
|
||||
{
|
||||
public:
|
||||
virtual ~DummyPolicy();
|
||||
virtual void configure();
|
||||
virtual void sort_queue(sgpem::Scheduler::event) const;
|
||||
virtual Glib::ustring get_description() const;
|
||||
virtual bool is_pre_emptive() const;
|
||||
virtual int get_time_slice() const;
|
||||
virtual void set_time_slice(const int&);
|
||||
|
||||
private:
|
||||
int _time_slice;
|
||||
};
|
||||
} //~ namespace sgpem
|
||||
|
||||
#endif // DUMMYPOLICY_HH
|
|
@ -28,6 +28,7 @@
|
|||
|
||||
#include "scheduler.hh"
|
||||
#include "policy_parameters.hh"
|
||||
#include "user_interrupt_exception.hh"
|
||||
|
||||
namespace sgpem
|
||||
{
|
||||
|
@ -51,7 +52,7 @@ namespace sgpem
|
|||
Because it's a pure virtual method, must be re-implemented
|
||||
in concrete derived classes.
|
||||
*/
|
||||
virtual void configure() = 0;
|
||||
virtual void configure() throw(UserInterruptException) = 0;
|
||||
|
||||
/**
|
||||
Sort the \ref SchedulableQueue object that contain all the Schedulable objects
|
||||
|
@ -61,13 +62,13 @@ namespace sgpem
|
|||
in concrete derived classes.
|
||||
\param event Call reason. Needed only by some scheduling policies.
|
||||
*/
|
||||
virtual void sort_queue(Scheduler::event event) const = 0;
|
||||
virtual void sort_queue(Scheduler::event event) const throw(UserInterruptException) = 0;
|
||||
|
||||
/**
|
||||
Gets the unique identifier (id) of this Policy.
|
||||
\return The Policy id.
|
||||
*/
|
||||
int get_id() const;
|
||||
int get_id() const;
|
||||
|
||||
/**
|
||||
Gets a string description of the policy.
|
||||
|
@ -76,7 +77,7 @@ namespace sgpem
|
|||
in concrete derived classes.
|
||||
\return String description of the policy.
|
||||
*/
|
||||
virtual Glib::ustring get_description() const = 0;
|
||||
virtual Glib::ustring get_description() const = 0;
|
||||
|
||||
/**
|
||||
Tell if this policy is preemptible.
|
||||
|
@ -88,7 +89,7 @@ namespace sgpem
|
|||
in concrete derived classes.
|
||||
\return True if this policy is preemptible.
|
||||
*/
|
||||
virtual bool is_pre_emptive() const = 0;
|
||||
virtual bool is_pre_emptive() const throw(UserInterruptException) = 0;
|
||||
|
||||
/**
|
||||
Gets the time quantum for the policy.
|
||||
|
@ -97,16 +98,7 @@ namespace sgpem
|
|||
in concrete derived classes.
|
||||
\return Time quantum for the policy.
|
||||
*/
|
||||
virtual int get_time_slice() const = 0;
|
||||
|
||||
/**
|
||||
Sets the time quantum for the policy.
|
||||
|
||||
Because it's a pure virtual method, must be re-implemented
|
||||
in concrete derived classes.
|
||||
\param quantum The desired time quantum for the policy.
|
||||
*/
|
||||
virtual void set_time_slice(const int& quantum) = 0;
|
||||
virtual int get_time_slice() const throw(UserInterruptException) = 0;
|
||||
|
||||
/**
|
||||
Gets the parameters related with this policy.
|
||||
|
@ -115,7 +107,7 @@ namespace sgpem
|
|||
in concrete derived classes.
|
||||
\return The policy parameters.
|
||||
*/
|
||||
PolicyParameters& get_parameters();
|
||||
PolicyParameters& get_parameters();
|
||||
|
||||
protected:
|
||||
PolicyParameters _parameters;
|
||||
|
|
|
@ -21,8 +21,23 @@
|
|||
|
||||
#include "policy_manager.hh"
|
||||
|
||||
PolicyManager*
|
||||
PolicyManager::_registered = NULL;
|
||||
|
||||
PolicyManager::~PolicyManager()
|
||||
{
|
||||
PolicyManager::PolicyManager()
|
||||
{
|
||||
_registered = this;
|
||||
}
|
||||
|
||||
|
||||
PolicyManager::~PolicyManager()
|
||||
{
|
||||
// This check is necessary:
|
||||
if(_registered == this) _registered = NULL;
|
||||
}
|
||||
|
||||
PolicyManager&
|
||||
PolicyManager::get_registered_manager()
|
||||
{
|
||||
return *_registered;
|
||||
}
|
||||
|
|
|
@ -36,6 +36,17 @@ namespace sgpem
|
|||
class SG_DLLEXPORT PolicyManager
|
||||
{
|
||||
public:
|
||||
/** \brief PolicyManager constructor
|
||||
*
|
||||
* Saves ``this'' pointer into the _registered attribute, so it can access
|
||||
* it when requested. This is done so that concrete subclasses can be defined
|
||||
* even if they are found in external dynamic modules not known at compile time.
|
||||
*
|
||||
* For the moment, just an instance of PolicyManager can be saved. This will
|
||||
* be expanded in next milestones.
|
||||
*/
|
||||
PolicyManager();
|
||||
|
||||
virtual ~PolicyManager() = 0;
|
||||
|
||||
/**
|
||||
|
@ -48,7 +59,17 @@ namespace sgpem
|
|||
/**
|
||||
Init (or reset if yet initialized) the manager.
|
||||
*/
|
||||
virtual void init() = 0;
|
||||
virtual void init() = 0;
|
||||
|
||||
/** \brief Get the registered manager instance
|
||||
*
|
||||
* \return The registered policy manager instance.
|
||||
*/
|
||||
static PolicyManager& get_registered_manager();
|
||||
|
||||
private:
|
||||
/** A pointer to the registered instance */
|
||||
static PolicyManager* _registered;
|
||||
};
|
||||
|
||||
} //~ namespace sgpem
|
||||
|
|
54
src/backend/pyloader/hook.cc
Normal file
54
src/backend/pyloader/hook.cc
Normal file
|
@ -0,0 +1,54 @@
|
|||
// src/backend/pyloader/hook.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
|
||||
|
||||
// The idea of this file is to provide a static function to execute
|
||||
// when the plugin (this library) is loaded. Thus the name "hook".
|
||||
|
||||
// For the moment, instead of a function hook to be called by the
|
||||
// libbackend.so module, we have a static PythonPolicyManager object.
|
||||
// This is a risk.
|
||||
#warning FIXME : this code is quite a bad idea. Replace me with \
|
||||
a hookable structure, and execute a pointer to function stored \
|
||||
therein. See "info libtool": "dlopened modules"
|
||||
|
||||
#include "python_policy_manager.hh"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define SG_CONSTRUCTOR __attribute__ ((constructor))
|
||||
#define SG_DESTRUCTOR __attribute__ ((destructor))
|
||||
|
||||
PolicyManager* _global_pm = NULL;
|
||||
|
||||
void SG_DLLEXPORT SG_CONSTRUCTOR hook_ctor(void)
|
||||
{
|
||||
_global_pm = PythonPolicyManager::get_instance();
|
||||
}
|
||||
|
||||
void SG_DLLEXPORT SG_DESTRUCTOR hook_dtor(void)
|
||||
{
|
||||
delete _global_pm;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -152,13 +152,6 @@ PythonPolicy::get_time_slice() const throw(UserInterruptException) {
|
|||
return tmp < 0 ? numeric_limits<int>::max() : static_cast<int>(tmp);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PythonPolicy::set_time_slice(const int&)
|
||||
{
|
||||
throw "The design is wrong, and I shouldn't be called.";
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PythonPolicy::wait_unlock() const throw(UserInterruptException)
|
||||
|
|
|
@ -76,12 +76,6 @@ namespace sgpem
|
|||
*/
|
||||
int get_time_slice() const throw(UserInterruptException);
|
||||
|
||||
// Singing with Caipha's voice: "must die, must die, this method must die!"
|
||||
/**
|
||||
Changes the time-slice of the policy.
|
||||
*/
|
||||
void set_time_slice(const int&);
|
||||
|
||||
private:
|
||||
PythonPolicy(const char* name);
|
||||
PythonPolicy(const PythonPolicy&);
|
||||
|
|
|
@ -185,7 +185,7 @@ namespace sgpem {
|
|||
// ---------------------------------------------
|
||||
class Scheduler {
|
||||
public:
|
||||
sgpem::Policy* get_policy();
|
||||
sgpem::Policy& get_policy();
|
||||
static sgpem::Scheduler& get_instance();
|
||||
sgpem::SchedulableList* get_ready_queue();
|
||||
private:
|
||||
|
|
|
@ -20,29 +20,33 @@
|
|||
|
||||
#include "policy.hh"
|
||||
#include "scheduler.hh"
|
||||
#include "policy_manager.hh"
|
||||
using namespace std;
|
||||
using namespace sgpem;
|
||||
using namespace memory;
|
||||
|
||||
//static object
|
||||
Scheduler Scheduler::_instance(10); //dummy parameter
|
||||
Scheduler*
|
||||
Scheduler::_instance = 0;
|
||||
|
||||
/**
|
||||
|
||||
*/
|
||||
Scheduler::Scheduler(int) //private constructor. The parameter is discarded
|
||||
{}
|
||||
//private constructor. The parameter is discarded
|
||||
Scheduler::Scheduler()
|
||||
: _policy_manager(PolicyManager::get_registered_manager())
|
||||
{
|
||||
_policy_manager.init();
|
||||
}
|
||||
|
||||
Scheduler&
|
||||
Scheduler::get_instance()
|
||||
{
|
||||
return _instance;
|
||||
if(!_instance)
|
||||
_instance = new Scheduler();
|
||||
return *_instance;
|
||||
}
|
||||
|
||||
SchedulableList*
|
||||
Scheduler::get_ready_queue()
|
||||
{
|
||||
return &_ready_queue;
|
||||
return &_ready_queue;
|
||||
}
|
||||
|
||||
|
||||
|
@ -58,23 +62,24 @@ Scheduler::reset_status()
|
|||
// restore the policy
|
||||
}
|
||||
|
||||
void
|
||||
/* void
|
||||
Scheduler::set_policy(Policy* p)
|
||||
{
|
||||
_policy = p;
|
||||
}
|
||||
_policy_manager.set_policy(p);
|
||||
}*/
|
||||
|
||||
|
||||
Policy*
|
||||
Policy&
|
||||
Scheduler::get_policy()
|
||||
{
|
||||
return _policy;
|
||||
return _policy_manager.get_policy();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Scheduler::step_forward()
|
||||
{
|
||||
Policy& policy = get_policy();
|
||||
|
||||
History& h = History::get_instance();
|
||||
//******************
|
||||
|
@ -107,7 +112,7 @@ Scheduler::step_forward()
|
|||
//cout << "\nnuovo running: " << initial->get_item_at(i)->get_schedulable()->get_name();
|
||||
|
||||
//restore the old running schedulable
|
||||
if (_policy->is_pre_emptive() == false && running_ptr)
|
||||
if (policy.is_pre_emptive() == false && running_ptr)
|
||||
_ready_queue.remove(0);
|
||||
|
||||
//adds the NEW one
|
||||
|
@ -116,10 +121,10 @@ Scheduler::step_forward()
|
|||
initial->get_item_at(i)->set_state(SchedulableStatus::state_ready);
|
||||
|
||||
// Sort the queue
|
||||
_policy->sort_queue(event_schedulable_arrival);
|
||||
policy.sort_queue(event_schedulable_arrival);
|
||||
|
||||
//restore the old running schedulable
|
||||
if (_policy->is_pre_emptive() == false && running_ptr)
|
||||
if (policy.is_pre_emptive() == false && running_ptr)
|
||||
_ready_queue.add_at_top(*running_ptr);
|
||||
}
|
||||
|
||||
|
@ -143,14 +148,14 @@ Scheduler::step_forward()
|
|||
running_ptr = NULL;
|
||||
|
||||
//IF _ready_queue.size() == 0 sort_queue(...) is called but has no effect!!
|
||||
_policy->sort_queue(event_schedulable_termination);
|
||||
policy.sort_queue(event_schedulable_termination);
|
||||
}
|
||||
|
||||
//*****************
|
||||
// Check for time slice
|
||||
//*****************
|
||||
if (_policy->get_time_slice() != numeric_limits<int>::max()) //time-slice
|
||||
_policy->sort_queue(event_end_time_slice);
|
||||
if (policy.get_time_slice() != numeric_limits<int>::max()) //time-slice
|
||||
policy.sort_queue(event_end_time_slice);
|
||||
|
||||
//******************
|
||||
// Create the final list of schedulable
|
||||
|
|
|
@ -22,7 +22,9 @@
|
|||
#define SCHEDULER_HH 1
|
||||
namespace sgpem
|
||||
{
|
||||
class Policy;
|
||||
class Scheduler;
|
||||
class PolicyManager;
|
||||
class Policy;
|
||||
}
|
||||
|
||||
#include "config.h"
|
||||
|
@ -71,9 +73,11 @@ namespace sgpem
|
|||
event_end_time_slice
|
||||
};
|
||||
|
||||
/**
|
||||
Returns the unique instance of this class, conforming to the Singleton pattern.
|
||||
\return the unique instance of this class, conforming to the Singleton pattern.
|
||||
/** \brief Returns the unique instance of this class, conforming to the Singleton pattern.
|
||||
*
|
||||
* If Scheduler isn't initialized, creates it. Should be called at least once before
|
||||
* starting the Simulation.
|
||||
* \return the unique instance of this class, conforming to the Singleton pattern.
|
||||
*/
|
||||
static Scheduler& get_instance();
|
||||
/**
|
||||
|
@ -97,19 +101,21 @@ namespace sgpem
|
|||
Sets the policy that will be used to generate the simulation at the next instant.
|
||||
\param policy the policy that will be used to generate the simulation at the next instant.
|
||||
*/
|
||||
/* DISABLED until we don't have PolicyManager::set_policy()
|
||||
void set_policy(Policy* policy);
|
||||
*/
|
||||
/**
|
||||
Returns the policy that will be used to generate the simulation at the next instant.
|
||||
\return the policy that will be used to generate the simulation at the next instant.
|
||||
*/
|
||||
Policy* get_policy();
|
||||
Policy& get_policy();
|
||||
|
||||
|
||||
private:
|
||||
Scheduler(int); //private constructor. The parameter is discarded
|
||||
static Scheduler _instance;
|
||||
Scheduler(); //private constructor.
|
||||
static Scheduler* _instance;
|
||||
SchedulableList _ready_queue;
|
||||
Policy* _policy;
|
||||
PolicyManager& _policy_manager;
|
||||
};
|
||||
|
||||
}//~ namespace sgpem
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue