mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
cputest: Generalize function names in cpu-cpuid.py
The function will have to deal with both CPUID and MSR features. Signed-off-by: Jiri Denemark <jdenemar@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
ee6185db02
commit
a7ad56edd9
@ -5,7 +5,7 @@ import sys
|
|||||||
import json
|
import json
|
||||||
import xmltodict
|
import xmltodict
|
||||||
|
|
||||||
def cpuidIsSet(cpuid, feature):
|
def checkFeature(cpuid, feature):
|
||||||
in_eax = feature["in_eax"]
|
in_eax = feature["in_eax"]
|
||||||
in_ecx = feature["in_ecx"]
|
in_ecx = feature["in_ecx"]
|
||||||
eax = feature["eax"]
|
eax = feature["eax"]
|
||||||
@ -23,7 +23,7 @@ def cpuidIsSet(cpuid, feature):
|
|||||||
(edx > 0 and leaf["edx"] & edx > 0))
|
(edx > 0 and leaf["edx"] & edx > 0))
|
||||||
|
|
||||||
|
|
||||||
def cpuidAdd(cpuid, feature):
|
def addFeature(cpuid, feature):
|
||||||
if feature["in_eax"] not in cpuid:
|
if feature["in_eax"] not in cpuid:
|
||||||
cpuid[feature["in_eax"]] = {}
|
cpuid[feature["in_eax"]] = {}
|
||||||
leaf = cpuid[feature["in_eax"]]
|
leaf = cpuid[feature["in_eax"]]
|
||||||
@ -37,19 +37,19 @@ def cpuidAdd(cpuid, feature):
|
|||||||
|
|
||||||
|
|
||||||
def parseQemu(path, features):
|
def parseQemu(path, features):
|
||||||
cpuid = {}
|
cpuData = {}
|
||||||
with open(path, "r") as f:
|
with open(path, "r") as f:
|
||||||
data, pos = json.JSONDecoder().raw_decode(f.read())
|
data, pos = json.JSONDecoder().raw_decode(f.read())
|
||||||
|
|
||||||
for (prop, val) in data["return"]["model"]["props"].items():
|
for (prop, val) in data["return"]["model"]["props"].items():
|
||||||
if val and prop in features:
|
if val and prop in features:
|
||||||
cpuidAdd(cpuid, features[prop])
|
addFeature(cpuData, features[prop])
|
||||||
|
|
||||||
return cpuid
|
return cpuData
|
||||||
|
|
||||||
|
|
||||||
def parseCpuid(path):
|
def parseCPUData(path):
|
||||||
cpuid = {}
|
cpuData = {}
|
||||||
with open(path, "rb") as f:
|
with open(path, "rb") as f:
|
||||||
data = xmltodict.parse(f)
|
data = xmltodict.parse(f)
|
||||||
|
|
||||||
@ -60,12 +60,12 @@ def parseCpuid(path):
|
|||||||
for reg in ["eax", "ebx", "ecx", "edx"]:
|
for reg in ["eax", "ebx", "ecx", "edx"]:
|
||||||
feature[reg] = int(leaf["@" + reg], 0)
|
feature[reg] = int(leaf["@" + reg], 0)
|
||||||
|
|
||||||
cpuidAdd(cpuid, feature)
|
addFeature(cpuData, feature)
|
||||||
|
|
||||||
return cpuid
|
return cpuData
|
||||||
|
|
||||||
|
|
||||||
def parseFeature(data):
|
def parseMapFeature(data):
|
||||||
cpuid = {}
|
cpuid = {}
|
||||||
for reg in ["in_eax", "in_ecx", "eax", "ebx", "ecx", "edx"]:
|
for reg in ["in_eax", "in_ecx", "eax", "ebx", "ecx", "edx"]:
|
||||||
if reg.startswith("in_"):
|
if reg.startswith("in_"):
|
||||||
@ -90,12 +90,12 @@ def parseMap():
|
|||||||
cpuMap = {}
|
cpuMap = {}
|
||||||
for feature in data["cpus"]["feature"]:
|
for feature in data["cpus"]["feature"]:
|
||||||
if "cpuid" in feature:
|
if "cpuid" in feature:
|
||||||
cpuMap[feature["@name"]] = parseFeature(feature["cpuid"])
|
cpuMap[feature["@name"]] = parseMapFeature(feature["cpuid"])
|
||||||
|
|
||||||
return cpuMap
|
return cpuMap
|
||||||
|
|
||||||
|
|
||||||
def formatCpuid(cpuid, path, comment):
|
def formatCPUData(cpuid, path, comment):
|
||||||
print(path)
|
print(path)
|
||||||
with open(path, "w") as f:
|
with open(path, "w") as f:
|
||||||
f.write("<!-- " + comment + " -->\n")
|
f.write("<!-- " + comment + " -->\n")
|
||||||
@ -115,23 +115,23 @@ def formatCpuid(cpuid, path, comment):
|
|||||||
def diff(cpuMap, path):
|
def diff(cpuMap, path):
|
||||||
base = path.replace(".json", "")
|
base = path.replace(".json", "")
|
||||||
jsonFile = path
|
jsonFile = path
|
||||||
cpuidFile = base + ".xml"
|
cpuDataFile = base + ".xml"
|
||||||
enabledFile = base + "-enabled.xml"
|
enabledFile = base + "-enabled.xml"
|
||||||
disabledFile = base + "-disabled.xml"
|
disabledFile = base + "-disabled.xml"
|
||||||
|
|
||||||
cpuid = parseCpuid(cpuidFile)
|
cpuData = parseCPUData(cpuDataFile)
|
||||||
qemu = parseQemu(jsonFile, cpuMap)
|
qemu = parseQemu(jsonFile, cpuMap)
|
||||||
|
|
||||||
enabled = {}
|
enabled = {}
|
||||||
disabled = {}
|
disabled = {}
|
||||||
for feature in cpuMap.values():
|
for feature in cpuMap.values():
|
||||||
if cpuidIsSet(qemu, feature):
|
if checkFeature(qemu, feature):
|
||||||
cpuidAdd(enabled, feature)
|
addFeature(enabled, feature)
|
||||||
elif cpuidIsSet(cpuid, feature):
|
elif checkFeature(cpuData, feature):
|
||||||
cpuidAdd(disabled, feature)
|
addFeature(disabled, feature)
|
||||||
|
|
||||||
formatCpuid(enabled, enabledFile, "Features enabled by QEMU")
|
formatCPUData(enabled, enabledFile, "Features enabled by QEMU")
|
||||||
formatCpuid(disabled, disabledFile, "Features disabled by QEMU")
|
formatCPUData(disabled, disabledFile, "Features disabled by QEMU")
|
||||||
|
|
||||||
|
|
||||||
if len(sys.argv) < 3:
|
if len(sys.argv) < 3:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user