drm/i915: Pre-allocation of shmem pages of a GEM object
Subsystems (2)
PATCH v2 1/1 drm/i915: Pre-allocation of shmem pages of a GEM object
From: Akash Goel <[email protected]>
This patch could help to reduce the time, 'struct_mutex' is kept locked during either the exec-buffer path or Page fault handling path as now the backing pages are requested from shmem layer without holding the 'struct_mutex'.
v2: Fixed the merge issue, due to which 'exec_lock' mutex was not released.
--- drivers/gpu/drm/i915/i915_debugfs.c | 9 +++- drivers/gpu/drm/i915/i915_dma.c | 1 + drivers/gpu/drm/i915/i915_drv.h | 5 ++ drivers/gpu/drm/i915/i915_gem.c | 75 ++++++++++++++++++++++++++ drivers/gpu/drm/i915/i915_gem_execbuffer.c | 87 ++++++++++++++++++++++++++---- drivers/gpu/drm/i915/i915_trace.h | 35 ++++++++++++ 6 files changed, 200 insertions(+), 12 deletions(-)
drivers/gpu/drm/i915/i915_debugfs.c +8 -1
@@ -247,10 +247,16 @@ static int i915_gem_stolen_list_info(struct seq_file *m, void *data)LIST_HEAD (stolen);int count, ret; - ret =mutex_lock_interruptible (&dev->struct_mutex); + ret =mutex_lock_interruptible (&dev_priv->exec_lock);if (ret)return ret; + ret =mutex_lock_interruptible (&dev->struct_mutex); +if (ret) { +mutex_unlock (&dev_priv->exec_lock); +return ret; + } + total_obj_size = total_gtt_size = count =0 ;list_for_each_entry (obj, &dev_priv->mm.bound_list, global_list) {if (obj->stolen ==NULL )
@@ -281,6 +287,7 @@ static int i915_gem_stolen_list_info(struct seq_file *m, void *data)list_del_init (&obj->obj_exec_link); }mutex_unlock (&dev->struct_mutex); +mutex_unlock (&dev_priv->exec_lock);seq_printf (m,"Total %d objects, %zu bytes, %zu GTT size\n" , count, total_obj_size, total_gtt_size);
drivers/gpu/drm/i915/i915_dma.c +1 -0
@@ -1572,6 +1572,7 @@ int i915_driver_load(struct drm_device *dev, unsigned long flags) dev_priv->ring_index =0 ;mutex_init (&dev_priv->dpio_lock);mutex_init (&dev_priv->modeset_restore_lock); +mutex_init (&dev_priv->exec_lock);intel_pm_setup (dev);
drivers/gpu/drm/i915/i915_drv.h +5 -0
@@ -1475,6 +1475,8 @@ struct drm_i915_private {struct i915_ums_state ums;/* the indicator for dispatch video commands on two BSD rings */ int ring_index; +/* for concurrent execbuffer protection */ +struct mutex exec_lock; };static inline struct drm_i915_private *to_i915 (const struct drm_device *dev)
@@ -2116,6 +2118,9 @@ int i915_gem_dumb_create(struct drm_file *file_priv, struct drm_mode_create_dumb *args);int i915_gem_mmap_gtt (struct drm_file *file_priv,struct drm_device *dev,uint32_t handle,uint64_t *offset); +void +i915_gem_object_shmem_preallocate (struct drm_i915_gem_object *obj); +/** * Returns true if seq1 is later than seq2. */
drivers/gpu/drm/i915/i915_gem.c +75 -0
87 lines not on this page · raw message
drivers/gpu/drm/i915/i915_gem_execbuffer.c +76 -11
182 lines not on this page · raw message
drivers/gpu/drm/i915/i915_trace.h +35 -0
@@ -245,6 +245,41 @@ TRACE_EVENT(i915_gem_object_fault, __entry->write ? ", writable" : "") ); +TRACE_EVENT (i915_gem_obj_prealloc_start, + TP_PROTO(struct drm_i915_gem_object *obj, u32 size), +TP_ARGS (obj, size), + +TP_STRUCT__entry ( + __field(struct drm_i915_gem_object *, obj) +__field (u32, size) + ), + +TP_fast_assign ( + __entry->obj = obj; + __entry->size = size; + ), + +TP_printk ("obj=%p, size=%x" , + __entry->obj, + __entry->size) +); + +TRACE_EVENT (i915_gem_obj_prealloc_end, + TP_PROTO(struct drm_i915_gem_object *obj), +TP_ARGS (obj), + +TP_STRUCT__entry ( + __field(struct drm_i915_gem_object *, obj) + ), + +TP_fast_assign ( + __entry->obj = obj; + ), + +TP_printk ("obj=%p" , + __entry->obj) +); + DECLARE_EVENT_CLASS(i915_gem_object, TP_PROTO(struct drm_i915_gem_object *obj), TP_ARGS(obj),
Signature · 1 line
1.9.2
Quoted 8 lines · On Mon, May 05, 2014 at 09:55:29AM +0530, [email protected] wrote:
From: Akash Goel <[email protected]>
This patch could help to reduce the time, '
struct_mutex' is kept locked during either the exec-buffer path or Page fault handling path as now the backing pages are requested from shmem layer without holding the 'struct_mutex'.v2: Fixed the merge issue, due to which '
exec_lock' mutex was not released.
This would be a good excuse to work on per-object locks and augmenting i915_gem_madvise_ioctl() to grab pages. iow, add obj->mutex and use that for guarding all obj->pages related members/operations, then add I915_MADV_POPULATE which can run without the struct mutex.
That should provide you with the lockless get_pages and keep execbuffer reasonably clean and fast.
Again, please think about why you are *clflushing* so many pages so often. That is a sign of userspace bo cache failure. -Chris
Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
Quoted 10 lines · Chris Wilson
Quoted 8 lines · On Mon, May 05, 2014 at 09:55:29AM +0530, [email protected] wrote:
From: Akash Goel <[email protected]>
This patch could help to reduce the time, '
struct_mutex' is kept locked during either the exec-buffer path or Page fault handling path as now the backing pages are requested from shmem layer without holding the 'struct_mutex'.v2: Fixed the merge issue, due to which '
exec_lock' mutex was not released.
Quoted 7 lines
This would be a good excuse to work on per-object locks and augmenting
i915_gem_madvise_ioctl()to grab pages. iow, addobj->mutexand use that for guarding allobj->pagesrelated members/operations, then addI915_MADV_POPULATEwhich can run without the struct mutex.That should provide you with the lockless
get_pagesand keep execbuffer reasonably clean and fast.
Yes the per object lock would be a more cleaner approach here. But it could take some time to implement it, so time being can we consider this as a stopgap solution.
Quoted 4 lines
Again, please think about why you are *clflushing* so many pages so often. That is a sign of userspace bo cache failure. -Chris
Sorry not sure that whether I understood your point here, but we are not doing any extra clflush here, just doing the needful.
Any newly allocated buffer from shmem, is by default marked as to be present in CPU domain, so when it is being submitted to rendering on GPU, all the pages of this buffer are 'clflushed'.
This is probably to ensure that any stale data for this buffer in CPU cache is flushed out, before GPU actually starts writing to this buffer, otherwise the data written by GPU could be overwritten with stale data in CPU cache subsequently.
Sometimes there is an odd need to process buffers of huge size (like ~34 MB) and that's where the user space bo cache might also fail.
Best regards
Akash