fence: add debugging lines to fence_is_signaled for the callback
Subsystems (8)
PATCH 1/19 fence: add debugging lines to fence_is_signaled for the callback
fence_is_signaled callback should support being run in atomic context, but not in irq context.
--- include/linux/fence.h | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-)
include/linux/fence.h +19 -4
@@ -143,6 +143,7 @@ struct fence_cb {* the second time will be a noop since it was already signaled. * * Notes on signaled: +* Called with interrupts enabled, and never from interrupt context. * May set fence->status if returning true. * * Notes on wait:
@@ -268,15 +269,29 @@ fence_is_signaled_locked(struct fence *fence)static inline bool fence_is_signaled (struct fence *fence) { +bool ret; +if (test_bit (FENCE_FLAG_SIGNALED_BIT , &fence->flags))return true; -if (fence->ops->signaled && fence->ops->signaled (fence)) { +if (!fence->ops->signaled) +return false; + +if (config_enabled (CONFIG_PROVE_LOCKING )) +WARN_ON (in_interrupt () ||irqs_disabled ()); + +if (config_enabled (CONFIG_DEBUG_ATOMIC_SLEEP )) +preempt_disable (); + + ret = fence->ops->signaled (fence); + +if (config_enabled (CONFIG_DEBUG_ATOMIC_SLEEP )) +preempt_enable (); + +if (ret)fence_signal (fence); -return true; - } -return false; +return ret; }/**
PATCH 2/19 drm/ttm: add interruptible parameter to ttm_eu_reserve_buffers
It seems some drivers really want this as a parameter, like vmwgfx.
--- drivers/gpu/drm/qxl/qxl_release.c | 2 +- drivers/gpu/drm/radeon/radeon_object.c | 2 +- drivers/gpu/drm/radeon/radeon_uvd.c | 2 +- drivers/gpu/drm/radeon/radeon_vm.c | 2 +- drivers/gpu/drm/ttm/ttm_execbuf_util.c | 22 +++++++++++++--------- drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c | 7 ++----- drivers/gpu/drm/vmwgfx/vmwgfx_resource.c | 2 +- include/drm/ttm/ttm_execbuf_util.h | 9 +++++---- 8 files changed, 25 insertions(+), 23 deletions(-)
drivers/gpu/drm/qxl/qxl_release.c +1 -1
@@ -159,7 +159,7 @@ int qxl_release_reserve_list(struct qxl_release *release, bool no_intr)if (list_is_singular (&release->bos))return 0 ; - ret =ttm_eu_reserve_buffers (&release->ticket, &release->bos); + ret =ttm_eu_reserve_buffers (&release->ticket, &release->bos, !no_intr);if (ret)return ret;
drivers/gpu/drm/radeon/radeon_object.c +1 -1
@@ -438,7 +438,7 @@ int radeon_bo_list_validate(struct radeon_device *rdev,u64 bytes_moved =0 , initial_bytes_moved;u64 bytes_moved_threshold =radeon_bo_get_threshold_for_moves (rdev); - r =ttm_eu_reserve_buffers (ticket, head); + r =ttm_eu_reserve_buffers (ticket, head, true);if (unlikely (r !=0 )) {return r; }
drivers/gpu/drm/radeon/radeon_uvd.c +1 -1
@@ -620,7 +620,7 @@ static int radeon_uvd_send_msg(struct radeon_device *rdev,INIT_LIST_HEAD (&head);list_add (&tv.head, &head); - r =ttm_eu_reserve_buffers (&ticket, &head); + r =ttm_eu_reserve_buffers (&ticket, &head, true);if (r)return r;
drivers/gpu/drm/radeon/radeon_vm.c +1 -1
@@ -365,7 +365,7 @@ static int radeon_vm_clear_bo(struct radeon_device *rdev,INIT_LIST_HEAD (&head);list_add (&tv.head, &head); - r =ttm_eu_reserve_buffers (&ticket, &head); + r =ttm_eu_reserve_buffers (&ticket, &head, true);if (r)return r;
drivers/gpu/drm/ttm/ttm_execbuf_util.c +13 -9
@@ -112,7 +112,7 @@ EXPORT_SYMBOL(ttm_eu_backoff_reservation);*/ int ttm_eu_reserve_buffers (struct ww_acquire_ctx *ticket, -struct list_head *list) +struct list_head *list,bool intr) {struct ttm_bo_global *glob;struct ttm_validate_buffer *entry;
@@ -140,7 +140,7 @@ retry:if (entry->reserved)continue ; - ret =__ttm_bo_reserve (bo, true, (ticket ==NULL ), true, + ret =__ttm_bo_reserve (bo, intr, (ticket ==NULL ), true, ticket);if (ret == -EDEADLK ) {
@@ -153,13 +153,17 @@ retry:ttm_eu_backoff_reservation_locked (list);spin_unlock (&glob->lru_lock);ttm_eu_list_ref_sub (list); - ret =ww_mutex_lock_slow_interruptible (&bo->resv->lock, - ticket); -if (unlikely (ret !=0 )) { -if (ret == -EINTR ) - ret = -ERESTARTSYS ; - goto err_fini; - } + +if (intr) { + ret =ww_mutex_lock_slow_interruptible (&bo->resv->lock, + ticket); +if (unlikely (ret !=0 )) { +if (ret == -EINTR ) + ret = -ERESTARTSYS ; + goto err_fini; + } + }else +ww_mutex_lock_slow (&bo->resv->lock, ticket); entry->reserved = true;if (unlikely (atomic_read (&bo->cpu_writers) >0 )) {
drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c +2 -5
@@ -2496,7 +2496,7 @@ int vmw_execbuf_process(struct drm_file *file_priv,if (unlikely (ret !=0 )) goto out_err_nores; - ret =ttm_eu_reserve_buffers (&ticket, &sw_context->validate_nodes); + ret =ttm_eu_reserve_buffers (&ticket, &sw_context->validate_nodes, true);if (unlikely (ret !=0 )) goto out_err;
@@ -2684,10 +2684,7 @@ void __vmw_execbuf_release_pinned_bo(struct vmw_private *dev_priv, query_val.bo =ttm_bo_reference (dev_priv->dummy_query_bo);list_add_tail (&query_val.head, &validate_list); -do { - ret =ttm_eu_reserve_buffers (&ticket, &validate_list); - }while (ret == -ERESTARTSYS ); - + ret =ttm_eu_reserve_buffers (&ticket, &validate_list, false);if (unlikely (ret !=0 )) {vmw_execbuf_unpin_panic (dev_priv); goto out_no_reserve;
drivers/gpu/drm/vmwgfx/vmwgfx_resource.c +1 -1
@@ -1215,7 +1215,7 @@ vmw_resource_check_buffer(struct vmw_resource *res,INIT_LIST_HEAD (&val_list); val_buf->bo =ttm_bo_reference (&res->backup->base);list_add_tail (&val_buf->head, &val_list); - ret =ttm_eu_reserve_buffers (NULL , &val_list); + ret =ttm_eu_reserve_buffers (NULL , &val_list, interruptible);if (unlikely (ret !=0 )) goto out_no_reserve;
include/drm/ttm/ttm_execbuf_util.h +5 -4
@@ -73,6 +73,7 @@ extern void ttm_eu_backoff_reservation(struct ww_acquire_ctx *ticket,* @ticket: [out] ww_acquire_ctx filled in by call, or NULL if only * non-blocking reserves should be tried. * @list: thread private list of ttm_validate_buffer structs. +* @intr: should the wait be interruptible * * Tries to reserve bos pointed to by the list entries for validation. * If the function returns 0, all buffers are marked as "unfenced",
@@ -84,9 +85,9 @@ extern void ttm_eu_backoff_reservation(struct ww_acquire_ctx *ticket,* CPU write reservations to be cleared, and for other threads to * unreserve their buffers. * -* This function may return -ERESTART or -EAGAIN if the calling process -* receives a signal while waiting. In that case, no buffers on the list -* will be reserved upon return. +* If intr is set to true, this function may return -ERESTARTSYS if the +* calling process receives a signal while waiting. In that case, no +* buffers on the list will be reserved upon return. * * Buffers reserved by this function should be unreserved by * a call to either ttm_eu_backoff_reservation() or
@@ -95,7 +96,7 @@ extern void ttm_eu_backoff_reservation(struct ww_acquire_ctx *ticket,*/ extern int ttm_eu_reserve_buffers (struct ww_acquire_ctx *ticket, -struct list_head *list); +struct list_head *list,bool intr);/** * function ttm_eu_fence_buffer_objects.
PATCH 3/19 drm/ttm: kill off some members to ttm_validate_buffer
In reply to Maarten LankhorstThis reorders the list to keep track of what buffers are reserved, so previous members are always unreserved.
This gets rid of some bookkeeping that's no longer needed, while simplifying the code some.
--- drivers/gpu/drm/qxl/qxl_release.c | 1 drivers/gpu/drm/ttm/ttm_execbuf_util.c | 142 +++++++++++-------------------- drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c | 1 include/drm/ttm/ttm_execbuf_util.h | 3 - 4 files changed, 50 insertions(+), 97 deletions(-)
drivers/gpu/drm/qxl/qxl_release.c +0 -1
@@ -350,7 +350,6 @@ void qxl_release_fence_buffer_objects(struct qxl_release *release)ttm_bo_add_to_lru (bo);__ttm_bo_unreserve (bo); - entry->reserved = false; }spin_unlock (&bdev->fence_lock);spin_unlock (&glob->lru_lock);
drivers/gpu/drm/ttm/ttm_execbuf_util.c +50 -92
199 lines not on this page · raw message
drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c +0 -1
@@ -346,7 +346,6 @@ static int vmw_bo_to_validate_list(struct vmw_sw_context *sw_context, ++sw_context->cur_val_buf; val_buf = &vval_buf->base; val_buf->bo =ttm_bo_reference (bo); - val_buf->reserved = false;list_add_tail (&val_buf->head, &sw_context->validate_nodes); vval_buf->validate_as_mob = validate_as_mob; }
include/drm/ttm/ttm_execbuf_util.h +0 -3
@@ -48,9 +48,6 @@struct ttm_validate_buffer {struct list_head head;struct ttm_buffer_object *bo; -bool reserved; -bool removed; -int put_count;void *old_sync_obj; };
PATCH 4/19 drm/nouveau: add reservation to nouveau_gem_ioctl_cpu_prep
In reply to Maarten LankhorstApart from some code inside ttm itself and nouveau_bo_vma_del, this is the only place where ttm_bo_wait is used without a reservation. Fix this so we can remove the fence_lock later on.
After the switch to rcu the reservation lock will be removed again.
--- drivers/gpu/drm/nouveau/nouveau_gem.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-)
drivers/gpu/drm/nouveau/nouveau_gem.c +18 -4
@@ -886,17 +886,31 @@ nouveau_gem_ioctl_cpu_prep(struct drm_device *dev, void *data,struct drm_gem_object *gem;struct nouveau_bo *nvbo;bool no_wait = !!(req->flags &NOUVEAU_GEM_CPU_PREP_NOWAIT ); -int ret = -EINVAL ; +int ret; +struct nouveau_fence *fence =NULL ; gem =drm_gem_object_lookup (dev, file_priv, req->handle);if (!gem)return -ENOENT ; nvbo =nouveau_gem_object (gem); -spin_lock (&nvbo->bo.bdev->fence_lock); - ret =ttm_bo_wait (&nvbo->bo, true, true, no_wait); -spin_unlock (&nvbo->bo.bdev->fence_lock); + ret =ttm_bo_reserve (&nvbo->bo, true, false, false,0 ); +if (!ret) { +spin_lock (&nvbo->bo.bdev->fence_lock); + ret =ttm_bo_wait (&nvbo->bo, true, true, true); +if (!no_wait && ret) + fence =nouveau_fence_ref (nvbo->bo.sync_obj); +spin_unlock (&nvbo->bo.bdev->fence_lock); + +ttm_bo_unreserve (&nvbo->bo); + }drm_gem_object_unreference_unlocked (gem); + +if (fence) { + ret =nouveau_fence_wait (fence, true, no_wait); +nouveau_fence_unref (&fence); + } +return ret; }
PATCH 5/19 drm/nouveau: require reservations for nouveau_fence_sync and nouveau_bo_fence
In reply to Maarten LankhorstThis will ensure we always hold the required lock when calling those functions.
--- drivers/gpu/drm/nouveau/nouveau_bo.c | 2 ++ drivers/gpu/drm/nouveau/nouveau_display.c | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-)
drivers/gpu/drm/nouveau/nouveau_bo.c +2 -0
@@ -1431,6 +1431,8 @@ nouveau_bo_fence(struct nouveau_bo *nvbo, struct nouveau_fence *fence)struct nouveau_fence *new_fence =nouveau_fence_ref (fence);struct nouveau_fence *old_fence =NULL ; +lockdep_assert_held (&nvbo->bo.resv->lock.base); +spin_lock (&nvbo->bo.bdev->fence_lock); old_fence = nvbo->bo.sync_obj; nvbo->bo.sync_obj = new_fence;
drivers/gpu/drm/nouveau/nouveau_display.c +13 -4
@@ -716,6 +716,9 @@ nouveau_crtc_page_flip(struct drm_crtc *crtc, struct drm_framebuffer *fb, }mutex_lock (&chan->cli->mutex); + ret =ttm_bo_reserve (&new_bo->bo, true, false, false,NULL ); +if (ret) + goto fail_unpin;/* synchronise rendering channel with the kernel's channel */ spin_lock (&new_bo->bo.bdev->fence_lock);
@@ -723,12 +726,18 @@ nouveau_crtc_page_flip(struct drm_crtc *crtc, struct drm_framebuffer *fb,spin_unlock (&new_bo->bo.bdev->fence_lock); ret =nouveau_fence_sync (fence, chan);nouveau_fence_unref (&fence); -if (ret) +if (ret) { +ttm_bo_unreserve (&new_bo->bo); goto fail_unpin; + } - ret =ttm_bo_reserve (&old_bo->bo, true, false, false,NULL ); -if (ret) - goto fail_unpin; +if (new_bo != old_bo) { +ttm_bo_unreserve (&new_bo->bo); + + ret =ttm_bo_reserve (&old_bo->bo, true, false, false,NULL ); +if (ret) + goto fail_unpin; + }/* Initialize a page flip struct */ *s = (struct nouveau_page_flip_state)
PATCH 6/19 drm/ttm: call ttm_bo_wait while inside a reservation
In reply to Maarten LankhorstThis is the last remaining function that doesn't use the reservation lock completely to fence off access to a buffer.
--- drivers/gpu/drm/ttm/ttm_bo.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-)
drivers/gpu/drm/ttm/ttm_bo.c +12 -13
@@ -502,17 +502,6 @@ static int ttm_bo_cleanup_refs_and_unlock(struct ttm_buffer_object *bo,if (ret)return ret; -/* -* remove sync_obj with ttm_bo_wait, the wait should be -* finished, and no new wait object should have been added. -*/ -spin_lock (&bdev->fence_lock); - ret =ttm_bo_wait (bo, false, false, true); -WARN_ON (ret); -spin_unlock (&bdev->fence_lock); -if (ret) -return ret; -spin_lock (&glob->lru_lock); ret =__ttm_bo_reserve (bo, false, true, false,NULL );
@@ -528,8 +517,16 @@ static int ttm_bo_cleanup_refs_and_unlock(struct ttm_buffer_object *bo,spin_unlock (&glob->lru_lock);return 0 ; } - }else -spin_unlock (&bdev->fence_lock); + +/* +* remove sync_obj with ttm_bo_wait, the wait should be +* finished, and no new wait object should have been added. +*/ +spin_lock (&bdev->fence_lock); + ret =ttm_bo_wait (bo, false, false, true); +WARN_ON (ret); + } +spin_unlock (&bdev->fence_lock);if (ret ||unlikely (list_empty (&bo->ddestroy))) {__ttm_bo_unreserve (bo);
@@ -1539,6 +1536,8 @@ int ttm_bo_wait(struct ttm_buffer_object *bo,void *sync_obj;int ret =0 ; +lockdep_assert_held (&bo->resv->lock.base); +if (likely (bo->sync_obj ==NULL ))return 0 ;
PATCH 7/19 drm/ttm: kill fence_lock
In reply to Maarten LankhorstNo users are left, kill it off! :D
Conversion to the reservation api is next on the list, after that the functionality can be restored with rcu.
--- drivers/gpu/drm/nouveau/nouveau_bo.c | 25 +++------- drivers/gpu/drm/nouveau/nouveau_display.c | 6 -- drivers/gpu/drm/nouveau/nouveau_gem.c | 16 +----- drivers/gpu/drm/qxl/qxl_cmd.c | 2 - drivers/gpu/drm/qxl/qxl_fence.c | 4 -- drivers/gpu/drm/qxl/qxl_object.h | 2 - drivers/gpu/drm/qxl/qxl_release.c | 2 - drivers/gpu/drm/radeon/radeon_display.c | 9 ++- drivers/gpu/drm/radeon/radeon_object.c | 2 - drivers/gpu/drm/ttm/ttm_bo.c | 75 +++++++---------------------- drivers/gpu/drm/ttm/ttm_bo_util.c | 5 -- drivers/gpu/drm/ttm/ttm_bo_vm.c | 3 - drivers/gpu/drm/ttm/ttm_execbuf_util.c | 2 - drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c | 4 -- drivers/gpu/drm/vmwgfx/vmwgfx_resource.c | 17 ++----- include/drm/ttm/ttm_bo_api.h | 5 -- include/drm/ttm/ttm_bo_driver.h | 3 - 17 files changed, 40 insertions(+), 142 deletions(-)
drivers/gpu/drm/nouveau/nouveau_bo.c +8 -17
@@ -1196,9 +1196,7 @@ nouveau_bo_move(struct ttm_buffer_object *bo, bool evict, bool intr, }/* Fallback to software copy. */ -spin_lock (&bo->bdev->fence_lock); ret =ttm_bo_wait (bo, true, intr, no_wait_gpu); -spin_unlock (&bo->bdev->fence_lock);if (ret ==0 ) ret =ttm_bo_move_memcpy (bo, evict, no_wait_gpu, new_mem);
@@ -1425,26 +1423,19 @@ nouveau_ttm_tt_unpopulate(struct ttm_tt *ttm)ttm_pool_unpopulate (ttm); } +static void +nouveau_bo_fence_unref (void **sync_obj) +{ +nouveau_fence_unref ((struct nouveau_fence **)sync_obj); +} +void nouveau_bo_fence (struct nouveau_bo *nvbo,struct nouveau_fence *fence) { -struct nouveau_fence *new_fence =nouveau_fence_ref (fence); -struct nouveau_fence *old_fence =NULL ; -lockdep_assert_held (&nvbo->bo.resv->lock.base); -spin_lock (&nvbo->bo.bdev->fence_lock); - old_fence = nvbo->bo.sync_obj; - nvbo->bo.sync_obj = new_fence; -spin_unlock (&nvbo->bo.bdev->fence_lock); - -nouveau_fence_unref (&old_fence); -} - -static void -nouveau_bo_fence_unref (void **sync_obj) -{ -nouveau_fence_unref ((struct nouveau_fence **)sync_obj); +nouveau_bo_fence_unref (&nvbo->bo.sync_obj); + nvbo->bo.sync_obj =nouveau_fence_ref (fence); } static void *
drivers/gpu/drm/nouveau/nouveau_display.c +1 -5
@@ -721,11 +721,7 @@ nouveau_crtc_page_flip(struct drm_crtc *crtc, struct drm_framebuffer *fb, goto fail_unpin;/* synchronise rendering channel with the kernel's channel */ -spin_lock (&new_bo->bo.bdev->fence_lock); - fence =nouveau_fence_ref (new_bo->bo.sync_obj); -spin_unlock (&new_bo->bo.bdev->fence_lock); - ret =nouveau_fence_sync (fence, chan); -nouveau_fence_unref (&fence); + ret =nouveau_fence_sync (new_bo->bo.sync_obj, chan);if (ret) {ttm_bo_unreserve (&new_bo->bo); goto fail_unpin;
drivers/gpu/drm/nouveau/nouveau_gem.c +2 -14
@@ -105,9 +105,7 @@ nouveau_gem_object_unmap(struct nouveau_bo *nvbo, struct nouveau_vma *vma)list_del (&vma->head);if (mapped) { -spin_lock (&nvbo->bo.bdev->fence_lock); fence =nouveau_fence_ref (nvbo->bo.sync_obj); -spin_unlock (&nvbo->bo.bdev->fence_lock); }if (fence) {
@@ -432,17 +430,11 @@ retry:static int validate_sync (struct nouveau_channel *chan,struct nouveau_bo *nvbo) { -struct nouveau_fence *fence =NULL ; +struct nouveau_fence *fence = nvbo->bo.sync_obj;int ret =0 ; -spin_lock (&nvbo->bo.bdev->fence_lock); - fence =nouveau_fence_ref (nvbo->bo.sync_obj); -spin_unlock (&nvbo->bo.bdev->fence_lock); - -if (fence) { +if (fence) ret =nouveau_fence_sync (fence, chan); -nouveau_fence_unref (&fence); - }return ret; }
@@ -661,9 +653,7 @@ nouveau_gem_pushbuf_reloc_apply(struct nouveau_cli *cli, data |= r->vor; } -spin_lock (&nvbo->bo.bdev->fence_lock); ret =ttm_bo_wait (&nvbo->bo, false, false, false); -spin_unlock (&nvbo->bo.bdev->fence_lock);if (ret) {NV_ERROR (cli,"reloc wait_idle failed: %d\n" , ret);break ;
@@ -896,11 +886,9 @@ nouveau_gem_ioctl_cpu_prep(struct drm_device *dev, void *data, ret =ttm_bo_reserve (&nvbo->bo, true, false, false,0 );if (!ret) { -spin_lock (&nvbo->bo.bdev->fence_lock); ret =ttm_bo_wait (&nvbo->bo, true, true, true);if (!no_wait && ret) fence =nouveau_fence_ref (nvbo->bo.sync_obj); -spin_unlock (&nvbo->bo.bdev->fence_lock);ttm_bo_unreserve (&nvbo->bo); }
drivers/gpu/drm/qxl/qxl_cmd.c +0 -2
@@ -628,9 +628,7 @@ static int qxl_reap_surf(struct qxl_device *qdev, struct qxl_bo *surf, bool stalif (stall)mutex_unlock (&qdev->surf_evict_mutex); -spin_lock (&surf->tbo.bdev->fence_lock); ret =ttm_bo_wait (&surf->tbo, true, true, !stall); -spin_unlock (&surf->tbo.bdev->fence_lock);if (stall)mutex_lock (&qdev->surf_evict_mutex);
drivers/gpu/drm/qxl/qxl_fence.c +0 -4
@@ -60,9 +60,6 @@ int qxl_fence_remove_release(struct qxl_fence *qfence, uint32_t rel_id) {void *ret;int retval =0 ; - struct qxl_bo *bo = container_of(qfence, struct qxl_bo, fence); - -spin_lock (&bo->tbo.bdev->fence_lock); ret =radix_tree_delete (&qfence->tree, rel_id);if (ret == qfence)
@@ -71,7 +68,6 @@ int qxl_fence_remove_release(struct qxl_fence *qfence, uint32_t rel_id)DRM_DEBUG ("didn't find fence in radix tree for %d\n" , rel_id); retval = -ENOENT ; } -spin_unlock (&bo->tbo.bdev->fence_lock);return retval; }
drivers/gpu/drm/qxl/qxl_object.h +0 -2
@@ -76,12 +76,10 @@ static inline int qxl_bo_wait(struct qxl_bo *bo, u32 *mem_type, }return r; } -spin_lock (&bo->tbo.bdev->fence_lock);if (mem_type) *mem_type = bo->tbo.mem.mem_type;if (bo->tbo.sync_obj) r =ttm_bo_wait (&bo->tbo, true, true, no_wait); -spin_unlock (&bo->tbo.bdev->fence_lock);ttm_bo_unreserve (&bo->tbo);return r; }
drivers/gpu/drm/qxl/qxl_release.c +0 -2
@@ -337,7 +337,6 @@ void qxl_release_fence_buffer_objects(struct qxl_release *release) glob = bo->glob;spin_lock (&glob->lru_lock); -spin_lock (&bdev->fence_lock);list_for_each_entry (entry, &release->bos, head) { bo = entry->bo;
@@ -351,7 +350,6 @@ void qxl_release_fence_buffer_objects(struct qxl_release *release)ttm_bo_add_to_lru (bo);__ttm_bo_unreserve (bo); } -spin_unlock (&bdev->fence_lock);spin_unlock (&glob->lru_lock);ww_acquire_fini (&release->ticket); }
drivers/gpu/drm/radeon/radeon_display.c +4 -5
@@ -462,11 +462,6 @@ static int radeon_crtc_page_flip(struct drm_crtc *crtc, obj = new_radeon_fb->obj; new_rbo =gem_to_radeon_bo (obj); -spin_lock (&new_rbo->tbo.bdev->fence_lock); -if (new_rbo->tbo.sync_obj) - work->fence =radeon_fence_ref (new_rbo->tbo.sync_obj); -spin_unlock (&new_rbo->tbo.bdev->fence_lock); -/* pin the new buffer */ DRM_DEBUG_DRIVER ("flip-ioctl() cur_rbo = %p, new_rbo = %p\n" , work->old_rbo, new_rbo);
@@ -485,6 +480,10 @@ static int radeon_crtc_page_flip(struct drm_crtc *crtc,DRM_ERROR ("failed to pin new rbo buffer before flip\n" ); goto cleanup; } + +if (new_rbo->tbo.sync_obj) + work->fence =radeon_fence_ref (new_rbo->tbo.sync_obj); +radeon_bo_get_tiling_flags (new_rbo, &tiling_flags,NULL );radeon_bo_unreserve (new_rbo);
drivers/gpu/drm/radeon/radeon_object.c +0 -2
@@ -734,12 +734,10 @@ int radeon_bo_wait(struct radeon_bo *bo, u32 *mem_type, bool no_wait) r =ttm_bo_reserve (&bo->tbo, true, no_wait, false,NULL );if (unlikely (r !=0 ))return r; -spin_lock (&bo->tbo.bdev->fence_lock);if (mem_type) *mem_type = bo->tbo.mem.mem_type;if (bo->tbo.sync_obj) r =ttm_bo_wait (&bo->tbo, true, true, no_wait); -spin_unlock (&bo->tbo.bdev->fence_lock);ttm_bo_unreserve (&bo->tbo);return r; }
drivers/gpu/drm/ttm/ttm_bo.c +18 -57
177 lines not on this page · raw message
drivers/gpu/drm/ttm/ttm_bo_util.c +0 -5
@@ -466,12 +466,10 @@ static int ttm_buffer_object_transfer(struct ttm_buffer_object *bo,drm_vma_node_reset (&fbo->vma_node);atomic_set (&fbo->cpu_writers,0 ); -spin_lock (&bdev->fence_lock);if (bo->sync_obj) fbo->sync_obj = driver->sync_obj_ref (bo->sync_obj);else fbo->sync_obj =NULL ; -spin_unlock (&bdev->fence_lock);kref_init (&fbo->list_kref);kref_init (&fbo->kref); fbo->destroy = &ttm_transfered_destroy;
@@ -657,7 +655,6 @@ int ttm_bo_move_accel_cleanup(struct ttm_buffer_object *bo,struct ttm_buffer_object *ghost_obj;void *tmp_obj =NULL ; -spin_lock (&bdev->fence_lock);if (bo->sync_obj) { tmp_obj = bo->sync_obj; bo->sync_obj =NULL ;
@@ -665,7 +662,6 @@ int ttm_bo_move_accel_cleanup(struct ttm_buffer_object *bo, bo->sync_obj = driver->sync_obj_ref (sync_obj);if (evict) { ret =ttm_bo_wait (bo, false, false, false); -spin_unlock (&bdev->fence_lock);if (tmp_obj) driver->sync_obj_unref (&tmp_obj);if (ret)
@@ -688,7 +684,6 @@ int ttm_bo_move_accel_cleanup(struct ttm_buffer_object *bo,*/ set_bit (TTM_BO_PRIV_FLAG_MOVING , &bo->priv_flags); -spin_unlock (&bdev->fence_lock);if (tmp_obj) driver->sync_obj_unref (&tmp_obj);
drivers/gpu/drm/ttm/ttm_bo_vm.c +0 -3
@@ -45,10 +45,8 @@ static int ttm_bo_vm_fault_idle(struct ttm_buffer_object *bo,struct vm_area_struct *vma, struct vm_fault *vmf) { - struct ttm_bo_device *bdev = bo->bdev; int ret = 0; -spin_lock (&bdev->fence_lock);if (likely (!test_bit (TTM_BO_PRIV_FLAG_MOVING , &bo->priv_flags))) goto out_unlock;
@@ -82,7 +80,6 @@ static int ttm_bo_vm_fault_idle(struct ttm_buffer_object *bo,VM_FAULT_NOPAGE ; out_unlock: -spin_unlock (&bdev->fence_lock);return ret; }
drivers/gpu/drm/ttm/ttm_execbuf_util.c +0 -2
@@ -180,7 +180,6 @@ void ttm_eu_fence_buffer_objects(struct ww_acquire_ctx *ticket, glob = bo->glob;spin_lock (&glob->lru_lock); -spin_lock (&bdev->fence_lock);list_for_each_entry (entry, list, head) { bo = entry->bo;
@@ -189,7 +188,6 @@ void ttm_eu_fence_buffer_objects(struct ww_acquire_ctx *ticket,ttm_bo_add_to_lru (bo);__ttm_bo_unreserve (bo); } -spin_unlock (&bdev->fence_lock);spin_unlock (&glob->lru_lock);if (ticket)ww_acquire_fini (ticket);
drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c +0 -4
@@ -829,11 +829,7 @@ static void vmw_move_notify(struct ttm_buffer_object *bo,*/ static void vmw_swap_notify (struct ttm_buffer_object *bo) { -struct ttm_bo_device *bdev = bo->bdev; - -spin_lock (&bdev->fence_lock);ttm_bo_wait (bo, false, false, false); -spin_unlock (&bdev->fence_lock); }
drivers/gpu/drm/vmwgfx/vmwgfx_resource.c +6 -11
@@ -567,12 +567,12 @@ static int vmw_user_dmabuf_synccpu_grab(struct vmw_user_dma_buffer *user_bo,int ret;if (flags & drm_vmw_synccpu_allow_cs) { -struct ttm_bo_device *bdev = bo->bdev; - -spin_lock (&bdev->fence_lock); - ret =ttm_bo_wait (bo, false, true, - !!(flags & drm_vmw_synccpu_dontblock)); -spin_unlock (&bdev->fence_lock); + ret =ttm_bo_reserve (bo, true, !!(flags & drm_vmw_synccpu_dontblock), false,0 ); +if (!ret) { + ret =ttm_bo_wait (bo, false, true, + !!(flags & drm_vmw_synccpu_dontblock)); +ttm_bo_unreserve (bo); + }return ret; }
@@ -1429,12 +1429,10 @@ void vmw_fence_single_bo(struct ttm_buffer_object *bo,else driver->sync_obj_ref (fence); -spin_lock (&bdev->fence_lock); old_fence_obj = bo->sync_obj; bo->sync_obj = fence; -spin_unlock (&bdev->fence_lock);if (old_fence_obj)vmw_fence_obj_unreference (&old_fence_obj);
@@ -1475,7 +1473,6 @@ void vmw_resource_move_notify(struct ttm_buffer_object *bo,if (mem->mem_type !=VMW_PL_MOB ) {struct vmw_resource *res, *n; -struct ttm_bo_device *bdev = bo->bdev;struct ttm_validate_buffer val_buf; val_buf.bo = bo;
@@ -1491,9 +1488,7 @@ void vmw_resource_move_notify(struct ttm_buffer_object *bo,list_del_init (&res->mob_head); } -spin_lock (&bdev->fence_lock); (void )ttm_bo_wait (bo, false, false, false); -spin_unlock (&bdev->fence_lock); } }
include/drm/ttm/ttm_bo_api.h +1 -4
@@ -227,10 +227,7 @@ struct ttm_buffer_object {struct list_head io_reserve_lru;/** -* Members protected by struct buffer_object_device::fence_lock -* In addition, setting sync_obj to anything else -* than NULL requires bo::reserved to be held. This allows for -* checking NULL while reserved but not holding the mentioned lock. +* Members protected by a bo reservation. */ void *sync_obj;
include/drm/ttm/ttm_bo_driver.h +0 -3
@@ -520,8 +520,6 @@ struct ttm_bo_global {* * @driver: Pointer to a struct ttm_bo_driver struct setup by the driver. * @man: An array of mem_type_managers. -* @fence_lock: Protects the synchronizing members on *all* bos belonging -* to this device. * @vma_manager: Address space manager * lru_lock: Spinlock that protects the buffer+device lru lists and * ddestroy lists.
@@ -541,7 +539,6 @@ struct ttm_bo_device {struct ttm_bo_global *glob;struct ttm_bo_driver *driver;struct ttm_mem_type_manager man[TTM_NUM_MEM_TYPES ]; -spinlock_t fence_lock;/* * Protected by internal locks.
PATCH 8/19 drm/nouveau: rework to new fence interface
In reply to Maarten LankhorstFrom: Maarten Lankhorst <maarten.lankhorst-GeWIH/[email protected]>
--- drivers/gpu/drm/nouveau/core/core/event.c | 4 drivers/gpu/drm/nouveau/nouveau_bo.c | 6 drivers/gpu/drm/nouveau/nouveau_display.c | 4 drivers/gpu/drm/nouveau/nouveau_fence.c | 435 ++++++++++++++++++++--------- drivers/gpu/drm/nouveau/nouveau_fence.h | 20 + drivers/gpu/drm/nouveau/nouveau_gem.c | 17 - drivers/gpu/drm/nouveau/nv04_fence.c | 4 drivers/gpu/drm/nouveau/nv10_fence.c | 4 drivers/gpu/drm/nouveau/nv17_fence.c | 2 drivers/gpu/drm/nouveau/nv50_fence.c | 2 drivers/gpu/drm/nouveau/nv84_fence.c | 11 - 11 files changed, 330 insertions(+), 179 deletions(-)
drivers/gpu/drm/nouveau/core/core/event.c +2 -2
@@ -139,14 +139,14 @@ nouveau_event_ref(struct nouveau_eventh *handler, struct nouveau_eventh **ref)void nouveau_event_trigger (struct nouveau_event *event,u32 types,int index) { -struct nouveau_eventh *handler; +struct nouveau_eventh *handler, *next;unsigned long flags;if (WARN_ON (index >= event->index_nr))return ;spin_lock_irqsave (&event->list_lock, flags); -list_for_each_entry (handler, &event->list[index], head) { +list_for_each_entry_safe (handler, next, &event->list[index], head) {if (!test_bit (NVKM_EVENT_ENABLE , &handler->flags))continue ;if (!(handler->types & types))
drivers/gpu/drm/nouveau/nouveau_bo.c +4 -2
@@ -959,7 +959,7 @@ nouveau_bo_move_m2mf(struct ttm_buffer_object *bo, int evict, bool intr, }mutex_lock_nested (&chan->cli->mutex,SINGLE_DEPTH_NESTING ); - ret =nouveau_fence_sync (bo->sync_obj, chan); + ret =nouveau_fence_sync (nouveau_bo (bo), chan);if (ret ==0 ) { ret = drm->ttm.move (chan, bo, &bo->mem, new_mem);if (ret ==0 ) {
@@ -1432,10 +1432,12 @@ nouveau_bo_fence_unref(void **sync_obj)void nouveau_bo_fence (struct nouveau_bo *nvbo,struct nouveau_fence *fence) { -lockdep_assert_held (&nvbo->bo.resv->lock.base); +struct reservation_object *resv = nvbo->bo.resv;nouveau_bo_fence_unref (&nvbo->bo.sync_obj); nvbo->bo.sync_obj =nouveau_fence_ref (fence); + +reservation_object_add_excl_fence (resv, &fence->base); } static void *
drivers/gpu/drm/nouveau/nouveau_display.c +2 -2
@@ -660,7 +660,7 @@ nouveau_page_flip_emit(struct nouveau_channel *chan,spin_unlock_irqrestore (&dev->event_lock, flags);/* Synchronize with the old framebuffer */ - ret =nouveau_fence_sync (old_bo->bo.sync_obj, chan); + ret =nouveau_fence_sync (old_bo, chan);if (ret) goto fail;
@@ -721,7 +721,7 @@ nouveau_crtc_page_flip(struct drm_crtc *crtc, struct drm_framebuffer *fb, goto fail_unpin;/* synchronise rendering channel with the kernel's channel */ - ret =nouveau_fence_sync (new_bo->bo.sync_obj, chan); + ret =nouveau_fence_sync (new_bo, chan);if (ret) {ttm_bo_unreserve (&new_bo->bo); goto fail_unpin;
drivers/gpu/drm/nouveau/nouveau_fence.c +293 -142
576 lines not on this page · raw message
drivers/gpu/drm/nouveau/nouveau_fence.h +13 -7
@@ -1,18 +1,21 @@#ifndef __NOUVEAU_FENCE_H__#define __NOUVEAU_FENCE_H__ +#include <linux/fence.h> +struct nouveau_drm ; +struct nouveau_bo ;struct nouveau_fence { +struct fence base; +struct list_head head; -struct list_head work; -struct kref kref; +struct nouveau_eventh event;bool sysmem;struct nouveau_channel *channel;unsigned long timeout; -u32 sequence; }; int nouveau_fence_new(struct nouveau_channel *, bool sysmem,
@@ -25,7 +28,7 @@ int nouveau_fence_emit(struct nouveau_fence *, struct nouveau_channel *);bool nouveau_fence_done (struct nouveau_fence *);void nouveau_fence_work (struct nouveau_fence *,void (*)(void *),void *);int nouveau_fence_wait (struct nouveau_fence *,bool lazy,bool intr); -int nouveau_fence_sync (struct nouveau_fence *,struct nouveau_channel *); +int nouveau_fence_sync (struct nouveau_bo *,struct nouveau_channel *);struct nouveau_fence_chan {struct list_head pending;
@@ -38,8 +41,10 @@ struct nouveau_fence_chan {int (*emit32)(struct nouveau_channel *,u64 ,u32 );int (*sync32)(struct nouveau_channel *,u64 ,u32 ); -spinlock_t lock; +spinlock_t *lock;u32 sequence; +u32 context; +char name[24 ]; };struct nouveau_fence_priv {
@@ -49,13 +54,14 @@ struct nouveau_fence_priv {int (*context_new)(struct nouveau_channel *);void (*context_del)(struct nouveau_channel *); -wait_queue_head_t waiting;bool uevent; + +u32 contexts, context_base; };#define nouveau_fence (drm) ((struct nouveau_fence_priv *)(drm)->fence) -void nouveau_fence_context_new (struct nouveau_fence_chan *); +void nouveau_fence_context_new (struct nouveau_channel *,struct nouveau_fence_chan *);void nouveau_fence_context_del (struct nouveau_fence_chan *);int nv04_fence_create (struct nouveau_drm *);
drivers/gpu/drm/nouveau/nouveau_gem.c +3 -14
@@ -428,18 +428,6 @@ retry: }static int -validate_sync (struct nouveau_channel *chan,struct nouveau_bo *nvbo) -{ -struct nouveau_fence *fence = nvbo->bo.sync_obj; -int ret =0 ; - -if (fence) - ret =nouveau_fence_sync (fence, chan); - -return ret; -} - -static int validate_list (struct nouveau_channel *chan,struct nouveau_cli *cli,struct list_head *list,struct drm_nouveau_gem_pushbuf_bo *pbbo,uint64_t user_pbbo_ptr)
@@ -468,9 +456,10 @@ validate_list(struct nouveau_channel *chan, struct nouveau_cli *cli,return ret; } - ret =validate_sync (chan, nvbo); + ret =nouveau_fence_sync (nvbo, chan);if (unlikely (ret)) { -NV_ERROR (cli,"fail post-validate sync\n" ); +if (ret != -ERESTARTSYS ) +NV_ERROR (cli,"fail post-validate sync\n" );return ret; }
drivers/gpu/drm/nouveau/nv04_fence.c +2 -2
@@ -43,7 +43,7 @@ nv04_fence_emit(struct nouveau_fence *fence)int ret =RING_SPACE (chan,2 );if (ret ==0 ) {BEGIN_NV04 (chan, NvSubSw,0x0150 ,1 ); -OUT_RING (chan, fence->sequence); +OUT_RING (chan, fence->base.seqno);FIRE_RING (chan); }return ret;
@@ -77,7 +77,7 @@ nv04_fence_context_new(struct nouveau_channel *chan) {struct nv04_fence_chan *fctx =kzalloc (sizeof (*fctx),GFP_KERNEL );if (fctx) { -nouveau_fence_context_new (&fctx->base); +nouveau_fence_context_new (chan, &fctx->base); fctx->base.emit = nv04_fence_emit; fctx->base.sync = nv04_fence_sync; fctx->base.read = nv04_fence_read;
drivers/gpu/drm/nouveau/nv10_fence.c +2 -2
@@ -36,7 +36,7 @@ nv10_fence_emit(struct nouveau_fence *fence)int ret =RING_SPACE (chan,2 );if (ret ==0 ) {BEGIN_NV04 (chan,0 ,NV10_SUBCHAN_REF_CNT ,1 ); -OUT_RING (chan, fence->sequence); +OUT_RING (chan, fence->base.seqno);FIRE_RING (chan); }return ret;
@@ -74,7 +74,7 @@ nv10_fence_context_new(struct nouveau_channel *chan)if (!fctx)return -ENOMEM ; -nouveau_fence_context_new (&fctx->base); +nouveau_fence_context_new (chan, &fctx->base); fctx->base.emit = nv10_fence_emit; fctx->base.read = nv10_fence_read; fctx->base.sync = nv10_fence_sync;
drivers/gpu/drm/nouveau/nv17_fence.c +1 -1
@@ -83,7 +83,7 @@ nv17_fence_context_new(struct nouveau_channel *chan)if (!fctx)return -ENOMEM ; -nouveau_fence_context_new (&fctx->base); +nouveau_fence_context_new (chan, &fctx->base); fctx->base.emit = nv10_fence_emit; fctx->base.read = nv10_fence_read; fctx->base.sync = nv17_fence_sync;
drivers/gpu/drm/nouveau/nv50_fence.c +1 -1
@@ -47,7 +47,7 @@ nv50_fence_context_new(struct nouveau_channel *chan)if (!fctx)return -ENOMEM ; -nouveau_fence_context_new (&fctx->base); +nouveau_fence_context_new (chan, &fctx->base); fctx->base.emit = nv10_fence_emit; fctx->base.read = nv10_fence_read; fctx->base.sync = nv17_fence_sync;
drivers/gpu/drm/nouveau/nv84_fence.c +7 -4
@@ -89,7 +89,7 @@ nv84_fence_emit(struct nouveau_fence *fence)else addr += fctx->vma.offset; -return fctx->base.emit32 (chan, addr, fence->sequence); +return fctx->base.emit32 (chan, addr, fence->base.seqno); } static int
@@ -105,7 +105,7 @@ nv84_fence_sync(struct nouveau_fence *fence,else addr += fctx->vma.offset; -return fctx->base.sync32 (chan, addr, fence->sequence); +return fctx->base.sync32 (chan, addr, fence->base.seqno); } static u32
@@ -149,12 +149,14 @@ nv84_fence_context_new(struct nouveau_channel *chan)if (!fctx)return -ENOMEM ; -nouveau_fence_context_new (&fctx->base); +nouveau_fence_context_new (chan, &fctx->base); fctx->base.emit = nv84_fence_emit; fctx->base.sync = nv84_fence_sync; fctx->base.read = nv84_fence_read; fctx->base.emit32 = nv84_fence_emit32; fctx->base.sync32 = nv84_fence_sync32; + fctx->base.sequence =nv84_fence_read (chan); + fctx->base.context = priv->base.context_base + fifo->chid; ret =nouveau_bo_vma_add (priv->bo, client->vm, &fctx->vma);if (ret ==0 ) {
@@ -239,7 +241,8 @@ nv84_fence_create(struct nouveau_drm *drm) priv->base.context_new = nv84_fence_context_new; priv->base.context_del = nv84_fence_context_del; -init_waitqueue_head (&priv->base.waiting); + priv->base.contexts = pfifo->max +1 ; + priv->base.context_base =fence_context_alloc (priv->base.contexts); priv->base.uevent = true; ret = nouveau_bo_new(drm->dev, 16 * (pfifo->max + 1), 0,
PATCH 9/19 drm/radeon: handle lockup in delayed work, v2
In reply to Maarten Lankhorst---
V1 had a nasty bug breaking gpu lockup recovery. The fix is not allowing radeon_fence_driver_check_lockup to take exclusive_lock, and kill it during lockup recovery instead.
--- drivers/gpu/drm/radeon/radeon.h | 3 + drivers/gpu/drm/radeon/radeon_device.c | 5 + drivers/gpu/drm/radeon/radeon_fence.c | 124 ++++++++++++++++++-------------- drivers/gpu/drm/radeon/radeon_ring.c | 1 4 files changed, 77 insertions(+), 56 deletions(-)
drivers/gpu/drm/radeon/radeon.h +3 -0
@@ -347,6 +347,8 @@ struct radeon_fence_driver {uint64_t sync_seq[RADEON_NUM_RINGS ];atomic64_t last_seq;bool initialized; +struct delayed_work fence_check_work; +struct radeon_device *rdev; };struct radeon_fence {
@@ -360,6 +362,7 @@ struct radeon_fence {int radeon_fence_driver_start_ring (struct radeon_device *rdev,int ring);int radeon_fence_driver_init (struct radeon_device *rdev); +void radeon_fence_cancel_delayed_check (struct radeon_device *rdev,int ring);void radeon_fence_driver_fini (struct radeon_device *rdev);void radeon_fence_driver_force_completion (struct radeon_device *rdev);int radeon_fence_emit (struct radeon_device *rdev,struct radeon_fence **fence,int ring);
drivers/gpu/drm/radeon/radeon_device.c +5 -0
@@ -1637,6 +1637,11 @@ int radeon_gpu_reset(struct radeon_device *rdev)radeon_save_bios_scratch_regs (rdev);/* block TTM */ resched =ttm_bo_lock_delayed_workqueue (&rdev->mman.bdev); + +/* kill all the hangcheck tests too */ +for (i =0 ; i <RADEON_NUM_RINGS ; ++i) +radeon_fence_cancel_delayed_check (rdev, i); +radeon_pm_suspend (rdev);radeon_suspend (rdev);
drivers/gpu/drm/radeon/radeon_fence.c +68 -56
179 lines not on this page · raw message
drivers/gpu/drm/radeon/radeon_ring.c +1 -0
@@ -261,6 +261,7 @@ int radeon_ib_ring_tests(struct radeon_device *rdev) r =radeon_ib_test (rdev, i, ring);if (r) { +radeon_fence_cancel_delayed_check (rdev, i); ring->ready = false; rdev->needs_reset = false;
Christian König
maintainerRe: [PATCH 09/19] drm/radeon: handle lockup in delayed work, v2
Am 31.07.2014 um 17:33 schrieb Maarten Lankhorst:
Quoted 5 lines
Signed-off-by Maarten Lankhorst <[email protected]>---
V1 had a nasty bug breaking gpu lockup recovery. The fix is not allowingradeon_fence_driver_check_lockupto takeexclusive_lock, and kill it during lockup recovery instead.
That looks like the delayed work starts running as soon as we submit a fence, and not when it's needed for waiting.
Since it's a backup for failing IRQs I would rather put it into radeon_irq_kms.c and start/stop it when the IRQs are started/stoped.
Christian.
Quoted 248 lines
--- drivers/gpu/drm/radeon/radeon.h | 3 + drivers/gpu/drm/radeon/radeon_device.c | 5 + drivers/gpu/drm/radeon/radeon_fence.c | 124 ++++++++++++++++++-------------- drivers/gpu/drm/radeon/radeon_ring.c | 1 4 files changed, 77 insertions(+), 56 deletions(-)drivers/gpu/drm/radeon/radeon.h +3
-0@@ -347,6 +347,8 @@ struct radeon_fence_driver {uint64_t sync_seq[RADEON_NUM_RINGS ];atomic64_t last_seq;bool initialized; +struct delayed_work fence_check_work; +struct radeon_device *rdev; };struct radeon_fence {@@ -360,6 +362,7 @@ struct radeon_fence {int radeon_fence_driver_start_ring (struct radeon_device *rdev,int ring);int radeon_fence_driver_init (struct radeon_device *rdev); +void radeon_fence_cancel_delayed_check (struct radeon_device *rdev,int ring);void radeon_fence_driver_fini (struct radeon_device *rdev);void radeon_fence_driver_force_completion (struct radeon_device *rdev);int radeon_fence_emit (struct radeon_device *rdev,struct radeon_fence **fence,int ring);drivers/gpu/drm/radeon/radeon_device.c +5
-0@@ -1637,6 +1637,11 @@ int radeon_gpu_reset(struct radeon_device *rdev)radeon_save_bios_scratch_regs (rdev);/* block TTM */ resched =ttm_bo_lock_delayed_workqueue (&rdev->mman.bdev); + +/* kill all the hangcheck tests too */ +for (i =0 ; i <RADEON_NUM_RINGS ; ++i) +radeon_fence_cancel_delayed_check (rdev, i); +radeon_pm_suspend (rdev);radeon_suspend (rdev);drivers/gpu/drm/radeon/radeon_fence.c +68
-56@@ -125,16 +125,7 @@ int radeon_fence_emit(struct radeon_device *rdev,return 0 ; } -/** -* radeon_fence_process - process a fence -* -* @rdev: radeon_device pointer -* @ring: ring index the fence is associated with -* -* Checks the current fence value and wakes the fence queue -* if the sequence number has increased (all asics). -*/ -void radeon_fence_process (struct radeon_device *rdev,int ring) +static bool __radeon_fence_process (struct radeon_device *rdev,int ring) {uint64_t seq, last_seq, last_emitted;unsigned count_loop =0 ;@@ -190,7 +181,51 @@ void radeon_fence_process(struct radeon_device *rdev, int ring) } }while (atomic64_xchg (&rdev->fence_drv[ring].last_seq, seq) > seq); -if (wake) +if (seq < last_emitted) +mod_delayed_work (system_power_efficient_wq, + &rdev->fence_drv[ring].fence_check_work, +RADEON_FENCE_JIFFIES_TIMEOUT ); + +return wake; +} + +static void radeon_fence_driver_check_lockup (struct work_struct *work) +{ +struct radeon_fence_driver *fence_drv; +struct radeon_device *rdev; +unsigned long iring; + + fence_drv = container_of(work, struct radeon_fence_driver, fence_check_work.work); + rdev = fence_drv->rdev; + iring = fence_drv - &rdev->fence_drv[0 ]; + +if (__radeon_fence_process (rdev, iring)) +wake_up_all (&rdev->fence_queue); +else if (radeon_ring_is_lockup (rdev, iring, &rdev->ring[iring])) { +/* good news we believe it's a lockup */ +dev_warn (rdev->dev,"GPU lockup (current fence id " +"0x%016llx last fence id 0x%016llx on ring %ld)\n" , + (uint64_t )atomic64_read (&fence_drv->last_seq), + fence_drv->sync_seq[iring], iring); + +/* remember that we need an reset */ + rdev->needs_reset = true; +wake_up_all (&rdev->fence_queue); + } +} + +/** +* radeon_fence_process - process a fence +* +* @rdev: radeon_device pointer +* @ring: ring index the fence is associated with +* +* Checks the current fence value and wakes the fence queue +* if the sequence number has increased (all asics). +*/ +void radeon_fence_process (struct radeon_device *rdev,int ring) +{ +if (__radeon_fence_process (rdev, ring))wake_up_all (&rdev->fence_queue); }@@ -302,9 +337,10 @@ static int radeon_fence_wait_seq(struct radeon_device *rdev, u64 *target_seq, {uint64_t last_seq[RADEON_NUM_RINGS ];bool signaled; -int i, r; +int i;while (!radeon_fence_any_seq_signaled (rdev, target_seq)) { +long r;/* Save current sequence values, used to check for GPU lockups */ for (i =0 ; i <RADEON_NUM_RINGS ; ++i) {@@ -319,11 +355,11 @@ static int radeon_fence_wait_seq(struct radeon_device *rdev, u64 *target_seq,if (intr) { r =wait_event_interruptible_timeout (rdev->fence_queue, ( (signaled =radeon_fence_any_seq_signaled (rdev, target_seq)) - || rdev->needs_reset),RADEON_FENCE_JIFFIES_TIMEOUT ); + || rdev->needs_reset),MAX_SCHEDULE_TIMEOUT ); }else { r =wait_event_timeout (rdev->fence_queue, ( (signaled =radeon_fence_any_seq_signaled (rdev, target_seq)) - || rdev->needs_reset),RADEON_FENCE_JIFFIES_TIMEOUT ); + || rdev->needs_reset),MAX_SCHEDULE_TIMEOUT ); }for (i =0 ; i <RADEON_NUM_RINGS ; ++i) {@@ -334,50 +370,11 @@ static int radeon_fence_wait_seq(struct radeon_device *rdev, u64 *target_seq,trace_radeon_fence_wait_end (rdev->ddev, i, target_seq[i]); } -if (unlikely (r <0 )) +if (r <0 )return r; -if (unlikely (!signaled)) { -if (rdev->needs_reset) -return -EDEADLK ; - -/* we were interrupted for some reason and fence -* isn't signaled yet, resume waiting */ -if (r) -continue ; - -for (i =0 ; i <RADEON_NUM_RINGS ; ++i) { -if (!target_seq[i]) -continue ; - -if (last_seq[i] !=atomic64_read (&rdev->fence_drv[i].last_seq)) -break ; - } - -if (i !=RADEON_NUM_RINGS ) -continue ; - -for (i =0 ; i <RADEON_NUM_RINGS ; ++i) { -if (!target_seq[i]) -continue ; - -if (radeon_ring_is_lockup (rdev, i, &rdev->ring[i])) -break ; - } - -if (i <RADEON_NUM_RINGS ) { -/* good news we believe it's a lockup */ -dev_warn (rdev->dev,"GPU lockup (waiting for " -"0x%016llx last fence id 0x%016llx on" -" ring %d)\n" , - target_seq[i], last_seq[i], i); - -/* remember that we need an reset */ - rdev->needs_reset = true; -wake_up_all (&rdev->fence_queue); -return -EDEADLK ; - } - } +if (rdev->needs_reset) +return -EDEADLK ; }return 0 ; }@@ -711,6 +708,8 @@ static void radeon_fence_driver_init_ring(struct radeon_device *rdev, int ring) rdev->fence_drv[ring].sync_seq[i] =0 ;atomic64_set (&rdev->fence_drv[ring].last_seq,0 ); rdev->fence_drv[ring].initialized = false; +INIT_DELAYED_WORK (&rdev->fence_drv[ring].fence_check_work, radeon_fence_driver_check_lockup); + rdev->fence_drv[ring].rdev = rdev; }/** @@ -740,6 +739,17 @@ int radeon_fence_driver_init(struct radeon_device *rdev) }/** +* radeon_fence_cancel_delayed_check - cancel all delayed checks on a ring during lockup +* +* This prevents the lockup check from being done while suspend is running +* during a recovery from a lockup. +*/ +void radeon_fence_cancel_delayed_check (struct radeon_device *rdev,int ring) +{ +cancel_delayed_work_sync (&rdev->fence_drv[ring].fence_check_work); +} + +/** * radeon_fence_driver_fini - tear down the fence driver * for all possible rings. * @@ -755,6 +765,8 @@ void radeon_fence_driver_fini(struct radeon_device *rdev)for (ring =0 ; ring <RADEON_NUM_RINGS ; ring++) {if (!rdev->fence_drv[ring].initialized)continue ; + +cancel_delayed_work_sync (&rdev->fence_drv[ring].fence_check_work); r =radeon_fence_wait_empty (rdev, ring);if (r) {/* no need to trigger GPU reset as we are unloading */ drivers/gpu/drm/radeon/radeon_ring.c +1
-0@@ -261,6 +261,7 @@ int radeon_ib_ring_tests(struct radeon_device *rdev) r =radeon_ib_test (rdev, i, ring);if (r) { +radeon_fence_cancel_delayed_check (rdev, i); ring->ready = false; rdev->needs_reset = false;
Re: [PATCH 09/19] drm/radeon: handle lockup in delayed work, v2
Quoted 10 lines · Christian König
Am 31.07.2014 um 17:33 schrieb Maarten Lankhorst:
Quoted 5 lines
Signed-off-by Maarten Lankhorst <[email protected]>---
V1 had a nasty bug breaking gpu lockup recovery. The fix is not allowingradeon_fence_driver_check_lockupto takeexclusive_lock, and kill it during lockup recovery instead.That looks like the delayed work starts running as soon as we submit a fence, and not when it's needed for waiting.
Since it's a backup for failing IRQs I would rather put it into
radeon_irq_kms.cand start/stop it when the IRQs are started/stoped.
The delayed work is not just for failing irq's, it's also the handler that's used to detect lockups, which is why I trigger after processing fences, and reset the timer after processing.
Specifically what happened was this scenario:
- lock up occurs
- write lock taken by gpu_reset
- delayed work runs, tries to acquire read lock, blocks
- gpu_reset tries to cancel delayed work synchronously
- has to wait for delayed work to finish -> deadlock
~Maarten
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Christian König
maintainerRe: [PATCH 09/19] drm/radeon: handle lockup in delayed work, v2
Hi Maarten,
Sorry for the delay. I've got way to much todo recently.
Am 01.08.2014 um 19:46 schrieb Maarten Lankhorst:
Quoted 8 lines · Christian König
Quoted 6 lines
Am 31.07.2014 um 17:33 schrieb Maarten Lankhorst:
Quoted 5 lines
Signed-off-by Maarten Lankhorst <[email protected]>---
V1 had a nasty bug breaking gpu lockup recovery. The fix is not allowingradeon_fence_driver_check_lockupto takeexclusive_lock, and kill it during lockup recovery instead.
Quoted 4 lines
Quoted 3 lines
That looks like the delayed work starts running as soon as we submit a fence, and not when it's needed for waiting.
Since it's a backup for failing IRQs I would rather put it into
radeon_irq_kms.cand start/stop it when the IRQs are started/stoped.The delayed work is not just for failing irq's, it's also the handler that's used to detect lockups, which is why I trigger after processing fences, and reset the timer after processing.
The idea was turning the delayed work on and off when we turn the irq on and off as well, processing of the delayed work handler can still happen in radeon_fence.c
Quoted 8 lines
Specifically what happened was this scenario:
- lock up occurs
- write lock taken bygpu_reset
- delayed work runs, tries to acquire read lock, blocks
-gpu_resettries to cancel delayed work synchronously
- has to wait for delayed work to finish -> deadlock
Why do you want to disable the work item from the lockup handler in the first place?
Just take the exclusive lock in the work item, when it concurrently runs with the lockup handler it will just block for the lockup handler to complete.
Regards,
Christian.
Quoted 1 line
~Maarten
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 09/19] drm/radeon: handle lockup in delayed work, v2
op 04-08-14 10:36, Christian König schreef:
Quoted 29 lines
Hi Maarten,
Sorry for the delay. I've got way to much todo recently.
Am 01.08.2014 um 19:46 schrieb Maarten Lankhorst:
Quoted 8 lines · Christian König
Quoted 6 lines
Am 31.07.2014 um 17:33 schrieb Maarten Lankhorst:
Quoted 5 lines
Signed-off-by Maarten Lankhorst <[email protected]>---
V1 had a nasty bug breaking gpu lockup recovery. The fix is not allowingradeon_fence_driver_check_lockupto takeexclusive_lock, and kill it during lockup recovery instead.Quoted 4 lines
Quoted 3 lines
That looks like the delayed work starts running as soon as we submit a fence, and not when it's needed for waiting.
Since it's a backup for failing IRQs I would rather put it into
radeon_irq_kms.cand start/stop it when the IRQs are started/stoped.The delayed work is not just for failing irq's, it's also the handler that's used to detect lockups, which is why I trigger after processing fences, and reset the timer after processing.
The idea was turning the delayed work on and off when we turn the irq on and off as well, processing of the delayed work handler can still happen in
radeon_fence.cQuoted 8 lines
Specifically what happened was this scenario:
- lock up occurs
- write lock taken bygpu_reset
- delayed work runs, tries to acquire read lock, blocks
-gpu_resettries to cancel delayed work synchronously
- has to wait for delayed work to finish -> deadlock
Quoted 3 lines
Why do you want to disable the work item from the lockup handler in the first place?
Just take the exclusive lock in the work item, when it concurrently runs with the lockup handler it will just block for the lockup handler to complete.
With the delayed work radeon_fence_wait no longer handles unreliable interrupts itself, so it has to run from the lockup handler. But an alternative solution could be adding a radeon_fence_wait_timeout, ignore the timeout and check if fence is signaled on timeout. This would probably be a cleaner solution.
~Maarten
_______________________________________________
Nouveau mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau
Christian König
maintainerRe: [PATCH 09/19] drm/radeon: handle lockup in delayed work, v2
Am 04.08.2014 um 10:55 schrieb Maarten Lankhorst:
Quoted 26 lines
op 04-08-14 10:36, Christian König schreef:
Quoted 25 lines
Hi Maarten,
Sorry for the delay. I've got way to much todo recently.
Am 01.08.2014 um 19:46 schrieb Maarten Lankhorst:
Quoted 11 lines · Christian König
Quoted 9 lines
Am 31.07.2014 um 17:33 schrieb Maarten Lankhorst:
Quoted 5 lines
Signed-off-by Maarten Lankhorst <[email protected]>---
V1 had a nasty bug breaking gpu lockup recovery. The fix is not allowingradeon_fence_driver_check_lockupto takeexclusive_lock, and kill it during lockup recovery instead.That looks like the delayed work starts running as soon as we submit a fence, and not when it's needed for waiting.
Since it's a backup for failing IRQs I would rather put it into
radeon_irq_kms.cand start/stop it when the IRQs are started/stoped.The delayed work is not just for failing irq's, it's also the handler that's used to detect lockups, which is why I trigger after processing fences, and reset the timer after processing.
The idea was turning the delayed work on and off when we turn the irq on and off as well, processing of the delayed work handler can still happen in
radeon_fence.cQuoted 7 lines
Specifically what happened was this scenario:
- lock up occurs
- write lock taken bygpu_reset
- delayed work runs, tries to acquire read lock, blocks
-gpu_resettries to cancel delayed work synchronously
- has to wait for delayed work to finish -> deadlock
Quoted 6 lines
Quoted 3 lines
Why do you want to disable the work item from the lockup handler in the first place?
Just take the exclusive lock in the work item, when it concurrently runs with the lockup handler it will just block for the lockup handler to complete.
With the delayed work
radeon_fence_waitno longer handles unreliable interrupts itself, so it has to run from the lockup handler. But an alternative solution could be adding aradeon_fence_wait_timeout, ignore the timeout and check if fence is signaled on timeout. This would probably be a cleaner solution.
Yeah, agree. Manually specifying a timeout in the fence wait on lockup handling sounds like the best alternative to me.
Christian.
Quoted 3 lines
~Maarten
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 09/19] drm/radeon: handle lockup in delayed work, v2
Hey,
op 04-08-14 13:57, Christian König schreef:
Quoted 27 lines
Am 04.08.2014 um 10:55 schrieb Maarten Lankhorst:
Quoted 26 lines
op 04-08-14 10:36, Christian König schreef:
Quoted 25 lines
Hi Maarten,
Sorry for the delay. I've got way to much todo recently.
Am 01.08.2014 um 19:46 schrieb Maarten Lankhorst:
Quoted 11 lines · Christian König
Quoted 9 lines
Am 31.07.2014 um 17:33 schrieb Maarten Lankhorst:
Quoted 5 lines
Signed-off-by Maarten Lankhorst <[email protected]>---
V1 had a nasty bug breaking gpu lockup recovery. The fix is not allowingradeon_fence_driver_check_lockupto takeexclusive_lock, and kill it during lockup recovery instead.That looks like the delayed work starts running as soon as we submit a fence, and not when it's needed for waiting.
Since it's a backup for failing IRQs I would rather put it into
radeon_irq_kms.cand start/stop it when the IRQs are started/stoped.The delayed work is not just for failing irq's, it's also the handler that's used to detect lockups, which is why I trigger after processing fences, and reset the timer after processing.
The idea was turning the delayed work on and off when we turn the irq on and off as well, processing of the delayed work handler can still happen in
radeon_fence.cQuoted 7 lines
Specifically what happened was this scenario:
- lock up occurs
- write lock taken bygpu_reset
- delayed work runs, tries to acquire read lock, blocks
-gpu_resettries to cancel delayed work synchronously
- has to wait for delayed work to finish -> deadlock
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Why do you want to disable the work item from the lockup handler in the first place?
Just take the exclusive lock in the work item, when it concurrently runs with the lockup handler it will just block for the lockup handler to complete.
With the delayed work
radeon_fence_waitno longer handles unreliable interrupts itself, so it has to run from the lockup handler. But an alternative solution could be adding aradeon_fence_wait_timeout, ignore the timeout and check if fence is signaled on timeout. This would probably be a cleaner solution.Yeah, agree. Manually specifying a timeout in the fence wait on lockup handling sounds like the best alternative to me.
It'a pain to deal with gpu reset.
I've now tried other solutions but that would mean reverting to the old style during gpu lockup recovery, and only running the delayed work when !lockup. But this meant that the timeout was useless to add. I think the cleanest is keeping the v2 patch, because potentially any waiting code can be called during lockup recovery.
~Maarten
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Christian König
maintainerRe: [PATCH 09/19] drm/radeon: handle lockup in delayed work, v2
Quoted 1 line
It'a pain to deal with gpu reset.
Yeah, well that's nothing new.
Quoted 2 lines
I've now tried other solutions but that would mean reverting to the old style during gpu lockup recovery, and only running the delayed work when !lockup. But this meant that the timeout was useless to add. I think the cleanest is keeping the v2 patch, because potentially any waiting code can be called during lockup recovery.
The lockup code itself should never call any waiting code and V2 doesn't seem to handle a couple of cases correctly either.
How about moving the fence waiting out of the reset code?
Christian.
Am 04.08.2014 um 15:34 schrieb Maarten Lankhorst:
Quoted 36 lines
Hey,
op 04-08-14 13:57, Christian König schreef:
Quoted 33 lines
Am 04.08.2014 um 10:55 schrieb Maarten Lankhorst:
Quoted 32 lines
op 04-08-14 10:36, Christian König schreef:
Quoted 20 lines
Hi Maarten,
Sorry for the delay. I've got way to much todo recently.
Am 01.08.2014 um 19:46 schrieb Maarten Lankhorst:
Quoted 11 lines · Christian König
Quoted 9 lines
Am 31.07.2014 um 17:33 schrieb Maarten Lankhorst:
Quoted 5 lines
Signed-off-by Maarten Lankhorst <[email protected]>---
V1 had a nasty bug breaking gpu lockup recovery. The fix is not allowingradeon_fence_driver_check_lockupto takeexclusive_lock, and kill it during lockup recovery instead.That looks like the delayed work starts running as soon as we submit a fence, and not when it's needed for waiting.
Since it's a backup for failing IRQs I would rather put it into
radeon_irq_kms.cand start/stop it when the IRQs are started/stoped.The delayed work is not just for failing irq's, it's also the handler that's used to detect lockups, which is why I trigger after processing fences, and reset the timer after processing.
The idea was turning the delayed work on and off when we turn the irq on and off as well, processing of the delayed work handler can still happen in
radeon_fence.cQuoted 2 lines
Specifically what happened was this scenario:
Quoted 8 lines
Quoted 5 lines
- lock up occurs
- write lock taken bygpu_reset
- delayed work runs, tries to acquire read lock, blocks
-gpu_resettries to cancel delayed work synchronously
- has to wait for delayed work to finish -> deadlockWhy do you want to disable the work item from the lockup handler in the first place?
Just take the exclusive lock in the work item, when it concurrently runs with the lockup handler it will just block for the lockup handler to complete.
With the delayed work
radeon_fence_waitno longer handles unreliable interrupts itself, so it has to run from the lockup handler. But an alternative solution could be adding aradeon_fence_wait_timeout, ignore the timeout and check if fence is signaled on timeout. This would probably be a cleaner solution.
Quoted 8 lines
Quoted 1 line
Yeah, agree. Manually specifying a timeout in the fence wait on lockup handling sounds like the best alternative to me.
It'a pain to deal with gpu reset.
I've now tried other solutions but that would mean reverting to the old style during gpu lockup recovery, and only running the delayed work when !lockup. But this meant that the timeout was useless to add. I think the cleanest is keeping the v2 patch, because potentially any waiting code can be called during lockup recovery.
~Maarten
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 09/19] drm/radeon: handle lockup in delayed work, v2
op 04-08-14 16:37, Christian König schreef:
Quoted 10 lines
Quoted 1 line
It'a pain to deal with gpu reset.
Yeah, well that's nothing new.
Quoted 2 lines
I've now tried other solutions but that would mean reverting to the old style during gpu lockup recovery, and only running the delayed work when !lockup. But this meant that the timeout was useless to add. I think the cleanest is keeping the v2 patch, because potentially any waiting code can be called during lockup recovery.
The lockup code itself should never call any waiting code and V2 doesn't seem to handle a couple of cases correctly either.
How about moving the fence waiting out of the reset code?
What cases did I miss then?
I'm curious how you want to move the fence waiting out of reset, when there are so many places that could potentially wait, like radeon_ib_get can call radeon_sa_bo_new which can do a wait, or radeon_ring_alloc that can wait on radeon_fence_wait_next, etc.
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Christian König
maintainerRe: [PATCH 09/19] drm/radeon: handle lockup in delayed work, v2
Am 04.08.2014 um 16:40 schrieb Maarten Lankhorst:
Quoted 4 lines
op 04-08-14 16:37, Christian König schreef:
Quoted 3 lines
Quoted 1 line
It'a pain to deal with gpu reset.
Yeah, well that's nothing new.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
I've now tried other solutions but that would mean reverting to the old style during gpu lockup recovery, and only running the delayed work when !lockup. But this meant that the timeout was useless to add. I think the cleanest is keeping the v2 patch, because potentially any waiting code can be called during lockup recovery.
The lockup code itself should never call any waiting code and V2 doesn't seem to handle a couple of cases correctly either.
How about moving the fence waiting out of the reset code?
What cases did I miss then?
I'm curious how you want to move the fence waiting out of reset, when there are so many places that could potentially wait, like
radeon_ib_getcan callradeon_sa_bo_newwhich can do a wait, orradeon_ring_allocthat can wait onradeon_fence_wait_next, etc.
The IB test itself doesn't needs to be protected by the exclusive lock. Only everything between radeon_save_bios_scratch_regs and radeon_ring_restore.
Christian.
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 09/19] drm/radeon: handle lockup in delayed work, v2
op 04-08-14 16:45, Christian König schreef:
Quoted 7 lines
Am 04.08.2014 um 16:40 schrieb Maarten Lankhorst:
Quoted 6 lines
op 04-08-14 16:37, Christian König schreef:
Quoted 5 lines
Quoted 1 line
It'a pain to deal with gpu reset.
Yeah, well that's nothing new.
Quoted 2 lines
I've now tried other solutions but that would mean reverting to the old style during gpu lockup recovery, and only running the delayed work when !lockup. But this meant that the timeout was useless to add. I think the cleanest is keeping the v2 patch, because potentially any waiting code can be called during lockup recovery.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
The lockup code itself should never call any waiting code and V2 doesn't seem to handle a couple of cases correctly either.
How about moving the fence waiting out of the reset code?
What cases did I miss then?
I'm curious how you want to move the fence waiting out of reset, when there are so many places that could potentially wait, like
radeon_ib_getcan callradeon_sa_bo_newwhich can do a wait, orradeon_ring_allocthat can wait onradeon_fence_wait_next, etc.The IB test itself doesn't needs to be protected by the exclusive lock. Only everything between
radeon_save_bios_scratch_regsandradeon_ring_restore.
I'm not sure about that, what do you want to do if the ring tests fail? Do you have to retake the exclusive lock?
~Maarten
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Christian König
maintainerRe: [PATCH 09/19] drm/radeon: handle lockup in delayed work, v2
Am 04.08.2014 um 16:58 schrieb Maarten Lankhorst:
Quoted 8 lines
op 04-08-14 16:45, Christian König schreef:
Quoted 7 lines
Am 04.08.2014 um 16:40 schrieb Maarten Lankhorst:
Quoted 6 lines
op 04-08-14 16:37, Christian König schreef:
Quoted 5 lines
Quoted 1 line
It'a pain to deal with gpu reset.
Yeah, well that's nothing new.
Quoted 2 lines
I've now tried other solutions but that would mean reverting to the old style during gpu lockup recovery, and only running the delayed work when !lockup. But this meant that the timeout was useless to add. I think the cleanest is keeping the v2 patch, because potentially any waiting code can be called during lockup recovery.
Quoted 8 lines
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines
The lockup code itself should never call any waiting code and V2 doesn't seem to handle a couple of cases correctly either.
How about moving the fence waiting out of the reset code?
What cases did I miss then?
I'm curious how you want to move the fence waiting out of reset, when there are so many places that could potentially wait, like
radeon_ib_getcan callradeon_sa_bo_newwhich can do a wait, orradeon_ring_allocthat can wait onradeon_fence_wait_next, etc.The IB test itself doesn't needs to be protected by the exclusive lock. Only everything between
radeon_save_bios_scratch_regsandradeon_ring_restore.I'm not sure about that, what do you want to do if the ring tests fail? Do you have to retake the exclusive lock?
Just set need_reset again and return -EAGAIN, that should have mostly the same effect as what we are doing right now.
Christian.
Quoted 3 lines
~Maarten
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 09/19] drm/radeon: handle lockup in delayed work, v2
op 04-08-14 17:04, Christian König schreef:
Quoted 11 lines
Am 04.08.2014 um 16:58 schrieb Maarten Lankhorst:
Quoted 10 lines
op 04-08-14 16:45, Christian König schreef:
Quoted 9 lines
Am 04.08.2014 um 16:40 schrieb Maarten Lankhorst:
Quoted 8 lines
op 04-08-14 16:37, Christian König schreef:
Quoted 7 lines
Quoted 1 line
It'a pain to deal with gpu reset.
Yeah, well that's nothing new.
Quoted 2 lines
I've now tried other solutions but that would mean reverting to the old style during gpu lockup recovery, and only running the delayed work when !lockup. But this meant that the timeout was useless to add. I think the cleanest is keeping the v2 patch, because potentially any waiting code can be called during lockup recovery.
The lockup code itself should never call any waiting code and V2 doesn't seem to handle a couple of cases correctly either.
Quoted 8 lines
Quoted 6 lines
Quoted 5 lines
Quoted 4 lines
Quoted 1 line
How about moving the fence waiting out of the reset code?
What cases did I miss then?
I'm curious how you want to move the fence waiting out of reset, when there are so many places that could potentially wait, like
radeon_ib_getcan callradeon_sa_bo_newwhich can do a wait, orradeon_ring_allocthat can wait onradeon_fence_wait_next, etc.The IB test itself doesn't needs to be protected by the exclusive lock. Only everything between
radeon_save_bios_scratch_regsandradeon_ring_restore.I'm not sure about that, what do you want to do if the ring tests fail? Do you have to retake the exclusive lock?
Just set
need_resetagain and return-EAGAIN, that should have mostly the same effect as what we are doing right now.
Yeah, except for the locking the ttm delayed workqueue, but that bool should be easy to save/restore. I think this could work.
~Maarten
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Christian König
maintainerRe: [PATCH 09/19] drm/radeon: handle lockup in delayed work, v2
Am 04.08.2014 um 17:09 schrieb Maarten Lankhorst:
Quoted 13 lines
op 04-08-14 17:04, Christian König schreef:
Quoted 12 lines
Am 04.08.2014 um 16:58 schrieb Maarten Lankhorst:
Quoted 11 lines
op 04-08-14 16:45, Christian König schreef:
Quoted 10 lines
Am 04.08.2014 um 16:40 schrieb Maarten Lankhorst:
Quoted 9 lines
op 04-08-14 16:37, Christian König schreef:
Quoted 8 lines
Quoted 1 line
It'a pain to deal with gpu reset.
Yeah, well that's nothing new.
Quoted 2 lines
I've now tried other solutions but that would mean reverting to the old style during gpu lockup recovery, and only running the delayed work when !lockup. But this meant that the timeout was useless to add. I think the cleanest is keeping the v2 patch, because potentially any waiting code can be called during lockup recovery.
The lockup code itself should never call any waiting code and V2 doesn't seem to handle a couple of cases correctly either.
How about moving the fence waiting out of the reset code?
Quoted 8 lines
Quoted 6 lines
Quoted 5 lines
Quoted 4 lines
Quoted 3 lines
What cases did I miss then?
I'm curious how you want to move the fence waiting out of reset, when there are so many places that could potentially wait, like
radeon_ib_getcan callradeon_sa_bo_newwhich can do a wait, orradeon_ring_allocthat can wait onradeon_fence_wait_next, etc.The IB test itself doesn't needs to be protected by the exclusive lock. Only everything between
radeon_save_bios_scratch_regsandradeon_ring_restore.I'm not sure about that, what do you want to do if the ring tests fail? Do you have to retake the exclusive lock?
Just set
need_resetagain and return-EAGAIN, that should have mostly the same effect as what we are doing right now.Yeah, except for the locking the ttm delayed workqueue, but that bool should be easy to save/restore. I think this could work.
Actually you could activate the delayed workqueue much earlier as well.
Thinking more about it that sounds like a bug in the current code, because we probably want the workqueue activated before waiting for the fence.
Christian.
Quoted 3 lines
~Maarten
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 09/19] drm/radeon: handle lockup in delayed work, v2
Quoted 19 lines · Christian König
Am 04.08.2014 um 17:09 schrieb Maarten Lankhorst:
Quoted 18 lines
op 04-08-14 17:04, Christian König schreef:
Quoted 17 lines
Am 04.08.2014 um 16:58 schrieb Maarten Lankhorst:
Quoted 16 lines
op 04-08-14 16:45, Christian König schreef:
Quoted 7 lines
Am 04.08.2014 um 16:40 schrieb Maarten Lankhorst:
Quoted 6 lines
op 04-08-14 16:37, Christian König schreef:
Quoted 5 lines
Quoted 1 line
It'a pain to deal with gpu reset.
Yeah, well that's nothing new.
Quoted 2 lines
I've now tried other solutions but that would mean reverting to the old style during gpu lockup recovery, and only running the delayed work when !lockup. But this meant that the timeout was useless to add. I think the cleanest is keeping the v2 patch, because potentially any waiting code can be called during lockup recovery.
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines
The lockup code itself should never call any waiting code and V2 doesn't seem to handle a couple of cases correctly either.
How about moving the fence waiting out of the reset code?
What cases did I miss then?
I'm curious how you want to move the fence waiting out of reset, when there are so many places that could potentially wait, like
radeon_ib_getcan callradeon_sa_bo_newwhich can do a wait, orradeon_ring_allocthat can wait onradeon_fence_wait_next, etc.The IB test itself doesn't needs to be protected by the exclusive lock. Only everything between
radeon_save_bios_scratch_regsandradeon_ring_restore.I'm not sure about that, what do you want to do if the ring tests fail? Do you have to retake the exclusive lock?
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
Just set
need_resetagain and return-EAGAIN, that should have mostly the same effect as what we are doing right now.Yeah, except for the locking the ttm delayed workqueue, but that bool should be easy to save/restore. I think this could work.
Actually you could activate the delayed workqueue much earlier as well.
Thinking more about it that sounds like a bug in the current code, because we probably want the workqueue activated before waiting for the fence.
We've actually had a similar issue on i915 where when userspace never waited for rendering (some shitty userspace drivers did that way back) we never noticed that the gpu died. So launching the hangcheck/stuck wait worker (we have both too) right away is what we do now. -Daniel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch
Re: [PATCH 09/19] drm/radeon: handle lockup in delayed work, v2
In reply to Christian Königop 04-08-14 19:04, Christian König schreef:
Quoted 18 lines
Am 04.08.2014 um 17:09 schrieb Maarten Lankhorst:
Quoted 17 lines
op 04-08-14 17:04, Christian König schreef:
Quoted 16 lines
Am 04.08.2014 um 16:58 schrieb Maarten Lankhorst:
Quoted 15 lines
op 04-08-14 16:45, Christian König schreef:
Quoted 14 lines
Am 04.08.2014 um 16:40 schrieb Maarten Lankhorst:
Quoted 4 lines
op 04-08-14 16:37, Christian König schreef:
Quoted 3 lines
Quoted 1 line
It'a pain to deal with gpu reset.
Yeah, well that's nothing new.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
I've now tried other solutions but that would mean reverting to the old style during gpu lockup recovery, and only running the delayed work when !lockup. But this meant that the timeout was useless to add. I think the cleanest is keeping the v2 patch, because potentially any waiting code can be called during lockup recovery.
The lockup code itself should never call any waiting code and V2 doesn't seem to handle a couple of cases correctly either.
How about moving the fence waiting out of the reset code?
What cases did I miss then?
I'm curious how you want to move the fence waiting out of reset, when there are so many places that could potentially wait, like
radeon_ib_getcan callradeon_sa_bo_newwhich can do a wait, orradeon_ring_allocthat can wait onradeon_fence_wait_next, etc.The IB test itself doesn't needs to be protected by the exclusive lock. Only everything between
radeon_save_bios_scratch_regsandradeon_ring_restore.
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Quoted 1 line
I'm not sure about that, what do you want to do if the ring tests fail? Do you have to retake the exclusive lock?
Just set
need_resetagain and return-EAGAIN, that should have mostly the same effect as what we are doing right now.Yeah, except for the locking the ttm delayed workqueue, but that bool should be easy to save/restore. I think this could work.
Actually you could activate the delayed workqueue much earlier as well.
Thinking more about it that sounds like a bug in the current code, because we probably want the workqueue activated before waiting for the fence.
Ok, how about this?
Because of the downgrade_write, a second gpu reset can't be started until the first finishes.
I'm uncertain about it, I think I might either have to stop calling radeon_restore_bios_scratch_regs a second time, or I should call save_bios_scratch_regs the second time around.
Also it feels like drm_helper_resume_force_mode should be called before downgrading exclusive_lock, but it might depend on PM restore. Tough! Maybe move both calls to before downgrade_write?
commit 3644aae8581a15e3a935279287c397f7eab400ff
Author: Maarten Lankhorst <[email protected]> Date: Tue Aug 5 10:29:23 2014 +0200
drm/radeon: take exclusive_lock in read mode during ring tests
drivers/gpu/drm/radeon/radeon.h +1 -1
@@ -2286,7 +2286,7 @@ struct radeon_device {bool need_dma32;bool accel_working;bool fastfb_working;/* IGP feature*/ -bool needs_reset; +bool needs_reset, in_reset;struct radeon_surface_reg surface_regs[RADEON_GEM_MAX_SURFACES ];const struct firmware *me_fw;/* all family ME firmware */ const struct firmware *pfp_fw;/* r6/700 PFP firmware */
drivers/gpu/drm/radeon/radeon_device.c +38 -25
115 lines not on this page · raw message
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 10/19 drm/radeon: add timeout argument to radeon_fence_wait_seq
In reply to Maarten LankhorstThis makes it possible to wait for a specific amount of time, rather than wait until infinity.
--- drivers/gpu/drm/radeon/radeon_fence.c | 50 ++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 20 deletions(-)
drivers/gpu/drm/radeon/radeon_fence.c +30 -20
@@ -318,22 +318,25 @@ static bool radeon_fence_any_seq_signaled(struct radeon_device *rdev, u64 *seq) }/** -* radeon_fence_wait_seq - wait for a specific sequence numbers +* radeon_fence_wait_seq_timeout - wait for a specific sequence numbers * * @rdev: radeon device pointer * @target_seq: sequence number(s) we want to wait for * @intr: use interruptable sleep +* @timeout: maximum time to wait, or MAX_SCHEDULE_TIMEOUT for infinite wait * * Wait for the requested sequence number(s) to be written by any ring * (all asics). Sequnce number array is indexed by ring id. * @intr selects whether to use interruptable (true) or non-interruptable * (false) sleep when waiting for the sequence number. Helper function * for radeon_fence_wait_*(). -* Returns 0 if the sequence number has passed, error for all other cases. +* Returns remaining time if the sequence number has passed, 0 when +* the wait timeout, or an error for all other cases. * -EDEADLK is returned when a GPU lockup has been detected. */ -static int radeon_fence_wait_seq (struct radeon_device *rdev,u64 *target_seq, -bool intr) +static long radeon_fence_wait_seq_timeout (struct radeon_device *rdev, +u64 *target_seq,bool intr, +long timeout) {uint64_t last_seq[RADEON_NUM_RINGS ];bool signaled;
@@ -355,11 +358,11 @@ static int radeon_fence_wait_seq(struct radeon_device *rdev, u64 *target_seq,if (intr) { r =wait_event_interruptible_timeout (rdev->fence_queue, ( (signaled =radeon_fence_any_seq_signaled (rdev, target_seq)) - || rdev->needs_reset),MAX_SCHEDULE_TIMEOUT ); + || rdev->needs_reset), timeout); }else { r =wait_event_timeout (rdev->fence_queue, ( (signaled =radeon_fence_any_seq_signaled (rdev, target_seq)) - || rdev->needs_reset),MAX_SCHEDULE_TIMEOUT ); + || rdev->needs_reset), timeout); }for (i =0 ; i <RADEON_NUM_RINGS ; ++i) {
@@ -370,20 +373,22 @@ static int radeon_fence_wait_seq(struct radeon_device *rdev, u64 *target_seq,trace_radeon_fence_wait_end (rdev->ddev, i, target_seq[i]); } -if (r <0 ) +if (r <=0 )return r;if (rdev->needs_reset)return -EDEADLK ; + + timeout = r; } -return 0 ; +return timeout; }/** * radeon_fence_wait - wait for a fence to signal * * @fence: radeon fence object -* @intr: use interruptable sleep +* @intr: use interruptible sleep * * Wait for the requested fence to signal (all asics). * @intr selects whether to use interruptable (true) or non-interruptable
@@ -393,7 +398,7 @@ static int radeon_fence_wait_seq(struct radeon_device *rdev, u64 *target_seq,int radeon_fence_wait (struct radeon_fence *fence,bool intr) {uint64_t seq[RADEON_NUM_RINGS ] = {}; -int r; +long r;if (fence ==NULL ) {WARN (1 ,"Querying an invalid fence : %p !\n" , fence);
@@ -404,9 +409,10 @@ int radeon_fence_wait(struct radeon_fence *fence, bool intr)if (seq[fence->ring] ==RADEON_FENCE_SIGNALED_SEQ )return 0 ; - r =radeon_fence_wait_seq (fence->rdev, seq, intr); -if (r) + r =radeon_fence_wait_seq_timeout (fence->rdev, seq, intr,MAX_SCHEDULE_TIMEOUT ); +if (r <0 ) {return r; + } fence->seq =RADEON_FENCE_SIGNALED_SEQ ;return 0 ;
@@ -431,7 +437,7 @@ int radeon_fence_wait_any(struct radeon_device *rdev, {uint64_t seq[RADEON_NUM_RINGS ];unsigned i, num_rings =0 ; -int r; +long r;for (i =0 ; i <RADEON_NUM_RINGS ; ++i) { seq[i] =0 ;
@@ -452,8 +458,8 @@ int radeon_fence_wait_any(struct radeon_device *rdev,if (num_rings ==0 )return -ENOENT ; - r =radeon_fence_wait_seq (rdev, seq, intr); -if (r) { + r =radeon_fence_wait_seq_timeout (rdev, seq, intr,MAX_SCHEDULE_TIMEOUT ); +if (r <0 ) {return r; }return 0 ;
@@ -472,6 +478,7 @@ int radeon_fence_wait_any(struct radeon_device *rdev,int radeon_fence_wait_next (struct radeon_device *rdev,int ring) {uint64_t seq[RADEON_NUM_RINGS ] = {}; +long r; seq[ring] =atomic64_read (&rdev->fence_drv[ring].last_seq) +1ULL ;if (seq[ring] >= rdev->fence_drv[ring].sync_seq[ring]) {
@@ -479,7 +486,10 @@ int radeon_fence_wait_next(struct radeon_device *rdev, int ring)already the last emited fence */ return -ENOENT ; } -return radeon_fence_wait_seq (rdev, seq, false); + r =radeon_fence_wait_seq_timeout (rdev, seq, false,MAX_SCHEDULE_TIMEOUT ); +if (r <0 ) +return r; +return 0 ; }/**
@@ -495,18 +505,18 @@ int radeon_fence_wait_next(struct radeon_device *rdev, int ring)int radeon_fence_wait_empty (struct radeon_device *rdev,int ring) {uint64_t seq[RADEON_NUM_RINGS ] = {}; -int r; +long r; seq[ring] = rdev->fence_drv[ring].sync_seq[ring];if (!seq[ring])return 0 ; - r =radeon_fence_wait_seq (rdev, seq, false); -if (r) { + r =radeon_fence_wait_seq_timeout (rdev, seq, false,MAX_SCHEDULE_TIMEOUT ); +if (r <0 ) {if (r == -EDEADLK )return -EDEADLK ; -dev_err (rdev->dev,"error waiting for ring[%d] to become idle (%d)\n" , +dev_err (rdev->dev,"error waiting for ring[%d] to become idle (%ld)\n" , ring, r); }return 0 ;
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 11/19 drm/radeon: use common fence implementation for fences, v2
In reply to Maarten LankhorstChanges since v1:
- Kill the sw interrupt dance, add and use radeon_irq_kms_sw_irq_get_delayed instead.
- Change custom wait function, lockdep complained about it. Holding exclusive_lock in the wait function might cause deadlocks. Instead do all the processing in .enable_signaling, and wait on the global fence_queue to pick up gpu resets.
- Process all fences in radeon_gpu_reset after reset to close a race with the trylock in enable_signaling.
--- drivers/gpu/drm/radeon/radeon.h | 18 +- drivers/gpu/drm/radeon/radeon_device.c | 22 ++- drivers/gpu/drm/radeon/radeon_fence.c | 263 +++++++++++++++++++++++++++---- drivers/gpu/drm/radeon/radeon_irq_kms.c | 43 +++++ 4 files changed, 293 insertions(+), 53 deletions(-)
drivers/gpu/drm/radeon/radeon.h +9 -9
@@ -64,6 +64,7 @@#include <linux/wait.h> #include <linux/list.h> #include <linux/kref.h> +#include <linux/fence.h> #include <ttm/ttm_bo_api.h> #include <ttm/ttm_bo_driver.h>
@@ -116,9 +117,6 @@ extern int radeon_deep_color;#define RADEONFB_CONN_LIMIT 4#define RADEON_BIOS_NUM_SCRATCH 8 -/* fence seq are set to this number when signaled */ -#define RADEON_FENCE_SIGNALED_SEQ 0LL -/* internal ring indices */ /* r1xx+ has gfx CP ring */ #define RADEON_RING_TYPE_GFX_INDEX 0
@@ -352,12 +350,15 @@ struct radeon_fence_driver { };struct radeon_fence { +struct fence base; +struct radeon_device *rdev; -struct kref kref;/* protected by radeon_fence.lock */ uint64_t seq;/* RB, DMA, etc. */ unsigned ring; + +wait_queue_t fence_wake; };int radeon_fence_driver_start_ring (struct radeon_device *rdev,int ring);
@@ -769,6 +770,7 @@ struct radeon_irq {int radeon_irq_kms_init (struct radeon_device *rdev);void radeon_irq_kms_fini (struct radeon_device *rdev);void radeon_irq_kms_sw_irq_get (struct radeon_device *rdev,int ring); +void radeon_irq_kms_sw_irq_get_delayed (struct radeon_device *rdev,int ring);void radeon_irq_kms_sw_irq_put (struct radeon_device *rdev,int ring);void radeon_irq_kms_pflip_irq_get (struct radeon_device *rdev,int crtc);void radeon_irq_kms_pflip_irq_put (struct radeon_device *rdev,int crtc);
@@ -2276,6 +2278,7 @@ struct radeon_device {struct radeon_mman mman;struct radeon_fence_driver fence_drv[RADEON_NUM_RINGS ];wait_queue_head_t fence_queue; +unsigned fence_context;struct mutex ring_lock;struct radeon_ring ring[RADEON_NUM_RINGS ];bool ib_pool_ready;
@@ -2314,6 +2317,8 @@ struct radeon_device {struct work_struct hotplug_work;struct work_struct audio_work;struct work_struct reset_work; +struct work_struct delayed_irq_work; +int num_crtc;/* number of crtcs */ struct mutex dc_hw_i2c_mutex;/* display controller hw i2c mutex */ bool has_uvd;
@@ -2366,11 +2371,6 @@ u32 cik_mm_rdoorbell(struct radeon_device *rdev, u32 index);void cik_mm_wdoorbell (struct radeon_device *rdev,u32 index,u32 v);/* -* Cast helper -*/ -#define to_radeon_fence (p) ((struct radeon_fence *)(p)) - -/* * Registers read & write functions. */ #define RREG8 (reg) readb((rdev->rmmio) + (reg))
drivers/gpu/drm/radeon/radeon_device.c +16 -6
@@ -1213,6 +1213,7 @@ int radeon_device_init(struct radeon_device *rdev,for (i =0 ; i <RADEON_NUM_RINGS ; i++) { rdev->ring[i].idx = i; } + rdev->fence_context =fence_context_alloc (RADEON_NUM_RINGS ); DRM_INFO("initializing kernel modesetting (%s 0x%04X:0x%04X 0x%04X:0x%04X).\n", radeon_family_name[rdev->family], pdev->vendor, pdev->device,
@@ -1622,15 +1623,13 @@ int radeon_gpu_reset(struct radeon_device *rdev)bool saved = false; -int i, r; +int i, r =0 ;int resched;down_write (&rdev->exclusive_lock); -if (!rdev->needs_reset) { -up_write (&rdev->exclusive_lock); -return 0 ; - } +if (!rdev->needs_reset) + goto out; rdev->needs_reset = false;
@@ -1697,7 +1696,18 @@ retry:dev_info (rdev->dev,"GPU reset failed\n" ); } -up_write (&rdev->exclusive_lock); +out: +/* +* force all waiters to recheck, some may have been +* added while the exclusive_lock was unavailable +*/ +downgrade_write (&rdev->exclusive_lock); +for (i =0 ; i <RADEON_NUM_RINGS ; ++i) { +if (rdev->ring[i].ready) +radeon_fence_process (rdev, i); + } +wake_up_all (&rdev->fence_queue); +up_read (&rdev->exclusive_lock);return r; }
drivers/gpu/drm/radeon/radeon_fence.c +225 -38
347 lines not on this page · raw message
drivers/gpu/drm/radeon/radeon_irq_kms.c +43 -0
67 lines not on this page · raw message
PATCH 12/19 drm/qxl: rework to new fence interface
In reply to Maarten LankhorstFinal driver! \o/
This is not a proper dma_fence because the hardware may never signal anything, so don't use dma-buf with qxl, ever.
--- drivers/gpu/drm/qxl/Makefile | 2 drivers/gpu/drm/qxl/qxl_cmd.c | 5 - drivers/gpu/drm/qxl/qxl_debugfs.c | 12 ++- drivers/gpu/drm/qxl/qxl_drv.h | 22 ++--- drivers/gpu/drm/qxl/qxl_fence.c | 87 ------------------- drivers/gpu/drm/qxl/qxl_kms.c | 2 drivers/gpu/drm/qxl/qxl_object.c | 2 drivers/gpu/drm/qxl/qxl_release.c | 166 ++++++++++++++++++++++++++++++++----- drivers/gpu/drm/qxl/qxl_ttm.c | 97 ++++++++++++---------- 9 files changed, 220 insertions(+), 175 deletions(-) delete mode 100644 drivers/gpu/drm/qxl/qxl_fence.c
drivers/gpu/drm/qxl/Makefile +1 -1
@@ -4,6 +4,6 @@ ccflags-y := -Iinclude/drm -qxl-y := qxl_drv.o qxl_kms.o qxl_display.o qxl_ttm.o qxl_fb.o qxl_object.o qxl_gem.o qxl_cmd.o qxl_image.o qxl_draw.o qxl_debugfs.o qxl_irq.o qxl_dumb.o qxl_ioctl.o qxl_fence.o qxl_release.o +qxl-y := qxl_drv.o qxl_kms.o qxl_display.o qxl_ttm.o qxl_fb.o qxl_object.o qxl_gem.o qxl_cmd.o qxl_image.o qxl_draw.o qxl_debugfs.o qxl_irq.o qxl_dumb.o qxl_ioctl.o qxl_release.o obj-$(CONFIG_DRM_QXL)+= qxl.o
drivers/gpu/drm/qxl/qxl_cmd.c +0 -5
@@ -620,11 +620,6 @@ static int qxl_reap_surf(struct qxl_device *qdev, struct qxl_bo *surf, bool stalif (ret == -EBUSY )return -EBUSY ; -if (surf->fence.num_active_releases >0 && stall == false) { -qxl_bo_unreserve (surf); -return -EBUSY ; - } -if (stall)mutex_unlock (&qdev->surf_evict_mutex);
drivers/gpu/drm/qxl/qxl_debugfs.c +11 -1
@@ -57,11 +57,21 @@ qxl_debugfs_buffers_info(struct seq_file *m, void *data)struct qxl_device *qdev = node->minor->dev->dev_private;struct qxl_bo *bo; +spin_lock (&qdev->release_lock);list_for_each_entry (bo, &qdev->gem.objects, list) { +struct reservation_object_list *fobj; +int rel; + +rcu_read_lock (); + fobj =rcu_dereference (bo->tbo.resv->fence); + rel = fobj ? fobj->shared_count :0 ; +rcu_read_unlock (); +seq_printf (m,"size %ld, pc %d, sync obj %p, num releases %d\n" , (unsigned long )bo->gem_base.size, bo->pin_count, - bo->tbo.sync_obj, bo->fence.num_active_releases); + bo->tbo.sync_obj, rel); } +spin_unlock (&qdev->release_lock);return 0 ; }
drivers/gpu/drm/qxl/qxl_drv.h +8 -14
@@ -31,6 +31,7 @@* Definitions taken from spice-protocol, plus kernel driver specific bits. */ +#include <linux/fence.h> #include <linux/workqueue.h> #include <linux/firmware.h> #include <linux/platform_device.h>
@@ -95,13 +96,6 @@ enum { QXL_INTERRUPT_IO_CMD |\ QXL_INTERRUPT_CLIENT_MONITORS_CONFIG) -struct qxl_fence { -struct qxl_device *qdev; -uint32_t num_active_releases; -uint32_t *release_ids; -struct radix_tree_root tree; -}; - struct qxl_bo { /* Protected by gem.mutex */ struct list_head list;
@@ -113,13 +107,13 @@ struct qxl_bo {unsigned pin_count;void *kptr;int type; +/* Constant after initialization */ struct drm_gem_object gem_base;bool is_primary;/* is this now a primary surface */ bool hw_surf_alloc;struct qxl_surface surf;uint32_t surface_id; -struct qxl_fence fence;/* per bo fence - list of releases */ struct qxl_release *surf_create; };#define gem_to_qxl_bo (gobj) container_of((gobj), struct qxl_bo, gem_base)
@@ -191,6 +185,8 @@ enum {* spice-protocol/qxl_dev.h */ #define QXL_MAX_RES 96struct qxl_release { +struct fence base; +int id;int type;uint32_t release_offset;
@@ -284,7 +280,11 @@ struct qxl_device {uint8_t slot_gen_bits;uint64_t va_slot_mask; +/* XXX: when rcu becomes available, release_lock can be killed */ +spinlock_t release_lock; +spinlock_t fence_lock;struct idr release_idr; +uint32_t release_seqno;spinlock_t release_idr_lock;struct mutex async_io_mutex;unsigned int last_sent_io_cmd;
@@ -561,10 +561,4 @@ qxl_surface_lookup(struct drm_device *dev, int surface_id);void qxl_surface_evict (struct qxl_device *qdev,struct qxl_bo *surf,bool freeing);int qxl_update_surface (struct qxl_device *qdev,struct qxl_bo *surf); -/* qxl_fence.c */ -void qxl_fence_add_release_locked (struct qxl_fence *qfence,uint32_t rel_id); -int qxl_fence_remove_release (struct qxl_fence *qfence,uint32_t rel_id); -int qxl_fence_init (struct qxl_device *qdev,struct qxl_fence *qfence); -void qxl_fence_fini (struct qxl_fence *qfence); -#endif
drivers/gpu/drm/qxl/qxl_fence.c deleted +0 -87
87 lines not on this page · raw message
drivers/gpu/drm/qxl/qxl_kms.c +2 -0
@@ -223,6 +223,8 @@ static int qxl_device_init(struct qxl_device *qdev,idr_init (&qdev->release_idr);spin_lock_init (&qdev->release_idr_lock); +spin_lock_init (&qdev->release_lock); +spin_lock_init (&qdev->fence_lock);idr_init (&qdev->surf_id_idr);spin_lock_init (&qdev->surf_id_idr_lock);
drivers/gpu/drm/qxl/qxl_object.c +0 -2
@@ -36,7 +36,6 @@ static void qxl_ttm_bo_destroy(struct ttm_buffer_object *tbo) qdev = (struct qxl_device *)bo->gem_base.dev->dev_private;qxl_surface_evict (qdev, bo, false); -qxl_fence_fini (&bo->fence);mutex_lock (&qdev->gem.mutex);list_del_init (&bo->list);mutex_unlock (&qdev->gem.mutex);
@@ -99,7 +98,6 @@ int qxl_bo_create(struct qxl_device *qdev, bo->type = domain; bo->pin_count = pinned ?1 :0 ; bo->surface_id =0 ; -qxl_fence_init (qdev, &bo->fence);INIT_LIST_HEAD (&bo->list);if (surf)
drivers/gpu/drm/qxl/qxl_release.c +144 -22
266 lines not on this page · raw message
drivers/gpu/drm/qxl/qxl_ttm.c +54 -43
137 lines not on this page · raw message
PATCH 13/19 drm/vmwgfx: get rid of different types of fence_flags entirely
In reply to Maarten LankhorstOnly one type was ever used. This is needed to simplify the fence support in the next commit.
--- drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c | 5 +-- drivers/gpu/drm/vmwgfx/vmwgfx_drv.h | 1 - drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c | 14 ++------- drivers/gpu/drm/vmwgfx/vmwgfx_fence.c | 50 ++++++++++++------------------- drivers/gpu/drm/vmwgfx/vmwgfx_fence.h | 8 +---- 5 files changed, 26 insertions(+), 52 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c +1 -4
@@ -792,15 +792,12 @@ static int vmw_sync_obj_flush(void *sync_obj)static bool vmw_sync_obj_signaled (void *sync_obj) { -return vmw_fence_obj_signaled ((struct vmw_fence_obj *) sync_obj, -DRM_VMW_FENCE_FLAG_EXEC ); - +return vmw_fence_obj_signaled ((struct vmw_fence_obj *) sync_obj); }static int vmw_sync_obj_wait (void *sync_obj,bool lazy,bool interruptible) {return vmw_fence_obj_wait ((struct vmw_fence_obj *) sync_obj, -DRM_VMW_FENCE_FLAG_EXEC , lazy, interruptible,VMW_FENCE_WAIT_TIMEOUT ); }
drivers/gpu/drm/vmwgfx/vmwgfx_drv.h +0 -1
@@ -342,7 +342,6 @@ struct vmw_sw_context{uint32_t *cmd_bounce;uint32_t cmd_bounce_size;struct list_head resource_list; -uint32_t fence_flags;struct ttm_buffer_object *cur_query_bo;struct list_head res_relocations;uint32_t *buf_start;
drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c +3 -11
@@ -350,8 +350,6 @@ static int vmw_bo_to_validate_list(struct vmw_sw_context *sw_context, vval_buf->validate_as_mob = validate_as_mob; } - sw_context->fence_flags |=DRM_VMW_FENCE_FLAG_EXEC ; -if (p_val_node) *p_val_node = val_node;
@@ -2337,13 +2335,9 @@ int vmw_execbuf_fence_commands(struct drm_file *file_priv,if (p_handle !=NULL ) ret =vmw_user_fence_create (file_priv, dev_priv->fman, - sequence, -DRM_VMW_FENCE_FLAG_EXEC , - p_fence, p_handle); + sequence, p_fence, p_handle);else - ret =vmw_fence_create (dev_priv->fman, sequence, -DRM_VMW_FENCE_FLAG_EXEC , - p_fence); + ret =vmw_fence_create (dev_priv->fman, sequence, p_fence);if (unlikely (ret !=0 && !synced)) { (void) vmw_fallback_wait(dev_priv, false, false,
@@ -2416,8 +2410,7 @@ vmw_execbuf_copy_fence_user(struct vmw_private *dev_priv,ttm_ref_object_base_unref (vmw_fp->tfile, fence_handle,TTM_REF_USAGE );DRM_ERROR ("Fence copy error. Syncing.\n" ); - (void )vmw_fence_obj_wait (fence, fence->signal_mask, - false, false, + (void )vmw_fence_obj_wait (fence, false, false,VMW_FENCE_WAIT_TIMEOUT ); } }
@@ -2469,7 +2462,6 @@ int vmw_execbuf_process(struct drm_file *file_priv, sw_context->fp =vmw_fpriv (file_priv); sw_context->cur_reloc =0 ; sw_context->cur_val_buf =0 ; - sw_context->fence_flags =0 ;INIT_LIST_HEAD (&sw_context->resource_list); sw_context->cur_query_bo = dev_priv->pinned_bo; sw_context->last_query_ctx =NULL ;
drivers/gpu/drm/vmwgfx/vmwgfx_fence.c +20 -30
170 lines not on this page · raw message
drivers/gpu/drm/vmwgfx/vmwgfx_fence.h +2 -6
@@ -56,7 +56,6 @@ struct vmw_fence_obj {struct vmw_fence_manager *fman;struct list_head head;uint32_t signaled; -uint32_t signal_mask;struct list_head seq_passed_actions;void (*destroy)(struct vmw_fence_obj *fence);wait_queue_head_t queue;
@@ -74,10 +73,9 @@ vmw_fence_obj_reference(struct vmw_fence_obj *fence);extern void vmw_fences_update (struct vmw_fence_manager *fman); -extern bool vmw_fence_obj_signaled (struct vmw_fence_obj *fence, -uint32_t flags); +extern bool vmw_fence_obj_signaled (struct vmw_fence_obj *fence); -extern int vmw_fence_obj_wait (struct vmw_fence_obj *fence,uint32_t flags, +extern int vmw_fence_obj_wait (struct vmw_fence_obj *fence,bool lazy,bool interruptible,unsigned long timeout);
@@ -85,13 +83,11 @@ extern void vmw_fence_obj_flush(struct vmw_fence_obj *fence);extern int vmw_fence_create (struct vmw_fence_manager *fman,uint32_t seqno, -uint32_t mask,struct vmw_fence_obj **p_fence);extern int vmw_user_fence_create (struct drm_file *file_priv,struct vmw_fence_manager *fman,uint32_t sequence, -uint32_t mask,struct vmw_fence_obj **p_fence,uint32_t *p_handle);
PATCH 14/19 drm/vmwgfx: rework to new fence interface
In reply to Maarten Lankhorst--- drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c | 2 drivers/gpu/drm/vmwgfx/vmwgfx_fence.c | 299 ++++++++++++++++++------------ drivers/gpu/drm/vmwgfx/vmwgfx_fence.h | 29 ++- drivers/gpu/drm/vmwgfx/vmwgfx_resource.c | 9 - 4 files changed, 200 insertions(+), 139 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c +1 -1
@@ -2389,7 +2389,7 @@ vmw_execbuf_copy_fence_user(struct vmw_private *dev_priv,BUG_ON (fence ==NULL ); fence_rep.handle = fence_handle; - fence_rep.seqno = fence->seqno; + fence_rep.seqno = fence->base.seqno;vmw_update_seqno (dev_priv, &dev_priv->fifo); fence_rep.passed_seqno = dev_priv->last_read_seqno; }
drivers/gpu/drm/vmwgfx/vmwgfx_fence.c +175 -124
514 lines not on this page · raw message
drivers/gpu/drm/vmwgfx/vmwgfx_fence.h +20 -9
@@ -27,6 +27,8 @@#ifndef _VMWGFX_FENCE_H_ +#include <linux/fence.h> +#define VMW_FENCE_WAIT_TIMEOUT (5*HZ)struct vmw_private ;
@@ -50,15 +52,11 @@ struct vmw_fence_action { };struct vmw_fence_obj { -struct kref kref; -u32 seqno; +struct fence base; -struct vmw_fence_manager *fman;struct list_head head; -uint32_t signaled;struct list_head seq_passed_actions;void (*destroy)(struct vmw_fence_obj *fence); -wait_queue_head_t queue; }; extern struct vmw_fence_manager *
@@ -66,10 +64,23 @@ vmw_fence_manager_init(struct vmw_private *dev_priv);extern void vmw_fence_manager_takedown (struct vmw_fence_manager *fman); -extern void vmw_fence_obj_unreference (struct vmw_fence_obj **fence_p); - -extern struct vmw_fence_obj * -vmw_fence_obj_reference (struct vmw_fence_obj *fence); +static inline void +vmw_fence_obj_unreference (struct vmw_fence_obj **fence_p) +{ +struct vmw_fence_obj *fence = *fence_p; + + *fence_p =NULL ; +if (fence) +fence_put (&fence->base); +} + +static inline struct vmw_fence_obj * +vmw_fence_obj_reference (struct vmw_fence_obj *fence) +{ +if (fence) +fence_get (&fence->base); +return fence; +}extern void vmw_fences_update (struct vmw_fence_manager *fman);
drivers/gpu/drm/vmwgfx/vmwgfx_resource.c +4 -5
@@ -1419,21 +1419,20 @@ void vmw_fence_single_bo(struct ttm_buffer_object *bo, struct vmw_fence_obj *fence) {struct ttm_bo_device *bdev = bo->bdev; -struct ttm_bo_driver *driver = bdev->driver;struct vmw_fence_obj *old_fence_obj;struct vmw_private *dev_priv = container_of(bdev, struct vmw_private, bdev); -if (fence ==NULL ) +if (fence ==NULL ) {vmw_execbuf_fence_commands (NULL , dev_priv, &fence,NULL ); -else - driver->sync_obj_ref (fence); + }else +vmw_fence_obj_reference (fence); +reservation_object_add_excl_fence (bo->resv, &fence->base); old_fence_obj = bo->sync_obj; bo->sync_obj = fence; -if (old_fence_obj)vmw_fence_obj_unreference (&old_fence_obj); }
PATCH 15/19 drm/ttm: flip the switch, and convert to dma_fence
In reply to Maarten Lankhorst--- drivers/gpu/drm/nouveau/nouveau_bo.c | 48 +------- drivers/gpu/drm/nouveau/nouveau_fence.c | 24 +--- drivers/gpu/drm/nouveau/nouveau_fence.h | 2 drivers/gpu/drm/nouveau/nouveau_gem.c | 16 ++- drivers/gpu/drm/qxl/qxl_debugfs.c | 6 + drivers/gpu/drm/qxl/qxl_drv.h | 2 drivers/gpu/drm/qxl/qxl_kms.c | 1 drivers/gpu/drm/qxl/qxl_object.h | 4 - drivers/gpu/drm/qxl/qxl_release.c | 3 - drivers/gpu/drm/qxl/qxl_ttm.c | 104 ------------------ drivers/gpu/drm/radeon/radeon_cs.c | 10 +- drivers/gpu/drm/radeon/radeon_display.c | 3 - drivers/gpu/drm/radeon/radeon_object.c | 4 - drivers/gpu/drm/radeon/radeon_ttm.c | 34 ------ drivers/gpu/drm/radeon/radeon_uvd.c | 8 + drivers/gpu/drm/radeon/radeon_vm.c | 14 ++ drivers/gpu/drm/ttm/ttm_bo.c | 171 +++++++++++++++++++++--------- drivers/gpu/drm/ttm/ttm_bo_util.c | 23 +--- drivers/gpu/drm/ttm/ttm_execbuf_util.c | 10 -- drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c | 40 ------- drivers/gpu/drm/vmwgfx/vmwgfx_resource.c | 14 +- include/drm/ttm/ttm_bo_api.h | 2 include/drm/ttm/ttm_bo_driver.h | 26 ----- include/drm/ttm/ttm_execbuf_util.h | 10 +- 24 files changed, 193 insertions(+), 386 deletions(-)
drivers/gpu/drm/nouveau/nouveau_bo.c +6 -42
@@ -92,13 +92,13 @@ nv10_bo_get_tile_region(struct drm_device *dev, int i)static void nv10_bo_put_tile_region (struct drm_device *dev,struct nouveau_drm_tile *tile, -struct nouveau_fence *fence) +struct fence *fence) {struct nouveau_drm *drm =nouveau_drm (dev);if (tile) {spin_lock (&drm->tile.lock); - tile->fence =nouveau_fence_ref (fence); + tile->fence =nouveau_fence_ref ((struct nouveau_fence *)fence); tile->used = false;spin_unlock (&drm->tile.lock); }
@@ -965,7 +965,8 @@ nouveau_bo_move_m2mf(struct ttm_buffer_object *bo, int evict, bool intr,if (ret ==0 ) { ret =nouveau_fence_new (chan, false, &fence);if (ret ==0 ) { - ret =ttm_bo_move_accel_cleanup (bo, fence, + ret =ttm_bo_move_accel_cleanup (bo, + &fence->base, evict, no_wait_gpu, new_mem);
@@ -1151,8 +1152,9 @@ nouveau_bo_vm_cleanup(struct ttm_buffer_object *bo, {struct nouveau_drm *drm =nouveau_bdev (bo->bdev);struct drm_device *dev = drm->dev; +struct fence *fence =reservation_object_get_excl (bo->resv); -nv10_bo_put_tile_region (dev, *old_tile, bo->sync_obj); +nv10_bo_put_tile_region (dev, *old_tile, fence); *old_tile = new_tile; }
@@ -1423,47 +1425,14 @@ nouveau_ttm_tt_unpopulate(struct ttm_tt *ttm)ttm_pool_unpopulate (ttm); } -static void -nouveau_bo_fence_unref (void **sync_obj) -{ -nouveau_fence_unref ((struct nouveau_fence **)sync_obj); -} -void nouveau_bo_fence (struct nouveau_bo *nvbo,struct nouveau_fence *fence) {struct reservation_object *resv = nvbo->bo.resv; -nouveau_bo_fence_unref (&nvbo->bo.sync_obj); - nvbo->bo.sync_obj =nouveau_fence_ref (fence); -reservation_object_add_excl_fence (resv, &fence->base); } -static void * -nouveau_bo_fence_ref (void *sync_obj) -{ -return nouveau_fence_ref (sync_obj); -} - -static bool -nouveau_bo_fence_signalled (void *sync_obj) -{ -return nouveau_fence_done (sync_obj); -} - -static int -nouveau_bo_fence_wait (void *sync_obj,bool lazy,bool intr) -{ -return nouveau_fence_wait (sync_obj, lazy, intr); -} - -static int -nouveau_bo_fence_flush (void *sync_obj) -{ -return 0 ; -} -struct ttm_bo_driver nouveau_bo_driver = { .ttm_tt_create = &nouveau_ttm_tt_create, .ttm_tt_populate = &nouveau_ttm_tt_populate,
@@ -1474,11 +1443,6 @@ struct ttm_bo_driver nouveau_bo_driver = { .move_notify = nouveau_bo_move_ntfy, .move = nouveau_bo_move, .verify_access = nouveau_bo_verify_access, - .sync_obj_signaled = nouveau_bo_fence_signalled, - .sync_obj_wait = nouveau_bo_fence_wait, - .sync_obj_flush = nouveau_bo_fence_flush, - .sync_obj_unref = nouveau_bo_fence_unref, - .sync_obj_ref = nouveau_bo_fence_ref, .fault_reserve_notify = &nouveau_ttm_fault_reserve_notify, .io_mem_reserve = &nouveau_ttm_io_mem_reserve, .io_mem_free = &nouveau_ttm_io_mem_free,
drivers/gpu/drm/nouveau/nouveau_fence.c +8 -16
@@ -139,17 +139,18 @@ static bool nouveau_fence_is_signaled(struct fence *f) }void -nouveau_fence_work (struct nouveau_fence *fence, +nouveau_fence_work (struct fence *fence,void (*func)(void *),void *data) {struct nouveau_fence_work *work; -if (fence_is_signaled (&fence->base)) +if (fence_is_signaled (fence)) goto err; work =kmalloc (sizeof (*work),GFP_KERNEL );if (!work) { -WARN_ON (nouveau_fence_wait (fence, false, false)); +WARN_ON (nouveau_fence_wait ((struct nouveau_fence *)fence, + false, false)); goto err; }
@@ -157,7 +158,7 @@ nouveau_fence_work(struct nouveau_fence *fence, work->func = func; work->data = data; -if (fence_add_callback (&fence->base, &work->cb, nouveau_fence_work_cb) <0 ) +if (fence_add_callback (fence, &work->cb, nouveau_fence_work_cb) <0 ) goto err_free;return ;
@@ -322,14 +323,9 @@ nouveau_fence_sync(struct nouveau_bo *nvbo, struct nouveau_channel *chan)struct reservation_object_list *fobj;int ret =0 , i; - fence = nvbo->bo.sync_obj; -if (fence &&fence_is_signaled (fence)) { -nouveau_fence_unref ((struct nouveau_fence **) - &nvbo->bo.sync_obj); - fence =NULL ; - } + fence =reservation_object_get_excl (resv); -if (fence) { +if (fence && !fence_is_signaled (fence)) {struct nouveau_fence *f =container_of (fence, struct nouveau_fence, base);
@@ -345,12 +341,8 @@ nouveau_fence_sync(struct nouveau_bo *nvbo, struct nouveau_channel *chan)if (ret)return ret; - fence =reservation_object_get_excl (resv); -if (fence && !nouveau_local_fence (fence, chan->drm)) - ret =fence_wait (fence, true); - fobj =reservation_object_get_list (resv); -if (!fobj || ret) +if (!fobj)return ret;for (i =0 ; i < fobj->shared_count && !ret; ++i) {
drivers/gpu/drm/nouveau/nouveau_fence.h +1 -1
@@ -26,7 +26,7 @@ void nouveau_fence_unref(struct nouveau_fence **);int nouveau_fence_emit (struct nouveau_fence *,struct nouveau_channel *);bool nouveau_fence_done (struct nouveau_fence *); -void nouveau_fence_work (struct nouveau_fence *,void (*)(void *),void *); +void nouveau_fence_work (struct fence *,void (*)(void *),void *);int nouveau_fence_wait (struct nouveau_fence *,bool lazy,bool intr);int nouveau_fence_sync (struct nouveau_bo *,struct nouveau_channel *);
drivers/gpu/drm/nouveau/nouveau_gem.c +9 -7
@@ -100,13 +100,12 @@ static void nouveau_gem_object_unmap(struct nouveau_bo *nvbo, struct nouveau_vma *vma) { const bool mapped = nvbo->bo.mem.mem_type != TTM_PL_SYSTEM; -struct nouveau_fence *fence =NULL ; +struct fence *fence =NULL ;list_del (&vma->head); -if (mapped) { - fence =nouveau_fence_ref (nvbo->bo.sync_obj); - } +if (mapped) + fence =reservation_object_get_excl (nvbo->bo.resv);if (fence) {nouveau_fence_work (fence, nouveau_gem_object_delete, vma);
@@ -116,7 +115,6 @@ nouveau_gem_object_unmap(struct nouveau_bo *nvbo, struct nouveau_vma *vma)nouveau_vm_put (vma);kfree (vma); } -nouveau_fence_unref (&fence); }void
@@ -876,8 +874,12 @@ nouveau_gem_ioctl_cpu_prep(struct drm_device *dev, void *data, ret =ttm_bo_reserve (&nvbo->bo, true, false, false,0 );if (!ret) { ret =ttm_bo_wait (&nvbo->bo, true, true, true); -if (!no_wait && ret) - fence =nouveau_fence_ref (nvbo->bo.sync_obj); +if (!no_wait && ret) { +struct fence *excl; + + excl =reservation_object_get_excl (nvbo->bo.resv); + fence =nouveau_fence_ref ((struct nouveau_fence *)excl); + }ttm_bo_unreserve (&nvbo->bo); }
drivers/gpu/drm/qxl/qxl_debugfs.c +3 -3
@@ -67,9 +67,9 @@ qxl_debugfs_buffers_info(struct seq_file *m, void *data) rel = fobj ? fobj->shared_count :0 ;rcu_read_unlock (); -seq_printf (m,"size %ld, pc %d, sync obj %p, num releases %d\n" , - (unsigned long )bo->gem_base.size, bo->pin_count, - bo->tbo.sync_obj, rel); +seq_printf (m,"size %ld, pc %d, num releases %d\n" , + (unsigned long )bo->gem_base.size, + bo->pin_count, rel); }spin_unlock (&qdev->release_lock);return 0 ;
drivers/gpu/drm/qxl/qxl_drv.h +0 -2
@@ -280,9 +280,7 @@ struct qxl_device {uint8_t slot_gen_bits;uint64_t va_slot_mask; -/* XXX: when rcu becomes available, release_lock can be killed */ spinlock_t release_lock; -spinlock_t fence_lock;struct idr release_idr;uint32_t release_seqno;spinlock_t release_idr_lock;
drivers/gpu/drm/qxl/qxl_kms.c +0 -1
@@ -224,7 +224,6 @@ static int qxl_device_init(struct qxl_device *qdev,idr_init (&qdev->release_idr);spin_lock_init (&qdev->release_idr_lock);spin_lock_init (&qdev->release_lock); -spin_lock_init (&qdev->fence_lock);idr_init (&qdev->surf_id_idr);spin_lock_init (&qdev->surf_id_idr_lock);
drivers/gpu/drm/qxl/qxl_object.h +2 -2
@@ -78,8 +78,8 @@ static inline int qxl_bo_wait(struct qxl_bo *bo, u32 *mem_type, }if (mem_type) *mem_type = bo->tbo.mem.mem_type; -if (bo->tbo.sync_obj) - r =ttm_bo_wait (&bo->tbo, true, true, no_wait); + + r =ttm_bo_wait (&bo->tbo, true, true, no_wait);ttm_bo_unreserve (&bo->tbo);return r; }
drivers/gpu/drm/qxl/qxl_release.c +0 -3
@@ -464,9 +464,6 @@ void qxl_release_fence_buffer_objects(struct qxl_release *release) bo = entry->bo; qbo =to_qxl_bo (bo); -if (!entry->bo->sync_obj) - entry->bo->sync_obj = qbo; -reservation_object_add_shared_fence (bo->resv, &release->base);ttm_bo_add_to_lru (bo);__ttm_bo_unreserve (bo);
drivers/gpu/drm/qxl/qxl_ttm.c +0 -104
116 lines not on this page · raw message
drivers/gpu/drm/radeon/radeon_cs.c +8 -2
@@ -228,11 +228,17 @@ static void radeon_cs_sync_rings(struct radeon_cs_parser *p)int i;for (i =0 ; i < p->nrelocs; i++) { +struct reservation_object *resv; +struct fence *fence; +if (!p->relocs[i].robj)continue ; + resv = p->relocs[i].robj->tbo.resv; + fence =reservation_object_get_excl (resv); +radeon_semaphore_sync_to (p->ib.semaphore, - p->relocs[i].robj->tbo.sync_obj); + (struct radeon_fence *)fence); } }
@@ -402,7 +408,7 @@ static void radeon_cs_parser_fini(struct radeon_cs_parser *parser, int error, bottm_eu_fence_buffer_objects (&parser->ticket, &parser->validated, - parser->ib.fence); + &parser->ib.fence->base); }else if (backoff) {ttm_eu_backoff_reservation (&parser->ticket, &parser->validated);
drivers/gpu/drm/radeon/radeon_display.c +1 -2
@@ -481,8 +481,7 @@ static int radeon_crtc_page_flip(struct drm_crtc *crtc, goto cleanup; } -if (new_rbo->tbo.sync_obj) - work->fence =radeon_fence_ref (new_rbo->tbo.sync_obj); + work->fence =fence_get (reservation_object_get_excl (new_rbo->tbo.resv));radeon_bo_get_tiling_flags (new_rbo, &tiling_flags,NULL );radeon_bo_unreserve (new_rbo);
drivers/gpu/drm/radeon/radeon_object.c +2 -2
@@ -736,8 +736,8 @@ int radeon_bo_wait(struct radeon_bo *bo, u32 *mem_type, bool no_wait)return r;if (mem_type) *mem_type = bo->tbo.mem.mem_type; -if (bo->tbo.sync_obj) - r =ttm_bo_wait (&bo->tbo, true, true, no_wait); + + r =ttm_bo_wait (&bo->tbo, true, true, no_wait);ttm_bo_unreserve (&bo->tbo);return r; }
drivers/gpu/drm/radeon/radeon_ttm.c +2 -32
@@ -265,12 +265,12 @@ static int radeon_move_blit(struct ttm_buffer_object *bo,BUILD_BUG_ON ((PAGE_SIZE %RADEON_GPU_PAGE_SIZE ) !=0 );/* sync other rings */ - fence = bo->sync_obj; + fence = (struct radeon_fence *)reservation_object_get_excl (bo->resv); r =radeon_copy (rdev, old_start, new_start, new_mem->num_pages * (PAGE_SIZE /RADEON_GPU_PAGE_SIZE ),/* GPU pages */ &fence);/* FIXME: handle copy error */ - r =ttm_bo_move_accel_cleanup (bo, (void *)fence, + r =ttm_bo_move_accel_cleanup (bo, &fence->base, evict, no_wait_gpu, new_mem);radeon_fence_unref (&fence);return r;
@@ -483,31 +483,6 @@ static void radeon_ttm_io_mem_free(struct ttm_bo_device *bdev, struct ttm_mem_re { } -static int radeon_sync_obj_wait (void *sync_obj,bool lazy,bool interruptible) -{ -return radeon_fence_wait ((struct radeon_fence *)sync_obj, interruptible); -} - -static int radeon_sync_obj_flush (void *sync_obj) -{ -return 0 ; -} - -static void radeon_sync_obj_unref (void **sync_obj) -{ -radeon_fence_unref ((struct radeon_fence **)sync_obj); -} - -static void *radeon_sync_obj_ref (void *sync_obj) -{ -return radeon_fence_ref ((struct radeon_fence *)sync_obj); -} - -static bool radeon_sync_obj_signaled (void *sync_obj) -{ -return radeon_fence_signaled ((struct radeon_fence *)sync_obj); -} -/* * TTM backend functions. */
@@ -685,11 +660,6 @@ static struct ttm_bo_driver radeon_bo_driver = { .evict_flags = &radeon_evict_flags, .move = &radeon_bo_move, .verify_access = &radeon_verify_access, - .sync_obj_signaled = &radeon_sync_obj_signaled, - .sync_obj_wait = &radeon_sync_obj_wait, - .sync_obj_flush = &radeon_sync_obj_flush, - .sync_obj_unref = &radeon_sync_obj_unref, - .sync_obj_ref = &radeon_sync_obj_ref, .move_notify = &radeon_bo_move_notify, .fault_reserve_notify = &radeon_bo_fault_reserve_notify, .io_mem_reserve = &radeon_ttm_io_mem_reserve,
drivers/gpu/drm/radeon/radeon_uvd.c +5 -3
@@ -356,6 +356,7 @@ static int radeon_uvd_cs_msg(struct radeon_cs_parser *p, struct radeon_bo *bo, {int32_t *msg, msg_type, handle;unsigned img_size =0 ; +struct fence *f;void *ptr;int i, r;
@@ -365,8 +366,9 @@ static int radeon_uvd_cs_msg(struct radeon_cs_parser *p, struct radeon_bo *bo,return -EINVAL ; } -if (bo->tbo.sync_obj) { - r =radeon_fence_wait (bo->tbo.sync_obj, false); + f =reservation_object_get_excl (bo->tbo.resv); +if (f) { + r =radeon_fence_wait ((struct radeon_fence *)f, false);if (r) {DRM_ERROR ("Failed waiting for UVD message (%d)!\n" , r);return r;
@@ -649,7 +651,7 @@ static int radeon_uvd_send_msg(struct radeon_device *rdev, r =radeon_ib_schedule (rdev, &ib,NULL );if (r) goto err; -ttm_eu_fence_buffer_objects (&ticket, &head, ib.fence); +ttm_eu_fence_buffer_objects (&ticket, &head, &ib.fence->base);if (fence) *fence =radeon_fence_ref (ib.fence);
drivers/gpu/drm/radeon/radeon_vm.c +11 -3
@@ -389,7 +389,7 @@ static int radeon_vm_clear_bo(struct radeon_device *rdev,if (r) goto error; -ttm_eu_fence_buffer_objects (&ticket, &head, ib.fence); +ttm_eu_fence_buffer_objects (&ticket, &head, &ib.fence->base);radeon_ib_free (rdev, &ib);return 0 ;
@@ -658,7 +658,12 @@ int radeon_vm_update_page_directory(struct radeon_device *rdev, incr, R600_PTE_VALID);if (ib.length_dw !=0 ) { -radeon_semaphore_sync_to (ib.semaphore, pd->tbo.sync_obj); +struct fence *fence; + + fence =reservation_object_get_excl (pd->tbo.resv); +radeon_semaphore_sync_to (ib.semaphore, + (struct radeon_fence *)fence); +radeon_semaphore_sync_to (ib.semaphore, vm->last_id_use); r =radeon_ib_schedule (rdev, &ib,NULL );if (r) {
@@ -786,8 +791,11 @@ static void radeon_vm_update_ptes(struct radeon_device *rdev,struct radeon_bo *pt = vm->page_tables[pt_idx].bo;unsigned nptes;uint64_t pte; +struct fence *fence; -radeon_semaphore_sync_to (ib->semaphore, pt->tbo.sync_obj); + fence =reservation_object_get_excl (pt->tbo.resv); +radeon_semaphore_sync_to (ib->semaphore, + (struct radeon_fence *)fence);if ((addr & ~mask) == (end & ~mask)) nptes = end - addr;
drivers/gpu/drm/ttm/ttm_bo.c +119 -52
244 lines not on this page · raw message
drivers/gpu/drm/ttm/ttm_bo_util.c +5 -18
@@ -37,6 +37,7 @@#include <linux/slab.h> #include <linux/vmalloc.h> #include <linux/module.h> +#include <linux/reservation.h> void ttm_bo_free_old_node (struct ttm_buffer_object *bo) {
@@ -444,8 +445,6 @@ static int ttm_buffer_object_transfer(struct ttm_buffer_object *bo, struct ttm_buffer_object **new_obj) {struct ttm_buffer_object *fbo; -struct ttm_bo_device *bdev = bo->bdev; -struct ttm_bo_driver *driver = bdev->driver;int ret; fbo =kmalloc (sizeof (*fbo),GFP_KERNEL );
@@ -466,10 +465,6 @@ static int ttm_buffer_object_transfer(struct ttm_buffer_object *bo,drm_vma_node_reset (&fbo->vma_node);atomic_set (&fbo->cpu_writers,0 ); -if (bo->sync_obj) - fbo->sync_obj = driver->sync_obj_ref (bo->sync_obj); -else - fbo->sync_obj =NULL ;kref_init (&fbo->list_kref);kref_init (&fbo->kref); fbo->destroy = &ttm_transfered_destroy;
@@ -642,28 +637,20 @@ void ttm_bo_kunmap(struct ttm_bo_kmap_obj *map)EXPORT_SYMBOL (ttm_bo_kunmap);int ttm_bo_move_accel_cleanup (struct ttm_buffer_object *bo, -void *sync_obj, +struct fence *fence,bool evict,bool no_wait_gpu,struct ttm_mem_reg *new_mem) {struct ttm_bo_device *bdev = bo->bdev; -struct ttm_bo_driver *driver = bdev->driver;struct ttm_mem_type_manager *man = &bdev->man[new_mem->mem_type];struct ttm_mem_reg *old_mem = &bo->mem;int ret;struct ttm_buffer_object *ghost_obj; -void *tmp_obj =NULL ; -if (bo->sync_obj) { - tmp_obj = bo->sync_obj; - bo->sync_obj =NULL ; - } - bo->sync_obj = driver->sync_obj_ref (sync_obj); +reservation_object_add_excl_fence (bo->resv, fence);if (evict) { ret =ttm_bo_wait (bo, false, false, false); -if (tmp_obj) - driver->sync_obj_unref (&tmp_obj);if (ret)return ret;
@@ -684,13 +671,13 @@ int ttm_bo_move_accel_cleanup(struct ttm_buffer_object *bo,*/ set_bit (TTM_BO_PRIV_FLAG_MOVING , &bo->priv_flags); -if (tmp_obj) - driver->sync_obj_unref (&tmp_obj); ret =ttm_buffer_object_transfer (bo, &ghost_obj);if (ret)return ret; +reservation_object_add_excl_fence (ghost_obj->resv, fence); +/** * If we're not moving to fixed memory, the TTM object * needs to stay alive. Otherwhise hang it on the ghost
drivers/gpu/drm/ttm/ttm_execbuf_util.c +2 -8
@@ -163,7 +163,7 @@ int ttm_eu_reserve_buffers(struct ww_acquire_ctx *ticket,EXPORT_SYMBOL (ttm_eu_reserve_buffers);void ttm_eu_fence_buffer_objects (struct ww_acquire_ctx *ticket, -struct list_head *list,void *sync_obj) +struct list_head *list,struct fence *fence) {struct ttm_validate_buffer *entry;struct ttm_buffer_object *bo;
@@ -183,18 +183,12 @@ void ttm_eu_fence_buffer_objects(struct ww_acquire_ctx *ticket,list_for_each_entry (entry, list, head) { bo = entry->bo; - entry->old_sync_obj = bo->sync_obj; - bo->sync_obj = driver->sync_obj_ref (sync_obj); +reservation_object_add_excl_fence (bo->resv, fence);ttm_bo_add_to_lru (bo);__ttm_bo_unreserve (bo); }spin_unlock (&glob->lru_lock);if (ticket)ww_acquire_fini (ticket); - -list_for_each_entry (entry, list, head) { -if (entry->old_sync_obj) - driver->sync_obj_unref (&entry->old_sync_obj); - } }EXPORT_SYMBOL (ttm_eu_fence_buffer_objects);
drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c +0 -40
@@ -768,41 +768,6 @@ static int vmw_ttm_fault_reserve_notify(struct ttm_buffer_object *bo) }/** -* FIXME: We're using the old vmware polling method to sync. -* Do this with fences instead. -*/ - -static void *vmw_sync_obj_ref (void *sync_obj) -{ - -return (void *) -vmw_fence_obj_reference ((struct vmw_fence_obj *) sync_obj); -} - -static void vmw_sync_obj_unref (void **sync_obj) -{ -vmw_fence_obj_unreference ((struct vmw_fence_obj **) sync_obj); -} - -static int vmw_sync_obj_flush (void *sync_obj) -{ -vmw_fence_obj_flush ((struct vmw_fence_obj *) sync_obj); -return 0 ; -} - -static bool vmw_sync_obj_signaled (void *sync_obj) -{ -return vmw_fence_obj_signaled ((struct vmw_fence_obj *) sync_obj); -} - -static int vmw_sync_obj_wait (void *sync_obj,bool lazy,bool interruptible) -{ -return vmw_fence_obj_wait ((struct vmw_fence_obj *) sync_obj, - lazy, interruptible, -VMW_FENCE_WAIT_TIMEOUT ); -} - -/** * vmw_move_notify - TTM move_notify_callback * * @bo: The TTM buffer object about to move.
@@ -839,11 +804,6 @@ struct ttm_bo_driver vmw_bo_driver = { .evict_flags = vmw_evict_flags, .move = NULL, .verify_access = vmw_verify_access, - .sync_obj_signaled = vmw_sync_obj_signaled, - .sync_obj_wait = vmw_sync_obj_wait, - .sync_obj_flush = vmw_sync_obj_flush, - .sync_obj_unref = vmw_sync_obj_unref, - .sync_obj_ref = vmw_sync_obj_ref, .move_notify = vmw_move_notify, .swap_notify = vmw_swap_notify, .fault_reserve_notify = &vmw_ttm_fault_reserve_notify,
drivers/gpu/drm/vmwgfx/vmwgfx_resource.c +4 -10
@@ -1419,22 +1419,16 @@ void vmw_fence_single_bo(struct ttm_buffer_object *bo, struct vmw_fence_obj *fence) {struct ttm_bo_device *bdev = bo->bdev; -struct vmw_fence_obj *old_fence_obj; +struct vmw_private *dev_priv = container_of(bdev, struct vmw_private, bdev);if (fence ==NULL ) {vmw_execbuf_fence_commands (NULL , dev_priv, &fence,NULL ); +reservation_object_add_excl_fence (bo->resv, &fence->base); +fence_put (&fence->base); }else -vmw_fence_obj_reference (fence); - -reservation_object_add_excl_fence (bo->resv, &fence->base); - - old_fence_obj = bo->sync_obj; - bo->sync_obj = fence; - -if (old_fence_obj) -vmw_fence_obj_unreference (&old_fence_obj); +reservation_object_add_excl_fence (bo->resv, &fence->base); }/**
include/drm/ttm/ttm_bo_api.h +0 -2
@@ -163,7 +163,6 @@ struct ttm_tt;* @lru: List head for the lru list. * @ddestroy: List head for the delayed destroy list. * @swap: List head for swap LRU list. -* @sync_obj: Pointer to a synchronization object. * @priv_flags: Flags describing buffer object internal state. * @vma_node: Address space manager node. * @offset: The current GPU offset, which can have different meanings
@@ -230,7 +229,6 @@ struct ttm_buffer_object {* Members protected by a bo reservation. */ -void *sync_obj;unsigned long priv_flags;struct drm_vma_offset_node vma_node;
include/drm/ttm/ttm_bo_driver.h +2 -24
@@ -311,11 +311,6 @@ struct ttm_mem_type_manager {* @move: Callback for a driver to hook in accelerated functions to * move a buffer. * If set to NULL, a potentially slow memcpy() move is used. -* @sync_obj_signaled: See ttm_fence_api.h -* @sync_obj_wait: See ttm_fence_api.h -* @sync_obj_flush: See ttm_fence_api.h -* @sync_obj_unref: See ttm_fence_api.h -* @sync_obj_ref: See ttm_fence_api.h */ struct ttm_bo_driver {
@@ -417,23 +412,6 @@ struct ttm_bo_driver {int (*verify_access) (struct ttm_buffer_object *bo,struct file *filp); -/** -* In case a driver writer dislikes the TTM fence objects, -* the driver writer can replace those with sync objects of -* his / her own. If it turns out that no driver writer is -* using these. I suggest we remove these hooks and plug in -* fences directly. The bo driver needs the following functionality: -* See the corresponding functions in the fence object API -* documentation. -*/ - -bool (*sync_obj_signaled) (void *sync_obj); -int (*sync_obj_wait) (void *sync_obj, -bool lazy,bool interruptible); -int (*sync_obj_flush) (void *sync_obj); -void (*sync_obj_unref) (void **sync_obj); -void *(*sync_obj_ref) (void *sync_obj); -/* hook to notify driver about a driver move so it * can do tiling things */ void (*move_notify)(struct ttm_buffer_object *bo,
@@ -1021,7 +999,7 @@ extern void ttm_bo_free_old_node(struct ttm_buffer_object *bo);* ttm_bo_move_accel_cleanup. * * @bo: A pointer to a struct ttm_buffer_object. -* @sync_obj: A sync object that signals when moving is complete. +* @fence: A fence object that signals when moving is complete. * @evict: This is an evict move. Don't return until the buffer is idle. * @no_wait_gpu: Return immediately if the GPU is busy. * @new_mem: struct ttm_mem_reg indicating where to move.
@@ -1035,7 +1013,7 @@ extern void ttm_bo_free_old_node(struct ttm_buffer_object *bo);*/ extern int ttm_bo_move_accel_cleanup (struct ttm_buffer_object *bo, -void *sync_obj, +struct fence *fence,bool evict,bool no_wait_gpu,struct ttm_mem_reg *new_mem);/**
include/drm/ttm/ttm_execbuf_util.h +3 -7
@@ -39,16 +39,11 @@* * @head: list head for thread-private list. * @bo: refcounted buffer object pointer. -* @reserved: Indicates whether @bo has been reserved for validation. -* @removed: Indicates whether @bo has been removed from lru lists. -* @put_count: Number of outstanding references on bo::list_kref. -* @old_sync_obj: Pointer to a sync object about to be unreferenced */ struct ttm_validate_buffer {struct list_head head;struct ttm_buffer_object *bo; -void *old_sync_obj; };/**
@@ -100,7 +95,7 @@ extern int ttm_eu_reserve_buffers(struct ww_acquire_ctx *ticket,* * @ticket: ww_acquire_ctx from reserve call * @list: thread private list of ttm_validate_buffer structs. -* @sync_obj: The new sync object for the buffers. +* @fence: The new exclusive fence for the buffers. * * This function should be called when command submission is complete, and * it will add a new sync object to bos pointed to by entries on @list.
@@ -109,6 +104,7 @@ extern int ttm_eu_reserve_buffers(struct ww_acquire_ctx *ticket,*/ extern void ttm_eu_fence_buffer_objects (struct ww_acquire_ctx *ticket, -struct list_head *list,void *sync_obj); +struct list_head *list, +struct fence *fence);#endif
PATCH 16/19 drm/nouveau: use rcu in nouveau_gem_ioctl_cpu_prep
In reply to Maarten LankhorstWith the conversion to the reservation api this should be safe.
--- drivers/gpu/drm/nouveau/nouveau_gem.c | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-)
drivers/gpu/drm/nouveau/nouveau_gem.c +12 -16
@@ -863,33 +863,29 @@ nouveau_gem_ioctl_cpu_prep(struct drm_device *dev, void *data,struct drm_gem_object *gem;struct nouveau_bo *nvbo;bool no_wait = !!(req->flags &NOUVEAU_GEM_CPU_PREP_NOWAIT ); +bool write = !!(req->flags &NOUVEAU_GEM_CPU_PREP_WRITE );int ret; -struct nouveau_fence *fence =NULL ; gem =drm_gem_object_lookup (dev, file_priv, req->handle);if (!gem)return -ENOENT ; nvbo =nouveau_gem_object (gem); - ret =ttm_bo_reserve (&nvbo->bo, true, false, false,0 ); -if (!ret) { - ret =ttm_bo_wait (&nvbo->bo, true, true, true); -if (!no_wait && ret) { -struct fence *excl; - - excl =reservation_object_get_excl (nvbo->bo.resv); - fence =nouveau_fence_ref ((struct nouveau_fence *)excl); - } +if (no_wait) + ret =reservation_object_test_signaled_rcu (nvbo->bo.resv, write) ?0 : -EBUSY ; +else { +long lret; -ttm_bo_unreserve (&nvbo->bo); + lret =reservation_object_wait_timeout_rcu (nvbo->bo.resv, write, true,30 *HZ ); +if (!lret) + ret = -EBUSY ; +else if (lret >0 ) + ret =0 ; +else + ret = lret; }drm_gem_object_unreference_unlocked (gem); -if (fence) { - ret =nouveau_fence_wait (fence, true, no_wait); -nouveau_fence_unref (&fence); - } -return ret; }
PATCH 17/19 drm/radeon: use rcu waits in some ioctls
In reply to Maarten Lankhorst--- drivers/gpu/drm/radeon/radeon_gem.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-)
drivers/gpu/drm/radeon/radeon_gem.c +14 -5
@@ -107,9 +107,12 @@ static int radeon_gem_set_domain(struct drm_gem_object *gobj, }if (domain ==RADEON_GEM_DOMAIN_CPU ) {/* Asking for cpu access wait for object idle */ - r =radeon_bo_wait (robj,NULL , false); -if (r) { -printk (KERN_ERR "Failed to wait for object !\n" ); + r =reservation_object_wait_timeout_rcu (robj->tbo.resv, true, true,30 *HZ ); +if (!r) + r = -EBUSY ; + +if (r <0 && r != -EINTR ) { +printk (KERN_ERR "Failed to wait for object: %i\n" , r);return r; } }
@@ -357,14 +360,20 @@ int radeon_gem_wait_idle_ioctl(struct drm_device *dev, void *data,struct drm_radeon_gem_wait_idle *args = data;struct drm_gem_object *gobj;struct radeon_bo *robj; -int r; +int r =0 ; +long ret; gobj =drm_gem_object_lookup (dev, filp, args->handle);if (gobj ==NULL ) {return -ENOENT ; } robj =gem_to_radeon_bo (gobj); - r =radeon_bo_wait (robj,NULL , false); + ret =reservation_object_wait_timeout_rcu (robj->tbo.resv, true, true,30 *HZ ); +if (ret ==0 ) + r = -EBUSY ; +else if (ret <0 ) + r = ret; +/* callback hw specific functions if any */ if (rdev->asic->ioctl_wait_idle) robj->rdev->asic->ioctl_wait_idle (rdev, robj);
Re: [PATCH 17/19] drm/radeon: use rcu waits in some ioctls
Quoted 14 lines · Maarten Lankhorst
drivers/gpu/drm/radeon/radeon_gem.c +2
-1@@ -357,14 +360,20 @@ int radeon_gem_wait_idle_ioctl(struct drm_device *dev, void *data,struct drm_radeon_gem_wait_idle *args = data;struct drm_gem_object *gobj;struct radeon_bo *robj; -int r; +int r =0 ; +long ret; gobj =drm_gem_object_lookup (dev, filp, args->handle);if (gobj ==NULL ) {return -ENOENT ; } robj =gem_to_radeon_bo (gobj);
drivers/gpu/drm/radeon/radeon_gem.c int radeon_gem_wait_idle_ioctl(struct drm_device *dev, void *data, · line 379
Quoted 10 lines
drivers/gpu/drm/radeon/radeon_gem.c +6
-1- r =radeon_bo_wait (robj,NULL , false); + ret =reservation_object_wait_timeout_rcu (robj->tbo.resv, true, true,30 *HZ ); +if (ret ==0 ) + r = -EBUSY ; +else if (ret <0 ) + r = ret; +/* callback hw specific functions if any */ if (rdev->asic->ioctl_wait_idle) robj->rdev->asic->ioctl_wait_idle (rdev, robj);
Heads up, this conflicts with
http://lists.freedesktop.org/archives/dri-devel/2014-August/065255.html
which passes a non-NULL second argument to radeon_bo_wait() to get the BO's current domain.
Signature · 2 lines
Earthling Michel Dänzer | http://www.amd.com Libre software enthusiast | Mesa and X developer
Re: [PATCH 17/19] drm/radeon: use rcu waits in some ioctls
Hey,
Quoted 22 lines · Michel Dänzer
Quoted 21 lines · Maarten Lankhorst
drivers/gpu/drm/radeon/radeon_gem.c +8
-2@@ -357,14 +360,20 @@ int radeon_gem_wait_idle_ioctl(struct drm_device *dev, void *data,struct drm_radeon_gem_wait_idle *args = data;struct drm_gem_object *gobj;struct radeon_bo *robj; -int r; +int r =0 ; +long ret; gobj =drm_gem_object_lookup (dev, filp, args->handle);if (gobj ==NULL ) {return -ENOENT ; } robj =gem_to_radeon_bo (gobj); - r =radeon_bo_wait (robj,NULL , false); + ret =reservation_object_wait_timeout_rcu (robj->tbo.resv, true, true,30 *HZ ); +if (ret ==0 ) + r = -EBUSY ; +else if (ret <0 ) + r = ret; +
Quoted 8 lines
drivers/gpu/drm/radeon/radeon_gem.c int radeon_gem_wait_idle_ioctl(struct drm_device *dev, void *data, · line 379
Quoted 3 lines
drivers/gpu/drm/radeon/radeon_gem.c +0
-0/* callback hw specific functions if any */ if (rdev->asic->ioctl_wait_idle) robj->rdev->asic->ioctl_wait_idle (rdev, robj);Heads up, this conflicts with
http://lists.freedesktop.org/archives/dri-devel/2014-August/065255.html
which passes a non-NULL second argument toradeon_bo_wait()to get the BO's current domain.
Ok, I will fix it up and resend it later.
Does it matter if I grab the current domain without grabbing the lock here? Because it doesn't matter if it sees the old or new domain, it could have been changed after returning too.
~Maarten
Re: [PATCH 17/19] drm/radeon: use rcu waits in some ioctls
Quoted 33 lines · Maarten Lankhorst
Hey,
Quoted 22 lines · Michel Dänzer
Quoted 21 lines · Maarten Lankhorst
drivers/gpu/drm/radeon/radeon_gem.c +8
-2@@ -357,14 +360,20 @@ int radeon_gem_wait_idle_ioctl(struct drm_device *dev, void *data,struct drm_radeon_gem_wait_idle *args = data;struct drm_gem_object *gobj;struct radeon_bo *robj; -int r; +int r =0 ; +long ret; gobj =drm_gem_object_lookup (dev, filp, args->handle);if (gobj ==NULL ) {return -ENOENT ; } robj =gem_to_radeon_bo (gobj); - r =radeon_bo_wait (robj,NULL , false); + ret =reservation_object_wait_timeout_rcu (robj->tbo.resv, true, true,30 *HZ ); +if (ret ==0 ) + r = -EBUSY ; +else if (ret <0 ) + r = ret; +Quoted 8 lines
drivers/gpu/drm/radeon/radeon_gem.c int radeon_gem_wait_idle_ioctl(struct drm_device *dev, void *data, · line 379
Quoted 3 lines
drivers/gpu/drm/radeon/radeon_gem.c +0
-0/* callback hw specific functions if any */ if (rdev->asic->ioctl_wait_idle) robj->rdev->asic->ioctl_wait_idle (rdev, robj);Heads up, this conflicts with
http://lists.freedesktop.org/archives/dri-devel/2014-August/065255.html
which passes a non-NULL second argument toradeon_bo_wait()to get the BO's current domain.
Quoted 5 lines
Ok, I will fix it up and resend it later.
Does it matter if I grab the current domain without grabbing the lock here? Because it doesn't matter if it sees the old or new domain, it could have been changed after returning too.
It should be the domain where the BO is located when the fence we are waiting for here signals.
Signature · 2 lines
Earthling Michel Dänzer | http://www.amd.com Libre software enthusiast | Mesa and X developer
Re: [PATCH 17/19] drm/radeon: use rcu waits in some ioctls
Quoted 34 lines · Michel Dänzer
Quoted 33 lines · Maarten Lankhorst
Hey,
Quoted 30 lines · Michel Dänzer
Quoted 14 lines · Maarten Lankhorst
drivers/gpu/drm/radeon/radeon_gem.c +2
-1@@ -357,14 +360,20 @@ int radeon_gem_wait_idle_ioctl(struct drm_device *dev, void *data,struct drm_radeon_gem_wait_idle *args = data;struct drm_gem_object *gobj;struct radeon_bo *robj; -int r; +int r =0 ; +long ret; gobj =drm_gem_object_lookup (dev, filp, args->handle);if (gobj ==NULL ) {return -ENOENT ; } robj =gem_to_radeon_bo (gobj);drivers/gpu/drm/radeon/radeon_gem.c int radeon_gem_wait_idle_ioctl(struct drm_device *dev, void *data, · line 379
Quoted 10 lines
drivers/gpu/drm/radeon/radeon_gem.c +6
-1- r =radeon_bo_wait (robj,NULL , false); + ret =reservation_object_wait_timeout_rcu (robj->tbo.resv, true, true,30 *HZ ); +if (ret ==0 ) + r = -EBUSY ; +else if (ret <0 ) + r = ret; +/* callback hw specific functions if any */ if (rdev->asic->ioctl_wait_idle) robj->rdev->asic->ioctl_wait_idle (rdev, robj);Heads up, this conflicts with
http://lists.freedesktop.org/archives/dri-devel/2014-August/065255.html
which passes a non-NULL second argument toradeon_bo_wait()to get the BO's current domain.
Quoted 8 lines
Quoted 5 lines
Ok, I will fix it up and resend it later.
Does it matter if I grab the current domain without grabbing the lock here? Because it doesn't matter if it sees the old or new domain, it could have been changed after returning too.
It should be the domain where the BO is located when the fence we are waiting for here signals.
Could we compare domain before and after the rcu wait, and retry waiting if they're different, and the new one is VRAM? (eg eviction happened) That should prevent needing to lock the bo.
~Maarten
Re: [PATCH 17/19] drm/radeon: use rcu waits in some ioctls
Quoted 39 lines · Maarten Lankhorst
Quoted 38 lines · Michel Dänzer
Quoted 36 lines · Maarten Lankhorst
Quoted 22 lines · Michel Dänzer
Quoted 21 lines · Maarten Lankhorst
drivers/gpu/drm/radeon/radeon_gem.c +8
-2@@ -357,14 +360,20 @@ int radeon_gem_wait_idle_ioctl(struct drm_device *dev, void *data,struct drm_radeon_gem_wait_idle *args = data;struct drm_gem_object *gobj;struct radeon_bo *robj; -int r; +int r =0 ; +long ret; gobj =drm_gem_object_lookup (dev, filp, args->handle);if (gobj ==NULL ) {return -ENOENT ; } robj =gem_to_radeon_bo (gobj); - r =radeon_bo_wait (robj,NULL , false); + ret =reservation_object_wait_timeout_rcu (robj->tbo.resv, true, true,30 *HZ ); +if (ret ==0 ) + r = -EBUSY ; +else if (ret <0 ) + r = ret; +Quoted 8 lines
drivers/gpu/drm/radeon/radeon_gem.c int radeon_gem_wait_idle_ioctl(struct drm_device *dev, void *data, · line 379
Quoted 3 lines
drivers/gpu/drm/radeon/radeon_gem.c +0
-0/* callback hw specific functions if any */ if (rdev->asic->ioctl_wait_idle) robj->rdev->asic->ioctl_wait_idle (rdev, robj);Heads up, this conflicts with
http://lists.freedesktop.org/archives/dri-devel/2014-August/065255.html
which passes a non-NULL second argument toradeon_bo_wait()to get the BO's current domain.Ok, I will fix it up and resend it later.
Does it matter if I grab the current domain without grabbing the lock here? Because it doesn't matter if it sees the old or new domain, it could have been changed after returning too.
Quoted 5 lines
Quoted 2 lines
It should be the domain where the BO is located when the fence we are waiting for here signals.
Could we compare domain before and after the rcu wait, and retry waiting if they're different, and the new one is VRAM? (eg eviction happened) That should prevent needing to lock the bo.
Eviction normally only happens from VRAM, not to VRAM. :) So if you know whether the domain is VRAM or not after the wait, you can just proceed accordingly, I don't see why you'd need to wait again.
Signature · 2 lines
Earthling Michel Dänzer | http://www.amd.com Libre software enthusiast | Mesa and X developer
Re: [PATCH 17/19] drm/radeon: use rcu waits in some ioctls
op 04-08-14 10:42, Michel Dänzer schreef:
Quoted 37 lines · Maarten Lankhorst
Quoted 36 lines · Michel Dänzer
Quoted 35 lines · Maarten Lankhorst
Quoted 34 lines · Michel Dänzer
Quoted 20 lines · Maarten Lankhorst
Quoted 19 lines
drivers/gpu/drm/radeon/radeon_gem.c +7
-2@@ -357,14 +360,20 @@ int radeon_gem_wait_idle_ioctl(struct drm_device *dev, void *data,struct drm_radeon_gem_wait_idle *args = data;struct drm_gem_object *gobj;struct radeon_bo *robj; -int r; +int r =0 ; +long ret; gobj =drm_gem_object_lookup (dev, filp, args->handle);if (gobj ==NULL ) {return -ENOENT ; } robj =gem_to_radeon_bo (gobj); - r =radeon_bo_wait (robj,NULL , false); + ret =reservation_object_wait_timeout_rcu (robj->tbo.resv, true, true,30 *HZ ); +if (ret ==0 ) + r = -EBUSY ; +else if (ret <0 ) + r = ret;Quoted 8 lines
drivers/gpu/drm/radeon/radeon_gem.c int radeon_gem_wait_idle_ioctl(struct drm_device *dev, void *data, · line 379
Quoted 4 lines
drivers/gpu/drm/radeon/radeon_gem.c +1
-0+/* callback hw specific functions if any */ if (rdev->asic->ioctl_wait_idle) robj->rdev->asic->ioctl_wait_idle (rdev, robj);Heads up, this conflicts with
http://lists.freedesktop.org/archives/dri-devel/2014-August/065255.html
which passes a non-NULL second argument toradeon_bo_wait()to get the BO's current domain.Ok, I will fix it up and resend it later.
Does it matter if I grab the current domain without grabbing the lock here? Because it doesn't matter if it sees the old or new domain, it could have been changed after returning too.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
It should be the domain where the BO is located when the fence we are waiting for here signals.
Could we compare domain before and after the rcu wait, and retry waiting if they're different, and the new one is VRAM? (eg eviction happened) That should prevent needing to lock the bo.
Eviction normally only happens from VRAM, not to VRAM. :) So if you know whether the domain is VRAM or not after the wait, you can just proceed accordingly, I don't see why you'd need to wait again.
Because in the worst case you didn't wait on the fence that started the eviction, but one before it. ;-)
~Maarten
Re: [PATCH 17/19] drm/radeon: use rcu waits in some ioctls
Quoted 40 lines · Maarten Lankhorst
op 04-08-14 10:42, Michel Dänzer schreef:
Quoted 39 lines · Maarten Lankhorst
Quoted 38 lines · Michel Dänzer
Quoted 37 lines · Maarten Lankhorst
Quoted 29 lines · Michel Dänzer
Quoted 20 lines · Maarten Lankhorst
Quoted 19 lines
(quoted diff) +7
-2@@ -357,14 +360,20 @@ int radeon_gem_wait_idle_ioctl(struct drm_device *dev, void *data, struct drm_radeon_gem_wait_idle *args = data; struct drm_gem_object *gobj; struct radeon_bo *robj; - int r; + int r = 0; + long ret; gobj = drm_gem_object_lookup(dev, filp, args->handle); if (gobj == NULL) { return -ENOENT; } robj = gem_to_radeon_bo(gobj); - r = radeon_bo_wait(robj, NULL, false); + ret = reservation_object_wait_timeout_rcu(robj->tbo.resv, true, true, 30 * HZ); + if (ret == 0) + r = -EBUSY; + else if (ret < 0) + r = ret;Quoted 8 lines
Review int radeon_gem_wait_idle_ioctl(struct drm_device *dev, void *data, · line 379
Quoted 4 lines
(quoted diff) +1
-0+ /* callback hw specific functions if any */ if (rdev->asic->ioctl_wait_idle) robj->rdev->asic->ioctl_wait_idle(rdev, robj);Heads up, this conflicts with
http://lists.freedesktop.org/archives/dri-devel/2014-August/065255.html
which passes a non-NULL second argument toradeon_bo_wait()to get the BO's current domain.Quoted 5 lines
Ok, I will fix it up and resend it later.
Does it matter if I grab the current domain without grabbing the lock here? Because it doesn't matter if it sees the old or new domain, it could have been changed after returning too.
It should be the domain where the BO is located when the fence we are waiting for here signals.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Could we compare domain before and after the rcu wait, and retry waiting if they're different, and the new one is VRAM? (eg eviction happened) That should prevent needing to lock the bo.
Eviction normally only happens from VRAM, not to VRAM. :) So if you know whether the domain is VRAM or not after the wait, you can just proceed accordingly, I don't see why you'd need to wait again.
Because in the worst case you didn't wait on the fence that started the eviction, but one before it. ;-)
I'm afraid you've lost me. Can you determine the domain that radeon_bo_wait() would have returned?
Signature · 2 lines
Earthling Michel Dänzer | http://www.amd.com Libre software enthusiast | Mesa and X developer
Re: [PATCH 17/19] drm/radeon: use rcu waits in some ioctls
op 04-08-14 11:25, Michel Dänzer schreef:
Quoted 44 lines · Maarten Lankhorst
Quoted 43 lines
op 04-08-14 10:42, Michel Dänzer schreef:
Quoted 42 lines · Maarten Lankhorst
Quoted 41 lines · Michel Dänzer
Quoted 30 lines · Maarten Lankhorst
Quoted 29 lines · Michel Dänzer
Quoted 28 lines · Maarten Lankhorst
Quoted 13 lines
(quoted diff) +2
-1@@ -357,14 +360,20 @@ int radeon_gem_wait_idle_ioctl(struct drm_device *dev, void *data, struct drm_radeon_gem_wait_idle *args = data; struct drm_gem_object *gobj; struct radeon_bo *robj; - int r; + int r = 0; + long ret; gobj = drm_gem_object_lookup(dev, filp, args->handle); if (gobj == NULL) { return -ENOENT; } robj = gem_to_radeon_bo(gobj);Review int radeon_gem_wait_idle_ioctl(struct drm_device *dev, void *data, · line 379
Quoted 10 lines
(quoted diff) +6
-1- r = radeon_bo_wait(robj, NULL, false); + ret = reservation_object_wait_timeout_rcu(robj->tbo.resv, true, true, 30 * HZ); + if (ret == 0) + r = -EBUSY; + else if (ret < 0) + r = ret; + /* callback hw specific functions if any */ if (rdev->asic->ioctl_wait_idle) robj->rdev->asic->ioctl_wait_idle(rdev, robj);Heads up, this conflicts with
http://lists.freedesktop.org/archives/dri-devel/2014-August/065255.html
which passes a non-NULL second argument toradeon_bo_wait()to get the BO's current domain.Quoted 7 lines
Quoted 5 lines
Ok, I will fix it up and resend it later.
Does it matter if I grab the current domain without grabbing the lock here? Because it doesn't matter if it sees the old or new domain, it could have been changed after returning too.
It should be the domain where the BO is located when the fence we are waiting for here signals.
Could we compare domain before and after the rcu wait, and retry waiting if they're different, and the new one is VRAM? (eg eviction happened) That should prevent needing to lock the bo.
Quoted 9 lines
Quoted 5 lines
Quoted 3 lines
Eviction normally only happens from VRAM, not to VRAM. :) So if you know whether the domain is VRAM or not after the wait, you can just proceed accordingly, I don't see why you'd need to wait again.
Because in the worst case you didn't wait on the fence that started the eviction, but one before it. ;-)
I'm afraid you've lost me. Can you determine the domain that
radeon_bo_wait()would have returned?
Ok so..
wait ioctl:
waits on fence 1
(eviction to vram happens asynchronously, fence 1 on the bo gets replaced by fence 2)
wait 1 completes, new domain is VRAM
vram flush happens, but fence 2 is not signaled yet so not everything is copied.
wait ioctl returns
Or is it unimportant here, and the vram flush doesn't depend on the fence being completed?
The second wait would be forced by ttm_bo_vm_fault anyway.
~Maarten
PATCH 18/19 drm/vmwgfx: use rcu in vmw_user_dmabuf_synccpu_grab
In reply to Maarten Lankhorst--- drivers/gpu/drm/vmwgfx/vmwgfx_resource.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_resource.c +10 -7
@@ -567,13 +567,16 @@ static int vmw_user_dmabuf_synccpu_grab(struct vmw_user_dma_buffer *user_bo,int ret;if (flags & drm_vmw_synccpu_allow_cs) { - ret =ttm_bo_reserve (bo, true, !!(flags & drm_vmw_synccpu_dontblock), false,0 ); -if (!ret) { - ret =ttm_bo_wait (bo, false, true, - !!(flags & drm_vmw_synccpu_dontblock)); -ttm_bo_unreserve (bo); - } -return ret; +long lret; +if (flags & drm_vmw_synccpu_dontblock) +return reservation_object_test_signaled_rcu (bo->resv, true) ?0 : -EBUSY ; + + lret =reservation_object_wait_timeout_rcu (bo->resv, true, true,MAX_SCHEDULE_TIMEOUT ); +if (!lret) +return -EBUSY ; +else if (lret <0 ) +return lret; +return 0 ; } ret = ttm_bo_synccpu_write_grab
PATCH 19/19 drm/ttm: use rcu in core ttm
In reply to Maarten Lankhorst--- drivers/gpu/drm/ttm/ttm_bo.c | 76 +++++++----------------------------------- 1 file changed, 13 insertions(+), 63 deletions(-)
drivers/gpu/drm/ttm/ttm_bo.c +13 -63
@@ -466,66 +466,6 @@ static void ttm_bo_cleanup_refs_or_queue(struct ttm_buffer_object *bo) ((HZ / 100) < 1) ? 1 : HZ / 100); } -static int ttm_bo_unreserve_and_wait (struct ttm_buffer_object *bo, -bool interruptible) -{ -struct ttm_bo_global *glob = bo->glob; -struct reservation_object_list *fobj; -struct fence *excl =NULL ; -struct fence **shared =NULL ; -u32 shared_count =0 , i; -int ret =0 ; - - fobj =reservation_object_get_list (bo->resv); -if (fobj && fobj->shared_count) { - shared =kmalloc (sizeof (*shared) * fobj->shared_count, -GFP_KERNEL ); - -if (!shared) { - ret = -ENOMEM ; -__ttm_bo_unreserve (bo); -spin_unlock (&glob->lru_lock); -return ret; - } - -for (i =0 ; i < fobj->shared_count; ++i) { -if (!fence_is_signaled (fobj->shared[i])) { -fence_get (fobj->shared[i]); - shared[shared_count++] = fobj->shared[i]; - } - } -if (!shared_count) { -kfree (shared); - shared =NULL ; - } - } - - excl =reservation_object_get_excl (bo->resv); -if (excl && !fence_is_signaled (excl)) -fence_get (excl); -else - excl =NULL ; - -__ttm_bo_unreserve (bo); -spin_unlock (&glob->lru_lock); - -if (excl) { - ret =fence_wait (excl, interruptible); -fence_put (excl); - } - -if (shared_count >0 ) { -for (i =0 ; i < shared_count; ++i) { -if (!ret) - ret =fence_wait (shared[i], interruptible); -fence_put (shared[i]); - } -kfree (shared); - } - -return ret; -} -/** * function ttm_bo_cleanup_refs_and_unlock * If bo idle, remove from delayed- and lru lists, and unref.
@@ -549,9 +489,19 @@ static int ttm_bo_cleanup_refs_and_unlock(struct ttm_buffer_object *bo, ret =ttm_bo_wait (bo, false, false, true);if (ret && !no_wait_gpu) { - ret =ttm_bo_unreserve_and_wait (bo, interruptible); -if (ret) -return ret; +long lret; +ww_mutex_unlock (&bo->resv->lock); +spin_unlock (&glob->lru_lock); + + lret =reservation_object_wait_timeout_rcu (bo->resv, + true, + interruptible, +30 *HZ ); + +if (lret <0 ) +return lret; +else if (lret ==0 ) +return -EBUSY ;spin_lock (&glob->lru_lock); ret =__ttm_bo_reserve (bo, false, true, false,NULL );