1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-22 17:34:18 +03:00

cpu-gather: Move static model expansion 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:24:55 +01:00 committed by Michal Privoznik
parent 028fc10cb3
commit 090259de55
2 changed files with 45 additions and 7 deletions

View File

@ -2,6 +2,7 @@
import argparse
import fcntl
import json
import os
import struct
import subprocess
@ -66,6 +67,47 @@ def gather_msr():
return None, {}
def call_qemu(qemu, qmp_cmds):
cmd = [
qemu,
"-machine", "accel=kvm",
"-cpu", "host",
"-nodefaults",
"-nographic",
"-qmp", "stdio"]
stdin = list()
stdin.append("{\"execute\": \"qmp_capabilities\"}")
stdin.extend([json.dumps(o) for o in qmp_cmds])
stdin.append("{\"execute\": \"quit\"}")
try:
output = subprocess.check_output(
cmd,
universal_newlines=True,
input="\n".join(stdin))
except subprocess.CalledProcessError:
exit("Error: Non-zero exit code from '{}'.".format(qemu))
except FileNotFoundError:
exit("Error: File not found: '{}'.".format(qemu))
return output
def gather_static_model(args):
output = call_qemu(args.path_to_qemu, [
{
"execute": "query-cpu-model-expansion",
"arguments":
{
"type": "static",
"model": {"name": "host"}
},
"id": "model-expansion"
}])
return output
def main():
parser = argparse.ArgumentParser(description="Gather cpu test data")
parser.add_argument(
@ -111,9 +153,12 @@ def main():
for key, value in sorted(msr.items()):
print(" 0x{:x}: 0x{:016x}\n".format(int(key), value))
static_model = gather_static_model(args)
print(end="", flush=True)
os.environ["CPU_GATHER_PY"] = "true"
os.environ["qemu"] = args.path_to_qemu
os.environ["model"] = static_model
subprocess.check_call("./cpu-gather.sh")

View File

@ -21,13 +21,6 @@ model_expansion()
'{"type":"'"$mode"'","model":'"$model"'},"id":"model-expansion"}'
}
model=$(
$qemu -machine accel=kvm -cpu host -nodefaults -nographic -qmp stdio <<EOF
{"execute":"qmp_capabilities"}
$(model_expansion static '{"name":"host"}')
{"execute":"quit"}
EOF
)
model=$(
echo "$model" | \
sed -ne 's/^{"return": {"model": {\(.*{.*}\)}}, .*/{\1}/p'