intel/tools/error_decode: Move code that can be shared between i915 and Xe error decoders

Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Signed-off-by: José Roberto de Souza <jose.souza@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27661>
This commit is contained in:
José Roberto de Souza 2024-02-21 06:12:14 -08:00 committed by Marge Bot
parent 6f9a5f4811
commit 7e88176b0b
6 changed files with 126 additions and 82 deletions

View file

@ -38,6 +38,7 @@
#include <getopt.h>
#include <zlib.h>
#include "aubinator_error_decode_lib.h"
#include "aubinator_error_decode_xe.h"
#include "compiler/brw_compiler.h"
#include "compiler/elk/elk_compiler.h"
@ -106,46 +107,6 @@ static const struct ring_register_mapping fault_registers[] = {
{ INTEL_ENGINE_CLASS_VIDEO_ENHANCE, 0, "VECS_FAULT_REG" },
};
static int ring_name_to_class(const char *ring_name,
enum intel_engine_class *class)
{
static const char *class_names[] = {
[INTEL_ENGINE_CLASS_RENDER] = "rcs",
[INTEL_ENGINE_CLASS_COMPUTE] = "ccs",
[INTEL_ENGINE_CLASS_COPY] = "bcs",
[INTEL_ENGINE_CLASS_VIDEO] = "vcs",
[INTEL_ENGINE_CLASS_VIDEO_ENHANCE] = "vecs",
};
for (size_t i = 0; i < ARRAY_SIZE(class_names); i++) {
if (strncmp(ring_name, class_names[i], strlen(class_names[i])))
continue;
*class = i;
return atoi(ring_name + strlen(class_names[i]));
}
static const struct {
const char *name;
unsigned int class;
int instance;
} legacy_names[] = {
{ "render", INTEL_ENGINE_CLASS_RENDER, 0 },
{ "blt", INTEL_ENGINE_CLASS_COPY, 0 },
{ "bsd", INTEL_ENGINE_CLASS_VIDEO, 0 },
{ "bsd2", INTEL_ENGINE_CLASS_VIDEO, 1 },
{ "vebox", INTEL_ENGINE_CLASS_VIDEO_ENHANCE, 0 },
};
for (size_t i = 0; i < ARRAY_SIZE(legacy_names); i++) {
if (strcmp(ring_name, legacy_names[i].name))
continue;
*class = legacy_names[i].class;
return legacy_names[i].instance;
}
return -1;
}
static const char *
register_name_from_ring(const struct ring_register_mapping *mapping,
unsigned nb_mapping,
@ -365,16 +326,7 @@ static int ascii85_decode(const char *in, uint32_t **out, bool inflate)
return 0;
}
if (*in == 'z') {
in++;
} else {
v += in[0] - 33; v *= 85;
v += in[1] - 33; v *= 85;
v += in[2] - 33; v *= 85;
v += in[3] - 33; v *= 85;
v += in[4] - 33;
in += 5;
}
in = ascii85_decode_char(in, &v);
(*out)[len++] = v;
}
@ -413,25 +365,7 @@ get_intel_batch_bo(void *user_data, bool ppgtt, uint64_t address)
}
static void
dump_shader_binary(void *user_data, const char *short_name,
uint64_t address, const void *data,
unsigned data_length)
{
char filename[128];
snprintf(filename, sizeof(filename), "%s_0x%016"PRIx64".bin",
short_name, address);
FILE *f = fopen(filename, "w");
if (f == NULL) {
fprintf(stderr, "Unable to open %s\n", filename);
return;
}
fwrite(data, data_length, 1, f);
fclose(f);
}
static void
read_i915_data_file(FILE *file)
read_i915_data_file(FILE *file, enum intel_batch_decode_flags batch_flags)
{
struct intel_spec *spec = NULL;
long long unsigned fence;
@ -732,15 +666,6 @@ read_i915_data_file(FILE *file)
}
}
enum intel_batch_decode_flags batch_flags = 0;
if (option_color == COLOR_ALWAYS)
batch_flags |= INTEL_BATCH_DECODE_IN_COLOR;
if (option_full_decode)
batch_flags |= INTEL_BATCH_DECODE_FULL;
if (option_print_offsets)
batch_flags |= INTEL_BATCH_DECODE_OFFSETS;
batch_flags |= INTEL_BATCH_DECODE_FLOATS;
struct intel_batch_decode_ctx batch_ctx;
if (devinfo.ver >= 9) {
intel_batch_decode_ctx_init_brw(&batch_ctx, &brw, &devinfo, stdout,
@ -912,6 +837,7 @@ open_i915_error_state_file(const char *path)
int
main(int argc, char *argv[])
{
enum intel_batch_decode_flags batch_flags = 0;
FILE *file;
int c, i;
bool help = false, pager = true;
@ -1004,12 +930,20 @@ main(int argc, char *argv[])
if (isatty(1) && pager)
setup_pager();
if (option_color == COLOR_ALWAYS)
batch_flags |= INTEL_BATCH_DECODE_IN_COLOR;
if (option_full_decode)
batch_flags |= INTEL_BATCH_DECODE_FULL;
if (option_print_offsets)
batch_flags |= INTEL_BATCH_DECODE_OFFSETS;
batch_flags |= INTEL_BATCH_DECODE_FLOATS;
getline(&line, &line_size, file);
rewind(file);
if (strncmp(line, XE_KMD_ERROR_DUMP_IDENTIFIER, strlen(XE_KMD_ERROR_DUMP_IDENTIFIER)) == 0)
read_xe_data_file(file);
read_xe_data_file(file, batch_flags);
else
read_i915_data_file(file);
read_i915_data_file(file, batch_flags);
free(line);
fclose(file);

View file

@ -0,0 +1,89 @@
/*
* Copyright 2024 Intel Corporation
* SPDX-License-Identifier: MIT
*/
#include "aubinator_error_decode_lib.h"
#include <inttypes.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include "util/macros.h"
int ring_name_to_class(const char *ring_name, enum intel_engine_class *class)
{
static const char *class_names[] = {
[INTEL_ENGINE_CLASS_RENDER] = "rcs",
[INTEL_ENGINE_CLASS_COMPUTE] = "ccs",
[INTEL_ENGINE_CLASS_COPY] = "bcs",
[INTEL_ENGINE_CLASS_VIDEO] = "vcs",
[INTEL_ENGINE_CLASS_VIDEO_ENHANCE] = "vecs",
};
for (size_t i = 0; i < ARRAY_SIZE(class_names); i++) {
if (strncmp(ring_name, class_names[i], strlen(class_names[i])))
continue;
*class = i;
return atoi(ring_name + strlen(class_names[i]));
}
static const struct {
const char *name;
unsigned int class;
int instance;
} legacy_names[] = {
{ "render", INTEL_ENGINE_CLASS_RENDER, 0 },
{ "blt", INTEL_ENGINE_CLASS_COPY, 0 },
{ "bsd", INTEL_ENGINE_CLASS_VIDEO, 0 },
{ "bsd2", INTEL_ENGINE_CLASS_VIDEO, 1 },
{ "vebox", INTEL_ENGINE_CLASS_VIDEO_ENHANCE, 0 },
};
for (size_t i = 0; i < ARRAY_SIZE(legacy_names); i++) {
if (strcmp(ring_name, legacy_names[i].name))
continue;
*class = legacy_names[i].class;
return legacy_names[i].instance;
}
return -1;
}
void
dump_shader_binary(void *user_data, const char *short_name,
uint64_t address, const void *data,
unsigned data_length)
{
char filename[128];
snprintf(filename, sizeof(filename), "%s_0x%016"PRIx64".bin",
short_name, address);
FILE *f = fopen(filename, "w");
if (f == NULL) {
fprintf(stderr, "Unable to open %s\n", filename);
return;
}
fwrite(data, data_length, 1, f);
fclose(f);
}
const char *
ascii85_decode_char(const char *in, uint32_t *v)
{
*v = 0;
if (*in == 'z') {
in++;
} else {
*v += in[0] - 33; *v *= 85;
*v += in[1] - 33; *v *= 85;
*v += in[2] - 33; *v *= 85;
*v += in[3] - 33; *v *= 85;
*v += in[4] - 33;
in += 5;
}
return in;
}

View file

@ -0,0 +1,17 @@
/*
* Copyright 2024 Intel Corporation
* SPDX-License-Identifier: MIT
*/
#pragma once
#include "intel/common/intel_engine.h"
int ring_name_to_class(const char *ring_name, enum intel_engine_class *class);
void
dump_shader_binary(void *user_data, const char *short_name,
uint64_t address, const void *data,
unsigned data_length);
const char *ascii85_decode_char(const char *in, uint32_t *v);

View file

@ -6,6 +6,6 @@
#include "aubinator_error_decode_xe.h"
void
read_xe_data_file(FILE *file)
read_xe_data_file(FILE *file, enum intel_batch_decode_flags batch_flags)
{
}

View file

@ -7,4 +7,6 @@
#include <stdio.h>
void read_xe_data_file(FILE *file);
#include "decoder/intel_decoder.h"
void read_xe_data_file(FILE *file, enum intel_batch_decode_flags batch_flags);

View file

@ -44,6 +44,8 @@ aubinator = executable(
aubinator_error_decode = executable(
'aubinator_error_decode',
files('aubinator_error_decode.c',
'aubinator_error_decode_lib.c',
'aubinator_error_decode_lib.h',
'aubinator_error_decode_xe.c',
'aubinator_error_decode_xe.h'),
dependencies : [idep_mesautil, dep_zlib, dep_thread, idep_intel_dev,