gdunlap/sched-sim.hg

changeset 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 a564c2327d2a
children 03ad237559b4
files sched_credit01.c sched_credit02.c sched_credit03.c
line diff
     1.1 --- a/sched_credit01.c	Fri Jul 16 11:15:33 2010 +0100
     1.2 +++ b/sched_credit01.c	Fri Jul 16 11:55:39 2010 +0100
     1.3 @@ -38,7 +38,18 @@ struct {
     1.4      int next_check;
     1.5  } sched_priv;
     1.6  
     1.7 -
     1.8 +/*
     1.9 + * - Everyone starts at fixed value
    1.10 + * - Burn credit at a constant rate
    1.11 + * - Insert in runq based on credit
    1.12 + * - Reset 
    1.13 + *  - Triggered when someone reaches zero
    1.14 + *  - Sets everyone to init
    1.15 + * - Timeslice
    1.16 + *  - Start with basic timeslice
    1.17 + *  - Don't run for more credit than you have
    1.18 + *  - Never less than MIN_TIMER
    1.19 + */
    1.20  
    1.21  static void reset_credit(int time)
    1.22  {
    1.23 @@ -68,25 +79,19 @@ static void burn_credit(struct sched_vm 
    1.24  
    1.25  static int calc_timer(struct sched_vm *svm)
    1.26  {
    1.27 -    int time = MAX_TIMER;
    1.28 +    int time;
    1.29  
    1.30 +    /* Start with basic timeslice */
    1.31 +    time = MAX_TIMER;
    1.32 +
    1.33 +    /* If we have less credit than that, cut it down to our credits */
    1.34      if ( time > svm->credit )
    1.35          time = svm->credit;
    1.36 -#if 0
    1.37 -    if ( !list_empty(&sched_priv.runq) )
    1.38 -    {
    1.39 -        struct sched_vm *sq = list_entry(sched_priv.runq.next, struct sched_vm, runq_elem);
    1.40  
    1.41 -        ASSERT(svm->credit >= sq->credit);
    1.42 -
    1.43 -        if ( (svm->credit - sq->credit) < time )
    1.44 -            time = (svm->credit - sq->credit);
    1.45 -    }
    1.46 -
    1.47 -#endif
    1.48 -
    1.49 +    /* No matter what, always run for at least MIN_TIMER */
    1.50      if ( time < MIN_TIMER )
    1.51          time = MIN_TIMER;
    1.52 +
    1.53      return time;
    1.54  }
    1.55  
    1.56 @@ -266,7 +271,7 @@ static struct vm* sched_credit_schedule(
    1.57  struct scheduler sched_credit01 =
    1.58  {
    1.59      .name="credit01",
    1.60 -    .desc="Zero-start, burn based on weight, reset to zero at negative credit",
    1.61 +    .desc="Zero-start, reset to zero at negative credit",
    1.62      .ops = {
    1.63          .sched_init = sched_credit_init,
    1.64          .vm_init    = sched_credit_vm_init,
     2.1 --- a/sched_credit02.c	Fri Jul 16 11:15:33 2010 +0100
     2.2 +++ b/sched_credit02.c	Fri Jul 16 11:55:39 2010 +0100
     2.3 @@ -38,7 +38,19 @@ struct {
     2.4      int next_check;
     2.5  } sched_priv;
     2.6  
     2.7 -
     2.8 +/*
     2.9 + * - Everyone starts at fixed value
    2.10 + * - Burn credit at a constant rate
    2.11 + * - Insert in runq based on credit
    2.12 + * - Reset 
    2.13 + *  - Triggered when someone reaches zero
    2.14 + *  - Sets everyone to init
    2.15 + * - Timeslice
    2.16 + *  - Start with basic timeslice
    2.17 + *  - Don't run for more credit than you have
    2.18 + *  + Only run until your credit would equal next VM in runqueue
    2.19 + *  - Never less than MIN_TIMER
    2.20 + */
    2.21  
    2.22  static void reset_credit(int time)
    2.23  {
    2.24 @@ -68,11 +80,18 @@ static void burn_credit(struct sched_vm 
    2.25  
    2.26  static int calc_timer(struct sched_vm *svm)
    2.27  {
    2.28 -    int time = MAX_TIMER;
    2.29 +    int time;
    2.30  
    2.31 +    /* Start with basic timeslice */
    2.32 +    time = MAX_TIMER;
    2.33 +
    2.34 +    /* If we have less credit than that, cut it down to our credits */
    2.35      if ( time > svm->credit )
    2.36          time = svm->credit;
    2.37  
    2.38 +    /* If there are other VMs on the runqueue, calculate
    2.39 +     * how much time until our credit will equal their credit.
    2.40 +     * If this is less than our timeslice, cut it down again. */
    2.41      if ( !list_empty(&sched_priv.runq) )
    2.42      {
    2.43          struct sched_vm *sq = list_entry(sched_priv.runq.next, struct sched_vm, runq_elem);
    2.44 @@ -83,9 +102,10 @@ static int calc_timer(struct sched_vm *s
    2.45              time = (svm->credit - sq->credit);
    2.46      }
    2.47  
    2.48 -
    2.49 +    /* No matter what, always run for at least MIN_TIMER */
    2.50      if ( time < MIN_TIMER )
    2.51          time = MIN_TIMER;
    2.52 +
    2.53      return time;
    2.54  }
    2.55  
    2.56 @@ -265,7 +285,7 @@ static struct vm* sched_credit_schedule(
    2.57  struct scheduler sched_credit02 =
    2.58  {
    2.59      .name="credit02",
    2.60 -    .desc="Zero-start, burn based on weight, reset to zero at negative credit, with time-on-credit-equal",
    2.61 +    .desc="c01 + Preempt when your credit equals the next VM on the runqueue",
    2.62      .ops = {
    2.63          .sched_init = sched_credit_init,
    2.64          .vm_init    = sched_credit_vm_init,
     3.1 --- a/sched_credit03.c	Fri Jul 16 11:15:33 2010 +0100
     3.2 +++ b/sched_credit03.c	Fri Jul 16 11:55:39 2010 +0100
     3.3 @@ -42,6 +42,21 @@ struct {
     3.4      int next_check;
     3.5  } sched_priv;
     3.6  
     3.7 +/*
     3.8 + * + Implement weights (hacky at the moment)
     3.9 + * - Everyone starts at fixed value
    3.10 + * - Burn credit based on variable weight
    3.11 + * - Insert in runq based on credit
    3.12 + * - Reset 
    3.13 + *  - Triggered when someone reaches zero
    3.14 + *  + Clip everyone's credit and add INIT
    3.15 + * - Timeslice
    3.16 + *  - Start with basic timeslice
    3.17 + *  - Don't run for more credit than you have
    3.18 + *  - Only run until your credit would equal next VM in runqueue
    3.19 + *  - Never less than MIN_TIMER
    3.20 + */
    3.21 +
    3.22  static int t2c(int time, struct sched_vm *svm)
    3.23  {
    3.24      return time * sched_priv.max_weight / svm->weight;
    3.25 @@ -65,8 +80,6 @@ static void reset_credit(int time)
    3.26          struct sched_vm *svm = sched_priv.vms + i;
    3.27          int tmax = CREDIT_CLIP;
    3.28  
    3.29 -        //sched_priv.vms[i].credit = 0;
    3.30 -        //sched_priv.vms[i].credit /= (CREDIT_INIT/10);
    3.31          if ( svm->credit > tmax )
    3.32              svm->credit = tmax;
    3.33          svm->credit += CREDIT_INIT;
    3.34 @@ -74,7 +87,7 @@ static void reset_credit(int time)
    3.35  
    3.36          dump_credit(time, svm);
    3.37      }
    3.38 -    /* No need to resort runq, as everyone's credit is now zero */
    3.39 +    /* No need to resort runq, as no one's credit is re-ordered */
    3.40  }
    3.41  
    3.42  static void burn_credit(struct sched_vm *svm, int time)
    3.43 @@ -89,11 +102,18 @@ static void burn_credit(struct sched_vm 
    3.44  
    3.45  static int calc_timer(struct sched_vm *svm)
    3.46  {
    3.47 -    int time = MAX_TIMER;
    3.48 +    int time;
    3.49  
    3.50 +    /* Start with basic timeslice */
    3.51 +    time = MAX_TIMER;
    3.52 +
    3.53 +    /* If we have less credit than that, cut it down to our credits */
    3.54      if ( time > c2t(svm->credit, svm) )
    3.55          time = c2t(svm->credit, svm);
    3.56  
    3.57 +    /* If there are other VMs on the runqueue, calculate
    3.58 +     * how much time until our credit will equal their credit.
    3.59 +     * If this is less than our timeslice, cut it down again. */
    3.60      if ( !list_empty(&sched_priv.runq) )
    3.61      {
    3.62          struct sched_vm *sq = list_entry(sched_priv.runq.next, struct sched_vm, runq_elem);
    3.63 @@ -105,6 +125,7 @@ static int calc_timer(struct sched_vm *s
    3.64              time = c2t(svm->credit - sq->credit, svm);
    3.65      }
    3.66  
    3.67 +    /* No matter what, always run for at least MIN_TIMER */
    3.68      if ( time < MIN_TIMER )
    3.69          time = MIN_TIMER;
    3.70  
    3.71 @@ -163,6 +184,7 @@ static void sched_credit_vm_init(int vid
    3.72      svm->v = vm_from_vid(vid);
    3.73  
    3.74      svm->credit = CREDIT_INIT;
    3.75 +    /* FIXME */
    3.76      svm->weight = init_weight[vid];
    3.77      if ( sched_priv.max_weight < svm->weight )
    3.78          sched_priv.max_weight = svm->weight;
    3.79 @@ -293,7 +315,7 @@ static struct vm* sched_credit_schedule(
    3.80  struct scheduler sched_credit03 =
    3.81  {
    3.82      .name="credit03",
    3.83 -    .desc="c02 + weight",
    3.84 +    .desc="c02 + implement weight + clip-and-add on reset",
    3.85      .ops = {
    3.86          .sched_init = sched_credit_init,
    3.87          .vm_init    = sched_credit_vm_init,