From patchwork Wed Oct 3 13:29:07 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Habkost X-Patchwork-Id: 188787 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 560D22C00BC for ; Thu, 4 Oct 2012 00:32:08 +1000 (EST) Received: from localhost ([::1]:40503 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TJP16-0006eQ-9E for incoming@patchwork.ozlabs.org; Wed, 03 Oct 2012 09:29:36 -0400 Received: from eggs.gnu.org ([208.118.235.92]:37148) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TJP00-0004BK-9F for qemu-devel@nongnu.org; Wed, 03 Oct 2012 09:28:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TJOzt-0006bP-8t for qemu-devel@nongnu.org; Wed, 03 Oct 2012 09:28:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:12904) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TJOzs-0006aO-Ur for qemu-devel@nongnu.org; Wed, 03 Oct 2012 09:28:21 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q93DSKTq027916 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 3 Oct 2012 09:28:20 -0400 Received: from blackpad.lan.raisama.net (vpn1-7-147.gru2.redhat.com [10.97.7.147]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q93DSJap025440; Wed, 3 Oct 2012 09:28:19 -0400 Received: by blackpad.lan.raisama.net (Postfix, from userid 500) id 8386B203634; Wed, 3 Oct 2012 10:29:21 -0300 (BRT) From: Eduardo Habkost To: qemu-devel@nongnu.org Date: Wed, 3 Oct 2012 10:29:07 -0300 Message-Id: <1349270954-4657-12-git-send-email-ehabkost@redhat.com> In-Reply-To: <1349270954-4657-1-git-send-email-ehabkost@redhat.com> References: <1349270954-4657-1-git-send-email-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: Igor Mammedov , =?UTF-8?q?Andreas=20F=C3=A4rber?= , Gleb Natapov , Paolo Bonzini Subject: [Qemu-devel] [RFC 11/18] target-i386: cpu_x86_init: allow APIC ID to be set by caller X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This allows callers of cpu_x86_init() to override the APIC ID, in case it needs to build a specific cores/threads topology. Because *-user doesn't have any concept of CPU topology, we do not require every caller to specify an APIC ID. So a negative value will indicate that the CPU index can be used as APIC ID, and *-user will use that mode. By now, all the callers use the default behavior, that's using the CPU index as APIC ID, but later the PC code will be changed to calculate the APIC IDs according to CPU topology. Signed-off-by: Eduardo Habkost --- hw/pc.c | 2 +- target-i386/cpu.h | 4 ++-- target-i386/helper.c | 15 +++++++++++++-- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/hw/pc.c b/hw/pc.c index 3cf56de..0915a9b 100644 --- a/hw/pc.c +++ b/hw/pc.c @@ -908,7 +908,7 @@ static X86CPU *pc_new_cpu(PC *pc, const char *cpu_model) X86CPU *cpu; CPUX86State *env; - cpu = cpu_x86_init(cpu_model); + cpu = cpu_x86_init(cpu_model, -1); if (cpu == NULL) { fprintf(stderr, "Unable to find x86 CPU definition\n"); exit(1); diff --git a/target-i386/cpu.h b/target-i386/cpu.h index f37e80b..3b6445c 100644 --- a/target-i386/cpu.h +++ b/target-i386/cpu.h @@ -874,7 +874,7 @@ typedef struct CPUX86State { #include "cpu-qom.h" -X86CPU *cpu_x86_init(const char *cpu_model); +X86CPU *cpu_x86_init(const char *cpu_model, long apic_id); int cpu_x86_exec(CPUX86State *s); void x86_cpu_list(FILE *f, fprintf_function cpu_fprintf); void x86_cpudef_setup(void); @@ -1050,7 +1050,7 @@ uint64_t cpu_get_tsc(CPUX86State *env); static inline CPUX86State *cpu_init(const char *cpu_model) { - X86CPU *cpu = cpu_x86_init(cpu_model); + X86CPU *cpu = cpu_x86_init(cpu_model, -1); if (cpu == NULL) { return NULL; } diff --git a/target-i386/helper.c b/target-i386/helper.c index 70a9f72..423d8da 100644 --- a/target-i386/helper.c +++ b/target-i386/helper.c @@ -1239,7 +1239,15 @@ int cpu_x86_get_descr_debug(CPUX86State *env, unsigned int selector, return 1; } -X86CPU *cpu_x86_init(const char *cpu_model) +/** + * cpu_x86_init: + * + * Creates and initializes a X86CPU object. + * + * @apic_id: sets a specific APIC ID for the CPU. If negative, the CPU index + * will be used as APIC ID. + */ +X86CPU *cpu_x86_init(const char *cpu_model, long apic_id) { X86CPU *cpu; CPUX86State *env; @@ -1249,7 +1257,10 @@ X86CPU *cpu_x86_init(const char *cpu_model) env = &cpu->env; env->cpu_model_str = cpu_model; - if (cpu_x86_register(cpu, cpu_model, env->cpu_index) < 0) { + if (apic_id < 0) { + apic_id = env->cpu_index; + } + if (cpu_x86_register(cpu, cpu_model, apic_id) < 0) { object_delete(OBJECT(cpu)); return NULL; }