Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0853695c authored by Chris Wilson's avatar Chris Wilson Committed by Daniel Vetter
Browse files

drm: Add reference counting to drm_atomic_state



drm_atomic_state has a complicated single owner model that tracks the
single reference from allocation through to destruction on another
thread - or perhaps on a local error path. We can simplify this tracking
by using reference counting (at a cost of a few more atomics). This is
even more beneficial when the lifetime of the state becomes more
convoluted than being passed to a single worker thread for the commit.

v2: Double check !intel atomic_commit functions for missing gets
v3: Update kerneldocs

Signed-off-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: dri-devel@lists.freedesktop.org
Reviewed-by: default avatarEric Engestrom <eric.engestrom@imgtec.com>
Reviewed-by: default avatarSean Paul <seanpaul@chromium.org>
Signed-off-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
Link: http://patchwork.freedesktop.org/patch/msgid/20161014121833.439-27-chris@chris-wilson.co.uk
parent 1dfdb0ed
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -464,7 +464,7 @@ atmel_hlcdc_dc_atomic_complete(struct atmel_hlcdc_dc_commit *commit)

	drm_atomic_helper_cleanup_planes(dev, old_state);

	drm_atomic_state_free(old_state);
	drm_atomic_state_put(old_state);

	/* Complete the commit, wake up any waiter. */
	spin_lock(&dc->commit.wait.lock);
@@ -521,6 +521,7 @@ static int atmel_hlcdc_dc_atomic_commit(struct drm_device *dev,
	/* Swap the state, this is the point of no return. */
	drm_atomic_helper_swap_state(state, true);

	drm_atomic_state_get(state);
	if (async)
		queue_work(dc->wq, &commit->work);
	else
+10 −15
Original line number Diff line number Diff line
@@ -74,6 +74,8 @@ EXPORT_SYMBOL(drm_atomic_state_default_release);
int
drm_atomic_state_init(struct drm_device *dev, struct drm_atomic_state *state)
{
	kref_init(&state->ref);

	/* TODO legacy paths should maybe do a better job about
	 * setting this appropriately?
	 */
@@ -215,22 +217,16 @@ void drm_atomic_state_clear(struct drm_atomic_state *state)
EXPORT_SYMBOL(drm_atomic_state_clear);

/**
 * drm_atomic_state_free - free all memory for an atomic state
 * @state: atomic state to deallocate
 * __drm_atomic_state_free - free all memory for an atomic state
 * @ref: This atomic state to deallocate
 *
 * This frees all memory associated with an atomic state, including all the
 * per-object state for planes, crtcs and connectors.
 */
void drm_atomic_state_free(struct drm_atomic_state *state)
void __drm_atomic_state_free(struct kref *ref)
{
	struct drm_device *dev;
	struct drm_mode_config *config;

	if (!state)
		return;

	dev = state->dev;
	config = &dev->mode_config;
	struct drm_atomic_state *state = container_of(ref, typeof(*state), ref);
	struct drm_mode_config *config = &state->dev->mode_config;

	drm_atomic_state_clear(state);

@@ -243,7 +239,7 @@ void drm_atomic_state_free(struct drm_atomic_state *state)
		kfree(state);
	}
}
EXPORT_SYMBOL(drm_atomic_state_free);
EXPORT_SYMBOL(__drm_atomic_state_free);

/**
 * drm_atomic_get_crtc_state - get crtc state
@@ -1742,7 +1738,7 @@ int drm_mode_atomic_ioctl(struct drm_device *dev,
	if (arg->flags & DRM_MODE_ATOMIC_TEST_ONLY) {
		/*
		 * Unlike commit, check_only does not clean up state.
		 * Below we call drm_atomic_state_free for it.
		 * Below we call drm_atomic_state_put for it.
		 */
		ret = drm_atomic_check_only(state);
	} else if (arg->flags & DRM_MODE_ATOMIC_NONBLOCK) {
@@ -1775,8 +1771,7 @@ int drm_mode_atomic_ioctl(struct drm_device *dev,
		goto retry;
	}

	if (ret || arg->flags & DRM_MODE_ATOMIC_TEST_ONLY)
		drm_atomic_state_free(state);
	drm_atomic_state_put(state);

	drm_modeset_drop_locks(&ctx);
	drm_modeset_acquire_fini(&ctx);
+24 −74
Original line number Diff line number Diff line
@@ -1208,7 +1208,7 @@ static void commit_tail(struct drm_atomic_state *state)

	drm_atomic_helper_commit_cleanup_done(state);

	drm_atomic_state_free(state);
	drm_atomic_state_put(state);
}

