- Fix compilation of libbackend.so

- Erased Scheduler::step_forward(): reimplementing from
scratch


git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@701 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
tchernobog 2006-07-03 20:55:19 +00:00
parent e2fc34f16b
commit 94f7c1d127
11 changed files with 45 additions and 167 deletions

View File

@ -169,7 +169,6 @@ src_backend_libbackend_la_SOURCES = \
src/backend/resource.cc \ src/backend/resource.cc \
src/backend/schedulable.cc \ src/backend/schedulable.cc \
src/backend/scheduler.cc \ src/backend/scheduler.cc \
src/backend/slice.cc \
src/backend/static_process.cc \ src/backend/static_process.cc \
src/backend/static_request.cc \ src/backend/static_request.cc \
src/backend/static_resource.cc \ src/backend/static_resource.cc \

View File

@ -360,9 +360,8 @@ ConcreteHistory::add_subrequest(Request& request,
reset(false); reset(false);
DynamicRequest& dyn_request = dynamic_cast<DynamicRequest&>(request); DynamicRequest& dyn_request = dynamic_cast<DynamicRequest&>(request);
StaticRequest& request_core = dyn_request.get_core();
StaticSubRequest* core = new StaticSubRequest(&request_core, resource_key, duration, places); StaticSubRequest* core = new StaticSubRequest(resource_key, duration, places);
DynamicSubRequest* subreq = new DynamicSubRequest(core, &dyn_request); DynamicSubRequest* subreq = new DynamicSubRequest(core, &dyn_request);
dyn_request.get_subrequests().push_back(subreq); dyn_request.get_subrequests().push_back(subreq);

View File

@ -56,157 +56,37 @@ Scheduler::get_ready_queue()
void void
Scheduler::reset_status() Scheduler::reset_status()
{ {
_ready_queue.clear(); // DEPRECATED (?)
History::get_instance().truncate_at(0);
// restore the policy
} }
/* void
Scheduler::set_policy(Policy* p)
{
_policy_manager.set_policy(p);
}*/
Policy& Policy&
Scheduler::get_policy() Scheduler::get_policy()
{ {
//return _policy_manager.get_policy(); // FIXME : fixme.
return *PoliciesGatekeeper::get_instance().get_current_policy(&History::get_instance()); // return *PoliciesGatekeeper::get_instance().get_current_policy(&History::get_instance());
} }
void void
Scheduler::step_forward() throw(UserInterruptException) Scheduler::step_forward(History& history, Policy& cpu_policy) throw(UserInterruptException)
{ {
try try
{ {
Policy& policy = get_policy();
History& h = History::get_instance();
//******************
//check for arrivals and prepare the queue
//******************
smart_ptr<ReadyQueue> initial = h.get_simulation_status_at(h.get_current_time());
if (!initial)
{
cout << _("\nNo initial state inserted!!\n");
return;
}
_ready_queue.clear();
//adds running schedulable
smart_ptr<DynamicSchedulable> running_ptr = h.get_scheduled_at(h.get_current_time());
if (running_ptr)
_ready_queue.add_at_top(*running_ptr);
//adds the READY ones
for(uint rea = 0; rea < initial->size(); rea++)
if (initial->get_item_at(rea)->get_state() == DynamicSchedulable::state_ready)
_ready_queue.add_at_bottom(*initial->get_item_at(rea));
//adds each new ready schedulable and sorts the queue
for(uint i = 0; i < initial->size(); i++)
if (initial->get_item_at(i)->get_state() == DynamicSchedulable::state_future
&& (int)initial->get_item_at(i)->get_schedulable()->get_arrival_time() == h.get_current_time())
{
//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)
_ready_queue.remove(0);
//adds the NEW one
_ready_queue.add_at_bottom(*initial->get_item_at(i));
_ready_queue.get_item_at(_ready_queue.size() - 1)->set_state(DynamicSchedulable::state_ready);
initial->get_item_at(i)->set_state(DynamicSchedulable::state_ready);
// Sort the queue
policy.sort_queue();
//restore the old running schedulable
if (policy.is_pre_emptive() == false && running_ptr)
_ready_queue.add_at_top(*running_ptr);
}
//****************
// Check for termination
//****************
if (running_ptr && running_ptr->get_cpu_time_left() == 0)
{
//there is a running schedulable and it's terminated. Append at the bottom with the state TERMINATED
for(uint i = 0; i < _ready_queue.size(); i++)
if (*_ready_queue.get_item_at(i) == *running_ptr)
{
_ready_queue.add_at_bottom(*_ready_queue.get_item_at(i));
_ready_queue.remove(i);
_ready_queue.get_item_at(_ready_queue.size() - 1)->set_state(DynamicSchedulable::state_terminated);
break;
}
//cout << "\nTERMINATO!!";
running_ptr = NULL;
//IF _ready_queue.size() == 0 sort_queue(...) is called but has no effect!!
policy.sort_queue();
}
//*****************
// Check for time slice
//*****************
if (policy.get_time_slice() != numeric_limits<int>::max()) //time-slice
policy.sort_queue();
//******************
// Create the final list of schedulable
//******************
if (_ready_queue.size() != 0 && (_ready_queue.get_item_at(0)->get_state() == DynamicSchedulable::state_ready
|| _ready_queue.get_item_at(0)->get_state() == DynamicSchedulable::state_running))
{
//the first ready element IS the running one (if != *running_ptr then there is a CONTEXT SWICH)
_ready_queue.get_item_at(0)->set_state(DynamicSchedulable::state_running);
_ready_queue.get_item_at(0)->give_cpu_time(1);
}
//all the others are ready
for (uint i = 1; i < _ready_queue.size(); i++)
if (_ready_queue.get_item_at(i)->get_state() == DynamicSchedulable::state_running)
_ready_queue.get_item_at(i)->set_state(DynamicSchedulable::state_ready);
//append blocked, future, and terminated schedulables
for (uint i = 0; i < initial->size(); i++)
if(initial->get_item_at(i)->get_state() == DynamicSchedulable::state_blocked
|| initial->get_item_at(i)->get_state() == DynamicSchedulable::state_future
|| initial->get_item_at(i)->get_state() == DynamicSchedulable::state_terminated)
_ready_queue.add_at_bottom(*initial->get_item_at(i));
cout << "\n";
/* for (uint i = 0; i < _ready_queue.size(); i++)
cout << " " << _ready_queue.get_item_at(i)->get_schedulable()->get_name()
<<"_" << _ready_queue.get_item_at(i)->get_state();
*/
h.enqueue_slice(_ready_queue);
} }
catch( UserInterruptException e ) catch( UserInterruptException e )
{ {
_policy_manager.init(); _policy_manager.init();
throw;
//TODO Do we need to perform some cleanup operation here? //TODO Do we need to perform some cleanup operation here?
// Do we need to update something? // Do we need to update something?
// https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1165761&group_id=5470 // Going up unwinding the stack, tell:
// maybe it's that??? oh, damn.
// or maybe not. see http://www.python.org/doc/2.4.2/api/initialization.html
// Tell:
// - the user that the policy sucks // - the user that the policy sucks
// - SimulationController that everything stopped // - SimulationController that everything stopped
throw;
} }
} }

View File

@ -33,6 +33,7 @@ namespace sgpem
#include <iostream> #include <iostream>
#include "history.hh" #include "history.hh"
#include "policy.hh"
#include "ready_queue.hh" #include "ready_queue.hh"
#include "user_interrupt_exception.hh" #include "user_interrupt_exception.hh"
@ -42,6 +43,7 @@ namespace sgpem
namespace sgpem namespace sgpem
{ {
class Scheduler; class Scheduler;
/** \brief Manages the DynamicSchedulable objects, implementing a given policy. /** \brief Manages the DynamicSchedulable objects, implementing a given policy.
@ -69,12 +71,12 @@ namespace sgpem
Resets the simulation to the initial state. Resets the simulation to the initial state.
*/ */
void reset_status(); void reset_status();
/** /**
Generates a new ReadyQueue representing the status of the processes Generates a new ReadyQueue representing the status of the processes
at the simulation instant next to the current one, and extends the History by at the simulation instant next to the current one, and extends the History by
one instant with it. one instant with it.
*/ */
void step_forward() throw(UserInterruptException); void step_forward(History& history, Policy& cpu_policy) throw(UserInterruptException);
/** /**
Sets the policy that will be used to generate the simulation at the next instant. 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. \param policy the policy that will be used to generate the simulation at the next instant.

View File

@ -41,7 +41,7 @@ StaticProcess::get_arrival_time() const
unsigned int unsigned int
StaticProcess::get_total_cpu_time() const StaticProcess::get_total_cpu_time() const
{ {
tyepdef std::vector<Thread*>::iterator ThreadIterator; typedef std::vector<StaticThread*>::const_iterator ThreadIterator;
unsigned int result = 0; unsigned int result = 0;
for(ThreadIterator it = _threads.begin(); it != _threads.end(); it++) for(ThreadIterator it = _threads.begin(); it != _threads.end(); it++)

View File

@ -32,6 +32,7 @@
namespace sgpem namespace sgpem
{ {
class StaticProcess; class StaticProcess;
class StaticThread;
/** \brief Represents a program in execution. /** \brief Represents a program in execution.

View File

@ -21,6 +21,8 @@
#ifndef STATIC_REQUEST_HH #ifndef STATIC_REQUEST_HH
#define STATIC_REQUEST_HH 1 #define STATIC_REQUEST_HH 1
#include "static_thread.hh"
#include "config.h" #include "config.h"
#include "glibmm/ustring.h" #include "glibmm/ustring.h"
@ -28,12 +30,12 @@ namespace sgpem
{ {
class StaticRequest; class StaticRequest;
class SerializeVisitor; class SerializeVisitor;
class StaticThread;
class SG_DLLLOCAL StaticRequest class SG_DLLLOCAL StaticRequest
{ {
public: public:
StaticRequest(StaticThread* thread, unsigned int instant); StaticRequest(StaticThread* thread, unsigned int instant);
~StaticRequest();
unsigned int get_instant() const; unsigned int get_instant() const;
StaticThread& get_thread(); StaticThread& get_thread();

View File

@ -18,6 +18,7 @@
// along with SGPEMv2; if not, write to the Free Software // along with SGPEMv2; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "static_request.hh"
#include "static_sub_request.hh" #include "static_sub_request.hh"
#include <algorithm> #include <algorithm>
@ -26,37 +27,33 @@
using namespace sgpem; using namespace sgpem;
StaticSubRequest::StaticSubRequest(StaticRequest* req, StaticSubRequest::StaticSubRequest(resource_key_t resource_key,
resource_key_t resource_key,
unsigned int length, unsigned int length,
unsigned int places) : unsigned int places) :
_static_request(req), _resource_key(resource_key), _resource_key(resource_key),
_length(length), _places(places) _length(length), _places(places)
{ {
assert(req != NULL && resource != NULL); //A static request doesn't keep track of its static subrequests
req->get_subrequests().push_back(this); //at least for now.
//req->get_subrequests().push_back(this);
} }
StaticSubRequest::~StaticSubRequest() StaticSubRequest::~StaticSubRequest()
{ {
typedef std::vector<StaticSubRequest*> SubRequests; // See comment in constructor.
SubRequests siblings& = _static_request.get_subrequests();
siblings.erase(find(siblings.begin(), siblings.end(), this)); // typedef std::vector<StaticSubRequest*> SubRequests;
// SubRequests siblings& = _static_request.get_subrequests();
// siblings.erase(find(siblings.begin(), siblings.end(), this));
} }
SubRequest::get_resource_key SubRequest::resource_key_t
StaticSubRequest::get_resource_key() const StaticSubRequest::get_resource_key() const
{ {
return _resource_key; return _resource_key;
} }
StaticRequest&
StaticSubRequest::get_static_request()
{
return *_static_request;
}
unsigned int unsigned int
StaticSubRequest::get_places() const StaticSubRequest::get_places() const
{ {
@ -68,4 +65,3 @@ StaticSubRequest::get_length() const
{ {
return _length; return _length;
} }

View File

@ -34,28 +34,24 @@ namespace sgpem
class SG_DLLLOCAL StaticSubRequest class SG_DLLLOCAL StaticSubRequest
{ {
public: public:
typedef SubRequest::resource_key_t resource_key_t; typedef SubRequest::resource_key_t resource_key_t;
StaticSubRequest(StaticRequest* req, StaticSubRequest(resource_key_t resource_key,
resource_key_t resource_key,
unsigned int length, unsigned int length,
unsigned int places = 1); unsigned int places = 1);
virtual ~StaticSubRequest(); ~StaticSubRequest();
resource_key_t get_resource_key() const; resource_key_t get_resource_key() const;
StaticRequest& get_request();
unsigned int get_places() const; unsigned int get_places() const;
unsigned int get_length() const; unsigned int get_length() const;
private: private:
StaticSubRequest(const StaticSubRequest&); StaticSubRequest(const StaticSubRequest&);
StaticSubRequest& operator=(const StaticSubRequest&); StaticSubRequest& operator=(const StaticSubRequest&);
StaticRequest* _static_request;
resource_key_t _resource_key; resource_key_t _resource_key;
unsigned int _length; unsigned int _length;
unsigned int _places; unsigned int _places;

View File

@ -44,8 +44,8 @@ StaticThread::StaticThread(const Glib::ustring& name,
StaticThread::~StaticThread() StaticThread::~StaticThread()
{ {
typedef std::vector<StaticThread*> Threads; typedef std::vector<StaticThread*> Threads;
Threads siblings& = _process.get_threads(); Threads& siblings = _process->get_threads();
siblings.erase(find(siblings.begin(), siblings.end(), this); siblings.erase(find(siblings.begin(), siblings.end(), this));
} }
@ -70,5 +70,5 @@ StaticThread::get_process()
std::vector<StaticRequest*>& std::vector<StaticRequest*>&
StaticThread::get_requests() StaticThread::get_requests()
{ {
return _requests; return _static_requests;
} }

View File

@ -21,17 +21,20 @@
#ifndef STATIC_THREAD_HH #ifndef STATIC_THREAD_HH
#define STATIC_THREAD_HH 1 #define STATIC_THREAD_HH 1
#include "static_process.hh"
#include "static_schedulable.hh"
#include "config.h" #include "config.h"
#include "gettext.h" #include "gettext.h"
#include "glibmm/ustring.h"
#include <vector>
#include "static_schedulable.hh" #include <glibmm/ustring.h>
#include <vector>
namespace sgpem namespace sgpem
{ {
class StaticThread;
class StaticProcess; class StaticProcess;
class StaticThread;
class StaticRequest; class StaticRequest;
class SG_DLLLOCAL StaticThread : public StaticSchedulable class SG_DLLLOCAL StaticThread : public StaticSchedulable