From: Ben Widawsky <benjamin.widawsky@intel.com>
To: Intel GFX <intel-gfx@lists.freedesktop.org>
Cc: Ben Widawsky <ben@bwidawsk.net>,
Ben Widawsky <benjamin.widawsky@intel.com>
Subject: [PATCH 3/6] drm/i915: Split up do_switch
Date: Mon, 23 Jun 2014 18:48:43 -0700 [thread overview]
Message-ID: <1403574526-15585-3-git-send-email-benjamin.widawsky@intel.com> (raw)
In-Reply-To: <1403574526-15585-1-git-send-email-benjamin.widawsky@intel.com>
There are two important reasons for this patch. It should make the
existing code a lot more readable. It also makes the next patch much
easier to understand in my opinion. There are 2 main variables that
effect this function, leaving 4 permutations:
ring: RCS vs !RCS
PPGTT: full or not
I didn't find extracting the full PPGTT usage to be very beneficial at
this point, but it may be in the future.
This was originally recommended by Daniel Vetter, and in this case, I
agree. There was no intentional behavioral change.
Signed-off-by: Ben Widawsky <ben@bwidawsk.net>
---
drivers/gpu/drm/i915/i915_gem_context.c | 76 +++++++++++++++++++++------------
1 file changed, 49 insertions(+), 27 deletions(-)
diff --git a/drivers/gpu/drm/i915/i915_gem_context.c b/drivers/gpu/drm/i915/i915_gem_context.c
index 0d2c75b..35985ad 100644
--- a/drivers/gpu/drm/i915/i915_gem_context.c
+++ b/drivers/gpu/drm/i915/i915_gem_context.c
@@ -591,31 +591,57 @@ mi_set_context(struct intel_engine_cs *ring,
return ret;
}
-static int do_switch(struct intel_engine_cs *ring,
- struct intel_context *to)
+static void do_switch_fini_common(struct intel_engine_cs *ring,
+ struct intel_context *from,
+ struct intel_context *to)
+{
+ if (likely(from))
+ i915_gem_context_unreference(from);
+ i915_gem_context_reference(to);
+ ring->last_context = to;
+}
+
+static int do_switch_xcs(struct intel_engine_cs *ring,
+ struct intel_context *from,
+ struct intel_context *to)
+{
+ struct drm_device *dev = ring->dev;
+ struct i915_hw_ppgtt *ppgtt = ctx_to_ppgtt(to);
+ int ret;
+
+ BUG_ON(from && from->obj != NULL);
+
+ if (USES_FULL_PPGTT(dev)) {
+ ret = ppgtt->switch_mm(ppgtt, ring, false);
+ if (ret)
+ return ret;
+ }
+
+ if (from)
+ do_switch_fini_common(ring, from, to);
+
+ return 0;
+}
+
+static int do_switch_rcs(struct intel_engine_cs *ring,
+ struct intel_context *from,
+ struct intel_context *to)
{
struct drm_i915_private *dev_priv = ring->dev->dev_private;
- struct intel_context *from = ring->last_context;
struct i915_hw_ppgtt *ppgtt = ctx_to_ppgtt(to);
u32 hw_flags = 0;
bool uninitialized = false;
int ret, i;
- if (from != NULL && ring == &dev_priv->ring[RCS]) {
+ if (from != NULL) {
BUG_ON(from->obj == NULL);
BUG_ON(!i915_gem_obj_is_pinned(from->obj));
}
- if (from == to && !to->remap_slice)
- return 0;
-
/* Trying to pin first makes error handling easier. */
- if (ring == &dev_priv->ring[RCS]) {
- ret = i915_gem_obj_ggtt_pin(to->obj,
- get_context_alignment(ring->dev), 0);
- if (ret)
- return ret;
- }
+ ret = i915_gem_obj_ggtt_pin(to->obj, get_context_alignment(ring->dev), 0);
+ if (ret)
+ return ret;
/*
* Pin can switch back to the default context if we end up calling into
@@ -630,12 +656,6 @@ static int do_switch(struct intel_engine_cs *ring,
goto unpin_out;
}
- if (ring != &dev_priv->ring[RCS]) {
- if (from)
- i915_gem_context_unreference(from);
- goto done;
- }
-
/*
* Clear this page out of any CPU caches for coherent swap-in/out. Note
* that thanks to write = false in this call and us not setting any gpu
@@ -694,15 +714,11 @@ static int do_switch(struct intel_engine_cs *ring,
/* obj is kept alive until the next request by its active ref */
i915_gem_object_ggtt_unpin(from->obj);
- i915_gem_context_unreference(from);
}
uninitialized = !to->is_initialized && from == NULL;
to->is_initialized = true;
-
-done:
- i915_gem_context_reference(to);
- ring->last_context = to;
+ do_switch_fini_common(ring, from, to);
if (uninitialized) {
ret = i915_gem_render_state_init(ring);
@@ -713,8 +729,7 @@ done:
return 0;
unpin_out:
- if (ring->id == RCS)
- i915_gem_object_ggtt_unpin(to->obj);
+ i915_gem_object_ggtt_unpin(to->obj);
return ret;
}
@@ -732,6 +747,7 @@ int i915_switch_context(struct intel_engine_cs *ring,
struct intel_context *to)
{
struct drm_i915_private *dev_priv = ring->dev->dev_private;
+ struct intel_context *from = ring->last_context;
WARN_ON(!mutex_is_locked(&dev_priv->dev->struct_mutex));
@@ -745,7 +761,13 @@ int i915_switch_context(struct intel_engine_cs *ring,
return 0;
}
- return do_switch(ring, to);
+ if (from == to && !to->remap_slice)
+ return 0;
+
+ if (ring->id == RCS)
+ return do_switch_rcs(ring, from, to);
+ else
+ return do_switch_xcs(ring, from, to);
}
static bool hw_context_enabled(struct drm_device *dev)
--
2.0.0
next prev parent reply other threads:[~2014-06-24 1:49 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-24 1:48 [PATCH 1/6] drm/i915: Prevent signals from interrupting close() Ben Widawsky
2014-06-24 1:48 ` [PATCH 2/6] drm/i915: Only mark the ctx as initialised after a SET_CONTEXT operation Ben Widawsky
2014-06-24 13:27 ` Jani Nikula
2014-06-24 1:48 ` Ben Widawsky [this message]
2014-06-24 1:48 ` [PATCH 4/6] drm/i915: Extract l3 remapping out of ctx switch Ben Widawsky
2014-06-24 1:48 ` [PATCH 5/6] drm/i915/ppgtt: Load address space after mi_set_context Ben Widawsky
2014-06-24 1:48 ` [PATCH 6/6] drm/i915/bdw: Enable full PPGTT Ben Widawsky
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1403574526-15585-3-git-send-email-benjamin.widawsky@intel.com \
--to=benjamin.widawsky@intel.com \
--cc=ben@bwidawsk.net \
--cc=intel-gfx@lists.freedesktop.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox