All of lore.kernel.org
 help / color / mirror / Atom feed
* RE: [PATCH][RESUBMIT] don't schedule unplugged vcpus
@ 2005-06-08 21:42 Ian Pratt
  2005-06-08 21:51 ` Keir Fraser
  2005-06-08 21:52 ` Ryan Harper
  0 siblings, 2 replies; 10+ messages in thread
From: Ian Pratt @ 2005-06-08 21:42 UTC (permalink / raw)
  To: Ryan Harper, xen-devel

> I've added in changes to DOM0_GETDOMINFO and 
> DOM0_GETVCPUCONTEXT hypercalls.  dominfo now creates a 
> vcpu_online_map bitmap which marks whether vcpus are up or 
> down.  I didn't want to clobber either the total number of 
> vcpus allocated to a domain (n_vcpu) nor the vcpu_to_cpu 
> mapping since both are still valid whether the vcpu is being 
> scheduled or not.

I don't see why we care about vcpus that are down. From the user's point
of view they've gone for good -- it just happens that Xen hasn't freed
the memory in anticipation of it being used again. What do you think?

I'd be inclined just to enter '-1' in the vcpu_to_cpu map. BTW: we could
make it an s16 rather than s32 at the same time. I think 32,768 CPUs
should keep be enough for anyone :-) 

Ian
 
> I modified vcpucontext to give the context for the first vcpu 
> not down.
> If the requested vcpu is down, it will return the context of 
> the next vcpu that is up, or -ESRCH if no vcpu past the 
> requested vcpu is valid.
> 
> I modified xm list -v to display an ONLINE column which 
> indicates the online status of each vcpu in a domain.

^ permalink raw reply	[flat|nested] 10+ messages in thread
* RE: [PATCH][RESUBMIT] don't schedule unplugged vcpus
@ 2005-06-08 21:59 Ian Pratt
  2005-06-08 22:12 ` Ryan Harper
  0 siblings, 1 reply; 10+ messages in thread
From: Ian Pratt @ 2005-06-08 21:59 UTC (permalink / raw)
  To: Ryan Harper; +Cc: xen-devel

> > I don't see why we care about vcpus that are down. From the user's 
> > point of view they've gone for good -- it just happens that 
> Xen hasn't 
> > freed the memory in anticipation of it being used again. 
> What do you think?
> 
> I don't think the users care so much as I want tools to be 
> able to extract the current state of affairs for load 
> balancing or other operations that want to account for domain state.

I think the vcpu_to_cpu map contains that. 
The n_vcpu variable isn't really needed: my inclination would be to just
report the number that are currently up, though I'm not hugely fussed.

Best,
Ian

^ permalink raw reply	[flat|nested] 10+ messages in thread
* [PATCH] don't schedule unplugged vcpus
@ 2005-06-06 21:03 Ryan Harper
  2005-06-08 21:29 ` [PATCH][RESUBMIT] " Ryan Harper
  0 siblings, 1 reply; 10+ messages in thread
From: Ryan Harper @ 2005-06-06 21:03 UTC (permalink / raw)
  To: xen-devel

This patch extends the CONFIG_HOTPLUG_CPU behavior down into the
hypervisor.  Currently when a CPU in Linux is moved offline,

echo 0 > /sys/devices/system/cpu/cpuX/online

the offline cpu yields its slice back to the hypervisor.  This patch
adds two SCHEDOPS (vcpu_down/vcpu_up) which set/clear a new VCPU flag,
VCPU_down.  The domain_runnable() check now looks at this flag and
subsequently the vcpu is not scheduled when VCPU_down is set.

The patch was built and tested against 20050606 nightly snapshot.
Testing requires DOMU with CONFIG_SMP and CONFIG_HOTPLUG_CPU.  Please
apply.

-- 
Ryan Harper
Software Engineer; Linux Technology Center
IBM Corp., Austin, Tx
(512) 838-9253   T/L: 678-9253
ryanh@us.ibm.com


diffstat output:
 linux-2.6.11-xen-sparse/arch/xen/i386/kernel/process.c       |    7 +
 linux-2.6.11-xen-sparse/arch/xen/i386/kernel/smpboot.c       |    4 
 linux-2.6.11-xen-sparse/include/asm-xen/asm-i386/hypercall.h |   31 +++++++
 xen/common/schedule.c                                        |   48 +++++++++++
 xen/include/public/xen.h                                     |    3 
 xen/include/xen/sched.h                                      |    5 -
 6 files changed, 96 insertions(+), 2 deletions(-)

Signed-off-by: Ryan Harper <ryanh@us.ibm.com>
---
diff -urN b/linux-2.6.11-xen-sparse/arch/xen/i386/kernel/process.c c/linux-2.6.11-xen-sparse/arch/xen/i386/kernel/process.c
--- b/linux-2.6.11-xen-sparse/arch/xen/i386/kernel/process.c	2005-06-05 22:09:07.000000000 -0500
+++ c/linux-2.6.11-xen-sparse/arch/xen/i386/kernel/process.c	2005-06-06 15:15:34.184156730 -0500
@@ -154,8 +154,13 @@
 				cpu_clear(cpu, cpu_idle_map);
 			rmb();
 
-			if (cpu_is_offline(cpu))
+			if (cpu_is_offline(cpu)) {
+#if defined(CONFIG_XEN) && defined(CONFIG_HOTPLUG_CPU)
+            /* Tell hypervisor not to schedule dead vcpus */
+            HYPERVISOR_vcpu_down(cpu);
+#endif
 				play_dead();
+         }
 
 			irq_stat[cpu].idle_timestamp = jiffies;
 			xen_idle();
diff -urN b/linux-2.6.11-xen-sparse/arch/xen/i386/kernel/smpboot.c c/linux-2.6.11-xen-sparse/arch/xen/i386/kernel/smpboot.c
--- b/linux-2.6.11-xen-sparse/arch/xen/i386/kernel/smpboot.c	2005-06-05 22:09:13.000000000 -0500
+++ c/linux-2.6.11-xen-sparse/arch/xen/i386/kernel/smpboot.c	2005-06-06 15:44:15.988564794 -0500
@@ -1380,6 +1380,10 @@
 	}
 
 #ifdef CONFIG_HOTPLUG_CPU
+#ifdef CONFIG_XEN
+   /* Tell hypervisor to bring vcpu up */
+   HYPERVISOR_vcpu_up(cpu);
+#endif
 	/* Already up, and in cpu_quiescent now? */
 	if (cpu_isset(cpu, smp_commenced_mask)) {
 		cpu_enable(cpu);
diff -urN b/linux-2.6.11-xen-sparse/include/asm-xen/asm-i386/hypercall.h c/linux-2.6.11-xen-sparse/include/asm-xen/asm-i386/hypercall.h
--- b/linux-2.6.11-xen-sparse/include/asm-xen/asm-i386/hypercall.h	2005-06-05 22:09:15.000000000 -0500
+++ c/linux-2.6.11-xen-sparse/include/asm-xen/asm-i386/hypercall.h	2005-06-06 14:18:17.414798645 -0500
@@ -517,4 +517,35 @@
     return ret;
 }
 
+static inline int
+HYPERVISOR_vcpu_down(
+    int vcpu)
+{
+    int ret;
+    unsigned long ign1;
+    __asm__ __volatile__ (
+        TRAP_INSTR
+        : "=a" (ret), "=b" (ign1)
+	: "0" (__HYPERVISOR_sched_op),
+	  "1" (SCHEDOP_vcpu_down | (vcpu << SCHEDOP_vcpushift))
+        : "memory" );
+
+    return ret;
+}
+
+static inline int
+HYPERVISOR_vcpu_up(
+    int vcpu)
+{
+    int ret;
+    unsigned long ign1;
+    __asm__ __volatile__ (
+        TRAP_INSTR
+        : "=a" (ret), "=b" (ign1)
+	: "0" (__HYPERVISOR_sched_op),
+	  "1" (SCHEDOP_vcpu_up | (vcpu << SCHEDOP_vcpushift))
+        : "memory" );
+
+    return ret;
+}
 #endif /* __HYPERCALL_H__ */
diff -urN b/xen/common/schedule.c c/xen/common/schedule.c
--- b/xen/common/schedule.c	2005-06-05 22:09:14.000000000 -0500
+++ c/xen/common/schedule.c	2005-06-06 15:50:35.549218230 -0500
@@ -261,6 +261,44 @@
     return 0;
 }
 
