iris: syncobjs are now owned by bufmgr instead of screen
authorPaulo Zanoni <paulo.r.zanoni@intel.com>
Tue, 3 Aug 2021 23:28:02 +0000 (16:28 -0700)
committerMarge Bot <eric+marge@anholt.net>
Wed, 1 Sep 2021 21:48:13 +0000 (21:48 +0000)
The next patches will justify the new ownership. We want the BOs to
have references on the batches' syncobjs so we can implement implicit
tracking. In other words: BOs will be able to wait on syncobjs owned
by different screens. Since our syncobjs are actually just a Kernel
handle with a refcount, they can be used globally and it makes more
sense to map them to the bufmgr, just like the BOs.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Signed-off-by: Paulo Zanoni <paulo.r.zanoni@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12363>

src/gallium/drivers/iris/iris_batch.c
src/gallium/drivers/iris/iris_batch.h
src/gallium/drivers/iris/iris_fence.c
src/gallium/drivers/iris/iris_fence.h
src/gallium/drivers/iris/iris_fine_fence.c
src/gallium/drivers/iris/iris_query.c

index c600ee5..aae730b 100644 (file)
@@ -398,6 +398,7 @@ static void
 iris_batch_reset(struct iris_batch *batch)
 {
    struct iris_screen *screen = batch->screen;
+   struct iris_bufmgr *bufmgr = screen->bufmgr;
 
    iris_bo_unreference(batch->bo);
    batch->primary_batch_size = 0;
@@ -409,9 +410,9 @@ iris_batch_reset(struct iris_batch *batch)
    create_batch(batch);
    assert(batch->bo->index == 0);
 
-   struct iris_syncobj *syncobj = iris_create_syncobj(screen);
+   struct iris_syncobj *syncobj = iris_create_syncobj(bufmgr);
    iris_batch_add_syncobj(batch, syncobj, I915_EXEC_FENCE_SIGNAL);
-   iris_syncobj_reference(screen, &syncobj, NULL);
+   iris_syncobj_reference(bufmgr, &syncobj, NULL);
 
    assert(!batch->sync_region_depth);
    iris_batch_sync_boundary(batch);
@@ -442,7 +443,7 @@ iris_batch_free(struct iris_batch *batch)
    pipe_resource_reference(&batch->fine_fences.ref.res, NULL);
 
    util_dynarray_foreach(&batch->syncobjs, struct iris_syncobj *, s)
-      iris_syncobj_reference(screen, s, NULL);
+      iris_syncobj_reference(bufmgr, s, NULL);
    ralloc_free(batch->syncobjs.mem_ctx);
 
    iris_fine_fence_reference(batch->screen, &batch->last_fence, NULL);
@@ -739,7 +740,7 @@ _iris_batch_flush(struct iris_batch *batch, const char *file, int line)
    batch->aperture_space = 0;
 
    util_dynarray_foreach(&batch->syncobjs, struct iris_syncobj *, s)
-      iris_syncobj_reference(screen, s, NULL);
+      iris_syncobj_reference(screen->bufmgr, s, NULL);
    util_dynarray_clear(&batch->syncobjs);
 
    util_dynarray_clear(&batch->exec_fences);
index a9f5cc6..cd7de52 100644 (file)
@@ -269,7 +269,7 @@ iris_batch_reference_signal_syncobj(struct iris_batch *batch,
                                    struct iris_syncobj **out_syncobj)
 {
    struct iris_syncobj *syncobj = iris_batch_get_signal_syncobj(batch);
-   iris_syncobj_reference(batch->screen, out_syncobj, syncobj);
+   iris_syncobj_reference(batch->screen->bufmgr, out_syncobj, syncobj);
 }
 
 /**
index f6b10d5..a7dffe5 100644 (file)
@@ -63,14 +63,15 @@ gem_syncobj_destroy(int fd, uint32_t handle)
  * Make a new sync-point.
  */
 struct iris_syncobj *
-iris_create_syncobj(struct iris_screen *screen)
+iris_create_syncobj(struct iris_bufmgr *bufmgr)
 {
+   int fd = iris_bufmgr_get_fd(bufmgr);
    struct iris_syncobj *syncobj = malloc(sizeof(*syncobj));
 
    if (!syncobj)
       return NULL;
 
-   syncobj->handle = gem_syncobj_create(screen->fd, 0);
+   syncobj->handle = gem_syncobj_create(fd, 0);
    assert(syncobj->handle);
 
    pipe_reference_init(&syncobj->ref, 1);
@@ -79,9 +80,10 @@ iris_create_syncobj(struct iris_screen *screen)
 }
 
 void
-iris_syncobj_destroy(struct iris_screen *screen, struct iris_syncobj *syncobj)
+iris_syncobj_destroy(struct iris_bufmgr *bufmgr, struct iris_syncobj *syncobj)
 {
-   gem_syncobj_destroy(screen->fd, syncobj->handle);
+   int fd = iris_bufmgr_get_fd(bufmgr);
+   gem_syncobj_destroy(fd, syncobj->handle);
    free(syncobj);
 }
 
@@ -107,7 +109,7 @@ iris_batch_add_syncobj(struct iris_batch *batch,
       util_dynarray_grow(&batch->syncobjs, struct iris_syncobj *, 1);
 
    *store = NULL;
-   iris_syncobj_reference(batch->screen, store, syncobj);
+   iris_syncobj_reference(batch->screen->bufmgr, store, syncobj);
 }
 
 /**
@@ -122,6 +124,7 @@ static void
 clear_stale_syncobjs(struct iris_batch *batch)
 {
    struct iris_screen *screen = batch->screen;
+   struct iris_bufmgr *bufmgr = screen->bufmgr;
 
    int n = util_dynarray_num_elements(&batch->syncobjs, struct iris_syncobj *);
 
@@ -137,13 +140,13 @@ clear_stale_syncobjs(struct iris_batch *batch)
                                struct drm_i915_gem_exec_fence, i);
       assert(fence->flags & I915_EXEC_FENCE_WAIT);
 
-      if (iris_wait_syncobj(&screen->base, *syncobj, 0))
+      if (iris_wait_syncobj(bufmgr, *syncobj, 0))
          continue;
 
       /* This sync object has already passed, there's no need to continue
        * marking it as a dependency; we can stop holding on to the reference.
        */
-      iris_syncobj_reference(screen, syncobj, NULL);
+      iris_syncobj_reference(bufmgr, syncobj, NULL);
 
       /* Remove it from the lists; move the last element here. */
       struct iris_syncobj **nth_syncobj =
@@ -194,20 +197,21 @@ iris_fence_reference(struct pipe_screen *p_screen,
 }
 
 bool
-iris_wait_syncobj(struct pipe_screen *p_screen,
+iris_wait_syncobj(struct iris_bufmgr *bufmgr,
                   struct iris_syncobj *syncobj,
                   int64_t timeout_nsec)
 {
    if (!syncobj)
       return false;
 
-   struct iris_screen *screen = (struct iris_screen *)p_screen;
+   int fd = iris_bufmgr_get_fd(bufmgr);
+
    struct drm_syncobj_wait args = {
       .handles = (uintptr_t)&syncobj->handle,
       .count_handles = 1,
       .timeout_nsec = timeout_nsec,
    };
-   return intel_ioctl(screen->fd, DRM_IOCTL_SYNCOBJ_WAIT, &args);
+   return intel_ioctl(fd, DRM_IOCTL_SYNCOBJ_WAIT, &args);
 }
 
 #define CSI "\e["
index 0696627..1332e55 100644 (file)
@@ -27,8 +27,8 @@
 #include "util/u_inlines.h"
 
 struct pipe_screen;
-struct iris_screen;
 struct iris_batch;
+struct iris_bufmgr;
 
 /**
  * A refcounted DRM Sync Object (drm_syncobj).
@@ -38,24 +38,24 @@ struct iris_syncobj {
    uint32_t handle;
 };
 
-struct iris_syncobj *iris_create_syncobj(struct iris_screen *screen);
-void iris_syncobj_destroy(struct iris_screen *, struct iris_syncobj *);
+struct iris_syncobj *iris_create_syncobj(struct iris_bufmgr *bufmgr);
+void iris_syncobj_destroy(struct iris_bufmgr*, struct iris_syncobj *);
 
 void iris_batch_add_syncobj(struct iris_batch *batch,
                             struct iris_syncobj *syncobj,
                             unsigned flags);
-bool iris_wait_syncobj(struct pipe_screen *screen,
+bool iris_wait_syncobj(struct iris_bufmgr *bufmgr,
                        struct iris_syncobj *syncobj,
                        int64_t timeout_nsec);
 
 static inline void
-iris_syncobj_reference(struct iris_screen *screen,
+iris_syncobj_reference(struct iris_bufmgr *bufmgr,
                        struct iris_syncobj **dst,
                        struct iris_syncobj *src)
 {
    if (pipe_reference(*dst ? &(*dst)->ref : NULL,
                       src ? &src->ref : NULL))
-      iris_syncobj_destroy(screen, *dst);
+      iris_syncobj_destroy(bufmgr, *dst);
 
    *dst = src;
 }
index 0470389..f057a64 100644 (file)
@@ -36,7 +36,7 @@ void
 iris_fine_fence_destroy(struct iris_screen *screen,
                         struct iris_fine_fence *fine)
 {
-   iris_syncobj_reference(screen, &fine->syncobj, NULL);
+   iris_syncobj_reference(screen->bufmgr, &fine->syncobj, NULL);
    pipe_resource_reference(&fine->ref.res, NULL);
    free(fine);
 }
@@ -52,7 +52,7 @@ iris_fine_fence_new(struct iris_batch *batch, unsigned flags)
 
    fine->seqno = iris_fine_fence_next(batch);
 
-   iris_syncobj_reference(batch->screen, &fine->syncobj,
+   iris_syncobj_reference(batch->screen->bufmgr, &fine->syncobj,
                           iris_batch_get_signal_syncobj(batch));
 
    pipe_resource_reference(&fine->ref.res, batch->fine_fences.ref.res);
index e497b71..e79d23c 100644 (file)
@@ -483,7 +483,7 @@ iris_destroy_query(struct pipe_context *ctx, struct pipe_query *p_query)
       iris_destroy_monitor_object(ctx, query->monitor);
       query->monitor = NULL;
    } else {
-      iris_syncobj_reference(screen, &query->syncobj, NULL);
+      iris_syncobj_reference(screen->bufmgr, &query->syncobj, NULL);
       screen->base.fence_reference(ctx->screen, &query->fence, NULL);
    }
    pipe_resource_reference(&query->query_state_ref.res, NULL);
@@ -632,7 +632,7 @@ iris_get_query_result(struct pipe_context *ctx,
 
       while (!READ_ONCE(q->map->snapshots_landed)) {
          if (wait)
-            iris_wait_syncobj(ctx->screen, q->syncobj, INT64_MAX);
+            iris_wait_syncobj(screen->bufmgr, q->syncobj, INT64_MAX);
          else
             return false;
       }