[Mesa-dev] [PATCH 10/15] radeonsi: move si_get_wave_info() to AMD common code
Marek Olšák
maraeo at gmail.com
Tue Sep 12 11:43:17 UTC 2017
Reviewed-by: Marek Olšák <marek.olsak at amd.com>
Marek
On Tue, Sep 12, 2017 at 12:35 PM, Samuel Pitoiset
<samuel.pitoiset at gmail.com> wrote:
> This will allow us to use it from radv.
>
> Signed-off-by: Samuel Pitoiset <samuel.pitoiset at gmail.com>
> ---
> src/amd/common/ac_debug.c | 76 ++++++++++++++++++++++++++
> src/amd/common/ac_debug.h | 18 +++++++
> src/gallium/drivers/radeonsi/si_debug.c | 96 ++-------------------------------
> 3 files changed, 97 insertions(+), 93 deletions(-)
>
> diff --git a/src/amd/common/ac_debug.c b/src/amd/common/ac_debug.c
> index 54685356f1..26d1f7dced 100644
> --- a/src/amd/common/ac_debug.c
> +++ b/src/amd/common/ac_debug.c
> @@ -43,6 +43,8 @@
> #include "util/u_memory.h"
> #include "util/u_string.h"
>
> +#include <assert.h>
> +
> /* Parsed IBs are difficult to read without colors. Use "less -R file" to
> * read them, or use "aha -b -f file" to convert them to html.
> */
> @@ -721,3 +723,77 @@ bool ac_vm_fault_occured(enum chip_class chip_class,
>
> return fault;
> }
> +
> +static int compare_wave(const void *p1, const void *p2)
> +{
> + struct ac_wave_info *w1 = (struct ac_wave_info *)p1;
> + struct ac_wave_info *w2 = (struct ac_wave_info *)p2;
> +
> + /* Sort waves according to PC and then SE, SH, CU, etc. */
> + if (w1->pc < w2->pc)
> + return -1;
> + if (w1->pc > w2->pc)
> + return 1;
> + if (w1->se < w2->se)
> + return -1;
> + if (w1->se > w2->se)
> + return 1;
> + if (w1->sh < w2->sh)
> + return -1;
> + if (w1->sh > w2->sh)
> + return 1;
> + if (w1->cu < w2->cu)
> + return -1;
> + if (w1->cu > w2->cu)
> + return 1;
> + if (w1->simd < w2->simd)
> + return -1;
> + if (w1->simd > w2->simd)
> + return 1;
> + if (w1->wave < w2->wave)
> + return -1;
> + if (w1->wave > w2->wave)
> + return 1;
> +
> + return 0;
> +}
> +
> +/* Return wave information. "waves" should be a large enough array. */
> +unsigned ac_get_wave_info(struct ac_wave_info waves[AC_MAX_WAVES_PER_CHIP])
> +{
> + char line[2000];
> + unsigned num_waves = 0;
> +
> + FILE *p = popen("umr -wa", "r");
> + if (!p)
> + return 0;
> +
> + if (!fgets(line, sizeof(line), p) ||
> + strncmp(line, "SE", 2) != 0) {
> + pclose(p);
> + return 0;
> + }
> +
> + while (fgets(line, sizeof(line), p)) {
> + struct ac_wave_info *w;
> + uint32_t pc_hi, pc_lo, exec_hi, exec_lo;
> +
> + assert(num_waves < AC_MAX_WAVES_PER_CHIP);
> + w = &waves[num_waves];
> +
> + if (sscanf(line, "%u %u %u %u %u %x %x %x %x %x %x %x",
> + &w->se, &w->sh, &w->cu, &w->simd, &w->wave,
> + &w->status, &pc_hi, &pc_lo, &w->inst_dw0,
> + &w->inst_dw1, &exec_hi, &exec_lo) == 12) {
> + w->pc = ((uint64_t)pc_hi << 32) | pc_lo;
> + w->exec = ((uint64_t)exec_hi << 32) | exec_lo;
> + w->matched = false;
> + num_waves++;
> + }
> + }
> +
> + qsort(waves, num_waves, sizeof(struct ac_wave_info), compare_wave);
> +
> + pclose(p);
> + return num_waves;
> +}
> diff --git a/src/amd/common/ac_debug.h b/src/amd/common/ac_debug.h
> index 35e950014b..df20752653 100644
> --- a/src/amd/common/ac_debug.h
> +++ b/src/amd/common/ac_debug.h
> @@ -36,6 +36,22 @@
> #define AC_IS_TRACE_POINT(x) (((x) & 0xcafe0000) == 0xcafe0000)
> #define AC_GET_TRACE_POINT_ID(x) ((x) & 0xffff)
>
> +#define AC_MAX_WAVES_PER_CHIP (64 * 40)
> +
> +struct ac_wave_info {
> + unsigned se; /* shader engine */
> + unsigned sh; /* shader array */
> + unsigned cu; /* compute unit */
> + unsigned simd;
> + unsigned wave;
> + uint32_t status;
> + uint64_t pc; /* program counter */
> + uint32_t inst_dw0;
> + uint32_t inst_dw1;
> + uint64_t exec;
> + bool matched; /* whether the wave is used by a currently-bound shader */
> +};
> +
> typedef void *(*ac_debug_addr_callback)(void *data, uint64_t addr);
>
> void ac_dump_reg(FILE *file, enum chip_class chip_class, unsigned offset,
> @@ -50,4 +66,6 @@ void ac_parse_ib(FILE *f, uint32_t *ib, int num_dw, const int *trace_ids,
> bool ac_vm_fault_occured(enum chip_class chip_class,
> uint64_t *old_dmesg_timestamp, uint64_t *out_addr);
>
> +unsigned ac_get_wave_info(struct ac_wave_info waves[AC_MAX_WAVES_PER_CHIP]);
> +
> #endif
> diff --git a/src/gallium/drivers/radeonsi/si_debug.c b/src/gallium/drivers/radeonsi/si_debug.c
> index 182574d653..16ae701c6c 100644
> --- a/src/gallium/drivers/radeonsi/si_debug.c
> +++ b/src/gallium/drivers/radeonsi/si_debug.c
> @@ -811,102 +811,12 @@ static void si_add_split_disasm(const char *disasm,
> }
> }
>
> -#define MAX_WAVES_PER_CHIP (64 * 40)
> -
> -struct si_wave_info {
> - unsigned se; /* shader engine */
> - unsigned sh; /* shader array */
> - unsigned cu; /* compute unit */
> - unsigned simd;
> - unsigned wave;
> - uint32_t status;
> - uint64_t pc; /* program counter */
> - uint32_t inst_dw0;
> - uint32_t inst_dw1;
> - uint64_t exec;
> - bool matched; /* whether the wave is used by a currently-bound shader */
> -};
> -
> -static int compare_wave(const void *p1, const void *p2)
> -{
> - struct si_wave_info *w1 = (struct si_wave_info *)p1;
> - struct si_wave_info *w2 = (struct si_wave_info *)p2;
> -
> - /* Sort waves according to PC and then SE, SH, CU, etc. */
> - if (w1->pc < w2->pc)
> - return -1;
> - if (w1->pc > w2->pc)
> - return 1;
> - if (w1->se < w2->se)
> - return -1;
> - if (w1->se > w2->se)
> - return 1;
> - if (w1->sh < w2->sh)
> - return -1;
> - if (w1->sh > w2->sh)
> - return 1;
> - if (w1->cu < w2->cu)
> - return -1;
> - if (w1->cu > w2->cu)
> - return 1;
> - if (w1->simd < w2->simd)
> - return -1;
> - if (w1->simd > w2->simd)
> - return 1;
> - if (w1->wave < w2->wave)
> - return -1;
> - if (w1->wave > w2->wave)
> - return 1;
> -
> - return 0;
> -}
> -
> -/* Return wave information. "waves" should be a large enough array. */
> -static unsigned si_get_wave_info(struct si_wave_info waves[MAX_WAVES_PER_CHIP])
> -{
> - char line[2000];
> - unsigned num_waves = 0;
> -
> - FILE *p = popen("umr -wa", "r");
> - if (!p)
> - return 0;
> -
> - if (!fgets(line, sizeof(line), p) ||
> - strncmp(line, "SE", 2) != 0) {
> - pclose(p);
> - return 0;
> - }
> -
> - while (fgets(line, sizeof(line), p)) {
> - struct si_wave_info *w;
> - uint32_t pc_hi, pc_lo, exec_hi, exec_lo;
> -
> - assert(num_waves < MAX_WAVES_PER_CHIP);
> - w = &waves[num_waves];
> -
> - if (sscanf(line, "%u %u %u %u %u %x %x %x %x %x %x %x",
> - &w->se, &w->sh, &w->cu, &w->simd, &w->wave,
> - &w->status, &pc_hi, &pc_lo, &w->inst_dw0,
> - &w->inst_dw1, &exec_hi, &exec_lo) == 12) {
> - w->pc = ((uint64_t)pc_hi << 32) | pc_lo;
> - w->exec = ((uint64_t)exec_hi << 32) | exec_lo;
> - w->matched = false;
> - num_waves++;
> - }
> - }
> -
> - qsort(waves, num_waves, sizeof(struct si_wave_info), compare_wave);
> -
> - pclose(p);
> - return num_waves;
> -}
> -
> /* If the shader is being executed, print its asm instructions, and annotate
> * those that are being executed right now with information about waves that
> * execute them. This is most useful during a GPU hang.
> */
> static void si_print_annotated_shader(struct si_shader *shader,
> - struct si_wave_info *waves,
> + struct ac_wave_info *waves,
> unsigned num_waves,
> FILE *f)
> {
> @@ -992,8 +902,8 @@ static void si_print_annotated_shader(struct si_shader *shader,
>
> static void si_dump_annotated_shaders(struct si_context *sctx, FILE *f)
> {
> - struct si_wave_info waves[MAX_WAVES_PER_CHIP];
> - unsigned num_waves = si_get_wave_info(waves);
> + struct ac_wave_info waves[AC_MAX_WAVES_PER_CHIP];
> + unsigned num_waves = ac_get_wave_info(waves);
>
> fprintf(f, COLOR_CYAN "The number of active waves = %u" COLOR_RESET
> "\n\n", num_waves);
> --
> 2.14.1
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
More information about the mesa-dev
mailing list