From: Rob Clark Date: Wed, 1 Jun 2016 20:11:52 +0000 (-0400) Subject: freedreno/msm: use private bo-cache for ringbuffer bo's X-Git-Tag: android-x86-6.0-r1~20 X-Git-Url: http://git.osdn.net/view?p=android-x86%2Fexternal-libdrm.git;a=commitdiff_plain;h=892141a321c7acd32000e145916217eda2da14bb freedreno/msm: use private bo-cache for ringbuffer bo's Since they get vmap'd on the kernel side, they are a bit more costly. Don't let them mingle with the riffraff. Signed-off-by: Rob Clark --- diff --git a/freedreno/msm/msm_device.c b/freedreno/msm/msm_device.c index 25c097c2..727baa44 100644 --- a/freedreno/msm/msm_device.c +++ b/freedreno/msm/msm_device.c @@ -39,6 +39,7 @@ static void msm_device_destroy(struct fd_device *dev) { struct msm_device *msm_dev = to_msm_device(dev); + fd_bo_cache_cleanup(&msm_dev->ring_cache, 0); free(msm_dev); } @@ -61,5 +62,7 @@ drm_private struct fd_device * msm_device_new(int fd) dev = &msm_dev->base; dev->funcs = &funcs; + fd_bo_cache_init(&msm_dev->ring_cache, TRUE); + return dev; } diff --git a/freedreno/msm/msm_priv.h b/freedreno/msm/msm_priv.h index e499b3b8..1f44398d 100644 --- a/freedreno/msm/msm_priv.h +++ b/freedreno/msm/msm_priv.h @@ -39,6 +39,7 @@ struct msm_device { struct fd_device base; + struct fd_bo_cache ring_cache; }; static inline struct msm_device * to_msm_device(struct fd_device *x) diff --git a/freedreno/msm/msm_ringbuffer.c b/freedreno/msm/msm_ringbuffer.c index 32ed8b49..66ae1463 100644 --- a/freedreno/msm/msm_ringbuffer.c +++ b/freedreno/msm/msm_ringbuffer.c @@ -65,6 +65,39 @@ struct msm_ringbuffer { }; static pthread_mutex_t idx_lock = PTHREAD_MUTEX_INITIALIZER; +drm_private extern pthread_mutex_t table_lock; + +static void ring_bo_del(struct fd_device *dev, struct fd_bo *bo) +{ + int ret; + + pthread_mutex_lock(&table_lock); + ret = fd_bo_cache_free(&to_msm_device(dev)->ring_cache, bo); + pthread_mutex_unlock(&table_lock); + + if (ret == 0) + return; + + fd_bo_del(bo); +} + +static struct fd_bo * ring_bo_new(struct fd_device *dev, uint32_t size) +{ + struct fd_bo *bo; + + bo = fd_bo_cache_alloc(&to_msm_device(dev)->ring_cache, &size, 0); + if (bo) + return bo; + + bo = fd_bo_new(dev, size, 0); + if (!bo) + return NULL; + + /* keep ringbuffer bo's out of the normal bo cache: */ + bo->bo_reuse = FALSE; + + return bo; +} static void *grow(void *ptr, uint32_t nr, uint32_t *max, uint32_t sz) { @@ -344,7 +377,7 @@ static void msm_ringbuffer_destroy(struct fd_ringbuffer *ring) { struct msm_ringbuffer *msm_ring = to_msm_ringbuffer(ring); if (msm_ring->ring_bo) - fd_bo_del(msm_ring->ring_bo); + ring_bo_del(ring->pipe->dev, msm_ring->ring_bo); free(msm_ring->submit.relocs); free(msm_ring->submit.cmds); free(msm_ring->submit.bos); @@ -377,7 +410,7 @@ drm_private struct fd_ringbuffer * msm_ringbuffer_new(struct fd_pipe *pipe, ring = &msm_ring->base; ring->funcs = &funcs; - msm_ring->ring_bo = fd_bo_new(pipe->dev, size, 0); + msm_ring->ring_bo = ring_bo_new(pipe->dev, size); if (!msm_ring->ring_bo) { ERROR_MSG("ringbuffer allocation failed"); goto fail;