From nobody Fri Oct 18 06:19:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1718976275035107.86676656858833; Fri, 21 Jun 2024 06:24:35 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id BD4C112DE; Fri, 21 Jun 2024 09:24:33 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 91B47126D; Fri, 21 Jun 2024 09:24:10 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 94A39CA9; Fri, 21 Jun 2024 09:24:06 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 0285511AF for ; Fri, 21 Jun 2024 09:24:05 -0400 (EDT) Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-488-I8a3juXHNza7aa_kq1BoYg-1; Fri, 21 Jun 2024 09:24:04 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4140D19560AF for ; Fri, 21 Jun 2024 13:24:03 +0000 (UTC) Received: from work.fritz.box (unknown [10.39.193.13]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 039A219560AF; Fri, 21 Jun 2024 13:24:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: *** X-Spam-Status: No, score=3.0 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,RCVD_IN_SBL_CSS,SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718976245; h=from:from: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; bh=etSHn0bRPu7zWh7Tmo7ufU1S1w5GlvMuBOxGraKcVec=; b=fgIhCdI+nYDd5bwLnEcF1YPWVDfJydfsHFuPh2ecHFCVu06dZ9kjA3Qg8xUmGcxk/0l+ep aQNxF6v9qLs9M6WNOVihxUYodl3K02HjymDGl5ztMmPAcscfy8zUzoyA8ed61OO4p5UvvI dwFRpnlmHbcT5wlpc3pIeX2goqxVpt8= X-MC-Unique: I8a3juXHNza7aa_kq1BoYg-1 From: Tim Wiederhake To: devel@lists.libvirt.org Subject: [PATCH] cpu_map: Add libcpuinfo as optional data source Date: Fri, 21 Jun 2024 15:24:00 +0200 Message-ID: <20240621132400.190223-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: DQU2RGW6UK6QMNCGY4Y4DS5OGMVADOGQ X-Message-ID-Hash: DQU2RGW6UK6QMNCGY4Y4DS5OGMVADOGQ X-MailFrom: twiederh@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: Tim Wiederhake X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1718976276698100001 Content-Type: text/plain; charset="utf-8"; x-default="true" This adds an option to use libcpuinfo [1] as data source for libvirt's list of x86 cpu features. This is purely optional and does not change the script's behavior if libcpuinfo is not installed. libcpuinfo is a cross-vendor, cross-architecture source for CPU related information that has the capability to replace libvirt's dependence on qemu's cpu feature list. [1] https://gitlab.com/twiederh/libcpuinfo Signed-off-by: Tim Wiederhake Reviewed-by: Michal Privoznik --- src/cpu_map/libcpuinfo_aliases.xml | 75 +++++++++++++++++++++++++ src/cpu_map/sync_qemu_features_i386.py | 77 +++++++++++++++++++++++--- 2 files changed, 145 insertions(+), 7 deletions(-) create mode 100644 src/cpu_map/libcpuinfo_aliases.xml diff --git a/src/cpu_map/libcpuinfo_aliases.xml b/src/cpu_map/libcpuinfo_al= iases.xml new file mode 100644 index 0000000000..75d243fead --- /dev/null +++ b/src/cpu_map/libcpuinfo_aliases.xml @@ -0,0 +1,75 @@ + + + + + feature + pclmulqdq + pclmuldq + libvirt + + + feature + ds-cpl + ds_cpl + libvirt + + + feature + sse4-1 + sse4.1 + libvirt + + + feature + sse4-2 + sse4.2 + libvirt + + + feature + tsc-adjust + tsc_adjust + libvirt + + + feature + lahf-lm + lahf_lm + libvirt + + + feature + cmp-legacy + cmp_legacy + libvirt + + + feature + nodeid-msr + nodeid_msr + libvirt + + + feature + perfctr-core + perfctr_core + libvirt + + + feature + perfctr-nb + perfctr_nb + libvirt + + + feature + fxsr-opt + fxsr_opt + libvirt + + diff --git a/src/cpu_map/sync_qemu_features_i386.py b/src/cpu_map/sync_qemu= _features_i386.py index e4b1f7275a..3b3ad5a643 100755 --- a/src/cpu_map/sync_qemu_features_i386.py +++ b/src/cpu_map/sync_qemu_features_i386.py @@ -4,6 +4,11 @@ import argparse import os import re =20 +try: + import pycpuinfo +except ImportError: + pycpuinfo =3D None + =20 # features in qemu that we do not want in libvirt FEATURES_IGNORE =3D ( @@ -22,6 +27,7 @@ FEATURES_IGNORE =3D ( "kvm-steal-time", "kvmclock", "kvmclock-stable-bit", + "kvmclock2", =20 "xstore", "xstore-en", @@ -295,6 +301,53 @@ def add_feature_qemu(query, data): add_feature_cpuid(eax, ecx, reg, bit, name) =20 =20 +def add_features_cpuinfo(): + def decode_bit(value): + for i in range(0, 64): + if value =3D=3D (1 << i): + return i + + def decode_cpuid(v): + if v[0] !=3D 0 and v[1] =3D=3D 0 and v[2] =3D=3D 0 and v[3] =3D=3D= 0: + reg, val =3D "eax", v[0] + if v[0] =3D=3D 0 and v[1] !=3D 0 and v[2] =3D=3D 0 and v[3] =3D=3D= 0: + reg, val =3D "ebx", v[1] + if v[0] =3D=3D 0 and v[1] =3D=3D 0 and v[2] !=3D 0 and v[3] =3D=3D= 0: + reg, val =3D "ecx", v[2] + if v[0] =3D=3D 0 and v[1] =3D=3D 0 and v[2] =3D=3D 0 and v[3] !=3D= 0: + reg, val =3D "edx", v[3] + + return reg, decode_bit(val) + + x86 =3D pycpuinfo.Family.find("x86", "") + + for feature in pycpuinfo.features(): + if feature.family() !=3D x86: + continue + + if list(feature.features()): + continue + + name =3D feature.name("libvirt") + if name in FEATURES_IGNORE: + continue + + cpuid =3D feature.extra_x86_cpuid() + if cpuid: + eax =3D cpuid[0] + ecx =3D cpuid[1] + if ecx =3D=3D pycpuinfo.x86.CPUINFO_X86_CPUID_ECX_NONE: + ecx =3D None + reg, bit =3D decode_cpuid(cpuid[2:]) + add_feature_cpuid(eax, ecx, reg, bit, name) + + msr =3D feature.extra_x86_msr() + if msr: + index =3D msr[0] + bit =3D decode_bit(msr[1] | (msr[2] << 32)) + add_feature_msr(index, bit, name) + + # read the `feature_word_info` struct from qemu's cpu.c into a list of str= ings def read_cpu_c(path): pattern_comment =3D re.compile("/\\*.*?\\*/") @@ -450,6 +503,12 @@ def main(): nargs=3D"?", type=3Dos.path.realpath, ) + if pycpuinfo: + parser.add_argument( + "--libcpuinfo", + help=3D"Use libcpuinfo as data source instead", + action=3D"store_true", + ) parser.add_argument( "--output", "-o", @@ -459,14 +518,18 @@ def main(): ) args =3D parser.parse_args() =20 - if not os.path.isdir(args.qemu): - parser.print_help() - exit("qemu source directory not found") + if pycpuinfo and args.libcpuinfo: + add_features_cpuinfo() + else: + if not os.path.isdir(args.qemu): + parser.print_help() + exit("qemu source directory not found") + + read_headers(args.qemu) + lines =3D read_cpu_c(args.qemu) + parse_feature_words(lines) + add_extra_features() =20 - read_headers(args.qemu) - lines =3D read_cpu_c(args.qemu) - parse_feature_words(lines) - add_extra_features() write_output(args.output) =20 print( --=20 2.43.0