gdunlap/sched-sim.hg

changeset 7:e274ac3f81ff

c01: Allow wake to preempt running processes
author George Dunlap <gdunlap@xensource.com>
date Tue Oct 20 18:00:17 2009 +0100 (2009-10-20)
parents 403bd7680df6
children 92a58ca1e356
files sched_credit01.c
line diff
     1.1 --- a/sched_credit01.c	Mon Oct 19 20:15:18 2009 +0100
     1.2 +++ b/sched_credit01.c	Tue Oct 20 18:00:17 2009 +0100
     1.3 @@ -164,17 +164,44 @@ static void sched_credit_wake(int time, 
     1.4  
     1.5      runq_insert(svm);
     1.6  
     1.7 -    /* Never preempt on wake; only kick idle processors */
     1.8 -    if ( P.idle > 0 )
     1.9 +    /* Scan for either:
    1.10 +     * + an idle cpu to wake up, or
    1.11 +     * + if there are cpus with lower credits, the lowest one
    1.12 +     */
    1.13      {
    1.14 -        int i;
    1.15 +        int i, ipid=-1, lowest = svm->credit;
    1.16 +        
    1.17  
    1.18          for ( i=0; i<P.count; i++ )
    1.19 +        {
    1.20              if ( P.pcpus[i].idle )
    1.21 +            {
    1.22 +                printf(" %s: p%d idle, waking\n", __func__, i);
    1.23 +                ipid=i;
    1.24                  break;
    1.25 +            }
    1.26 +            else if ( P.pcpus[i].current )
    1.27 +            {
    1.28 +                struct vm* ovm = P.pcpus[i].current;
    1.29 +                int ovid = ovm->vid;
    1.30 +                struct sched_vm *osvm = sched_priv.vms + ovid;
    1.31  
    1.32 -        printf(" %s: waking p%d\n", __func__, i);
    1.33 -        sim_sched_timer(0, i);
    1.34 +                /* Update credits of currently running VM */
    1.35 +                burn_credit(osvm, time);
    1.36 +
    1.37 +                if ( osvm->credit < lowest )
    1.38 +                {
    1.39 +                    ipid = i;
    1.40 +                    lowest = osvm->credit;
    1.41 +                }
    1.42 +            }
    1.43 +            
    1.44 +        }
    1.45 +
    1.46 +        if ( ipid >= 0 )
    1.47 +            sim_sched_timer(0, ipid);
    1.48 +        else
    1.49 +            dump_credit(time, svm);
    1.50      }
    1.51  }
    1.52