Skip to contentSkip to conversation

kvm tools: Use per-VCPU threads for execution

PATCH New Pekka Enberg 1 participant 1 message Apr 9, 2011 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kvm tools: Use per-VCPU threads for execution

This patch makes the core hypervisor to use per-VCPU threads for execution.
NOTE: We only start one thread right now because we're unable to let the guest kernel know about more cores at the moment.

---
 tools/kvm/include/kvm/kvm-cpu.h |    7 +++-
 tools/kvm/kvm-cpu.c             |   21 +++++---
 tools/kvm/kvm-run.c             |   95 +++++++++++++++++++++++++++------------
 tools/kvm/kvm.c                 |   11 -----
 4 files changed, 85 insertions(+), 49 deletions(-)
tools/kvm/include/kvm/kvm-cpu.h +6 -1
index b4e2134..0d0881e 100644
@@ -3,11 +3,16 @@
 
 #include <linux/kvm.h>	/* for struct kvm_regs */
 
+#include <pthread.h>
 #include <stdint.h>
 
 struct kvm;
 
 struct kvm_cpu {
+	pthread_t		thread;		/* VCPU thread */
+
+	unsigned long		cpu_id;
+
 	struct kvm		*kvm;		/* parent KVM */
 	int			vcpu_fd;	/* For VCPU ioctls() */
 	struct kvm_run		*kvm_run;
@@ -19,7 +24,7 @@ struct kvm_cpu {
 	struct kvm_msrs		*msrs;		/* dynamically allocated */
 };
 
-struct kvm_cpu *kvm_cpu__init(struct kvm *kvm);
+struct kvm_cpu *kvm_cpu__init(struct kvm *kvm, unsigned long cpu_id);
 void kvm_cpu__delete(struct kvm_cpu *self);
 void kvm_cpu__reset_vcpu(struct kvm_cpu *self);
 void kvm_cpu__setup_cpuid(struct kvm_cpu *self);
tools/kvm/kvm-cpu.c +13 -8
index 4cbe597..dc40b42 100644
@@ -1,12 +1,11 @@
 #include "kvm/kvm-cpu.h"
 
-#include "kvm/virtio-console.h"
-#include "kvm/8250-serial.h"
 #include "kvm/util.h"
 #include "kvm/kvm.h"
 
 #include <sys/ioctl.h>
 #include <sys/mman.h>
+#include <signal.h>
 #include <stdlib.h>
 #include <errno.h>
 #include <stdio.h>
@@ -61,7 +60,7 @@ void kvm_cpu__delete(struct kvm_cpu *self)
 	free(self);
 }
 
-struct kvm_cpu *kvm_cpu__init(struct kvm *kvm)
+struct kvm_cpu *kvm_cpu__init(struct kvm *kvm, unsigned long cpu_id)
 {
 	struct kvm_cpu *self;
 	int mmap_size;
@@ -70,7 +69,9 @@ struct kvm_cpu *kvm_cpu__init(struct kvm *kvm)
 	if (!self)
 		return NULL;
 
-	self->vcpu_fd = ioctl(self->kvm->vm_fd, KVM_CREATE_VCPU, 0);
+	self->cpu_id	= cpu_id;
+
+	self->vcpu_fd = ioctl(self->kvm->vm_fd, KVM_CREATE_VCPU, cpu_id);
 	if (self->vcpu_fd < 0)
 		die_perror("KVM_CREATE_VCPU ioctl");
 
@@ -373,6 +374,13 @@ void kvm_cpu__run(struct kvm_cpu *self)
 
 int kvm_cpu__start(struct kvm_cpu *cpu)
 {
+	sigset_t sigset;
+
+	sigemptyset(&sigset);
+	sigaddset(&sigset, SIGALRM);
+
+	pthread_sigmask(SIG_BLOCK, &sigset, NULL);
+
 	kvm_cpu__setup_cpuid(cpu);
 	kvm_cpu__reset_vcpu(cpu);
 
@@ -412,11 +420,8 @@ int kvm_cpu__start(struct kvm_cpu *cpu)
 				goto panic_kvm;
 			break;
 		}
-		case KVM_EXIT_INTR: {
-			serial8250__inject_interrupt(cpu->kvm);
-			virtio_console__inject_interrupt(cpu->kvm);
+		case KVM_EXIT_INTR:
 			break;
-		}
 		case KVM_EXIT_SHUTDOWN:
 			goto exit_kvm;
 		default:
tools/kvm/kvm-run.c +66 -29

142 lines not on this page · raw message

tools/kvm/kvm.c +0 -11
index 7ca4421..08ff63c 100644
@@ -412,10 +412,6 @@ void kvm__setup_bios(struct kvm *self)
 
 #define TIMER_INTERVAL_NS 1000000	/* 1 msec */
 
-static void alarm_handler(int sig)
-{
-}
-
 /*
  * This function sets up a timer that's used to inject interrupts from the
  * userspace hypervisor into the guest at periodical intervals. Please note
@@ -424,15 +420,8 @@ static void alarm_handler(int sig)
 void kvm__start_timer(struct kvm *self)
 {
 	struct itimerspec its;
-	struct sigaction sa;
 	struct sigevent sev;
 
-	sigfillset(&sa.sa_mask);
-	sa.sa_flags			= 0;
-	sa.sa_handler			= alarm_handler;
-
-	sigaction(SIGALRM, &sa, NULL);
-
 	memset(&sev, 0, sizeof(struct sigevent));
 	sev.sigev_value.sival_int	= 0;
 	sev.sigev_notify		= SIGEV_SIGNAL;
Signature · 1 line
1.7.0.4