From patchwork Mon Sep 21 08:55:34 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avi Kivity X-Patchwork-Id: 49007 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 n8L8tjRT027884 for ; Mon, 21 Sep 2009 08:55:45 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755411AbZIUIzj (ORCPT ); Mon, 21 Sep 2009 04:55:39 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1755454AbZIUIzi (ORCPT ); Mon, 21 Sep 2009 04:55:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:6314 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755397AbZIUIzh (ORCPT ); Mon, 21 Sep 2009 04:55:37 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n8L8tfsd029950 for ; Mon, 21 Sep 2009 04:55:41 -0400 Received: from cleopatra.tlv.redhat.com (cleopatra.tlv.redhat.com [10.35.255.11]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n8L8tdSu029407; Mon, 21 Sep 2009 04:55:40 -0400 Received: from localhost.localdomain (cleopatra.tlv.redhat.com [10.35.255.11]) by cleopatra.tlv.redhat.com (Postfix) with ESMTP id D610C250050; Mon, 21 Sep 2009 11:55:38 +0300 (IDT) From: Avi Kivity To: kvm@vger.kernel.org Cc: Marcelo Tosatti Subject: [PATCH QEMU-KVM 3/7] test: optimize smp_id() Date: Mon, 21 Sep 2009 11:55:34 +0300 Message-Id: <1253523338-22784-4-git-send-email-avi@redhat.com> In-Reply-To: <1253523338-22784-1-git-send-email-avi@redhat.com> References: <1253523338-22784-1-git-send-email-avi@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Rather than reading it from the APIC, read it from the per-cpu area. Signed-off-by: Avi Kivity --- kvm/user/test/lib/x86/smp.c | 17 +++++++++++++++-- 1 files changed, 15 insertions(+), 2 deletions(-) diff --git a/kvm/user/test/lib/x86/smp.c b/kvm/user/test/lib/x86/smp.c index 25f0cae..9eface5 100644 --- a/kvm/user/test/lib/x86/smp.c +++ b/kvm/user/test/lib/x86/smp.c @@ -71,13 +71,21 @@ int cpu_count(void) int smp_id(void) { - return apic_read(APIC_ID); + unsigned id; + + asm ("mov %%gs:0, %0" : "=r"(id)); + return id; +} + +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) { spin_lock(&ipi_lock); - if (cpu == apic_id()) + if (cpu == smp_id()) function(data); else { ipi_function = function; @@ -98,4 +106,9 @@ void smp_init(void) void ipi_entry(void); set_ipi_descriptor(ipi_entry); + + setup_smp_id(0); + for (i = 1; i < cpu_count(); ++i) + on_cpu(i, setup_smp_id, 0); + }