summaryrefslogtreecommitdiff
path: root/kvm
diff options
context:
space:
mode:
authorAvi Kivity <avi@redhat.com>2009-09-16 12:26:05 +0300
committerMarcelo Tosatti <mtosatti@redhat.com>2009-09-16 16:00:53 -0300
commit175dcb6b50c0711025c9494e8324be423e9efb74 (patch)
treef3a6faacb70d84686d8be370937ead38a89fddda /kvm
parenttest: wait for all processors to complete initialization (diff)
downloadqemu-kvm-175dcb6b50c0711025c9494e8324be423e9efb74.tar.gz
qemu-kvm-175dcb6b50c0711025c9494e8324be423e9efb74.tar.bz2
qemu-kvm-175dcb6b50c0711025c9494e8324be423e9efb74.zip
test: port smp runtime to real apic
instead of the old fake apic. Signed-off-by: Avi Kivity <avi@redhat.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Diffstat (limited to 'kvm')
-rw-r--r--kvm/user/test/lib/x86/smp.c68
-rw-r--r--kvm/user/test/lib/x86/smp.h2
-rw-r--r--kvm/user/test/x86/smptest.c10
3 files changed, 12 insertions, 68 deletions
diff --git a/kvm/user/test/lib/x86/smp.c b/kvm/user/test/lib/x86/smp.c
index 92ebada77..a3a5472dd 100644
--- a/kvm/user/test/lib/x86/smp.c
+++ b/kvm/user/test/lib/x86/smp.c
@@ -1,46 +1,11 @@
#include <libcflat.h>
#include "smp.h"
-#include "fake-apic.h"
+#include "apic.h"
+#include "fwcfg.h"
#define IPI_VECTOR 0x20
-static int apic_read(int reg)
-{
- unsigned short port = APIC_BASE + reg;
- unsigned v;
-
- asm volatile ("in %1, %0" : "=a"(v) : "d"(port));
- return v;
-}
-
-static void apic_write(int reg, unsigned v)
-{
- unsigned short port = APIC_BASE + reg;
-
- asm volatile ("out %0, %1" : : "a"(v), "d"(port));
-}
-
-static int apic_get_cpu_count()
-{
- return apic_read(APIC_REG_NCPU);
-}
-
-static int apic_get_id()
-{
- return apic_read(APIC_REG_ID);
-}
-
-static void apic_set_ipi_vector(int vector)
-{
- apic_write(APIC_REG_IPI_VECTOR, vector);
-}
-
-static void apic_send_ipi(int cpu)
-{
- apic_write(APIC_REG_SEND_IPI, cpu);
-}
-
static struct spinlock ipi_lock;
static void (*ipi_function)(void *data);
static void *ipi_data;
@@ -100,23 +65,25 @@ void spin_unlock(struct spinlock *lock)
int cpu_count(void)
{
- return apic_get_cpu_count();
+ return fwcfg_get_nb_cpus();
}
int smp_id(void)
{
- return apic_get_id();
+ return apic_read(APIC_ID);
}
void on_cpu(int cpu, void (*function)(void *data), void *data)
{
spin_lock(&ipi_lock);
- if (cpu == apic_get_id())
+ if (cpu == apic_id())
function(data);
else {
ipi_function = function;
ipi_data = data;
- apic_send_ipi(cpu);
+ apic_icr_write(APIC_INT_ASSERT | APIC_DEST_PHYSICAL | APIC_DM_FIXED
+ | IPI_VECTOR,
+ cpu);
while (!ipi_done)
;
ipi_done = 0;
@@ -124,27 +91,10 @@ void on_cpu(int cpu, void (*function)(void *data), void *data)
spin_unlock(&ipi_lock);
}
-static void (*smp_main_func)(void);
-static volatile int smp_main_running;
-
-asm ("smp_init_entry: \n"
- "incl smp_main_running \n"
- "sti \n"
- "call *smp_main_func");
-
-void smp_init(void (*smp_main)(void))
+void smp_init(void)
{
int i;
- void smp_init_entry(void);
void ipi_entry(void);
- apic_set_ipi_vector(IPI_VECTOR);
- set_ipi_descriptor(smp_init_entry);
- smp_main_func = smp_main;
- for (i = 1; i < cpu_count(); ++i) {
- apic_send_ipi(i);
- while (smp_main_running < i)
- ;
- }
set_ipi_descriptor(ipi_entry);
}
diff --git a/kvm/user/test/lib/x86/smp.h b/kvm/user/test/lib/x86/smp.h
index bcf76a357..bac7e1478 100644
--- a/kvm/user/test/lib/x86/smp.h
+++ b/kvm/user/test/lib/x86/smp.h
@@ -5,7 +5,7 @@ struct spinlock {
int v;
};
-void smp_init(void (*smp_main)(void));
+void smp_init(void);
int cpu_count(void);
int smp_id(void);
diff --git a/kvm/user/test/x86/smptest.c b/kvm/user/test/x86/smptest.c
index 7b1ba498b..37805999b 100644
--- a/kvm/user/test/x86/smptest.c
+++ b/kvm/user/test/x86/smptest.c
@@ -10,19 +10,13 @@ static void ipi_test(void *data)
printf("but wrong cpu %d\n", smp_id());
}
-static void smp_main(void)
-{
- printf("smp main %d\n", smp_id());
- while (1)
- asm volatile ("hlt" : : : "memory");
-}
-
int main()
{
int ncpus;
int i;
- smp_init(smp_main);
+ smp_init();
+
ncpus = cpu_count();
printf("found %d cpus\n", ncpus);
for (i = 0; i < ncpus; ++i)