- fixed a number of bugs
- added dummy_policy written in C++ - the interpreter is now finished (hopefully) git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@366 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
parent
ea70e2f092
commit
4482b98df7
17 changed files with 230 additions and 106 deletions
|
@ -47,41 +47,41 @@ History::get_instance()
|
|||
It can be NULL if time is out of range or if there are no running entities in the associated
|
||||
SchedulableList
|
||||
*/
|
||||
smart_ptr<const SchedulableStatus>
|
||||
smart_ptr<SchedulableStatus>
|
||||
History::get_scheduled_at(int time) const
|
||||
{
|
||||
if (time >= _total_time_elapsed || time < 0) //out of range
|
||||
return smart_ptr<const SchedulableStatus>(NULL);
|
||||
if (time > _total_time_elapsed || time < 0) //out of range
|
||||
return smart_ptr<SchedulableStatus>(NULL);
|
||||
|
||||
//look for a runing entity
|
||||
smart_ptr<const SchedulableList> p = get_simulation_status_at(time);
|
||||
smart_ptr<SchedulableList> p = get_simulation_status_at(time);
|
||||
|
||||
for (uint i = 0; i < p->size(); i++)
|
||||
if (p->get_item_at(i)->get_state() == SchedulableStatus::state_running)
|
||||
return smart_ptr<const SchedulableStatus>(new SchedulableStatus(*(p->get_item_at(i))));
|
||||
return smart_ptr<SchedulableStatus>(new SchedulableStatus(*(p->get_item_at(i))));
|
||||
|
||||
return smart_ptr<const SchedulableStatus>(NULL);
|
||||
return smart_ptr<SchedulableStatus>(NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
Returns a pointer to a copy of the SimulationStatus object relative to this instant or NULL
|
||||
if time is out of range.
|
||||
*/
|
||||
smart_ptr<const SchedulableList>
|
||||
smart_ptr<SchedulableList>
|
||||
History::get_simulation_status_at(int time) const
|
||||
{
|
||||
if (time > _total_time_elapsed || time < 0) //out of range
|
||||
return smart_ptr<const SchedulableList>(NULL);
|
||||
return smart_ptr<SchedulableList>(NULL);
|
||||
|
||||
int trascorso = -1;
|
||||
for(vector<Slice>::const_iterator i=_slices.begin(); i < _slices.end(); i++)
|
||||
if (time <= trascorso + i->get_duration()) //FOUND!!
|
||||
return smart_ptr<const SchedulableList>(new SchedulableList(*i->get_simulation_status()));
|
||||
return smart_ptr<SchedulableList>(new SchedulableList(*i->get_simulation_status()));
|
||||
else //Go on...
|
||||
trascorso += i->get_duration();
|
||||
|
||||
//never reached if all slices are CONTIGUOUS (ans THIS shoul be!!)!!!
|
||||
return smart_ptr<const SchedulableList>(NULL);
|
||||
return smart_ptr<SchedulableList>(NULL);
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -100,7 +100,7 @@ History::enqueue_slice(const SchedulableList& status)
|
|||
if(_slices.size() == 0)
|
||||
{
|
||||
_slices.push_back(Slice(-1, 1, status));
|
||||
_total_time_elapsed = 1;
|
||||
_total_time_elapsed++;
|
||||
notify();
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -51,8 +51,8 @@ namespace sgpem
|
|||
{
|
||||
public:
|
||||
|
||||
memory::smart_ptr<const sgpem::SchedulableStatus> get_scheduled_at(int time) const;
|
||||
memory::smart_ptr<const sgpem::SchedulableList> get_simulation_status_at(int time) const;
|
||||
memory::smart_ptr<sgpem::SchedulableStatus> get_scheduled_at(int time) const;
|
||||
memory::smart_ptr<sgpem::SchedulableList> get_simulation_status_at(int time) const;
|
||||
int get_current_time() const;
|
||||
void enqueue_slice(const sgpem::SchedulableList& status);
|
||||
void truncate_at(int instant);
|
||||
|
|
|
@ -34,7 +34,8 @@ void
|
|||
ObservedSubject::notify()
|
||||
{
|
||||
for(vector<Observer*>::iterator i = _attached.begin(); i < _attached.end(); i++)
|
||||
(*i)->update();
|
||||
(*i)->update();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -34,8 +34,8 @@ Policy::get_id() const
|
|||
}
|
||||
|
||||
|
||||
const PolicyParameters&
|
||||
Policy::get_parameters() const
|
||||
PolicyParameters&
|
||||
Policy::get_parameters()
|
||||
{
|
||||
return _parameters;
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#define POLICY_HH 1
|
||||
|
||||
#include "config.h"
|
||||
#include "gettext.h"
|
||||
|
||||
#include "glibmm/ustring.h"
|
||||
|
||||
|
@ -50,16 +51,15 @@ namespace sgpem
|
|||
virtual int get_time_slice() const = 0;
|
||||
virtual void set_time_slice(const int&) = 0;
|
||||
|
||||
const PolicyParameters& get_parameters() const;
|
||||
PolicyParameters& get_parameters();
|
||||
|
||||
|
||||
private:
|
||||
protected:
|
||||
PolicyParameters _parameters;
|
||||
int _id;
|
||||
int _id;
|
||||
};
|
||||
|
||||
}//~ namespace sgpem
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -134,7 +134,7 @@ SchedulableList::remove(const uint& position)
|
|||
}
|
||||
|
||||
/**
|
||||
Switches two elements in the queue. Returns FALSE if one of the indexes is out of range.
|
||||
|
||||
*/
|
||||
bool
|
||||
SchedulableList::insert_at(const uint& which, const uint& where)
|
||||
|
|
|
@ -75,29 +75,46 @@ Scheduler::get_policy()
|
|||
void
|
||||
Scheduler::step_forward()
|
||||
{
|
||||
|
||||
History& h = History::get_instance();
|
||||
//******************
|
||||
//check for arrivals and prepare the queue
|
||||
//******************
|
||||
smart_ptr<const SchedulableList> initial = h.get_simulation_status_at(h.get_current_time());
|
||||
smart_ptr<SchedulableList> 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<const SchedulableStatus> running_ptr = h.get_scheduled_at(h.get_current_time());
|
||||
smart_ptr<SchedulableStatus> 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() == SchedulableStatus::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() == SchedulableStatus::state_ready
|
||||
if (initial->get_item_at(i)->get_state() == SchedulableStatus::state_future
|
||||
&& (int)initial->get_item_at(i)->get_schedulable()->get_arrival_time() == h.get_current_time())
|
||||
{
|
||||
_ready_queue.add_at_bottom(*initial->get_item_at(i));
|
||||
|
||||
//pops the running schedulable only if the policy is not preemptive
|
||||
//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(SchedulableStatus::state_ready);
|
||||
initial->get_item_at(i)->set_state(SchedulableStatus::state_ready);
|
||||
|
||||
// Sort the queue
|
||||
_policy->sort_queue(event_schedulable_arrival);
|
||||
|
||||
|
@ -106,22 +123,27 @@ Scheduler::step_forward()
|
|||
_ready_queue.add_at_top(*running_ptr);
|
||||
}
|
||||
|
||||
|
||||
//****************
|
||||
// Check for termination
|
||||
//****************
|
||||
|
||||
if (running_ptr && running_ptr->get_cpu_time_left() == 0)
|
||||
{
|
||||
//there was a running schedulable and it's terminated. Remove it!
|
||||
//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(SchedulableStatus::state_terminated);
|
||||
break;
|
||||
}
|
||||
//cout << "\nTERMINATO!!";
|
||||
running_ptr = NULL;
|
||||
|
||||
//IF _ready_queue.size() == 0 sort_queue(...) is called but has no effect!!
|
||||
_policy->sort_queue(event_schedulable_termination);
|
||||
//IF _ready_queue.size() == 0 sort_queue(...) is called but has no effect!!
|
||||
_policy->sort_queue(event_schedulable_termination);
|
||||
}
|
||||
|
||||
//*****************
|
||||
|
@ -134,30 +156,31 @@ Scheduler::step_forward()
|
|||
// Create the final list of schedulable
|
||||
//******************
|
||||
|
||||
SchedulableList final = _ready_queue;
|
||||
|
||||
if (final.size() != 0)
|
||||
//the firs element IS the running one (if != *running_ptr then there is a CONTEXT SWICH)
|
||||
final.get_item_at(0)->set_state(SchedulableStatus::state_running);
|
||||
|
||||
if (_ready_queue.size() != 0 && (_ready_queue.get_item_at(0)->get_state() == SchedulableStatus::state_ready
|
||||
|| _ready_queue.get_item_at(0)->get_state() == SchedulableStatus::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(SchedulableStatus::state_running);
|
||||
_ready_queue.get_item_at(0)->give_cpu_time(1);
|
||||
}
|
||||
|
||||
//all the others are ready
|
||||
for (uint i = 1; i < final.size(); i++)
|
||||
if (final.get_item_at(i)->get_state() == SchedulableStatus::state_running)
|
||||
final.get_item_at(i)->set_state(SchedulableStatus::state_ready);
|
||||
for (uint i = 1; i < _ready_queue.size(); i++)
|
||||
if (_ready_queue.get_item_at(i)->get_state() == SchedulableStatus::state_running)
|
||||
_ready_queue.get_item_at(i)->set_state(SchedulableStatus::state_ready);
|
||||
|
||||
//append blocked, future, terminated and the old running schedulables
|
||||
//append blocked, future, and terminated schedulables
|
||||
for (uint i = 0; i < initial->size(); i++)
|
||||
if(initial->get_item_at(i)->get_state() == SchedulableStatus::state_blocked
|
||||
|| initial->get_item_at(i)->get_state() == SchedulableStatus::state_future
|
||||
|| initial->get_item_at(i)->get_state() == SchedulableStatus::state_terminated
|
||||
|| (initial->get_item_at(i)->get_state() == SchedulableStatus::state_ready
|
||||
&& (int)initial->get_item_at(i)->get_schedulable()->get_arrival_time() != h.get_current_time()) )
|
||||
final.add_at_bottom(*initial->get_item_at(i));
|
||||
|
||||
h.enqueue_slice(final);
|
||||
|| initial->get_item_at(i)->get_state() == SchedulableStatus::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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ namespace sgpem
|
|||
#include "config.h"
|
||||
|
||||
#include <limits>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "observed_subject.hh"
|
||||
#include "history.hh"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue