xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0 of 2] Scheduler: Implement yield for credit scheduler
@ 2010-08-09 11:20 George Dunlap
  2010-08-09 11:20 ` [PATCH 1 of 2] scheduler: Add a per-scheduler yield callback George Dunlap
  2010-08-09 11:20 ` [PATCH 2 of 2] scheduler: Implement yield for credit1 George Dunlap
  0 siblings, 2 replies; 3+ messages in thread
From: George Dunlap @ 2010-08-09 11:20 UTC (permalink / raw)
  To: xen-devel; +Cc: george.dunlap

As discussed in a previous e-mail, this patch series implements yield
for the credit scheduler.  This allows a VM to actually yield (give up
the cpu to another VM) when it wants to.  This has been shown to be
effective when used in the spinlock code to avoid wasting time
spinning when another vcpu is not currently scheduled.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1 of 2] scheduler: Add a per-scheduler yield callback
  2010-08-09 11:20 [PATCH 0 of 2] Scheduler: Implement yield for credit scheduler George Dunlap
@ 2010-08-09 11:20 ` George Dunlap
  2010-08-09 11:20 ` [PATCH 2 of 2] scheduler: Implement yield for credit1 George Dunlap
  1 sibling, 0 replies; 3+ messages in thread
From: George Dunlap @ 2010-08-09 11:20 UTC (permalink / raw)
  To: xen-devel; +Cc: george.dunlap

Signed-off-by: George Dunlap <george.dunlap@eu.citrix.com>

diff -r 6f07d9ac1e7c -r 1c9288cd2af3 xen/common/schedule.c
--- a/xen/common/schedule.c	Thu Aug 05 14:41:14 2010 +0100
+++ b/xen/common/schedule.c	Fri Aug 06 15:41:56 2010 +0100
@@ -641,6 +641,12 @@
 /* Voluntarily yield the processor for this allocation. */
 static long do_yield(void)
 {
+    struct vcpu * v=current;
+
+    vcpu_schedule_lock_irq(v);
+    SCHED_OP(VCPU2OP(v), yield, v);
+    vcpu_schedule_unlock_irq(v);
+
     TRACE_2D(TRC_SCHED_YIELD, current->domain->domain_id, current->vcpu_id);
     raise_softirq(SCHEDULE_SOFTIRQ);
     return 0;
diff -r 6f07d9ac1e7c -r 1c9288cd2af3 xen/include/xen/sched-if.h
--- a/xen/include/xen/sched-if.h	Thu Aug 05 14:41:14 2010 +0100
+++ b/xen/include/xen/sched-if.h	Fri Aug 06 15:41:56 2010 +0100
@@ -107,6 +107,7 @@
 
     void         (*sleep)          (const struct scheduler *, struct vcpu *);
     void         (*wake)           (const struct scheduler *, struct vcpu *);
+    void         (*yield)           (const struct scheduler *, struct vcpu *);
     void         (*context_saved)  (const struct scheduler *, struct vcpu *);
 
     struct task_slice (*do_schedule) (const struct scheduler *, s_time_t,

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 2 of 2] scheduler: Implement yield for credit1
  2010-08-09 11:20 [PATCH 0 of 2] Scheduler: Implement yield for credit scheduler George Dunlap
  2010-08-09 11:20 ` [PATCH 1 of 2] scheduler: Add a per-scheduler yield callback George Dunlap
@ 2010-08-09 11:20 ` George Dunlap
  1 sibling, 0 replies; 3+ messages in thread
From: George Dunlap @ 2010-08-09 11:20 UTC (permalink / raw)
  To: xen-devel; +Cc: george.dunlap

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>

diff -r 1c9288cd2af3 -r 83e1162f1fdc xen/common/sched_credit.c
--- a/xen/common/sched_credit.c	Fri Aug 06 15:41:56 2010 +0100
+++ b/xen/common/sched_credit.c	Fri Aug 06 15:41:57 2010 +0100
@@ -64,7 +64,8 @@
 /*
  * Flags
  */
-#define CSCHED_FLAG_VCPU_PARKED 0x0001  /* VCPU over capped credits */
+#define CSCHED_FLAG_VCPU_PARKED    0x0001  /* VCPU over capped credits */
+#define CSCHED_FLAG_VCPU_YIELD     0x0002  /* VCPU yielding */
 
 
 /*
@@ -108,6 +109,12 @@
 
 
 /*
+ * Boot parameters
+ */
+int sched_credit_default_yield = 0;
+boolean_param("sched_credit_default_yield", sched_credit_default_yield);
+
+/*
  * Physical CPU
  */
 struct csched_pcpu {
@@ -202,6 +209,18 @@
             break;
     }
 
+    /* If the vcpu yielded, try to put it behind one lower-priority
+     * runnable vcpu if we can.  The next runq_sort will bring it forward
+     * within 30ms if the queue too long. */
+    if ( svc->flags & CSCHED_FLAG_VCPU_YIELD
+         && __runq_elem(iter)->pri > CSCHED_PRI_IDLE )
+    {
+        iter=iter->next;
+
+        /* Some sanity checks */
+        BUG_ON(iter == runq);
+    }
+
     list_add_tail(&svc->runq_elem, iter);
 }
 
@@ -748,6 +767,18 @@
     __runq_tickle(cpu, svc);
 }
 
+static void
+csched_vcpu_yield(const struct scheduler *ops, struct vcpu *vc)
+{
+    struct csched_vcpu * const sv = CSCHED_VCPU(vc);
+
+    if ( !sched_credit_default_yield )
+    {
+        /* Let the scheduler know that this vcpu is trying to yield */
+        sv->flags |= CSCHED_FLAG_VCPU_YIELD;
+    }
+}
+
 static int
 csched_dom_cntl(
     const struct scheduler *ops,
@@ -1282,6 +1313,12 @@
     }
 
     /*
+     * Clear YIELD flag before scheduling out
+     */
+    if ( scurr->flags & CSCHED_FLAG_VCPU_YIELD )
+        scurr->flags &= ~(CSCHED_FLAG_VCPU_YIELD);
+
+    /*
      * SMP Load balance:
      *
      * If the next highest priority local runnable VCPU has already eaten
@@ -1509,6 +1546,7 @@
 
     .sleep          = csched_vcpu_sleep,
     .wake           = csched_vcpu_wake,
+    .yield          = csched_vcpu_yield,
 
     .adjust         = csched_dom_cntl,

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-08-09 11:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-08-09 11:20 [PATCH 0 of 2] Scheduler: Implement yield for credit scheduler George Dunlap
2010-08-09 11:20 ` [PATCH 1 of 2] scheduler: Add a per-scheduler yield callback George Dunlap
2010-08-09 11:20 ` [PATCH 2 of 2] scheduler: Implement yield for credit1 George Dunlap

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).