i965: Make brw_vs_outputs_written static.
[mesa.git] / src / mesa / drivers / dri / i965 / brw_oa.py
1 # Copyright (c) 2015-2017 Intel Corporation
2 #
3 # Permission is hereby granted, free of charge, to any person obtaining a
4 # copy of this software and associated documentation files (the "Software"),
5 # to deal in the Software without restriction, including without limitation
6 # the rights to use, copy, modify, merge, publish, distribute, sublicense,
7 # and/or sell copies of the Software, and to permit persons to whom the
8 # Software is furnished to do so, subject to the following conditions:
9 #
10 # The above copyright notice and this permission notice (including the next
11 # paragraph) shall be included in all copies or substantial portions of the
12 # Software.
13 #
14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20 # IN THE SOFTWARE.
21
22 import argparse
23 import os
24 import sys
25 import textwrap
26
27 import xml.etree.cElementTree as et
28
29 hashed_funcs = {}
30
31 c_file = None
32 _c_indent = 0
33
34 def c(*args):
35 code = ' '.join(map(str,args))
36 for line in code.splitlines():
37 text = ''.rjust(_c_indent) + line
38 c_file.write(text.rstrip() + "\n")
39
40 # indented, but no trailing newline...
41 def c_line_start(code):
42 c_file.write(''.rjust(_c_indent) + code)
43 def c_raw(code):
44 c_file.write(code)
45
46 def c_indent(n):
47 global _c_indent
48 _c_indent = _c_indent + n
49 def c_outdent(n):
50 global _c_indent
51 _c_indent = _c_indent - n
52
53 header_file = None
54 _h_indent = 0
55
56 def h(*args):
57 code = ' '.join(map(str,args))
58 for line in code.splitlines():
59 text = ''.rjust(_h_indent) + line
60 header_file.write(text.rstrip() + "\n")
61
62 def h_indent(n):
63 global _c_indent
64 _h_indent = _h_indent + n
65 def h_outdent(n):
66 global _c_indent
67 _h_indent = _h_indent - n
68
69
70 def emit_fadd(tmp_id, args):
71 c("double tmp{0} = {1} + {2};".format(tmp_id, args[1], args[0]))
72 return tmp_id + 1
73
74 # Be careful to check for divide by zero...
75 def emit_fdiv(tmp_id, args):
76 c("double tmp{0} = {1};".format(tmp_id, args[1]))
77 c("double tmp{0} = {1};".format(tmp_id + 1, args[0]))
78 c("double tmp{0} = tmp{1} ? tmp{2} / tmp{1} : 0;".format(tmp_id + 2, tmp_id + 1, tmp_id))
79 return tmp_id + 3
80
81 def emit_fmax(tmp_id, args):
82 c("double tmp{0} = {1};".format(tmp_id, args[1]))
83 c("double tmp{0} = {1};".format(tmp_id + 1, args[0]))
84 c("double tmp{0} = MAX(tmp{1}, tmp{2});".format(tmp_id + 2, tmp_id, tmp_id + 1))
85 return tmp_id + 3
86
87 def emit_fmul(tmp_id, args):
88 c("double tmp{0} = {1} * {2};".format(tmp_id, args[1], args[0]))
89 return tmp_id + 1
90
91 def emit_fsub(tmp_id, args):
92 c("double tmp{0} = {1} - {2};".format(tmp_id, args[1], args[0]))
93 return tmp_id + 1
94
95 def emit_read(tmp_id, args):
96 type = args[1].lower()
97 c("uint64_t tmp{0} = accumulator[query->{1}_offset + {2}];".format(tmp_id, type, args[0]))
98 return tmp_id + 1
99
100 def emit_uadd(tmp_id, args):
101 c("uint64_t tmp{0} = {1} + {2};".format(tmp_id, args[1], args[0]))
102 return tmp_id + 1
103
104 # Be careful to check for divide by zero...
105 def emit_udiv(tmp_id, args):
106 c("uint64_t tmp{0} = {1};".format(tmp_id, args[1]))
107 c("uint64_t tmp{0} = {1};".format(tmp_id + 1, args[0]))
108 c("uint64_t tmp{0} = tmp{1} ? tmp{2} / tmp{1} : 0;".format(tmp_id + 2, tmp_id + 1, tmp_id))
109 return tmp_id + 3
110
111 def emit_umul(tmp_id, args):
112 c("uint64_t tmp{0} = {1} * {2};".format(tmp_id, args[1], args[0]))
113 return tmp_id + 1
114
115 def emit_usub(tmp_id, args):
116 c("uint64_t tmp{0} = {1} - {2};".format(tmp_id, args[1], args[0]))
117 return tmp_id + 1
118
119 def emit_umin(tmp_id, args):
120 c("uint64_t tmp{0} = MIN({1}, {2});".format(tmp_id, args[1], args[0]))
121 return tmp_id + 1
122
123 def emit_lshft(tmp_id, args):
124 c("uint64_t tmp{0} = {1} << {2};".format(tmp_id, args[1], args[0]))
125 return tmp_id + 1
126
127 def emit_rshft(tmp_id, args):
128 c("uint64_t tmp{0} = {1} >> {2};".format(tmp_id, args[1], args[0]))
129 return tmp_id + 1
130
131 def emit_and(tmp_id, args):
132 c("uint64_t tmp{0} = {1} & {2};".format(tmp_id, args[1], args[0]))
133 return tmp_id + 1
134
135 ops = {}
136 # (n operands, emitter)
137 ops["FADD"] = (2, emit_fadd)
138 ops["FDIV"] = (2, emit_fdiv)
139 ops["FMAX"] = (2, emit_fmax)
140 ops["FMUL"] = (2, emit_fmul)
141 ops["FSUB"] = (2, emit_fsub)
142 ops["READ"] = (2, emit_read)
143 ops["UADD"] = (2, emit_uadd)
144 ops["UDIV"] = (2, emit_udiv)
145 ops["UMUL"] = (2, emit_umul)
146 ops["USUB"] = (2, emit_usub)
147 ops["UMIN"] = (2, emit_umin)
148 ops["<<"] = (2, emit_lshft)
149 ops[">>"] = (2, emit_rshft)
150 ops["AND"] = (2, emit_and)
151
152 def brkt(subexp):
153 if " " in subexp:
154 return "(" + subexp + ")"
155 else:
156 return subexp
157
158 def splice_bitwise_and(args):
159 return brkt(args[1]) + " & " + brkt(args[0])
160
161 def splice_logical_and(args):
162 return brkt(args[1]) + " && " + brkt(args[0])
163
164 def splice_ult(args):
165 return brkt(args[1]) + " < " + brkt(args[0])
166
167 def splice_ugte(args):
168 return brkt(args[1]) + " >= " + brkt(args[0])
169
170 exp_ops = {}
171 # (n operands, splicer)
172 exp_ops["AND"] = (2, splice_bitwise_and)
173 exp_ops["UGTE"] = (2, splice_ugte)
174 exp_ops["ULT"] = (2, splice_ult)
175 exp_ops["&&"] = (2, splice_logical_and)
176
177
178 hw_vars = {}
179 hw_vars["$EuCoresTotalCount"] = "brw->perfquery.sys_vars.n_eus"
180 hw_vars["$EuSlicesTotalCount"] = "brw->perfquery.sys_vars.n_eu_slices"
181 hw_vars["$EuSubslicesTotalCount"] = "brw->perfquery.sys_vars.n_eu_sub_slices"
182 hw_vars["$EuThreadsCount"] = "brw->perfquery.sys_vars.eu_threads_count"
183 hw_vars["$SliceMask"] = "brw->perfquery.sys_vars.slice_mask"
184 hw_vars["$SubsliceMask"] = "brw->perfquery.sys_vars.subslice_mask"
185 hw_vars["$GpuTimestampFrequency"] = "brw->perfquery.sys_vars.timestamp_frequency"
186 hw_vars["$GpuMinFrequency"] = "brw->perfquery.sys_vars.gt_min_freq"
187 hw_vars["$GpuMaxFrequency"] = "brw->perfquery.sys_vars.gt_max_freq"
188 hw_vars["$SkuRevisionId"] = "brw->perfquery.sys_vars.revision"
189
190 def output_rpn_equation_code(set, counter, equation):
191 c("/* RPN equation: " + equation + " */")
192 tokens = equation.split()
193 stack = []
194 tmp_id = 0
195 tmp = None
196
197 for token in tokens:
198 stack.append(token)
199 while stack and stack[-1] in ops:
200 op = stack.pop()
201 argc, callback = ops[op]
202 args = []
203 for i in range(0, argc):
204 operand = stack.pop()
205 if operand[0] == "$":
206 if operand in hw_vars:
207 operand = hw_vars[operand]
208 elif operand in set.counter_vars:
209 reference = set.counter_vars[operand]
210 operand = set.read_funcs[operand[1:]] + "(brw, query, accumulator)"
211 else:
212 raise Exception("Failed to resolve variable " + operand + " in equation " + equation + " for " + set.name + " :: " + counter.get('name'));
213 args.append(operand)
214
215 tmp_id = callback(tmp_id, args)
216
217 tmp = "tmp{0}".format(tmp_id - 1)
218 stack.append(tmp)
219
220 if len(stack) != 1:
221 raise Exception("Spurious empty rpn code for " + set.name + " :: " +
222 counter.get('name') + ".\nThis is probably due to some unhandled RPN function, in the equation \"" +
223 equation + "\"")
224
225 value = stack[-1]
226
227 if value in hw_vars:
228 value = hw_vars[value]
229 if value in set.counter_vars:
230 value = set.read_funcs[value[1:]] + "(brw, query, accumulator)"
231
232 c("\nreturn " + value + ";")
233
234 def splice_rpn_expression(set, counter, expression):
235 tokens = expression.split()
236 stack = []
237
238 for token in tokens:
239 stack.append(token)
240 while stack and stack[-1] in exp_ops:
241 op = stack.pop()
242 argc, callback = exp_ops[op]
243 args = []
244 for i in range(0, argc):
245 operand = stack.pop()
246 if operand[0] == "$":
247 if operand in hw_vars:
248 operand = hw_vars[operand]
249 else:
250 raise Exception("Failed to resolve variable " + operand + " in expression " + expression + " for " + set.name + " :: " + counter.get('name'));
251 args.append(operand)
252
253 subexp = callback(args)
254
255 stack.append(subexp)
256
257 if len(stack) != 1:
258 raise Exception("Spurious empty rpn expression for " + set.name + " :: " +
259 counter.get('name') + ".\nThis is probably due to some unhandled RPN operation, in the expression \"" +
260 expression + "\"")
261
262 return stack[-1]
263
264 def output_counter_read(gen, set, counter):
265 c("\n")
266 c("/* {0} :: {1} */".format(set.name, counter.get('name')))
267
268 if counter.read_hash in hashed_funcs:
269 c("#define %s \\" % counter.read_sym)
270 c_indent(3)
271 c("%s" % hashed_funcs[counter.read_hash])
272 c_outdent(3)
273 else:
274 ret_type = counter.get('data_type')
275 if ret_type == "uint64":
276 ret_type = "uint64_t"
277
278 read_eq = counter.get('equation')
279
280 c("static " + ret_type)
281 c(counter.read_sym + "(MAYBE_UNUSED struct brw_context *brw,\n")
282 c_indent(len(counter.read_sym) + 1)
283 c("const struct brw_perf_query_info *query,\n")
284 c("uint64_t *accumulator)\n")
285 c_outdent(len(counter.read_sym) + 1)
286
287 c("{")
288 c_indent(3)
289 output_rpn_equation_code(set, counter, read_eq)
290 c_outdent(3)
291 c("}")
292
293 hashed_funcs[counter.read_hash] = counter.read_sym
294
295
296 def output_counter_max(gen, set, counter):
297 max_eq = counter.get('max_equation')
298
299 if not counter.has_max_func():
300 return
301
302 c("\n")
303 c("/* {0} :: {1} */".format(set.name, counter.get('name')))
304
305 if counter.max_hash in hashed_funcs:
306 c("#define %s \\" % counter.max_sym())
307 c_indent(3)
308 c("%s" % hashed_funcs[counter.max_hash])
309 c_outdent(3)
310 else:
311 ret_type = counter.get('data_type')
312 if ret_type == "uint64":
313 ret_type = "uint64_t"
314
315 c("static " + ret_type)
316 c(counter.max_sym() + "(struct brw_context *brw)\n")
317 c("{")
318 c_indent(3)
319 output_rpn_equation_code(set, counter, max_eq)
320 c_outdent(3)
321 c("}")
322
323 hashed_funcs[counter.max_hash] = counter.max_sym()
324
325
326 c_type_sizes = { "uint32_t": 4, "uint64_t": 8, "float": 4, "double": 8, "bool": 4 }
327 def sizeof(c_type):
328 return c_type_sizes[c_type]
329
330 def pot_align(base, pot_alignment):
331 return (base + pot_alignment - 1) & ~(pot_alignment - 1);
332
333 semantic_type_map = {
334 "duration": "raw",
335 "ratio": "event"
336 }
337
338 def output_availability(set, availability, counter_name):
339 expression = splice_rpn_expression(set, counter_name, availability)
340 lines = expression.split(' && ')
341 n_lines = len(lines)
342 if n_lines == 1:
343 c("if (" + lines[0] + ") {")
344 else:
345 c("if (" + lines[0] + " &&")
346 c_indent(4)
347 for i in range(1, (n_lines - 1)):
348 c(lines[i] + " &&")
349 c(lines[(n_lines - 1)] + ") {")
350 c_outdent(4)
351
352
353 def output_counter_report(set, counter, current_offset):
354 data_type = counter.get('data_type')
355 data_type_uc = data_type.upper()
356 c_type = data_type
357
358 if "uint" in c_type:
359 c_type = c_type + "_t"
360
361 semantic_type = counter.get('semantic_type')
362 if semantic_type in semantic_type_map:
363 semantic_type = semantic_type_map[semantic_type]
364
365 semantic_type_uc = semantic_type.upper()
366
367 c("\n")
368
369 availability = counter.get('availability')
370 if availability:
371 output_availability(set, availability, counter.get('name'))
372 c_indent(3)
373
374 c("counter = &query->counters[query->n_counters++];\n")
375 c("counter->oa_counter_read_" + data_type + " = " + set.read_funcs[counter.get('symbol_name')] + ";\n")
376 c("counter->name = \"" + counter.get('name') + "\";\n")
377 c("counter->desc = \"" + counter.get('description') + "\";\n")
378 c("counter->type = GL_PERFQUERY_COUNTER_" + semantic_type_uc + "_INTEL;\n")
379 c("counter->data_type = GL_PERFQUERY_COUNTER_DATA_" + data_type_uc + "_INTEL;\n")
380 c("counter->raw_max = " + set.max_values[counter.get('symbol_name')] + ";\n")
381
382 current_offset = pot_align(current_offset, sizeof(c_type))
383 c("counter->offset = " + str(current_offset) + ";\n")
384 c("counter->size = sizeof(" + c_type + ");\n")
385
386 if availability:
387 c_outdent(3);
388 c("}")
389
390 return current_offset + sizeof(c_type)
391
392
393 register_types = {
394 'FLEX': 'flex_regs',
395 'NOA': 'mux_regs',
396 'OA': 'b_counter_regs',
397 }
398
399 def compute_register_lengths(set):
400 register_lengths = {}
401 register_configs = set.findall('register_config')
402 for register_config in register_configs:
403 t = register_types[register_config.get('type')]
404 if t not in register_lengths:
405 register_lengths[t] = len(register_config.findall('register'))
406 else:
407 register_lengths[t] += len(register_config.findall('register'))
408
409 return register_lengths
410
411
412 def generate_register_configs(set):
413 register_configs = set.findall('register_config')
414 for register_config in register_configs:
415 t = register_types[register_config.get('type')]
416
417 availability = register_config.get('availability')
418 if availability:
419 output_availability(set, availability, register_config.get('type') + ' register config')
420 c_indent(3)
421
422 for register in register_config.findall('register'):
423 c("query->%s[query->n_%s++] = (struct brw_perf_query_register_prog) { .reg = %s, .val = %s };" %
424 (t, t, register.get('address'), register.get('value')))
425
426 if availability:
427 c_outdent(3)
428 c("}")
429 c("\n")
430
431
432 # Wraps a <counter> element from the brw_oa_*.xml files.
433 class Counter:
434 def __init__(self, set, xml):
435 self.xml = xml
436 self.set = set
437 self.read_hash = None
438 self.max_hash = None
439
440 self.read_sym = "{0}__{1}__{2}__read".format(self.set.gen.chipset,
441 self.set.underscore_name,
442 self.xml.get('underscore_name'))
443
444 def get(self, prop):
445 return self.xml.get(prop)
446
447 # Compute the hash of a counter's equation by expanding (including all the
448 # sub-equations it depends on)
449 def compute_hashes(self):
450 if self.read_hash is not None:
451 return
452
453 def replace_token(token):
454 if token[0] != "$":
455 return token
456 if token not in self.set.counter_vars:
457 return token
458 self.set.counter_vars[token].compute_hashes()
459 return self.set.counter_vars[token].read_hash
460
461 read_eq = self.xml.get('equation')
462 self.read_hash = ' '.join(map(replace_token, read_eq.split()))
463
464 max_eq = self.xml.get('max_equation')
465 if max_eq:
466 self.max_hash = ' '.join(map(replace_token, max_eq.split()))
467
468 def has_max_func(self):
469 max_eq = self.xml.get('max_equation')
470 if not max_eq:
471 return False
472
473 try:
474 val = float(max_eq)
475 return False
476 except ValueError:
477 pass
478
479 for token in max_eq.split():
480 if token[0] == '$' and token not in hw_vars:
481 return False
482 return True
483
484 def max_sym(self):
485 assert self.has_max_func()
486 return "{0}__{1}__{2}__max".format(self.set.gen.chipset,
487 self.set.underscore_name,
488 self.xml.get('underscore_name'))
489
490 def max_value(self):
491 max_eq = self.xml.get('max_equation')
492 if not max_eq:
493 return "0 /* undefined */"
494
495 try:
496 return "{0}".format(float(max_eq))
497 except ValueError:
498 pass
499
500 for token in max_eq.split():
501 if token[0] == '$' and token not in hw_vars:
502 return "0 /* unsupported (varies over time) */"
503
504 return "{0}__{1}__{2}__max(brw)".format(self.set.gen.chipset,
505 self.set.underscore_name,
506 self.xml.get('underscore_name'))
507
508 # Wraps a <set> element from the brw_oa_*.xml files.
509 class Set:
510 def __init__(self, gen, xml):
511 self.gen = gen
512 self.xml = xml
513
514 self.counter_vars = {}
515 self.max_values = {}
516 self.read_funcs = {}
517
518 xml_counters = self.xml.findall("counter")
519 self.counters = []
520 for xml_counter in xml_counters:
521 counter = Counter(self, xml_counter)
522 self.counters.append(counter)
523 self.counter_vars["$" + counter.get('symbol_name')] = counter
524 self.read_funcs[counter.get('symbol_name')] = counter.read_sym
525 self.max_values[counter.get('symbol_name')] = counter.max_value()
526
527 for counter in self.counters:
528 counter.compute_hashes()
529
530 @property
531 def hw_config_guid(self):
532 return self.xml.get('hw_config_guid')
533
534 @property
535 def name(self):
536 return self.xml.get('name')
537
538 @property
539 def symbol_name(self):
540 return self.xml.get('symbol_name')
541
542 @property
543 def underscore_name(self):
544 return self.xml.get('underscore_name')
545
546 def findall(self, path):
547 return self.xml.findall(path)
548
549 def find(self, path):
550 return self.xml.find(path)
551
552
553 # Wraps an entire brw_oa_*.xml file.
554 class Gen:
555 def __init__(self, filename):
556 self.filename = filename
557 self.xml = et.parse(self.filename)
558 self.chipset = self.xml.find('.//set').get('chipset').lower()
559 self.sets = []
560
561 for xml_set in self.xml.findall(".//set"):
562 self.sets.append(Set(self, xml_set))
563
564
565 def main():
566 global c_file
567 global header_file
568
569 parser = argparse.ArgumentParser()
570 parser.add_argument("--header", help="Header file to write", required=True)
571 parser.add_argument("--code", help="C file to write", required=True)
572 parser.add_argument("xml_files", nargs='+', help="List of xml metrics files to process")
573
574 args = parser.parse_args()
575
576 header_file = open(args.header, 'w')
577 c_file = open(args.code, 'w')
578
579 gens = []
580 for xml_file in args.xml_files:
581 gens.append(Gen(xml_file))
582
583
584 copyright = textwrap.dedent("""\
585 /* Autogenerated file, DO NOT EDIT manually! generated by {}
586 *
587 * Copyright (c) 2015 Intel Corporation
588 *
589 * Permission is hereby granted, free of charge, to any person obtaining a
590 * copy of this software and associated documentation files (the "Software"),
591 * to deal in the Software without restriction, including without limitation
592 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
593 * and/or sell copies of the Software, and to permit persons to whom the
594 * Software is furnished to do so, subject to the following conditions:
595 *
596 * The above copyright notice and this permission notice (including the next
597 * paragraph) shall be included in all copies or substantial portions of the
598 * Software.
599 *
600 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
601 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
602 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
603 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
604 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
605 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
606 * DEALINGS IN THE SOFTWARE.
607 */
608
609 """).format(os.path.basename(__file__))
610
611 h(copyright)
612 h(textwrap.dedent("""\
613 #pragma once
614
615 struct brw_context;
616
617 """))
618
619 c(copyright)
620 c(textwrap.dedent("""\
621 #include <stdint.h>
622 #include <stdbool.h>
623
624 #include "util/hash_table.h"
625
626 """))
627
628 c("#include \"" + os.path.basename(args.header) + "\"")
629
630 c(textwrap.dedent("""\
631 #include "brw_context.h"
632 #include "brw_performance_query_metrics.h"
633
634
635 #define MIN(a, b) ((a < b) ? (a) : (b))
636 #define MAX(a, b) ((a > b) ? (a) : (b))
637
638
639 """))
640
641 # Print out all equation functions.
642 for gen in gens:
643 for set in gen.sets:
644 for counter in set.counters:
645 output_counter_read(gen, set, counter)
646 output_counter_max(gen, set, counter)
647
648 # Print out all metric sets registration functions for each set in each
649 # generation.
650 for gen in gens:
651 for set in gen.sets:
652 counters = set.counters
653
654 c("\n")
655 register_lengths = compute_register_lengths(set);
656 for reg_type, reg_length in register_lengths.iteritems():
657 c("static struct brw_perf_query_register_prog {0}_{1}_{2}[{3}];".format(gen.chipset,
658 set.underscore_name,
659 reg_type, reg_length))
660
661 c("\nstatic struct brw_perf_query_counter {0}_{1}_query_counters[{2}];\n".format(gen.chipset, set.underscore_name, len(counters)))
662 c("static struct brw_perf_query_info " + gen.chipset + "_" + set.underscore_name + "_query = {\n")
663 c_indent(3)
664
665 c(".kind = OA_COUNTERS,\n")
666 c(".name = \"" + set.name + "\",\n")
667 c(".guid = \"" + set.hw_config_guid + "\",\n")
668
669 c(".counters = {0}_{1}_query_counters,".format(gen.chipset, set.underscore_name))
670 c(".n_counters = 0,")
671 c(".oa_metrics_set_id = 0, /* determined at runtime, via sysfs */")
672
673 if gen.chipset == "hsw":
674 c(textwrap.dedent("""\
675 .oa_format = I915_OA_FORMAT_A45_B8_C8,
676
677 /* Accumulation buffer offsets... */
678 .gpu_time_offset = 0,
679 .a_offset = 1,
680 .b_offset = 46,
681 .c_offset = 54,
682 """))
683 else:
684 c(textwrap.dedent("""\
685 .oa_format = I915_OA_FORMAT_A32u40_A4u32_B8_C8,
686
687 /* Accumulation buffer offsets... */
688 .gpu_time_offset = 0,
689 .gpu_clock_offset = 1,
690 .a_offset = 2,
691 .b_offset = 38,
692 .c_offset = 46,
693 """))
694
695 for reg_type, reg_length in register_lengths.iteritems():
696 c(".{0} = {1}_{2}_{3},".format(reg_type, gen.chipset, set.underscore_name, reg_type))
697 c(".n_{0} = 0, /* Determined at runtime */".format(reg_type))
698
699 c_outdent(3)
700 c("};\n")
701
702 c("\nstatic void\n")
703 c("{0}_register_{1}_counter_query(struct brw_context *brw)\n".format(gen.chipset, set.underscore_name))
704 c("{\n")
705 c_indent(3)
706
707 c("static struct brw_perf_query_info *query = &" + gen.chipset + "_" + set.underscore_name + "_query;\n")
708 c("struct brw_perf_query_counter *counter;\n")
709
710 c("\n")
711 c("/* Note: we're assuming there can't be any variation in the definition ")
712 c(" * of a query between contexts so it's ok to describe a query within a ")
713 c(" * global variable which only needs to be initialized once... */")
714 c("\nif (!query->data_size) {")
715 c_indent(3)
716
717 generate_register_configs(set)
718
719 offset = 0
720 for counter in counters:
721 offset = output_counter_report(set, counter, offset)
722
723
724 c("\nquery->data_size = counter->offset + counter->size;\n")
725
726 c_outdent(3)
727 c("}");
728
729 c("\n_mesa_hash_table_insert(brw->perfquery.oa_metrics_table, query->guid, query);")
730
731 c_outdent(3)
732 c("}\n")
733
734 h("void brw_oa_register_queries_" + gen.chipset + "(struct brw_context *brw);\n")
735
736 c("\nvoid")
737 c("brw_oa_register_queries_" + gen.chipset + "(struct brw_context *brw)")
738 c("{")
739 c_indent(3)
740
741 for set in gen.sets:
742 c("{0}_register_{1}_counter_query(brw);".format(gen.chipset, set.underscore_name))
743
744 c_outdent(3)
745 c("}")
746
747
748 if __name__ == '__main__':
749 main()