iris: Store iris_context's priority

This way when replacing a broken context we don't need to ask to
kernel what is the priority of the context being replaced.

Also this will be necessary for Xe kmd as it don't have any uapi to
query engine priority.

While doing that also taking the oportunity to move more code from
iris_bufmgr.c/h that only has one caller.

Signed-off-by: José Roberto de Souza <jose.souza@intel.com>
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21965>
This commit is contained in:
José Roberto de Souza
2022-11-11 11:53:52 -08:00
committed by Marge Bot
parent 75b9d0b3d8
commit 7a1d0b31a6
6 changed files with 68 additions and 59 deletions

View File

@@ -45,6 +45,7 @@
#include "iris_utrace.h"
#include "common/intel_aux_map.h"
#include "common/intel_defines.h"
#include "intel/common/intel_gem.h"
#include "intel/ds/intel_tracepoints.h"
#include "util/hash_table.h"
@@ -250,8 +251,36 @@ iris_init_batch(struct iris_context *ice,
iris_batch_reset(batch);
}
static int
iris_context_priority_to_i915_priority(enum iris_context_priority priority)
{
switch (priority) {
case IRIS_CONTEXT_HIGH_PRIORITY:
return INTEL_CONTEXT_HIGH_PRIORITY;
case IRIS_CONTEXT_LOW_PRIORITY:
return INTEL_CONTEXT_LOW_PRIORITY;
case IRIS_CONTEXT_MEDIUM_PRIORITY:
FALLTHROUGH;
default:
return INTEL_CONTEXT_MEDIUM_PRIORITY;
}
}
static int
context_set_priority(struct iris_bufmgr *bufmgr, uint32_t ctx_id,
enum iris_context_priority priority)
{
int err = 0;
int i915_priority = iris_context_priority_to_i915_priority(priority);
if (!intel_gem_set_context_param(iris_bufmgr_get_fd(bufmgr), ctx_id,
I915_CONTEXT_PARAM_PRIORITY, i915_priority))
err = -errno;
return err;
}
static void
iris_init_non_engine_contexts(struct iris_context *ice, int priority)
iris_init_non_engine_contexts(struct iris_context *ice)
{
struct iris_screen *screen = (void *) ice->ctx.screen;
@@ -259,7 +288,7 @@ iris_init_non_engine_contexts(struct iris_context *ice, int priority)
batch->ctx_id = iris_create_hw_context(screen->bufmgr, ice->protected);
batch->exec_flags = I915_EXEC_RENDER;
assert(batch->ctx_id);
iris_hw_context_set_priority(screen->bufmgr, batch->ctx_id, priority);
context_set_priority(screen->bufmgr, batch->ctx_id, ice->priority);
}
ice->batches[IRIS_BATCH_BLITTER].exec_flags = I915_EXEC_BLT;
@@ -267,7 +296,7 @@ iris_init_non_engine_contexts(struct iris_context *ice, int priority)
}
static int
iris_create_engines_context(struct iris_context *ice, int priority)
iris_create_engines_context(struct iris_context *ice)
{
struct iris_screen *screen = (void *) ice->ctx.screen;
const struct intel_device_info *devinfo = screen->devinfo;
@@ -307,16 +336,16 @@ iris_create_engines_context(struct iris_context *ice, int priority)
iris_hw_context_set_unrecoverable(screen->bufmgr, engines_ctx);
iris_hw_context_set_vm_id(screen->bufmgr, engines_ctx);
iris_hw_context_set_priority(screen->bufmgr, engines_ctx, priority);
context_set_priority(screen->bufmgr, engines_ctx, ice->priority);
free(engines_info);
return engines_ctx;
}
static bool
iris_init_engines_context(struct iris_context *ice, int priority)
iris_init_engines_context(struct iris_context *ice)
{
int engines_ctx = iris_create_engines_context(ice, priority);
int engines_ctx = iris_create_engines_context(ice);
if (engines_ctx < 0)
return false;
@@ -331,14 +360,14 @@ iris_init_engines_context(struct iris_context *ice, int priority)
}
void
iris_init_batches(struct iris_context *ice, int priority)
iris_init_batches(struct iris_context *ice)
{
/* We have to do this early for iris_foreach_batch() to work */
for (int i = 0; i < IRIS_BATCH_COUNT; i++)
ice->batches[i].screen = (void *) ice->ctx.screen;
if (!iris_init_engines_context(ice, priority))
iris_init_non_engine_contexts(ice, priority);
if (!iris_init_engines_context(ice))
iris_init_non_engine_contexts(ice);
iris_foreach_batch(ice, batch)
iris_init_batch(ice, batch - &ice->batches[0]);
}
@@ -732,6 +761,21 @@ iris_finish_batch(struct iris_batch *batch)
record_batch_sizes(batch);
}
static uint32_t
clone_hw_context(struct iris_batch *batch)
{
struct iris_screen *screen = batch->screen;
struct iris_bufmgr *bufmgr = screen->bufmgr;
struct iris_context *ice = batch->ice;
bool protected = iris_hw_context_get_protected(bufmgr, batch->ctx_id);
uint32_t new_ctx = iris_create_hw_context(bufmgr, protected);
if (new_ctx)
context_set_priority(bufmgr, new_ctx, ice->priority);
return new_ctx;
}
/**
* Replace our current GEM context with a new one (in case it got banned).
*/
@@ -743,9 +787,8 @@ replace_kernel_ctx(struct iris_batch *batch)
struct iris_context *ice = batch->ice;
if (ice->has_engines_context) {
int priority = iris_kernel_context_get_priority(bufmgr, batch->ctx_id);
uint32_t old_ctx = batch->ctx_id;
int new_ctx = iris_create_engines_context(ice, priority);
int new_ctx = iris_create_engines_context(ice);
if (new_ctx < 0)
return false;
iris_foreach_batch(ice, bat) {
@@ -755,7 +798,7 @@ replace_kernel_ctx(struct iris_batch *batch)
}
iris_destroy_kernel_context(bufmgr, old_ctx);
} else {
uint32_t new_ctx = iris_clone_hw_context(bufmgr, batch->ctx_id);
uint32_t new_ctx = clone_hw_context(batch);
if (!new_ctx)
return false;

View File

@@ -207,7 +207,7 @@ struct iris_batch {
struct intel_ds_queue ds;
};
void iris_init_batches(struct iris_context *ice, int priority);
void iris_init_batches(struct iris_context *ice);
void iris_chain_to_new_batch(struct iris_batch *batch);
void iris_destroy_batches(struct iris_context *ice);
void iris_batch_maybe_flush(struct iris_batch *batch, unsigned estimate);

View File

@@ -2100,29 +2100,7 @@ iris_create_hw_context(struct iris_bufmgr *bufmgr, bool protected)
return ctx_id;
}
int
iris_kernel_context_get_priority(struct iris_bufmgr *bufmgr, uint32_t ctx_id)
{
uint64_t priority = 0;
intel_gem_get_context_param(bufmgr->fd, ctx_id,
I915_CONTEXT_PARAM_PRIORITY, &priority);
return priority; /* on error, return 0 i.e. default priority */
}
int
iris_hw_context_set_priority(struct iris_bufmgr *bufmgr,
uint32_t ctx_id,
int priority)
{
int err = 0;
if (!intel_gem_set_context_param(bufmgr->fd, ctx_id,
I915_CONTEXT_PARAM_PRIORITY, priority))
err = -errno;
return err;
}
static bool
bool
iris_hw_context_get_protected(struct iris_bufmgr *bufmgr, uint32_t ctx_id)
{
uint64_t protected_content = 0;
@@ -2132,21 +2110,6 @@ iris_hw_context_get_protected(struct iris_bufmgr *bufmgr, uint32_t ctx_id)
return protected_content;
}
uint32_t
iris_clone_hw_context(struct iris_bufmgr *bufmgr, uint32_t ctx_id)
{
uint32_t new_ctx =
iris_create_hw_context(bufmgr,
iris_hw_context_get_protected(bufmgr, ctx_id));
if (new_ctx) {
int priority = iris_kernel_context_get_priority(bufmgr, ctx_id);
iris_hw_context_set_priority(bufmgr, new_ctx, priority);
}
return new_ctx;
}
void
iris_destroy_kernel_context(struct iris_bufmgr *bufmgr, uint32_t ctx_id)
{

View File

@@ -483,13 +483,11 @@ void* iris_bufmgr_get_aux_map_context(struct iris_bufmgr *bufmgr);
uint32_t iris_create_hw_context(struct iris_bufmgr *bufmgr, bool protected);
uint32_t iris_clone_hw_context(struct iris_bufmgr *bufmgr, uint32_t ctx_id);
int iris_kernel_context_get_priority(struct iris_bufmgr *bufmgr, uint32_t ctx_id);
void iris_hw_context_set_unrecoverable(struct iris_bufmgr *bufmgr,
uint32_t ctx_id);
void iris_hw_context_set_vm_id(struct iris_bufmgr *bufmgr, uint32_t ctx_id);
int iris_hw_context_set_priority(struct iris_bufmgr *bufmgr,
uint32_t ctx_id, int priority);
bool iris_hw_context_get_protected(struct iris_bufmgr *bufmgr, uint32_t ctx_id);
void iris_destroy_kernel_context(struct iris_bufmgr *bufmgr, uint32_t ctx_id);

View File

@@ -34,7 +34,6 @@
#include "iris_resource.h"
#include "iris_screen.h"
#include "iris_utrace.h"
#include "common/intel_defines.h"
#include "common/intel_sample_positions.h"
/**
@@ -360,11 +359,10 @@ iris_create_context(struct pipe_screen *pscreen, void *priv, unsigned flags)
genX_call(devinfo, init_blorp, ice);
genX_call(devinfo, init_query, ice);
int priority = 0;
if (flags & PIPE_CONTEXT_HIGH_PRIORITY)
priority = INTEL_CONTEXT_HIGH_PRIORITY;
ice->priority = IRIS_CONTEXT_HIGH_PRIORITY;
if (flags & PIPE_CONTEXT_LOW_PRIORITY)
priority = INTEL_CONTEXT_LOW_PRIORITY;
ice->priority = IRIS_CONTEXT_LOW_PRIORITY;
if (flags & PIPE_CONTEXT_PROTECTED)
ice->protected = true;
@@ -374,7 +372,7 @@ iris_create_context(struct pipe_screen *pscreen, void *priv, unsigned flags)
/* Do this before initializing the batches */
iris_utrace_init(ice);
iris_init_batches(ice, priority);
iris_init_batches(ice);
screen->vtbl.init_render_context(&ice->batches[IRIS_BATCH_RENDER]);
screen->vtbl.init_compute_context(&ice->batches[IRIS_BATCH_COMPUTE]);

View File

@@ -612,6 +612,12 @@ struct iris_stream_output_target {
bool zero_offset;
};
enum iris_context_priority {
IRIS_CONTEXT_MEDIUM_PRIORITY = 0,
IRIS_CONTEXT_LOW_PRIORITY,
IRIS_CONTEXT_HIGH_PRIORITY
};
/**
* The API context (derived from pipe_context).
*
@@ -642,6 +648,7 @@ struct iris_context {
struct blorp_context blorp;
struct iris_batch batches[IRIS_BATCH_COUNT];
enum iris_context_priority priority;
bool has_engines_context;
struct u_upload_mgr *query_buffer_uploader;