Lines Matching defs:entity
37 * drm_sched_entity_init - Init a context entity used by scheduler when
40 * @entity: scheduler entity to init
41 * @priority: priority of the entity
43 * entity can be submitted
48 * Note that the &sched_list must have at least one element to schedule the entity.
54 * An entity is cleaned up by callind drm_sched_entity_fini(). See also
59 int drm_sched_entity_init(struct drm_sched_entity *entity,
65 if (!(entity && sched_list && (num_sched_list == 0 || sched_list[0])))
68 memset(entity, 0, sizeof(struct drm_sched_entity));
69 INIT_LIST_HEAD(&entity->list);
70 entity->rq = NULL;
71 entity->guilty = guilty;
72 entity->num_sched_list = num_sched_list;
73 entity->priority = priority;
74 entity->sched_list = num_sched_list > 1 ? sched_list : NULL;
75 RCU_INIT_POINTER(entity->last_scheduled, NULL);
76 RB_CLEAR_NODE(&entity->rb_tree_node);
79 entity->rq = &sched_list[0]->sched_rq[entity->priority];
81 init_completion(&entity->entity_idle);
84 complete_all(&entity->entity_idle);
86 mtx_init(&entity->rq_lock, IPL_NONE);
87 spsc_queue_init(&entity->job_queue);
89 atomic_set(&entity->fence_seq, 0);
90 entity->fence_context = dma_fence_context_alloc(2);
97 * drm_sched_entity_modify_sched - Modify sched of an entity
98 * @entity: scheduler entity to init
100 * existing entity->sched_list
103 * Note that this must be called under the same common lock for @entity as
106 * can be pushed to @entity.
108 void drm_sched_entity_modify_sched(struct drm_sched_entity *entity,
114 spin_lock(&entity->rq_lock);
115 entity->sched_list = sched_list;
116 entity->num_sched_list = num_sched_list;
117 spin_unlock(&entity->rq_lock);
121 static bool drm_sched_entity_is_idle(struct drm_sched_entity *entity)
125 if (list_empty(&entity->list) ||
126 spsc_queue_count(&entity->job_queue) == 0 ||
127 entity->stopped)
133 /* Return true if entity could provide a job. */
134 bool drm_sched_entity_is_ready(struct drm_sched_entity *entity)
136 if (spsc_queue_peek(&entity->job_queue) == NULL)
139 if (READ_ONCE(entity->dependency))
147 * @entity: scheduler entity to check
152 int drm_sched_entity_error(struct drm_sched_entity *entity)
158 fence = rcu_dereference(entity->last_scheduled);
175 /* Signal the scheduler finished fence when the entity in question is killed. */
216 /* Remove the entity from the scheduler and kill all pending jobs */
217 static void drm_sched_entity_kill(struct drm_sched_entity *entity)
222 if (!entity->rq)
225 spin_lock(&entity->rq_lock);
226 entity->stopped = true;
227 drm_sched_rq_remove_entity(entity->rq, entity);
228 spin_unlock(&entity->rq_lock);
230 /* Make sure this entity is not used by the scheduler at the moment */
231 wait_for_completion(&entity->entity_idle);
233 /* The entity is guaranteed to not be used by the scheduler */
234 prev = rcu_dereference_check(entity->last_scheduled, true);
236 while ((job = to_drm_sched_job(spsc_queue_pop(&entity->job_queue)))) {
250 * drm_sched_entity_flush - Flush a context entity
252 * @entity: scheduler entity
256 * waiting, removes the entity from the runqueue and returns an error when the
261 long drm_sched_entity_flush(struct drm_sched_entity *entity, long timeout)
271 if (!entity->rq)
274 sched = entity->rq->sched;
288 drm_sched_entity_is_idle(entity),
292 drm_sched_entity_is_idle(entity));
297 last_user = cmpxchg(&entity->last_user, current->group_leader, NULL);
301 last_user = cmpxchg(&entity->last_user, curpr, NULL);
306 drm_sched_entity_kill(entity);
313 * drm_sched_entity_fini - Destroy a context entity
315 * @entity: scheduler entity
317 * Cleanups up @entity which has been initialized by drm_sched_entity_init().
321 * the entity and signals all jobs with an error code if the process was killed.
323 void drm_sched_entity_fini(struct drm_sched_entity *entity)
327 * them here. Also makes sure that the scheduler won't touch this entity
330 drm_sched_entity_kill(entity);
332 if (entity->dependency) {
333 dma_fence_remove_callback(entity->dependency, &entity->cb);
334 dma_fence_put(entity->dependency);
335 entity->dependency = NULL;
338 dma_fence_put(rcu_dereference_check(entity->last_scheduled, true));
339 RCU_INIT_POINTER(entity->last_scheduled, NULL);
344 * drm_sched_entity_destroy - Destroy a context entity
345 * @entity: scheduler entity
350 void drm_sched_entity_destroy(struct drm_sched_entity *entity)
352 drm_sched_entity_flush(entity, MAX_WAIT_SCHED_ENTITY_Q_EMPTY);
353 drm_sched_entity_fini(entity);
361 struct drm_sched_entity *entity =
364 entity->dependency = NULL;
375 struct drm_sched_entity *entity =
379 drm_sched_wakeup_if_can_queue(entity->rq->sched);
383 * drm_sched_entity_set_priority - Sets priority of the entity
385 * @entity: scheduler entity
388 * Update the priority of runqueus used for the entity.
390 void drm_sched_entity_set_priority(struct drm_sched_entity *entity,
393 spin_lock(&entity->rq_lock);
394 entity->priority = priority;
395 spin_unlock(&entity->rq_lock);
400 * Add a callback to the current dependency of the entity to wake up the
401 * scheduler when the entity becomes available.
403 static bool drm_sched_entity_add_dependency_cb(struct drm_sched_entity *entity)
405 struct drm_gpu_scheduler *sched = entity->rq->sched;
406 struct dma_fence *fence = entity->dependency;
409 if (fence->context == entity->fence_context ||
410 fence->context == entity->fence_context + 1) {
413 * which belongs to the same entity, we can ignore
416 dma_fence_put(entity->dependency);
429 dma_fence_put(entity->dependency);
430 entity->dependency = fence;
431 if (!dma_fence_add_callback(fence, &entity->cb,
440 if (!dma_fence_add_callback(entity->dependency, &entity->cb,
444 dma_fence_put(entity->dependency);
450 struct drm_sched_entity *entity)
465 return job->sched->ops->prepare_job(job, entity);
470 struct drm_sched_job *drm_sched_entity_pop_job(struct drm_sched_entity *entity)
474 sched_job = to_drm_sched_job(spsc_queue_peek(&entity->job_queue));
478 while ((entity->dependency =
479 drm_sched_job_dependency(sched_job, entity))) {
480 trace_drm_sched_job_wait_dep(sched_job, entity->dependency);
482 if (drm_sched_entity_add_dependency_cb(entity))
486 /* skip jobs from entity that marked guilty */
487 if (entity->guilty && atomic_read(entity->guilty))
490 dma_fence_put(rcu_dereference_check(entity->last_scheduled, true));
491 rcu_assign_pointer(entity->last_scheduled,
501 spsc_queue_pop(&entity->job_queue);
504 * Update the entity's location in the min heap according to
510 next = to_drm_sched_job(spsc_queue_peek(&entity->job_queue));
512 drm_sched_rq_update_fifo(entity, next->submit_ts);
516 * removing the job from the entities queue, set the jobs entity pointer
517 * to NULL to prevent any future access of the entity through this job.
519 sched_job->entity = NULL;
524 void drm_sched_entity_select_rq(struct drm_sched_entity *entity)
531 if (!entity->sched_list)
535 if (spsc_queue_count(&entity->job_queue))
546 fence = rcu_dereference_check(entity->last_scheduled, true);
552 spin_lock(&entity->rq_lock);
553 sched = drm_sched_pick_best(entity->sched_list, entity->num_sched_list);
554 rq = sched ? &sched->sched_rq[entity->priority] : NULL;
555 if (rq != entity->rq) {
556 drm_sched_rq_remove_entity(entity->rq, entity);
557 entity->rq = rq;
559 spin_unlock(&entity->rq_lock);
561 if (entity->num_sched_list == 1)
562 entity->sched_list = NULL;
566 * drm_sched_entity_push_job - Submit a job to the entity's job queue
578 struct drm_sched_entity *entity = sched_job->entity;
582 trace_drm_sched_job(sched_job, entity);
583 atomic_inc(entity->rq->sched->score);
585 WRITE_ONCE(entity->last_user, current->group_leader);
587 WRITE_ONCE(entity->last_user, curproc->p_p);
591 * After the sched_job is pushed into the entity queue, it may be
596 first = spsc_queue_push(&entity->job_queue, &sched_job->queue_node);
600 /* Add the entity to the run queue */
601 spin_lock(&entity->rq_lock);
602 if (entity->stopped) {
603 spin_unlock(&entity->rq_lock);
605 DRM_ERROR("Trying to push to a killed entity\n");
609 drm_sched_rq_add_entity(entity->rq, entity);
610 spin_unlock(&entity->rq_lock);
613 drm_sched_rq_update_fifo(entity, submit_ts);
615 drm_sched_wakeup_if_can_queue(entity->rq->sched);