From nobody Mon Feb 9 14:38:22 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1690289607; cv=none; d=zohomail.com; s=zohoarc; b=ci9BDNL7hbU/CHX26REARV6SDDDPd20jwGwIpKEKUaRwOHBoZqUVgrI85GaM0vXBcZfvc6WG+6gjaHIIH5MBIEkQronh/euFy6sTgKfWUHBt5fWBBThpZjKMiN29YxVvHLwM5Zr/P3Npg3z3kJ3XWDZYwcNg8675fi8cAJ+S7HE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690289607; 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=mkZm9gh/yZQ/T6EMD/rBg97qNnAEcCAJZYWOxDe4uUg=; b=XHDBGf64QJLNMKAOPe9gdpdSf49Mf2mkcCbpl+E0BjahUkBEFN4LpH1bfAnvsGmd0uPnWAx4cCh0THyjdKNxt1ow3ez5jiW0ASngUQdu1LW3uX+frbyw3d5GqaSLYX2HUXw6kOK9+Sik80hDhAO0wEamw5UwNqPAaN9VeAa3+4M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1690289607726527.5611790999096; Tue, 25 Jul 2023 05:53:27 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-64-iUBtL1MCNWqjnrTTSCi6mg-1; Tue, 25 Jul 2023 08:53:22 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E72A18002BF; Tue, 25 Jul 2023 12:53:19 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id CE0724094DC0; Tue, 25 Jul 2023 12:53:19 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 580BE194E104; Tue, 25 Jul 2023 12:53:08 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id D2A72194E101 for ; Tue, 25 Jul 2023 12:53:06 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id B20CD492CA6; Tue, 25 Jul 2023 12:53:06 +0000 (UTC) Received: from work.fritz.box (unknown [10.39.194.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 43A5F492B01; Tue, 25 Jul 2023 12:53:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1690289606; 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=mkZm9gh/yZQ/T6EMD/rBg97qNnAEcCAJZYWOxDe4uUg=; b=Ry9QyO7be0ZYrCpD+eiSUnUkPwN8g0pjzwrBtTi7PjwnUV6JsRRwNrr5O1unlUkZGbGKHR /c6cqBTwwb9y/KmPhQVSgPcOj8j4oZLiP3Cs8Uhn4epxoVZ1xS4nrHvkPhHvux8ioQxcMG vPxJl+49z7kwBoAdA+9KNgmBDq9twNc= X-MC-Unique: iUBtL1MCNWqjnrTTSCi6mg-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH 5/5] cpu_map: Generate x86 feature map from libcpuinfo Date: Tue, 25 Jul 2023 14:53:01 +0200 Message-Id: <20230725125301.35943-6-twiederh@redhat.com> In-Reply-To: <20230725125301.35943-1-twiederh@redhat.com> References: <20230725125301.35943-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tim Wiederhake Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1690289609487100002 Content-Type: text/plain; charset="utf-8"; x-default="true" Signed-off-by: Tim Wiederhake --- src/cpu_map/x86_features.py | 119 ++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100755 src/cpu_map/x86_features.py diff --git a/src/cpu_map/x86_features.py b/src/cpu_map/x86_features.py new file mode 100755 index 0000000000..5bc7e06216 --- /dev/null +++ b/src/cpu_map/x86_features.py @@ -0,0 +1,119 @@ +#!/bin/env python3 + +import os +import pycpuinfo + +non_migratable =3D ( + "invtsc", + "xsaves", +) + +family_x86 =3D pycpuinfo.Family.find("x86") + +features_cpuid =3D dict() +features_msr =3D dict() + + +def cpuid_to_reg_value(data): + if data[2]: + return "eax", data[2] + if data[3]: + return "ebx", data[3] + if data[4]: + return "ecx", data[4] + if data[5]: + return "edx", data[5] + + +def add_cpuid(feature): + name =3D feature.name("libvirt") + data =3D feature.extra_x86_cpuid() + reg_value =3D cpuid_to_reg_value(data) + + if data[0] not in features_cpuid: + features_cpuid[data[0]] =3D dict() + + if data[1] not in features_cpuid[data[0]]: + features_cpuid[data[0]][data[1]] =3D dict() + + if reg_value[0] not in features_cpuid[data[0]][data[1]]: + features_cpuid[data[0]][data[1]][reg_value[0]] =3D set() + + features_cpuid[data[0]][data[1]][reg_value[0]].add(( + reg_value[1], + name, + )) + + +def add_msr(feature): + data =3D feature.extra_x86_msr() + if data[0] not in features_msr: + features_msr[data[0]] =3D set() + + features_msr[data[0]].add(( + data[2], + data[1], + feature.name("libvirt"), + )) + + +def print_feature_cpuid(f): + tmpl_ecx =3D ( + " \n", + " \n" + ) + tmpl_any =3D ( + " \n", + " \n" + ) + + for eax in sorted(features_cpuid): + for ecx in sorted(features_cpuid[eax]): + if ecx =3D=3D pycpuinfo.x86.CPUINFO_X86_CPUID_ECX_NONE: + template =3D tmpl_any + else: + template =3D tmpl_ecx + + for reg in sorted(features_cpuid[eax][ecx]): + f.write(template[0].format(eax, ecx, reg)) + for data in sorted(features_cpuid[eax][ecx][reg]): + extra =3D "" + if data[1] in non_migratable: + extra =3D " migratable=3D'no'" + f.write(" \n".format(data[1], = extra)) + f.write(template[1].format(eax, ecx, reg, data[0])) + f.write(" \n") + f.write("\n") + + +def print_feature_msr(f): + template =3D " \n" + for msr in sorted(features_msr): + f.write(" \n".format(msr)) + for data in sorted(features_msr[msr]): + f.write(" \n".format(data[2])) + f.write(template.format(msr, data[0], data[1])) + f.write(" \n") + f.write("\n") + + +for feature in pycpuinfo.features(): + if feature.family() !=3D family_x86: + continue + + if feature.extra_x86_cpuid(): + add_cpuid(feature) + elif feature.extra_x86_msr(): + add_msr(feature) + + +filename =3D os.path.join(os.path.dirname(__file__), "x86_features.xml") +with open(filename, "tw") as f: + f.write( + "\n") + f.write("\n") + print_feature_cpuid(f) + print_feature_msr(f) + f.write("\n") --=20 2.39.2