Skip to content

Commit

Permalink
drm/i915: Pack params to engine->schedule() into a struct
Browse files Browse the repository at this point in the history
Today we only want to pass along the priority to engine->schedule(), but
in the future we want to have much more control over the various aspects
of the GPU during a context's execution, for example controlling the
frequency allowed. As we need an ever growing number of parameters for
scheduling, move those into a struct for convenience.

v2: Move the anonymous struct into its own function for legibility and
ye olde gcc.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20180418184052.7129-3-chris@chris-wilson.co.uk
  • Loading branch information
Chris Wilson committed Apr 18, 2018
1 parent 0c7112a commit b7268c5
Show file tree
Hide file tree
Showing 17 changed files with 91 additions and 55 deletions.
2 changes: 1 addition & 1 deletion drivers/gpu/drm/i915/gvt/scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -1135,7 +1135,7 @@ int intel_vgpu_setup_submission(struct intel_vgpu *vgpu)
return PTR_ERR(s->shadow_ctx);

if (HAS_LOGICAL_RING_PREEMPTION(vgpu->gvt->dev_priv))
s->shadow_ctx->priority = INT_MAX;
s->shadow_ctx->sched.priority = INT_MAX;

bitmap_zero(s->shadow_ctx_desc_updated, I915_NUM_ENGINES);

Expand Down
3 changes: 2 additions & 1 deletion drivers/gpu/drm/i915/i915_drv.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
#include "i915_gem_timeline.h"
#include "i915_gpu_error.h"
#include "i915_request.h"
#include "i915_scheduler.h"
#include "i915_vma.h"

#include "intel_gvt.h"
Expand Down Expand Up @@ -3158,7 +3159,7 @@ int i915_gem_object_wait(struct drm_i915_gem_object *obj,
struct intel_rps_client *rps);
int i915_gem_object_wait_priority(struct drm_i915_gem_object *obj,
unsigned int flags,
int priority);
const struct i915_sched_attr *attr);
#define I915_PRIORITY_DISPLAY I915_PRIORITY_MAX

int __must_check
Expand Down
18 changes: 10 additions & 8 deletions drivers/gpu/drm/i915/i915_gem.c
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,8 @@ i915_gem_object_wait_reservation(struct reservation_object *resv,
return timeout;
}

static void __fence_set_priority(struct dma_fence *fence, int prio)
static void __fence_set_priority(struct dma_fence *fence,
const struct i915_sched_attr *attr)
{
struct i915_request *rq;
struct intel_engine_cs *engine;
Expand All @@ -577,28 +578,29 @@ static void __fence_set_priority(struct dma_fence *fence, int prio)

rcu_read_lock();
if (engine->schedule)
engine->schedule(rq, prio);
engine->schedule(rq, attr);
rcu_read_unlock();
}

static void fence_set_priority(struct dma_fence *fence, int prio)
static void fence_set_priority(struct dma_fence *fence,
const struct i915_sched_attr *attr)
{
/* Recurse once into a fence-array */
if (dma_fence_is_array(fence)) {
struct dma_fence_array *array = to_dma_fence_array(fence);
int i;

for (i = 0; i < array->num_fences; i++)
__fence_set_priority(array->fences[i], prio);
__fence_set_priority(array->fences[i], attr);
} else {
__fence_set_priority(fence, prio);
__fence_set_priority(fence, attr);
}
}

