Commit 809e9447 authored by Maarten Lankhorst's avatar Maarten Lankhorst
Browse files

drm/nouveau: use shared fences for readable objects



nouveau keeps track in userspace whether a buffer is being
written to or being read, but it doesn't use that information.

Change this to allow multiple readers on the same bo.

Signed-off-by: default avatarMaarten Lankhorst <maarten.lankhorst@canonical.com>
Acked-by: default avatarBen Skeggs <bskeggs@redhat.com>
parent 9242829a
Loading
Loading
Loading
Loading
+7 −4
Original line number Diff line number Diff line
@@ -94,7 +94,7 @@ nv10_bo_put_tile_region(struct drm_device *dev, struct nouveau_drm_tile *tile,

	if (tile) {
		spin_lock(&drm->tile.lock);
		tile->fence = nouveau_fence_ref((struct nouveau_fence *)fence);
		tile->fence = (struct nouveau_fence *)fence_get(fence);
		tile->used = false;
		spin_unlock(&drm->tile.lock);
	}
@@ -970,7 +970,7 @@ nouveau_bo_move_m2mf(struct ttm_buffer_object *bo, int evict, bool intr,
	}

	mutex_lock_nested(&cli->mutex, SINGLE_DEPTH_NESTING);
	ret = nouveau_fence_sync(nouveau_bo(bo), chan);
	ret = nouveau_fence_sync(nouveau_bo(bo), chan, true);
	if (ret == 0) {
		ret = drm->ttm.move(chan, bo, &bo->mem, new_mem);
		if (ret == 0) {
@@ -1458,11 +1458,14 @@ nouveau_ttm_tt_unpopulate(struct ttm_tt *ttm)
}

void
nouveau_bo_fence(struct nouveau_bo *nvbo, struct nouveau_fence *fence)
nouveau_bo_fence(struct nouveau_bo *nvbo, struct nouveau_fence *fence, bool exclusive)
{
	struct reservation_object *resv = nvbo->bo.resv;

	if (exclusive)
		reservation_object_add_excl_fence(resv, &fence->base);
	else if (fence)
		reservation_object_add_shared_fence(resv, &fence->base);
}

struct ttm_bo_driver nouveau_bo_driver = {
+1 −1
Original line number Diff line number Diff line
@@ -78,7 +78,7 @@ u16 nouveau_bo_rd16(struct nouveau_bo *, unsigned index);
void nouveau_bo_wr16(struct nouveau_bo *, unsigned index, u16 val);
u32  nouveau_bo_rd32(struct nouveau_bo *, unsigned index);
void nouveau_bo_wr32(struct nouveau_bo *, unsigned index, u32 val);
void nouveau_bo_fence(struct nouveau_bo *, struct nouveau_fence *);
void nouveau_bo_fence(struct nouveau_bo *, struct nouveau_fence *, bool exclusive);
int  nouveau_bo_validate(struct nouveau_bo *, bool interruptible,
			 bool no_wait_gpu);

+3 −3
Original line number Diff line number Diff line
@@ -658,7 +658,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, chan);
	ret = nouveau_fence_sync(old_bo, chan, false);
	if (ret)
		goto fail;

@@ -722,7 +722,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, chan);
	ret = nouveau_fence_sync(new_bo, chan, false);
	if (ret) {
		ttm_bo_unreserve(&new_bo->bo);
		goto fail_unpin;
@@ -780,7 +780,7 @@ nouveau_crtc_page_flip(struct drm_crtc *crtc, struct drm_framebuffer *fb,
	/* Update the crtc struct and cleanup */
	crtc->primary->fb = fb;

	nouveau_bo_fence(old_bo, fence);
	nouveau_bo_fence(old_bo, fence, false);
	ttm_bo_unreserve(&old_bo->bo);
	if (old_bo != new_bo)
		nouveau_bo_unpin(old_bo);
+31 −24
Original line number Diff line number Diff line
@@ -342,41 +342,56 @@ nouveau_fence_wait(struct nouveau_fence *fence, bool lazy, bool intr)
}

int
nouveau_fence_sync(struct nouveau_bo *nvbo, struct nouveau_channel *chan)
nouveau_fence_sync(struct nouveau_bo *nvbo, struct nouveau_channel *chan, bool exclusive)
{
	struct nouveau_fence_chan *fctx = chan->fence;
	struct fence *fence = NULL;
	struct fence *fence;
	struct reservation_object *resv = nvbo->bo.resv;
	struct reservation_object_list *fobj;
	struct nouveau_fence *f;
	int ret = 0, i;

	if (!exclusive) {
		ret = reservation_object_reserve_shared(resv);

		if (ret)
			return ret;
	}

	fobj = reservation_object_get_list(resv);
	fence = reservation_object_get_excl(resv);

	if (fence && !fence_is_signaled(fence)) {
		struct nouveau_fence *f = from_fence(fence);
		struct nouveau_channel *prev = f->channel;
	if (fence && (!exclusive || !fobj || !fobj->shared_count)) {
		struct nouveau_channel *prev = NULL;

		if (prev != chan) {
			ret = fctx->sync(f, prev, chan);
			if (unlikely(ret))
				ret = nouveau_fence_wait(f, true, true);
		}
	}
		f = nouveau_local_fence(fence, chan->drm);
		if (f)
			prev = f->channel;

		if (!prev || (prev != chan && (ret = fctx->sync(f, prev, chan))))
			ret = fence_wait(fence, true);

	if (ret)
		return ret;
	}

	fobj = reservation_object_get_list(resv);
	if (!fobj)
	if (!exclusive || !fobj)
		return ret;

	for (i = 0; i < fobj->shared_count && !ret; ++i) {
		struct nouveau_channel *prev = NULL;

		fence = rcu_dereference_protected(fobj->shared[i],
						reservation_object_held(resv));

		/* should always be true, for now */
		if (!nouveau_local_fence(fence, chan->drm))
		f = nouveau_local_fence(fence, chan->drm);
		if (f)
			prev = f->channel;

		if (!prev || (ret = fctx->sync(f, prev, chan)))
			ret = fence_wait(fence, true);

		if (ret)
			break;
	}

	return ret;
@@ -390,14 +405,6 @@ nouveau_fence_unref(struct nouveau_fence **pfence)
	*pfence = NULL;
}

struct nouveau_fence *
nouveau_fence_ref(struct nouveau_fence *fence)
{
	if (fence)
		fence_get(&fence->base);
	return fence;
}

int
nouveau_fence_new(struct nouveau_channel *chan, bool sysmem,
		  struct nouveau_fence **pfence)
+1 −3
Original line number Diff line number Diff line
@@ -20,15 +20,13 @@ struct nouveau_fence {

int  nouveau_fence_new(struct nouveau_channel *, bool sysmem,
		       struct nouveau_fence **);
struct nouveau_fence *
nouveau_fence_ref(struct nouveau_fence *);
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 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 *);
int  nouveau_fence_sync(struct nouveau_bo *, struct nouveau_channel *, bool exclusive);

struct nouveau_fence_chan {
	spinlock_t lock;
Loading