- Fix book-keeping of thread data fields
- (temp) Add debug printout into text simulation of a thread acquiring time and release time. Will be removed just after scheduler is fixed. git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@975 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
parent
1bc33d37ec
commit
5b7130a9a0
|
@ -18,6 +18,15 @@
|
|||
// along with SGPEMv2; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
|
||||
/* DISCLAIMER FOR THE RAMPANT CODER: */
|
||||
// ----------------------------------------------------\\
|
||||
// ``If you touch this code, your ass is grass, \\
|
||||
// and I'm the lawnmover.'' \\
|
||||
// -- David Cutler \\
|
||||
// ----------------------------------------------------\\
|
||||
|
||||
|
||||
#include "concrete_environment.hh"
|
||||
#include "concrete_history.hh"
|
||||
#include "cpu_policy.hh"
|
||||
|
@ -396,7 +405,7 @@ Scheduler::step_forward(History& history, CPUPolicy& cpu_policy, ResourcePolicy&
|
|||
ConcreteHistory& concrete_history = static_cast<ConcreteHistory&>(history);
|
||||
|
||||
// Use an auto_ptr since we've some exceptions in the coming...
|
||||
auto_ptr<ConcreteEnvironment> new_snapshot(new ConcreteEnvironment(concrete_history.get_last_environment()));
|
||||
auto_ptr<ConcreteEnvironment> new_snapshot(new ConcreteEnvironment(concrete_history.get_environment_at(current_instant)));
|
||||
|
||||
Threads all_threads;
|
||||
DynamicThread* running_thread = NULL;
|
||||
|
@ -429,6 +438,7 @@ Scheduler::step_forward(History& history, CPUPolicy& cpu_policy, ResourcePolicy&
|
|||
if (current.get_total_cpu_time() - current.get_elapsed_time() == 0)
|
||||
{
|
||||
current.set_state(Schedulable::state_terminated);
|
||||
current.set_last_release(current_instant);
|
||||
terminate_all_requests_of(current, *new_snapshot);
|
||||
}
|
||||
|
||||
|
@ -497,7 +507,9 @@ Scheduler::step_forward(History& history, CPUPolicy& cpu_policy, ResourcePolicy&
|
|||
time_slice == current_instant - running_thread->get_last_acquisition()) )
|
||||
{
|
||||
running_thread->set_state(Schedulable::state_ready);
|
||||
running_thread->set_last_release(current_instant);
|
||||
// We don't set the last_release parameter here. If necessary,
|
||||
// we'll do that below, when selecting a new running thread,
|
||||
// if it's different from the previous one.
|
||||
}
|
||||
|
||||
|
||||
|
@ -532,17 +544,14 @@ Scheduler::step_forward(History& history, CPUPolicy& cpu_policy, ResourcePolicy&
|
|||
{
|
||||
// Else, it's time to see if the first candidate can run
|
||||
DynamicThread& candidate = (DynamicThread&) _ready_queue->get_item_at(0);
|
||||
candidate.set_last_acquisition(current_instant);
|
||||
// Even if it can run, we anyhow sets its release time to now, because
|
||||
// it means its release time is *at least* the current_instant. This
|
||||
// is needed for RR policies.
|
||||
candidate.set_last_release(current_instant);
|
||||
|
||||
// If a thread has been created with duration "0" (silly, but possible);
|
||||
// if you think it's safe, you can change this condition with an assert
|
||||
// and delete the body of the ``if''.
|
||||
if(candidate.get_total_cpu_time() - candidate.get_elapsed_time() == 0)
|
||||
{
|
||||
candidate.set_last_acquisition(current_instant);
|
||||
candidate.set_last_release(current_instant);
|
||||
candidate.set_state(Schedulable::state_terminated);
|
||||
// Put every request of this thread to state_exhausted
|
||||
terminate_all_requests_of(candidate, *new_snapshot);
|
||||
|
@ -559,6 +568,7 @@ Scheduler::step_forward(History& history, CPUPolicy& cpu_policy, ResourcePolicy&
|
|||
we_ve_got_a_winner /*!hurrah!*/ = true;
|
||||
else // if blocked, we've to remove it from the ready queue
|
||||
{
|
||||
candidate.set_last_acquisition(current_instant);
|
||||
_ready_queue->erase_first();
|
||||
alive_threads--;
|
||||
}
|
||||
|
@ -572,6 +582,16 @@ Scheduler::step_forward(History& history, CPUPolicy& cpu_policy, ResourcePolicy&
|
|||
// Fix fields of running thread
|
||||
DynamicThread& new_running = (DynamicThread&) _ready_queue->get_item_at(0);
|
||||
new_running.set_state(Schedulable::state_running);
|
||||
|
||||
// If the new running is different from the old one,
|
||||
// remember to release our old pal, and to acquire our
|
||||
// new runner.
|
||||
if(&new_running != running_thread)
|
||||
{
|
||||
if(running_thread != NULL)
|
||||
running_thread->set_last_release(current_instant);
|
||||
new_running.set_last_acquisition(current_instant);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1782,8 +1782,13 @@ TextSimulation::update(const Simulation& changed_simulation)
|
|||
oss << setw(fill1) << t.get_state();
|
||||
oss << setw(fill1) << t.get_arrival_time();
|
||||
oss << setw(fill1) << t.get_total_cpu_time();
|
||||
oss << setw(fill1) << t.get_elapsed_time();
|
||||
oss << setw(fill1) << t.get_elapsed_time();
|
||||
oss << setw(fill1) << t.get_current_priority();
|
||||
|
||||
// FIXME: temporary debug code. Remove me when done.
|
||||
oss << setw(fill1 / 2) << t.get_last_acquisition();
|
||||
oss << setw(fill1 / 2) << t.get_last_release();
|
||||
|
||||
oss << endl;
|
||||
|
||||
p_stdout(oss.str());
|
||||
|
|
Loading…
Reference in New Issue