- 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:
elvez 2006-07-23 22:27:33 +00:00
parent f26b80f76b
commit 6a88e3d85e
13 changed files with 167 additions and 23 deletions

View File

@ -164,6 +164,7 @@ src_backend_libbackend_la_SOURCES = \
src/backend/invalid_plugin_exception.cc \
src/backend/key_file.cc \
src/backend/module.cc \
src/backend/null_policy_exception.cc \
src/backend/plugin_manager.cc \
src/backend/policies_gatekeeper.cc \
src/backend/policy.cc \
@ -199,6 +200,7 @@ pkginclude_HEADERS += \
src/backend/invalid_plugin_exception.hh \
src/backend/key_file.hh \
src/backend/module.hh \
src/backend/null_policy_exception.hh \
src/backend/plugin.hh \
src/backend/plugin_manager.hh \
src/backend/policies_gatekeeper.hh \

View File

@ -176,7 +176,9 @@ PythonPolicy::wait_unlock() const throw(UserInterruptException)
{
Py_UNBLOCK_THREADS;
usleep(WAIT_FOR); // hack'a'ton! magggggiccc nummmbeeerrrrrs!!
cout << "got here..." << endl;
Py_BLOCK_THREADS;
cout << "wow I also got here!" << endl;
PyObject* retval = PyObject_CallMethod(_adapter, "mutex_test_lock", NULL);
assert(retval);

View File

@ -33,7 +33,7 @@ using namespace memory;
using Glib::usleep;
ConcreteSimulation::ConcreteSimulation() :
_state(state_paused), _mode(true), _timer_interval(1000), _policy(NULL)
_state(state_stopped), _mode(true), _timer_interval(1000), _policy(NULL)
{}
void
@ -73,7 +73,7 @@ ConcreteSimulation::stop()
}
void
ConcreteSimulation::run() throw(UserInterruptException)
ConcreteSimulation::run() throw(UserInterruptException, NullPolicyException)
{
switch(_state)
{
@ -117,7 +117,12 @@ ConcreteSimulation::run() throw(UserInterruptException)
try
{
assert(get_policy() != NULL);
if(get_policy() == NULL)
{
stop();
throw NullPolicyException("no policy selected");
}
//step forward
Scheduler::get_instance().step_forward(_history, *get_policy());

View File

@ -33,7 +33,7 @@ namespace sgpem
public:
ConcreteSimulation();
void run() throw(UserInterruptException);
void run() throw(UserInterruptException, NullPolicyException);
void pause();

View File

@ -49,8 +49,9 @@ DynamicThread::DynamicThread(StaticThread* core, DynamicProcess* parent)
DynamicThread::DynamicThread(const DynamicThread &other, DynamicProcess* parent) :
Schedulable(), DynamicSchedulable(other), Thread(),
_state(other._state), _parent(parent), _ran_for(other._ran_for),
_last_acquisition(other._last_acquisition), _last_release(other._last_release)
_core(other._core), _state(other._state), _parent(parent),
_ran_for(other._ran_for), _last_acquisition(other._last_acquisition),
_last_release(other._last_release)
{
typedef vector<DynamicRequest*>::const_iterator ReqIt;

View File

@ -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() {}

View File

@ -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

View File

@ -57,6 +57,13 @@ ReadyQueue::get_item_at(position 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
ReadyQueue::append(Thread& thread)

View File

@ -40,6 +40,7 @@ namespace sgpem
void swap(position a, position b) throw (std::out_of_range);
size_t size() const;
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);
private:

View File

@ -32,6 +32,7 @@ namespace sgpem
#include "singleton.hh"
#include "user_interrupt_exception.hh"
#include "null_policy_exception.hh"
#include <vector>
namespace sgpem
@ -76,7 +77,7 @@ namespace sgpem
Advances the simulation by one or more steps, depending on the
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.

View File

@ -23,10 +23,14 @@
#include "backend/global_preferences.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 "io_manager.hh"
#include "gui_builder.hh"
#include "parse_opts.hh"
#
#include <glibmm/optioncontext.h>
#include <gtkmm/main.h>
@ -35,7 +39,7 @@
#include <iostream>
using namespace sgpem;
using namespace std;
void
parse_options(int argc, char** argv)
@ -110,7 +114,16 @@ parse_options(int argc, char** argv)
// Now that GlobalPreferences has been initialized properly,
// 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)
{

View File

@ -89,10 +89,13 @@ namespace sgpem
}
TextSimulation::TextSimulation()
{
}
TextSimulation::~TextSimulation()
{}
{
}
/**
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;
}
else if(arguments.size() > num)
p_stderr(_("\nWARNING: some arguments will be ignored"));
p_stderr(_("\nWARNING: some arguments will be ignored\n"));
return true;
}
@ -187,10 +190,12 @@ template <typename T>
void
TextSimulation::get_parameter(CommandParameter<T>& parameter)
{
bool correct = true;
bool correct;
do
{
correct = true;
ostringstream buf;
buf << "\n";
@ -333,6 +338,9 @@ TextSimulation::on_run(const Tokens& arguments)
{
check_arguments_num(arguments, 0);
// Listen for updates only during scheduling
Simulation::get_instance().get_history().attach(*this);
try
{
Simulation::get_instance().run();
@ -343,6 +351,14 @@ TextSimulation::on_run(const Tokens& arguments)
p_stderr(e.what());
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
@ -920,9 +936,9 @@ TextSimulation::on_show_cpu_policies(const Tokens& arguments)
oss << "\t" << (*it)->get_description() << endl;
p_stdout(oss.str());
}
++index;
}
}
}
void
@ -944,7 +960,10 @@ TextSimulation::on_add(const Tokens& arguments)
}
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
Tokens args = arguments;
@ -1034,7 +1053,7 @@ TextSimulation::on_add_thread(const Tokens& arguments)
}
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> base_priority(_("base priority"), 0, INT_MAX, false, 0);
@ -1209,10 +1228,9 @@ TextSimulation::on_remove_resource(const Tokens& arguments)
ustring resource = arguments[0];
const Environment& env = Simulation::get_instance().get_history().get_environment_at(0);
const Environment::Processes& processes = env.get_processes();
//const Environment& env = Simulation::get_instance().get_history().get_environment_at(0);
ConcreteHistory::resource_key_t rid;
History::resource_key_t rid;
try
{
@ -1795,8 +1813,22 @@ TextSimulation::parse_command(TextSimulation& sim, const ustring& str)
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();
// int when, arr;
// ustring temp;

View File

@ -29,6 +29,7 @@
#include "templates/smartp.hh"
//#include "backend/policy_parameters.hh"
#include "backend/string_utils.hh"
#include "backend/history_observer.hh"
#include "smartp.hh"
@ -55,9 +56,10 @@ namespace sgpem
Any object returned after the call to Simulation will be returned to the output
devices(s) in a human-readable format.
*/
class SG_DLLEXPORT TextSimulation : public sigc::trackable
class SG_DLLEXPORT TextSimulation : public HistoryObserver
{
public:
TextSimulation();
~TextSimulation();
/**
@ -120,13 +122,13 @@ namespace sgpem
*/
void add_io_device(memory::smart_ptr<IOManager>);
private:
/**
Prints the actual state of the simulation, with emphasis on the current
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);
template <typename Container>
void show(const Container& entities);