drm/nouveau/gem: attach fences to VMAs to track GPU usage
authorBen Skeggs <bskeggs@redhat.com>
Tue, 8 May 2018 10:39:47 +0000 (20:39 +1000)
committerBen Skeggs <bskeggs@redhat.com>
Fri, 18 May 2018 05:01:26 +0000 (15:01 +1000)
An upcoming patch will use these to fix issues related to the deferred
unmapping of GEM objects.

Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
drivers/gpu/drm/nouveau/nouveau_gem.c
drivers/gpu/drm/nouveau/nouveau_vmm.c
drivers/gpu/drm/nouveau/nouveau_vmm.h

index 707e02c80f1826dd01ab674264b9f03e635ffd5d..2016d9eb338e160a49e16cacd58a9854172b9c4c 100644 (file)
@@ -99,6 +99,7 @@ struct nouveau_gem_object_unmap {
 static void
 nouveau_gem_object_delete(struct nouveau_vma *vma)
 {
+       nouveau_fence_unref(&vma->fence);
        nouveau_vma_del(&vma);
 }
 
@@ -344,9 +345,20 @@ validate_fini_no_ticket(struct validate_op *op, struct nouveau_fence *fence,
                nvbo = list_entry(op->list.next, struct nouveau_bo, entry);
                b = &pbbo[nvbo->pbbo_index];
 
-               if (likely(fence))
+               if (likely(fence)) {
+                       struct nouveau_drm *drm = nouveau_bdev(nvbo->bo.bdev);
+                       struct nouveau_vma *vma;
+
                        nouveau_bo_fence(nvbo, fence, !!b->write_domains);
 
+                       if (drm->client.vmm.vmm.object.oclass >= NVIF_CLASS_VMM_NV50) {
+                               vma = (void *)(unsigned long)b->user_priv;
+                               nouveau_fence_unref(&vma->fence);
+                               dma_fence_get(&fence->base);
+                               vma->fence = fence;
+                       }
+               }
+
                if (unlikely(nvbo->validate_mapped)) {
                        ttm_bo_kunmap(&nvbo->kmap);
                        nvbo->validate_mapped = false;
index f5371d96b003c23cac9e1f34cf3deca3b54b06a6..2032c3e4f6e5d879219593b139fcc4152f44a8b1 100644 (file)
@@ -92,6 +92,7 @@ nouveau_vma_new(struct nouveau_bo *nvbo, struct nouveau_vmm *vmm,
        vma->refs = 1;
        vma->addr = ~0ULL;
        vma->mem = NULL;
+       vma->fence = NULL;
        list_add_tail(&vma->head, &nvbo->vma_list);
 
        if (nvbo->bo.mem.mem_type != TTM_PL_SYSTEM &&
index 5c31f43678d3f912d995a1be812f3603692a37df..7e3b118cf7c4da6016874aac0c2f2d653db72398 100644 (file)
@@ -11,6 +11,8 @@ struct nouveau_vma {
        u64 addr;
 
        struct nouveau_mem *mem;
+
+       struct nouveau_fence *fence;
 };
 
 struct nouveau_vma *nouveau_vma_find(struct nouveau_bo *, struct nouveau_vmm *);