Commit 27a5dcfe authored by Chris Wilson's avatar Chris Wilson Committed by Joonas Lahtinen

drm/i915/gem: Remove disordered per-file request list for throttling

I915_GEM_THROTTLE dates back to the time before contexts where there was
just a single engine, and therefore a single timeline and request list
globally. That request list was in execution/retirement order, and so
walking it to find a particular aged request made sense and could be
split per file.

That is no more. We now have many timelines with a file, as many as the
user wants to construct (essentially per-engine, per-context). Each of
those run independently and so make the single list futile. Remove the
disordered list, and iterate over all the timelines to find a request to
wait on in each to satisfy the criteria that the CPU is no more than 20ms
ahead of its oldest request.

It should go without saying that the I915_GEM_THROTTLE ioctl is no
longer used as the primary means of throttling, so it makes sense to push
the complication into the ioctl where it only impacts upon its few
irregular users, rather than the execbuf/retire where everybody has to
pay the cost. Fortunately, the few users do not create vast amount of
contexts, so the loops over contexts/engines should be concise.
Signed-off-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Cc: Mika Kuoppala <mika.kuoppala@linux.intel.com>
Reviewed-by: default avatarTvrtko Ursulin <tvrtko.ursulin@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20200728152010.30701-1-chris@chris-wilson.co.ukSigned-off-by: default avatarRodrigo Vivi <rodrigo.vivi@intel.com>
Signed-off-by: default avatarJoonas Lahtinen <joonas.lahtinen@linux.intel.com>
parent 3adee4ac
...@@ -1928,18 +1928,6 @@ static int eb_parse(struct i915_execbuffer *eb) ...@@ -1928,18 +1928,6 @@ static int eb_parse(struct i915_execbuffer *eb)
return err; return err;
} }
static void
add_to_client(struct i915_request *rq, struct drm_file *file)
{
struct drm_i915_file_private *file_priv = file->driver_priv;
rq->file_priv = file_priv;
spin_lock(&file_priv->mm.lock);
list_add_tail(&rq->client_link, &file_priv->mm.request_list);
spin_unlock(&file_priv->mm.lock);
}
static int eb_submit(struct i915_execbuffer *eb, struct i915_vma *batch) static int eb_submit(struct i915_execbuffer *eb, struct i915_vma *batch)
{ {
int err; int err;
...@@ -2772,7 +2760,6 @@ i915_gem_do_execbuffer(struct drm_device *dev, ...@@ -2772,7 +2760,6 @@ i915_gem_do_execbuffer(struct drm_device *dev,
trace_i915_request_queue(eb.request, eb.batch_flags); trace_i915_request_queue(eb.request, eb.batch_flags);
err = eb_submit(&eb, batch); err = eb_submit(&eb, batch);
err_request: err_request:
add_to_client(eb.request, file);
i915_request_get(eb.request); i915_request_get(eb.request);
eb_request_add(&eb); eb_request_add(&eb);
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <drm/drm_file.h> #include <drm/drm_file.h>
#include "i915_drv.h" #include "i915_drv.h"
#include "i915_gem_context.h"
#include "i915_gem_ioctls.h" #include "i915_gem_ioctls.h"
#include "i915_gem_object.h" #include "i915_gem_object.h"
...@@ -35,9 +36,10 @@ int ...@@ -35,9 +36,10 @@ int
i915_gem_throttle_ioctl(struct drm_device *dev, void *data, i915_gem_throttle_ioctl(struct drm_device *dev, void *data,
struct drm_file *file) struct drm_file *file)
{ {
const unsigned long recent_enough = jiffies - DRM_I915_THROTTLE_JIFFIES;
struct drm_i915_file_private *file_priv = file->driver_priv; struct drm_i915_file_private *file_priv = file->driver_priv;
unsigned long recent_enough = jiffies - DRM_I915_THROTTLE_JIFFIES; struct i915_gem_context *ctx;
struct i915_request *request, *target = NULL; unsigned long idx;
long ret; long ret;
/* ABI: return -EIO if already wedged */ /* ABI: return -EIO if already wedged */
...@@ -45,27 +47,54 @@ i915_gem_throttle_ioctl(struct drm_device *dev, void *data, ...@@ -45,27 +47,54 @@ i915_gem_throttle_ioctl(struct drm_device *dev, void *data,
if (ret) if (ret)
return ret; return ret;
spin_lock(&file_priv->mm.lock); rcu_read_lock();
list_for_each_entry(request, &file_priv->mm.request_list, client_link) { xa_for_each(&file_priv->context_xa, idx, ctx) {
if (time_after_eq(request->emitted_jiffies, recent_enough)) struct i915_gem_engines_iter it;
break; struct intel_context *ce;
if (target && xchg(&target->file_priv, NULL)) if (!kref_get_unless_zero(&ctx->ref))
list_del(&target->client_link); continue;
rcu_read_unlock();
target = request; for_each_gem_engine(ce,
} i915_gem_context_lock_engines(ctx),
if (target) it) {
i915_request_get(target); struct i915_request *rq, *target = NULL;
spin_unlock(&file_priv->mm.lock);
if (!ce->timeline)
continue;
mutex_lock(&ce->timeline->mutex);
list_for_each_entry_reverse(rq,
&ce->timeline->requests,
link) {
if (i915_request_completed(rq))
break;
if (!target) if (time_after(rq->emitted_jiffies,
return 0; recent_enough))
continue;
ret = i915_request_wait(target, target = i915_request_get(rq);
I915_WAIT_INTERRUPTIBLE, break;
MAX_SCHEDULE_TIMEOUT); }
i915_request_put(target); mutex_unlock(&ce->timeline->mutex);
if (!target)
continue;
ret = i915_request_wait(target,
I915_WAIT_INTERRUPTIBLE,
MAX_SCHEDULE_TIMEOUT);
i915_request_put(target);
if (ret < 0)
break;
}
i915_gem_context_unlock_engines(ctx);
i915_gem_context_put(ctx);
rcu_read_lock();
}
rcu_read_unlock();
return ret < 0 ? ret : 0; return ret < 0 ? ret : 0;
} }
...@@ -2729,7 +2729,7 @@ static int create_gang(struct intel_engine_cs *engine, ...@@ -2729,7 +2729,7 @@ static int create_gang(struct intel_engine_cs *engine,
i915_gem_object_put(obj); i915_gem_object_put(obj);
intel_context_put(ce); intel_context_put(ce);
rq->client_link.next = &(*prev)->client_link; rq->mock.link.next = &(*prev)->mock.link;
*prev = rq; *prev = rq;
return 0; return 0;
...@@ -2970,8 +2970,7 @@ static int live_preempt_gang(void *arg) ...@@ -2970,8 +2970,7 @@ static int live_preempt_gang(void *arg)
} }
while (rq) { /* wait for each rq from highest to lowest prio */ while (rq) { /* wait for each rq from highest to lowest prio */
struct i915_request *n = struct i915_request *n = list_next_entry(rq, mock.link);
list_next_entry(rq, client_link);
if (err == 0 && i915_request_wait(rq, 0, HZ / 5) < 0) { if (err == 0 && i915_request_wait(rq, 0, HZ / 5) < 0) {
struct drm_printer p = struct drm_printer p =
......
...@@ -1119,7 +1119,6 @@ static void i915_driver_postclose(struct drm_device *dev, struct drm_file *file) ...@@ -1119,7 +1119,6 @@ static void i915_driver_postclose(struct drm_device *dev, struct drm_file *file)
struct drm_i915_file_private *file_priv = file->driver_priv; struct drm_i915_file_private *file_priv = file->driver_priv;
i915_gem_context_close(file); i915_gem_context_close(file);
i915_gem_release(dev, file);
kfree_rcu(file_priv, rcu); kfree_rcu(file_priv, rcu);
......
...@@ -203,11 +203,6 @@ struct drm_i915_file_private { ...@@ -203,11 +203,6 @@ struct drm_i915_file_private {
struct rcu_head rcu; struct rcu_head rcu;
}; };
struct {
spinlock_t lock;
struct list_head request_list;
} mm;
struct xarray context_xa; struct xarray context_xa;
struct xarray vm_xa; struct xarray vm_xa;
...@@ -1867,7 +1862,6 @@ void i915_gem_suspend_late(struct drm_i915_private *dev_priv); ...@@ -1867,7 +1862,6 @@ void i915_gem_suspend_late(struct drm_i915_private *dev_priv);
void i915_gem_resume(struct drm_i915_private *dev_priv); void i915_gem_resume(struct drm_i915_private *dev_priv);
int i915_gem_open(struct drm_i915_private *i915, struct drm_file *file); int i915_gem_open(struct drm_i915_private *i915, struct drm_file *file);
void i915_gem_release(struct drm_device *dev, struct drm_file *file);
int i915_gem_object_set_cache_level(struct drm_i915_gem_object *obj, int i915_gem_object_set_cache_level(struct drm_i915_gem_object *obj,
enum i915_cache_level cache_level); enum i915_cache_level cache_level);
......
...@@ -1301,21 +1301,6 @@ int i915_gem_freeze_late(struct drm_i915_private *i915) ...@@ -1301,21 +1301,6 @@ int i915_gem_freeze_late(struct drm_i915_private *i915)
return 0; return 0;
} }
void i915_gem_release(struct drm_device *dev, struct drm_file *file)
{
struct drm_i915_file_private *file_priv = file->driver_priv;
struct i915_request *request;
/* Clean up our request list when the client is going away, so that
* later retire_requests won't dereference our soon-to-be-gone
* file_priv.
*/
spin_lock(&file_priv->mm.lock);
list_for_each_entry(request, &file_priv->mm.request_list, client_link)
request->file_priv = NULL;
spin_unlock(&file_priv->mm.lock);
}
int i915_gem_open(struct drm_i915_private *i915, struct drm_file *file) int i915_gem_open(struct drm_i915_private *i915, struct drm_file *file)
{ {
struct drm_i915_file_private *file_priv; struct drm_i915_file_private *file_priv;
...@@ -1331,9 +1316,6 @@ int i915_gem_open(struct drm_i915_private *i915, struct drm_file *file) ...@@ -1331,9 +1316,6 @@ int i915_gem_open(struct drm_i915_private *i915, struct drm_file *file)
file_priv->dev_priv = i915; file_priv->dev_priv = i915;
file_priv->file = file; file_priv->file = file;
spin_lock_init(&file_priv->mm.lock);
INIT_LIST_HEAD(&file_priv->mm.request_list);
file_priv->bsd_engine = -1; file_priv->bsd_engine = -1;
file_priv->hang_timestamp = jiffies; file_priv->hang_timestamp = jiffies;
......
...@@ -212,24 +212,6 @@ static void __notify_execute_cb(struct i915_request *rq) ...@@ -212,24 +212,6 @@ static void __notify_execute_cb(struct i915_request *rq)
init_llist_head(&rq->execute_cb); init_llist_head(&rq->execute_cb);
} }
static inline void
remove_from_client(struct i915_request *request)
{
struct drm_i915_file_private *file_priv;
if (!READ_ONCE(request->file_priv))
return;
rcu_read_lock();
file_priv = xchg(&request->file_priv, NULL);
if (file_priv) {
spin_lock(&file_priv->mm.lock);
list_del(&request->client_link);
spin_unlock(&file_priv->mm.lock);
}
rcu_read_unlock();
}
static void free_capture_list(struct i915_request *request) static void free_capture_list(struct i915_request *request)
{ {
struct i915_capture_list *capture; struct i915_capture_list *capture;
...@@ -330,7 +312,6 @@ bool i915_request_retire(struct i915_request *rq) ...@@ -330,7 +312,6 @@ bool i915_request_retire(struct i915_request *rq)
GEM_BUG_ON(!llist_empty(&rq->execute_cb)); GEM_BUG_ON(!llist_empty(&rq->execute_cb));
spin_unlock_irq(&rq->lock); spin_unlock_irq(&rq->lock);
remove_from_client(rq);
__list_del_entry(&rq->link); /* poison neither prev/next (RCU walks) */ __list_del_entry(&rq->link); /* poison neither prev/next (RCU walks) */
intel_context_exit(rq->context); intel_context_exit(rq->context);
...@@ -757,7 +738,6 @@ static void __i915_request_ctor(void *arg) ...@@ -757,7 +738,6 @@ static void __i915_request_ctor(void *arg)
dma_fence_init(&rq->fence, &i915_fence_ops, &rq->lock, 0, 0); dma_fence_init(&rq->fence, &i915_fence_ops, &rq->lock, 0, 0);
rq->file_priv = NULL;
rq->capture_list = NULL; rq->capture_list = NULL;
init_llist_head(&rq->execute_cb); init_llist_head(&rq->execute_cb);
...@@ -847,7 +827,6 @@ __i915_request_create(struct intel_context *ce, gfp_t gfp) ...@@ -847,7 +827,6 @@ __i915_request_create(struct intel_context *ce, gfp_t gfp)
/* No zalloc, everything must be cleared after use */ /* No zalloc, everything must be cleared after use */
rq->batch = NULL; rq->batch = NULL;
GEM_BUG_ON(rq->file_priv);
GEM_BUG_ON(rq->capture_list); GEM_BUG_ON(rq->capture_list);
GEM_BUG_ON(!llist_empty(&rq->execute_cb)); GEM_BUG_ON(!llist_empty(&rq->execute_cb));
......
...@@ -284,10 +284,6 @@ struct i915_request { ...@@ -284,10 +284,6 @@ struct i915_request {
/** timeline->request entry for this request */ /** timeline->request entry for this request */
struct list_head link; struct list_head link;
struct drm_i915_file_private *file_priv;
/** file_priv list entry for this request */
struct list_head client_link;
I915_SELFTEST_DECLARE(struct { I915_SELFTEST_DECLARE(struct {
struct list_head link; struct list_head link;
unsigned long delay; unsigned long delay;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment