From patchwork Wed Sep 16 09:26:05 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avi Kivity X-Patchwork-Id: 47897 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n8G9R8xH009794 for ; Wed, 16 Sep 2009 09:27:08 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758328AbZIPJ1A (ORCPT ); Wed, 16 Sep 2009 05:27:00 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1758386AbZIPJ07 (ORCPT ); Wed, 16 Sep 2009 05:26:59 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50507 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758369AbZIPJ0M (ORCPT ); Wed, 16 Sep 2009 05:26:12 -0400 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n8G9QGjV010901 for ; Wed, 16 Sep 2009 05:26:16 -0400 Received: from cleopatra.tlv.redhat.com (cleopatra.tlv.redhat.com [10.35.255.11]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n8G9QD7j005533; Wed, 16 Sep 2009 05:26:15 -0400 Received: from localhost.localdomain (cleopatra.tlv.redhat.com [10.35.255.11]) by cleopatra.tlv.redhat.com (Postfix) with ESMTP id 2D73425004D; Wed, 16 Sep 2009 12:26:12 +0300 (IDT) From: Avi Kivity To: Marcelo Tosatti Cc: kvm@vger.kernel.org Subject: [PATCH QEMU-KVM 30/34] test: port smp runtime to real apic Date: Wed, 16 Sep 2009 12:26:05 +0300 Message-Id: <1253093169-1423-31-git-send-email-avi@redhat.com> In-Reply-To: <1253093169-1423-1-git-send-email-avi@redhat.com> References: <1253093169-1423-1-git-send-email-avi@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.17 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org instead of the old fake apic. Signed-off-by: Avi Kivity --- kvm/user/test/lib/x86/smp.c | 68 ++++++------------------------------------- kvm/user/test/lib/x86/smp.h | 2 +- kvm/user/test/x86/smptest.c | 10 +----- 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 92ebada..a3a5472 100644 --- a/kvm/user/test/lib/x86/smp.c +++ b/kvm/user/test/lib/x86/smp.c @@ -1,46 +1,11 @@ #include #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 bcf76a3..bac7e14 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 7b1ba49..3780599 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)