drm/radeon: simplify semaphore handling v2
authorJerome Glisse <jglisse@redhat.com>
Wed, 9 May 2012 13:34:57 +0000 (15:34 +0200)
committerDave Airlie <airlied@redhat.com>
Wed, 9 May 2012 16:22:40 +0000 (17:22 +0100)
Directly use the suballocator to get small chunks of memory.
It's equally fast and doesn't crash when we encounter a GPU reset.

v2: rebased on new SA interface.

Signed-off-by: Christian König <deathsimple@vodafone.de>
Signed-off-by: Jerome Glisse <jglisse@redhat.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
drivers/gpu/drm/radeon/evergreen.c
drivers/gpu/drm/radeon/ni.c
drivers/gpu/drm/radeon/r600.c
drivers/gpu/drm/radeon/radeon.h
drivers/gpu/drm/radeon/radeon_device.c
drivers/gpu/drm/radeon/radeon_fence.c
drivers/gpu/drm/radeon/radeon_semaphore.c
drivers/gpu/drm/radeon/radeon_test.c
drivers/gpu/drm/radeon/rv770.c
drivers/gpu/drm/radeon/si.c

index ecc29bc1cbe3efaa890837816fe033e799e192c8..7e7ac3d6e76e072a67fe0c6900f459e2a748e67d 100644 (file)
@@ -3550,7 +3550,6 @@ void evergreen_fini(struct radeon_device *rdev)
        evergreen_pcie_gart_fini(rdev);
        r600_vram_scratch_fini(rdev);
        radeon_gem_fini(rdev);
-       radeon_semaphore_driver_fini(rdev);
        radeon_fence_driver_fini(rdev);
        radeon_agp_fini(rdev);
        radeon_bo_fini(rdev);
index 9cd2657eb2cab84bb413393581c5479e71c42917..107b2177e6c5a44bcbc390f989c98e1565d7aecc 100644 (file)
@@ -1744,7 +1744,6 @@ void cayman_fini(struct radeon_device *rdev)
        cayman_pcie_gart_fini(rdev);
        r600_vram_scratch_fini(rdev);
        radeon_gem_fini(rdev);
-       radeon_semaphore_driver_fini(rdev);
        radeon_fence_driver_fini(rdev);
        radeon_bo_fini(rdev);
        radeon_atombios_fini(rdev);
index d02f13fdaa66c48dccb52b1c8c34abd60db86410..478b51ea4d87e1fb836a01bf09ea0f85955f4f64 100644 (file)
@@ -2658,7 +2658,6 @@ void r600_fini(struct radeon_device *rdev)
        r600_vram_scratch_fini(rdev);
        radeon_agp_fini(rdev);
        radeon_gem_fini(rdev);
-       radeon_semaphore_driver_fini(rdev);
        radeon_fence_driver_fini(rdev);
        radeon_bo_fini(rdev);
        radeon_atombios_fini(rdev);
index cc7f16ab257fab6da12af5fa9ea5c85d010a84a3..45164e101257e696974740bce460f89c75a53352 100644 (file)
@@ -434,34 +434,13 @@ int radeon_mode_dumb_destroy(struct drm_file *file_priv,
 /*
  * 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;
+       struct radeon_sa_bo             *sa_bo;
+       signed                          waiters;
        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,
@@ -473,7 +452,8 @@ int radeon_semaphore_sync_rings(struct radeon_device *rdev,
                                bool sync_to[RADEON_NUM_RINGS],
                                int dst_ring);
 void radeon_semaphore_free(struct radeon_device *rdev,
-                          struct radeon_semaphore *semaphore);
+                          struct radeon_semaphore *semaphore,
+                          struct radeon_fence *fence);
 
 /*
  * GART structures, functions & helpers
@@ -1540,7 +1520,6 @@ struct radeon_device {
        struct radeon_mman              mman;
        struct radeon_fence_driver      fence_drv[RADEON_NUM_RINGS];
        wait_queue_head_t               fence_queue;
-       struct radeon_semaphore_driver  semaphore_drv;
        struct mutex                    ring_lock;
        struct radeon_ring              ring[RADEON_NUM_RINGS];
        struct radeon_ib_pool           ib_pool;
index b827b2e578f3971d3ba331b9701e76b4502a2e6f..48876c11a4a9e2324c9d9b6b1ef20020576a6669 100644 (file)
@@ -732,11 +732,9 @@ int radeon_device_init(struct radeon_device *rdev,
        mutex_init(&rdev->gem.mutex);
        mutex_init(&rdev->pm.mutex);
        mutex_init(&rdev->vram_mutex);
-       rwlock_init(&rdev->semaphore_drv.lock);
        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.bo);
        /* initialize vm here */
        rdev->vm_manager.use_bitmap = 1;
        rdev->vm_manager.max_pfn = 1 << 20;
index 14dbc287cac7835d4b784e4db0c001c44fa6a968..3a49311fc711ce77d43408f4f964a08f77230d74 100644 (file)
@@ -140,7 +140,7 @@ static void radeon_fence_destroy(struct kref *kref)
        fence = container_of(kref, struct radeon_fence, kref);
        fence->seq = RADEON_FENCE_NOTEMITED_SEQ;
        if (fence->semaphore)
-               radeon_semaphore_free(fence->rdev, fence->semaphore);
+               radeon_semaphore_free(fence->rdev, fence->semaphore, NULL);
        kfree(fence);
 }
 
