aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/perfmon/intel_json_to_c.py
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2019-01-28 13:27:31 +0100
committerFilip Tehlar <ftehlar@cisco.com>2019-03-20 03:06:52 -0700
commit47d165e4c1a5f571995d39b0ce142c06f17dea47 (patch)
tree8490a7c1194967746017df72c3e3322831a2203e /src/plugins/perfmon/intel_json_to_c.py
parentd89411ef5f59b91101b0311a2dd41a3641985d1e (diff)
perfmon: python to C parser for intel CPUs
EXAMPLE: src/plugins/perfmon/intel_json_to_c.py \ -i skylakex_core_v1.12.json \ -o src/plugins/perfmon/perfmon_intel_skx.c \ -m 0x55,0 \ -m 0x55,1 \ -m 0x55,2 \ -m 0x55,3 Change-Id: I16ce059e231d340ecfcb6f6638e29c5b46304683 Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src/plugins/perfmon/intel_json_to_c.py')
-rwxr-xr-xsrc/plugins/perfmon/intel_json_to_c.py72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/plugins/perfmon/intel_json_to_c.py b/src/plugins/perfmon/intel_json_to_c.py
new file mode 100755
index 00000000000..6a625ac2c33
--- /dev/null
+++ b/src/plugins/perfmon/intel_json_to_c.py
@@ -0,0 +1,72 @@
+#!/usr/bin/env python3
+
+import json, argparse
+
+p = argparse.ArgumentParser()
+
+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)
+
+r = p.parse_args()
+
+with open(r.input, 'r') as fp:
+ objects = json.load(fp)
+
+c = open(r.output, 'w')
+
+c.write ("""
+#include <perfmon/perfmon_intel.h>
+
+static perfmon_intel_pmc_cpu_model_t cpu_model_table[] = {
+""")
+
+for v in r.model:
+ if "," in v:
+ (m, s) = v.split(",")
+ m = int(m, 0)
+ s = int(s, 0)
+ c.write (" {}0x{:02X}, 0x{:02X}, 1{},\n".format("{", m, s, "}"))
+ else:
+ m = int(v, 0)
+ c.write (" {}0x{:02X}, 0x00, 0{},\n".format("{", m, "}"))
+c.write ("""
+};
+
+static perfmon_intel_pmc_event_t event_table[] = {
+""")
+
+for obj in objects:
+ MSRIndex = obj["MSRIndex"]
+ if MSRIndex != "0":
+ continue
+
+ EventCode = obj["EventCode"]
+ UMask = obj["UMask"]
+ EventName = obj["EventName"].lower()
+ if "," in EventCode:
+ continue
+
+ 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")
+
+
+c.write (""" {
+ .event_name = 0,
+ },
+};
+
+PERFMON_REGISTER_INTEL_PMC (cpu_model_table, event_table);
+
+""")
+
+c.close()