cpu-parse: Move xml output to new script

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Tim Wiederhake 2020-12-15 17:25:06 +01:00 committed by Michal Privoznik
parent 43d3703d3a
commit 58a1ad721f
2 changed files with 40 additions and 18 deletions

View File

@ -207,10 +207,50 @@ def parse_filename(data):
return "x86_64-cpuid-{}".format(filename) return "x86_64-cpuid-{}".format(filename)
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 = \
" <cpuid" \
" eax_in='{}'" \
" ecx_in='{}'" \
" eax='{}'" \
" ebx='{}'" \
" ecx='{}'" \
" edx='{}'" \
"/>\n"
msr_template = " <msr index='0x{:x}' edx='0x{:08x}' eax='0x{:08x}'/>\n"
print(filename)
with open(filename, "wt") as f:
f.write("<!-- {} -->\n".format(data["name"]))
f.write("<cpudata arch='x86'>\n")
for line in data["leaves"]:
match = leave_pattern.match(line)
f.write(leave_template.format(*match.groups()))
for key, value in sorted(data["msr"].items()):
f.write(msr_template.format(
int(key),
0xffffffff & (value >> 32),
0xffffffff & (value >> 0)))
f.write("</cpudata>\n")
def parse(args): def parse(args):
data = json.load(sys.stdin) data = json.load(sys.stdin)
filename = parse_filename(data) filename = parse_filename(data)
filename_xml = "{}.xml".format(filename)
output_xml(data, filename_xml)
os.environ["CPU_GATHER_PY"] = "true" os.environ["CPU_GATHER_PY"] = "true"
os.environ["model"] = data["name"] os.environ["model"] = data["name"]

View File

@ -7,21 +7,6 @@ fi
data=`cat` data=`cat`
xml()
{
hex='\(0x[0-9a-f]\+\)'
matchCPUID="$hex $hex: eax=$hex ebx=$hex ecx=$hex edx=$hex"
substCPUID="<cpuid eax_in='\\1' ecx_in='\\2' eax='\\3' ebx='\\4' ecx='\\5' edx='\\6'\\/>"
matchMSR="$hex: $hex\(.......[0-9a-f]\)"
substMSR="<msr index='\\1' edx='\\2' eax='0x\\3'\\/>"
echo "<!-- $model -->"
echo "<cpudata arch='x86'>"
sed -ne "s/^ *$matchCPUID$/ $substCPUID/p; s/^ *$matchMSR$/ $substMSR/p"
echo "</cpudata>"
}
json() json()
{ {
first=true first=true
@ -36,9 +21,6 @@ json()
done done
} }
xml <<<"$data" >$fname.xml
echo $fname.xml
json <<<"$data" >$fname.json json <<<"$data" >$fname.json
if [[ -s $fname.json ]]; then if [[ -s $fname.json ]]; then
echo $fname.json echo $fname.json