Commit 2d60d3e0 authored by Chris Wilson's avatar Chris Wilson

drm/i915/gem: Reduce ctx->engines_mutex for get_engines()

Take a snapshot of the ctx->engines, so we can avoid taking the
ctx->engines_mutex for a mere read in get_engines().
Signed-off-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: default avatarAndi Shyti <andi.shyti@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20210114135612.13210-4-chris@chris-wilson.co.uk
parent 1a72e741
...@@ -1843,27 +1843,6 @@ set_engines(struct i915_gem_context *ctx, ...@@ -1843,27 +1843,6 @@ set_engines(struct i915_gem_context *ctx,
return 0; return 0;
} }
static struct i915_gem_engines *
__copy_engines(struct i915_gem_engines *e)
{
struct i915_gem_engines *copy;
unsigned int n;
copy = alloc_engines(e->num_engines);
if (!copy)
return ERR_PTR(-ENOMEM);
for (n = 0; n < e->num_engines; n++) {
if (e->engines[n])
copy->engines[n] = intel_context_get(e->engines[n]);
else
copy->engines[n] = NULL;
}
copy->num_engines = n;
return copy;
}
static int static int
get_engines(struct i915_gem_context *ctx, get_engines(struct i915_gem_context *ctx,
struct drm_i915_gem_context_param *args) struct drm_i915_gem_context_param *args)
...@@ -1871,19 +1850,17 @@ get_engines(struct i915_gem_context *ctx, ...@@ -1871,19 +1850,17 @@ get_engines(struct i915_gem_context *ctx,
struct i915_context_param_engines __user *user; struct i915_context_param_engines __user *user;
struct i915_gem_engines *e; struct i915_gem_engines *e;
size_t n, count, size; size_t n, count, size;
bool user_engines;
int err = 0; int err = 0;
err = mutex_lock_interruptible(&ctx->engines_mutex); e = __context_engines_await(ctx, &user_engines);
if (err) if (!e)
return err; return -ENOENT;
e = NULL; if (!user_engines) {
if (i915_gem_context_user_engines(ctx)) i915_sw_fence_complete(&e->fence);
e = __copy_engines(i915_gem_context_engines(ctx));
mutex_unlock(&ctx->engines_mutex);
if (IS_ERR_OR_NULL(e)) {
args->size = 0; args->size = 0;
return PTR_ERR_OR_ZERO(e); return 0;
} }
count = e->num_engines; count = e->num_engines;
...@@ -1934,7 +1911,7 @@ get_engines(struct i915_gem_context *ctx, ...@@ -1934,7 +1911,7 @@ get_engines(struct i915_gem_context *ctx,
args->size = size; args->size = size;
err_free: err_free:
free_engines(e); i915_sw_fence_complete(&e->fence);
return err; return err;
} }
......
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