- Added NullPolicyException to scheduler
- Started code for printing the state of the scheduling - Fixed a bug in the copy constructor of DynamicThread git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@794 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
parent
f26b80f76b
commit
6a88e3d85e
|
@ -164,6 +164,7 @@ src_backend_libbackend_la_SOURCES = \
|
||||||
src/backend/invalid_plugin_exception.cc \
|
src/backend/invalid_plugin_exception.cc \
|
||||||
src/backend/key_file.cc \
|
src/backend/key_file.cc \
|
||||||
src/backend/module.cc \
|
src/backend/module.cc \
|
||||||
|
src/backend/null_policy_exception.cc \
|
||||||
src/backend/plugin_manager.cc \
|
src/backend/plugin_manager.cc \
|
||||||
src/backend/policies_gatekeeper.cc \
|
src/backend/policies_gatekeeper.cc \
|
||||||
src/backend/policy.cc \
|
src/backend/policy.cc \
|
||||||
|
@ -199,6 +200,7 @@ pkginclude_HEADERS += \
|
||||||
src/backend/invalid_plugin_exception.hh \
|
src/backend/invalid_plugin_exception.hh \
|
||||||
src/backend/key_file.hh \
|
src/backend/key_file.hh \
|
||||||
src/backend/module.hh \
|
src/backend/module.hh \
|
||||||
|
src/backend/null_policy_exception.hh \
|
||||||
src/backend/plugin.hh \
|
src/backend/plugin.hh \
|
||||||
src/backend/plugin_manager.hh \
|
src/backend/plugin_manager.hh \
|
||||||
src/backend/policies_gatekeeper.hh \
|
src/backend/policies_gatekeeper.hh \
|
||||||
|
|
|
@ -176,7 +176,9 @@ PythonPolicy::wait_unlock() const throw(UserInterruptException)
|
||||||
{
|
{
|
||||||
Py_UNBLOCK_THREADS;
|
Py_UNBLOCK_THREADS;
|
||||||
usleep(WAIT_FOR); // hack'a'ton! magggggiccc nummmbeeerrrrrs!!
|
usleep(WAIT_FOR); // hack'a'ton! magggggiccc nummmbeeerrrrrs!!
|
||||||
|
cout << "got here..." << endl;
|
||||||
Py_BLOCK_THREADS;
|
Py_BLOCK_THREADS;
|
||||||
|
cout << "wow I also got here!" << endl;
|
||||||
|
|
||||||
PyObject* retval = PyObject_CallMethod(_adapter, "mutex_test_lock", NULL);
|
PyObject* retval = PyObject_CallMethod(_adapter, "mutex_test_lock", NULL);
|
||||||
assert(retval);
|
assert(retval);
|
||||||
|
|
|
@ -33,7 +33,7 @@ using namespace memory;
|
||||||
using Glib::usleep;
|
using Glib::usleep;
|
||||||
|
|
||||||
ConcreteSimulation::ConcreteSimulation() :
|
ConcreteSimulation::ConcreteSimulation() :
|
||||||
_state(state_paused), _mode(true), _timer_interval(1000), _policy(NULL)
|
_state(state_stopped), _mode(true), _timer_interval(1000), _policy(NULL)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -73,7 +73,7 @@ ConcreteSimulation::stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ConcreteSimulation::run() throw(UserInterruptException)
|
ConcreteSimulation::run() throw(UserInterruptException, NullPolicyException)
|
||||||
{
|
{
|
||||||
switch(_state)
|
switch(_state)
|
||||||
{
|
{
|
||||||
|
@ -117,7 +117,12 @@ ConcreteSimulation::run() throw(UserInterruptException)
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
assert(get_policy() != NULL);
|
if(get_policy() == NULL)
|
||||||
|
{
|
||||||
|
stop();
|
||||||
|
throw NullPolicyException("no policy selected");
|
||||||
|
}
|
||||||
|
|
||||||
//step forward
|
//step forward
|
||||||
Scheduler::get_instance().step_forward(_history, *get_policy());
|
Scheduler::get_instance().step_forward(_history, *get_policy());
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ namespace sgpem
|
||||||
public:
|
public:
|
||||||
ConcreteSimulation();
|
ConcreteSimulation();
|
||||||
|
|
||||||
void run() throw(UserInterruptException);
|
void run() throw(UserInterruptException, NullPolicyException);
|
||||||
|
|
||||||
void pause();
|
void pause();
|
||||||
|
|
||||||
|
|
|
@ -49,8 +49,9 @@ DynamicThread::DynamicThread(StaticThread* core, DynamicProcess* parent)
|
||||||
|
|
||||||
DynamicThread::DynamicThread(const DynamicThread &other, DynamicProcess* parent) :
|
DynamicThread::DynamicThread(const DynamicThread &other, DynamicProcess* parent) :
|
||||||
Schedulable(), DynamicSchedulable(other), Thread(),
|
Schedulable(), DynamicSchedulable(other), Thread(),
|
||||||
_state(other._state), _parent(parent), _ran_for(other._ran_for),
|
_core(other._core), _state(other._state), _parent(parent),
|
||||||
_last_acquisition(other._last_acquisition), _last_release(other._last_release)
|
_ran_for(other._ran_for), _last_acquisition(other._last_acquisition),
|
||||||
|
_last_release(other._last_release)
|
||||||
{
|
{
|
||||||
typedef vector<DynamicRequest*>::const_iterator ReqIt;
|
typedef vector<DynamicRequest*>::const_iterator ReqIt;
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
// src/backend/null_policy_exception.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
|
||||||
|
|
||||||
|
// Warning! This exception will be thrown across different libraries.
|
||||||
|
// It could be necessary to do dynamic type-checking when
|
||||||
|
// catching it (with typeinfo).
|
||||||
|
|
||||||
|
#include "null_policy_exception.hh"
|
||||||
|
using namespace sgpem;
|
||||||
|
|
||||||
|
NullPolicyException::NullPolicyException(const char* msg)
|
||||||
|
: std::runtime_error(msg)
|
||||||
|
{}
|
||||||
|
|
||||||
|
NullPolicyException::~NullPolicyException() throw() {}
|
|
@ -0,0 +1,46 @@
|
||||||
|
// src/backend/null_policy_exception.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
|
||||||
|
|
||||||
|
// Warning! This exception will be thrown across different libraries.
|
||||||
|
// It could be necessary to do dynamic type-checking when
|
||||||
|
// catching it (with typeinfo).
|
||||||
|
|
||||||
|
#ifndef NULL_POLICY_EXCEPTION
|
||||||
|
#define NULL_POLICY_EXCEPTION 1
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
namespace sgpem
|
||||||
|
{
|
||||||
|
class NullPolicyException;
|
||||||
|
|
||||||
|
class SG_DLLEXPORT NullPolicyException : public std::runtime_error
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
NullPolicyException(const char* msg = "");
|
||||||
|
virtual ~NullPolicyException() throw ();
|
||||||
|
|
||||||
|
private:
|
||||||
|
};
|
||||||
|
} //~ namespace sgpem
|
||||||
|
|
||||||
|
#endif
|
|
@ -57,6 +57,13 @@ ReadyQueue::get_item_at(position index)
|
||||||
return *_scheds.at(index);
|
return *_scheds.at(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const sgpem::Thread&
|
||||||
|
ReadyQueue::get_item_at(position index) const
|
||||||
|
throw (std::out_of_range)
|
||||||
|
{
|
||||||
|
// Checks index access
|
||||||
|
return *_scheds.at(index);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ReadyQueue::append(Thread& thread)
|
ReadyQueue::append(Thread& thread)
|
||||||
|
|
|
@ -40,6 +40,7 @@ namespace sgpem
|
||||||
void swap(position a, position b) throw (std::out_of_range);
|
void swap(position a, position b) throw (std::out_of_range);
|
||||||
size_t size() const;
|
size_t size() const;
|
||||||
Thread& get_item_at(position index) throw (std::out_of_range);
|
Thread& get_item_at(position index) throw (std::out_of_range);
|
||||||
|
const Thread& get_item_at(position index) const throw (std::out_of_range);
|
||||||
void append(Thread& schedulable);
|
void append(Thread& schedulable);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -32,6 +32,7 @@ namespace sgpem
|
||||||
|
|
||||||
#include "singleton.hh"
|
#include "singleton.hh"
|
||||||
#include "user_interrupt_exception.hh"
|
#include "user_interrupt_exception.hh"
|
||||||
|
#include "null_policy_exception.hh"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace sgpem
|
namespace sgpem
|
||||||
|
@ -76,7 +77,7 @@ namespace sgpem
|
||||||
Advances the simulation by one or more steps, depending on the
|
Advances the simulation by one or more steps, depending on the
|
||||||
actual state and on the value set with set_mode().
|
actual state and on the value set with set_mode().
|
||||||
*/
|
*/
|
||||||
virtual void run() throw(UserInterruptException) = 0;
|
virtual void run() throw(UserInterruptException, NullPolicyException) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Pauses a running simulation.
|
\brief Pauses a running simulation.
|
||||||
|
|
|
@ -23,10 +23,14 @@
|
||||||
|
|
||||||
#include "backend/global_preferences.hh"
|
#include "backend/global_preferences.hh"
|
||||||
#include "backend/plugin_manager.hh"
|
#include "backend/plugin_manager.hh"
|
||||||
|
#include "backend/policy_manager.hh"
|
||||||
|
#include "backend/policies_gatekeeper.hh"
|
||||||
|
#include "backend/module.hh"
|
||||||
#include "text_simulation.hh"
|
#include "text_simulation.hh"
|
||||||
#include "io_manager.hh"
|
#include "io_manager.hh"
|
||||||
#include "gui_builder.hh"
|
#include "gui_builder.hh"
|
||||||
#include "parse_opts.hh"
|
#include "parse_opts.hh"
|
||||||
|
#
|
||||||
|
|
||||||
#include <glibmm/optioncontext.h>
|
#include <glibmm/optioncontext.h>
|
||||||
#include <gtkmm/main.h>
|
#include <gtkmm/main.h>
|
||||||
|
@ -35,7 +39,7 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
using namespace sgpem;
|
using namespace sgpem;
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
void
|
void
|
||||||
parse_options(int argc, char** argv)
|
parse_options(int argc, char** argv)
|
||||||
|
@ -110,7 +114,16 @@ parse_options(int argc, char** argv)
|
||||||
|
|
||||||
// Now that GlobalPreferences has been initialized properly,
|
// Now that GlobalPreferences has been initialized properly,
|
||||||
// initialize plugins, too
|
// initialize plugins, too
|
||||||
PluginManager::get_instance();
|
vector<Module*> modules = PluginManager::get_instance().get_module_list();
|
||||||
|
|
||||||
|
for(vector<Module*>::iterator it = modules.begin(); it != modules.end(); ++it)
|
||||||
|
(*it)->set_enabled(true);
|
||||||
|
|
||||||
|
vector<PolicyManager*> managers = PoliciesGatekeeper::get_instance().get_registered();
|
||||||
|
|
||||||
|
for(vector<PolicyManager*>::iterator it = managers.begin(); it != managers.end(); ++it)
|
||||||
|
(*it)->init();
|
||||||
|
|
||||||
|
|
||||||
if(no_gui_enabled)
|
if(no_gui_enabled)
|
||||||
{
|
{
|
||||||
|
|
|
@ -89,10 +89,13 @@ namespace sgpem
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TextSimulation::TextSimulation()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
TextSimulation::~TextSimulation()
|
TextSimulation::~TextSimulation()
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Adds an IO_device and creates a thread which loops the read-parse-execute process
|
Adds an IO_device and creates a thread which loops the read-parse-execute process
|
||||||
|
@ -120,7 +123,7 @@ TextSimulation::check_arguments_num(const Tokens& arguments, unsigned int num)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else if(arguments.size() > num)
|
else if(arguments.size() > num)
|
||||||
p_stderr(_("\nWARNING: some arguments will be ignored"));
|
p_stderr(_("\nWARNING: some arguments will be ignored\n"));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -187,10 +190,12 @@ template <typename T>
|
||||||
void
|
void
|
||||||
TextSimulation::get_parameter(CommandParameter<T>& parameter)
|
TextSimulation::get_parameter(CommandParameter<T>& parameter)
|
||||||
{
|
{
|
||||||
bool correct = true;
|
bool correct;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
correct = true;
|
||||||
|
|
||||||
ostringstream buf;
|
ostringstream buf;
|
||||||
|
|
||||||
buf << "\n";
|
buf << "\n";
|
||||||
|
@ -333,6 +338,9 @@ TextSimulation::on_run(const Tokens& arguments)
|
||||||
{
|
{
|
||||||
check_arguments_num(arguments, 0);
|
check_arguments_num(arguments, 0);
|
||||||
|
|
||||||
|
// Listen for updates only during scheduling
|
||||||
|
Simulation::get_instance().get_history().attach(*this);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Simulation::get_instance().run();
|
Simulation::get_instance().run();
|
||||||
|
@ -343,6 +351,14 @@ TextSimulation::on_run(const Tokens& arguments)
|
||||||
p_stderr(e.what());
|
p_stderr(e.what());
|
||||||
p_stderr(_("\nSimulation is now stopped"));
|
p_stderr(_("\nSimulation is now stopped"));
|
||||||
}
|
}
|
||||||
|
catch(NullPolicyException e)
|
||||||
|
{
|
||||||
|
p_stderr(_("\nERROR: "));
|
||||||
|
p_stderr(e.what());
|
||||||
|
p_stderr(_("\nSimulation is now stopped"));
|
||||||
|
}
|
||||||
|
|
||||||
|
Simulation::get_instance().get_history().detach(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -920,8 +936,8 @@ TextSimulation::on_show_cpu_policies(const Tokens& arguments)
|
||||||
oss << "\t" << (*it)->get_description() << endl;
|
oss << "\t" << (*it)->get_description() << endl;
|
||||||
|
|
||||||
p_stdout(oss.str());
|
p_stdout(oss.str());
|
||||||
|
++index;
|
||||||
}
|
}
|
||||||
++index;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -944,7 +960,10 @@ TextSimulation::on_add(const Tokens& arguments)
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Simulation::get_instance().get_state() != Simulation::state_stopped)
|
if(Simulation::get_instance().get_state() != Simulation::state_stopped)
|
||||||
p_stderr(_("WARNING: Simulation is not stopped, it will be automatically stopped"));
|
{
|
||||||
|
p_stderr(_("WARNING: Simulation is not stopped, it will be automatically stopped\n"));
|
||||||
|
Simulation::get_instance().stop();
|
||||||
|
}
|
||||||
|
|
||||||
//make a local copy which we'll probably modify
|
//make a local copy which we'll probably modify
|
||||||
Tokens args = arguments;
|
Tokens args = arguments;
|
||||||
|
@ -1034,7 +1053,7 @@ TextSimulation::on_add_thread(const Tokens& arguments)
|
||||||
}
|
}
|
||||||
|
|
||||||
CommandParameter<ustring> name(_("name"), "", "", false, "");
|
CommandParameter<ustring> name(_("name"), "", "", false, "");
|
||||||
CommandParameter<int> cpu_time(_("cpu time"), 0, INT_MAX, true, 0);
|
CommandParameter<int> cpu_time(_("cpu time"), 1, INT_MAX, true, 0);
|
||||||
CommandParameter<int> arrival_time(_("arrival time"), 0, INT_MAX, false, 0);
|
CommandParameter<int> arrival_time(_("arrival time"), 0, INT_MAX, false, 0);
|
||||||
CommandParameter<int> base_priority(_("base priority"), 0, INT_MAX, false, 0);
|
CommandParameter<int> base_priority(_("base priority"), 0, INT_MAX, false, 0);
|
||||||
|
|
||||||
|
@ -1209,10 +1228,9 @@ TextSimulation::on_remove_resource(const Tokens& arguments)
|
||||||
|
|
||||||
ustring resource = arguments[0];
|
ustring resource = arguments[0];
|
||||||
|
|
||||||
const Environment& env = Simulation::get_instance().get_history().get_environment_at(0);
|
//const Environment& env = Simulation::get_instance().get_history().get_environment_at(0);
|
||||||
const Environment::Processes& processes = env.get_processes();
|
|
||||||
|
|
||||||
ConcreteHistory::resource_key_t rid;
|
History::resource_key_t rid;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -1795,8 +1813,22 @@ TextSimulation::parse_command(TextSimulation& sim, const ustring& str)
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TextSimulation::update()
|
TextSimulation::update(const History& changed_history)
|
||||||
{
|
{
|
||||||
|
p_stdout(_("\nqueue: { "));
|
||||||
|
|
||||||
|
const Environment& env = changed_history.get_last_environment();
|
||||||
|
const ReadyQueue& q = env.get_sorted_queue();
|
||||||
|
|
||||||
|
for(unsigned int i = 0; i < q.size(); ++i)
|
||||||
|
{
|
||||||
|
const Thread& t = q.get_item_at(i);
|
||||||
|
|
||||||
|
p_stdout(t.get_name() + " ~ ");
|
||||||
|
}
|
||||||
|
|
||||||
|
p_stdout("}\n");
|
||||||
|
|
||||||
// History& h = History::get_instance();
|
// History& h = History::get_instance();
|
||||||
// int when, arr;
|
// int when, arr;
|
||||||
// ustring temp;
|
// ustring temp;
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
#include "templates/smartp.hh"
|
#include "templates/smartp.hh"
|
||||||
//#include "backend/policy_parameters.hh"
|
//#include "backend/policy_parameters.hh"
|
||||||
#include "backend/string_utils.hh"
|
#include "backend/string_utils.hh"
|
||||||
|
#include "backend/history_observer.hh"
|
||||||
|
|
||||||
#include "smartp.hh"
|
#include "smartp.hh"
|
||||||
|
|
||||||
|
@ -55,9 +56,10 @@ namespace sgpem
|
||||||
Any object returned after the call to Simulation will be returned to the output
|
Any object returned after the call to Simulation will be returned to the output
|
||||||
devices(s) in a human-readable format.
|
devices(s) in a human-readable format.
|
||||||
*/
|
*/
|
||||||
class SG_DLLEXPORT TextSimulation : public sigc::trackable
|
class SG_DLLEXPORT TextSimulation : public HistoryObserver
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
TextSimulation();
|
||||||
~TextSimulation();
|
~TextSimulation();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -120,13 +122,13 @@ namespace sgpem
|
||||||
*/
|
*/
|
||||||
void add_io_device(memory::smart_ptr<IOManager>);
|
void add_io_device(memory::smart_ptr<IOManager>);
|
||||||
|
|
||||||
|
private:
|
||||||
/**
|
/**
|
||||||
Prints the actual state of the simulation, with emphasis on the current
|
Prints the actual state of the simulation, with emphasis on the current
|
||||||
status of the scheduling process (ready queue and running process).
|
status of the scheduling process (ready queue and running process).
|
||||||
*/
|
*/
|
||||||
void update();
|
virtual void update(const History& changed_history);
|
||||||
|
|
||||||
private:
|
|
||||||
bool check_arguments_num(const Tokens& arguments, unsigned int num);
|
bool check_arguments_num(const Tokens& arguments, unsigned int num);
|
||||||
template <typename Container>
|
template <typename Container>
|
||||||
void show(const Container& entities);
|
void show(const Container& entities);
|
||||||
|
|
Loading…
Reference in New Issue