gdunlap/sched-sim.hg

changeset 3:d957708efa86

Fix some simulator bugs, mostly dealing with events happening at the same time
author George Dunlap <gdunlap@xensource.com>
date Mon Oct 19 20:11:33 2009 +0100 (2009-10-19)
parents 1d7310217c5a
children f7c1a67cf976
files simulator.c
line diff
     1.1 --- a/simulator.c	Wed Oct 14 16:12:26 2009 +0100
     1.2 +++ b/simulator.c	Mon Oct 19 20:11:33 2009 +0100
     1.3 @@ -171,8 +171,8 @@ void vm_block(int now, struct vm *v)
     1.4  {
     1.5      ASSERT(v->e->type == PHASE_RUN);
     1.6      v->time_this_phase += now - v->state_start_time;
     1.7 -    printf("%s: v%d time_this_phase %d\n",
     1.8 -           __func__, v->vid, v->time_this_phase);
     1.9 +    printf("%s: v%d time_this_phase %d (evt %d)\n",
    1.10 +           __func__, v->vid, v->time_this_phase, v->e->time);
    1.11  
    1.12      ASSERT(v->time_this_phase == v->e->time);
    1.13  
    1.14 @@ -205,7 +205,7 @@ void vm_wake(int now, struct vm *v)
    1.15  void vm_run(int now, struct vm *v)
    1.16  {
    1.17      ASSERT(v->e->type == PHASE_RUN);
    1.18 -    ASSERT(v->time_this_phase < v->e->time);
    1.19 +    ASSERT(v->time_this_phase <= v->e->time);
    1.20  
    1.21      sim_insert_event(now + v->e->time - v->time_this_phase, EVT_BLOCK, v->vid, 0);
    1.22      v->state_start_time = now;
    1.23 @@ -217,15 +217,16 @@ void vm_preempt(int now, struct vm *v)
    1.24  {
    1.25      struct event* evt;
    1.26  
    1.27 +    v->time_this_phase += now - v->state_start_time;
    1.28 +    printf("%s: v%d time_this_phase %d (evt %d)\n",
    1.29 +           __func__, v->vid, v->time_this_phase, v->e->time);
    1.30 +
    1.31 +    ASSERT( v->time_this_phase <= v->e->time );
    1.32 +
    1.33 +    /* Only remove block event if we still have more runtime left */
    1.34      if ( ( evt = sim_remove_event(EVT_BLOCK, v->vid) ) )
    1.35          free(evt);
    1.36  
    1.37 -    v->time_this_phase += now - v->state_start_time;
    1.38 -    printf("%s: v%d time_this_phase %d\n",
    1.39 -           __func__, v->vid, v->time_this_phase);
    1.40 -
    1.41 -    ASSERT(v->time_this_phase < v->e->time);
    1.42 -
    1.43      v->was_preempted = 1;
    1.44  }
    1.45  
    1.46 @@ -233,6 +234,13 @@ void vm_preempt(int now, struct vm *v)
    1.47  /* Callbacks the scheduler may make */
    1.48  void sim_sched_timer(int time, int pid)
    1.49  {
    1.50 +    if ( time < 0 )
    1.51 +    {
    1.52 +        fprintf(stderr, "%s: Time %d < 0!\n",
    1.53 +                __func__, time);
    1.54 +        abort();
    1.55 +    }
    1.56 +
    1.57      if ( pid >= P.count )
    1.58      {
    1.59          fprintf(stderr, "%s: p%d >= P.count %d\n",
    1.60 @@ -386,8 +394,18 @@ void simulate(void)
    1.61                      next->processor = pid;
    1.62                  }
    1.63              }
    1.64 -            else
    1.65 +            else 
    1.66              {
    1.67 +                if ( P.pcpus[pid].idle )
    1.68 +                {
    1.69 +                    fprintf(stderr, "Strange, pid %d already idle!\n",
    1.70 +                            pid);
    1.71 +                    abort();
    1.72 +                }
    1.73 +
    1.74 +                /* If the pcpu is going idle, clear all timers from it */
    1.75 +                sim_remove_event(EVT_TIMER, pid);
    1.76 +
    1.77                  P.pcpus[pid].idle = 1;
    1.78                  P.idle++;
    1.79              }