xcp-1.6-updates/xen-4.1.hg

changeset 23255:1f95b55ef427

sched_credit: Use delay to control scheduling frequency

This patch can improve Xen performance:
1. Basically, the "delay method" can achieve 11% overall performance
boost for SPECvirt than original credit scheduler.
2. We have tried 1ms delay and 10ms delay, there is no big difference
between these two configurations. (1ms is enough to achieve a good
performance)
3. We have compared different load level response time/latency (low,
high, peak), "delay method" didn't bring very much response time
increase.
4. 1ms delay can reduce 30% context switch at peak performance, where
produces the benefits. (int sched_ratelimit_us = 1000 is the
recommended setting)

Signed-off-by: Hui Lv <hui.lv@intel.com>
Signed-off-by: George Dunlap <george.dunlap@eu.citrix.com>
Acked-by: George Dunlap <george.dunlap@eu.citrix.com>
Committed-by: Keir Fraser <keir@xen.org>
xen-unstable changeset: 24518:44c2856b1952
xen-unstable date: Tue Jan 17 11:18:48 2012 +0000
author Hui Lv <hui.lv@intel.com>
date Wed Mar 07 09:34:26 2012 +0000 (2012-03-07)
parents 1c0f76eea67d
children b7efb9e1a041
files xen/common/sched_credit.c xen/common/schedule.c xen/include/xen/perfc_defn.h xen/include/xen/sched-if.h
line diff
     1.1 --- a/xen/common/sched_credit.c	Wed Mar 07 09:33:45 2012 +0000
     1.2 +++ b/xen/common/sched_credit.c	Wed Mar 07 09:34:26 2012 +0000
     1.3 @@ -172,6 +172,7 @@ struct csched_private {
     1.4      uint32_t credit;
     1.5      int credit_balance;
     1.6      uint32_t runq_sort;
     1.7 +    unsigned ratelimit_us;
     1.8      /* Period of master and tick in milliseconds */
     1.9      unsigned tslice_ms, tick_period_us, ticks_per_tslice;
    1.10      unsigned credits_per_tslice;
    1.11 @@ -1298,10 +1299,15 @@ csched_schedule(
    1.12      struct csched_private *prv = CSCHED_PRIV(ops);
    1.13      struct csched_vcpu *snext;
    1.14      struct task_slice ret;
    1.15 +    s_time_t runtime, tslice;
    1.16  
    1.17      CSCHED_STAT_CRANK(schedule);
    1.18      CSCHED_VCPU_CHECK(current);
    1.19  
    1.20 +    runtime = now - current->runstate.state_entry_time;
    1.21 +    if ( runtime < 0 ) /* Does this ever happen? */
    1.22 +        runtime = 0;
    1.23 +
    1.24      if ( !is_idle_vcpu(scurr->vcpu) )
    1.25      {
    1.26          /* Update credits of a non-idle VCPU. */
    1.27 @@ -1314,6 +1320,35 @@ csched_schedule(
    1.28          scurr->pri = CSCHED_PRI_IDLE;
    1.29      }
    1.30  
    1.31 +    /* Choices, choices:
    1.32 +     * - If we have a tasklet, we need to run the idle vcpu no matter what.
    1.33 +     * - If sched rate limiting is in effect, and the current vcpu has
    1.34 +     *   run for less than that amount of time, continue the current one,
    1.35 +     *   but with a shorter timeslice and return it immediately
    1.36 +     * - Otherwise, chose the one with the highest priority (which may
    1.37 +     *   be the one currently running)
    1.38 +     * - If the currently running one is TS_OVER, see if there
    1.39 +     *   is a higher priority one waiting on the runqueue of another
    1.40 +     *   cpu and steal it.
    1.41 +     */
    1.42 +
    1.43 +    /* If we have schedule rate limiting enabled, check to see
    1.44 +     * how long we've run for. */
    1.45 +    if ( !tasklet_work_scheduled
    1.46 +         && prv->ratelimit_us
    1.47 +         && vcpu_runnable(current)
    1.48 +         && !is_idle_vcpu(current)
    1.49 +         && runtime < MICROSECS(prv->ratelimit_us) )
    1.50 +    {
    1.51 +        snext = scurr;
    1.52 +        snext->start_time += now;
    1.53 +        perfc_incr(delay_ms);
    1.54 +        tslice = MICROSECS(prv->ratelimit_us);
    1.55 +        ret.migrated = 0;
    1.56 +        goto out;
    1.57 +    }
    1.58 +    tslice = MILLISECS(prv->tslice_ms);
    1.59 +
    1.60      /*
    1.61       * Select next runnable local VCPU (ie top of local runq)
    1.62       */
    1.63 @@ -1368,11 +1403,12 @@ csched_schedule(
    1.64      if ( !is_idle_vcpu(snext->vcpu) )
    1.65          snext->start_time += now;
    1.66  
    1.67 +out:
    1.68      /*
    1.69       * Return task to run next...
    1.70       */
    1.71      ret.time = (is_idle_vcpu(snext->vcpu) ?
    1.72 -                -1 : MILLISECS(prv->tslice_ms));
    1.73 +                -1 : tslice);
    1.74      ret.task = snext->vcpu;
    1.75  
    1.76      CSCHED_VCPU_CHECK(ret.task);
    1.77 @@ -1522,6 +1558,15 @@ csched_init(struct scheduler *ops)
    1.78      prv->tick_period_us = prv->tslice_ms * 1000 / prv->ticks_per_tslice;
    1.79      prv->credits_per_tslice = CSCHED_CREDITS_PER_MSEC * prv->tslice_ms;
    1.80  
    1.81 +    if ( MICROSECS(sched_ratelimit_us) > MILLISECS(sched_credit_tslice_ms) )
    1.82 +    {
    1.83 +        printk("WARNING: sched_ratelimit_us >" 
    1.84 +               "sched_credit_tslice_ms is undefined\n"
    1.85 +               "Setting ratelimit_us to 1000 * tslice_ms\n");
    1.86 +        prv->ratelimit_us = 1000 * prv->tslice_ms;
    1.87 +    }
    1.88 +    else
    1.89 +        prv->ratelimit_us = sched_ratelimit_us;
    1.90      return 0;
    1.91  }
    1.92  
     2.1 --- a/xen/common/schedule.c	Wed Mar 07 09:33:45 2012 +0000
     2.2 +++ b/xen/common/schedule.c	Wed Mar 07 09:34:26 2012 +0000
     2.3 @@ -47,6 +47,11 @@ string_param("sched", opt_sched);
     2.4  bool_t sched_smt_power_savings = 0;
     2.5  boolean_param("sched_smt_power_savings", sched_smt_power_savings);
     2.6  
     2.7 +/* Default scheduling rate limit: 1ms 
     2.8 + * The behavior when sched_ratelimit_us is greater than sched_credit_tslice_ms is undefined
     2.9 + * */
    2.10 +int sched_ratelimit_us = 1000;
    2.11 +integer_param("sched_ratelimit_us", sched_ratelimit_us);
    2.12  /* Various timer handlers. */
    2.13  static void s_timer_fn(void *unused);
    2.14  static void vcpu_periodic_timer_fn(void *data);
     3.1 --- a/xen/include/xen/perfc_defn.h	Wed Mar 07 09:33:45 2012 +0000
     3.2 +++ b/xen/include/xen/perfc_defn.h	Wed Mar 07 09:34:26 2012 +0000
     3.3 @@ -16,6 +16,7 @@ PERFCOUNTER(sched_irq,              "sch
     3.4  PERFCOUNTER(sched_run,              "sched: runs through scheduler")
     3.5  PERFCOUNTER(sched_ctx,              "sched: context switches")
     3.6  
     3.7 +PERFCOUNTER(delay_ms,               "csched: delay")
     3.8  PERFCOUNTER(vcpu_check,             "csched: vcpu_check")
     3.9  PERFCOUNTER(schedule,               "csched: schedule")
    3.10  PERFCOUNTER(acct_run,               "csched: acct_run")
     4.1 --- a/xen/include/xen/sched-if.h	Wed Mar 07 09:33:45 2012 +0000
     4.2 +++ b/xen/include/xen/sched-if.h	Wed Mar 07 09:34:26 2012 +0000
     4.3 @@ -16,6 +16,11 @@ extern struct cpupool *cpupool0;
     4.4  /* cpus currently in no cpupool */
     4.5  extern cpumask_t cpupool_free_cpus;
     4.6  
     4.7 +/* Scheduler generic parameters
     4.8 + * */
     4.9 +extern int sched_ratelimit_us;
    4.10 +
    4.11 +
    4.12  /*
    4.13   * In order to allow a scheduler to remap the lock->cpu mapping,
    4.14   * we have a per-cpu pointer, along with a pre-allocated set of