From: "Jun Koi" Subject: Re: [kvm-commits] kvm: kvmctl: create secondary vcpus Date: Tue, 5 Jun 2007 17:49:51 +0900 Message-ID: References: <20070605072901.DF7EF25016C@il.qumranet.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Cc: kvm-devel To: "Avi Kivity" Return-path: In-Reply-To: <20070605072901.DF7EF25016C-LjA0eNSCdXrQnzwC+xcbyw@public.gmane.org> Content-Disposition: inline List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: kvm-devel-bounces-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org Errors-To: kvm-devel-bounces-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org List-Id: kvm.vger.kernel.org So now we can have SMP guest with KVM? Great! One thing I dont understand: I dont see where you unlock vcpu[n].sipi_sem? Thanks, Jun On 6/5/07, Avi Kivity wrote: > repository: /home/avi/kvm > branch: master > commit 61f2f77a6f11a08f06134c03e083713c78765509 > Author: Avi Kivity > Date: Mon Jun 4 19:04:14 2007 +0300 > > kvm: kvmctl: create secondary vcpus > > diff --git a/user/Makefile b/user/Makefile > index dc5b5a6..6050bf9 100644 > --- a/user/Makefile > +++ b/user/Makefile > @@ -32,6 +32,8 @@ endif > > all: kvmctl libkvm.a flatfiles > > +kvmctl: LDFLAGS += -pthread -lrt > + > kvmctl: kvmctl.o main.o > > balloon_ctl: balloon_ctl.o > diff --git a/user/main.c b/user/main.c > index 41fc288..2e0a41f 100644 > --- a/user/main.c > +++ b/user/main.c > @@ -21,9 +21,33 @@ > #include > #include > #include > +#include > +#include > +#include > +#include > +#include > +#include > + > + > +static int gettid(void) > +{ > + return syscall(__NR_gettid); > +} > > kvm_context_t kvm; > > +#define MAX_VCPUS 4 > + > +static int ncpus = 1; > +static sem_t init_sem; > + > +struct vcpu_info { > + pid_t tid; > + sem_t sipi_sem; > +}; > + > +struct vcpu_info *vcpus; > + > static int test_inb(void *opaque, uint16_t addr, uint8_t *value) > { > printf("inb 0x%x\n", addr); > @@ -171,6 +195,33 @@ static void enter_32(kvm_context_t kvm) > kvm_set_sregs(kvm, 0, &sregs); > } > > +static void init_vcpu(int n) > +{ > + vcpus[n].tid = gettid(); > + sem_post(&init_sem); > +} > + > +static void *do_create_vcpu(void *_n) > +{ > + int n = (long)_n; > + > + kvm_create_vcpu(kvm, n); > + init_vcpu(n); > + printf("vcpu %d: waiting for sipi\n", n); > + sem_wait(&vcpus[n].sipi_sem); > + printf("vcpu %d: running\n", n); > + kvm_run(kvm, n); > + return NULL; > +} > + > +static void start_vcpu(int n) > +{ > + pthread_t thread; > + > + sem_init(&vcpus[n].sipi_sem, 0, 0); > + pthread_create(&thread, NULL, do_create_vcpu, (void *)(long)n); > +} > + > const char *progname; > > static void usage() > @@ -191,7 +242,7 @@ static int isarg(const char *arg, const char *longform, const char *shortform) > int main(int ac, char **av) > { > void *vm_mem; > - int ncpus = 1; > + int i; > > progname = av[0]; > while (ac > 1 && av[1][0] =='-') { > @@ -207,6 +258,12 @@ int main(int ac, char **av) > ++av, --ac; > } > > + vcpus = calloc(ncpus, sizeof *vcpus); > + if (!vcpus) { > + fprintf(stderr, "calloc failed\n"); > + return 1; > + } > + > kvm = kvm_init(&test_callbacks, 0); > if (!kvm) { > fprintf(stderr, "kvm_init failed\n"); > @@ -226,6 +283,12 @@ int main(int ac, char **av) > if (ac > 2) > load_file(vm_mem + 0x100000, av[2]); > > + sem_init(&init_sem, 0, 1 - ncpus); > + init_vcpu(0); > + for (i = 1; i < ncpus; ++i) > + start_vcpu(i); > + sem_wait(&init_sem); > + > kvm_run(kvm, 0); > > return 0; > > ------------------------------------------------------------------------- > 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/ > _______________________________________________ > kvm-commits mailing list > kvm-commits-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org > https://lists.sourceforge.net/lists/listinfo/kvm-commits > ------------------------------------------------------------------------- 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/