提交 df9a23be 编写于 作者: J Jiri Denemark

cputest: Prepare cpu-cpuid.py for MSR features

Let's make sure the current CPUID specific code is only applied to CPUID
features.
Signed-off-by: NJiri Denemark <jdenemar@redhat.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
上级 6cbab502
...@@ -5,7 +5,7 @@ import sys ...@@ -5,7 +5,7 @@ import sys
import json import json
import xmltodict import xmltodict
def checkFeature(cpuid, feature): def checkCPUIDFeature(cpuData, feature):
eax_in = feature["eax_in"] eax_in = feature["eax_in"]
ecx_in = feature["ecx_in"] ecx_in = feature["ecx_in"]
eax = feature["eax"] eax = feature["eax"]
...@@ -13,6 +13,10 @@ def checkFeature(cpuid, feature): ...@@ -13,6 +13,10 @@ def checkFeature(cpuid, feature):
ecx = feature["ecx"] ecx = feature["ecx"]
edx = feature["edx"] edx = feature["edx"]
if "cpuid" not in cpuData:
return False
cpuid = cpuData["cpuid"]
if eax_in not in cpuid or ecx_in not in cpuid[eax_in]: if eax_in not in cpuid or ecx_in not in cpuid[eax_in]:
return False return False
...@@ -23,7 +27,18 @@ def checkFeature(cpuid, feature): ...@@ -23,7 +27,18 @@ def checkFeature(cpuid, feature):
(edx > 0 and leaf["edx"] & edx == edx)) (edx > 0 and leaf["edx"] & edx == edx))
def addFeature(cpuid, feature): def checkFeature(cpuData, feature):
if feature["type"] == "cpuid":
return checkCPUIDFeature(cpuData, feature)
return False
def addCPUIDFeature(cpuData, feature):
if "cpuid" not in cpuData:
cpuData["cpuid"] = {}
cpuid = cpuData["cpuid"]
if feature["eax_in"] not in cpuid: if feature["eax_in"] not in cpuid:
cpuid[feature["eax_in"]] = {} cpuid[feature["eax_in"]] = {}
leaf = cpuid[feature["eax_in"]] leaf = cpuid[feature["eax_in"]]
...@@ -36,6 +51,11 @@ def addFeature(cpuid, feature): ...@@ -36,6 +51,11 @@ def addFeature(cpuid, feature):
leaf[reg] |= feature[reg] leaf[reg] |= feature[reg]
def addFeature(cpuData, feature):
if feature["type"] == "cpuid":
addCPUIDFeature(cpuData, feature)
def parseQemu(path, features): def parseQemu(path, features):
cpuData = {} cpuData = {}
with open(path, "r") as f: with open(path, "r") as f:
...@@ -54,7 +74,7 @@ def parseCPUData(path): ...@@ -54,7 +74,7 @@ def parseCPUData(path):
data = xmltodict.parse(f) data = xmltodict.parse(f)
for leaf in data["cpudata"]["cpuid"]: for leaf in data["cpudata"]["cpuid"]:
feature = {} feature = {"type": "cpuid"}
feature["eax_in"] = int(leaf["@eax_in"], 0) feature["eax_in"] = int(leaf["@eax_in"], 0)
feature["ecx_in"] = int(leaf["@ecx_in"], 0) feature["ecx_in"] = int(leaf["@ecx_in"], 0)
for reg in ["eax", "ebx", "ecx", "edx"]: for reg in ["eax", "ebx", "ecx", "edx"]:
...@@ -66,7 +86,7 @@ def parseCPUData(path): ...@@ -66,7 +86,7 @@ def parseCPUData(path):
def parseMapFeature(data): def parseMapFeature(data):
cpuid = {} cpuid = {"type": "cpuid"}
for reg in ["eax_in", "ecx_in", "eax", "ebx", "ecx", "edx"]: for reg in ["eax_in", "ecx_in", "eax", "ebx", "ecx", "edx"]:
attr = "@%s" % reg attr = "@%s" % reg
...@@ -92,11 +112,13 @@ def parseMap(): ...@@ -92,11 +112,13 @@ def parseMap():
return cpuMap return cpuMap
def formatCPUData(cpuid, path, comment): def formatCPUData(cpuData, 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")
f.write("<cpudata arch='x86'>\n") f.write("<cpudata arch='x86'>\n")
cpuid = cpuData["cpuid"]
for eax_in in sorted(cpuid.keys()): for eax_in in sorted(cpuid.keys()):
for ecx_in in sorted(cpuid[eax_in].keys()): for ecx_in in sorted(cpuid[eax_in].keys()):
leaf = cpuid[eax_in][ecx_in] leaf = cpuid[eax_in][ecx_in]
...@@ -119,8 +141,8 @@ def diff(cpuMap, path): ...@@ -119,8 +141,8 @@ def diff(cpuMap, path):
cpuData = parseCPUData(cpuDataFile) cpuData = parseCPUData(cpuDataFile)
qemu = parseQemu(jsonFile, cpuMap) qemu = parseQemu(jsonFile, cpuMap)
enabled = {} enabled = {"cpuid": {}}
disabled = {} disabled = {"cpuid": {}}
for feature in cpuMap.values(): for feature in cpuMap.values():
if checkFeature(qemu, feature): if checkFeature(qemu, feature):
addFeature(enabled, feature) addFeature(enabled, feature)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册