From: Daniele Ceraolo Spurio <daniele.ceraolospurio@intel.com>
To: intel-gfx@lists.freedesktop.org
Subject: [PATCH] drm/i915: extract common ce->pin_count check
Date: Mon, 1 Oct 2018 13:46:56 -0700 [thread overview]
Message-ID: <20181001204656.34804-1-daniele.ceraolospurio@intel.com> (raw)
We already have it coded 3 times and a 4th one is coming for the GuC
path in an upcoming patch, so let's move it to a common place.
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Michal Wajdeczko <michal.wajdeczko@intel.com>
Signed-off-by: Daniele Ceraolo Spurio <daniele.ceraolospurio@intel.com>
---
drivers/gpu/drm/i915/i915_gem_context.h | 8 +++++++-
drivers/gpu/drm/i915/intel_lrc.c | 10 ++--------
drivers/gpu/drm/i915/intel_ringbuffer.c | 10 ++--------
drivers/gpu/drm/i915/intel_ringbuffer.h | 3 ++-
drivers/gpu/drm/i915/selftests/mock_engine.c | 13 +++++--------
5 files changed, 18 insertions(+), 26 deletions(-)
diff --git a/drivers/gpu/drm/i915/i915_gem_context.h b/drivers/gpu/drm/i915/i915_gem_context.h
index 08165f6a0a84..5309004f8f8a 100644
--- a/drivers/gpu/drm/i915/i915_gem_context.h
+++ b/drivers/gpu/drm/i915/i915_gem_context.h
@@ -302,7 +302,13 @@ to_intel_context(struct i915_gem_context *ctx,
static inline struct intel_context *
intel_context_pin(struct i915_gem_context *ctx, struct intel_engine_cs *engine)
{
- return engine->context_pin(engine, ctx);
+ struct intel_context *ce = to_intel_context(ctx, engine);
+
+ if (likely(ce->pin_count++))
+ return ce;
+ GEM_BUG_ON(!ce->pin_count); /* no overflow please! */
+
+ return engine->context_pin(engine, ctx, ce);
}
static inline void __intel_context_pin(struct intel_context *ce)
diff --git a/drivers/gpu/drm/i915/intel_lrc.c b/drivers/gpu/drm/i915/intel_lrc.c
index 4ee00f531153..a97f455361f6 100644
--- a/drivers/gpu/drm/i915/intel_lrc.c
+++ b/drivers/gpu/drm/i915/intel_lrc.c
@@ -1422,19 +1422,13 @@ static const struct intel_context_ops execlists_context_ops = {
static struct intel_context *
execlists_context_pin(struct intel_engine_cs *engine,
- struct i915_gem_context *ctx)
+ struct i915_gem_context *ctx,
+ struct intel_context *ce)
{
- struct intel_context *ce = to_intel_context(ctx, engine);
-
lockdep_assert_held(&ctx->i915->drm.struct_mutex);
GEM_BUG_ON(!ctx->ppgtt);
- if (likely(ce->pin_count++))
- return ce;
- GEM_BUG_ON(!ce->pin_count); /* no overflow please! */
-
ce->ops = &execlists_context_ops;
-
return __execlists_context_pin(engine, ctx, ce);
}
diff --git a/drivers/gpu/drm/i915/intel_ringbuffer.c b/drivers/gpu/drm/i915/intel_ringbuffer.c
index c092d5099ebf..a82564c50496 100644
--- a/drivers/gpu/drm/i915/intel_ringbuffer.c
+++ b/drivers/gpu/drm/i915/intel_ringbuffer.c
@@ -1386,18 +1386,12 @@ static const struct intel_context_ops ring_context_ops = {
static struct intel_context *
intel_ring_context_pin(struct intel_engine_cs *engine,
- struct i915_gem_context *ctx)
+ struct i915_gem_context *ctx,
+ struct intel_context *ce)
{
- struct intel_context *ce = to_intel_context(ctx, engine);
-
lockdep_assert_held(&ctx->i915->drm.struct_mutex);
- if (likely(ce->pin_count++))
- return ce;
- GEM_BUG_ON(!ce->pin_count); /* no overflow please! */
-
ce->ops = &ring_context_ops;
-
return __ring_context_pin(engine, ctx, ce);
}
diff --git a/drivers/gpu/drm/i915/intel_ringbuffer.h b/drivers/gpu/drm/i915/intel_ringbuffer.h
index 1534de5bb852..91973bd9003c 100644
--- a/drivers/gpu/drm/i915/intel_ringbuffer.h
+++ b/drivers/gpu/drm/i915/intel_ringbuffer.h
@@ -473,7 +473,8 @@ struct intel_engine_cs {
void (*set_default_submission)(struct intel_engine_cs *engine);
struct intel_context *(*context_pin)(struct intel_engine_cs *engine,
- struct i915_gem_context *ctx);
+ struct i915_gem_context *ctx,
+ struct intel_context *ce);
int (*request_alloc)(struct i915_request *rq);
int (*init_context)(struct i915_request *rq);
diff --git a/drivers/gpu/drm/i915/selftests/mock_engine.c b/drivers/gpu/drm/i915/selftests/mock_engine.c
index 22a73da45ad5..4d5103634a2b 100644
--- a/drivers/gpu/drm/i915/selftests/mock_engine.c
+++ b/drivers/gpu/drm/i915/selftests/mock_engine.c
@@ -89,15 +89,12 @@ static const struct intel_context_ops mock_context_ops = {
static struct intel_context *
mock_context_pin(struct intel_engine_cs *engine,
- struct i915_gem_context *ctx)
+ struct i915_gem_context *ctx,
+ struct intel_context *ce)
{
- struct intel_context *ce = to_intel_context(ctx, engine);
-
- if (!ce->pin_count++) {
- i915_gem_context_get(ctx);
- ce->ring = engine->buffer;
- ce->ops = &mock_context_ops;
- }
+ i915_gem_context_get(ctx);
+ ce->ring = engine->buffer;
+ ce->ops = &mock_context_ops;
return ce;
}
--
2.19.0
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
next reply other threads:[~2018-10-01 20:47 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-01 20:46 Daniele Ceraolo Spurio [this message]
2018-10-01 21:09 ` [PATCH] drm/i915: extract common ce->pin_count check Chris Wilson
2018-10-01 21:34 ` Daniele Ceraolo Spurio
2018-10-01 22:51 ` ✓ Fi.CI.BAT: success for " Patchwork
2018-10-02 3:03 ` ✓ Fi.CI.IGT: " Patchwork
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=20181001204656.34804-1-daniele.ceraolospurio@intel.com \
--to=daniele.ceraolospurio@intel.com \
--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