From patchwork Mon Apr 1 19:46:48 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Habkost X-Patchwork-Id: 232795 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 D85062C0124 for ; Tue, 2 Apr 2013 06:48:50 +1100 (EST) Received: from localhost ([::1]:44671 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UMkin-0001jn-4z for incoming@patchwork.ozlabs.org; Mon, 01 Apr 2013 15:48:49 -0400 Received: from eggs.gnu.org ([208.118.235.92]:34279) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UMkhI-0007zW-63 for qemu-devel@nongnu.org; Mon, 01 Apr 2013 15:47:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UMkhF-0007zB-JD for qemu-devel@nongnu.org; Mon, 01 Apr 2013 15:47:16 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60577) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UMkhF-0007yu-Bg for qemu-devel@nongnu.org; Mon, 01 Apr 2013 15:47:13 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r31JlCuQ025090 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 1 Apr 2013 15:47:12 -0400 Received: from localhost (vpn1-6-127.gru2.redhat.com [10.97.6.127]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r31JlBnV012897; Mon, 1 Apr 2013 15:47:12 -0400 From: Eduardo Habkost To: qemu-devel@nongnu.org Date: Mon, 1 Apr 2013 16:46:48 -0300 Message-Id: <1364845609-10543-4-git-send-email-ehabkost@redhat.com> In-Reply-To: <1364845609-10543-1-git-send-email-ehabkost@redhat.com> References: <1364845609-10543-1-git-send-email-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: libvir-list@redhat.com, Igor Mammedov , Jiri Denemark , =?UTF-8?q?Andreas=20F=C3=A4rber?= Subject: [Qemu-devel] [RFC 3/4] target-i386: Add "feature-words" property 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 property will be useful for libvirt, as libvirt already has logic based on low-level feature bits (not feature names), so it will be really easy to convert the current libvirt logic to something using the "feature-words" property. The property will have two main use cases: - Checking host capabilities, by checking the features of the "host" CPU model - Checking which features are enabled on each CPU model Example output: $ ./QMP/qmp --path=/tmp/m qom-get --path=/machine/unattached/device[1] --property=feature-words item[0].cpuid-register: EDX item[0].cpuid-input-eax: 1 item[0].features: 126614521 item[1].cpuid-register: ECX item[1].cpuid-input-eax: 1 item[1].features: 2155880449 item[2].cpuid-register: EBX item[2].cpuid-input-eax: 7 item[2].features: 0 item[2].cpuid-input-ecx: 0 item[3].cpuid-register: EDX item[3].cpuid-input-eax: 2147483649 item[3].features: 563346425 item[4].cpuid-register: ECX item[4].cpuid-input-eax: 2147483649 item[4].features: 101 item[5].cpuid-register: EDX item[5].cpuid-input-eax: 3221225473 item[5].features: 0 item[6].cpuid-register: EAX item[6].cpuid-input-eax: 1073741825 item[6].features: 0 item[7].cpuid-register: EDX item[7].cpuid-input-eax: 2147483658 item[7].features: 0 Signed-off-by: Eduardo Habkost --- * This is the solution not using qapi. The next patch will introduce a solution using qapi, so both approaches can get feedback. * Current solution is not based on the "feature word array" patch, but it may be easily rebased and simplified if we decide to include the CPUX86State feature_word array later. --- target-i386/cpu.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/target-i386/cpu.c b/target-i386/cpu.c index 2020147..ebf6358 100644 --- a/target-i386/cpu.c +++ b/target-i386/cpu.c @@ -1277,6 +1277,44 @@ static void x86_cpuid_set_tsc_freq(Object *obj, Visitor *v, void *opaque, cpu->env.tsc_khz = value / 1000; } +static void x86_cpu_get_feature_words(Object *obj, Visitor *v, void *opaque, + const char *name, Error **errp) +{ + X86CPU *cpu = X86_CPU(obj); + CPUX86State *env = &cpu->env; + FeatureWord w; + Error *err = NULL; + uint32_t feat_values[FEATURE_WORDS] = { }; + + /* We need to set the entries one-by-one, by now, while we don't have + * a single feature_words array on X86CPU + */ + feat_values[FEAT_1_EDX] = env->cpuid_features; + feat_values[FEAT_1_ECX] = env->cpuid_ext_features; + feat_values[FEAT_8000_0001_EDX] = env->cpuid_ext2_features; + feat_values[FEAT_8000_0001_ECX] = env->cpuid_ext3_features; + feat_values[FEAT_C000_0001_EDX] = env->cpuid_ext4_features; + feat_values[FEAT_KVM] = env->cpuid_kvm_features; + feat_values[FEAT_SVM] = env->cpuid_svm_features; + feat_values[FEAT_7_0_EBX] = env->cpuid_7_0_ebx_features; + + visit_start_list(v, "feature-words", &err); + for (w = 0; w < FEATURE_WORDS; w++) { + FeatureWordInfo *wi = &feature_word_info[w]; + visit_start_struct(v, NULL, NULL, NULL, 0, &err); + visit_type_uint32(v, &wi->cpuid_eax, "cpuid-input-eax", &err); + if (wi->cpuid_needs_ecx) { + visit_type_uint32(v, &wi->cpuid_ecx, "cpuid-input-ecx", &err); + } + visit_type_enum(v, &wi->cpuid_reg, reg_names_32, "x86-register-32", + "cpuid-register", &err); + visit_type_uint32(v, &feat_values[w], "features", &err); + visit_end_struct(v, &err); + } + visit_end_list(v, &err); + error_propagate(errp, err); +} + static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char *name) { x86_def_t *def; @@ -2232,6 +2270,9 @@ static void x86_cpu_initfn(Object *obj) object_property_add(obj, "tsc-frequency", "int", x86_cpuid_get_tsc_freq, x86_cpuid_set_tsc_freq, NULL, NULL, NULL); + object_property_add(obj, "feature-words", "x86-cpu-feature-words", + x86_cpu_get_feature_words, + NULL, NULL, NULL, NULL); env->cpuid_apic_id = x86_cpu_apic_id_from_index(cs->cpu_index);