[Mesa-dev] [PATCH] r600g: Use new kernel interface to wait for fences

Michel Dänzer michel at daenzer.net
Tue Jan 31 09:56:59 PST 2012


On Die, 2012-01-31 at 17:02 +0000, Simon Farnsworth wrote: 
> Instead of busywaiting for the GPU to finish a fence, use the new kernel
> interface to wait for fence completion.
> 
> If the new kernel interface is unavailable, fall back to busywaiting.
> 
> Signed-off-by: Simon Farnsworth <simon.farnsworth at onelan.co.uk>
[...] 
> diff --git a/src/gallium/drivers/r600/r600_pipe.c b/src/gallium/drivers/r600/r600_pipe.c
> index c38fbc5..12c5bf5 100644
> --- a/src/gallium/drivers/r600/r600_pipe.c
> +++ b/src/gallium/drivers/r600/r600_pipe.c
> @@ -605,13 +604,10 @@ static boolean r600_fence_finish(struct pipe_screen *pscreen,
>  	}
>  
>  	while (rscreen->fences.data[rfence->index] == 0) {
> -		if (++spins % 256)
> -			continue;
> -#ifdef PIPE_OS_UNIX
> -		sched_yield();
> -#else
> -		os_time_sleep(10);
> -#endif
> +		rscreen->ws->buffer_wait_fence(rscreen->fences.bo->buf,
> +					       rfence->index << 2,
> +					       0,
> +					       timeout);
>  		if (timeout != PIPE_TIMEOUT_INFINITE &&
>  		    os_time_get() - start_time >= timeout) {
>  			return FALSE;

Maybe add something like

if (rscreen->fences.data[rfence->index])
return TRUE;

before the timeout check? Otherwise there may be a false negative if the
fence signalled just before the timeout.


> diff --git a/src/gallium/winsys/radeon/drm/radeon_drm_bo.c b/src/gallium/winsys/radeon/drm/radeon_drm_bo.c
> index 143dcf9..487fc58 100644
> --- a/src/gallium/winsys/radeon/drm/radeon_drm_bo.c
> +++ b/src/gallium/winsys/radeon/drm/radeon_drm_bo.c
> @@ -892,4 +922,9 @@ void radeon_bomgr_init_functions(struct radeon_drm_winsys *ws)
>      ws->base.buffer_from_handle = radeon_winsys_bo_from_handle;
>      ws->base.buffer_get_handle = radeon_winsys_bo_get_handle;
>      ws->base.buffer_get_virtual_address = radeon_winsys_bo_va;
> +    if (ws->info.drm_major > 2 ||
> +        (ws->info.drm_major == 2 && ws->info.drm_minor >= 15))
> +        ws->base.buffer_wait_fence = radeon_winsys_bo_wait_fence;
> +    else
> +        ws->base.buffer_wait_fence = radeon_winsys_bo_wait_fence_nokernel;
>  }

We have no idea what kind of API a hypothetical major version > 2 might
have, so I think it's better to only check for (ws->info.drm_minor >=
15) here.


The rest looks good to me.


-- 
Earthling Michel Dänzer           |                   http://www.amd.com
Libre software enthusiast         |          Debian, X and DRI developer


More information about the mesa-dev mailing list