amdgpu: implement new CTX OP to set/get stable pstates
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Fri, 31 Dec 2021 08:10:03 +0000 (09:10 +0100)
committerSamuel Pitoiset <samuel.pitoiset@gmail.com>
Thu, 20 Jan 2022 17:32:46 +0000 (18:32 +0100)
Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
amdgpu/amdgpu-symbols.txt
amdgpu/amdgpu.h
amdgpu/amdgpu_cs.c

index af2b643..d41d9c2 100644 (file)
@@ -25,6 +25,7 @@ amdgpu_cs_ctx_create
 amdgpu_cs_ctx_create2
 amdgpu_cs_ctx_free
 amdgpu_cs_ctx_override_priority
+amdgpu_cs_ctx_stable_pstate
 amdgpu_cs_destroy_semaphore
 amdgpu_cs_destroy_syncobj
 amdgpu_cs_export_syncobj
index cde8585..5ef2524 100644 (file)
@@ -940,6 +940,21 @@ int amdgpu_cs_ctx_override_priority(amdgpu_device_handle dev,
                                     unsigned priority);
 
 /**
+ * Set or query the stable power state for GPU profiling.
+ *
+ * \param   dev        - \c [in] device handle
+ * \param   op         - \c [in] AMDGPU_CTX_OP_{GET,SET}_STABLE_PSTATE
+ * \param   flags      - \c [in] AMDGPU_CTX_STABLE_PSTATE_*
+ * \param   out_flags  - \c [out] output current stable pstate
+ *
+ * \return  0 on success otherwise POSIX Error code.
+ */
+int amdgpu_cs_ctx_stable_pstate(amdgpu_context_handle context,
+                               uint32_t op,
+                               uint32_t flags,
+                               uint32_t *out_flags);
+
+/**
  * Query reset state for the specific GPU Context
  *
  * \param   context - \c [in]  GPU Context handle
index fad484b..638fd7d 100644 (file)
@@ -167,6 +167,28 @@ drm_public int amdgpu_cs_ctx_override_priority(amdgpu_device_handle dev,
        return 0;
 }
 
+drm_public int amdgpu_cs_ctx_stable_pstate(amdgpu_context_handle context,
+                                          uint32_t op,
+                                          uint32_t flags,
+                                          uint32_t *out_flags)
+{
+       union drm_amdgpu_ctx args;
+       int r;
+
+       if (!context)
+               return -EINVAL;
+
+       memset(&args, 0, sizeof(args));
+       args.in.op = op;
+       args.in.ctx_id = context->id;
+       args.in.flags = flags;
+       r = drmCommandWriteRead(context->dev->fd, DRM_AMDGPU_CTX,
+                               &args, sizeof(args));
+       if (!r && out_flags)
+               *out_flags = args.out.pstate.flags;
+       return r;
+}
+
 drm_public int amdgpu_cs_query_reset_state(amdgpu_context_handle context,
                                           uint32_t *state, uint32_t *hangs)
 {