public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] kvm tools: Extract kvm_cpu__start() function
@ 2011-04-09 10:51 Pekka Enberg
  2011-04-09 10:51 ` [PATCH 2/2] kvm tools: Move CPU initialization to kvm_cpu__start() Pekka Enberg
  0 siblings, 1 reply; 2+ messages in thread
From: Pekka Enberg @ 2011-04-09 10:51 UTC (permalink / raw)
  To: kvm; +Cc: Pekka Enberg, Asias He, Cyrill Gorcunov, Ingo Molnar

In preparation for threaded execution, separate kvm_cpu__start() function so it
can be reused for multiple threads.

Cc: Asias He <asias.hejun@gmail.com>
Cc: Cyrill Gorcunov <gorcunov@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
---
 tools/kvm/include/kvm/kvm-cpu.h |    1 +
 tools/kvm/kvm-cpu.c             |   59 +++++++++++++++++++++++++++++++++++++++
 tools/kvm/kvm-run.c             |   51 ++-------------------------------
 3 files changed, 63 insertions(+), 48 deletions(-)

diff --git a/tools/kvm/include/kvm/kvm-cpu.h b/tools/kvm/include/kvm/kvm-cpu.h
index d36dadf..b4e2134 100644
--- a/tools/kvm/include/kvm/kvm-cpu.h
+++ b/tools/kvm/include/kvm/kvm-cpu.h
@@ -25,6 +25,7 @@ void kvm_cpu__reset_vcpu(struct kvm_cpu *self);
 void kvm_cpu__setup_cpuid(struct kvm_cpu *self);
 void kvm_cpu__enable_singlestep(struct kvm_cpu *self);
 void kvm_cpu__run(struct kvm_cpu *self);
+int kvm_cpu__start(struct kvm_cpu *cpu);
 
 void kvm_cpu__show_code(struct kvm_cpu *self);
 void kvm_cpu__show_registers(struct kvm_cpu *self);
diff --git a/tools/kvm/kvm-cpu.c b/tools/kvm/kvm-cpu.c
index 374adb2..392fad3 100644
--- a/tools/kvm/kvm-cpu.c
+++ b/tools/kvm/kvm-cpu.c
@@ -1,5 +1,7 @@
 #include "kvm/kvm-cpu.h"
 
+#include "kvm/virtio-console.h"
+#include "kvm/8250-serial.h"
 #include "kvm/util.h"
 #include "kvm/kvm.h"
 
@@ -368,3 +370,60 @@ void kvm_cpu__run(struct kvm_cpu *self)
 	if (err && (errno != EINTR && errno != EAGAIN))
 		die_perror("KVM_RUN failed");
 }
+
+int kvm_cpu__start(struct kvm_cpu *cpu)
+{
+	for (;;) {
+		kvm_cpu__run(cpu);
+
+		switch (cpu->kvm_run->exit_reason) {
+		case KVM_EXIT_DEBUG:
+			kvm_cpu__show_registers(cpu);
+			kvm_cpu__show_code(cpu);
+			break;
+		case KVM_EXIT_IO: {
+			bool ret;
+
+			ret = kvm__emulate_io(cpu->kvm,
+					cpu->kvm_run->io.port,
+					(uint8_t *)cpu->kvm_run +
+					cpu->kvm_run->io.data_offset,
+					cpu->kvm_run->io.direction,
+					cpu->kvm_run->io.size,
+					cpu->kvm_run->io.count);
+
+			if (!ret)
+				goto panic_kvm;
+			break;
+		}
+		case KVM_EXIT_MMIO: {
+			bool ret;
+
+			ret = kvm__emulate_mmio(cpu->kvm,
+					cpu->kvm_run->mmio.phys_addr,
+					cpu->kvm_run->mmio.data,
+					cpu->kvm_run->mmio.len,
+					cpu->kvm_run->mmio.is_write);
+
+			if (!ret)
+				goto panic_kvm;
+			break;
+		}
+		case KVM_EXIT_INTR: {
+			serial8250__inject_interrupt(cpu->kvm);
+			virtio_console__inject_interrupt(cpu->kvm);
+			break;
+		}
+		case KVM_EXIT_SHUTDOWN:
+			goto exit_kvm;
+		default:
+			goto panic_kvm;
+		}
+	}
+
+exit_kvm:
+	return 0;
+
+panic_kvm:
+	return 1;
+}
diff --git a/tools/kvm/kvm-run.c b/tools/kvm/kvm-run.c
index 9392818..9a0400b 100644
--- a/tools/kvm/kvm-run.c
+++ b/tools/kvm/kvm-run.c
@@ -177,54 +177,9 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix)
 
 	kvm__start_timer(kvm);
 
-	for (;;) {
-		kvm_cpu__run(cpu);
-
-		switch (cpu->kvm_run->exit_reason) {
-		case KVM_EXIT_DEBUG:
-			kvm_cpu__show_registers(cpu);
-			kvm_cpu__show_code(cpu);
-			break;
-		case KVM_EXIT_IO: {
-			bool ret;
-
-			ret = kvm__emulate_io(kvm,
-					cpu->kvm_run->io.port,
-					(uint8_t *)cpu->kvm_run +
-					cpu->kvm_run->io.data_offset,
-					cpu->kvm_run->io.direction,
-					cpu->kvm_run->io.size,
-					cpu->kvm_run->io.count);
-
-			if (!ret)
-				goto panic_kvm;
-			break;
-		}
-		case KVM_EXIT_MMIO: {
-			bool ret;
-
-			ret = kvm__emulate_mmio(kvm,
-					cpu->kvm_run->mmio.phys_addr,
-					cpu->kvm_run->mmio.data,
-					cpu->kvm_run->mmio.len,
-					cpu->kvm_run->mmio.is_write);
-
-			if (!ret)
-				goto panic_kvm;
-			break;
-		}
-		case KVM_EXIT_INTR: {
-			serial8250__inject_interrupt(kvm);
-			virtio_console__inject_interrupt(kvm);
-			break;
-		}
-		case KVM_EXIT_SHUTDOWN:
-			goto exit_kvm;
-		default:
-			goto panic_kvm;
-		}
-	}
-exit_kvm:
+	if (kvm_cpu__start(cpu))
+		goto panic_kvm;
+
 	disk_image__close(kvm->disk_image);
 	kvm__delete(kvm);
 
-- 
1.7.0.4


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

* [PATCH 2/2] kvm tools: Move CPU initialization to kvm_cpu__start()
  2011-04-09 10:51 [PATCH 1/2] kvm tools: Extract kvm_cpu__start() function Pekka Enberg
@ 2011-04-09 10:51 ` Pekka Enberg
  0 siblings, 0 replies; 2+ messages in thread
