Skip to contentSkip to conversation

kvm tools: Extract kvm_cpu__start() function

PATCH New Pekka Enberg 1 participant 2 messages Apr 9, 2011 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 kvm tools: Extract kvm_cpu__start() function

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

Cc Asias He <[email protected]>
Cc Cyrill Gorcunov <[email protected]>
Cc Ingo Molnar <[email protected]>
---
 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(-)
tools/kvm/include/kvm/kvm-cpu.h +1 -0
index d36dadf..b4e2134 100644
@@ -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);
tools/kvm/kvm-cpu.c +59 -0

67 lines not on this page · raw message

tools/kvm/kvm-run.c +3 -48

57 lines not on this page · raw message

Signature · 1 line
1.7.0.4
#1 lore raw

PATCH 2/2 kvm tools: Move CPU initialization to kvm_cpu__start()

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

Cc Asias He <[email protected]>
Cc Cyrill Gorcunov <[email protected]>
Cc Ingo Molnar <[email protected]>
---
 tools/kvm/kvm-cpu.c |    3 +++
 tools/kvm/kvm-run.c |   10 +++-------
 2 files changed, 6 insertions(+), 7 deletions(-)
tools/kvm/kvm-cpu.c +3 -0
index 392fad3..4cbe597 100644
@@ -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);
 
tools/kvm/kvm-run.c +3 -7
index 9a0400b..8a9747b 100644
@@ -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;
 
Signature · 1 line
1.7.0.4