diff mbox

[1/2] test: add wait parameter to on_cpu

Message ID 20090928112247.375362302@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Marcelo Tosatti Sept. 28, 2009, 11:22 a.m. UTC
To determine whether to wait for IPI to finish on remote cpu.

Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>



--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Avi Kivity Sept. 29, 2009, 8:32 a.m. UTC | #1
On 09/28/2009 01:22 PM, Marcelo Tosatti wrote:
> To determine whether to wait for IPI to finish on remote cpu.
>
> Signed-off-by: Marcelo Tosatti<mtosatti@redhat.com>
>
> Index: qemu-kvm/kvm/user/test/lib/x86/smp.c
> ===================================================================
> --- qemu-kvm.orig/kvm/user/test/lib/x86/smp.c
> +++ qemu-kvm/kvm/user/test/lib/x86/smp.c
> @@ -82,7 +82,7 @@ static void setup_smp_id(void *data)
>       asm ("mov %0, %%gs:0" : : "r"(apic_id()) : "memory");
>   }
>
> -void on_cpu(int cpu, void (*function)(void *data), void *data)
> +void on_cpu(int cpu, void (*function)(void *data), void *data, int wait)
>   {
>       spin_lock(&ipi_lock);
>       if (cpu == smp_id())
> @@ -93,9 +93,11 @@ void on_cpu(int cpu, void (*function)(vo
>   	apic_icr_write(APIC_INT_ASSERT | APIC_DEST_PHYSICAL | APIC_DM_FIXED
>                          | IPI_VECTOR,
>                          cpu);
> -	while (!ipi_done)
> -	    ;
> -	ipi_done = 0;
> +	if (wait) {
> +		while (!ipi_done)
> +		    ;
> +		ipi_done = 0;
> +	}
>       }
>       spin_unlock(&ipi_lock);
>   }
> @@ -109,6 +111,6 @@ void smp_init(void)
>
>       setup_smp_id(0);
>       for (i = 1; i<  cpu_count(); ++i)
> -        on_cpu(i, setup_smp_id, 0);
> +        on_cpu(i, setup_smp_id, 0, 1);
>
>   }
> Index: qemu-kvm/kvm/user/test/lib/x86/smp.h
> ===================================================================
> --- qemu-kvm.orig/kvm/user/test/lib/x86/smp.h
> +++ qemu-kvm/kvm/user/test/lib/x86/smp.h
> @@ -9,7 +9,7 @@ void smp_init(void);
>
>   int cpu_count(void);
>   int smp_id(void);
> -void on_cpu(int cpu, void (*function)(void *data), void *data);
> +void on_cpu(int cpu, void (*function)(void *data), void *data, int wait);
>   void spin_lock(struct spinlock *lock);
>   void spin_unlock(struct spinlock *lock);
>
> Index: qemu-kvm/kvm/user/test/x86/smptest.c
> ===================================================================
> --- qemu-kvm.orig/kvm/user/test/x86/smptest.c
> +++ qemu-kvm/kvm/user/test/x86/smptest.c
> @@ -20,6 +20,6 @@ int main()
>       ncpus = cpu_count();
>       printf("found %d cpus\n", ncpus);
>       for (i = 0; i<  ncpus; ++i)
> -	on_cpu(i, ipi_test, (void *)(long)i);
> +	on_cpu(i, ipi_test, (void *)(long)i, 1);
>       return 0;
>   }
> Index: qemu-kvm/kvm/user/test/x86/vmexit.c
> ===================================================================
> --- qemu-kvm.orig/kvm/user/test/x86/vmexit.c
> +++ qemu-kvm/kvm/user/test/x86/vmexit.c
> @@ -63,14 +63,14 @@ static void nop(void *junk)
>
>   static void ipi(void)
>   {
> -	on_cpu(1, nop, 0);
> +	on_cpu(1, nop, 0, 1);
>   }
>
>   static void ipi_halt(void)
>   {
>   	unsigned long long t;
>
> -	on_cpu(1, nop, 0);
> +	on_cpu(1, nop, 0, 1);
>   	t = rdtsc() + 2000;
>   	while (rdtsc()<  t)
>   		;
>
>    

Boolean parameters are unreadable at the call site.  I'd much prefer a 
new API (on_cpu_async(), with on_cpu_join() to wait for completion).
diff mbox

Patch

Index: qemu-kvm/kvm/user/test/lib/x86/smp.c
===================================================================
--- qemu-kvm.orig/kvm/user/test/lib/x86/smp.c
+++ qemu-kvm/kvm/user/test/lib/x86/smp.c
@@ -82,7 +82,7 @@  static void setup_smp_id(void *data)
     asm ("mov %0, %%gs:0" : : "r"(apic_id()) : "memory");
 }
 
-void on_cpu(int cpu, void (*function)(void *data), void *data)
+void on_cpu(int cpu, void (*function)(void *data), void *data, int wait)
 {
     spin_lock(&ipi_lock);
     if (cpu == smp_id())
@@ -93,9 +93,11 @@  void on_cpu(int cpu, void (*function)(vo
 	apic_icr_write(APIC_INT_ASSERT | APIC_DEST_PHYSICAL | APIC_DM_FIXED
                        | IPI_VECTOR,
                        cpu);
-	while (!ipi_done)
-	    ;
-	ipi_done = 0;
+	if (wait) {
+		while (!ipi_done)
+		    ;
+		ipi_done = 0;
+	}
     }
     spin_unlock(&ipi_lock);
 }
@@ -109,6 +111,6 @@  void smp_init(void)
 
     setup_smp_id(0);
     for (i = 1; i < cpu_count(); ++i)
-        on_cpu(i, setup_smp_id, 0);
+        on_cpu(i, setup_smp_id, 0, 1);
 
 }
Index: qemu-kvm/kvm/user/test/lib/x86/smp.h
===================================================================
--- qemu-kvm.orig/kvm/user/test/lib/x86/smp.h
+++ qemu-kvm/kvm/user/test/lib/x86/smp.h
@@ -9,7 +9,7 @@  void smp_init(void);
 
 int cpu_count(void);
 int smp_id(void);
-void on_cpu(int cpu, void (*function)(void *data), void *data);
+void on_cpu(int cpu, void (*function)(void *data), void *data, int wait);
 void spin_lock(struct spinlock *lock);
 void spin_unlock(struct spinlock *lock);
 
Index: qemu-kvm/kvm/user/test/x86/smptest.c
===================================================================
--- qemu-kvm.orig/kvm/user/test/x86/smptest.c
+++ qemu-kvm/kvm/user/test/x86/smptest.c
@@ -20,6 +20,6 @@  int main()
     ncpus = cpu_count();
     printf("found %d cpus\n", ncpus);
     for (i = 0; i < ncpus; ++i)
-	on_cpu(i, ipi_test, (void *)(long)i);
+	on_cpu(i, ipi_test, (void *)(long)i, 1);
     return 0;
 }
Index: qemu-kvm/kvm/user/test/x86/vmexit.c
===================================================================
--- qemu-kvm.orig/kvm/user/test/x86/vmexit.c
+++ qemu-kvm/kvm/user/test/x86/vmexit.c
@@ -63,14 +63,14 @@  static void nop(void *junk)
 
 static void ipi(void)
 {
-	on_cpu(1, nop, 0);
+	on_cpu(1, nop, 0, 1);
 }
 
 static void ipi_halt(void)
 {
 	unsigned long long t;
 
-	on_cpu(1, nop, 0);
+	on_cpu(1, nop, 0, 1);
 	t = rdtsc() + 2000;
 	while (rdtsc() < t)
 		;