mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-03 11:35:19 +00:00
cpu-cpuid: Deduplicate register list
Signed-off-by: Tim Wiederhake <twiederh@redhat.com> Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
This commit is contained in:
parent
21d097c4e1
commit
d90738bacc
@ -7,47 +7,36 @@ import json
|
|||||||
import xml.etree.ElementTree
|
import xml.etree.ElementTree
|
||||||
|
|
||||||
|
|
||||||
def checkFeature(cpuData, feature):
|
_KEYS = {
|
||||||
if feature["type"] == "cpuid":
|
"cpuid": ["eax_in", "ecx_in"],
|
||||||
# cpuData["cpuid"][eax_in][ecx_in] = {eax:, ebx:, ecx:, edx:}
|
"msr": ["index"],
|
||||||
keyList = ["type", "eax_in", "ecx_in"]
|
}
|
||||||
regList = ["eax", "ebx", "ecx", "edx"]
|
|
||||||
elif feature["type"] == "msr":
|
|
||||||
# cpuData["msr"][index] = {eax:, edx:}
|
|
||||||
keyList = ["type", "index"]
|
|
||||||
regList = ["eax", "edx"]
|
|
||||||
else:
|
|
||||||
return False
|
|
||||||
|
|
||||||
for key in keyList:
|
_REGS = {
|
||||||
|
"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:
|
if feature[key] not in cpuData:
|
||||||
return False
|
return False
|
||||||
cpuData = cpuData[feature[key]]
|
cpuData = cpuData[feature[key]]
|
||||||
|
|
||||||
for reg in regList:
|
for reg in _REGS.get(feature["type"], list()):
|
||||||
if feature[reg] > 0 and feature[reg] == feature[reg] & cpuData[reg]:
|
if feature[reg] > 0 and feature[reg] == feature[reg] & cpuData[reg]:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def addFeature(cpuData, feature):
|
def addFeature(cpuData, feature):
|
||||||
if feature["type"] == "cpuid":
|
for key in ["type"] + _KEYS.get(feature["type"], list()):
|
||||||
# cpuData["cpuid"][eax_in][ecx_in] = {eax:, ebx:, ecx:, edx:}
|
|
||||||
keyList = ["type", "eax_in", "ecx_in"]
|
|
||||||
regList = ["eax", "ebx", "ecx", "edx"]
|
|
||||||
elif feature["type"] == "msr":
|
|
||||||
# cpuData["msr"][index] = {eax:, edx:}
|
|
||||||
keyList = ["type", "index"]
|
|
||||||
regList = ["eax", "edx"]
|
|
||||||
else:
|
|
||||||
return
|
|
||||||
|
|
||||||
for key in keyList:
|
|
||||||
if feature[key] not in cpuData:
|
if feature[key] not in cpuData:
|
||||||
cpuData[feature[key]] = dict()
|
cpuData[feature[key]] = dict()
|
||||||
cpuData = cpuData[feature[key]]
|
cpuData = cpuData[feature[key]]
|
||||||
|
|
||||||
for reg in regList:
|
for reg in _REGS.get(feature["type"], list()):
|
||||||
cpuData[reg] = cpuData.get(reg, 0) | feature[reg]
|
cpuData[reg] = cpuData.get(reg, 0) | feature[reg]
|
||||||
|
|
||||||
|
|
||||||
@ -66,15 +55,11 @@ def parseQemu(path, features):
|
|||||||
def parseCPUData(path):
|
def parseCPUData(path):
|
||||||
cpuData = dict()
|
cpuData = dict()
|
||||||
for f in xml.etree.ElementTree.parse(path).getroot():
|
for f in xml.etree.ElementTree.parse(path).getroot():
|
||||||
if f.tag == "cpuid":
|
if f.tag not in ("cpuid", "msr"):
|
||||||
reg_list = ["eax_in", "ecx_in", "eax", "ebx", "ecx", "edx"]
|
|
||||||
elif f.tag == "msr":
|
|
||||||
reg_list = ["index", "eax", "edx"]
|
|
||||||
else:
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
feature = {"type": f.tag}
|
feature = {"type": f.tag}
|
||||||
for reg in reg_list:
|
for reg in _KEYS[f.tag] + _REGS[f.tag]:
|
||||||
feature[reg] = int(f.attrib.get(reg, "0"), 0)
|
feature[reg] = int(f.attrib.get(reg, "0"), 0)
|
||||||
addFeature(cpuData, feature)
|
addFeature(cpuData, feature)
|
||||||
return cpuData
|
return cpuData
|
||||||
@ -86,15 +71,11 @@ def parseMap():
|
|||||||
|
|
||||||
cpuMap = dict()
|
cpuMap = dict()
|
||||||
for f in xml.etree.ElementTree.parse(path).getroot().iter("feature"):
|
for f in xml.etree.ElementTree.parse(path).getroot().iter("feature"):
|
||||||
if f[0].tag == "cpuid":
|
if f[0].tag not in ("cpuid", "msr"):
|
||||||
reg_list = ["eax_in", "ecx_in", "eax", "ebx", "ecx", "edx"]
|
|
||||||
elif f[0].tag == "msr":
|
|
||||||
reg_list = ["index", "eax", "edx"]
|
|
||||||
else:
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
feature = {"type": f[0].tag}
|
feature = {"type": f[0].tag}
|
||||||
for reg in reg_list:
|
for reg in _KEYS[f[0].tag] + _REGS[f[0].tag]:
|
||||||
feature[reg] = int(f[0].attrib.get(reg, "0"), 0)
|
feature[reg] = int(f[0].attrib.get(reg, "0"), 0)
|
||||||
cpuMap[f.attrib["name"]] = feature
|
cpuMap[f.attrib["name"]] = feature
|
||||||
return cpuMap
|
return cpuMap
|
||||||
|
Loading…
Reference in New Issue
Block a user