2016-12-31 18:20:11 +07:00
|
|
|
/*
|
|
|
|
* Copyright © 2016 Intel Corporation
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
* Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
|
|
* IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __I915_GEM_CONTEXT_H__
|
|
|
|
#define __I915_GEM_CONTEXT_H__
|
|
|
|
|
|
|
|
#include <linux/bitops.h>
|
|
|
|
#include <linux/list.h>
|
2017-08-16 15:52:08 +07:00
|
|
|
#include <linux/radix-tree.h>
|
2016-12-31 18:20:11 +07:00
|
|
|
|
2018-02-13 21:18:33 +07:00
|
|
|
#include "i915_gem.h"
|
2018-05-24 22:06:20 +07:00
|
|
|
#include "i915_scheduler.h"
|
2019-02-05 16:50:28 +07:00
|
|
|
#include "intel_device_info.h"
|
2018-02-13 21:18:33 +07:00
|
|
|
|
2016-12-31 18:20:11 +07:00
|
|
|
struct pid;
|
|
|
|
|
|
|
|
struct drm_device;
|
|
|
|
struct drm_file;
|
|
|
|
|
|
|
|
struct drm_i915_private;
|
|
|
|
struct drm_i915_file_private;
|
|
|
|
struct i915_hw_ppgtt;
|
2018-02-23 00:24:05 +07:00
|
|
|
struct i915_request;
|
2016-12-31 18:20:11 +07:00
|
|
|
struct i915_vma;
|
|
|
|
struct intel_ring;
|
|
|
|
|
|
|
|
#define DEFAULT_CONTEXT_HANDLE 0
|
|
|
|
|
2018-05-24 22:06:21 +07:00
|
|
|
struct intel_context;
|
|
|
|
|
2018-05-18 04:26:32 +07:00
|
|
|
struct intel_context_ops {
|
|
|
|
void (*unpin)(struct intel_context *ce);
|
|
|
|
void (*destroy)(struct intel_context *ce);
|
|
|
|
};
|
|
|
|
|
2019-02-05 16:50:28 +07:00
|
|
|
/*
|
|
|
|
* Powergating configuration for a particular (context,engine).
|
|
|
|
*/
|
|
|
|
struct intel_sseu {
|
|
|
|
u8 slice_mask;
|
|
|
|
u8 subslice_mask;
|
|
|
|
u8 min_eus_per_subslice;
|
|
|
|
u8 max_eus_per_subslice;
|
|
|
|
};
|
|
|
|
|
2016-12-31 18:20:11 +07:00
|
|
|
/**
|
|
|
|
* struct i915_gem_context - client state
|
|
|
|
*
|
|
|
|
* The struct i915_gem_context represents the combined view of the driver and
|
|
|
|
* logical hardware state for a particular client.
|
|
|
|
*/
|
|
|
|
struct i915_gem_context {
|
|
|
|
/** i915: i915 device backpointer */
|
|
|
|
struct drm_i915_private *i915;
|
|
|
|
|
|
|
|
/** file_priv: owning file descriptor */
|
|
|
|
struct drm_i915_file_private *file_priv;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ppgtt: unique address space (GTT)
|
|
|
|
*
|
|
|
|
* In full-ppgtt mode, each context has its own address space ensuring
|
|
|
|
* complete seperation of one client from all others.
|
|
|
|
*
|
|
|
|
* In other modes, this is a NULL pointer with the expectation that
|
|
|
|
* the caller uses the shared global GTT.
|
|
|
|
*/
|
|
|
|
struct i915_hw_ppgtt *ppgtt;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @pid: process id of creator
|
|
|
|
*
|
|
|
|
* Note that who created the context may not be the principle user,
|
|
|
|
* as the context may be shared across a local socket. However,
|
|
|
|
* that should only affect the default context, all contexts created
|
|
|
|
* explicitly by the client are expected to be isolated.
|
|
|
|
*/
|
|
|
|
struct pid *pid;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name: arbitrary name
|
|
|
|
*
|
|
|
|
* A name is constructed for the context from the creator's process
|
|
|
|
* name, pid and user handle in order to uniquely identify the
|
|
|
|
* context in messages.
|
|
|
|
*/
|
|
|
|
const char *name;
|
|
|
|
|
|
|
|
/** link: place with &drm_i915_private.context_list */
|
|
|
|
struct list_head link;
|
2017-06-20 18:05:46 +07:00
|
|
|
struct llist_node free_link;
|
2016-12-31 18:20:11 +07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @ref: reference count
|
|
|
|
*
|
|
|
|
* A reference to a context is held by both the client who created it
|
|
|
|
* and on each request submitted to the hardware using the request
|
|
|
|
* (to ensure the hardware has access to the state until it has
|
|
|
|
* finished all pending writes). See i915_gem_context_get() and
|
|
|
|
* i915_gem_context_put() for access.
|
|
|
|
*/
|
|
|
|
struct kref ref;
|
|
|
|
|
2017-06-20 18:05:47 +07:00
|
|
|
/**
|
|
|
|
* @rcu: rcu_head for deferred freeing.
|
|
|
|
*/
|
|
|
|
struct rcu_head rcu;
|
|
|
|
|
2018-09-11 20:22:06 +07:00
|
|
|
/**
|
|
|
|
* @user_flags: small set of booleans controlled by the user
|
|
|
|
*/
|
|
|
|
unsigned long user_flags;
|
|
|
|
#define UCONTEXT_NO_ZEROMAP 0
|
|
|
|
#define UCONTEXT_NO_ERROR_CAPTURE 1
|
|
|
|
#define UCONTEXT_BANNABLE 2
|
2019-02-18 17:58:21 +07:00
|
|
|
#define UCONTEXT_RECOVERABLE 3
|
2018-09-11 20:22:06 +07:00
|
|
|
|
2016-12-31 18:20:11 +07:00
|
|
|
/**
|
|
|
|
* @flags: small set of booleans
|
|
|
|
*/
|
|
|
|
unsigned long flags;
|
2018-09-11 20:22:06 +07:00
|
|
|
#define CONTEXT_BANNED 0
|
|
|
|
#define CONTEXT_CLOSED 1
|
|
|
|
#define CONTEXT_FORCE_SINGLE_SUBMISSION 2
|
2016-12-31 18:20:11 +07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @hw_id: - unique identifier for the context
|
|
|
|
*
|
|
|
|
* The hardware needs to uniquely identify the context for a few
|
|
|
|
* functions like fault reporting, PASID, scheduling. The
|
|
|
|
* &drm_i915_private.context_hw_ida is used to assign a unqiue
|
|
|
|
* id for the lifetime of the context.
|
2018-09-04 22:31:17 +07:00
|
|
|
*
|
|
|
|
* @hw_id_pin_count: - number of times this context had been pinned
|
|
|
|
* for use (should be, at most, once per engine).
|
|
|
|
*
|
|
|
|
* @hw_id_link: - all contexts with an assigned id are tracked
|
|
|
|
* for possible repossession.
|
2016-12-31 18:20:11 +07:00
|
|
|
*/
|
|
|
|
unsigned int hw_id;
|
2018-09-04 22:31:17 +07:00
|
|
|
atomic_t hw_id_pin_count;
|
|
|
|
struct list_head hw_id_link;
|
2016-12-31 18:20:11 +07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @user_handle: userspace identifier
|
|
|
|
*
|
|
|
|
* A unique per-file identifier is generated from
|
|
|
|
* &drm_i915_file_private.contexts.
|
|
|
|
*/
|
|
|
|
u32 user_handle;
|
|
|
|
|
2018-04-19 01:40:52 +07:00
|
|
|
struct i915_sched_attr sched;
|
2016-12-31 18:20:11 +07:00
|
|
|
|
|
|
|
/** engine: per-engine logical HW state */
|
|
|
|
struct intel_context {
|
2018-05-18 04:26:32 +07:00
|
|
|
struct i915_gem_context *gem_context;
|
2018-10-03 18:09:41 +07:00
|
|
|
struct intel_engine_cs *active;
|
drm/i915: Replace global breadcrumbs with per-context interrupt tracking
A few years ago, see commit 688e6c725816 ("drm/i915: Slaughter the
thundering i915_wait_request herd"), the issue of handling multiple
clients waiting in parallel was brought to our attention. The
requirement was that every client should be woken immediately upon its
request being signaled, without incurring any cpu overhead.
To handle certain fragility of our hw meant that we could not do a
simple check inside the irq handler (some generations required almost
unbounded delays before we could be sure of seqno coherency) and so
request completion checking required delegation.
Before commit 688e6c725816, the solution was simple. Every client
waiting on a request would be woken on every interrupt and each would do
a heavyweight check to see if their request was complete. Commit
688e6c725816 introduced an rbtree so that only the earliest waiter on
the global timeline would woken, and would wake the next and so on.
(Along with various complications to handle requests being reordered
along the global timeline, and also a requirement for kthread to provide
a delegate for fence signaling that had no process context.)
The global rbtree depends on knowing the execution timeline (and global
seqno). Without knowing that order, we must instead check all contexts
queued to the HW to see which may have advanced. We trim that list by
only checking queued contexts that are being waited on, but still we
keep a list of all active contexts and their active signalers that we
inspect from inside the irq handler. By moving the waiters onto the fence
signal list, we can combine the client wakeup with the dma_fence
signaling (a dramatic reduction in complexity, but does require the HW
being coherent, the seqno must be visible from the cpu before the
interrupt is raised - we keep a timer backup just in case).
Having previously fixed all the issues with irq-seqno serialisation (by
inserting delays onto the GPU after each request instead of random delays
on the CPU after each interrupt), we can rely on the seqno state to
perfom direct wakeups from the interrupt handler. This allows us to
preserve our single context switch behaviour of the current routine,
with the only downside that we lose the RT priority sorting of wakeups.
In general, direct wakeup latency of multiple clients is about the same
(about 10% better in most cases) with a reduction in total CPU time spent
in the waiter (about 20-50% depending on gen). Average herd behaviour is
improved, but at the cost of not delegating wakeups on task_prio.
v2: Capture fence signaling state for error state and add comments to
warm even the most cold of hearts.
v3: Check if the request is still active before busywaiting
v4: Reduce the amount of pointer misdirection with list_for_each_safe
and using a local i915_request variable inside the loops
v5: Add a missing pluralisation to a purely informative selftest message.
References: 688e6c725816 ("drm/i915: Slaughter the thundering i915_wait_request herd")
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/20190129205230.19056-2-chris@chris-wilson.co.uk
2019-01-30 03:52:29 +07:00
|
|
|
struct list_head signal_link;
|
|
|
|
struct list_head signals;
|
2016-12-31 18:20:11 +07:00
|
|
|
struct i915_vma *state;
|
|
|
|
struct intel_ring *ring;
|
|
|
|
u32 *lrc_reg_state;
|
|
|
|
u64 lrc_desc;
|
|
|
|
int pin_count;
|
2018-05-18 04:26:32 +07: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 16:50:31 +07:00
|
|
|
/**
|
|
|
|
* active_tracker: Active tracker for the external rq activity
|
|
|
|
* on this intel_context object.
|
|
|
|
*/
|
drm/i915: Pull i915_gem_active into the i915_active family
Looking forward, we need to break the struct_mutex dependency on
i915_gem_active. In the meantime, external use of i915_gem_active is
quite beguiling, little do new users suspect that it implies a barrier
as each request it tracks must be ordered wrt the previous one. As one
of many, it can be used to track activity across multiple timelines, a
shared fence, which fits our unordered request submission much better. We
need to steer external users away from the singular, exclusive fence
imposed by i915_gem_active to i915_active instead. As part of that
process, we move i915_gem_active out of i915_request.c into
i915_active.c to start separating the two concepts, and rename it to
i915_active_request (both to tie it to the concept of tracking just one
request, and to give it a longer, less appealing name).
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20190205130005.2807-5-chris@chris-wilson.co.uk
2019-02-05 20:00:05 +07:00
|
|
|
struct i915_active_request active_tracker;
|
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 16:50:31 +07:00
|
|
|
|
2018-05-18 04:26:32 +07:00
|
|
|
const struct intel_context_ops *ops;
|
2019-02-05 16:50:28 +07:00
|
|
|
|
|
|
|
/** sseu: Control eu/slice partitioning */
|
|
|
|
struct intel_sseu sseu;
|
2018-04-30 20:15:01 +07:00
|
|
|
} __engine[I915_NUM_ENGINES];
|
2016-12-31 18:20:11 +07:00
|
|
|
|
|
|
|
/** ring_size: size for allocating the per-engine ring buffer */
|
|
|
|
u32 ring_size;
|
|
|
|
/** desc_template: invariant fields for the HW context descriptor */
|
|
|
|
u32 desc_template;
|
|
|
|
|
|
|
|
/** guilty_count: How many times this context has caused a GPU hang. */
|
2017-07-21 19:32:30 +07:00
|
|
|
atomic_t guilty_count;
|
2016-12-31 18:20:11 +07:00
|
|
|
/**
|
|
|
|
* @active_count: How many times this context was active during a GPU
|
|
|
|
* hang, but did not cause it.
|
|
|
|
*/
|
2017-07-21 19:32:30 +07:00
|
|
|
atomic_t active_count;
|
2016-12-31 18:20:11 +07:00
|
|
|
|
drm/i915: Use time based guilty context banning
Currently, we accumulate each time a context hangs the GPU, offset
against the number of requests it submits, and if that score exceeds a
certain threshold, we ban that context from submitting any more requests
(cancelling any work in flight). In contrast, we use a simple timer on
the file, that if we see more than a 9 hangs faster than 60s apart in
total across all of its contexts, we will ban the client from creating
any more contexts. This leads to a confusing situation where the file
may be banned before the context, so lets use a simple timer scheme for
each.
If the context submits 3 hanging requests within a 120s period, declare
it forbidden to ever send more requests.
This has the advantage of not being easy to repair by simply sending
empty requests, but has the disadvantage that if the context is idle
then it is forgiven. However, if the context is idle, it is not
disrupting the system, but a hog can evade the request counting and
cause much more severe disruption to the system.
Updating ban_score from request retirement is dubious as the retirement
is purposely not in sync with request submission (i.e. we try and batch
retirement to reduce overhead and avoid latency on submission), which
leads to surprising situations where we can forgive a hang immediately
due to a backlog of requests from before the hang being retired
afterwards.
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Mika Kuoppala <mika.kuoppala@intel.com>
Reviewed-by: Mika Kuoppala <mika.kuoppala@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20190219122215.8941-2-chris@chris-wilson.co.uk
2019-02-19 19:21:52 +07:00
|
|
|
/**
|
|
|
|
* @hang_timestamp: The last time(s) this context caused a GPU hang
|
|
|
|
*/
|
|
|
|
unsigned long hang_timestamp[2];
|
|
|
|
#define CONTEXT_FAST_HANG_JIFFIES (120 * HZ) /* 3 hangs within 120s? Banned! */
|
2016-12-31 18:20:11 +07:00
|
|
|
|
|
|
|
/** remap_slice: Bitmask of cache lines that need remapping */
|
|
|
|
u8 remap_slice;
|
2017-08-16 15:52:08 +07:00
|
|
|
|
|
|
|
/** handles_vma: rbtree to look up our context specific obj/vma for
|
|
|
|
* the user handle. (user handles are per fd, but the binding is
|
|
|
|
* per vm, which may be one per context or shared with the global GTT)
|
|
|
|
*/
|
|
|
|
struct radix_tree_root handles_vma;
|
|
|
|
|
|
|
|
/** handles_list: reverse list of all the rbtree entries in use for
|
|
|
|
* this context, which allows us to free all the allocations on
|
|
|
|
* context close.
|
|
|
|
*/
|
|
|
|
struct list_head handles_list;
|
2016-12-31 18:20:11 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
static inline bool i915_gem_context_is_closed(const struct i915_gem_context *ctx)
|
|
|
|
{
|
|
|
|
return test_bit(CONTEXT_CLOSED, &ctx->flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void i915_gem_context_set_closed(struct i915_gem_context *ctx)
|
|
|
|
{
|
|
|
|
GEM_BUG_ON(i915_gem_context_is_closed(ctx));
|
2018-09-11 20:22:06 +07:00
|
|
|
set_bit(CONTEXT_CLOSED, &ctx->flags);
|
2016-12-31 18:20:11 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool i915_gem_context_no_error_capture(const struct i915_gem_context *ctx)
|
|
|
|
{
|
2018-09-11 20:22:06 +07:00
|
|
|
return test_bit(UCONTEXT_NO_ERROR_CAPTURE, &ctx->user_flags);
|
2016-12-31 18:20:11 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void i915_gem_context_set_no_error_capture(struct i915_gem_context *ctx)
|
|
|
|
{
|
2018-09-11 20:22:06 +07:00
|
|
|
set_bit(UCONTEXT_NO_ERROR_CAPTURE, &ctx->user_flags);
|
2016-12-31 18:20:11 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void i915_gem_context_clear_no_error_capture(struct i915_gem_context *ctx)
|
|
|
|
{
|
2018-09-11 20:22:06 +07:00
|
|
|
clear_bit(UCONTEXT_NO_ERROR_CAPTURE, &ctx->user_flags);
|
2016-12-31 18:20:11 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool i915_gem_context_is_bannable(const struct i915_gem_context *ctx)
|
|
|
|
{
|
2018-09-11 20:22:06 +07:00
|
|
|
return test_bit(UCONTEXT_BANNABLE, &ctx->user_flags);
|
2016-12-31 18:20:11 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void i915_gem_context_set_bannable(struct i915_gem_context *ctx)
|
|
|
|
{
|
2018-09-11 20:22:06 +07:00
|
|
|
set_bit(UCONTEXT_BANNABLE, &ctx->user_flags);
|
2016-12-31 18:20:11 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void i915_gem_context_clear_bannable(struct i915_gem_context *ctx)
|
|
|
|
{
|
2018-09-11 20:22:06 +07:00
|
|
|
clear_bit(UCONTEXT_BANNABLE, &ctx->user_flags);
|
2016-12-31 18:20:11 +07:00
|
|
|
}
|
|
|
|
|
2019-02-18 17:58:21 +07:00
|
|
|
static inline bool i915_gem_context_is_recoverable(const struct i915_gem_context *ctx)
|
|
|
|
{
|
|
|
|
return test_bit(UCONTEXT_RECOVERABLE, &ctx->user_flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void i915_gem_context_set_recoverable(struct i915_gem_context *ctx)
|
|
|
|
{
|
|
|
|
set_bit(UCONTEXT_RECOVERABLE, &ctx->user_flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void i915_gem_context_clear_recoverable(struct i915_gem_context *ctx)
|
|
|
|
{
|
|
|
|
clear_bit(UCONTEXT_RECOVERABLE, &ctx->user_flags);
|
|
|
|
}
|
|
|
|
|
2016-12-31 18:20:11 +07:00
|
|
|
static inline bool i915_gem_context_is_banned(const struct i915_gem_context *ctx)
|
|
|
|
{
|
|
|
|
return test_bit(CONTEXT_BANNED, &ctx->flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void i915_gem_context_set_banned(struct i915_gem_context *ctx)
|
|
|
|
{
|
2018-09-11 20:22:06 +07:00
|
|
|
set_bit(CONTEXT_BANNED, &ctx->flags);
|
2016-12-31 18:20:11 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool i915_gem_context_force_single_submission(const struct i915_gem_context *ctx)
|
|
|
|
{
|
|
|
|
return test_bit(CONTEXT_FORCE_SINGLE_SUBMISSION, &ctx->flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void i915_gem_context_set_force_single_submission(struct i915_gem_context *ctx)
|
|
|
|
{
|
|
|
|
__set_bit(CONTEXT_FORCE_SINGLE_SUBMISSION, &ctx->flags);
|
|
|
|
}
|
|
|
|
|
2018-09-04 22:31:17 +07:00
|
|
|
int __i915_gem_context_pin_hw_id(struct i915_gem_context *ctx);
|
|
|
|
static inline int i915_gem_context_pin_hw_id(struct i915_gem_context *ctx)
|
|
|
|
{
|
|
|
|
if (atomic_inc_not_zero(&ctx->hw_id_pin_count))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return __i915_gem_context_pin_hw_id(ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void i915_gem_context_unpin_hw_id(struct i915_gem_context *ctx)
|
|
|
|
{
|
|
|
|
GEM_BUG_ON(atomic_read(&ctx->hw_id_pin_count) == 0u);
|
|
|
|
atomic_dec(&ctx->hw_id_pin_count);
|
|
|
|
}
|
|
|
|
|
2016-12-31 18:20:11 +07:00
|
|
|
static inline bool i915_gem_context_is_default(const struct i915_gem_context *c)
|
|
|
|
{
|
|
|
|
return c->user_handle == DEFAULT_CONTEXT_HANDLE;
|
|
|
|
}
|
|
|
|
|
2017-01-06 22:20:13 +07:00
|
|
|
static inline bool i915_gem_context_is_kernel(struct i915_gem_context *ctx)
|
|
|
|
{
|
|
|
|
return !ctx->file_priv;
|
|
|
|
}
|
|
|
|
|
2018-04-30 20:15:01 +07:00
|
|
|
static inline struct intel_context *
|
|
|
|
to_intel_context(struct i915_gem_context *ctx,
|
|
|
|
const struct intel_engine_cs *engine)
|
|
|
|
{
|
|
|
|
return &ctx->__engine[engine->id];
|
|
|
|
}
|
|
|
|
|
2018-05-18 04:26:32 +07:00
|
|
|
static inline struct intel_context *
|
2018-04-30 20:15:01 +07:00
|
|
|
intel_context_pin(struct i915_gem_context *ctx, struct intel_engine_cs *engine)
|
|
|
|
{
|
|
|
|
return engine->context_pin(engine, ctx);
|
|
|
|
}
|
|
|
|
|
2018-05-18 04:26:32 +07:00
|
|
|
static inline void __intel_context_pin(struct intel_context *ce)
|
2018-04-30 20:15:01 +07:00
|
|
|
{
|
|
|
|
GEM_BUG_ON(!ce->pin_count);
|
|
|
|
ce->pin_count++;
|
|
|
|
}
|
|
|
|
|
2018-05-18 04:26:32 +07:00
|
|
|
static inline void intel_context_unpin(struct intel_context *ce)
|
2018-04-30 20:15:01 +07:00
|
|
|
{
|
2018-05-18 04:26:33 +07:00
|
|
|
GEM_BUG_ON(!ce->pin_count);
|
|
|
|
if (--ce->pin_count)
|
|
|
|
return;
|
|
|
|
|
2018-05-18 04:26:32 +07:00
|
|
|
GEM_BUG_ON(!ce->ops);
|
|
|
|
ce->ops->unpin(ce);
|
2018-04-30 20:15:01 +07:00
|
|
|
}
|
|
|
|
|
2016-12-31 18:20:11 +07:00
|
|
|
/* i915_gem_context.c */
|
2017-06-20 18:05:45 +07:00
|
|
|
int __must_check i915_gem_contexts_init(struct drm_i915_private *dev_priv);
|
|
|
|
void i915_gem_contexts_lost(struct drm_i915_private *dev_priv);
|
|
|
|
void i915_gem_contexts_fini(struct drm_i915_private *dev_priv);
|
|
|
|
|
|
|
|
int i915_gem_context_open(struct drm_i915_private *i915,
|
|
|
|
struct drm_file *file);
|
|
|
|
void i915_gem_context_close(struct drm_file *file);
|
|
|
|
|
2018-02-21 16:56:36 +07:00
|
|
|
int i915_switch_context(struct i915_request *rq);
|
2016-12-31 18:20:11 +07:00
|
|
|
int i915_gem_switch_to_kernel_context(struct drm_i915_private *dev_priv);
|
2017-06-20 18:05:45 +07:00
|
|
|
|
2017-06-20 18:05:46 +07:00
|
|
|
void i915_gem_context_release(struct kref *ctx_ref);
|
2016-12-31 18:20:11 +07:00
|
|
|
struct i915_gem_context *
|
|
|
|
i915_gem_context_create_gvt(struct drm_device *dev);
|
|
|
|
|
|
|
|
int i915_gem_context_create_ioctl(struct drm_device *dev, void *data,
|
|
|
|
struct drm_file *file);
|
|
|
|
int i915_gem_context_destroy_ioctl(struct drm_device *dev, void *data,
|
|
|
|
struct drm_file *file);
|
|
|
|
int i915_gem_context_getparam_ioctl(struct drm_device *dev, void *data,
|
|
|
|
struct drm_file *file_priv);
|
|
|
|
int i915_gem_context_setparam_ioctl(struct drm_device *dev, void *data,
|
|
|
|
struct drm_file *file_priv);
|
|
|
|
int i915_gem_context_reset_stats_ioctl(struct drm_device *dev, void *data,
|
|
|
|
struct drm_file *file);
|
|
|
|
|
2017-11-10 21:26:33 +07:00
|
|
|
struct i915_gem_context *
|
|
|
|
i915_gem_context_create_kernel(struct drm_i915_private *i915, int prio);
|
|
|
|
|
2017-06-20 18:05:46 +07:00
|
|
|
static inline struct i915_gem_context *
|
|
|
|
i915_gem_context_get(struct i915_gem_context *ctx)
|
|
|
|
{
|
|
|
|
kref_get(&ctx->ref);
|
|
|
|
return ctx;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void i915_gem_context_put(struct i915_gem_context *ctx)
|
|
|
|
{
|
|
|
|
kref_put(&ctx->ref, i915_gem_context_release);
|
|
|
|
}
|
|
|
|
|
2019-01-24 15:37:10 +07:00
|
|
|
void intel_context_init(struct intel_context *ce,
|
|
|
|
struct i915_gem_context *ctx,
|
|
|
|
struct intel_engine_cs *engine);
|
2019-01-22 05:20:50 +07:00
|
|
|
|
2016-12-31 18:20:11 +07:00
|
|
|
#endif /* !__I915_GEM_CONTEXT_H__ */
|