From: Tim Wiederhake Date: Tue, 15 Dec 2020 16:25:12 +0000 (+0100) Subject: cpu-gather: Parse cpuid leaves early X-Git-Tag: v7.0.0-rc1~144 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=731b922a657ec359797196b1c32f67ea8e163de9;p=thirdparty%2Flibvirt.git cpu-gather: Parse cpuid leaves early Signed-off-by: Tim Wiederhake Reviewed-by: Michal Privoznik --- diff --git a/tests/cputestdata/cpu-gather.py b/tests/cputestdata/cpu-gather.py index 49c72df320..fe660c486e 100755 --- a/tests/cputestdata/cpu-gather.py +++ b/tests/cputestdata/cpu-gather.py @@ -24,6 +24,15 @@ def gather_name(args): def gather_cpuid_leaves(args): + leave_pattern = re.compile( + "^\\s*" + "(0x[0-9a-f]+)\\s*" + "(0x[0-9a-f]+):\\s*" + "eax=(0x[0-9a-f]+)\\s*" + "ebx=(0x[0-9a-f]+)\\s*" + "ecx=(0x[0-9a-f]+)\\s*" + "edx=(0x[0-9a-f]+)\\s*$") + cpuid = args.path_to_cpuid or "cpuid" try: output = subprocess.check_output( @@ -36,11 +45,16 @@ def gather_cpuid_leaves(args): "'http://www.etallen.com/cpuid.html'.".format(e.filename)) for line in output.split("\n"): - if not line: + match = leave_pattern.match(line) + if not match: continue - if line == "CPU:": - continue - yield line.strip() + yield { + "eax_in": int(match.group(1), 0), + "ecx_in": int(match.group(2), 0), + "eax": int(match.group(3), 0), + "ebx": int(match.group(4), 0), + "ecx": int(match.group(5), 0), + "edx": int(match.group(6), 0)} def gather_msr(): @@ -214,23 +228,14 @@ def parse_filename(data): def output_xml(data, filename): - leave_pattern = re.compile( - "^\\s*" - "(0x[0-9a-f]+)\\s*" - "(0x[0-9a-f]+):\\s*" - "eax=(0x[0-9a-f]+)\\s*" - "ebx=(0x[0-9a-f]+)\\s*" - "ecx=(0x[0-9a-f]+)\\s*" - "edx=(0x[0-9a-f]+)\\s*$") - leave_template = \ " \n" msr_template = " \n" @@ -239,9 +244,8 @@ def output_xml(data, filename): with open(filename, "wt") as f: f.write("\n".format(data["name"])) f.write("\n") - for line in data["leaves"]: - match = leave_pattern.match(line) - f.write(leave_template.format(*match.groups())) + for leave in data["leaves"]: + f.write(leave_template.format(leave)) for key, value in sorted(data["msr"].items()): f.write(msr_template.format( int(key),