From: Pekka Enberg @ 2011-04-09 10:51 UTC (permalink / raw)
  To: kvm; +Cc: Pekka Enberg, Asias He, Cyrill Gorcunov, Ingo Molnar

Move CPUID setup and CPU reset code to kvm_cpu__start() so that CPU state is
setup in one place.

Cc: Asias He <asias.hejun@gmail.com>
Cc: Cyrill Gorcunov <gorcunov@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
---
 tools/kvm/kvm-cpu.c |    3 +++
 tools/kvm/kvm-run.c |   10 +++-------
 2 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/tools/kvm/kvm-cpu.c b/tools/kvm/kvm-cpu.c
index 392fad3..4cbe597 100644
--- a/tools/kvm/kvm-cpu.c
+++ b/tools/kvm/kvm-cpu.c
@@ -373,6 +373,9 @@ void kvm_cpu__run(struct kvm_cpu *self)
 
 int kvm_cpu__start(struct kvm_cpu *cpu)
 {
+	kvm_cpu__setup_cpuid(cpu);
+	kvm_cpu__reset_vcpu(cpu);
+
 	for (;;) {
 		kvm_cpu__run(cpu);
 
diff --git a/tools/kvm/kvm-run.c b/tools/kvm/kvm-run.c
index 9a0400b..8a9747b 100644
--- a/tools/kvm/kvm-run.c
+++ b/tools/kvm/kvm-run.c
@@ -143,8 +143,6 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix)
 			die("unable to load disk image %s", image_filename);
 	}
 
-	kvm_cpu__setup_cpuid(cpu);
-
 	strcpy(real_cmdline, "notsc nolapic noacpi pci=conf1 console=ttyS0 ");
 	if (!kernel_cmdline || !strstr(kernel_cmdline, "root=")) {
 		strlcat(real_cmdline, "root=/dev/vda rw ",
@@ -160,13 +158,8 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix)
 				real_cmdline))
 		die("unable to load kernel %s", kernel_filename);
 
-	kvm_cpu__reset_vcpu(cpu);
-
 	kvm__setup_bios(kvm);
 
-	if (single_step)
-		kvm_cpu__enable_singlestep(cpu);
-
 	serial8250__init(kvm);
 
 	pci__init();
@@ -177,6 +170,9 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix)
 
 	kvm__start_timer(kvm);
 
+	if (single_step)
+		kvm_cpu__enable_singlestep(cpu);
+
 	if (kvm_cpu__start(cpu))
 		goto panic_kvm;
 
-- 
1.7.0.4


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

end of thread, other threads:[~2011-04-09 10:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-04-09 10:51 [PATCH 1/2] kvm tools: Extract kvm_cpu__start() function Pekka Enberg
2011-04-09 10:51 ` [PATCH 2/2] kvm tools: Move CPU initialization to kvm_cpu__start() Pekka Enberg

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