index dbde874b2e5e537257f7de8fb12f99afcfc1d097..1bc5513a529219acc47fcddb45a704f7b6c7e545 100644 (file)
 #include "drm.h"
 #include "radeon.h"
 
-static int radeon_semaphore_add_bo(struct radeon_device *rdev)
-{
-       struct radeon_semaphore_bo *bo;
-       unsigned long irq_flags;
-       uint64_t gpu_addr;
-       uint32_t *cpu_ptr;
-       int r, i;
-
-       bo = kmalloc(sizeof(struct radeon_semaphore_bo), GFP_KERNEL);
-       if (bo == NULL) {
-               return -ENOMEM;
-       }
-       INIT_LIST_HEAD(&bo->free);
-       INIT_LIST_HEAD(&bo->list);
-       bo->nused = 0;
-
-       r = radeon_ib_get(rdev, 0, &bo->ib, RADEON_SEMAPHORE_BO_SIZE);
-       if (r) {
-               dev_err(rdev->dev, "failed to get a bo after 5 retry\n");
-               kfree(bo);
-               return r;
-       }
-       gpu_addr = radeon_sa_bo_gpu_addr(bo->ib->sa_bo);
-       cpu_ptr = radeon_sa_bo_cpu_addr(bo->ib->sa_bo);
-       for (i = 0; i < (RADEON_SEMAPHORE_BO_SIZE/8); i++) {
-               bo->semaphores[i].gpu_addr = gpu_addr;
-               bo->semaphores[i].cpu_ptr = cpu_ptr;
-               bo->semaphores[i].bo = bo;
-               list_add_tail(&bo->semaphores[i].list, &bo->free);
-               gpu_addr += 8;
-               cpu_ptr += 2;
-       }
-       write_lock_irqsave(&rdev->semaphore_drv.lock, irq_flags);
-       list_add_tail(&bo->list, &rdev->semaphore_drv.bo);
-       write_unlock_irqrestore(&rdev->semaphore_drv.lock, irq_flags);
-       return 0;
-}
-
-static void radeon_semaphore_del_bo_locked(struct radeon_device *rdev,
-                                          struct radeon_semaphore_bo *bo)
-{
-       radeon_sa_bo_free(rdev, &bo->ib->sa_bo, NULL);
-       radeon_fence_unref(&bo->ib->fence);
-       list_del(&bo->list);
-       kfree(bo);
-}
-
-void radeon_semaphore_shrink_locked(struct radeon_device *rdev)
-{
-       struct radeon_semaphore_bo *bo, *n;
-
-       if (list_empty(&rdev->semaphore_drv.bo)) {
-               return;
-       }
-       /* only shrink if first bo has free semaphore */
-       bo = list_first_entry(&rdev->semaphore_drv.bo, struct radeon_semaphore_bo, list);
-       if (list_empty(&bo->free)) {
-               return;
-       }
-       list_for_each_entry_safe_continue(bo, n, &rdev->semaphore_drv.bo, list) {
-               if (bo->nused)
-                       continue;
-               radeon_semaphore_del_bo_locked(rdev, bo);
-       }
-}
 
 int radeon_semaphore_create(struct radeon_device *rdev,
                            struct radeon_semaphore **semaphore)
 {
-       struct radeon_semaphore_bo *bo;
-       unsigned long irq_flags;
-       bool do_retry = true;
        int r;
 
-retry:
-       *semaphore = NULL;
-       write_lock_irqsave(&rdev->semaphore_drv.lock, irq_flags);
-       list_for_each_entry(bo, &rdev->semaphore_drv.bo, list) {
-               if (list_empty(&bo->free))
-                       continue;
-               *semaphore = list_first_entry(&bo->free, struct radeon_semaphore, list);
-               (*semaphore)->cpu_ptr[0] = 0;
-               (*semaphore)->cpu_ptr[1] = 0;
-               list_del(&(*semaphore)->list);
-               bo->nused++;
-               break;
-       }
-       write_unlock_irqrestore(&rdev->semaphore_drv.lock, irq_flags);
-
+       *semaphore = kmalloc(sizeof(struct radeon_semaphore), GFP_KERNEL);
        if (*semaphore == NULL) {
-               if (do_retry) {
-                       do_retry = false;
-                       r = radeon_semaphore_add_bo(rdev);
-                       if (r)
-                               return r;
-                       goto retry;
-               }
                return -ENOMEM;
        }
-
+       r = radeon_sa_bo_new(rdev, &rdev->ib_pool.sa_manager,
+                            &(*semaphore)->sa_bo, 8, 8, true);
+       if (r) {
+               kfree(*semaphore);
+               *semaphore = NULL;
+               return r;
+       }
+       (*semaphore)->waiters = 0;
+       (*semaphore)->gpu_addr = radeon_sa_bo_gpu_addr((*semaphore)->sa_bo);
+       *((uint64_t*)radeon_sa_bo_cpu_addr((*semaphore)->sa_bo)) = 0;
        return 0;
 }
 
 void radeon_semaphore_emit_signal(struct radeon_device *rdev, int ring,
                                  struct radeon_semaphore *semaphore)
 {
+       --semaphore->waiters;
        radeon_semaphore_ring_emit(rdev, ring, &rdev->ring[ring], semaphore, false);
 }
 
 void radeon_semaphore_emit_wait(struct radeon_device *rdev, int ring,
                                struct radeon_semaphore *semaphore)
 {
+       ++semaphore->waiters;
        radeon_semaphore_ring_emit(rdev, ring, &rdev->ring[ring], semaphore, true);
 }
 
