From nobody Mon Feb 9 07:39:38 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1489768633687154.3535400742544; Fri, 17 Mar 2017 09:37:13 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 27816624DF; Fri, 17 Mar 2017 16:37:11 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 41577BFA66; Fri, 17 Mar 2017 16:37:10 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id CE3A21853D11; Fri, 17 Mar 2017 16:37:09 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v2HGb20J007155 for ; Fri, 17 Mar 2017 12:37:02 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7FE6C5DD67; Fri, 17 Mar 2017 16:37:02 +0000 (UTC) Received: from mamuti.net (ovpn-204-109.brq.redhat.com [10.40.204.109]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2663A5DC1D for ; Fri, 17 Mar 2017 16:37:02 +0000 (UTC) Received: by mamuti.net (Postfix, from userid 500) id 41EC21061CC; Fri, 17 Mar 2017 17:36:55 +0100 (CET) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 27816624DF Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 27816624DF From: Jiri Denemark To: libvir-list@redhat.com Date: Fri, 17 Mar 2017 17:36:48 +0100 Message-Id: <786afd4c4073c2100298f827509a0dd9251233b0.1489768416.git.jdenemar@redhat.com> In-Reply-To: References: In-Reply-To: References: Mail-Followup-To: libvir-list@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 10/14] cputest: Add "diff" command to cpu-cpuid.py X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 17 Mar 2017 16:37:13 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The new command can be used to generate test data for virCPUUpdateLive. When "cpu-cpuid.py diff x86-cpuid-Something.json" is run, it reads raw CPUID data stored in x86-cpuid-Something.xml and CPUID data from QEMU stored in x86-cpuid-Something.json to produce two more CPUID files: x86-cpuid-Something-enabled.xml and x86-cpuid-Something-disabled.xml. - x86-cpuid-Something-enabled.xml will contain CPUID bits present in x86-cpuid-Something.json (i.e., enabled by QEMU for the "host" CPU) - x86-cpuid-Something-disabled.xml will contain all CPUID bits from x86-cpuid-Something.xml which are not present in x86-cpuid-Something.json (i.e., CPUID bits which the host CPU supports, but QEMU does not enable them for the "host" CPU) Signed-off-by: Jiri Denemark --- tests/cputestdata/cpu-cpuid.py | 89 ++++++++++++++++++++++++++++++++++++++= +++- tests/cputestdata/cpu-parse.sh | 1 + 2 files changed, 89 insertions(+), 1 deletion(-) diff --git a/tests/cputestdata/cpu-cpuid.py b/tests/cputestdata/cpu-cpuid.py index f4cf6d440..4b9b04ace 100755 --- a/tests/cputestdata/cpu-cpuid.py +++ b/tests/cputestdata/cpu-cpuid.py @@ -2,6 +2,7 @@ =20 import sys import json +import xmltodict =20 # This is a list of x86 CPU features as of QEMU 2.8.50 and it won't need a= ny # updates since in the future because query-cpu-model-expansion will be us= ed @@ -171,6 +172,16 @@ cpuidMap =3D [ ] =20 =20 +def reverseCpuidMap(): + features =3D {} + + for feature in cpuidMap: + for name in feature["names"]: + features[name] =3D feature + + return features + + def cpuidIsSet(cpuid, feature): in_eax =3D feature["in_eax"] in_ecx =3D feature["in_ecx"] @@ -201,6 +212,12 @@ def cpuidLeaf(cpuid, in_eax, in_ecx): return leaf =20 =20 +def cpuidAdd(cpuid, feature): + leaf =3D cpuidLeaf(cpuid, feature["in_eax"], feature["in_ecx"]) + for reg in ["eax", "ebx", "ecx", "edx"]: + leaf[reg] |=3D feature[reg] + + def parseFeatureWords(path): features =3D None =20 @@ -240,6 +257,50 @@ def parseFeatureWords(path): return props, cpuid =20 =20 +def parseQemu(path, features): + cpuid =3D {} + with open(path, "r") as f: + data =3D json.load(f) + + for (prop, val) in data["return"]["model"]["props"].iteritems(): + if val and prop in features: + cpuidAdd(cpuid, features[prop]) + + return cpuid + + +def parseCpuid(path): + cpuid =3D {} + with open(path, "r") as f: + data =3D xmltodict.parse(f) + + for leaf in data["cpudata"]["cpuid"]: + leaf["in_eax"] =3D int(leaf["@eax_in"], 0) + leaf["in_ecx"] =3D int(leaf["@ecx_in"], 0) + for reg in ["eax", "ebx", "ecx", "edx"]: + leaf[reg] =3D int(leaf["@" + reg], 0) + + cpuidAdd(cpuid, leaf) + + return cpuid + + +def formatCpuid(cpuid, path, comment): + with open(path, "w") as f: + f.write("\n") + f.write("\n") + for in_eax in sorted(cpuid.keys()): + for in_ecx in sorted(cpuid[in_eax].keys()): + leaf =3D cpuid[in_eax][in_ecx] + line =3D " \n" + f.write(line %( + in_eax, in_ecx, + leaf["eax"], leaf["ebx"], leaf["ecx"], leaf["edx"]= )) + f.write("\n") + + def convert(path): props, cpuid =3D parseFeatureWords(path) =20 @@ -255,8 +316,30 @@ def convert(path): f.write("\n") =20 =20 +def diff(features, path): + base =3D path.replace(".json", "") + jsonFile =3D path + cpuidFile =3D base + ".xml" + enabledFile =3D base + "-enabled.xml" + disabledFile =3D base + "-disabled.xml" + + cpuid =3D parseCpuid(cpuidFile) + qemu =3D parseQemu(jsonFile, features) + + enabled =3D {} + disabled =3D {} + for feature in cpuidMap: + if cpuidIsSet(qemu, feature): + cpuidAdd(enabled, feature) + elif cpuidIsSet(cpuid, feature): + cpuidAdd(disabled, feature) + + formatCpuid(enabled, enabledFile, "Features enabled by QEMU") + formatCpuid(disabled, disabledFile, "Features disabled by QEMU") + + if len(sys.argv) < 3: - print "Usage: %s convert json_file..." % sys.argv[0] + print "Usage: %s convert|diff json_file..." % sys.argv[0] sys.exit(1) =20 action =3D sys.argv[1] @@ -265,6 +348,10 @@ args =3D sys.argv[2:] if action =3D=3D "convert": for path in args: convert(path) +elif action =3D=3D "diff": + features =3D reverseCpuidMap() + for path in args: + diff(features, path) else: print "Unknown action: " + action sys.exit(1) diff --git a/tests/cputestdata/cpu-parse.sh b/tests/cputestdata/cpu-parse.sh index d823c399b..cd1ab024b 100755 --- a/tests/cputestdata/cpu-parse.sh +++ b/tests/cputestdata/cpu-parse.sh @@ -55,6 +55,7 @@ if [[ -s $fname.json ]]; then if ! grep -q model-expansion $fname.json; then $(dirname $0)/cpu-cpuid.py convert $fname.json fi + $(dirname $0)/cpu-cpuid.py diff $fname.json else rm $fname.json fi --=20 2.12.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list