Commit be1cb55a authored by Chris Wilson's avatar Chris Wilson
Browse files

drm/i915/gt: Keep a no-frills swappable copy of the default context state



We need to keep the default context state around to instantiate new
contexts (aka golden rendercontext), and we also keep it pinned while
the engine is active so that we can quickly reset a hanging context.
However, the default contexts are large enough to merit keeping in
swappable memory as opposed to kernel memory, so we store them inside
shmemfs. Currently, we use the normal GEM objects to create the default
context image, but we can throw away all but the shmemfs file.

This greatly simplifies the tricky power management code which wants to
run underneath the normal GT locking, and we definitely do not want to
use any high level objects that may appear to recurse back into the GT.
Though perhaps the primary advantage of the complex GEM object is that
we aggressively cache the mapping, but here we are recreating the
vm_area everytime time we unpark. At the worst, we add a lightweight
cache, but first find a microbenchmark that is impacted.

Having started to create some utility functions to make working with
shmemfs objects easier, we can start putting them to wider use, where
GEM objects are overkill, such as storing persistent error state.

Signed-off-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
Cc: Matthew Auld <matthew.auld@intel.com>
Cc: Ramalingam C <ramalingam.c@intel.com>
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Reviewed-by: default avatarMatthew Auld <matthew.auld@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20200429172429.6054-1-chris@chris-wilson.co.uk
parent 8c35a195
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -111,6 +111,7 @@ gt-y += \
	gt/intel_sseu.o \
	gt/intel_timeline.o \
	gt/intel_workarounds.o \
	gt/shmem_utils.o \
	gt/sysfs_engines.o
# autogenerated null render state
gt-y += \
+1 −1
Original line number Diff line number Diff line
@@ -834,7 +834,7 @@ void intel_engine_cleanup_common(struct intel_engine_cs *engine)
	intel_engine_cleanup_cmd_parser(engine);

	if (engine->default_state)
		i915_gem_object_put(engine->default_state);
		fput(engine->default_state);

	if (engine->kernel_context) {
		intel_context_unpin(engine->kernel_context);
+5 −5
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
#include "intel_gt_pm.h"
#include "intel_rc6.h"
#include "intel_ring.h"
#include "shmem_utils.h"

static int __engine_unpark(struct intel_wakeref *wf)
{
@@ -30,9 +31,7 @@ static int __engine_unpark(struct intel_wakeref *wf)
	/* Pin the default state for fast resets from atomic context. */
	map = NULL;
	if (engine->default_state)
		map = i915_gem_object_pin_map(engine->default_state,
					      I915_MAP_WB);
	if (!IS_ERR_OR_NULL(map))
		map = shmem_pin_map(engine->default_state);
	engine->pinned_default_state = map;

	/* Discard stale context state from across idling */
@@ -264,7 +263,8 @@ static int __engine_park(struct intel_wakeref *wf)
		engine->park(engine);

	if (engine->pinned_default_state) {
		i915_gem_object_unpin_map(engine->default_state);
		shmem_unpin_map(engine->default_state,
				engine->pinned_default_state);
		engine->pinned_default_state = NULL;
	}

+1 −1
Original line number Diff line number Diff line
@@ -339,7 +339,7 @@ struct intel_engine_cs {

	unsigned long wakeref_serial;
	struct intel_wakeref wakeref;
	struct drm_i915_gem_object *default_state;
	struct file *default_state;
	void *pinned_default_state;

	struct {
+8 −52
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@
#include "intel_rps.h"
#include "intel_uncore.h"
#include "intel_pm.h"
#include "shmem_utils.h"

void intel_gt_init_early(struct intel_gt *gt, struct drm_i915_private *i915)
{
@@ -371,18 +372,6 @@ static struct i915_address_space *kernel_vm(struct intel_gt *gt)
		return i915_vm_get(&gt->ggtt->vm);
}

static int __intel_context_flush_retire(struct intel_context *ce)
{
	struct intel_timeline *tl;

	tl = intel_context_timeline_lock(ce);
	if (IS_ERR(tl))
		return PTR_ERR(tl);

	intel_context_timeline_unlock(tl);
	return 0;
}

static int __engines_record_defaults(struct intel_gt *gt)
{
	struct i915_request *requests[I915_NUM_ENGINES] = {};
@@ -448,8 +437,7 @@ err_rq:

	for (id = 0; id < ARRAY_SIZE(requests); id++) {
		struct i915_request *rq;
		struct i915_vma *state;
		void *vaddr;
		struct file *state;

		rq = requests[id];
		if (!rq)
@@ -461,48 +449,16 @@ err_rq:
		}

		GEM_BUG_ON(!test_bit(CONTEXT_ALLOC_BIT, &rq->context->flags));
		state = rq->context->state;
		if (!state)
		if (!rq->context->state)
			continue;

		/* Serialise with retirement on another CPU */
		GEM_BUG_ON(!i915_request_completed(rq));
		err = __intel_context_flush_retire(rq->context);
		if (err)
			goto out;

		/* We want to be able to unbind the state from the GGTT */
		GEM_BUG_ON(intel_context_is_pinned(rq->context));

		/*
		 * As we will hold a reference to the logical state, it will
		 * not be torn down with the context, and importantly the
		 * object will hold onto its vma (making it possible for a
		 * stray GTT write to corrupt our defaults). Unmap the vma
		 * from the GTT to prevent such accidents and reclaim the
		 * space.
		 */
		err = i915_vma_unbind(state);
		if (err)
			goto out;

		i915_gem_object_lock(state->obj);
		err = i915_gem_object_set_to_cpu_domain(state->obj, false);
		i915_gem_object_unlock(state->obj);
		if (err)
			goto out;

		i915_gem_object_set_cache_coherency(state->obj, I915_CACHE_LLC);

		/* Check we can acquire the image of the context state */
		vaddr = i915_gem_object_pin_map(state->obj, I915_MAP_FORCE_WB);
		if (IS_ERR(vaddr)) {
			err = PTR_ERR(vaddr);
		/* Keep a copy of the state's backing pages; free the obj */
		state = shmem_create_from_object(rq->context->state->obj);
		if (IS_ERR(state)) {
			err = PTR_ERR(state);
			goto out;
		}

		rq->engine->default_state = i915_gem_object_get(state->obj);
		i915_gem_object_unpin_map(state->obj);
		rq->engine->default_state = state;
	}

out:
Loading