Skip to contentSkip to conversation

Fixes to drm_sched_priority (v2)

PATCH In review Luben Tuikov 2 participants 5 messages Aug 15, 2020 – Aug 17, 2020

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover Fixes to drm_sched_priority (v2)

Some fixes to enum drm_sched_priority which I'd wanted to do since last year.

For instance, renaming MAX to COUNT, as usually a maximum value is a value which is part of the set of values, (e.g. a maxima of a function), and thus assignable, whereby a count is the size of a set (the enumeration in this case). It also makes it clearer when used to define size of arrays.

Removing some redundant naming and perhaps better naming could be had for PRIORITY_SW and PRIORITY_HW, maybe "moderate" and "temperate" respectively. However, I've left them as "sw" and "hw".

Also remove a macro which was used in only a single place.

In the second patch, remove priority INVALID, since it is not a priority, e.g. a scheduler cannot be assigned and run at priority "invalid". It seems to be more of a directive, a status, of user input, and as such has no place in the enumeration of priority levels.

Something else I'd like to do, is to eliminate priority enumeration "UNSET", since it is not really a priority level, but a directive, instructing the code to "reset the priority of a context to the initial priority".

At the moment, this functionality is overloaded to this priority value, and it should be an IOCTL op, as opposed to a priority value.

Tested on my desktop system, which is running a kernel with this patch applied.

v2: Some reverts; eliminate SW and HW for HIGH, and bring back
KERNEL--the highest!

Luben Tuikov (2):
drm/scheduler: Scheduler priority fixes (v2) drm/scheduler: Remove priority macro INVALID (v2)

 drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c   |  9 +++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_job.c   |  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c  |  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h  |  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_sched.c | 40 +++++++++++++++++------
 drivers/gpu/drm/amd/amdgpu/amdgpu_sched.h |  3 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c   |  2 +-
 drivers/gpu/drm/scheduler/sched_main.c    |  4 +--
 include/drm/gpu_scheduler.h               | 13 ++++----
 9 files changed, 49 insertions(+), 28 deletions(-)
Signature · 6 lines
2.28.0.215.g878e727637

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
#1 lore raw

PATCH 1/2 drm/scheduler: Scheduler priority fixes (v2)

Remove DRM_SCHED_PRIORITY_LOW, as it was used in only one place.

Rename and separate by a line DRM_SCHED_PRIORITY_MAX to DRM_SCHED_PRIORITY_COUNT as it represents a (total) count of said priorities and it is used as such in loops throughout the code. (0-based indexing is the the count number.)

Remove redundant word HIGH in priority names, and rename *KERNEL* to *HIGH*, as it really means that, high.

v2: Add back KERNEL and remove SW and HW,
in lieu of a single HIGH between NORMAL and KERNEL.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c   |  4 ++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_job.c   |  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c  |  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h  |  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_sched.c |  6 +++---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c   |  2 +-
 drivers/gpu/drm/scheduler/sched_main.c    |  4 ++--
 include/drm/gpu_scheduler.h               | 12 +++++++-----
 8 files changed, 18 insertions(+), 16 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +2 -2
index d85d13f7a043..68eaa4f687a6 100644
@@ -46,7 +46,7 @@ const unsigned int amdgpu_ctx_num_entities[AMDGPU_HW_IP_NUM] = {
 static int amdgpu_ctx_priority_permit(struct drm_file *filp,
 				      enum drm_sched_priority priority)
 {
-	if (priority < 0 || priority >= DRM_SCHED_PRIORITY_MAX)
+	if (priority < 0 || priority >= DRM_SCHED_PRIORITY_COUNT)
 		return -EINVAL;
 
 	/* NORMAL and below are accessible by everyone */
@@ -65,7 +65,7 @@ static int amdgpu_ctx_priority_permit(struct drm_file *filp,
 static enum gfx_pipe_priority amdgpu_ctx_sched_prio_to_compute_prio(enum drm_sched_priority prio)
 {
 	switch (prio) {
-	case DRM_SCHED_PRIORITY_HIGH_HW:
+	case DRM_SCHED_PRIORITY_HIGH:
 	case DRM_SCHED_PRIORITY_KERNEL:
 		return AMDGPU_GFX_PIPE_PRIO_HIGH;
 	default:
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +1 -1
index 75d37dfb51aa..bb9e5481ff3c 100644
@@ -251,7 +251,7 @@ void amdgpu_job_stop_all_jobs_on_sched(struct drm_gpu_scheduler *sched)
 	int i;
 
 	/* Signal all jobs not yet scheduled */
-	for (i = DRM_SCHED_PRIORITY_MAX - 1; i >= DRM_SCHED_PRIORITY_MIN; i--) {
+	for (i = DRM_SCHED_PRIORITY_COUNT - 1; i >= DRM_SCHED_PRIORITY_MIN; i--) {
 		struct drm_sched_rq *rq = &sched->sched_rq[i];
 
 		if (!rq)
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +1 -1
index 13ea8ebc421c..6d4fc79bf84a 100644
@@ -267,7 +267,7 @@ int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring,
 			&ring->sched;
 	}
 
-	for (i = 0; i < DRM_SCHED_PRIORITY_MAX; ++i)
+	for (i = DRM_SCHED_PRIORITY_MIN; i < DRM_SCHED_PRIORITY_COUNT; ++i)
 		atomic_set(&ring->num_jobs[i], 0);
 
 	return 0;
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +1 -1
index da871d84b742..7112137689db 100644
@@ -243,7 +243,7 @@ struct amdgpu_ring {
 	bool			has_compute_vm_bug;
 	bool			no_scheduler;
 
-	atomic_t		num_jobs[DRM_SCHED_PRIORITY_MAX];
+	atomic_t		num_jobs[DRM_SCHED_PRIORITY_COUNT];
 	struct mutex		priority_mutex;
 	/* protected by priority_mutex */
 	int			priority;
drivers/gpu/drm/amd/amdgpu/amdgpu_sched.c +3 -3
index c799691dfa84..17661ede9488 100644
@@ -36,14 +36,14 @@ enum drm_sched_priority amdgpu_to_sched_priority(int amdgpu_priority)
 {
 	switch (amdgpu_priority) {
 	case AMDGPU_CTX_PRIORITY_VERY_HIGH:
-		return DRM_SCHED_PRIORITY_HIGH_HW;
+		return DRM_SCHED_PRIORITY_HIGH;
 	case AMDGPU_CTX_PRIORITY_HIGH:
-		return DRM_SCHED_PRIORITY_HIGH_SW;
+		return DRM_SCHED_PRIORITY_HIGH;
 	case AMDGPU_CTX_PRIORITY_NORMAL:
 		return DRM_SCHED_PRIORITY_NORMAL;
 	case AMDGPU_CTX_PRIORITY_LOW:
 	case AMDGPU_CTX_PRIORITY_VERY_LOW:
-		return DRM_SCHED_PRIORITY_LOW;
+		return DRM_SCHED_PRIORITY_MIN;
 	case AMDGPU_CTX_PRIORITY_UNSET:
 		return DRM_SCHED_PRIORITY_UNSET;
 	default:
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +1 -1
index 20fa0497aaa4..60e2d3267ae5 100644
@@ -2114,7 +2114,7 @@ void amdgpu_ttm_set_buffer_funcs_status(struct amdgpu_device *adev, bool enable)
 		ring = adev->mman.buffer_funcs_ring;
 		sched = &ring->sched;
 		r = drm_sched_entity_init(&adev->mman.entity,
-				          DRM_SCHED_PRIORITY_KERNEL, &sched,
+					  DRM_SCHED_PRIORITY_KERNEL, &sched,
 					  1, NULL);
 		if (r) {
 			DRM_ERROR("Failed setting up TTM BO move entity (%d)\n",
drivers/gpu/drm/scheduler/sched_main.c +2 -2
index 2f319102ae9f..19f381e5e661 100644
@@ -623,7 +623,7 @@ drm_sched_select_entity(struct drm_gpu_scheduler *sched)
 		return NULL;
 
 	/* Kernel run queue has higher priority than normal run queue*/
-	for (i = DRM_SCHED_PRIORITY_MAX - 1; i >= DRM_SCHED_PRIORITY_MIN; i--) {
+	for (i = DRM_SCHED_PRIORITY_COUNT - 1; i >= DRM_SCHED_PRIORITY_MIN; i--) {
 		entity = drm_sched_rq_select_entity(&sched->sched_rq[i]);
 		if (entity)
 			break;
@@ -851,7 +851,7 @@ int drm_sched_init(struct drm_gpu_scheduler *sched,
 	sched->name = name;
 	sched->timeout = timeout;
 	sched->hang_limit = hang_limit;
-	for (i = DRM_SCHED_PRIORITY_MIN; i < DRM_SCHED_PRIORITY_MAX; i++)
+	for (i = DRM_SCHED_PRIORITY_MIN; i < DRM_SCHED_PRIORITY_COUNT; i++)
 		drm_sched_rq_init(sched, &sched->sched_rq[i]);
 
 	init_waitqueue_head(&sched->wake_up_worker);
include/drm/gpu_scheduler.h +7 -5
index 26b04ff62676..ed998464ded4 100644
@@ -33,14 +33,16 @@
 struct drm_gpu_scheduler;
 struct drm_sched_rq;
 
+/* These are often used as an (initial) index
+ * to an array, and as such should start at 0.
+ */
 enum drm_sched_priority {
 	DRM_SCHED_PRIORITY_MIN,
-	DRM_SCHED_PRIORITY_LOW = DRM_SCHED_PRIORITY_MIN,
 	DRM_SCHED_PRIORITY_NORMAL,
-	DRM_SCHED_PRIORITY_HIGH_SW,
-	DRM_SCHED_PRIORITY_HIGH_HW,
+	DRM_SCHED_PRIORITY_HIGH,
 	DRM_SCHED_PRIORITY_KERNEL,
-	DRM_SCHED_PRIORITY_MAX,
+
+	DRM_SCHED_PRIORITY_COUNT,
 	DRM_SCHED_PRIORITY_INVALID = -1,
 	DRM_SCHED_PRIORITY_UNSET = -2
 };
@@ -273,7 +275,7 @@ struct drm_gpu_scheduler {
 	uint32_t			hw_submission_limit;
 	long				timeout;
 	const char			*name;
-	struct drm_sched_rq		sched_rq[DRM_SCHED_PRIORITY_MAX];
+	struct drm_sched_rq		sched_rq[DRM_SCHED_PRIORITY_COUNT];
 	wait_queue_head_t		wake_up_worker;
 	wait_queue_head_t		job_scheduled;
 	atomic_t			hw_rq_count;
Signature · 6 lines
2.28.0.215.g878e727637

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
reviewer Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] drm/scheduler: Scheduler priority fixes (v2)

Am 15.08.20 um 04:48 schrieb Luben Tuikov:

Quoted 10 lines

Remove DRM_SCHED_PRIORITY_LOW, as it was used in only one place.

Rename and separate by a line DRM_SCHED_PRIORITY_MAX to DRM_SCHED_PRIORITY_COUNT as it represents a (total) count of said priorities and it is used as such in loops throughout the code. (0-based indexing is the the count number.)

Quoted 8 lines

Remove redundant word HIGH in priority names, and rename *KERNEL* to *HIGH*, as it really means that, high.

v2: Add back KERNEL and remove SW and HW,
in lieu of a single HIGH between NORMAL and KERNEL.

I can't really judge the difference between MAX and COUNT, but the we rename the values and get rid of the invalid one sounds like a good idea to me.

Quoted 155 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c   |  4 ++--
  drivers/gpu/drm/amd/amdgpu/amdgpu_job.c   |  2 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c  |  2 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h  |  2 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_sched.c |  6 +++---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c   |  2 +-
  drivers/gpu/drm/scheduler/sched_main.c    |  4 ++--
  include/drm/gpu_scheduler.h               | 12 +++++++-----
  8 files changed, 18 insertions(+), 16 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +2 -2
index d85d13f7a043..68eaa4f687a6 100644
@@ -46,7 +46,7 @@ const unsigned int amdgpu_ctx_num_entities[AMDGPU_HW_IP_NUM] = {
  static int amdgpu_ctx_priority_permit(struct drm_file *filp,
  				      enum drm_sched_priority priority)
  {
-	if (priority < 0 || priority >= DRM_SCHED_PRIORITY_MAX)
+	if (priority < 0 || priority >= DRM_SCHED_PRIORITY_COUNT)
  		return -EINVAL;
 
  	/* NORMAL and below are accessible by everyone */
@@ -65,7 +65,7 @@ static int amdgpu_ctx_priority_permit(struct drm_file *filp,
  static enum gfx_pipe_priority amdgpu_ctx_sched_prio_to_compute_prio(enum drm_sched_priority prio)
  {
  	switch (prio) {
-	case DRM_SCHED_PRIORITY_HIGH_HW:
+	case DRM_SCHED_PRIORITY_HIGH:
  	case DRM_SCHED_PRIORITY_KERNEL:
  		return AMDGPU_GFX_PIPE_PRIO_HIGH;
  	default:
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +1 -1
index 75d37dfb51aa..bb9e5481ff3c 100644
@@ -251,7 +251,7 @@ void amdgpu_job_stop_all_jobs_on_sched(struct drm_gpu_scheduler *sched)
  	int i;
 
  	/* Signal all jobs not yet scheduled */
-	for (i = DRM_SCHED_PRIORITY_MAX - 1; i >= DRM_SCHED_PRIORITY_MIN; i--) {
+	for (i = DRM_SCHED_PRIORITY_COUNT - 1; i >= DRM_SCHED_PRIORITY_MIN; i--) {
  		struct drm_sched_rq *rq = &sched->sched_rq[i];
 
  		if (!rq)
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +1 -1
index 13ea8ebc421c..6d4fc79bf84a 100644
@@ -267,7 +267,7 @@ int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring,
  			&ring->sched;
  	}
 
-	for (i = 0; i < DRM_SCHED_PRIORITY_MAX; ++i)
+	for (i = DRM_SCHED_PRIORITY_MIN; i < DRM_SCHED_PRIORITY_COUNT; ++i)
  		atomic_set(&ring->num_jobs[i], 0);
 
  	return 0;
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +1 -1
index da871d84b742..7112137689db 100644
@@ -243,7 +243,7 @@ struct amdgpu_ring {
  	bool			has_compute_vm_bug;
  	bool			no_scheduler;
 
-	atomic_t		num_jobs[DRM_SCHED_PRIORITY_MAX];
+	atomic_t		num_jobs[DRM_SCHED_PRIORITY_COUNT];
  	struct mutex		priority_mutex;
  	/* protected by priority_mutex */
  	int			priority;
drivers/gpu/drm/amd/amdgpu/amdgpu_sched.c +3 -3
index c799691dfa84..17661ede9488 100644
@@ -36,14 +36,14 @@ enum drm_sched_priority amdgpu_to_sched_priority(int amdgpu_priority)
  {
  	switch (amdgpu_priority) {
  	case AMDGPU_CTX_PRIORITY_VERY_HIGH:
-		return DRM_SCHED_PRIORITY_HIGH_HW;
+		return DRM_SCHED_PRIORITY_HIGH;
  	case AMDGPU_CTX_PRIORITY_HIGH:
-		return DRM_SCHED_PRIORITY_HIGH_SW;
+		return DRM_SCHED_PRIORITY_HIGH;
  	case AMDGPU_CTX_PRIORITY_NORMAL:
  		return DRM_SCHED_PRIORITY_NORMAL;
  	case AMDGPU_CTX_PRIORITY_LOW:
  	case AMDGPU_CTX_PRIORITY_VERY_LOW:
-		return DRM_SCHED_PRIORITY_LOW;
+		return DRM_SCHED_PRIORITY_MIN;
  	case AMDGPU_CTX_PRIORITY_UNSET:
  		return DRM_SCHED_PRIORITY_UNSET;
  	default:
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +1 -1
index 20fa0497aaa4..60e2d3267ae5 100644
@@ -2114,7 +2114,7 @@ void amdgpu_ttm_set_buffer_funcs_status(struct amdgpu_device *adev, bool enable)
  		ring = adev->mman.buffer_funcs_ring;
  		sched = &ring->sched;
  		r = drm_sched_entity_init(&adev->mman.entity,
-				          DRM_SCHED_PRIORITY_KERNEL, &sched,
+					  DRM_SCHED_PRIORITY_KERNEL, &sched,
  					  1, NULL);
  		if (r) {
  			DRM_ERROR("Failed setting up TTM BO move entity (%d)\n",
drivers/gpu/drm/scheduler/sched_main.c +2 -2
index 2f319102ae9f..19f381e5e661 100644
@@ -623,7 +623,7 @@ drm_sched_select_entity(struct drm_gpu_scheduler *sched)
  		return NULL;
 
  	/* Kernel run queue has higher priority than normal run queue*/
-	for (i = DRM_SCHED_PRIORITY_MAX - 1; i >= DRM_SCHED_PRIORITY_MIN; i--) {
+	for (i = DRM_SCHED_PRIORITY_COUNT - 1; i >= DRM_SCHED_PRIORITY_MIN; i--) {
  		entity = drm_sched_rq_select_entity(&sched->sched_rq[i]);
  		if (entity)
  			break;
@@ -851,7 +851,7 @@ int drm_sched_init(struct drm_gpu_scheduler *sched,
  	sched->name = name;
  	sched->timeout = timeout;
  	sched->hang_limit = hang_limit;
-	for (i = DRM_SCHED_PRIORITY_MIN; i < DRM_SCHED_PRIORITY_MAX; i++)
+	for (i = DRM_SCHED_PRIORITY_MIN; i < DRM_SCHED_PRIORITY_COUNT; i++)
  		drm_sched_rq_init(sched, &sched->sched_rq[i]);
 
  	init_waitqueue_head(&sched->wake_up_worker);
include/drm/gpu_scheduler.h +6 -4
index 26b04ff62676..ed998464ded4 100644
@@ -33,14 +33,16 @@
  struct drm_gpu_scheduler;
  struct drm_sched_rq;
 
+/* These are often used as an (initial) index
+ * to an array, and as such should start at 0.
+ */
  enum drm_sched_priority {
  	DRM_SCHED_PRIORITY_MIN,
-	DRM_SCHED_PRIORITY_LOW = DRM_SCHED_PRIORITY_MIN,
  	DRM_SCHED_PRIORITY_NORMAL,
-	DRM_SCHED_PRIORITY_HIGH_SW,
-	DRM_SCHED_PRIORITY_HIGH_HW,
+	DRM_SCHED_PRIORITY_HIGH,
  	DRM_SCHED_PRIORITY_KERNEL,
-	DRM_SCHED_PRIORITY_MAX,
+
+	DRM_SCHED_PRIORITY_COUNT,
  	DRM_SCHED_PRIORITY_INVALID = -1,
  	DRM_SCHED_PRIORITY_UNSET = -2
  };

include/drm/gpu_scheduler.h struct drm_gpu_scheduler { · line 281

Quoted 8 lines
include/drm/gpu_scheduler.h +1 -1
@@ -273,7 +275,7 @@ struct drm_gpu_scheduler {
  	uint32_t			hw_submission_limit;
  	long				timeout;
  	const char			*name;
-	struct drm_sched_rq		sched_rq[DRM_SCHED_PRIORITY_MAX];
+	struct drm_sched_rq		sched_rq[DRM_SCHED_PRIORITY_COUNT];
  	wait_queue_head_t		wake_up_worker;
  	wait_queue_head_t		job_scheduled;
  	atomic_t			hw_rq_count;

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#3 lore raw

Re: [PATCH 1/2] drm/scheduler: Scheduler priority fixes (v2)

Quoted 15 lines · Christian König

Am 15.08.20 um 04:48 schrieb Luben Tuikov:

Quoted 14 lines

Remove DRM_SCHED_PRIORITY_LOW, as it was used in only one place.

Rename and separate by a line DRM_SCHED_PRIORITY_MAX to DRM_SCHED_PRIORITY_COUNT as it represents a (total) count of said priorities and it is used as such in loops throughout the code. (0-based indexing is the the count number.)

Remove redundant word HIGH in priority names, and rename *KERNEL* to *HIGH*, as it really means that, high.

Quoted 8 lines
Quoted 4 lines

v2: Add back KERNEL and remove SW and HW,
in lieu of a single HIGH between NORMAL and KERNEL.

I can't really judge the difference between MAX and COUNT, but the we rename the values and get rid of the invalid one sounds like a good idea to me.

Thanks Christian.

As to "max" vs. "count", I alluded to the difference in the patch cover letter text:

Quoted 5 lines

For instance, renaming MAX to COUNT, as usually a maximum value is a value which is part of the set of values, (e.g. a maxima of a function), and thus assignable, whereby a count is the size of a set (the enumeration in this case). It also makes it clearer when used to define size of arrays.

A "maximum" value is value which *can be attained.* For instance, some would say, "The maximum temperature we expect today is 35 degC." While a "count" is just the (usually integer) number of objects in a set. The set could be composed of various objects, not necessarily integers. It is possible that the maximum number in a set of integers to also be the size of that set, e.g. A = { 1, 2, 3 }, max(A) = 3, sizeof(A) = 3, but as you can see this is a special case; consider A = { Red, Green, Blue }, or A = { 2, 3, 5 }, or A = { 3 }.

To me it is confusing to read "MAX", as this is usually used as a "watermark", say in temperature of a unit or something like that, which we monitor and perform certain actions depending on whether the maximum temperature is/has been attained. Usually, there'd be one above it, called "CRITICAL".

And I've seen bugs where people would assume that MAX is an attainable value, e.g. MAX_PRIORITY, "This is the maximum priority a task could run at."

I'll add your RB to the patch! Thanks for your review.

Regards,
Luben

Quoted 158 lines
Quoted 155 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c   |  4 ++--
  drivers/gpu/drm/amd/amdgpu/amdgpu_job.c   |  2 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c  |  2 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h  |  2 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_sched.c |  6 +++---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c   |  2 +-
  drivers/gpu/drm/scheduler/sched_main.c    |  4 ++--
  include/drm/gpu_scheduler.h               | 12 +++++++-----
  8 files changed, 18 insertions(+), 16 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +2 -2
index d85d13f7a043..68eaa4f687a6 100644
@@ -46,7 +46,7 @@ const unsigned int amdgpu_ctx_num_entities[AMDGPU_HW_IP_NUM] = {
  static int amdgpu_ctx_priority_permit(struct drm_file *filp,
  				      enum drm_sched_priority priority)
  {
-	if (priority < 0 || priority >= DRM_SCHED_PRIORITY_MAX)
+	if (priority < 0 || priority >= DRM_SCHED_PRIORITY_COUNT)
  		return -EINVAL;
 
  	/* NORMAL and below are accessible by everyone */
@@ -65,7 +65,7 @@ static int amdgpu_ctx_priority_permit(struct drm_file *filp,
  static enum gfx_pipe_priority amdgpu_ctx_sched_prio_to_compute_prio(enum drm_sched_priority prio)
  {
  	switch (prio) {
-	case DRM_SCHED_PRIORITY_HIGH_HW:
+	case DRM_SCHED_PRIORITY_HIGH:
  	case DRM_SCHED_PRIORITY_KERNEL:
  		return AMDGPU_GFX_PIPE_PRIO_HIGH;
  	default:
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +1 -1
index 75d37dfb51aa..bb9e5481ff3c 100644
@@ -251,7 +251,7 @@ void amdgpu_job_stop_all_jobs_on_sched(struct drm_gpu_scheduler *sched)
  	int i;
 
  	/* Signal all jobs not yet scheduled */
-	for (i = DRM_SCHED_PRIORITY_MAX - 1; i >= DRM_SCHED_PRIORITY_MIN; i--) {
+	for (i = DRM_SCHED_PRIORITY_COUNT - 1; i >= DRM_SCHED_PRIORITY_MIN; i--) {
  		struct drm_sched_rq *rq = &sched->sched_rq[i];
 
  		if (!rq)
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +1 -1
index 13ea8ebc421c..6d4fc79bf84a 100644
@@ -267,7 +267,7 @@ int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring,
  			&ring->sched;
  	}
 
-	for (i = 0; i < DRM_SCHED_PRIORITY_MAX; ++i)
+	for (i = DRM_SCHED_PRIORITY_MIN; i < DRM_SCHED_PRIORITY_COUNT; ++i)
  		atomic_set(&ring->num_jobs[i], 0);
 
  	return 0;
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +1 -1
index da871d84b742..7112137689db 100644
@@ -243,7 +243,7 @@ struct amdgpu_ring {
  	bool			has_compute_vm_bug;
  	bool			no_scheduler;
 
-	atomic_t		num_jobs[DRM_SCHED_PRIORITY_MAX];
+	atomic_t		num_jobs[DRM_SCHED_PRIORITY_COUNT];
  	struct mutex		priority_mutex;
  	/* protected by priority_mutex */
  	int			priority;
drivers/gpu/drm/amd/amdgpu/amdgpu_sched.c +3 -3
index c799691dfa84..17661ede9488 100644
@@ -36,14 +36,14 @@ enum drm_sched_priority amdgpu_to_sched_priority(int amdgpu_priority)
  {
  	switch (amdgpu_priority) {
  	case AMDGPU_CTX_PRIORITY_VERY_HIGH:
-		return DRM_SCHED_PRIORITY_HIGH_HW;
+		return DRM_SCHED_PRIORITY_HIGH;
  	case AMDGPU_CTX_PRIORITY_HIGH:
-		return DRM_SCHED_PRIORITY_HIGH_SW;
+		return DRM_SCHED_PRIORITY_HIGH;
  	case AMDGPU_CTX_PRIORITY_NORMAL:
  		return DRM_SCHED_PRIORITY_NORMAL;
  	case AMDGPU_CTX_PRIORITY_LOW:
  	case AMDGPU_CTX_PRIORITY_VERY_LOW:
-		return DRM_SCHED_PRIORITY_LOW;
+		return DRM_SCHED_PRIORITY_MIN;
  	case AMDGPU_CTX_PRIORITY_UNSET:
  		return DRM_SCHED_PRIORITY_UNSET;
  	default:
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +1 -1
index 20fa0497aaa4..60e2d3267ae5 100644
@@ -2114,7 +2114,7 @@ void amdgpu_ttm_set_buffer_funcs_status(struct amdgpu_device *adev, bool enable)
  		ring = adev->mman.buffer_funcs_ring;
  		sched = &ring->sched;
  		r = drm_sched_entity_init(&adev->mman.entity,
-				          DRM_SCHED_PRIORITY_KERNEL, &sched,
+					  DRM_SCHED_PRIORITY_KERNEL, &sched,
  					  1, NULL);
  		if (r) {
  			DRM_ERROR("Failed setting up TTM BO move entity (%d)\n",
drivers/gpu/drm/scheduler/sched_main.c +2 -2
index 2f319102ae9f..19f381e5e661 100644
@@ -623,7 +623,7 @@ drm_sched_select_entity(struct drm_gpu_scheduler *sched)
  		return NULL;
 
  	/* Kernel run queue has higher priority than normal run queue*/
-	for (i = DRM_SCHED_PRIORITY_MAX - 1; i >= DRM_SCHED_PRIORITY_MIN; i--) {
+	for (i = DRM_SCHED_PRIORITY_COUNT - 1; i >= DRM_SCHED_PRIORITY_MIN; i--) {
  		entity = drm_sched_rq_select_entity(&sched->sched_rq[i]);
  		if (entity)
  			break;
@@ -851,7 +851,7 @@ int drm_sched_init(struct drm_gpu_scheduler *sched,
  	sched->name = name;
  	sched->timeout = timeout;
  	sched->hang_limit = hang_limit;
-	for (i = DRM_SCHED_PRIORITY_MIN; i < DRM_SCHED_PRIORITY_MAX; i++)
+	for (i = DRM_SCHED_PRIORITY_MIN; i < DRM_SCHED_PRIORITY_COUNT; i++)
  		drm_sched_rq_init(sched, &sched->sched_rq[i]);
 
  	init_waitqueue_head(&sched->wake_up_worker);
include/drm/gpu_scheduler.h +6 -4
index 26b04ff62676..ed998464ded4 100644
@@ -33,14 +33,16 @@
  struct drm_gpu_scheduler;
  struct drm_sched_rq;
 
+/* These are often used as an (initial) index
+ * to an array, and as such should start at 0.
+ */
  enum drm_sched_priority {
  	DRM_SCHED_PRIORITY_MIN,
-	DRM_SCHED_PRIORITY_LOW = DRM_SCHED_PRIORITY_MIN,
  	DRM_SCHED_PRIORITY_NORMAL,
-	DRM_SCHED_PRIORITY_HIGH_SW,
-	DRM_SCHED_PRIORITY_HIGH_HW,
+	DRM_SCHED_PRIORITY_HIGH,
  	DRM_SCHED_PRIORITY_KERNEL,
-	DRM_SCHED_PRIORITY_MAX,
+
+	DRM_SCHED_PRIORITY_COUNT,
  	DRM_SCHED_PRIORITY_INVALID = -1,
  	DRM_SCHED_PRIORITY_UNSET = -2
  };
@@ -273,7 +275,7 @@ struct drm_gpu_scheduler {
Quoted 9 lines

include/drm/gpu_scheduler.h struct drm_gpu_scheduler { · line 281

Quoted 8 lines
include/drm/gpu_scheduler.h +1 -1
  	uint32_t			hw_submission_limit;
  	long				timeout;
  	const char			*name;
-	struct drm_sched_rq		sched_rq[DRM_SCHED_PRIORITY_MAX];
+	struct drm_sched_rq		sched_rq[DRM_SCHED_PRIORITY_COUNT];
  	wait_queue_head_t		wake_up_worker;
  	wait_queue_head_t		job_scheduled;
  	atomic_t			hw_rq_count;

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#4 lore raw

PATCH 2/2 drm/scheduler: Remove priority macro INVALID (v2)

In reply to Luben Tuikov

Remove DRM_SCHED_PRIORITY_INVALID. We no longer carry around an invalid priority and cut it off at the source.

Backwards compatibility behaviour of AMDGPU CTX IOCTL passing in garbage for context priority from user space and then mapping that to DRM_SCHED_PRIORITY_NORMAL is preserved.

v2: Revert "res" --> "r" and

           "prio" --> "priority".
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c   |  5 ++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_sched.c | 40 +++++++++++++++++------
 drivers/gpu/drm/amd/amdgpu/amdgpu_sched.h |  3 +-
 include/drm/gpu_scheduler.h               |  1 -
 4 files changed, 34 insertions(+), 15 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +2 -3
index 68eaa4f687a6..0a980f59cfd0 100644
@@ -392,13 +392,12 @@ int amdgpu_ctx_ioctl(struct drm_device *dev, void *data,
 	struct amdgpu_device *adev = dev->dev_private;
 	struct amdgpu_fpriv *fpriv = filp->driver_priv;
 
-	r = 0;
 	id = args->in.ctx_id;
-	priority = amdgpu_to_sched_priority(args->in.priority);
+	r = amdgpu_to_sched_priority(args->in.priority, &priority);
 
 	/* For backwards compatibility reasons, we need to accept
 	 * ioctls with garbage in the priority field */
-	if (priority == DRM_SCHED_PRIORITY_INVALID)
+	if (r == -EINVAL)
 		priority = DRM_SCHED_PRIORITY_NORMAL;
 
 	switch (args->in.op) {
drivers/gpu/drm/amd/amdgpu/amdgpu_sched.c +30 -10
index 17661ede9488..9581283a4c78 100644
@@ -32,24 +32,32 @@
 
 #include "amdgpu_vm.h"
 
-enum drm_sched_priority amdgpu_to_sched_priority(int amdgpu_priority)
+int amdgpu_to_sched_priority(int amdgpu_priority,
+			     enum drm_sched_priority *prio)
 {
 	switch (amdgpu_priority) {
 	case AMDGPU_CTX_PRIORITY_VERY_HIGH:
-		return DRM_SCHED_PRIORITY_HIGH;
+		*prio = DRM_SCHED_PRIORITY_HIGH;
+		break;
 	case AMDGPU_CTX_PRIORITY_HIGH:
-		return DRM_SCHED_PRIORITY_HIGH;
+		*prio = DRM_SCHED_PRIORITY_HIGH;
+		break;
 	case AMDGPU_CTX_PRIORITY_NORMAL:
-		return DRM_SCHED_PRIORITY_NORMAL;
+		*prio = DRM_SCHED_PRIORITY_NORMAL;
+		break;
 	case AMDGPU_CTX_PRIORITY_LOW:
 	case AMDGPU_CTX_PRIORITY_VERY_LOW:
-		return DRM_SCHED_PRIORITY_MIN;
+		*prio = DRM_SCHED_PRIORITY_MIN;
+		break;
 	case AMDGPU_CTX_PRIORITY_UNSET:
-		return DRM_SCHED_PRIORITY_UNSET;
+		*prio = DRM_SCHED_PRIORITY_UNSET;
+		break;
 	default:
 		WARN(1, "Invalid context priority %d\n", amdgpu_priority);
-		return DRM_SCHED_PRIORITY_INVALID;
+		return -EINVAL;
 	}
+
+	return 0;
 }
 
 static int amdgpu_sched_process_priority_override(struct amdgpu_device *adev,
@@ -119,9 +127,20 @@ int amdgpu_sched_ioctl(struct drm_device *dev, void *data,
 	enum drm_sched_priority priority;
 	int r;
 
-	priority = amdgpu_to_sched_priority(args->in.priority);
-	if (priority == DRM_SCHED_PRIORITY_INVALID)
+	/* First check the op, then the op's argument.
+	 */
+	switch (args->in.op) {
+	case AMDGPU_SCHED_OP_PROCESS_PRIORITY_OVERRIDE:
+	case AMDGPU_SCHED_OP_CONTEXT_PRIORITY_OVERRIDE:
+		break;
+	default:
+		DRM_ERROR("Invalid sched op specified: %d\n", args->in.op);
 		return -EINVAL;
+	}
+
+	r = amdgpu_to_sched_priority(args->in.priority, &priority);
+	if (r)
+		return r;
 
 	switch (args->in.op) {
 	case AMDGPU_SCHED_OP_PROCESS_PRIORITY_OVERRIDE:
@@ -136,7 +155,8 @@ int amdgpu_sched_ioctl(struct drm_device *dev, void *data,
 							   priority);
 		break;
 	default:
-		DRM_ERROR("Invalid sched op specified: %d\n", args->in.op);
+		/* Impossible.
+		 */
 		r = -EINVAL;
 		break;
 	}
drivers/gpu/drm/amd/amdgpu/amdgpu_sched.h +2 -1
index 12299fd95691..67e5b2472f6a 100644
@@ -30,7 +30,8 @@ enum drm_sched_priority;
 struct drm_device;
 struct drm_file;
 
-enum drm_sched_priority amdgpu_to_sched_priority(int amdgpu_priority);
+int amdgpu_to_sched_priority(int amdgpu_priority,
+			     enum drm_sched_priority *prio);
 int amdgpu_sched_ioctl(struct drm_device *dev, void *data,
 		       struct drm_file *filp);
 
include/drm/gpu_scheduler.h +0 -1
index ed998464ded4..5eb464248621 100644
@@ -43,7 +43,6 @@ enum drm_sched_priority {
 	DRM_SCHED_PRIORITY_KERNEL,
 
 	DRM_SCHED_PRIORITY_COUNT,
-	DRM_SCHED_PRIORITY_INVALID = -1,
 	DRM_SCHED_PRIORITY_UNSET = -2
 };
 
Signature · 6 lines
2.28.0.215.g878e727637

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx