Skip to content

Commit

Permalink
drm/i915: Drop GEM context as a direct link from i915_request
Browse files Browse the repository at this point in the history
Keep the intel_context as being the primary state for i915_request, with
the GEM context a backpointer from the low level state for the rarer
cases we need client information. Our goal is to remove such references
to clients from the backend, and leave the HW submission agnostic to
client interfaces and self-contained.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Andi Shyti <andi.shyti@intel.com>
Reviewed-by: Andi Shyti <andi.shyti@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20191220101230.256839-1-chris@chris-wilson.co.uk
  • Loading branch information
Chris Wilson committed Dec 20, 2019
1 parent d5e1935 commit 9f3ccd4
Show file tree
Hide file tree
Showing 21 changed files with 165 additions and 161 deletions.
15 changes: 5 additions & 10 deletions drivers/gpu/drm/i915/gem/i915_gem_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@

#include <drm/i915_drm.h>

#include "gt/intel_context.h"
#include "gt/intel_engine_heartbeat.h"
#include "gt/intel_engine_pm.h"
#include "gt/intel_engine_user.h"
Expand Down Expand Up @@ -423,15 +424,6 @@ static void kill_context(struct i915_gem_context *ctx)
struct i915_gem_engines_iter it;
struct intel_context *ce;

/*
* If we are already banned, it was due to a guilty request causing
* a reset and the entire context being evicted from the GPU.
*/
if (i915_gem_context_is_banned(ctx))
return;

i915_gem_context_set_banned(ctx);

/*
* Map the user's engine back to the actual engines; one virtual
* engine will be mapped to multiple engines, and using ctx->engine[]
Expand All @@ -442,6 +434,9 @@ static void kill_context(struct i915_gem_context *ctx)
for_each_gem_engine(ce, __context_engines_static(ctx), it) {
struct intel_engine_cs *engine;

if (intel_context_set_banned(ce))
continue;

/*
* Check the current active state of this context; if we
* are currently executing on the GPU we need to evict
Expand Down Expand Up @@ -1093,7 +1088,7 @@ static void set_ppgtt_barrier(void *data)

static int emit_ppgtt_update(struct i915_request *rq, void *data)
{
struct i915_address_space *vm = rq->hw_context->vm;
struct i915_address_space *vm = rq->context->vm;
struct intel_engine_cs *engine = rq->engine;
u32 base = engine->mmio_base;
u32 *cs;
Expand Down
38 changes: 0 additions & 38 deletions drivers/gpu/drm/i915/gem/i915_gem_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,26 +91,6 @@ static inline void i915_gem_context_clear_persistence(struct i915_gem_context *c
clear_bit(UCONTEXT_PERSISTENCE, &ctx->user_flags);
}

static inline bool i915_gem_context_is_banned(const struct i915_gem_context *ctx)
{
return test_bit(CONTEXT_BANNED, &ctx->flags);
}

static inline void i915_gem_context_set_banned(struct i915_gem_context *ctx)
{
set_bit(CONTEXT_BANNED, &ctx->flags);
}

static inline bool i915_gem_context_force_single_submission(const struct i915_gem_context *ctx)
{
return test_bit(CONTEXT_FORCE_SINGLE_SUBMISSION, &ctx->flags);
}

static inline void i915_gem_context_set_force_single_submission(struct i915_gem_context *ctx)
{
__set_bit(CONTEXT_FORCE_SINGLE_SUBMISSION, &ctx->flags);
}

static inline bool
i915_gem_context_user_engines(const struct i915_gem_context *ctx)
{
Expand All @@ -129,24 +109,6 @@ i915_gem_context_clear_user_engines(struct i915_gem_context *ctx)
clear_bit(CONTEXT_USER_ENGINES, &ctx->flags);
}

static inline bool
i915_gem_context_nopreempt(const struct i915_gem_context *ctx)
{
return test_bit(CONTEXT_NOPREEMPT, &ctx->flags);
}

static inline void
i915_gem_context_set_nopreempt(struct i915_gem_context *ctx)
{
set_bit(CONTEXT_NOPREEMPT, &ctx->flags);
}

static inline void
i915_gem_context_clear_nopreempt(struct i915_gem_context *ctx)
{
clear_bit(CONTEXT_NOPREEMPT, &ctx->flags);
}

static inline bool i915_gem_context_is_kernel(struct i915_gem_context *ctx)
{
return !ctx->file_priv;
Expand Down
7 changes: 2 additions & 5 deletions drivers/gpu/drm/i915/gem/i915_gem_context_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,8 @@ struct i915_gem_context {
* @flags: small set of booleans
*/
unsigned long flags;
#define CONTEXT_BANNED 0
#define CONTEXT_CLOSED 1
#define CONTEXT_FORCE_SINGLE_SUBMISSION 2
#define CONTEXT_USER_ENGINES 3
#define CONTEXT_NOPREEMPT 4
#define CONTEXT_CLOSED 0
#define CONTEXT_USER_ENGINES 1

struct mutex mutex;

Expand Down
8 changes: 4 additions & 4 deletions drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -730,9 +730,6 @@ static int eb_lookup_vmas(struct i915_execbuffer *eb)
unsigned int i, batch;
int err;

if (unlikely(i915_gem_context_is_banned(eb->gem_context)))
return -EIO;

INIT_LIST_HEAD(&eb->relocs);
INIT_LIST_HEAD(&eb->unbound);

Expand Down Expand Up @@ -2175,7 +2172,7 @@ static int eb_submit(struct i915_execbuffer *eb)
return err;
}

if (i915_gem_context_nopreempt(eb->gem_context))
if (intel_context_nopreempt(eb->context))
eb->request->flags |= I915_REQUEST_NOPREEMPT;

return 0;
Expand Down Expand Up @@ -2261,6 +2258,9 @@ static int __eb_pin_engine(struct i915_execbuffer *eb, struct intel_context *ce)
if (err)
return err;

if (unlikely(intel_context_is_banned(ce)))
return -EIO;

/*
* Pinning the contexts may generate requests in order to acquire
* GGTT space, so do this first before we reserve a seqno for
Expand Down
4 changes: 2 additions & 2 deletions drivers/gpu/drm/i915/gt/intel_breadcrumbs.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ bool i915_request_enable_breadcrumb(struct i915_request *rq)

if (test_bit(I915_FENCE_FLAG_ACTIVE, &rq->fence.flags)) {
struct intel_breadcrumbs *b = &rq->engine->breadcrumbs;
struct intel_context *ce = rq->hw_context;
struct intel_context *ce = rq->context;
struct list_head *pos;

spin_lock(&b->irq_lock);
Expand Down Expand Up @@ -338,7 +338,7 @@ void i915_request_cancel_breadcrumb(struct i915_request *rq)
*/
spin_lock(&b->irq_lock);
if (test_bit(I915_FENCE_FLAG_SIGNAL, &rq->fence.flags)) {
struct intel_context *ce = rq->hw_context;
struct intel_context *ce = rq->context;

list_del(&rq->signal_link);
if (list_empty(&ce->signals))
Expand Down
2 changes: 1 addition & 1 deletion drivers/gpu/drm/i915/gt/intel_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ int intel_context_prepare_remote_request(struct intel_context *ce,
int err;

/* Only suitable for use in remotely modifying this context */
GEM_BUG_ON(rq->hw_context == ce);
GEM_BUG_ON(rq->context == ce);

if (rcu_access_pointer(rq->timeline) != tl) { /* timeline sharing! */
/* Queue this switch after current activity by this context. */
Expand Down
42 changes: 42 additions & 0 deletions drivers/gpu/drm/i915/gt/intel_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
#ifndef __INTEL_CONTEXT_H__
#define __INTEL_CONTEXT_H__

#include <linux/bitops.h>
#include <linux/lockdep.h>
#include <linux/types.h>

#include "i915_active.h"
#include "intel_context_types.h"
Expand Down Expand Up @@ -160,4 +162,44 @@ static inline struct intel_ring *__intel_context_ring_size(u64 sz)
return u64_to_ptr(struct intel_ring, sz);
}

static inline bool intel_context_is_banned(const struct intel_context *ce)
{
return test_bit(CONTEXT_BANNED, &ce->flags);
}

static inline bool intel_context_set_banned(struct intel_context *ce)
{
return test_and_set_bit(CONTEXT_BANNED, &ce->flags);
}

static inline bool
intel_context_force_single_submission(const struct intel_context *ce)
{
return test_bit(CONTEXT_FORCE_SINGLE_SUBMISSION, &ce->flags);
}

static inline void
intel_context_set_single_submission(struct intel_context *ce)
{
__set_bit(CONTEXT_FORCE_SINGLE_SUBMISSION, &ce->flags);
}

static inline bool
intel_context_nopreempt(const struct intel_context *ce)
{
return test_bit(CONTEXT_NOPREEMPT, &ce->flags);
}

static inline void
intel_context_set_nopreempt(struct intel_context *ce)
{
set_bit(CONTEXT_NOPREEMPT, &ce->flags);
}

static inline void
intel_context_clear_nopreempt(struct intel_context *ce)
{
clear_bit(CONTEXT_NOPREEMPT, &ce->flags);
}

#endif /* __INTEL_CONTEXT_H__ */
7 changes: 5 additions & 2 deletions drivers/gpu/drm/i915/gt/intel_context_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,11 @@ struct intel_context {
struct intel_timeline *timeline;

unsigned long flags;
#define CONTEXT_ALLOC_BIT 0
#define CONTEXT_VALID_BIT 1
#define CONTEXT_ALLOC_BIT 0
#define CONTEXT_VALID_BIT 1
#define CONTEXT_BANNED 2
#define CONTEXT_FORCE_SINGLE_SUBMISSION 3
#define CONTEXT_NOPREEMPT 4

u32 *lrc_reg_state;
u64 lrc_desc;
Expand Down
6 changes: 3 additions & 3 deletions drivers/gpu/drm/i915/gt/intel_engine_cs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1523,9 +1523,9 @@ void intel_engine_dump(struct intel_engine_cs *engine,

print_request_ring(m, rq);

if (rq->hw_context->lrc_reg_state) {
if (rq->context->lrc_reg_state) {
drm_printf(m, "Logical Ring Context:\n");
hexdump(m, rq->hw_context->lrc_reg_state, PAGE_SIZE);
hexdump(m, rq->context->lrc_reg_state, PAGE_SIZE);
}
}
spin_unlock_irqrestore(&engine->active.lock, flags);
Expand Down Expand Up @@ -1586,7 +1586,7 @@ int intel_enable_engine_stats(struct intel_engine_cs *engine)

for (port = execlists->pending; (rq = *port); port++) {
/* Exclude any contexts already counted in active */
if (!intel_context_inflight_count(rq->hw_context))
if (!intel_context_inflight_count(rq->context))
engine->stats.active++;
}

Expand Down
Loading

0 comments on commit 9f3ccd4

Please sign in to comment.