From nobody Tue May 14 16:20:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1609759838; cv=none; d=zohomail.com; s=zohoarc; b=HuchkzzJjhSoxVkBN2iBgLvP1/ePOgxYjjnmQo2DuIPdYeYlgjdoSIODEdPxEDc94F3/I84rCIdPmlCdlInH9sAiBDw41GzVBj14vMPGFBgb9SCfaoIHhXb7btKOcLviVnbjur1FMtSnoMnaUq1YJ8cGE2Vlnx2WfSFwH7kTh58= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609759838; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=eT1vCTh8nCYbDa4DXFVJX1psCF0Mld0eqMm9ZQ8A3uY=; b=Q0UAVA0R7JOpx/4rGM5UCnafIsNN0v970ZvHvaHTA6+hl+4dHBTBBm7l5VAqur+JCo0Kx77PYjoI+LeR11pqBU3jXZTd97CdCGyoO3Ng2FF0y2lp17XSblBIF2MHhiZNvixDiZU0msid2Kk8wr39/kSkIKdQTD+KVksw9tft8+U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1609759838424139.6894592688834; Mon, 4 Jan 2021 03:30:38 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-118-_i3Q9zS3M_G9nZG-YdwPiA-1; Mon, 04 Jan 2021 06:30:33 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6C76F1800D41; Mon, 4 Jan 2021 11:30:28 +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 44D1219726; Mon, 4 Jan 2021 11:30:28 +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 79BD01809C9F; Mon, 4 Jan 2021 11:30:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 104BUP4O006481 for ; Mon, 4 Jan 2021 06:30:25 -0500 Received: by smtp.corp.redhat.com (Postfix) id B666D5D756; Mon, 4 Jan 2021 11:30:25 +0000 (UTC) Received: from work.redhat.com (ovpn-112-122.ams2.redhat.com [10.36.112.122]) by smtp.corp.redhat.com (Postfix) with ESMTP id 027625D761; Mon, 4 Jan 2021 11:30:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1609759836; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=eT1vCTh8nCYbDa4DXFVJX1psCF0Mld0eqMm9ZQ8A3uY=; b=CIR6MFU4S6KnsWKsvWELVnBmlp9QKdb2lvLFe63u0iMC8nEQcYpeWTpnyuOZ6U9mdq01RU VziF/p8Uj+U/lFd/pD/to5DyfwcDLotgj9UihblLorq/JuCwWrwImw+mYL/BtT8XPdQ1RN JwTxe5kKnaaRYHs4crJMw27PxD5giI0= X-MC-Unique: _i3Q9zS3M_G9nZG-YdwPiA-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH 1/9] cpu-cpuid: Use argparse to parse arguments Date: Mon, 4 Jan 2021 12:30:11 +0100 Message-Id: <20210104113019.106513-2-twiederh@redhat.com> In-Reply-To: <20210104113019.106513-1-twiederh@redhat.com> References: <20210104113019.106513-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: Tim Wiederhake 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Using 'argparse' for argument handling simplifies merging this script with cpu-gather.py in a later patch. Signed-off-by: Tim Wiederhake --- tests/cputestdata/cpu-cpuid.py | 78 +++++++++++++++++++--------------- 1 file changed, 43 insertions(+), 35 deletions(-) diff --git a/tests/cputestdata/cpu-cpuid.py b/tests/cputestdata/cpu-cpuid.py index dac43debb6..6ca72d2262 100755 --- a/tests/cputestdata/cpu-cpuid.py +++ b/tests/cputestdata/cpu-cpuid.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 =20 +import argparse import os import sys import json @@ -191,39 +192,46 @@ def formatCPUData(cpuData, path, comment): f.write("\n") =20 =20 -def diff(cpuMap, path): - base =3D path.replace(".json", "") - jsonFile =3D path - cpuDataFile =3D base + ".xml" - enabledFile =3D base + "-enabled.xml" - disabledFile =3D base + "-disabled.xml" - - cpuData =3D parseCPUData(cpuDataFile) - qemu =3D parseQemu(jsonFile, cpuMap) - - enabled =3D {"cpuid": {}} - disabled =3D {"cpuid": {}} - for feature in cpuMap.values(): - if checkFeature(qemu, feature): - addFeature(enabled, feature) - elif checkFeature(cpuData, feature): - addFeature(disabled, feature) - - formatCPUData(enabled, enabledFile, "Features enabled by QEMU") - formatCPUData(disabled, disabledFile, "Features disabled by QEMU") - - -if len(sys.argv) < 3: - print("Usage: %s diff json_file..." % sys.argv[0]) - sys.exit(1) - -action =3D sys.argv[1] -args =3D sys.argv[2:] - -if action =3D=3D "diff": +def diff(args): cpuMap =3D parseMap() - for path in args: - diff(cpuMap, path) -else: - print("Unknown action: %s" % action) - sys.exit(1) + + for jsonFile in args.json_files: + cpuDataFile =3D jsonFile.replace(".json", ".xml") + enabledFile =3D jsonFile.replace(".json", "-enabled.xml") + disabledFile =3D jsonFile.replace(".json", "-disabled.xml") + + cpuData =3D parseCPUData(cpuDataFile) + qemu =3D parseQemu(jsonFile, cpuMap) + + enabled =3D dict() + disabled =3D dict() + for feature in cpuMap.values(): + if checkFeature(qemu, feature): + addFeature(enabled, feature) + elif checkFeature(cpuData, feature): + addFeature(disabled, feature) + + formatCPUData(enabled, enabledFile, "Features enabled by QEMU") + formatCPUData(disabled, disabledFile, "Features disabled by QEMU") + + +def main(): + parser =3D argparse.ArgumentParser(description=3D"Diff cpuid results") + subparsers =3D parser.add_subparsers(dest=3D"action", required=3DTrue) + diffparser =3D subparsers.add_parser( + "diff", + help=3D"Diff json description of CPU model against known features.= ") + diffparser.add_argument( + "json_files", + nargs=3D"+", + metavar=3D"FILE", + type=3Dos.path.realpath, + help=3D"Path to one or more json CPU model descriptions.") + args =3D parser.parse_args() + + diff(args) + exit(0) + + +if __name__ =3D=3D "__main__": + main() --=20 2.26.2 From nobody Tue May 14 16:20:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1609759846; cv=none; d=zohomail.com; s=zohoarc; b=nwJEfUNeaiz1IMb0lWsGeZIQGyLNFArcN+AkgEZD4NGak2IgQLfcwAB+W5+rftQPPj5eh2Vc24S510xOkgh43BviZ2dIPjDDfvfc16CqUtuxlbAVcclps5C7WnpAHiyOMdOdwNDNWmXcIcBoCh/B6tNDKX0UcU0ZX2JLrXhSk6o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609759846; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=IacJsmjQk9g1elNC+0Ht1bBTtbGa8P2O1z4UO84y4n8=; b=GX30N1cUfU3sHGklXyNW0aSn/6DmpoMOLks0iXY/SX1IXCm2SZGg3MNOKXCIA5/GgO2/w459MgbzPICStEeng6GyVh92psWedsWqQcohfiwDDu+fYioKkHJuVyI9iCk8ChEMHfEY3S0MvFKYPxQHAvFbwgIBLoXmSPUhvyo2lZk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1609759846385586.6651525168451; Mon, 4 Jan 2021 03:30:46 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-291-KQBJJVjTPIuuSmLldB9PPw-1; Mon, 04 Jan 2021 06:30:43 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 347928018A1; Mon, 4 Jan 2021 11:30:37 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 119026F81E; Mon, 4 Jan 2021 11:30:37 +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 C81B34EA6C; Mon, 4 Jan 2021 11:30:36 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 104BUQbK006491 for ; Mon, 4 Jan 2021 06:30:26 -0500 Received: by smtp.corp.redhat.com (Postfix) id D17715D761; Mon, 4 Jan 2021 11:30:26 +0000 (UTC) Received: from work.redhat.com (ovpn-112-122.ams2.redhat.com [10.36.112.122]) by smtp.corp.redhat.com (Postfix) with ESMTP id 174875D756; Mon, 4 Jan 2021 11:30:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1609759845; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=IacJsmjQk9g1elNC+0Ht1bBTtbGa8P2O1z4UO84y4n8=; b=KAEXVgFu7TPTu2599s08g7x/671UestHy7zLtroq8FT/3YqdBnTwm789X4TWxBbCqByKIW uoptyD4heEm1LQVNJk0e0pKkh7dyybqQ1c4Yois3RYwZa7VHVSkYJXjXKbGyQTVC/9PP36 IGQjTPdIEBjsHUbf50DGUlZC37h5IqM= X-MC-Unique: KQBJJVjTPIuuSmLldB9PPw-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH 2/9] cpu-cpuid: Remove xmltodict usage in parseMap Date: Mon, 4 Jan 2021 12:30:12 +0100 Message-Id: <20210104113019.106513-3-twiederh@redhat.com> In-Reply-To: <20210104113019.106513-1-twiederh@redhat.com> References: <20210104113019.106513-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: Tim Wiederhake 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" 'xmltodict' is a Python module that is not installed by default. Replace it, so the dependencies of cpu-gather.py do not change when both scripts are merged. Signed-off-by: Tim Wiederhake --- tests/cputestdata/cpu-cpuid.py | 39 ++++++++++++---------------------- 1 file changed, 13 insertions(+), 26 deletions(-) diff --git a/tests/cputestdata/cpu-cpuid.py b/tests/cputestdata/cpu-cpuid.py index 6ca72d2262..8e06baea85 100755 --- a/tests/cputestdata/cpu-cpuid.py +++ b/tests/cputestdata/cpu-cpuid.py @@ -5,6 +5,7 @@ import os import sys import json import xmltodict +import xml.etree.ElementTree =20 =20 def checkCPUIDFeature(cpuData, feature): @@ -132,37 +133,23 @@ def parseCPUData(path): return cpuData =20 =20 -def parseMapFeature(fType, data): - ret =3D {"type": fType} - - if fType =3D=3D "cpuid": - fields =3D ["eax_in", "ecx_in", "eax", "ebx", "ecx", "edx"] - elif fType =3D=3D "msr": - fields =3D ["index", "edx", "eax"] - - for field in fields: - attr =3D "@%s" % field - if attr in data: - ret[field] =3D int(data[attr], 0) - else: - ret[field] =3D 0 - - return ret - - def parseMap(): path =3D os.path.dirname(sys.argv[0]) path =3D os.path.join(path, "..", "..", "src", "cpu_map", "x86_feature= s.xml") - with open(path, "rb") as f: - data =3D xmltodict.parse(f) =20 - cpuMap =3D {} - for feature in data["cpus"]["feature"]: - for fType in ["cpuid", "msr"]: - if fType not in feature: - continue - cpuMap[feature["@name"]] =3D parseMapFeature(fType, feature[fT= ype]) + cpuMap =3D dict() + for f in xml.etree.ElementTree.parse(path).getroot().iter("feature"): + if f[0].tag =3D=3D "cpuid": + reg_list =3D ["eax_in", "ecx_in", "eax", "ebx", "ecx", "edx"] + elif f[0].tag =3D=3D "msr": + reg_list =3D ["index", "eax", "edx"] + else: + continue =20 + feature =3D {"type": f[0].tag} + for reg in reg_list: + feature[reg] =3D int(f[0].attrib.get(reg, "0"), 0) + cpuMap[f.attrib["name"]] =3D feature return cpuMap =20 =20 --=20 2.26.2 From nobody Tue May 14 16:20:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1609759839; cv=none; d=zohomail.com; s=zohoarc; b=g1KMEiNMTJ32n7T/0i1DX1oENbgJnphRLiOTsy/erdhkbliOaoPKGGXWgBsvTpz6rhjnogcBNYyj837STdN3h/obMIuIh3vllVntoeXbdJ2RW3Noaq4gYfJ0vdegM1PnwZo2VSzqaB1jyGGvtmRtF9MAasz2mQWkpQv8dqzL+ec= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609759839; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=CfbiicbQeY/mrQG8spT3HS1rZNf+6AcdKndCxCxYQpw=; b=SrDK4PbQnn8Em8bx1pos831IATcBAoAtZyOq07co2cfO9CxJ8XiGMuTkVoXPZDO9V/7xqsXbS0D9Xhz68aLe/2lrnCGmXVVTj2yBiDbK8p8mOj6iVpqO9pfRNZarLHbaRxmZxfCmlz/2w5L29AhK181JTyKxHhjCD1ZFbCA8kSo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1609759839734828.3722625700536; Mon, 4 Jan 2021 03:30:39 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-235-r93kJuZlOFq2DRVsLObsbQ-1; Mon, 04 Jan 2021 06:30:35 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A559C1005504; Mon, 4 Jan 2021 11:30:29 +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 836F86F7EF; Mon, 4 Jan 2021 11:30:29 +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 188D11809CA2; Mon, 4 Jan 2021 11:30:29 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 104BURfx006501 for ; Mon, 4 Jan 2021 06:30:28 -0500 Received: by smtp.corp.redhat.com (Postfix) id ED46D669FC; Mon, 4 Jan 2021 11:30:27 +0000 (UTC) Received: from work.redhat.com (ovpn-112-122.ams2.redhat.com [10.36.112.122]) by smtp.corp.redhat.com (Postfix) with ESMTP id 308EC5D756; Mon, 4 Jan 2021 11:30:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1609759838; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=CfbiicbQeY/mrQG8spT3HS1rZNf+6AcdKndCxCxYQpw=; b=bjVSpdFX16Fiu3sVvcHRokYiSyYvsWiX0wR7C+Ckyi3IpvaMM18MyPMPHVKaqjiQlsAb8C gylvaXlzj1bRZRY11sYrwjwZraHcVmN+KqBfvqQ23e9wrjLmYi+8V0v4g8sn39xoGLtjLz IOLSRimxHZgGSi2ScsBKY9YbrN8tWXU= X-MC-Unique: r93kJuZlOFq2DRVsLObsbQ-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH 3/9] cpu-cpuid: Remove xmltodict usage in parseCPU Date: Mon, 4 Jan 2021 12:30:13 +0100 Message-Id: <20210104113019.106513-4-twiederh@redhat.com> In-Reply-To: <20210104113019.106513-1-twiederh@redhat.com> References: <20210104113019.106513-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: Tim Wiederhake 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" 'xmltodict' is a Python module that is not installed by default. Replace it, so the dependencies of cpu-gather.py do not change when both scripts are merged. Signed-off-by: Tim Wiederhake --- tests/cputestdata/cpu-cpuid.py | 35 +++++++++++----------------------- 1 file changed, 11 insertions(+), 24 deletions(-) diff --git a/tests/cputestdata/cpu-cpuid.py b/tests/cputestdata/cpu-cpuid.py index 8e06baea85..d570884db6 100755 --- a/tests/cputestdata/cpu-cpuid.py +++ b/tests/cputestdata/cpu-cpuid.py @@ -4,7 +4,6 @@ import argparse import os import sys import json -import xmltodict import xml.etree.ElementTree =20 =20 @@ -105,31 +104,19 @@ def parseQemu(path, features): =20 =20 def parseCPUData(path): - cpuData =3D {} - with open(path, "rb") as f: - data =3D xmltodict.parse(f) - - for leaf in data["cpudata"]["cpuid"]: - feature =3D {"type": "cpuid"} - feature["eax_in"] =3D int(leaf["@eax_in"], 0) - feature["ecx_in"] =3D int(leaf["@ecx_in"], 0) - for reg in ["eax", "ebx", "ecx", "edx"]: - feature[reg] =3D int(leaf["@" + reg], 0) + cpuData =3D dict() + for f in xml.etree.ElementTree.parse(path).getroot(): + if f.tag =3D=3D "cpuid": + reg_list =3D ["eax_in", "ecx_in", "eax", "ebx", "ecx", "edx"] + elif f.tag =3D=3D "msr": + reg_list =3D ["index", "eax", "edx"] + else: + continue =20 + feature =3D {"type": f.tag} + for reg in reg_list: + feature[reg] =3D int(f.attrib.get(reg, "0"), 0) addFeature(cpuData, feature) - - if "msr" in data["cpudata"]: - if not isinstance(data["cpudata"]["msr"], list): - data["cpudata"]["msr"] =3D [data["cpudata"]["msr"]] - - for msr in data["cpudata"]["msr"]: - feature =3D {"type": "msr"} - feature["index"] =3D int(msr["@index"], 0) - feature["edx"] =3D int(msr["@edx"], 0) - feature["eax"] =3D int(msr["@eax"], 0) - - addFeature(cpuData, feature) - return cpuData =20 =20 --=20 2.26.2 From nobody Tue May 14 16:20:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1609759864; cv=none; d=zohomail.com; s=zohoarc; b=Bse1YxV9Lwo1DLakkndjZ2FVeeVET1WrioQAA7LIkz+FpKEon0P4bAchtUhyumQIVCqBoKTQERDcE/R+apVMUkexYB4ShcfbVzmxh93VvpCI3y/JCyGwqbFJ6CyaqUQ/sswN4jopVK3RPltXYWxn+zQDwHrrjhl1fQxxc14y6zY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609759864; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=VeCGxiXhJTAfoMKnMXt2RAPwWRq9pEuBl3K+iel6T1w=; b=YUWdm92ymhG8oW59xyo575hEGljczj7+1vm0miMIMnE0ORW9PDO3rce9ezx8HnF1ve2+eLl4f6D5NFDvVTGIjWQE14bOGTQAJNnWT63zsdJNyLgVKRXHZi5TLor5f9fCbeWdLfX3le1ZP8eruRG/Nl5GvVIrOA4nXM1mLT47YgA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 160975986398621.94962974572968; Mon, 4 Jan 2021 03:31:03 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-15-ZYgg2Y2wOn24id9bF25_Bg-1; Mon, 04 Jan 2021 06:30:46 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1F6C1612B5; Mon, 4 Jan 2021 11:30:40 +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 EFD8060BE5; Mon, 4 Jan 2021 11:30:39 +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 BA3FB1809CA6; Mon, 4 Jan 2021 11:30:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 104BUTN6006514 for ; Mon, 4 Jan 2021 06:30:29 -0500 Received: by smtp.corp.redhat.com (Postfix) id 0E9F7669FC; Mon, 4 Jan 2021 11:30:29 +0000 (UTC) Received: from work.redhat.com (ovpn-112-122.ams2.redhat.com [10.36.112.122]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4F33C61F20; Mon, 4 Jan 2021 11:30:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1609759862; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=VeCGxiXhJTAfoMKnMXt2RAPwWRq9pEuBl3K+iel6T1w=; b=heEWBQ5SqaWA8JiCXuImV888K7mk576XRgIlQ7sDUgfBz05+gT25/GNvy/bRD+rOjOPtCn yI9jASPIym5GAos2XIUkiCLah59L64wJV7zC91ecPtNTLOen5aadzWHsJ08yrHr7WpeTlm UWrF9Jf4bibnQ5KvPsbmsRw3YFgd3gE= X-MC-Unique: ZYgg2Y2wOn24id9bF25_Bg-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH 4/9] cpu-cpuid: Merge addFeature functions Date: Mon, 4 Jan 2021 12:30:14 +0100 Message-Id: <20210104113019.106513-5-twiederh@redhat.com> In-Reply-To: <20210104113019.106513-1-twiederh@redhat.com> References: <20210104113019.106513-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: Tim Wiederhake 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Prepare to deduplicate the list of relevant registers for cpuid and msr information. Signed-off-by: Tim Wiederhake --- tests/cputestdata/cpu-cpuid.py | 48 ++++++++++++---------------------- 1 file changed, 16 insertions(+), 32 deletions(-) diff --git a/tests/cputestdata/cpu-cpuid.py b/tests/cputestdata/cpu-cpuid.py index d570884db6..c9948da6f8 100755 --- a/tests/cputestdata/cpu-cpuid.py +++ b/tests/cputestdata/cpu-cpuid.py @@ -54,41 +54,25 @@ def checkFeature(cpuData, feature): return checkMSRFeature(cpuData, feature) =20 =20 -def addCPUIDFeature(cpuData, feature): - if "cpuid" not in cpuData: - cpuData["cpuid"] =3D {} - cpuid =3D cpuData["cpuid"] - - if feature["eax_in"] not in cpuid: - cpuid[feature["eax_in"]] =3D {} - leaf =3D cpuid[feature["eax_in"]] - - if feature["ecx_in"] not in leaf: - leaf[feature["ecx_in"]] =3D {"eax": 0, "ebx": 0, "ecx": 0, "edx": = 0} - leaf =3D leaf[feature["ecx_in"]] - - for reg in ["eax", "ebx", "ecx", "edx"]: - leaf[reg] |=3D feature[reg] - - -def addMSRFeature(cpuData, feature): - if "msr" not in cpuData: - cpuData["msr"] =3D {} - msr =3D cpuData["msr"] - - if feature["index"] not in msr: - msr[feature["index"]] =3D {"edx": 0, "eax": 0} - msr =3D msr[feature["index"]] - - for reg in ["edx", "eax"]: - msr[reg] |=3D feature[reg] - - def addFeature(cpuData, feature): if feature["type"] =3D=3D "cpuid": - addCPUIDFeature(cpuData, feature) + # cpuData["cpuid"][eax_in][ecx_in] =3D {eax:, ebx:, ecx:, edx:} + keyList =3D ["type", "eax_in", "ecx_in"] + regList =3D ["eax", "ebx", "ecx", "edx"] elif feature["type"] =3D=3D "msr": - addMSRFeature(cpuData, feature) + # cpuData["msr"][index] =3D {eax:, edx:} + keyList =3D ["type", "index"] + regList =3D ["eax", "edx"] + else: + return + + for key in keyList: + if feature[key] not in cpuData: + cpuData[feature[key]] =3D dict() + cpuData =3D cpuData[feature[key]] + + for reg in regList: + cpuData[reg] =3D cpuData.get(reg, 0) | feature[reg] =20 =20 def parseQemu(path, features): --=20 2.26.2 From nobody Tue May 14 16:20:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1609759851; cv=none; d=zohomail.com; s=zohoarc; b=aoQFD783NCVsKquzyeNyPaGP2oHFQFViSdJ9PxM4YqLonQojbg8ogjq1CCQbHzWinRjo5QKX4jpItX2TgGQdLToYSUpWx52gCPdtJ83qu3wkZVDUM7GOQKH4FS+iBpy+2MlQITusFmJvV/A8Swe2gELJ6t4Y9ABUoo25er/cJLA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609759851; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=iPOL/Hb31U4uM5Tw0r3lNEhZkVBq5WoLCZSAoHjDr6g=; b=bXZ5vDE/Sm0NcIZ0TTK/iPeDLgoWdsaqo432+ltwKLyHuNExJVGgTjpY/SW02ad1Pn3jJsMGv7vSpkPLoOTye6mXZOoOhgdYi4Y0ux5giDS35ousUkOwGVBPFTnhr9lM7NZkwAwfBfKZT03nDqVIzNAiTAJLBZBFM5fsyheEro0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1609759851540578.5842525867114; Mon, 4 Jan 2021 03:30:51 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-526-gZu-AFpKODmL_dpwsoe-Gg-1; Mon, 04 Jan 2021 06:30:48 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D42E0612AD; Mon, 4 Jan 2021 11:30:42 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 985DB10023B1; Mon, 4 Jan 2021 11:30:42 +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 631E050030; Mon, 4 Jan 2021 11:30:42 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 104BUUee006522 for ; Mon, 4 Jan 2021 06:30:30 -0500 Received: by smtp.corp.redhat.com (Postfix) id 22DFD5D756; Mon, 4 Jan 2021 11:30:30 +0000 (UTC) Received: from work.redhat.com (ovpn-112-122.ams2.redhat.com [10.36.112.122]) by smtp.corp.redhat.com (Postfix) with ESMTP id 626F061F20; Mon, 4 Jan 2021 11:30:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1609759850; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=iPOL/Hb31U4uM5Tw0r3lNEhZkVBq5WoLCZSAoHjDr6g=; b=bhRFFWPQIV+7jI/ctXmDrYUJAoGiN/EAjAPVDQs+XWccfBS4KEks1oJwLOgULRktx+zrI3 1okBIshI9U1osNmPhxBpqEc1n9O9s/uLfRFi3UT14tt5G7935QKE6K03NzcH+PVjBVf7Ab c254O6n4zOePdl+slfaTi4hbbpmcANo= X-MC-Unique: gZu-AFpKODmL_dpwsoe-Gg-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH 5/9] cpu-cpuid: Merge checkFeature functions Date: Mon, 4 Jan 2021 12:30:15 +0100 Message-Id: <20210104113019.106513-6-twiederh@redhat.com> In-Reply-To: <20210104113019.106513-1-twiederh@redhat.com> References: <20210104113019.106513-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: Tim Wiederhake 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Prepare to deduplicate the list of relevant registers for cpuid and msr information. Signed-off-by: Tim Wiederhake --- tests/cputestdata/cpu-cpuid.py | 60 ++++++++++------------------------ 1 file changed, 18 insertions(+), 42 deletions(-) diff --git a/tests/cputestdata/cpu-cpuid.py b/tests/cputestdata/cpu-cpuid.py index c9948da6f8..e90165e563 100755 --- a/tests/cputestdata/cpu-cpuid.py +++ b/tests/cputestdata/cpu-cpuid.py @@ -7,51 +7,27 @@ import json import xml.etree.ElementTree =20 =20 -def checkCPUIDFeature(cpuData, feature): - eax_in =3D feature["eax_in"] - ecx_in =3D feature["ecx_in"] - eax =3D feature["eax"] - ebx =3D feature["ebx"] - ecx =3D feature["ecx"] - edx =3D feature["edx"] - - if "cpuid" not in cpuData: - return False - - cpuid =3D cpuData["cpuid"] - if eax_in not in cpuid or ecx_in not in cpuid[eax_in]: - return False - - leaf =3D cpuid[eax_in][ecx_in] - return ((eax > 0 and leaf["eax"] & eax =3D=3D eax) or - (ebx > 0 and leaf["ebx"] & ebx =3D=3D ebx) or - (ecx > 0 and leaf["ecx"] & ecx =3D=3D ecx) or - (edx > 0 and leaf["edx"] & edx =3D=3D edx)) - - -def checkMSRFeature(cpuData, feature): - index =3D feature["index"] - edx =3D feature["edx"] - eax =3D feature["eax"] - - if "msr" not in cpuData: - return False - - msr =3D cpuData["msr"] - if index not in msr: - return False - - msr =3D msr[index] - return ((edx > 0 and msr["edx"] & edx =3D=3D edx) or - (eax > 0 and msr["eax"] & eax =3D=3D eax)) - - def checkFeature(cpuData, feature): if feature["type"] =3D=3D "cpuid": - return checkCPUIDFeature(cpuData, feature) + # cpuData["cpuid"][eax_in][ecx_in] =3D {eax:, ebx:, ecx:, edx:} + keyList =3D ["type", "eax_in", "ecx_in"] + regList =3D ["eax", "ebx", "ecx", "edx"] + elif feature["type"] =3D=3D "msr": + # cpuData["msr"][index] =3D {eax:, edx:} + keyList =3D ["type", "index"] + regList =3D ["eax", "edx"] + else: + return False + + for key in keyList: + if feature[key] not in cpuData: + return False + cpuData =3D cpuData[feature[key]] =20 - if feature["type"] =3D=3D "msr": - return checkMSRFeature(cpuData, feature) + for reg in regList: + if feature[reg] > 0 and feature[reg] =3D=3D feature[reg] & cpuData= [reg]: + return True + return False =20 =20 def addFeature(cpuData, feature): --=20 2.26.2 From nobody Tue May 14 16:20:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1609759866; cv=none; d=zohomail.com; s=zohoarc; b=MmmUNG60VL7tllq+exn/IJD69chSfkjGXB3iz5KYAzswjFg/kebk3a0xn8lp5lYFsXFJokS0NIcUGWVfAfQ6VPgjMWkC+RL7QRewMmFTpCVPo74RcvNJcjyGrmyjbYU/ALF8PDxSeNdILirjvcnZmEeORSZVObqSLMLuzy58qig= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609759866; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=RoCka9Gg7AXmjf6nTaTK3uyPQCmJBcmxdokdPLiy2TA=; b=kpKNwh9+vX3hlt2ZfeWDgEexuOeUsMgz2G6/4G/Z5xPTIcVbmjZjz3Uf3yzDexdYu3Bjd80ZXeTU02NcGsUlAqutG0ss2VZUxjZaOQ+gctr+LuZCTFXXwXc6q0Cb9lMP/qBCaVRBYXkZ/MggO4leg+BnzlzIxM23aaLcaglzzLc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1609759866959262.01799333581175; Mon, 4 Jan 2021 03:31:06 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-159-Q2WeNLToMV-nNzm3uJ_-ZA-1; Mon, 04 Jan 2021 06:30:43 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3AEA5190B2A1; Mon, 4 Jan 2021 11:30:37 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0A97119726; Mon, 4 Jan 2021 11:30:37 +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 C11524E590; Mon, 4 Jan 2021 11:30:36 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 104BUV4t006532 for ; Mon, 4 Jan 2021 06:30:31 -0500 Received: by smtp.corp.redhat.com (Postfix) id 3A41C5D761; Mon, 4 Jan 2021 11:30:31 +0000 (UTC) Received: from work.redhat.com (ovpn-112-122.ams2.redhat.com [10.36.112.122]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7567E5D756; Mon, 4 Jan 2021 11:30:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1609759865; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=RoCka9Gg7AXmjf6nTaTK3uyPQCmJBcmxdokdPLiy2TA=; b=ajE8NJocOskfPmpE6+vLoM6UkAaqbgaWtVZWFbjWehOhybLCv/5ttoZMeUtzo6W23OZC+J 857h45u080GInpgivvcR+lSsE4ZwizD9bRSuiQb9Qw6lblQrlzvmWp9fMjywCvN8s1j0f4 lnyP3nR5bJGxew53a5cyhyyEi0eANLM= X-MC-Unique: Q2WeNLToMV-nNzm3uJ_-ZA-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH 6/9] cpu-cpuid: Deduplicate register list Date: Mon, 4 Jan 2021 12:30:16 +0100 Message-Id: <20210104113019.106513-7-twiederh@redhat.com> In-Reply-To: <20210104113019.106513-1-twiederh@redhat.com> References: <20210104113019.106513-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: Tim Wiederhake 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Signed-off-by: Tim Wiederhake --- tests/cputestdata/cpu-cpuid.py | 57 ++++++++++++---------------------- 1 file changed, 19 insertions(+), 38 deletions(-) diff --git a/tests/cputestdata/cpu-cpuid.py b/tests/cputestdata/cpu-cpuid.py index e90165e563..3e852d5d55 100755 --- a/tests/cputestdata/cpu-cpuid.py +++ b/tests/cputestdata/cpu-cpuid.py @@ -7,47 +7,36 @@ import json import xml.etree.ElementTree =20 =20 +_KEYS =3D { + "cpuid": ["eax_in", "ecx_in"], + "msr": ["index"], +} + +_REGS =3D { + "cpuid": ["eax", "ebx", "ecx", "edx"], + "msr": ["eax", "edx"], +} + + def checkFeature(cpuData, feature): - if feature["type"] =3D=3D "cpuid": - # cpuData["cpuid"][eax_in][ecx_in] =3D {eax:, ebx:, ecx:, edx:} - keyList =3D ["type", "eax_in", "ecx_in"] - regList =3D ["eax", "ebx", "ecx", "edx"] - elif feature["type"] =3D=3D "msr": - # cpuData["msr"][index] =3D {eax:, edx:} - keyList =3D ["type", "index"] - regList =3D ["eax", "edx"] - else: - return False - - for key in keyList: + for key in ["type"] + _KEYS.get(feature["type"], list()): if feature[key] not in cpuData: return False cpuData =3D cpuData[feature[key]] =20 - for reg in regList: + for reg in _REGS.get(feature["type"], list()): if feature[reg] > 0 and feature[reg] =3D=3D feature[reg] & cpuData= [reg]: return True return False =20 =20 def addFeature(cpuData, feature): - if feature["type"] =3D=3D "cpuid": - # cpuData["cpuid"][eax_in][ecx_in] =3D {eax:, ebx:, ecx:, edx:} - keyList =3D ["type", "eax_in", "ecx_in"] - regList =3D ["eax", "ebx", "ecx", "edx"] - elif feature["type"] =3D=3D "msr": - # cpuData["msr"][index] =3D {eax:, edx:} - keyList =3D ["type", "index"] - regList =3D ["eax", "edx"] - else: - return - - for key in keyList: + for key in ["type"] + _KEYS.get(feature["type"], list()): if feature[key] not in cpuData: cpuData[feature[key]] =3D dict() cpuData =3D cpuData[feature[key]] =20 - for reg in regList: + for reg in _REGS.get(feature["type"], list()): cpuData[reg] =3D cpuData.get(reg, 0) | feature[reg] =20 =20 @@ -66,15 +55,11 @@ def parseQemu(path, features): def parseCPUData(path): cpuData =3D dict() for f in xml.etree.ElementTree.parse(path).getroot(): - if f.tag =3D=3D "cpuid": - reg_list =3D ["eax_in", "ecx_in", "eax", "ebx", "ecx", "edx"] - elif f.tag =3D=3D "msr": - reg_list =3D ["index", "eax", "edx"] - else: + if f.tag not in ("cpuid", "msr"): continue =20 feature =3D {"type": f.tag} - for reg in reg_list: + for reg in _KEYS[f.tag] + _REGS[f.tag]: feature[reg] =3D int(f.attrib.get(reg, "0"), 0) addFeature(cpuData, feature) return cpuData @@ -86,15 +71,11 @@ def parseMap(): =20 cpuMap =3D dict() for f in xml.etree.ElementTree.parse(path).getroot().iter("feature"): - if f[0].tag =3D=3D "cpuid": - reg_list =3D ["eax_in", "ecx_in", "eax", "ebx", "ecx", "edx"] - elif f[0].tag =3D=3D "msr": - reg_list =3D ["index", "eax", "edx"] - else: + if f[0].tag not in ("cpuid", "msr"): continue =20 feature =3D {"type": f[0].tag} - for reg in reg_list: + for reg in _KEYS[f[0].tag] + _REGS[f[0].tag]: feature[reg] =3D int(f[0].attrib.get(reg, "0"), 0) cpuMap[f.attrib["name"]] =3D feature return cpuMap --=20 2.26.2 From nobody Tue May 14 16:20:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1609759850; cv=none; d=zohomail.com; s=zohoarc; b=b2CtLjFhlagBnNopVbT3xX1pX1s0Q+vZopk+hPYrKABLpLLl6okKl+hHVZ6YVM+am+MxTGGIxt/kQdWX4kgcDA/JZwbz4h0L46s6jaqiHjplKzsGOawEckPwxkysjVScU3rHR2GeHXqiimqoVBPVYHN2cLosrwQtaqDoc5zjBdQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609759850; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=XPq+s355VXhZF9ewlHGTRIOj6N/6dbSRKEIkO49IxEc=; b=GF2n23rkA4A+3gohcLPC3JcTE5q02LKXE527VxWXCl089pB518x57rjo5/3UJNJwHjp3cBpyD06Z9j1axXhhvEUqLY1C4sw1PQizprOVqyUlDOZtavkxQ03JCowp6gtIqUMuHkJn/iwjFhbleHL8lk/4nhIVvjvnmpFQWZmLJBo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1609759850039671.3942208330946; Mon, 4 Jan 2021 03:30:50 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-399-m75_SBtjP6mhbswJsJobEQ-1; Mon, 04 Jan 2021 06:30:46 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 171D1190B2AE; Mon, 4 Jan 2021 11:30:40 +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 E8EBC5D9D3; Mon, 4 Jan 2021 11:30:39 +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 B00351809CA4; Mon, 4 Jan 2021 11:30:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 104BUWkA006537 for ; Mon, 4 Jan 2021 06:30:32 -0500 Received: by smtp.corp.redhat.com (Postfix) id 24D0D5D761; Mon, 4 Jan 2021 11:30:32 +0000 (UTC) Received: from work.redhat.com (ovpn-112-122.ams2.redhat.com [10.36.112.122]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8EAE65D756; Mon, 4 Jan 2021 11:30:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1609759848; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=XPq+s355VXhZF9ewlHGTRIOj6N/6dbSRKEIkO49IxEc=; b=XL/lTOjgQ+ZeyM+gZSTOh+y24S/ww6hat4HW8zXv0GQMTaVIP8sHCHBf7O7V6yYOCAm69L 26J9Zp5TmuOG7kGMvAq5WfNN1QWd64fcL6wNe1nWXQHADgmfSY39DeBu8nNaWye9iOy5Jk lQ5CSWHkrm/3tXF64va9D1lKH5arZgk= X-MC-Unique: m75_SBtjP6mhbswJsJobEQ-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH 7/9] cpu-gather: Use actions instead of flags for action argument Date: Mon, 4 Jan 2021 12:30:17 +0100 Message-Id: <20210104113019.106513-8-twiederh@redhat.com> In-Reply-To: <20210104113019.106513-1-twiederh@redhat.com> References: <20210104113019.106513-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: Tim Wiederhake 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" This allows for the functionality of cpu-cpuid.py script to be integrated more naturally in a later patch. Changes the way this script should be called: cpu-gather.py -> cpu-gather.py cpu-gather.py --gather -> cpu-gather.py gather cpu-gather.py --parse -> cpu-gather.py parse cpu-gather.py --gather --parse -> cpu-gather.py full Signed-off-by: Tim Wiederhake --- tests/cputestdata/cpu-gather.py | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/tests/cputestdata/cpu-gather.py b/tests/cputestdata/cpu-gather= .py index a01c615504..5ca19e5f2b 100755 --- a/tests/cputestdata/cpu-gather.py +++ b/tests/cputestdata/cpu-gather.py @@ -324,21 +324,22 @@ def main(): help=3D"Path to qemu. " "If unset, will try '/usr/bin/qemu-system-x86_64', " "'/usr/bin/qemu-kvm', and '/usr/libexec/qemu-kvm'.") - parser.add_argument( - "--gather", - action=3D"store_true", - help=3D"Acquire data on target system. This is the default. " - "If '--parse' is not set, outputs data on stdout.") - parser.add_argument( - "--parse", - action=3D"store_true", - help=3D"Parse data for libvirt use. " - "If '--gather' is not set, expects input on stdin.") + subparsers =3D parser.add_subparsers(dest=3D"action") + subparsers.add_parser( + "gather", + help=3D"Acquire data on target system and outputs to stdout. " + "This is the default. ") + subparsers.add_parser( + "parse", + help=3D"Reads data from stdin and parses data for libvirt use.") + subparsers.add_parser( + "full", + help=3D"Equivalent to `cpu-gather gather | cpu-gather parse`.") =20 args =3D parser.parse_args() =20 - if not args.gather and not args.parse: - args.gather =3D True + if not args.action: + args.action =3D "gather" =20 if not args.path_to_qemu: args.path_to_qemu =3D "qemu-system-x86_64" @@ -350,13 +351,13 @@ def main(): if os.path.isfile(f): args.path_to_qemu =3D f =20 - if args.gather: + if args.action in ["gather", "full"]: data =3D gather(args) - if not args.parse: + if args.action =3D=3D "gather": json.dump(data, sys.stdout, indent=3D2) =20 - if args.parse: - if not args.gather: + if args.action in ["parse", "full"]: + if args.action =3D=3D "parse": data =3D json.load(sys.stdin) parse(data) =20 --=20 2.26.2 From nobody Tue May 14 16:20:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1609759854; cv=none; d=zohomail.com; s=zohoarc; b=Ok9km9kVk1mDt0DQ2kpfpbHdpMieDb310otvLwHUOmm9XRuXRJ4Ghm6o9qElJJhz3UbYitkcdr7tBkvjV6Z/n21d89/4VCCQtEWU/MvRumxJSbVksOyt5xXfclp0Qxc6LgdTdOl24walepPh6BA3sMIJ5qv+NcEtycoxCfLoMco= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609759854; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=iOyuX4PNehjuM6MfM9fVn3B6WWhuvkeD2YN3Fv19KEY=; b=MSvdrcx09mja1pCXU1JBDfJ8g36UW48iRb2NsEB/KDduCuLcB4+JhRU/KA8sqB68XeJTssbeId6zMLA3RLwS+D/dXIFcDIF9YgbO5ih88Be+17XMIbJZlyoJjF3r3NffbE8QOGZ5pq2VHUduMgMk98oN2YMjSmGwKt9TUXQLq44= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1609759854675230.18262105234157; Mon, 4 Jan 2021 03:30:54 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-267-nqf1ps1xNP6Nhc0zamaqCA-1; Mon, 04 Jan 2021 06:30:51 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7C60B801FAE; Mon, 4 Jan 2021 11:30:45 +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 5C3AE6F7EF; Mon, 4 Jan 2021 11:30:45 +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 1D7731809CAA; Mon, 4 Jan 2021 11:30:45 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 104BUXYU006552 for ; Mon, 4 Jan 2021 06:30:33 -0500 Received: by smtp.corp.redhat.com (Postfix) id 32C2D5D761; Mon, 4 Jan 2021 11:30:33 +0000 (UTC) Received: from work.redhat.com (ovpn-112-122.ams2.redhat.com [10.36.112.122]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7822A669FC; Mon, 4 Jan 2021 11:30:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1609759853; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=iOyuX4PNehjuM6MfM9fVn3B6WWhuvkeD2YN3Fv19KEY=; b=G5UOQ/j9VwMkOw6UTAIJpYU3MZatB/WBviKX29F0KjqzLYZi0tX/rd96+dDda1eccux4T3 pNnJr8VQzOe7rymu/CPgazcAOa1khd0KMo3ZgU7PgKmIDwQj53sfSd8uAcoQrmfaHmEH1n iXGNJlbF5zjW3IxNHxraO7krL1AYmtA= X-MC-Unique: nqf1ps1xNP6Nhc0zamaqCA-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH 8/9] cpu-gather: Factor out call to cpu-cpuid.py Date: Mon, 4 Jan 2021 12:30:18 +0100 Message-Id: <20210104113019.106513-9-twiederh@redhat.com> In-Reply-To: <20210104113019.106513-1-twiederh@redhat.com> References: <20210104113019.106513-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: Tim Wiederhake 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" This is a preparatory step to merge cpu-cpuid.py. Signed-off-by: Tim Wiederhake --- tests/cputestdata/cpu-gather.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/cputestdata/cpu-gather.py b/tests/cputestdata/cpu-gather= .py index 5ca19e5f2b..a4a4050e42 100755 --- a/tests/cputestdata/cpu-gather.py +++ b/tests/cputestdata/cpu-gather.py @@ -288,7 +288,7 @@ def output_json(data, filename): f.write("\n") =20 =20 -def parse(data): +def parse(args, data): filename =3D parse_filename(data) filename_xml =3D "{}.xml".format(filename) filename_json =3D "{}.json".format(filename) @@ -301,10 +301,7 @@ def parse(data): if os.path.getsize(filename_json) =3D=3D 0: return =20 - output =3D subprocess.check_output( - ["./cpu-cpuid.py", "diff", filename_json], - universal_newlines=3DTrue) - print(output) + args.json_files =3D getattr(args, "json_files", list()) + [filename_js= on] =20 =20 def main(): @@ -359,7 +356,12 @@ def main(): if args.action in ["parse", "full"]: if args.action =3D=3D "parse": data =3D json.load(sys.stdin) - parse(data) + parse(args, data) + + if "json_files" in args: + cmd =3D ["./cpu-cpuid.py", "diff"] + cmd.extend(args.json_files) + subprocess.check_call(cmd, universal_newlines=3DTrue) =20 =20 if __name__ =3D=3D "__main__": --=20 2.26.2 From nobody Tue May 14 16:20:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1609759858; cv=none; d=zohomail.com; s=zohoarc; b=ZXFFzGJQY5JOlKCLBGXIN5wPfIE8K9q328UUS2XDbcYAECDKLEsA0Mi8pUu5AaJ/dUzezs5kHBhkxwMR5CLzW38S/1/C6OLHX+eOpxmpLSzvZ3TWf5njvjuKUVFJqTSe0itdtbmkHTgZ/RHAe1CNSLoLnMyIaQzdiB04FKYKxso= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609759858; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=8xeOUujaZiStIHX1Svi057GyO2y23uz91Lt2Byfu8TA=; b=i13q2xk5bcjAvxkyVUBh9MZNZ8BSv4gOoqACRiZDzFDAf6sSfy1uDrvbpH39sIN6Q/DqABfZEVzsUx2djd3gwdaD2wR98d5C+Z+8b+61WWrsCjG99avPPoskECsa4Y+zUg6687mJVoEU1kbJaoLP8NheBu43U59tVDvkbzKADsk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1609759858094891.5559068794204; Mon, 4 Jan 2021 03:30:58 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-327-xa1J_e1hMe-_KtCbQDEvEw-1; Mon, 04 Jan 2021 06:30:54 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 657A3107ACF5; Mon, 4 Jan 2021 11:30:48 +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 3DE3019726; Mon, 4 Jan 2021 11:30:48 +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 04DCA1809CAE; Mon, 4 Jan 2021 11:30:48 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 104BUYvc006557 for ; Mon, 4 Jan 2021 06:30:34 -0500 Received: by smtp.corp.redhat.com (Postfix) id 4557D5D761; Mon, 4 Jan 2021 11:30:34 +0000 (UTC) Received: from work.redhat.com (ovpn-112-122.ams2.redhat.com [10.36.112.122]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8705761F20; Mon, 4 Jan 2021 11:30:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1609759856; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=8xeOUujaZiStIHX1Svi057GyO2y23uz91Lt2Byfu8TA=; b=VrEfod1+rgmFGblVi1AKk2izLo9POcDLkpLsk8eMYFA1zlTZrN4S3uxIhv/KnMivL4v3o5 OMcJPfaLndV9e8iawmWTEHpNeGyhoPw9GLd2XRuY5tJ/INTVCn9m+dTeeIZsFVd8g4AA8b d2P09Bt1z+1tQsyfTjnRK9ekBDdH5Jc= X-MC-Unique: xa1J_e1hMe-_KtCbQDEvEw-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH 9/9] cpu-gather: Merge cpu-cpuid.py Date: Mon, 4 Jan 2021 12:30:19 +0100 Message-Id: <20210104113019.106513-10-twiederh@redhat.com> In-Reply-To: <20210104113019.106513-1-twiederh@redhat.com> References: <20210104113019.106513-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: Tim Wiederhake 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Old usage: cpu-cpuid.py diff FILE... New usage: cpu-gather.py diff FILE... Signed-off-by: Tim Wiederhake --- tests/cputestdata/cpu-cpuid.py | 152 -------------------------------- tests/cputestdata/cpu-gather.py | 137 +++++++++++++++++++++++++++- 2 files changed, 134 insertions(+), 155 deletions(-) delete mode 100755 tests/cputestdata/cpu-cpuid.py diff --git a/tests/cputestdata/cpu-cpuid.py b/tests/cputestdata/cpu-cpuid.py deleted file mode 100755 index 3e852d5d55..0000000000 --- a/tests/cputestdata/cpu-cpuid.py +++ /dev/null @@ -1,152 +0,0 @@ -#!/usr/bin/env python3 - -import argparse -import os -import sys -import json -import xml.etree.ElementTree - - -_KEYS =3D { - "cpuid": ["eax_in", "ecx_in"], - "msr": ["index"], -} - -_REGS =3D { - "cpuid": ["eax", "ebx", "ecx", "edx"], - "msr": ["eax", "edx"], -} - - -def checkFeature(cpuData, feature): - for key in ["type"] + _KEYS.get(feature["type"], list()): - if feature[key] not in cpuData: - return False - cpuData =3D cpuData[feature[key]] - - for reg in _REGS.get(feature["type"], list()): - if feature[reg] > 0 and feature[reg] =3D=3D feature[reg] & cpuData= [reg]: - return True - return False - - -def addFeature(cpuData, feature): - for key in ["type"] + _KEYS.get(feature["type"], list()): - if feature[key] not in cpuData: - cpuData[feature[key]] =3D dict() - cpuData =3D cpuData[feature[key]] - - for reg in _REGS.get(feature["type"], list()): - cpuData[reg] =3D cpuData.get(reg, 0) | feature[reg] - - -def parseQemu(path, features): - cpuData =3D {} - with open(path, "r") as f: - data, pos =3D json.JSONDecoder().raw_decode(f.read()) - - for (prop, val) in data["return"]["model"]["props"].items(): - if val and prop in features: - addFeature(cpuData, features[prop]) - - return cpuData - - -def parseCPUData(path): - cpuData =3D dict() - for f in xml.etree.ElementTree.parse(path).getroot(): - if f.tag not in ("cpuid", "msr"): - continue - - feature =3D {"type": f.tag} - for reg in _KEYS[f.tag] + _REGS[f.tag]: - feature[reg] =3D int(f.attrib.get(reg, "0"), 0) - addFeature(cpuData, feature) - return cpuData - - -def parseMap(): - path =3D os.path.dirname(sys.argv[0]) - path =3D os.path.join(path, "..", "..", "src", "cpu_map", "x86_feature= s.xml") - - cpuMap =3D dict() - for f in xml.etree.ElementTree.parse(path).getroot().iter("feature"): - if f[0].tag not in ("cpuid", "msr"): - continue - - feature =3D {"type": f[0].tag} - for reg in _KEYS[f[0].tag] + _REGS[f[0].tag]: - feature[reg] =3D int(f[0].attrib.get(reg, "0"), 0) - cpuMap[f.attrib["name"]] =3D feature - return cpuMap - - -def formatCPUData(cpuData, path, comment): - print(path) - with open(path, "w") as f: - f.write("\n") - f.write("\n") - - cpuid =3D cpuData["cpuid"] - for eax_in in sorted(cpuid.keys()): - for ecx_in in sorted(cpuid[eax_in].keys()): - leaf =3D cpuid[eax_in][ecx_in] - line =3D (" \n") - f.write(line % ( - eax_in, ecx_in, - leaf["eax"], leaf["ebx"], leaf["ecx"], leaf["edx"]= )) - - if "msr" in cpuData: - msr =3D cpuData["msr"] - for index in sorted(msr.keys()): - f.write(" \n" % - (index, msr[index]['edx'], msr[index]['eax'])) - - f.write("\n") - - -def diff(args): - cpuMap =3D parseMap() - - for jsonFile in args.json_files: - cpuDataFile =3D jsonFile.replace(".json", ".xml") - enabledFile =3D jsonFile.replace(".json", "-enabled.xml") - disabledFile =3D jsonFile.replace(".json", "-disabled.xml") - - cpuData =3D parseCPUData(cpuDataFile) - qemu =3D parseQemu(jsonFile, cpuMap) - - enabled =3D dict() - disabled =3D dict() - for feature in cpuMap.values(): - if checkFeature(qemu, feature): - addFeature(enabled, feature) - elif checkFeature(cpuData, feature): - addFeature(disabled, feature) - - formatCPUData(enabled, enabledFile, "Features enabled by QEMU") - formatCPUData(disabled, disabledFile, "Features disabled by QEMU") - - -def main(): - parser =3D argparse.ArgumentParser(description=3D"Diff cpuid results") - subparsers =3D parser.add_subparsers(dest=3D"action", required=3DTrue) - diffparser =3D subparsers.add_parser( - "diff", - help=3D"Diff json description of CPU model against known features.= ") - diffparser.add_argument( - "json_files", - nargs=3D"+", - metavar=3D"FILE", - type=3Dos.path.realpath, - help=3D"Path to one or more json CPU model descriptions.") - args =3D parser.parse_args() - - diff(args) - exit(0) - - -if __name__ =3D=3D "__main__": - main() diff --git a/tests/cputestdata/cpu-gather.py b/tests/cputestdata/cpu-gather= .py index a4a4050e42..f679fb9066 100755 --- a/tests/cputestdata/cpu-gather.py +++ b/tests/cputestdata/cpu-gather.py @@ -8,6 +8,18 @@ import re import struct import subprocess import sys +import xml.etree.ElementTree + + +_KEYS =3D { + "cpuid": ["eax_in", "ecx_in"], + "msr": ["index"], +} + +_REGS =3D { + "cpuid": ["eax", "ebx", "ecx", "edx"], + "msr": ["eax", "edx"], +} =20 =20 def gather_name(args): @@ -304,6 +316,118 @@ def parse(args, data): args.json_files =3D getattr(args, "json_files", list()) + [filename_js= on] =20 =20 +def checkFeature(cpuData, feature): + for key in ["type"] + _KEYS.get(feature["type"], list()): + if feature[key] not in cpuData: + return False + cpuData =3D cpuData[feature[key]] + + for reg in _REGS.get(feature["type"], list()): + if feature[reg] > 0 and feature[reg] =3D=3D feature[reg] & cpuData= [reg]: + return True + return False + + +def addFeature(cpuData, feature): + for key in ["type"] + _KEYS.get(feature["type"], list()): + if feature[key] not in cpuData: + cpuData[feature[key]] =3D dict() + cpuData =3D cpuData[feature[key]] + + for reg in _REGS.get(feature["type"], list()): + cpuData[reg] =3D cpuData.get(reg, 0) | feature[reg] + + +def parseQemu(path, features): + cpuData =3D {} + with open(path, "r") as f: + data, pos =3D json.JSONDecoder().raw_decode(f.read()) + + for (prop, val) in data["return"]["model"]["props"].items(): + if val and prop in features: + addFeature(cpuData, features[prop]) + + return cpuData + + +def parseCPUData(path): + cpuData =3D dict() + for f in xml.etree.ElementTree.parse(path).getroot(): + if f.tag not in ("cpuid", "msr"): + continue + + feature =3D {"type": f.tag} + for reg in _KEYS[f.tag] + _REGS[f.tag]: + feature[reg] =3D int(f.attrib.get(reg, "0"), 0) + addFeature(cpuData, feature) + return cpuData + + +def parseMap(): + path =3D os.path.dirname(sys.argv[0]) + path =3D os.path.join(path, "..", "..", "src", "cpu_map", "x86_feature= s.xml") + + cpuMap =3D dict() + for f in xml.etree.ElementTree.parse(path).getroot().iter("feature"): + if f[0].tag not in ("cpuid", "msr"): + continue + + feature =3D {"type": f[0].tag} + for reg in _KEYS[f[0].tag] + _REGS[f[0].tag]: + feature[reg] =3D int(f[0].attrib.get(reg, "0"), 0) + cpuMap[f.attrib["name"]] =3D feature + return cpuMap + + +def formatCPUData(cpuData, path, comment): + print(path) + with open(path, "w") as f: + f.write("\n") + f.write("\n") + + cpuid =3D cpuData["cpuid"] + for eax_in in sorted(cpuid.keys()): + for ecx_in in sorted(cpuid[eax_in].keys()): + leaf =3D cpuid[eax_in][ecx_in] + line =3D (" \n") + f.write(line % ( + eax_in, ecx_in, + leaf["eax"], leaf["ebx"], leaf["ecx"], leaf["edx"]= )) + + if "msr" in cpuData: + msr =3D cpuData["msr"] + for index in sorted(msr.keys()): + f.write(" \n" % + (index, msr[index]['edx'], msr[index]['eax'])) + + f.write("\n") + + +def diff(args): + cpuMap =3D parseMap() + + for jsonFile in args.json_files: + cpuDataFile =3D jsonFile.replace(".json", ".xml") + enabledFile =3D jsonFile.replace(".json", "-enabled.xml") + disabledFile =3D jsonFile.replace(".json", "-disabled.xml") + + cpuData =3D parseCPUData(cpuDataFile) + qemu =3D parseQemu(jsonFile, cpuMap) + + enabled =3D dict() + disabled =3D dict() + for feature in cpuMap.values(): + if checkFeature(qemu, feature): + addFeature(enabled, feature) + elif checkFeature(cpuData, feature): + addFeature(disabled, feature) + + formatCPUData(enabled, enabledFile, "Features enabled by QEMU") + formatCPUData(disabled, disabledFile, "Features disabled by QEMU") + + def main(): parser =3D argparse.ArgumentParser(description=3D"Gather cpu test data= ") parser.add_argument( @@ -332,6 +456,15 @@ def main(): subparsers.add_parser( "full", help=3D"Equivalent to `cpu-gather gather | cpu-gather parse`.") + diffparser =3D subparsers.add_parser( + "diff", + help=3D"Diff json description of CPU model against known features.= ") + diffparser.add_argument( + "json_files", + nargs=3D"+", + metavar=3D"FILE", + type=3Dos.path.realpath, + help=3D"Path to one or more json CPU model descriptions.") =20 args =3D parser.parse_args() =20 @@ -359,9 +492,7 @@ def main(): parse(args, data) =20 if "json_files" in args: - cmd =3D ["./cpu-cpuid.py", "diff"] - cmd.extend(args.json_files) - subprocess.check_call(cmd, universal_newlines=3DTrue) + diff(args) =20 =20 if __name__ =3D=3D "__main__": --=20 2.26.2