From patchwork Fri Dec 28 20:33:58 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Habkost X-Patchwork-Id: 208592 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 D353F2C00EC for ; Sat, 29 Dec 2012 08:17:37 +1100 (EST) Received: from localhost ([::1]:36626 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TogcH-0002HL-QI for incoming@patchwork.ozlabs.org; Fri, 28 Dec 2012 15:33:17 -0500 Received: from eggs.gnu.org ([208.118.235.92]:46370) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Togbb-0000eh-Ux for qemu-devel@nongnu.org; Fri, 28 Dec 2012 15:32:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TogbW-00043W-MF for qemu-devel@nongnu.org; Fri, 28 Dec 2012 15:32:35 -0500 Received: from mx1.redhat.com ([209.132.183.28]:32431) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TogbW-000436-Eq for qemu-devel@nongnu.org; Fri, 28 Dec 2012 15:32:30 -0500 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 qBSKWTvO007808 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 28 Dec 2012 15:32:29 -0500 Received: from blackpad.lan.raisama.net (vpn1-6-233.gru2.redhat.com [10.97.6.233]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id qBSKWTEY020201; Fri, 28 Dec 2012 15:32:29 -0500 Received: by blackpad.lan.raisama.net (Postfix, from userid 500) id B10E7203CF9; Fri, 28 Dec 2012 18:34:07 -0200 (BRST) From: Eduardo Habkost To: qemu-devel@nongnu.org Date: Fri, 28 Dec 2012 18:33:58 -0200 Message-Id: <1356726846-10637-2-git-send-email-ehabkost@redhat.com> In-Reply-To: <1356726846-10637-1-git-send-email-ehabkost@redhat.com> References: <1356726846-10637-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: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Igor Mammedov , =?UTF-8?q?Andreas=20F=C3=A4rber?= Subject: [Qemu-devel] [PATCH 1/9] target-i386: Move CPU object creation to cpu.c 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 As we will need to create the CPU object after splitting the CPU model string (because we're going to use different subclasses for each CPU model), move the CPU object creation to cpu_x86_register(), and at the same time rename cpu_x86_register() to cpu_x86_create(). This will also simplify the CPU creation code to a trivial cpu_x86_create()+cpu_x86_realize() sequence. This will be useful for code that have to set additional properties before cpu_x86_realize() is called (e.g. the PC CPU initialization code, that needs to set APIC IDs depending on the CPU cores/threads topology). Signed-off-by: Eduardo Habkost --- Changes v2: - Move CPU creation code after cpu_model split (as we will eventually use just the "model name" part to find the right CPU class) - Small update on comment about feature string before cpu_x86_create() function --- target-i386/cpu.c | 18 +++++++++++++++--- target-i386/cpu.h | 2 +- target-i386/helper.c | 9 ++------- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/target-i386/cpu.c b/target-i386/cpu.c index 8cd8b90..8c4be8b 100644 --- a/target-i386/cpu.c +++ b/target-i386/cpu.c @@ -1482,8 +1482,13 @@ static void filter_features_for_kvm(X86CPU *cpu) } #endif -int cpu_x86_register(X86CPU *cpu, const char *cpu_model) +/* Create and initialize a X86CPU object, based on the full CPU model string + * (that may include "+feature,-feature,feature=xxx,feature" feature strings) + */ +X86CPU *cpu_x86_create(const char *cpu_model) { + X86CPU *cpu = NULL; + CPUX86State *env; x86_def_t def1, *def = &def1; QDict *props = NULL; Error *error = NULL; @@ -1505,6 +1510,10 @@ int cpu_x86_register(X86CPU *cpu, const char *cpu_model) goto out; } + cpu = X86_CPU(object_new(TYPE_X86_CPU)); + env = &cpu->env; + env->cpu_model_str = cpu_model; + def->kvm_features |= kvm_default_features; add_flagname_to_bitmaps("hypervisor", &def->features, &def->ext_features, &def->ext2_features, @@ -1525,9 +1534,12 @@ out: if (error) { fprintf(stderr, "%s\n", error_get_pretty(error)); error_free(error); - return -1; + if (cpu) { + object_delete(OBJECT(cpu)); + } + return NULL; } - return 0; + return cpu; } #if !defined(CONFIG_USER_ONLY) diff --git a/target-i386/cpu.h b/target-i386/cpu.h index 8d93393..21b3233 100644 --- a/target-i386/cpu.h +++ b/target-i386/cpu.h @@ -979,7 +979,7 @@ int cpu_x86_signal_handler(int host_signum, void *pinfo, void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx); -int cpu_x86_register(X86CPU *cpu, const char *cpu_model); +X86CPU *cpu_x86_create(const char *cpu_model); void cpu_clear_apic_feature(CPUX86State *env); void host_cpuid(uint32_t function, uint32_t count, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx); diff --git a/target-i386/helper.c b/target-i386/helper.c index dca1360..7482c97 100644 --- a/target-i386/helper.c +++ b/target-i386/helper.c @@ -1240,15 +1240,10 @@ int cpu_x86_get_descr_debug(CPUX86State *env, unsigned int selector, X86CPU *cpu_x86_init(const char *cpu_model) { X86CPU *cpu; - CPUX86State *env; Error *error = NULL; - cpu = X86_CPU(object_new(TYPE_X86_CPU)); - env = &cpu->env; - env->cpu_model_str = cpu_model; - - if (cpu_x86_register(cpu, cpu_model) < 0) { - object_delete(OBJECT(cpu)); + cpu = cpu_x86_create(cpu_model); + if (!cpu) { return NULL; }