[PATCH libdrm 2/2] amdgpu: change proirity value to be consistent with kernel

Zhenneng Li lizhenneng at kylinos.cn
Mon Jan 8 09:40:52 UTC 2024


In libdrm-amdgpu and amdgpu kernel driver, there are only such priority level:

AMDGPU_CTX_PRIORITY_VERY_LOW,
AMDGPU_CTX_PRIORITY_LOW,
AMDGPU_CTX_PRIORITY_NORMAL,
AMDGPU_CTX_PRIORITY_HIGH,
AMDGPU_CTX_PRIORITY_VERY_HIGH

If priority value is not the one of the above data, the kernel will treat it as invalid.
If you set prority to HIGH or VERY_HIGH, please make sure the process have CAP_SYS_NICE
capability or DRM_MASTER permission.

Signed-off-by: Zhenneng Li <lizhenneng at kylinos.cn>
---
 amdgpu/amdgpu_cs.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/amdgpu/amdgpu_cs.c b/amdgpu/amdgpu_cs.c
index eb72c638..d6d768ba 100644
--- a/amdgpu/amdgpu_cs.c
+++ b/amdgpu/amdgpu_cs.c
@@ -57,6 +57,7 @@ drm_public int amdgpu_cs_ctx_create2(amdgpu_device_handle dev,
 	int i, j, k;
 	int r;
 	char *override_priority;
+	int32_t override_prio;
 
 	if (!dev || !context)
 		return -EINVAL;
@@ -66,9 +67,16 @@ drm_public int amdgpu_cs_ctx_create2(amdgpu_device_handle dev,
 		/* The priority is a signed integer. The variable type is
 		 * wrong. If parsing fails, priority is unchanged.
 		 */
-		if (sscanf(override_priority, "%i", &priority) == 1) {
+		if (sscanf(override_priority, "%i", &override_prio) == 1) {
 			printf("amdgpu: context priority changed to %i\n",
-			       priority);
+			       override_prio);
+			if (override_prio == 0) {
+				priority = AMDGPU_CTX_PRIORITY_NORMAL;
+			} else if (override_prio < 0) {
+				priority = AMDGPU_CTX_PRIORITY_HIGH;
+			} else {
+				priority = AMDGPU_CTX_PRIORITY_LOW;
+			}
 		}
 	}
 
-- 
2.34.1



More information about the amd-gfx mailing list