+/* Mark target vcpu as non-runnable so it is not scheduled */
+static long do_vcpu_down(int vcpu)
+{
+    struct vcpu *target;
+    
+    if (vcpu > MAX_VIRT_CPUS)
+        return -EINVAL;
+
+    target = current->domain->vcpu[vcpu];
+    /* DEBUG
+     * printk("DOM%d VCPU%d going down\n",
+     *     target->domain->domain_id, target->vcpu_id);
+     */
+    set_bit(_VCPUF_down, &target->vcpu_flags);
+
+    return 0;
+}
+
+/* Mark target vcpu as runnable and wake it */
+static long do_vcpu_up(int vcpu)
+{
+    struct vcpu *target;
+   
+    if (vcpu > MAX_VIRT_CPUS)
+        return -EINVAL;
+
+    target = current->domain->vcpu[vcpu];
+    /* DEBUG
+     * printk("DOM%d VCPU%d coming up\n", 
+     *     target->domain->domain_id, target->vcpu_id);
+     */
+    clear_bit(_VCPUF_down, &target->vcpu_flags);
+    /* wake vcpu */
+    domain_wake(target);
+
+    return 0;
+}
+
 /*
  * Demultiplex scheduler-related hypercalls.
  */
@@ -290,6 +328,16 @@
         domain_shutdown((u8)(op >> SCHEDOP_reasonshift));
         break;
     }
+    case SCHEDOP_vcpu_down:
+    {
+        ret = do_vcpu_down((int)(op >> SCHEDOP_vcpushift));
+        break;
+    }
+    case SCHEDOP_vcpu_up:
+    {
+        ret = do_vcpu_up((int)(op >> SCHEDOP_vcpushift));
+        break;
+    }
 
     default:
         ret = -ENOSYS;
diff -urN b/xen/include/public/xen.h c/xen/include/public/xen.h
--- b/xen/include/public/xen.h	2005-06-05 22:09:13.000000000 -0500
+++ c/xen/include/public/xen.h	2005-06-06 14:18:17.427796825 -0500
@@ -200,8 +200,11 @@
 #define SCHEDOP_yield           0   /* Give up the CPU voluntarily.       */
 #define SCHEDOP_block           1   /* Block until an event is received.  */
 #define SCHEDOP_shutdown        2   /* Stop executing this domain.        */
+#define SCHEDOP_vcpu_down       3   /* make target VCPU not-runnable.     */
+#define SCHEDOP_vcpu_up         4   /* make target VCPU runnable.         */
 #define SCHEDOP_cmdmask       255   /* 8-bit command. */
 #define SCHEDOP_reasonshift     8   /* 8-bit reason code. (SCHEDOP_shutdown) */
+#define SCHEDOP_vcpushift       8   /* 8-bit VCPU target. (SCHEDOP_up|down) */
 
 /*
  * Reason codes for SCHEDOP_shutdown. These may be interpreted by control 
diff -urN b/xen/include/xen/sched.h c/xen/include/xen/sched.h
--- b/xen/include/xen/sched.h	2005-06-05 22:09:08.000000000 -0500
+++ c/xen/include/xen/sched.h	2005-06-06 14:18:17.000000000 -0500
@@ -346,6 +346,9 @@
  /* Initialization completed. */
 #define _VCPUF_initialised     8
 #define VCPUF_initialised      (1UL<<_VCPUF_initialised)
+ /* VCPU is not-runnable */
+#define _VCPUF_down            9
+#define VCPUF_down             (1UL<<_VCPUF_down)
 
 /*
  * Per-domain flags (domain_flags).
@@ -375,7 +378,7 @@
 static inline int domain_runnable(struct vcpu *v)
 {
     return ( (atomic_read(&v->pausecnt) == 0) &&
-             !(v->vcpu_flags & (VCPUF_blocked|VCPUF_ctrl_pause)) &&
+             !(v->vcpu_flags & (VCPUF_blocked|VCPUF_ctrl_pause|VCPUF_down)) &&
              !(v->domain->domain_flags & (DOMF_shutdown|DOMF_shuttingdown)) );
 }

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

end of thread, other threads:[~2005-06-09  7:58 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-06-08 21:42 [PATCH][RESUBMIT] don't schedule unplugged vcpus Ian Pratt
2005-06-08 21:51 ` Keir Fraser
2005-06-08 22:00   ` Ryan Harper
2005-06-08 22:03     ` Keir Fraser
2005-06-08 22:18       ` Ryan Harper
2005-06-09  7:58         ` Keir Fraser
2005-06-08 21:52 ` Ryan Harper
  -- strict thread matches above, loose matches on Subject: below --
2005-06-08 21:59 Ian Pratt
2005-06-08 22:12 ` Ryan Harper
2005-06-06 21:03 [PATCH] " Ryan Harper
2005-06-08 21:29 ` [PATCH][RESUBMIT] " Ryan Harper

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.