Convert TTM to the new fence interface.
Subsystems (8)
cover Convert TTM to the new fence interface.
This series applies on top of the driver-core-next branch ofgit://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core.git
Before converting ttm to the new fence interface I had to fix some drivers to require a reservation before poking with fence_obj. After flipping the switch RCU becomes available instead, and the extra reservations can be dropped again. :-)
I've done at least basic testing on all the drivers I've converted at some point, but more testing is definitely welcomed!
---
Maarten Lankhorst (17):
drm/ttm: add interruptible parameter to ttm_eu_reserve_buffers drm/ttm: kill off some members to ttm_validate_buffer drm/nouveau: add reservation to nouveau_gem_ioctl_cpu_prep drm/nouveau: require reservations for nouveau_fence_sync and nouveau_bo_fence drm/ttm: call ttm_bo_wait while inside a reservation
drm/ttm: kill fence_lock
drm/nouveau: rework to new fence interface
drm/radeon: add timeout argument to radeon_fence_wait_seq drm/radeon: use common fence implementation for fences
drm/qxl: rework to new fence interface
drm/vmwgfx: get rid of different types of fence_flags entirely drm/vmwgfx: rework to new fence interface
drm/ttm: flip the switch, and convert to dma_fence
drm/nouveau: use rcu in nouveau_gem_ioctl_cpu_prep
drm/radeon: use rcu waits in some ioctls
drm/vmwgfx: use rcu in vmw_user_dmabuf_synccpu_grab
drm/ttm: use rcu in core ttm
drivers/gpu/drm/nouveau/core/core/event.c | 4 drivers/gpu/drm/nouveau/nouveau_bo.c | 59 +--- drivers/gpu/drm/nouveau/nouveau_display.c | 25 +- drivers/gpu/drm/nouveau/nouveau_fence.c | 431 +++++++++++++++++++---------- drivers/gpu/drm/nouveau/nouveau_fence.h | 22 + drivers/gpu/drm/nouveau/nouveau_gem.c | 55 +--- 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 - drivers/gpu/drm/qxl/Makefile | 2 drivers/gpu/drm/qxl/qxl_cmd.c | 7 drivers/gpu/drm/qxl/qxl_debugfs.c | 16 + drivers/gpu/drm/qxl/qxl_drv.h | 20 - drivers/gpu/drm/qxl/qxl_fence.c | 91 ------ drivers/gpu/drm/qxl/qxl_kms.c | 1 drivers/gpu/drm/qxl/qxl_object.c | 2 drivers/gpu/drm/qxl/qxl_object.h | 6 drivers/gpu/drm/qxl/qxl_release.c | 172 ++++++++++-- drivers/gpu/drm/qxl/qxl_ttm.c | 93 ------ drivers/gpu/drm/radeon/radeon.h | 15 - drivers/gpu/drm/radeon/radeon_cs.c | 10 + drivers/gpu/drm/radeon/radeon_device.c | 60 ++++ drivers/gpu/drm/radeon/radeon_display.c | 21 + drivers/gpu/drm/radeon/radeon_fence.c | 283 +++++++++++++++---- drivers/gpu/drm/radeon/radeon_gem.c | 19 + drivers/gpu/drm/radeon/radeon_object.c | 8 - drivers/gpu/drm/radeon/radeon_ttm.c | 34 -- drivers/gpu/drm/radeon/radeon_uvd.c | 10 - drivers/gpu/drm/radeon/radeon_vm.c | 16 + drivers/gpu/drm/ttm/ttm_bo.c | 187 ++++++------- drivers/gpu/drm/ttm/ttm_bo_util.c | 28 -- drivers/gpu/drm/ttm/ttm_bo_vm.c | 3 drivers/gpu/drm/ttm/ttm_execbuf_util.c | 146 +++------- drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c | 47 --- drivers/gpu/drm/vmwgfx/vmwgfx_drv.h | 1 drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c | 24 -- drivers/gpu/drm/vmwgfx/vmwgfx_fence.c | 329 ++++++++++++---------- drivers/gpu/drm/vmwgfx/vmwgfx_fence.h | 35 +- drivers/gpu/drm/vmwgfx/vmwgfx_resource.c | 43 +-- include/drm/ttm/ttm_bo_api.h | 7 include/drm/ttm/ttm_bo_driver.h | 29 -- include/drm/ttm/ttm_execbuf_util.h | 22 + 44 files changed, 1256 insertions(+), 1150 deletions(-) delete mode 100644 drivers/gpu/drm/qxl/qxl_fence.c
Signature · 1 line
Signature
PATCH 1/17 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
@@ -364,7 +364,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
@@ -2465,7 +2465,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;
@@ -2655,10 +2655,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 2/17 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 3/17 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 4/17 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 5/17 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,0 );
@@ -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 6/17 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 | 12 +++-- 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, 45 insertions(+), 140 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 +9 -3
@@ -544,10 +544,16 @@ static int radeon_crtc_page_flip(struct drm_crtc *crtc, obj = new_radeon_fb->obj; work->new_rbo =gem_to_radeon_bo (obj); -spin_lock (&work->new_rbo->tbo.bdev->fence_lock); -if (work->new_rbo->tbo.sync_obj) +if (work->new_rbo->tbo.sync_obj) { +int ret =ttm_bo_reserve (&work->new_rbo->tbo, true, false, false,NULL ); +if (ret) { +drm_gem_object_unreference_unlocked (&work->old_rbo->gem_base); +kfree (work); +return ret; + } work->fence =radeon_fence_ref (work->new_rbo->tbo.sync_obj); -spin_unlock (&work->new_rbo->tbo.bdev->fence_lock); +ttm_bo_unreserve (&work->new_rbo->tbo); + }/* We borrow the event spin lock for protecting flip_work */ spin_lock_irqsave (&crtc->dev->event_lock, flags);
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
@@ -518,8 +518,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.
@@ -539,7 +537,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 7/17 drm/nouveau: rework to new fence interface
In reply to Maarten LankhorstFrom: Maarten Lankhorst <[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 8/17 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 | 60 ++++++++++++++++++++++----------- 1 file changed, 40 insertions(+), 20 deletions(-)
drivers/gpu/drm/radeon/radeon_fence.c +40 -20
@@ -283,28 +283,35 @@ 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; -int i, r; +int i;while (!radeon_fence_any_seq_signaled (rdev, target_seq)) { +long r, waited; + + waited = timeout <RADEON_FENCE_JIFFIES_TIMEOUT ? + timeout :RADEON_FENCE_JIFFIES_TIMEOUT ;/* Save current sequence values, used to check for GPU lockups */ for (i =0 ; i <RADEON_NUM_RINGS ; ++i) {
@@ -319,11 +326,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), waited); }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), waited); }for (i =0 ; i <RADEON_NUM_RINGS ; ++i) {
@@ -337,6 +344,14 @@ static int radeon_fence_wait_seq(struct radeon_device *rdev, u64 *target_seq,if (unlikely (r <0 ))return r; + timeout -= waited - r; + +/* +* If this is a timed wait and the wait completely timed out just return. +*/ +if (!timeout) +break ; +if (unlikely (!signaled)) {if (rdev->needs_reset)return -EDEADLK ;
@@ -379,14 +394,14 @@ static int radeon_fence_wait_seq(struct radeon_device *rdev, u64 *target_seq, } } } -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
@@ -396,7 +411,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);
@@ -407,9 +422,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 ;
@@ -434,7 +450,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 ;
@@ -455,8 +471,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 ;
@@ -475,6 +491,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]) {
@@ -482,7 +499,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 ; }/**
@@ -498,18 +518,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 9/17 drm/radeon: use common fence implementation for fences
In reply to Maarten Lankhorst--- drivers/gpu/drm/radeon/radeon.h | 15 +- drivers/gpu/drm/radeon/radeon_device.c | 60 ++++++++- drivers/gpu/drm/radeon/radeon_fence.c | 223 ++++++++++++++++++++++++++------ 3 files changed, 248 insertions(+), 50 deletions(-)
drivers/gpu/drm/radeon/radeon.h +6 -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
@@ -350,12 +348,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);
@@ -2268,6 +2269,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;
@@ -2358,11 +2360,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 +59 -1
96 lines not on this page · raw message
drivers/gpu/drm/radeon/radeon_fence.c +183 -40
311 lines not on this page · raw message
Deucher, Alexander
maintainerRE: [PATCH 09/17] drm/radeon: use common fence implementation for fences
Quoted 524 lines
-----Original Message-----
From: Maarten Lankhorst [mailto:[email protected]]
Sent: Wednesday, July 09, 2014 8:30 AM
To: [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; Deucher, Alexander; Koenig, Christian
Subject: [PATCH 09/17] drm/radeon: use common fence implementation for fencesSigned-off-by Maarten Lankhorst <[email protected]>--- drivers/gpu/drm/radeon/radeon.h | 15 +- drivers/gpu/drm/radeon/radeon_device.c | 60 ++++++++- drivers/gpu/drm/radeon/radeon_fence.c | 223 ++++++++++++++++++++++++++------ 3 files changed, 248 insertions(+), 50 deletions(-)drivers/gpu/drm/radeon/radeon.h +6
-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@@ -350,12 +348,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);@@ -2268,6 +2269,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;@@ -2358,11 +2360,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 +1
-0@@ -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-Quoted 1 line
device,
drivers/gpu/drm/radeon/radeon_device.c +48
-0@@ -1607,6 +1608,54 @@ int radeon_resume_kms(struct drm_device *dev, bool resume, bool fbcon) return 0; } +static uint32_t radeon_gpu_mask_sw_irq (struct radeon_device *rdev) +{ +uint32_t mask =0 ; +int i; + +if (!rdev->ddev->irq_enabled) +return mask; + +/* +* increase refcount on sw interrupts for all rings to stop +* enabling interrupts in radeon_fence_enable_signaling during +* gpu reset. +*/ + +for (i =0 ; i <RADEON_NUM_RINGS ; ++i) { +if (!rdev->ring[i].ready) +continue ; + +atomic_inc (&rdev->irq.ring_int[i]); + mask |=1 << i; + } +return mask; +} + +static void radeon_gpu_unmask_sw_irq (struct radeon_device *rdev,uint32_t mask) +{ +unsigned long irqflags; +int i; + +if (!mask) +return ; + +/* +* undo refcount increase, and reset irqs to correct value. +*/ + +for (i =0 ; i <RADEON_NUM_RINGS ; ++i) { +if (!(mask & (1 << i))) +continue ; + +atomic_dec (&rdev->irq.ring_int[i]); + } + +spin_lock_irqsave (&rdev->irq.lock, irqflags); +radeon_irq_set (rdev); +spin_unlock_irqrestore (&rdev->irq.lock, irqflags); +} +/** *
radeon_gpu_reset- reset the asic
*drivers/gpu/drm/radeon/radeon_device.c +10
-1@@ -1624,6 +1673,7 @@ int radeon_gpu_reset(struct radeon_device *rdev)int i, r;int resched; +uint32_t sw_mask;down_write (&rdev->exclusive_lock);@@ -1637,6 +1687,7 @@ 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); + sw_mask =radeon_gpu_mask_sw_irq (rdev);radeon_pm_suspend (rdev);radeon_suspend (rdev);@@ -1686,13 +1737,20 @@ retry:radeon_pm_resume (rdev);drm_helper_resume_force_mode (rdev->ddev); +radeon_gpu_unmask_sw_irq (rdev, sw_mask);ttm_bo_unlock_delayed_workqueue (&rdev->mman.bdev, resched);if (r) {/* bad news, how to tell it to userspace ? */ dev_info (rdev->dev,"GPU reset failed\n" ); } -up_write (&rdev->exclusive_lock); +/* +* force all waiters to recheck, some may have been +* added while the exclusive_lock was unavailable +*/ +downgrade_write (&rdev->exclusive_lock); +wake_up_all (&rdev->fence_queue); +up_read (&rdev->exclusive_lock);return r; }drivers/gpu/drm/radeon/radeon_fence.c +27
-10@@ -39,6 +39,15 @@#include "radeon.h" #include "radeon_trace.h" +static const struct fence_ops radeon_fence_ops; + +#define to_radeon_fence (p) \ + ({ \ + struct radeon_fence *__f; \ + __f = container_of((p), struct radeon_fence, base); \ + __f->base.ops == &radeon_fence_ops ? __f : NULL; \ + }) +/* * Fences * Fences mark an event in the GPUs pipeline and are used @@ -111,30 +120,55 @@ int radeon_fence_emit(struct radeon_device *rdev, struct radeon_fence **fence, int ring) { +u64 seq = ++rdev->fence_drv[ring].sync_seq[ring]; +/* we are protected by the ring emission mutex */ *fence =kmalloc (sizeof (struct radeon_fence ),GFP_KERNEL );if ((*fence) ==NULL ) {return -ENOMEM ; } -kref_init (&((*fence)->kref)); - (*fence)->rdev = rdev; - (*fence)->seq = ++rdev->fence_drv[ring].sync_seq[ring]; (*fence)->ring = ring; +fence_init (&(*fence)->base, &radeon_fence_ops, + &rdev->fence_queue.lock, rdev->fence_context + ring, seq); + (*fence)->rdev = rdev; + (*fence)->seq = seq;radeon_fence_ring_emit (rdev, ring, *fence);trace_radeon_fence_emit (rdev->ddev, ring, (*fence)->seq);return 0 ; }/** -* radeon_fence_process - process a fence +* radeon_fence_check_signaled - callback from fence_queue * -* @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). +* this function is called with fence_queue lock held, which is also used +* for the fence locking itself, so unlocked variants are used for +* fence_signal, and remove_wait_queue. */ -void radeon_fence_process(struct radeon_device *rdev, int ring) +static int radeon_fence_check_signaled(wait_queue_t *wait, unsigned mode, int flags, void *key) +{ + struct radeon_fence *fence; + u64 seq; + + fence = container_of(wait, struct radeon_fence, fence_wake); + + seq = atomic64_read(&fence->rdev->fence_drv[fence-Quoted 1 line
ring].last_seq);
drivers/gpu/drm/radeon/radeon_fence.c +5
-0+if (seq >= fence->seq) { +int ret =fence_signal_locked (&fence->base); + +if (!ret) + FENCE_TRACE(&fence->base, "signaled from irqcontext\n");
drivers/gpu/drm/radeon/radeon_fence.c +2
-0+else + FENCE_TRACE(&fence->base, "was alreadysignaled\n");
drivers/gpu/drm/radeon/radeon_fence.c +3
-0+ +radeon_irq_kms_sw_irq_put (fence->rdev, fence->ring); + __remove_wait_queue(&fence->rdev->fence_queue,
&fence->fence_wake);drivers/gpu/drm/radeon/radeon_fence.c +16
-10+fence_put (&fence->base); + }else +FENCE_TRACE (&fence->base,"pending\n" ); +return 0 ; +} + +static bool __radeon_fence_process (struct radeon_device *rdev,int ring) {uint64_t seq, last_seq, last_emitted;unsigned count_loop =0 ;@@ -190,23 +224,22 @@ void radeon_fence_process(struct radeon_device *rdev, int ring) } } while (atomic64_xchg(&rdev->fence_drv[ring].last_seq, seq) > seq); -if (wake) -wake_up_all (&rdev->fence_queue); +return wake; }/** -* radeon_fence_destroy - destroy a fence +* radeon_fence_process - process a fence * -* @kref: fence kref +* @rdev: radeon_device pointer +* @ring: ring index the fence is associated with * -* Frees the fence object (all asics). +* Checks the current fence value and wakes the fence queue +* if the sequence number has increased (all asics). */ -static void radeon_fence_destroy (struct kref *kref) +void radeon_fence_process (struct radeon_device *rdev,int ring) { -struct radeon_fence *fence; - - fence = container_of(kref, struct radeon_fence, kref); -kfree (fence); +if (__radeon_fence_process (rdev, ring)) +wake_up_all (&rdev->fence_queue); }/**
drivers/gpu/drm/radeon/radeon_fence.c +36
-0@@ -237,6 +270,69 @@ static bool radeon_fence_seq_signaled(structradeon_device *rdev, return false; } +static bool __radeon_fence_signaled (struct fence *f) +{ +struct radeon_fence *fence =to_radeon_fence (f); +struct radeon_device *rdev = fence->rdev; +unsigned ring = fence->ring; +u64 seq = fence->seq; + +if (atomic64_read (&rdev->fence_drv[ring].last_seq) >= seq) { +return true; + } + +if (down_read_trylock (&rdev->exclusive_lock)) { +radeon_fence_process (rdev, ring); +up_read (&rdev->exclusive_lock); + +if (atomic64_read (&rdev->fence_drv[ring].last_seq) >= seq) { +return true; + } + } +return false; +} + +/** +* radeon_fence_enable_signaling - enable signalling on fence +* @fence: fence +* +* This function is called with fence_queue lock held, and adds a callback +* to fence_queue that checks if this fence is signaled, and if so it +* signals the fence and removes itself. +*/ +static bool radeon_fence_enable_signaling (struct fence *f) +{ +struct radeon_fence *fence =to_radeon_fence (f); +struct radeon_device *rdev = fence->rdev; + + if (atomic64_read(&rdev->fence_drv[fence->ring].last_seq) >=
fence->seq||drivers/gpu/drm/radeon/radeon_fence.c +14
-0+ !rdev->ddev->irq_enabled) +return false; + +radeon_irq_kms_sw_irq_get (rdev, fence->ring); + +if (down_read_trylock (&rdev->exclusive_lock)) { +if (__radeon_fence_process (rdev, fence->ring)) +wake_up_all_locked (&rdev->fence_queue); + +up_read (&rdev->exclusive_lock); + } + +/* did fence get signaled after we enabled the sw irq? */ + if (atomic64_read(&rdev->fence_drv[fence->ring].last_seq) >=
fence->seq) {drivers/gpu/drm/radeon/radeon_fence.c +19
-4+radeon_irq_kms_sw_irq_put (rdev, fence->ring); +return false; + } + + fence->fence_wake.flags =0 ; + fence->fence_wake.private =NULL ; + fence->fence_wake.func = radeon_fence_check_signaled; +__add_wait_queue (&rdev->fence_queue, &fence->fence_wake); +fence_get (f); + +return true; +} +/** * radeon_fence_signaled - check if a fence has signaled * @@ -250,11 +346,13 @@ bool radeon_fence_signaled(struct radeon_fence *fence)if (!fence) {return true; } -if (fence->seq ==RADEON_FENCE_SIGNALED_SEQ ) { -return true; - } +if (radeon_fence_seq_signaled (fence->rdev, fence->seq, fence- >ring)) { - fence->seq =RADEON_FENCE_SIGNALED_SEQ ; +int ret; + + ret =fence_signal (&fence->base); +if (!ret) +FENCE_TRACE (&fence->base,"signaled from radeon_fence_signaled\n");drivers/gpu/drm/radeon/radeon_fence.c +5
-8return true; }return false;@@ -413,21 +511,18 @@ int radeon_fence_wait(struct radeon_fence *fence, bool intr)uint64_t seq[RADEON_NUM_RINGS ] = {};long r; -if (fence ==NULL ) { -WARN (1 ,"Querying an invalid fence : %p !\n" , fence); -return -EINVAL ; - } - - seq[fence->ring] = fence->seq; -if (seq[fence->ring] ==RADEON_FENCE_SIGNALED_SEQ ) +if (test_bit (FENCE_FLAG_SIGNALED_BIT , &fence->base.flags))return 0 ; + seq[fence->ring] = fence->seq; r =radeon_fence_wait_seq_timeout (fence->rdev, seq, intr,MAX_SCHEDULE_TIMEOUT );if (r <0 ) {return r; } - fence->seq =RADEON_FENCE_SIGNALED_SEQ ; + r =fence_signal (&fence->base); +if (!r) +FENCE_TRACE (&fence->base,"signaled from fence_wait\n");drivers/gpu/drm/radeon/radeon_fence.c +5
-4return 0 ; }@@ -459,12 +554,13 @@ int radeon_fence_wait_any(struct radeon_device *rdev, continue; } +if (test_bit (FENCE_FLAG_SIGNALED_BIT , &fences[i]- >base.flags)) { +/* already signaled */ +return 0 ; + } + seq[i] = fences[i]->seq; ++num_rings; - -/* test if something was allready signaled */ -if (seq[i] ==RADEON_FENCE_SIGNALED_SEQ ) -return 0 ; }drivers/gpu/drm/radeon/radeon_fence.c +3
-4/* nothing to wait for ? */ @@ -545,7 +641,7 @@ int radeon_fence_wait_empty(struct radeon_device*rdev, int ring) */ struct radeon_fence *radeon_fence_ref (struct radeon_fence *fence) { -kref_get (&fence->kref); +fence_get (&fence->base);return fence; }@@ -561,9 +657,8 @@ void radeon_fence_unref(struct radeon_fence **fence)struct radeon_fence *tmp = *fence; *fence =NULL ; -if (tmp) { -kref_put (&tmp->kref, radeon_fence_destroy); - } +if (tmp) +fence_put (&tmp->base); }/**
drivers/gpu/drm/radeon/radeon_fence.c +12
-0@@ -872,3 +967,51 @@ int radeon_debugfs_fence_init(struct radeon_device *rdev)return 0 ;#endif } + +static long __radeon_fence_wait (struct fence *f,bool intr,long timeout) +{ +struct radeon_fence *fence =to_radeon_fence (f); +u64 target_seq[RADEON_NUM_RINGS ] = {}; +struct radeon_device *rdev = fence->rdev; +long r; + + target_seq[fence->ring] = fence->seq; + +down_read (&rdev->exclusive_lock); + r = radeon_fence_wait_seq_timeout(fence->rdev, target_seq, intr,timeout);
drivers/gpu/drm/radeon/radeon_fence.c +3
-0+ +if (r >0 && !fence_signal (&fence->base)) + FENCE_TRACE(&fence->base, "signaled from__radeon_fence_wait\n");
drivers/gpu/drm/radeon/radeon_fence.c +11
-0+ +up_read (&rdev->exclusive_lock); +return r; + +} + +static const char *radeon_fence_get_driver_name (struct fence *fence) +{ +return "radeon" ; +} +
drivers/gpu/drm/radeon/radeon_fence.c int radeon_debugfs_fence_init(struct radeon_device *rdev) · line 1005
Quoted 10 lines
drivers/gpu/drm/radeon/radeon_fence.c +10
-0+static const char *radeon_fence_get_timeline_name (struct fence *f) +{ +struct radeon_fence *fence =to_radeon_fence (f); +switch (fence->ring) { +case RADEON_RING_TYPE_GFX_INDEX :return "radeon.gfx" ; +case CAYMAN_RING_TYPE_CP1_INDEX :return "radeon.cp1" ; +case CAYMAN_RING_TYPE_CP2_INDEX :return "radeon.cp2" ; +case R600_RING_TYPE_DMA_INDEX :return "radeon.dma" ; +case CAYMAN_RING_TYPE_DMA1_INDEX :return "radeon.dma1" ; +case R600_RING_TYPE_UVD_INDEX :return "radeon.uvd" ;
Radeon supports vce rings on newer ascis. Probably want to add the case for those here too.
Alex
Quoted 12 lines
drivers/gpu/drm/radeon/radeon_fence.c +12
-0+default :WARN_ON_ONCE (1 );return "radeon.unk" ; + } +} + +static const struct fence_ops radeon_fence_ops = { + .get_driver_name = radeon_fence_get_driver_name, + .get_timeline_name = radeon_fence_get_timeline_name, + .enable_signaling = radeon_fence_enable_signaling, + .signaled = __radeon_fence_signaled, + .wait = __radeon_fence_wait, + .release =NULL , +};
PATCH v2 9/17 drm/radeon: use common fence implementation for fences
op 09-07-14 14:57, Deucher, Alexander schreef:
Quoted 13 lines
Review
Quoted 11 lines
<snip>
(quoted diff) +10
-0+static const char *radeon_fence_get_timeline_name(struct fence *f) +{ + struct radeon_fence *fence = to_radeon_fence(f); + switch (fence->ring) { + case RADEON_RING_TYPE_GFX_INDEX: return "radeon.gfx"; + case CAYMAN_RING_TYPE_CP1_INDEX: return "radeon.cp1"; + case CAYMAN_RING_TYPE_CP2_INDEX: return "radeon.cp2"; + case R600_RING_TYPE_DMA_INDEX: return "radeon.dma"; + case CAYMAN_RING_TYPE_DMA1_INDEX: return "radeon.dma1"; + case R600_RING_TYPE_UVD_INDEX: return "radeon.uvd";Radeon supports vce rings on newer ascis. Probably want to add the case for those here too.
Quoted 2 lines
Alex
Indeed, how about this?
----------8<-------
--- drivers/gpu/drm/radeon/radeon.h | 15 +-- drivers/gpu/drm/radeon/radeon_device.c | 60 ++++++++- drivers/gpu/drm/radeon/radeon_fence.c | 225 +++++++++++++++++++++++++++------ 3 files changed, 250 insertions(+), 50 deletions(-)
drivers/gpu/drm/radeon/radeon.h +6 -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
@@ -350,12 +348,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);
@@ -2268,6 +2269,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;
@@ -2358,11 +2360,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 +59 -1
96 lines not on this page · raw message
drivers/gpu/drm/radeon/radeon_fence.c +185 -40
313 lines not on this page · raw message
Signature · 1 line
2.0.0
Re: [PATCH v2 09/17] drm/radeon: use common fence implementation for fences
Quoted 14 lines · Maarten Lankhorst
op 09-07-14 14:57, Deucher, Alexander schreef:
Quoted 13 lines
drivers/gpu/drm/radeon/radeon_fence.c int radeon_debugfs_fence_init(struct radeon_device *rdev) · line 1005
Quoted 11 lines
<snip>
drivers/gpu/drm/radeon/radeon_fence.c +10
-0+static const char *radeon_fence_get_timeline_name (struct fence *f) +{ +struct radeon_fence *fence =to_radeon_fence (f); +switch (fence->ring) { +case RADEON_RING_TYPE_GFX_INDEX :return "radeon.gfx" ; +case CAYMAN_RING_TYPE_CP1_INDEX :return "radeon.cp1" ; +case CAYMAN_RING_TYPE_CP2_INDEX :return "radeon.cp2" ; +case R600_RING_TYPE_DMA_INDEX :return "radeon.dma" ; +case CAYMAN_RING_TYPE_DMA1_INDEX :return "radeon.dma1" ; +case R600_RING_TYPE_UVD_INDEX :return "radeon.uvd" ;Radeon supports vce rings on newer ascis. Probably want to add the case for those here too.
Quoted 3 lines
Quoted 2 lines
Alex
Indeed, how about this?
Looks good. I'll let Christian comment on the rest of the changes.
Alex
Quoted 507 lines
----------8<-------
Signed-off-by Maarten Lankhorst <[email protected]>--- drivers/gpu/drm/radeon/radeon.h | 15 +-- drivers/gpu/drm/radeon/radeon_device.c | 60 ++++++++- drivers/gpu/drm/radeon/radeon_fence.c | 225 +++++++++++++++++++++++++++------ 3 files changed, 250 insertions(+), 50 deletions(-)drivers/gpu/drm/radeon/radeon.h +6
-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@@ -350,12 +348,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);@@ -2268,6 +2269,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;@@ -2358,11 +2360,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 +59
-1@@ -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,@@ -1607,6 +1608,54 @@ int radeon_resume_kms(struct drm_device *dev, bool resume, bool fbcon)return 0 ; } +static uint32_t radeon_gpu_mask_sw_irq (struct radeon_device *rdev) +{ +uint32_t mask =0 ; +int i; + +if (!rdev->ddev->irq_enabled) +return mask; + +/* +* increase refcount on sw interrupts for all rings to stop +* enabling interrupts in radeon_fence_enable_signaling during +* gpu reset. +*/ + +for (i =0 ; i <RADEON_NUM_RINGS ; ++i) { +if (!rdev->ring[i].ready) +continue ; + +atomic_inc (&rdev->irq.ring_int[i]); + mask |=1 << i; + } +return mask; +} + +static void radeon_gpu_unmask_sw_irq (struct radeon_device *rdev,uint32_t mask) +{ +unsigned long irqflags; +int i; + +if (!mask) +return ; + +/* +* undo refcount increase, and reset irqs to correct value. +*/ + +for (i =0 ; i <RADEON_NUM_RINGS ; ++i) { +if (!(mask & (1 << i))) +continue ; + +atomic_dec (&rdev->irq.ring_int[i]); + } + +spin_lock_irqsave (&rdev->irq.lock, irqflags); +radeon_irq_set (rdev); +spin_unlock_irqrestore (&rdev->irq.lock, irqflags); +} +/** * radeon_gpu_reset - reset the asic * @@ -1624,6 +1673,7 @@ int radeon_gpu_reset(struct radeon_device *rdev)int i, r;int resched; +uint32_t sw_mask;down_write (&rdev->exclusive_lock);@@ -1637,6 +1687,7 @@ 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); + sw_mask =radeon_gpu_mask_sw_irq (rdev);radeon_pm_suspend (rdev);radeon_suspend (rdev);@@ -1686,13 +1737,20 @@ retry:radeon_pm_resume (rdev);drm_helper_resume_force_mode (rdev->ddev); +radeon_gpu_unmask_sw_irq (rdev, sw_mask);ttm_bo_unlock_delayed_workqueue (&rdev->mman.bdev, resched);if (r) {/* bad news, how to tell it to userspace ? */ dev_info (rdev->dev,"GPU reset failed\n" ); } -up_write (&rdev->exclusive_lock); +/* +* force all waiters to recheck, some may have been +* added while the exclusive_lock was unavailable +*/ +downgrade_write (&rdev->exclusive_lock); +wake_up_all (&rdev->fence_queue); +up_read (&rdev->exclusive_lock);return r; }drivers/gpu/drm/radeon/radeon_fence.c +185
-41@@ -39,6 +39,15 @@#include "radeon.h" #include "radeon_trace.h" +static const struct fence_ops radeon_fence_ops; + +#define to_radeon_fence (p) \ + ({ \ + struct radeon_fence *__f; \ + __f = container_of((p), struct radeon_fence, base); \ + __f->base.ops == &radeon_fence_ops ? __f : NULL; \ + }) +/* * Fences * Fences mark an event in the GPUs pipeline and are used @@ -111,30 +120,55 @@ int radeon_fence_emit(struct radeon_device *rdev, struct radeon_fence **fence, int ring) { +u64 seq = ++rdev->fence_drv[ring].sync_seq[ring]; +/* we are protected by the ring emission mutex */ *fence =kmalloc (sizeof (struct radeon_fence ),GFP_KERNEL );if ((*fence) ==NULL ) {return -ENOMEM ; } -kref_init (&((*fence)->kref)); - (*fence)->rdev = rdev; - (*fence)->seq = ++rdev->fence_drv[ring].sync_seq[ring]; (*fence)->ring = ring; +fence_init (&(*fence)->base, &radeon_fence_ops, + &rdev->fence_queue.lock, rdev->fence_context + ring, seq); + (*fence)->rdev = rdev; + (*fence)->seq = seq;radeon_fence_ring_emit (rdev, ring, *fence);trace_radeon_fence_emit (rdev->ddev, ring, (*fence)->seq);return 0 ; }/** -* radeon_fence_process - process a fence +* radeon_fence_check_signaled - callback from fence_queue * -* @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). +* this function is called with fence_queue lock held, which is also used +* for the fence locking itself, so unlocked variants are used for +* fence_signal, and remove_wait_queue. */ -void radeon_fence_process (struct radeon_device *rdev,int ring) +static int radeon_fence_check_signaled (wait_queue_t *wait,unsigned mode,int flags,void *key) +{ +struct radeon_fence *fence; +u64 seq; + + fence = container_of(wait, struct radeon_fence, fence_wake); + + seq =atomic64_read (&fence->rdev->fence_drv[fence->ring].last_seq); +if (seq >= fence->seq) { +int ret =fence_signal_locked (&fence->base); + +if (!ret) +FENCE_TRACE (&fence->base,"signaled from irq context\n" ); +else +FENCE_TRACE (&fence->base,"was already signaled\n" ); + +radeon_irq_kms_sw_irq_put (fence->rdev, fence->ring); +__remove_wait_queue (&fence->rdev->fence_queue, &fence->fence_wake); +fence_put (&fence->base); + }else +FENCE_TRACE (&fence->base,"pending\n" ); +return 0 ; +} + +static bool __radeon_fence_process (struct radeon_device *rdev,int ring) {uint64_t seq, last_seq, last_emitted;unsigned count_loop =0 ;@@ -190,23 +224,22 @@ void radeon_fence_process(struct radeon_device *rdev, int ring) } }while (atomic64_xchg (&rdev->fence_drv[ring].last_seq, seq) > seq); -if (wake) -wake_up_all (&rdev->fence_queue); +return wake; }/** -* radeon_fence_destroy - destroy a fence +* radeon_fence_process - process a fence * -* @kref: fence kref +* @rdev: radeon_device pointer +* @ring: ring index the fence is associated with * -* Frees the fence object (all asics). +* Checks the current fence value and wakes the fence queue +* if the sequence number has increased (all asics). */ -static void radeon_fence_destroy (struct kref *kref) +void radeon_fence_process (struct radeon_device *rdev,int ring) { -struct radeon_fence *fence; - - fence = container_of(kref, struct radeon_fence, kref); -kfree (fence); +if (__radeon_fence_process (rdev, ring)) +wake_up_all (&rdev->fence_queue); }/** @@ -237,6 +270,69 @@ static bool radeon_fence_seq_signaled(struct radeon_device *rdev,return false; } +static bool __radeon_fence_signaled (struct fence *f) +{ +struct radeon_fence *fence =to_radeon_fence (f); +struct radeon_device *rdev = fence->rdev; +unsigned ring = fence->ring; +u64 seq = fence->seq; + +if (atomic64_read (&rdev->fence_drv[ring].last_seq) >= seq) { +return true; + } + +if (down_read_trylock (&rdev->exclusive_lock)) { +radeon_fence_process (rdev, ring); +up_read (&rdev->exclusive_lock); + +if (atomic64_read (&rdev->fence_drv[ring].last_seq) >= seq) { +return true; + } + } +return false; +} + +/** +* radeon_fence_enable_signaling - enable signalling on fence +* @fence: fence +* +* This function is called with fence_queue lock held, and adds a callback +* to fence_queue that checks if this fence is signaled, and if so it +* signals the fence and removes itself. +*/ +static bool radeon_fence_enable_signaling (struct fence *f) +{ +struct radeon_fence *fence =to_radeon_fence (f); +struct radeon_device *rdev = fence->rdev; + +if (atomic64_read (&rdev->fence_drv[fence->ring].last_seq) >= fence->seq || + !rdev->ddev->irq_enabled) +return false; + +radeon_irq_kms_sw_irq_get (rdev, fence->ring); + +if (down_read_trylock (&rdev->exclusive_lock)) { +if (__radeon_fence_process (rdev, fence->ring)) +wake_up_all_locked (&rdev->fence_queue); + +up_read (&rdev->exclusive_lock); + } + +/* did fence get signaled after we enabled the sw irq? */ +if (atomic64_read (&rdev->fence_drv[fence->ring].last_seq) >= fence->seq) { +radeon_irq_kms_sw_irq_put (rdev, fence->ring); +return false; + } + + fence->fence_wake.flags =0 ; + fence->fence_wake.private =NULL ; + fence->fence_wake.func = radeon_fence_check_signaled; +__add_wait_queue (&rdev->fence_queue, &fence->fence_wake); +fence_get (f); + +return true; +} +/** * radeon_fence_signaled - check if a fence has signaled * @@ -250,11 +346,13 @@ bool radeon_fence_signaled(struct radeon_fence *fence)if (!fence) {return true; } -if (fence->seq ==RADEON_FENCE_SIGNALED_SEQ ) { -return true; - } +if (radeon_fence_seq_signaled (fence->rdev, fence->seq, fence->ring)) { - fence->seq =RADEON_FENCE_SIGNALED_SEQ ; +int ret; + + ret =fence_signal (&fence->base); +if (!ret) +FENCE_TRACE (&fence->base,"signaled from radeon_fence_signaled\n" );return true; }return false;@@ -413,21 +511,18 @@ int radeon_fence_wait(struct radeon_fence *fence, bool intr)uint64_t seq[RADEON_NUM_RINGS ] = {};long r; -if (fence ==NULL ) { -WARN (1 ,"Querying an invalid fence : %p !\n" , fence); -return -EINVAL ; - } - - seq[fence->ring] = fence->seq; -if (seq[fence->ring] ==RADEON_FENCE_SIGNALED_SEQ ) +if (test_bit (FENCE_FLAG_SIGNALED_BIT , &fence->base.flags))return 0 ; + seq[fence->ring] = fence->seq; r =radeon_fence_wait_seq_timeout (fence->rdev, seq, intr,MAX_SCHEDULE_TIMEOUT );if (r <0 ) {return r; } - fence->seq =RADEON_FENCE_SIGNALED_SEQ ; + r =fence_signal (&fence->base); +if (!r) +FENCE_TRACE (&fence->base,"signaled from fence_wait\n" );return 0 ; }@@ -459,12 +554,13 @@ int radeon_fence_wait_any(struct radeon_device *rdev,continue ; } +if (test_bit (FENCE_FLAG_SIGNALED_BIT , &fences[i]->base.flags)) { +/* already signaled */ +return 0 ; + } + seq[i] = fences[i]->seq; ++num_rings; - -/* test if something was allready signaled */ -if (seq[i] ==RADEON_FENCE_SIGNALED_SEQ ) -return 0 ; }/* nothing to wait for ? */ @@ -545,7 +641,7 @@ int radeon_fence_wait_empty(struct radeon_device *rdev, int ring)*/ struct radeon_fence *radeon_fence_ref (struct radeon_fence *fence) { -kref_get (&fence->kref); +fence_get (&fence->base);return fence; }@@ -561,9 +657,8 @@ void radeon_fence_unref(struct radeon_fence **fence)struct radeon_fence *tmp = *fence; *fence =NULL ; -if (tmp) { -kref_put (&tmp->kref, radeon_fence_destroy); - } +if (tmp) +fence_put (&tmp->base); }/** @@ -872,3 +967,53 @@ int radeon_debugfs_fence_init(struct radeon_device *rdev)return 0 ;#endif } + +static long __radeon_fence_wait (struct fence *f,bool intr,long timeout) +{ +struct radeon_fence *fence =to_radeon_fence (f); +u64 target_seq[RADEON_NUM_RINGS ] = {}; +struct radeon_device *rdev = fence->rdev; +long r; + + target_seq[fence->ring] = fence->seq; + +down_read (&rdev->exclusive_lock); + r =radeon_fence_wait_seq_timeout (fence->rdev, target_seq, intr, timeout); + +if (r >0 && !fence_signal (&fence->base)) +FENCE_TRACE (&fence->base,"signaled from __radeon_fence_wait\n" ); + +up_read (&rdev->exclusive_lock); +return r; + +} + +static const char *radeon_fence_get_driver_name (struct fence *fence) +{ +return "radeon" ; +} + +static const char *radeon_fence_get_timeline_name (struct fence *f) +{ +struct radeon_fence *fence =to_radeon_fence (f); +switch (fence->ring) { +case RADEON_RING_TYPE_GFX_INDEX :return "radeon.gfx" ; +case CAYMAN_RING_TYPE_CP1_INDEX :return "radeon.cp1" ; +case CAYMAN_RING_TYPE_CP2_INDEX :return "radeon.cp2" ; +case R600_RING_TYPE_DMA_INDEX :return "radeon.dma" ; +case CAYMAN_RING_TYPE_DMA1_INDEX :return "radeon.dma1" ; +case R600_RING_TYPE_UVD_INDEX :return "radeon.uvd" ; +case TN_RING_TYPE_VCE1_INDEX :return "radeon.vce1" ; +case TN_RING_TYPE_VCE2_INDEX :return "radeon.vce2" ; +default :WARN_ON_ONCE (1 );return "radeon.unk" ; + } +} + +static const struct fence_ops radeon_fence_ops = { + .get_driver_name = radeon_fence_get_driver_name, + .get_timeline_name = radeon_fence_get_timeline_name, + .enable_signaling = radeon_fence_enable_signaling, + .signaled = __radeon_fence_signaled, + .wait = __radeon_fence_wait, + .release =NULL , +}; --2.0.0
_______________________________________________
dri-devel mailing list [email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Dave Airlie
maintainerRe: [PATCH 09/17] drm/radeon: use common fence implementation for fences
In reply to Maarten LankhorstQuoted 9 lines · Maarten Lankhorst
Signed-off-by Maarten Lankhorst <[email protected]>--- drivers/gpu/drm/radeon/radeon.h | 15 +- drivers/gpu/drm/radeon/radeon_device.c | 60 ++++++++- drivers/gpu/drm/radeon/radeon_fence.c | 223 ++++++++++++++++++++++++++------ 3 files changed, 248 insertions(+), 50 deletions(-)From what I can see this is still suffering from the problem that we
need to find a proper solution to,
My summary of the issues after talking to Jerome and Ben and re-reading things is:
We really need to work out a better interface into the drivers to be able to avoid random atomic entrypoints,
I'm sure you have some ideas and I think you really need to investigate them to move this thing forward,
even it if means some issues with android sync pts.
but none of the two major drivers seem to want the interface as-is so something needs to give
My major question is why we need an atomic callback here at all, what scenario does it cover?
Surely we can use a workqueue based callback to ask a driver to check its signalling, is it really
that urgent?
Dave.
Christian König
maintainerRe: [PATCH 09/17] drm/radeon: use common fence implementation for fences
Am 22.07.2014 06:05, schrieb Dave Airlie:
Quoted 8 lines · Maarten Lankhorst
Quoted 7 lines
Signed-off-by Maarten Lankhorst <[email protected]>--- drivers/gpu/drm/radeon/radeon.h | 15 +- drivers/gpu/drm/radeon/radeon_device.c | 60 ++++++++- drivers/gpu/drm/radeon/radeon_fence.c | 223 ++++++++++++++++++++++++++------ 3 files changed, 248 insertions(+), 50 deletions(-)
Quoted 8 lines
From what I can see this is still suffering from the problem that we
need to find a proper solution to,My summary of the issues after talking to Jerome and Ben and re-reading things is:
We really need to work out a better interface into the drivers to be able to avoid random atomic entrypoints,
Which is exactly what I criticized from the very first beginning. Good to know that I'm not the only one thinking that this isn't such a good idea.
Quoted 3 lines
I'm sure you have some ideas and I think you really need to investigate them to move this thing forward,
even it if means some issues with android sync pts.
Actually I think that TTMs fence interface already gave quite a good hint how it might look like. I can only guess that this won't fit with the Android stuff, otherwise I can't see a good reason why we didn't stick with that.
Quoted 5 lines
but none of the two major drivers seem to want the interface as-is so something needs to give
My major question is why we need an atomic callback here at all, what scenario does it cover?
Agree totally. As far as I can see all current uses of the interface are of the kind of waiting for a fence to signal.
No need for any callback from one driver into another, especially not in atomic context. If a driver needs such a functionality it should just start up a kernel thread and do it's waiting there.
This obviously shouldn't be an obstacle for pure hardware implementations where one driver signals a semaphore another driver is waiting for, or a high signal on an interrupt line directly wired between two chips. And I think this is a completely different topic and not necessarily part of the common fence interface we should currently focus on.
Christian.
Quoted 5 lines
Surely we can use a workqueue based callback to ask a driver to check its signalling, is it really
that urgent?Dave.
Re: [PATCH 09/17] drm/radeon: use common fence implementation for fences
Quoted 12 lines · Christian König
Am 22.07.2014 06:05, schrieb Dave Airlie:
Quoted 11 lines · Maarten Lankhorst
Quoted 7 lines
Signed-off-by Maarten Lankhorst <[email protected]>--- drivers/gpu/drm/radeon/radeon.h | 15 +- drivers/gpu/drm/radeon/radeon_device.c | 60 ++++++++- drivers/gpu/drm/radeon/radeon_fence.c | 223 ++++++++++++++++++++++++++------ 3 files changed, 248 insertions(+), 50 deletions(-)From what I can see this is still suffering from the problem that we need to find a proper solution to,
Quoted 8 lines
Quoted 5 lines
My summary of the issues after talking to Jerome and Ben and re-reading things is:
We really need to work out a better interface into the drivers to be able to avoid random atomic entrypoints,
Which is exactly what I criticized from the very first beginning. Good to know that I'm not the only one thinking that this isn't such a good idea.
I guess I've lost context a bit, but which atomic entry point are we talking about? Afaics the only one that's mandatory is the is fence->signaled callback to check whether a fence really has been signalled. It's used internally by the fence code to avoid spurious wakeups. Afaik that should be doable already on any hardware. If that's not the case then we can always track the signalled state in software and double-check in a worker thread before updating the sw state. And wrap this all up into a special fence class if there's more than one driver needing this.
There is nothing else that forces callbacks from atomic contexts upon you. You can use them if you see it fit, but really if it doesn't suit your driver you can just ignore that part and do process based waits everywhere.
Quoted 8 lines
Quoted 3 lines
I'm sure you have some ideas and I think you really need to investigate them to move this thing forward,
even it if means some issues with android sync pts.Actually I think that TTMs fence interface already gave quite a good hint how it might look like. I can only guess that this won't fit with the Android stuff, otherwise I can't see a good reason why we didn't stick with that.
Well the current plan for i915<->radeon sync from Maarten is to use these atomic callbacks on the i915 side. So android didn't figure into this at all. Actually with android the entire implementation is kinda the platforms problem, the generic parts just give you a userspace interface and some means to stack up fences.
Quoted 13 lines
Quoted 5 lines
but none of the two major drivers seem to want the interface as-is so something needs to give
My major question is why we need an atomic callback here at all, what scenario does it cover?
Agree totally. As far as I can see all current uses of the interface are of the kind of waiting for a fence to signal.
No need for any callback from one driver into another, especially not in atomic context. If a driver needs such a functionality it should just start up a kernel thread and do it's waiting there.
Quoted 5 lines
This obviously shouldn't be an obstacle for pure hardware implementations where one driver signals a semaphore another driver is waiting for, or a high signal on an interrupt line directly wired between two chips. And I think this is a completely different topic and not necessarily part of the common fence interface we should currently focus on.
It's for mixed hw/sw stuff where we want to poke the hw from the irq context (if possible) since someone forgot the wire. At least on the i915 side it boils down to one mmio write, and it's fairly pointless to launch a thread for that.
So I haven't dug into ttm details but from the i915 side the current stuff and atomic semantics makes sense. Maybe we just need to wrap a bit more insulation around ttm-based drivers.
-Daniel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch
Re: [PATCH 09/17] drm/radeon: use common fence implementation for fences
Quoted 32 lines · Daniel Vetter
Quoted 12 lines · Christian König
Am 22.07.2014 06:05, schrieb Dave Airlie:
Quoted 11 lines · Maarten Lankhorst
Quoted 7 lines
Signed-off-by Maarten Lankhorst <[email protected]>--- drivers/gpu/drm/radeon/radeon.h | 15 +- drivers/gpu/drm/radeon/radeon_device.c | 60 ++++++++- drivers/gpu/drm/radeon/radeon_fence.c | 223 ++++++++++++++++++++++++++------ 3 files changed, 248 insertions(+), 50 deletions(-)From what I can see this is still suffering from the problem that we need to find a proper solution to,
Quoted 8 lines
Quoted 5 lines
My summary of the issues after talking to Jerome and Ben and re-reading things is:
We really need to work out a better interface into the drivers to be able to avoid random atomic entrypoints,
Which is exactly what I criticized from the very first beginning. Good to know that I'm not the only one thinking that this isn't such a good idea.
I guess I've lost context a bit, but which atomic entry point are we talking about? Afaics the only one that's mandatory is the is
fence->signaledcallback to check whether a fence really has been signalled. It's used internally by the fence code to avoid spurious wakeups. Afaik that should be doable already on any hardware. If that's not the case then we can always track the signalled state in software and double-check in a worker thread before updating the sw state. And wrap this all up into a special fence class if there's more than one driver needing this.
Quoted 4 lines
There is nothing else that forces callbacks from atomic contexts upon you. You can use them if you see it fit, but really if it doesn't suit your driver you can just ignore that part and do process based waits everywhere.
Aside: The fence-process-callback has already been implemented by nouveau with the struct fence_work in nouveau_fence.c. Would make loads of sense to move that code into the driver core and adapat it to Maarten's struct fence once this has all landed.
-Daniel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch
Re: [PATCH 09/17] drm/radeon: use common fence implementation for fences
In reply to Daniel VetterQuoted 22 lines · Daniel Vetter
Quoted 12 lines · Christian König
Am 22.07.2014 06:05, schrieb Dave Airlie:
Quoted 11 lines · Maarten Lankhorst
Quoted 7 lines
Signed-off-by Maarten Lankhorst <[email protected]>--- drivers/gpu/drm/radeon/radeon.h | 15 +- drivers/gpu/drm/radeon/radeon_device.c | 60 ++++++++- drivers/gpu/drm/radeon/radeon_fence.c | 223 ++++++++++++++++++++++++++------ 3 files changed, 248 insertions(+), 50 deletions(-)From what I can see this is still suffering from the problem that we need to find a proper solution to,
Quoted 8 lines
Quoted 5 lines
My summary of the issues after talking to Jerome and Ben and re-reading things is:
We really need to work out a better interface into the drivers to be able to avoid random atomic entrypoints,
Which is exactly what I criticized from the very first beginning. Good to know that I'm not the only one thinking that this isn't such a good idea.
Quoted 9 lines
I guess I've lost context a bit, but which atomic entry point are we talking about? Afaics the only one that's mandatory is the is
fence->signaledcallback to check whether a fence really has been signalled. It's used internally by the fence code to avoid spurious wakeups. Afaik that should be doable already on any hardware. If that's not the case then we can always track the signalled state in software and double-check in a worker thread before updating the sw state. And wrap this all up into a special fence class if there's more than one driver needing this.
One thing I've forgotten: The i915 scheduler that's floating around runs its bottom half from irq context. So I really want to be able to check fence state from irq context and I also want to make it possible (possible! not mandatory) to register callbacks which are run from any context asap after the fence is signalled.
If the radeon hw/driver doesn't want to cope with that complexity we can fully insolate it with the sw tracked fence state if you don't like Maarten's radeon implementation. But forcing everyone to forgoe this just because you don't like it and don't want to use it in radeon doesn't sound right.
-Daniel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch
Christian König
NAKRe: [PATCH 09/17] drm/radeon: use common fence implementation for fences
Am 22.07.2014 13:57, schrieb Daniel Vetter:
Quoted 30 lines · Daniel Vetter
Quoted 20 lines · Christian König
Quoted 12 lines
Am 22.07.2014 06:05, schrieb Dave Airlie:
Quoted 11 lines · Maarten Lankhorst
Quoted 7 lines
Signed-off-by Maarten Lankhorst <[email protected]>--- drivers/gpu/drm/radeon/radeon.h | 15 +- drivers/gpu/drm/radeon/radeon_device.c | 60 ++++++++- drivers/gpu/drm/radeon/radeon_fence.c | 223 ++++++++++++++++++++++++++------ 3 files changed, 248 insertions(+), 50 deletions(-)From what I can see this is still suffering from the problem that we
need to find a proper solution to,Quoted 7 lines
Quoted 5 lines
My summary of the issues after talking to Jerome and Ben and re-reading things is:
We really need to work out a better interface into the drivers to be able to avoid random atomic entrypoints,
Which is exactly what I criticized from the very first beginning. Good to know that I'm not the only one thinking that this isn't such a good idea.
Quoted 9 lines
I guess I've lost context a bit, but which atomic entry point are we talking about? Afaics the only one that's mandatory is the is
fence->signaledcallback to check whether a fence really has been signalled. It's used internally by the fence code to avoid spurious wakeups. Afaik that should be doable already on any hardware. If that's not the case then we can always track the signalled state in software and double-check in a worker thread before updating the sw state. And wrap this all up into a special fence class if there's more than one driver needing this.
Quoted 5 lines
One thing I've forgotten: The i915 scheduler that's floating around runs its bottom half from irq context. So I really want to be able to check fence state from irq context and I also want to make it possible (possible! not mandatory) to register callbacks which are run from any context asap after the fence is signalled.
NAK, that's just the bad design I've talked about. Checking fence state inside the same driver from interrupt context is OK, because it's the drivers interrupt that we are talking about here.
Checking fence status from another drivers interrupt context is what really concerns me here, cause your driver doesn't have the slightest idea if the called driver is really capable of checking the fence right now.
Quoted 5 lines
If the radeon hw/driver doesn't want to cope with that complexity we can fully insolate it with the sw tracked fence state if you don't like Maarten's radeon implementation. But forcing everyone to forgoe this just because you don't like it and don't want to use it in radeon doesn't sound right.
While it's clearly a hack Maarten's solution for radeon would indeed work, but that's not really the point here.
It's just that I think leaking interrupt context from one driver into another driver is just a really really bad idea from a design point of view.
And calling into a driver while in atomic context to check for a fence being signaled doesn't sounds like a good idea either, cause that limits way to much what the called driver can do for checking the status of a fence.
Christian.
Re: [Nouveau] [PATCH 09/17] drm/radeon: use common fence implementation for fences
Quoted 37 lines · Christian König
Am 22.07.2014 13:57, schrieb Daniel Vetter:
Quoted 30 lines · Daniel Vetter
Quoted 20 lines · Christian König
Quoted 12 lines
Am 22.07.2014 06:05, schrieb Dave Airlie:
Quoted 11 lines · Maarten Lankhorst
Quoted 7 lines
Signed-off-by Maarten Lankhorst <[email protected]>--- drivers/gpu/drm/radeon/radeon.h | 15 +- drivers/gpu/drm/radeon/radeon_device.c | 60 ++++++++- drivers/gpu/drm/radeon/radeon_fence.c | 223 ++++++++++++++++++++++++++------ 3 files changed, 248 insertions(+), 50 deletions(-)From what I can see this is still suffering from the problem that we need to find a proper solution to,
Quoted 7 lines
Quoted 5 lines
My summary of the issues after talking to Jerome and Ben and re-reading things is:
We really need to work out a better interface into the drivers to be able to avoid random atomic entrypoints,
Which is exactly what I criticized from the very first beginning. Good to know that I'm not the only one thinking that this isn't such a good idea.
Quoted 9 lines
I guess I've lost context a bit, but which atomic entry point are we talking about? Afaics the only one that's mandatory is the is
fence->signaledcallback to check whether a fence really has been signalled. It's used internally by the fence code to avoid spurious wakeups. Afaik that should be doable already on any hardware. If that's not the case then we can always track the signalled state in software and double-check in a worker thread before updating the sw state. And wrap this all up into a special fence class if there's more than one driver needing this.Quoted 5 lines
One thing I've forgotten: The i915 scheduler that's floating around runs its bottom half from irq context. So I really want to be able to check fence state from irq context and I also want to make it possible (possible! not mandatory) to register callbacks which are run from any context asap after the fence is signalled.
Quoted 7 lines
NAK, that's just the bad design I've talked about. Checking fence state inside the same driver from interrupt context is OK, because it's the drivers interrupt that we are talking about here.
Checking fence status from another drivers interrupt context is what really concerns me here, cause your driver doesn't have the slightest idea if the called driver is really capable of checking the fence right now.
I guess my mail hasn't been clear then. If you don't like it we could add a bit of glue to insulate the madness and bad design i915 might do from radeon. That imo doesn't invalidate the overall fence interfaces.
So what about the following:
- fence->enabling_signaling is restricted to be called from process context. We don't use any different yet, so would boild down to adding a WARN_ON(in_interrupt) or so to fence_enable_sw_signalling.
- Make fence->signaled optional (already the case) and don't implement it in readon (i.e. reduce this patch here). Only downside is that radeon needs to correctly (i.e. without races or so) call fence_signal. And the cross-driver synchronization might be a bit less efficient. Note that you can call fence_signal from wherever you want to, so hopefully that doesn't restrict your implementation.
End result: No one calls into radeon from interrupt context, and this is guaranteed.
Would that be something you can agree to?
Like I've said I think restricting the insanity other people are willing to live with just because you don't like it isn't right. But it is certainly right for you to insist on not being forced into any such design. I think the above would achieve this.
-Daniel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch
Re: [Nouveau] [PATCH 09/17] drm/radeon: use common fence implementation for fences
Am 22.07.2014 15:26, schrieb Daniel Vetter:
Quoted 60 lines · Christian König
Quoted 36 lines
Am 22.07.2014 13:57, schrieb Daniel Vetter:
Quoted 30 lines · Daniel Vetter
Quoted 20 lines · Christian König
Quoted 12 lines
Am 22.07.2014 06:05, schrieb Dave Airlie:
Quoted 11 lines · Maarten Lankhorst
Quoted 7 lines
Signed-off-by Maarten Lankhorst <[email protected]>--- drivers/gpu/drm/radeon/radeon.h | 15 +- drivers/gpu/drm/radeon/radeon_device.c | 60 ++++++++- drivers/gpu/drm/radeon/radeon_fence.c | 223 ++++++++++++++++++++++++++------ 3 files changed, 248 insertions(+), 50 deletions(-)From what I can see this is still suffering from the problem that we
need to find a proper solution to,Quoted 7 lines
Quoted 5 lines
My summary of the issues after talking to Jerome and Ben and re-reading things is:
We really need to work out a better interface into the drivers to be able to avoid random atomic entrypoints,
Which is exactly what I criticized from the very first beginning. Good to know that I'm not the only one thinking that this isn't such a good idea.
Quoted 9 lines
I guess I've lost context a bit, but which atomic entry point are we talking about? Afaics the only one that's mandatory is the is
fence->signaledcallback to check whether a fence really has been signalled. It's used internally by the fence code to avoid spurious wakeups. Afaik that should be doable already on any hardware. If that's not the case then we can always track the signalled state in software and double-check in a worker thread before updating the sw state. And wrap this all up into a special fence class if there's more than one driver needing this.Quoted 5 lines
One thing I've forgotten: The i915 scheduler that's floating around runs its bottom half from irq context. So I really want to be able to check fence state from irq context and I also want to make it possible (possible! not mandatory) to register callbacks which are run from any context asap after the fence is signalled.
Quoted 7 lines
NAK, that's just the bad design I've talked about. Checking fence state inside the same driver from interrupt context is OK, because it's the drivers interrupt that we are talking about here.
Checking fence status from another drivers interrupt context is what really concerns me here, cause your driver doesn't have the slightest idea if the called driver is really capable of checking the fence right now.
I guess my mail hasn't been clear then. If you don't like it we could add a bit of glue to insulate the madness and bad design i915 might do from radeon. That imo doesn't invalidate the overall fence interfaces.
So what about the following:
-fence->enabling_signalingis restricted to be called from process context. We don't use any different yet, so would boild down to adding aWARN_ON(in_interrupt)or so tofence_enable_sw_signalling.- Make
fence->signaledoptional (already the case) and don't implement it in readon (i.e. reduce this patch here). Only downside is that radeon needs to correctly (i.e. without races or so) callfence_signal. And the cross-driver synchronization might be a bit less efficient. Note that you can callfence_signalfrom wherever you want to, so hopefully that doesn't restrict your implementation.
Quoted 4 lines
End result: No one calls into radeon from interrupt context, and this is guaranteed.
Would that be something you can agree to?
No, the whole enable_signaling stuff should go away. No callback from the driver into the fence code, only the other way around.
fence->signaled as well as fence->wait should become mandatory and only called from process context without holding any locks, neither atomic nor any mutex/semaphore (rcu might be ok).
Quoted 4 lines
Like I've said I think restricting the insanity other people are willing to live with just because you don't like it isn't right. But it is certainly right for you to insist on not being forced into any such design. I think the above would achieve this.
I don't think so. If it's just me I would say that I'm just to cautious and the idea is still save to apply to the whole kernel.
But since Dave, Jerome and Ben seems to have similar concerns I think we need to agree to a minimum and save interface for all drivers.
Christian.
Re: [Nouveau] [PATCH 09/17] drm/radeon: use common fence implementation for fences
op 22-07-14 15:45, Christian König schreef:
Quoted 61 lines
Am 22.07.2014 15:26, schrieb Daniel Vetter:
Quoted 60 lines · Christian König
Quoted 36 lines
Am 22.07.2014 13:57, schrieb Daniel Vetter:
Quoted 30 lines · Daniel Vetter
Quoted 20 lines · Christian König
Quoted 12 lines
Am 22.07.2014 06:05, schrieb Dave Airlie:
Quoted 11 lines · Maarten Lankhorst
Quoted 7 lines
Signed-off-by Maarten Lankhorst <[email protected]>--- drivers/gpu/drm/radeon/radeon.h | 15 +- drivers/gpu/drm/radeon/radeon_device.c | 60 ++++++++- drivers/gpu/drm/radeon/radeon_fence.c | 223 ++++++++++++++++++++++++++------ 3 files changed, 248 insertions(+), 50 deletions(-)From what I can see this is still suffering from the problem that we
need to find a proper solution to,Quoted 7 lines
Quoted 5 lines
My summary of the issues after talking to Jerome and Ben and re-reading things is:
We really need to work out a better interface into the drivers to be able to avoid random atomic entrypoints,
Which is exactly what I criticized from the very first beginning. Good to know that I'm not the only one thinking that this isn't such a good idea.
Quoted 9 lines
I guess I've lost context a bit, but which atomic entry point are we talking about? Afaics the only one that's mandatory is the is
fence->signaledcallback to check whether a fence really has been signalled. It's used internally by the fence code to avoid spurious wakeups. Afaik that should be doable already on any hardware. If that's not the case then we can always track the signalled state in software and double-check in a worker thread before updating the sw state. And wrap this all up into a special fence class if there's more than one driver needing this.Quoted 5 lines
One thing I've forgotten: The i915 scheduler that's floating around runs its bottom half from irq context. So I really want to be able to check fence state from irq context and I also want to make it possible (possible! not mandatory) to register callbacks which are run from any context asap after the fence is signalled.
Quoted 7 lines
NAK, that's just the bad design I've talked about. Checking fence state inside the same driver from interrupt context is OK, because it's the drivers interrupt that we are talking about here.
Checking fence status from another drivers interrupt context is what really concerns me here, cause your driver doesn't have the slightest idea if the called driver is really capable of checking the fence right now.
I guess my mail hasn't been clear then. If you don't like it we could add a bit of glue to insulate the madness and bad design i915 might do from radeon. That imo doesn't invalidate the overall fence interfaces.
So what about the following:
-fence->enabling_signalingis restricted to be called from process context. We don't use any different yet, so would boild down to adding aWARN_ON(in_interrupt)or so tofence_enable_sw_signalling.- Make
fence->signaledoptional (already the case) and don't implement it in readon (i.e. reduce this patch here). Only downside is that radeon needs to correctly (i.e. without races or so) callfence_signal. And the cross-driver synchronization might be a bit less efficient. Note that you can callfence_signalfrom wherever you want to, so hopefully that doesn't restrict your implementation.
Quoted 8 lines
Quoted 4 lines
End result: No one calls into radeon from interrupt context, and this is guaranteed.
Would that be something you can agree to?
No, the whole
enable_signalingstuff should go away. No callback from the driver into the fence code, only the other way around.
fence->signaledas well asfence->waitshould become mandatory and only called from process context without holding any locks, neither atomic nor any mutex/semaphore (rcu might be ok).
fence->wait is mandatory, and already requires sleeping.
If .signaled is not implemented there is no guarantee the fence will be signaled sometime soon, this is also why enable_signaling exists, to allow the driver to flush. I get it that it doesn't apply to radeon and nouveau, but for other drivers that could be necessary, like vmwgfx.
Ironically that is also a part of the ttm fence, except it was called flush there.
I would also like to note that ttm_bo_wait currently is also a function that currently uses is_signaled from atomic_context...
For the more complicated locking worries: Lockdep is your friend, use PROVE_LOCKING and find bugs before they trigger. ;-)
Quoted 11 lines
Quoted 4 lines
Like I've said I think restricting the insanity other people are willing to live with just because you don't like it isn't right. But it is certainly right for you to insist on not being forced into any such design. I think the above would achieve this.
I don't think so. If it's just me I would say that I'm just to cautious and the idea is still save to apply to the whole kernel.
But since Dave, Jerome and Ben seems to have similar concerns I think we need to agree to a minimum and save interface for all drivers.
Christian.
Christian König
maintainerRe: [Nouveau] [PATCH 09/17] drm/radeon: use common fence implementation for fences
Am 22.07.2014 16:44, schrieb Maarten Lankhorst:
Quoted 69 lines
op 22-07-14 15:45, Christian König schreef:
Quoted 61 lines
Am 22.07.2014 15:26, schrieb Daniel Vetter:
Quoted 60 lines · Christian König
Quoted 36 lines
Am 22.07.2014 13:57, schrieb Daniel Vetter:
Quoted 30 lines · Daniel Vetter
Quoted 20 lines · Christian König
Quoted 12 lines
Am 22.07.2014 06:05, schrieb Dave Airlie:
Quoted 11 lines · Maarten Lankhorst
Quoted 7 lines
Signed-off-by Maarten Lankhorst <[email protected]>--- drivers/gpu/drm/radeon/radeon.h | 15 +- drivers/gpu/drm/radeon/radeon_device.c | 60 ++++++++- drivers/gpu/drm/radeon/radeon_fence.c | 223 ++++++++++++++++++++++++++------ 3 files changed, 248 insertions(+), 50 deletions(-)From what I can see this is still suffering from the problem that we
need to find a proper solution to,Quoted 7 lines
Quoted 5 lines
My summary of the issues after talking to Jerome and Ben and re-reading things is:
We really need to work out a better interface into the drivers to be able to avoid random atomic entrypoints,
Which is exactly what I criticized from the very first beginning. Good to know that I'm not the only one thinking that this isn't such a good idea.
Quoted 9 lines
I guess I've lost context a bit, but which atomic entry point are we talking about? Afaics the only one that's mandatory is the is
fence->signaledcallback to check whether a fence really has been signalled. It's used internally by the fence code to avoid spurious wakeups. Afaik that should be doable already on any hardware. If that's not the case then we can always track the signalled state in software and double-check in a worker thread before updating the sw state. And wrap this all up into a special fence class if there's more than one driver needing this.Quoted 5 lines
One thing I've forgotten: The i915 scheduler that's floating around runs its bottom half from irq context. So I really want to be able to check fence state from irq context and I also want to make it possible (possible! not mandatory) to register callbacks which are run from any context asap after the fence is signalled.
Quoted 7 lines
NAK, that's just the bad design I've talked about. Checking fence state inside the same driver from interrupt context is OK, because it's the drivers interrupt that we are talking about here.
Checking fence status from another drivers interrupt context is what really concerns me here, cause your driver doesn't have the slightest idea if the called driver is really capable of checking the fence right now.
I guess my mail hasn't been clear then. If you don't like it we could add a bit of glue to insulate the madness and bad design i915 might do from radeon. That imo doesn't invalidate the overall fence interfaces.
So what about the following:
-fence->enabling_signalingis restricted to be called from process context. We don't use any different yet, so would boild down to adding aWARN_ON(in_interrupt)or so tofence_enable_sw_signalling.- Make
fence->signaledoptional (already the case) and don't implement it in readon (i.e. reduce this patch here). Only downside is that radeon needs to correctly (i.e. without races or so) callfence_signal. And the cross-driver synchronization might be a bit less efficient. Note that you can callfence_signalfrom wherever you want to, so hopefully that doesn't restrict your implementation.Quoted 7 lines
Quoted 4 lines
End result: No one calls into radeon from interrupt context, and this is guaranteed.
Would that be something you can agree to?
No, the whole
enable_signalingstuff should go away. No callback from the driver into the fence code, only the other way around.
fence->signaledas well asfence->waitshould become mandatory and only called from process context without holding any locks, neither atomic nor any mutex/semaphore (rcu might be ok).
Quoted 8 lines
fence->waitis mandatory, and already requires sleeping.If .signaled is not implemented there is no guarantee the fence will be signaled sometime soon, this is also why
enable_signalingexists, to allow the driver to flush. I get it that it doesn't apply to radeon and nouveau, but for other drivers that could be necessary, like vmwgfx.Ironically that is also a part of the ttm fence, except it was called flush there.
Then call it flush again and make it optional like in TTM.
Quoted 1 line
I would also like to note that
ttm_bo_waitcurrently is also a function that currently usesis_signaledfromatomic_context...
I know, but TTM is only called from inside a single driver, no inter driver needs here. We currently even call the internal fence implementation from interrupt context as well and at more than one occasion assume that TTM only uses radeon fences.
Christian.
Quoted 12 lines
For the more complicated locking worries: Lockdep is your friend, use
PROVE_LOCKINGand find bugs before they trigger. ;-)Quoted 10 lines
Quoted 4 lines
Like I've said I think restricting the insanity other people are willing to live with just because you don't like it isn't right. But it is certainly right for you to insist on not being forced into any such design. I think the above would achieve this.
I don't think so. If it's just me I would say that I'm just to cautious and the idea is still save to apply to the whole kernel.
But since Dave, Jerome and Ben seems to have similar concerns I think we need to agree to a minimum and save interface for all drivers.
Christian.
Re: [Nouveau] [PATCH 09/17] drm/radeon: use common fence implementation for fences
Hey,
op 22-07-14 17:02, Christian König schreef:
Quoted 72 lines
Am 22.07.2014 16:44, schrieb Maarten Lankhorst:
Quoted 71 lines
op 22-07-14 15:45, Christian König schreef:
Quoted 61 lines
Am 22.07.2014 15:26, schrieb Daniel Vetter:
Quoted 60 lines · Christian König
Quoted 36 lines
Am 22.07.2014 13:57, schrieb Daniel Vetter:
Quoted 30 lines · Daniel Vetter
Quoted 20 lines · Christian König
Quoted 12 lines
Am 22.07.2014 06:05, schrieb Dave Airlie:
Quoted 11 lines · Maarten Lankhorst
Quoted 7 lines
Signed-off-by Maarten Lankhorst <[email protected]>--- drivers/gpu/drm/radeon/radeon.h | 15 +- drivers/gpu/drm/radeon/radeon_device.c | 60 ++++++++- drivers/gpu/drm/radeon/radeon_fence.c | 223 ++++++++++++++++++++++++++------ 3 files changed, 248 insertions(+), 50 deletions(-)From what I can see this is still suffering from the problem that we
need to find a proper solution to,Quoted 7 lines
Quoted 5 lines
My summary of the issues after talking to Jerome and Ben and re-reading things is:
We really need to work out a better interface into the drivers to be able to avoid random atomic entrypoints,
Which is exactly what I criticized from the very first beginning. Good to know that I'm not the only one thinking that this isn't such a good idea.
Quoted 9 lines
I guess I've lost context a bit, but which atomic entry point are we talking about? Afaics the only one that's mandatory is the is
fence->signaledcallback to check whether a fence really has been signalled. It's used internally by the fence code to avoid spurious wakeups. Afaik that should be doable already on any hardware. If that's not the case then we can always track the signalled state in software and double-check in a worker thread before updating the sw state. And wrap this all up into a special fence class if there's more than one driver needing this.Quoted 5 lines
One thing I've forgotten: The i915 scheduler that's floating around runs its bottom half from irq context. So I really want to be able to check fence state from irq context and I also want to make it possible (possible! not mandatory) to register callbacks which are run from any context asap after the fence is signalled.
Quoted 7 lines
NAK, that's just the bad design I've talked about. Checking fence state inside the same driver from interrupt context is OK, because it's the drivers interrupt that we are talking about here.
Checking fence status from another drivers interrupt context is what really concerns me here, cause your driver doesn't have the slightest idea if the called driver is really capable of checking the fence right now.
I guess my mail hasn't been clear then. If you don't like it we could add a bit of glue to insulate the madness and bad design i915 might do from radeon. That imo doesn't invalidate the overall fence interfaces.
So what about the following:
-fence->enabling_signalingis restricted to be called from process context. We don't use any different yet, so would boild down to adding aWARN_ON(in_interrupt)or so tofence_enable_sw_signalling.- Make
fence->signaledoptional (already the case) and don't implement it in readon (i.e. reduce this patch here). Only downside is that radeon needs to correctly (i.e. without races or so) callfence_signal. And the cross-driver synchronization might be a bit less efficient. Note that you can callfence_signalfrom wherever you want to, so hopefully that doesn't restrict your implementation.Quoted 7 lines
Quoted 4 lines
End result: No one calls into radeon from interrupt context, and this is guaranteed.
Would that be something you can agree to?
No, the whole
enable_signalingstuff should go away. No callback from the driver into the fence code, only the other way around.
fence->signaledas well asfence->waitshould become mandatory and only called from process context without holding any locks, neither atomic nor any mutex/semaphore (rcu might be ok).
fence->waitis mandatory, and already requires sleeping.
Quoted 8 lines
Quoted 6 lines
If .signaled is not implemented there is no guarantee the fence will be signaled sometime soon, this is also why
enable_signalingexists, to allow the driver to flush. I get it that it doesn't apply to radeon and nouveau, but for other drivers that could be necessary, like vmwgfx.Ironically that is also a part of the ttm fence, except it was called flush there.
Then call it flush again and make it optional like in TTM.
You've posted a lot of concerns, but I haven't seen you come up with any scenario that could create a lockup and lockdep wouldn't warn about.
Quoted 3 lines
Quoted 1 line
I would also like to note that
ttm_bo_waitcurrently is also a function that currently usesis_signaledfromatomic_context...I know, but TTM is only called from inside a single driver, no inter driver needs here. We currently even call the internal fence implementation from interrupt context as well and at more than one occasion assume that TTM only uses radeon fences.
This is no longer true when you start synchronizing with other drivers. The TTM core will see the intel fences and treat them no differently. That's the entire reason for this conversion. It's also needed to remove the need to pin dma-buf when exporting.
~Maarten.
Re: [Nouveau] [PATCH 09/17] drm/radeon: use common fence implementation for fences
In reply to Christian KönigQuoted 9 lines · Christian König
Quoted 1 line
Would that be something you can agree to?
No, the whole
enable_signalingstuff should go away. No callback from the driver into the fence code, only the other way around.
fence->signaledas well asfence->waitshould become mandatory and only called from process context without holding any locks, neither atomic nor any mutex/semaphore (rcu might be ok).
So for the enable_signaling, that's optional already. It's only for drivers that don't want to keep interrupts enabled all the time. You can opt out of that easily.
Wrt holding no locks at all while calling into any fence functions, that's just not going to work out. The point here is to make different drivers work together and we can rework all the ttm and i915 code to work locklessly in all cases where they need to wait for someone to complete rendering. Or at least I don't think that's feasible. So if you insist that no one might call into radeon code then we simply need to exclude radeon from participating in any shared fencing. But that's a bit pointless.
Quoted 11 lines
Quoted 4 lines
Like I've said I think restricting the insanity other people are willing to live with just because you don't like it isn't right. But it is certainly right for you to insist on not being forced into any such design. I think the above would achieve this.
I don't think so. If it's just me I would say that I'm just to cautious and the idea is still save to apply to the whole kernel.
But since Dave, Jerome and Ben seems to have similar concerns I think we need to agree to a minimum and save interface for all drivers.
Well I haven't yet seen a proposal that actually works. From an intel pov I don't care that much since we don't care about desktop prime, so if radeon/nouveau don't want to do that, meh. Imo the design as-is is fairly sound, and as simple as it can get given the requirements. I haven't heard an argument convincing me otherwise, so I guess we won't have prime support on linux that actually works, ever. -Daniel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch _______________________________________________ Nouveau mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/nouveau
Christian König
maintainerRe: [Nouveau] [PATCH 09/17] drm/radeon: use common fence implementation for fences
Am 22.07.2014 17:17, schrieb Daniel Vetter:
Quoted 28 lines
Quoted 8 lines · Christian König
Quoted 1 line
Would that be something you can agree to?
No, the whole
enable_signalingstuff should go away. No callback from the driver into the fence code, only the other way around.
fence->signaledas well asfence->waitshould become mandatory and only called from process context without holding any locks, neither atomic nor any mutex/semaphore (rcu might be ok).So for the
enable_signaling, that's optional already. It's only for drivers that don't want to keep interrupts enabled all the time. You can opt out of that easily.Wrt holding no locks at all while calling into any fence functions, that's just not going to work out. The point here is to make different drivers work together and we can rework all the ttm and i915 code to work locklessly in all cases where they need to wait for someone to complete rendering. Or at least I don't think that's feasible. So if you insist that no one might call into radeon code then we simply need to exclude radeon from participating in any shared fencing. But that's a bit pointless.
Quoted 5 lines
Quoted 4 lines
Like I've said I think restricting the insanity other people are willing to live with just because you don't like it isn't right. But it is certainly right for you to insist on not being forced into any such design. I think the above would achieve this.
Quoted 6 lines
Quoted 5 lines
I don't think so. If it's just me I would say that I'm just to cautious and the idea is still save to apply to the whole kernel.
But since Dave, Jerome and Ben seems to have similar concerns I think we need to agree to a minimum and save interface for all drivers.
Well I haven't yet seen a proposal that actually works.
How about this:
Drivers exporting fences need to provide a fence->signaled and a fence->wait function, everything else like fence->enable_signaling or calling fence_signaled() from the driver is optional.
Drivers wanting to use exported fences don't call fence->signaled or fence->wait in atomic or interrupt context, and not with holding any global locking primitives (like mmap_sem etc...). Holding locking primitives local to the driver is ok, as long as they don't conflict with anything possible used by their own fence implementation.
Christian.
Quoted 7 lines
From an intel
pov I don't care that much since we don't care about desktop prime, so if radeon/nouveau don't want to do that, meh. Imo the design as-is is fairly sound, and as simple as it can get given the requirements. I haven't heard an argument convincing me otherwise, so I guess we won't have prime support on linux that actually works, ever. -Daniel
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [Nouveau] [PATCH 09/17] drm/radeon: use common fence implementation for fences
Quoted 9 lines · Christian König
Drivers exporting fences need to provide a
fence->signaledand afence->waitfunction, everything else likefence->enable_signalingor callingfence_signaled()from the driver is optional.Drivers wanting to use exported fences don't call
fence->signaledorfence->waitin atomic or interrupt context, and not with holding any global locking primitives (likemmap_semetc...). Holding locking primitives local to the driver is ok, as long as they don't conflict with anything possible used by their own fence implementation.
Well that's almost what we have right now with the exception that drivers are allowed (actually must for correctness when updating fences) the ww_mutexes for dma-bufs (or other buffer objects). Locking correctness is enforced with some extremely nasty lockdep annotations
+ additional debugging infrastructure enabled with CONFIG_DEBUG_WW_MUTEX_SLOWPATH. We really need to be able to hold dma-buf ww_mutexes while updating fences or waiting for them. And obviously for ->wait we need non-atomic context, not just non-interrupt.
Agreed that any shared locks are out of the way (especially stuff like dev->struct_mutex or other non-strictly driver-private stuff, i915 is really bad here still).
So from the core fence framework I think we already have exactly this, and we only need to adjust the radeon implementation a bit to make it less risky and invasive to the radeon driver logic.
-Daniel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [Nouveau] [PATCH 09/17] drm/radeon: use common fence implementation for fences
Am 22.07.2014 17:42, schrieb Daniel Vetter:
Quoted 6 lines
Quoted 4 lines · Christian König
Drivers exporting fences need to provide a
fence->signaledand afence->waitfunction, everything else likefence->enable_signalingor callingfence_signaled()from the driver is optional.
Quoted 8 lines
Quoted 5 lines
Drivers wanting to use exported fences don't call
fence->signaledorfence->waitin atomic or interrupt context, and not with holding any global locking primitives (likemmap_semetc...). Holding locking primitives local to the driver is ok, as long as they don't conflict with anything possible used by their own fence implementation.Well that's almost what we have right now with the exception that drivers are allowed (actually must for correctness when updating fences) the
ww_mutexesfor dma-bufs (or other buffer objects).
In this case sorry for so much noise. I really haven't looked in so much detail into anything but Maarten's Radeon patches.
But how does that then work right now? My impression was that it's mandatory for drivers to call fence_signaled()?
Quoted 7 lines
Locking
correctness is enforced with some extremely nasty lockdep annotations
+ additional debugging infrastructure enabled withCONFIG_DEBUG_WW_MUTEX_SLOWPATH. We really need to be able to hold dma-bufww_mutexeswhile updating fences or waiting for them. And obviously for ->wait we need non-atomic context, not just non-interrupt.
Sounds mostly reasonable, but for holding the dma-buf ww_mutex, wouldn't be an RCU be more appropriate here? E.g. aren't we just interested that the current assigned fence at some point is signaled?
Something like grab ww_mutexes, grab a reference to the current fence object, release ww_mutex, wait for fence, release reference to the fence object.
Quoted 3 lines
Agreed that any shared locks are out of the way (especially stuff like
dev->struct_mutexor other non-strictly driver-private stuff, i915 is really bad here still).
Yeah that's also an point I've wanted to note on Maartens patch. Radeon grabs the read side of it's exclusive semaphore while waiting for fences (because it assumes that the fence it waits for is a Radeon fence).
Assuming that we need to wait in both directions with Prime (e.g. Intel driver needs to wait for Radeon to finish rendering and Radeon needs to wait for Intel to finish displaying), this might become a perfect example of locking inversion.
Quoted 3 lines
So from the core fence framework I think we already have exactly this, and we only need to adjust the radeon implementation a bit to make it less risky and invasive to the radeon driver logic.
Agree. Well the biggest problem I see is that exclusive semaphore I need to take when anything calls into the driver. For the fence code I need to move that down into the fence->signaled handler, cause that now can be called from outside the driver.
Maarten solved this by telling the driver in the lockup handler (where we grab the write side of the exclusive lock) that all interrupts are already enabled, so that fence->signaled hopefully wouldn't mess with the hardware at all. While this probably works, it just leaves me with a feeling that we are doing something wrong here.
Christian.
Quoted 1 line
-Daniel
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [Nouveau] [PATCH 09/17] drm/radeon: use common fence implementation for fences
Quoted 24 lines · Christian König
Am 22.07.2014 17:42, schrieb Daniel Vetter:
Quoted 17 lines
Quoted 6 lines · Christian König
Drivers exporting fences need to provide a
fence->signaledand afence->wait
function, everything else likefence->enable_signalingor callingfence_signaled()from the driver is optional.Quoted 8 lines
Drivers wanting to use exported fences don't call
fence->signaledorfence->waitin atomic or interrupt context, and not with holding any global
locking primitives (likemmap_semetc...). Holding locking primitives local
to the driver is ok, as long as they don't conflict with anything possible
used by their own fence implementation.Quoted 3 lines
Well that's almost what we have right now with the exception that drivers are allowed (actually must for correctness when updating fences) the
ww_mutexesfor dma-bufs (or other buffer objects).
Quoted 5 lines
In this case sorry for so much noise. I really haven't looked in so much detail into anything but Maarten's Radeon patches.
But how does that then work right now? My impression was that it's mandatory for drivers to call
fence_signaled()?
Maybe I've mixed things up a bit in my description. There is fence_signal which the implementor/exporter of a fence must call when the fence is completed. If the exporter has an ->enable_signaling callback it can delay that call to fence_signal for as long as it wishes as long as enable_signaling isn't called yet. But that's just the optimization to not required irqs to be turned on all the time.
The other function is fence_is_signaled, which is used by code that is interested in the fence state, together with fence_wait if it wants to block and not just wants to know the momentary fence state. All the other functions (the stuff that adds callbacks and the various _locked and other versions) are just for fancy special cases.
Quoted 9 lines
Quoted 7 lines
Locking
correctness is enforced with some extremely nasty lockdep annotations
+ additional debugging infrastructure enabled withCONFIG_DEBUG_WW_MUTEX_SLOWPATH. We really need to be able to hold dma-bufww_mutexeswhile updating fences or waiting for them. And obviously for ->wait we need non-atomic context, not just non-interrupt.
Quoted 3 lines
Sounds mostly reasonable, but for holding the dma-buf
ww_mutex, wouldn't be an RCU be more appropriate here? E.g. aren't we just interested that the current assigned fence at some point is signaled?
Yeah, as an optimization you can get the set of currently attached fences to a dma-buf with just rcu. But if you update the set of fences attached to a dma-buf (e.g. radeon blits the newly rendered frame to a dma-buf exported by i915 for scanout on i915) then you need a write lock on that buffer. Which is what the ww_mutex is for, to make sure that you don't deadlock with i915 doing concurrent ops on the same underlying buffer.
Quoted 3 lines
Something like grab
ww_mutexes, grab a reference to the current fence object, releaseww_mutex, wait for fence, release reference to the fence object.
Yeah, if the only thing you want to do is wait for fences, then the rcu-protected fence ref grabbing + lockless waiting is all you need. But e.g. in an execbuf you also need to update fences and maybe deep down in the reservation code you notice that you need to evict some stuff and so need to wait on some other guy to finish, and it's too complicated to drop and reacquire all the locks. Or you simply need to do a blocking wait on other gpus (because there's no direct hw sync mechanism) and again dropping locks would needlessly complicate the code. So I think we should allow this just to avoid too hairy/brittle (and almost definitely little tested code) in drivers.
Afaik this is also the same way ttm currently handles things wrt buffer reservation and eviction.
Quoted 5 lines
Quoted 3 lines
Agreed that any shared locks are out of the way (especially stuff like
dev->struct_mutexor other non-strictly driver-private stuff, i915 is really bad here still).
Quoted 8 lines
Yeah that's also an point I've wanted to note on Maartens patch. Radeon grabs the read side of it's exclusive semaphore while waiting for fences (because it assumes that the fence it waits for is a Radeon fence).
Assuming that we need to wait in both directions with Prime (e.g. Intel driver needs to wait for Radeon to finish rendering and Radeon needs to wait for Intel to finish displaying), this might become a perfect example of locking inversion.
fence updates are atomic on a dma-buf, protected by ww_mutex. The neat trick of ww_mutex is that they enforce a global ordering, so in your scenario either i915 or radeon would be first and you can't deadlock. There is no way to interleave anything even if you have lots of buffers shared between i915/radeon. Wrt deadlocking it's exactly the same guarantees as the magic ttm provides for just one driver with concurrent command submission since it's the same idea.
Quoted 10 lines
Quoted 3 lines
So from the core fence framework I think we already have exactly this, and we only need to adjust the radeon implementation a bit to make it less risky and invasive to the radeon driver logic.
Agree. Well the biggest problem I see is that exclusive semaphore I need to take when anything calls into the driver. For the fence code I need to move that down into the
fence->signaledhandler, cause that now can be called from outside the driver.
Quoted 5 lines
Maarten solved this by telling the driver in the lockup handler (where we grab the write side of the exclusive lock) that all interrupts are already enabled, so that
fence->signaledhopefully wouldn't mess with the hardware at all. While this probably works, it just leaves me with a feeling that we are doing something wrong here.
I'm not versed on the details in readon, but on i915 we can attach a memory location and cookie value to each fence and just do a memory fetch to figure out whether the fence has passed or not. So no locking needed at all. Of course the fence itself needs to lock a reference onto that memory location, which is a neat piece of integration work that we still need to tackle in some cases - there's conflicting patch series all over this ;-)
But like I've said fence->signaled is optional so you don't need this necessarily, as long as radeon eventually calls fence_signaled once the fence has completed.
-Daniel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
Christian König
maintainerRe: [Nouveau] [PATCH 09/17] drm/radeon: use common fence implementation for fences
Quoted 7 lines
Maybe I've mixed things up a bit in my description. There is
fence_signalwhich the implementor/exporter of a fence must call when the fence is completed. If the exporter has an ->enable_signaling callback it can delay that call tofence_signalfor as long as it wishes as long asenable_signalingisn't called yet. But that's just the optimization to not required irqs to be turned on all the time.
Quoted 5 lines
The other function is
fence_is_signaled, which is used by code that is interested in the fence state, together withfence_waitif it wants to block and not just wants to know the momentary fence state. All the other functions (the stuff that adds callbacks and the various_lockedand other versions) are just for fancy special cases.
Well that's rather bad, cause IRQs aren't reliable enough on Radeon HW for such a thing. Especially on Prime systems and Macs.
That's why we have this fancy HZ/2 timeout on all fence wait operations to manually check if the fence is signaled or not.
To guarantee that a fence is signaled after enable_signaling is called we would need to fire up a kernel thread which periodically calls fence->signaled.
Christian.
Am 22.07.2014 18:21, schrieb Daniel Vetter:
Quoted 119 lines
Quoted 21 lines · Christian König
Am 22.07.2014 17:42, schrieb Daniel Vetter:
Quoted 15 lines
Quoted 5 lines · Christian König
Drivers exporting fences need to provide a
fence->signaledand afence->wait
function, everything else likefence->enable_signalingor callingfence_signaled()from the driver is optional.Quoted 8 lines
Drivers wanting to use exported fences don't call
fence->signaledorfence->waitin atomic or interrupt context, and not with holding any global
locking primitives (likemmap_semetc...). Holding locking primitives local
to the driver is ok, as long as they don't conflict with anything possible
used by their own fence implementation.Quoted 3 lines
Well that's almost what we have right now with the exception that drivers are allowed (actually must for correctness when updating fences) the
ww_mutexesfor dma-bufs (or other buffer objects).Quoted 5 lines
In this case sorry for so much noise. I really haven't looked in so much detail into anything but Maarten's Radeon patches.
But how does that then work right now? My impression was that it's mandatory for drivers to call
fence_signaled()?Maybe I've mixed things up a bit in my description. There is
fence_signalwhich the implementor/exporter of a fence must call when the fence is completed. If the exporter has an ->enable_signaling callback it can delay that call tofence_signalfor as long as it wishes as long asenable_signalingisn't called yet. But that's just the optimization to not required irqs to be turned on all the time.The other function is
fence_is_signaled, which is used by code that is interested in the fence state, together withfence_waitif it wants to block and not just wants to know the momentary fence state. All the other functions (the stuff that adds callbacks and the various_lockedand other versions) are just for fancy special cases.Quoted 11 lines
Quoted 7 lines
Locking
correctness is enforced with some extremely nasty lockdep annotations
+ additional debugging infrastructure enabled withCONFIG_DEBUG_WW_MUTEX_SLOWPATH. We really need to be able to hold dma-bufww_mutexeswhile updating fences or waiting for them. And obviously for ->wait we need non-atomic context, not just non-interrupt.Sounds mostly reasonable, but for holding the dma-buf
ww_mutex, wouldn't be an RCU be more appropriate here? E.g. aren't we just interested that the current assigned fence at some point is signaled?Yeah, as an optimization you can get the set of currently attached fences to a dma-buf with just rcu. But if you update the set of fences attached to a dma-buf (e.g. radeon blits the newly rendered frame to a dma-buf exported by i915 for scanout on i915) then you need a write lock on that buffer. Which is what the
ww_mutexis for, to make sure that you don't deadlock with i915 doing concurrent ops on the same underlying buffer.Quoted 3 lines
Something like grab
ww_mutexes, grab a reference to the current fence object, releaseww_mutex, wait for fence, release reference to the fence object.Yeah, if the only thing you want to do is wait for fences, then the rcu-protected fence ref grabbing + lockless waiting is all you need. But e.g. in an execbuf you also need to update fences and maybe deep down in the reservation code you notice that you need to evict some stuff and so need to wait on some other guy to finish, and it's too complicated to drop and reacquire all the locks. Or you simply need to do a blocking wait on other gpus (because there's no direct hw sync mechanism) and again dropping locks would needlessly complicate the code. So I think we should allow this just to avoid too hairy/brittle (and almost definitely little tested code) in drivers.
Afaik this is also the same way ttm currently handles things wrt buffer reservation and eviction.
Quoted 4 lines
Quoted 3 lines
Agreed that any shared locks are out of the way (especially stuff like
dev->struct_mutexor other non-strictly driver-private stuff, i915 is really bad here still).Quoted 8 lines
Yeah that's also an point I've wanted to note on Maartens patch. Radeon grabs the read side of it's exclusive semaphore while waiting for fences (because it assumes that the fence it waits for is a Radeon fence).
Assuming that we need to wait in both directions with Prime (e.g. Intel driver needs to wait for Radeon to finish rendering and Radeon needs to wait for Intel to finish displaying), this might become a perfect example of locking inversion.
fence updates are atomic on a dma-buf, protected by
ww_mutex. The neat trick ofww_mutexis that they enforce a global ordering, so in your scenario either i915 or radeon would be first and you can't deadlock. There is no way to interleave anything even if you have lots of buffers shared between i915/radeon. Wrt deadlocking it's exactly the same guarantees as the magic ttm provides for just one driver with concurrent command submission since it's the same idea.Quoted 9 lines
Quoted 3 lines
So from the core fence framework I think we already have exactly this, and we only need to adjust the radeon implementation a bit to make it less risky and invasive to the radeon driver logic.
Agree. Well the biggest problem I see is that exclusive semaphore I need to take when anything calls into the driver. For the fence code I need to move that down into the
fence->signaledhandler, cause that now can be called from outside the driver.Quoted 5 lines
Maarten solved this by telling the driver in the lockup handler (where we grab the write side of the exclusive lock) that all interrupts are already enabled, so that
fence->signaledhopefully wouldn't mess with the hardware at all. While this probably works, it just leaves me with a feeling that we are doing something wrong here.I'm not versed on the details in readon, but on i915 we can attach a memory location and cookie value to each fence and just do a memory fetch to figure out whether the fence has passed or not. So no locking needed at all. Of course the fence itself needs to lock a reference onto that memory location, which is a neat piece of integration work that we still need to tackle in some cases - there's conflicting patch series all over this ;-)
Quoted 4 lines
But like I've said
fence->signaledis optional so you don't need this necessarily, as long as radeon eventually callsfence_signaledonce the fence has completed.
-Daniel
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [Nouveau] [PATCH 09/17] drm/radeon: use common fence implementation for fences
Quoted 16 lines · Christian König
Quoted 7 lines
Maybe I've mixed things up a bit in my description. There is
fence_signalwhich the implementor/exporter of a fence must call when the fence is completed. If the exporter has an ->enable_signaling callback it can delay that call tofence_signalfor as long as it wishes as long asenable_signalingisn't called yet. But that's just the optimization to not required irqs to be turned on all the time.Quoted 5 lines
The other function is
fence_is_signaled, which is used by code that is interested in the fence state, together withfence_waitif it wants to block and not just wants to know the momentary fence state. All the other functions (the stuff that adds callbacks and the various_lockedand other versions) are just for fancy special cases.Well that's rather bad, cause IRQs aren't reliable enough on Radeon HW for such a thing. Especially on Prime systems and Macs.
Quoted 6 lines
That's why we have this fancy HZ/2 timeout on all fence wait operations to manually check if the fence is signaled or not.
To guarantee that a fence is signaled after
enable_signalingis called we would need to fire up a kernel thread which periodically callsfence->signaled.
We actually have seen similar fun on some i915 platforms. I wonder whether we shouldn't have something in the fence core for this given how common it is. Currently we have the same trick with regular wakups on platforms with unreliable interrupts, but I haven't yet looked at how we'll do this with callbacks once we add the scheduler and fences. It might be though that we've finally fixed these coherency issues between the interrupt and the fence write for real.
-Daniel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [Nouveau] [PATCH 09/17] drm/radeon: use common fence implementation for fences
In reply to Daniel VetterQuoted 3 lines · Daniel Vetter
But like I've said
fence->signaledis optional so you don't need this necessarily, as long as radeon eventually callsfence_signaledonce the fence has completed.
Actually I've chatted a bit with Maarten about the different ways we could restrict both the calling context and the implementations for fence callbacks to avoid surprises. One is certainyl that we need WARN_ON(in_interrupt) around the wait, enable_singaling and add callback stuff.
But we also talked about ensure that the ->signaled callback never sleeps by wrapping it in a preempt_enable/disable section. Currently sleeping is allowed in ->signaled, which the radeon implementation here does. I think it would be reasonable to forbid this and drop __radeon_fence_signaled.
-Daniel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch
Re: [Nouveau] [PATCH 09/17] drm/radeon: use common fence implementation for fences
In reply to Christian Königop 22-07-14 17:59, Christian König schreef:
Quoted 12 lines
Am 22.07.2014 17:42, schrieb Daniel Vetter:
Quoted 11 lines
Quoted 9 lines · Christian König
Drivers exporting fences need to provide a
fence->signaledand afence->waitfunction, everything else likefence->enable_signalingor callingfence_signaled()from the driver is optional.Drivers wanting to use exported fences don't call
fence->signaledorfence->waitin atomic or interrupt context, and not with holding any global locking primitives (likemmap_semetc...). Holding locking primitives local to the driver is ok, as long as they don't conflict with anything possible used by their own fence implementation.
Quoted 7 lines
Quoted 3 lines
Well that's almost what we have right now with the exception that drivers are allowed (actually must for correctness when updating fences) the
ww_mutexesfor dma-bufs (or other buffer objects).In this case sorry for so much noise. I really haven't looked in so much detail into anything but Maarten's Radeon patches.
But how does that then work right now? My impression was that it's mandatory for drivers to call
fence_signaled()?
It's only mandatory to call fence_signal() if the .enable_signaling callback has been called, else you can get away with never calling signaling a fence at all before dropping the last refcount to it. This allows you to keep interrupts disabled when you don't need them.
Quoted 9 lines
Quoted 7 lines
Locking
correctness is enforced with some extremely nasty lockdep annotations
+ additional debugging infrastructure enabled withCONFIG_DEBUG_WW_MUTEX_SLOWPATH. We really need to be able to hold dma-bufww_mutexeswhile updating fences or waiting for them. And obviously for ->wait we need non-atomic context, not just non-interrupt.Sounds mostly reasonable, but for holding the dma-buf
ww_mutex, wouldn't be an RCU be more appropriate here? E.g. aren't we just interested that the current assigned fence at some point is signaled?
You can wait with RCU, without holding the ww_mutex, by calling reservation_object_wait_timeout_rcu on ttm_bo->resv.
If you don't want to block you could test with reservation_object_test_signaled_rcu.
Or if you want a copy of all fences without taking locks, try reservation_object_get_fences_rcu. (Might be out of date by the time the function returns if you don't hold ww_mutex, if you hold ww_mutex you probably don't need to call this function.)
I didn't add non-rcu versions, but using the RCU functions would work with ww_mutex held too, probably with some small overhead.
Quoted 1 line
Something like grab
ww_mutexes, grab a reference to the current fence object, releaseww_mutex, wait for fence, release reference to the fence object.
This is what I do currently. :-) The reservation_object that's embedded in TTM gets shared with the dma-buf, so there will be no special case needed for dma-buf at all, all objects can simply be shared and the synchronization is handled in the same way.
ttm_bo_reserve and friends automatically end up locking the dma-buf too, and lockdep works on it.
Quoted 8 lines
Quoted 4 lines
Agreed that any shared locks are out of the way (especially stuff like
dev->struct_mutexor other non-strictly driver-private stuff, i915 is really bad here still).Yeah that's also an point I've wanted to note on Maartens patch. Radeon grabs the read side of it's exclusive semaphore while waiting for fences (because it assumes that the fence it waits for is a Radeon fence).
Assuming that we need to wait in both directions with Prime (e.g. Intel driver needs to wait for Radeon to finish rendering and Radeon needs to wait for Intel to finish displaying), this might become a perfect example of locking inversion.
In the preliminary patches where I can sync radeon with other GPU's I've been very careful in all the places that call into fences, to make sure that radeon wouldn't try to handle lockups for a different (possibly also radeon) card.
This is also why fence_is_signaled should never block, and why it trylocks the exclusive_lock. :-) I think lockdep would complain if I grabbed exclusive_lock while blocking in is_signaled.
Quoted 7 lines
Quoted 3 lines
So from the core fence framework I think we already have exactly this, and we only need to adjust the radeon implementation a bit to make it less risky and invasive to the radeon driver logic.
Agree. Well the biggest problem I see is that exclusive semaphore I need to take when anything calls into the driver. For the fence code I need to move that down into the
fence->signaledhandler, cause that now can be called from outside the driver.Maarten solved this by telling the driver in the lockup handler (where we grab the write side of the exclusive lock) that all interrupts are already enabled, so that
fence->signaledhopefully wouldn't mess with the hardware at all. While this probably works, it just leaves me with a feeling that we are doing something wrong here.
There is unfortunately no global mechanism to say 'this card is locked up, please don't call into any of my fences', and I don't associate fences with devices, and radeon doesn't keep a global list of fences. If all of that existed, it would complicate the interface and its callers a lot, while I like to keep things simple.
So I did the best I could, and simply prevented the fence calls from fiddling with the hardware. Fortunately gpu lockup is not a common operation. :-)
~Maarten
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Christian König
maintainerRe: [Nouveau] [PATCH 09/17] drm/radeon: use common fence implementation for fences
Am 23.07.2014 08:40, schrieb Maarten Lankhorst:
Quoted 13 lines
op 22-07-14 17:59, Christian König schreef:
Quoted 12 lines
Am 22.07.2014 17:42, schrieb Daniel Vetter:
Quoted 11 lines
Quoted 9 lines · Christian König
Drivers exporting fences need to provide a
fence->signaledand afence->waitfunction, everything else likefence->enable_signalingor callingfence_signaled()from the driver is optional.Drivers wanting to use exported fences don't call
fence->signaledorfence->waitin atomic or interrupt context, and not with holding any global locking primitives (likemmap_semetc...). Holding locking primitives local to the driver is ok, as long as they don't conflict with anything possible used by their own fence implementation.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Well that's almost what we have right now with the exception that drivers are allowed (actually must for correctness when updating fences) the
ww_mutexesfor dma-bufs (or other buffer objects).In this case sorry for so much noise. I really haven't looked in so much detail into anything but Maarten's Radeon patches.
But how does that then work right now? My impression was that it's mandatory for drivers to call
fence_signaled()?It's only mandatory to call
fence_signal()if the .enable_signaling callback has been called, else you can get away with never calling signaling a fence at all before dropping the last refcount to it. This allows you to keep interrupts disabled when you don't need them.
Can we somehow avoid the need to call fence_signal() at all? The interrupts at least on radeon are way to unreliable for such a thing. Can enable_signalling fail? What's the reason for fence_signaled() in the first place?
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines
Agreed that any shared locks are out of the way (especially stuff like
dev->struct_mutexor other non-strictly driver-private stuff, i915 is really bad here still).Yeah that's also an point I've wanted to note on Maartens patch. Radeon grabs the read side of it's exclusive semaphore while waiting for fences (because it assumes that the fence it waits for is a Radeon fence).
Assuming that we need to wait in both directions with Prime (e.g. Intel driver needs to wait for Radeon to finish rendering and Radeon needs to wait for Intel to finish displaying), this might become a perfect example of locking inversion.
In the preliminary patches where I can sync radeon with other GPU's I've been very careful in all the places that call into fences, to make sure that radeon wouldn't try to handle lockups for a different (possibly also radeon) card.
That's actually not such a good idea.
In case of a lockup we need to handle the lockup cause otherwise it could happen that radeon waits for the lockup to be resolved and the lockup handling needs to wait for a fence that's never signaled because of the lockup.
Christian.
Quoted 6 lines
This is also why
fence_is_signaledshould never block, and why it trylocks theexclusive_lock. :-) I think lockdep would complain if I grabbedexclusive_lockwhile blocking inis_signaled.Quoted 3 lines
Quoted 3 lines
So from the core fence framework I think we already have exactly this, and we only need to adjust the radeon implementation a bit to make it less risky and invasive to the radeon driver logic.
Quoted 10 lines
Quoted 3 lines
Agree. Well the biggest problem I see is that exclusive semaphore I need to take when anything calls into the driver. For the fence code I need to move that down into the
fence->signaledhandler, cause that now can be called from outside the driver.Maarten solved this by telling the driver in the lockup handler (where we grab the write side of the exclusive lock) that all interrupts are already enabled, so that
fence->signaledhopefully wouldn't mess with the hardware at all. While this probably works, it just leaves me with a feeling that we are doing something wrong here.There is unfortunately no global mechanism to say 'this card is locked up, please don't call into any of my fences', and I don't associate fences with devices, and radeon doesn't keep a global list of fences. If all of that existed, it would complicate the interface and its callers a lot, while I like to keep things simple.
So I did the best I could, and simply prevented the fence calls from fiddling with the hardware. Fortunately gpu lockup is not a common operation. :-)~Maarten
_______________________________________________
Nouveau mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau
Re: [Nouveau] [PATCH 09/17] drm/radeon: use common fence implementation for fences
Quoted 11 lines · Christian König
Quoted 4 lines
In the preliminary patches where I can sync radeon with other GPU's I've been very careful in all the places that call into fences, to make sure that radeon wouldn't try to handle lockups for a different (possibly also radeon) card.
That's actually not such a good idea.
In case of a lockup we need to handle the lockup cause otherwise it could happen that radeon waits for the lockup to be resolved and the lockup handling needs to wait for a fence that's never signaled because of the lockup.
I thought the plan for now is that each driver handles lookups themselfs for now. So if any batch gets stuck for too long (whether it's our own gpu that's stuck or whether we're somehow stuck on a fence from a 2nd gpu doesn't matter) the driver steps in with a reset and signals completion to all its own fences that have been in that pile-up. As long as each driver participating in fencing has means to abort/reset we'll eventually get unstuck.
Essentially every driver has to guarantee that assuming dependent fences all complete eventually that it _will_ complete its own fences no matter what.
For now this should be good enough, but for arb_robusteness or people who care a bit about their compute results we need reliable notification to userspace that a reset happened. I think we could add a new "aborted" fence state for that case and then propagate that. But given how tricky the code to compute reset victims in i915 is already I think we should leave this out for now. And even later on make it strictly opt-in.
-Daniel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch _______________________________________________ Nouveau mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/nouveau
Re: [Nouveau] [PATCH 09/17] drm/radeon: use common fence implementation for fences
In reply to Christian Königop 23-07-14 08:52, Christian König schreef:
Quoted 17 lines
Am 23.07.2014 08:40, schrieb Maarten Lankhorst:
Quoted 16 lines
op 22-07-14 17:59, Christian König schreef:
Quoted 15 lines
Am 22.07.2014 17:42, schrieb Daniel Vetter:
Quoted 14 lines
Quoted 9 lines · Christian König
Drivers exporting fences need to provide a
fence->signaledand afence->waitfunction, everything else likefence->enable_signalingor callingfence_signaled()from the driver is optional.Drivers wanting to use exported fences don't call
fence->signaledorfence->waitin atomic or interrupt context, and not with holding any global locking primitives (likemmap_semetc...). Holding locking primitives local to the driver is ok, as long as they don't conflict with anything possible used by their own fence implementation.Well that's almost what we have right now with the exception that drivers are allowed (actually must for correctness when updating fences) the
ww_mutexesfor dma-bufs (or other buffer objects).
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
In this case sorry for so much noise. I really haven't looked in so much detail into anything but Maarten's Radeon patches.
But how does that then work right now? My impression was that it's mandatory for drivers to call
fence_signaled()?It's only mandatory to call
fence_signal()if the .enable_signaling callback has been called, else you can get away with never calling signaling a fence at all before dropping the last refcount to it. This allows you to keep interrupts disabled when you don't need them.Can we somehow avoid the need to call
fence_signal()at all? The interrupts at least on radeon are way to unreliable for such a thing. Canenable_signallingfail? What's the reason forfence_signaled()in the first place?
It doesn't need to be completely reliable, or finish immediately.
And any time wake_up_all(&rdev->fence_queue) is called all the fences that were enabled will be rechecked.
Quoted 11 lines
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines
Agreed that any shared locks are out of the way (especially stuff like
dev->struct_mutexor other non-strictly driver-private stuff, i915 is really bad here still).Yeah that's also an point I've wanted to note on Maartens patch. Radeon grabs the read side of it's exclusive semaphore while waiting for fences (because it assumes that the fence it waits for is a Radeon fence).
Assuming that we need to wait in both directions with Prime (e.g. Intel driver needs to wait for Radeon to finish rendering and Radeon needs to wait for Intel to finish displaying), this might become a perfect example of locking inversion.
In the preliminary patches where I can sync radeon with other GPU's I've been very careful in all the places that call into fences, to make sure that radeon wouldn't try to handle lockups for a different (possibly also radeon) card.
That's actually not such a good idea.
In case of a lockup we need to handle the lockup cause otherwise it could happen that radeon waits for the lockup to be resolved and the lockup handling needs to wait for a fence that's never signaled because of the lockup.
The lockup handling calls radeon_fence_wait, not the generic fence_wait. It doesn't call the exported wait function that takes the exclusive_lock in read mode. And lockdep should have complained if I screwed that up. :-)
~Maarten
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [Nouveau] [PATCH 09/17] drm/radeon: use common fence implementation for fences
Quoted 4 lines · Maarten Lankhorst
Quoted 1 line
Can we somehow avoid the need to call
fence_signal()at all? The interrupts at least on radeon are way to unreliable for such a thing. Canenable_signallingfail? What's the reason forfence_signaled()in the first place?It doesn't need to be completely reliable, or finish immediately.
And any time
wake_up_all(&rdev->fence_queue)is called all the fences that were enabled will be rechecked.
I raised this already somewhere else, but should we have some common infrastructure in the core fence code to recheck fences periodically? radeon doesn't seem to be the only hw where this isn't reliable enough. Of course timer-based rechecking would only work if the driver provides the fence->signalled callback to recheck actual fence state. -Daniel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch
Christian König
maintainerRe: [Nouveau] [PATCH 09/17] drm/radeon: use common fence implementation for fences
Am 23.07.2014 09:09, schrieb Daniel Vetter:
Quoted 11 lines
Quoted 4 lines · Maarten Lankhorst
Quoted 1 line
Can we somehow avoid the need to call
fence_signal()at all? The interrupts at least on radeon are way to unreliable for such a thing. Canenable_signallingfail? What's the reason forfence_signaled()in the first place?It doesn't need to be completely reliable, or finish immediately.
And any time
wake_up_all(&rdev->fence_queue)is called all the fences that were enabled will be rechecked.I raised this already somewhere else, but should we have some common infrastructure in the core fence code to recheck fences periodically? radeon doesn't seem to be the only hw where this isn't reliable enough. Of course timer-based rechecking would only work if the driver provides the
fence->signalledcallback to recheck actual fence state.
Yeah, agree. The proposal won't work reliable at all with radeon.
Interrupts are accumulated before sending them to the CPU, e.g. you can get one interrupt for multiple fences finished. If it's just the interrupt for the last fence submitted that gets lost you are completely screwed up because you won't get another interrupt.
I had that problem multiple times while working on UVD support, resulting in the driver thinking that it can't submit more jobs because non of the interrupts for the already submitted fence cam through.
Apart from that interrupts on Macs usually don't work at all, so we really need a solution where calling fence_signaled() is completely optional.
Christian.
Quoted 1 line
-Daniel
Re: [Nouveau] [PATCH 09/17] drm/radeon: use common fence implementation for fences
op 23-07-14 09:15, Christian König schreef:
Quoted 13 lines
Am 23.07.2014 09:09, schrieb Daniel Vetter:
Quoted 11 lines
Quoted 4 lines · Maarten Lankhorst
Quoted 1 line
Can we somehow avoid the need to call
fence_signal()at all? The interrupts at least on radeon are way to unreliable for such a thing. Canenable_signallingfail? What's the reason forfence_signaled()in the first place?It doesn't need to be completely reliable, or finish immediately.
And any time
wake_up_all(&rdev->fence_queue)is called all the fences that were enabled will be rechecked.I raised this already somewhere else, but should we have some common infrastructure in the core fence code to recheck fences periodically? radeon doesn't seem to be the only hw where this isn't reliable enough. Of course timer-based rechecking would only work if the driver provides the
fence->signalledcallback to recheck actual fence state.
Quoted 5 lines
Yeah, agree. The proposal won't work reliable at all with radeon.
Interrupts are accumulated before sending them to the CPU, e.g. you can get one interrupt for multiple fences finished. If it's just the interrupt for the last fence submitted that gets lost you are completely screwed up because you won't get another interrupt.
I had that problem multiple times while working on UVD support, resulting in the driver thinking that it can't submit more jobs because non of the interrupts for the already submitted fence cam through.
Yeah but all the fences that have .enable_signaling will get signaled from a single interrupt, or when any waiter calls radeon_fence_process.
Quoted 1 line
Apart from that interrupts on Macs usually don't work at all, so we really need a solution where calling
fence_signaled()is completely optional.
I haven't had a problem with interrupts on my mbp after d1f9809ed1315c4cdc5760cf2f59626fd3276952, but it should be trivial to start a timer that periodically does wake_up_all, and gets its timeout reset in a call to radeon_fence_process. It could either be added as a work item, or as a normal timer (disabled during gpu lockup recovery to prevent checks from fiddling with things it shouldn't).
~Maarten
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Christian König
maintainerRe: [Nouveau] [PATCH 09/17] drm/radeon: use common fence implementation for fences
Am 23.07.2014 09:32, schrieb Maarten Lankhorst:
Quoted 13 lines
op 23-07-14 09:15, Christian König schreef:
Quoted 12 lines
Am 23.07.2014 09:09, schrieb Daniel Vetter:
Quoted 11 lines
Quoted 4 lines · Maarten Lankhorst
Quoted 1 line
Can we somehow avoid the need to call
fence_signal()at all? The interrupts at least on radeon are way to unreliable for such a thing. Canenable_signallingfail? What's the reason forfence_signaled()in the first place?It doesn't need to be completely reliable, or finish immediately.
And any time
wake_up_all(&rdev->fence_queue)is called all the fences that were enabled will be rechecked.I raised this already somewhere else, but should we have some common infrastructure in the core fence code to recheck fences periodically? radeon doesn't seem to be the only hw where this isn't reliable enough. Of course timer-based rechecking would only work if the driver provides the
fence->signalledcallback to recheck actual fence state.
Quoted 6 lines
Quoted 5 lines
Yeah, agree. The proposal won't work reliable at all with radeon.
Interrupts are accumulated before sending them to the CPU, e.g. you can get one interrupt for multiple fences finished. If it's just the interrupt for the last fence submitted that gets lost you are completely screwed up because you won't get another interrupt.
I had that problem multiple times while working on UVD support, resulting in the driver thinking that it can't submit more jobs because non of the interrupts for the already submitted fence cam through.
Yeah but all the fences that have .enable_signaling will get signaled from a single interrupt, or when any waiter calls
radeon_fence_process.
You still need to check if the fence is really signaled, cause radeon_fence_process might wakeup the wait queue because of something completely different.
Apart from that you once again rely on somebody else calling radeon_fence_process. This will probably work most of the times, but it's not 100% reliable.
Quoted 3 lines
Quoted 2 lines
Apart from that interrupts on Macs usually don't work at all, so we really need a solution where calling
fence_signaled()is completely optional.I haven't had a problem with interrupts on my mbp after
d1f9809ed1315c4cdc5760cf2f59626fd3276952, but it should be trivial to start a timer that periodically doeswake_up_all, and gets its timeout reset in a call toradeon_fence_process. It could either be added as a work item, or as a normal timer (disabled during gpu lockup recovery to prevent checks from fiddling with things it shouldn't).
That will probably work, but just again sounds like we force the driver to fit the fence implementation instead of the other way around.
Why is that fence_signaled() call needed for in the first place?
Christian.
Quoted 3 lines
~Maarten
_______________________________________________
Nouveau mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau
Re: [Nouveau] [PATCH 09/17] drm/radeon: use common fence implementation for fences
In reply to Maarten LankhorstAm 23.07.2014 09:06, schrieb Maarten Lankhorst:
Quoted 33 lines
op 23-07-14 08:52, Christian König schreef:
Quoted 17 lines
Am 23.07.2014 08:40, schrieb Maarten Lankhorst:
Quoted 16 lines
op 22-07-14 17:59, Christian König schreef:
Quoted 15 lines
Am 22.07.2014 17:42, schrieb Daniel Vetter:
Quoted 14 lines
Quoted 9 lines · Christian König
Drivers exporting fences need to provide a
fence->signaledand afence->waitfunction, everything else likefence->enable_signalingor callingfence_signaled()from the driver is optional.Drivers wanting to use exported fences don't call
fence->signaledorfence->waitin atomic or interrupt context, and not with holding any global locking primitives (likemmap_semetc...). Holding locking primitives local to the driver is ok, as long as they don't conflict with anything possible used by their own fence implementation.Well that's almost what we have right now with the exception that drivers are allowed (actually must for correctness when updating fences) the
ww_mutexesfor dma-bufs (or other buffer objects).Quoted 6 lines
Quoted 5 lines
Quoted 3 lines
In this case sorry for so much noise. I really haven't looked in so much detail into anything but Maarten's Radeon patches.
But how does that then work right now? My impression was that it's mandatory for drivers to call
fence_signaled()?It's only mandatory to call
fence_signal()if the .enable_signaling callback has been called, else you can get away with never calling signaling a fence at all before dropping the last refcount to it. This allows you to keep interrupts disabled when you don't need them.Can we somehow avoid the need to call
fence_signal()at all? The interrupts at least on radeon are way to unreliable for such a thing. Canenable_signallingfail? What's the reason forfence_signaled()in the first place?It doesn't need to be completely reliable, or finish immediately.
And any time
wake_up_all(&rdev->fence_queue)is called all the fences that were enabled will be rechecked.Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
Agreed that any shared locks are out of the way (especially stuff like
dev->struct_mutexor other non-strictly driver-private stuff, i915 is really bad here still).Yeah that's also an point I've wanted to note on Maartens patch. Radeon grabs the read side of it's exclusive semaphore while waiting for fences (because it assumes that the fence it waits for is a Radeon fence).
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Quoted 1 line
Assuming that we need to wait in both directions with Prime (e.g. Intel driver needs to wait for Radeon to finish rendering and Radeon needs to wait for Intel to finish displaying), this might become a perfect example of locking inversion.
In the preliminary patches where I can sync radeon with other GPU's I've been very careful in all the places that call into fences, to make sure that radeon wouldn't try to handle lockups for a different (possibly also radeon) card.
That's actually not such a good idea.
In case of a lockup we need to handle the lockup cause otherwise it could happen that radeon waits for the lockup to be resolved and the lockup handling needs to wait for a fence that's never signaled because of the lockup.
The lockup handling calls
radeon_fence_wait, not the genericfence_wait. It doesn't call the exported wait function that takes theexclusive_lockin read mode. And lockdep should have complained if I screwed that up. :-)
You screwed it up and lockdep didn't warn you about it :-P
It's not a locking problem I'm talking about here. Radeons lockup handling kicks in when anything calls into the driver from the outside, if you have a fence wait function that's called from the outside but doesn't handle lockups you essentially rely on somebody else calling another radeon function for the lockup to be resolved.
Christian.
Quoted 3 lines
~Maarten
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [Nouveau] [PATCH 09/17] drm/radeon: use common fence implementation for fences
Quoted 5 lines · Christian König
It's not a locking problem I'm talking about here. Radeons lockup handling kicks in when anything calls into the driver from the outside, if you have a fence wait function that's called from the outside but doesn't handle lockups you essentially rely on somebody else calling another radeon function for the lockup to be resolved.
So you don't have a timer in radeon that periodically checks whether progress is still being made? That's the approach we're using in i915, together with some tricks to kick any stuck waiters so that we can reliably step in and grab locks for the reset.
-Daniel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
Christian König
maintainerRe: [Nouveau] [PATCH 09/17] drm/radeon: use common fence implementation for fences
Am 23.07.2014 09:31, schrieb Daniel Vetter:
Quoted 11 lines
Quoted 5 lines · Christian König
It's not a locking problem I'm talking about here. Radeons lockup handling kicks in when anything calls into the driver from the outside, if you have a fence wait function that's called from the outside but doesn't handle lockups you essentially rely on somebody else calling another radeon function for the lockup to be resolved.
So you don't have a timer in radeon that periodically checks whether progress is still being made? That's the approach we're using in i915, together with some tricks to kick any stuck waiters so that we can reliably step in and grab locks for the reset.
We tried this approach, but it didn't worked at all.
I already considered trying it again because of the upcoming fence implementation, but reconsidering that when a driver is forced to change it's handling because of the fence implementation that's just another hint that there is something wrong here.
Christian.
Quoted 1 line
-Daniel
_______________________________________________
Nouveau mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau
Re: [Nouveau] [PATCH 09/17] drm/radeon: use common fence implementation for fences
op 23-07-14 09:37, Christian König schreef:
Quoted 8 lines
Am 23.07.2014 09:31, schrieb Daniel Vetter:
Quoted 7 lines
Quoted 5 lines · Christian König
It's not a locking problem I'm talking about here. Radeons lockup handling kicks in when anything calls into the driver from the outside, if you have a fence wait function that's called from the outside but doesn't handle lockups you essentially rely on somebody else calling another radeon function for the lockup to be resolved.
Quoted 8 lines
Quoted 4 lines
So you don't have a timer in radeon that periodically checks whether progress is still being made? That's the approach we're using in i915, together with some tricks to kick any stuck waiters so that we can reliably step in and grab locks for the reset.
We tried this approach, but it didn't worked at all.
I already considered trying it again because of the upcoming fence implementation, but reconsidering that when a driver is forced to change it's handling because of the fence implementation that's just another hint that there is something wrong here.
As far as I can tell it wouldn't need to be reworked for the fence implementation currently, only the moment you want to allow callers outside of radeon. :-) Doing a GPU lockup recovery in the wait function would be messy even right now, you would hit a deadlock in ttm_bo_delayed_delete -> ttm_bo_cleanup_refs_and_unlock.
Regardless of the fence implementation, why would it be a good idea to do a full lockup recovery when some other driver is calling your wait function? That doesn't seem to be a nice thing to do, so I think a timeout is the best error you could return here, other drivers have to deal with that anyway.
~Maarten
_______________________________________________
Nouveau mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau
Re: [Nouveau] [PATCH 09/17] drm/radeon: use common fence implementation for fences
Quoted 3 lines
Regardless of the fence implementation, why would it be a good idea to do a full lockup recovery when some other driver is calling your wait function? That doesn't seem to be a nice thing to do, so I think a timeout is the best error you could return here, other drivers have to deal with that anyway.
The problem is that we need to guarantee that the lockup will be resolved eventually.
Just imagine an application using prime is locking up Radeon and because of that gets killed by the user. Nothing else in the system would use the Radeon hardware any more and so radeon gets only called by another driver waiting patiently for radeon to finish rendering which never happens because the whole thing is locked up and we don't get a chance to recover.
Christian.
Am 23.07.2014 09:51, schrieb Maarten Lankhorst:
Quoted 16 lines
op 23-07-14 09:37, Christian König schreef:
Quoted 8 lines
Am 23.07.2014 09:31, schrieb Daniel Vetter:
Quoted 7 lines
Quoted 5 lines · Christian König
It's not a locking problem I'm talking about here. Radeons lockup handling kicks in when anything calls into the driver from the outside, if you have a fence wait function that's called from the outside but doesn't handle lockups you essentially rely on somebody else calling another radeon function for the lockup to be resolved.
Quoted 7 lines
Quoted 4 lines
So you don't have a timer in radeon that periodically checks whether progress is still being made? That's the approach we're using in i915, together with some tricks to kick any stuck waiters so that we can reliably step in and grab locks for the reset.
We tried this approach, but it didn't worked at all.
I already considered trying it again because of the upcoming fence implementation, but reconsidering that when a driver is forced to change it's handling because of the fence implementation that's just another hint that there is something wrong here.
Quoted 9 lines
As far as I can tell it wouldn't need to be reworked for the fence implementation currently, only the moment you want to allow callers outside of radeon. :-) Doing a GPU lockup recovery in the wait function would be messy even right now, you would hit a deadlock in
ttm_bo_delayed_delete->ttm_bo_cleanup_refs_and_unlock.Regardless of the fence implementation, why would it be a good idea to do a full lockup recovery when some other driver is calling your wait function? That doesn't seem to be a nice thing to do, so I think a timeout is the best error you could return here, other drivers have to deal with that anyway.
~Maarten
_______________________________________________
Nouveau mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau
Re: [Nouveau] [PATCH 09/17] drm/radeon: use common fence implementation for fences
Quoted 5 lines · Christian König
Just imagine an application using prime is locking up Radeon and because of that gets killed by the user. Nothing else in the system would use the Radeon hardware any more and so radeon gets only called by another driver waiting patiently for radeon to finish rendering which never happens because the whole thing is locked up and we don't get a chance to recover.
But isn't that possible already without fences? X hangs radeon, user crashes X for unrelated reasons before radeon will notice the hang. Then no one uses radeon any longer and the hang stays undetected. -Daniel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch _______________________________________________ Nouveau mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/nouveau
Christian König
maintainerRe: [Nouveau] [PATCH 09/17] drm/radeon: use common fence implementation for fences
Am 23.07.2014 10:07, schrieb Daniel Vetter:
Quoted 10 lines
Quoted 5 lines · Christian König
Just imagine an application using prime is locking up Radeon and because of that gets killed by the user. Nothing else in the system would use the Radeon hardware any more and so radeon gets only called by another driver waiting patiently for radeon to finish rendering which never happens because the whole thing is locked up and we don't get a chance to recover.
But isn't that possible already without fences? X hangs radeon, user crashes X for unrelated reasons before radeon will notice the hang. Then no one uses radeon any longer and the hang stays undetected.
Yeah, especially with multimedia application. But I don't really care about this problem because the next time an application tries to use the block in question we actually do the reset and everything is fine.
In your example we would do the reset when the next X server starts, before that point nobody would care because nobody uses the hardware.
An additional problem here is that resets are something perfect normal for radeon. For example UVD can "crash" when you feed it with invalid bitstream data, (ok actually it send an interrupt and stops any processing for the driver to investigate). To continue processing you need to go through a rather complicated reset procedure.
Christian.
Quoted 1 line
-Daniel
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [Nouveau] [PATCH 09/17] drm/radeon: use common fence implementation for fences
op 23-07-14 10:20, Christian König schreef:
Quoted 12 lines
Am 23.07.2014 10:07, schrieb Daniel Vetter:
Quoted 10 lines
Quoted 5 lines · Christian König
Just imagine an application using prime is locking up Radeon and because of that gets killed by the user. Nothing else in the system would use the Radeon hardware any more and so radeon gets only called by another driver waiting patiently for radeon to finish rendering which never happens because the whole thing is locked up and we don't get a chance to recover.
But isn't that possible already without fences? X hangs radeon, user crashes X for unrelated reasons before radeon will notice the hang. Then no one uses radeon any longer and the hang stays undetected.
Quoted 5 lines
Yeah, especially with multimedia application. But I don't really care about this problem because the next time an application tries to use the block in question we actually do the reset and everything is fine.
In your example we would do the reset when the next X server starts, before that point nobody would care because nobody uses the hardware.
An additional problem here is that resets are something perfect normal for radeon. For example UVD can "crash" when you feed it with invalid bitstream data, (ok actually it send an interrupt and stops any processing for the driver to investigate). To continue processing you need to go through a rather complicated reset procedure.
In this case if the sync was to i915 the i915 lockup procedure would take care of itself. It wouldn't fix radeon, but it would at least unblock your intel card again. I haven't specifically added a special case to attempt to unblock external fences, but I've considered it. :-)
~Maarten
_______________________________________________
Nouveau mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau
Re: [Nouveau] [PATCH 09/17] drm/radeon: use common fence implementation for fences
Quoted 1 line · Maarten Lankhorst
In this case if the sync was to i915 the i915 lockup procedure would take care of itself. It wouldn't fix radeon, but it would at least unblock your intel card again. I haven't specifically added a special case to attempt to unblock external fences, but I've considered it. :-)
Actually the i915 reset stuff relies crucially on being able to kick all waiters holding driver locks. Since the current fence code only exposes an opaque wait function without exposing the underlying wait queue we won't be able to sleep on both the fence queue and the reset queue. So would pose a problem if we add fence_wait calls to our driver.
-Daniel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch
Re: [Nouveau] [PATCH 09/17] drm/radeon: use common fence implementation for fences
Am 23.07.2014 10:42, schrieb Daniel Vetter:
Quoted 9 lines
Quoted 1 line · Maarten Lankhorst
In this case if the sync was to i915 the i915 lockup procedure would take care of itself. It wouldn't fix radeon, but it would at least unblock your intel card again. I haven't specifically added a special case to attempt to unblock external fences, but I've considered it. :-)
Actually the i915 reset stuff relies crucially on being able to kick all waiters holding driver locks. Since the current fence code only exposes an opaque wait function without exposing the underlying wait queue we won't be able to sleep on both the fence queue and the reset queue. So would pose a problem if we add
fence_waitcalls to our driver.
And apart from that I really think that I misunderstood Maarten. But his explanation sounds like i915 would do a reset because Radeon is locked up, right?
Well if that's really the case then I would question the interface even more, cause that is really nonsense.
Christian.
Quoted 1 line
-Daniel
Re: [Nouveau] [PATCH 09/17] drm/radeon: use common fence implementation for fences
Quoted 18 lines · Christian König
Am 23.07.2014 10:42, schrieb Daniel Vetter:
Quoted 8 lines
Quoted 5 lines · Maarten Lankhorst
In this case if the sync was to i915 the i915 lockup procedure would take care of itself. It wouldn't fix radeon, but it would at least unblock your intel card again. I haven't specifically added a special case to attempt to unblock external fences, but I've considered it. :-)
Quoted 6 lines
Actually the i915 reset stuff relies crucially on being able to kick all waiters holding driver locks. Since the current fence code only exposes an opaque wait function without exposing the underlying wait queue we won't be able to sleep on both the fence queue and the reset queue. So would pose a problem if we add
fence_waitcalls to our driver.
Quoted 6 lines
And apart from that I really think that I misunderstood Maarten. But his explanation sounds like i915 would do a reset because Radeon is locked up, right?
Well if that's really the case then I would question the interface even more, cause that is really nonsense.
I disagree - the entire point of fences is that we can do multi-gpu work asynchronously. So by the time we'll notice that radeon's dead we have accepted the batch from userspace already. The only way to get rid of it again is through our reset machinery, which also tells userspace that we couldn't execute the batch. Whether we actually need to do a hw reset depends upon whether we've committed the batch to the hw already. Atm that's always the case, but the scheduler will change that. So I have no issues with intel doing a reset when other drivers don't signal fences.
Also this isn't a problem with the interface really, but with the current implementation for radeon. And getting cross-driver reset notifications right will require more work either way. -Daniel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch _______________________________________________ Nouveau mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/nouveau
Christian König
maintainerRe: [Nouveau] [PATCH 09/17] drm/radeon: use common fence implementation for fences
Am 23.07.2014 10:54, schrieb Daniel Vetter:
Quoted 23 lines
Quoted 15 lines · Christian König
Am 23.07.2014 10:42, schrieb Daniel Vetter:
Quoted 6 lines
Quoted 4 lines · Maarten Lankhorst
In this case if the sync was to i915 the i915 lockup procedure would take care of itself. It wouldn't fix radeon, but it would at least unblock your intel card again. I haven't specifically added a special case to attempt to unblock external fences, but I've considered it. :-)
Quoted 6 lines
Actually the i915 reset stuff relies crucially on being able to kick all waiters holding driver locks. Since the current fence code only exposes an opaque wait function without exposing the underlying wait queue we won't be able to sleep on both the fence queue and the reset queue. So would pose a problem if we add
fence_waitcalls to our driver.Quoted 6 lines
And apart from that I really think that I misunderstood Maarten. But his explanation sounds like i915 would do a reset because Radeon is locked up, right?
Well if that's really the case then I would question the interface even more, cause that is really nonsense.
Quoted 9 lines
I disagree - the entire point of fences is that we can do multi-gpu work asynchronously. So by the time we'll notice that radeon's dead we have accepted the batch from userspace already. The only way to get rid of it again is through our reset machinery, which also tells userspace that we couldn't execute the batch. Whether we actually need to do a hw reset depends upon whether we've committed the batch to the hw already. Atm that's always the case, but the scheduler will change that. So I have no issues with intel doing a reset when other drivers don't signal fences.
You submit a job to the hardware and then block the job to wait for radeon to be finished? Well than this would indeed require a hardware reset, but wouldn't that make the whole problem even worse?
I mean currently we block one userspace process to wait for other hardware to be finished with a buffer, but what you are describing here blocks the whole hardware to wait for other hardware which in the end blocks all userspace process accessing the hardware.
Talking about alternative approaches wouldn't it be simpler to just offload the waiting to a different kernel or userspace thread?
Christian.
Quoted 5 lines
Also this isn't a problem with the interface really, but with the current implementation for radeon. And getting cross-driver reset notifications right will require more work either way. -Daniel
_______________________________________________
Nouveau mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau
Re: [Nouveau] [PATCH 09/17] drm/radeon: use common fence implementation for fences
Quoted 8 lines · Christian König
You submit a job to the hardware and then block the job to wait for radeon to be finished? Well than this would indeed require a hardware reset, but wouldn't that make the whole problem even worse?
I mean currently we block one userspace process to wait for other hardware to be finished with a buffer, but what you are describing here blocks the whole hardware to wait for other hardware which in the end blocks all userspace process accessing the hardware.
There is nothing new here with prime - if one context hangs the gpu it blocks everyone else on i915.
Quoted 2 lines
Talking about alternative approaches wouldn't it be simpler to just offload the waiting to a different kernel or userspace thread?
Well this is exactly what we'll do once we have the scheduler. But this is an orthogonal issue imo.
-Daniel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch _______________________________________________ Nouveau mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/nouveau
Christian König
maintainerRe: [Nouveau] [PATCH 09/17] drm/radeon: use common fence implementation for fences
Am 23.07.2014 11:30, schrieb Daniel Vetter:
Quoted 10 lines
Quoted 8 lines · Christian König
You submit a job to the hardware and then block the job to wait for radeon to be finished? Well than this would indeed require a hardware reset, but wouldn't that make the whole problem even worse?
I mean currently we block one userspace process to wait for other hardware to be finished with a buffer, but what you are describing here blocks the whole hardware to wait for other hardware which in the end blocks all userspace process accessing the hardware.
Quoted 7 lines
There is nothing new here with prime - if one context hangs the gpu it blocks everyone else on i915.
Quoted 2 lines
Talking about alternative approaches wouldn't it be simpler to just offload the waiting to a different kernel or userspace thread?
Well this is exactly what we'll do once we have the scheduler. But this is an orthogonal issue imo.
Mhm, could have the scheduler first?
Cause that sounds like reducing the necessary fence interface to just a fence->wait function.
Christian.
Quoted 1 line
-Daniel
_______________________________________________
Nouveau mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau
Re: [Nouveau] [PATCH 09/17] drm/radeon: use common fence implementation for fences
op 23-07-14 11:36, Christian König schreef:
Quoted 14 lines
Am 23.07.2014 11:30, schrieb Daniel Vetter:
Quoted 13 lines
Quoted 8 lines · Christian König
You submit a job to the hardware and then block the job to wait for radeon to be finished? Well than this would indeed require a hardware reset, but wouldn't that make the whole problem even worse?
I mean currently we block one userspace process to wait for other hardware to be finished with a buffer, but what you are describing here blocks the whole hardware to wait for other hardware which in the end blocks all userspace process accessing the hardware.
There is nothing new here with prime - if one context hangs the gpu it blocks everyone else on i915.
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Talking about alternative approaches wouldn't it be simpler to just offload the waiting to a different kernel or userspace thread?
Well this is exactly what we'll do once we have the scheduler. But this is an orthogonal issue imo.
Mhm, could have the scheduler first?
Cause that sounds like reducing the necessary fence interface to just a
fence->waitfunction.
You would also lose benefits like having a 'perf timechart' for gpu's.
~Maarten
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Christian König
maintainerRe: [Nouveau] [PATCH 09/17] drm/radeon: use common fence implementation for fences
Am 23.07.2014 11:38, schrieb Maarten Lankhorst:
Quoted 15 lines
op 23-07-14 11:36, Christian König schreef:
Quoted 14 lines
Am 23.07.2014 11:30, schrieb Daniel Vetter:
Quoted 13 lines
Quoted 8 lines · Christian König
You submit a job to the hardware and then block the job to wait for radeon to be finished? Well than this would indeed require a hardware reset, but wouldn't that make the whole problem even worse?
I mean currently we block one userspace process to wait for other hardware to be finished with a buffer, but what you are describing here blocks the whole hardware to wait for other hardware which in the end blocks all userspace process accessing the hardware.
There is nothing new here with prime - if one context hangs the gpu it blocks everyone else on i915.
Quoted 8 lines
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Talking about alternative approaches wouldn't it be simpler to just offload the waiting to a different kernel or userspace thread?
Well this is exactly what we'll do once we have the scheduler. But this is an orthogonal issue imo.
Mhm, could have the scheduler first?
Cause that sounds like reducing the necessary fence interface to just a
fence->waitfunction.You would also lose benefits like having a 'perf timechart' for gpu's.
I can live with that, when it reduces the complexity of the fence interface.
Christian.
Quoted 3 lines
~Maarten
_______________________________________________
Nouveau mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau
Re: [Nouveau] [PATCH 09/17] drm/radeon: use common fence implementation for fences
In reply to Christian KönigQuoted 23 lines · Christian König
Am 23.07.2014 11:30, schrieb Daniel Vetter:
Quoted 21 lines
Quoted 11 lines · Christian König
You submit a job to the hardware and then block the job to wait for radeon
to be finished? Well than this would indeed require a hardware reset, but wouldn't that make the whole problem even worse?I mean currently we block one userspace process to wait for other hardware
to be finished with a buffer, but what you are describing here blocks the whole hardware to wait for other hardware which in the end blocks all userspace process accessing the hardware.There is nothing new here with prime - if one context hangs the gpu it blocks everyone else on i915.
Quoted 3 lines
Talking about alternative approaches wouldn't it be simpler to just offload
the waiting to a different kernel or userspace thread?
Quoted 8 lines
Quoted 2 lines
Well this is exactly what we'll do once we have the scheduler. But this is an orthogonal issue imo.
Mhm, could have the scheduler first?
Cause that sounds like reducing the necessary fence interface to just a
fence->waitfunction.
The scheduler needs to keep track of a lot of fences, so I think we'll have to register callbacks, not a simple wait function. We must keep track of all the non-i915 fences for all oustanding batches. Also, the scheduler doesn't eliminate the hw queue, only keep it much slower so that we can sneak in higher priority things.
Really, scheduler or not is orthogonal.
-Daniel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [Nouveau] [PATCH 09/17] drm/radeon: use common fence implementation for fences
Quoted 7 lines · Daniel Vetter
The scheduler needs to keep track of a lot of fences, so I think we'll have to register callbacks, not a simple wait function. We must keep track of all the non-i915 fences for all oustanding batches. Also, the scheduler doesn't eliminate the hw queue, only keep it much slower so that we can sneak in higher priority things.
Really, scheduler or not is orthogonal.
Also see my other comment about interactions between wait_fence and the i915 reset logic. We can't actually use it from within the scheduler code since that would deadlock.
-Daniel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch
Re: [Nouveau] [PATCH 09/17] drm/radeon: use common fence implementation for fences
Am 23.07.2014 11:44, schrieb Daniel Vetter:
Quoted 11 lines · Daniel Vetter
Quoted 7 lines
The scheduler needs to keep track of a lot of fences, so I think we'll have to register callbacks, not a simple wait function. We must keep track of all the non-i915 fences for all oustanding batches. Also, the scheduler doesn't eliminate the hw queue, only keep it much slower so that we can sneak in higher priority things.
Really, scheduler or not is orthogonal.
Also see my other comment about interactions between
wait_fenceand the i915 reset logic. We can't actually use it from within the scheduler code since that would deadlock.
Yeah, I see. You would need some way to abort the waiting on other devices fences in case of a lockup.
What about an userspace thread to offload waiting and command submission to?
Just playing with ideas right now,
Christian.
Quoted 1 line
-Daniel
Re: [Nouveau] [PATCH 09/17] drm/radeon: use common fence implementation for fences
Quoted 17 lines · Christian König
Am 23.07.2014 11:44, schrieb Daniel Vetter:
Quoted 9 lines
Quoted 7 lines · Daniel Vetter
The scheduler needs to keep track of a lot of fences, so I think we'll have to register callbacks, not a simple wait function. We must keep track of all the non-i915 fences for all oustanding batches. Also, the scheduler doesn't eliminate the hw queue, only keep it much slower so that we can sneak in higher priority things.
Quoted 5 lines
Quoted 1 line
Really, scheduler or not is orthogonal.
Also see my other comment about interactions between
wait_fenceand the i915 reset logic. We can't actually use it from within the scheduler code since that would deadlock.
Quoted 4 lines
Yeah, I see. You would need some way to abort the waiting on other devices fences in case of a lockup.
What about an userspace thread to offload waiting and command submission to?
That's what your android guys currently do. They hate it. And google explicitly created their syncpts stuff to move all that into the kernel. That one does explicit fencing, but the end result is still that you have fences as deps between different drivers.
The other problem is that dri/prime is running under an implicitly sync'ed model, so there's no clear point/responsibility for who would actually do the waiting. You'll end up with synchronous behaviour since the render sooner or later needs to perfectly align with client/compositor ipc.
-Daniel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch _______________________________________________ Nouveau mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/nouveau
Re: [Nouveau] [PATCH 09/17] drm/radeon: use common fence implementation for fences
In reply to Christian Königop 23-07-14 11:47, Christian König schreef:
Quoted 8 lines
Am 23.07.2014 11:44, schrieb Daniel Vetter:
Quoted 7 lines · Daniel Vetter
Quoted 6 lines
The scheduler needs to keep track of a lot of fences, so I think we'll have to register callbacks, not a simple wait function. We must keep track of all the non-i915 fences for all oustanding batches. Also, the scheduler doesn't eliminate the hw queue, only keep it much slower so that we can sneak in higher priority things.
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Really, scheduler or not is orthogonal.
Also see my other comment about interactions between
wait_fenceand the i915 reset logic. We can't actually use it from within the scheduler code since that would deadlock.Yeah, I see. You would need some way to abort the waiting on other devices fences in case of a lockup.
What about an userspace thread to offload waiting and command submission to?
You would still need enable_signaling, else polling on the dma-buf wouldn't work. ;-)
Can't wait synchronously with multiple shared fences, need to poll for that.
And the dma-buf would still have fences belonging to both drivers, and it would still call from outside the driver.
~Maarten
_______________________________________________
Nouveau mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau
Christian König
maintainerRe: [Nouveau] [PATCH 09/17] drm/radeon: use common fence implementation for fences
Am 23.07.2014 11:55, schrieb Maarten Lankhorst:
Quoted 10 lines
op 23-07-14 11:47, Christian König schreef:
Quoted 9 lines
Am 23.07.2014 11:44, schrieb Daniel Vetter:
Quoted 8 lines · Daniel Vetter
Quoted 7 lines
The scheduler needs to keep track of a lot of fences, so I think we'll have to register callbacks, not a simple wait function. We must keep track of all the non-i915 fences for all oustanding batches. Also, the scheduler doesn't eliminate the hw queue, only keep it much slower so that we can sneak in higher priority things.
Really, scheduler or not is orthogonal.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Also see my other comment about interactions between
wait_fenceand the i915 reset logic. We can't actually use it from within the scheduler code since that would deadlock.Yeah, I see. You would need some way to abort the waiting on other devices fences in case of a lockup.
What about an userspace thread to offload waiting and command submission to?
You would still need
enable_signaling, else polling on the dma-buf wouldn't work. ;-) Can't wait synchronously with multiple shared fences, need to poll for that.
No you don't. Just make a list of fences you need to wait for and wait for each after another. But having an thread for each command submission context doesn't sounds like the best solution anyway.
Quoted 1 line
And the dma-buf would still have fences belonging to both drivers, and it would still call from outside the driver.
Calling from outside the driver is fine as long as the driver can do everything necessary to complete it's work and isn't forced into any ugly hacks and things that are not 100% reliable.
So I don't see much other approach as integrating recovery code for not firing interrupts and some kind of lockup handling into the fence code as well.
Christian.
Quoted 3 lines
~Maarten
_______________________________________________
Nouveau mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau
Re: [Nouveau] [PATCH 09/17] drm/radeon: use common fence implementation for fences
Quoted 5 lines · Christian König
Quoted 3 lines
And the dma-buf would still have fences belonging to both drivers, and it would still call from outside the driver.
Quoted 7 lines
Calling from outside the driver is fine as long as the driver can do everything necessary to complete it's work and isn't forced into any ugly hacks and things that are not 100% reliable.
So I don't see much other approach as integrating recovery code for not firing interrupts and some kind of lockup handling into the fence code as well.
That approach doesn't really work at that well since every driver has it's own reset semantics. And we're trying to move away from global reset to fine-grained reset. So stop-the-world reset is out of fashion, at least for i915. As you said, reset is normal in gpus and we're trying to make reset less invasive. I really don't see a point in imposing a reset scheme upon all drivers and I think you have about as much motivation to convert radeon to the scheme used by i915 as I'll have for converting to the one used by radeon. If it would fit at all.
I guess for radeon we just have to add tons of insulation by punting all callbacks to work items so that radeon can do whatever it wants. Plus start a delayed_work based fallback when ->enable_signalling is called to make sure we work on platforms that lack interrupts. -Daniel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
Christian König
maintainerRe: [Nouveau] [PATCH 09/17] drm/radeon: use common fence implementation for fences
Am 23.07.2014 12:52, schrieb Daniel Vetter:
Quoted 12 lines
Quoted 10 lines · Christian König
Quoted 2 lines
And the dma-buf would still have fences belonging to both drivers, and it would still call from outside the driver.
Calling from outside the driver is fine as long as the driver can do everything necessary to complete it's work and isn't forced into any ugly hacks and things that are not 100% reliable.
So I don't see much other approach as integrating recovery code for not firing interrupts and some kind of lockup handling into the fence code as well.
Quoted 9 lines
That approach doesn't really work at that well since every driver has it's own reset semantics. And we're trying to move away from global reset to fine-grained reset. So stop-the-world reset is out of fashion, at least for i915. As you said, reset is normal in gpus and we're trying to make reset less invasive. I really don't see a point in imposing a reset scheme upon all drivers and I think you have about as much motivation to convert radeon to the scheme used by i915 as I'll have for converting to the one used by radeon. If it would fit at all.
Oh my! No, I didn't wanted to suggest any global reset infrastructure.
My idea was more that the fence framework provides a fence->process_signaling callback that is periodically called after enable_signaling is called to trigger manual signal processing in the driver.
This would both be suitable as a fallback in case of not working interrupts as well as a chance for any driver to do necessary lockup handling.
Christian.
Quoted 5 lines
I guess for radeon we just have to add tons of insulation by punting all callbacks to work items so that radeon can do whatever it wants. Plus start a
delayed_workbased fallback when ->enable_signalling is called to make sure we work on platforms that lack interrupts. -Daniel
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [Nouveau] [PATCH 09/17] drm/radeon: use common fence implementation for fences
Quoted 7 lines · Christian König
My idea was more that the fence framework provides a
fence->process_signalingcallback that is periodically called afterenable_signalingis called to trigger manual signal processing in the driver.This would both be suitable as a fallback in case of not working interrupts as well as a chance for any driver to do necessary lockup handling.
Imo that should be an implementation detail of the fence provider. So in ->enable_signaling radeon needs to arm a delayed work to regularly check fence and signal them if the irq failed. If it's a common need we might provide some shared code for this (e.g. a struct unreliable_fence or so). But this shouldn't be mandatory since not all gpus are broken like that.
And if we force other drivers to care for this special case that imo leaks the abstraction out of radeon (or any other driver with unreliable interrupts).
-Daniel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [Nouveau] [PATCH 09/17] drm/radeon: use common fence implementation for fences
In reply to Christian Königop 23-07-14 14:36, Christian König schreef:
Quoted 22 lines
Am 23.07.2014 12:52, schrieb Daniel Vetter:
Quoted 12 lines
Quoted 10 lines · Christian König
Quoted 2 lines
And the dma-buf would still have fences belonging to both drivers, and it would still call from outside the driver.
Calling from outside the driver is fine as long as the driver can do everything necessary to complete it's work and isn't forced into any ugly hacks and things that are not 100% reliable.
So I don't see much other approach as integrating recovery code for not firing interrupts and some kind of lockup handling into the fence code as well.
Quoted 9 lines
That approach doesn't really work at that well since every driver has it's own reset semantics. And we're trying to move away from global reset to fine-grained reset. So stop-the-world reset is out of fashion, at least for i915. As you said, reset is normal in gpus and we're trying to make reset less invasive. I really don't see a point in imposing a reset scheme upon all drivers and I think you have about as much motivation to convert radeon to the scheme used by i915 as I'll have for converting to the one used by radeon. If it would fit at all.
Quoted 5 lines
Oh my! No, I didn't wanted to suggest any global reset infrastructure.
My idea was more that the fence framework provides a
fence->process_signalingcallback that is periodically called afterenable_signalingis called to trigger manual signal processing in the driver.This would both be suitable as a fallback in case of not working interrupts as well as a chance for any driver to do necessary lockup handling.
I managed to do it without needing it to be part of the interface? I'm not sure whether radeon_fence_driver_recheck needs exclusive_lock, but if so it's a small change..
drivers/gpu/drm/radeon/radeon.h +3 -0
@@ -345,6 +345,9 @@ struct radeon_fence_driver {uint64_t sync_seq[RADEON_NUM_RINGS ];atomic64_t last_seq;bool initialized; +struct delayed_work work; +struct radeon_device *rdev; +unsigned ring; };struct radeon_fence_cb {
drivers/gpu/drm/radeon/radeon_fence.c +16 -0
@@ -231,6 +231,9 @@ static bool __radeon_fence_process(struct radeon_device *rdev, int ring) } }while (atomic64_xchg (&rdev->fence_drv[ring].last_seq, seq) > seq); +if (!wake && last_seq < last_emitted) +schedule_delayed_work (&rdev->fence_drv[ring].work,jiffies_to_msecs (10 )); +return wake; }
@@ -815,6 +818,14 @@ int radeon_fence_driver_start_ring(struct radeon_device *rdev, int ring)return 0 ; } +static void radeon_fence_driver_recheck (struct work_struct *work) +{ + struct radeon_fence_driver *drv = container_of(work, struct radeon_fence_driver, work.work); + +DRM_ERROR ("omg, working!\n" ); +radeon_fence_process (drv->rdev, drv->ring); +} +/** * radeon_fence_driver_init_ring - init the fence driver * for the requested ring.
@@ -836,6 +847,10 @@ 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; + + rdev->fence_drv[ring].ring = ring; + rdev->fence_drv[ring].rdev = rdev; +INIT_DELAYED_WORK (&rdev->fence_drv[ring].work, radeon_fence_driver_recheck); }/**
@@ -880,6 +895,7 @@ 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].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_irq_kms.c +2 -2
@@ -331,7 +331,7 @@ void radeon_irq_kms_sw_irq_get(struct radeon_device *rdev, int ring) {unsigned long irqflags; -if (!rdev->ddev->irq_enabled) +// if (!rdev->ddev->irq_enabled) return ;if (atomic_inc_return (&rdev->irq.ring_int[ring]) ==1 ) {
@@ -355,7 +355,7 @@ void radeon_irq_kms_sw_irq_put(struct radeon_device *rdev, int ring) {unsigned long irqflags; -if (!rdev->ddev->irq_enabled) +// if (!rdev->ddev->irq_enabled) return ;if (atomic_dec_and_test (&rdev->irq.ring_int[ring])) {
_______________________________________________
Nouveau mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau
Re: [Nouveau] [PATCH 09/17] drm/radeon: use common fence implementation for fences
op 23-07-14 15:16, Maarten Lankhorst schreef:
Quoted 48 lines
op 23-07-14 14:36, Christian König schreef:
Quoted 21 lines
Am 23.07.2014 12:52, schrieb Daniel Vetter:
Quoted 11 lines
Quoted 9 lines · Christian König
Quoted 2 lines
And the dma-buf would still have fences belonging to both drivers, and it would still call from outside the driver.
Calling from outside the driver is fine as long as the driver can do everything necessary to complete it's work and isn't forced into any ugly hacks and things that are not 100% reliable.
So I don't see much other approach as integrating recovery code for not firing interrupts and some kind of lockup handling into the fence code as well.
Quoted 9 lines
That approach doesn't really work at that well since every driver has it's own reset semantics. And we're trying to move away from global reset to fine-grained reset. So stop-the-world reset is out of fashion, at least for i915. As you said, reset is normal in gpus and we're trying to make reset less invasive. I really don't see a point in imposing a reset scheme upon all drivers and I think you have about as much motivation to convert radeon to the scheme used by i915 as I'll have for converting to the one used by radeon. If it would fit at all.
Quoted 5 lines
Oh my! No, I didn't wanted to suggest any global reset infrastructure.
My idea was more that the fence framework provides a
fence->process_signalingcallback that is periodically called afterenable_signalingis called to trigger manual signal processing in the driver.This would both be suitable as a fallback in case of not working interrupts as well as a chance for any driver to do necessary lockup handling.
I managed to do it without needing it to be part of the interface? I'm not sure whether
radeon_fence_driver_recheckneedsexclusive_lock, but if so it's a small change..drivers/gpu/drm/radeon/radeon.h +3
-0@@ -345,6 +345,9 @@ struct radeon_fence_driver {uint64_t sync_seq[RADEON_NUM_RINGS ];atomic64_t last_seq;bool initialized; +struct delayed_work work; +struct radeon_device *rdev; +unsigned ring; };struct radeon_fence_cb {drivers/gpu/drm/radeon/radeon_fence.c +0
-0
drivers/gpu/drm/radeon/radeon_fence.c static bool __radeon_fence_process(struct radeon_device *rdev, int ring) · line 237
Quoted 7 lines
drivers/gpu/drm/radeon/radeon_fence.c +3
-0@@ -231,6 +231,9 @@ static bool __radeon_fence_process(struct radeon_device *rdev, int ring) } }while (atomic64_xchg (&rdev->fence_drv[ring].last_seq, seq) > seq); +if (!wake && last_seq < last_emitted) +schedule_delayed_work (&rdev->fence_drv[ring].work,jiffies_to_msecs (10 )); +
When trying this: if (seq < last_emitted) is probably a better check.
~Maarten
_______________________________________________
Nouveau mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau
Christian König
maintainerRe: [Nouveau] [PATCH 09/17] drm/radeon: use common fence implementation for fences
Hi Maarten,
try to implement this as a replacement for specifying the RADEON_FENCE_JIFFIES_TIMEOUT on wait_event_*. And reset the timeout every time radeon_fence_process is called and not only when any of the sequences increment.
I don't have the time right now to look deeper into it or help with the patch, but the general approach sounds valid to me.
Regards,
Christian.
Am 23.07.2014 16:05, schrieb Maarten Lankhorst:
Quoted 52 lines
op 23-07-14 15:16, Maarten Lankhorst schreef:
Quoted 51 lines
op 23-07-14 14:36, Christian König schreef:
Quoted 21 lines
Am 23.07.2014 12:52, schrieb Daniel Vetter:
Quoted 11 lines
Quoted 9 lines · Christian König
Quoted 2 lines
And the dma-buf would still have fences belonging to both drivers, and it would still call from outside the driver.
Calling from outside the driver is fine as long as the driver can do everything necessary to complete it's work and isn't forced into any ugly hacks and things that are not 100% reliable.
So I don't see much other approach as integrating recovery code for not firing interrupts and some kind of lockup handling into the fence code as well.
Quoted 9 lines
That approach doesn't really work at that well since every driver has it's own reset semantics. And we're trying to move away from global reset to fine-grained reset. So stop-the-world reset is out of fashion, at least for i915. As you said, reset is normal in gpus and we're trying to make reset less invasive. I really don't see a point in imposing a reset scheme upon all drivers and I think you have about as much motivation to convert radeon to the scheme used by i915 as I'll have for converting to the one used by radeon. If it would fit at all.
Quoted 5 lines
Oh my! No, I didn't wanted to suggest any global reset infrastructure.
My idea was more that the fence framework provides a
fence->process_signalingcallback that is periodically called afterenable_signalingis called to trigger manual signal processing in the driver.This would both be suitable as a fallback in case of not working interrupts as well as a chance for any driver to do necessary lockup handling.
I managed to do it without needing it to be part of the interface? I'm not sure whether
radeon_fence_driver_recheckneedsexclusive_lock, but if so it's a small change..drivers/gpu/drm/radeon/radeon.h +3
-0@@ -345,6 +345,9 @@ struct radeon_fence_driver {uint64_t sync_seq[RADEON_NUM_RINGS ];atomic64_t last_seq;bool initialized; +struct delayed_work work; +struct radeon_device *rdev; +unsigned ring; };struct radeon_fence_cb {drivers/gpu/drm/radeon/radeon_fence.c +0
-0@@ -231,6 +231,9 @@ static bool __radeon_fence_process(struct radeon_device *rdev, int ring) } }while (atomic64_xchg (&rdev->fence_drv[ring].last_seq, seq) > seq);
Quoted 8 lines
drivers/gpu/drm/radeon/radeon_fence.c static bool __radeon_fence_process(struct radeon_device *rdev, int ring) · line 239
Quoted 4 lines
drivers/gpu/drm/radeon/radeon_fence.c +3
-0+if (!wake && last_seq < last_emitted) +schedule_delayed_work (&rdev->fence_drv[ring].work,jiffies_to_msecs (10 )); +When trying this: if (seq <
last_emitted) is probably a better check.~Maarten
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [Nouveau] [PATCH 09/17] drm/radeon: use common fence implementation for fences
In reply to Christian KönigQuoted 18 lines · Christian König
Am 23.07.2014 09:31, schrieb Daniel Vetter:
Quoted 11 lines
Quoted 8 lines · Christian König
It's not a locking problem I'm talking about here. Radeons lockup handling
kicks in when anything calls into the driver from the outside, if you have a
fence wait function that's called from the outside but doesn't handle lockups you essentially rely on somebody else calling another radeon function for the lockup to be resolved.Quoted 4 lines
So you don't have a timer in radeon that periodically checks whether progress is still being made? That's the approach we're using in i915, together with some tricks to kick any stuck waiters so that we can reliably step in and grab locks for the reset.
Quoted 6 lines
We tried this approach, but it didn't worked at all.
I already considered trying it again because of the upcoming fence implementation, but reconsidering that when a driver is forced to change it's handling because of the fence implementation that's just another hint that there is something wrong here.
Out of curiosity: What's the blocker for using a timer/scheduled work to reset radeon? Getting this right on i915 has been fairly tricky and we now have an elaborate multi-stage state machine to get the driver through a reset. So always interested in different solutions. -Daniel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
Christian König
maintainerRe: [Nouveau] [PATCH 09/17] drm/radeon: use common fence implementation for fences
Am 23.07.2014 10:01, schrieb Daniel Vetter:
Quoted 19 lines
Quoted 17 lines · Christian König
Am 23.07.2014 09:31, schrieb Daniel Vetter:
Quoted 9 lines
Quoted 7 lines · Christian König
It's not a locking problem I'm talking about here. Radeons lockup handling
kicks in when anything calls into the driver from the outside, if you have a
fence wait function that's called from the outside but doesn't handle lockups you essentially rely on somebody else calling another radeon function for the lockup to be resolved.Quoted 4 lines
So you don't have a timer in radeon that periodically checks whether progress is still being made? That's the approach we're using in i915, together with some tricks to kick any stuck waiters so that we can reliably step in and grab locks for the reset.
We tried this approach, but it didn't worked at all.
Quoted 8 lines
Quoted 4 lines
I already considered trying it again because of the upcoming fence implementation, but reconsidering that when a driver is forced to change it's handling because of the fence implementation that's just another hint that there is something wrong here.
Out of curiosity: What's the blocker for using a timer/scheduled work to reset radeon? Getting this right on i915 has been fairly tricky and we now have an elaborate multi-stage state machine to get the driver through a reset. So always interested in different solutions.
IIRC we would have needed a quite advanced multi-stage state machine as well and that was just to much overhead at this point.
One major problem was the power management in use back then, but that got replaced by DPM in the meantime. So it might be a good idea to try again.
What we currently do is marking the driver as "needs reset" and returning -EAGAIN and then the next IOCTL starts the reset procedure before doing anything else.
Christian.
Quoted 1 line
-Daniel
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [Nouveau] [PATCH 09/17] drm/radeon: use common fence implementation for fences
In reply to Christian KönigQuoted 39 lines · Christian König
Am 23.07.2014 08:40, schrieb Maarten Lankhorst:
Quoted 28 lines
op 22-07-14 17:59, Christian König schreef:
Quoted 27 lines
Am 22.07.2014 17:42, schrieb Daniel Vetter:
Quoted 18 lines
Quoted 6 lines · Christian König
Drivers exporting fences need to provide a
fence->signaledand afence->wait
function, everything else likefence->enable_signalingor callingfence_signaled()from the driver is optional.Quoted 8 lines
Drivers wanting to use exported fences don't call
fence->signaledorfence->waitin atomic or interrupt context, and not with holding any global
locking primitives (likemmap_semetc...). Holding locking primitives local
to the driver is ok, as long as they don't conflict with anything possible
used by their own fence implementation.Quoted 3 lines
Well that's almost what we have right now with the exception that drivers are allowed (actually must for correctness when updating fences) the
ww_mutexesfor dma-bufs (or other buffer objects).In this case sorry for so much noise. I really haven't looked in so much detail into anything but Maarten's Radeon patches.
Quoted 7 lines
Quoted 2 lines
But how does that then work right now? My impression was that it's mandatory for drivers to call
fence_signaled()?It's only mandatory to call
fence_signal()if the .enable_signaling callback has been called, else you can get away with never calling signaling a fence at all before dropping the last refcount to it.
This allows you to keep interrupts disabled when you don't need them.
Quoted 5 lines
Can we somehow avoid the need to call
fence_signal()at all? The interrupts at least on radeon are way to unreliable for such a thing. Canenable_signallingfail? What's the reason forfence_signaled()in the first place?
the device you are sharing with may not be able to do hw<->hw signalling.. think about buffer sharing w/ camera, for example.
You probably want your ->enable_signalling() to enable whatever workaround periodic-polling you need to do to catch missed irq's (and then call fence->signal() once you detect the fence has passed.
fwiw, I haven't had a chance to read this whole thread yet, but I expect that a lot of the SoC devices, especially ones with separate kms-only display and gpu drivers, will want callback from gpu's irq to bang a few display controller registers. I agree in general callbacks from atomic ctx is probably something you want to avoid, but in this particular case I think it is worth the extra complexity. Nothing is stopping a driver from using a callback that just chucks something on a workqueue, whereas the inverse is not possible.
BR,
-R
Quoted 59 lines
Quoted 14 lines
Quoted 5 lines
Quoted 4 lines
Agreed that any shared locks are out of the way (especially stuff like
dev->struct_mutexor other non-strictly driver-private stuff, i915 is really bad here still).Quoted 8 lines
Yeah that's also an point I've wanted to note on Maartens patch. Radeon grabs the read side of it's exclusive semaphore while waiting for fences (because it assumes that the fence it waits for is a Radeon fence).
Assuming that we need to wait in both directions with Prime (e.g. Intel driver needs to wait for Radeon to finish rendering and Radeon needs to wait for Intel to finish displaying), this might become a perfect example of locking inversion.
Quoted 4 lines
In the preliminary patches where I can sync radeon with other GPU's I've been very careful in all the places that call into fences, to make sure that radeon wouldn't try to handle lockups for a different (possibly also radeon) card.
That's actually not such a good idea.
In case of a lockup we need to handle the lockup cause otherwise it could happen that radeon waits for the lockup to be resolved and the lockup handling needs to wait for a fence that's never signaled because of the lockup.
Christian.
Quoted 29 lines
This is also why
fence_is_signaledshould never block, and why it trylocks theexclusive_lock. :-) I think lockdep would complain if I grabbedexclusive_lockwhile blocking inis_signaled.Quoted 9 lines
Quoted 3 lines
So from the core fence framework I think we already have exactly this, and we only need to adjust the radeon implementation a bit to make it less risky and invasive to the radeon driver logic.
Agree. Well the biggest problem I see is that exclusive semaphore I need to take when anything calls into the driver. For the fence code I need to move that down into the
fence->signaledhandler, cause that now can be called from outside the driver.Quoted 5 lines
Maarten solved this by telling the driver in the lockup handler (where we grab the write side of the exclusive lock) that all interrupts are already enabled, so that
fence->signaledhopefully wouldn't mess with the hardware at all. While this probably works, it just leaves me with a feeling that we are doing something wrong here.There is unfortunately no global mechanism to say 'this card is locked up, please don't call into any of my fences', and I don't associate fences with devices, and radeon doesn't keep a global list of fences.
If all of that existed, it would complicate the interface and its callers a lot, while I like to keep things simple.
So I did the best I could, and simply prevented the fence calls from fiddling with the hardware. Fortunately gpu lockup is not a common operation. :-)
Quoted 8 lines
Quoted 3 lines
~Maarten
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 09/17] drm/radeon: use common fence implementation for fences
In reply to Christian Königop 22-07-14 14:19, Christian König schreef:
Quoted 37 lines
Am 22.07.2014 13:57, schrieb Daniel Vetter:
Quoted 30 lines · Daniel Vetter
Quoted 20 lines · Christian König
Quoted 12 lines
Am 22.07.2014 06:05, schrieb Dave Airlie:
Quoted 11 lines · Maarten Lankhorst
Quoted 7 lines
Signed-off-by Maarten Lankhorst <[email protected]>--- drivers/gpu/drm/radeon/radeon.h | 15 +- drivers/gpu/drm/radeon/radeon_device.c | 60 ++++++++- drivers/gpu/drm/radeon/radeon_fence.c | 223 ++++++++++++++++++++++++++------ 3 files changed, 248 insertions(+), 50 deletions(-)From what I can see this is still suffering from the problem that we
need to find a proper solution to,Quoted 7 lines
Quoted 5 lines
My summary of the issues after talking to Jerome and Ben and re-reading things is:
We really need to work out a better interface into the drivers to be able to avoid random atomic entrypoints,
Which is exactly what I criticized from the very first beginning. Good to know that I'm not the only one thinking that this isn't such a good idea.
Quoted 9 lines
I guess I've lost context a bit, but which atomic entry point are we talking about? Afaics the only one that's mandatory is the is
fence->signaledcallback to check whether a fence really has been signalled. It's used internally by the fence code to avoid spurious wakeups. Afaik that should be doable already on any hardware. If that's not the case then we can always track the signalled state in software and double-check in a worker thread before updating the sw state. And wrap this all up into a special fence class if there's more than one driver needing this.Quoted 5 lines
One thing I've forgotten: The i915 scheduler that's floating around runs its bottom half from irq context. So I really want to be able to check fence state from irq context and I also want to make it possible (possible! not mandatory) to register callbacks which are run from any context asap after the fence is signalled.
Quoted 3 lines
NAK, that's just the bad design I've talked about. Checking fence state inside the same driver from interrupt context is OK, because it's the drivers interrupt that we are talking about here.
Checking fence status from another drivers interrupt context is what really concerns me here, cause your driver doesn't have the slightest idea if the called driver is really capable of checking the fence right now.
I think there is a usecase for having atomic context allowed with fence_is_signaled, but I don't think there is one for interrupt context, so it's good with me if fence_is_signaled cannot be called in interrupt context, or with irqs disabled.
fence_enable_sw_signaling disables interrupts because it holds fence->lock, so in theory it could be called from any context including interrupts. But no sane driver author does that, or at least I hope not..
Would a sanity check like the one below be enough to allay your fears? 8<-------
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; }/**
8<--------
Quoted 11 lines
Quoted 5 lines
If the radeon hw/driver doesn't want to cope with that complexity we can fully insolate it with the sw tracked fence state if you don't like Maarten's radeon implementation. But forcing everyone to forgoe this just because you don't like it and don't want to use it in radeon doesn't sound right.
While it's clearly a hack Maarten's solution for radeon would indeed work, but that's not really the point here.
It's just that I think leaking interrupt context from one driver into another driver is just a really really bad idea from a design point of view.
And calling into a driver while in atomic context to check for a fence being signaled doesn't sounds like a good idea either, cause that limits way to much what the called driver can do for checking the status of a fence.
No, you really shouldn't be doing much in the check anyway, it's meant to be a lightweight check. If you're not ready yet because of a lockup simply return not signaled yet.
~Maarten
Christian König
maintainerRe: [PATCH 09/17] drm/radeon: use common fence implementation for fences
Quoted 1 line
No, you really shouldn't be doing much in the check anyway, it's meant to be a lightweight check. If you're not ready yet because of a lockup simply return not signaled yet.
It's not only the lockup case from radeon I have in mind here. For userspace queues it might be necessary to call copy_from_user to figure out if a fence is signaled or not.
Returning false all the time is probably not a good idea either.
Christian.
Am 22.07.2014 16:05, schrieb Maarten Lankhorst:
Quoted 109 lines
op 22-07-14 14:19, Christian König schreef:
Quoted 31 lines
Am 22.07.2014 13:57, schrieb Daniel Vetter:
Quoted 30 lines · Daniel Vetter
Quoted 29 lines · Christian König
Quoted 12 lines
Am 22.07.2014 06:05, schrieb Dave Airlie:
Quoted 11 lines · Maarten Lankhorst
Quoted 7 lines
Signed-off-by Maarten Lankhorst <[email protected]>--- drivers/gpu/drm/radeon/radeon.h | 15 +- drivers/gpu/drm/radeon/radeon_device.c | 60 ++++++++- drivers/gpu/drm/radeon/radeon_fence.c | 223 ++++++++++++++++++++++++++------ 3 files changed, 248 insertions(+), 50 deletions(-)From what I can see this is still suffering from the problem that we
need to find a proper solution to,Quoted 7 lines
Quoted 5 lines
My summary of the issues after talking to Jerome and Ben and re-reading things is:
We really need to work out a better interface into the drivers to be able to avoid random atomic entrypoints,
Which is exactly what I criticized from the very first beginning. Good to know that I'm not the only one thinking that this isn't such a good idea.
I guess I've lost context a bit, but which atomic entry point are we talking about? Afaics the only one that's mandatory is the is
fence->signaledcallback to check whether a fence really has been signalled. It's used internally by the fence code to avoid spurious wakeups. Afaik that should be doable already on any hardware. If that's not the case then we can always track the signalled state in software and double-check in a worker thread before updating the sw state. And wrap this all up into a special fence class if there's more than one driver needing this.Quoted 8 lines
Quoted 5 lines
One thing I've forgotten: The i915 scheduler that's floating around runs its bottom half from irq context. So I really want to be able to check fence state from irq context and I also want to make it possible (possible! not mandatory) to register callbacks which are run from any context asap after the fence is signalled.
NAK, that's just the bad design I've talked about. Checking fence state inside the same driver from interrupt context is OK, because it's the drivers interrupt that we are talking about here.
Checking fence status from another drivers interrupt context is what really concerns me here, cause your driver doesn't have the slightest idea if the called driver is really capable of checking the fence right now.
I think there is a usecase for having atomic context allowed with
fence_is_signaled, but I don't think there is one for interrupt context, so it's good with me iffence_is_signaledcannot be called in interrupt context, or with irqs disabled.
fence_enable_sw_signalingdisables interrupts because it holdsfence->lock, so in theory it could be called from any context including interrupts. But no sane driver author does that, or at least I hope not..Would a sanity check like the one below be enough to allay your fears? 8<-------
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; }/** 8<--------
Quoted 10 lines
Quoted 5 lines
If the radeon hw/driver doesn't want to cope with that complexity we can fully insolate it with the sw tracked fence state if you don't like Maarten's radeon implementation. But forcing everyone to forgoe this just because you don't like it and don't want to use it in radeon doesn't sound right.
While it's clearly a hack Maarten's solution for radeon would indeed work, but that's not really the point here.
It's just that I think leaking interrupt context from one driver into another driver is just a really really bad idea from a design point of view.
And calling into a driver while in atomic context to check for a fence being signaled doesn't sounds like a good idea either, cause that limits way to much what the called driver can do for checking the status of a fence.
No, you really shouldn't be doing much in the check anyway, it's meant to be a lightweight check. If you're not ready yet because of a lockup simply return not signaled yet.
~Maarten
Re: [PATCH 09/17] drm/radeon: use common fence implementation for fences
op 22-07-14 16:24, Christian König schreef:
Quoted 4 lines
Quoted 1 line
No, you really shouldn't be doing much in the check anyway, it's meant to be a lightweight check. If you're not ready yet because of a lockup simply return not signaled yet.
It's not only the lockup case from radeon I have in mind here. For userspace queues it might be necessary to call
copy_from_userto figure out if a fence is signaled or not.Returning false all the time is probably not a good idea either.
Having userspace implement a fence sounds like an awful idea, why would you want to do that?
A fence could be exported to userspace, but that would only mean it can wait for it to be signaled with an interface like poll..
~Maarten
Christian König
maintainerRe: [PATCH 09/17] drm/radeon: use common fence implementation for fences
Am 22.07.2014 16:27, schrieb Maarten Lankhorst:
Quoted 6 lines
op 22-07-14 16:24, Christian König schreef:
Quoted 4 lines
Quoted 1 line
No, you really shouldn't be doing much in the check anyway, it's meant to be a lightweight check. If you're not ready yet because of a lockup simply return not signaled yet.
It's not only the lockup case from radeon I have in mind here. For userspace queues it might be necessary to call
copy_from_userto figure out if a fence is signaled or not.Returning false all the time is probably not a good idea either.
Having userspace implement a fence sounds like an awful idea, why would you want to do that?
Marketing moves in mysterious ways. Don't ask me, but that the direction it currently moves with userspace queues and IOMMU etc...
Quoted 1 line
A fence could be exported to userspace, but that would only mean it can wait for it to be signaled with an interface like poll..
Yeah agree totally, but the point for the fence interface is that I can't predict what's necessary to check if a fence is signaled or not on future hardware.
For the currently available radeon hardware I can say that reading a value from a kernel page is pretty much all you need. But for older hardware that was reading from a register which might become very tricky if the hardware is power off or currently inside a reset cycle.
Because off this I would avoid any such interface if it's not absolutely required by some use case, and currently I don't see this requirement because the functionality you want to archive could be implemented without this.
Christian.
Quoted 3 lines
~Maarten
Re: [PATCH 09/17] drm/radeon: use common fence implementation for fences
op 22-07-14 16:39, Christian König schreef:
Quoted 10 lines
Am 22.07.2014 16:27, schrieb Maarten Lankhorst:
Quoted 6 lines
op 22-07-14 16:24, Christian König schreef:
Quoted 4 lines
Quoted 1 line
No, you really shouldn't be doing much in the check anyway, it's meant to be a lightweight check. If you're not ready yet because of a lockup simply return not signaled yet.
It's not only the lockup case from radeon I have in mind here. For userspace queues it might be necessary to call
copy_from_userto figure out if a fence is signaled or not.Returning false all the time is probably not a good idea either.
Having userspace implement a fence sounds like an awful idea, why would you want to do that?
Marketing moves in mysterious ways. Don't ask me, but that the direction it currently moves with userspace queues and IOMMU etc...
Quoted 7 lines
Quoted 1 line
A fence could be exported to userspace, but that would only mean it can wait for it to be signaled with an interface like poll..
Yeah agree totally, but the point for the fence interface is that I can't predict what's necessary to check if a fence is signaled or not on future hardware.
For the currently available radeon hardware I can say that reading a value from a kernel page is pretty much all you need. But for older hardware that was reading from a register which might become very tricky if the hardware is power off or currently inside a reset cycle.
Because off this I would avoid any such interface if it's not absolutely required by some use case, and currently I don't see this requirement because the functionality you want to archive could be implemented without this.
Oh? I've already done that in radeon_fence, there is no way enable_signaling will fiddle with hardware registers during a reset cycle. I've also made sure that __radeon_fence_is_signaled grabs exclusive_lock in read mode before touching any hw state.
Older hardware also doesn't implement optimus, so I think power off is not much of a worry for them, if you could point me at the checking done for that I could make sure that this is the case.
~Maarten
Re: [PATCH 09/17] drm/radeon: use common fence implementation for fences
Am 22.07.2014 16:47, schrieb Maarten Lankhorst:
Quoted 13 lines
op 22-07-14 16:39, Christian König schreef:
Quoted 12 lines
Am 22.07.2014 16:27, schrieb Maarten Lankhorst:
Quoted 6 lines
op 22-07-14 16:24, Christian König schreef:
Quoted 4 lines
Quoted 1 line
No, you really shouldn't be doing much in the check anyway, it's meant to be a lightweight check. If you're not ready yet because of a lockup simply return not signaled yet.
It's not only the lockup case from radeon I have in mind here. For userspace queues it might be necessary to call
copy_from_userto figure out if a fence is signaled or not.Returning false all the time is probably not a good idea either.
Having userspace implement a fence sounds like an awful idea, why would you want to do that?
Marketing moves in mysterious ways. Don't ask me, but that the direction it currently moves with userspace queues and IOMMU etc...
Quoted 1 line
A fence could be exported to userspace, but that would only mean it can wait for it to be signaled with an interface like poll..
Yeah agree totally, but the point for the fence interface is that I can't predict what's necessary to check if a fence is signaled or not on future hardware.
Quoted 7 lines
Quoted 3 lines
For the currently available radeon hardware I can say that reading a value from a kernel page is pretty much all you need. But for older hardware that was reading from a register which might become very tricky if the hardware is power off or currently inside a reset cycle.
Because off this I would avoid any such interface if it's not absolutely required by some use case, and currently I don't see this requirement because the functionality you want to archive could be implemented without this.
Oh? I've already done that in
radeon_fence, there is no wayenable_signalingwill fiddle with hardware registers during a reset cycle. I've also made sure that__radeon_fence_is_signaledgrabsexclusive_lockin read mode before touching any hw state.Older hardware also doesn't implement optimus, so I think power off is not much of a worry for them, if you could point me at the checking done for that I could make sure that this is the case.
I'm not talking about any specific radeon hardware or use case here. As far as I can see you indeed solved all driver problems with the current interface design.
The question I'm raising is if the current interface design needs as complex as it is. And my answer to this is a clear *no*, so why do you want to stick with this design? I still haven't understood that.
If it's just to support a further feature of direct synchronization in interrupt context between different drivers then I must clearly say that this is a NAK, cause you add complexity to the kernel that isn't necessary.
Christian.
Quoted 3 lines
~Maarten
Re: [PATCH 09/17] drm/radeon: use common fence implementation for fences
In reply to Christian KönigQuoted 12 lines · Christian König
Am 22.07.2014 16:27, schrieb Maarten Lankhorst:
Quoted 10 lines
op 22-07-14 16:24, Christian König schreef:
Quoted 9 lines
Quoted 4 lines
No, you really shouldn't be doing much in the check anyway, it's meant to be a lightweight check. If you're not ready yet because of a lockup simply return not signaled yet.
It's not only the lockup case from radeon I have in mind here. For userspace queues it might be necessary to call
copy_from_userto figure out if a fence is signaled or not.
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Returning false all the time is probably not a good idea either.
Having userspace implement a fence sounds like an awful idea, why would you want to do that?
Marketing moves in mysterious ways. Don't ask me, but that the direction it currently moves with userspace queues and IOMMU etc...
Fence-based syncing between userspace queues submitted stuff through doorbells and anything submitted by the general simply wont work. Which is why I think the doorbell is a stupid interface since I just don't see cameras and v4l devices implementing all that complexity to get a pure userspace side sync solution.
But that's a different problem really, and I guess marketing will eventually figure this one out, too.
-Daniel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 09/17] drm/radeon: use common fence implementation for fences
Quoted 20 lines · Daniel Vetter
Quoted 18 lines · Christian König
Am 22.07.2014 16:27, schrieb Maarten Lankhorst:
Quoted 14 lines
op 22-07-14 16:24, Christian König schreef:
Quoted 10 lines
Quoted 4 lines
No, you really shouldn't be doing much in the check anyway, it's meant to be a lightweight check. If you're not ready yet because of a lockup simply return not signaled yet.
It's not only the lockup case from radeon I have in mind here. For userspace queues it might be necessary to call
copy_from_userto figure out if a fence is signaled or not.Returning false all the time is probably not a good idea either.
Having userspace implement a fence sounds like an awful idea, why would you want to do that?
Quoted 9 lines
Quoted 2 lines
Marketing moves in mysterious ways. Don't ask me, but that the direction it currently moves with userspace queues and IOMMU etc...
Fence-based syncing between userspace queues submitted stuff through doorbells and anything submitted by the general simply wont work. Which is why I think the doorbell is a stupid interface since I just don't see cameras and v4l devices implementing all that complexity to get a pure userspace side sync solution.
Like it or not this is what a lot of application writers want (look at mantle and metal and similar new APIs or android synpts). Having queues and fences in userspace allows the application to structure things to best fit their own task graphs. The app can decide how to deal with dependencies and synchronization explicitly instead of blocking the queues in the kernel for everyone. Anyway, this is getting off topic.
Alex
_______________________________________________
Nouveau mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau
Re: [PATCH 09/17] drm/radeon: use common fence implementation for fences
Quoted 7 lines · Alex Deucher
Quoted 6 lines
Fence-based syncing between userspace queues submitted stuff through doorbells and anything submitted by the general simply wont work. Which is why I think the doorbell is a stupid interface since I just don't see cameras and v4l devices implementing all that complexity to get a pure userspace side sync solution.
Quoted 7 lines
Like it or not this is what a lot of application writers want (look at mantle and metal and similar new APIs or android synpts). Having queues and fences in userspace allows the application to structure things to best fit their own task graphs. The app can decide how to deal with dependencies and synchronization explicitly instead of blocking the queues in the kernel for everyone. Anyway, this is getting off topic.
Well there's explicit fences as used in opencl and android syncpts. My plan is actually to support that in i915 using Maarten's struct fence stuff (and there's just a very trivial patch for the android stuff in merging needed to get there). What doesn't work is fences created behind the kernel's back purely in userspace by giving shared memory locations special meaning. Those get the kernel completely out of the picture (as opposed to android syncpts, which just make sync explicit).
I guess long-term we might need something like gpu futexes to make that pure userspace syncing integrate a bit better, but imo that's (at least for now) out of scope. For fences here I have the goal of one internally representation used by both implicit syncing (dma-buf on classic linux, e.g. prime) and explicit fencing on android or opencl or something like that.
We don't have the code yet ready, but that's the direction i915 will move towards for the near future. Jesse is working on some patches already.
-Daniel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch
Re: [PATCH 09/17] drm/radeon: use common fence implementation for fences
Quoted 25 lines · On Tue, 22 Jul 2014 17:48:18 +0200 Daniel Vetter <[email protected]> wrote:
Quoted 7 lines · Alex Deucher
Quoted 6 lines
Fence-based syncing between userspace queues submitted stuff through doorbells and anything submitted by the general simply wont work. Which is why I think the doorbell is a stupid interface since I just don't see cameras and v4l devices implementing all that complexity to get a pure userspace side sync solution.
Quoted 7 lines
Like it or not this is what a lot of application writers want (look at mantle and metal and similar new APIs or android synpts). Having queues and fences in userspace allows the application to structure things to best fit their own task graphs. The app can decide how to deal with dependencies and synchronization explicitly instead of blocking the queues in the kernel for everyone. Anyway, this is getting off topic.
Well there's explicit fences as used in opencl and android syncpts. My plan is actually to support that in i915 using Maarten's struct fence stuff (and there's just a very trivial patch for the android stuff in merging needed to get there). What doesn't work is fences created behind the kernel's back purely in userspace by giving shared memory locations special meaning. Those get the kernel completely out of the picture (as opposed to android syncpts, which just make sync explicit).
Quoted 3 lines
I guess long-term we might need something like gpu futexes to make that pure userspace syncing integrate a bit better, but imo that's (at least for now) out of scope. For fences here I have the goal of one
Yeah, with a little kernel help you could have a mostly kernel independent sync mechanism using just shared mem in userspace. The kernel would just need to signal any interested clients when something happened (even if it didn't know what) and let userspace sort out the rest. I think that would be a nice thing to provide at some point, as it could allow for some fine grained CPU/GPU algorithms that use lightweight synchronization with and without busy looping on the CPU side.
But all of that is definitely a lower priority than getting explicit fencing exported to userspace to work right, both for intra-driver sync and inter-driver sync.
Quoted 7 lines
internally representation used by both implicit syncing (dma-buf on classic linux, e.g. prime) and explicit fencing on android or opencl or something like that.
We don't have the code yet ready, but that's the direction i915 will move towards for the near future. Jesse is working on some patches already.
Yeah I'd like to get some feedback from Maarten on my bits so I can get them ready for upstream. I still need to add documentation and tests, but I'd like to make sure the interfaces and internals get acked first.
Thanks,
Signature · 1 line
Jesse Barnes, Intel Open Source Technology Center
Re: [Nouveau] [PATCH 09/17] drm/radeon: use common fence implementation for fences
Quoted 7 lines · Jesse Barnes
Quoted 3 lines
We don't have the code yet ready, but that's the direction i915 will move towards for the near future. Jesse is working on some patches already.
Yeah I'd like to get some feedback from Maarten on my bits so I can get them ready for upstream. I still need to add documentation and tests, but I'd like to make sure the interfaces and internals get acked first.
Review works better if you supply a pointer to the patches ;-) I asked Maarten whether he looked at it and he said he didn't know where ... -Daniel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch
Re: [Nouveau] [PATCH 09/17] drm/radeon: use common fence implementation for fences
Quoted 11 lines · On Wed, 23 Jul 2014 11:47:15 +0200 Daniel Vetter <[email protected]> wrote:
Quoted 7 lines · Jesse Barnes
Quoted 3 lines
We don't have the code yet ready, but that's the direction i915 will move towards for the near future. Jesse is working on some patches already.
Yeah I'd like to get some feedback from Maarten on my bits so I can get them ready for upstream. I still need to add documentation and tests, but I'd like to make sure the interfaces and internals get acked first.
Review works better if you supply a pointer to the patches ;-) I asked Maarten whether he looked at it and he said he didn't know where ...
Oh I provided it in IRC earlier, figured Maarten was just busy. :)
Tree is android-dma-buf-i915-fences in my fdo linux repo.
Signature · 1 line
Jesse Barnes, Intel Open Source Technology Center
Re: [PATCH 09/17] drm/radeon: use common fence implementation for fences
In reply to Dave AirlieHey,
op 22-07-14 06:05, Dave Airlie schreef:
Quoted 14 lines · Maarten Lankhorst
Quoted 7 lines
Signed-off-by Maarten Lankhorst <[email protected]>--- drivers/gpu/drm/radeon/radeon.h | 15 +- drivers/gpu/drm/radeon/radeon_device.c | 60 ++++++++- drivers/gpu/drm/radeon/radeon_fence.c | 223 ++++++++++++++++++++++++++------ 3 files changed, 248 insertions(+), 50 deletions(-)From what I can see this is still suffering from the problem that we need to find a proper solution to,
My summary of the issues after talking to Jerome and Ben and re-reading things is:
Quoted 8 lines
We really need to work out a better interface into the drivers to be able to avoid random atomic entrypoints,
I'm sure you have some ideas and I think you really need to investigate them to move this thing forward,
even it if means some issues with android sync pts.but none of the two major drivers seem to want the interface as-is so something needs to give
wait_queue_t (which radeon uses for fence_queue) uses atomic entrypoints too, the most common one being autoremove_wake_function, which wakes up the thread it was initialized from, and removes itself from the wait_queue_t list, in atomic fashion. It's used by __wait_event_interruptible_locked, if something internally wants to add some arbitrary callback it could already happen...
Quoted 2 lines
My major question is why we need an atomic callback here at all, what scenario does it cover?
A atomic callback could do something like schedule_work(&work) (like nouveau_fence_work already does right now!!!!).
I've also added some more experimental things in my unsubmitted branch, in a codepath that's taken when synchronization is used with multiple GPU's:
Nouveau: I write the new seqno to the GART fence, which I added a GPU wait for using SEMAPHORE_TRIGGER.ACQUIRE_GE.
radeon: I write to a memory location to unblock the execution ring, this will probably be replaced by a call to the GPU scheduler.
i915: write to the EXCC (condition code) register to unblock the ring operation when it's waiting for the condition code.
But I want to emphasize that this is a hack, and driver maintainers will probably NACK it, I think I will only submit the one for nouveau, which is sane there because it schedules contexts in hardware. Even so that part is not final and will probably go through a few iterations before submission.
Quoted 3 lines
Surely we can use a workqueue based callback to ask a driver to check its signalling, is it really
that urgent?
Nothing prevents a driver from using that approach, even with those changes.
Driver maintainers can still NACK the use of fence_add_callback if they want to, or choose not to export fences to outside the driver. Because fences are still not exporting, nothing will change for them compared to the current situation.
~Maarten
PATCH 10/17 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 11/17 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
@@ -332,7 +332,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;
@@ -2308,13 +2306,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,
@@ -2387,8 +2381,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 ); } }
@@ -2438,7 +2431,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 12/17 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
@@ -2360,7 +2360,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 13/17 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 | 25 +++- 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, 208 insertions(+), 393 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 +16 -9
@@ -518,6 +518,7 @@ static int radeon_crtc_page_flip(struct drm_crtc *crtc,struct radeon_framebuffer *new_radeon_fb;struct drm_gem_object *obj;struct radeon_flip_work *work; +struct fence *fence;unsigned long flags; work =kzalloc (sizeof *work,GFP_KERNEL );
@@ -544,15 +545,21 @@ static int radeon_crtc_page_flip(struct drm_crtc *crtc, obj = new_radeon_fb->obj; work->new_rbo =gem_to_radeon_bo (obj); -if (work->new_rbo->tbo.sync_obj) { -int ret =ttm_bo_reserve (&work->new_rbo->tbo, true, false, false,NULL ); -if (ret) { -drm_gem_object_unreference_unlocked (&work->old_rbo->gem_base); -kfree (work); -return ret; - } - work->fence =radeon_fence_ref (work->new_rbo->tbo.sync_obj); -ttm_bo_unreserve (&work->new_rbo->tbo); +/* XXX: Hack, bo should really be pinned at this point */ +do { +rcu_read_lock (); + fence =rcu_dereference (work->new_rbo->tbo.resv->fence_excl); +if (fence) + work->fence = (struct radeon_fence *)fence_get_rcu (fence); +rcu_read_unlock (); + }while (fence && !work->fence); + +if (fence && !fence->ops->signaled) { +/* +* make sure if this fence doesn't belong to this +* device that it will still signal completion +*/ +fence_enable_sw_signaling (fence); }/* We borrow the event spin lock for protecting flip_work */
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
@@ -388,7 +388,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 ;
@@ -644,7 +644,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) {
@@ -772,8 +777,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
@@ -309,11 +309,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 {
@@ -415,23 +410,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,
@@ -1031,7 +1009,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.
@@ -1045,7 +1023,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 14/17 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 15/17 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);
PATCH 16/17 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 17/17 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,0 );
Hi Maarten
Will this stop the stuttering I've been seeing with DRI3 and PRIME? Or will other patches / plumbing be required
Cheers
Mike
Quoted 81 lines · Maarten Lankhorst
This series applies on top of the driver-core-next branch of
git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core.gitBefore converting ttm to the new fence interface I had to fix some drivers to require a reservation before poking with
fence_obj. After flipping the switch RCU becomes available instead, and the extra reservations can be dropped again. :-)I've done at least basic testing on all the drivers I've converted at some point, but more testing is definitely welcomed!
---
Maarten Lankhorst (17):
drm/ttm: add interruptible parameter tottm_eu_reserve_buffersdrm/ttm: kill off some members tottm_validate_bufferdrm/nouveau: add reservation tonouveau_gem_ioctl_cpu_prepdrm/nouveau: require reservations fornouveau_fence_syncandnouveau_bo_fence
drm/ttm: callttm_bo_waitwhile inside a reservation drm/ttm: killfence_lock
drm/nouveau: rework to new fence interface drm/radeon: add timeout argument toradeon_fence_wait_seqdrm/radeon: use common fence implementation for fences drm/qxl: rework to new fence interface
drm/vmwgfx: get rid of different types offence_flagsentirely drm/vmwgfx: rework to new fence interface
drm/ttm: flip the switch, and convert todma_fencedrm/nouveau: use rcu innouveau_gem_ioctl_cpu_prepdrm/radeon: use rcu waits in some ioctls drm/vmwgfx: use rcu invmw_user_dmabuf_synccpu_grabdrm/ttm: use rcu in core ttmdrivers/gpu/drm/nouveau/core/core/event.c | 4 drivers/gpu/drm/nouveau/nouveau_bo.c | 59 +--- drivers/gpu/drm/nouveau/nouveau_display.c | 25 +- drivers/gpu/drm/nouveau/nouveau_fence.c | 431 +++++++++++++++++++---------- drivers/gpu/drm/nouveau/nouveau_fence.h | 22 + drivers/gpu/drm/nouveau/nouveau_gem.c | 55 +--- 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 - drivers/gpu/drm/qxl/Makefile | 2 drivers/gpu/drm/qxl/qxl_cmd.c | 7 drivers/gpu/drm/qxl/qxl_debugfs.c | 16 + drivers/gpu/drm/qxl/qxl_drv.h | 20 - drivers/gpu/drm/qxl/qxl_fence.c | 91 ------ drivers/gpu/drm/qxl/qxl_kms.c | 1 drivers/gpu/drm/qxl/qxl_object.c | 2 drivers/gpu/drm/qxl/qxl_object.h | 6 drivers/gpu/drm/qxl/qxl_release.c | 172 ++++++++++-- drivers/gpu/drm/qxl/qxl_ttm.c | 93 ------ drivers/gpu/drm/radeon/radeon.h | 15 - drivers/gpu/drm/radeon/radeon_cs.c | 10 + drivers/gpu/drm/radeon/radeon_device.c | 60 ++++ drivers/gpu/drm/radeon/radeon_display.c | 21 + drivers/gpu/drm/radeon/radeon_fence.c | 283 +++++++++++++++---- drivers/gpu/drm/radeon/radeon_gem.c | 19 + drivers/gpu/drm/radeon/radeon_object.c | 8 - drivers/gpu/drm/radeon/radeon_ttm.c | 34 -- drivers/gpu/drm/radeon/radeon_uvd.c | 10 - drivers/gpu/drm/radeon/radeon_vm.c | 16 + drivers/gpu/drm/ttm/ttm_bo.c | 187 ++++++------- drivers/gpu/drm/ttm/ttm_bo_util.c | 28 -- drivers/gpu/drm/ttm/ttm_bo_vm.c | 3 drivers/gpu/drm/ttm/ttm_execbuf_util.c | 146 +++------- drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c | 47 --- drivers/gpu/drm/vmwgfx/vmwgfx_drv.h | 1 drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c | 24 -- drivers/gpu/drm/vmwgfx/vmwgfx_fence.c | 329 ++++++++++++---------- drivers/gpu/drm/vmwgfx/vmwgfx_fence.h | 35 +- drivers/gpu/drm/vmwgfx/vmwgfx_resource.c | 43 +-- include/drm/ttm/ttm_bo_api.h | 7 include/drm/ttm/ttm_bo_driver.h | 29 -- include/drm/ttm/ttm_execbuf_util.h | 22 + 44 files changed, 1256 insertions(+), 1150 deletions(-) delete mode 100644 drivers/gpu/drm/qxl/qxl_fence.c
Quoted 7 lines
--
Signature
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
op 09-07-14 15:09, Mike Lothian schreef:
Quoted 5 lines
Hi Maarten
Will this stop the stuttering I've been seeing with DRI3 and PRIME? Or will other patches / plumbing be required
No, that testing was with the whole series including the parts where you synchronized intel with radeon (iirc). Although it might if lucky, I noticed that I missed a int to long conversion, which resulted in a success being reported as error, disabling graphics acceleration entirely.
The series here simply convert the drivers to a common fence infrastructure, but shouldn't cause any regressions or any major behavioral changes. A separate series is needed to make intel and radeon synchronized, and for that series the support on the intel side is a hack. It should be possible to get the the radeon/nouveau changes upstreamed, but this conversion is required for that.
~Maarten
Quoted 10 lines · Maarten Lankhorst
This series applies on top of the driver-core-next branch of
git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core.gitBefore converting ttm to the new fence interface I had to fix some drivers to require a reservation before poking with
fence_obj. After flipping the switch RCU becomes available instead, and the extra reservations can be dropped again. :-)I've done at least basic testing on all the drivers I've converted at some point, but more testing is definitely welcomed!
I'm currently on vacation for the next couple of weeks, so I can't test or review but otherwise
Quoted 68 lines
---
Maarten Lankhorst (17):
drm/ttm: add interruptible parameter tottm_eu_reserve_buffersdrm/ttm: kill off some members tottm_validate_bufferdrm/nouveau: add reservation tonouveau_gem_ioctl_cpu_prepdrm/nouveau: require reservations fornouveau_fence_syncandnouveau_bo_fencedrm/ttm: callttm_bo_waitwhile inside a reservation
drm/ttm: killfence_lock
drm/nouveau: rework to new fence interface
drm/radeon: add timeout argument toradeon_fence_wait_seqdrm/radeon: use common fence implementation for fences
drm/qxl: rework to new fence interface
drm/vmwgfx: get rid of different types offence_flagsentirely drm/vmwgfx: rework to new fence interface
drm/ttm: flip the switch, and convert todma_fence
drm/nouveau: use rcu innouveau_gem_ioctl_cpu_prep
drm/radeon: use rcu waits in some ioctls
drm/vmwgfx: use rcu invmw_user_dmabuf_synccpu_grab
drm/ttm: use rcu in core ttmdrivers/gpu/drm/nouveau/core/core/event.c | 4 drivers/gpu/drm/nouveau/nouveau_bo.c | 59 +--- drivers/gpu/drm/nouveau/nouveau_display.c | 25 +- drivers/gpu/drm/nouveau/nouveau_fence.c | 431 +++++++++++++++++++---------- drivers/gpu/drm/nouveau/nouveau_fence.h | 22 + drivers/gpu/drm/nouveau/nouveau_gem.c | 55 +--- 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 - drivers/gpu/drm/qxl/Makefile | 2 drivers/gpu/drm/qxl/qxl_cmd.c | 7 drivers/gpu/drm/qxl/qxl_debugfs.c | 16 + drivers/gpu/drm/qxl/qxl_drv.h | 20 - drivers/gpu/drm/qxl/qxl_fence.c | 91 ------ drivers/gpu/drm/qxl/qxl_kms.c | 1 drivers/gpu/drm/qxl/qxl_object.c | 2 drivers/gpu/drm/qxl/qxl_object.h | 6 drivers/gpu/drm/qxl/qxl_release.c | 172 ++++++++++-- drivers/gpu/drm/qxl/qxl_ttm.c | 93 ------ drivers/gpu/drm/radeon/radeon.h | 15 - drivers/gpu/drm/radeon/radeon_cs.c | 10 + drivers/gpu/drm/radeon/radeon_device.c | 60 ++++ drivers/gpu/drm/radeon/radeon_display.c | 21 + drivers/gpu/drm/radeon/radeon_fence.c | 283 +++++++++++++++---- drivers/gpu/drm/radeon/radeon_gem.c | 19 + drivers/gpu/drm/radeon/radeon_object.c | 8 - drivers/gpu/drm/radeon/radeon_ttm.c | 34 -- drivers/gpu/drm/radeon/radeon_uvd.c | 10 - drivers/gpu/drm/radeon/radeon_vm.c | 16 + drivers/gpu/drm/ttm/ttm_bo.c | 187 ++++++------- drivers/gpu/drm/ttm/ttm_bo_util.c | 28 -- drivers/gpu/drm/ttm/ttm_bo_vm.c | 3 drivers/gpu/drm/ttm/ttm_execbuf_util.c | 146 +++------- drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c | 47 --- drivers/gpu/drm/vmwgfx/vmwgfx_drv.h | 1 drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c | 24 -- drivers/gpu/drm/vmwgfx/vmwgfx_fence.c | 329 ++++++++++++---------- drivers/gpu/drm/vmwgfx/vmwgfx_fence.h | 35 +- drivers/gpu/drm/vmwgfx/vmwgfx_resource.c | 43 +-- include/drm/ttm/ttm_bo_api.h | 7 include/drm/ttm/ttm_bo_driver.h | 29 -- include/drm/ttm/ttm_execbuf_util.h | 22 + 44 files changed, 1256 insertions(+), 1150 deletions(-)delete mode 100644
drivers/gpu/drm/qxl/qxl_fence.c