public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* Re: rebase hlt emulation
@ 2007-07-12 14:45 Gregory Haskins
       [not found] ` <4696065E0200005A0002766F-Igcdv/6uVdMHoYOw/+koYqIwWpluYiW7@public.gmane.org>
  0 siblings, 1 reply; 10+ messages in thread
From: Gregory Haskins @ 2007-07-12 14:45 UTC (permalink / raw)
  To: eddie.dong-ral2JQCrhuEAvxtiuMwx3w
  Cc: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f

On Thu, 2007-07-12 at 22:20 +0800, Dong, Eddie wrote:


> Apply to current kvm.git? Then we need to define false for
> irqchip_in_kernel() which makes the patch quit stranger.

I think what Avi is saying is this can be generalized as a separate
feature independent of in-kernel-PIC.  Since Avi and I are both
advocating a separate capability for in-kernel-HLT, you wouldn't need to
have a stubbed irqchip_in_kernel.  Rather, you should have a flag that
indicates whether userspace enabled the HLT capability or not.

>  
> In theory this is only valid for a case with irqchip in kernel since we
> always fall back to user if irqchip is in user.

How so?  In theory, we can halt in the kernel independent of modeling
interrupts in the kernel.  The difference is in the wakeup logic.  For
the patch that goes in pre-PIC, the wakeup is predicated solely on
signal delivery.  Later, the PIC series can modify the wakeup to include
the in-kernel sources as well.

-Greg



-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/

^ permalink raw reply	[flat|nested] 10+ messages in thread
* Re: rebase hlt emulation
@ 2007-07-12  9:31 Gregory Haskins
       [not found] ` <4695BCA50200005A000275FE-Igcdv/6uVdMHoYOw/+koYqIwWpluYiW7@public.gmane.org>
  0 siblings, 1 reply; 10+ messages in thread
From: Gregory Haskins @ 2007-07-12  9:31 UTC (permalink / raw)
  To: eddie.dong-ral2JQCrhuEAvxtiuMwx3w
  Cc: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f

On Thu, 2007-07-12 at 13:33 +0800, Dong, Eddie wrote:
> Here is the update with adding HLT cap.

Thats a good start, but you probably need to make the decision to use
the halt predicated on a halt-specific boolean set by userspace in order
to actually function as we've discussed.  This is in contrast to
overloading the decision with the presence of the in-kernel PIC.  A
capability indicator without a way to turn it on/off is fairly useless,
IMHO.

Conversely I don't think its a big deal to just skip the predicate all
together since your version of the patches wont cause as severe of an
issue as we had in hybrid mode.  So I would say either make the full
conversion or drop the CAP altogether.

-Greg


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/

^ permalink raw reply	[flat|nested] 10+ messages in thread
* rebase hlt emulation
@ 2007-07-07  4:42 Dong, Eddie
       [not found] ` <10EA09EFD8728347A513008B6B0DA77A01B8F3F3-wq7ZOvIWXbNpB2pF5aRoyrfspsVTdybXVpNB7YpNyf8@public.gmane.org>
  0 siblings, 1 reply; 10+ messages in thread
From: Dong, Eddie @ 2007-07-07  4:42 UTC (permalink / raw)
  To: Avi Kivity; +Cc: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f

[-- Attachment #1: Type: text/plain, Size: 3188 bytes --]

This rebase the HLT emulation patch to lapic2 branch.

Signed-off-by: Gregory Haskins [ghaskins-Et1tbQHTxzrQT0dZR+AlfA@public.gmane.org]
Signed-off-by: Yaozu (Eddie) Dong <eddie.dong-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>

diff --git a/drivers/kvm/i8259.c b/drivers/kvm/i8259.c
index f4ae5f7..e84e665 100644
--- a/drivers/kvm/i8259.c
+++ b/drivers/kvm/i8259.c
@@ -411,8 +411,13 @@ static void picdev_read(struct kvm_io_device *this,
 static void pic_irq_request(void *opaque, int level)
 {
 	struct kvm *kvm = opaque;
+	struct kvm_vcpu *vcpu = &kvm->vcpus[0];
 
 	pic_irqchip(kvm)->output = level;
+	if (waitqueue_active(&vcpu->wq)) {
+		wake_up_interruptible(&vcpu->wq);
+		++vcpu->stat.halt_wakeup;
+	}
 }
 
 struct kvm_pic *kvm_create_pic(struct kvm *kvm)
diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
index f1a6773..1d1ee4f 100644
--- a/drivers/kvm/kvm.h
+++ b/drivers/kvm/kvm.h
@@ -260,6 +260,7 @@ struct kvm_stat {
 	u32 signal_exits;
 	u32 irq_window_exits;
 	u32 halt_exits;
+	u32 halt_wakeup;
 	u32 request_irq_exits;
 	u32 irq_exits;
 	u32 light_exits;
@@ -399,6 +400,7 @@ struct kvm_vcpu {
 	gva_t mmio_fault_cr2;
 	struct kvm_pio_request pio;
 	void *pio_data;
+	wait_queue_head_t wq;
 
 	int sigset_active;
 	sigset_t sigset;
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index 06e5804..18da363 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -74,6 +74,7 @@ static struct kvm_stats_debugfs_item {
 	{ "signal_exits", STAT_OFFSET(signal_exits) },
 	{ "irq_window", STAT_OFFSET(irq_window_exits) },
 	{ "halt_exits", STAT_OFFSET(halt_exits) },
+	{ "halt_wakeup", STAT_OFFSET(halt_wakeup) },
 	{ "request_irq", STAT_OFFSET(request_irq_exits) },
 	{ "irq_exits", STAT_OFFSET(irq_exits) },
 	{ "light_exits", STAT_OFFSET(light_exits) },
@@ -326,6 +327,7 @@ static struct kvm *kvm_create_vm(void)
 		vcpu->cpu = -1;
 		vcpu->kvm = kvm;
 		vcpu->mmu.root_hpa = INVALID_PAGE;
+		init_waitqueue_head(&vcpu->wq);
 	}
 	return kvm;
 }
@@ -1324,15 +1326,36 @@ int emulate_instruction(struct kvm_vcpu *vcpu,
 }
 EXPORT_SYMBOL_GPL(emulate_instruction);
 
-int kvm_emulate_halt(struct kvm_vcpu *vcpu)
+/*
+ * The vCPU has executed a HLT instruction with in-kernel mode enabled.
+ */
+static void kvm_vcpu_kernel_halt(struct kvm_vcpu *vcpu)
 {
-	if (vcpu->irq_summary ||
-		(irqchip_in_kernel(vcpu->kvm) &&
kvm_cpu_has_interrupt(vcpu)))
-		return 1;
+	DECLARE_WAITQUEUE(wait, current);
+
+	add_wait_queue(&vcpu->wq, &wait);
+
+	/*
+	 * We will block until either an interrupt or a signal wakes us
up
+	 */
+	while(!(irqchip_in_kernel(vcpu->kvm) &&
kvm_cpu_has_interrupt(vcpu))
+	      && !vcpu->irq_summary
+	      && !signal_pending(current)) {
+		set_current_state(TASK_INTERRUPTIBLE);
+		vcpu_put(vcpu);
+		schedule();
+		vcpu_load(vcpu);
+	}
+
+	remove_wait_queue(&vcpu->wq, &wait);
+	set_current_state(TASK_RUNNING);
+}
 
-	vcpu->run->exit_reason = KVM_EXIT_HLT;
+int kvm_emulate_halt(struct kvm_vcpu *vcpu)
+{
 	++vcpu->stat.halt_exits;
-	return 0;
+	kvm_vcpu_kernel_halt(vcpu);
+	return 1;
 }
 EXPORT_SYMBOL_GPL(kvm_emulate_halt);
 

[-- Attachment #2: pic-hlt2.patch --]
[-- Type: application/octet-stream, Size: 2854 bytes --]

diff --git a/drivers/kvm/i8259.c b/drivers/kvm/i8259.c
index f4ae5f7..e84e665 100644
--- a/drivers/kvm/i8259.c
+++ b/drivers/kvm/i8259.c
@@ -411,8 +411,13 @@ static void picdev_read(struct kvm_io_device *this,
 static void pic_irq_request(void *opaque, int level)
 {
 	struct kvm *kvm = opaque;
+	struct kvm_vcpu *vcpu = &kvm->vcpus[0];
 
 	pic_irqchip(kvm)->output = level;
+	if (waitqueue_active(&vcpu->wq)) {
+		wake_up_interruptible(&vcpu->wq);
+		++vcpu->stat.halt_wakeup;
+	}
 }
 
 struct kvm_pic *kvm_create_pic(struct kvm *kvm)
diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
index f1a6773..1d1ee4f 100644
--- a/drivers/kvm/kvm.h
+++ b/drivers/kvm/kvm.h
@@ -260,6 +260,7 @@ struct kvm_stat {
 	u32 signal_exits;
 	u32 irq_window_exits;
 	u32 halt_exits;
+	u32 halt_wakeup;
 	u32 request_irq_exits;
 	u32 irq_exits;
 	u32 light_exits;
@@ -399,6 +400,7 @@ struct kvm_vcpu {
 	gva_t mmio_fault_cr2;
 	struct kvm_pio_request pio;
 	void *pio_data;
+	wait_queue_head_t wq;
 
 	int sigset_active;
 	sigset_t sigset;
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index 06e5804..18da363 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -74,6 +74,7 @@ static struct kvm_stats_debugfs_item {
 	{ "signal_exits", STAT_OFFSET(signal_exits) },
 	{ "irq_window", STAT_OFFSET(irq_window_exits) },
 	{ "halt_exits", STAT_OFFSET(halt_exits) },
+	{ "halt_wakeup", STAT_OFFSET(halt_wakeup) },
 	{ "request_irq", STAT_OFFSET(request_irq_exits) },
 	{ "irq_exits", STAT_OFFSET(irq_exits) },
 	{ "light_exits", STAT_OFFSET(light_exits) },
@@ -326,6 +327,7 @@ static struct kvm *kvm_create_vm(void)
 		vcpu->cpu = -1;
 		vcpu->kvm = kvm;
 		vcpu->mmu.root_hpa = INVALID_PAGE;
+		init_waitqueue_head(&vcpu->wq);
 	}
 	return kvm;
 }
@@ -1324,15 +1326,36 @@ int emulate_instruction(struct kvm_vcpu *vcpu,
 }
 EXPORT_SYMBOL_GPL(emulate_instruction);
 
-int kvm_emulate_halt(struct kvm_vcpu *vcpu)
+/*
+ * The vCPU has executed a HLT instruction with in-kernel mode enabled.
+ */
+static void kvm_vcpu_kernel_halt(struct kvm_vcpu *vcpu)
 {
-	if (vcpu->irq_summary ||
-		(irqchip_in_kernel(vcpu->kvm) && kvm_cpu_has_interrupt(vcpu)))
-		return 1;
+	DECLARE_WAITQUEUE(wait, current);
+
+	add_wait_queue(&vcpu->wq, &wait);
+
+	/*
+	 * We will block until either an interrupt or a signal wakes us up
+	 */
+	while(!(irqchip_in_kernel(vcpu->kvm) && kvm_cpu_has_interrupt(vcpu))
+	      && !vcpu->irq_summary
+	      && !signal_pending(current)) {
+		set_current_state(TASK_INTERRUPTIBLE);
+		vcpu_put(vcpu);
+		schedule();
+		vcpu_load(vcpu);
+	}
+
+	remove_wait_queue(&vcpu->wq, &wait);
+	set_current_state(TASK_RUNNING);
+}
 
-	vcpu->run->exit_reason = KVM_EXIT_HLT;
+int kvm_emulate_halt(struct kvm_vcpu *vcpu)
+{
 	++vcpu->stat.halt_exits;
-	return 0;
+	kvm_vcpu_kernel_halt(vcpu);
+	return 1;
 }
 EXPORT_SYMBOL_GPL(kvm_emulate_halt);
 

[-- Attachment #3: Type: text/plain, Size: 286 bytes --]

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/

[-- Attachment #4: Type: text/plain, Size: 186 bytes --]

_______________________________________________
kvm-devel mailing list
kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/kvm-devel

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

end of thread, other threads:[~2007-07-12 15:34 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-07-12 14:45 rebase hlt emulation Gregory Haskins
     [not found] ` <4696065E0200005A0002766F-Igcdv/6uVdMHoYOw/+koYqIwWpluYiW7@public.gmane.org>
2007-07-12 14:54   ` Dong, Eddie
     [not found]     ` <10EA09EFD8728347A513008B6B0DA77A01C24C36-wq7ZOvIWXbNpB2pF5aRoyrfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2007-07-12 15:00       ` Avi Kivity
     [not found]         ` <469641FF.2090408-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-07-12 15:34           ` Dong, Eddie
  -- strict thread matches above, loose matches on Subject: below --
2007-07-12  9:31 Gregory Haskins
     [not found] ` <4695BCA50200005A000275FE-Igcdv/6uVdMHoYOw/+koYqIwWpluYiW7@public.gmane.org>
2007-07-12  9:53   ` Avi Kivity
2007-07-07  4:42 Dong, Eddie
     [not found] ` <10EA09EFD8728347A513008B6B0DA77A01B8F3F3-wq7ZOvIWXbNpB2pF5aRoyrfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2007-07-12  5:33   ` Dong, Eddie
     [not found]     ` <10EA09EFD8728347A513008B6B0DA77A01C249B6-wq7ZOvIWXbNpB2pF5aRoyrfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2007-07-12  9:51       ` Avi Kivity
     [not found]         ` <4695F9BF.9000301-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-07-12 14:20           ` Dong, Eddie

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox