diff options
author | John Harrison <John.C.Harrison@Intel.com> | 2014-04-02 11:38:35 +0100 |
---|---|---|
committer | John Harrison <John.C.Harrison@Intel.com> | 2016-05-06 14:12:52 +0100 |
commit | aa7e53075a8c7cd4435a1073d7a40fc57d9d5099 (patch) | |
tree | 1ef8246296e668000a73b2ea0164898f0b54da86 | |
parent | 61350574b209353dab5ea7c7c2cef03f6d6f0c83 (diff) |
drm/i915: Added scheduler hook when closing DRM file handles
The scheduler decouples the submission of batch buffers to the driver
with submission of batch buffers to the hardware. Thus it is possible
for an application to close its DRM file handle while there is still
work outstanding. That means the scheduler needs to know about file
close events so it can remove the file pointer from such orphaned
batch buffers and not attempt to dereference it later.
v3: Updated to not wait for outstanding work to complete but merely
remove the file handle reference. The wait was getting excessively
complicated with inter-ring dependencies, pre-emption, and other such
issues.
v4: Changed some white space to keep the style checker happy.
v5: Added function documentation and removed apparently objectionable
white space. [Joonas Lahtinen]
Used lighter weight spinlocks.
v6: Updated to newer nightly (lots of ring -> engine renaming).
Added 'for_each_scheduler_node()' helper macro. Updated to use
'to_i915()' instead of dev_private. Removed the return value from
i915_scheduler_closefile() as it is not used for anything. [review
feedback from Joonas Lahtinen]
For: VIZ-1587
Signed-off-by: John Harrison <John.C.Harrison@Intel.com>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Reviewed-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
-rw-r--r-- | drivers/gpu/drm/i915/i915_dma.c | 2 | ||||
-rw-r--r-- | drivers/gpu/drm/i915/i915_scheduler.c | 45 | ||||
-rw-r--r-- | drivers/gpu/drm/i915/i915_scheduler.h | 1 |
3 files changed, 48 insertions, 0 deletions
diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c index 2ad4071bd7c8..75dc3136dcb6 100644 --- a/drivers/gpu/drm/i915/i915_dma.c +++ b/drivers/gpu/drm/i915/i915_dma.c @@ -1509,6 +1509,8 @@ void i915_driver_lastclose(struct drm_device *dev) void i915_driver_preclose(struct drm_device *dev, struct drm_file *file) { + i915_scheduler_closefile(dev, file); + mutex_lock(&dev->struct_mutex); i915_gem_context_close(dev, file); i915_gem_release(dev, file); diff --git a/drivers/gpu/drm/i915/i915_scheduler.c b/drivers/gpu/drm/i915/i915_scheduler.c index 9d628b93eb38..6dd98389bb58 100644 --- a/drivers/gpu/drm/i915/i915_scheduler.c +++ b/drivers/gpu/drm/i915/i915_scheduler.c @@ -865,3 +865,48 @@ void i915_scheduler_process_work(struct intel_engine_cs *engine) if (do_submit) intel_runtime_pm_put(dev_priv); } + +/** + * i915_scheduler_closefile - notify the scheduler that a DRM file handle + * has been closed. + * @dev: DRM device + * @file: file being closed + * + * Goes through the scheduler's queues and removes all connections to the + * disappearing file handle that still exist. There is an argument to say + * that this should also flush such outstanding work through the hardware. + * However, with pre-emption, TDR and other such complications doing so + * becomes a locking nightmare. So instead, just warn with a debug message + * if the application is leaking uncompleted work and make sure a null + * pointer dereference will not follow. + */ +void i915_scheduler_closefile(struct drm_device *dev, struct drm_file *file) +{ + struct i915_scheduler_queue_entry *node; + struct drm_i915_private *dev_priv = to_i915(dev); + struct i915_scheduler *scheduler = dev_priv->scheduler; + struct intel_engine_cs *engine; + + if (!scheduler) + return; + + spin_lock_irq(&scheduler->lock); + + for_each_engine(engine, dev_priv) { + for_each_scheduler_node(node, engine->id) { + if (node->params.file != file) + continue; + + if (!I915_SQS_IS_COMPLETE(node)) + DRM_DEBUG_DRIVER("Closing file handle with outstanding work: %d:%d/%d on %s\n", + node->params.request->uniq, + node->params.request->seqno, + node->status, + engine->name); + + node->params.file = NULL; + } + } + + spin_unlock_irq(&scheduler->lock); +} diff --git a/drivers/gpu/drm/i915/i915_scheduler.h b/drivers/gpu/drm/i915/i915_scheduler.h index c895c4cbc68e..40398bb96f26 100644 --- a/drivers/gpu/drm/i915/i915_scheduler.h +++ b/drivers/gpu/drm/i915/i915_scheduler.h @@ -105,6 +105,7 @@ enum { bool i915_scheduler_is_enabled(struct drm_device *dev); int i915_scheduler_init(struct drm_device *dev); void i915_scheduler_destroy(struct drm_i915_private *dev_priv); +void i915_scheduler_closefile(struct drm_device *dev, struct drm_file *file); void i915_scheduler_clean_node(struct i915_scheduler_queue_entry *node); int i915_scheduler_queue_execbuffer(struct i915_scheduler_queue_entry *qe); bool i915_scheduler_notify_request(struct drm_i915_gem_request *req); |