Skip to contentSkip to conversation

amdgpu: add context creation flags in CS IOCTL

PATCH In review Shashank Sharma 4 participants 6 messages Aug 2, 2022 – Aug 8, 2022 DRM drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 amdgpu: add context creation flags in CS IOCTL

This patch adds:
- A new input parameter "flags" in the amdgpu_ctx_create2 call.
- Some new flags defining workload type hints.
- Some change in the caller function of amdgpu_ctx_create2, to accomodate this new parameter.

The idea is to pass the workload hints while context creation, so that kernel GPU scheduler can pass this information to GPU FW, which in turn can adjust the GPU characterstics as per the workload type.

Cc Alex Deucher <[email protected]>
Cc Marek Olsak <[email protected]>
Cc Christian Koenig <[email protected]>
Cc Amarnath Somalapuram <[email protected]>
---
 amdgpu/amdgpu.h          |  2 ++
 amdgpu/amdgpu_cs.c       |  5 ++++-
 include/drm/amdgpu_drm.h | 10 +++++++++-
 3 files changed, 15 insertions(+), 2 deletions(-)
amdgpu/amdgpu.h +2 -0
index b118dd48..1ebb46e6 100644
@@ -874,6 +874,7 @@ int amdgpu_bo_list_update(amdgpu_bo_list_handle handle,
  *
  * \param   dev      - \c [in] Device handle. See #amdgpu_device_initialize()
  * \param   priority - \c [in] Context creation flags. See AMDGPU_CTX_PRIORITY_*
+ * \param   flags    - \c [in] Context flags. See AMDGPU_CTX_FLAGS_*
  * \param   context  - \c [out] GPU Context handle
  *
  * \return   0 on success\n
@@ -884,6 +885,7 @@ int amdgpu_bo_list_update(amdgpu_bo_list_handle handle,
 */
 int amdgpu_cs_ctx_create2(amdgpu_device_handle dev,
 			 uint32_t priority,
+			 uint32_t flags,
 			 amdgpu_context_handle *context);
 /**
  * Create GPU execution Context
amdgpu/amdgpu_cs.c +4 -1
index fad484bf..d4723ea5 100644
@@ -44,12 +44,14 @@ static int amdgpu_cs_reset_sem(amdgpu_semaphore_handle sem);
  *
  * \param   dev      - \c [in] Device handle. See #amdgpu_device_initialize()
  * \param   priority - \c [in] Context creation flags. See AMDGPU_CTX_PRIORITY_*
+ * \param   flags    - \c [in] Context flags. See AMDGPU_CTX_FLAGS_*
  * \param   context  - \c [out] GPU Context handle
  *
  * \return  0 on success otherwise POSIX Error code
 */
 drm_public int amdgpu_cs_ctx_create2(amdgpu_device_handle dev,
 				     uint32_t priority,
+				     uint32_t flags,
 				     amdgpu_context_handle *context)
 {
 	struct amdgpu_context *gpu_context;
@@ -74,6 +76,7 @@ drm_public int amdgpu_cs_ctx_create2(amdgpu_device_handle dev,
 	memset(&args, 0, sizeof(args));
 	args.in.op = AMDGPU_CTX_OP_ALLOC_CTX;
 	args.in.priority = priority;
+	args.in.flags = flags;
 
 	r = drmCommandWriteRead(dev->fd, DRM_AMDGPU_CTX, &args, sizeof(args));
 	if (r)
@@ -97,7 +100,7 @@ error:
 drm_public int amdgpu_cs_ctx_create(amdgpu_device_handle dev,
 				    amdgpu_context_handle *context)
 {
-	return amdgpu_cs_ctx_create2(dev, AMDGPU_CTX_PRIORITY_NORMAL, context);
+	return amdgpu_cs_ctx_create2(dev, AMDGPU_CTX_PRIORITY_NORMAL, 0, context);
 }
 
 /**
include/drm/amdgpu_drm.h +9 -1
index 0cbd1540..d9fb1f20 100644
@@ -238,10 +238,18 @@ union drm_amdgpu_bo_list {
 #define AMDGPU_CTX_PRIORITY_HIGH        512
 #define AMDGPU_CTX_PRIORITY_VERY_HIGH   1023
 
+/* GPU context workload hint bitmask */
+#define AMDGPU_CTX_FLAGS_WORKLOAD_HINT_MASK    0xFF
+#define AMDGPU_CTX_FLAGS_WORKLOAD_HINT_NONE    0
+#define AMDGPU_CTX_FLAGS_WORKLOAD_HINT_3D      (1 << 1)
+#define AMDGPU_CTX_FLAGS_WORKLOAD_HINT_VIDEO   (1 << 2)
+#define AMDGPU_CTX_FLAGS_WORKLOAD_HINT_VR      (1 << 3)
+#define AMDGPU_CTX_FLAGS_WORKLOAD_HINT_COMPUTE (1 << 4)
+
 struct drm_amdgpu_ctx_in {
 	/** AMDGPU_CTX_OP_* */
 	__u32	op;
-	/** For future use, no flags defined so far */
+	/** AMDGPU_CTX_FLAGS_* */
 	__u32	flags;
 	__u32	ctx_id;
 	/** AMDGPU_CTX_PRIORITY_* */
Signature · 1 line
2.34.1
#1 lore raw
Quoted 15 lines · Shashank Sharma

This patch adds:
- A new input parameter "flags" in the amdgpu_ctx_create2 call.
- Some new flags defining workload type hints.
- Some change in the caller function of amdgpu_ctx_create2, to accomodate this new parameter.

The idea is to pass the workload hints while context creation, so that kernel GPU scheduler can pass this information to GPU FW, which in turn can adjust the GPU characterstics as per the workload type.

Cc Alex Deucher <[email protected]>
Cc Marek Olsak <[email protected]>
Cc Christian Koenig <[email protected]>
Cc Amarnath Somalapuram <[email protected]>
Quoted 4 lines
---
 amdgpu/amdgpu.h          |  2 ++
 amdgpu/amdgpu_cs.c       |  5 ++++-
 include/drm/amdgpu_drm.h | 10 +++++++++-

See include/drm/README on how to handle changes to include/drm/*_drm.h .

Also, libdrm changes are now reviewed and merged as GitLab merge requests: https://gitlab.freedesktop.org/mesa/drm/-/merge_requests

Signature · 2 lines
Earthling Michel Dänzer            |                  https://redhat.com
Libre software enthusiast          |         Mesa and Xwayland developer
#2 lore raw
Quoted 21 lines · Michel Dänzer
Quoted 15 lines · Shashank Sharma

This patch adds:
- A new input parameter "flags" in the amdgpu_ctx_create2 call.
- Some new flags defining workload type hints.
- Some change in the caller function of amdgpu_ctx_create2, to accomodate this new parameter.

The idea is to pass the workload hints while context creation, so that kernel GPU scheduler can pass this information to GPU FW, which in turn can adjust the GPU characterstics as per the workload type.

Cc Alex Deucher <[email protected]>
Cc Marek Olsak <[email protected]>
Cc Christian Koenig <[email protected]>
Cc Amarnath Somalapuram <[email protected]>
Quoted 4 lines
---
  amdgpu/amdgpu.h          |  2 ++
  amdgpu/amdgpu_cs.c       |  5 ++++-
  include/drm/amdgpu_drm.h | 10 +++++++++-
Quoted 6 lines

See include/drm/README on how to handle changes to include/drm/*_drm.h .

Also, libdrm changes are now reviewed and merged as GitLab merge requests: https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgitlab.freedesktop.org%2Fmesa%2Fdrm%2F-%2Fmerge_requests&amp;data=05%7C01%7Cshashank.sharma%40amd.com%7C50e342a42eac4d4d4fd408da749fd574%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637950527087917031%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=qU41z3Hxo0jKMWgehDWLYi7r4x1QDsA%2F2KfOigj9iew%3D&amp;reserved=0

Noted, Thanks.

Regards
Shashank

#3 lore raw
In reply to Shashank Sharma
Quoted 69 lines · Shashank Sharma

This patch adds:
- A new input parameter "flags" in the amdgpu_ctx_create2 call.
- Some new flags defining workload type hints.
- Some change in the caller function of amdgpu_ctx_create2, to accomodate this new parameter.

The idea is to pass the workload hints while context creation, so that kernel GPU scheduler can pass this information to GPU FW, which in turn can adjust the GPU characterstics as per the workload type.

Cc Alex Deucher <[email protected]>
Cc Marek Olsak <[email protected]>
Cc Christian Koenig <[email protected]>
Cc Amarnath Somalapuram <[email protected]>
---
  amdgpu/amdgpu.h          |  2 ++
  amdgpu/amdgpu_cs.c       |  5 ++++-
  include/drm/amdgpu_drm.h | 10 +++++++++-
  3 files changed, 15 insertions(+), 2 deletions(-)
amdgpu/amdgpu.h +2 -0
index b118dd48..1ebb46e6 100644
@@ -874,6 +874,7 @@ int amdgpu_bo_list_update(amdgpu_bo_list_handle handle,
   *
   * \param   dev      - \c [in] Device handle. See #amdgpu_device_initialize()
   * \param   priority - \c [in] Context creation flags. See AMDGPU_CTX_PRIORITY_*
+ * \param   flags    - \c [in] Context flags. See AMDGPU_CTX_FLAGS_*
   * \param   context  - \c [out] GPU Context handle
   *
   * \return   0 on success\n
@@ -884,6 +885,7 @@ int amdgpu_bo_list_update(amdgpu_bo_list_handle handle,
  */
  int amdgpu_cs_ctx_create2(amdgpu_device_handle dev,
  			 uint32_t priority,
+			 uint32_t flags,
  			 amdgpu_context_handle *context);
  /**
   * Create GPU execution Context
amdgpu/amdgpu_cs.c +3 -0
index fad484bf..d4723ea5 100644
@@ -44,12 +44,14 @@ static int amdgpu_cs_reset_sem(amdgpu_semaphore_handle sem);
   *
   * \param   dev      - \c [in] Device handle. See #amdgpu_device_initialize()
   * \param   priority - \c [in] Context creation flags. See AMDGPU_CTX_PRIORITY_*
+ * \param   flags    - \c [in] Context flags. See AMDGPU_CTX_FLAGS_*
   * \param   context  - \c [out] GPU Context handle
   *
   * \return  0 on success otherwise POSIX Error code
  */
  drm_public int amdgpu_cs_ctx_create2(amdgpu_device_handle dev,
  				     uint32_t priority,
+				     uint32_t flags,
  				     amdgpu_context_handle *context)
  {
  	struct amdgpu_context *gpu_context;
@@ -74,6 +76,7 @@ drm_public int amdgpu_cs_ctx_create2(amdgpu_device_handle dev,
  	memset(&args, 0, sizeof(args));
  	args.in.op = AMDGPU_CTX_OP_ALLOC_CTX;
  	args.in.priority = priority;
+	args.in.flags = flags;
 
  	r = drmCommandWriteRead(dev->fd, DRM_AMDGPU_CTX, &args, sizeof(args));
  	if (r)

amdgpu/amdgpu_cs.c error: · line 103

Quoted 5 lines
amdgpu/amdgpu_cs.c +1 -1
@@ -97,7 +100,7 @@ error:
  drm_public int amdgpu_cs_ctx_create(amdgpu_device_handle dev,
  				    amdgpu_context_handle *context)
  {
-	return amdgpu_cs_ctx_create2(dev, AMDGPU_CTX_PRIORITY_NORMAL, context);
+	return amdgpu_cs_ctx_create2(dev, AMDGPU_CTX_PRIORITY_NORMAL, 0, context);

How do we set workload hint from application, amdgpu_cs_ctx_create show have flag ?

Regards,
S.Amarnath

Quoted 27 lines
amdgpu/amdgpu_cs.c +0 -0
  }
 
  /**
include/drm/amdgpu_drm.h +9 -1
index 0cbd1540..d9fb1f20 100644
@@ -238,10 +238,18 @@ union drm_amdgpu_bo_list {
  #define AMDGPU_CTX_PRIORITY_HIGH        512
  #define AMDGPU_CTX_PRIORITY_VERY_HIGH   1023
 
+/* GPU context workload hint bitmask */
+#define AMDGPU_CTX_FLAGS_WORKLOAD_HINT_MASK    0xFF
+#define AMDGPU_CTX_FLAGS_WORKLOAD_HINT_NONE    0
+#define AMDGPU_CTX_FLAGS_WORKLOAD_HINT_3D      (1 << 1)
+#define AMDGPU_CTX_FLAGS_WORKLOAD_HINT_VIDEO   (1 << 2)
+#define AMDGPU_CTX_FLAGS_WORKLOAD_HINT_VR      (1 << 3)
+#define AMDGPU_CTX_FLAGS_WORKLOAD_HINT_COMPUTE (1 << 4)
+
  struct drm_amdgpu_ctx_in {
  	/** AMDGPU_CTX_OP_* */
  	__u32	op;
-	/** For future use, no flags defined so far */
+	/** AMDGPU_CTX_FLAGS_* */
  	__u32	flags;
  	__u32	ctx_id;
  	/** AMDGPU_CTX_PRIORITY_* */
#4 lore raw
In reply to Shashank Sharma

Am 02.08.22 um 15:55 schrieb Shashank Sharma:

Quoted 7 lines

This patch adds:
- A new input parameter "flags" in the amdgpu_ctx_create2 call.
- Some new flags defining workload type hints.
- Some change in the caller function of amdgpu_ctx_create2, to accomodate this new parameter.

The idea is to pass the workload hints while context creation,

Bad idea.

Please take AMDGPU_CTX_OP_SET_STABLE_PSTATE and AMDGPU_CTX_OP_GET_STABLE_PSTATE as blueprint for this and don't add extra flags to the context creation.

Regards,
Christian.

Quoted 95 lines

so
that kernel GPU scheduler can pass this information to GPU FW, which in turn can adjust the GPU characterstics as per the workload type.

Cc Alex Deucher <[email protected]>
Cc Marek Olsak <[email protected]>
Cc Christian Koenig <[email protected]>
Cc Amarnath Somalapuram <[email protected]>
---
  amdgpu/amdgpu.h          |  2 ++
  amdgpu/amdgpu_cs.c       |  5 ++++-
  include/drm/amdgpu_drm.h | 10 +++++++++-
  3 files changed, 15 insertions(+), 2 deletions(-)
amdgpu/amdgpu.h +2 -0
index b118dd48..1ebb46e6 100644
@@ -874,6 +874,7 @@ int amdgpu_bo_list_update(amdgpu_bo_list_handle handle,
   *
   * \param   dev      - \c [in] Device handle. See #amdgpu_device_initialize()
   * \param   priority - \c [in] Context creation flags. See AMDGPU_CTX_PRIORITY_*
+ * \param   flags    - \c [in] Context flags. See AMDGPU_CTX_FLAGS_*
   * \param   context  - \c [out] GPU Context handle
   *
   * \return   0 on success\n
@@ -884,6 +885,7 @@ int amdgpu_bo_list_update(amdgpu_bo_list_handle handle,
  */
  int amdgpu_cs_ctx_create2(amdgpu_device_handle dev,
  			 uint32_t priority,
+			 uint32_t flags,
  			 amdgpu_context_handle *context);
  /**
   * Create GPU execution Context
amdgpu/amdgpu_cs.c +4 -1
index fad484bf..d4723ea5 100644
@@ -44,12 +44,14 @@ static int amdgpu_cs_reset_sem(amdgpu_semaphore_handle sem);
   *
   * \param   dev      - \c [in] Device handle. See #amdgpu_device_initialize()
   * \param   priority - \c [in] Context creation flags. See AMDGPU_CTX_PRIORITY_*
+ * \param   flags    - \c [in] Context flags. See AMDGPU_CTX_FLAGS_*
   * \param   context  - \c [out] GPU Context handle
   *
   * \return  0 on success otherwise POSIX Error code
  */
  drm_public int amdgpu_cs_ctx_create2(amdgpu_device_handle dev,
  				     uint32_t priority,
+				     uint32_t flags,
  				     amdgpu_context_handle *context)
  {
  	struct amdgpu_context *gpu_context;
@@ -74,6 +76,7 @@ drm_public int amdgpu_cs_ctx_create2(amdgpu_device_handle dev,
  	memset(&args, 0, sizeof(args));
  	args.in.op = AMDGPU_CTX_OP_ALLOC_CTX;
  	args.in.priority = priority;
+	args.in.flags = flags;
 
  	r = drmCommandWriteRead(dev->fd, DRM_AMDGPU_CTX, &args, sizeof(args));
  	if (r)
@@ -97,7 +100,7 @@ error:
  drm_public int amdgpu_cs_ctx_create(amdgpu_device_handle dev,
  				    amdgpu_context_handle *context)
  {
-	return amdgpu_cs_ctx_create2(dev, AMDGPU_CTX_PRIORITY_NORMAL, context);
+	return amdgpu_cs_ctx_create2(dev, AMDGPU_CTX_PRIORITY_NORMAL, 0, context);
  }
 
  /**
include/drm/amdgpu_drm.h +9 -1
index 0cbd1540..d9fb1f20 100644
@@ -238,10 +238,18 @@ union drm_amdgpu_bo_list {
  #define AMDGPU_CTX_PRIORITY_HIGH        512
  #define AMDGPU_CTX_PRIORITY_VERY_HIGH   1023
 
+/* GPU context workload hint bitmask */
+#define AMDGPU_CTX_FLAGS_WORKLOAD_HINT_MASK    0xFF
+#define AMDGPU_CTX_FLAGS_WORKLOAD_HINT_NONE    0
+#define AMDGPU_CTX_FLAGS_WORKLOAD_HINT_3D      (1 << 1)
+#define AMDGPU_CTX_FLAGS_WORKLOAD_HINT_VIDEO   (1 << 2)
+#define AMDGPU_CTX_FLAGS_WORKLOAD_HINT_VR      (1 << 3)
+#define AMDGPU_CTX_FLAGS_WORKLOAD_HINT_COMPUTE (1 << 4)
+
  struct drm_amdgpu_ctx_in {
  	/** AMDGPU_CTX_OP_* */
  	__u32	op;
-	/** For future use, no flags defined so far */
+	/** AMDGPU_CTX_FLAGS_* */
  	__u32	flags;
  	__u32	ctx_id;
  	/** AMDGPU_CTX_PRIORITY_* */
#5 lore raw
Quoted 7 lines · Christian König

Am 02.08.22 um 15:55 schrieb Shashank Sharma:

Quoted 6 lines

This patch adds:
- A new input parameter "flags" in the amdgpu_ctx_create2 call.
- Some new flags defining workload type hints.
- Some change in the caller function of amdgpu_ctx_create2, to accomodate this new parameter.

Quoted 8 lines
Quoted 1 line

The idea is to pass the workload hints while context creation,

Bad idea.

Please take AMDGPU_CTX_OP_SET_STABLE_PSTATE and AMDGPU_CTX_OP_GET_STABLE_PSTATE as blueprint for this and don't add extra flags to the context creation.

Regards,
Christian.

Hey Christian,
Noted, let me have a look at AMDGPU_CTX_OP_GET/SET_STABLE_PSTATE implementation.

- Shashank

Quoted 101 lines
Quoted 100 lines

  so
that kernel GPU scheduler can pass this information to GPU FW, which in turn can adjust the GPU characterstics as per the workload type.

Cc Alex Deucher <[email protected]>
Cc Marek Olsak <[email protected]>
Cc Christian Koenig <[email protected]>
Cc Amarnath Somalapuram <[email protected]>

---
  amdgpu/amdgpu.h          |  2 ++
  amdgpu/amdgpu_cs.c       |  5 ++++-
  include/drm/amdgpu_drm.h | 10 +++++++++-

  3 files changed, 15 insertions(+), 2 deletions(-)
amdgpu/amdgpu.h +1 -0
index b118dd48..1ebb46e6 100644
@@ -874,6 +874,7 @@ int amdgpu_bo_list_update(amdgpu_bo_list_handle 
 handle,
    *
    * \param   dev      - \c [in] Device handle. See #amdgpu_device_initialize()
    * \param   priority - \c [in] Context creation flags. See AMDGPU_CTX_PRIORITY_*
+ * \param   flags    - \c [in] Context flags. See AMDGPU_CTX_FLAGS_*
    * \param   context  - \c [out] GPU Context handle
    *

   * \return   0 on success\n

amdgpu/amdgpu.h +1 -0
@@ -884,6 +885,7 @@ int amdgpu_bo_list_update(amdgpu_bo_list_handle 
 handle,
   */
   int amdgpu_cs_ctx_create2(amdgpu_device_handle dev,
                uint32_t priority,
+             uint32_t flags,
                amdgpu_context_handle *context);
   /**

   * Create GPU execution Context

amdgpu/amdgpu_cs.c +2 -0
index fad484bf..d4723ea5 100644
@@ -44,12 +44,14 @@ static int 
 amdgpu_cs_reset_sem(amdgpu_semaphore_handle sem);
    *
    * \param   dev      - \c [in] Device handle. See #amdgpu_device_initialize()
    * \param   priority - \c [in] Context creation flags. See AMDGPU_CTX_PRIORITY_*
+ * \param   flags    - \c [in] Context flags. See AMDGPU_CTX_FLAGS_*
    * \param   context  - \c [out] GPU Context handle
    *
    * \return  0 on success otherwise POSIX Error code
   */
   drm_public int amdgpu_cs_ctx_create2(amdgpu_device_handle dev,
                        uint32_t priority,
+                     uint32_t flags,
                        amdgpu_context_handle *context)
   {

      struct amdgpu_context *gpu_context;

amdgpu/amdgpu_cs.c +2 -1
@@ -74,6 +76,7 @@ drm_public int 
 amdgpu_cs_ctx_create2(amdgpu_device_handle dev,
       memset(&args, 0, sizeof(args));
       args.in.op = AMDGPU_CTX_OP_ALLOC_CTX;
       args.in.priority = priority;
+    args.in.flags = flags;
       r = drmCommandWriteRead(dev->fd, DRM_AMDGPU_CTX, &args, sizeof(args));
       if (r)
@@ -97,7 +100,7 @@ error:
   drm_public int amdgpu_cs_ctx_create(amdgpu_device_handle dev,
                       amdgpu_context_handle *context)
   {
-    return amdgpu_cs_ctx_create2(dev, AMDGPU_CTX_PRIORITY_NORMAL, 
 context);
+    return amdgpu_cs_ctx_create2(dev, AMDGPU_CTX_PRIORITY_NORMAL, 0, 
 context);
   }

  /**

include/drm/amdgpu_drm.h +9 -1
index 0cbd1540..d9fb1f20 100644
@@ -238,10 +238,18 @@ union drm_amdgpu_bo_list {
   #define AMDGPU_CTX_PRIORITY_HIGH        512
   #define AMDGPU_CTX_PRIORITY_VERY_HIGH   1023
+/* GPU context workload hint bitmask */
+#define AMDGPU_CTX_FLAGS_WORKLOAD_HINT_MASK    0xFF
+#define AMDGPU_CTX_FLAGS_WORKLOAD_HINT_NONE    0
+#define AMDGPU_CTX_FLAGS_WORKLOAD_HINT_3D      (1 << 1)
+#define AMDGPU_CTX_FLAGS_WORKLOAD_HINT_VIDEO   (1 << 2)
+#define AMDGPU_CTX_FLAGS_WORKLOAD_HINT_VR      (1 << 3)
+#define AMDGPU_CTX_FLAGS_WORKLOAD_HINT_COMPUTE (1 << 4)
+
   struct drm_amdgpu_ctx_in {
       /** AMDGPU_CTX_OP_* */
       __u32    op;
-    /** For future use, no flags defined so far */
+    /** AMDGPU_CTX_FLAGS_* */
       __u32    flags;
       __u32    ctx_id;
       /** AMDGPU_CTX_PRIORITY_* */