drm/i915: preliminary context support
Very basic code for context setup/destruction in the driver.
Adds the file i915_gem_context.c This file implements HW context
support. On gen5+ a HW context consists of an opaque GPU object which is
referenced at times of context saves and restores. With RC6 enabled,
the context is also referenced as the GPU enters and exists from RC6
(GPU has it's own internal power context, except on gen5). Though
something like a context does exist for the media ring, the code only
supports contexts for the render ring.
In software, there is a distinction between contexts created by the
user, and the default HW context. The default HW context is used by GPU
clients that do not request setup of their own hardware context. The
default context's state is never restored to help prevent programming
errors. This would happen if a client ran and piggy-backed off another
clients GPU state. The default context only exists to give the GPU some
offset to load as the current to invoke a save of the context we
actually care about. In fact, the code could likely be constructed,
albeit in a more complicated fashion, to never use the default context,
though that limits the driver's ability to swap out, and/or destroy
other contexts.
All other contexts are created as a request by the GPU client. These
contexts store GPU state, and thus allow GPU clients to not re-emit
state (and potentially query certain state) at any time. The kernel
driver makes certain that the appropriate commands are inserted.
There are 4 entry points into the contexts, init, fini, open, close.
The names are self-explanatory except that init can be called during
reset, and also during pm thaw/resume. As we expect our context to be
preserved across these events, we do not reinitialize in this case.
As Adam Jackson pointed out, The cutoff of 1MB where a HW context is
considered too big is arbitrary. The reason for this is even though
context sizes are increasing with every generation, they have yet to
eclipse even 32k. If we somehow read back way more than that, it
probably means BIOS has done something strange, or we're running on a
platform that wasn't designed for this.
v2: rename load/unload to init/fini (daniel)
remove ILK support for get_size() (indirectly daniel)
add HAS_HW_CONTEXTS macro to clarify supported platforms (daniel)
added comments (Ben)
Signed-off-by: Ben Widawsky <ben@bwidawsk.net>
2012-06-04 21:42:42 +00:00
|
|
|
/*
|
2019-05-28 09:29:49 +00:00
|
|
|
* SPDX-License-Identifier: MIT
|
drm/i915: preliminary context support
Very basic code for context setup/destruction in the driver.
Adds the file i915_gem_context.c This file implements HW context
support. On gen5+ a HW context consists of an opaque GPU object which is
referenced at times of context saves and restores. With RC6 enabled,
the context is also referenced as the GPU enters and exists from RC6
(GPU has it's own internal power context, except on gen5). Though
something like a context does exist for the media ring, the code only
supports contexts for the render ring.
In software, there is a distinction between contexts created by the
user, and the default HW context. The default HW context is used by GPU
clients that do not request setup of their own hardware context. The
default context's state is never restored to help prevent programming
errors. This would happen if a client ran and piggy-backed off another
clients GPU state. The default context only exists to give the GPU some
offset to load as the current to invoke a save of the context we
actually care about. In fact, the code could likely be constructed,
albeit in a more complicated fashion, to never use the default context,
though that limits the driver's ability to swap out, and/or destroy
other contexts.
All other contexts are created as a request by the GPU client. These
contexts store GPU state, and thus allow GPU clients to not re-emit
state (and potentially query certain state) at any time. The kernel
driver makes certain that the appropriate commands are inserted.
There are 4 entry points into the contexts, init, fini, open, close.
The names are self-explanatory except that init can be called during
reset, and also during pm thaw/resume. As we expect our context to be
preserved across these events, we do not reinitialize in this case.
As Adam Jackson pointed out, The cutoff of 1MB where a HW context is
considered too big is arbitrary. The reason for this is even though
context sizes are increasing with every generation, they have yet to
eclipse even 32k. If we somehow read back way more than that, it
probably means BIOS has done something strange, or we're running on a
platform that wasn't designed for this.
v2: rename load/unload to init/fini (daniel)
remove ILK support for get_size() (indirectly daniel)
add HAS_HW_CONTEXTS macro to clarify supported platforms (daniel)
added comments (Ben)
Signed-off-by: Ben Widawsky <ben@bwidawsk.net>
2012-06-04 21:42:42 +00:00
|
|
|
*
|
2019-05-28 09:29:49 +00:00
|
|
|
* Copyright © 2011-2012 Intel Corporation
|
drm/i915: preliminary context support
Very basic code for context setup/destruction in the driver.
Adds the file i915_gem_context.c This file implements HW context
support. On gen5+ a HW context consists of an opaque GPU object which is
referenced at times of context saves and restores. With RC6 enabled,
the context is also referenced as the GPU enters and exists from RC6
(GPU has it's own internal power context, except on gen5). Though
something like a context does exist for the media ring, the code only
supports contexts for the render ring.
In software, there is a distinction between contexts created by the
user, and the default HW context. The default HW context is used by GPU
clients that do not request setup of their own hardware context. The
default context's state is never restored to help prevent programming
errors. This would happen if a client ran and piggy-backed off another
clients GPU state. The default context only exists to give the GPU some
offset to load as the current to invoke a save of the context we
actually care about. In fact, the code could likely be constructed,
albeit in a more complicated fashion, to never use the default context,
though that limits the driver's ability to swap out, and/or destroy
other contexts.
All other contexts are created as a request by the GPU client. These
contexts store GPU state, and thus allow GPU clients to not re-emit
state (and potentially query certain state) at any time. The kernel
driver makes certain that the appropriate commands are inserted.
There are 4 entry points into the contexts, init, fini, open, close.
The names are self-explanatory except that init can be called during
reset, and also during pm thaw/resume. As we expect our context to be
preserved across these events, we do not reinitialize in this case.
As Adam Jackson pointed out, The cutoff of 1MB where a HW context is
considered too big is arbitrary. The reason for this is even though
context sizes are increasing with every generation, they have yet to
eclipse even 32k. If we somehow read back way more than that, it
probably means BIOS has done something strange, or we're running on a
platform that wasn't designed for this.
v2: rename load/unload to init/fini (daniel)
remove ILK support for get_size() (indirectly daniel)
add HAS_HW_CONTEXTS macro to clarify supported platforms (daniel)
added comments (Ben)
Signed-off-by: Ben Widawsky <ben@bwidawsk.net>
2012-06-04 21:42:42 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file implements HW context support. On gen5+ a HW context consists of an
|
|
|
|
* opaque GPU object which is referenced at times of context saves and restores.
|
|
|
|
* With RC6 enabled, the context is also referenced as the GPU enters and exists
|
|
|
|
* from RC6 (GPU has it's own internal power context, except on gen5). Though
|
|
|
|
* something like a context does exist for the media ring, the code only
|
|
|
|
* supports contexts for the render ring.
|
|
|
|
*
|
|
|
|
* In software, there is a distinction between contexts created by the user,
|
|
|
|
* and the default HW context. The default HW context is used by GPU clients
|
|
|
|
* that do not request setup of their own hardware context. The default
|
|
|
|
* context's state is never restored to help prevent programming errors. This
|
|
|
|
* would happen if a client ran and piggy-backed off another clients GPU state.
|
|
|
|
* The default context only exists to give the GPU some offset to load as the
|
|
|
|
* current to invoke a save of the context we actually care about. In fact, the
|
|
|
|
* code could likely be constructed, albeit in a more complicated fashion, to
|
|
|
|
* never use the default context, though that limits the driver's ability to
|
|
|
|
* swap out, and/or destroy other contexts.
|
|
|
|
*
|
|
|
|
* All other contexts are created as a request by the GPU client. These contexts
|
|
|
|
* store GPU state, and thus allow GPU clients to not re-emit state (and
|
|
|
|
* potentially query certain state) at any time. The kernel driver makes
|
|
|
|
* certain that the appropriate commands are inserted.
|
|
|
|
*
|
|
|
|
* The context life cycle is semi-complicated in that context BOs may live
|
|
|
|
* longer than the context itself because of the way the hardware, and object
|
|
|
|
* tracking works. Below is a very crude representation of the state machine
|
|
|
|
* describing the context life.
|
|
|
|
* refcount pincount active
|
|
|
|
* S0: initial state 0 0 0
|
|
|
|
* S1: context created 1 0 0
|
|
|
|
* S2: context is currently running 2 1 X
|
|
|
|
* S3: GPU referenced, but not current 2 0 1
|
|
|
|
* S4: context is current, but destroyed 1 1 0
|
|
|
|
* S5: like S3, but destroyed 1 0 1
|
|
|
|
*
|
|
|
|
* The most common (but not all) transitions:
|
|
|
|
* S0->S1: client creates a context
|
|
|
|
* S1->S2: client submits execbuf with context
|
|
|
|
* S2->S3: other clients submits execbuf with context
|
|
|
|
* S3->S1: context object was retired
|
|
|
|
* S3->S2: clients submits another execbuf
|
|
|
|
* S2->S4: context destroy called with current context
|
|
|
|
* S3->S5->S0: destroy path
|
|
|
|
* S4->S5->S0: destroy path on current context
|
|
|
|
*
|
|
|
|
* There are two confusing terms used above:
|
|
|
|
* The "current context" means the context which is currently running on the
|
2013-08-30 13:40:26 +00:00
|
|
|
* GPU. The GPU has loaded its state already and has stored away the gtt
|
drm/i915: preliminary context support
Very basic code for context setup/destruction in the driver.
Adds the file i915_gem_context.c This file implements HW context
support. On gen5+ a HW context consists of an opaque GPU object which is
referenced at times of context saves and restores. With RC6 enabled,
the context is also referenced as the GPU enters and exists from RC6
(GPU has it's own internal power context, except on gen5). Though
something like a context does exist for the media ring, the code only
supports contexts for the render ring.
In software, there is a distinction between contexts created by the
user, and the default HW context. The default HW context is used by GPU
clients that do not request setup of their own hardware context. The
default context's state is never restored to help prevent programming
errors. This would happen if a client ran and piggy-backed off another
clients GPU state. The default context only exists to give the GPU some
offset to load as the current to invoke a save of the context we
actually care about. In fact, the code could likely be constructed,
albeit in a more complicated fashion, to never use the default context,
though that limits the driver's ability to swap out, and/or destroy
other contexts.
All other contexts are created as a request by the GPU client. These
contexts store GPU state, and thus allow GPU clients to not re-emit
state (and potentially query certain state) at any time. The kernel
driver makes certain that the appropriate commands are inserted.
There are 4 entry points into the contexts, init, fini, open, close.
The names are self-explanatory except that init can be called during
reset, and also during pm thaw/resume. As we expect our context to be
preserved across these events, we do not reinitialize in this case.
As Adam Jackson pointed out, The cutoff of 1MB where a HW context is
considered too big is arbitrary. The reason for this is even though
context sizes are increasing with every generation, they have yet to
eclipse even 32k. If we somehow read back way more than that, it
probably means BIOS has done something strange, or we're running on a
platform that wasn't designed for this.
v2: rename load/unload to init/fini (daniel)
remove ILK support for get_size() (indirectly daniel)
add HAS_HW_CONTEXTS macro to clarify supported platforms (daniel)
added comments (Ben)
Signed-off-by: Ben Widawsky <ben@bwidawsk.net>
2012-06-04 21:42:42 +00:00
|
|
|
* offset of the BO. The GPU is not actively referencing the data at this
|
|
|
|
* offset, but it will on the next context switch. The only way to avoid this
|
|
|
|
* is to do a GPU reset.
|
|
|
|
*
|
|
|
|
* An "active context' is one which was previously the "current context" and is
|
|
|
|
* on the active list waiting for the next context switch to occur. Until this
|
|
|
|
* happens, the object must remain at the same gtt offset. It is therefore
|
|
|
|
* possible to destroy a context, but it is still active.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2017-06-16 14:05:16 +00:00
|
|
|
#include <linux/log2.h>
|
drm/i915: Load balancing across a virtual engine
Having allowed the user to define a set of engines that they will want
to only use, we go one step further and allow them to bind those engines
into a single virtual instance. Submitting a batch to the virtual engine
will then forward it to any one of the set in a manner as best to
distribute load. The virtual engine has a single timeline across all
engines (it operates as a single queue), so it is not able to concurrently
run batches across multiple engines by itself; that is left up to the user
to submit multiple concurrent batches to multiple queues. Multiple users
will be load balanced across the system.
The mechanism used for load balancing in this patch is a late greedy
balancer. When a request is ready for execution, it is added to each
engine's queue, and when an engine is ready for its next request it
claims it from the virtual engine. The first engine to do so, wins, i.e.
the request is executed at the earliest opportunity (idle moment) in the
system.
As not all HW is created equal, the user is still able to skip the
virtual engine and execute the batch on a specific engine, all within the
same queue. It will then be executed in order on the correct engine,
with execution on other virtual engines being moved away due to the load
detection.
A couple of areas for potential improvement left!
- The virtual engine always take priority over equal-priority tasks.
Mostly broken up by applying FQ_CODEL rules for prioritising new clients,
and hopefully the virtual and real engines are not then congested (i.e.
all work is via virtual engines, or all work is to the real engine).
- We require the breadcrumb irq around every virtual engine request. For
normal engines, we eliminate the need for the slow round trip via
interrupt by using the submit fence and queueing in order. For virtual
engines, we have to allow any job to transfer to a new ring, and cannot
coalesce the submissions, so require the completion fence instead,
forcing the persistent use of interrupts.
- We only drip feed single requests through each virtual engine and onto
the physical engines, even if there was enough work to fill all ELSP,
leaving small stalls with an idle CS event at the end of every request.
Could we be greedy and fill both slots? Being lazy is virtuous for load
distribution on less-than-full workloads though.
Other areas of improvement are more general, such as reducing lock
contention, reducing dispatch overhead, looking at direct submission
rather than bouncing around tasklets etc.
sseu: Lift the restriction to allow sseu to be reconfigured on virtual
engines composed of RENDER_CLASS (rcs).
v2: macroize check_user_mbz()
v3: Cancel virtual engines on wedging
v4: Commence commenting
v5: Replace 64b sibling_mask with a list of class:instance
v6: Drop the one-element array in the uabi
v7: Assert it is an virtual engine in to_virtual_engine()
v8: Skip over holes in [class][inst] so we can selftest with (vcs0, vcs2)
Link: https://github.com/intel/media-driver/pull/283
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20190521211134.16117-6-chris@chris-wilson.co.uk
2019-05-21 21:11:30 +00:00
|
|
|
#include <linux/nospec.h>
|
2019-04-24 17:48:39 +00:00
|
|
|
|
2021-07-08 15:48:12 +00:00
|
|
|
#include <drm/drm_syncobj.h>
|
|
|
|
|
2020-01-07 13:40:09 +00:00
|
|
|
#include "gt/gen6_ppgtt.h"
|
2019-12-20 10:12:29 +00:00
|
|
|
#include "gt/intel_context.h"
|
2020-02-25 19:22:05 +00:00
|
|
|
#include "gt/intel_context_param.h"
|
2019-10-23 13:31:07 +00:00
|
|
|
#include "gt/intel_engine_heartbeat.h"
|
2019-08-06 12:43:00 +00:00
|
|
|
#include "gt/intel_engine_user.h"
|
2020-12-16 13:54:52 +00:00
|
|
|
#include "gt/intel_gpu_commands.h"
|
2019-10-24 10:03:44 +00:00
|
|
|
#include "gt/intel_ring.h"
|
2019-04-24 17:48:39 +00:00
|
|
|
|
2019-05-28 09:29:49 +00:00
|
|
|
#include "i915_gem_context.h"
|
2014-11-10 13:44:31 +00:00
|
|
|
#include "i915_trace.h"
|
2019-03-22 09:23:23 +00:00
|
|
|
#include "i915_user_extensions.h"
|
drm/i915: preliminary context support
Very basic code for context setup/destruction in the driver.
Adds the file i915_gem_context.c This file implements HW context
support. On gen5+ a HW context consists of an opaque GPU object which is
referenced at times of context saves and restores. With RC6 enabled,
the context is also referenced as the GPU enters and exists from RC6
(GPU has it's own internal power context, except on gen5). Though
something like a context does exist for the media ring, the code only
supports contexts for the render ring.
In software, there is a distinction between contexts created by the
user, and the default HW context. The default HW context is used by GPU
clients that do not request setup of their own hardware context. The
default context's state is never restored to help prevent programming
errors. This would happen if a client ran and piggy-backed off another
clients GPU state. The default context only exists to give the GPU some
offset to load as the current to invoke a save of the context we
actually care about. In fact, the code could likely be constructed,
albeit in a more complicated fashion, to never use the default context,
though that limits the driver's ability to swap out, and/or destroy
other contexts.
All other contexts are created as a request by the GPU client. These
contexts store GPU state, and thus allow GPU clients to not re-emit
state (and potentially query certain state) at any time. The kernel
driver makes certain that the appropriate commands are inserted.
There are 4 entry points into the contexts, init, fini, open, close.
The names are self-explanatory except that init can be called during
reset, and also during pm thaw/resume. As we expect our context to be
preserved across these events, we do not reinitialize in this case.
As Adam Jackson pointed out, The cutoff of 1MB where a HW context is
considered too big is arbitrary. The reason for this is even though
context sizes are increasing with every generation, they have yet to
eclipse even 32k. If we somehow read back way more than that, it
probably means BIOS has done something strange, or we're running on a
platform that wasn't designed for this.
v2: rename load/unload to init/fini (daniel)
remove ILK support for get_size() (indirectly daniel)
add HAS_HW_CONTEXTS macro to clarify supported platforms (daniel)
added comments (Ben)
Signed-off-by: Ben Widawsky <ben@bwidawsk.net>
2012-06-04 21:42:42 +00:00
|
|
|
|
2016-04-28 08:56:41 +00:00
|
|
|
#define ALL_L3_SLICES(dev) (1 << NUM_L3_SLICES(dev)) - 1
|
|
|
|
|
2021-07-27 12:10:31 +00:00
|
|
|
static struct kmem_cache *slab_luts;
|
2019-02-28 10:20:34 +00:00
|
|
|
|
|
|
|
struct i915_lut_handle *i915_lut_handle_alloc(void)
|
|
|
|
{
|
2021-07-27 12:10:31 +00:00
|
|
|
return kmem_cache_alloc(slab_luts, GFP_KERNEL);
|
2019-02-28 10:20:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void i915_lut_handle_free(struct i915_lut_handle *lut)
|
|
|
|
{
|
2021-07-27 12:10:31 +00:00
|
|
|
return kmem_cache_free(slab_luts, lut);
|
2019-02-28 10:20:34 +00:00
|
|
|
}
|
|
|
|
|
2017-08-16 08:52:08 +00:00
|
|
|
static void lut_close(struct i915_gem_context *ctx)
|
2017-06-16 14:05:16 +00:00
|
|
|
{
|
2017-08-16 08:52:08 +00:00
|
|
|
struct radix_tree_iter iter;
|
|
|
|
void __rcu **slot;
|
|
|
|
|
2020-07-03 00:43:06 +00:00
|
|
|
mutex_lock(&ctx->lut_mutex);
|
2017-10-26 13:00:32 +00:00
|
|
|
rcu_read_lock();
|
2017-08-16 08:52:08 +00:00
|
|
|
radix_tree_for_each_slot(slot, &ctx->handles_vma, &iter, 0) {
|
|
|
|
struct i915_vma *vma = rcu_dereference_raw(*slot);
|
2019-06-06 11:23:20 +00:00
|
|
|
struct drm_i915_gem_object *obj = vma->obj;
|
|
|
|
struct i915_lut_handle *lut;
|
|
|
|
|
|
|
|
if (!kref_get_unless_zero(&obj->base.refcount))
|
|
|
|
continue;
|
2017-06-16 14:05:16 +00:00
|
|
|
|
2020-07-01 08:44:39 +00:00
|
|
|
spin_lock(&obj->lut_lock);
|
2019-06-06 11:23:20 +00:00
|
|
|
list_for_each_entry(lut, &obj->lut_list, obj_link) {
|
|
|
|
if (lut->ctx != ctx)
|
|
|
|
continue;
|
2019-03-22 09:23:23 +00:00
|
|
|
|
2019-06-06 11:23:20 +00:00
|
|
|
if (lut->handle != iter.index)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
list_del(&lut->obj_link);
|
|
|
|
break;
|
|
|
|
}
|
2020-07-01 08:44:39 +00:00
|
|
|
spin_unlock(&obj->lut_lock);
|
2019-06-06 11:23:20 +00:00
|
|
|
|
|
|
|
if (&lut->obj_link != &obj->lut_list) {
|
|
|
|
i915_lut_handle_free(lut);
|
|
|
|
radix_tree_iter_delete(&ctx->handles_vma, &iter, slot);
|
2020-04-22 19:05:58 +00:00
|
|
|
i915_vma_close(vma);
|
2019-06-06 11:23:20 +00:00
|
|
|
i915_gem_object_put(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
i915_gem_object_put(obj);
|
2017-06-16 14:05:16 +00:00
|
|
|
}
|
2017-10-26 13:00:32 +00:00
|
|
|
rcu_read_unlock();
|
2020-07-03 00:43:06 +00:00
|
|
|
mutex_unlock(&ctx->lut_mutex);
|
2017-06-16 14:05:16 +00:00
|
|
|
}
|
|
|
|
|
2019-04-26 16:33:32 +00:00
|
|
|
static struct intel_context *
|
drm/i915: Allow a context to define its set of engines
Over the last few years, we have debated how to extend the user API to
support an increase in the number of engines, that may be sparse and
even be heterogeneous within a class (not all video decoders created
equal). We settled on using (class, instance) tuples to identify a
specific engine, with an API for the user to construct a map of engines
to capabilities. Into this picture, we then add a challenge of virtual
engines; one user engine that maps behind the scenes to any number of
physical engines. To keep it general, we want the user to have full
control over that mapping. To that end, we allow the user to constrain a
context to define the set of engines that it can access, order fully
controlled by the user via (class, instance). With such precise control
in context setup, we can continue to use the existing execbuf uABI of
specifying a single index; only now it doesn't automagically map onto
the engines, it uses the user defined engine map from the context.
v2: Fixup freeing of local on success of get_engines()
v3: Allow empty engines[]
v4: s/nengine/num_engines/
v5: Replace 64 limit on num_engines with a note that execbuf is
currently limited to only using the first 64 engines.
v6: Actually use the engines_mutex to guard the ctx->engines.
Testcase: igt/gem_ctx_engines
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20190521211134.16117-2-chris@chris-wilson.co.uk
2019-05-21 21:11:26 +00:00
|
|
|
lookup_user_engine(struct i915_gem_context *ctx,
|
|
|
|
unsigned long flags,
|
|
|
|
const struct i915_engine_class_instance *ci)
|
|
|
|
#define LOOKUP_USER_INDEX BIT(0)
|
2019-04-26 16:33:32 +00:00
|
|
|
{
|
drm/i915: Allow a context to define its set of engines
Over the last few years, we have debated how to extend the user API to
support an increase in the number of engines, that may be sparse and
even be heterogeneous within a class (not all video decoders created
equal). We settled on using (class, instance) tuples to identify a
specific engine, with an API for the user to construct a map of engines
to capabilities. Into this picture, we then add a challenge of virtual
engines; one user engine that maps behind the scenes to any number of
physical engines. To keep it general, we want the user to have full
control over that mapping. To that end, we allow the user to constrain a
context to define the set of engines that it can access, order fully
controlled by the user via (class, instance). With such precise control
in context setup, we can continue to use the existing execbuf uABI of
specifying a single index; only now it doesn't automagically map onto
the engines, it uses the user defined engine map from the context.
v2: Fixup freeing of local on success of get_engines()
v3: Allow empty engines[]
v4: s/nengine/num_engines/
v5: Replace 64 limit on num_engines with a note that execbuf is
currently limited to only using the first 64 engines.
v6: Actually use the engines_mutex to guard the ctx->engines.
Testcase: igt/gem_ctx_engines
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20190521211134.16117-2-chris@chris-wilson.co.uk
2019-05-21 21:11:26 +00:00
|
|
|
int idx;
|
2019-04-26 16:33:32 +00:00
|
|
|
|
drm/i915: Allow a context to define its set of engines
Over the last few years, we have debated how to extend the user API to
support an increase in the number of engines, that may be sparse and
even be heterogeneous within a class (not all video decoders created
equal). We settled on using (class, instance) tuples to identify a
specific engine, with an API for the user to construct a map of engines
to capabilities. Into this picture, we then add a challenge of virtual
engines; one user engine that maps behind the scenes to any number of
physical engines. To keep it general, we want the user to have full
control over that mapping. To that end, we allow the user to constrain a
context to define the set of engines that it can access, order fully
controlled by the user via (class, instance). With such precise control
in context setup, we can continue to use the existing execbuf uABI of
specifying a single index; only now it doesn't automagically map onto
the engines, it uses the user defined engine map from the context.
v2: Fixup freeing of local on success of get_engines()
v3: Allow empty engines[]
v4: s/nengine/num_engines/
v5: Replace 64 limit on num_engines with a note that execbuf is
currently limited to only using the first 64 engines.
v6: Actually use the engines_mutex to guard the ctx->engines.
Testcase: igt/gem_ctx_engines
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20190521211134.16117-2-chris@chris-wilson.co.uk
2019-05-21 21:11:26 +00:00
|
|
|
if (!!(flags & LOOKUP_USER_INDEX) != i915_gem_context_user_engines(ctx))
|
2019-04-26 16:33:32 +00:00
|
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
|
drm/i915: Allow a context to define its set of engines
Over the last few years, we have debated how to extend the user API to
support an increase in the number of engines, that may be sparse and
even be heterogeneous within a class (not all video decoders created
equal). We settled on using (class, instance) tuples to identify a
specific engine, with an API for the user to construct a map of engines
to capabilities. Into this picture, we then add a challenge of virtual
engines; one user engine that maps behind the scenes to any number of
physical engines. To keep it general, we want the user to have full
control over that mapping. To that end, we allow the user to constrain a
context to define the set of engines that it can access, order fully
controlled by the user via (class, instance). With such precise control
in context setup, we can continue to use the existing execbuf uABI of
specifying a single index; only now it doesn't automagically map onto
the engines, it uses the user defined engine map from the context.
v2: Fixup freeing of local on success of get_engines()
v3: Allow empty engines[]
v4: s/nengine/num_engines/
v5: Replace 64 limit on num_engines with a note that execbuf is
currently limited to only using the first 64 engines.
v6: Actually use the engines_mutex to guard the ctx->engines.
Testcase: igt/gem_ctx_engines
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20190521211134.16117-2-chris@chris-wilson.co.uk
2019-05-21 21:11:26 +00:00
|
|
|
if (!i915_gem_context_user_engines(ctx)) {
|
|
|
|
struct intel_engine_cs *engine;
|
|
|
|
|
|
|
|
engine = intel_engine_lookup_user(ctx->i915,
|
|
|
|
ci->engine_class,
|
|
|
|
ci->engine_instance);
|
|
|
|
if (!engine)
|
|
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
|
2019-08-08 11:06:12 +00:00
|
|
|
idx = engine->legacy_idx;
|
drm/i915: Allow a context to define its set of engines
Over the last few years, we have debated how to extend the user API to
support an increase in the number of engines, that may be sparse and
even be heterogeneous within a class (not all video decoders created
equal). We settled on using (class, instance) tuples to identify a
specific engine, with an API for the user to construct a map of engines
to capabilities. Into this picture, we then add a challenge of virtual
engines; one user engine that maps behind the scenes to any number of
physical engines. To keep it general, we want the user to have full
control over that mapping. To that end, we allow the user to constrain a
context to define the set of engines that it can access, order fully
controlled by the user via (class, instance). With such precise control
in context setup, we can continue to use the existing execbuf uABI of
specifying a single index; only now it doesn't automagically map onto
the engines, it uses the user defined engine map from the context.
v2: Fixup freeing of local on success of get_engines()
v3: Allow empty engines[]
v4: s/nengine/num_engines/
v5: Replace 64 limit on num_engines with a note that execbuf is
currently limited to only using the first 64 engines.
v6: Actually use the engines_mutex to guard the ctx->engines.
Testcase: igt/gem_ctx_engines
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20190521211134.16117-2-chris@chris-wilson.co.uk
2019-05-21 21:11:26 +00:00
|
|
|
} else {
|
|
|
|
idx = ci->engine_instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
return i915_gem_context_get_engine(ctx, idx);
|
2019-04-26 16:33:32 +00:00
|
|
|
}
|
|
|
|
|
2021-07-08 15:48:19 +00:00
|
|
|
static int validate_priority(struct drm_i915_private *i915,
|
|
|
|
const struct drm_i915_gem_context_param *args)
|
|
|
|
{
|
|
|
|
s64 priority = args->value;
|
|
|
|
|
|
|
|
if (args->size)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (!(i915->caps.scheduler & I915_SCHEDULER_CAP_PRIORITY))
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
if (priority > I915_CONTEXT_MAX_USER_PRIORITY ||
|
|
|
|
priority < I915_CONTEXT_MIN_USER_PRIORITY)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (priority > I915_CONTEXT_DEFAULT_PRIORITY &&
|
|
|
|
!capable(CAP_SYS_NICE))
|
|
|
|
return -EPERM;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-07-08 15:48:21 +00:00
|
|
|
static void proto_context_close(struct i915_gem_proto_context *pc)
|
|
|
|
{
|
2021-07-08 15:48:26 +00:00
|
|
|
int i;
|
|
|
|
|
2021-07-08 15:48:21 +00:00
|
|
|
if (pc->vm)
|
|
|
|
i915_vm_put(pc->vm);
|
2021-07-08 15:48:26 +00:00
|
|
|
if (pc->user_engines) {
|
|
|
|
for (i = 0; i < pc->num_user_engines; i++)
|
|
|
|
kfree(pc->user_engines[i].siblings);
|
|
|
|
kfree(pc->user_engines);
|
|
|
|
}
|
2021-07-08 15:48:21 +00:00
|
|
|
kfree(pc);
|
|
|
|
}
|
|
|
|
|
2021-07-08 15:48:26 +00:00
|
|
|
static int proto_context_set_persistence(struct drm_i915_private *i915,
|
|
|
|
struct i915_gem_proto_context *pc,
|
|
|
|
bool persist)
|
|
|
|
{
|
|
|
|
if (persist) {
|
|
|
|
/*
|
|
|
|
* Only contexts that are short-lived [that will expire or be
|
|
|
|
* reset] are allowed to survive past termination. We require
|
|
|
|
* hangcheck to ensure that the persistent requests are healthy.
|
|
|
|
*/
|
|
|
|
if (!i915->params.enable_hangcheck)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
pc->user_flags |= BIT(UCONTEXT_PERSISTENCE);
|
|
|
|
} else {
|
|
|
|
/* To cancel a context we use "preempt-to-idle" */
|
|
|
|
if (!(i915->caps.scheduler & I915_SCHEDULER_CAP_PREEMPTION))
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the cancel fails, we then need to reset, cleanly!
|
|
|
|
*
|
|
|
|
* If the per-engine reset fails, all hope is lost! We resort
|
|
|
|
* to a full GPU reset in that unlikely case, but realistically
|
|
|
|
* if the engine could not reset, the full reset does not fare
|
|
|
|
* much better. The damage has been done.
|
|
|
|
*
|
|
|
|
* However, if we cannot reset an engine by itself, we cannot
|
|
|
|
* cleanup a hanging persistent context without causing
|
|
|
|
* colateral damage, and we should not pretend we can by
|
|
|
|
* exposing the interface.
|
|
|
|
*/
|
|
|
|
if (!intel_has_reset_engine(&i915->gt))
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
pc->user_flags &= ~BIT(UCONTEXT_PERSISTENCE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-07-08 15:48:21 +00:00
|
|
|
static struct i915_gem_proto_context *
|
|
|
|
proto_context_create(struct drm_i915_private *i915, unsigned int flags)
|
|
|
|
{
|
|
|
|
struct i915_gem_proto_context *pc, *err;
|
|
|
|
|
|
|
|
pc = kzalloc(sizeof(*pc), GFP_KERNEL);
|
|
|
|
if (!pc)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
2021-07-08 15:48:26 +00:00
|
|
|
pc->num_user_engines = -1;
|
|
|
|
pc->user_engines = NULL;
|
2021-07-08 15:48:21 +00:00
|
|
|
pc->user_flags = BIT(UCONTEXT_BANNABLE) |
|
|
|
|
BIT(UCONTEXT_RECOVERABLE);
|
|
|
|
if (i915->params.enable_hangcheck)
|
|
|
|
pc->user_flags |= BIT(UCONTEXT_PERSISTENCE);
|
|
|
|
pc->sched.priority = I915_PRIORITY_NORMAL;
|
|
|
|
|
|
|
|
if (flags & I915_CONTEXT_CREATE_FLAGS_SINGLE_TIMELINE) {
|
|
|
|
if (!HAS_EXECLISTS(i915)) {
|
|
|
|
err = ERR_PTR(-EINVAL);
|
|
|
|
goto proto_close;
|
|
|
|
}
|
|
|
|
pc->single_timeline = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pc;
|
|
|
|
|
|
|
|
proto_close:
|
|
|
|
proto_context_close(pc);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
drm/i915/gem: Delay context creation (v3)
The current context uAPI allows for two methods of setting context
parameters: SET_CONTEXT_PARAM and CONTEXT_CREATE_EXT_SETPARAM. The
former is allowed to be called at any time while the later happens as
part of GEM_CONTEXT_CREATE. Currently, everything settable via one is
settable via the other. While some params are fairly simple and setting
them on a live context is harmless such as the context priority, others
are far trickier such as the VM or the set of engines. In order to swap
out the VM, for instance, we have to delay until all current in-flight
work is complete, swap in the new VM, and then continue. This leads to
a plethora of potential race conditions we'd really rather avoid.
In previous patches, we added a i915_gem_proto_context struct which is
capable of storing and tracking all such create parameters. This commit
delays the creation of the actual context until after the client is done
configuring it with SET_CONTEXT_PARAM. From the perspective of the
client, it has the same u32 context ID the whole time. From the
perspective of i915, however, it's an i915_gem_proto_context right up
until the point where we attempt to do something which the proto-context
can't handle. Then the real context gets created.
This is accomplished via a little xarray dance. When GEM_CONTEXT_CREATE
is called, we create a proto-context, reserve a slot in context_xa but
leave it NULL, the proto-context in the corresponding slot in
proto_context_xa. Then, whenever we go to look up a context, we first
check context_xa. If it's there, we return the i915_gem_context and
we're done. If it's not, we look in proto_context_xa and, if we find it
there, we create the actual context and kill the proto-context.
In order for this dance to work properly, everything which ever touches
a proto-context is guarded by drm_i915_file_private::proto_context_lock,
including context creation. Yes, this means context creation now takes
a giant global lock but it can't really be helped and that should never
be on any driver's fast-path anyway.
v2 (Daniel Vetter):
- Commit message grammatical fixes.
- Use WARN_ON instead of GEM_BUG_ON
- Rename lazy_create_context_locked to finalize_create_context_locked
- Rework the control-flow logic in the setparam ioctl
- Better documentation all around
v3 (kernel test robot):
- Make finalize_create_context_locked static
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/20210708154835.528166-25-jason@jlekstrand.net
2021-07-08 15:48:29 +00:00
|
|
|
static int proto_context_register_locked(struct drm_i915_file_private *fpriv,
|
|
|
|
struct i915_gem_proto_context *pc,
|
|
|
|
u32 *id)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
void *old;
|
|
|
|
|
|
|
|
lockdep_assert_held(&fpriv->proto_context_lock);
|
|
|
|
|
|
|
|
ret = xa_alloc(&fpriv->context_xa, id, NULL, xa_limit_32b, GFP_KERNEL);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
old = xa_store(&fpriv->proto_context_xa, *id, pc, GFP_KERNEL);
|
|
|
|
if (xa_is_err(old)) {
|
|
|
|
xa_erase(&fpriv->context_xa, *id);
|
|
|
|
return xa_err(old);
|
|
|
|
}
|
|
|
|
WARN_ON(old);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int proto_context_register(struct drm_i915_file_private *fpriv,
|
|
|
|
struct i915_gem_proto_context *pc,
|
|
|
|
u32 *id)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
mutex_lock(&fpriv->proto_context_lock);
|
|
|
|
ret = proto_context_register_locked(fpriv, pc, id);
|
|
|
|
mutex_unlock(&fpriv->proto_context_lock);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-07-08 15:48:26 +00:00
|
|
|
static int set_proto_ctx_vm(struct drm_i915_file_private *fpriv,
|
|
|
|
struct i915_gem_proto_context *pc,
|
|
|
|
const struct drm_i915_gem_context_param *args)
|
|
|
|
{
|
|
|
|
struct drm_i915_private *i915 = fpriv->dev_priv;
|
|
|
|
struct i915_address_space *vm;
|
|
|
|
|
|
|
|
if (args->size)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (!HAS_FULL_PPGTT(i915))
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
if (upper_32_bits(args->value))
|
|
|
|
return -ENOENT;
|
|
|
|
|
|
|
|
vm = i915_gem_vm_lookup(fpriv, args->value);
|
|
|
|
if (!vm)
|
|
|
|
return -ENOENT;
|
|
|
|
|
|
|
|
if (pc->vm)
|
|
|
|
i915_vm_put(pc->vm);
|
|
|
|
pc->vm = vm;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct set_proto_ctx_engines {
|
|
|
|
struct drm_i915_private *i915;
|
|
|
|
unsigned num_engines;
|
|
|
|
struct i915_gem_proto_engine *engines;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
set_proto_ctx_engines_balance(struct i915_user_extension __user *base,
|
|
|
|
void *data)
|
|
|
|
{
|
|
|
|
struct i915_context_engines_load_balance __user *ext =
|
|
|
|
container_of_user(base, typeof(*ext), base);
|
|
|
|
const struct set_proto_ctx_engines *set = data;
|
|
|
|
struct drm_i915_private *i915 = set->i915;
|
|
|
|
struct intel_engine_cs **siblings;
|
|
|
|
u16 num_siblings, idx;
|
|
|
|
unsigned int n;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
if (!HAS_EXECLISTS(i915))
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
if (get_user(idx, &ext->engine_index))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
if (idx >= set->num_engines) {
|
|
|
|
drm_dbg(&i915->drm, "Invalid placement value, %d >= %d\n",
|
|
|
|
idx, set->num_engines);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
idx = array_index_nospec(idx, set->num_engines);
|
|
|
|
if (set->engines[idx].type != I915_GEM_ENGINE_TYPE_INVALID) {
|
|
|
|
drm_dbg(&i915->drm,
|
|
|
|
"Invalid placement[%d], already occupied\n", idx);
|
|
|
|
return -EEXIST;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (get_user(num_siblings, &ext->num_siblings))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
err = check_user_mbz(&ext->flags);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
err = check_user_mbz(&ext->mbz64);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
if (num_siblings == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
siblings = kmalloc_array(num_siblings, sizeof(*siblings), GFP_KERNEL);
|
|
|
|
if (!siblings)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
for (n = 0; n < num_siblings; n++) {
|
|
|
|
struct i915_engine_class_instance ci;
|
|
|
|
|
|
|
|
if (copy_from_user(&ci, &ext->engines[n], sizeof(ci))) {
|
|
|
|
err = -EFAULT;
|
|
|
|
goto err_siblings;
|
|
|
|
}
|
|
|
|
|
|
|
|
siblings[n] = intel_engine_lookup_user(i915,
|
|
|
|
ci.engine_class,
|
|
|
|
ci.engine_instance);
|
|
|
|
if (!siblings[n]) {
|
|
|
|
drm_dbg(&i915->drm,
|
|
|
|
"Invalid sibling[%d]: { class:%d, inst:%d }\n",
|
|
|
|
n, ci.engine_class, ci.engine_instance);
|
|
|
|
err = -EINVAL;
|
|
|
|
goto err_siblings;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (num_siblings == 1) {
|
|
|
|
set->engines[idx].type = I915_GEM_ENGINE_TYPE_PHYSICAL;
|
|
|
|
set->engines[idx].engine = siblings[0];
|
|
|
|
kfree(siblings);
|
|
|
|
} else {
|
|
|
|
set->engines[idx].type = I915_GEM_ENGINE_TYPE_BALANCED;
|
|
|
|
set->engines[idx].num_siblings = num_siblings;
|
|
|
|
set->engines[idx].siblings = siblings;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_siblings:
|
|
|
|
kfree(siblings);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
set_proto_ctx_engines_bond(struct i915_user_extension __user *base, void *data)
|
|
|
|
{
|
|
|
|
struct i915_context_engines_bond __user *ext =
|
|
|
|
container_of_user(base, typeof(*ext), base);
|
|
|
|
const struct set_proto_ctx_engines *set = data;
|
|
|
|
struct drm_i915_private *i915 = set->i915;
|
|
|
|
struct i915_engine_class_instance ci;
|
|
|
|
struct intel_engine_cs *master;
|
|
|
|
u16 idx, num_bonds;
|
|
|
|
int err, n;
|
|
|
|
|
|
|
|
if (get_user(idx, &ext->virtual_index))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
if (idx >= set->num_engines) {
|
|
|
|
drm_dbg(&i915->drm,
|
|
|
|
"Invalid index for virtual engine: %d >= %d\n",
|
|
|
|
idx, set->num_engines);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
idx = array_index_nospec(idx, set->num_engines);
|
|
|
|
if (set->engines[idx].type == I915_GEM_ENGINE_TYPE_INVALID) {
|
|
|
|
drm_dbg(&i915->drm, "Invalid engine at %d\n", idx);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (set->engines[idx].type != I915_GEM_ENGINE_TYPE_PHYSICAL) {
|
|
|
|
drm_dbg(&i915->drm,
|
|
|
|
"Bonding with virtual engines not allowed\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = check_user_mbz(&ext->flags);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
for (n = 0; n < ARRAY_SIZE(ext->mbz64); n++) {
|
|
|
|
err = check_user_mbz(&ext->mbz64[n]);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (copy_from_user(&ci, &ext->master, sizeof(ci)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
master = intel_engine_lookup_user(i915,
|
|
|
|
ci.engine_class,
|
|
|
|
ci.engine_instance);
|
|
|
|
if (!master) {
|
|
|
|
drm_dbg(&i915->drm,
|
|
|
|
"Unrecognised master engine: { class:%u, instance:%u }\n",
|
|
|
|
ci.engine_class, ci.engine_instance);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2021-07-27 00:23:19 +00:00
|
|
|
if (intel_engine_uses_guc(master)) {
|
|
|
|
DRM_DEBUG("bonding extension not supported with GuC submission");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2021-07-08 15:48:26 +00:00
|
|
|
if (get_user(num_bonds, &ext->num_bonds))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
for (n = 0; n < num_bonds; n++) {
|
|
|
|
struct intel_engine_cs *bond;
|
|
|
|
|
|
|
|
if (copy_from_user(&ci, &ext->engines[n], sizeof(ci)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
bond = intel_engine_lookup_user(i915,
|
|
|
|
ci.engine_class,
|
|
|
|
ci.engine_instance);
|
|
|
|
if (!bond) {
|
|
|
|
drm_dbg(&i915->drm,
|
|
|
|
"Unrecognised engine[%d] for bonding: { class:%d, instance: %d }\n",
|
|
|
|
n, ci.engine_class, ci.engine_instance);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const i915_user_extension_fn set_proto_ctx_engines_extensions[] = {
|
|
|
|
[I915_CONTEXT_ENGINES_EXT_LOAD_BALANCE] = set_proto_ctx_engines_balance,
|
|
|
|
[I915_CONTEXT_ENGINES_EXT_BOND] = set_proto_ctx_engines_bond,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int set_proto_ctx_engines(struct drm_i915_file_private *fpriv,
|
|
|
|
struct i915_gem_proto_context *pc,
|
|
|
|
const struct drm_i915_gem_context_param *args)
|
|
|
|
{
|
|
|
|
struct drm_i915_private *i915 = fpriv->dev_priv;
|
|
|
|
struct set_proto_ctx_engines set = { .i915 = i915 };
|
|
|
|
struct i915_context_param_engines __user *user =
|
|
|
|
u64_to_user_ptr(args->value);
|
|
|
|
unsigned int n;
|
|
|
|
u64 extensions;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
if (pc->num_user_engines >= 0) {
|
|
|
|
drm_dbg(&i915->drm, "Cannot set engines twice");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (args->size < sizeof(*user) ||
|
|
|
|
!IS_ALIGNED(args->size - sizeof(*user), sizeof(*user->engines))) {
|
|
|
|
drm_dbg(&i915->drm, "Invalid size for engine array: %d\n",
|
|
|
|
args->size);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
set.num_engines = (args->size - sizeof(*user)) / sizeof(*user->engines);
|
|
|
|
/* RING_MASK has no shift so we can use it directly here */
|
|
|
|
if (set.num_engines > I915_EXEC_RING_MASK + 1)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
set.engines = kmalloc_array(set.num_engines, sizeof(*set.engines), GFP_KERNEL);
|
|
|
|
if (!set.engines)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
for (n = 0; n < set.num_engines; n++) {
|
|
|
|
struct i915_engine_class_instance ci;
|
|
|
|
struct intel_engine_cs *engine;
|
|
|
|
|
|
|
|
if (copy_from_user(&ci, &user->engines[n], sizeof(ci))) {
|
|
|
|
kfree(set.engines);
|
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(&set.engines[n], 0, sizeof(set.engines[n]));
|
|
|
|
|
|
|
|
if (ci.engine_class == (u16)I915_ENGINE_CLASS_INVALID &&
|
|
|
|
ci.engine_instance == (u16)I915_ENGINE_CLASS_INVALID_NONE)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
engine = intel_engine_lookup_user(i915,
|
|
|
|
ci.engine_class,
|
|
|
|
ci.engine_instance);
|
|
|
|
if (!engine) {
|
|
|
|
drm_dbg(&i915->drm,
|
|
|
|
"Invalid engine[%d]: { class:%d, instance:%d }\n",
|
|
|
|
n, ci.engine_class, ci.engine_instance);
|
|
|
|
kfree(set.engines);
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
set.engines[n].type = I915_GEM_ENGINE_TYPE_PHYSICAL;
|
|
|
|
set.engines[n].engine = engine;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = -EFAULT;
|
|
|
|
if (!get_user(extensions, &user->extensions))
|
|
|
|
err = i915_user_extensions(u64_to_user_ptr(extensions),
|
|
|
|
set_proto_ctx_engines_extensions,
|
|
|
|
ARRAY_SIZE(set_proto_ctx_engines_extensions),
|
|
|
|
&set);
|
|
|
|
if (err) {
|
|
|
|
kfree(set.engines);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
pc->num_user_engines = set.num_engines;
|
|
|
|
pc->user_engines = set.engines;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int set_proto_ctx_sseu(struct drm_i915_file_private *fpriv,
|
|
|
|
struct i915_gem_proto_context *pc,
|
|
|
|
struct drm_i915_gem_context_param *args)
|
|
|
|
{
|
|
|
|
struct drm_i915_private *i915 = fpriv->dev_priv;
|
|
|
|
struct drm_i915_gem_context_param_sseu user_sseu;
|
|
|
|
struct intel_sseu *sseu;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (args->size < sizeof(user_sseu))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (GRAPHICS_VER(i915) != 11)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
if (copy_from_user(&user_sseu, u64_to_user_ptr(args->value),
|
|
|
|
sizeof(user_sseu)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
if (user_sseu.rsvd)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (user_sseu.flags & ~(I915_CONTEXT_SSEU_FLAG_ENGINE_INDEX))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (!!(user_sseu.flags & I915_CONTEXT_SSEU_FLAG_ENGINE_INDEX) != (pc->num_user_engines >= 0))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (pc->num_user_engines >= 0) {
|
|
|
|
int idx = user_sseu.engine.engine_instance;
|
|
|
|
struct i915_gem_proto_engine *pe;
|
|
|
|
|
|
|
|
if (idx >= pc->num_user_engines)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
pe = &pc->user_engines[idx];
|
|
|
|
|
|
|
|
/* Only render engine supports RPCS configuration. */
|
|
|
|
if (pe->engine->class != RENDER_CLASS)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
sseu = &pe->sseu;
|
|
|
|
} else {
|
|
|
|
/* Only render engine supports RPCS configuration. */
|
|
|
|
if (user_sseu.engine.engine_class != I915_ENGINE_CLASS_RENDER)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
/* There is only one render engine */
|
|
|
|
if (user_sseu.engine.engine_instance != 0)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
sseu = &pc->legacy_rcs_sseu;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = i915_gem_user_to_context_sseu(&i915->gt, &user_sseu, sseu);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
args->size = sizeof(user_sseu);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int set_proto_ctx_param(struct drm_i915_file_private *fpriv,
|
|
|
|
struct i915_gem_proto_context *pc,
|
|
|
|
struct drm_i915_gem_context_param *args)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
switch (args->param) {
|
|
|
|
case I915_CONTEXT_PARAM_NO_ERROR_CAPTURE:
|
|
|
|
if (args->size)
|
|
|
|
ret = -EINVAL;
|
|
|
|
else if (args->value)
|
|
|
|
pc->user_flags |= BIT(UCONTEXT_NO_ERROR_CAPTURE);
|
|
|
|
else
|
|
|
|
pc->user_flags &= ~BIT(UCONTEXT_NO_ERROR_CAPTURE);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case I915_CONTEXT_PARAM_BANNABLE:
|
|
|
|
if (args->size)
|
|
|
|
ret = -EINVAL;
|
|
|
|
else if (!capable(CAP_SYS_ADMIN) && !args->value)
|
|
|
|
ret = -EPERM;
|
|
|
|
else if (args->value)
|
|
|
|
pc->user_flags |= BIT(UCONTEXT_BANNABLE);
|
|
|
|
else
|
|
|
|
pc->user_flags &= ~BIT(UCONTEXT_BANNABLE);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case I915_CONTEXT_PARAM_RECOVERABLE:
|
|
|
|
if (args->size)
|
|
|
|
ret = -EINVAL;
|
|
|
|
else if (args->value)
|
|
|
|
pc->user_flags |= BIT(UCONTEXT_RECOVERABLE);
|
|
|
|
else
|
|
|
|
pc->user_flags &= ~BIT(UCONTEXT_RECOVERABLE);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case I915_CONTEXT_PARAM_PRIORITY:
|
|
|
|
ret = validate_priority(fpriv->dev_priv, args);
|
|
|
|
if (!ret)
|
|
|
|
pc->sched.priority = args->value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case I915_CONTEXT_PARAM_SSEU:
|
|
|
|
ret = set_proto_ctx_sseu(fpriv, pc, args);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case I915_CONTEXT_PARAM_VM:
|
|
|
|
ret = set_proto_ctx_vm(fpriv, pc, args);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case I915_CONTEXT_PARAM_ENGINES:
|
|
|
|
ret = set_proto_ctx_engines(fpriv, pc, args);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case I915_CONTEXT_PARAM_PERSISTENCE:
|
|
|
|
if (args->size)
|
|
|
|
ret = -EINVAL;
|
|
|
|
ret = proto_context_set_persistence(fpriv->dev_priv, pc,
|
|
|
|
args->value);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case I915_CONTEXT_PARAM_NO_ZEROMAP:
|
|
|
|
case I915_CONTEXT_PARAM_BAN_PERIOD:
|
|
|
|
case I915_CONTEXT_PARAM_RINGSIZE:
|
|
|
|
default:
|
|
|
|
ret = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-11-06 09:13:12 +00:00
|
|
|
static struct i915_address_space *
|
|
|
|
context_get_vm_rcu(struct i915_gem_context *ctx)
|
|
|
|
{
|
|
|
|
GEM_BUG_ON(!rcu_access_pointer(ctx->vm));
|
|
|
|
|
|
|
|
do {
|
|
|
|
struct i915_address_space *vm;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We do not allow downgrading from full-ppgtt [to a shared
|
|
|
|
* global gtt], so ctx->vm cannot become NULL.
|
|
|
|
*/
|
|
|
|
vm = rcu_dereference(ctx->vm);
|
|
|
|
if (!kref_get_unless_zero(&vm->ref))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This ppgtt may have be reallocated between
|
|
|
|
* the read and the kref, and reassigned to a third
|
|
|
|
* context. In order to avoid inadvertent sharing
|
|
|
|
* of this ppgtt with that third context (and not
|
|
|
|
* src), we have to confirm that we have the same
|
|
|
|
* ppgtt after passing through the strong memory
|
|
|
|
* barrier implied by a successful
|
|
|
|
* kref_get_unless_zero().
|
|
|
|
*
|
|
|
|
* Once we have acquired the current ppgtt of ctx,
|
|
|
|
* we no longer care if it is released from ctx, as
|
|
|
|
* it cannot be reallocated elsewhere.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (vm == rcu_access_pointer(ctx->vm))
|
|
|
|
return rcu_pointer_handoff(vm);
|
|
|
|
|
|
|
|
i915_vm_put(vm);
|
|
|
|
} while (1);
|
|
|
|
}
|
|
|
|
|
2021-07-08 15:48:23 +00:00
|
|
|
static int intel_context_set_gem(struct intel_context *ce,
|
|
|
|
struct i915_gem_context *ctx,
|
|
|
|
struct intel_sseu sseu)
|
2019-12-21 16:03:24 +00:00
|
|
|
{
|
2021-07-08 15:48:23 +00:00
|
|
|
int ret = 0;
|
|
|
|
|
2019-12-22 23:35:58 +00:00
|
|
|
GEM_BUG_ON(rcu_access_pointer(ce->gem_context));
|
|
|
|
RCU_INIT_POINTER(ce->gem_context, ctx);
|
2019-12-21 16:03:24 +00:00
|
|
|
|
2021-07-08 15:48:07 +00:00
|
|
|
ce->ring_size = SZ_16K;
|
2019-12-21 16:03:24 +00:00
|
|
|
|
|
|
|
if (rcu_access_pointer(ctx->vm)) {
|
|
|
|
struct i915_address_space *vm;
|
|
|
|
|
|
|
|
rcu_read_lock();
|
|
|
|
vm = context_get_vm_rcu(ctx); /* hmm */
|
|
|
|
rcu_read_unlock();
|
|
|
|
|
|
|
|
i915_vm_put(ce->vm);
|
|
|
|
ce->vm = vm;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ctx->sched.priority >= I915_PRIORITY_NORMAL &&
|
2021-07-21 21:50:56 +00:00
|
|
|
intel_engine_has_timeslices(ce->engine) &&
|
|
|
|
intel_engine_has_semaphores(ce->engine))
|
2019-12-21 16:03:24 +00:00
|
|
|
__set_bit(CONTEXT_USE_SEMAPHORES, &ce->flags);
|
2021-03-24 12:13:34 +00:00
|
|
|
|
2021-07-08 15:48:09 +00:00
|
|
|
if (IS_ACTIVE(CONFIG_DRM_I915_REQUEST_TIMEOUT) &&
|
|
|
|
ctx->i915->params.request_timeout_ms) {
|
|
|
|
unsigned int timeout_ms = ctx->i915->params.request_timeout_ms;
|
|
|
|
|
|
|
|
intel_context_set_watchdog_us(ce, (u64)timeout_ms * 1000);
|
|
|
|
}
|
2021-07-08 15:48:23 +00:00
|
|
|
|
|
|
|
/* A valid SSEU has no zero fields */
|
|
|
|
if (sseu.slice_mask && !WARN_ON(ce->engine->class != RENDER_CLASS))
|
|
|
|
ret = intel_context_reconfigure_sseu(ce, sseu);
|
|
|
|
|
|
|
|
return ret;
|
2019-12-21 16:03:24 +00:00
|
|
|
}
|
|
|
|
|
2019-04-26 16:33:34 +00:00
|
|
|
static void __free_engines(struct i915_gem_engines *e, unsigned int count)
|
2012-06-04 21:42:43 +00:00
|
|
|
{
|
2019-04-26 16:33:34 +00:00
|
|
|
while (count--) {
|
|
|
|
if (!e->engines[count])
|
|
|
|
continue;
|
|
|
|
|
|
|
|
intel_context_put(e->engines[count]);
|
|
|
|
}
|
|
|
|
kfree(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void free_engines(struct i915_gem_engines *e)
|
|
|
|
{
|
|
|
|
__free_engines(e, e->num_engines);
|
|
|
|
}
|
|
|
|
|
2019-06-06 11:23:20 +00:00
|
|
|
static void free_engines_rcu(struct rcu_head *rcu)
|
drm/i915: Allow a context to define its set of engines
Over the last few years, we have debated how to extend the user API to
support an increase in the number of engines, that may be sparse and
even be heterogeneous within a class (not all video decoders created
equal). We settled on using (class, instance) tuples to identify a
specific engine, with an API for the user to construct a map of engines
to capabilities. Into this picture, we then add a challenge of virtual
engines; one user engine that maps behind the scenes to any number of
physical engines. To keep it general, we want the user to have full
control over that mapping. To that end, we allow the user to constrain a
context to define the set of engines that it can access, order fully
controlled by the user via (class, instance). With such precise control
in context setup, we can continue to use the existing execbuf uABI of
specifying a single index; only now it doesn't automagically map onto
the engines, it uses the user defined engine map from the context.
v2: Fixup freeing of local on success of get_engines()
v3: Allow empty engines[]
v4: s/nengine/num_engines/
v5: Replace 64 limit on num_engines with a note that execbuf is
currently limited to only using the first 64 engines.
v6: Actually use the engines_mutex to guard the ctx->engines.
Testcase: igt/gem_ctx_engines
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20190521211134.16117-2-chris@chris-wilson.co.uk
2019-05-21 21:11:26 +00:00
|
|
|
{
|
2020-03-03 08:05:44 +00:00
|
|
|
struct i915_gem_engines *engines =
|
|
|
|
container_of(rcu, struct i915_gem_engines, rcu);
|
|
|
|
|
|
|
|
i915_sw_fence_fini(&engines->fence);
|
|
|
|
free_engines(engines);
|
drm/i915: Allow a context to define its set of engines
Over the last few years, we have debated how to extend the user API to
support an increase in the number of engines, that may be sparse and
even be heterogeneous within a class (not all video decoders created
equal). We settled on using (class, instance) tuples to identify a
specific engine, with an API for the user to construct a map of engines
to capabilities. Into this picture, we then add a challenge of virtual
engines; one user engine that maps behind the scenes to any number of
physical engines. To keep it general, we want the user to have full
control over that mapping. To that end, we allow the user to constrain a
context to define the set of engines that it can access, order fully
controlled by the user via (class, instance). With such precise control
in context setup, we can continue to use the existing execbuf uABI of
specifying a single index; only now it doesn't automagically map onto
the engines, it uses the user defined engine map from the context.
v2: Fixup freeing of local on success of get_engines()
v3: Allow empty engines[]
v4: s/nengine/num_engines/
v5: Replace 64 limit on num_engines with a note that execbuf is
currently limited to only using the first 64 engines.
v6: Actually use the engines_mutex to guard the ctx->engines.
Testcase: igt/gem_ctx_engines
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20190521211134.16117-2-chris@chris-wilson.co.uk
2019-05-21 21:11:26 +00:00
|
|
|
}
|
|
|
|
|
2020-03-11 22:17:39 +00:00
|
|
|
static int __i915_sw_fence_call
|
|
|
|
engines_notify(struct i915_sw_fence *fence, enum i915_sw_fence_notify state)
|
|
|
|
{
|
|
|
|
struct i915_gem_engines *engines =
|
|
|
|
container_of(fence, typeof(*engines), fence);
|
|
|
|
|
|
|
|
switch (state) {
|
|
|
|
case FENCE_COMPLETE:
|
|
|
|
if (!list_empty(&engines->link)) {
|
|
|
|
struct i915_gem_context *ctx = engines->ctx;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&ctx->stale.lock, flags);
|
|
|
|
list_del(&engines->link);
|
|
|
|
spin_unlock_irqrestore(&ctx->stale.lock, flags);
|
|
|
|
}
|
|
|
|
i915_gem_context_put(engines->ctx);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FENCE_FREE:
|
|
|
|
init_rcu_head(&engines->rcu);
|
|
|
|
call_rcu(&engines->rcu, free_engines_rcu);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NOTIFY_DONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct i915_gem_engines *alloc_engines(unsigned int count)
|
|
|
|
{
|
|
|
|
struct i915_gem_engines *e;
|
|
|
|
|
|
|
|
e = kzalloc(struct_size(e, engines, count), GFP_KERNEL);
|
|
|
|
if (!e)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
i915_sw_fence_init(&e->fence, engines_notify);
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
|
2021-07-08 15:48:23 +00:00
|
|
|
static struct i915_gem_engines *default_engines(struct i915_gem_context *ctx,
|
|
|
|
struct intel_sseu rcs_sseu)
|
2019-04-26 16:33:34 +00:00
|
|
|
{
|
2019-08-08 11:06:12 +00:00
|
|
|
const struct intel_gt *gt = &ctx->i915->gt;
|
2019-04-26 16:33:34 +00:00
|
|
|
struct intel_engine_cs *engine;
|
2021-07-08 15:48:22 +00:00
|
|
|
struct i915_gem_engines *e, *err;
|
2019-04-26 16:33:34 +00:00
|
|
|
enum intel_engine_id id;
|
|
|
|
|
2020-03-11 22:17:39 +00:00
|
|
|
e = alloc_engines(I915_NUM_ENGINES);
|
2019-04-26 16:33:34 +00:00
|
|
|
if (!e)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
2019-08-08 11:06:12 +00:00
|
|
|
for_each_engine(engine, gt, id) {
|
2019-04-26 16:33:34 +00:00
|
|
|
struct intel_context *ce;
|
2021-07-08 15:48:23 +00:00
|
|
|
struct intel_sseu sseu = {};
|
|
|
|
int ret;
|
2019-04-26 16:33:34 +00:00
|
|
|
|
2019-10-17 16:18:52 +00:00
|
|
|
if (engine->legacy_idx == INVALID_ENGINE)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
GEM_BUG_ON(engine->legacy_idx >= I915_NUM_ENGINES);
|
|
|
|
GEM_BUG_ON(e->engines[engine->legacy_idx]);
|
|
|
|
|
2019-12-21 16:03:24 +00:00
|
|
|
ce = intel_context_create(engine);
|
2019-04-26 16:33:34 +00:00
|
|
|
if (IS_ERR(ce)) {
|
2021-07-08 15:48:22 +00:00
|
|
|
err = ERR_CAST(ce);
|
|
|
|
goto free_engines;
|
2019-04-26 16:33:34 +00:00
|
|
|
}
|
2012-06-04 21:42:43 +00:00
|
|
|
|
2019-10-17 16:18:52 +00:00
|
|
|
e->engines[engine->legacy_idx] = ce;
|
2021-07-08 15:48:22 +00:00
|
|
|
e->num_engines = max(e->num_engines, engine->legacy_idx + 1);
|
2021-07-08 15:48:23 +00:00
|
|
|
|
|
|
|
if (engine->class == RENDER_CLASS)
|
|
|
|
sseu = rcs_sseu;
|
|
|
|
|
|
|
|
ret = intel_context_set_gem(ce, ctx, sseu);
|
|
|
|
if (ret) {
|
|
|
|
err = ERR_PTR(ret);
|
|
|
|
goto free_engines;
|
|
|
|
}
|
|
|
|
|
2019-04-26 16:33:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return e;
|
2021-07-08 15:48:22 +00:00
|
|
|
|
|
|
|
free_engines:
|
|
|
|
free_engines(e);
|
|
|
|
return err;
|
2019-04-26 16:33:34 +00:00
|
|
|
}
|
|
|
|
|
2021-07-08 15:48:26 +00:00
|
|
|
static struct i915_gem_engines *user_engines(struct i915_gem_context *ctx,
|
|
|
|
unsigned int num_engines,
|
|
|
|
struct i915_gem_proto_engine *pe)
|
|
|
|
{
|
|
|
|
struct i915_gem_engines *e, *err;
|
|
|
|
unsigned int n;
|
|
|
|
|
|
|
|
e = alloc_engines(num_engines);
|
|
|
|
for (n = 0; n < num_engines; n++) {
|
|
|
|
struct intel_context *ce;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
switch (pe[n].type) {
|
|
|
|
case I915_GEM_ENGINE_TYPE_PHYSICAL:
|
|
|
|
ce = intel_context_create(pe[n].engine);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case I915_GEM_ENGINE_TYPE_BALANCED:
|
2021-07-27 00:23:16 +00:00
|
|
|
ce = intel_engine_create_virtual(pe[n].siblings,
|
|
|
|
pe[n].num_siblings);
|
2021-07-08 15:48:26 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case I915_GEM_ENGINE_TYPE_INVALID:
|
|
|
|
default:
|
|
|
|
GEM_WARN_ON(pe[n].type != I915_GEM_ENGINE_TYPE_INVALID);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IS_ERR(ce)) {
|
|
|
|
err = ERR_CAST(ce);
|
|
|
|
goto free_engines;
|
|
|
|
}
|
|
|
|
|
|
|
|
e->engines[n] = ce;
|
|
|
|
|
|
|
|
ret = intel_context_set_gem(ce, ctx, pe->sseu);
|
|
|
|
if (ret) {
|
|
|
|
err = ERR_PTR(ret);
|
|
|
|
goto free_engines;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
e->num_engines = num_engines;
|
|
|
|
|
|
|
|
return e;
|
|
|
|
|
|
|
|
free_engines:
|
|
|
|
free_engines(e);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2020-12-15 15:21:38 +00:00
|
|
|
void i915_gem_context_release(struct kref *ref)
|
2019-04-26 16:33:34 +00:00
|
|
|
{
|
2020-12-15 15:21:38 +00:00
|
|
|
struct i915_gem_context *ctx = container_of(ref, typeof(*ctx), ref);
|
2014-11-10 13:44:31 +00:00
|
|
|
|
2020-12-15 15:21:38 +00:00
|
|
|
trace_i915_context_free(ctx);
|
|
|
|
GEM_BUG_ON(!i915_gem_context_is_closed(ctx));
|
2019-10-04 13:40:09 +00:00
|
|
|
|
2019-04-26 16:33:34 +00:00
|
|
|
mutex_destroy(&ctx->engines_mutex);
|
2020-07-03 00:43:06 +00:00
|
|
|
mutex_destroy(&ctx->lut_mutex);
|
2016-05-24 13:53:41 +00:00
|
|
|
|
2016-08-15 09:49:08 +00:00
|
|
|
put_pid(ctx->pid);
|
2019-03-08 13:25:16 +00:00
|
|
|
mutex_destroy(&ctx->mutex);
|
2016-04-28 08:56:51 +00:00
|
|
|
|
2017-06-20 11:05:47 +00:00
|
|
|
kfree_rcu(ctx, rcu);
|
2012-06-04 21:42:43 +00:00
|
|
|
}
|
|
|
|
|
2019-10-23 13:31:07 +00:00
|
|
|
static inline struct i915_gem_engines *
|
|
|
|
__context_engines_static(const struct i915_gem_context *ctx)
|
|
|
|
{
|
|
|
|
return rcu_dereference_protected(ctx->engines, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __reset_context(struct i915_gem_context *ctx,
|
|
|
|
struct intel_engine_cs *engine)
|
|
|
|
{
|
|
|
|
intel_gt_handle_error(engine->gt, engine->mask, 0,
|
|
|
|
"context closure in %s", ctx->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool __cancel_engine(struct intel_engine_cs *engine)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Send a "high priority pulse" down the engine to cause the
|
|
|
|
* current request to be momentarily preempted. (If it fails to
|
|
|
|
* be preempted, it will be reset). As we have marked our context
|
|
|
|
* as banned, any incomplete request, including any running, will
|
|
|
|
* be skipped following the preemption.
|
|
|
|
*
|
|
|
|
* If there is no hangchecking (one of the reasons why we try to
|
|
|
|
* cancel the context) and no forced preemption, there may be no
|
|
|
|
* means by which we reset the GPU and evict the persistent hog.
|
|
|
|
* Ergo if we are unable to inject a preemptive pulse that can
|
|
|
|
* kill the banned context, we fallback to doing a local reset
|
|
|
|
* instead.
|
|
|
|
*/
|
2020-09-28 22:15:10 +00:00
|
|
|
return intel_engine_pulse(engine) == 0;
|
2019-10-23 13:31:07 +00:00
|
|
|
}
|
|
|
|
|
2019-10-31 09:01:04 +00:00
|
|
|
static struct intel_engine_cs *active_engine(struct intel_context *ce)
|
|
|
|
{
|
|
|
|
struct intel_engine_cs *engine = NULL;
|
|
|
|
struct i915_request *rq;
|
|
|
|
|
2020-12-29 14:41:14 +00:00
|
|
|
if (intel_context_has_inflight(ce))
|
|
|
|
return intel_context_inflight(ce);
|
|
|
|
|
2019-10-31 09:01:04 +00:00
|
|
|
if (!ce->timeline)
|
|
|
|
return NULL;
|
|
|
|
|
2020-09-25 10:11:07 +00:00
|
|
|
/*
|
|
|
|
* rq->link is only SLAB_TYPESAFE_BY_RCU, we need to hold a reference
|
|
|
|
* to the request to prevent it being transferred to a new timeline
|
|
|
|
* (and onto a new timeline->requests list).
|
|
|
|
*/
|
2020-08-06 10:59:54 +00:00
|
|
|
rcu_read_lock();
|
2020-09-25 10:11:07 +00:00
|
|
|
list_for_each_entry_reverse(rq, &ce->timeline->requests, link) {
|
|
|
|
bool found;
|
|
|
|
|
|
|
|
/* timeline is already completed upto this point? */
|
|
|
|
if (!i915_request_get_rcu(rq))
|
|
|
|
break;
|
2019-10-31 09:01:04 +00:00
|
|
|
|
|
|
|
/* Check with the backend if the request is inflight */
|
2020-09-25 10:11:07 +00:00
|
|
|
found = true;
|
|
|
|
if (likely(rcu_access_pointer(rq->timeline) == ce->timeline))
|
2021-03-24 12:13:29 +00:00
|
|
|
found = i915_request_active_engine(rq, &engine);
|
2020-09-25 10:11:07 +00:00
|
|
|
|
|
|
|
i915_request_put(rq);
|
|
|
|
if (found)
|
2019-10-31 09:01:04 +00:00
|
|
|
break;
|
|
|
|
}
|
2020-08-06 10:59:54 +00:00
|
|
|
rcu_read_unlock();
|
2019-10-31 09:01:04 +00:00
|
|
|
|
|
|
|
return engine;
|
|
|
|
}
|
|
|
|
|
2020-09-28 22:15:10 +00:00
|
|
|
static void kill_engines(struct i915_gem_engines *engines, bool ban)
|
2019-10-23 13:31:07 +00:00
|
|
|
{
|
|
|
|
struct i915_gem_engines_iter it;
|
|
|
|
struct intel_context *ce;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Map the user's engine back to the actual engines; one virtual
|
|
|
|
* engine will be mapped to multiple engines, and using ctx->engine[]
|
|
|
|
* the same engine may be have multiple instances in the user's map.
|
|
|
|
* However, we only care about pending requests, so only include
|
|
|
|
* engines on which there are incomplete requests.
|
|
|
|
*/
|
2020-02-11 14:48:31 +00:00
|
|
|
for_each_gem_engine(ce, engines, it) {
|
2019-10-23 13:31:07 +00:00
|
|
|
struct intel_engine_cs *engine;
|
|
|
|
|
2021-07-27 00:23:39 +00:00
|
|
|
if (ban && intel_context_ban(ce, NULL))
|
2019-12-20 10:12:29 +00:00
|
|
|
continue;
|
|
|
|
|
2019-10-31 09:01:04 +00:00
|
|
|
/*
|
|
|
|
* Check the current active state of this context; if we
|
|
|
|
* are currently executing on the GPU we need to evict
|
|
|
|
* ourselves. On the other hand, if we haven't yet been
|
|
|
|
* submitted to the GPU or if everything is complete,
|
|
|
|
* we have nothing to do.
|
|
|
|
*/
|
|
|
|
engine = active_engine(ce);
|
2019-10-23 13:31:07 +00:00
|
|
|
|
|
|
|
/* First attempt to gracefully cancel the context */
|
2020-09-28 22:15:10 +00:00
|
|
|
if (engine && !__cancel_engine(engine) && ban)
|
2019-10-23 13:31:07 +00:00
|
|
|
/*
|
|
|
|
* If we are unable to send a preemptive pulse to bump
|
|
|
|
* the context from the GPU, we have to resort to a full
|
|
|
|
* reset. We hope the collateral damage is worth it.
|
|
|
|
*/
|
2020-02-11 14:48:31 +00:00
|
|
|
__reset_context(engines->ctx, engine);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-28 22:15:10 +00:00
|
|
|
static void kill_context(struct i915_gem_context *ctx)
|
2020-02-11 14:48:31 +00:00
|
|
|
{
|
2020-09-28 22:15:10 +00:00
|
|
|
bool ban = (!i915_gem_context_is_persistent(ctx) ||
|
|
|
|
!ctx->i915->params.enable_hangcheck);
|
2020-02-11 14:48:31 +00:00
|
|
|
struct i915_gem_engines *pos, *next;
|
|
|
|
|
2020-03-03 08:05:44 +00:00
|
|
|
spin_lock_irq(&ctx->stale.lock);
|
|
|
|
GEM_BUG_ON(!i915_gem_context_is_closed(ctx));
|
2020-02-11 14:48:31 +00:00
|
|
|
list_for_each_entry_safe(pos, next, &ctx->stale.engines, link) {
|
2020-03-03 08:05:44 +00:00
|
|
|
if (!i915_sw_fence_await(&pos->fence)) {
|
|
|
|
list_del_init(&pos->link);
|
2020-02-11 14:48:31 +00:00
|
|
|
continue;
|
2020-03-03 08:05:44 +00:00
|
|
|
}
|
2020-02-11 14:48:31 +00:00
|
|
|
|
2020-03-03 08:05:44 +00:00
|
|
|
spin_unlock_irq(&ctx->stale.lock);
|
2020-02-11 14:48:31 +00:00
|
|
|
|
2020-09-28 22:15:10 +00:00
|
|
|
kill_engines(pos, ban);
|
2020-02-11 14:48:31 +00:00
|
|
|
|
2020-03-03 08:05:44 +00:00
|
|
|
spin_lock_irq(&ctx->stale.lock);
|
|
|
|
GEM_BUG_ON(i915_sw_fence_signaled(&pos->fence));
|
2020-02-11 14:48:31 +00:00
|
|
|
list_safe_reset_next(pos, next, link);
|
|
|
|
list_del_init(&pos->link); /* decouple from FENCE_COMPLETE */
|
|
|
|
|
|
|
|
i915_sw_fence_complete(&pos->fence);
|
2019-10-23 13:31:07 +00:00
|
|
|
}
|
2020-03-03 08:05:44 +00:00
|
|
|
spin_unlock_irq(&ctx->stale.lock);
|
2020-02-11 14:48:31 +00:00
|
|
|
}
|
|
|
|
|
2020-03-03 08:05:44 +00:00
|
|
|
static void engines_idle_release(struct i915_gem_context *ctx,
|
|
|
|
struct i915_gem_engines *engines)
|
|
|
|
{
|
|
|
|
struct i915_gem_engines_iter it;
|
|
|
|
struct intel_context *ce;
|
|
|
|
|
|
|
|
INIT_LIST_HEAD(&engines->link);
|
|
|
|
|
|
|
|
engines->ctx = i915_gem_context_get(ctx);
|
|
|
|
|
|
|
|
for_each_gem_engine(ce, engines, it) {
|
2020-04-06 15:58:40 +00:00
|
|
|
int err;
|
2020-03-03 08:05:44 +00:00
|
|
|
|
|
|
|
/* serialises with execbuf */
|
2020-03-19 17:07:06 +00:00
|
|
|
set_bit(CONTEXT_CLOSED_BIT, &ce->flags);
|
2020-03-03 08:05:44 +00:00
|
|
|
if (!intel_context_pin_if_active(ce))
|
|
|
|
continue;
|
|
|
|
|
2020-04-06 15:58:40 +00:00
|
|
|
/* Wait until context is finally scheduled out and retired */
|
|
|
|
err = i915_sw_fence_await_active(&engines->fence,
|
|
|
|
&ce->active,
|
|
|
|
I915_ACTIVE_AWAIT_BARRIER);
|
2020-03-03 08:05:44 +00:00
|
|
|
intel_context_unpin(ce);
|
2020-04-06 15:58:40 +00:00
|
|
|
if (err)
|
2020-03-03 08:05:44 +00:00
|
|
|
goto kill;
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_lock_irq(&ctx->stale.lock);
|
|
|
|
if (!i915_gem_context_is_closed(ctx))
|
|
|
|
list_add_tail(&engines->link, &ctx->stale.engines);
|
|
|
|
spin_unlock_irq(&ctx->stale.lock);
|
|
|
|
|
|
|
|
kill:
|
|
|
|
if (list_empty(&engines->link)) /* raced, already closed */
|
2020-09-28 22:15:10 +00:00
|
|
|
kill_engines(engines, true);
|
2020-03-03 08:05:44 +00:00
|
|
|
|
|
|
|
i915_sw_fence_commit(&engines->fence);
|
2019-10-23 13:31:07 +00:00
|
|
|
}
|
|
|
|
|
2019-11-11 11:43:21 +00:00
|
|
|
static void set_closed_name(struct i915_gem_context *ctx)
|
|
|
|
{
|
|
|
|
char *s;
|
|
|
|
|
|
|
|
/* Replace '[]' with '<>' to indicate closed in debug prints */
|
|
|
|
|
|
|
|
s = strrchr(ctx->name, '[');
|
|
|
|
if (!s)
|
|
|
|
return;
|
|
|
|
|
|
|
|
*s = '<';
|
|
|
|
|
|
|
|
s = strchr(s + 1, ']');
|
|
|
|
if (s)
|
|
|
|
*s = '>';
|
|
|
|
}
|
|
|
|
|
2016-08-04 06:52:46 +00:00
|
|
|
static void context_close(struct i915_gem_context *ctx)
|
|
|
|
{
|
2019-10-04 13:40:09 +00:00
|
|
|
struct i915_address_space *vm;
|
drm/i915: Pull i915_vma_pin under the vm->mutex
Replace the struct_mutex requirement for pinning the i915_vma with the
local vm->mutex instead. Note that the vm->mutex is tainted by the
shrinker (we require unbinding from inside fs-reclaim) and so we cannot
allocate while holding that mutex. Instead we have to preallocate
workers to do allocate and apply the PTE updates after we have we
reserved their slot in the drm_mm (using fences to order the PTE writes
with the GPU work and with later unbind).
In adding the asynchronous vma binding, one subtle requirement is to
avoid coupling the binding fence into the backing object->resv. That is
the asynchronous binding only applies to the vma timeline itself and not
to the pages as that is a more global timeline (the binding of one vma
does not need to be ordered with another vma, nor does the implicit GEM
fencing depend on a vma, only on writes to the backing store). Keeping
the vma binding distinct from the backing store timelines is verified by
a number of async gem_exec_fence and gem_exec_schedule tests. The way we
do this is quite simple, we keep the fence for the vma binding separate
and only wait on it as required, and never add it to the obj->resv
itself.
Another consequence in reducing the locking around the vma is the
destruction of the vma is no longer globally serialised by struct_mutex.
A natural solution would be to add a kref to i915_vma, but that requires
decoupling the reference cycles, possibly by introducing a new
i915_mm_pages object that is own by both obj->mm and vma->pages.
However, we have not taken that route due to the overshadowing lmem/ttm
discussions, and instead play a series of complicated games with
trylocks to (hopefully) ensure that only one destruction path is called!
v2: Add some commentary, and some helpers to reduce patch churn.
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20191004134015.13204-4-chris@chris-wilson.co.uk
2019-10-04 13:39:58 +00:00
|
|
|
|
2020-03-03 08:05:44 +00:00
|
|
|
/* Flush any concurrent set_engines() */
|
|
|
|
mutex_lock(&ctx->engines_mutex);
|
|
|
|
engines_idle_release(ctx, rcu_replace_pointer(ctx->engines, NULL, 1));
|
2019-10-04 13:40:09 +00:00
|
|
|
i915_gem_context_set_closed(ctx);
|
2020-03-03 08:05:44 +00:00
|
|
|
mutex_unlock(&ctx->engines_mutex);
|
drm/i915: Pull i915_vma_pin under the vm->mutex
Replace the struct_mutex requirement for pinning the i915_vma with the
local vm->mutex instead. Note that the vm->mutex is tainted by the
shrinker (we require unbinding from inside fs-reclaim) and so we cannot
allocate while holding that mutex. Instead we have to preallocate
workers to do allocate and apply the PTE updates after we have we
reserved their slot in the drm_mm (using fences to order the PTE writes
with the GPU work and with later unbind).
In adding the asynchronous vma binding, one subtle requirement is to
avoid coupling the binding fence into the backing object->resv. That is
the asynchronous binding only applies to the vma timeline itself and not
to the pages as that is a more global timeline (the binding of one vma
does not need to be ordered with another vma, nor does the implicit GEM
fencing depend on a vma, only on writes to the backing store). Keeping
the vma binding distinct from the backing store timelines is verified by
a number of async gem_exec_fence and gem_exec_schedule tests. The way we
do this is quite simple, we keep the fence for the vma binding separate
and only wait on it as required, and never add it to the obj->resv
itself.
Another consequence in reducing the locking around the vma is the
destruction of the vma is no longer globally serialised by struct_mutex.
A natural solution would be to add a kref to i915_vma, but that requires
decoupling the reference cycles, possibly by introducing a new
i915_mm_pages object that is own by both obj->mm and vma->pages.
However, we have not taken that route due to the overshadowing lmem/ttm
discussions, and instead play a series of complicated games with
trylocks to (hopefully) ensure that only one destruction path is called!
v2: Add some commentary, and some helpers to reduce patch churn.
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20191004134015.13204-4-chris@chris-wilson.co.uk
2019-10-04 13:39:58 +00:00
|
|
|
|
2019-06-06 11:23:20 +00:00
|
|
|
mutex_lock(&ctx->mutex);
|
|
|
|
|
2020-03-03 08:05:44 +00:00
|
|
|
set_closed_name(ctx);
|
|
|
|
|
2019-10-04 13:40:09 +00:00
|
|
|
vm = i915_gem_context_vm(ctx);
|
|
|
|
if (vm)
|
|
|
|
i915_vm_close(vm);
|
|
|
|
|
2021-07-08 15:48:12 +00:00
|
|
|
if (ctx->syncobj)
|
|
|
|
drm_syncobj_put(ctx->syncobj);
|
|
|
|
|
2019-06-06 11:23:20 +00:00
|
|
|
ctx->file_priv = ERR_PTR(-EBADF);
|
2017-08-16 08:52:08 +00:00
|
|
|
|
2017-11-09 08:55:40 +00:00
|
|
|
/*
|
|
|
|
* The LUT uses the VMA as a backpointer to unref the object,
|
|
|
|
* so we need to clear the LUT before we close all the VMA (inside
|
|
|
|
* the ppgtt).
|
|
|
|
*/
|
2017-08-16 08:52:08 +00:00
|
|
|
lut_close(ctx);
|
|
|
|
|
2020-12-15 15:21:38 +00:00
|
|
|
spin_lock(&ctx->i915->gem.contexts.lock);
|
|
|
|
list_del(&ctx->link);
|
|
|
|
spin_unlock(&ctx->i915->gem.contexts.lock);
|
|
|
|
|
2019-06-06 11:23:20 +00:00
|
|
|
mutex_unlock(&ctx->mutex);
|
2019-10-23 13:31:07 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If the user has disabled hangchecking, we can not be sure that
|
|
|
|
* the batches will ever complete after the context is closed,
|
|
|
|
* keeping the context and all resources pinned forever. So in this
|
|
|
|
* case we opt to forcibly kill off all remaining requests on
|
|
|
|
* context close.
|
|
|
|
*/
|
2020-09-28 22:15:10 +00:00
|
|
|
kill_context(ctx);
|
2019-10-23 13:31:07 +00:00
|
|
|
|
2016-08-04 06:52:46 +00:00
|
|
|
i915_gem_context_put(ctx);
|
|
|
|
}
|
|
|
|
|
drm/i915/gem: Make context persistence optional
Our existing behaviour is to allow contexts and their GPU requests to
persist past the point of closure until the requests are complete. This
allows clients to operate in a 'fire-and-forget' manner where they can
setup a rendering pipeline and hand it over to the display server and
immediately exit. As the rendering pipeline is kept alive until
completion, the display server (or other consumer) can use the results
in the future and present them to the user.
The compute model is a little different. They have little to no buffer
sharing between processes as their kernels tend to operate on a
continuous stream, feeding the results back to the client application.
These kernels operate for an indeterminate length of time, with many
clients wishing that the kernel was always running for as long as they
keep feeding in the data, i.e. acting like a DSP.
Not all clients want this persistent "desktop" behaviour and would prefer
that the contexts are cleaned up immediately upon closure. This ensures
that when clients are run without hangchecking (e.g. for compute kernels
of indeterminate runtime), any GPU hang or other unexpected workloads
are terminated with the process and does not continue to hog resources.
The default behaviour for new contexts is the legacy persistence mode,
as some desktop applications are dependent upon the existing behaviour.
New clients will have to opt in to immediate cleanup on context
closure. If the hangchecking modparam is disabled, so is persistent
context support -- all contexts will be terminated on closure.
We expect this behaviour change to be welcomed by compute users, who
have often been caught between a rock and a hard place. They disable
hangchecking to avoid their kernels being "unfairly" declared hung, but
have also experienced true hangs that the system was then unable to
clean up. Naturally, this leads to bug reports.
Testcase: igt/gem_ctx_persistence
Link: https://github.com/intel/compute-runtime/pull/228
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Cc: Michał Winiarski <michal.winiarski@intel.com>
Cc: Jon Bloomfield <jon.bloomfield@intel.com>
Reviewed-by: Jon Bloomfield <jon.bloomfield@intel.com>
Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Reviewed-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Acked-by: Jason Ekstrand <jason@jlekstrand.net>
Link: https://patchwork.freedesktop.org/patch/msgid/20191029202338.8841-1-chris@chris-wilson.co.uk
2019-10-29 20:23:38 +00:00
|
|
|
static int __context_set_persistence(struct i915_gem_context *ctx, bool state)
|
|
|
|
{
|
|
|
|
if (i915_gem_context_is_persistent(ctx) == state)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (state) {
|
|
|
|
/*
|
|
|
|
* Only contexts that are short-lived [that will expire or be
|
|
|
|
* reset] are allowed to survive past termination. We require
|
|
|
|
* hangcheck to ensure that the persistent requests are healthy.
|
|
|
|
*/
|
2020-06-18 15:04:02 +00:00
|
|
|
if (!ctx->i915->params.enable_hangcheck)
|
drm/i915/gem: Make context persistence optional
Our existing behaviour is to allow contexts and their GPU requests to
persist past the point of closure until the requests are complete. This
allows clients to operate in a 'fire-and-forget' manner where they can
setup a rendering pipeline and hand it over to the display server and
immediately exit. As the rendering pipeline is kept alive until
completion, the display server (or other consumer) can use the results
in the future and present them to the user.
The compute model is a little different. They have little to no buffer
sharing between processes as their kernels tend to operate on a
continuous stream, feeding the results back to the client application.
These kernels operate for an indeterminate length of time, with many
clients wishing that the kernel was always running for as long as they
keep feeding in the data, i.e. acting like a DSP.
Not all clients want this persistent "desktop" behaviour and would prefer
that the contexts are cleaned up immediately upon closure. This ensures
that when clients are run without hangchecking (e.g. for compute kernels
of indeterminate runtime), any GPU hang or other unexpected workloads
are terminated with the process and does not continue to hog resources.
The default behaviour for new contexts is the legacy persistence mode,
as some desktop applications are dependent upon the existing behaviour.
New clients will have to opt in to immediate cleanup on context
closure. If the hangchecking modparam is disabled, so is persistent
context support -- all contexts will be terminated on closure.
We expect this behaviour change to be welcomed by compute users, who
have often been caught between a rock and a hard place. They disable
hangchecking to avoid their kernels being "unfairly" declared hung, but
have also experienced true hangs that the system was then unable to
clean up. Naturally, this leads to bug reports.
Testcase: igt/gem_ctx_persistence
Link: https://github.com/intel/compute-runtime/pull/228
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Cc: Michał Winiarski <michal.winiarski@intel.com>
Cc: Jon Bloomfield <jon.bloomfield@intel.com>
Reviewed-by: Jon Bloomfield <jon.bloomfield@intel.com>
Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Reviewed-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Acked-by: Jason Ekstrand <jason@jlekstrand.net>
Link: https://patchwork.freedesktop.org/patch/msgid/20191029202338.8841-1-chris@chris-wilson.co.uk
2019-10-29 20:23:38 +00:00
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
i915_gem_context_set_persistence(ctx);
|
|
|
|
} else {
|
|
|
|
/* To cancel a context we use "preempt-to-idle" */
|
|
|
|
if (!(ctx->i915->caps.scheduler & I915_SCHEDULER_CAP_PREEMPTION))
|
|
|
|
return -ENODEV;
|
|
|
|
|
2020-01-30 16:45:53 +00:00
|
|
|
/*
|
|
|
|
* If the cancel fails, we then need to reset, cleanly!
|
|
|
|
*
|
|
|
|
* If the per-engine reset fails, all hope is lost! We resort
|
|
|
|
* to a full GPU reset in that unlikely case, but realistically
|
|
|
|
* if the engine could not reset, the full reset does not fare
|
|
|
|
* much better. The damage has been done.
|
|
|
|
*
|
|
|
|
* However, if we cannot reset an engine by itself, we cannot
|
|
|
|
* cleanup a hanging persistent context without causing
|
|
|
|
* colateral damage, and we should not pretend we can by
|
|
|
|
* exposing the interface.
|
|
|
|
*/
|
|
|
|
if (!intel_has_reset_engine(&ctx->i915->gt))
|
|
|
|
return -ENODEV;
|
|
|
|
|
drm/i915/gem: Make context persistence optional
Our existing behaviour is to allow contexts and their GPU requests to
persist past the point of closure until the requests are complete. This
allows clients to operate in a 'fire-and-forget' manner where they can
setup a rendering pipeline and hand it over to the display server and
immediately exit. As the rendering pipeline is kept alive until
completion, the display server (or other consumer) can use the results
in the future and present them to the user.
The compute model is a little different. They have little to no buffer
sharing between processes as their kernels tend to operate on a
continuous stream, feeding the results back to the client application.
These kernels operate for an indeterminate length of time, with many
clients wishing that the kernel was always running for as long as they
keep feeding in the data, i.e. acting like a DSP.
Not all clients want this persistent "desktop" behaviour and would prefer
that the contexts are cleaned up immediately upon closure. This ensures
that when clients are run without hangchecking (e.g. for compute kernels
of indeterminate runtime), any GPU hang or other unexpected workloads
are terminated with the process and does not continue to hog resources.
The default behaviour for new contexts is the legacy persistence mode,
as some desktop applications are dependent upon the existing behaviour.
New clients will have to opt in to immediate cleanup on context
closure. If the hangchecking modparam is disabled, so is persistent
context support -- all contexts will be terminated on closure.
We expect this behaviour change to be welcomed by compute users, who
have often been caught between a rock and a hard place. They disable
hangchecking to avoid their kernels being "unfairly" declared hung, but
have also experienced true hangs that the system was then unable to
clean up. Naturally, this leads to bug reports.
Testcase: igt/gem_ctx_persistence
Link: https://github.com/intel/compute-runtime/pull/228
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Cc: Michał Winiarski <michal.winiarski@intel.com>
Cc: Jon Bloomfield <jon.bloomfield@intel.com>
Reviewed-by: Jon Bloomfield <jon.bloomfield@intel.com>
Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Reviewed-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Acked-by: Jason Ekstrand <jason@jlekstrand.net>
Link: https://patchwork.freedesktop.org/patch/msgid/20191029202338.8841-1-chris@chris-wilson.co.uk
2019-10-29 20:23:38 +00:00
|
|
|
i915_gem_context_clear_persistence(ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-04-02 12:42:18 +00:00
|
|
|
static inline struct i915_gem_engines *
|
2021-01-14 13:56:10 +00:00
|
|
|
__context_engines_await(const struct i915_gem_context *ctx,
|
|
|
|
bool *user_engines)
|
2020-04-02 12:42:18 +00:00
|
|
|
{
|
|
|
|
struct i915_gem_engines *engines;
|
|
|
|
|
|
|
|
rcu_read_lock();
|
|
|
|
do {
|
|
|
|
engines = rcu_dereference(ctx->engines);
|
|
|
|
GEM_BUG_ON(!engines);
|
|
|
|
|
2021-01-14 13:56:10 +00:00
|
|
|
if (user_engines)
|
|
|
|
*user_engines = i915_gem_context_user_engines(ctx);
|
|
|
|
|
|
|
|
/* successful await => strong mb */
|
2020-04-02 12:42:18 +00:00
|
|
|
if (unlikely(!i915_sw_fence_await(&engines->fence)))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (likely(engines == rcu_access_pointer(ctx->engines)))
|
|
|
|
break;
|
|
|
|
|
|
|
|
i915_sw_fence_complete(&engines->fence);
|
|
|
|
} while (1);
|
|
|
|
rcu_read_unlock();
|
|
|
|
|
|
|
|
return engines;
|
|
|
|
}
|
|
|
|
|
2021-07-08 15:48:10 +00:00
|
|
|
static void
|
2019-08-09 18:25:17 +00:00
|
|
|
context_apply_all(struct i915_gem_context *ctx,
|
2021-07-08 15:48:10 +00:00
|
|
|
void (*fn)(struct intel_context *ce, void *data),
|
2019-08-09 18:25:17 +00:00
|
|
|
void *data)
|
|
|
|
{
|
|
|
|
struct i915_gem_engines_iter it;
|
2020-04-02 12:42:18 +00:00
|
|
|
struct i915_gem_engines *e;
|
2019-08-09 18:25:17 +00:00
|
|
|
struct intel_context *ce;
|
|
|
|
|
2021-01-14 13:56:10 +00:00
|
|
|
e = __context_engines_await(ctx, NULL);
|
2021-07-08 15:48:10 +00:00
|
|
|
for_each_gem_engine(ce, e, it)
|
|
|
|
fn(ce, data);
|
2020-04-02 12:42:18 +00:00
|
|
|
i915_sw_fence_complete(&e->fence);
|
2019-08-09 18:25:17 +00:00
|
|
|
}
|
|
|
|
|
2016-05-24 13:53:34 +00:00
|
|
|
static struct i915_gem_context *
|
2021-07-08 15:48:21 +00:00
|
|
|
i915_gem_create_context(struct drm_i915_private *i915,
|
|
|
|
const struct i915_gem_proto_context *pc)
|
drm/i915: preliminary context support
Very basic code for context setup/destruction in the driver.
Adds the file i915_gem_context.c This file implements HW context
support. On gen5+ a HW context consists of an opaque GPU object which is
referenced at times of context saves and restores. With RC6 enabled,
the context is also referenced as the GPU enters and exists from RC6
(GPU has it's own internal power context, except on gen5). Though
something like a context does exist for the media ring, the code only
supports contexts for the render ring.
In software, there is a distinction between contexts created by the
user, and the default HW context. The default HW context is used by GPU
clients that do not request setup of their own hardware context. The
default context's state is never restored to help prevent programming
errors. This would happen if a client ran and piggy-backed off another
clients GPU state. The default context only exists to give the GPU some
offset to load as the current to invoke a save of the context we
actually care about. In fact, the code could likely be constructed,
albeit in a more complicated fashion, to never use the default context,
though that limits the driver's ability to swap out, and/or destroy
other contexts.
All other contexts are created as a request by the GPU client. These
contexts store GPU state, and thus allow GPU clients to not re-emit
state (and potentially query certain state) at any time. The kernel
driver makes certain that the appropriate commands are inserted.
There are 4 entry points into the contexts, init, fini, open, close.
The names are self-explanatory except that init can be called during
reset, and also during pm thaw/resume. As we expect our context to be
preserved across these events, we do not reinitialize in this case.
As Adam Jackson pointed out, The cutoff of 1MB where a HW context is
considered too big is arbitrary. The reason for this is even though
context sizes are increasing with every generation, they have yet to
eclipse even 32k. If we somehow read back way more than that, it
probably means BIOS has done something strange, or we're running on a
platform that wasn't designed for this.
v2: rename load/unload to init/fini (daniel)
remove ILK support for get_size() (indirectly daniel)
add HAS_HW_CONTEXTS macro to clarify supported platforms (daniel)
added comments (Ben)
Signed-off-by: Ben Widawsky <ben@bwidawsk.net>
2012-06-04 21:42:42 +00:00
|
|
|
{
|
2016-05-24 13:53:34 +00:00
|
|
|
struct i915_gem_context *ctx;
|
2021-07-08 15:48:34 +00:00
|
|
|
struct i915_address_space *vm = NULL;
|
|
|
|
struct i915_gem_engines *e;
|
|
|
|
int err;
|
|
|
|
int i;
|
2012-06-04 21:42:43 +00:00
|
|
|
|
2021-07-08 15:48:34 +00:00
|
|
|
ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
|
|
|
|
if (!ctx)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
|
|
|
kref_init(&ctx->ref);
|
|
|
|
ctx->i915 = i915;
|
|
|
|
ctx->sched = pc->sched;
|
|
|
|
mutex_init(&ctx->mutex);
|
|
|
|
INIT_LIST_HEAD(&ctx->link);
|
|
|
|
|
|
|
|
spin_lock_init(&ctx->stale.lock);
|
|
|
|
INIT_LIST_HEAD(&ctx->stale.engines);
|
2012-06-04 21:42:43 +00:00
|
|
|
|
2021-07-08 15:48:21 +00:00
|
|
|
if (pc->vm) {
|
2021-07-08 15:48:34 +00:00
|
|
|
vm = i915_vm_get(pc->vm);
|
2021-07-08 15:48:21 +00:00
|
|
|
} else if (HAS_FULL_PPGTT(i915)) {
|
2019-06-11 09:12:38 +00:00
|
|
|
struct i915_ppgtt *ppgtt;
|
2013-12-06 22:11:18 +00:00
|
|
|
|
2020-01-07 13:40:09 +00:00
|
|
|
ppgtt = i915_ppgtt_create(&i915->gt);
|
2016-05-24 13:53:38 +00:00
|
|
|
if (IS_ERR(ppgtt)) {
|
drm/i915/gem: initial conversion to new logging macros using coccinelle
First pass of conversion to the new struct drm_based device logging
macros in the drm/i915/gem directory. This conversion was achieved using
the following coccinelle script that transforms based on the existence
of a straightforward struct drm_i915_private device:
@rule1@
identifier fn, T;
@@
fn(struct drm_i915_private *T,...) {
<+...
(
-DRM_INFO(
+drm_info(&T->drm,
...)
|
-DRM_ERROR(
+drm_err(&T->drm,
...)
|
-DRM_WARN(
+drm_warn(&T->drm,
...)
|
-DRM_DEBUG(
+drm_dbg(&T->drm,
...)
|
-DRM_DEBUG_DRIVER(
+drm_dbg(&T->drm,
...)
|
-DRM_DEBUG_KMS(
+drm_dbg_kms(&T->drm,
...)
|
-DRM_DEBUG_ATOMIC(
+drm_dbg_atomic(&T->drm,
...)
)
...+>
}
@rule2@
identifier fn, T;
@@
fn(...) {
...
struct drm_i915_private *T = ...;
<+...
(
-DRM_INFO(
+drm_info(&T->drm,
...)
|
-DRM_ERROR(
+drm_err(&T->drm,
...)
|
-DRM_WARN(
+drm_warn(&T->drm,
...)
|
-DRM_DEBUG(
+drm_dbg(&T->drm,
...)
|
-DRM_DEBUG_KMS(
+drm_dbg_kms(&T->drm,
...)
|
-DRM_DEBUG_DRIVER(
+drm_dbg(&T->drm,
...)
|
-DRM_DEBUG_ATOMIC(
+drm_dbg_atomic(&T->drm,
...)
)
...+>
}
Checkpatch warnings were addressed manually.
Acked-by: Chris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: Wambui Karuga <wambui.karugax@gmail.com>
Signed-off-by: Jani Nikula <jani.nikula@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20200122125750.9737-2-wambui.karugax@gmail.com
2020-01-22 12:57:49 +00:00
|
|
|
drm_dbg(&i915->drm, "PPGTT setup failed (%ld)\n",
|
|
|
|
PTR_ERR(ppgtt));
|
2021-07-08 15:48:34 +00:00
|
|
|
err = PTR_ERR(ppgtt);
|
|
|
|
goto err_ctx;
|
2014-08-06 13:04:53 +00:00
|
|
|
}
|
2021-07-08 15:48:34 +00:00
|
|
|
vm = &ppgtt->vm;
|
|
|
|
}
|
|
|
|
if (vm) {
|
|
|
|
RCU_INIT_POINTER(ctx->vm, i915_vm_open(vm));
|
2014-08-06 13:04:53 +00:00
|
|
|
|
2021-07-08 15:48:34 +00:00
|
|
|
/* i915_vm_open() takes a reference */
|
|
|
|
i915_vm_put(vm);
|
2014-08-06 13:04:53 +00:00
|
|
|
}
|
2013-12-06 22:11:18 +00:00
|
|
|
|
2021-07-08 15:48:34 +00:00
|
|
|
mutex_init(&ctx->engines_mutex);
|
2021-07-08 15:48:26 +00:00
|
|
|
if (pc->num_user_engines >= 0) {
|
2021-07-08 15:48:34 +00:00
|
|
|
i915_gem_context_set_user_engines(ctx);
|
|
|
|
e = user_engines(ctx, pc->num_user_engines, pc->user_engines);
|
|
|
|
} else {
|
|
|
|
i915_gem_context_clear_user_engines(ctx);
|
|
|
|
e = default_engines(ctx, pc->legacy_rcs_sseu);
|
|
|
|
}
|
|
|
|
if (IS_ERR(e)) {
|
|
|
|
err = PTR_ERR(e);
|
|
|
|
goto err_vm;
|
|
|
|
}
|
|
|
|
RCU_INIT_POINTER(ctx->engines, e);
|
2021-07-08 15:48:26 +00:00
|
|
|
|
2021-07-08 15:48:34 +00:00
|
|
|
INIT_RADIX_TREE(&ctx->handles_vma, GFP_KERNEL);
|
|
|
|
mutex_init(&ctx->lut_mutex);
|
2021-07-08 15:48:26 +00:00
|
|
|
|
2021-07-08 15:48:34 +00:00
|
|
|
/* NB: Mark all slices as needing a remap so that when the context first
|
|
|
|
* loads it will restore whatever remap state already exists. If there
|
|
|
|
* is no remap info, it will be a NOP. */
|
|
|
|
ctx->remap_slice = ALL_L3_SLICES(i915);
|
2021-07-08 15:48:26 +00:00
|
|
|
|
2021-07-08 15:48:34 +00:00
|
|
|
ctx->user_flags = pc->user_flags;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(ctx->hang_timestamp); i++)
|
|
|
|
ctx->hang_timestamp[i] = jiffies - CONTEXT_FAST_HANG_JIFFIES;
|
2021-07-08 15:48:26 +00:00
|
|
|
|
2021-07-08 15:48:21 +00:00
|
|
|
if (pc->single_timeline) {
|
2021-07-08 15:48:34 +00:00
|
|
|
err = drm_syncobj_create(&ctx->syncobj,
|
2021-07-08 15:48:12 +00:00
|
|
|
DRM_SYNCOBJ_CREATE_SIGNALED,
|
|
|
|
NULL);
|
2021-07-08 15:48:34 +00:00
|
|
|
if (err)
|
|
|
|
goto err_engines;
|
2019-03-22 09:23:25 +00:00
|
|
|
}
|
|
|
|
|
2014-11-10 13:44:31 +00:00
|
|
|
trace_i915_context_create(ctx);
|
|
|
|
|
2013-12-06 22:11:05 +00:00
|
|
|
return ctx;
|
2021-07-08 15:48:34 +00:00
|
|
|
|
|
|
|
err_engines:
|
|
|
|
free_engines(e);
|
|
|
|
err_vm:
|
|
|
|
if (ctx->vm)
|
|
|
|
i915_vm_close(ctx->vm);
|
|
|
|
err_ctx:
|
|
|
|
kfree(ctx);
|
|
|
|
return ERR_PTR(err);
|
drm/i915: preliminary context support
Very basic code for context setup/destruction in the driver.
Adds the file i915_gem_context.c This file implements HW context
support. On gen5+ a HW context consists of an opaque GPU object which is
referenced at times of context saves and restores. With RC6 enabled,
the context is also referenced as the GPU enters and exists from RC6
(GPU has it's own internal power context, except on gen5). Though
something like a context does exist for the media ring, the code only
supports contexts for the render ring.
In software, there is a distinction between contexts created by the
user, and the default HW context. The default HW context is used by GPU
clients that do not request setup of their own hardware context. The
default context's state is never restored to help prevent programming
errors. This would happen if a client ran and piggy-backed off another
clients GPU state. The default context only exists to give the GPU some
offset to load as the current to invoke a save of the context we
actually care about. In fact, the code could likely be constructed,
albeit in a more complicated fashion, to never use the default context,
though that limits the driver's ability to swap out, and/or destroy
other contexts.
All other contexts are created as a request by the GPU client. These
contexts store GPU state, and thus allow GPU clients to not re-emit
state (and potentially query certain state) at any time. The kernel
driver makes certain that the appropriate commands are inserted.
There are 4 entry points into the contexts, init, fini, open, close.
The names are self-explanatory except that init can be called during
reset, and also during pm thaw/resume. As we expect our context to be
preserved across these events, we do not reinitialize in this case.
As Adam Jackson pointed out, The cutoff of 1MB where a HW context is
considered too big is arbitrary. The reason for this is even though
context sizes are increasing with every generation, they have yet to
eclipse even 32k. If we somehow read back way more than that, it
probably means BIOS has done something strange, or we're running on a
platform that wasn't designed for this.
v2: rename load/unload to init/fini (daniel)
remove ILK support for get_size() (indirectly daniel)
add HAS_HW_CONTEXTS macro to clarify supported platforms (daniel)
added comments (Ben)
Signed-off-by: Ben Widawsky <ben@bwidawsk.net>
2012-06-04 21:42:42 +00:00
|
|
|
}
|
|
|
|
|
2019-10-04 13:40:09 +00:00
|
|
|
static void init_contexts(struct i915_gem_contexts *gc)
|
2017-10-03 20:34:48 +00:00
|
|
|
{
|
2019-10-04 13:40:09 +00:00
|
|
|
spin_lock_init(&gc->lock);
|
|
|
|
INIT_LIST_HEAD(&gc->list);
|
2017-10-03 20:34:48 +00:00
|
|
|
}
|
|
|
|
|
2019-12-21 16:03:24 +00:00
|
|
|
void i915_gem_init__contexts(struct drm_i915_private *i915)
|
drm/i915: preliminary context support
Very basic code for context setup/destruction in the driver.
Adds the file i915_gem_context.c This file implements HW context
support. On gen5+ a HW context consists of an opaque GPU object which is
referenced at times of context saves and restores. With RC6 enabled,
the context is also referenced as the GPU enters and exists from RC6
(GPU has it's own internal power context, except on gen5). Though
something like a context does exist for the media ring, the code only
supports contexts for the render ring.
In software, there is a distinction between contexts created by the
user, and the default HW context. The default HW context is used by GPU
clients that do not request setup of their own hardware context. The
default context's state is never restored to help prevent programming
errors. This would happen if a client ran and piggy-backed off another
clients GPU state. The default context only exists to give the GPU some
offset to load as the current to invoke a save of the context we
actually care about. In fact, the code could likely be constructed,
albeit in a more complicated fashion, to never use the default context,
though that limits the driver's ability to swap out, and/or destroy
other contexts.
All other contexts are created as a request by the GPU client. These
contexts store GPU state, and thus allow GPU clients to not re-emit
state (and potentially query certain state) at any time. The kernel
driver makes certain that the appropriate commands are inserted.
There are 4 entry points into the contexts, init, fini, open, close.
The names are self-explanatory except that init can be called during
reset, and also during pm thaw/resume. As we expect our context to be
preserved across these events, we do not reinitialize in this case.
As Adam Jackson pointed out, The cutoff of 1MB where a HW context is
considered too big is arbitrary. The reason for this is even though
context sizes are increasing with every generation, they have yet to
eclipse even 32k. If we somehow read back way more than that, it
probably means BIOS has done something strange, or we're running on a
platform that wasn't designed for this.
v2: rename load/unload to init/fini (daniel)
remove ILK support for get_size() (indirectly daniel)
add HAS_HW_CONTEXTS macro to clarify supported platforms (daniel)
added comments (Ben)
Signed-off-by: Ben Widawsky <ben@bwidawsk.net>
2012-06-04 21:42:42 +00:00
|
|
|
{
|
2019-10-04 13:40:09 +00:00
|
|
|
init_contexts(&i915->gem.contexts);
|
drm/i915: preliminary context support
Very basic code for context setup/destruction in the driver.
Adds the file i915_gem_context.c This file implements HW context
support. On gen5+ a HW context consists of an opaque GPU object which is
referenced at times of context saves and restores. With RC6 enabled,
the context is also referenced as the GPU enters and exists from RC6
(GPU has it's own internal power context, except on gen5). Though
something like a context does exist for the media ring, the code only
supports contexts for the render ring.
In software, there is a distinction between contexts created by the
user, and the default HW context. The default HW context is used by GPU
clients that do not request setup of their own hardware context. The
default context's state is never restored to help prevent programming
errors. This would happen if a client ran and piggy-backed off another
clients GPU state. The default context only exists to give the GPU some
offset to load as the current to invoke a save of the context we
actually care about. In fact, the code could likely be constructed,
albeit in a more complicated fashion, to never use the default context,
though that limits the driver's ability to swap out, and/or destroy
other contexts.
All other contexts are created as a request by the GPU client. These
contexts store GPU state, and thus allow GPU clients to not re-emit
state (and potentially query certain state) at any time. The kernel
driver makes certain that the appropriate commands are inserted.
There are 4 entry points into the contexts, init, fini, open, close.
The names are self-explanatory except that init can be called during
reset, and also during pm thaw/resume. As we expect our context to be
preserved across these events, we do not reinitialize in this case.
As Adam Jackson pointed out, The cutoff of 1MB where a HW context is
considered too big is arbitrary. The reason for this is even though
context sizes are increasing with every generation, they have yet to
eclipse even 32k. If we somehow read back way more than that, it
probably means BIOS has done something strange, or we're running on a
platform that wasn't designed for this.
v2: rename load/unload to init/fini (daniel)
remove ILK support for get_size() (indirectly daniel)
add HAS_HW_CONTEXTS macro to clarify supported platforms (daniel)
added comments (Ben)
Signed-off-by: Ben Widawsky <ben@bwidawsk.net>
2012-06-04 21:42:42 +00:00
|
|
|
}
|
|
|
|
|
drm/i915/gem: Delay context creation (v3)
The current context uAPI allows for two methods of setting context
parameters: SET_CONTEXT_PARAM and CONTEXT_CREATE_EXT_SETPARAM. The
former is allowed to be called at any time while the later happens as
part of GEM_CONTEXT_CREATE. Currently, everything settable via one is
settable via the other. While some params are fairly simple and setting
them on a live context is harmless such as the context priority, others
are far trickier such as the VM or the set of engines. In order to swap
out the VM, for instance, we have to delay until all current in-flight
work is complete, swap in the new VM, and then continue. This leads to
a plethora of potential race conditions we'd really rather avoid.
In previous patches, we added a i915_gem_proto_context struct which is
capable of storing and tracking all such create parameters. This commit
delays the creation of the actual context until after the client is done
configuring it with SET_CONTEXT_PARAM. From the perspective of the
client, it has the same u32 context ID the whole time. From the
perspective of i915, however, it's an i915_gem_proto_context right up
until the point where we attempt to do something which the proto-context
can't handle. Then the real context gets created.
This is accomplished via a little xarray dance. When GEM_CONTEXT_CREATE
is called, we create a proto-context, reserve a slot in context_xa but
leave it NULL, the proto-context in the corresponding slot in
proto_context_xa. Then, whenever we go to look up a context, we first
check context_xa. If it's there, we return the i915_gem_context and
we're done. If it's not, we look in proto_context_xa and, if we find it
there, we create the actual context and kill the proto-context.
In order for this dance to work properly, everything which ever touches
a proto-context is guarded by drm_i915_file_private::proto_context_lock,
including context creation. Yes, this means context creation now takes
a giant global lock but it can't really be helped and that should never
be on any driver's fast-path anyway.
v2 (Daniel Vetter):
- Commit message grammatical fixes.
- Use WARN_ON instead of GEM_BUG_ON
- Rename lazy_create_context_locked to finalize_create_context_locked
- Rework the control-flow logic in the setparam ioctl
- Better documentation all around
v3 (kernel test robot):
- Make finalize_create_context_locked static
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/20210708154835.528166-25-jason@jlekstrand.net
2021-07-08 15:48:29 +00:00
|
|
|
static void gem_context_register(struct i915_gem_context *ctx,
|
|
|
|
struct drm_i915_file_private *fpriv,
|
|
|
|
u32 id)
|
2019-03-21 14:07:08 +00:00
|
|
|
{
|
2020-07-30 09:28:56 +00:00
|
|
|
struct drm_i915_private *i915 = ctx->i915;
|
drm/i915/gem: Delay context creation (v3)
The current context uAPI allows for two methods of setting context
parameters: SET_CONTEXT_PARAM and CONTEXT_CREATE_EXT_SETPARAM. The
former is allowed to be called at any time while the later happens as
part of GEM_CONTEXT_CREATE. Currently, everything settable via one is
settable via the other. While some params are fairly simple and setting
them on a live context is harmless such as the context priority, others
are far trickier such as the VM or the set of engines. In order to swap
out the VM, for instance, we have to delay until all current in-flight
work is complete, swap in the new VM, and then continue. This leads to
a plethora of potential race conditions we'd really rather avoid.
In previous patches, we added a i915_gem_proto_context struct which is
capable of storing and tracking all such create parameters. This commit
delays the creation of the actual context until after the client is done
configuring it with SET_CONTEXT_PARAM. From the perspective of the
client, it has the same u32 context ID the whole time. From the
perspective of i915, however, it's an i915_gem_proto_context right up
until the point where we attempt to do something which the proto-context
can't handle. Then the real context gets created.
This is accomplished via a little xarray dance. When GEM_CONTEXT_CREATE
is called, we create a proto-context, reserve a slot in context_xa but
leave it NULL, the proto-context in the corresponding slot in
proto_context_xa. Then, whenever we go to look up a context, we first
check context_xa. If it's there, we return the i915_gem_context and
we're done. If it's not, we look in proto_context_xa and, if we find it
there, we create the actual context and kill the proto-context.
In order for this dance to work properly, everything which ever touches
a proto-context is guarded by drm_i915_file_private::proto_context_lock,
including context creation. Yes, this means context creation now takes
a giant global lock but it can't really be helped and that should never
be on any driver's fast-path anyway.
v2 (Daniel Vetter):
- Commit message grammatical fixes.
- Use WARN_ON instead of GEM_BUG_ON
- Rename lazy_create_context_locked to finalize_create_context_locked
- Rework the control-flow logic in the setparam ioctl
- Better documentation all around
v3 (kernel test robot):
- Make finalize_create_context_locked static
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/20210708154835.528166-25-jason@jlekstrand.net
2021-07-08 15:48:29 +00:00
|
|
|
void *old;
|
2019-03-21 14:07:08 +00:00
|
|
|
|
|
|
|
ctx->file_priv = fpriv;
|
2019-10-04 13:40:09 +00:00
|
|
|
|
2019-03-21 14:07:08 +00:00
|
|
|
ctx->pid = get_task_pid(current, PIDTYPE_PID);
|
2019-11-11 11:43:20 +00:00
|
|
|
snprintf(ctx->name, sizeof(ctx->name), "%s[%d]",
|
|
|
|
current->comm, pid_nr(ctx->pid));
|
2019-03-21 14:07:08 +00:00
|
|
|
|
|
|
|
/* And finally expose ourselves to userspace via the idr */
|
drm/i915/gem: Delay context creation (v3)
The current context uAPI allows for two methods of setting context
parameters: SET_CONTEXT_PARAM and CONTEXT_CREATE_EXT_SETPARAM. The
former is allowed to be called at any time while the later happens as
part of GEM_CONTEXT_CREATE. Currently, everything settable via one is
settable via the other. While some params are fairly simple and setting
them on a live context is harmless such as the context priority, others
are far trickier such as the VM or the set of engines. In order to swap
out the VM, for instance, we have to delay until all current in-flight
work is complete, swap in the new VM, and then continue. This leads to
a plethora of potential race conditions we'd really rather avoid.
In previous patches, we added a i915_gem_proto_context struct which is
capable of storing and tracking all such create parameters. This commit
delays the creation of the actual context until after the client is done
configuring it with SET_CONTEXT_PARAM. From the perspective of the
client, it has the same u32 context ID the whole time. From the
perspective of i915, however, it's an i915_gem_proto_context right up
until the point where we attempt to do something which the proto-context
can't handle. Then the real context gets created.
This is accomplished via a little xarray dance. When GEM_CONTEXT_CREATE
is called, we create a proto-context, reserve a slot in context_xa but
leave it NULL, the proto-context in the corresponding slot in
proto_context_xa. Then, whenever we go to look up a context, we first
check context_xa. If it's there, we return the i915_gem_context and
we're done. If it's not, we look in proto_context_xa and, if we find it
there, we create the actual context and kill the proto-context.
In order for this dance to work properly, everything which ever touches
a proto-context is guarded by drm_i915_file_private::proto_context_lock,
including context creation. Yes, this means context creation now takes
a giant global lock but it can't really be helped and that should never
be on any driver's fast-path anyway.
v2 (Daniel Vetter):
- Commit message grammatical fixes.
- Use WARN_ON instead of GEM_BUG_ON
- Rename lazy_create_context_locked to finalize_create_context_locked
- Rework the control-flow logic in the setparam ioctl
- Better documentation all around
v3 (kernel test robot):
- Make finalize_create_context_locked static
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/20210708154835.528166-25-jason@jlekstrand.net
2021-07-08 15:48:29 +00:00
|
|
|
old = xa_store(&fpriv->context_xa, id, ctx, GFP_KERNEL);
|
|
|
|
WARN_ON(old);
|
2020-07-30 09:28:56 +00:00
|
|
|
|
|
|
|
spin_lock(&i915->gem.contexts.lock);
|
|
|
|
list_add_tail(&ctx->link, &i915->gem.contexts.list);
|
|
|
|
spin_unlock(&i915->gem.contexts.lock);
|
2019-03-21 14:07:08 +00:00
|
|
|
}
|
|
|
|
|
2017-06-20 11:05:45 +00:00
|
|
|
int i915_gem_context_open(struct drm_i915_private *i915,
|
|
|
|
struct drm_file *file)
|
2013-12-06 22:10:58 +00:00
|
|
|
{
|
|
|
|
struct drm_i915_file_private *file_priv = file->driver_priv;
|
2021-07-08 15:48:21 +00:00
|
|
|
struct i915_gem_proto_context *pc;
|
2016-05-24 13:53:34 +00:00
|
|
|
struct i915_gem_context *ctx;
|
2019-03-21 14:07:08 +00:00
|
|
|
int err;
|
2013-12-06 22:10:58 +00:00
|
|
|
|
drm/i915/gem: Delay context creation (v3)
The current context uAPI allows for two methods of setting context
parameters: SET_CONTEXT_PARAM and CONTEXT_CREATE_EXT_SETPARAM. The
former is allowed to be called at any time while the later happens as
part of GEM_CONTEXT_CREATE. Currently, everything settable via one is
settable via the other. While some params are fairly simple and setting
them on a live context is harmless such as the context priority, others
are far trickier such as the VM or the set of engines. In order to swap
out the VM, for instance, we have to delay until all current in-flight
work is complete, swap in the new VM, and then continue. This leads to
a plethora of potential race conditions we'd really rather avoid.
In previous patches, we added a i915_gem_proto_context struct which is
capable of storing and tracking all such create parameters. This commit
delays the creation of the actual context until after the client is done
configuring it with SET_CONTEXT_PARAM. From the perspective of the
client, it has the same u32 context ID the whole time. From the
perspective of i915, however, it's an i915_gem_proto_context right up
until the point where we attempt to do something which the proto-context
can't handle. Then the real context gets created.
This is accomplished via a little xarray dance. When GEM_CONTEXT_CREATE
is called, we create a proto-context, reserve a slot in context_xa but
leave it NULL, the proto-context in the corresponding slot in
proto_context_xa. Then, whenever we go to look up a context, we first
check context_xa. If it's there, we return the i915_gem_context and
we're done. If it's not, we look in proto_context_xa and, if we find it
there, we create the actual context and kill the proto-context.
In order for this dance to work properly, everything which ever touches
a proto-context is guarded by drm_i915_file_private::proto_context_lock,
including context creation. Yes, this means context creation now takes
a giant global lock but it can't really be helped and that should never
be on any driver's fast-path anyway.
v2 (Daniel Vetter):
- Commit message grammatical fixes.
- Use WARN_ON instead of GEM_BUG_ON
- Rename lazy_create_context_locked to finalize_create_context_locked
- Rework the control-flow logic in the setparam ioctl
- Better documentation all around
v3 (kernel test robot):
- Make finalize_create_context_locked static
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/20210708154835.528166-25-jason@jlekstrand.net
2021-07-08 15:48:29 +00:00
|
|
|
mutex_init(&file_priv->proto_context_lock);
|
|
|
|
xa_init_flags(&file_priv->proto_context_xa, XA_FLAGS_ALLOC);
|
|
|
|
|
|
|
|
/* 0 reserved for the default context */
|
|
|
|
xa_init_flags(&file_priv->context_xa, XA_FLAGS_ALLOC1);
|
2019-03-22 09:23:23 +00:00
|
|
|
|
2020-01-22 16:15:31 +00:00
|
|
|
/* 0 reserved for invalid/unassigned ppgtt */
|
|
|
|
xa_init_flags(&file_priv->vm_xa, XA_FLAGS_ALLOC1);
|
2013-12-06 22:10:58 +00:00
|
|
|
|
2021-07-08 15:48:21 +00:00
|
|
|
pc = proto_context_create(i915, 0);
|
|
|
|
if (IS_ERR(pc)) {
|
|
|
|
err = PTR_ERR(pc);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx = i915_gem_create_context(i915, pc);
|
|
|
|
proto_context_close(pc);
|
2014-05-22 13:13:38 +00:00
|
|
|
if (IS_ERR(ctx)) {
|
2019-03-21 14:07:08 +00:00
|
|
|
err = PTR_ERR(ctx);
|
|
|
|
goto err;
|
2013-12-06 22:11:19 +00:00
|
|
|
}
|
|
|
|
|
drm/i915/gem: Delay context creation (v3)
The current context uAPI allows for two methods of setting context
parameters: SET_CONTEXT_PARAM and CONTEXT_CREATE_EXT_SETPARAM. The
former is allowed to be called at any time while the later happens as
part of GEM_CONTEXT_CREATE. Currently, everything settable via one is
settable via the other. While some params are fairly simple and setting
them on a live context is harmless such as the context priority, others
are far trickier such as the VM or the set of engines. In order to swap
out the VM, for instance, we have to delay until all current in-flight
work is complete, swap in the new VM, and then continue. This leads to
a plethora of potential race conditions we'd really rather avoid.
In previous patches, we added a i915_gem_proto_context struct which is
capable of storing and tracking all such create parameters. This commit
delays the creation of the actual context until after the client is done
configuring it with SET_CONTEXT_PARAM. From the perspective of the
client, it has the same u32 context ID the whole time. From the
perspective of i915, however, it's an i915_gem_proto_context right up
until the point where we attempt to do something which the proto-context
can't handle. Then the real context gets created.
This is accomplished via a little xarray dance. When GEM_CONTEXT_CREATE
is called, we create a proto-context, reserve a slot in context_xa but
leave it NULL, the proto-context in the corresponding slot in
proto_context_xa. Then, whenever we go to look up a context, we first
check context_xa. If it's there, we return the i915_gem_context and
we're done. If it's not, we look in proto_context_xa and, if we find it
there, we create the actual context and kill the proto-context.
In order for this dance to work properly, everything which ever touches
a proto-context is guarded by drm_i915_file_private::proto_context_lock,
including context creation. Yes, this means context creation now takes
a giant global lock but it can't really be helped and that should never
be on any driver's fast-path anyway.
v2 (Daniel Vetter):
- Commit message grammatical fixes.
- Use WARN_ON instead of GEM_BUG_ON
- Rename lazy_create_context_locked to finalize_create_context_locked
- Rework the control-flow logic in the setparam ioctl
- Better documentation all around
v3 (kernel test robot):
- Make finalize_create_context_locked static
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/20210708154835.528166-25-jason@jlekstrand.net
2021-07-08 15:48:29 +00:00
|
|
|
gem_context_register(ctx, file_priv, 0);
|
2019-03-21 14:07:08 +00:00
|
|
|
|
2013-12-06 22:10:58 +00:00
|
|
|
return 0;
|
2019-03-21 14:07:08 +00:00
|
|
|
|
2019-03-21 14:07:09 +00:00
|
|
|
err:
|
2020-01-22 16:15:31 +00:00
|
|
|
xa_destroy(&file_priv->vm_xa);
|
2019-12-24 09:59:20 +00:00
|
|
|
xa_destroy(&file_priv->context_xa);
|
drm/i915/gem: Delay context creation (v3)
The current context uAPI allows for two methods of setting context
parameters: SET_CONTEXT_PARAM and CONTEXT_CREATE_EXT_SETPARAM. The
former is allowed to be called at any time while the later happens as
part of GEM_CONTEXT_CREATE. Currently, everything settable via one is
settable via the other. While some params are fairly simple and setting
them on a live context is harmless such as the context priority, others
are far trickier such as the VM or the set of engines. In order to swap
out the VM, for instance, we have to delay until all current in-flight
work is complete, swap in the new VM, and then continue. This leads to
a plethora of potential race conditions we'd really rather avoid.
In previous patches, we added a i915_gem_proto_context struct which is
capable of storing and tracking all such create parameters. This commit
delays the creation of the actual context until after the client is done
configuring it with SET_CONTEXT_PARAM. From the perspective of the
client, it has the same u32 context ID the whole time. From the
perspective of i915, however, it's an i915_gem_proto_context right up
until the point where we attempt to do something which the proto-context
can't handle. Then the real context gets created.
This is accomplished via a little xarray dance. When GEM_CONTEXT_CREATE
is called, we create a proto-context, reserve a slot in context_xa but
leave it NULL, the proto-context in the corresponding slot in
proto_context_xa. Then, whenever we go to look up a context, we first
check context_xa. If it's there, we return the i915_gem_context and
we're done. If it's not, we look in proto_context_xa and, if we find it
there, we create the actual context and kill the proto-context.
In order for this dance to work properly, everything which ever touches
a proto-context is guarded by drm_i915_file_private::proto_context_lock,
including context creation. Yes, this means context creation now takes
a giant global lock but it can't really be helped and that should never
be on any driver's fast-path anyway.
v2 (Daniel Vetter):
- Commit message grammatical fixes.
- Use WARN_ON instead of GEM_BUG_ON
- Rename lazy_create_context_locked to finalize_create_context_locked
- Rework the control-flow logic in the setparam ioctl
- Better documentation all around
v3 (kernel test robot):
- Make finalize_create_context_locked static
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/20210708154835.528166-25-jason@jlekstrand.net
2021-07-08 15:48:29 +00:00
|
|
|
xa_destroy(&file_priv->proto_context_xa);
|
|
|
|
mutex_destroy(&file_priv->proto_context_lock);
|
2019-03-25 09:03:52 +00:00
|
|
|
return err;
|
2013-12-06 22:10:58 +00:00
|
|
|
}
|
|
|
|
|
2017-06-20 11:05:45 +00:00
|
|
|
void i915_gem_context_close(struct drm_file *file)
|
drm/i915: preliminary context support
Very basic code for context setup/destruction in the driver.
Adds the file i915_gem_context.c This file implements HW context
support. On gen5+ a HW context consists of an opaque GPU object which is
referenced at times of context saves and restores. With RC6 enabled,
the context is also referenced as the GPU enters and exists from RC6
(GPU has it's own internal power context, except on gen5). Though
something like a context does exist for the media ring, the code only
supports contexts for the render ring.
In software, there is a distinction between contexts created by the
user, and the default HW context. The default HW context is used by GPU
clients that do not request setup of their own hardware context. The
default context's state is never restored to help prevent programming
errors. This would happen if a client ran and piggy-backed off another
clients GPU state. The default context only exists to give the GPU some
offset to load as the current to invoke a save of the context we
actually care about. In fact, the code could likely be constructed,
albeit in a more complicated fashion, to never use the default context,
though that limits the driver's ability to swap out, and/or destroy
other contexts.
All other contexts are created as a request by the GPU client. These
contexts store GPU state, and thus allow GPU clients to not re-emit
state (and potentially query certain state) at any time. The kernel
driver makes certain that the appropriate commands are inserted.
There are 4 entry points into the contexts, init, fini, open, close.
The names are self-explanatory except that init can be called during
reset, and also during pm thaw/resume. As we expect our context to be
preserved across these events, we do not reinitialize in this case.
As Adam Jackson pointed out, The cutoff of 1MB where a HW context is
considered too big is arbitrary. The reason for this is even though
context sizes are increasing with every generation, they have yet to
eclipse even 32k. If we somehow read back way more than that, it
probably means BIOS has done something strange, or we're running on a
platform that wasn't designed for this.
v2: rename load/unload to init/fini (daniel)
remove ILK support for get_size() (indirectly daniel)
add HAS_HW_CONTEXTS macro to clarify supported platforms (daniel)
added comments (Ben)
Signed-off-by: Ben Widawsky <ben@bwidawsk.net>
2012-06-04 21:42:42 +00:00
|
|
|
{
|
2012-06-04 21:42:43 +00:00
|
|
|
struct drm_i915_file_private *file_priv = file->driver_priv;
|
drm/i915/gem: Delay context creation (v3)
The current context uAPI allows for two methods of setting context
parameters: SET_CONTEXT_PARAM and CONTEXT_CREATE_EXT_SETPARAM. The
former is allowed to be called at any time while the later happens as
part of GEM_CONTEXT_CREATE. Currently, everything settable via one is
settable via the other. While some params are fairly simple and setting
them on a live context is harmless such as the context priority, others
are far trickier such as the VM or the set of engines. In order to swap
out the VM, for instance, we have to delay until all current in-flight
work is complete, swap in the new VM, and then continue. This leads to
a plethora of potential race conditions we'd really rather avoid.
In previous patches, we added a i915_gem_proto_context struct which is
capable of storing and tracking all such create parameters. This commit
delays the creation of the actual context until after the client is done
configuring it with SET_CONTEXT_PARAM. From the perspective of the
client, it has the same u32 context ID the whole time. From the
perspective of i915, however, it's an i915_gem_proto_context right up
until the point where we attempt to do something which the proto-context
can't handle. Then the real context gets created.
This is accomplished via a little xarray dance. When GEM_CONTEXT_CREATE
is called, we create a proto-context, reserve a slot in context_xa but
leave it NULL, the proto-context in the corresponding slot in
proto_context_xa. Then, whenever we go to look up a context, we first
check context_xa. If it's there, we return the i915_gem_context and
we're done. If it's not, we look in proto_context_xa and, if we find it
there, we create the actual context and kill the proto-context.
In order for this dance to work properly, everything which ever touches
a proto-context is guarded by drm_i915_file_private::proto_context_lock,
including context creation. Yes, this means context creation now takes
a giant global lock but it can't really be helped and that should never
be on any driver's fast-path anyway.
v2 (Daniel Vetter):
- Commit message grammatical fixes.
- Use WARN_ON instead of GEM_BUG_ON
- Rename lazy_create_context_locked to finalize_create_context_locked
- Rework the control-flow logic in the setparam ioctl
- Better documentation all around
v3 (kernel test robot):
- Make finalize_create_context_locked static
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/20210708154835.528166-25-jason@jlekstrand.net
2021-07-08 15:48:29 +00:00
|
|
|
struct i915_gem_proto_context *pc;
|
2020-01-22 16:15:31 +00:00
|
|
|
struct i915_address_space *vm;
|
2019-12-24 09:59:20 +00:00
|
|
|
struct i915_gem_context *ctx;
|
|
|
|
unsigned long idx;
|
drm/i915: preliminary context support
Very basic code for context setup/destruction in the driver.
Adds the file i915_gem_context.c This file implements HW context
support. On gen5+ a HW context consists of an opaque GPU object which is
referenced at times of context saves and restores. With RC6 enabled,
the context is also referenced as the GPU enters and exists from RC6
(GPU has it's own internal power context, except on gen5). Though
something like a context does exist for the media ring, the code only
supports contexts for the render ring.
In software, there is a distinction between contexts created by the
user, and the default HW context. The default HW context is used by GPU
clients that do not request setup of their own hardware context. The
default context's state is never restored to help prevent programming
errors. This would happen if a client ran and piggy-backed off another
clients GPU state. The default context only exists to give the GPU some
offset to load as the current to invoke a save of the context we
actually care about. In fact, the code could likely be constructed,
albeit in a more complicated fashion, to never use the default context,
though that limits the driver's ability to swap out, and/or destroy
other contexts.
All other contexts are created as a request by the GPU client. These
contexts store GPU state, and thus allow GPU clients to not re-emit
state (and potentially query certain state) at any time. The kernel
driver makes certain that the appropriate commands are inserted.
There are 4 entry points into the contexts, init, fini, open, close.
The names are self-explanatory except that init can be called during
reset, and also during pm thaw/resume. As we expect our context to be
preserved across these events, we do not reinitialize in this case.
As Adam Jackson pointed out, The cutoff of 1MB where a HW context is
considered too big is arbitrary. The reason for this is even though
context sizes are increasing with every generation, they have yet to
eclipse even 32k. If we somehow read back way more than that, it
probably means BIOS has done something strange, or we're running on a
platform that wasn't designed for this.
v2: rename load/unload to init/fini (daniel)
remove ILK support for get_size() (indirectly daniel)
add HAS_HW_CONTEXTS macro to clarify supported platforms (daniel)
added comments (Ben)
Signed-off-by: Ben Widawsky <ben@bwidawsk.net>
2012-06-04 21:42:42 +00:00
|
|
|
|
drm/i915/gem: Delay context creation (v3)
The current context uAPI allows for two methods of setting context
parameters: SET_CONTEXT_PARAM and CONTEXT_CREATE_EXT_SETPARAM. The
former is allowed to be called at any time while the later happens as
part of GEM_CONTEXT_CREATE. Currently, everything settable via one is
settable via the other. While some params are fairly simple and setting
them on a live context is harmless such as the context priority, others
are far trickier such as the VM or the set of engines. In order to swap
out the VM, for instance, we have to delay until all current in-flight
work is complete, swap in the new VM, and then continue. This leads to
a plethora of potential race conditions we'd really rather avoid.
In previous patches, we added a i915_gem_proto_context struct which is
capable of storing and tracking all such create parameters. This commit
delays the creation of the actual context until after the client is done
configuring it with SET_CONTEXT_PARAM. From the perspective of the
client, it has the same u32 context ID the whole time. From the
perspective of i915, however, it's an i915_gem_proto_context right up
until the point where we attempt to do something which the proto-context
can't handle. Then the real context gets created.
This is accomplished via a little xarray dance. When GEM_CONTEXT_CREATE
is called, we create a proto-context, reserve a slot in context_xa but
leave it NULL, the proto-context in the corresponding slot in
proto_context_xa. Then, whenever we go to look up a context, we first
check context_xa. If it's there, we return the i915_gem_context and
we're done. If it's not, we look in proto_context_xa and, if we find it
there, we create the actual context and kill the proto-context.
In order for this dance to work properly, everything which ever touches
a proto-context is guarded by drm_i915_file_private::proto_context_lock,
including context creation. Yes, this means context creation now takes
a giant global lock but it can't really be helped and that should never
be on any driver's fast-path anyway.
v2 (Daniel Vetter):
- Commit message grammatical fixes.
- Use WARN_ON instead of GEM_BUG_ON
- Rename lazy_create_context_locked to finalize_create_context_locked
- Rework the control-flow logic in the setparam ioctl
- Better documentation all around
v3 (kernel test robot):
- Make finalize_create_context_locked static
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/20210708154835.528166-25-jason@jlekstrand.net
2021-07-08 15:48:29 +00:00
|
|
|
xa_for_each(&file_priv->proto_context_xa, idx, pc)
|
|
|
|
proto_context_close(pc);
|
|
|
|
xa_destroy(&file_priv->proto_context_xa);
|
|
|
|
mutex_destroy(&file_priv->proto_context_lock);
|
|
|
|
|
2019-12-24 09:59:20 +00:00
|
|
|
xa_for_each(&file_priv->context_xa, idx, ctx)
|
|
|
|
context_close(ctx);
|
|
|
|
xa_destroy(&file_priv->context_xa);
|
2019-03-22 09:23:23 +00:00
|
|
|
|
2020-01-22 16:15:31 +00:00
|
|
|
xa_for_each(&file_priv->vm_xa, idx, vm)
|
|
|
|
i915_vm_put(vm);
|
|
|
|
xa_destroy(&file_priv->vm_xa);
|
2019-03-22 09:23:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int i915_gem_vm_create_ioctl(struct drm_device *dev, void *data,
|
|
|
|
struct drm_file *file)
|
|
|
|
{
|
|
|
|
struct drm_i915_private *i915 = to_i915(dev);
|
|
|
|
struct drm_i915_gem_vm_control *args = data;
|
|
|
|
struct drm_i915_file_private *file_priv = file->driver_priv;
|
2019-06-11 09:12:38 +00:00
|
|
|
struct i915_ppgtt *ppgtt;
|
2020-01-22 16:15:31 +00:00
|
|
|
u32 id;
|
2019-03-22 09:23:23 +00:00
|
|
|
int err;
|
|
|
|
|
|
|
|
if (!HAS_FULL_PPGTT(i915))
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
if (args->flags)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2020-01-07 13:40:09 +00:00
|
|
|
ppgtt = i915_ppgtt_create(&i915->gt);
|
2019-03-22 09:23:23 +00:00
|
|
|
if (IS_ERR(ppgtt))
|
|
|
|
return PTR_ERR(ppgtt);
|
|
|
|
|
|
|
|
if (args->extensions) {
|
|
|
|
err = i915_user_extensions(u64_to_user_ptr(args->extensions),
|
|
|
|
NULL, 0,
|
|
|
|
ppgtt);
|
|
|
|
if (err)
|
|
|
|
goto err_put;
|
|
|
|
}
|
|
|
|
|
2020-01-22 16:15:31 +00:00
|
|
|
err = xa_alloc(&file_priv->vm_xa, &id, &ppgtt->vm,
|
|
|
|
xa_limit_32b, GFP_KERNEL);
|
2019-03-22 09:23:23 +00:00
|
|
|
if (err)
|
|
|
|
goto err_put;
|
|
|
|
|
2020-01-22 16:15:31 +00:00
|
|
|
GEM_BUG_ON(id == 0); /* reserved for invalid/unassigned ppgtt */
|
|
|
|
args->vm_id = id;
|
2019-03-22 09:23:23 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_put:
|
2019-06-11 09:12:37 +00:00
|
|
|
i915_vm_put(&ppgtt->vm);
|
2019-03-22 09:23:23 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
int i915_gem_vm_destroy_ioctl(struct drm_device *dev, void *data,
|
|
|
|
struct drm_file *file)
|
|
|
|
{
|
|
|
|
struct drm_i915_file_private *file_priv = file->driver_priv;
|
|
|
|
struct drm_i915_gem_vm_control *args = data;
|
2019-06-11 09:12:37 +00:00
|
|
|
struct i915_address_space *vm;
|
2019-03-22 09:23:23 +00:00
|
|
|
|
|
|
|
if (args->flags)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (args->extensions)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2020-01-22 16:15:31 +00:00
|
|
|
vm = xa_erase(&file_priv->vm_xa, args->vm_id);
|
2019-06-11 09:12:37 +00:00
|
|
|
if (!vm)
|
2019-03-22 09:23:23 +00:00
|
|
|
return -ENOENT;
|
|
|
|
|
2019-06-11 09:12:37 +00:00
|
|
|
i915_vm_put(vm);
|
2019-03-22 09:23:23 +00:00
|
|
|
return 0;
|
2012-06-04 21:42:43 +00:00
|
|
|
}
|
|
|
|
|
2019-03-30 10:03:49 +00:00
|
|
|
static int get_ppgtt(struct drm_i915_file_private *file_priv,
|
|
|
|
struct i915_gem_context *ctx,
|
2019-03-22 09:23:23 +00:00
|
|
|
struct drm_i915_gem_context_param *args)
|
|
|
|
{
|
2019-06-11 09:12:37 +00:00
|
|
|
struct i915_address_space *vm;
|
2020-01-22 16:15:31 +00:00
|
|
|
int err;
|
|
|
|
u32 id;
|
2019-03-22 09:23:23 +00:00
|
|
|
|
2019-10-04 13:40:09 +00:00
|
|
|
if (!rcu_access_pointer(ctx->vm))
|
2019-03-22 09:23:23 +00:00
|
|
|
return -ENODEV;
|
|
|
|
|
2019-10-04 13:40:09 +00:00
|
|
|
rcu_read_lock();
|
2019-11-06 09:13:12 +00:00
|
|
|
vm = context_get_vm_rcu(ctx);
|
2019-10-04 13:40:09 +00:00
|
|
|
rcu_read_unlock();
|
2020-01-23 15:26:02 +00:00
|
|
|
if (!vm)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
err = xa_alloc(&file_priv->vm_xa, &id, vm, xa_limit_32b, GFP_KERNEL);
|
2020-01-22 16:15:31 +00:00
|
|
|
if (err)
|
2019-03-22 09:23:23 +00:00
|
|
|
goto err_put;
|
|
|
|
|
drm/i915: Pull i915_vma_pin under the vm->mutex
Replace the struct_mutex requirement for pinning the i915_vma with the
local vm->mutex instead. Note that the vm->mutex is tainted by the
shrinker (we require unbinding from inside fs-reclaim) and so we cannot
allocate while holding that mutex. Instead we have to preallocate
workers to do allocate and apply the PTE updates after we have we
reserved their slot in the drm_mm (using fences to order the PTE writes
with the GPU work and with later unbind).
In adding the asynchronous vma binding, one subtle requirement is to
avoid coupling the binding fence into the backing object->resv. That is
the asynchronous binding only applies to the vma timeline itself and not
to the pages as that is a more global timeline (the binding of one vma
does not need to be ordered with another vma, nor does the implicit GEM
fencing depend on a vma, only on writes to the backing store). Keeping
the vma binding distinct from the backing store timelines is verified by
a number of async gem_exec_fence and gem_exec_schedule tests. The way we
do this is quite simple, we keep the fence for the vma binding separate
and only wait on it as required, and never add it to the obj->resv
itself.
Another consequence in reducing the locking around the vma is the
destruction of the vma is no longer globally serialised by struct_mutex.
A natural solution would be to add a kref to i915_vma, but that requires
decoupling the reference cycles, possibly by introducing a new
i915_mm_pages object that is own by both obj->mm and vma->pages.
However, we have not taken that route due to the overshadowing lmem/ttm
discussions, and instead play a series of complicated games with
trylocks to (hopefully) ensure that only one destruction path is called!
v2: Add some commentary, and some helpers to reduce patch churn.
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20191004134015.13204-4-chris@chris-wilson.co.uk
2019-10-04 13:39:58 +00:00
|
|
|
i915_vm_open(vm);
|
2019-03-22 09:23:23 +00:00
|
|
|
|
2020-01-22 16:15:31 +00:00
|
|
|
GEM_BUG_ON(id == 0); /* reserved for invalid/unassigned ppgtt */
|
|
|
|
args->value = id;
|
2019-03-22 09:23:23 +00:00
|
|
|
args->size = 0;
|
|
|
|
|
|
|
|
err_put:
|
2019-06-11 09:12:37 +00:00
|
|
|
i915_vm_put(vm);
|
2020-01-22 16:15:31 +00:00
|
|
|
return err;
|
2019-03-22 09:23:23 +00:00
|
|
|
}
|
|
|
|
|
2020-03-17 13:22:22 +00:00
|
|
|
int
|
2020-07-08 00:39:50 +00:00
|
|
|
i915_gem_user_to_context_sseu(struct intel_gt *gt,
|
2020-03-17 13:22:22 +00:00
|
|
|
const struct drm_i915_gem_context_param_sseu *user,
|
|
|
|
struct intel_sseu *context)
|
drm/i915: Expose RPCS (SSEU) configuration to userspace (Gen11 only)
We want to allow userspace to reconfigure the subslice configuration on a
per context basis.
This is required for the functional requirement of shutting down non-VME
enabled sub-slices on Gen11 parts.
To do so, we expose a context parameter to allow adjustment of the RPCS
register stored within the context image (and currently not accessible via
LRI).
If the context is adjusted before first use or whilst idle, the adjustment
is for "free"; otherwise if the context is active we queue a request to do
so (using the kernel context), following all other activity by that
context, which is also marked as barrier for all following submission
against the same context.
Since the overhead of device re-configuration during context switching can
be significant, especially in multi-context workloads, we limit this new
uAPI to only support the Gen11 VME use case. In this use case either the
device is fully enabled, and exactly one slice and half of the subslices
are enabled.
Example usage:
struct drm_i915_gem_context_param_sseu sseu = { };
struct drm_i915_gem_context_param arg = {
.param = I915_CONTEXT_PARAM_SSEU,
.ctx_id = gem_context_create(fd),
.size = sizeof(sseu),
.value = to_user_pointer(&sseu)
};
/* Query device defaults. */
gem_context_get_param(fd, &arg);
/* Set VME configuration on a 1x6x8 part. */
sseu.slice_mask = 0x1;
sseu.subslice_mask = 0xe0;
gem_context_set_param(fd, &arg);
v2: Fix offset of CTX_R_PWR_CLK_STATE in intel_lr_context_set_sseu()
(Lionel)
v3: Add ability to program this per engine (Chris)
v4: Move most get_sseu() into i915_gem_context.c (Lionel)
v5: Validate sseu configuration against the device's capabilities (Lionel)
v6: Change context powergating settings through MI_SDM on kernel context
(Chris)
v7: Synchronize the requests following a powergating setting change using
a global dependency (Chris)
Iterate timelines through dev_priv.gt.active_rings (Tvrtko)
Disable RPCS configuration setting for non capable users
(Lionel/Tvrtko)
v8: s/union intel_sseu/struct intel_sseu/ (Lionel)
s/dev_priv/i915/ (Tvrtko)
Change uapi class/instance fields to u16 (Tvrtko)
Bump mask fields to 64bits (Lionel)
Don't return EPERM when dynamic sseu is disabled (Tvrtko)
v9: Import context image into kernel context's ppgtt only when
reconfiguring powergated slice/subslices (Chris)
Use aliasing ppgtt when needed (Michel)
Tvrtko Ursulin:
v10:
* Update for upstream changes.
* Request submit needs a RPM reference.
* Reject on !FULL_PPGTT for simplicity.
* Pull out get/set param to helpers for readability and less indent.
* Use i915_request_await_dma_fence in add_global_barrier to skip waits
on the same timeline and avoid GEM_BUG_ON.
* No need to explicitly assign a NULL pointer to engine in legacy mode.
* No need to move gen8_make_rpcs up.
* Factored out global barrier as prep patch.
* Allow to only CAP_SYS_ADMIN if !Gen11.
v11:
* Remove engine vfunc in favour of local helper. (Chris Wilson)
* Stop retiring requests before updates since it is not needed
(Chris Wilson)
* Implement direct CPU update path for idle contexts. (Chris Wilson)
* Left side dependency needs only be on the same context timeline.
(Chris Wilson)
* It is sufficient to order the timeline. (Chris Wilson)
* Reject !RCS configuration attempts with -ENODEV for now.
v12:
* Rebase for make_rpcs.
v13:
* Centralize SSEU normalization to make_rpcs.
* Type width checking (uAPI <-> implementation).
* Gen11 restrictions uAPI checks.
* Gen11 subslice count differences handling.
Chris Wilson:
* args->size handling fixes.
* Update context image from GGTT.
* Postpone context image update to pinning.
* Use i915_gem_active_raw instead of last_request_on_engine.
v14:
* Add activity tracker on intel_context to fix the lifetime issues
and simplify the code. (Chris Wilson)
v15:
* Fix context pin leak if no space in ring by simplifying the
context pinning sequence.
v16:
* Rebase for context get/set param locking changes.
* Just -ENODEV on !Gen11. (Joonas)
v17:
* Fix one Gen11 subslice enablement rule.
* Handle error from i915_sw_fence_await_sw_fence_gfp. (Chris Wilson)
v18:
* Update commit message. (Joonas)
* Restrict uAPI to VME use case. (Joonas)
v19:
* Rebase.
v20:
* Rebase for ce->active_tracker.
v21:
* Rebase for IS_GEN changes.
v22:
* Reserve uAPI for flags straight away. (Chris Wilson)
v23:
* Rebase for RUNTIME_INFO.
v24:
* Added some headline docs for the uapi usage. (Joonas/Chris)
v25:
* Renamed class/instance to engine_class/engine_instance to avoid clash
with C++ keyword. (Tony Ye)
v26:
* Rebased for runtime pm api changes.
v27:
* Rebased for intel_context_init.
* Wrap commit msg to 75.
v28:
(Chris Wilson)
* Use i915_gem_ggtt.
* Use i915_request_await_dma_fence to show a better example.
v29:
* i915_timeline_set_barrier can now fail. (Chris Wilson)
v30:
* Capture some acks.
v31:
* Drop the WARN_ON from use controllable paths. (Chris Wilson)
* Use overflows_type for all checks.
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=100899
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=107634
Issue: https://github.com/intel/media-driver/issues/267
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Cc: Dmitry Rogozhkin <dmitry.v.rogozhkin@intel.com>
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Cc: Zhipeng Gong <zhipeng.gong@intel.com>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Cc: Tony Ye <tony.ye@intel.com>
Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Acked-by: Timo Aaltonen <timo.aaltonen@canonical.com>
Acked-by: Takashi Iwai <tiwai@suse.de>
Acked-by: Stéphane Marchesin <marcheu@chromium.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20190205095032.22673-4-tvrtko.ursulin@linux.intel.com
2019-02-05 09:50:31 +00:00
|
|
|
{
|
2020-07-08 00:39:50 +00:00
|
|
|
const struct sseu_dev_info *device = >->info.sseu;
|
|
|
|
struct drm_i915_private *i915 = gt->i915;
|
drm/i915: Expose RPCS (SSEU) configuration to userspace (Gen11 only)
We want to allow userspace to reconfigure the subslice configuration on a
per context basis.
This is required for the functional requirement of shutting down non-VME
enabled sub-slices on Gen11 parts.
To do so, we expose a context parameter to allow adjustment of the RPCS
register stored within the context image (and currently not accessible via
LRI).
If the context is adjusted before first use or whilst idle, the adjustment
is for "free"; otherwise if the context is active we queue a request to do
so (using the kernel context), following all other activity by that
context, which is also marked as barrier for all following submission
against the same context.
Since the overhead of device re-configuration during context switching can
be significant, especially in multi-context workloads, we limit this new
uAPI to only support the Gen11 VME use case. In this use case either the
device is fully enabled, and exactly one slice and half of the subslices
are enabled.
Example usage:
struct drm_i915_gem_context_param_sseu sseu = { };
struct drm_i915_gem_context_param arg = {
.param = I915_CONTEXT_PARAM_SSEU,
.ctx_id = gem_context_create(fd),
.size = sizeof(sseu),
.value = to_user_pointer(&sseu)
};
/* Query device defaults. */
gem_context_get_param(fd, &arg);
/* Set VME configuration on a 1x6x8 part. */
sseu.slice_mask = 0x1;
sseu.subslice_mask = 0xe0;
gem_context_set_param(fd, &arg);
v2: Fix offset of CTX_R_PWR_CLK_STATE in intel_lr_context_set_sseu()
(Lionel)
v3: Add ability to program this per engine (Chris)
v4: Move most get_sseu() into i915_gem_context.c (Lionel)
v5: Validate sseu configuration against the device's capabilities (Lionel)
v6: Change context powergating settings through MI_SDM on kernel context
(Chris)
v7: Synchronize the requests following a powergating setting change using
a global dependency (Chris)
Iterate timelines through dev_priv.gt.active_rings (Tvrtko)
Disable RPCS configuration setting for non capable users
(Lionel/Tvrtko)
v8: s/union intel_sseu/struct intel_sseu/ (Lionel)
s/dev_priv/i915/ (Tvrtko)
Change uapi class/instance fields to u16 (Tvrtko)
Bump mask fields to 64bits (Lionel)
Don't return EPERM when dynamic sseu is disabled (Tvrtko)
v9: Import context image into kernel context's ppgtt only when
reconfiguring powergated slice/subslices (Chris)
Use aliasing ppgtt when needed (Michel)
Tvrtko Ursulin:
v10:
* Update for upstream changes.
* Request submit needs a RPM reference.
* Reject on !FULL_PPGTT for simplicity.
* Pull out get/set param to helpers for readability and less indent.
* Use i915_request_await_dma_fence in add_global_barrier to skip waits
on the same timeline and avoid GEM_BUG_ON.
* No need to explicitly assign a NULL pointer to engine in legacy mode.
* No need to move gen8_make_rpcs up.
* Factored out global barrier as prep patch.
* Allow to only CAP_SYS_ADMIN if !Gen11.
v11:
* Remove engine vfunc in favour of local helper. (Chris Wilson)
* Stop retiring requests before updates since it is not needed
(Chris Wilson)
* Implement direct CPU update path for idle contexts. (Chris Wilson)
* Left side dependency needs only be on the same context timeline.
(Chris Wilson)
* It is sufficient to order the timeline. (Chris Wilson)
* Reject !RCS configuration attempts with -ENODEV for now.
v12:
* Rebase for make_rpcs.
v13:
* Centralize SSEU normalization to make_rpcs.
* Type width checking (uAPI <-> implementation).
* Gen11 restrictions uAPI checks.
* Gen11 subslice count differences handling.
Chris Wilson:
* args->size handling fixes.
* Update context image from GGTT.
* Postpone context image update to pinning.
* Use i915_gem_active_raw instead of last_request_on_engine.
v14:
* Add activity tracker on intel_context to fix the lifetime issues
and simplify the code. (Chris Wilson)
v15:
* Fix context pin leak if no space in ring by simplifying the
context pinning sequence.
v16:
* Rebase for context get/set param locking changes.
* Just -ENODEV on !Gen11. (Joonas)
v17:
* Fix one Gen11 subslice enablement rule.
* Handle error from i915_sw_fence_await_sw_fence_gfp. (Chris Wilson)
v18:
* Update commit message. (Joonas)
* Restrict uAPI to VME use case. (Joonas)
v19:
* Rebase.
v20:
* Rebase for ce->active_tracker.
v21:
* Rebase for IS_GEN changes.
v22:
* Reserve uAPI for flags straight away. (Chris Wilson)
v23:
* Rebase for RUNTIME_INFO.
v24:
* Added some headline docs for the uapi usage. (Joonas/Chris)
v25:
* Renamed class/instance to engine_class/engine_instance to avoid clash
with C++ keyword. (Tony Ye)
v26:
* Rebased for runtime pm api changes.
v27:
* Rebased for intel_context_init.
* Wrap commit msg to 75.
v28:
(Chris Wilson)
* Use i915_gem_ggtt.
* Use i915_request_await_dma_fence to show a better example.
v29:
* i915_timeline_set_barrier can now fail. (Chris Wilson)
v30:
* Capture some acks.
v31:
* Drop the WARN_ON from use controllable paths. (Chris Wilson)
* Use overflows_type for all checks.
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=100899
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=107634
Issue: https://github.com/intel/media-driver/issues/267
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Cc: Dmitry Rogozhkin <dmitry.v.rogozhkin@intel.com>
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Cc: Zhipeng Gong <zhipeng.gong@intel.com>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Cc: Tony Ye <tony.ye@intel.com>
Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Acked-by: Timo Aaltonen <timo.aaltonen@canonical.com>
Acked-by: Takashi Iwai <tiwai@suse.de>
Acked-by: Stéphane Marchesin <marcheu@chromium.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20190205095032.22673-4-tvrtko.ursulin@linux.intel.com
2019-02-05 09:50:31 +00:00
|
|
|
|
|
|
|
/* No zeros in any field. */
|
|
|
|
if (!user->slice_mask || !user->subslice_mask ||
|
|
|
|
!user->min_eus_per_subslice || !user->max_eus_per_subslice)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
/* Max > min. */
|
|
|
|
if (user->max_eus_per_subslice < user->min_eus_per_subslice)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Some future proofing on the types since the uAPI is wider than the
|
|
|
|
* current internal implementation.
|
|
|
|
*/
|
|
|
|
if (overflows_type(user->slice_mask, context->slice_mask) ||
|
|
|
|
overflows_type(user->subslice_mask, context->subslice_mask) ||
|
|
|
|
overflows_type(user->min_eus_per_subslice,
|
|
|
|
context->min_eus_per_subslice) ||
|
|
|
|
overflows_type(user->max_eus_per_subslice,
|
|
|
|
context->max_eus_per_subslice))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
/* Check validity against hardware. */
|
|
|
|
if (user->slice_mask & ~device->slice_mask)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (user->subslice_mask & ~device->subslice_mask[0])
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (user->max_eus_per_subslice > device->max_eus_per_subslice)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
context->slice_mask = user->slice_mask;
|
|
|
|
context->subslice_mask = user->subslice_mask;
|
|
|
|
context->min_eus_per_subslice = user->min_eus_per_subslice;
|
|
|
|
context->max_eus_per_subslice = user->max_eus_per_subslice;
|
|
|
|
|
|
|
|
/* Part specific restrictions. */
|
2021-06-05 15:53:54 +00:00
|
|
|
if (GRAPHICS_VER(i915) == 11) {
|
drm/i915: Expose RPCS (SSEU) configuration to userspace (Gen11 only)
We want to allow userspace to reconfigure the subslice configuration on a
per context basis.
This is required for the functional requirement of shutting down non-VME
enabled sub-slices on Gen11 parts.
To do so, we expose a context parameter to allow adjustment of the RPCS
register stored within the context image (and currently not accessible via
LRI).
If the context is adjusted before first use or whilst idle, the adjustment
is for "free"; otherwise if the context is active we queue a request to do
so (using the kernel context), following all other activity by that
context, which is also marked as barrier for all following submission
against the same context.
Since the overhead of device re-configuration during context switching can
be significant, especially in multi-context workloads, we limit this new
uAPI to only support the Gen11 VME use case. In this use case either the
device is fully enabled, and exactly one slice and half of the subslices
are enabled.
Example usage:
struct drm_i915_gem_context_param_sseu sseu = { };
struct drm_i915_gem_context_param arg = {
.param = I915_CONTEXT_PARAM_SSEU,
.ctx_id = gem_context_create(fd),
.size = sizeof(sseu),
.value = to_user_pointer(&sseu)
};
/* Query device defaults. */
gem_context_get_param(fd, &arg);
/* Set VME configuration on a 1x6x8 part. */
sseu.slice_mask = 0x1;
sseu.subslice_mask = 0xe0;
gem_context_set_param(fd, &arg);
v2: Fix offset of CTX_R_PWR_CLK_STATE in intel_lr_context_set_sseu()
(Lionel)
v3: Add ability to program this per engine (Chris)
v4: Move most get_sseu() into i915_gem_context.c (Lionel)
v5: Validate sseu configuration against the device's capabilities (Lionel)
v6: Change context powergating settings through MI_SDM on kernel context
(Chris)
v7: Synchronize the requests following a powergating setting change using
a global dependency (Chris)
Iterate timelines through dev_priv.gt.active_rings (Tvrtko)
Disable RPCS configuration setting for non capable users
(Lionel/Tvrtko)
v8: s/union intel_sseu/struct intel_sseu/ (Lionel)
s/dev_priv/i915/ (Tvrtko)
Change uapi class/instance fields to u16 (Tvrtko)
Bump mask fields to 64bits (Lionel)
Don't return EPERM when dynamic sseu is disabled (Tvrtko)
v9: Import context image into kernel context's ppgtt only when
reconfiguring powergated slice/subslices (Chris)
Use aliasing ppgtt when needed (Michel)
Tvrtko Ursulin:
v10:
* Update for upstream changes.
* Request submit needs a RPM reference.
* Reject on !FULL_PPGTT for simplicity.
* Pull out get/set param to helpers for readability and less indent.
* Use i915_request_await_dma_fence in add_global_barrier to skip waits
on the same timeline and avoid GEM_BUG_ON.
* No need to explicitly assign a NULL pointer to engine in legacy mode.
* No need to move gen8_make_rpcs up.
* Factored out global barrier as prep patch.
* Allow to only CAP_SYS_ADMIN if !Gen11.
v11:
* Remove engine vfunc in favour of local helper. (Chris Wilson)
* Stop retiring requests before updates since it is not needed
(Chris Wilson)
* Implement direct CPU update path for idle contexts. (Chris Wilson)
* Left side dependency needs only be on the same context timeline.
(Chris Wilson)
* It is sufficient to order the timeline. (Chris Wilson)
* Reject !RCS configuration attempts with -ENODEV for now.
v12:
* Rebase for make_rpcs.
v13:
* Centralize SSEU normalization to make_rpcs.
* Type width checking (uAPI <-> implementation).
* Gen11 restrictions uAPI checks.
* Gen11 subslice count differences handling.
Chris Wilson:
* args->size handling fixes.
* Update context image from GGTT.
* Postpone context image update to pinning.
* Use i915_gem_active_raw instead of last_request_on_engine.
v14:
* Add activity tracker on intel_context to fix the lifetime issues
and simplify the code. (Chris Wilson)
v15:
* Fix context pin leak if no space in ring by simplifying the
context pinning sequence.
v16:
* Rebase for context get/set param locking changes.
* Just -ENODEV on !Gen11. (Joonas)
v17:
* Fix one Gen11 subslice enablement rule.
* Handle error from i915_sw_fence_await_sw_fence_gfp. (Chris Wilson)
v18:
* Update commit message. (Joonas)
* Restrict uAPI to VME use case. (Joonas)
v19:
* Rebase.
v20:
* Rebase for ce->active_tracker.
v21:
* Rebase for IS_GEN changes.
v22:
* Reserve uAPI for flags straight away. (Chris Wilson)
v23:
* Rebase for RUNTIME_INFO.
v24:
* Added some headline docs for the uapi usage. (Joonas/Chris)
v25:
* Renamed class/instance to engine_class/engine_instance to avoid clash
with C++ keyword. (Tony Ye)
v26:
* Rebased for runtime pm api changes.
v27:
* Rebased for intel_context_init.
* Wrap commit msg to 75.
v28:
(Chris Wilson)
* Use i915_gem_ggtt.
* Use i915_request_await_dma_fence to show a better example.
v29:
* i915_timeline_set_barrier can now fail. (Chris Wilson)
v30:
* Capture some acks.
v31:
* Drop the WARN_ON from use controllable paths. (Chris Wilson)
* Use overflows_type for all checks.
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=100899
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=107634
Issue: https://github.com/intel/media-driver/issues/267
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Cc: Dmitry Rogozhkin <dmitry.v.rogozhkin@intel.com>
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Cc: Zhipeng Gong <zhipeng.gong@intel.com>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Cc: Tony Ye <tony.ye@intel.com>
Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Acked-by: Timo Aaltonen <timo.aaltonen@canonical.com>
Acked-by: Takashi Iwai <tiwai@suse.de>
Acked-by: Stéphane Marchesin <marcheu@chromium.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20190205095032.22673-4-tvrtko.ursulin@linux.intel.com
2019-02-05 09:50:31 +00:00
|
|
|
unsigned int hw_s = hweight8(device->slice_mask);
|
|
|
|
unsigned int hw_ss_per_s = hweight8(device->subslice_mask[0]);
|
|
|
|
unsigned int req_s = hweight8(context->slice_mask);
|
|
|
|
unsigned int req_ss = hweight8(context->subslice_mask);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Only full subslice enablement is possible if more than one
|
|
|
|
* slice is turned on.
|
|
|
|
*/
|
|
|
|
if (req_s > 1 && req_ss != hw_ss_per_s)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If more than four (SScount bitfield limit) subslices are
|
|
|
|
* requested then the number has to be even.
|
|
|
|
*/
|
|
|
|
if (req_ss > 4 && (req_ss & 1))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If only one slice is enabled and subslice count is below the
|
|
|
|
* device full enablement, it must be at most half of the all
|
|
|
|
* available subslices.
|
|
|
|
*/
|
|
|
|
if (req_s == 1 && req_ss < hw_ss_per_s &&
|
|
|
|
req_ss > (hw_ss_per_s / 2))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
/* ABI restriction - VME use case only. */
|
|
|
|
|
|
|
|
/* All slices or one slice only. */
|
|
|
|
if (req_s != 1 && req_s != hw_s)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Half subslices or full enablement only when one slice is
|
|
|
|
* enabled.
|
|
|
|
*/
|
|
|
|
if (req_s == 1 &&
|
|
|
|
(req_ss != hw_ss_per_s && req_ss != (hw_ss_per_s / 2)))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
/* No EU configuration changes. */
|
|
|
|
if ((user->min_eus_per_subslice !=
|
|
|
|
device->max_eus_per_subslice) ||
|
|
|
|
(user->max_eus_per_subslice !=
|
|
|
|
device->max_eus_per_subslice))
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int set_sseu(struct i915_gem_context *ctx,
|
|
|
|
struct drm_i915_gem_context_param *args)
|
|
|
|
{
|
|
|
|
struct drm_i915_private *i915 = ctx->i915;
|
|
|
|
struct drm_i915_gem_context_param_sseu user_sseu;
|
2019-04-26 16:33:32 +00:00
|
|
|
struct intel_context *ce;
|
drm/i915: Expose RPCS (SSEU) configuration to userspace (Gen11 only)
We want to allow userspace to reconfigure the subslice configuration on a
per context basis.
This is required for the functional requirement of shutting down non-VME
enabled sub-slices on Gen11 parts.
To do so, we expose a context parameter to allow adjustment of the RPCS
register stored within the context image (and currently not accessible via
LRI).
If the context is adjusted before first use or whilst idle, the adjustment
is for "free"; otherwise if the context is active we queue a request to do
so (using the kernel context), following all other activity by that
context, which is also marked as barrier for all following submission
against the same context.
Since the overhead of device re-configuration during context switching can
be significant, especially in multi-context workloads, we limit this new
uAPI to only support the Gen11 VME use case. In this use case either the
device is fully enabled, and exactly one slice and half of the subslices
are enabled.
Example usage:
struct drm_i915_gem_context_param_sseu sseu = { };
struct drm_i915_gem_context_param arg = {
.param = I915_CONTEXT_PARAM_SSEU,
.ctx_id = gem_context_create(fd),
.size = sizeof(sseu),
.value = to_user_pointer(&sseu)
};
/* Query device defaults. */
gem_context_get_param(fd, &arg);
/* Set VME configuration on a 1x6x8 part. */
sseu.slice_mask = 0x1;
sseu.subslice_mask = 0xe0;
gem_context_set_param(fd, &arg);
v2: Fix offset of CTX_R_PWR_CLK_STATE in intel_lr_context_set_sseu()
(Lionel)
v3: Add ability to program this per engine (Chris)
v4: Move most get_sseu() into i915_gem_context.c (Lionel)
v5: Validate sseu configuration against the device's capabilities (Lionel)
v6: Change context powergating settings through MI_SDM on kernel context
(Chris)
v7: Synchronize the requests following a powergating setting change using
a global dependency (Chris)
Iterate timelines through dev_priv.gt.active_rings (Tvrtko)
Disable RPCS configuration setting for non capable users
(Lionel/Tvrtko)
v8: s/union intel_sseu/struct intel_sseu/ (Lionel)
s/dev_priv/i915/ (Tvrtko)
Change uapi class/instance fields to u16 (Tvrtko)
Bump mask fields to 64bits (Lionel)
Don't return EPERM when dynamic sseu is disabled (Tvrtko)
v9: Import context image into kernel context's ppgtt only when
reconfiguring powergated slice/subslices (Chris)
Use aliasing ppgtt when needed (Michel)
Tvrtko Ursulin:
v10:
* Update for upstream changes.
* Request submit needs a RPM reference.
* Reject on !FULL_PPGTT for simplicity.
* Pull out get/set param to helpers for readability and less indent.
* Use i915_request_await_dma_fence in add_global_barrier to skip waits
on the same timeline and avoid GEM_BUG_ON.
* No need to explicitly assign a NULL pointer to engine in legacy mode.
* No need to move gen8_make_rpcs up.
* Factored out global barrier as prep patch.
* Allow to only CAP_SYS_ADMIN if !Gen11.
v11:
* Remove engine vfunc in favour of local helper. (Chris Wilson)
* Stop retiring requests before updates since it is not needed
(Chris Wilson)
* Implement direct CPU update path for idle contexts. (Chris Wilson)
* Left side dependency needs only be on the same context timeline.
(Chris Wilson)
* It is sufficient to order the timeline. (Chris Wilson)
* Reject !RCS configuration attempts with -ENODEV for now.
v12:
* Rebase for make_rpcs.
v13:
* Centralize SSEU normalization to make_rpcs.
* Type width checking (uAPI <-> implementation).
* Gen11 restrictions uAPI checks.
* Gen11 subslice count differences handling.
Chris Wilson:
* args->size handling fixes.
* Update context image from GGTT.
* Postpone context image update to pinning.
* Use i915_gem_active_raw instead of last_request_on_engine.
v14:
* Add activity tracker on intel_context to fix the lifetime issues
and simplify the code. (Chris Wilson)
v15:
* Fix context pin leak if no space in ring by simplifying the
context pinning sequence.
v16:
* Rebase for context get/set param locking changes.
* Just -ENODEV on !Gen11. (Joonas)
v17:
* Fix one Gen11 subslice enablement rule.
* Handle error from i915_sw_fence_await_sw_fence_gfp. (Chris Wilson)
v18:
* Update commit message. (Joonas)
* Restrict uAPI to VME use case. (Joonas)
v19:
* Rebase.
v20:
* Rebase for ce->active_tracker.
v21:
* Rebase for IS_GEN changes.
v22:
* Reserve uAPI for flags straight away. (Chris Wilson)
v23:
* Rebase for RUNTIME_INFO.
v24:
* Added some headline docs for the uapi usage. (Joonas/Chris)
v25:
* Renamed class/instance to engine_class/engine_instance to avoid clash
with C++ keyword. (Tony Ye)
v26:
* Rebased for runtime pm api changes.
v27:
* Rebased for intel_context_init.
* Wrap commit msg to 75.
v28:
(Chris Wilson)
* Use i915_gem_ggtt.
* Use i915_request_await_dma_fence to show a better example.
v29:
* i915_timeline_set_barrier can now fail. (Chris Wilson)
v30:
* Capture some acks.
v31:
* Drop the WARN_ON from use controllable paths. (Chris Wilson)
* Use overflows_type for all checks.
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=100899
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=107634
Issue: https://github.com/intel/media-driver/issues/267
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Cc: Dmitry Rogozhkin <dmitry.v.rogozhkin@intel.com>
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Cc: Zhipeng Gong <zhipeng.gong@intel.com>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Cc: Tony Ye <tony.ye@intel.com>
Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Acked-by: Timo Aaltonen <timo.aaltonen@canonical.com>
Acked-by: Takashi Iwai <tiwai@suse.de>
Acked-by: Stéphane Marchesin <marcheu@chromium.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20190205095032.22673-4-tvrtko.ursulin@linux.intel.com
2019-02-05 09:50:31 +00:00
|
|
|
struct intel_sseu sseu;
|
2019-05-21 21:11:27 +00:00
|
|
|
unsigned long lookup;
|
drm/i915: Expose RPCS (SSEU) configuration to userspace (Gen11 only)
We want to allow userspace to reconfigure the subslice configuration on a
per context basis.
This is required for the functional requirement of shutting down non-VME
enabled sub-slices on Gen11 parts.
To do so, we expose a context parameter to allow adjustment of the RPCS
register stored within the context image (and currently not accessible via
LRI).
If the context is adjusted before first use or whilst idle, the adjustment
is for "free"; otherwise if the context is active we queue a request to do
so (using the kernel context), following all other activity by that
context, which is also marked as barrier for all following submission
against the same context.
Since the overhead of device re-configuration during context switching can
be significant, especially in multi-context workloads, we limit this new
uAPI to only support the Gen11 VME use case. In this use case either the
device is fully enabled, and exactly one slice and half of the subslices
are enabled.
Example usage:
struct drm_i915_gem_context_param_sseu sseu = { };
struct drm_i915_gem_context_param arg = {
.param = I915_CONTEXT_PARAM_SSEU,
.ctx_id = gem_context_create(fd),
.size = sizeof(sseu),
.value = to_user_pointer(&sseu)
};
/* Query device defaults. */
gem_context_get_param(fd, &arg);
/* Set VME configuration on a 1x6x8 part. */
sseu.slice_mask = 0x1;
sseu.subslice_mask = 0xe0;
gem_context_set_param(fd, &arg);
v2: Fix offset of CTX_R_PWR_CLK_STATE in intel_lr_context_set_sseu()
(Lionel)
v3: Add ability to program this per engine (Chris)
v4: Move most get_sseu() into i915_gem_context.c (Lionel)
v5: Validate sseu configuration against the device's capabilities (Lionel)
v6: Change context powergating settings through MI_SDM on kernel context
(Chris)
v7: Synchronize the requests following a powergating setting change using
a global dependency (Chris)
Iterate timelines through dev_priv.gt.active_rings (Tvrtko)
Disable RPCS configuration setting for non capable users
(Lionel/Tvrtko)
v8: s/union intel_sseu/struct intel_sseu/ (Lionel)
s/dev_priv/i915/ (Tvrtko)
Change uapi class/instance fields to u16 (Tvrtko)
Bump mask fields to 64bits (Lionel)
Don't return EPERM when dynamic sseu is disabled (Tvrtko)
v9: Import context image into kernel context's ppgtt only when
reconfiguring powergated slice/subslices (Chris)
Use aliasing ppgtt when needed (Michel)
Tvrtko Ursulin:
v10:
* Update for upstream changes.
* Request submit needs a RPM reference.
* Reject on !FULL_PPGTT for simplicity.
* Pull out get/set param to helpers for readability and less indent.
* Use i915_request_await_dma_fence in add_global_barrier to skip waits
on the same timeline and avoid GEM_BUG_ON.
* No need to explicitly assign a NULL pointer to engine in legacy mode.
* No need to move gen8_make_rpcs up.
* Factored out global barrier as prep patch.
* Allow to only CAP_SYS_ADMIN if !Gen11.
v11:
* Remove engine vfunc in favour of local helper. (Chris Wilson)
* Stop retiring requests before updates since it is not needed
(Chris Wilson)
* Implement direct CPU update path for idle contexts. (Chris Wilson)
* Left side dependency needs only be on the same context timeline.
(Chris Wilson)
* It is sufficient to order the timeline. (Chris Wilson)
* Reject !RCS configuration attempts with -ENODEV for now.
v12:
* Rebase for make_rpcs.
v13:
* Centralize SSEU normalization to make_rpcs.
* Type width checking (uAPI <-> implementation).
* Gen11 restrictions uAPI checks.
* Gen11 subslice count differences handling.
Chris Wilson:
* args->size handling fixes.
* Update context image from GGTT.
* Postpone context image update to pinning.
* Use i915_gem_active_raw instead of last_request_on_engine.
v14:
* Add activity tracker on intel_context to fix the lifetime issues
and simplify the code. (Chris Wilson)
v15:
* Fix context pin leak if no space in ring by simplifying the
context pinning sequence.
v16:
* Rebase for context get/set param locking changes.
* Just -ENODEV on !Gen11. (Joonas)
v17:
* Fix one Gen11 subslice enablement rule.
* Handle error from i915_sw_fence_await_sw_fence_gfp. (Chris Wilson)
v18:
* Update commit message. (Joonas)
* Restrict uAPI to VME use case. (Joonas)
v19:
* Rebase.
v20:
* Rebase for ce->active_tracker.
v21:
* Rebase for IS_GEN changes.
v22:
* Reserve uAPI for flags straight away. (Chris Wilson)
v23:
* Rebase for RUNTIME_INFO.
v24:
* Added some headline docs for the uapi usage. (Joonas/Chris)
v25:
* Renamed class/instance to engine_class/engine_instance to avoid clash
with C++ keyword. (Tony Ye)
v26:
* Rebased for runtime pm api changes.
v27:
* Rebased for intel_context_init.
* Wrap commit msg to 75.
v28:
(Chris Wilson)
* Use i915_gem_ggtt.
* Use i915_request_await_dma_fence to show a better example.
v29:
* i915_timeline_set_barrier can now fail. (Chris Wilson)
v30:
* Capture some acks.
v31:
* Drop the WARN_ON from use controllable paths. (Chris Wilson)
* Use overflows_type for all checks.
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=100899
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=107634
Issue: https://github.com/intel/media-driver/issues/267
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Cc: Dmitry Rogozhkin <dmitry.v.rogozhkin@intel.com>
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Cc: Zhipeng Gong <zhipeng.gong@intel.com>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Cc: Tony Ye <tony.ye@intel.com>
Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Acked-by: Timo Aaltonen <timo.aaltonen@canonical.com>
Acked-by: Takashi Iwai <tiwai@suse.de>
Acked-by: Stéphane Marchesin <marcheu@chromium.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20190205095032.22673-4-tvrtko.ursulin@linux.intel.com
2019-02-05 09:50:31 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (args->size < sizeof(user_sseu))
|
|
|
|
return -EINVAL;
|
|
|
|
|
2021-06-05 15:53:54 +00:00
|
|
|
if (GRAPHICS_VER(i915) != 11)
|
drm/i915: Expose RPCS (SSEU) configuration to userspace (Gen11 only)
We want to allow userspace to reconfigure the subslice configuration on a
per context basis.
This is required for the functional requirement of shutting down non-VME
enabled sub-slices on Gen11 parts.
To do so, we expose a context parameter to allow adjustment of the RPCS
register stored within the context image (and currently not accessible via
LRI).
If the context is adjusted before first use or whilst idle, the adjustment
is for "free"; otherwise if the context is active we queue a request to do
so (using the kernel context), following all other activity by that
context, which is also marked as barrier for all following submission
against the same context.
Since the overhead of device re-configuration during context switching can
be significant, especially in multi-context workloads, we limit this new
uAPI to only support the Gen11 VME use case. In this use case either the
device is fully enabled, and exactly one slice and half of the subslices
are enabled.
Example usage:
struct drm_i915_gem_context_param_sseu sseu = { };
struct drm_i915_gem_context_param arg = {
.param = I915_CONTEXT_PARAM_SSEU,
.ctx_id = gem_context_create(fd),
.size = sizeof(sseu),
.value = to_user_pointer(&sseu)
};
/* Query device defaults. */
gem_context_get_param(fd, &arg);
/* Set VME configuration on a 1x6x8 part. */
sseu.slice_mask = 0x1;
sseu.subslice_mask = 0xe0;
gem_context_set_param(fd, &arg);
v2: Fix offset of CTX_R_PWR_CLK_STATE in intel_lr_context_set_sseu()
(Lionel)
v3: Add ability to program this per engine (Chris)
v4: Move most get_sseu() into i915_gem_context.c (Lionel)
v5: Validate sseu configuration against the device's capabilities (Lionel)
v6: Change context powergating settings through MI_SDM on kernel context
(Chris)
v7: Synchronize the requests following a powergating setting change using
a global dependency (Chris)
Iterate timelines through dev_priv.gt.active_rings (Tvrtko)
Disable RPCS configuration setting for non capable users
(Lionel/Tvrtko)
v8: s/union intel_sseu/struct intel_sseu/ (Lionel)
s/dev_priv/i915/ (Tvrtko)
Change uapi class/instance fields to u16 (Tvrtko)
Bump mask fields to 64bits (Lionel)
Don't return EPERM when dynamic sseu is disabled (Tvrtko)
v9: Import context image into kernel context's ppgtt only when
reconfiguring powergated slice/subslices (Chris)
Use aliasing ppgtt when needed (Michel)
Tvrtko Ursulin:
v10:
* Update for upstream changes.
* Request submit needs a RPM reference.
* Reject on !FULL_PPGTT for simplicity.
* Pull out get/set param to helpers for readability and less indent.
* Use i915_request_await_dma_fence in add_global_barrier to skip waits
on the same timeline and avoid GEM_BUG_ON.
* No need to explicitly assign a NULL pointer to engine in legacy mode.
* No need to move gen8_make_rpcs up.
* Factored out global barrier as prep patch.
* Allow to only CAP_SYS_ADMIN if !Gen11.
v11:
* Remove engine vfunc in favour of local helper. (Chris Wilson)
* Stop retiring requests before updates since it is not needed
(Chris Wilson)
* Implement direct CPU update path for idle contexts. (Chris Wilson)
* Left side dependency needs only be on the same context timeline.
(Chris Wilson)
* It is sufficient to order the timeline. (Chris Wilson)
* Reject !RCS configuration attempts with -ENODEV for now.
v12:
* Rebase for make_rpcs.
v13:
* Centralize SSEU normalization to make_rpcs.
* Type width checking (uAPI <-> implementation).
* Gen11 restrictions uAPI checks.
* Gen11 subslice count differences handling.
Chris Wilson:
* args->size handling fixes.
* Update context image from GGTT.
* Postpone context image update to pinning.
* Use i915_gem_active_raw instead of last_request_on_engine.
v14:
* Add activity tracker on intel_context to fix the lifetime issues
and simplify the code. (Chris Wilson)
v15:
* Fix context pin leak if no space in ring by simplifying the
context pinning sequence.
v16:
* Rebase for context get/set param locking changes.
* Just -ENODEV on !Gen11. (Joonas)
v17:
* Fix one Gen11 subslice enablement rule.
* Handle error from i915_sw_fence_await_sw_fence_gfp. (Chris Wilson)
v18:
* Update commit message. (Joonas)
* Restrict uAPI to VME use case. (Joonas)
v19:
* Rebase.
v20:
* Rebase for ce->active_tracker.
v21:
* Rebase for IS_GEN changes.
v22:
* Reserve uAPI for flags straight away. (Chris Wilson)
v23:
* Rebase for RUNTIME_INFO.
v24:
* Added some headline docs for the uapi usage. (Joonas/Chris)
v25:
* Renamed class/instance to engine_class/engine_instance to avoid clash
with C++ keyword. (Tony Ye)
v26:
* Rebased for runtime pm api changes.
v27:
* Rebased for intel_context_init.
* Wrap commit msg to 75.
v28:
(Chris Wilson)
* Use i915_gem_ggtt.
* Use i915_request_await_dma_fence to show a better example.
v29:
* i915_timeline_set_barrier can now fail. (Chris Wilson)
v30:
* Capture some acks.
v31:
* Drop the WARN_ON from use controllable paths. (Chris Wilson)
* Use overflows_type for all checks.
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=100899
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=107634
Issue: https://github.com/intel/media-driver/issues/267
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Cc: Dmitry Rogozhkin <dmitry.v.rogozhkin@intel.com>
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Cc: Zhipeng Gong <zhipeng.gong@intel.com>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Cc: Tony Ye <tony.ye@intel.com>
Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Acked-by: Timo Aaltonen <timo.aaltonen@canonical.com>
Acked-by: Takashi Iwai <tiwai@suse.de>
Acked-by: Stéphane Marchesin <marcheu@chromium.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20190205095032.22673-4-tvrtko.ursulin@linux.intel.com
2019-02-05 09:50:31 +00:00
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
if (copy_from_user(&user_sseu, u64_to_user_ptr(args->value),
|
|
|
|
sizeof(user_sseu)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
2019-05-21 21:11:27 +00:00
|
|
|
if (user_sseu.rsvd)
|
drm/i915: Expose RPCS (SSEU) configuration to userspace (Gen11 only)
We want to allow userspace to reconfigure the subslice configuration on a
per context basis.
This is required for the functional requirement of shutting down non-VME
enabled sub-slices on Gen11 parts.
To do so, we expose a context parameter to allow adjustment of the RPCS
register stored within the context image (and currently not accessible via
LRI).
If the context is adjusted before first use or whilst idle, the adjustment
is for "free"; otherwise if the context is active we queue a request to do
so (using the kernel context), following all other activity by that
context, which is also marked as barrier for all following submission
against the same context.
Since the overhead of device re-configuration during context switching can
be significant, especially in multi-context workloads, we limit this new
uAPI to only support the Gen11 VME use case. In this use case either the
device is fully enabled, and exactly one slice and half of the subslices
are enabled.
Example usage:
struct drm_i915_gem_context_param_sseu sseu = { };
struct drm_i915_gem_context_param arg = {
.param = I915_CONTEXT_PARAM_SSEU,
.ctx_id = gem_context_create(fd),
.size = sizeof(sseu),
.value = to_user_pointer(&sseu)
};
/* Query device defaults. */
gem_context_get_param(fd, &arg);
/* Set VME configuration on a 1x6x8 part. */
sseu.slice_mask = 0x1;
sseu.subslice_mask = 0xe0;
gem_context_set_param(fd, &arg);
v2: Fix offset of CTX_R_PWR_CLK_STATE in intel_lr_context_set_sseu()
(Lionel)
v3: Add ability to program this per engine (Chris)
v4: Move most get_sseu() into i915_gem_context.c (Lionel)
v5: Validate sseu configuration against the device's capabilities (Lionel)
v6: Change context powergating settings through MI_SDM on kernel context
(Chris)
v7: Synchronize the requests following a powergating setting change using
a global dependency (Chris)
Iterate timelines through dev_priv.gt.active_rings (Tvrtko)
Disable RPCS configuration setting for non capable users
(Lionel/Tvrtko)
v8: s/union intel_sseu/struct intel_sseu/ (Lionel)
s/dev_priv/i915/ (Tvrtko)
Change uapi class/instance fields to u16 (Tvrtko)
Bump mask fields to 64bits (Lionel)
Don't return EPERM when dynamic sseu is disabled (Tvrtko)
v9: Import context image into kernel context's ppgtt only when
reconfiguring powergated slice/subslices (Chris)
Use aliasing ppgtt when needed (Michel)
Tvrtko Ursulin:
v10:
* Update for upstream changes.
* Request submit needs a RPM reference.
* Reject on !FULL_PPGTT for simplicity.
* Pull out get/set param to helpers for readability and less indent.
* Use i915_request_await_dma_fence in add_global_barrier to skip waits
on the same timeline and avoid GEM_BUG_ON.
* No need to explicitly assign a NULL pointer to engine in legacy mode.
* No need to move gen8_make_rpcs up.
* Factored out global barrier as prep patch.
* Allow to only CAP_SYS_ADMIN if !Gen11.
v11:
* Remove engine vfunc in favour of local helper. (Chris Wilson)
* Stop retiring requests before updates since it is not needed
(Chris Wilson)
* Implement direct CPU update path for idle contexts. (Chris Wilson)
* Left side dependency needs only be on the same context timeline.
(Chris Wilson)
* It is sufficient to order the timeline. (Chris Wilson)
* Reject !RCS configuration attempts with -ENODEV for now.
v12:
* Rebase for make_rpcs.
v13:
* Centralize SSEU normalization to make_rpcs.
* Type width checking (uAPI <-> implementation).
* Gen11 restrictions uAPI checks.
* Gen11 subslice count differences handling.
Chris Wilson:
* args->size handling fixes.
* Update context image from GGTT.
* Postpone context image update to pinning.
* Use i915_gem_active_raw instead of last_request_on_engine.
v14:
* Add activity tracker on intel_context to fix the lifetime issues
and simplify the code. (Chris Wilson)
v15:
* Fix context pin leak if no space in ring by simplifying the
context pinning sequence.
v16:
* Rebase for context get/set param locking changes.
* Just -ENODEV on !Gen11. (Joonas)
v17:
* Fix one Gen11 subslice enablement rule.
* Handle error from i915_sw_fence_await_sw_fence_gfp. (Chris Wilson)
v18:
* Update commit message. (Joonas)
* Restrict uAPI to VME use case. (Joonas)
v19:
* Rebase.
v20:
* Rebase for ce->active_tracker.
v21:
* Rebase for IS_GEN changes.
v22:
* Reserve uAPI for flags straight away. (Chris Wilson)
v23:
* Rebase for RUNTIME_INFO.
v24:
* Added some headline docs for the uapi usage. (Joonas/Chris)
v25:
* Renamed class/instance to engine_class/engine_instance to avoid clash
with C++ keyword. (Tony Ye)
v26:
* Rebased for runtime pm api changes.
v27:
* Rebased for intel_context_init.
* Wrap commit msg to 75.
v28:
(Chris Wilson)
* Use i915_gem_ggtt.
* Use i915_request_await_dma_fence to show a better example.
v29:
* i915_timeline_set_barrier can now fail. (Chris Wilson)
v30:
* Capture some acks.
v31:
* Drop the WARN_ON from use controllable paths. (Chris Wilson)
* Use overflows_type for all checks.
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=100899
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=107634
Issue: https://github.com/intel/media-driver/issues/267
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Cc: Dmitry Rogozhkin <dmitry.v.rogozhkin@intel.com>
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Cc: Zhipeng Gong <zhipeng.gong@intel.com>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Cc: Tony Ye <tony.ye@intel.com>
Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Acked-by: Timo Aaltonen <timo.aaltonen@canonical.com>
Acked-by: Takashi Iwai <tiwai@suse.de>
Acked-by: Stéphane Marchesin <marcheu@chromium.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20190205095032.22673-4-tvrtko.ursulin@linux.intel.com
2019-02-05 09:50:31 +00:00
|
|
|
return -EINVAL;
|
|
|
|
|
2019-05-21 21:11:27 +00:00
|
|
|
if (user_sseu.flags & ~(I915_CONTEXT_SSEU_FLAG_ENGINE_INDEX))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
lookup = 0;
|
|
|
|
if (user_sseu.flags & I915_CONTEXT_SSEU_FLAG_ENGINE_INDEX)
|
|
|
|
lookup |= LOOKUP_USER_INDEX;
|
|
|
|
|
|
|
|
ce = lookup_user_engine(ctx, lookup, &user_sseu.engine);
|
2019-04-26 16:33:32 +00:00
|
|
|
if (IS_ERR(ce))
|
|
|
|
return PTR_ERR(ce);
|
drm/i915: Expose RPCS (SSEU) configuration to userspace (Gen11 only)
We want to allow userspace to reconfigure the subslice configuration on a
per context basis.
This is required for the functional requirement of shutting down non-VME
enabled sub-slices on Gen11 parts.
To do so, we expose a context parameter to allow adjustment of the RPCS
register stored within the context image (and currently not accessible via
LRI).
If the context is adjusted before first use or whilst idle, the adjustment
is for "free"; otherwise if the context is active we queue a request to do
so (using the kernel context), following all other activity by that
context, which is also marked as barrier for all following submission
against the same context.
Since the overhead of device re-configuration during context switching can
be significant, especially in multi-context workloads, we limit this new
uAPI to only support the Gen11 VME use case. In this use case either the
device is fully enabled, and exactly one slice and half of the subslices
are enabled.
Example usage:
struct drm_i915_gem_context_param_sseu sseu = { };
struct drm_i915_gem_context_param arg = {
.param = I915_CONTEXT_PARAM_SSEU,
.ctx_id = gem_context_create(fd),
.size = sizeof(sseu),
.value = to_user_pointer(&sseu)
};
/* Query device defaults. */
gem_context_get_param(fd, &arg);
/* Set VME configuration on a 1x6x8 part. */
sseu.slice_mask = 0x1;
sseu.subslice_mask = 0xe0;
gem_context_set_param(fd, &arg);
v2: Fix offset of CTX_R_PWR_CLK_STATE in intel_lr_context_set_sseu()
(Lionel)
v3: Add ability to program this per engine (Chris)
v4: Move most get_sseu() into i915_gem_context.c (Lionel)
v5: Validate sseu configuration against the device's capabilities (Lionel)
v6: Change context powergating settings through MI_SDM on kernel context
(Chris)
v7: Synchronize the requests following a powergating setting change using
a global dependency (Chris)
Iterate timelines through dev_priv.gt.active_rings (Tvrtko)
Disable RPCS configuration setting for non capable users
(Lionel/Tvrtko)
v8: s/union intel_sseu/struct intel_sseu/ (Lionel)
s/dev_priv/i915/ (Tvrtko)
Change uapi class/instance fields to u16 (Tvrtko)
Bump mask fields to 64bits (Lionel)
Don't return EPERM when dynamic sseu is disabled (Tvrtko)
v9: Import context image into kernel context's ppgtt only when
reconfiguring powergated slice/subslices (Chris)
Use aliasing ppgtt when needed (Michel)
Tvrtko Ursulin:
v10:
* Update for upstream changes.
* Request submit needs a RPM reference.
* Reject on !FULL_PPGTT for simplicity.
* Pull out get/set param to helpers for readability and less indent.
* Use i915_request_await_dma_fence in add_global_barrier to skip waits
on the same timeline and avoid GEM_BUG_ON.
* No need to explicitly assign a NULL pointer to engine in legacy mode.
* No need to move gen8_make_rpcs up.
* Factored out global barrier as prep patch.
* Allow to only CAP_SYS_ADMIN if !Gen11.
v11:
* Remove engine vfunc in favour of local helper. (Chris Wilson)
* Stop retiring requests before updates since it is not needed
(Chris Wilson)
* Implement direct CPU update path for idle contexts. (Chris Wilson)
* Left side dependency needs only be on the same context timeline.
(Chris Wilson)
* It is sufficient to order the timeline. (Chris Wilson)
* Reject !RCS configuration attempts with -ENODEV for now.
v12:
* Rebase for make_rpcs.
v13:
* Centralize SSEU normalization to make_rpcs.
* Type width checking (uAPI <-> implementation).
* Gen11 restrictions uAPI checks.
* Gen11 subslice count differences handling.
Chris Wilson:
* args->size handling fixes.
* Update context image from GGTT.
* Postpone context image update to pinning.
* Use i915_gem_active_raw instead of last_request_on_engine.
v14:
* Add activity tracker on intel_context to fix the lifetime issues
and simplify the code. (Chris Wilson)
v15:
* Fix context pin leak if no space in ring by simplifying the
context pinning sequence.
v16:
* Rebase for context get/set param locking changes.
* Just -ENODEV on !Gen11. (Joonas)
v17:
* Fix one Gen11 subslice enablement rule.
* Handle error from i915_sw_fence_await_sw_fence_gfp. (Chris Wilson)
v18:
* Update commit message. (Joonas)
* Restrict uAPI to VME use case. (Joonas)
v19:
* Rebase.
v20:
* Rebase for ce->active_tracker.
v21:
* Rebase for IS_GEN changes.
v22:
* Reserve uAPI for flags straight away. (Chris Wilson)
v23:
* Rebase for RUNTIME_INFO.
v24:
* Added some headline docs for the uapi usage. (Joonas/Chris)
v25:
* Renamed class/instance to engine_class/engine_instance to avoid clash
with C++ keyword. (Tony Ye)
v26:
* Rebased for runtime pm api changes.
v27:
* Rebased for intel_context_init.
* Wrap commit msg to 75.
v28:
(Chris Wilson)
* Use i915_gem_ggtt.
* Use i915_request_await_dma_fence to show a better example.
v29:
* i915_timeline_set_barrier can now fail. (Chris Wilson)
v30:
* Capture some acks.
v31:
* Drop the WARN_ON from use controllable paths. (Chris Wilson)
* Use overflows_type for all checks.
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=100899
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=107634
Issue: https://github.com/intel/media-driver/issues/267
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Cc: Dmitry Rogozhkin <dmitry.v.rogozhkin@intel.com>
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Cc: Zhipeng Gong <zhipeng.gong@intel.com>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Cc: Tony Ye <tony.ye@intel.com>
Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Acked-by: Timo Aaltonen <timo.aaltonen@canonical.com>
Acked-by: Takashi Iwai <tiwai@suse.de>
Acked-by: Stéphane Marchesin <marcheu@chromium.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20190205095032.22673-4-tvrtko.ursulin@linux.intel.com
2019-02-05 09:50:31 +00:00
|
|
|
|
|
|
|
/* Only render engine supports RPCS configuration. */
|
2019-04-26 16:33:32 +00:00
|
|
|
if (ce->engine->class != RENDER_CLASS) {
|
|
|
|
ret = -ENODEV;
|
|
|
|
goto out_ce;
|
|
|
|
}
|
drm/i915: Expose RPCS (SSEU) configuration to userspace (Gen11 only)
We want to allow userspace to reconfigure the subslice configuration on a
per context basis.
This is required for the functional requirement of shutting down non-VME
enabled sub-slices on Gen11 parts.
To do so, we expose a context parameter to allow adjustment of the RPCS
register stored within the context image (and currently not accessible via
LRI).
If the context is adjusted before first use or whilst idle, the adjustment
is for "free"; otherwise if the context is active we queue a request to do
so (using the kernel context), following all other activity by that
context, which is also marked as barrier for all following submission
against the same context.
Since the overhead of device re-configuration during context switching can
be significant, especially in multi-context workloads, we limit this new
uAPI to only support the Gen11 VME use case. In this use case either the
device is fully enabled, and exactly one slice and half of the subslices
are enabled.
Example usage:
struct drm_i915_gem_context_param_sseu sseu = { };
struct drm_i915_gem_context_param arg = {
.param = I915_CONTEXT_PARAM_SSEU,
.ctx_id = gem_context_create(fd),
.size = sizeof(sseu),
.value = to_user_pointer(&sseu)
};
/* Query device defaults. */
gem_context_get_param(fd, &arg);
/* Set VME configuration on a 1x6x8 part. */
sseu.slice_mask = 0x1;
sseu.subslice_mask = 0xe0;
gem_context_set_param(fd, &arg);
v2: Fix offset of CTX_R_PWR_CLK_STATE in intel_lr_context_set_sseu()
(Lionel)
v3: Add ability to program this per engine (Chris)
v4: Move most get_sseu() into i915_gem_context.c (Lionel)
v5: Validate sseu configuration against the device's capabilities (Lionel)
v6: Change context powergating settings through MI_SDM on kernel context
(Chris)
v7: Synchronize the requests following a powergating setting change using
a global dependency (Chris)
Iterate timelines through dev_priv.gt.active_rings (Tvrtko)
Disable RPCS configuration setting for non capable users
(Lionel/Tvrtko)
v8: s/union intel_sseu/struct intel_sseu/ (Lionel)
s/dev_priv/i915/ (Tvrtko)
Change uapi class/instance fields to u16 (Tvrtko)
Bump mask fields to 64bits (Lionel)
Don't return EPERM when dynamic sseu is disabled (Tvrtko)
v9: Import context image into kernel context's ppgtt only when
reconfiguring powergated slice/subslices (Chris)
Use aliasing ppgtt when needed (Michel)
Tvrtko Ursulin:
v10:
* Update for upstream changes.
* Request submit needs a RPM reference.
* Reject on !FULL_PPGTT for simplicity.
* Pull out get/set param to helpers for readability and less indent.
* Use i915_request_await_dma_fence in add_global_barrier to skip waits
on the same timeline and avoid GEM_BUG_ON.
* No need to explicitly assign a NULL pointer to engine in legacy mode.
* No need to move gen8_make_rpcs up.
* Factored out global barrier as prep patch.
* Allow to only CAP_SYS_ADMIN if !Gen11.
v11:
* Remove engine vfunc in favour of local helper. (Chris Wilson)
* Stop retiring requests before updates since it is not needed
(Chris Wilson)
* Implement direct CPU update path for idle contexts. (Chris Wilson)
* Left side dependency needs only be on the same context timeline.
(Chris Wilson)
* It is sufficient to order the timeline. (Chris Wilson)
* Reject !RCS configuration attempts with -ENODEV for now.
v12:
* Rebase for make_rpcs.
v13:
* Centralize SSEU normalization to make_rpcs.
* Type width checking (uAPI <-> implementation).
* Gen11 restrictions uAPI checks.
* Gen11 subslice count differences handling.
Chris Wilson:
* args->size handling fixes.
* Update context image from GGTT.
* Postpone context image update to pinning.
* Use i915_gem_active_raw instead of last_request_on_engine.
v14:
* Add activity tracker on intel_context to fix the lifetime issues
and simplify the code. (Chris Wilson)
v15:
* Fix context pin leak if no space in ring by simplifying the
context pinning sequence.
v16:
* Rebase for context get/set param locking changes.
* Just -ENODEV on !Gen11. (Joonas)
v17:
* Fix one Gen11 subslice enablement rule.
* Handle error from i915_sw_fence_await_sw_fence_gfp. (Chris Wilson)
v18:
* Update commit message. (Joonas)
* Restrict uAPI to VME use case. (Joonas)
v19:
* Rebase.
v20:
* Rebase for ce->active_tracker.
v21:
* Rebase for IS_GEN changes.
v22:
* Reserve uAPI for flags straight away. (Chris Wilson)
v23:
* Rebase for RUNTIME_INFO.
v24:
* Added some headline docs for the uapi usage. (Joonas/Chris)
v25:
* Renamed class/instance to engine_class/engine_instance to avoid clash
with C++ keyword. (Tony Ye)
v26:
* Rebased for runtime pm api changes.
v27:
* Rebased for intel_context_init.
* Wrap commit msg to 75.
v28:
(Chris Wilson)
* Use i915_gem_ggtt.
* Use i915_request_await_dma_fence to show a better example.
v29:
* i915_timeline_set_barrier can now fail. (Chris Wilson)
v30:
* Capture some acks.
v31:
* Drop the WARN_ON from use controllable paths. (Chris Wilson)
* Use overflows_type for all checks.
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=100899
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=107634
Issue: https://github.com/intel/media-driver/issues/267
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Cc: Dmitry Rogozhkin <dmitry.v.rogozhkin@intel.com>
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Cc: Zhipeng Gong <zhipeng.gong@intel.com>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Cc: Tony Ye <tony.ye@intel.com>
Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Acked-by: Timo Aaltonen <timo.aaltonen@canonical.com>
Acked-by: Takashi Iwai <tiwai@suse.de>
Acked-by: Stéphane Marchesin <marcheu@chromium.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20190205095032.22673-4-tvrtko.ursulin@linux.intel.com
2019-02-05 09:50:31 +00:00
|
|
|
|
2020-07-08 00:39:50 +00:00
|
|
|
ret = i915_gem_user_to_context_sseu(ce->engine->gt, &user_sseu, &sseu);
|
drm/i915: Expose RPCS (SSEU) configuration to userspace (Gen11 only)
We want to allow userspace to reconfigure the subslice configuration on a
per context basis.
This is required for the functional requirement of shutting down non-VME
enabled sub-slices on Gen11 parts.
To do so, we expose a context parameter to allow adjustment of the RPCS
register stored within the context image (and currently not accessible via
LRI).
If the context is adjusted before first use or whilst idle, the adjustment
is for "free"; otherwise if the context is active we queue a request to do
so (using the kernel context), following all other activity by that
context, which is also marked as barrier for all following submission
against the same context.
Since the overhead of device re-configuration during context switching can
be significant, especially in multi-context workloads, we limit this new
uAPI to only support the Gen11 VME use case. In this use case either the
device is fully enabled, and exactly one slice and half of the subslices
are enabled.
Example usage:
struct drm_i915_gem_context_param_sseu sseu = { };
struct drm_i915_gem_context_param arg = {
.param = I915_CONTEXT_PARAM_SSEU,
.ctx_id = gem_context_create(fd),
.size = sizeof(sseu),
.value = to_user_pointer(&sseu)
};
/* Query device defaults. */
gem_context_get_param(fd, &arg);
/* Set VME configuration on a 1x6x8 part. */
sseu.slice_mask = 0x1;
sseu.subslice_mask = 0xe0;
gem_context_set_param(fd, &arg);
v2: Fix offset of CTX_R_PWR_CLK_STATE in intel_lr_context_set_sseu()
(Lionel)
v3: Add ability to program this per engine (Chris)
v4: Move most get_sseu() into i915_gem_context.c (Lionel)
v5: Validate sseu configuration against the device's capabilities (Lionel)
v6: Change context powergating settings through MI_SDM on kernel context
(Chris)
v7: Synchronize the requests following a powergating setting change using
a global dependency (Chris)
Iterate timelines through dev_priv.gt.active_rings (Tvrtko)
Disable RPCS configuration setting for non capable users
(Lionel/Tvrtko)
v8: s/union intel_sseu/struct intel_sseu/ (Lionel)
s/dev_priv/i915/ (Tvrtko)
Change uapi class/instance fields to u16 (Tvrtko)
Bump mask fields to 64bits (Lionel)
Don't return EPERM when dynamic sseu is disabled (Tvrtko)
v9: Import context image into kernel context's ppgtt only when
reconfiguring powergated slice/subslices (Chris)
Use aliasing ppgtt when needed (Michel)
Tvrtko Ursulin:
v10:
* Update for upstream changes.
* Request submit needs a RPM reference.
* Reject on !FULL_PPGTT for simplicity.
* Pull out get/set param to helpers for readability and less indent.
* Use i915_request_await_dma_fence in add_global_barrier to skip waits
on the same timeline and avoid GEM_BUG_ON.
* No need to explicitly assign a NULL pointer to engine in legacy mode.
* No need to move gen8_make_rpcs up.
* Factored out global barrier as prep patch.
* Allow to only CAP_SYS_ADMIN if !Gen11.
v11:
* Remove engine vfunc in favour of local helper. (Chris Wilson)
* Stop retiring requests before updates since it is not needed
(Chris Wilson)
* Implement direct CPU update path for idle contexts. (Chris Wilson)
* Left side dependency needs only be on the same context timeline.
(Chris Wilson)
* It is sufficient to order the timeline. (Chris Wilson)
* Reject !RCS configuration attempts with -ENODEV for now.
v12:
* Rebase for make_rpcs.
v13:
* Centralize SSEU normalization to make_rpcs.
* Type width checking (uAPI <-> implementation).
* Gen11 restrictions uAPI checks.
* Gen11 subslice count differences handling.
Chris Wilson:
* args->size handling fixes.
* Update context image from GGTT.
* Postpone context image update to pinning.
* Use i915_gem_active_raw instead of last_request_on_engine.
v14:
* Add activity tracker on intel_context to fix the lifetime issues
and simplify the code. (Chris Wilson)
v15:
* Fix context pin leak if no space in ring by simplifying the
context pinning sequence.
v16:
* Rebase for context get/set param locking changes.
* Just -ENODEV on !Gen11. (Joonas)
v17:
* Fix one Gen11 subslice enablement rule.
* Handle error from i915_sw_fence_await_sw_fence_gfp. (Chris Wilson)
v18:
* Update commit message. (Joonas)
* Restrict uAPI to VME use case. (Joonas)
v19:
* Rebase.
v20:
* Rebase for ce->active_tracker.
v21:
* Rebase for IS_GEN changes.
v22:
* Reserve uAPI for flags straight away. (Chris Wilson)
v23:
* Rebase for RUNTIME_INFO.
v24:
* Added some headline docs for the uapi usage. (Joonas/Chris)
v25:
* Renamed class/instance to engine_class/engine_instance to avoid clash
with C++ keyword. (Tony Ye)
v26:
* Rebased for runtime pm api changes.
v27:
* Rebased for intel_context_init.
* Wrap commit msg to 75.
v28:
(Chris Wilson)
* Use i915_gem_ggtt.
* Use i915_request_await_dma_fence to show a better example.
v29:
* i915_timeline_set_barrier can now fail. (Chris Wilson)
v30:
* Capture some acks.
v31:
* Drop the WARN_ON from use controllable paths. (Chris Wilson)
* Use overflows_type for all checks.
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=100899
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=107634
Issue: https://github.com/intel/media-driver/issues/267
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Cc: Dmitry Rogozhkin <dmitry.v.rogozhkin@intel.com>
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Cc: Zhipeng Gong <zhipeng.gong@intel.com>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Cc: Tony Ye <tony.ye@intel.com>
Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Acked-by: Timo Aaltonen <timo.aaltonen@canonical.com>
Acked-by: Takashi Iwai <tiwai@suse.de>
Acked-by: Stéphane Marchesin <marcheu@chromium.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20190205095032.22673-4-tvrtko.ursulin@linux.intel.com
2019-02-05 09:50:31 +00:00
|
|
|
if (ret)
|
2019-04-26 16:33:32 +00:00
|
|
|
goto out_ce;
|
drm/i915: Expose RPCS (SSEU) configuration to userspace (Gen11 only)
We want to allow userspace to reconfigure the subslice configuration on a
per context basis.
This is required for the functional requirement of shutting down non-VME
enabled sub-slices on Gen11 parts.
To do so, we expose a context parameter to allow adjustment of the RPCS
register stored within the context image (and currently not accessible via
LRI).
If the context is adjusted before first use or whilst idle, the adjustment
is for "free"; otherwise if the context is active we queue a request to do
so (using the kernel context), following all other activity by that
context, which is also marked as barrier for all following submission
against the same context.
Since the overhead of device re-configuration during context switching can
be significant, especially in multi-context workloads, we limit this new
uAPI to only support the Gen11 VME use case. In this use case either the
device is fully enabled, and exactly one slice and half of the subslices
are enabled.
Example usage:
struct drm_i915_gem_context_param_sseu sseu = { };
struct drm_i915_gem_context_param arg = {
.param = I915_CONTEXT_PARAM_SSEU,
.ctx_id = gem_context_create(fd),
.size = sizeof(sseu),
.value = to_user_pointer(&sseu)
};
/* Query device defaults. */
gem_context_get_param(fd, &arg);
/* Set VME configuration on a 1x6x8 part. */
sseu.slice_mask = 0x1;
sseu.subslice_mask = 0xe0;
gem_context_set_param(fd, &arg);
v2: Fix offset of CTX_R_PWR_CLK_STATE in intel_lr_context_set_sseu()
(Lionel)
v3: Add ability to program this per engine (Chris)
v4: Move most get_sseu() into i915_gem_context.c (Lionel)
v5: Validate sseu configuration against the device's capabilities (Lionel)
v6: Change context powergating settings through MI_SDM on kernel context
(Chris)
v7: Synchronize the requests following a powergating setting change using
a global dependency (Chris)
Iterate timelines through dev_priv.gt.active_rings (Tvrtko)
Disable RPCS configuration setting for non capable users
(Lionel/Tvrtko)
v8: s/union intel_sseu/struct intel_sseu/ (Lionel)
s/dev_priv/i915/ (Tvrtko)
Change uapi class/instance fields to u16 (Tvrtko)
Bump mask fields to 64bits (Lionel)
Don't return EPERM when dynamic sseu is disabled (Tvrtko)
v9: Import context image into kernel context's ppgtt only when
reconfiguring powergated slice/subslices (Chris)
Use aliasing ppgtt when needed (Michel)
Tvrtko Ursulin:
v10:
* Update for upstream changes.
* Request submit needs a RPM reference.
* Reject on !FULL_PPGTT for simplicity.
* Pull out get/set param to helpers for readability and less indent.
* Use i915_request_await_dma_fence in add_global_barrier to skip waits
on the same timeline and avoid GEM_BUG_ON.
* No need to explicitly assign a NULL pointer to engine in legacy mode.
* No need to move gen8_make_rpcs up.
* Factored out global barrier as prep patch.
* Allow to only CAP_SYS_ADMIN if !Gen11.
v11:
* Remove engine vfunc in favour of local helper. (Chris Wilson)
* Stop retiring requests before updates since it is not needed
(Chris Wilson)
* Implement direct CPU update path for idle contexts. (Chris Wilson)
* Left side dependency needs only be on the same context timeline.
(Chris Wilson)
* It is sufficient to order the timeline. (Chris Wilson)
* Reject !RCS configuration attempts with -ENODEV for now.
v12:
* Rebase for make_rpcs.
v13:
* Centralize SSEU normalization to make_rpcs.
* Type width checking (uAPI <-> implementation).
* Gen11 restrictions uAPI checks.
* Gen11 subslice count differences handling.
Chris Wilson:
* args->size handling fixes.
* Update context image from GGTT.
* Postpone context image update to pinning.
* Use i915_gem_active_raw instead of last_request_on_engine.
v14:
* Add activity tracker on intel_context to fix the lifetime issues
and simplify the code. (Chris Wilson)
v15:
* Fix context pin leak if no space in ring by simplifying the
context pinning sequence.
v16:
* Rebase for context get/set param locking changes.
* Just -ENODEV on !Gen11. (Joonas)
v17:
* Fix one Gen11 subslice enablement rule.
* Handle error from i915_sw_fence_await_sw_fence_gfp. (Chris Wilson)
v18:
* Update commit message. (Joonas)
* Restrict uAPI to VME use case. (Joonas)
v19:
* Rebase.
v20:
* Rebase for ce->active_tracker.
v21:
* Rebase for IS_GEN changes.
v22:
* Reserve uAPI for flags straight away. (Chris Wilson)
v23:
* Rebase for RUNTIME_INFO.
v24:
* Added some headline docs for the uapi usage. (Joonas/Chris)
v25:
* Renamed class/instance to engine_class/engine_instance to avoid clash
with C++ keyword. (Tony Ye)
v26:
* Rebased for runtime pm api changes.
v27:
* Rebased for intel_context_init.
* Wrap commit msg to 75.
v28:
(Chris Wilson)
* Use i915_gem_ggtt.
* Use i915_request_await_dma_fence to show a better example.
v29:
* i915_timeline_set_barrier can now fail. (Chris Wilson)
v30:
* Capture some acks.
v31:
* Drop the WARN_ON from use controllable paths. (Chris Wilson)
* Use overflows_type for all checks.
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=100899
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=107634
Issue: https://github.com/intel/media-driver/issues/267
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Cc: Dmitry Rogozhkin <dmitry.v.rogozhkin@intel.com>
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Cc: Zhipeng Gong <zhipeng.gong@intel.com>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Cc: Tony Ye <tony.ye@intel.com>
Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Acked-by: Timo Aaltonen <timo.aaltonen@canonical.com>
Acked-by: Takashi Iwai <tiwai@suse.de>
Acked-by: Stéphane Marchesin <marcheu@chromium.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20190205095032.22673-4-tvrtko.ursulin@linux.intel.com
2019-02-05 09:50:31 +00:00
|
|
|
|
2019-04-26 16:33:32 +00:00
|
|
|
ret = intel_context_reconfigure_sseu(ce, sseu);
|
drm/i915: Expose RPCS (SSEU) configuration to userspace (Gen11 only)
We want to allow userspace to reconfigure the subslice configuration on a
per context basis.
This is required for the functional requirement of shutting down non-VME
enabled sub-slices on Gen11 parts.
To do so, we expose a context parameter to allow adjustment of the RPCS
register stored within the context image (and currently not accessible via
LRI).
If the context is adjusted before first use or whilst idle, the adjustment
is for "free"; otherwise if the context is active we queue a request to do
so (using the kernel context), following all other activity by that
context, which is also marked as barrier for all following submission
against the same context.
Since the overhead of device re-configuration during context switching can
be significant, especially in multi-context workloads, we limit this new
uAPI to only support the Gen11 VME use case. In this use case either the
device is fully enabled, and exactly one slice and half of the subslices
are enabled.
Example usage:
struct drm_i915_gem_context_param_sseu sseu = { };
struct drm_i915_gem_context_param arg = {
.param = I915_CONTEXT_PARAM_SSEU,
.ctx_id = gem_context_create(fd),
.size = sizeof(sseu),
.value = to_user_pointer(&sseu)
};
/* Query device defaults. */
gem_context_get_param(fd, &arg);
/* Set VME configuration on a 1x6x8 part. */
sseu.slice_mask = 0x1;
sseu.subslice_mask = 0xe0;
gem_context_set_param(fd, &arg);
v2: Fix offset of CTX_R_PWR_CLK_STATE in intel_lr_context_set_sseu()
(Lionel)
v3: Add ability to program this per engine (Chris)
v4: Move most get_sseu() into i915_gem_context.c (Lionel)
v5: Validate sseu configuration against the device's capabilities (Lionel)
v6: Change context powergating settings through MI_SDM on kernel context
(Chris)
v7: Synchronize the requests following a powergating setting change using
a global dependency (Chris)
Iterate timelines through dev_priv.gt.active_rings (Tvrtko)
Disable RPCS configuration setting for non capable users
(Lionel/Tvrtko)
v8: s/union intel_sseu/struct intel_sseu/ (Lionel)
s/dev_priv/i915/ (Tvrtko)
Change uapi class/instance fields to u16 (Tvrtko)
Bump mask fields to 64bits (Lionel)
Don't return EPERM when dynamic sseu is disabled (Tvrtko)
v9: Import context image into kernel context's ppgtt only when
reconfiguring powergated slice/subslices (Chris)
Use aliasing ppgtt when needed (Michel)
Tvrtko Ursulin:
v10:
* Update for upstream changes.
* Request submit needs a RPM reference.
* Reject on !FULL_PPGTT for simplicity.
* Pull out get/set param to helpers for readability and less indent.
* Use i915_request_await_dma_fence in add_global_barrier to skip waits
on the same timeline and avoid GEM_BUG_ON.
* No need to explicitly assign a NULL pointer to engine in legacy mode.
* No need to move gen8_make_rpcs up.
* Factored out global barrier as prep patch.
* Allow to only CAP_SYS_ADMIN if !Gen11.
v11:
* Remove engine vfunc in favour of local helper. (Chris Wilson)
* Stop retiring requests before updates since it is not needed
(Chris Wilson)
* Implement direct CPU update path for idle contexts. (Chris Wilson)
* Left side dependency needs only be on the same context timeline.
(Chris Wilson)
* It is sufficient to order the timeline. (Chris Wilson)
* Reject !RCS configuration attempts with -ENODEV for now.
v12:
* Rebase for make_rpcs.
v13:
* Centralize SSEU normalization to make_rpcs.
* Type width checking (uAPI <-> implementation).
* Gen11 restrictions uAPI checks.
* Gen11 subslice count differences handling.
Chris Wilson:
* args->size handling fixes.
* Update context image from GGTT.
* Postpone context image update to pinning.
* Use i915_gem_active_raw instead of last_request_on_engine.
v14:
* Add activity tracker on intel_context to fix the lifetime issues
and simplify the code. (Chris Wilson)
v15:
* Fix context pin leak if no space in ring by simplifying the
context pinning sequence.
v16:
* Rebase for context get/set param locking changes.
* Just -ENODEV on !Gen11. (Joonas)
v17:
* Fix one Gen11 subslice enablement rule.
* Handle error from i915_sw_fence_await_sw_fence_gfp. (Chris Wilson)
v18:
* Update commit message. (Joonas)
* Restrict uAPI to VME use case. (Joonas)
v19:
* Rebase.
v20:
* Rebase for ce->active_tracker.
v21:
* Rebase for IS_GEN changes.
v22:
* Reserve uAPI for flags straight away. (Chris Wilson)
v23:
* Rebase for RUNTIME_INFO.
v24:
* Added some headline docs for the uapi usage. (Joonas/Chris)
v25:
* Renamed class/instance to engine_class/engine_instance to avoid clash
with C++ keyword. (Tony Ye)
v26:
* Rebased for runtime pm api changes.
v27:
* Rebased for intel_context_init.
* Wrap commit msg to 75.
v28:
(Chris Wilson)
* Use i915_gem_ggtt.
* Use i915_request_await_dma_fence to show a better example.
v29:
* i915_timeline_set_barrier can now fail. (Chris Wilson)
v30:
* Capture some acks.
v31:
* Drop the WARN_ON from use controllable paths. (Chris Wilson)
* Use overflows_type for all checks.
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=100899
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=107634
Issue: https://github.com/intel/media-driver/issues/267
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Cc: Dmitry Rogozhkin <dmitry.v.rogozhkin@intel.com>
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Cc: Zhipeng Gong <zhipeng.gong@intel.com>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Cc: Tony Ye <tony.ye@intel.com>
Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Acked-by: Timo Aaltonen <timo.aaltonen@canonical.com>
Acked-by: Takashi Iwai <tiwai@suse.de>
Acked-by: Stéphane Marchesin <marcheu@chromium.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20190205095032.22673-4-tvrtko.ursulin@linux.intel.com
2019-02-05 09:50:31 +00:00
|
|
|
if (ret)
|
2019-04-26 16:33:32 +00:00
|
|
|
goto out_ce;
|
drm/i915: Expose RPCS (SSEU) configuration to userspace (Gen11 only)
We want to allow userspace to reconfigure the subslice configuration on a
per context basis.
This is required for the functional requirement of shutting down non-VME
enabled sub-slices on Gen11 parts.
To do so, we expose a context parameter to allow adjustment of the RPCS
register stored within the context image (and currently not accessible via
LRI).
If the context is adjusted before first use or whilst idle, the adjustment
is for "free"; otherwise if the context is active we queue a request to do
so (using the kernel context), following all other activity by that
context, which is also marked as barrier for all following submission
against the same context.
Since the overhead of device re-configuration during context switching can
be significant, especially in multi-context workloads, we limit this new
uAPI to only support the Gen11 VME use case. In this use case either the
device is fully enabled, and exactly one slice and half of the subslices
are enabled.
Example usage:
struct drm_i915_gem_context_param_sseu sseu = { };
struct drm_i915_gem_context_param arg = {
.param = I915_CONTEXT_PARAM_SSEU,
.ctx_id = gem_context_create(fd),
.size = sizeof(sseu),
.value = to_user_pointer(&sseu)
};
/* Query device defaults. */
gem_context_get_param(fd, &arg);
/* Set VME configuration on a 1x6x8 part. */
sseu.slice_mask = 0x1;
sseu.subslice_mask = 0xe0;
gem_context_set_param(fd, &arg);
v2: Fix offset of CTX_R_PWR_CLK_STATE in intel_lr_context_set_sseu()
(Lionel)
v3: Add ability to program this per engine (Chris)
v4: Move most get_sseu() into i915_gem_context.c (Lionel)
v5: Validate sseu configuration against the device's capabilities (Lionel)
v6: Change context powergating settings through MI_SDM on kernel context
(Chris)
v7: Synchronize the requests following a powergating setting change using
a global dependency (Chris)
Iterate timelines through dev_priv.gt.active_rings (Tvrtko)
Disable RPCS configuration setting for non capable users
(Lionel/Tvrtko)
v8: s/union intel_sseu/struct intel_sseu/ (Lionel)
s/dev_priv/i915/ (Tvrtko)
Change uapi class/instance fields to u16 (Tvrtko)
Bump mask fields to 64bits (Lionel)
Don't return EPERM when dynamic sseu is disabled (Tvrtko)
v9: Import context image into kernel context's ppgtt only when
reconfiguring powergated slice/subslices (Chris)
Use aliasing ppgtt when needed (Michel)
Tvrtko Ursulin:
v10:
* Update for upstream changes.
* Request submit needs a RPM reference.
* Reject on !FULL_PPGTT for simplicity.
* Pull out get/set param to helpers for readability and less indent.
* Use i915_request_await_dma_fence in add_global_barrier to skip waits
on the same timeline and avoid GEM_BUG_ON.
* No need to explicitly assign a NULL pointer to engine in legacy mode.
* No need to move gen8_make_rpcs up.
* Factored out global barrier as prep patch.
* Allow to only CAP_SYS_ADMIN if !Gen11.
v11:
* Remove engine vfunc in favour of local helper. (Chris Wilson)
* Stop retiring requests before updates since it is not needed
(Chris Wilson)
* Implement direct CPU update path for idle contexts. (Chris Wilson)
* Left side dependency needs only be on the same context timeline.
(Chris Wilson)
* It is sufficient to order the timeline. (Chris Wilson)
* Reject !RCS configuration attempts with -ENODEV for now.
v12:
* Rebase for make_rpcs.
v13:
* Centralize SSEU normalization to make_rpcs.
* Type width checking (uAPI <-> implementation).
* Gen11 restrictions uAPI checks.
* Gen11 subslice count differences handling.
Chris Wilson:
* args->size handling fixes.
* Update context image from GGTT.
* Postpone context image update to pinning.
* Use i915_gem_active_raw instead of last_request_on_engine.
v14:
* Add activity tracker on intel_context to fix the lifetime issues
and simplify the code. (Chris Wilson)
v15:
* Fix context pin leak if no space in ring by simplifying the
context pinning sequence.
v16:
* Rebase for context get/set param locking changes.
* Just -ENODEV on !Gen11. (Joonas)
v17:
* Fix one Gen11 subslice enablement rule.
* Handle error from i915_sw_fence_await_sw_fence_gfp. (Chris Wilson)
v18:
* Update commit message. (Joonas)
* Restrict uAPI to VME use case. (Joonas)
v19:
* Rebase.
v20:
* Rebase for ce->active_tracker.
v21:
* Rebase for IS_GEN changes.
v22:
* Reserve uAPI for flags straight away. (Chris Wilson)
v23:
* Rebase for RUNTIME_INFO.
v24:
* Added some headline docs for the uapi usage. (Joonas/Chris)
v25:
* Renamed class/instance to engine_class/engine_instance to avoid clash
with C++ keyword. (Tony Ye)
v26:
* Rebased for runtime pm api changes.
v27:
* Rebased for intel_context_init.
* Wrap commit msg to 75.
v28:
(Chris Wilson)
* Use i915_gem_ggtt.
* Use i915_request_await_dma_fence to show a better example.
v29:
* i915_timeline_set_barrier can now fail. (Chris Wilson)
v30:
* Capture some acks.
v31:
* Drop the WARN_ON from use controllable paths. (Chris Wilson)
* Use overflows_type for all checks.
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=100899
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=107634
Issue: https://github.com/intel/media-driver/issues/267
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Cc: Dmitry Rogozhkin <dmitry.v.rogozhkin@intel.com>
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Cc: Zhipeng Gong <zhipeng.gong@intel.com>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Cc: Tony Ye <tony.ye@intel.com>
Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Acked-by: Timo Aaltonen <timo.aaltonen@canonical.com>
Acked-by: Takashi Iwai <tiwai@suse.de>
Acked-by: Stéphane Marchesin <marcheu@chromium.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20190205095032.22673-4-tvrtko.ursulin@linux.intel.com
2019-02-05 09:50:31 +00:00
|
|
|
|
|
|
|
args->size = sizeof(user_sseu);
|
|
|
|
|
2019-04-26 16:33:32 +00:00
|
|
|
out_ce:
|
|
|
|
intel_context_put(ce);
|
|
|
|
return ret;
|
drm/i915: Expose RPCS (SSEU) configuration to userspace (Gen11 only)
We want to allow userspace to reconfigure the subslice configuration on a
per context basis.
This is required for the functional requirement of shutting down non-VME
enabled sub-slices on Gen11 parts.
To do so, we expose a context parameter to allow adjustment of the RPCS
register stored within the context image (and currently not accessible via
LRI).
If the context is adjusted before first use or whilst idle, the adjustment
is for "free"; otherwise if the context is active we queue a request to do
so (using the kernel context), following all other activity by that
context, which is also marked as barrier for all following submission
against the same context.
Since the overhead of device re-configuration during context switching can
be significant, especially in multi-context workloads, we limit this new
uAPI to only support the Gen11 VME use case. In this use case either the
device is fully enabled, and exactly one slice and half of the subslices
are enabled.
Example usage:
struct drm_i915_gem_context_param_sseu sseu = { };
struct drm_i915_gem_context_param arg = {
.param = I915_CONTEXT_PARAM_SSEU,
.ctx_id = gem_context_create(fd),
.size = sizeof(sseu),
.value = to_user_pointer(&sseu)
};
/* Query device defaults. */
gem_context_get_param(fd, &arg);
/* Set VME configuration on a 1x6x8 part. */
sseu.slice_mask = 0x1;
sseu.subslice_mask = 0xe0;
gem_context_set_param(fd, &arg);
v2: Fix offset of CTX_R_PWR_CLK_STATE in intel_lr_context_set_sseu()
(Lionel)
v3: Add ability to program this per engine (Chris)
v4: Move most get_sseu() into i915_gem_context.c (Lionel)
v5: Validate sseu configuration against the device's capabilities (Lionel)
v6: Change context powergating settings through MI_SDM on kernel context
(Chris)
v7: Synchronize the requests following a powergating setting change using
a global dependency (Chris)
Iterate timelines through dev_priv.gt.active_rings (Tvrtko)
Disable RPCS configuration setting for non capable users
(Lionel/Tvrtko)
v8: s/union intel_sseu/struct intel_sseu/ (Lionel)
s/dev_priv/i915/ (Tvrtko)
Change uapi class/instance fields to u16 (Tvrtko)
Bump mask fields to 64bits (Lionel)
Don't return EPERM when dynamic sseu is disabled (Tvrtko)
v9: Import context image into kernel context's ppgtt only when
reconfiguring powergated slice/subslices (Chris)
Use aliasing ppgtt when needed (Michel)
Tvrtko Ursulin:
v10:
* Update for upstream changes.
* Request submit needs a RPM reference.
* Reject on !FULL_PPGTT for simplicity.
* Pull out get/set param to helpers for readability and less indent.
* Use i915_request_await_dma_fence in add_global_barrier to skip waits
on the same timeline and avoid GEM_BUG_ON.
* No need to explicitly assign a NULL pointer to engine in legacy mode.
* No need to move gen8_make_rpcs up.
* Factored out global barrier as prep patch.
* Allow to only CAP_SYS_ADMIN if !Gen11.
v11:
* Remove engine vfunc in favour of local helper. (Chris Wilson)
* Stop retiring requests before updates since it is not needed
(Chris Wilson)
* Implement direct CPU update path for idle contexts. (Chris Wilson)
* Left side dependency needs only be on the same context timeline.
(Chris Wilson)
* It is sufficient to order the timeline. (Chris Wilson)
* Reject !RCS configuration attempts with -ENODEV for now.
v12:
* Rebase for make_rpcs.
v13:
* Centralize SSEU normalization to make_rpcs.
* Type width checking (uAPI <-> implementation).
* Gen11 restrictions uAPI checks.
* Gen11 subslice count differences handling.
Chris Wilson:
* args->size handling fixes.
* Update context image from GGTT.
* Postpone context image update to pinning.
* Use i915_gem_active_raw instead of last_request_on_engine.
v14:
* Add activity tracker on intel_context to fix the lifetime issues
and simplify the code. (Chris Wilson)
v15:
* Fix context pin leak if no space in ring by simplifying the
context pinning sequence.
v16:
* Rebase for context get/set param locking changes.
* Just -ENODEV on !Gen11. (Joonas)
v17:
* Fix one Gen11 subslice enablement rule.
* Handle error from i915_sw_fence_await_sw_fence_gfp. (Chris Wilson)
v18:
* Update commit message. (Joonas)
* Restrict uAPI to VME use case. (Joonas)
v19:
* Rebase.
v20:
* Rebase for ce->active_tracker.
v21:
* Rebase for IS_GEN changes.
v22:
* Reserve uAPI for flags straight away. (Chris Wilson)
v23:
* Rebase for RUNTIME_INFO.
v24:
* Added some headline docs for the uapi usage. (Joonas/Chris)
v25:
* Renamed class/instance to engine_class/engine_instance to avoid clash
with C++ keyword. (Tony Ye)
v26:
* Rebased for runtime pm api changes.
v27:
* Rebased for intel_context_init.
* Wrap commit msg to 75.
v28:
(Chris Wilson)
* Use i915_gem_ggtt.
* Use i915_request_await_dma_fence to show a better example.
v29:
* i915_timeline_set_barrier can now fail. (Chris Wilson)
v30:
* Capture some acks.
v31:
* Drop the WARN_ON from use controllable paths. (Chris Wilson)
* Use overflows_type for all checks.
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=100899
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=107634
Issue: https://github.com/intel/media-driver/issues/267
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Cc: Dmitry Rogozhkin <dmitry.v.rogozhkin@intel.com>
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Cc: Zhipeng Gong <zhipeng.gong@intel.com>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Cc: Tony Ye <tony.ye@intel.com>
Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Acked-by: Timo Aaltonen <timo.aaltonen@canonical.com>
Acked-by: Takashi Iwai <tiwai@suse.de>
Acked-by: Stéphane Marchesin <marcheu@chromium.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20190205095032.22673-4-tvrtko.ursulin@linux.intel.com
2019-02-05 09:50:31 +00:00
|
|
|
}
|
|
|
|
|
drm/i915/gem: Make context persistence optional
Our existing behaviour is to allow contexts and their GPU requests to
persist past the point of closure until the requests are complete. This
allows clients to operate in a 'fire-and-forget' manner where they can
setup a rendering pipeline and hand it over to the display server and
immediately exit. As the rendering pipeline is kept alive until
completion, the display server (or other consumer) can use the results
in the future and present them to the user.
The compute model is a little different. They have little to no buffer
sharing between processes as their kernels tend to operate on a
continuous stream, feeding the results back to the client application.
These kernels operate for an indeterminate length of time, with many
clients wishing that the kernel was always running for as long as they
keep feeding in the data, i.e. acting like a DSP.
Not all clients want this persistent "desktop" behaviour and would prefer
that the contexts are cleaned up immediately upon closure. This ensures
that when clients are run without hangchecking (e.g. for compute kernels
of indeterminate runtime), any GPU hang or other unexpected workloads
are terminated with the process and does not continue to hog resources.
The default behaviour for new contexts is the legacy persistence mode,
as some desktop applications are dependent upon the existing behaviour.
New clients will have to opt in to immediate cleanup on context
closure. If the hangchecking modparam is disabled, so is persistent
context support -- all contexts will be terminated on closure.
We expect this behaviour change to be welcomed by compute users, who
have often been caught between a rock and a hard place. They disable
hangchecking to avoid their kernels being "unfairly" declared hung, but
have also experienced true hangs that the system was then unable to
clean up. Naturally, this leads to bug reports.
Testcase: igt/gem_ctx_persistence
Link: https://github.com/intel/compute-runtime/pull/228
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Cc: Michał Winiarski <michal.winiarski@intel.com>
Cc: Jon Bloomfield <jon.bloomfield@intel.com>
Reviewed-by: Jon Bloomfield <jon.bloomfield@intel.com>
Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Reviewed-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Acked-by: Jason Ekstrand <jason@jlekstrand.net>
Link: https://patchwork.freedesktop.org/patch/msgid/20191029202338.8841-1-chris@chris-wilson.co.uk
2019-10-29 20:23:38 +00:00
|
|
|
static int
|
|
|
|
set_persistence(struct i915_gem_context *ctx,
|
|
|
|
const struct drm_i915_gem_context_param *args)
|
|
|
|
{
|
|
|
|
if (args->size)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
return __context_set_persistence(ctx, args->value);
|
|
|
|
}
|
|
|
|
|
2021-07-08 15:48:10 +00:00
|
|
|
static void __apply_priority(struct intel_context *ce, void *arg)
|
2019-12-20 10:12:30 +00:00
|
|
|
{
|
|
|
|
struct i915_gem_context *ctx = arg;
|
|
|
|
|
2020-05-21 14:06:16 +00:00
|
|
|
if (!intel_engine_has_timeslices(ce->engine))
|
2021-07-08 15:48:10 +00:00
|
|
|
return;
|
2019-12-20 10:12:30 +00:00
|
|
|
|
2021-07-21 21:50:56 +00:00
|
|
|
if (ctx->sched.priority >= I915_PRIORITY_NORMAL &&
|
|
|
|
intel_engine_has_semaphores(ce->engine))
|
2019-12-20 10:12:30 +00:00
|
|
|
intel_context_set_use_semaphores(ce);
|
|
|
|
else
|
|
|
|
intel_context_clear_use_semaphores(ce);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int set_priority(struct i915_gem_context *ctx,
|
|
|
|
const struct drm_i915_gem_context_param *args)
|
|
|
|
{
|
2021-07-08 15:48:19 +00:00
|
|
|
int err;
|
2019-12-20 10:12:30 +00:00
|
|
|
|
2021-07-08 15:48:19 +00:00
|
|
|
err = validate_priority(ctx->i915, args);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2019-12-20 10:12:30 +00:00
|
|
|
|
2021-07-08 15:48:19 +00:00
|
|
|
ctx->sched.priority = args->value;
|
2019-12-20 10:12:30 +00:00
|
|
|
context_apply_all(ctx, __apply_priority, ctx);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-03-30 10:03:49 +00:00
|
|
|
static int ctx_setparam(struct drm_i915_file_private *fpriv,
|
|
|
|
struct i915_gem_context *ctx,
|
2019-03-22 09:23:24 +00:00
|
|
|
struct drm_i915_gem_context_param *args)
|
2014-12-24 16:13:40 +00:00
|
|
|
{
|
2018-09-11 13:22:06 +00:00
|
|
|
int ret = 0;
|
2014-12-24 16:13:40 +00:00
|
|
|
|
|
|
|
switch (args->param) {
|
2016-07-04 07:08:39 +00:00
|
|
|
case I915_CONTEXT_PARAM_NO_ERROR_CAPTURE:
|
2016-12-31 11:20:11 +00:00
|
|
|
if (args->size)
|
2016-07-04 07:08:39 +00:00
|
|
|
ret = -EINVAL;
|
2016-12-31 11:20:11 +00:00
|
|
|
else if (args->value)
|
|
|
|
i915_gem_context_set_no_error_capture(ctx);
|
|
|
|
else
|
|
|
|
i915_gem_context_clear_no_error_capture(ctx);
|
2015-05-20 14:00:13 +00:00
|
|
|
break;
|
2019-03-22 09:23:24 +00:00
|
|
|
|
2016-11-16 15:20:32 +00:00
|
|
|
case I915_CONTEXT_PARAM_BANNABLE:
|
|
|
|
if (args->size)
|
|
|
|
ret = -EINVAL;
|
|
|
|
else if (!capable(CAP_SYS_ADMIN) && !args->value)
|
|
|
|
ret = -EPERM;
|
2016-12-31 11:20:11 +00:00
|
|
|
else if (args->value)
|
|
|
|
i915_gem_context_set_bannable(ctx);
|
2016-11-16 15:20:32 +00:00
|
|
|
else
|
2016-12-31 11:20:11 +00:00
|
|
|
i915_gem_context_clear_bannable(ctx);
|
2016-11-16 15:20:32 +00:00
|
|
|
break;
|
drm/i915/scheduler: Support user-defined priorities
Use a priority stored in the context as the initial value when
submitting a request. This allows us to change the default priority on a
per-context basis, allowing different contexts to be favoured with GPU
time at the expense of lower importance work. The user can adjust the
context's priority via I915_CONTEXT_PARAM_PRIORITY, with more positive
values being higher priority (they will be serviced earlier, after their
dependencies have been resolved). Any prerequisite work for an execbuf
will have its priority raised to match the new request as required.
Normal users can specify any value in the range of -1023 to 0 [default],
i.e. they can reduce the priority of their workloads (and temporarily
boost it back to normal if so desired).
Privileged users can specify any value in the range of -1023 to 1023,
[default is 0], i.e. they can raise their priority above all overs and
so potentially starve the system.
Note that the existing schedulers are not fair, nor load balancing, the
execution is strictly by priority on a first-come, first-served basis,
and the driver may choose to boost some requests above the range
available to users.
This priority was originally based around nice(2), but evolved to allow
clients to adjust their priority within a small range, and allow for a
privileged high priority range.
For example, this can be used to implement EGL_IMG_context_priority
https://www.khronos.org/registry/egl/extensions/IMG/EGL_IMG_context_priority.txt
EGL_CONTEXT_PRIORITY_LEVEL_IMG determines the priority level of
the context to be created. This attribute is a hint, as an
implementation may not support multiple contexts at some
priority levels and system policy may limit access to high
priority contexts to appropriate system privilege level. The
default value for EGL_CONTEXT_PRIORITY_LEVEL_IMG is
EGL_CONTEXT_PRIORITY_MEDIUM_IMG."
so we can map
PRIORITY_HIGH -> 1023 [privileged, will failback to 0]
PRIORITY_MED -> 0 [default]
PRIORITY_LOW -> -1023
They also map onto the priorities used by VkQueue (and a VkQueue is
essentially a timeline, our i915_gem_context under full-ppgtt).
v2: s/CAP_SYS_ADMIN/CAP_SYS_NICE/
v3: Report min/max user priorities as defines in the uapi, and rebase
internal priorities on the exposed values.
Testcase: igt/gem_exec_schedule
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Reviewed-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20171003203453.15692-9-chris@chris-wilson.co.uk
2017-10-03 20:34:53 +00:00
|
|
|
|
2019-02-18 10:58:21 +00:00
|
|
|
case I915_CONTEXT_PARAM_RECOVERABLE:
|
|
|
|
if (args->size)
|
|
|
|
ret = -EINVAL;
|
|
|
|
else if (args->value)
|
|
|
|
i915_gem_context_set_recoverable(ctx);
|
|
|
|
else
|
|
|
|
i915_gem_context_clear_recoverable(ctx);
|
|
|
|
break;
|
|
|
|
|
drm/i915/scheduler: Support user-defined priorities
Use a priority stored in the context as the initial value when
submitting a request. This allows us to change the default priority on a
per-context basis, allowing different contexts to be favoured with GPU
time at the expense of lower importance work. The user can adjust the
context's priority via I915_CONTEXT_PARAM_PRIORITY, with more positive
values being higher priority (they will be serviced earlier, after their
dependencies have been resolved). Any prerequisite work for an execbuf
will have its priority raised to match the new request as required.
Normal users can specify any value in the range of -1023 to 0 [default],
i.e. they can reduce the priority of their workloads (and temporarily
boost it back to normal if so desired).
Privileged users can specify any value in the range of -1023 to 1023,
[default is 0], i.e. they can raise their priority above all overs and
so potentially starve the system.
Note that the existing schedulers are not fair, nor load balancing, the
execution is strictly by priority on a first-come, first-served basis,
and the driver may choose to boost some requests above the range
available to users.
This priority was originally based around nice(2), but evolved to allow
clients to adjust their priority within a small range, and allow for a
privileged high priority range.
For example, this can be used to implement EGL_IMG_context_priority
https://www.khronos.org/registry/egl/extensions/IMG/EGL_IMG_context_priority.txt
EGL_CONTEXT_PRIORITY_LEVEL_IMG determines the priority level of
the context to be created. This attribute is a hint, as an
implementation may not support multiple contexts at some
priority levels and system policy may limit access to high
priority contexts to appropriate system privilege level. The
default value for EGL_CONTEXT_PRIORITY_LEVEL_IMG is
EGL_CONTEXT_PRIORITY_MEDIUM_IMG."
so we can map
PRIORITY_HIGH -> 1023 [privileged, will failback to 0]
PRIORITY_MED -> 0 [default]
PRIORITY_LOW -> -1023
They also map onto the priorities used by VkQueue (and a VkQueue is
essentially a timeline, our i915_gem_context under full-ppgtt).
v2: s/CAP_SYS_ADMIN/CAP_SYS_NICE/
v3: Report min/max user priorities as defines in the uapi, and rebase
internal priorities on the exposed values.
Testcase: igt/gem_exec_schedule
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Reviewed-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20171003203453.15692-9-chris@chris-wilson.co.uk
2017-10-03 20:34:53 +00:00
|
|
|
case I915_CONTEXT_PARAM_PRIORITY:
|
2019-12-20 10:12:30 +00:00
|
|
|
ret = set_priority(ctx, args);
|
drm/i915/scheduler: Support user-defined priorities
Use a priority stored in the context as the initial value when
submitting a request. This allows us to change the default priority on a
per-context basis, allowing different contexts to be favoured with GPU
time at the expense of lower importance work. The user can adjust the
context's priority via I915_CONTEXT_PARAM_PRIORITY, with more positive
values being higher priority (they will be serviced earlier, after their
dependencies have been resolved). Any prerequisite work for an execbuf
will have its priority raised to match the new request as required.
Normal users can specify any value in the range of -1023 to 0 [default],
i.e. they can reduce the priority of their workloads (and temporarily
boost it back to normal if so desired).
Privileged users can specify any value in the range of -1023 to 1023,
[default is 0], i.e. they can raise their priority above all overs and
so potentially starve the system.
Note that the existing schedulers are not fair, nor load balancing, the
execution is strictly by priority on a first-come, first-served basis,
and the driver may choose to boost some requests above the range
available to users.
This priority was originally based around nice(2), but evolved to allow
clients to adjust their priority within a small range, and allow for a
privileged high priority range.
For example, this can be used to implement EGL_IMG_context_priority
https://www.khronos.org/registry/egl/extensions/IMG/EGL_IMG_context_priority.txt
EGL_CONTEXT_PRIORITY_LEVEL_IMG determines the priority level of
the context to be created. This attribute is a hint, as an
implementation may not support multiple contexts at some
priority levels and system policy may limit access to high
priority contexts to appropriate system privilege level. The
default value for EGL_CONTEXT_PRIORITY_LEVEL_IMG is
EGL_CONTEXT_PRIORITY_MEDIUM_IMG."
so we can map
PRIORITY_HIGH -> 1023 [privileged, will failback to 0]
PRIORITY_MED -> 0 [default]
PRIORITY_LOW -> -1023
They also map onto the priorities used by VkQueue (and a VkQueue is
essentially a timeline, our i915_gem_context under full-ppgtt).
v2: s/CAP_SYS_ADMIN/CAP_SYS_NICE/
v3: Report min/max user priorities as defines in the uapi, and rebase
internal priorities on the exposed values.
Testcase: igt/gem_exec_schedule
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Reviewed-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20171003203453.15692-9-chris@chris-wilson.co.uk
2017-10-03 20:34:53 +00:00
|
|
|
break;
|
2019-03-22 09:23:23 +00:00
|
|
|
|
drm/i915: Expose RPCS (SSEU) configuration to userspace (Gen11 only)
We want to allow userspace to reconfigure the subslice configuration on a
per context basis.
This is required for the functional requirement of shutting down non-VME
enabled sub-slices on Gen11 parts.
To do so, we expose a context parameter to allow adjustment of the RPCS
register stored within the context image (and currently not accessible via
LRI).
If the context is adjusted before first use or whilst idle, the adjustment
is for "free"; otherwise if the context is active we queue a request to do
so (using the kernel context), following all other activity by that
context, which is also marked as barrier for all following submission
against the same context.
Since the overhead of device re-configuration during context switching can
be significant, especially in multi-context workloads, we limit this new
uAPI to only support the Gen11 VME use case. In this use case either the
device is fully enabled, and exactly one slice and half of the subslices
are enabled.
Example usage:
struct drm_i915_gem_context_param_sseu sseu = { };
struct drm_i915_gem_context_param arg = {
.param = I915_CONTEXT_PARAM_SSEU,
.ctx_id = gem_context_create(fd),
.size = sizeof(sseu),
.value = to_user_pointer(&sseu)
};
/* Query device defaults. */
gem_context_get_param(fd, &arg);
/* Set VME configuration on a 1x6x8 part. */
sseu.slice_mask = 0x1;
sseu.subslice_mask = 0xe0;
gem_context_set_param(fd, &arg);
v2: Fix offset of CTX_R_PWR_CLK_STATE in intel_lr_context_set_sseu()
(Lionel)
v3: Add ability to program this per engine (Chris)
v4: Move most get_sseu() into i915_gem_context.c (Lionel)
v5: Validate sseu configuration against the device's capabilities (Lionel)
v6: Change context powergating settings through MI_SDM on kernel context
(Chris)
v7: Synchronize the requests following a powergating setting change using
a global dependency (Chris)
Iterate timelines through dev_priv.gt.active_rings (Tvrtko)
Disable RPCS configuration setting for non capable users
(Lionel/Tvrtko)
v8: s/union intel_sseu/struct intel_sseu/ (Lionel)
s/dev_priv/i915/ (Tvrtko)
Change uapi class/instance fields to u16 (Tvrtko)
Bump mask fields to 64bits (Lionel)
Don't return EPERM when dynamic sseu is disabled (Tvrtko)
v9: Import context image into kernel context's ppgtt only when
reconfiguring powergated slice/subslices (Chris)
Use aliasing ppgtt when needed (Michel)
Tvrtko Ursulin:
v10:
* Update for upstream changes.
* Request submit needs a RPM reference.
* Reject on !FULL_PPGTT for simplicity.
* Pull out get/set param to helpers for readability and less indent.
* Use i915_request_await_dma_fence in add_global_barrier to skip waits
on the same timeline and avoid GEM_BUG_ON.
* No need to explicitly assign a NULL pointer to engine in legacy mode.
* No need to move gen8_make_rpcs up.
* Factored out global barrier as prep patch.
* Allow to only CAP_SYS_ADMIN if !Gen11.
v11:
* Remove engine vfunc in favour of local helper. (Chris Wilson)
* Stop retiring requests before updates since it is not needed
(Chris Wilson)
* Implement direct CPU update path for idle contexts. (Chris Wilson)
* Left side dependency needs only be on the same context timeline.
(Chris Wilson)
* It is sufficient to order the timeline. (Chris Wilson)
* Reject !RCS configuration attempts with -ENODEV for now.
v12:
* Rebase for make_rpcs.
v13:
* Centralize SSEU normalization to make_rpcs.
* Type width checking (uAPI <-> implementation).
* Gen11 restrictions uAPI checks.
* Gen11 subslice count differences handling.
Chris Wilson:
* args->size handling fixes.
* Update context image from GGTT.
* Postpone context image update to pinning.
* Use i915_gem_active_raw instead of last_request_on_engine.
v14:
* Add activity tracker on intel_context to fix the lifetime issues
and simplify the code. (Chris Wilson)
v15:
* Fix context pin leak if no space in ring by simplifying the
context pinning sequence.
v16:
* Rebase for context get/set param locking changes.
* Just -ENODEV on !Gen11. (Joonas)
v17:
* Fix one Gen11 subslice enablement rule.
* Handle error from i915_sw_fence_await_sw_fence_gfp. (Chris Wilson)
v18:
* Update commit message. (Joonas)
* Restrict uAPI to VME use case. (Joonas)
v19:
* Rebase.
v20:
* Rebase for ce->active_tracker.
v21:
* Rebase for IS_GEN changes.
v22:
* Reserve uAPI for flags straight away. (Chris Wilson)
v23:
* Rebase for RUNTIME_INFO.
v24:
* Added some headline docs for the uapi usage. (Joonas/Chris)
v25:
* Renamed class/instance to engine_class/engine_instance to avoid clash
with C++ keyword. (Tony Ye)
v26:
* Rebased for runtime pm api changes.
v27:
* Rebased for intel_context_init.
* Wrap commit msg to 75.
v28:
(Chris Wilson)
* Use i915_gem_ggtt.
* Use i915_request_await_dma_fence to show a better example.
v29:
* i915_timeline_set_barrier can now fail. (Chris Wilson)
v30:
* Capture some acks.
v31:
* Drop the WARN_ON from use controllable paths. (Chris Wilson)
* Use overflows_type for all checks.
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=100899
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=107634
Issue: https://github.com/intel/media-driver/issues/267
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Cc: Dmitry Rogozhkin <dmitry.v.rogozhkin@intel.com>
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Cc: Zhipeng Gong <zhipeng.gong@intel.com>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Cc: Tony Ye <tony.ye@intel.com>
Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Acked-by: Timo Aaltonen <timo.aaltonen@canonical.com>
Acked-by: Takashi Iwai <tiwai@suse.de>
Acked-by: Stéphane Marchesin <marcheu@chromium.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20190205095032.22673-4-tvrtko.ursulin@linux.intel.com
2019-02-05 09:50:31 +00:00
|
|
|
case I915_CONTEXT_PARAM_SSEU:
|
|
|
|
ret = set_sseu(ctx, args);
|
|
|
|
break;
|
2019-03-22 09:23:23 +00:00
|
|
|
|
drm/i915/gem: Make context persistence optional
Our existing behaviour is to allow contexts and their GPU requests to
persist past the point of closure until the requests are complete. This
allows clients to operate in a 'fire-and-forget' manner where they can
setup a rendering pipeline and hand it over to the display server and
immediately exit. As the rendering pipeline is kept alive until
completion, the display server (or other consumer) can use the results
in the future and present them to the user.
The compute model is a little different. They have little to no buffer
sharing between processes as their kernels tend to operate on a
continuous stream, feeding the results back to the client application.
These kernels operate for an indeterminate length of time, with many
clients wishing that the kernel was always running for as long as they
keep feeding in the data, i.e. acting like a DSP.
Not all clients want this persistent "desktop" behaviour and would prefer
that the contexts are cleaned up immediately upon closure. This ensures
that when clients are run without hangchecking (e.g. for compute kernels
of indeterminate runtime), any GPU hang or other unexpected workloads
are terminated with the process and does not continue to hog resources.
The default behaviour for new contexts is the legacy persistence mode,
as some desktop applications are dependent upon the existing behaviour.
New clients will have to opt in to immediate cleanup on context
closure. If the hangchecking modparam is disabled, so is persistent
context support -- all contexts will be terminated on closure.
We expect this behaviour change to be welcomed by compute users, who
have often been caught between a rock and a hard place. They disable
hangchecking to avoid their kernels being "unfairly" declared hung, but
have also experienced true hangs that the system was then unable to
clean up. Naturally, this leads to bug reports.
Testcase: igt/gem_ctx_persistence
Link: https://github.com/intel/compute-runtime/pull/228
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Cc: Michał Winiarski <michal.winiarski@intel.com>
Cc: Jon Bloomfield <jon.bloomfield@intel.com>
Reviewed-by: Jon Bloomfield <jon.bloomfield@intel.com>
Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Reviewed-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Acked-by: Jason Ekstrand <jason@jlekstrand.net>
Link: https://patchwork.freedesktop.org/patch/msgid/20191029202338.8841-1-chris@chris-wilson.co.uk
2019-10-29 20:23:38 +00:00
|
|
|
case I915_CONTEXT_PARAM_PERSISTENCE:
|
|
|
|
ret = set_persistence(ctx, args);
|
|
|
|
break;
|
|
|
|
|
2021-07-08 15:48:08 +00:00
|
|
|
case I915_CONTEXT_PARAM_NO_ZEROMAP:
|
2019-03-22 09:23:23 +00:00
|
|
|
case I915_CONTEXT_PARAM_BAN_PERIOD:
|
2021-07-08 15:48:06 +00:00
|
|
|
case I915_CONTEXT_PARAM_RINGSIZE:
|
2021-07-08 15:48:30 +00:00
|
|
|
case I915_CONTEXT_PARAM_VM:
|
2021-07-08 15:48:31 +00:00
|
|
|
case I915_CONTEXT_PARAM_ENGINES:
|
2014-12-24 16:13:40 +00:00
|
|
|
default:
|
|
|
|
ret = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-03-22 09:23:24 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct create_ext {
|
2021-07-08 15:48:26 +00:00
|
|
|
struct i915_gem_proto_context *pc;
|
2019-03-22 09:23:24 +00:00
|
|
|
struct drm_i915_file_private *fpriv;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int create_setparam(struct i915_user_extension __user *ext, void *data)
|
|
|
|
{
|
|
|
|
struct drm_i915_gem_context_create_ext_setparam local;
|
|
|
|
const struct create_ext *arg = data;
|
|
|
|
|
|
|
|
if (copy_from_user(&local, ext, sizeof(local)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
if (local.param.ctx_id)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2021-07-08 15:48:26 +00:00
|
|
|
return set_proto_ctx_param(arg->fpriv, arg->pc, &local.param);
|
2019-03-22 09:23:24 +00:00
|
|
|
}
|
|
|
|
|
2021-07-08 15:48:11 +00:00
|
|
|
static int invalid_ext(struct i915_user_extension __user *ext, void *data)
|
2019-05-21 21:11:29 +00:00
|
|
|
{
|
2021-07-08 15:48:11 +00:00
|
|
|
return -EINVAL;
|
2019-05-21 21:11:29 +00:00
|
|
|
}
|
|
|
|
|
2019-03-22 09:23:24 +00:00
|
|
|
static const i915_user_extension_fn create_extensions[] = {
|
|
|
|
[I915_CONTEXT_CREATE_EXT_SETPARAM] = create_setparam,
|
2021-07-08 15:48:11 +00:00
|
|
|
[I915_CONTEXT_CREATE_EXT_CLONE] = invalid_ext,
|
2019-03-22 09:23:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool client_is_banned(struct drm_i915_file_private *file_priv)
|
|
|
|
{
|
|
|
|
return atomic_read(&file_priv->ban_score) >= I915_CLIENT_SCORE_BANNED;
|
|
|
|
}
|
|
|
|
|
drm/i915/gem: Delay context creation (v3)
The current context uAPI allows for two methods of setting context
parameters: SET_CONTEXT_PARAM and CONTEXT_CREATE_EXT_SETPARAM. The
former is allowed to be called at any time while the later happens as
part of GEM_CONTEXT_CREATE. Currently, everything settable via one is
settable via the other. While some params are fairly simple and setting
them on a live context is harmless such as the context priority, others
are far trickier such as the VM or the set of engines. In order to swap
out the VM, for instance, we have to delay until all current in-flight
work is complete, swap in the new VM, and then continue. This leads to
a plethora of potential race conditions we'd really rather avoid.
In previous patches, we added a i915_gem_proto_context struct which is
capable of storing and tracking all such create parameters. This commit
delays the creation of the actual context until after the client is done
configuring it with SET_CONTEXT_PARAM. From the perspective of the
client, it has the same u32 context ID the whole time. From the
perspective of i915, however, it's an i915_gem_proto_context right up
until the point where we attempt to do something which the proto-context
can't handle. Then the real context gets created.
This is accomplished via a little xarray dance. When GEM_CONTEXT_CREATE
is called, we create a proto-context, reserve a slot in context_xa but
leave it NULL, the proto-context in the corresponding slot in
proto_context_xa. Then, whenever we go to look up a context, we first
check context_xa. If it's there, we return the i915_gem_context and
we're done. If it's not, we look in proto_context_xa and, if we find it
there, we create the actual context and kill the proto-context.
In order for this dance to work properly, everything which ever touches
a proto-context is guarded by drm_i915_file_private::proto_context_lock,
including context creation. Yes, this means context creation now takes
a giant global lock but it can't really be helped and that should never
be on any driver's fast-path anyway.
v2 (Daniel Vetter):
- Commit message grammatical fixes.
- Use WARN_ON instead of GEM_BUG_ON
- Rename lazy_create_context_locked to finalize_create_context_locked
- Rework the control-flow logic in the setparam ioctl
- Better documentation all around
v3 (kernel test robot):
- Make finalize_create_context_locked static
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/20210708154835.528166-25-jason@jlekstrand.net
2021-07-08 15:48:29 +00:00
|
|
|
static inline struct i915_gem_context *
|
|
|
|
__context_lookup(struct drm_i915_file_private *file_priv, u32 id)
|
|
|
|
{
|
|
|
|
struct i915_gem_context *ctx;
|
|
|
|
|
|
|
|
rcu_read_lock();
|
|
|
|
ctx = xa_load(&file_priv->context_xa, id);
|
|
|
|
if (ctx && !kref_get_unless_zero(&ctx->ref))
|
|
|
|
ctx = NULL;
|
|
|
|
rcu_read_unlock();
|
|
|
|
|
|
|
|
return ctx;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct i915_gem_context *
|
|
|
|
finalize_create_context_locked(struct drm_i915_file_private *file_priv,
|
|
|
|
struct i915_gem_proto_context *pc, u32 id)
|
|
|
|
{
|
|
|
|
struct i915_gem_context *ctx;
|
|
|
|
void *old;
|
|
|
|
|
|
|
|
lockdep_assert_held(&file_priv->proto_context_lock);
|
|
|
|
|
|
|
|
ctx = i915_gem_create_context(file_priv->dev_priv, pc);
|
|
|
|
if (IS_ERR(ctx))
|
|
|
|
return ctx;
|
|
|
|
|
|
|
|
gem_context_register(ctx, file_priv, id);
|
|
|
|
|
|
|
|
old = xa_erase(&file_priv->proto_context_xa, id);
|
|
|
|
GEM_BUG_ON(old != pc);
|
|
|
|
proto_context_close(pc);
|
|
|
|
|
|
|
|
/* One for the xarray and one for the caller */
|
|
|
|
return i915_gem_context_get(ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct i915_gem_context *
|
|
|
|
i915_gem_context_lookup(struct drm_i915_file_private *file_priv, u32 id)
|
|
|
|
{
|
|
|
|
struct i915_gem_proto_context *pc;
|
|
|
|
struct i915_gem_context *ctx;
|
|
|
|
|
|
|
|
ctx = __context_lookup(file_priv, id);
|
|
|
|
if (ctx)
|
|
|
|
return ctx;
|
|
|
|
|
|
|
|
mutex_lock(&file_priv->proto_context_lock);
|
|
|
|
/* Try one more time under the lock */
|
|
|
|
ctx = __context_lookup(file_priv, id);
|
|
|
|
if (!ctx) {
|
|
|
|
pc = xa_load(&file_priv->proto_context_xa, id);
|
|
|
|
if (!pc)
|
|
|
|
ctx = ERR_PTR(-ENOENT);
|
|
|
|
else
|
|
|
|
ctx = finalize_create_context_locked(file_priv, pc, id);
|
|
|
|
}
|
|
|
|
mutex_unlock(&file_priv->proto_context_lock);
|
|
|
|
|
|
|
|
return ctx;
|
|
|
|
}
|
|
|
|
|
2019-03-22 09:23:24 +00:00
|
|
|
int i915_gem_context_create_ioctl(struct drm_device *dev, void *data,
|
|
|
|
struct drm_file *file)
|
|
|
|
{
|
|
|
|
struct drm_i915_private *i915 = to_i915(dev);
|
|
|
|
struct drm_i915_gem_context_create_ext *args = data;
|
|
|
|
struct create_ext ext_data;
|
|
|
|
int ret;
|
2019-12-24 09:59:20 +00:00
|
|
|
u32 id;
|
2019-03-22 09:23:24 +00:00
|
|
|
|
|
|
|
if (!DRIVER_CAPS(i915)->has_logical_contexts)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
if (args->flags & I915_CONTEXT_CREATE_FLAGS_UNKNOWN)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2019-07-12 19:29:53 +00:00
|
|
|
ret = intel_gt_terminally_wedged(&i915->gt);
|
2019-03-22 09:23:24 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ext_data.fpriv = file->driver_priv;
|
|
|
|
if (client_is_banned(ext_data.fpriv)) {
|
drm/i915/gem: initial conversion to new logging macros using coccinelle
First pass of conversion to the new struct drm_based device logging
macros in the drm/i915/gem directory. This conversion was achieved using
the following coccinelle script that transforms based on the existence
of a straightforward struct drm_i915_private device:
@rule1@
identifier fn, T;
@@
fn(struct drm_i915_private *T,...) {
<+...
(
-DRM_INFO(
+drm_info(&T->drm,
...)
|
-DRM_ERROR(
+drm_err(&T->drm,
...)
|
-DRM_WARN(
+drm_warn(&T->drm,
...)
|
-DRM_DEBUG(
+drm_dbg(&T->drm,
...)
|
-DRM_DEBUG_DRIVER(
+drm_dbg(&T->drm,
...)
|
-DRM_DEBUG_KMS(
+drm_dbg_kms(&T->drm,
...)
|
-DRM_DEBUG_ATOMIC(
+drm_dbg_atomic(&T->drm,
...)
)
...+>
}
@rule2@
identifier fn, T;
@@
fn(...) {
...
struct drm_i915_private *T = ...;
<+...
(
-DRM_INFO(
+drm_info(&T->drm,
...)
|
-DRM_ERROR(
+drm_err(&T->drm,
...)
|
-DRM_WARN(
+drm_warn(&T->drm,
...)
|
-DRM_DEBUG(
+drm_dbg(&T->drm,
...)
|
-DRM_DEBUG_KMS(
+drm_dbg_kms(&T->drm,
...)
|
-DRM_DEBUG_DRIVER(
+drm_dbg(&T->drm,
...)
|
-DRM_DEBUG_ATOMIC(
+drm_dbg_atomic(&T->drm,
...)
)
...+>
}
Checkpatch warnings were addressed manually.
Acked-by: Chris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: Wambui Karuga <wambui.karugax@gmail.com>
Signed-off-by: Jani Nikula <jani.nikula@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20200122125750.9737-2-wambui.karugax@gmail.com
2020-01-22 12:57:49 +00:00
|
|
|
drm_dbg(&i915->drm,
|
|
|
|
"client %s[%d] banned from creating ctx\n",
|
|
|
|
current->comm, task_pid_nr(current));
|
2019-03-22 09:23:24 +00:00
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
2021-07-08 15:48:26 +00:00
|
|
|
ext_data.pc = proto_context_create(i915, args->flags);
|
|
|
|
if (IS_ERR(ext_data.pc))
|
|
|
|
return PTR_ERR(ext_data.pc);
|
2019-03-22 09:23:24 +00:00
|
|
|
|
|
|
|
if (args->flags & I915_CONTEXT_CREATE_FLAGS_USE_EXTENSIONS) {
|
|
|
|
ret = i915_user_extensions(u64_to_user_ptr(args->extensions),
|
|
|
|
create_extensions,
|
|
|
|
ARRAY_SIZE(create_extensions),
|
|
|
|
&ext_data);
|
drm/i915/gem: Delay context creation (v3)
The current context uAPI allows for two methods of setting context
parameters: SET_CONTEXT_PARAM and CONTEXT_CREATE_EXT_SETPARAM. The
former is allowed to be called at any time while the later happens as
part of GEM_CONTEXT_CREATE. Currently, everything settable via one is
settable via the other. While some params are fairly simple and setting
them on a live context is harmless such as the context priority, others
are far trickier such as the VM or the set of engines. In order to swap
out the VM, for instance, we have to delay until all current in-flight
work is complete, swap in the new VM, and then continue. This leads to
a plethora of potential race conditions we'd really rather avoid.
In previous patches, we added a i915_gem_proto_context struct which is
capable of storing and tracking all such create parameters. This commit
delays the creation of the actual context until after the client is done
configuring it with SET_CONTEXT_PARAM. From the perspective of the
client, it has the same u32 context ID the whole time. From the
perspective of i915, however, it's an i915_gem_proto_context right up
until the point where we attempt to do something which the proto-context
can't handle. Then the real context gets created.
This is accomplished via a little xarray dance. When GEM_CONTEXT_CREATE
is called, we create a proto-context, reserve a slot in context_xa but
leave it NULL, the proto-context in the corresponding slot in
proto_context_xa. Then, whenever we go to look up a context, we first
check context_xa. If it's there, we return the i915_gem_context and
we're done. If it's not, we look in proto_context_xa and, if we find it
there, we create the actual context and kill the proto-context.
In order for this dance to work properly, everything which ever touches
a proto-context is guarded by drm_i915_file_private::proto_context_lock,
including context creation. Yes, this means context creation now takes
a giant global lock but it can't really be helped and that should never
be on any driver's fast-path anyway.
v2 (Daniel Vetter):
- Commit message grammatical fixes.
- Use WARN_ON instead of GEM_BUG_ON
- Rename lazy_create_context_locked to finalize_create_context_locked
- Rework the control-flow logic in the setparam ioctl
- Better documentation all around
v3 (kernel test robot):
- Make finalize_create_context_locked static
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/20210708154835.528166-25-jason@jlekstrand.net
2021-07-08 15:48:29 +00:00
|
|
|
if (ret)
|
|
|
|
goto err_pc;
|
2019-03-22 09:23:24 +00:00
|
|
|
}
|
|
|
|
|
2021-07-08 15:48:35 +00:00
|
|
|
if (GRAPHICS_VER(i915) > 12) {
|
|
|
|
struct i915_gem_context *ctx;
|
|
|
|
|
|
|
|
/* Get ourselves a context ID */
|
|
|
|
ret = xa_alloc(&ext_data.fpriv->context_xa, &id, NULL,
|
|
|
|
xa_limit_32b, GFP_KERNEL);
|
|
|
|
if (ret)
|
|
|
|
goto err_pc;
|
|
|
|
|
|
|
|
ctx = i915_gem_create_context(i915, ext_data.pc);
|
|
|
|
if (IS_ERR(ctx)) {
|
|
|
|
ret = PTR_ERR(ctx);
|
|
|
|
goto err_pc;
|
|
|
|
}
|
|
|
|
|
|
|
|
proto_context_close(ext_data.pc);
|
|
|
|
gem_context_register(ctx, ext_data.fpriv, id);
|
|
|
|
} else {
|
|
|
|
ret = proto_context_register(ext_data.fpriv, ext_data.pc, &id);
|
|
|
|
if (ret < 0)
|
|
|
|
goto err_pc;
|
|
|
|
}
|
2019-03-22 09:23:24 +00:00
|
|
|
|
2019-12-24 09:59:20 +00:00
|
|
|
args->ctx_id = id;
|
drm/i915/gem: initial conversion to new logging macros using coccinelle
First pass of conversion to the new struct drm_based device logging
macros in the drm/i915/gem directory. This conversion was achieved using
the following coccinelle script that transforms based on the existence
of a straightforward struct drm_i915_private device:
@rule1@
identifier fn, T;
@@
fn(struct drm_i915_private *T,...) {
<+...
(
-DRM_INFO(
+drm_info(&T->drm,
...)
|
-DRM_ERROR(
+drm_err(&T->drm,
...)
|
-DRM_WARN(
+drm_warn(&T->drm,
...)
|
-DRM_DEBUG(
+drm_dbg(&T->drm,
...)
|
-DRM_DEBUG_DRIVER(
+drm_dbg(&T->drm,
...)
|
-DRM_DEBUG_KMS(
+drm_dbg_kms(&T->drm,
...)
|
-DRM_DEBUG_ATOMIC(
+drm_dbg_atomic(&T->drm,
...)
)
...+>
}
@rule2@
identifier fn, T;
@@
fn(...) {
...
struct drm_i915_private *T = ...;
<+...
(
-DRM_INFO(
+drm_info(&T->drm,
...)
|
-DRM_ERROR(
+drm_err(&T->drm,
...)
|
-DRM_WARN(
+drm_warn(&T->drm,
...)
|
-DRM_DEBUG(
+drm_dbg(&T->drm,
...)
|
-DRM_DEBUG_KMS(
+drm_dbg_kms(&T->drm,
...)
|
-DRM_DEBUG_DRIVER(
+drm_dbg(&T->drm,
...)
|
-DRM_DEBUG_ATOMIC(
+drm_dbg_atomic(&T->drm,
...)
)
...+>
}
Checkpatch warnings were addressed manually.
Acked-by: Chris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: Wambui Karuga <wambui.karugax@gmail.com>
Signed-off-by: Jani Nikula <jani.nikula@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20200122125750.9737-2-wambui.karugax@gmail.com
2020-01-22 12:57:49 +00:00
|
|
|
drm_dbg(&i915->drm, "HW context %d created\n", args->ctx_id);
|
2019-03-22 09:23:24 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
drm/i915/gem: Delay context creation (v3)
The current context uAPI allows for two methods of setting context
parameters: SET_CONTEXT_PARAM and CONTEXT_CREATE_EXT_SETPARAM. The
former is allowed to be called at any time while the later happens as
part of GEM_CONTEXT_CREATE. Currently, everything settable via one is
settable via the other. While some params are fairly simple and setting
them on a live context is harmless such as the context priority, others
are far trickier such as the VM or the set of engines. In order to swap
out the VM, for instance, we have to delay until all current in-flight
work is complete, swap in the new VM, and then continue. This leads to
a plethora of potential race conditions we'd really rather avoid.
In previous patches, we added a i915_gem_proto_context struct which is
capable of storing and tracking all such create parameters. This commit
delays the creation of the actual context until after the client is done
configuring it with SET_CONTEXT_PARAM. From the perspective of the
client, it has the same u32 context ID the whole time. From the
perspective of i915, however, it's an i915_gem_proto_context right up
until the point where we attempt to do something which the proto-context
can't handle. Then the real context gets created.
This is accomplished via a little xarray dance. When GEM_CONTEXT_CREATE
is called, we create a proto-context, reserve a slot in context_xa but
leave it NULL, the proto-context in the corresponding slot in
proto_context_xa. Then, whenever we go to look up a context, we first
check context_xa. If it's there, we return the i915_gem_context and
we're done. If it's not, we look in proto_context_xa and, if we find it
there, we create the actual context and kill the proto-context.
In order for this dance to work properly, everything which ever touches
a proto-context is guarded by drm_i915_file_private::proto_context_lock,
including context creation. Yes, this means context creation now takes
a giant global lock but it can't really be helped and that should never
be on any driver's fast-path anyway.
v2 (Daniel Vetter):
- Commit message grammatical fixes.
- Use WARN_ON instead of GEM_BUG_ON
- Rename lazy_create_context_locked to finalize_create_context_locked
- Rework the control-flow logic in the setparam ioctl
- Better documentation all around
v3 (kernel test robot):
- Make finalize_create_context_locked static
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/20210708154835.528166-25-jason@jlekstrand.net
2021-07-08 15:48:29 +00:00
|
|
|
err_pc:
|
|
|
|
proto_context_close(ext_data.pc);
|
2019-03-22 09:23:24 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int i915_gem_context_destroy_ioctl(struct drm_device *dev, void *data,
|
|
|
|
struct drm_file *file)
|
|
|
|
{
|
|
|
|
struct drm_i915_gem_context_destroy *args = data;
|
|
|
|
struct drm_i915_file_private *file_priv = file->driver_priv;
|
drm/i915/gem: Delay context creation (v3)
The current context uAPI allows for two methods of setting context
parameters: SET_CONTEXT_PARAM and CONTEXT_CREATE_EXT_SETPARAM. The
former is allowed to be called at any time while the later happens as
part of GEM_CONTEXT_CREATE. Currently, everything settable via one is
settable via the other. While some params are fairly simple and setting
them on a live context is harmless such as the context priority, others
are far trickier such as the VM or the set of engines. In order to swap
out the VM, for instance, we have to delay until all current in-flight
work is complete, swap in the new VM, and then continue. This leads to
a plethora of potential race conditions we'd really rather avoid.
In previous patches, we added a i915_gem_proto_context struct which is
capable of storing and tracking all such create parameters. This commit
delays the creation of the actual context until after the client is done
configuring it with SET_CONTEXT_PARAM. From the perspective of the
client, it has the same u32 context ID the whole time. From the
perspective of i915, however, it's an i915_gem_proto_context right up
until the point where we attempt to do something which the proto-context
can't handle. Then the real context gets created.
This is accomplished via a little xarray dance. When GEM_CONTEXT_CREATE
is called, we create a proto-context, reserve a slot in context_xa but
leave it NULL, the proto-context in the corresponding slot in
proto_context_xa. Then, whenever we go to look up a context, we first
check context_xa. If it's there, we return the i915_gem_context and
we're done. If it's not, we look in proto_context_xa and, if we find it
there, we create the actual context and kill the proto-context.
In order for this dance to work properly, everything which ever touches
a proto-context is guarded by drm_i915_file_private::proto_context_lock,
including context creation. Yes, this means context creation now takes
a giant global lock but it can't really be helped and that should never
be on any driver's fast-path anyway.
v2 (Daniel Vetter):
- Commit message grammatical fixes.
- Use WARN_ON instead of GEM_BUG_ON
- Rename lazy_create_context_locked to finalize_create_context_locked
- Rework the control-flow logic in the setparam ioctl
- Better documentation all around
v3 (kernel test robot):
- Make finalize_create_context_locked static
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/20210708154835.528166-25-jason@jlekstrand.net
2021-07-08 15:48:29 +00:00
|
|
|
struct i915_gem_proto_context *pc;
|
2019-03-22 09:23:24 +00:00
|
|
|
struct i915_gem_context *ctx;
|
|
|
|
|
|
|
|
if (args->pad != 0)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (!args->ctx_id)
|
|
|
|
return -ENOENT;
|
|
|
|
|
drm/i915/gem: Delay context creation (v3)
The current context uAPI allows for two methods of setting context
parameters: SET_CONTEXT_PARAM and CONTEXT_CREATE_EXT_SETPARAM. The
former is allowed to be called at any time while the later happens as
part of GEM_CONTEXT_CREATE. Currently, everything settable via one is
settable via the other. While some params are fairly simple and setting
them on a live context is harmless such as the context priority, others
are far trickier such as the VM or the set of engines. In order to swap
out the VM, for instance, we have to delay until all current in-flight
work is complete, swap in the new VM, and then continue. This leads to
a plethora of potential race conditions we'd really rather avoid.
In previous patches, we added a i915_gem_proto_context struct which is
capable of storing and tracking all such create parameters. This commit
delays the creation of the actual context until after the client is done
configuring it with SET_CONTEXT_PARAM. From the perspective of the
client, it has the same u32 context ID the whole time. From the
perspective of i915, however, it's an i915_gem_proto_context right up
until the point where we attempt to do something which the proto-context
can't handle. Then the real context gets created.
This is accomplished via a little xarray dance. When GEM_CONTEXT_CREATE
is called, we create a proto-context, reserve a slot in context_xa but
leave it NULL, the proto-context in the corresponding slot in
proto_context_xa. Then, whenever we go to look up a context, we first
check context_xa. If it's there, we return the i915_gem_context and
we're done. If it's not, we look in proto_context_xa and, if we find it
there, we create the actual context and kill the proto-context.
In order for this dance to work properly, everything which ever touches
a proto-context is guarded by drm_i915_file_private::proto_context_lock,
including context creation. Yes, this means context creation now takes
a giant global lock but it can't really be helped and that should never
be on any driver's fast-path anyway.
v2 (Daniel Vetter):
- Commit message grammatical fixes.
- Use WARN_ON instead of GEM_BUG_ON
- Rename lazy_create_context_locked to finalize_create_context_locked
- Rework the control-flow logic in the setparam ioctl
- Better documentation all around
v3 (kernel test robot):
- Make finalize_create_context_locked static
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/20210708154835.528166-25-jason@jlekstrand.net
2021-07-08 15:48:29 +00:00
|
|
|
/* We need to hold the proto-context lock here to prevent races
|
|
|
|
* with finalize_create_context_locked().
|
|
|
|
*/
|
|
|
|
mutex_lock(&file_priv->proto_context_lock);
|
2019-12-24 09:59:20 +00:00
|
|
|
ctx = xa_erase(&file_priv->context_xa, args->ctx_id);
|
drm/i915/gem: Delay context creation (v3)
The current context uAPI allows for two methods of setting context
parameters: SET_CONTEXT_PARAM and CONTEXT_CREATE_EXT_SETPARAM. The
former is allowed to be called at any time while the later happens as
part of GEM_CONTEXT_CREATE. Currently, everything settable via one is
settable via the other. While some params are fairly simple and setting
them on a live context is harmless such as the context priority, others
are far trickier such as the VM or the set of engines. In order to swap
out the VM, for instance, we have to delay until all current in-flight
work is complete, swap in the new VM, and then continue. This leads to
a plethora of potential race conditions we'd really rather avoid.
In previous patches, we added a i915_gem_proto_context struct which is
capable of storing and tracking all such create parameters. This commit
delays the creation of the actual context until after the client is done
configuring it with SET_CONTEXT_PARAM. From the perspective of the
client, it has the same u32 context ID the whole time. From the
perspective of i915, however, it's an i915_gem_proto_context right up
until the point where we attempt to do something which the proto-context
can't handle. Then the real context gets created.
This is accomplished via a little xarray dance. When GEM_CONTEXT_CREATE
is called, we create a proto-context, reserve a slot in context_xa but
leave it NULL, the proto-context in the corresponding slot in
proto_context_xa. Then, whenever we go to look up a context, we first
check context_xa. If it's there, we return the i915_gem_context and
we're done. If it's not, we look in proto_context_xa and, if we find it
there, we create the actual context and kill the proto-context.
In order for this dance to work properly, everything which ever touches
a proto-context is guarded by drm_i915_file_private::proto_context_lock,
including context creation. Yes, this means context creation now takes
a giant global lock but it can't really be helped and that should never
be on any driver's fast-path anyway.
v2 (Daniel Vetter):
- Commit message grammatical fixes.
- Use WARN_ON instead of GEM_BUG_ON
- Rename lazy_create_context_locked to finalize_create_context_locked
- Rework the control-flow logic in the setparam ioctl
- Better documentation all around
v3 (kernel test robot):
- Make finalize_create_context_locked static
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/20210708154835.528166-25-jason@jlekstrand.net
2021-07-08 15:48:29 +00:00
|
|
|
pc = xa_erase(&file_priv->proto_context_xa, args->ctx_id);
|
|
|
|
mutex_unlock(&file_priv->proto_context_lock);
|
|
|
|
|
|
|
|
if (!ctx && !pc)
|
2019-03-22 09:23:24 +00:00
|
|
|
return -ENOENT;
|
drm/i915/gem: Delay context creation (v3)
The current context uAPI allows for two methods of setting context
parameters: SET_CONTEXT_PARAM and CONTEXT_CREATE_EXT_SETPARAM. The
former is allowed to be called at any time while the later happens as
part of GEM_CONTEXT_CREATE. Currently, everything settable via one is
settable via the other. While some params are fairly simple and setting
them on a live context is harmless such as the context priority, others
are far trickier such as the VM or the set of engines. In order to swap
out the VM, for instance, we have to delay until all current in-flight
work is complete, swap in the new VM, and then continue. This leads to
a plethora of potential race conditions we'd really rather avoid.
In previous patches, we added a i915_gem_proto_context struct which is
capable of storing and tracking all such create parameters. This commit
delays the creation of the actual context until after the client is done
configuring it with SET_CONTEXT_PARAM. From the perspective of the
client, it has the same u32 context ID the whole time. From the
perspective of i915, however, it's an i915_gem_proto_context right up
until the point where we attempt to do something which the proto-context
can't handle. Then the real context gets created.
This is accomplished via a little xarray dance. When GEM_CONTEXT_CREATE
is called, we create a proto-context, reserve a slot in context_xa but
leave it NULL, the proto-context in the corresponding slot in
proto_context_xa. Then, whenever we go to look up a context, we first
check context_xa. If it's there, we return the i915_gem_context and
we're done. If it's not, we look in proto_context_xa and, if we find it
there, we create the actual context and kill the proto-context.
In order for this dance to work properly, everything which ever touches
a proto-context is guarded by drm_i915_file_private::proto_context_lock,
including context creation. Yes, this means context creation now takes
a giant global lock but it can't really be helped and that should never
be on any driver's fast-path anyway.
v2 (Daniel Vetter):
- Commit message grammatical fixes.
- Use WARN_ON instead of GEM_BUG_ON
- Rename lazy_create_context_locked to finalize_create_context_locked
- Rework the control-flow logic in the setparam ioctl
- Better documentation all around
v3 (kernel test robot):
- Make finalize_create_context_locked static
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/20210708154835.528166-25-jason@jlekstrand.net
2021-07-08 15:48:29 +00:00
|
|
|
GEM_WARN_ON(ctx && pc);
|
|
|
|
|
|
|
|
if (pc)
|
|
|
|
proto_context_close(pc);
|
|
|
|
|
|
|
|
if (ctx)
|
|
|
|
context_close(ctx);
|
2019-03-22 09:23:24 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int get_sseu(struct i915_gem_context *ctx,
|
|
|
|
struct drm_i915_gem_context_param *args)
|
|
|
|
{
|
|
|
|
struct drm_i915_gem_context_param_sseu user_sseu;
|
|
|
|
struct intel_context *ce;
|
2019-05-21 21:11:27 +00:00
|
|
|
unsigned long lookup;
|
2019-04-26 16:33:32 +00:00
|
|
|
int err;
|
2019-03-22 09:23:24 +00:00
|
|
|
|
|
|
|
if (args->size == 0)
|
|
|
|
goto out;
|
|
|
|
else if (args->size < sizeof(user_sseu))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (copy_from_user(&user_sseu, u64_to_user_ptr(args->value),
|
|
|
|
sizeof(user_sseu)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
2019-05-21 21:11:27 +00:00
|
|
|
if (user_sseu.rsvd)
|
2019-03-22 09:23:24 +00:00
|
|
|
return -EINVAL;
|
|
|
|
|
2019-05-21 21:11:27 +00:00
|
|
|
if (user_sseu.flags & ~(I915_CONTEXT_SSEU_FLAG_ENGINE_INDEX))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
lookup = 0;
|
|
|
|
if (user_sseu.flags & I915_CONTEXT_SSEU_FLAG_ENGINE_INDEX)
|
|
|
|
lookup |= LOOKUP_USER_INDEX;
|
|
|
|
|
|
|
|
ce = lookup_user_engine(ctx, lookup, &user_sseu.engine);
|
2019-03-22 09:23:24 +00:00
|
|
|
if (IS_ERR(ce))
|
|
|
|
return PTR_ERR(ce);
|
|
|
|
|
2019-04-26 16:33:32 +00:00
|
|
|
err = intel_context_lock_pinned(ce); /* serialises with set_sseu */
|
|
|
|
if (err) {
|
|
|
|
intel_context_put(ce);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2019-03-22 09:23:24 +00:00
|
|
|
user_sseu.slice_mask = ce->sseu.slice_mask;
|
|
|
|
user_sseu.subslice_mask = ce->sseu.subslice_mask;
|
|
|
|
user_sseu.min_eus_per_subslice = ce->sseu.min_eus_per_subslice;
|
|
|
|
user_sseu.max_eus_per_subslice = ce->sseu.max_eus_per_subslice;
|
|
|
|
|
2019-04-26 16:33:32 +00:00
|
|
|
intel_context_unlock_pinned(ce);
|
|
|
|
intel_context_put(ce);
|
2019-03-22 09:23:24 +00:00
|
|
|
|
|
|
|
if (copy_to_user(u64_to_user_ptr(args->value), &user_sseu,
|
|
|
|
sizeof(user_sseu)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
out:
|
|
|
|
args->size = sizeof(user_sseu);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int i915_gem_context_getparam_ioctl(struct drm_device *dev, void *data,
|
|
|
|
struct drm_file *file)
|
|
|
|
{
|
|
|
|
struct drm_i915_file_private *file_priv = file->driver_priv;
|
|
|
|
struct drm_i915_gem_context_param *args = data;
|
|
|
|
struct i915_gem_context *ctx;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
ctx = i915_gem_context_lookup(file_priv, args->ctx_id);
|
2021-07-08 15:48:27 +00:00
|
|
|
if (IS_ERR(ctx))
|
|
|
|
return PTR_ERR(ctx);
|
2019-03-22 09:23:24 +00:00
|
|
|
|
|
|
|
switch (args->param) {
|
|
|
|
case I915_CONTEXT_PARAM_GTT_SIZE:
|
|
|
|
args->size = 0;
|
2019-10-04 13:40:09 +00:00
|
|
|
rcu_read_lock();
|
|
|
|
if (rcu_access_pointer(ctx->vm))
|
|
|
|
args->value = rcu_dereference(ctx->vm)->total;
|
2019-03-22 09:23:24 +00:00
|
|
|
else
|
|
|
|
args->value = to_i915(dev)->ggtt.vm.total;
|
2019-10-04 13:40:09 +00:00
|
|
|
rcu_read_unlock();
|
2019-03-22 09:23:24 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case I915_CONTEXT_PARAM_NO_ERROR_CAPTURE:
|
|
|
|
args->size = 0;
|
|
|
|
args->value = i915_gem_context_no_error_capture(ctx);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case I915_CONTEXT_PARAM_BANNABLE:
|
|
|
|
args->size = 0;
|
|
|
|
args->value = i915_gem_context_is_bannable(ctx);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case I915_CONTEXT_PARAM_RECOVERABLE:
|
|
|
|
args->size = 0;
|
|
|
|
args->value = i915_gem_context_is_recoverable(ctx);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case I915_CONTEXT_PARAM_PRIORITY:
|
|
|
|
args->size = 0;
|
2021-01-20 12:14:39 +00:00
|
|
|
args->value = ctx->sched.priority;
|
2019-03-22 09:23:24 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case I915_CONTEXT_PARAM_SSEU:
|
|
|
|
ret = get_sseu(ctx, args);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case I915_CONTEXT_PARAM_VM:
|
2019-03-30 10:03:49 +00:00
|
|
|
ret = get_ppgtt(file_priv, ctx, args);
|
2019-03-22 09:23:24 +00:00
|
|
|
break;
|
|
|
|
|
drm/i915/gem: Make context persistence optional
Our existing behaviour is to allow contexts and their GPU requests to
persist past the point of closure until the requests are complete. This
allows clients to operate in a 'fire-and-forget' manner where they can
setup a rendering pipeline and hand it over to the display server and
immediately exit. As the rendering pipeline is kept alive until
completion, the display server (or other consumer) can use the results
in the future and present them to the user.
The compute model is a little different. They have little to no buffer
sharing between processes as their kernels tend to operate on a
continuous stream, feeding the results back to the client application.
These kernels operate for an indeterminate length of time, with many
clients wishing that the kernel was always running for as long as they
keep feeding in the data, i.e. acting like a DSP.
Not all clients want this persistent "desktop" behaviour and would prefer
that the contexts are cleaned up immediately upon closure. This ensures
that when clients are run without hangchecking (e.g. for compute kernels
of indeterminate runtime), any GPU hang or other unexpected workloads
are terminated with the process and does not continue to hog resources.
The default behaviour for new contexts is the legacy persistence mode,
as some desktop applications are dependent upon the existing behaviour.
New clients will have to opt in to immediate cleanup on context
closure. If the hangchecking modparam is disabled, so is persistent
context support -- all contexts will be terminated on closure.
We expect this behaviour change to be welcomed by compute users, who
have often been caught between a rock and a hard place. They disable
hangchecking to avoid their kernels being "unfairly" declared hung, but
have also experienced true hangs that the system was then unable to
clean up. Naturally, this leads to bug reports.
Testcase: igt/gem_ctx_persistence
Link: https://github.com/intel/compute-runtime/pull/228
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Cc: Michał Winiarski <michal.winiarski@intel.com>
Cc: Jon Bloomfield <jon.bloomfield@intel.com>
Reviewed-by: Jon Bloomfield <jon.bloomfield@intel.com>
Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Reviewed-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Acked-by: Jason Ekstrand <jason@jlekstrand.net>
Link: https://patchwork.freedesktop.org/patch/msgid/20191029202338.8841-1-chris@chris-wilson.co.uk
2019-10-29 20:23:38 +00:00
|
|
|
case I915_CONTEXT_PARAM_PERSISTENCE:
|
|
|
|
args->size = 0;
|
|
|
|
args->value = i915_gem_context_is_persistent(ctx);
|
|
|
|
break;
|
|
|
|
|
2021-07-08 15:48:08 +00:00
|
|
|
case I915_CONTEXT_PARAM_NO_ZEROMAP:
|
2019-03-22 09:23:24 +00:00
|
|
|
case I915_CONTEXT_PARAM_BAN_PERIOD:
|
2021-07-08 15:48:13 +00:00
|
|
|
case I915_CONTEXT_PARAM_ENGINES:
|
2021-07-08 15:48:06 +00:00
|
|
|
case I915_CONTEXT_PARAM_RINGSIZE:
|
2019-03-22 09:23:24 +00:00
|
|
|
default:
|
|
|
|
ret = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
i915_gem_context_put(ctx);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int i915_gem_context_setparam_ioctl(struct drm_device *dev, void *data,
|
|
|
|
struct drm_file *file)
|
|
|
|
{
|
|
|
|
struct drm_i915_file_private *file_priv = file->driver_priv;
|
|
|
|
struct drm_i915_gem_context_param *args = data;
|
drm/i915/gem: Delay context creation (v3)
The current context uAPI allows for two methods of setting context
parameters: SET_CONTEXT_PARAM and CONTEXT_CREATE_EXT_SETPARAM. The
former is allowed to be called at any time while the later happens as
part of GEM_CONTEXT_CREATE. Currently, everything settable via one is
settable via the other. While some params are fairly simple and setting
them on a live context is harmless such as the context priority, others
are far trickier such as the VM or the set of engines. In order to swap
out the VM, for instance, we have to delay until all current in-flight
work is complete, swap in the new VM, and then continue. This leads to
a plethora of potential race conditions we'd really rather avoid.
In previous patches, we added a i915_gem_proto_context struct which is
capable of storing and tracking all such create parameters. This commit
delays the creation of the actual context until after the client is done
configuring it with SET_CONTEXT_PARAM. From the perspective of the
client, it has the same u32 context ID the whole time. From the
perspective of i915, however, it's an i915_gem_proto_context right up
until the point where we attempt to do something which the proto-context
can't handle. Then the real context gets created.
This is accomplished via a little xarray dance. When GEM_CONTEXT_CREATE
is called, we create a proto-context, reserve a slot in context_xa but
leave it NULL, the proto-context in the corresponding slot in
proto_context_xa. Then, whenever we go to look up a context, we first
check context_xa. If it's there, we return the i915_gem_context and
we're done. If it's not, we look in proto_context_xa and, if we find it
there, we create the actual context and kill the proto-context.
In order for this dance to work properly, everything which ever touches
a proto-context is guarded by drm_i915_file_private::proto_context_lock,
including context creation. Yes, this means context creation now takes
a giant global lock but it can't really be helped and that should never
be on any driver's fast-path anyway.
v2 (Daniel Vetter):
- Commit message grammatical fixes.
- Use WARN_ON instead of GEM_BUG_ON
- Rename lazy_create_context_locked to finalize_create_context_locked
- Rework the control-flow logic in the setparam ioctl
- Better documentation all around
v3 (kernel test robot):
- Make finalize_create_context_locked static
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/20210708154835.528166-25-jason@jlekstrand.net
2021-07-08 15:48:29 +00:00
|
|
|
struct i915_gem_proto_context *pc;
|
2019-03-22 09:23:24 +00:00
|
|
|
struct i915_gem_context *ctx;
|
drm/i915/gem: Delay context creation (v3)
The current context uAPI allows for two methods of setting context
parameters: SET_CONTEXT_PARAM and CONTEXT_CREATE_EXT_SETPARAM. The
former is allowed to be called at any time while the later happens as
part of GEM_CONTEXT_CREATE. Currently, everything settable via one is
settable via the other. While some params are fairly simple and setting
them on a live context is harmless such as the context priority, others
are far trickier such as the VM or the set of engines. In order to swap
out the VM, for instance, we have to delay until all current in-flight
work is complete, swap in the new VM, and then continue. This leads to
a plethora of potential race conditions we'd really rather avoid.
In previous patches, we added a i915_gem_proto_context struct which is
capable of storing and tracking all such create parameters. This commit
delays the creation of the actual context until after the client is done
configuring it with SET_CONTEXT_PARAM. From the perspective of the
client, it has the same u32 context ID the whole time. From the
perspective of i915, however, it's an i915_gem_proto_context right up
until the point where we attempt to do something which the proto-context
can't handle. Then the real context gets created.
This is accomplished via a little xarray dance. When GEM_CONTEXT_CREATE
is called, we create a proto-context, reserve a slot in context_xa but
leave it NULL, the proto-context in the corresponding slot in
proto_context_xa. Then, whenever we go to look up a context, we first
check context_xa. If it's there, we return the i915_gem_context and
we're done. If it's not, we look in proto_context_xa and, if we find it
there, we create the actual context and kill the proto-context.
In order for this dance to work properly, everything which ever touches
a proto-context is guarded by drm_i915_file_private::proto_context_lock,
including context creation. Yes, this means context creation now takes
a giant global lock but it can't really be helped and that should never
be on any driver's fast-path anyway.
v2 (Daniel Vetter):
- Commit message grammatical fixes.
- Use WARN_ON instead of GEM_BUG_ON
- Rename lazy_create_context_locked to finalize_create_context_locked
- Rework the control-flow logic in the setparam ioctl
- Better documentation all around
v3 (kernel test robot):
- Make finalize_create_context_locked static
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/20210708154835.528166-25-jason@jlekstrand.net
2021-07-08 15:48:29 +00:00
|
|
|
int ret = 0;
|
2019-03-22 09:23:24 +00:00
|
|
|
|
drm/i915/gem: Delay context creation (v3)
The current context uAPI allows for two methods of setting context
parameters: SET_CONTEXT_PARAM and CONTEXT_CREATE_EXT_SETPARAM. The
former is allowed to be called at any time while the later happens as
part of GEM_CONTEXT_CREATE. Currently, everything settable via one is
settable via the other. While some params are fairly simple and setting
them on a live context is harmless such as the context priority, others
are far trickier such as the VM or the set of engines. In order to swap
out the VM, for instance, we have to delay until all current in-flight
work is complete, swap in the new VM, and then continue. This leads to
a plethora of potential race conditions we'd really rather avoid.
In previous patches, we added a i915_gem_proto_context struct which is
capable of storing and tracking all such create parameters. This commit
delays the creation of the actual context until after the client is done
configuring it with SET_CONTEXT_PARAM. From the perspective of the
client, it has the same u32 context ID the whole time. From the
perspective of i915, however, it's an i915_gem_proto_context right up
until the point where we attempt to do something which the proto-context
can't handle. Then the real context gets created.
This is accomplished via a little xarray dance. When GEM_CONTEXT_CREATE
is called, we create a proto-context, reserve a slot in context_xa but
leave it NULL, the proto-context in the corresponding slot in
proto_context_xa. Then, whenever we go to look up a context, we first
check context_xa. If it's there, we return the i915_gem_context and
we're done. If it's not, we look in proto_context_xa and, if we find it
there, we create the actual context and kill the proto-context.
In order for this dance to work properly, everything which ever touches
a proto-context is guarded by drm_i915_file_private::proto_context_lock,
including context creation. Yes, this means context creation now takes
a giant global lock but it can't really be helped and that should never
be on any driver's fast-path anyway.
v2 (Daniel Vetter):
- Commit message grammatical fixes.
- Use WARN_ON instead of GEM_BUG_ON
- Rename lazy_create_context_locked to finalize_create_context_locked
- Rework the control-flow logic in the setparam ioctl
- Better documentation all around
v3 (kernel test robot):
- Make finalize_create_context_locked static
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/20210708154835.528166-25-jason@jlekstrand.net
2021-07-08 15:48:29 +00:00
|
|
|
mutex_lock(&file_priv->proto_context_lock);
|
|
|
|
ctx = __context_lookup(file_priv, args->ctx_id);
|
|
|
|
if (!ctx) {
|
|
|
|
pc = xa_load(&file_priv->proto_context_xa, args->ctx_id);
|
2021-07-08 15:48:35 +00:00
|
|
|
if (pc) {
|
|
|
|
/* Contexts should be finalized inside
|
|
|
|
* GEM_CONTEXT_CREATE starting with graphics
|
|
|
|
* version 13.
|
|
|
|
*/
|
|
|
|
WARN_ON(GRAPHICS_VER(file_priv->dev_priv) > 12);
|
drm/i915/gem: Delay context creation (v3)
The current context uAPI allows for two methods of setting context
parameters: SET_CONTEXT_PARAM and CONTEXT_CREATE_EXT_SETPARAM. The
former is allowed to be called at any time while the later happens as
part of GEM_CONTEXT_CREATE. Currently, everything settable via one is
settable via the other. While some params are fairly simple and setting
them on a live context is harmless such as the context priority, others
are far trickier such as the VM or the set of engines. In order to swap
out the VM, for instance, we have to delay until all current in-flight
work is complete, swap in the new VM, and then continue. This leads to
a plethora of potential race conditions we'd really rather avoid.
In previous patches, we added a i915_gem_proto_context struct which is
capable of storing and tracking all such create parameters. This commit
delays the creation of the actual context until after the client is done
configuring it with SET_CONTEXT_PARAM. From the perspective of the
client, it has the same u32 context ID the whole time. From the
perspective of i915, however, it's an i915_gem_proto_context right up
until the point where we attempt to do something which the proto-context
can't handle. Then the real context gets created.
This is accomplished via a little xarray dance. When GEM_CONTEXT_CREATE
is called, we create a proto-context, reserve a slot in context_xa but
leave it NULL, the proto-context in the corresponding slot in
proto_context_xa. Then, whenever we go to look up a context, we first
check context_xa. If it's there, we return the i915_gem_context and
we're done. If it's not, we look in proto_context_xa and, if we find it
there, we create the actual context and kill the proto-context.
In order for this dance to work properly, everything which ever touches
a proto-context is guarded by drm_i915_file_private::proto_context_lock,
including context creation. Yes, this means context creation now takes
a giant global lock but it can't really be helped and that should never
be on any driver's fast-path anyway.
v2 (Daniel Vetter):
- Commit message grammatical fixes.
- Use WARN_ON instead of GEM_BUG_ON
- Rename lazy_create_context_locked to finalize_create_context_locked
- Rework the control-flow logic in the setparam ioctl
- Better documentation all around
v3 (kernel test robot):
- Make finalize_create_context_locked static
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/20210708154835.528166-25-jason@jlekstrand.net
2021-07-08 15:48:29 +00:00
|
|
|
ret = set_proto_ctx_param(file_priv, pc, args);
|
2021-07-08 15:48:35 +00:00
|
|
|
} else {
|
drm/i915/gem: Delay context creation (v3)
The current context uAPI allows for two methods of setting context
parameters: SET_CONTEXT_PARAM and CONTEXT_CREATE_EXT_SETPARAM. The
former is allowed to be called at any time while the later happens as
part of GEM_CONTEXT_CREATE. Currently, everything settable via one is
settable via the other. While some params are fairly simple and setting
them on a live context is harmless such as the context priority, others
are far trickier such as the VM or the set of engines. In order to swap
out the VM, for instance, we have to delay until all current in-flight
work is complete, swap in the new VM, and then continue. This leads to
a plethora of potential race conditions we'd really rather avoid.
In previous patches, we added a i915_gem_proto_context struct which is
capable of storing and tracking all such create parameters. This commit
delays the creation of the actual context until after the client is done
configuring it with SET_CONTEXT_PARAM. From the perspective of the
client, it has the same u32 context ID the whole time. From the
perspective of i915, however, it's an i915_gem_proto_context right up
until the point where we attempt to do something which the proto-context
can't handle. Then the real context gets created.
This is accomplished via a little xarray dance. When GEM_CONTEXT_CREATE
is called, we create a proto-context, reserve a slot in context_xa but
leave it NULL, the proto-context in the corresponding slot in
proto_context_xa. Then, whenever we go to look up a context, we first
check context_xa. If it's there, we return the i915_gem_context and
we're done. If it's not, we look in proto_context_xa and, if we find it
there, we create the actual context and kill the proto-context.
In order for this dance to work properly, everything which ever touches
a proto-context is guarded by drm_i915_file_private::proto_context_lock,
including context creation. Yes, this means context creation now takes
a giant global lock but it can't really be helped and that should never
be on any driver's fast-path anyway.
v2 (Daniel Vetter):
- Commit message grammatical fixes.
- Use WARN_ON instead of GEM_BUG_ON
- Rename lazy_create_context_locked to finalize_create_context_locked
- Rework the control-flow logic in the setparam ioctl
- Better documentation all around
v3 (kernel test robot):
- Make finalize_create_context_locked static
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/20210708154835.528166-25-jason@jlekstrand.net
2021-07-08 15:48:29 +00:00
|
|
|
ret = -ENOENT;
|
2021-07-08 15:48:35 +00:00
|
|
|
}
|
drm/i915/gem: Delay context creation (v3)
The current context uAPI allows for two methods of setting context
parameters: SET_CONTEXT_PARAM and CONTEXT_CREATE_EXT_SETPARAM. The
former is allowed to be called at any time while the later happens as
part of GEM_CONTEXT_CREATE. Currently, everything settable via one is
settable via the other. While some params are fairly simple and setting
them on a live context is harmless such as the context priority, others
are far trickier such as the VM or the set of engines. In order to swap
out the VM, for instance, we have to delay until all current in-flight
work is complete, swap in the new VM, and then continue. This leads to
a plethora of potential race conditions we'd really rather avoid.
In previous patches, we added a i915_gem_proto_context struct which is
capable of storing and tracking all such create parameters. This commit
delays the creation of the actual context until after the client is done
configuring it with SET_CONTEXT_PARAM. From the perspective of the
client, it has the same u32 context ID the whole time. From the
perspective of i915, however, it's an i915_gem_proto_context right up
until the point where we attempt to do something which the proto-context
can't handle. Then the real context gets created.
This is accomplished via a little xarray dance. When GEM_CONTEXT_CREATE
is called, we create a proto-context, reserve a slot in context_xa but
leave it NULL, the proto-context in the corresponding slot in
proto_context_xa. Then, whenever we go to look up a context, we first
check context_xa. If it's there, we return the i915_gem_context and
we're done. If it's not, we look in proto_context_xa and, if we find it
there, we create the actual context and kill the proto-context.
In order for this dance to work properly, everything which ever touches
a proto-context is guarded by drm_i915_file_private::proto_context_lock,
including context creation. Yes, this means context creation now takes
a giant global lock but it can't really be helped and that should never
be on any driver's fast-path anyway.
v2 (Daniel Vetter):
- Commit message grammatical fixes.
- Use WARN_ON instead of GEM_BUG_ON
- Rename lazy_create_context_locked to finalize_create_context_locked
- Rework the control-flow logic in the setparam ioctl
- Better documentation all around
v3 (kernel test robot):
- Make finalize_create_context_locked static
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/20210708154835.528166-25-jason@jlekstrand.net
2021-07-08 15:48:29 +00:00
|
|
|
}
|
|
|
|
mutex_unlock(&file_priv->proto_context_lock);
|
2019-03-22 09:23:24 +00:00
|
|
|
|
drm/i915/gem: Delay context creation (v3)
The current context uAPI allows for two methods of setting context
parameters: SET_CONTEXT_PARAM and CONTEXT_CREATE_EXT_SETPARAM. The
former is allowed to be called at any time while the later happens as
part of GEM_CONTEXT_CREATE. Currently, everything settable via one is
settable via the other. While some params are fairly simple and setting
them on a live context is harmless such as the context priority, others
are far trickier such as the VM or the set of engines. In order to swap
out the VM, for instance, we have to delay until all current in-flight
work is complete, swap in the new VM, and then continue. This leads to
a plethora of potential race conditions we'd really rather avoid.
In previous patches, we added a i915_gem_proto_context struct which is
capable of storing and tracking all such create parameters. This commit
delays the creation of the actual context until after the client is done
configuring it with SET_CONTEXT_PARAM. From the perspective of the
client, it has the same u32 context ID the whole time. From the
perspective of i915, however, it's an i915_gem_proto_context right up
until the point where we attempt to do something which the proto-context
can't handle. Then the real context gets created.
This is accomplished via a little xarray dance. When GEM_CONTEXT_CREATE
is called, we create a proto-context, reserve a slot in context_xa but
leave it NULL, the proto-context in the corresponding slot in
proto_context_xa. Then, whenever we go to look up a context, we first
check context_xa. If it's there, we return the i915_gem_context and
we're done. If it's not, we look in proto_context_xa and, if we find it
there, we create the actual context and kill the proto-context.
In order for this dance to work properly, everything which ever touches
a proto-context is guarded by drm_i915_file_private::proto_context_lock,
including context creation. Yes, this means context creation now takes
a giant global lock but it can't really be helped and that should never
be on any driver's fast-path anyway.
v2 (Daniel Vetter):
- Commit message grammatical fixes.
- Use WARN_ON instead of GEM_BUG_ON
- Rename lazy_create_context_locked to finalize_create_context_locked
- Rework the control-flow logic in the setparam ioctl
- Better documentation all around
v3 (kernel test robot):
- Make finalize_create_context_locked static
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/20210708154835.528166-25-jason@jlekstrand.net
2021-07-08 15:48:29 +00:00
|
|
|
if (ctx) {
|
|
|
|
ret = ctx_setparam(file_priv, ctx, args);
|
|
|
|
i915_gem_context_put(ctx);
|
|
|
|
}
|
2019-03-22 09:23:24 +00:00
|
|
|
|
2014-12-24 16:13:40 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2016-05-13 10:57:19 +00:00
|
|
|
|
|
|
|
int i915_gem_context_reset_stats_ioctl(struct drm_device *dev,
|
|
|
|
void *data, struct drm_file *file)
|
|
|
|
{
|
2019-10-04 13:40:09 +00:00
|
|
|
struct drm_i915_private *i915 = to_i915(dev);
|
2016-05-13 10:57:19 +00:00
|
|
|
struct drm_i915_reset_stats *args = data;
|
2016-05-24 13:53:34 +00:00
|
|
|
struct i915_gem_context *ctx;
|
2016-05-13 10:57:19 +00:00
|
|
|
|
|
|
|
if (args->flags || args->pad)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2021-07-08 15:48:18 +00:00
|
|
|
ctx = i915_gem_context_lookup(file->driver_priv, args->ctx_id);
|
2021-07-08 15:48:27 +00:00
|
|
|
if (IS_ERR(ctx))
|
|
|
|
return PTR_ERR(ctx);
|
2016-05-13 10:57:19 +00:00
|
|
|
|
2017-06-20 11:05:47 +00:00
|
|
|
/*
|
|
|
|
* We opt for unserialised reads here. This may result in tearing
|
|
|
|
* in the extremely unlikely event of a GPU hang on this context
|
|
|
|
* as we are querying them. If we need that extra layer of protection,
|
|
|
|
* we should wrap the hangstats with a seqlock.
|
|
|
|
*/
|
2016-05-13 10:57:19 +00:00
|
|
|
|
|
|
|
if (capable(CAP_SYS_ADMIN))
|
2019-10-04 13:40:09 +00:00
|
|
|
args->reset_count = i915_reset_count(&i915->gpu_error);
|
2016-05-13 10:57:19 +00:00
|
|
|
else
|
|
|
|
args->reset_count = 0;
|
|
|
|
|
2017-07-21 12:32:30 +00:00
|
|
|
args->batch_active = atomic_read(&ctx->guilty_count);
|
|
|
|
args->batch_pending = atomic_read(&ctx->active_count);
|
2016-05-13 10:57:19 +00:00
|
|
|
|
2021-07-08 15:48:18 +00:00
|
|
|
i915_gem_context_put(ctx);
|
|
|
|
return 0;
|
2016-05-13 10:57:19 +00:00
|
|
|
}
|
2017-02-13 17:15:19 +00:00
|
|
|
|
2019-04-26 16:33:34 +00:00
|
|
|
/* GEM context-engines iterator: for_each_gem_engine() */
|
|
|
|
struct intel_context *
|
|
|
|
i915_gem_engines_iter_next(struct i915_gem_engines_iter *it)
|
|
|
|
{
|
|
|
|
const struct i915_gem_engines *e = it->engines;
|
|
|
|
struct intel_context *ctx;
|
|
|
|
|
2020-03-03 08:05:44 +00:00
|
|
|
if (unlikely(!e))
|
|
|
|
return NULL;
|
|
|
|
|
2019-04-26 16:33:34 +00:00
|
|
|
do {
|
|
|
|
if (it->idx >= e->num_engines)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
ctx = e->engines[it->idx++];
|
|
|
|
} while (!ctx);
|
|
|
|
|
|
|
|
return ctx;
|
|
|
|
}
|
|
|
|
|
2017-02-13 17:15:19 +00:00
|
|
|
#if IS_ENABLED(CONFIG_DRM_I915_SELFTEST)
|
|
|
|
#include "selftests/mock_context.c"
|
2017-02-13 17:15:49 +00:00
|
|
|
#include "selftests/i915_gem_context.c"
|
2017-02-13 17:15:19 +00:00
|
|
|
#endif
|
2019-02-28 10:20:34 +00:00
|
|
|
|
2021-07-27 12:10:31 +00:00
|
|
|
void i915_gem_context_module_exit(void)
|
2019-02-28 10:20:34 +00:00
|
|
|
{
|
2021-07-27 12:10:31 +00:00
|
|
|
kmem_cache_destroy(slab_luts);
|
2019-02-28 10:20:34 +00:00
|
|
|
}
|
|
|
|
|
2021-07-27 12:10:31 +00:00
|
|
|
int __init i915_gem_context_module_init(void)
|
2019-02-28 10:20:34 +00:00
|
|
|
{
|
2021-07-27 12:10:31 +00:00
|
|
|
slab_luts = KMEM_CACHE(i915_lut_handle, 0);
|
|
|
|
if (!slab_luts)
|
2019-03-05 21:38:30 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
return 0;
|
2019-02-28 10:20:34 +00:00
|
|
|
}
|