2019-01-28 13:27:31 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import json, argparse
|
|
|
|
|
|
|
|
p = argparse.ArgumentParser()
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
p.add_argument(
|
|
|
|
"-i", "--input", action="store", help="input JSON file name", required=True
|
|
|
|
)
|
|
|
|
|
|
|
|
p.add_argument(
|
|
|
|
"-o", "--output", action="store", help="output C file name", required=True
|
|
|
|
)
|
|
|
|
|
|
|
|
p.add_argument(
|
|
|
|
"-m",
|
|
|
|
"--model",
|
|
|
|
action="append",
|
|
|
|
help="CPU model in format: model[,stepping0]",
|
|
|
|
required=True,
|
|
|
|
)
|
2019-01-28 13:27:31 +01:00
|
|
|
|
|
|
|
r = p.parse_args()
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
with open(r.input, "r") as fp:
|
2019-01-28 13:27:31 +01:00
|
|
|
objects = json.load(fp)
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
c = open(r.output, "w")
|
2019-01-28 13:27:31 +01:00
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
c.write(
|
|
|
|
"""
|
2019-01-28 13:27:31 +01:00
|
|
|
#include <perfmon/perfmon_intel.h>
|
|
|
|
|
|
|
|
static perfmon_intel_pmc_cpu_model_t cpu_model_table[] = {
|
2022-04-26 19:02:15 +02:00
|
|
|
"""
|
|
|
|
)
|
2019-01-28 13:27:31 +01:00
|
|
|
|
|
|
|
for v in r.model:
|
|
|
|
if "," in v:
|
2022-04-26 19:02:15 +02:00
|
|
|
(m, s) = v.split(",")
|
2019-01-28 13:27:31 +01:00
|
|
|
m = int(m, 0)
|
|
|
|
s = int(s, 0)
|
2022-04-26 19:02:15 +02:00
|
|
|
c.write(" {}0x{:02X}, 0x{:02X}, 1{},\n".format("{", m, s, "}"))
|
2019-01-28 13:27:31 +01:00
|
|
|
else:
|
|
|
|
m = int(v, 0)
|
2022-04-26 19:02:15 +02:00
|
|
|
c.write(" {}0x{:02X}, 0x00, 0{},\n".format("{", m, "}"))
|
|
|
|
c.write(
|
|
|
|
"""
|
2019-01-28 13:27:31 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static perfmon_intel_pmc_event_t event_table[] = {
|
2022-04-26 19:02:15 +02:00
|
|
|
"""
|
|
|
|
)
|
2019-01-28 13:27:31 +01:00
|
|
|
|
|
|
|
for obj in objects:
|
|
|
|
MSRIndex = obj["MSRIndex"]
|
|
|
|
if MSRIndex != "0":
|
2022-04-26 19:02:15 +02:00
|
|
|
continue
|
2019-01-28 13:27:31 +01:00
|
|
|
|
|
|
|
EventCode = obj["EventCode"]
|
|
|
|
UMask = obj["UMask"]
|
|
|
|
EventName = obj["EventName"].lower()
|
|
|
|
if "," in EventCode:
|
|
|
|
continue
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
c.write(" {\n")
|
|
|
|
c.write(" .event_code = {}{}{},\n".format("{", EventCode, "}"))
|
|
|
|
c.write(" .umask = {},\n".format(UMask))
|
|
|
|
c.write(' .event_name = "{}",\n'.format(EventName))
|
|
|
|
c.write(" },\n")
|
2019-01-28 13:27:31 +01:00
|
|
|
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
c.write(
|
|
|
|
""" {
|
2019-01-28 13:27:31 +01:00
|
|
|
.event_name = 0,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
PERFMON_REGISTER_INTEL_PMC (cpu_model_table, event_table);
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
"""
|
|
|
|
)
|
2019-01-28 13:27:31 +01:00
|
|
|
|
|
|
|
c.close()
|