ia64/xen-unstable

changeset 12047:b21246720fde

[XEN] Cleanup and improve accuracy of credit scheduler accounting code
Signed-off-by: Emmanuel Ackaouy <ack@xensource.com>
author Emmanuel Ackaouy <ack@xensource.com>
date Mon Oct 30 17:35:11 2006 +0000 (2006-10-30)
parents d6802cfaf5f8
children d9a0690399e0 eb3fe0620e3d b2371c9e05f5
files xen/common/sched_credit.c
line diff
     1.1 --- a/xen/common/sched_credit.c	Mon Oct 30 14:28:29 2006 +0000
     1.2 +++ b/xen/common/sched_credit.c	Mon Oct 30 17:35:11 2006 +0000
     1.3 @@ -36,11 +36,17 @@
     1.4  /*
     1.5   * Basic constants
     1.6   */
     1.7 -#define CSCHED_TICK             10      /* milliseconds */
     1.8 -#define CSCHED_TSLICE           30      /* milliseconds */
     1.9 -#define CSCHED_ACCT_NTICKS      3
    1.10 -#define CSCHED_ACCT_PERIOD      (CSCHED_ACCT_NTICKS * CSCHED_TICK)
    1.11 -#define CSCHED_DEFAULT_WEIGHT   256
    1.12 +#define CSCHED_DEFAULT_WEIGHT       256
    1.13 +#define CSCHED_TICKS_PER_TSLICE     3
    1.14 +#define CSCHED_TICKS_PER_ACCT       3
    1.15 +#define CSCHED_MSECS_PER_TICK       10
    1.16 +#define CSCHED_MSECS_PER_TSLICE     \
    1.17 +    (CSCHED_MSECS_PER_TICK * CSCHED_TICKS_PER_TSLICE)
    1.18 +#define CSCHED_CREDITS_PER_TICK     100
    1.19 +#define CSCHED_CREDITS_PER_TSLICE   \
    1.20 +    (CSCHED_CREDITS_PER_TICK * CSCHED_TICKS_PER_TSLICE)
    1.21 +#define CSCHED_CREDITS_PER_ACCT     \
    1.22 +    (CSCHED_CREDITS_PER_TICK * CSCHED_TICKS_PER_ACCT)
    1.23  
    1.24  
    1.25  /*
    1.26 @@ -314,7 +320,7 @@ csched_pcpu_init(int cpu)
    1.27      spin_lock_irqsave(&csched_priv.lock, flags);
    1.28  
    1.29      /* Initialize/update system-wide config */
    1.30 -    csched_priv.credit += CSCHED_ACCT_PERIOD;
    1.31 +    csched_priv.credit += CSCHED_CREDITS_PER_ACCT;
    1.32      if ( csched_priv.ncpus <= cpu )
    1.33          csched_priv.ncpus = cpu + 1;
    1.34      if ( csched_priv.master >= csched_priv.ncpus )
    1.35 @@ -439,8 +445,6 @@ static inline void
    1.36          list_del_init(&sdom->active_sdom_elem);
    1.37          csched_priv.weight -= sdom->weight;
    1.38      }
    1.39 -
    1.40 -    atomic_set(&svc->credit, 0);
    1.41  }
    1.42  
    1.43  static int
    1.44 @@ -767,7 +771,7 @@ csched_acct(void)
    1.45           * for one full accounting period. We allow a domain to earn more
    1.46           * only when the system-wide credit balance is negative.
    1.47           */
    1.48 -        credit_peak = sdom->active_vcpu_count * CSCHED_ACCT_PERIOD;
    1.49 +        credit_peak = sdom->active_vcpu_count * CSCHED_CREDITS_PER_ACCT;
    1.50          if ( csched_priv.credit_balance < 0 )
    1.51          {
    1.52              credit_peak += ( ( -csched_priv.credit_balance * sdom->weight) +
    1.53 @@ -776,7 +780,9 @@ csched_acct(void)
    1.54          }
    1.55          if ( sdom->cap != 0U )
    1.56          {
    1.57 -            uint32_t credit_cap = ((sdom->cap * CSCHED_ACCT_PERIOD) + 99) / 100;
    1.58 +            uint32_t credit_cap;
    1.59 +            
    1.60 +            credit_cap = ((sdom->cap * CSCHED_CREDITS_PER_ACCT) + 99) / 100;
    1.61              if ( credit_cap < credit_peak )
    1.62                  credit_peak = credit_cap;
    1.63          }
    1.64 @@ -839,10 +845,10 @@ csched_acct(void)
    1.65                  else
    1.66                      svc->pri = CSCHED_PRI_TS_PARKED;
    1.67  
    1.68 -                if ( credit < -CSCHED_TSLICE )
    1.69 +                if ( credit < -CSCHED_CREDITS_PER_TSLICE )
    1.70                  {
    1.71                      CSCHED_STAT_CRANK(acct_min_credit);
    1.72 -                    credit = -CSCHED_TSLICE;
    1.73 +                    credit = -CSCHED_CREDITS_PER_TSLICE;
    1.74                      atomic_set(&svc->credit, credit);
    1.75                  }
    1.76              }
    1.77 @@ -850,8 +856,12 @@ csched_acct(void)
    1.78              {
    1.79                  svc->pri = CSCHED_PRI_TS_UNDER;
    1.80  
    1.81 -                if ( credit > CSCHED_TSLICE )
    1.82 +                if ( credit > CSCHED_CREDITS_PER_TSLICE )
    1.83 +                {
    1.84                      __csched_vcpu_acct_idle_locked(svc);
    1.85 +                    credit = 0;
    1.86 +                    atomic_set(&svc->credit, credit);
    1.87 +                }
    1.88              }
    1.89  
    1.90              svc->credit_last = credit;
    1.91 @@ -881,7 +891,7 @@ csched_tick(unsigned int cpu)
    1.92       */
    1.93      if ( likely(sdom != NULL) )
    1.94      {
    1.95 -        csched_vcpu_acct(svc, CSCHED_TICK);
    1.96 +        csched_vcpu_acct(svc, CSCHED_CREDITS_PER_TICK);
    1.97      }
    1.98  
    1.99      /*
   1.100 @@ -891,7 +901,7 @@ csched_tick(unsigned int cpu)
   1.101       * we could distribute or at the very least cycle the duty.
   1.102       */
   1.103      if ( (csched_priv.master == cpu) &&
   1.104 -         (per_cpu(schedule_data, cpu).tick % CSCHED_ACCT_NTICKS) == 0 )
   1.105 +         (per_cpu(schedule_data, cpu).tick % CSCHED_TICKS_PER_ACCT) == 0 )
   1.106      {
   1.107          csched_acct();
   1.108      }
   1.109 @@ -1069,7 +1079,7 @@ csched_schedule(s_time_t now)
   1.110      /*
   1.111       * Return task to run next...
   1.112       */
   1.113 -    ret.time = MILLISECS(CSCHED_TSLICE);
   1.114 +    ret.time = MILLISECS(CSCHED_MSECS_PER_TSLICE);
   1.115      ret.task = snext->vcpu;
   1.116  
   1.117      CSCHED_VCPU_CHECK(ret.task);
   1.118 @@ -1150,20 +1160,22 @@ csched_dump(void)
   1.119             "\tcredit balance     = %d\n"
   1.120             "\tweight             = %u\n"
   1.121             "\trunq_sort          = %u\n"
   1.122 -           "\ttick               = %dms\n"
   1.123 -           "\ttslice             = %dms\n"
   1.124 -           "\taccounting period  = %dms\n"
   1.125 -           "\tdefault-weight     = %d\n",
   1.126 +           "\tdefault-weight     = %d\n"
   1.127 +           "\tmsecs per tick     = %dms\n"
   1.128 +           "\tcredits per tick   = %d\n"
   1.129 +           "\tticks per tslice   = %d\n"
   1.130 +           "\tticks per acct     = %d\n",
   1.131             csched_priv.ncpus,
   1.132             csched_priv.master,
   1.133             csched_priv.credit,
   1.134             csched_priv.credit_balance,
   1.135             csched_priv.weight,
   1.136             csched_priv.runq_sort,
   1.137 -           CSCHED_TICK,
   1.138 -           CSCHED_TSLICE,
   1.139 -           CSCHED_ACCT_PERIOD,
   1.140 -           CSCHED_DEFAULT_WEIGHT);
   1.141 +           CSCHED_DEFAULT_WEIGHT,
   1.142 +           CSCHED_MSECS_PER_TICK,
   1.143 +           CSCHED_CREDITS_PER_TICK,
   1.144 +           CSCHED_TICKS_PER_TSLICE,
   1.145 +           CSCHED_TICKS_PER_ACCT);
   1.146  
   1.147      printk("idlers: 0x%lx\n", csched_priv.idlers.bits[0]);
   1.148