blob: 6a625ac2c33474057ac8ee8a6e23ffb67099a4a2 [file] [log] [blame]
Damjan Marion47d165e2019-01-28 13:27:31 +01001#!/usr/bin/env python3
2
3import json, argparse
4
5p = argparse.ArgumentParser()
6
7p.add_argument('-i', '--input', action="store",
8 help="input JSON file name", required = True)
9
10p.add_argument('-o', '--output', action="store",
11 help="output C file name", required = True)
12
13p.add_argument('-m', '--model', action="append",
14 help="CPU model in format: model[,stepping0]",
15 required = True)
16
17r = p.parse_args()
18
19with open(r.input, 'r') as fp:
20 objects = json.load(fp)
21
22c = open(r.output, 'w')
23
24c.write ("""
25#include <perfmon/perfmon_intel.h>
26
27static perfmon_intel_pmc_cpu_model_t cpu_model_table[] = {
28""")
29
30for v in r.model:
31 if "," in v:
32 (m, s) = v.split(",")
33 m = int(m, 0)
34 s = int(s, 0)
35 c.write (" {}0x{:02X}, 0x{:02X}, 1{},\n".format("{", m, s, "}"))
36 else:
37 m = int(v, 0)
38 c.write (" {}0x{:02X}, 0x00, 0{},\n".format("{", m, "}"))
39c.write ("""
40};
41
42static perfmon_intel_pmc_event_t event_table[] = {
43""")
44
45for obj in objects:
46 MSRIndex = obj["MSRIndex"]
47 if MSRIndex != "0":
48 continue
49
50 EventCode = obj["EventCode"]
51 UMask = obj["UMask"]
52 EventName = obj["EventName"].lower()
53 if "," in EventCode:
54 continue
55
56 c.write (" {\n")
57 c.write (" .event_code = {}{}{},\n".format("{", EventCode, "}"))
58 c.write (" .umask = {},\n".format(UMask))
59 c.write (" .event_name = \"{}\",\n".format(EventName))
60 c.write (" },\n")
61
62
63c.write (""" {
64 .event_name = 0,
65 },
66};
67
68PERFMON_REGISTER_INTEL_PMC (cpu_model_table, event_table);
69
70""")
71
72c.close()