static void commit_work(struct work_struct *work)
@@ -1290,6 +1290,7 @@ int drm_atomic_helper_commit(struct drm_device *dev,
	 * make sure work items don't artifically stall on each another.
	 */

	drm_atomic_state_get(state);
	if (nonblock)
		queue_work(system_unbound_wq, &state->commit_work);
	else
@@ -1591,7 +1592,7 @@ EXPORT_SYMBOL(drm_atomic_helper_commit_hw_done);
 *
 * This signals completion of the atomic update @state, including any cleanup
 * work. If used, it must be called right before calling
 * drm_atomic_state_free().
 * drm_atomic_state_put().
 *
 * This is part of the atomic helper support for nonblocking commits, see
 * drm_atomic_helper_setup_commit() for an overview.
@@ -2114,18 +2115,13 @@ int drm_atomic_helper_update_plane(struct drm_plane *plane,
		state->legacy_cursor_update = true;

	ret = drm_atomic_commit(state);
	if (ret != 0)
		goto fail;

	/* Driver takes ownership of state on successful commit. */
	return 0;
fail:
	if (ret == -EDEADLK)
		goto backoff;

	drm_atomic_state_free(state);

	drm_atomic_state_put(state);
	return ret;

backoff:
	drm_atomic_state_clear(state);
	drm_atomic_legacy_backoff(state);
@@ -2187,18 +2183,13 @@ int drm_atomic_helper_disable_plane(struct drm_plane *plane)
		goto fail;

	ret = drm_atomic_commit(state);
	if (ret != 0)
		goto fail;

	/* Driver takes ownership of state on successful commit. */
	return 0;
fail:
	if (ret == -EDEADLK)
		goto backoff;

	drm_atomic_state_free(state);

	drm_atomic_state_put(state);
	return ret;

backoff:
	drm_atomic_state_clear(state);
	drm_atomic_legacy_backoff(state);
@@ -2327,18 +2318,13 @@ int drm_atomic_helper_set_config(struct drm_mode_set *set)
		goto fail;

	ret = drm_atomic_commit(state);
	if (ret != 0)
		goto fail;

	/* Driver takes ownership of state on successful commit. */
	return 0;
fail:
	if (ret == -EDEADLK)
		goto backoff;

	drm_atomic_state_free(state);

	drm_atomic_state_put(state);
	return ret;

backoff:
	drm_atomic_state_clear(state);
	drm_atomic_legacy_backoff(state);
@@ -2480,11 +2466,8 @@ int drm_atomic_helper_disable_all(struct drm_device *dev,
	}

	err = drm_atomic_commit(state);

free:
	if (err < 0)
		drm_atomic_state_free(state);

	drm_atomic_state_put(state);
	return err;
}
EXPORT_SYMBOL(drm_atomic_helper_disable_all);
@@ -2535,7 +2518,7 @@ struct drm_atomic_state *drm_atomic_helper_suspend(struct drm_device *dev)

	err = drm_atomic_helper_disable_all(dev, &ctx);
	if (err < 0) {
		drm_atomic_state_free(state);
		drm_atomic_state_put(state);
		state = ERR_PTR(err);
		goto unlock;
	}
@@ -2624,18 +2607,13 @@ drm_atomic_helper_crtc_set_property(struct drm_crtc *crtc,
		goto fail;

	ret = drm_atomic_commit(state);
	if (ret != 0)
		goto fail;

	/* Driver takes ownership of state on successful commit. */
	return 0;
fail:
	if (ret == -EDEADLK)
		goto backoff;

	drm_atomic_state_free(state);

	drm_atomic_state_put(state);
	return ret;

backoff:
	drm_atomic_state_clear(state);
	drm_atomic_legacy_backoff(state);
@@ -2684,18 +2662,13 @@ drm_atomic_helper_plane_set_property(struct drm_plane *plane,
		goto fail;

	ret = drm_atomic_commit(state);
	if (ret != 0)
		goto fail;

	/* Driver takes ownership of state on successful commit. */
	return 0;
fail:
	if (ret == -EDEADLK)
		goto backoff;

	drm_atomic_state_free(state);

	drm_atomic_state_put(state);
	return ret;

backoff:
	drm_atomic_state_clear(state);
	drm_atomic_legacy_backoff(state);
@@ -2744,18 +2717,13 @@ drm_atomic_helper_connector_set_property(struct drm_connector *connector,
		goto fail;

	ret = drm_atomic_commit(state);
	if (ret != 0)
		goto fail;

	/* Driver takes ownership of state on successful commit. */
	return 0;
fail:
	if (ret == -EDEADLK)
		goto backoff;

	drm_atomic_state_free(state);

	drm_atomic_state_put(state);
	return ret;

backoff:
	drm_atomic_state_clear(state);
	drm_atomic_legacy_backoff(state);
@@ -2828,18 +2796,13 @@ int drm_atomic_helper_page_flip(struct drm_crtc *crtc,
	}

	ret = drm_atomic_nonblocking_commit(state);
	if (ret != 0)
		goto fail;

	/* Driver takes ownership of state on successful commit. */
	return 0;
fail:
	if (ret == -EDEADLK)
		goto backoff;

	drm_atomic_state_free(state);

	drm_atomic_state_put(state);
	return ret;

backoff:
	drm_atomic_state_clear(state);
	drm_atomic_legacy_backoff(state);
@@ -2915,19 +2878,14 @@ int drm_atomic_helper_connector_dpms(struct drm_connector *connector,
	crtc_state->active = active;

	ret = drm_atomic_commit(state);
	if (ret != 0)
		goto fail;

	/* Driver takes ownership of state on successful commit. */
	return 0;
fail:
	if (ret == -EDEADLK)
		goto backoff;

	connector->dpms = old_mode;
	drm_atomic_state_free(state);

	drm_atomic_state_put(state);
	return ret;

backoff:
	drm_atomic_state_clear(state);
	drm_atomic_legacy_backoff(state);
@@ -3334,7 +3292,7 @@ drm_atomic_helper_duplicate_state(struct drm_device *dev,

free:
	if (err < 0) {
		drm_atomic_state_free(state);
		drm_atomic_state_put(state);
		state = ERR_PTR(err);
	}

@@ -3449,22 +3407,14 @@ int drm_atomic_helper_legacy_gamma_set(struct drm_crtc *crtc,
		goto fail;

	ret = drm_atomic_commit(state);
	if (ret)
		goto fail;

	/* Driver takes ownership of state on successful commit. */

	drm_property_unreference_blob(blob);

	return 0;
fail:
	if (ret == -EDEADLK)
		goto backoff;

	drm_atomic_state_free(state);
	drm_atomic_state_put(state);
	drm_property_unreference_blob(blob);

	return ret;

backoff:
	drm_atomic_state_clear(state);
	drm_atomic_legacy_backoff(state);
+2 −7
Original line number Diff line number Diff line
@@ -367,9 +367,7 @@ static int restore_fbdev_mode_atomic(struct drm_fb_helper *fb_helper)
	if (ret == -EDEADLK)
		goto backoff;

	if (ret != 0)
		drm_atomic_state_free(state);

	drm_atomic_state_put(state);
	return ret;

backoff:
@@ -1361,16 +1359,13 @@ static int pan_display_atomic(struct fb_var_screeninfo *var,
	info->var.xoffset = var->xoffset;
	info->var.yoffset = var->yoffset;


fail:
	drm_atomic_clean_old_fb(dev, plane_mask, ret);

	if (ret == -EDEADLK)
		goto backoff;

	if (ret != 0)
		drm_atomic_state_free(state);

	drm_atomic_state_put(state);
	return ret;

backoff:
+2 −1
Original line number Diff line number Diff line
@@ -69,7 +69,7 @@ static void exynos_atomic_commit_complete(struct exynos_atomic_commit *commit)

	drm_atomic_helper_cleanup_planes(dev, state);

	drm_atomic_state_free(state);
	drm_atomic_state_put(state);

	spin_lock(&priv->lock);
	priv->pending &= ~commit->crtcs;
@@ -254,6 +254,7 @@ int exynos_atomic_commit(struct drm_device *dev, struct drm_atomic_state *state,

	drm_atomic_helper_swap_state(state, true);

	drm_atomic_state_get(state);
	if (nonblock)
		schedule_work(&commit->work);
	else
Loading