Message ID | 20190417183338.23437-1-bas@basnieuwenhuizen.nl (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [libdrm] amdgpu: Add context priority override function. | expand |
Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com> On 4/17/19 8:33 PM, Bas Nieuwenhuizen wrote: > This way we can override the priority of a single context using a > master fd. > > Since we cannot usefully create an amdgpu device of a master fd > without the fd deduplication kicking in this takes a plain fd. > > This can be used by e.g. radv to get high priority contexts using > a master fd from the primary node or a lease. > --- > amdgpu/amdgpu-symbol-check | 1 + > amdgpu/amdgpu.h | 15 +++++++++++++++ > amdgpu/amdgpu_cs.c | 25 +++++++++++++++++++++++++ > 3 files changed, 41 insertions(+) > > diff --git a/amdgpu/amdgpu-symbol-check b/amdgpu/amdgpu-symbol-check > index 96a44b40..4d806922 100755 > --- a/amdgpu/amdgpu-symbol-check > +++ b/amdgpu/amdgpu-symbol-check > @@ -38,6 +38,7 @@ amdgpu_cs_create_syncobj2 > amdgpu_cs_ctx_create > amdgpu_cs_ctx_create2 > amdgpu_cs_ctx_free > +amdgpu_cs_ctx_override_priority > amdgpu_cs_destroy_semaphore > amdgpu_cs_destroy_syncobj > amdgpu_cs_export_syncobj > diff --git a/amdgpu/amdgpu.h b/amdgpu/amdgpu.h > index d6de3b8d..3d838e08 100644 > --- a/amdgpu/amdgpu.h > +++ b/amdgpu/amdgpu.h > @@ -911,6 +911,21 @@ int amdgpu_cs_ctx_create(amdgpu_device_handle dev, > */ > int amdgpu_cs_ctx_free(amdgpu_context_handle context); > > +/** > + * Override the submission priority for the given context using a master fd. > + * > + * \param dev - \c [in] device handle > + * \param context - \c [in] context handle for context id > + * \param master_fd - \c [in] The master fd to authorize the override. > + * \param priority - \c [in] The priority to assign to the context. > + * > + * \return 0 on success or a a negative Posix error code on failure. > + */ > +int amdgpu_cs_ctx_override_priority(amdgpu_device_handle dev, > + amdgpu_context_handle context, > + int master_fd, > + unsigned priority); > + > /** > * Query reset state for the specific GPU Context > * > diff --git a/amdgpu/amdgpu_cs.c b/amdgpu/amdgpu_cs.c > index 5bedf748..7ee844fb 100644 > --- a/amdgpu/amdgpu_cs.c > +++ b/amdgpu/amdgpu_cs.c > @@ -142,6 +142,31 @@ drm_public int amdgpu_cs_ctx_free(amdgpu_context_handle context) > return r; > } > > +drm_public int amdgpu_cs_ctx_override_priority(amdgpu_device_handle dev, > + amdgpu_context_handle context, > + int master_fd, > + unsigned priority) > +{ > + int r; > + > + if (!dev || !context || master_fd < 0) > + return -EINVAL; > + > + union drm_amdgpu_sched args; > + memset(&args, 0, sizeof(args)); > + > + args.in.op = AMDGPU_SCHED_OP_CONTEXT_PRIORITY_OVERRIDE; > + args.in.fd = dev->fd; > + args.in.priority = priority; > + args.in.ctx_id = context->id; > + > + r = drmCommandWrite(master_fd, DRM_AMDGPU_SCHED, &args, sizeof(args)); > + if (r) > + return r; > + > + return 0; > +} > + > drm_public int amdgpu_cs_query_reset_state(amdgpu_context_handle context, > uint32_t *state, uint32_t *hangs) > {
On 2019-04-17 2:33 p.m., Bas Nieuwenhuizen wrote: > This way we can override the priority of a single context using a > master fd. > > Since we cannot usefully create an amdgpu device of a master fd > without the fd deduplication kicking in this takes a plain fd. > > This can be used by e.g. radv to get high priority contexts using > a master fd from the primary node or a lease > --- > amdgpu/amdgpu-symbol-check | 1 + > amdgpu/amdgpu.h | 15 +++++++++++++++ > amdgpu/amdgpu_cs.c | 25 +++++++++++++++++++++++++ > 3 files changed, 41 insertions(+) > > diff --git a/amdgpu/amdgpu-symbol-check b/amdgpu/amdgpu-symbol-check > index 96a44b40..4d806922 100755 > --- a/amdgpu/amdgpu-symbol-check > +++ b/amdgpu/amdgpu-symbol-check > @@ -38,6 +38,7 @@ amdgpu_cs_create_syncobj2 > amdgpu_cs_ctx_create > amdgpu_cs_ctx_create2 > amdgpu_cs_ctx_free > +amdgpu_cs_ctx_override_priority > amdgpu_cs_destroy_semaphore > amdgpu_cs_destroy_syncobj > amdgpu_cs_export_syncobj > diff --git a/amdgpu/amdgpu.h b/amdgpu/amdgpu.h > index d6de3b8d..3d838e08 100644 > --- a/amdgpu/amdgpu.h > +++ b/amdgpu/amdgpu.h > @@ -911,6 +911,21 @@ int amdgpu_cs_ctx_create(amdgpu_device_handle dev, > */ > int amdgpu_cs_ctx_free(amdgpu_context_handle context); > > +/** > + * Override the submission priority for the given context using a master fd. > + * > + * \param dev - \c [in] device handle Minor indentation misalignment here. > + * \param context - \c [in] context handle for context id > + * \param master_fd - \c [in] The master fd to authorize the override. > + * \param priority - \c [in] The priority to assign to the context. > + * > + * \return 0 on success or a a negative Posix error code on failure. > + */ > +int amdgpu_cs_ctx_override_priority(amdgpu_device_handle dev, > + amdgpu_context_handle context, > + int master_fd, > + unsigned priority); > + > /** > * Query reset state for the specific GPU Context > * > diff --git a/amdgpu/amdgpu_cs.c b/amdgpu/amdgpu_cs.c > index 5bedf748..7ee844fb 100644 > --- a/amdgpu/amdgpu_cs.c > +++ b/amdgpu/amdgpu_cs.c > @@ -142,6 +142,31 @@ drm_public int amdgpu_cs_ctx_free(amdgpu_context_handle context) > return r; > } > > +drm_public int amdgpu_cs_ctx_override_priority(amdgpu_device_handle dev, > + amdgpu_context_handle context, > + int master_fd, > + unsigned priority) > +{ > + int r; > + > + if (!dev || !context || master_fd < 0) > + return -EINVAL; > + > + union drm_amdgpu_sched args; > + memset(&args, 0, sizeof(args)); > + > + args.in.op = AMDGPU_SCHED_OP_CONTEXT_PRIORITY_OVERRIDE; > + args.in.fd = dev->fd; > + args.in.priority = priority; > + args.in.ctx_id = context->id; > + > + r = drmCommandWrite(master_fd, DRM_AMDGPU_SCHED, &args, sizeof(args)); I'm assuming there is no other initialization required before this command can be executed on the master_fd. If so, this changed is: Reviewed-by: Andres Rodriguez <andresx7@gmail.com> > + if (r) > + return r; > + > + return 0; > +} > + > drm_public int amdgpu_cs_query_reset_state(amdgpu_context_handle context, > uint32_t *state, uint32_t *hangs) > { >
On Wed, Apr 17, 2019 at 9:21 PM Andres Rodriguez <andresx7@gmail.com> wrote: > > > > On 2019-04-17 2:33 p.m., Bas Nieuwenhuizen wrote: > > This way we can override the priority of a single context using a > > master fd. > > > > Since we cannot usefully create an amdgpu device of a master fd > > without the fd deduplication kicking in this takes a plain fd. > > > > This can be used by e.g. radv to get high priority contexts using > > a master fd from the primary node or a lease > > --- > > amdgpu/amdgpu-symbol-check | 1 + > > amdgpu/amdgpu.h | 15 +++++++++++++++ > > amdgpu/amdgpu_cs.c | 25 +++++++++++++++++++++++++ > > 3 files changed, 41 insertions(+) > > > > diff --git a/amdgpu/amdgpu-symbol-check b/amdgpu/amdgpu-symbol-check > > index 96a44b40..4d806922 100755 > > --- a/amdgpu/amdgpu-symbol-check > > +++ b/amdgpu/amdgpu-symbol-check > > @@ -38,6 +38,7 @@ amdgpu_cs_create_syncobj2 > > amdgpu_cs_ctx_create > > amdgpu_cs_ctx_create2 > > amdgpu_cs_ctx_free > > +amdgpu_cs_ctx_override_priority > > amdgpu_cs_destroy_semaphore > > amdgpu_cs_destroy_syncobj > > amdgpu_cs_export_syncobj > > diff --git a/amdgpu/amdgpu.h b/amdgpu/amdgpu.h > > index d6de3b8d..3d838e08 100644 > > --- a/amdgpu/amdgpu.h > > +++ b/amdgpu/amdgpu.h > > @@ -911,6 +911,21 @@ int amdgpu_cs_ctx_create(amdgpu_device_handle dev, > > */ > > int amdgpu_cs_ctx_free(amdgpu_context_handle context); > > > > +/** > > + * Override the submission priority for the given context using a master fd. > > + * > > + * \param dev - \c [in] device handle > > Minor indentation misalignment here. Fixed locally. > > > + * \param context - \c [in] context handle for context id > > + * \param master_fd - \c [in] The master fd to authorize the override. > > + * \param priority - \c [in] The priority to assign to the context. > > + * > > + * \return 0 on success or a a negative Posix error code on failure. > > + */ > > +int amdgpu_cs_ctx_override_priority(amdgpu_device_handle dev, > > + amdgpu_context_handle context, > > + int master_fd, > > + unsigned priority); > > + > > /** > > * Query reset state for the specific GPU Context > > * > > diff --git a/amdgpu/amdgpu_cs.c b/amdgpu/amdgpu_cs.c > > index 5bedf748..7ee844fb 100644 > > --- a/amdgpu/amdgpu_cs.c > > +++ b/amdgpu/amdgpu_cs.c > > @@ -142,6 +142,31 @@ drm_public int amdgpu_cs_ctx_free(amdgpu_context_handle context) > > return r; > > } > > > > +drm_public int amdgpu_cs_ctx_override_priority(amdgpu_device_handle dev, > > + amdgpu_context_handle context, > > + int master_fd, > > + unsigned priority) > > +{ > > + int r; > > + > > + if (!dev || !context || master_fd < 0) > > + return -EINVAL; > > + > > + union drm_amdgpu_sched args; > > + memset(&args, 0, sizeof(args)); > > + > > + args.in.op = AMDGPU_SCHED_OP_CONTEXT_PRIORITY_OVERRIDE; > > + args.in.fd = dev->fd; > > + args.in.priority = priority; > > + args.in.ctx_id = context->id; > > + > > + r = drmCommandWrite(master_fd, DRM_AMDGPU_SCHED, &args, sizeof(args)); > > I'm assuming there is no other initialization required before this > command can be executed on the master_fd. Correct. The two limitations are (1) master_fd should be an amdgpu fd (as we call the ioctl on master fd) and (2) master_fd should be allowed to do ioctls guarded with DRM_MASTER. Neither requires any extra initialization. > > If so, this changed is: > Reviewed-by: Andres Rodriguez <andresx7@gmail.com> Thanks! > > > > + if (r) > > + return r; > > + > > + return 0; > > +} > > + > > drm_public int amdgpu_cs_query_reset_state(amdgpu_context_handle context, > > uint32_t *state, uint32_t *hangs) > > { > >
Reviewed-by: Chunming Zhou <david1.zhou@amd.com> > -----Original Message----- > From: dri-devel <dri-devel-bounces@lists.freedesktop.org> On Behalf Of Bas > Nieuwenhuizen > Sent: Thursday, April 18, 2019 2:34 AM > To: dri-devel@lists.freedesktop.org > Subject: [PATCH libdrm] amdgpu: Add context priority override function. > > This way we can override the priority of a single context using a master fd. > > Since we cannot usefully create an amdgpu device of a master fd without the > fd deduplication kicking in this takes a plain fd. > > This can be used by e.g. radv to get high priority contexts using a master fd > from the primary node or a lease. > --- > amdgpu/amdgpu-symbol-check | 1 + > amdgpu/amdgpu.h | 15 +++++++++++++++ > amdgpu/amdgpu_cs.c | 25 +++++++++++++++++++++++++ > 3 files changed, 41 insertions(+) > > diff --git a/amdgpu/amdgpu-symbol-check b/amdgpu/amdgpu-symbol- > check index 96a44b40..4d806922 100755 > --- a/amdgpu/amdgpu-symbol-check > +++ b/amdgpu/amdgpu-symbol-check > @@ -38,6 +38,7 @@ amdgpu_cs_create_syncobj2 amdgpu_cs_ctx_create > amdgpu_cs_ctx_create2 > amdgpu_cs_ctx_free > +amdgpu_cs_ctx_override_priority > amdgpu_cs_destroy_semaphore > amdgpu_cs_destroy_syncobj > amdgpu_cs_export_syncobj > diff --git a/amdgpu/amdgpu.h b/amdgpu/amdgpu.h index > d6de3b8d..3d838e08 100644 > --- a/amdgpu/amdgpu.h > +++ b/amdgpu/amdgpu.h > @@ -911,6 +911,21 @@ int amdgpu_cs_ctx_create(amdgpu_device_handle > dev, */ int amdgpu_cs_ctx_free(amdgpu_context_handle context); > > +/** > + * Override the submission priority for the given context using a master fd. > + * > + * \param dev - \c [in] device handle > + * \param context - \c [in] context handle for context id > + * \param master_fd - \c [in] The master fd to authorize the override. > + * \param priority - \c [in] The priority to assign to the context. > + * > + * \return 0 on success or a a negative Posix error code on failure. > + */ > +int amdgpu_cs_ctx_override_priority(amdgpu_device_handle dev, > + amdgpu_context_handle context, > + int master_fd, > + unsigned priority); > + > /** > * Query reset state for the specific GPU Context > * > diff --git a/amdgpu/amdgpu_cs.c b/amdgpu/amdgpu_cs.c index > 5bedf748..7ee844fb 100644 > --- a/amdgpu/amdgpu_cs.c > +++ b/amdgpu/amdgpu_cs.c > @@ -142,6 +142,31 @@ drm_public int > amdgpu_cs_ctx_free(amdgpu_context_handle context) > return r; > } > > +drm_public int amdgpu_cs_ctx_override_priority(amdgpu_device_handle > dev, > + amdgpu_context_handle context, > + int master_fd, > + unsigned priority) { > + int r; > + > + if (!dev || !context || master_fd < 0) > + return -EINVAL; > + > + union drm_amdgpu_sched args; > + memset(&args, 0, sizeof(args)); > + > + args.in.op = AMDGPU_SCHED_OP_CONTEXT_PRIORITY_OVERRIDE; > + args.in.fd = dev->fd; > + args.in.priority = priority; > + args.in.ctx_id = context->id; > + > + r = drmCommandWrite(master_fd, DRM_AMDGPU_SCHED, &args, > sizeof(args)); > + if (r) > + return r; > + > + return 0; > +} > + > drm_public int amdgpu_cs_query_reset_state(amdgpu_context_handle > context, > uint32_t *state, uint32_t *hangs) { > -- > 2.21.0 > > _______________________________________________ > dri-devel mailing list > dri-devel@lists.freedesktop.org > https://lists.freedesktop.org/mailman/listinfo/dri-devel
diff --git a/amdgpu/amdgpu-symbol-check b/amdgpu/amdgpu-symbol-check index 96a44b40..4d806922 100755 --- a/amdgpu/amdgpu-symbol-check +++ b/amdgpu/amdgpu-symbol-check @@ -38,6 +38,7 @@ amdgpu_cs_create_syncobj2 amdgpu_cs_ctx_create amdgpu_cs_ctx_create2 amdgpu_cs_ctx_free +amdgpu_cs_ctx_override_priority amdgpu_cs_destroy_semaphore amdgpu_cs_destroy_syncobj amdgpu_cs_export_syncobj diff --git a/amdgpu/amdgpu.h b/amdgpu/amdgpu.h index d6de3b8d..3d838e08 100644 --- a/amdgpu/amdgpu.h +++ b/amdgpu/amdgpu.h @@ -911,6 +911,21 @@ int amdgpu_cs_ctx_create(amdgpu_device_handle dev, */ int amdgpu_cs_ctx_free(amdgpu_context_handle context); +/** + * Override the submission priority for the given context using a master fd. + * + * \param dev - \c [in] device handle + * \param context - \c [in] context handle for context id + * \param master_fd - \c [in] The master fd to authorize the override. + * \param priority - \c [in] The priority to assign to the context. + * + * \return 0 on success or a a negative Posix error code on failure. + */ +int amdgpu_cs_ctx_override_priority(amdgpu_device_handle dev, + amdgpu_context_handle context, + int master_fd, + unsigned priority); + /** * Query reset state for the specific GPU Context * diff --git a/amdgpu/amdgpu_cs.c b/amdgpu/amdgpu_cs.c index 5bedf748..7ee844fb 100644 --- a/amdgpu/amdgpu_cs.c +++ b/amdgpu/amdgpu_cs.c @@ -142,6 +142,31 @@ drm_public int amdgpu_cs_ctx_free(amdgpu_context_handle context) return r; } +drm_public int amdgpu_cs_ctx_override_priority(amdgpu_device_handle dev, + amdgpu_context_handle context, + int master_fd, + unsigned priority) +{ + int r; + + if (!dev || !context || master_fd < 0) + return -EINVAL; + + union drm_amdgpu_sched args; + memset(&args, 0, sizeof(args)); + + args.in.op = AMDGPU_SCHED_OP_CONTEXT_PRIORITY_OVERRIDE; + args.in.fd = dev->fd; + args.in.priority = priority; + args.in.ctx_id = context->id; + + r = drmCommandWrite(master_fd, DRM_AMDGPU_SCHED, &args, sizeof(args)); + if (r) + return r; + + return 0; +} + drm_public int amdgpu_cs_query_reset_state(amdgpu_context_handle context, uint32_t *state, uint32_t *hangs) {