@@ -200,29 +122,16 @@ error:
 }
 
 void radeon_semaphore_free(struct radeon_device *rdev,
-                          struct radeon_semaphore *semaphore)
+                          struct radeon_semaphore *semaphore,
+                          struct radeon_fence *fence)
 {
-       unsigned long irq_flags;
-
-       write_lock_irqsave(&rdev->semaphore_drv.lock, irq_flags);
-       semaphore->bo->nused--;
-       list_add_tail(&semaphore->list, &semaphore->bo->free);
-       radeon_semaphore_shrink_locked(rdev);
-       write_unlock_irqrestore(&rdev->semaphore_drv.lock, irq_flags);
-}
-
-void radeon_semaphore_driver_fini(struct radeon_device *rdev)
-{
-       struct radeon_semaphore_bo *bo, *n;
-       unsigned long irq_flags;
-
-       write_lock_irqsave(&rdev->semaphore_drv.lock, irq_flags);
-       /* we force to free everything */
-       list_for_each_entry_safe(bo, n, &rdev->semaphore_drv.bo, list) {
-               if (!list_empty(&bo->free)) {
-                       dev_err(rdev->dev, "still in use semaphore\n");
-               }
-               radeon_semaphore_del_bo_locked(rdev, bo);
+       if (semaphore == NULL) {
+               return;
+       }
+       if (semaphore->waiters > 0) {
+               dev_err(rdev->dev, "semaphore %p has more waiters than signalers,"
+                       " hardware lockup imminent!\n", semaphore);
        }
-       write_unlock_irqrestore(&rdev->semaphore_drv.lock, irq_flags);
+       radeon_sa_bo_free(rdev, &semaphore->sa_bo, fence);
+       kfree(semaphore);
 }
index dc5dcf483aa3c0217c85a2db318ac07542754dde..b05738762790504c4495ce39ab664892a7e77498 100644 (file)
@@ -317,7 +317,7 @@ void radeon_test_ring_sync(struct radeon_device *rdev,
 
 out_cleanup:
        if (semaphore)
-               radeon_semaphore_free(rdev, semaphore);
+               radeon_semaphore_free(rdev, semaphore, NULL);
 
        if (fence1)
                radeon_fence_unref(&fence1);
@@ -437,7 +437,7 @@ void radeon_test_ring_sync2(struct radeon_device *rdev,
 
 out_cleanup:
        if (semaphore)
-               radeon_semaphore_free(rdev, semaphore);
+               radeon_semaphore_free(rdev, semaphore, NULL);
 
        if (fenceA)
                radeon_fence_unref(&fenceA);
index a8b001641e4bd85997ef1b23dbf9e03d8072ea5b..40f82e22a621325fa26d76d4aa635b27cdd7b0bb 100644 (file)
@@ -1278,7 +1278,6 @@ void rv770_fini(struct radeon_device *rdev)
        rv770_pcie_gart_fini(rdev);
        r600_vram_scratch_fini(rdev);
        radeon_gem_fini(rdev);
-       radeon_semaphore_driver_fini(rdev);
        radeon_fence_driver_fini(rdev);
        radeon_agp_fini(rdev);
        radeon_bo_fini(rdev);
index 779f0b604fadf5b724af31db8db6e860b12bf862..be3b9fd6c931b0ca4234757a73c473114b8b23db 100644 (file)
@@ -4109,7 +4109,6 @@ void si_fini(struct radeon_device *rdev)
        si_pcie_gart_fini(rdev);
        r600_vram_scratch_fini(rdev);
        radeon_gem_fini(rdev);
-       radeon_semaphore_driver_fini(rdev);
        radeon_fence_driver_fini(rdev);
        radeon_bo_fini(rdev);
        radeon_atombios_fini(rdev);