[PATCH 5/8] drm/amd/sched: allow clients to edit an entity's rq v2

2017-09-21 Thread Andres Rodriguez
This is useful for changing an entity's priority at runtime.

v2: don't modify the order of amd_sched_entity members

Signed-off-by: Andres Rodriguez 
Acked-by: Christian König 
---
 drivers/gpu/drm/amd/scheduler/gpu_scheduler.c | 24 ++--
 drivers/gpu/drm/amd/scheduler/gpu_scheduler.h |  3 +++
 2 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/scheduler/gpu_scheduler.c 
b/drivers/gpu/drm/amd/scheduler/gpu_scheduler.c
index 97c94f9..a5adde1 100644
--- a/drivers/gpu/drm/amd/scheduler/gpu_scheduler.c
+++ b/drivers/gpu/drm/amd/scheduler/gpu_scheduler.c
@@ -133,6 +133,7 @@ int amd_sched_entity_init(struct amd_gpu_scheduler *sched,
entity->rq = rq;
entity->sched = sched;
 
+   spin_lock_init(&entity->rq_lock);
spin_lock_init(&entity->queue_lock);
r = kfifo_alloc(&entity->job_queue, jobs * sizeof(void *), GFP_KERNEL);
if (r)
@@ -204,7 +205,6 @@ static bool amd_sched_entity_is_ready(struct 
amd_sched_entity *entity)
 void amd_sched_entity_fini(struct amd_gpu_scheduler *sched,
   struct amd_sched_entity *entity)
 {
-   struct amd_sched_rq *rq = entity->rq;
int r;
 
if (!amd_sched_entity_is_initialized(sched, entity))
@@ -218,7 +218,7 @@ void amd_sched_entity_fini(struct amd_gpu_scheduler *sched,
else
r = wait_event_killable(sched->job_scheduled,
amd_sched_entity_is_idle(entity));
-   amd_sched_rq_remove_entity(rq, entity);
+   amd_sched_entity_set_rq(entity, NULL);
if (r) {
struct amd_sched_job *job;
 
@@ -251,6 +251,24 @@ static void amd_sched_entity_clear_dep(struct dma_fence 
*f, struct dma_fence_cb
dma_fence_put(f);
 }
 
+void amd_sched_entity_set_rq(struct amd_sched_entity *entity,
+struct amd_sched_rq *rq)
+{
+   if (entity->rq == rq)
+   return;
+
+   spin_lock(&entity->rq_lock);
+
+   if (entity->rq)
+   amd_sched_rq_remove_entity(entity->rq, entity);
+
+   entity->rq = rq;
+   if (rq)
+   amd_sched_rq_add_entity(rq, entity);
+
+   spin_unlock(&entity->rq_lock);
+}
+
 bool amd_sched_dependency_optimized(struct dma_fence* fence,
struct amd_sched_entity *entity)
 {
@@ -348,7 +366,9 @@ static bool amd_sched_entity_in(struct amd_sched_job 
*sched_job)
/* first job wakes up scheduler */
if (first) {
/* Add the entity to the run queue */
+   spin_lock(&entity->rq_lock);
amd_sched_rq_add_entity(entity->rq, entity);
+   spin_unlock(&entity->rq_lock);
amd_sched_wakeup(sched);
}
return added;
diff --git a/drivers/gpu/drm/amd/scheduler/gpu_scheduler.h 
b/drivers/gpu/drm/amd/scheduler/gpu_scheduler.h
index da040bc..4b528f7 100644
--- a/drivers/gpu/drm/amd/scheduler/gpu_scheduler.h
+++ b/drivers/gpu/drm/amd/scheduler/gpu_scheduler.h
@@ -39,6 +39,7 @@ struct amd_sched_rq;
 struct amd_sched_entity {
struct list_headlist;
struct amd_sched_rq *rq;
+   spinlock_t  rq_lock;
struct amd_gpu_scheduler*sched;
 
spinlock_t  queue_lock;
@@ -154,6 +155,8 @@ int amd_sched_entity_init(struct amd_gpu_scheduler *sched,
 void amd_sched_entity_fini(struct amd_gpu_scheduler *sched,
   struct amd_sched_entity *entity);
 void amd_sched_entity_push_job(struct amd_sched_job *sched_job);
+void amd_sched_entity_set_rq(struct amd_sched_entity *entity,
+struct amd_sched_rq *rq);
 
 int amd_sched_fence_slab_init(void);
 void amd_sched_fence_slab_fini(void);
-- 
2.9.3

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH 5/8] drm/amd/sched: allow clients to edit an entity's rq v2

2017-07-07 Thread Andres Rodriguez
This is useful for changing an entity's priority at runtime.

v2: don't modify the order of amd_sched_entity members

Signed-off-by: Andres Rodriguez 
Acked-by: Christian König 
---
 drivers/gpu/drm/amd/scheduler/gpu_scheduler.c | 26 +++---
 drivers/gpu/drm/amd/scheduler/gpu_scheduler.h |  3 +++
 2 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/amd/scheduler/gpu_scheduler.c 
b/drivers/gpu/drm/amd/scheduler/gpu_scheduler.c
index 38cea6f..0166620 100644
--- a/drivers/gpu/drm/amd/scheduler/gpu_scheduler.c
+++ b/drivers/gpu/drm/amd/scheduler/gpu_scheduler.c
@@ -133,6 +133,7 @@ int amd_sched_entity_init(struct amd_gpu_scheduler *sched,
entity->rq = rq;
entity->sched = sched;
 
+   spin_lock_init(&entity->rq_lock);
spin_lock_init(&entity->queue_lock);
r = kfifo_alloc(&entity->job_queue, jobs * sizeof(void *), GFP_KERNEL);
if (r)
@@ -204,8 +205,6 @@ static bool amd_sched_entity_is_ready(struct 
amd_sched_entity *entity)
 void amd_sched_entity_fini(struct amd_gpu_scheduler *sched,
   struct amd_sched_entity *entity)
 {
-   struct amd_sched_rq *rq = entity->rq;
-
if (!amd_sched_entity_is_initialized(sched, entity))
return;
 
@@ -215,7 +214,8 @@ void amd_sched_entity_fini(struct amd_gpu_scheduler *sched,
*/
wait_event(sched->job_scheduled, amd_sched_entity_is_idle(entity));
 
-   amd_sched_rq_remove_entity(rq, entity);
+   amd_sched_entity_set_rq(entity, NULL);
+
kfifo_free(&entity->job_queue);
 }
 
@@ -236,6 +236,24 @@ static void amd_sched_entity_clear_dep(struct dma_fence 
*f, struct dma_fence_cb
dma_fence_put(f);
 }
 
+void amd_sched_entity_set_rq(struct amd_sched_entity *entity,
+struct amd_sched_rq *rq)
+{
+   if (entity->rq == rq)
+   return;
+
+   spin_lock(&entity->rq_lock);
+
+   if (entity->rq)
+   amd_sched_rq_remove_entity(entity->rq, entity);
+
+   entity->rq = rq;
+   if (rq)
+   amd_sched_rq_add_entity(rq, entity);
+
+   spin_unlock(&entity->rq_lock);
+}
+
 bool amd_sched_dependency_optimized(struct dma_fence* fence,
struct amd_sched_entity *entity)
 {
@@ -333,7 +351,9 @@ static bool amd_sched_entity_in(struct amd_sched_job 
*sched_job)
/* first job wakes up scheduler */
if (first) {
/* Add the entity to the run queue */
+   spin_lock(&entity->rq_lock);
amd_sched_rq_add_entity(entity->rq, entity);
+   spin_unlock(&entity->rq_lock);
amd_sched_wakeup(sched);
}
return added;
diff --git a/drivers/gpu/drm/amd/scheduler/gpu_scheduler.h 
b/drivers/gpu/drm/amd/scheduler/gpu_scheduler.h
index da040bc..4b528f7 100644
--- a/drivers/gpu/drm/amd/scheduler/gpu_scheduler.h
+++ b/drivers/gpu/drm/amd/scheduler/gpu_scheduler.h
@@ -39,6 +39,7 @@ struct amd_sched_rq;
 struct amd_sched_entity {
struct list_headlist;
struct amd_sched_rq *rq;
+   spinlock_t  rq_lock;
struct amd_gpu_scheduler*sched;
 
spinlock_t  queue_lock;
@@ -154,6 +155,8 @@ int amd_sched_entity_init(struct amd_gpu_scheduler *sched,
 void amd_sched_entity_fini(struct amd_gpu_scheduler *sched,
   struct amd_sched_entity *entity);
 void amd_sched_entity_push_job(struct amd_sched_job *sched_job);
+void amd_sched_entity_set_rq(struct amd_sched_entity *entity,
+struct amd_sched_rq *rq);
 
 int amd_sched_fence_slab_init(void);
 void amd_sched_fence_slab_fini(void);
-- 
2.9.3

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


Re: [PATCH 5/8] drm/amd/sched: allow clients to edit an entity's rq v2

2017-06-27 Thread Christian König

Am 26.06.2017 um 22:36 schrieb Andres Rodriguez:

This is useful for changing an entity's priority at runtime.

v2: don't modify the order of amd_sched_entity members

Signed-off-by: Andres Rodriguez 


Reviewed-by: Christian König 


---
  drivers/gpu/drm/amd/scheduler/gpu_scheduler.c | 26 +++---
  drivers/gpu/drm/amd/scheduler/gpu_scheduler.h |  3 +++
  2 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/amd/scheduler/gpu_scheduler.c 
b/drivers/gpu/drm/amd/scheduler/gpu_scheduler.c
index 38cea6f..0166620 100644
--- a/drivers/gpu/drm/amd/scheduler/gpu_scheduler.c
+++ b/drivers/gpu/drm/amd/scheduler/gpu_scheduler.c
@@ -133,6 +133,7 @@ int amd_sched_entity_init(struct amd_gpu_scheduler *sched,
entity->rq = rq;
entity->sched = sched;
  
+	spin_lock_init(&entity->rq_lock);

spin_lock_init(&entity->queue_lock);
r = kfifo_alloc(&entity->job_queue, jobs * sizeof(void *), GFP_KERNEL);
if (r)
@@ -204,8 +205,6 @@ static bool amd_sched_entity_is_ready(struct 
amd_sched_entity *entity)
  void amd_sched_entity_fini(struct amd_gpu_scheduler *sched,
   struct amd_sched_entity *entity)
  {
-   struct amd_sched_rq *rq = entity->rq;
-
if (!amd_sched_entity_is_initialized(sched, entity))
return;
  
@@ -215,7 +214,8 @@ void amd_sched_entity_fini(struct amd_gpu_scheduler *sched,

*/
wait_event(sched->job_scheduled, amd_sched_entity_is_idle(entity));
  
-	amd_sched_rq_remove_entity(rq, entity);

+   amd_sched_entity_set_rq(entity, NULL);
+
kfifo_free(&entity->job_queue);
  }
  
@@ -236,6 +236,24 @@ static void amd_sched_entity_clear_dep(struct dma_fence *f, struct dma_fence_cb

dma_fence_put(f);
  }
  
+void amd_sched_entity_set_rq(struct amd_sched_entity *entity,

+struct amd_sched_rq *rq)
+{
+   if (entity->rq == rq)
+   return;
+
+   spin_lock(&entity->rq_lock);
+
+   if (entity->rq)
+   amd_sched_rq_remove_entity(entity->rq, entity);
+
+   entity->rq = rq;
+   if (rq)
+   amd_sched_rq_add_entity(rq, entity);
+
+   spin_unlock(&entity->rq_lock);
+}
+
  bool amd_sched_dependency_optimized(struct dma_fence* fence,
struct amd_sched_entity *entity)
  {
@@ -333,7 +351,9 @@ static bool amd_sched_entity_in(struct amd_sched_job 
*sched_job)
/* first job wakes up scheduler */
if (first) {
/* Add the entity to the run queue */
+   spin_lock(&entity->rq_lock);
amd_sched_rq_add_entity(entity->rq, entity);
+   spin_unlock(&entity->rq_lock);
amd_sched_wakeup(sched);
}
return added;
diff --git a/drivers/gpu/drm/amd/scheduler/gpu_scheduler.h 
b/drivers/gpu/drm/amd/scheduler/gpu_scheduler.h
index da040bc..4b528f7 100644
--- a/drivers/gpu/drm/amd/scheduler/gpu_scheduler.h
+++ b/drivers/gpu/drm/amd/scheduler/gpu_scheduler.h
@@ -39,6 +39,7 @@ struct amd_sched_rq;
  struct amd_sched_entity {
struct list_headlist;
struct amd_sched_rq *rq;
+   spinlock_t  rq_lock;
struct amd_gpu_scheduler*sched;
  
  	spinlock_t			queue_lock;

@@ -154,6 +155,8 @@ int amd_sched_entity_init(struct amd_gpu_scheduler *sched,
  void amd_sched_entity_fini(struct amd_gpu_scheduler *sched,
   struct amd_sched_entity *entity);
  void amd_sched_entity_push_job(struct amd_sched_job *sched_job);
+void amd_sched_entity_set_rq(struct amd_sched_entity *entity,
+struct amd_sched_rq *rq);
  
  int amd_sched_fence_slab_init(void);

  void amd_sched_fence_slab_fini(void);



___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH 5/8] drm/amd/sched: allow clients to edit an entity's rq v2

2017-06-26 Thread Andres Rodriguez
This is useful for changing an entity's priority at runtime.

v2: don't modify the order of amd_sched_entity members

Signed-off-by: Andres Rodriguez 
---
 drivers/gpu/drm/amd/scheduler/gpu_scheduler.c | 26 +++---
 drivers/gpu/drm/amd/scheduler/gpu_scheduler.h |  3 +++
 2 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/amd/scheduler/gpu_scheduler.c 
b/drivers/gpu/drm/amd/scheduler/gpu_scheduler.c
index 38cea6f..0166620 100644
--- a/drivers/gpu/drm/amd/scheduler/gpu_scheduler.c
+++ b/drivers/gpu/drm/amd/scheduler/gpu_scheduler.c
@@ -133,6 +133,7 @@ int amd_sched_entity_init(struct amd_gpu_scheduler *sched,
entity->rq = rq;
entity->sched = sched;
 
+   spin_lock_init(&entity->rq_lock);
spin_lock_init(&entity->queue_lock);
r = kfifo_alloc(&entity->job_queue, jobs * sizeof(void *), GFP_KERNEL);
if (r)
@@ -204,8 +205,6 @@ static bool amd_sched_entity_is_ready(struct 
amd_sched_entity *entity)
 void amd_sched_entity_fini(struct amd_gpu_scheduler *sched,
   struct amd_sched_entity *entity)
 {
-   struct amd_sched_rq *rq = entity->rq;
-
if (!amd_sched_entity_is_initialized(sched, entity))
return;
 
@@ -215,7 +214,8 @@ void amd_sched_entity_fini(struct amd_gpu_scheduler *sched,
*/
wait_event(sched->job_scheduled, amd_sched_entity_is_idle(entity));
 
-   amd_sched_rq_remove_entity(rq, entity);
+   amd_sched_entity_set_rq(entity, NULL);
+
kfifo_free(&entity->job_queue);
 }
 
@@ -236,6 +236,24 @@ static void amd_sched_entity_clear_dep(struct dma_fence 
*f, struct dma_fence_cb
dma_fence_put(f);
 }
 
+void amd_sched_entity_set_rq(struct amd_sched_entity *entity,
+struct amd_sched_rq *rq)
+{
+   if (entity->rq == rq)
+   return;
+
+   spin_lock(&entity->rq_lock);
+
+   if (entity->rq)
+   amd_sched_rq_remove_entity(entity->rq, entity);
+
+   entity->rq = rq;
+   if (rq)
+   amd_sched_rq_add_entity(rq, entity);
+
+   spin_unlock(&entity->rq_lock);
+}
+
 bool amd_sched_dependency_optimized(struct dma_fence* fence,
struct amd_sched_entity *entity)
 {
@@ -333,7 +351,9 @@ static bool amd_sched_entity_in(struct amd_sched_job 
*sched_job)
/* first job wakes up scheduler */
if (first) {
/* Add the entity to the run queue */
+   spin_lock(&entity->rq_lock);
amd_sched_rq_add_entity(entity->rq, entity);
+   spin_unlock(&entity->rq_lock);
amd_sched_wakeup(sched);
}
return added;
diff --git a/drivers/gpu/drm/amd/scheduler/gpu_scheduler.h 
b/drivers/gpu/drm/amd/scheduler/gpu_scheduler.h
index da040bc..4b528f7 100644
--- a/drivers/gpu/drm/amd/scheduler/gpu_scheduler.h
+++ b/drivers/gpu/drm/amd/scheduler/gpu_scheduler.h
@@ -39,6 +39,7 @@ struct amd_sched_rq;
 struct amd_sched_entity {
struct list_headlist;
struct amd_sched_rq *rq;
+   spinlock_t  rq_lock;
struct amd_gpu_scheduler*sched;
 
spinlock_t  queue_lock;
@@ -154,6 +155,8 @@ int amd_sched_entity_init(struct amd_gpu_scheduler *sched,
 void amd_sched_entity_fini(struct amd_gpu_scheduler *sched,
   struct amd_sched_entity *entity);
 void amd_sched_entity_push_job(struct amd_sched_job *sched_job);
+void amd_sched_entity_set_rq(struct amd_sched_entity *entity,
+struct amd_sched_rq *rq);
 
 int amd_sched_fence_slab_init(void);
 void amd_sched_fence_slab_fini(void);
-- 
2.9.3

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx