[Mesa-dev] [PATCH] gallium/u_queue: add optional cleanup callback

Marek Olšák maraeo at gmail.com
Thu Jul 14 22:03:27 UTC 2016


Reviewed-by: Marek Olšák <marek.olsak at amd.com>

Marek

On Thu, Jul 14, 2016 at 9:08 PM, Rob Clark <robdclark at gmail.com> wrote:
> Adds a second optional cleanup callback, called after the fence is
> signaled.  This is needed if, for example, the queue has the last
> reference to the object that embeds the util_queue_fence.  In this
> case we cannot drop the ref in the main callback, since that would
> result in the fence being destroyed before it is signaled.
>
> Signed-off-by: Rob Clark <robdclark at gmail.com>
> ---
> v2: drop the util_queue_add_job2() and just fixup existing callers
>
>  src/gallium/auxiliary/util/u_queue.c            | 6 +++++-
>  src/gallium/auxiliary/util/u_queue.h            | 6 +++++-
>  src/gallium/drivers/radeonsi/si_state_shaders.c | 3 ++-
>  src/gallium/winsys/amdgpu/drm/amdgpu_cs.c       | 2 +-
>  src/gallium/winsys/radeon/drm/radeon_drm_cs.c   | 2 +-
>  5 files changed, 14 insertions(+), 5 deletions(-)
>
> diff --git a/src/gallium/auxiliary/util/u_queue.c b/src/gallium/auxiliary/util/u_queue.c
> index ac3afa1..838464f 100644
> --- a/src/gallium/auxiliary/util/u_queue.c
> +++ b/src/gallium/auxiliary/util/u_queue.c
> @@ -91,6 +91,8 @@ static PIPE_THREAD_ROUTINE(util_queue_thread_func, input)
>        if (job.job) {
>           job.execute(job.job, thread_index);
>           util_queue_fence_signal(job.fence);
> +         if (job.cleanup)
> +            job.cleanup(job.job, thread_index);
>        }
>     }
>
> @@ -213,7 +215,8 @@ void
>  util_queue_add_job(struct util_queue *queue,
>                     void *job,
>                     struct util_queue_fence *fence,
> -                   util_queue_execute_func execute)
> +                   util_queue_execute_func execute,
> +                   util_queue_execute_func cleanup)
>  {
>     struct util_queue_job *ptr;
>
> @@ -232,6 +235,7 @@ util_queue_add_job(struct util_queue *queue,
>     ptr->job = job;
>     ptr->fence = fence;
>     ptr->execute = execute;
> +   ptr->cleanup = cleanup;
>     queue->write_idx = (queue->write_idx + 1) % queue->max_jobs;
>
>     queue->num_queued++;
> diff --git a/src/gallium/auxiliary/util/u_queue.h b/src/gallium/auxiliary/util/u_queue.h
> index f70d646..59646cc 100644
> --- a/src/gallium/auxiliary/util/u_queue.h
> +++ b/src/gallium/auxiliary/util/u_queue.h
> @@ -50,6 +50,7 @@ struct util_queue_job {
>     void *job;
>     struct util_queue_fence *fence;
>     util_queue_execute_func execute;
> +   util_queue_execute_func cleanup;
>  };
>
>  /* Put this into your context. */
> @@ -75,10 +76,13 @@ void util_queue_destroy(struct util_queue *queue);
>  void util_queue_fence_init(struct util_queue_fence *fence);
>  void util_queue_fence_destroy(struct util_queue_fence *fence);
>
> +/* optional cleanup callback is called after fence is signaled: */
>  void util_queue_add_job(struct util_queue *queue,
>                          void *job,
>                          struct util_queue_fence *fence,
> -                        util_queue_execute_func execute);
> +                        util_queue_execute_func execute,
> +                        util_queue_execute_func cleanup);
> +
>  void util_queue_job_wait(struct util_queue_fence *fence);
>
>  /* util_queue needs to be cleared to zeroes for this to work */
> diff --git a/src/gallium/drivers/radeonsi/si_state_shaders.c b/src/gallium/drivers/radeonsi/si_state_shaders.c
> index c24130d..a423296 100644
> --- a/src/gallium/drivers/radeonsi/si_state_shaders.c
> +++ b/src/gallium/drivers/radeonsi/si_state_shaders.c
> @@ -1330,7 +1330,8 @@ static void *si_create_shader_selector(struct pipe_context *ctx,
>                 si_init_shader_selector_async(sel, -1);
>         else
>                 util_queue_add_job(&sscreen->shader_compiler_queue, sel,
> -                                   &sel->ready, si_init_shader_selector_async);
> +                                   &sel->ready, si_init_shader_selector_async,
> +                                   NULL);
>
>         return sel;
>  }
> diff --git a/src/gallium/winsys/amdgpu/drm/amdgpu_cs.c b/src/gallium/winsys/amdgpu/drm/amdgpu_cs.c
> index 1302f29..75bbfeb 100644
> --- a/src/gallium/winsys/amdgpu/drm/amdgpu_cs.c
> +++ b/src/gallium/winsys/amdgpu/drm/amdgpu_cs.c
> @@ -1054,7 +1054,7 @@ static void amdgpu_cs_flush(struct radeon_winsys_cs *rcs,
>        if ((flags & RADEON_FLUSH_ASYNC) &&
>            util_queue_is_initialized(&ws->cs_queue)) {
>           util_queue_add_job(&ws->cs_queue, cs, &cs->flush_completed,
> -                            amdgpu_cs_submit_ib);
> +                            amdgpu_cs_submit_ib, NULL);
>        } else {
>           amdgpu_cs_submit_ib(cs, 0);
>        }
> diff --git a/src/gallium/winsys/radeon/drm/radeon_drm_cs.c b/src/gallium/winsys/radeon/drm/radeon_drm_cs.c
> index ed34a2c..8dc8b04 100644
> --- a/src/gallium/winsys/radeon/drm/radeon_drm_cs.c
> +++ b/src/gallium/winsys/radeon/drm/radeon_drm_cs.c
> @@ -587,7 +587,7 @@ static void radeon_drm_cs_flush(struct radeon_winsys_cs *rcs,
>
>          if (util_queue_is_initialized(&cs->ws->cs_queue)) {
>              util_queue_add_job(&cs->ws->cs_queue, cs, &cs->flush_completed,
> -                               radeon_drm_cs_emit_ioctl_oneshot);
> +                               radeon_drm_cs_emit_ioctl_oneshot, NULL);
>              if (!(flags & RADEON_FLUSH_ASYNC))
>                  radeon_drm_cs_sync_flush(rcs);
>          } else {
> --
> 2.7.4
>


More information about the mesa-dev mailing list