int
i915_gem_object_wait_priority(struct drm_i915_gem_object *obj,
unsigned int flags,
int prio)
const struct i915_sched_attr *attr)
{
struct dma_fence *excl;

Expand All @@ -613,7 +615,7 @@ i915_gem_object_wait_priority(struct drm_i915_gem_object *obj,
return ret;

for (i = 0; i < count; i++) {
fence_set_priority(shared[i], prio);
fence_set_priority(shared[i], attr);
dma_fence_put(shared[i]);
}

Expand All @@ -623,7 +625,7 @@ i915_gem_object_wait_priority(struct drm_i915_gem_object *obj,
}

if (excl) {
fence_set_priority(excl, prio);
fence_set_priority(excl, attr);
dma_fence_put(excl);
}
return 0;
Expand Down
8 changes: 4 additions & 4 deletions drivers/gpu/drm/i915/i915_gem_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ __create_hw_context(struct drm_i915_private *dev_priv,
kref_init(&ctx->ref);
list_add_tail(&ctx->link, &dev_priv->contexts.list);
ctx->i915 = dev_priv;
ctx->priority = I915_PRIORITY_NORMAL;
ctx->sched.priority = I915_PRIORITY_NORMAL;

INIT_RADIX_TREE(&ctx->handles_vma, GFP_KERNEL);
INIT_LIST_HEAD(&ctx->handles_list);
Expand Down Expand Up @@ -431,7 +431,7 @@ i915_gem_context_create_kernel(struct drm_i915_private *i915, int prio)
return ctx;

i915_gem_context_clear_bannable(ctx);
ctx->priority = prio;
ctx->sched.priority = prio;
ctx->ring_size = PAGE_SIZE;

GEM_BUG_ON(!i915_gem_context_is_kernel(ctx));
Expand Down Expand Up @@ -753,7 +753,7 @@ int i915_gem_context_getparam_ioctl(struct drm_device *dev, void *data,
args->value = i915_gem_context_is_bannable(ctx);
break;
case I915_CONTEXT_PARAM_PRIORITY:
args->value = ctx->priority;
args->value = ctx->sched.priority;
break;
default:
ret = -EINVAL;
Expand Down Expand Up @@ -826,7 +826,7 @@ int i915_gem_context_setparam_ioctl(struct drm_device *dev, void *data,
!capable(CAP_SYS_NICE))
ret = -EPERM;
else
ctx->priority = priority;
ctx->sched.priority = priority;
}
break;

Expand Down
13 changes: 1 addition & 12 deletions drivers/gpu/drm/i915/i915_gem_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,18 +137,7 @@ struct i915_gem_context {
*/
u32 user_handle;

/**
* @priority: execution and service priority
*
* All clients are equal, but some are more equal than others!
*
* Requests from a context with a greater (more positive) value of
* @priority will be executed before those with a lower @priority
* value, forming a simple QoS.
*
* The &drm_i915_private.kernel_context is assigned the lowest priority.
*/
int priority;
struct i915_sched_attr sched;

/** ggtt_offset_bias: placement restriction for context objects */
u32 ggtt_offset_bias;
Expand Down
8 changes: 4 additions & 4 deletions drivers/gpu/drm/i915/i915_gpu_error.c
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ static void error_print_request(struct drm_i915_error_state_buf *m,

err_printf(m, "%s pid %d, ban score %d, seqno %8x:%08x, prio %d, emitted %dms ago, head %08x, tail %08x\n",
prefix, erq->pid, erq->ban_score,
erq->context, erq->seqno, erq->priority,
erq->context, erq->seqno, erq->sched_attr.priority,
jiffies_to_msecs(jiffies - erq->jiffies),
erq->head, erq->tail);
}
Expand All @@ -422,7 +422,7 @@ static void error_print_context(struct drm_i915_error_state_buf *m,
{
err_printf(m, "%s%s[%d] user_handle %d hw_id %d, prio %d, ban score %d%s guilty %d active %d\n",
header, ctx->comm, ctx->pid, ctx->handle, ctx->hw_id,
ctx->priority, ctx->ban_score, bannable(ctx),
ctx->sched_attr.priority, ctx->ban_score, bannable(ctx),
ctx->guilty, ctx->active);
}

Expand Down Expand Up @@ -1278,7 +1278,7 @@ static void record_request(struct i915_request *request,
struct drm_i915_error_request *erq)
{
erq->context = request->ctx->hw_id;
erq->priority = request->sched.priority;
erq->sched_attr = request->sched.attr;
erq->ban_score = atomic_read(&request->ctx->ban_score);
erq->seqno = request->global_seqno;
erq->jiffies = request->emitted_jiffies;
Expand Down Expand Up @@ -1372,7 +1372,7 @@ static void record_context(struct drm_i915_error_context *e,

e->handle = ctx->user_handle;
e->hw_id = ctx->hw_id;
e->priority = ctx->priority;
e->sched_attr = ctx->sched;
e->ban_score = atomic_read(&ctx->ban_score);
e->bannable = i915_gem_context_is_bannable(ctx);
e->guilty = atomic_read(&ctx->guilty_count);
Expand Down
5 changes: 3 additions & 2 deletions drivers/gpu/drm/i915/i915_gpu_error.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "i915_gem.h"
#include "i915_gem_gtt.h"
#include "i915_params.h"
#include "i915_scheduler.h"

struct drm_i915_private;
struct intel_overlay_error_state;
Expand Down Expand Up @@ -122,11 +123,11 @@ struct i915_gpu_state {
pid_t pid;
u32 handle;
u32 hw_id;
int priority;
int ban_score;
int active;
int guilty;
bool bannable;
struct i915_sched_attr sched_attr;
} context;

struct drm_i915_error_object {
Expand All @@ -147,11 +148,11 @@ struct i915_gpu_state {
long jiffies;
pid_t pid;
u32 context;
int priority;
int ban_score;
u32 seqno;
u32 head;
u32 tail;
struct i915_sched_attr sched_attr;
} *requests, execlist[EXECLIST_MAX_PORTS];
unsigned int num_ports;

Expand Down
4 changes: 2 additions & 2 deletions drivers/gpu/drm/i915/i915_request.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ i915_sched_node_init(struct i915_sched_node *node)
INIT_LIST_HEAD(&node->signalers_list);
INIT_LIST_HEAD(&node->waiters_list);
INIT_LIST_HEAD(&node->link);
node->priority = I915_PRIORITY_INVALID;
node->attr.priority = I915_PRIORITY_INVALID;
}

static int reset_all_global_seqno(struct drm_i915_private *i915, u32 seqno)
Expand Down Expand Up @@ -1064,7 +1064,7 @@ void __i915_request_add(struct i915_request *request, bool flush_caches)
*/
rcu_read_lock();
if (engine->schedule)
engine->schedule(request, request->ctx->priority);
engine->schedule(request, &request->ctx->sched);
rcu_read_unlock();

local_bh_disable();
Expand Down
1 change: 1 addition & 0 deletions drivers/gpu/drm/i915/i915_request.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "i915_gem.h"
#include "i915_scheduler.h"
#include "i915_sw_fence.h"
#include "i915_scheduler.h"

#include <uapi/drm/i915_drm.h>

Expand Down
17 changes: 16 additions & 1 deletion drivers/gpu/drm/i915/i915_scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,21 @@ enum {
I915_PRIORITY_INVALID = INT_MIN
};

struct i915_sched_attr {
/**
* @priority: execution and service priority
*
* All clients are equal, but some are more equal than others!
*
* Requests from a context with a greater (more positive) value of
* @priority will be executed before those with a lower @priority
* value, forming a simple QoS.
*
* The &drm_i915_private.kernel_context is assigned the lowest priority.
*/
int priority;
};

/*
* "People assume that time is a strict progression of cause to effect, but
* actually, from a nonlinear, non-subjective viewpoint, it's more like a big
Expand All @@ -42,7 +57,7 @@ struct i915_sched_node {
struct list_head signalers_list; /* those before us, we depend upon */
struct list_head waiters_list; /* those after us, they depend upon us */
struct list_head link;
int priority;
struct i915_sched_attr attr;
};

struct i915_dependency {
Expand Down
11 changes: 10 additions & 1 deletion drivers/gpu/drm/i915/intel_display.c
Original file line number Diff line number Diff line change
Expand Up @@ -12761,6 +12761,15 @@ static void intel_plane_unpin_fb(struct intel_plane_state *old_plane_state)
intel_unpin_fb_vma(vma, old_plane_state->flags);
}

static void fb_obj_bump_render_priority(struct drm_i915_gem_object *obj)
{
struct i915_sched_attr attr = {
.priority = I915_PRIORITY_DISPLAY,
};

i915_gem_object_wait_priority(obj, 0, &attr);
}

/**
* intel_prepare_plane_fb - Prepare fb for usage on plane
* @plane: drm plane to prepare for
Expand Down Expand Up @@ -12837,7 +12846,7 @@ intel_prepare_plane_fb(struct drm_plane *plane,

ret = intel_plane_pin_fb(to_intel_plane_state(new_state));

i915_gem_object_wait_priority(obj, 0, I915_PRIORITY_DISPLAY);
fb_obj_bump_render_priority(obj);

mutex_unlock(&dev_priv->drm.struct_mutex);
i915_gem_object_unpin_pages(obj);
Expand Down
18 changes: 15 additions & 3 deletions drivers/gpu/drm/i915/intel_engine_cs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1113,17 +1113,29 @@ unsigned int intel_engines_has_context_isolation(struct drm_i915_private *i915)
return which;
}

static void print_sched_attr(struct drm_printer *m,
const struct drm_i915_private *i915,
const struct i915_sched_attr *attr)
{
if (attr->priority == I915_PRIORITY_INVALID)
return;

drm_printf(m, "prio=%d", attr->priority);
}

static void print_request(struct drm_printer *m,
struct i915_request *rq,
const char *prefix)
{
const char *name = rq->fence.ops->get_timeline_name(&rq->fence);

drm_printf(m, "%s%x%s [%llx:%x] prio=%d @ %dms: %s\n", prefix,
drm_printf(m, "%s%x%s [%llx:%x] ",
prefix,
rq->global_seqno,
i915_request_completed(rq) ? "!" : "",
rq->fence.context, rq->fence.seqno,
rq->sched.priority,
rq->fence.context, rq->fence.seqno);
print_sched_attr(m, rq->i915, &rq->sched.attr);
drm_printf(m, " @ %dms: %s\n",
jiffies_to_msecs(jiffies - rq->emitted_jiffies),
name);
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/gpu/drm/i915/intel_guc_submission.c
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ static void port_assign(struct execlist_port *port, struct i915_request *rq)

static inline int rq_prio(const struct i915_request *rq)
{
return rq->sched.priority;
return rq->sched.attr.priority;
}

static inline int port_prio(const struct execlist_port *port)
Expand Down
Loading

0 comments on commit b7268c5

Please sign in to comment.