* Re: [kvm-commits] kvm: kvmctl: create secondary vcpus
[not found] ` <20070604160414.8C1D125016C-LjA0eNSCdXrQnzwC+xcbyw@public.gmane.org>
@ 2007-06-05 2:30 ` Nguyen Anh Quynh
[not found] ` <9cde8bff0706041930q575311c1y8e8bdb61e31e42ba-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
0 siblings, 1 reply; 4+ messages in thread
From: Nguyen Anh Quynh @ 2007-06-05 2:30 UTC (permalink / raw)
To: Avi Kivity; +Cc: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f
Hi Avi,
Perhaps I miss something, but I dont see you initialize ncpus anywhere
in the patch?
Cheers,
Quynh
On 6/5/07, Avi Kivity <avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org> wrote:
> repository: /home/avi/kvm
> branch: master
> commit 9d02d1c4345c77ffbc95136c12011a112a8d1c7e
> Author: Avi Kivity <avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
> 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..f5b3838 100644
> --- a/user/main.c
> +++ b/user/main.c
> @@ -21,9 +21,33 @@
> #include <fcntl.h>
> #include <stdlib.h>
> #include <string.h>
> +#include <semaphore.h>
> +#include <sys/types.h>
> +#include <errno.h>
> +#include <pthread.h>
> +#include <sys/syscall.h>
> +#include <linux/unistd.h>
> +
> +
> +static int gettid(void)
> +{
> + return syscall(__NR_gettid);
> +}
>
> kvm_context_t kvm;
>
> +#define MAX_VCPUS 4
> +
> +static int ncpus;
> +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/
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [kvm-commits] kvm: kvmctl: create secondary vcpus
[not found] ` <9cde8bff0706041930q575311c1y8e8bdb61e31e42ba-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2007-06-05 7:29 ` Avi Kivity
0 siblings, 0 replies; 4+ messages in thread
From: Avi Kivity @ 2007-06-05 7:29 UTC (permalink / raw)
To: Nguyen Anh Quynh; +Cc: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f
Nguyen Anh Quynh wrote:
> Hi Avi,
>
> Perhaps I miss something, but I dont see you initialize ncpus anywhere
> in the patch?
>
Good catch. Fixed.
--
error compiling committee.c: too many arguments to function
-------------------------------------------------------------------------
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] 4+ messages in thread
* Re: [kvm-commits] kvm: kvmctl: create secondary vcpus
[not found] ` <20070605072901.DF7EF25016C-LjA0eNSCdXrQnzwC+xcbyw@public.gmane.org>
@ 2007-06-05 8:49 ` Jun Koi
[not found] ` <fdaac4d50706050149y2cb791b2ib8220dc628f2e1a0-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
0 siblings, 1 reply; 4+ messages in thread
From: Jun Koi @ 2007-06-05 8:49 UTC (permalink / raw)
To: Avi Kivity; +Cc: kvm-devel
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 <avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org> wrote:
> repository: /home/avi/kvm
> branch: master
> commit 61f2f77a6f11a08f06134c03e083713c78765509
> Author: Avi Kivity <avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
> 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 <fcntl.h>
> #include <stdlib.h>
> #include <string.h>
> +#include <semaphore.h>
> +#include <sys/types.h>
> +#include <errno.h>
> +#include <pthread.h>
> +#include <sys/syscall.h>
> +#include <linux/unistd.h>
> +
> +
> +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/
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [kvm-commits] kvm: kvmctl: create secondary vcpus
[not found] ` <fdaac4d50706050149y2cb791b2ib8220dc628f2e1a0-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2007-06-05 9:18 ` Avi Kivity
0 siblings, 0 replies; 4+ messages in thread
From: Avi Kivity @ 2007-06-05 9:18 UTC (permalink / raw)
To: Jun Koi; +Cc: kvm-devel
Jun Koi wrote:
> So now we can have SMP guest with KVM? Great!
>
It's not done yet.
> One thing I dont understand: I dont see where you unlock
> vcpu[n].sipi_sem?
>
That's still cooking. I've written small pseudo apic which can issue
the sipi.
--
error compiling committee.c: too many arguments to function
-------------------------------------------------------------------------
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] 4+ messages in thread
end of thread, other threads:[~2007-06-05 9:18 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20070604160414.8C1D125016C@il.qumranet.com>
[not found] ` <20070604160414.8C1D125016C-LjA0eNSCdXrQnzwC+xcbyw@public.gmane.org>
2007-06-05 2:30 ` [kvm-commits] kvm: kvmctl: create secondary vcpus Nguyen Anh Quynh
[not found] ` <9cde8bff0706041930q575311c1y8e8bdb61e31e42ba-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2007-06-05 7:29 ` Avi Kivity
[not found] <20070605072901.DF7EF25016C@il.qumranet.com>
[not found] ` <20070605072901.DF7EF25016C-LjA0eNSCdXrQnzwC+xcbyw@public.gmane.org>
2007-06-05 8:49 ` Jun Koi
[not found] ` <fdaac4d50706050149y2cb791b2ib8220dc628f2e1a0-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2007-06-05 9:18 ` Avi Kivity
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox