From 65d242ff5e57319c065cec4192dcec6237d60b91 Mon Sep 17 00:00:00 2001 From: Lionel Landwerlin Date: Thu, 2 Apr 2020 16:29:30 +0300 Subject: [PATCH] intel/perf: update generated code to ralloc all data Previously counter descriptions as well register values were written in global static variables. This isn't really thread safe so instead ralloc all the data back under the gen_perf_config object. Signed-off-by: Lionel Landwerlin Reviewed-by: Jason Ekstrand Part-of: --- src/intel/perf/gen_perf.py | 74 +++++++++++++++----------------------- 1 file changed, 29 insertions(+), 45 deletions(-) diff --git a/src/intel/perf/gen_perf.py b/src/intel/perf/gen_perf.py index caee7725b63..a82259c7edb 100644 --- a/src/intel/perf/gen_perf.py +++ b/src/intel/perf/gen_perf.py @@ -413,6 +413,7 @@ def compute_register_lengths(set): def generate_register_configs(set): register_configs = set.findall('register_config') + for register_config in register_configs: t = register_types[register_config.get('type')] @@ -421,7 +422,9 @@ def generate_register_configs(set): output_availability(set, availability, register_config.get('type') + ' register config') c_indent(3) - for register in register_config.findall('register'): + registers = register_config.findall('register') + c("query->config.%s = rzalloc_array(query, struct gen_perf_query_register_prog, %d);" % (t, len(registers))) + for register in registers: c("query->config.%s[query->config.n_%s++] = (struct gen_perf_query_register_prog) { .reg = %s, .val = %s };" % (t, t, register.get('address'), register.get('value'))) @@ -626,6 +629,7 @@ def main(): #include #include "util/hash_table.h" + #include "util/ralloc.h" """)) @@ -655,64 +659,44 @@ def main(): counters = set.counters c("\n") - register_lengths = compute_register_lengths(set); - for reg_type, reg_length in register_lengths.items(): - c("static struct gen_perf_query_register_prog {0}_{1}_{2}[{3}];".format(gen.chipset, - set.underscore_name, - reg_type, reg_length)) - - c("\nstatic struct gen_perf_query_counter {0}_{1}_query_counters[{2}];\n".format(gen.chipset, set.underscore_name, len(counters))) - c("static struct gen_perf_query_info " + gen.chipset + "_" + set.underscore_name + "_query = {\n") + c("\nstatic void\n") + c("{0}_register_{1}_counter_query(struct gen_perf_config *perf)\n".format(gen.chipset, set.underscore_name)) + c("{\n") c_indent(3) - c(".kind = GEN_PERF_QUERY_TYPE_OA,\n") - c(".name = \"" + set.name + "\",\n") - c(".guid = \"" + set.hw_config_guid + "\",\n") + c("struct gen_perf_query_info *query = rzalloc(perf, struct gen_perf_query_info);\n") + c("\n") + c("query->kind = GEN_PERF_QUERY_TYPE_OA;\n") + c("query->name = \"" + set.name + "\";\n") + c("query->guid = \"" + set.hw_config_guid + "\";\n") - c(".counters = {0}_{1}_query_counters,".format(gen.chipset, set.underscore_name)) - c(".n_counters = 0,") - c(".oa_metrics_set_id = 0, /* determined at runtime, via sysfs */") + c("query->counters = rzalloc_array(query, struct gen_perf_query_counter, %u);" % len(counters)) + c("query->n_counters = 0;") + c("query->oa_metrics_set_id = 0; /* determined at runtime, via sysfs */") if gen.chipset == "hsw": c(textwrap.dedent("""\ - .oa_format = I915_OA_FORMAT_A45_B8_C8, - + query->oa_format = I915_OA_FORMAT_A45_B8_C8; /* Accumulation buffer offsets... */ - .gpu_time_offset = 0, - .a_offset = 1, - .b_offset = 46, - .c_offset = 54, + query->gpu_time_offset = 0; + query->a_offset = 1; + query->b_offset = 46; + query->c_offset = 54; """)) else: c(textwrap.dedent("""\ - .oa_format = I915_OA_FORMAT_A32u40_A4u32_B8_C8, - + query->oa_format = I915_OA_FORMAT_A32u40_A4u32_B8_C8; /* Accumulation buffer offsets... */ - .gpu_time_offset = 0, - .gpu_clock_offset = 1, - .a_offset = 2, - .b_offset = 38, - .c_offset = 46, + query->gpu_time_offset = 0; + query->gpu_clock_offset = 1; + query->a_offset = 2; + query->b_offset = 38; + query->c_offset = 46; """)) - c(".config = {") - c_indent(3) - for reg_type, reg_length in register_lengths.items(): - c(".{0} = {1}_{2}_{3},".format(reg_type, gen.chipset, set.underscore_name, reg_type)) - c(".n_{0} = 0, /* Determined at runtime */".format(reg_type)) - c_outdent(3) - c("},") - c_outdent(3) - c("};\n") - - c("\nstatic void\n") - c("{0}_register_{1}_counter_query(struct gen_perf_config *perf)\n".format(gen.chipset, set.underscore_name)) - c("{\n") - c_indent(3) - - c("static struct gen_perf_query_info *query = &" + gen.chipset + "_" + set.underscore_name + "_query;\n") - c("struct gen_perf_query_counter *counter;\n") + c("\n") + c("struct gen_perf_query_counter *counter = query->counters;\n") c("\n") c("/* Note: we're assuming there can't be any variation in the definition ") -- 2.30.2