From ec2d20a70d018736c6ef7cb5bbbe48d82e8c6b4c Mon Sep 17 00:00:00 2001 From: Caio Oliveira Date: Wed, 15 Jan 2025 21:45:32 -0800 Subject: [PATCH] intel/tools: Add helpers for decoder_init/disasm Isolate the BRW/ELK differences in a single place. The way is done now, we are not reusing the isa_info between calls. For the tools here this is probably fine, if its someday this gets in the way, we can add an opaque pointer to store the right data. This intentionally is not used in Iris, since there the driver need more detailed view into BRW/ELK and we don't want to create an all encompassing abstraction for that. Reviewed-by: Daniel Stone Reviewed-by: Lionel Landwerlin Acked-by: Kenneth Graunke Part-of: --- src/intel/tools/aubinator.c | 16 ++------ src/intel/tools/aubinator_error_decode.c | 22 ++--------- src/intel/tools/aubinator_viewer.cpp | 23 ++--------- src/intel/tools/intel_hang_replay.c | 22 ++--------- src/intel/tools/intel_hang_viewer.cpp | 25 ++---------- src/intel/tools/intel_tools.c | 49 ++++++++++++++++++++++++ src/intel/tools/intel_tools.h | 33 ++++++++++++++++ src/intel/tools/meson.build | 46 +++++++++++++++------- 8 files changed, 134 insertions(+), 102 deletions(-) create mode 100644 src/intel/tools/intel_tools.c create mode 100644 src/intel/tools/intel_tools.h diff --git a/src/intel/tools/aubinator.c b/src/intel/tools/aubinator.c index 4db72559895..b7eb7193509 100644 --- a/src/intel/tools/aubinator.c +++ b/src/intel/tools/aubinator.c @@ -38,8 +38,7 @@ #include #include -#include "intel/compiler/brw_isa_info.h" -#include "intel/compiler/elk/elk_isa_info.h" +#include "intel_tools.h" #include "util/macros.h" #include "aub_read.h" @@ -61,8 +60,6 @@ static enum { COLOR_AUTO, COLOR_ALWAYS, COLOR_NEVER } option_color; uint16_t pci_id = 0; char *input_file = NULL, *xml_path = NULL; struct intel_device_info devinfo; -struct brw_isa_info brw; -struct elk_isa_info elk; struct intel_batch_decode_ctx batch_ctx; struct aub_mem mem; @@ -99,15 +96,8 @@ aubinator_init(void *user_data, int aub_pci_id, const char *app_name) batch_flags |= INTEL_BATCH_DECODE_OFFSETS; batch_flags |= INTEL_BATCH_DECODE_FLOATS; - if (devinfo.ver >= 9) { - brw_init_isa_info(&brw, &devinfo); - intel_batch_decode_ctx_init_brw(&batch_ctx, &brw, &devinfo, outfile, - batch_flags, xml_path, NULL, NULL, NULL); - } else { - elk_init_isa_info(&elk, &devinfo); - intel_batch_decode_ctx_init_elk(&batch_ctx, &elk, &devinfo, outfile, - batch_flags, xml_path, NULL, NULL, NULL); - } + intel_decoder_init(&batch_ctx, &devinfo, outfile, + batch_flags, xml_path, NULL, NULL, NULL); /* Check for valid spec instance, if wrong xml_path is passed then spec * instance is not initialized properly diff --git a/src/intel/tools/aubinator_error_decode.c b/src/intel/tools/aubinator_error_decode.c index 5f932c6a656..b7702ca4731 100644 --- a/src/intel/tools/aubinator_error_decode.c +++ b/src/intel/tools/aubinator_error_decode.c @@ -41,12 +41,11 @@ #include "aubinator_error_decode_lib.h" #include "aubinator_error_decode_xe.h" #include "common/intel_debug_identifier.h" -#include "compiler/brw_compiler.h" -#include "compiler/elk/elk_compiler.h" #include "decoder/intel_decoder.h" #include "dev/intel_debug.h" #include "error_decode_lib.h" #include "util/macros.h" +#include "intel_tools.h" #define MIN(a, b) ((a) < (b) ? (a) : (b)) @@ -379,8 +378,6 @@ read_i915_data_file(FILE *file, enum intel_batch_decode_flags batch_flags) bool ring_wraps = false; char *ring_name = NULL; struct intel_device_info devinfo; - struct brw_isa_info brw; - struct elk_isa_info elk; uint64_t acthd = 0; while (getline(&line, &line_size, file) > 0) { @@ -473,11 +470,6 @@ read_i915_data_file(FILE *file, enum intel_batch_decode_flags batch_flags) printf("Detected GEN%i chipset\n", devinfo.ver); - if (devinfo.ver >= 9) - brw_init_isa_info(&brw, &devinfo); - else - elk_init_isa_info(&elk, &devinfo); - if (xml_path == NULL) spec = intel_spec_load(&devinfo); else @@ -669,15 +661,9 @@ read_i915_data_file(FILE *file, enum intel_batch_decode_flags batch_flags) } struct intel_batch_decode_ctx batch_ctx; - if (devinfo.ver >= 9) { - intel_batch_decode_ctx_init_brw(&batch_ctx, &brw, &devinfo, stdout, - batch_flags, xml_path, get_intel_batch_bo, - NULL, NULL); - } else { - intel_batch_decode_ctx_init_elk(&batch_ctx, &elk, &devinfo, stdout, - batch_flags, xml_path, get_intel_batch_bo, - NULL, NULL); - } + intel_decoder_init(&batch_ctx, &devinfo, stdout, + batch_flags, xml_path, get_intel_batch_bo, + NULL, NULL); batch_ctx.acthd = acthd; if (option_dump_kernels) diff --git a/src/intel/tools/aubinator_viewer.cpp b/src/intel/tools/aubinator_viewer.cpp index 0df122cdb5a..140c36d152b 100644 --- a/src/intel/tools/aubinator_viewer.cpp +++ b/src/intel/tools/aubinator_viewer.cpp @@ -39,10 +39,7 @@ #include "aub_read.h" #include "aub_mem.h" -#include "compiler/brw_disasm.h" -#include "compiler/brw_isa_info.h" -#include "compiler/elk/elk_disasm.h" -#include "compiler/elk/elk_isa_info.h" +#include "intel_tools.h" #define xtzalloc(name) ((decltype(&name)) calloc(1, sizeof(name))) #define xtalloc(name) ((decltype(&name)) malloc(sizeof(name))) @@ -65,8 +62,6 @@ struct aub_file { /* Device state */ struct intel_device_info devinfo; - struct brw_isa_info brw; - struct elk_isa_info elk; struct intel_spec *spec; }; @@ -134,10 +129,6 @@ handle_info(void *user_data, int pci_id, const char *app_name) fprintf(stderr, "can't find device information: pci_id=0x%x\n", file->pci_id); exit(EXIT_FAILURE); } - if (file->devinfo.ver >= 9) - brw_init_isa_info(&file->brw, &file->devinfo); - else - elk_init_isa_info(&file->elk, &file->devinfo); file->spec = intel_spec_load(&file->devinfo); } @@ -401,15 +392,9 @@ new_shader_window(struct aub_mem *mem, uint64_t address, const char *desc) if (shader_bo.map) { FILE *f = open_memstream(&window->shader, &window->shader_size); if (f) { - if (context.file->devinfo.ver >= 9) { - brw_disassemble_with_errors(&context.file->brw, - (const uint8_t *) shader_bo.map + - (address - shader_bo.addr), 0, f); - } else { - elk_disassemble_with_errors(&context.file->elk, - (const uint8_t *) shader_bo.map + - (address - shader_bo.addr), 0, f); - } + intel_disassemble(&context.file->devinfo, + (const uint8_t *) shader_bo.map + + (address - shader_bo.addr), 0, f); fclose(f); } } diff --git a/src/intel/tools/intel_hang_replay.c b/src/intel/tools/intel_hang_replay.c index a763b2c1f4d..c7bee2861af 100644 --- a/src/intel/tools/intel_hang_replay.c +++ b/src/intel/tools/intel_hang_replay.c @@ -45,10 +45,6 @@ #include "common/intel_gem.h" #include "common/i915/intel_gem.h" #include "common/intel_hang_dump.h" -#include "compiler/elk/elk_disasm.h" -#include "compiler/elk/elk_isa_info.h" -#include "compiler/brw_disasm.h" -#include "compiler/brw_isa_info.h" #include "dev/intel_device_info.h" #include "drm-uapi/i915_drm.h" @@ -56,6 +52,8 @@ #include "util/u_dynarray.h" #include "util/u_math.h" +#include "intel_tools.h" + static uint32_t gem_create(int drm_fd, uint64_t size) { @@ -517,20 +515,8 @@ main(int argc, char *argv[]) found = true; fprintf(stderr, "shader at 0x%016"PRIx64" file_offset=0%016"PRIx64" addr_offset=%016"PRIx64":\n", *addr, (bo->file_offset - aligned_offset), (*addr - bo->offset)); - if (devinfo.ver >= 9) { - struct brw_isa_info _isa, *isa = &_isa; - brw_init_isa_info(isa, &devinfo); - brw_disassemble_with_errors(isa, - map + (bo->file_offset - aligned_offset) + (*addr - bo->offset), - 0, stderr); - } else { - struct elk_isa_info _isa, *isa = &_isa; - elk_init_isa_info(isa, &devinfo); - elk_disassemble_with_errors(isa, - map + (bo->file_offset - aligned_offset) + (*addr - bo->offset), - 0, stderr); - } - + intel_disassemble(&devinfo, map + (bo->file_offset - aligned_offset) + (*addr - bo->offset), + 0, stderr); munmap(map, remaining_length); } diff --git a/src/intel/tools/intel_hang_viewer.cpp b/src/intel/tools/intel_hang_viewer.cpp index 51624a1703a..8759b79ede0 100644 --- a/src/intel/tools/intel_hang_viewer.cpp +++ b/src/intel/tools/intel_hang_viewer.cpp @@ -43,10 +43,7 @@ #include "common/intel_hang_dump.h" -#include "compiler/brw_disasm.h" -#include "compiler/brw_isa_info.h" -#include "compiler/elk/elk_disasm.h" -#include "compiler/elk/elk_isa_info.h" +#include "intel_tools.h" /* Data */ @@ -128,9 +125,6 @@ static struct Context { struct intel_device_info devinfo; struct intel_spec *spec = NULL; - struct brw_isa_info brw; - struct elk_isa_info elk; - /* Result of parsing the hang file */ std::vector bos; std::vector maps; @@ -228,15 +222,9 @@ public: size_t shader_txt_size = 0; FILE *f = open_memstream(&shader_txt, &shader_txt_size); if (f) { - if (context.devinfo.ver >= 9) { - brw_disassemble_with_errors(&context.brw, - (const uint8_t *) bo->map + - (address - bo->offset), 0, f); - } else { - elk_disassemble_with_errors(&context.elk, - (const uint8_t *) bo->map + - (address - bo->offset), 0, f); - } + intel_disassemble(&context.devinfo, + (const uint8_t *) bo->map + + (address - bo->offset), 0, f); fclose(f); } @@ -780,11 +768,6 @@ main(int argc, char *argv[]) intel_device_name_to_pci_device_id(platform), &context.devinfo); - if (context.devinfo.ver >= 9) { - brw_init_isa_info(&context.brw, &context.devinfo); - } else { - elk_init_isa_info(&context.elk, &context.devinfo); - } context.spec = intel_spec_load(&context.devinfo); parse_hang_file(filename); diff --git a/src/intel/tools/intel_tools.c b/src/intel/tools/intel_tools.c new file mode 100644 index 00000000000..c263170c8c4 --- /dev/null +++ b/src/intel/tools/intel_tools.c @@ -0,0 +1,49 @@ +/* + * Copyright © 2025 Intel Corporation + * SPDX-License-Identifier: MIT + */ + +#include "intel_tools.h" + +#include "compiler/brw_disasm.h" +#include "compiler/brw_isa_info.h" +#include "compiler/elk/elk_disasm.h" +#include "compiler/elk/elk_isa_info.h" +#include "dev/intel_device_info.h" + +void +intel_disassemble(const struct intel_device_info *devinfo, + const void *assembly, int start, FILE *out) +{ + if (devinfo->ver >= 9) { + struct brw_isa_info isa; + brw_init_isa_info(&isa, devinfo); + brw_disassemble_with_errors(&isa, assembly, start, out); + } else { + struct elk_isa_info isa; + elk_init_isa_info(&isa, devinfo); + elk_disassemble_with_errors(&isa, assembly, start, out); + } +} + +void +intel_decoder_init(struct intel_batch_decode_ctx *ctx, + const struct intel_device_info *devinfo, + FILE *fp, enum intel_batch_decode_flags flags, + const char *xml_path, + struct intel_batch_decode_bo (*get_bo)(void *, bool, uint64_t), + unsigned (*get_state_size)(void *, uint64_t, uint64_t), + void *user_data) +{ + if (devinfo->ver >= 9) { + struct brw_isa_info isa; + brw_init_isa_info(&isa, devinfo); + intel_batch_decode_ctx_init_brw(ctx, &isa, devinfo, fp, + flags, xml_path, get_bo, get_state_size, user_data); + } else { + struct elk_isa_info isa; + elk_init_isa_info(&isa, devinfo); + intel_batch_decode_ctx_init_elk(ctx, &isa, devinfo, fp, + flags, xml_path, get_bo, get_state_size, user_data); + } +} diff --git a/src/intel/tools/intel_tools.h b/src/intel/tools/intel_tools.h new file mode 100644 index 00000000000..3d33160ab44 --- /dev/null +++ b/src/intel/tools/intel_tools.h @@ -0,0 +1,33 @@ +/* + * Copyright © 2025 Intel Corporation + * SPDX-License-Identifier: MIT + */ + +#pragma once + +#include + +#include "intel/decoder/intel_decoder.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct intel_device_info; + +/* Helpers to abstract some BRW/ELK differences. */ + +void intel_disassemble(const struct intel_device_info *devinfo, + const void *assembly, int start, FILE *out); + +void intel_decoder_init(struct intel_batch_decode_ctx *ctx, + const struct intel_device_info *devinfo, + FILE *fp, enum intel_batch_decode_flags flags, + const char *xml_path, + struct intel_batch_decode_bo (*get_bo)(void *, bool, uint64_t), + unsigned (*get_state_size)(void *, uint64_t, uint64_t), + void *user_data); + +#ifdef __cplusplus +} +#endif diff --git a/src/intel/tools/meson.build b/src/intel/tools/meson.build index f9daa52264d..5c7a1707bad 100644 --- a/src/intel/tools/meson.build +++ b/src/intel/tools/meson.build @@ -11,13 +11,39 @@ libaub = static_library( install : false ) +libintel_tools = static_library( + 'intel_tools', + files( + 'intel_tools.c', + 'intel_tools.h' + ), + dependencies : [ + idep_intel_decoder_brw, + idep_intel_decoder_elk, + idep_intel_compiler_brw, + idep_intel_compiler_elk, + idep_libintel_common, + ], + include_directories : [inc_include, inc_src, inc_intel], + link_with : [libintel_common], + c_args : [no_override_init_args], + gnu_symbol_visibility : 'hidden', + install : false, +) + +idep_libintel_tools = declare_dependency( + link_with : libintel_tools, + dependencies : [ + idep_intel_decoder_brw, + idep_intel_decoder_elk, + ] +) + aubinator = executable( 'aubinator', files('aubinator.c'), dependencies : [idep_mesautil, dep_expat, dep_zlib, dep_dl, dep_thread, dep_m, idep_intel_dev, - idep_libintel_common, - idep_intel_decoder_brw, idep_intel_decoder_elk, - idep_intel_compiler_brw, idep_intel_compiler_elk], + idep_libintel_common, idep_libintel_tools], include_directories : [inc_include, inc_src, inc_intel], link_with : [libaub], c_args : [no_override_init_args], @@ -37,9 +63,7 @@ aubinator_error_decode = executable( 'error_decode_xe_lib.c', 'error_decode_xe_lib.h'), dependencies : [idep_mesautil, dep_zlib, dep_thread, idep_intel_dev, - idep_libintel_common, - idep_intel_decoder_brw, idep_intel_decoder_elk, - idep_intel_compiler_brw, idep_intel_compiler_elk], + idep_libintel_common, idep_libintel_tools], include_directories : [inc_include, inc_src, inc_intel], c_args : [no_override_init_args], gnu_symbol_visibility : 'hidden', @@ -82,7 +106,7 @@ intel_hang_replay = executable( 'intel_hang_replay', files('intel_hang_replay.c'), dependencies : [idep_intel_dev, idep_libintel_common, dep_libdrm, dep_dl, dep_thread, dep_m, - idep_intel_compiler_brw, idep_intel_compiler_elk], + idep_libintel_tools], include_directories : [inc_include, inc_src, inc_intel], c_args : [no_override_init_args], gnu_symbol_visibility : 'hidden', @@ -166,8 +190,7 @@ if with_tools.contains('intel-ui') 'aubinator_viewer', files('aubinator_viewer.cpp', 'aubinator_viewer_decoder.cpp'), dependencies : [idep_mesautil, dep_zlib, dep_dl, dep_thread, dep_m, libintel_imgui_gtk_dep, idep_intel_dev, - idep_libintel_common, - idep_intel_compiler_brw, idep_intel_compiler_elk], + idep_libintel_common, idep_libintel_tools], include_directories : [inc_include, inc_src, inc_intel], link_with : [libaub], c_args : [no_override_init_args], @@ -188,10 +211,7 @@ if with_tools.contains('intel-ui') libintel_imgui_gtk_dep, idep_intel_dev, idep_libintel_common, - idep_intel_compiler_brw, - idep_intel_compiler_elk, - idep_intel_decoder_brw, - idep_intel_decoder_elk, + idep_libintel_tools, ], include_directories : [inc_include, inc_src, inc_intel], c_args : [no_override_init_args],