From: Kevin Rogovin <kevin.rogo...@intel.com> The interface for BatchbufferLogger is that it is active only if it is LD_PRELOAD'ed. Thus, the i965 driver is to use dlsym to see if it is there, and if so fetch the object at intel_screen creation.
Signed-off-by: Kevin Rogovin <kevin.rogo...@intel.com> --- src/mesa/drivers/dri/i965/brw_bufmgr.c | 22 ++++++++++++- src/mesa/drivers/dri/i965/brw_bufmgr.h | 8 ++++- src/mesa/drivers/dri/i965/brw_context.c | 2 ++ src/mesa/drivers/dri/i965/brw_context.h | 6 ++++ src/mesa/drivers/dri/i965/intel_screen.c | 55 ++++++++++++++++++++++++++++++-- src/mesa/drivers/dri/i965/intel_screen.h | 3 ++ 6 files changed, 91 insertions(+), 5 deletions(-) diff --git a/src/mesa/drivers/dri/i965/brw_bufmgr.c b/src/mesa/drivers/dri/i965/brw_bufmgr.c index 44aaf02..3473be7 100644 --- a/src/mesa/drivers/dri/i965/brw_bufmgr.c +++ b/src/mesa/drivers/dri/i965/brw_bufmgr.c @@ -66,6 +66,8 @@ #include "string.h" #include "i915_drm.h" +#include "intel_screen.h" +#include "tools/i965_batchbuffer_logger.h" #ifdef HAVE_VALGRIND #include <valgrind.h> @@ -105,6 +107,7 @@ struct bo_cache_bucket { }; struct brw_bufmgr { + struct intel_screen *screen; int fd; pthread_mutex_t lock; @@ -619,9 +622,14 @@ bo_unreference_final(struct brw_bo *bo, time_t time) { struct brw_bufmgr *bufmgr = bo->bufmgr; struct bo_cache_bucket *bucket; + struct i965_batchbuffer_logger *bb_logger = + bufmgr->screen->batchbuffer_logger; DBG("bo_unreference final: %d (%s)\n", bo->gem_handle, bo->name); + if(bb_logger != NULL) { + bb_logger->aborted_batchbuffer(bb_logger, bufmgr->fd, bo->gem_handle); + } bucket = bucket_for_size(bufmgr, bo->size); /* Put the buffer into our internal cache for reuse if we can. */ if (bufmgr->bo_reuse && bo->reusable && bucket != NULL && @@ -1061,6 +1069,12 @@ brw_bufmgr_destroy(struct brw_bufmgr *bufmgr) free(bufmgr); } +int +brw_bufmgr_fd(const struct brw_bufmgr *bufmgr) +{ + return bufmgr->fd; +} + static int bo_set_tiling_internal(struct brw_bo *bo, uint32_t tiling_mode, uint32_t stride) @@ -1334,9 +1348,14 @@ gem_param(int fd, int name) * \param fd File descriptor of the opened DRM device. */ struct brw_bufmgr * -brw_bufmgr_init(struct gen_device_info *devinfo, int fd) +brw_bufmgr_init(struct intel_screen *screen) { struct brw_bufmgr *bufmgr; + struct gen_device_info *devinfo; + int fd; + + devinfo = &screen->devinfo; + fd = screen->driScrnPriv->fd; bufmgr = calloc(1, sizeof(*bufmgr)); if (bufmgr == NULL) @@ -1352,6 +1371,7 @@ brw_bufmgr_init(struct gen_device_info *devinfo, int fd) * fd so that its namespace does not clash with another. */ bufmgr->fd = fd; + bufmgr->screen = screen; if (pthread_mutex_init(&bufmgr->lock, NULL) != 0) { free(bufmgr); diff --git a/src/mesa/drivers/dri/i965/brw_bufmgr.h b/src/mesa/drivers/dri/i965/brw_bufmgr.h index de0ba1d..b78907b 100644 --- a/src/mesa/drivers/dri/i965/brw_bufmgr.h +++ b/src/mesa/drivers/dri/i965/brw_bufmgr.h @@ -46,6 +46,7 @@ extern "C" { struct gen_device_info; struct brw_context; +struct intel_screen; struct brw_bo { /** @@ -275,6 +276,11 @@ void brw_bo_wait_rendering(struct brw_bo *bo); void brw_bufmgr_destroy(struct brw_bufmgr *bufmgr); /** + * Returns the file descriptor of the buffer manager + */ +int brw_bufmgr_fd(const struct brw_bufmgr *bufmgr); + +/** * Get the current tiling (and resulting swizzling) mode for the bo. * * \param buf Buffer to get tiling mode for @@ -313,7 +319,7 @@ int brw_bo_busy(struct brw_bo *bo); int brw_bo_madvise(struct brw_bo *bo, int madv); /* drm_bacon_bufmgr_gem.c */ -struct brw_bufmgr *brw_bufmgr_init(struct gen_device_info *devinfo, int fd); +struct brw_bufmgr *brw_bufmgr_init(struct intel_screen *screen); struct brw_bo *brw_bo_gem_create_from_name(struct brw_bufmgr *bufmgr, const char *name, unsigned int handle); diff --git a/src/mesa/drivers/dri/i965/brw_context.c b/src/mesa/drivers/dri/i965/brw_context.c index ee1badd..d084272 100644 --- a/src/mesa/drivers/dri/i965/brw_context.c +++ b/src/mesa/drivers/dri/i965/brw_context.c @@ -1009,6 +1009,7 @@ brwCreateContext(gl_api api, vbo_use_buffer_objects(ctx); vbo_always_unmap_buffers(ctx); + brw->have_active_batchbuffer = true; return true; } @@ -1021,6 +1022,7 @@ intelDestroyContext(__DRIcontext * driContextPriv) struct gl_context *ctx = &brw->ctx; const struct gen_device_info *devinfo = &brw->screen->devinfo; + brw->have_active_batchbuffer = false; _mesa_meta_free(&brw->ctx); if (INTEL_DEBUG & DEBUG_SHADER_TIME) { diff --git a/src/mesa/drivers/dri/i965/brw_context.h b/src/mesa/drivers/dri/i965/brw_context.h index e130fbf..2d1f5d8 100644 --- a/src/mesa/drivers/dri/i965/brw_context.h +++ b/src/mesa/drivers/dri/i965/brw_context.h @@ -1211,6 +1211,12 @@ struct brw_context */ bool draw_aux_buffer_disabled[MAX_DRAW_BUFFERS]; + /* Set to true if the brw_context is in a state (i.e. not in the middle + * of construction or deconstruction) that it has an active batchbuffer + * and it can report "where" it is in that batchbuffer. + */ + bool have_active_batchbuffer; + __DRIcontext *driContext; struct intel_screen *screen; }; diff --git a/src/mesa/drivers/dri/i965/intel_screen.c b/src/mesa/drivers/dri/i965/intel_screen.c index bc2bba0..b3fbf81 100644 --- a/src/mesa/drivers/dri/i965/intel_screen.c +++ b/src/mesa/drivers/dri/i965/intel_screen.c @@ -23,6 +23,7 @@ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +#include <dlfcn.h> #include <drm_fourcc.h> #include <errno.h> #include <time.h> @@ -39,10 +40,14 @@ #include "brw_defines.h" #include "brw_state.h" #include "compiler/nir/nir.h" +#include "intel_batchbuffer.h" +#include "brw_context.h" #include "utils.h" #include "util/xmlpool.h" +#include "tools/i965_batchbuffer_logger.h" + static const __DRIconfigOptionsExtension brw_config_options = { .base = { __DRI_CONFIG_OPTIONS, 1 }, .xml = @@ -1476,7 +1481,12 @@ static void intelDestroyScreen(__DRIscreen * sPriv) { struct intel_screen *screen = sPriv->driverPrivate; + struct i965_batchbuffer_logger *batchbuffer_logger; + batchbuffer_logger = screen->batchbuffer_logger; + if(batchbuffer_logger != NULL) { + batchbuffer_logger->release_driver(batchbuffer_logger); + } brw_bufmgr_destroy(screen->bufmgr); driDestroyOptionInfo(&screen->optionCache); @@ -1640,12 +1650,10 @@ err_out: static bool intel_init_bufmgr(struct intel_screen *screen) { - __DRIscreen *dri_screen = screen->driScrnPriv; - if (getenv("INTEL_NO_HW") != NULL) screen->no_hw = true; - screen->bufmgr = brw_bufmgr_init(&screen->devinfo, dri_screen->fd); + screen->bufmgr = brw_bufmgr_init(screen); if (screen->bufmgr == NULL) { fprintf(stderr, "[%s:%u] Error initializing buffer manager.\n", __func__, __LINE__); @@ -2230,6 +2238,35 @@ get_pci_device_id(struct intel_screen *screen) return intel_get_integer(screen, I915_PARAM_CHIPSET_ID); } +static +uint32_t +intel_batchbuffer_state(const struct i965_logged_batchbuffer *st) +{ + struct intel_batchbuffer *batch + = (struct intel_batchbuffer*) st->driver_data; + + assert(batch->bo->gem_handle == st->gem_bo); + return batch->map_next - batch->map; +} + +static +void +intel_active_batchbuffer(struct i965_logged_batchbuffer *st) +{ + GET_CURRENT_CONTEXT(ctx); + struct brw_context *brw = brw_context(ctx); + + if(brw != NULL && brw->have_active_batchbuffer) { + st->driver_data = &brw->batch; + st->gem_bo = brw->batch.bo->gem_handle; + st->fd = brw_bufmgr_fd(brw->bufmgr); + } else { + st->driver_data = NULL; + st->gem_bo = -1; + st->fd = -1; + } +} + /** * This is the driver specific part of the createNewScreen entry point. * Called when using DRI2. @@ -2240,6 +2277,7 @@ static const __DRIconfig **intelInitScreen2(__DRIscreen *dri_screen) { struct intel_screen *screen; + i965_batchbuffer_logger_acquire_fcn i965_batchbuffer_logger_acquire; if (dri_screen->image.loader) { } else if (dri_screen->dri2.loader->base.version <= 2 || @@ -2517,6 +2555,17 @@ __DRIconfig **intelInitScreen2(__DRIscreen *dri_screen) intel_screen_init_surface_formats(screen); + i965_batchbuffer_logger_acquire = (i965_batchbuffer_logger_acquire_fcn) + dlsym(NULL, "i965_batchbuffer_logger_acquire"); + if(i965_batchbuffer_logger_acquire) { + screen->batchbuffer_logger = + i965_batchbuffer_logger_acquire(screen->deviceID, + intel_batchbuffer_state, + intel_active_batchbuffer); + } else { + screen->batchbuffer_logger = NULL; + } + return (const __DRIconfig**) intel_screen_make_configs(dri_screen); } diff --git a/src/mesa/drivers/dri/i965/intel_screen.h b/src/mesa/drivers/dri/i965/intel_screen.h index 41e1dbd..ef10d71 100644 --- a/src/mesa/drivers/dri/i965/intel_screen.h +++ b/src/mesa/drivers/dri/i965/intel_screen.h @@ -44,6 +44,7 @@ extern "C" { #endif +struct i965_batchbuffer_logger; struct intel_screen { int deviceID; @@ -117,6 +118,8 @@ struct intel_screen bool mesa_format_supports_texture[MESA_FORMAT_COUNT]; bool mesa_format_supports_render[MESA_FORMAT_COUNT]; enum isl_format mesa_to_isl_render_format[MESA_FORMAT_COUNT]; + + struct i965_batchbuffer_logger *batchbuffer_logger; }; extern void intelDestroyContext(__DRIcontext * driContextPriv); -- 2.7.4 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev