[Mesa-dev] [PATCH 2/4] radeon: Add bo statistics dumping support

Marek Olšák maraeo at gmail.com
Mon Jan 6 15:22:08 PST 2014


Is the logging really needed apart from initial debugging and
validation of the code? I don't see a reason to have this in master.

Also, pipe_screen functions must not change the contents of
radeon_winsys. They are different objects. The two can only
communicate using the functions declared in the radeon_winsys
structure.

Marek

On Mon, Jan 6, 2014 at 12:17 PM, Lauri Kasanen <cand at gmx.com> wrote:
> No measurable overhead when off (glxgears within 0.5%).
>
> v2: Cosmetic changes.
>
> Signed-off-by: Lauri Kasanen <cand at gmx.com>
> ---
>  src/gallium/drivers/radeon/r600_pipe_common.c | 32 +++++++++++++++++++++++++++
>  src/gallium/drivers/radeon/r600_pipe_common.h |  1 +
>  src/gallium/winsys/radeon/drm/radeon_drm_bo.c | 17 ++++++++++++++
>  src/gallium/winsys/radeon/drm/radeon_drm_cs.c |  9 ++++++++
>  src/gallium/winsys/radeon/drm/radeon_winsys.h |  6 +++++
>  5 files changed, 65 insertions(+)
>
> diff --git a/src/gallium/drivers/radeon/r600_pipe_common.c b/src/gallium/drivers/radeon/r600_pipe_common.c
> index 28921be..f649b9f 100644
> --- a/src/gallium/drivers/radeon/r600_pipe_common.c
> +++ b/src/gallium/drivers/radeon/r600_pipe_common.c
> @@ -26,11 +26,18 @@
>
>  #include "r600_pipe_common.h"
>  #include "r600_cs.h"
> +#include "../../winsys/radeon/drm/radeon_drm_winsys.h"
> +#include "os/os_time.h"
>  #include "tgsi/tgsi_parse.h"
>  #include "util/u_format_s3tc.h"
>  #include "util/u_upload_mgr.h"
>  #include <inttypes.h>
>
> +#ifdef __GLIBC__
> +#define _GNU_SOURCE
> +#include <errno.h>
> +#endif
> +
>  static const struct debug_named_value common_debug_options[] = {
>         /* logging */
>         { "tex", DBG_TEX, "Print texture info" },
> @@ -38,6 +45,7 @@ static const struct debug_named_value common_debug_options[] = {
>         { "compute", DBG_COMPUTE, "Print compute info" },
>         { "vm", DBG_VM, "Print virtual addresses when creating resources" },
>         { "trace_cs", DBG_TRACE_CS, "Trace cs and write rlockup_<csid>.c file with faulty cs" },
> +       { "bostats", DBG_BO_STATS, "Write bo statistics to /tmp/bostats.<pid>[.name]" },
>
>         /* shaders */
>         { "fs", DBG_FS, "Print fetch shaders" },
> @@ -209,6 +217,24 @@ bool r600_common_screen_init(struct r600_common_screen *rscreen,
>                 return false;
>         }
>
> +       if (rscreen->debug_flags & DBG_BO_STATS) {
> +               char statsfile[80];
> +               const pid_t pid = getpid();
> +
> +#ifdef __GLIBC__
> +               snprintf(statsfile, 80, "/tmp/bostats.%u.%s", pid, program_invocation_short_name);
> +#else
> +               snprintf(statsfile, 80, "/tmp/bostats.%u", pid);
> +#endif
> +
> +               rscreen->ws->bo_stats_file = fopen(statsfile, "w");
> +               if (!rscreen->ws->bo_stats_file)
> +                       fprintf(stderr, "Failed to open bo stats file %s\n", statsfile);
> +               else
> +                       fprintf(rscreen->ws->bo_stats_file, "started @%llu\n",
> +                               stats_time_get(ws));
> +       }
> +
>         util_format_s3tc_init();
>
>         pipe_mutex_init(rscreen->aux_context_lock);
> @@ -217,6 +243,12 @@ bool r600_common_screen_init(struct r600_common_screen *rscreen,
>
>  void r600_common_screen_cleanup(struct r600_common_screen *rscreen)
>  {
> +       if ((rscreen->debug_flags & DBG_BO_STATS) && rscreen->ws->bo_stats_file) {
> +               fflush(rscreen->ws->bo_stats_file);
> +               fclose(rscreen->ws->bo_stats_file);
> +               rscreen->ws->bo_stats_file = NULL;
> +       }
> +
>         pipe_mutex_destroy(rscreen->aux_context_lock);
>         rscreen->aux_context->destroy(rscreen->aux_context);
>  }
> diff --git a/src/gallium/drivers/radeon/r600_pipe_common.h b/src/gallium/drivers/radeon/r600_pipe_common.h
> index bf0b968..4c35e66 100644
> --- a/src/gallium/drivers/radeon/r600_pipe_common.h
> +++ b/src/gallium/drivers/radeon/r600_pipe_common.h
> @@ -67,6 +67,7 @@
>  #define DBG_COMPUTE            (1 << 2)
>  #define DBG_VM                 (1 << 3)
>  #define DBG_TRACE_CS           (1 << 4)
> +#define DBG_BO_STATS           (1 << 5)
>  /* shaders */
>  #define DBG_FS                 (1 << 8)
>  #define DBG_VS                 (1 << 9)
> diff --git a/src/gallium/winsys/radeon/drm/radeon_drm_bo.c b/src/gallium/winsys/radeon/drm/radeon_drm_bo.c
> index ca569a1..7543840 100644
> --- a/src/gallium/winsys/radeon/drm/radeon_drm_bo.c
> +++ b/src/gallium/winsys/radeon/drm/radeon_drm_bo.c
> @@ -370,6 +370,7 @@ static void radeon_bo_destroy(struct pb_buffer *_buf)
>  {
>      struct radeon_bo *bo = radeon_bo(_buf);
>      struct radeon_bomgr *mgr = bo->mgr;
> +    struct radeon_winsys *ws = (struct radeon_winsys *) mgr->rws;
>      struct drm_gem_close args;
>
>      memset(&args, 0, sizeof(args));
> @@ -399,6 +400,11 @@ static void radeon_bo_destroy(struct pb_buffer *_buf)
>          bo->rws->allocated_vram -= align(bo->base.size, 4096);
>      else if (bo->initial_domain & RADEON_DOMAIN_GTT)
>          bo->rws->allocated_gtt -= align(bo->base.size, 4096);
> +
> +    if (ws->bo_stats_file) {
> +        fprintf(ws->bo_stats_file, "%p destroyed @%llu\n", bo, stats_time_get(ws));
> +    }
> +
>      FREE(bo);
>  }
>
> @@ -450,6 +456,7 @@ static void *radeon_bo_map(struct radeon_winsys_cs_handle *buf,
>  {
>      struct radeon_bo *bo = (struct radeon_bo*)buf;
>      struct radeon_drm_cs *cs = (struct radeon_drm_cs*)rcs;
> +    struct radeon_winsys *ws = (struct radeon_winsys *) bo->mgr->rws;
>
>      /* If it's not unsynchronized bo_map, flush CS if needed and then wait. */
>      if (!(usage & PIPE_TRANSFER_UNSYNCHRONIZED)) {
> @@ -518,6 +525,10 @@ static void *radeon_bo_map(struct radeon_winsys_cs_handle *buf,
>          }
>      }
>
> +    if (ws->bo_stats_file) {
> +        fprintf(ws->bo_stats_file, "%p cpu mapped @%llu\n", bo, stats_time_get(ws));
> +    }
> +
>      return radeon_bo_do_map(bo);
>  }
>
> @@ -562,6 +573,7 @@ static struct pb_buffer *radeon_bomgr_create_bo(struct pb_manager *_mgr,
>  {
>      struct radeon_bomgr *mgr = radeon_bomgr(_mgr);
>      struct radeon_drm_winsys *rws = mgr->rws;
> +    struct radeon_winsys *ws = (struct radeon_winsys *) rws;
>      struct radeon_bo *bo;
>      struct drm_radeon_gem_create args;
>      struct radeon_bo_desc *rdesc = (struct radeon_bo_desc*)desc;
> @@ -636,6 +648,11 @@ static struct pb_buffer *radeon_bomgr_create_bo(struct pb_manager *_mgr,
>      else if (rdesc->initial_domains & RADEON_DOMAIN_GTT)
>          rws->allocated_gtt += align(size, 4096);
>
> +    if (ws->bo_stats_file) {
> +        fprintf(ws->bo_stats_file, "%p created, size %u, prio %u, @%llu\n", bo, size,
> +                                   bo->stats.high_prio, stats_time_get(ws));
> +    }
> +
>      return &bo->base;
>  }
>
> diff --git a/src/gallium/winsys/radeon/drm/radeon_drm_cs.c b/src/gallium/winsys/radeon/drm/radeon_drm_cs.c
> index d8ad297..4d46e85 100644
> --- a/src/gallium/winsys/radeon/drm/radeon_drm_cs.c
> +++ b/src/gallium/winsys/radeon/drm/radeon_drm_cs.c
> @@ -344,6 +344,7 @@ static unsigned radeon_drm_cs_add_reloc(struct radeon_winsys_cs *rcs,
>  {
>      struct radeon_drm_cs *cs = radeon_drm_cs(rcs);
>      struct radeon_bo *bo = (struct radeon_bo*)buf;
> +    struct radeon_winsys *ws = (struct radeon_winsys *) cs->ws;
>      enum radeon_bo_domain added_domains;
>      unsigned index = radeon_add_reloc(cs, bo, usage, domains, &added_domains);
>
> @@ -352,6 +353,14 @@ static unsigned radeon_drm_cs_add_reloc(struct radeon_winsys_cs *rcs,
>      if (added_domains & RADEON_DOMAIN_VRAM)
>          cs->csc->used_vram += bo->base.size;
>
> +    if (ws->bo_stats_file) {
> +        if (usage & RADEON_USAGE_WRITE) {
> +            fprintf(ws->bo_stats_file, "%p write @%llu\n", bo, stats_time_get(ws));
> +        } else {
> +            fprintf(ws->bo_stats_file, "%p read @%llu\n", bo, stats_time_get(ws));
> +        }
> +    }
> +
>      return index;
>  }
>
> diff --git a/src/gallium/winsys/radeon/drm/radeon_winsys.h b/src/gallium/winsys/radeon/drm/radeon_winsys.h
> index 85458c2..33e5c3e 100644
> --- a/src/gallium/winsys/radeon/drm/radeon_winsys.h
> +++ b/src/gallium/winsys/radeon/drm/radeon_winsys.h
> @@ -40,6 +40,7 @@
>   * - R16F/RG16F
>   */
>
> +#include <stdio.h>
>  #include "pipebuffer/pb_buffer.h"
>  #include "radeon_surface.h"
>
> @@ -214,6 +215,11 @@ struct radeon_winsys {
>      struct pipe_screen *screen;
>
>      /**
> +     * The bo statistics debug file, if any
> +     */
> +    FILE *bo_stats_file;
> +
> +    /**
>       * Destroy this winsys.
>       *
>       * \param ws        The winsys this function is called from.
> --
> 1.8.3.1
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev


More information about the mesa-dev mailing list