debuggers.hg

changeset 21982:fc29e13f669d

scheduler: Implement yield for credit1

This patch implements 'yield' for credit1. It does this by attempting
to put yielding vcpu behind a single lower-priority vcpu on the
runqueue. If no lower-priority vcpus are in the queue, it will go at
the back (which if the queue is empty, will also be the front).

Runqueues are sorted every 30ms, so that's the longest this priority
inversion can happen.

For workloads with heavy concurrency hazard, and guest which implement
yield-on-spinlock, this patch significantly increases performance and
total system throughput.

Signed-off-by: George Dunlap <george.dunlap@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Mon Aug 09 16:36:07 2010 +0100 (2010-08-09)
parents 93074767205e
children 2129cabe5f33
files xen/common/sched_credit.c
line diff
     1.1 --- a/xen/common/sched_credit.c	Mon Aug 09 16:35:27 2010 +0100
     1.2 +++ b/xen/common/sched_credit.c	Mon Aug 09 16:36:07 2010 +0100
     1.3 @@ -64,7 +64,8 @@
     1.4  /*
     1.5   * Flags
     1.6   */
     1.7 -#define CSCHED_FLAG_VCPU_PARKED 0x0001  /* VCPU over capped credits */
     1.8 +#define CSCHED_FLAG_VCPU_PARKED    0x0001  /* VCPU over capped credits */
     1.9 +#define CSCHED_FLAG_VCPU_YIELD     0x0002  /* VCPU yielding */
    1.10  
    1.11  
    1.12  /*
    1.13 @@ -108,6 +109,12 @@
    1.14  
    1.15  
    1.16  /*
    1.17 + * Boot parameters
    1.18 + */
    1.19 +int sched_credit_default_yield = 0;
    1.20 +boolean_param("sched_credit_default_yield", sched_credit_default_yield);
    1.21 +
    1.22 +/*
    1.23   * Physical CPU
    1.24   */
    1.25  struct csched_pcpu {
    1.26 @@ -202,6 +209,18 @@ static inline void
    1.27              break;
    1.28      }
    1.29  
    1.30 +    /* If the vcpu yielded, try to put it behind one lower-priority
    1.31 +     * runnable vcpu if we can.  The next runq_sort will bring it forward
    1.32 +     * within 30ms if the queue too long. */
    1.33 +    if ( svc->flags & CSCHED_FLAG_VCPU_YIELD
    1.34 +         && __runq_elem(iter)->pri > CSCHED_PRI_IDLE )
    1.35 +    {
    1.36 +        iter=iter->next;
    1.37 +
    1.38 +        /* Some sanity checks */
    1.39 +        BUG_ON(iter == runq);
    1.40 +    }
    1.41 +
    1.42      list_add_tail(&svc->runq_elem, iter);
    1.43  }
    1.44  
    1.45 @@ -748,6 +767,18 @@ csched_vcpu_wake(const struct scheduler 
    1.46      __runq_tickle(cpu, svc);
    1.47  }
    1.48  
    1.49 +static void
    1.50 +csched_vcpu_yield(const struct scheduler *ops, struct vcpu *vc)
    1.51 +{
    1.52 +    struct csched_vcpu * const sv = CSCHED_VCPU(vc);
    1.53 +
    1.54 +    if ( !sched_credit_default_yield )
    1.55 +    {
    1.56 +        /* Let the scheduler know that this vcpu is trying to yield */
    1.57 +        sv->flags |= CSCHED_FLAG_VCPU_YIELD;
    1.58 +    }
    1.59 +}
    1.60 +
    1.61  static int
    1.62  csched_dom_cntl(
    1.63      const struct scheduler *ops,
    1.64 @@ -1282,6 +1313,12 @@ csched_schedule(
    1.65      }
    1.66  
    1.67      /*
    1.68 +     * Clear YIELD flag before scheduling out
    1.69 +     */
    1.70 +    if ( scurr->flags & CSCHED_FLAG_VCPU_YIELD )
    1.71 +        scurr->flags &= ~(CSCHED_FLAG_VCPU_YIELD);
    1.72 +
    1.73 +    /*
    1.74       * SMP Load balance:
    1.75       *
    1.76       * If the next highest priority local runnable VCPU has already eaten
    1.77 @@ -1509,6 +1546,7 @@ const struct scheduler sched_credit_def 
    1.78  
    1.79      .sleep          = csched_vcpu_sleep,
    1.80      .wake           = csched_vcpu_wake,
    1.81 +    .yield          = csched_vcpu_yield,
    1.82  
    1.83      .adjust         = csched_dom_cntl,
    1.84