dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: Jason Ekstrand <jason@jlekstrand.net>
To: Daniel Vetter <daniel@ffwll.ch>
Cc: Intel GFX <intel-gfx@lists.freedesktop.org>,
	Maling list - DRI developers <dri-devel@lists.freedesktop.org>
Subject: Re: [Intel-gfx] [PATCH 05/21] drm/i915: Drop the CONTEXT_CLONE API
Date: Wed, 28 Apr 2021 12:38:40 -0500	[thread overview]
Message-ID: <CAOFGe97tFt3=GTr0kJ7fwRmHVy+N9jUfoQ9HwF+U6fytxbAmNA@mail.gmail.com> (raw)
In-Reply-To: <YIfePDDB9Xuit1i+@phenom.ffwll.local>

On Tue, Apr 27, 2021 at 4:49 AM Daniel Vetter <daniel@ffwll.ch> wrote:
>
> On Fri, Apr 23, 2021 at 05:31:15PM -0500, Jason Ekstrand wrote:
> > This API allows one context to grab bits out of another context upon
> > creation.  It can be used as a short-cut for setparam(getparam()) for
> > things like I915_CONTEXT_PARAM_VM.  However, it's never been used by any
> > real userspace.  It's used by a few IGT tests and that's it.  Since it
> > doesn't add any real value (most of the stuff you can CLONE you can copy
> > in other ways), drop it.
> >
> > There is one thing that this API allows you to clone which you cannot
> > clone via getparam/setparam: timelines.  However, timelines are an
> > implementation detail of i915 and not really something that needs to be
> > exposed to userspace.  Also, sharing timelines between contexts isn't
> > obviously useful and supporting it has the potential to complicate i915
> > internally.  It also doesn't add any functionality that the client can't
> > get in other ways.  If a client really wants a shared timeline, they can
> > use a syncobj and set it as an in and out fence on every submit.
> >
> > Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
> > Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
> > ---
> >  drivers/gpu/drm/i915/gem/i915_gem_context.c | 199 +-------------------
> >  include/uapi/drm/i915_drm.h                 |  16 +-
> >  2 files changed, 6 insertions(+), 209 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/i915/gem/i915_gem_context.c b/drivers/gpu/drm/i915/gem/i915_gem_context.c
> > index 8a77855123cec..2c2fefa912805 100644
> > --- a/drivers/gpu/drm/i915/gem/i915_gem_context.c
> > +++ b/drivers/gpu/drm/i915/gem/i915_gem_context.c
> > @@ -1958,207 +1958,14 @@ static int create_setparam(struct i915_user_extension __user *ext, void *data)
> >       return ctx_setparam(arg->fpriv, arg->ctx, &local.param);
> >  }
> >
> > -static int clone_engines(struct i915_gem_context *dst,
> > -                      struct i915_gem_context *src)
> > +static int invalid_ext(struct i915_user_extension __user *ext, void *data)
> >  {
> > -     struct i915_gem_engines *clone, *e;
> > -     bool user_engines;
> > -     unsigned long n;
> > -
> > -     e = __context_engines_await(src, &user_engines);
> > -     if (!e)
> > -             return -ENOENT;
> > -
> > -     clone = alloc_engines(e->num_engines);
> > -     if (!clone)
> > -             goto err_unlock;
> > -
> > -     for (n = 0; n < e->num_engines; n++) {
> > -             struct intel_engine_cs *engine;
> > -
> > -             if (!e->engines[n]) {
> > -                     clone->engines[n] = NULL;
> > -                     continue;
> > -             }
> > -             engine = e->engines[n]->engine;
> > -
> > -             /*
> > -              * Virtual engines are singletons; they can only exist
> > -              * inside a single context, because they embed their
> > -              * HW context... As each virtual context implies a single
> > -              * timeline (each engine can only dequeue a single request
> > -              * at any time), it would be surprising for two contexts
> > -              * to use the same engine. So let's create a copy of
> > -              * the virtual engine instead.
> > -              */
> > -             if (intel_engine_is_virtual(engine))
> > -                     clone->engines[n] =
> > -                             intel_execlists_clone_virtual(engine);
>
> You forgot to gc this function here ^^

Done, with pleasure!

> > -             else
> > -                     clone->engines[n] = intel_context_create(engine);
> > -             if (IS_ERR_OR_NULL(clone->engines[n])) {
> > -                     __free_engines(clone, n);
> > -                     goto err_unlock;
> > -             }
> > -
> > -             intel_context_set_gem(clone->engines[n], dst);
>
> Not peeked ahead, but I'm really hoping intel_context_set_gem gets removed
> eventually too ...

I've not gotten rid of it yet but it's on my list of things to clean
up.  The problem is that there are a pile of parameters we want to set
for user engines which we don't set for internal engines:

 - VM
 - priority
 - hangcheck timeout
 - gem_context back-pointer (I'd love to drop this one!)
 - a bunch more when we start shifting more stuff into intel_context

And there are a bunch of places where we create non-user engines.  The
end result being that we have four ugly options:

 1. Set them after the fact as per intel_context_set_gem
 2. Touch all 79 instances of intel_context_create( for each new
create param we add
 3. Add a new struct intel_context_create_args which contains all the
extra stuff and make NULL mean "use the defaults"
 4. Add a new struct i915_gem_engine which is used for client-visible
engines.  When we switch to an engine-based uAPI, this is probably
what would be exposed to userspace.

I'm happy to hear opinions on which of those is the best option. 2. is
clearly a bad idea.


> > -     }
> > -     clone->num_engines = n;
> > -     i915_sw_fence_complete(&e->fence);
> > -
> > -     /* Serialised by constructor */
> > -     engines_idle_release(dst, rcu_replace_pointer(dst->engines, clone, 1));
> > -     if (user_engines)
> > -             i915_gem_context_set_user_engines(dst);
> > -     else
> > -             i915_gem_context_clear_user_engines(dst);
> > -     return 0;
> > -
> > -err_unlock:
> > -     i915_sw_fence_complete(&e->fence);
> > -     return -ENOMEM;
> > -}
> > -
> > -static int clone_flags(struct i915_gem_context *dst,
> > -                    struct i915_gem_context *src)
> > -{
> > -     dst->user_flags = src->user_flags;
> > -     return 0;
> > -}
> > -
> > -static int clone_schedattr(struct i915_gem_context *dst,
> > -                        struct i915_gem_context *src)
> > -{
> > -     dst->sched = src->sched;
> > -     return 0;
> > -}
> > -
> > -static int clone_sseu(struct i915_gem_context *dst,
> > -                   struct i915_gem_context *src)
> > -{
> > -     struct i915_gem_engines *e = i915_gem_context_lock_engines(src);
> > -     struct i915_gem_engines *clone;
> > -     unsigned long n;
> > -     int err;
> > -
> > -     /* no locking required; sole access under constructor*/
> > -     clone = __context_engines_static(dst);
> > -     if (e->num_engines != clone->num_engines) {
> > -             err = -EINVAL;
> > -             goto unlock;
> > -     }
> > -
> > -     for (n = 0; n < e->num_engines; n++) {
> > -             struct intel_context *ce = e->engines[n];
> > -
> > -             if (clone->engines[n]->engine->class != ce->engine->class) {
> > -                     /* Must have compatible engine maps! */
> > -                     err = -EINVAL;
> > -                     goto unlock;
> > -             }
> > -
> > -             /* serialises with set_sseu */
> > -             err = intel_context_lock_pinned(ce);
> > -             if (err)
> > -                     goto unlock;
> > -
> > -             clone->engines[n]->sseu = ce->sseu;
> > -             intel_context_unlock_pinned(ce);
> > -     }
> > -
> > -     err = 0;
> > -unlock:
> > -     i915_gem_context_unlock_engines(src);
> > -     return err;
> > -}
> > -
> > -static int clone_timeline(struct i915_gem_context *dst,
> > -                       struct i915_gem_context *src)
> > -{
> > -     if (src->timeline)
> > -             __assign_timeline(dst, src->timeline);
> > -
> > -     return 0;
> > -}
> > -
> > -static int clone_vm(struct i915_gem_context *dst,
> > -                 struct i915_gem_context *src)
> > -{
> > -     struct i915_address_space *vm;
> > -     int err = 0;
> > -
> > -     if (!rcu_access_pointer(src->vm))
> > -             return 0;
> > -
> > -     rcu_read_lock();
> > -     vm = context_get_vm_rcu(src);
> > -     rcu_read_unlock();
> > -
> > -     if (!mutex_lock_interruptible(&dst->mutex)) {
> > -             __assign_ppgtt(dst, vm);
> > -             mutex_unlock(&dst->mutex);
> > -     } else {
> > -             err = -EINTR;
> > -     }
> > -
> > -     i915_vm_put(vm);
> > -     return err;
> > -}
> > -
> > -static int create_clone(struct i915_user_extension __user *ext, void *data)
> > -{
> > -     static int (* const fn[])(struct i915_gem_context *dst,
> > -                               struct i915_gem_context *src) = {
> > -#define MAP(x, y) [ilog2(I915_CONTEXT_CLONE_##x)] = y
> > -             MAP(ENGINES, clone_engines),
> > -             MAP(FLAGS, clone_flags),
> > -             MAP(SCHEDATTR, clone_schedattr),
> > -             MAP(SSEU, clone_sseu),
> > -             MAP(TIMELINE, clone_timeline),
> > -             MAP(VM, clone_vm),
> > -#undef MAP
> > -     };
> > -     struct drm_i915_gem_context_create_ext_clone local;
> > -     const struct create_ext *arg = data;
> > -     struct i915_gem_context *dst = arg->ctx;
> > -     struct i915_gem_context *src;
> > -     int err, bit;
> > -
> > -     if (copy_from_user(&local, ext, sizeof(local)))
> > -             return -EFAULT;
> > -
> > -     BUILD_BUG_ON(GENMASK(BITS_PER_TYPE(local.flags) - 1, ARRAY_SIZE(fn)) !=
> > -                  I915_CONTEXT_CLONE_UNKNOWN);
> > -
> > -     if (local.flags & I915_CONTEXT_CLONE_UNKNOWN)
> > -             return -EINVAL;
> > -
> > -     if (local.rsvd)
> > -             return -EINVAL;
> > -
> > -     rcu_read_lock();
> > -     src = __i915_gem_context_lookup_rcu(arg->fpriv, local.clone_id);
> > -     rcu_read_unlock();
> > -     if (!src)
> > -             return -ENOENT;
> > -
> > -     GEM_BUG_ON(src == dst);
> > -
> > -     for (bit = 0; bit < ARRAY_SIZE(fn); bit++) {
> > -             if (!(local.flags & BIT(bit)))
> > -                     continue;
> > -
> > -             err = fn[bit](dst, src);
> > -             if (err)
> > -                     return err;
> > -     }
> > -
> > -     return 0;
> > +     return -EINVAL;
> >  }
> >
> >  static const i915_user_extension_fn create_extensions[] = {
> >       [I915_CONTEXT_CREATE_EXT_SETPARAM] = create_setparam,
> > -     [I915_CONTEXT_CREATE_EXT_CLONE] = create_clone,
> > +     [I915_CONTEXT_CREATE_EXT_CLONE] = invalid_ext,
> >  };
> >
> >  static bool client_is_banned(struct drm_i915_file_private *file_priv)
> > diff --git a/include/uapi/drm/i915_drm.h b/include/uapi/drm/i915_drm.h
> > index a0aaa8298f28d..75a71b6756ed8 100644
> > --- a/include/uapi/drm/i915_drm.h
> > +++ b/include/uapi/drm/i915_drm.h
> > @@ -1887,20 +1887,10 @@ struct drm_i915_gem_context_create_ext_setparam {
> >       struct drm_i915_gem_context_param param;
> >  };
> >
> > -struct drm_i915_gem_context_create_ext_clone {
> > +/* This API has been removed.  On the off chance someone somewhere has
> > + * attempted to use it, never re-use this extension number.
> > + */
> >  #define I915_CONTEXT_CREATE_EXT_CLONE 1
>
> I think we need to put these somewhere else now, here it's just plain
> lost. I think in the kerneldoc for
> drm_i915_gem_context_create_ext_setparam would be best, with the #define
> right above and in the kerneldoc an enumeration of all the values and what
> they're for.

I fully agree it's not great.  But I'm not sure create_ext_setparam
makes sense either.  This is it's own extension that's unrelated to
ext_setparam.

--Jason


> I think I'll need to sign up Matt B or you for doing some kerneldoc polish
> on these so they're all collected together.
> -Daniel
>
> > -     struct i915_user_extension base;
> > -     __u32 clone_id;
> > -     __u32 flags;
> > -#define I915_CONTEXT_CLONE_ENGINES   (1u << 0)
> > -#define I915_CONTEXT_CLONE_FLAGS     (1u << 1)
> > -#define I915_CONTEXT_CLONE_SCHEDATTR (1u << 2)
> > -#define I915_CONTEXT_CLONE_SSEU              (1u << 3)
> > -#define I915_CONTEXT_CLONE_TIMELINE  (1u << 4)
> > -#define I915_CONTEXT_CLONE_VM                (1u << 5)
> > -#define I915_CONTEXT_CLONE_UNKNOWN -(I915_CONTEXT_CLONE_VM << 1)
> > -     __u64 rsvd;
> > -};
> >
> >  struct drm_i915_gem_context_destroy {
> >       __u32 ctx_id;
> > --
> > 2.31.1
> >
> > _______________________________________________
> > Intel-gfx mailing list
> > Intel-gfx@lists.freedesktop.org
> > https://lists.freedesktop.org/mailman/listinfo/intel-gfx
>
> --
> Daniel Vetter
> Software Engineer, Intel Corporation
> http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  reply	other threads:[~2021-04-28 17:38 UTC|newest]

Thread overview: 110+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-23 22:31 [PATCH 00/21] drm/i915/gem: ioctl clean-ups Jason Ekstrand
2021-04-23 22:31 ` [PATCH 01/21] drm/i915: Drop I915_CONTEXT_PARAM_RINGSIZE Jason Ekstrand
2021-04-27  9:32   ` Daniel Vetter
2021-04-28  3:33     ` Jason Ekstrand
2021-04-23 22:31 ` [PATCH 02/21] drm/i915: Drop I915_CONTEXT_PARAM_NO_ZEROMAP Jason Ekstrand
2021-04-27  9:38   ` [Intel-gfx] " Daniel Vetter
2021-04-23 22:31 ` [PATCH 03/21] drm/i915/gem: Set the watchdog timeout directly in intel_context_set_gem Jason Ekstrand
2021-04-27  9:42   ` Daniel Vetter
2021-04-28 15:55   ` [Intel-gfx] " Tvrtko Ursulin
2021-04-28 17:24     ` Jason Ekstrand
2021-04-29  8:04       ` Tvrtko Ursulin
2021-04-29 14:54         ` Jason Ekstrand
2021-04-29 17:12           ` Daniel Vetter
2021-04-29 17:13             ` Daniel Vetter
2021-04-29 18:41               ` Jason Ekstrand
2021-04-30 11:18           ` Tvrtko Ursulin
2021-04-30 15:35             ` Jason Ekstrand
2021-04-23 22:31 ` [PATCH 04/21] drm/i915/gem: Return void from context_apply_all Jason Ekstrand
2021-04-27  9:42   ` Daniel Vetter
2021-04-23 22:31 ` [PATCH 05/21] drm/i915: Drop the CONTEXT_CLONE API Jason Ekstrand
2021-04-27  9:49   ` [Intel-gfx] " Daniel Vetter
2021-04-28 17:38     ` Jason Ekstrand [this message]
2021-04-28 15:59   ` Tvrtko Ursulin
2021-04-23 22:31 ` [PATCH 06/21] drm/i915: Implement SINGLE_TIMELINE with a syncobj (v3) Jason Ekstrand
2021-04-27  9:55   ` [Intel-gfx] " Daniel Vetter
2021-04-28 15:49   ` Tvrtko Ursulin
2021-04-28 17:26     ` Jason Ekstrand
2021-04-29  8:06       ` Tvrtko Ursulin
2021-04-29 12:08         ` Daniel Vetter
2021-04-29 14:47           ` Jason Ekstrand
2021-04-23 22:31 ` [PATCH 07/21] drm/i915: Drop getparam support for I915_CONTEXT_PARAM_ENGINES Jason Ekstrand
2021-04-27  9:58   ` Daniel Vetter
2021-04-23 22:31 ` [PATCH 08/21] drm/i915/gem: Disallow bonding of virtual engines Jason Ekstrand
2021-04-26 23:43   ` [PATCH 08/20] drm/i915/gem: Disallow bonding of virtual engines (v2) Jason Ekstrand
2021-04-27 13:58     ` [Intel-gfx] " Daniel Vetter
2021-04-27 13:51   ` [PATCH 08/21] drm/i915/gem: Disallow bonding of virtual engines Jason Ekstrand
2021-04-28 10:13     ` Daniel Vetter
2021-04-28 17:18       ` Jason Ekstrand
2021-04-28 17:18         ` [Intel-gfx] " Matthew Brost
2021-04-28 17:46           ` Jason Ekstrand
2021-04-28 17:55             ` Matthew Brost
2021-04-28 18:17               ` Jason Ekstrand
2021-04-29 12:14                 ` Daniel Vetter
2021-04-30  4:03                   ` Matthew Brost
2021-04-30 10:11                     ` Daniel Vetter
2021-05-01 17:17                       ` Matthew Brost
2021-05-04  7:36                         ` Daniel Vetter
2021-04-28 18:58         ` Jason Ekstrand
2021-04-29 12:16           ` Daniel Vetter
2021-04-29 16:02             ` Jason Ekstrand
2021-04-29 17:14               ` Daniel Vetter
2021-04-28 15:51   ` [Intel-gfx] " Tvrtko Ursulin
2021-04-29 12:24     ` Daniel Vetter
2021-04-29 12:54       ` Tvrtko Ursulin
2021-04-29 15:41         ` Jason Ekstrand
2021-04-23 22:31 ` [PATCH 09/21] drm/i915/gem: Disallow creating contexts with too many engines Jason Ekstrand
2021-04-28 10:16   ` [Intel-gfx] " Daniel Vetter
2021-04-28 10:42     ` Tvrtko Ursulin
2021-04-28 14:02       ` Daniel Vetter
2021-04-28 14:26         ` Tvrtko Ursulin
2021-04-28 17:09           ` Jason Ekstrand
2021-04-29  8:01             ` Tvrtko Ursulin
2021-04-29 19:16               ` Jason Ekstrand
2021-04-30 11:40                 ` Tvrtko Ursulin
2021-04-30 15:54                   ` Jason Ekstrand
2021-04-23 22:31 ` [PATCH 10/21] drm/i915/request: Remove the hook from await_execution Jason Ekstrand
2021-04-26 23:44   ` Jason Ekstrand
2021-04-23 22:31 ` [PATCH 11/21] drm/i915: Stop manually RCU banging in reset_stats_ioctl Jason Ekstrand
2021-04-28 10:27   ` Daniel Vetter
2021-04-28 18:22     ` Jason Ekstrand
2021-04-29 12:22       ` Daniel Vetter
2021-04-23 22:31 ` [PATCH 12/21] drm/i915/gem: Add a separate validate_priority helper Jason Ekstrand
2021-04-28 14:37   ` Daniel Vetter
2021-04-23 22:31 ` [PATCH 13/21] drm/i915/gem: Add an intermediate proto_context struct Jason Ekstrand
2021-04-29 13:02   ` [Intel-gfx] " Daniel Vetter
2021-04-29 16:44     ` Jason Ekstrand
2021-04-23 22:31 ` [PATCH 14/21] drm/i915/gem: Return an error ptr from context_lookup Jason Ekstrand
2021-04-29 13:27   ` [Intel-gfx] " Daniel Vetter
2021-04-29 15:29     ` Jason Ekstrand
2021-04-29 17:16       ` Daniel Vetter
2021-04-23 22:31 ` [PATCH 15/21] drm/i915/gt: Drop i915_address_space::file Jason Ekstrand
2021-04-29 12:37   ` Daniel Vetter
2021-04-29 15:26     ` Jason Ekstrand
2021-04-23 22:31 ` [PATCH 16/21] drm/i915/gem: Delay context creation Jason Ekstrand
2021-04-24  3:21   ` [Intel-gfx] " kernel test robot
2021-04-24  3:24   ` kernel test robot
2021-04-29 15:51   ` Daniel Vetter
2021-04-29 18:16     ` Jason Ekstrand
2021-04-29 18:56       ` Daniel Vetter
2021-04-29 19:01         ` Jason Ekstrand
2021-04-29 19:07           ` Daniel Vetter
2021-04-29 21:35             ` Jason Ekstrand
2021-04-30  6:53               ` Daniel Vetter
2021-04-30 11:58                 ` Tvrtko Ursulin
2021-04-30 12:30                   ` Daniel Vetter
2021-04-30 12:44                     ` Tvrtko Ursulin
2021-04-30 13:07                       ` Daniel Vetter
2021-04-30 13:15                         ` Tvrtko Ursulin
2021-04-30 16:27                 ` Jason Ekstrand
2021-04-30 16:33                   ` Daniel Vetter
2021-04-30 16:57                     ` Jason Ekstrand
2021-04-30 17:08                       ` Daniel Vetter
2021-04-23 22:31 ` [PATCH 17/21] drm/i915/gem: Don't allow changing the VM on running contexts Jason Ekstrand
2021-04-23 22:31 ` [PATCH 18/21] drm/i915/gem: Don't allow changing the engine set " Jason Ekstrand
2021-04-29 17:21   ` Daniel Vetter
2021-04-23 22:31 ` [PATCH 19/21] drm/i915/selftests: Take a VM in kernel_context() Jason Ekstrand
2021-04-23 22:31 ` [PATCH 20/21] i915/gem/selftests: Assign the VM at context creation in igt_shared_ctx_exec Jason Ekstrand
2021-04-29 17:19   ` [Intel-gfx] " Daniel Vetter
2021-04-23 22:31 ` [PATCH 21/21] drm/i915/gem: Roll all of context creation together Jason Ekstrand
2021-04-29 17:25   ` Daniel Vetter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAOFGe97tFt3=GTr0kJ7fwRmHVy+N9jUfoQ9HwF+U6fytxbAmNA@mail.gmail.com' \
    --to=jason@jlekstrand.net \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).