gdunlap/sched-sim.hg

diff sched_credit03.c @ 16:cb624ff1d4fe

Clean up scheduler code to make it easier to see the differences
author George Dunlap <george.dunlap@eu.citrix.com>
date Fri Jul 16 11:55:39 2010 +0100 (2010-07-16)
parents f289f886cbcc
children
line diff
     1.1 --- a/sched_credit03.c	Fri Jul 16 11:15:33 2010 +0100
     1.2 +++ b/sched_credit03.c	Fri Jul 16 11:55:39 2010 +0100
     1.3 @@ -42,6 +42,21 @@ struct {
     1.4      int next_check;
     1.5  } sched_priv;
     1.6  
     1.7 +/*
     1.8 + * + Implement weights (hacky at the moment)
     1.9 + * - Everyone starts at fixed value
    1.10 + * - Burn credit based on variable weight
    1.11 + * - Insert in runq based on credit
    1.12 + * - Reset 
    1.13 + *  - Triggered when someone reaches zero
    1.14 + *  + Clip everyone's credit and add INIT
    1.15 + * - Timeslice
    1.16 + *  - Start with basic timeslice
    1.17 + *  - Don't run for more credit than you have
    1.18 + *  - Only run until your credit would equal next VM in runqueue
    1.19 + *  - Never less than MIN_TIMER
    1.20 + */
    1.21 +
    1.22  static int t2c(int time, struct sched_vm *svm)
    1.23  {
    1.24      return time * sched_priv.max_weight / svm->weight;
    1.25 @@ -65,8 +80,6 @@ static void reset_credit(int time)
    1.26          struct sched_vm *svm = sched_priv.vms + i;
    1.27          int tmax = CREDIT_CLIP;
    1.28  
    1.29 -        //sched_priv.vms[i].credit = 0;
    1.30 -        //sched_priv.vms[i].credit /= (CREDIT_INIT/10);
    1.31          if ( svm->credit > tmax )
    1.32              svm->credit = tmax;
    1.33          svm->credit += CREDIT_INIT;
    1.34 @@ -74,7 +87,7 @@ static void reset_credit(int time)
    1.35  
    1.36          dump_credit(time, svm);
    1.37      }
    1.38 -    /* No need to resort runq, as everyone's credit is now zero */
    1.39 +    /* No need to resort runq, as no one's credit is re-ordered */
    1.40  }
    1.41  
    1.42  static void burn_credit(struct sched_vm *svm, int time)
    1.43 @@ -89,11 +102,18 @@ static void burn_credit(struct sched_vm 
    1.44  
    1.45  static int calc_timer(struct sched_vm *svm)
    1.46  {
    1.47 -    int time = MAX_TIMER;
    1.48 +    int time;
    1.49  
    1.50 +    /* Start with basic timeslice */
    1.51 +    time = MAX_TIMER;
    1.52 +
    1.53 +    /* If we have less credit than that, cut it down to our credits */
    1.54      if ( time > c2t(svm->credit, svm) )
    1.55          time = c2t(svm->credit, svm);
    1.56  
    1.57 +    /* If there are other VMs on the runqueue, calculate
    1.58 +     * how much time until our credit will equal their credit.
    1.59 +     * If this is less than our timeslice, cut it down again. */
    1.60      if ( !list_empty(&sched_priv.runq) )
    1.61      {
    1.62          struct sched_vm *sq = list_entry(sched_priv.runq.next, struct sched_vm, runq_elem);
    1.63 @@ -105,6 +125,7 @@ static int calc_timer(struct sched_vm *s
    1.64              time = c2t(svm->credit - sq->credit, svm);
    1.65      }
    1.66  
    1.67 +    /* No matter what, always run for at least MIN_TIMER */
    1.68      if ( time < MIN_TIMER )
    1.69          time = MIN_TIMER;
    1.70  
    1.71 @@ -163,6 +184,7 @@ static void sched_credit_vm_init(int vid
    1.72      svm->v = vm_from_vid(vid);
    1.73  
    1.74      svm->credit = CREDIT_INIT;
    1.75 +    /* FIXME */
    1.76      svm->weight = init_weight[vid];
    1.77      if ( sched_priv.max_weight < svm->weight )
    1.78          sched_priv.max_weight = svm->weight;
    1.79 @@ -293,7 +315,7 @@ static struct vm* sched_credit_schedule(
    1.80  struct scheduler sched_credit03 =
    1.81  {
    1.82      .name="credit03",
    1.83 -    .desc="c02 + weight",
    1.84 +    .desc="c02 + implement weight + clip-and-add on reset",
    1.85      .ops = {
    1.86          .sched_init = sched_credit_init,
    1.87          .vm_init    = sched_credit_vm_init,