From patchwork Thu Dec 6 09:06:55 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andreas_F=C3=A4rber?= X-Patchwork-Id: 204200 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 58DA72C01FB for ; Thu, 6 Dec 2012 20:48:50 +1100 (EST) Received: from localhost ([::1]:35835 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TgXR1-0001KW-Gs for incoming@patchwork.ozlabs.org; Thu, 06 Dec 2012 04:07:59 -0500 Received: from eggs.gnu.org ([208.118.235.92]:50909) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TgXQJ-00008B-FI for qemu-devel@nongnu.org; Thu, 06 Dec 2012 04:07:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TgXQG-0007ck-GL for qemu-devel@nongnu.org; Thu, 06 Dec 2012 04:07:15 -0500 Received: from cantor2.suse.de ([195.135.220.15]:47524 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TgXQG-0007cP-5i for qemu-devel@nongnu.org; Thu, 06 Dec 2012 04:07:12 -0500 Received: from relay1.suse.de (unknown [195.135.220.254]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx2.suse.de (Postfix) with ESMTP id C19A0A329E; Thu, 6 Dec 2012 10:07:11 +0100 (CET) From: =?UTF-8?q?Andreas=20F=C3=A4rber?= To: qemu-devel@nongnu.org Date: Thu, 6 Dec 2012 10:06:55 +0100 Message-Id: <1354784817-1340-12-git-send-email-afaerber@suse.de> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1354784817-1340-1-git-send-email-afaerber@suse.de> References: <1354784817-1340-1-git-send-email-afaerber@suse.de> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x X-Received-From: 195.135.220.15 Cc: Eduardo Habkost , =?UTF-8?q?Andreas=20F=C3=A4rber?= Subject: [Qemu-devel] [PATCH 11/13] target-i386: Separate feature string parsing from CPU model lookup 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 From: Eduardo Habkost Instead of parsing the whole cpu_model string inside cpu_x86_find_by_name(), first split it into the CPU model name and the full feature string, then parse the feature string into pieces. When using CPU model classes, those two pieces of information will be used at different moments (CPU model name will be used to find CPU class, feature string will be used after CPU object was created), so making the split in two steps will make it easier to refactor the code later. This should also help on the CPU properties work, that will just need to replace the cpu_x86_parse_featurestr() logic (and can keep the CPU model lookup code as-is). Signed-off-by: Eduardo Habkost Reviewed-by: Igor Mammedov Signed-off-by: Andreas Färber --- target-i386/cpu.c | 69 +++++++++++++++++++++++++++++++++++------------------ 1 Datei geändert, 46 Zeilen hinzugefügt(+), 23 Zeilen entfernt(-) diff --git a/target-i386/cpu.c b/target-i386/cpu.c index 754af68..7877df1 100644 --- a/target-i386/cpu.c +++ b/target-i386/cpu.c @@ -1208,25 +1208,10 @@ static void x86_cpuid_set_tsc_freq(Object *obj, Visitor *v, void *opaque, cpu->env.tsc_khz = value / 1000; } -static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char *cpu_model) +static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char *name) { - unsigned int i; x86_def_t *def; - char *s = g_strdup(cpu_model); - char *featurestr, *name = strtok(s, ","); - /* Features to be added */ - uint32_t plus_features = 0, plus_ext_features = 0; - uint32_t plus_ext2_features = 0, plus_ext3_features = 0; - uint32_t plus_kvm_features = kvm_default_features, plus_svm_features = 0; - uint32_t plus_7_0_ebx_features = 0; - /* Features to be removed */ - uint32_t minus_features = 0, minus_ext_features = 0; - uint32_t minus_ext2_features = 0, minus_ext3_features = 0; - uint32_t minus_kvm_features = 0, minus_svm_features = 0; - uint32_t minus_7_0_ebx_features = 0; - uint32_t numvalue; - for (def = x86_defs; def; def = def->next) { if (name && !strcmp(name, def->name)) { break; @@ -1235,16 +1220,37 @@ static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char *cpu_model) if (kvm_enabled() && name && strcmp(name, "host") == 0) { kvm_cpu_fill_host(x86_cpu_def); } else if (!def) { - goto error; + return -1; } else { memcpy(x86_cpu_def, def, sizeof(*def)); } + return 0; +} + +/* Parse "+feature,-feature,feature=foo" CPU feature string + */ +static int cpu_x86_parse_featurestr(x86_def_t *x86_cpu_def, char *features) +{ + unsigned int i; + char *featurestr; /* Single 'key=value" string being parsed */ + /* Features to be added */ + uint32_t plus_features = 0, plus_ext_features = 0; + uint32_t plus_ext2_features = 0, plus_ext3_features = 0; + uint32_t plus_kvm_features = kvm_default_features, plus_svm_features = 0; + uint32_t plus_7_0_ebx_features = 0; + /* Features to be removed */ + uint32_t minus_features = 0, minus_ext_features = 0; + uint32_t minus_ext2_features = 0, minus_ext3_features = 0; + uint32_t minus_kvm_features = 0, minus_svm_features = 0; + uint32_t minus_7_0_ebx_features = 0; + uint32_t numvalue; + add_flagname_to_bitmaps("hypervisor", &plus_features, &plus_ext_features, &plus_ext2_features, &plus_ext3_features, &plus_kvm_features, &plus_svm_features, &plus_7_0_ebx_features); - featurestr = strtok(NULL, ","); + featurestr = features ? strtok(features, ",") : NULL; while (featurestr) { char *val; @@ -1378,11 +1384,9 @@ static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char *cpu_model) if (x86_cpu_def->cpuid_7_0_ebx_features && x86_cpu_def->level < 7) { x86_cpu_def->level = 7; } - g_free(s); return 0; error: - g_free(s); return -1; } @@ -1492,11 +1496,25 @@ int cpu_x86_register(X86CPU *cpu, const char *cpu_model) CPUX86State *env = &cpu->env; x86_def_t def1, *def = &def1; Error *error = NULL; + char *name, *features; + gchar **model_pieces; memset(def, 0, sizeof(*def)); - if (cpu_x86_find_by_name(def, cpu_model) < 0) - return -1; + model_pieces = g_strsplit(cpu_model, ",", 2); + if (!model_pieces[0]) { + goto error; + } + name = model_pieces[0]; + features = model_pieces[1]; + + if (cpu_x86_find_by_name(def, name) < 0) { + goto error; + } + + if (cpu_x86_parse_featurestr(def, features) < 0) { + goto error; + } if (def->vendor1) { env->cpuid_vendor1 = def->vendor1; env->cpuid_vendor2 = def->vendor2; @@ -1553,9 +1571,14 @@ int cpu_x86_register(X86CPU *cpu, const char *cpu_model) if (error) { fprintf(stderr, "%s\n", error_get_pretty(error)); error_free(error); - return -1; + goto error; } + + g_strfreev(model_pieces); return 0; +error: + g_strfreev(model_pieces); + return -1; } #if !defined(CONFIG_USER_ONLY)