From: Tim Wiederhake Date: Mon, 4 Jan 2021 11:30:14 +0000 (+0100) Subject: cpu-cpuid: Merge addFeature functions X-Git-Tag: v7.0.0-rc1~65 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=41460d4c151725b53ca28c990afc237611f4aa75;p=thirdparty%2Flibvirt.git cpu-cpuid: Merge addFeature functions Prepare to deduplicate the list of relevant registers for cpuid and msr information. Signed-off-by: Tim Wiederhake Reviewed-by: Jiri Denemark --- diff --git a/tests/cputestdata/cpu-cpuid.py b/tests/cputestdata/cpu-cpuid.py index ebf8cdee7e..9065aa5cb2 100755 --- a/tests/cputestdata/cpu-cpuid.py +++ b/tests/cputestdata/cpu-cpuid.py @@ -54,41 +54,25 @@ def checkFeature(cpuData, feature): return checkMSRFeature(cpuData, feature) -def addCPUIDFeature(cpuData, feature): - if "cpuid" not in cpuData: - cpuData["cpuid"] = {} - cpuid = cpuData["cpuid"] - - if feature["eax_in"] not in cpuid: - cpuid[feature["eax_in"]] = {} - leaf = cpuid[feature["eax_in"]] - - if feature["ecx_in"] not in leaf: - leaf[feature["ecx_in"]] = {"eax": 0, "ebx": 0, "ecx": 0, "edx": 0} - leaf = leaf[feature["ecx_in"]] - - for reg in ["eax", "ebx", "ecx", "edx"]: - leaf[reg] |= feature[reg] - - -def addMSRFeature(cpuData, feature): - if "msr" not in cpuData: - cpuData["msr"] = {} - msr = cpuData["msr"] - - if feature["index"] not in msr: - msr[feature["index"]] = {"edx": 0, "eax": 0} - msr = msr[feature["index"]] - - for reg in ["edx", "eax"]: - msr[reg] |= feature[reg] - - def addFeature(cpuData, feature): if feature["type"] == "cpuid": - addCPUIDFeature(cpuData, feature) + # 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": - addMSRFeature(cpuData, feature) + # cpuData["msr"][index] = {eax:, edx:} + keyList = ["type", "index"] + regList = ["eax", "edx"] + else: + return + + for key in keyList: + if feature[key] not in cpuData: + cpuData[feature[key]] = dict() + cpuData = cpuData[feature[key]] + + for reg in regList: + cpuData[reg] = cpuData.get(reg, 0) | feature[reg] def parseQemu(path, features):