Make ib allocation size function of cs size
Subsystems (2)
Two following patch are on top of
http://cgit.freedesktop.org/~glisse/linux
They make the ib allocation size a function of the cs size, this allow to avoid wasting pool space and avoid to trigger fence_wait in ib_get. I am still evaluating how much fence_wait we avoid with this.
Cheers,
Jerome
PATCH 1/2 drm/radeon: make ib size variable
From: Jerome Glisse <[email protected]>
This avoid to waste ib pool size and avoid a bunch of wait for previous ib to finish.
--- drivers/gpu/drm/radeon/r100.c | 2 +- drivers/gpu/drm/radeon/r600.c | 2 +- drivers/gpu/drm/radeon/r600_blit_kms.c | 16 +++++++++------- drivers/gpu/drm/radeon/radeon.h | 3 ++- drivers/gpu/drm/radeon/radeon_cs.c | 6 ++++-- drivers/gpu/drm/radeon/radeon_ring.c | 7 +++++-- 6 files changed, 22 insertions(+), 14 deletions(-)
drivers/gpu/drm/radeon/r100.c +1 -1
@@ -3708,7 +3708,7 @@ int r100_ib_test(struct radeon_device *rdev)return r; }WREG32 (scratch,0xCAFEDEAD ); - r =radeon_ib_get (rdev,RADEON_RING_TYPE_GFX_INDEX , &ib); + r =radeon_ib_get (rdev,RADEON_RING_TYPE_GFX_INDEX , &ib,256 );if (r) {return r; }
drivers/gpu/drm/radeon/r600.c +1 -1
@@ -2711,7 +2711,7 @@ int r600_ib_test(struct radeon_device *rdev, int ring)return r; }WREG32 (scratch,0xCAFEDEAD ); - r =radeon_ib_get (rdev, ring, &ib); + r =radeon_ib_get (rdev, ring, &ib,256 );if (r) {DRM_ERROR ("radeon: failed to get ib (%d).\n" , r);return r;
drivers/gpu/drm/radeon/r600_blit_kms.c +9 -7
@@ -619,16 +619,17 @@ void r600_blit_fini(struct radeon_device *rdev)radeon_bo_unref (&rdev->r600_blit.shader_obj); } -static int r600_vb_ib_get (struct radeon_device *rdev) +static int r600_vb_ib_get (struct radeon_device *rdev,unsigned size) {int r; - r =radeon_ib_get (rdev,RADEON_RING_TYPE_GFX_INDEX , &rdev->r600_blit.vb_ib); + r =radeon_ib_get (rdev,RADEON_RING_TYPE_GFX_INDEX , + &rdev->r600_blit.vb_ib, size);if (r) {DRM_ERROR ("failed to get IB for vertex buffer\n" );return r; } - rdev->r600_blit.vb_total =64 *1024 ; + rdev->r600_blit.vb_total = size; rdev->r600_blit.vb_used =0 ;return 0 ; }
@@ -693,10 +694,6 @@ int r600_blit_prepare_copy(struct radeon_device *rdev, unsigned num_gpu_pages)int num_loops =0 ;int dwords_per_loop = rdev->r600_blit.ring_size_per_loop; - r =r600_vb_ib_get (rdev); -if (r) -return r; -/* num loops */ while (num_gpu_pages) { num_gpu_pages -=
@@ -705,6 +702,11 @@ int r600_blit_prepare_copy(struct radeon_device *rdev, unsigned num_gpu_pages) num_loops++; } +/* 48 bytes for vertex per loop */ + r =r600_vb_ib_get (rdev, (num_loops*48 )+256 ); +if (r) +return r; +/* calculate number of loops correctly */ ring_size = num_loops * dwords_per_loop; ring_size += rdev->r600_blit.ring_size_common;
drivers/gpu/drm/radeon/radeon.h +2 -1
@@ -713,7 +713,8 @@ struct r600_blit {void r600_blit_suspend (struct radeon_device *rdev); -int radeon_ib_get (struct radeon_device *rdev,int ring,struct radeon_ib **ib); +int radeon_ib_get (struct radeon_device *rdev,int ring, +struct radeon_ib **ib,unsigned size);void radeon_ib_free (struct radeon_device *rdev,struct radeon_ib **ib);int radeon_ib_schedule (struct radeon_device *rdev,struct radeon_ib *ib);int radeon_ib_pool_init (struct radeon_device *rdev);
drivers/gpu/drm/radeon/radeon_cs.c +4 -2
@@ -288,7 +288,8 @@ static int radeon_cs_ib_chunk(struct radeon_device *rdev,* input memory (cached) and write to the IB (which can be * uncached). */ - r =radeon_ib_get (rdev, parser->ring, &parser->ib); + r =radeon_ib_get (rdev, parser->ring, &parser->ib, + ib_chunk->length_dw *4 );if (r) {DRM_ERROR ("Failed to get ib !\n" );return r;
@@ -348,7 +349,8 @@ static int radeon_cs_ib_vm_chunk(struct radeon_device *rdev,DRM_ERROR ("cs IB too big: %d\n" , ib_chunk->length_dw);return -EINVAL ; } - r =radeon_ib_get (rdev, parser->ring, &parser->ib); + r =radeon_ib_get (rdev, parser->ring, &parser->ib, + ib_chunk->length_dw *4 );if (r) {DRM_ERROR ("Failed to get ib !\n" );return r;
drivers/gpu/drm/radeon/radeon_ring.c +5 -2
@@ -93,13 +93,16 @@ static bool radeon_ib_try_free(struct radeon_device *rdev,return done; } -int radeon_ib_get (struct radeon_device *rdev,int ring,struct radeon_ib **ib) +int radeon_ib_get (struct radeon_device *rdev,int ring, +struct radeon_ib **ib,unsigned size) {struct radeon_fence *fence;unsigned cretry =0 ;int r =0 , i, idx; *ib =NULL ; +/* align size on 256 bytes */ + size =ALIGN (size,256 ); r =radeon_fence_create (rdev, &fence, ring);if (r) {
@@ -121,7 +124,7 @@ retry:if (rdev->ib_pool.ibs[idx].fence ==NULL ) { r =radeon_sa_bo_new (rdev, &rdev->ib_pool.sa_manager, &rdev->ib_pool.ibs[idx].sa_bo, -64 *1024 ,64 ); + size,256 );if (!r) { *ib = &rdev->ib_pool.ibs[idx]; (*ib)->ptr = rdev->ib_pool.sa_manager.cpu_ptr;
Signature · 1 line
1.7.7.1
PATCH 2/2 drm/radeon: allocate semaphore from the ib pool
In reply to [email protected]From: Jerome Glisse <[email protected]>
This allow to share the ib pool with semaphore and avoid having more bo around.
--- drivers/gpu/drm/radeon/radeon.h | 67 ++++++++----- drivers/gpu/drm/radeon/radeon_device.c | 2 +- drivers/gpu/drm/radeon/radeon_ring.c | 5 +- drivers/gpu/drm/radeon/radeon_semaphore.c | 157 ++++++++++++++++------------- 4 files changed, 131 insertions(+), 100 deletions(-)
drivers/gpu/drm/radeon/radeon.h +41 -26
@@ -247,32 +247,6 @@ void radeon_fence_unref(struct radeon_fence **fence);int radeon_fence_count_emitted (struct radeon_device *rdev,int ring);/* -* Semaphores. -*/ -struct radeon_ring ; - -struct radeon_semaphore_driver { -rwlock_t lock; -struct list_head free; -}; - -struct radeon_semaphore { -struct radeon_bo *robj; -struct list_head list; -uint64_t gpu_addr; -}; - -void radeon_semaphore_driver_fini (struct radeon_device *rdev); -int radeon_semaphore_create (struct radeon_device *rdev, -struct radeon_semaphore **semaphore); -void radeon_semaphore_emit_signal (struct radeon_device *rdev,int ring, -struct radeon_semaphore *semaphore); -void radeon_semaphore_emit_wait (struct radeon_device *rdev,int ring, -struct radeon_semaphore *semaphore); -void radeon_semaphore_free (struct radeon_device *rdev, -struct radeon_semaphore *semaphore); - -/* * Tiling registers */ struct radeon_surface_reg {
@@ -410,6 +384,46 @@ int radeon_mode_dumb_destroy(struct drm_file *file_priv, uint32_t handle);/* +* Semaphores. +*/ +struct radeon_ring ; + +#define RADEON_SEMAPHORE_BO_SIZE 256 + +struct radeon_semaphore_driver { +rwlock_t lock; +struct list_head bo; +}; + +struct radeon_semaphore_bo ; + +/* everything here is constant */ +struct radeon_semaphore { +struct list_head list; +uint64_t gpu_addr; +uint32_t *cpu_ptr; +struct radeon_semaphore_bo *bo; +}; + +struct radeon_semaphore_bo { +struct list_head list; +struct radeon_ib *ib; +struct list_head free; +struct radeon_semaphore semaphores[RADEON_SEMAPHORE_BO_SIZE /8 ]; +unsigned nused; +}; + +void radeon_semaphore_driver_fini (struct radeon_device *rdev); +int radeon_semaphore_create (struct radeon_device *rdev, +struct radeon_semaphore **semaphore); +void radeon_semaphore_emit_signal (struct radeon_device *rdev,int ring, +struct radeon_semaphore *semaphore); +void radeon_semaphore_emit_wait (struct radeon_device *rdev,int ring, +struct radeon_semaphore *semaphore); +void radeon_semaphore_free (struct radeon_device *rdev, +struct radeon_semaphore *semaphore); + +/* * GART structures, functions & helpers */ struct radeon_mc ;
@@ -716,6 +730,7 @@ void r600_blit_suspend(struct radeon_device *rdev);int radeon_ib_get (struct radeon_device *rdev,int ring,struct radeon_ib **ib,unsigned size);void radeon_ib_free (struct radeon_device *rdev,struct radeon_ib **ib); +bool radeon_ib_try_free (struct radeon_device *rdev,struct radeon_ib *ib);int radeon_ib_schedule (struct radeon_device *rdev,struct radeon_ib *ib);int radeon_ib_pool_init (struct radeon_device *rdev);void radeon_ib_pool_fini (struct radeon_device *rdev);
drivers/gpu/drm/radeon/radeon_device.c +1 -1
@@ -731,7 +731,7 @@ int radeon_device_init(struct radeon_device *rdev,INIT_LIST_HEAD (&rdev->gem.objects);init_waitqueue_head (&rdev->irq.vblank_queue);init_waitqueue_head (&rdev->irq.idle_queue); -INIT_LIST_HEAD (&rdev->semaphore_drv.free); +INIT_LIST_HEAD (&rdev->semaphore_drv.bo);/* initialize vm here */ rdev->vm_manager.use_bitmap =1 ; rdev->vm_manager.max_pfn =1 <<20 ;
drivers/gpu/drm/radeon/radeon_ring.c +2 -3
@@ -77,8 +77,7 @@ void radeon_ring_write(struct radeon_ring *ring, uint32_t v)/* * IB. */ -static bool radeon_ib_try_free (struct radeon_device *rdev, -struct radeon_ib *ib) +bool radeon_ib_try_free (struct radeon_device *rdev,struct radeon_ib *ib) {bool done = false;
@@ -148,7 +147,7 @@ retry:/* this should be rare event, ie all ib scheduled none signaled yet. */ for (i =0 ; i <RADEON_IB_POOL_SIZE ; i++) { -if (rdev->ib_pool.ibs[idx].fence) { +if (rdev->ib_pool.ibs[idx].fence && rdev->ib_pool.ibs[idx].fence->emitted) { r =radeon_fence_wait (rdev->ib_pool.ibs[idx].fence, false);if (!r) { goto retry;
drivers/gpu/drm/radeon/radeon_semaphore.c +87 -70
208 lines not on this page · raw message
Signature · 1 line
1.7.7.1
Alex Deucher
Reviewed-byQuoted 7 lines · On Mon, Dec 5, 2011 at 6:39 PM, <[email protected]> wrote:
Two following patch are on top of
http://cgit.freedesktop.org/~glisse/linuxThey make the ib allocation size a function of the cs size, this allow to avoid wasting pool space and avoid to trigger
fence_waitinib_get. I am still evaluating how muchfence_waitwe avoid with this.
Both patches are lightly tested and
Quoted 9 lines
Cheers,
Jerome_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel