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 spin_lock_init(&entity->rq_lock);
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 entity->sched_list = sched_list;
115 entity->num_sched_list = num_sched_list;
119 static bool drm_sched_entity_is_idle(struct drm_sched_entity *entity)
123 if (list_empty(&entity->list) ||
124 spsc_queue_count(&entity->job_queue) == 0 ||
125 entity->stopped)
131 /* Return true if entity could provide a job. */
132 bool drm_sched_entity_is_ready(struct drm_sched_entity *entity)
134 if (spsc_queue_peek(&entity->job_queue) == NULL)
137 if (READ_ONCE(entity->dependency))
145 * @entity: scheduler entity to check
150 int drm_sched_entity_error(struct drm_sched_entity *entity)
156 fence = rcu_dereference(entity->last_scheduled);
173 /* Signal the scheduler finished fence when the entity in question is killed. */
214 /* Remove the entity from the scheduler and kill all pending jobs */
215 static void drm_sched_entity_kill(struct drm_sched_entity *entity)
220 if (!entity->rq)
223 spin_lock(&entity->rq_lock);
224 entity->stopped = true;
225 drm_sched_rq_remove_entity(entity->rq, entity);
226 spin_unlock(&entity->rq_lock);
228 /* Make sure this entity is not used by the scheduler at the moment */
229 wait_for_completion(&entity->entity_idle);
231 /* The entity is guaranteed to not be used by the scheduler */
232 prev = rcu_dereference_check(entity->last_scheduled, true);
234 while ((job = to_drm_sched_job(spsc_queue_pop(&entity->job_queue)))) {
248 * drm_sched_entity_flush - Flush a context entity
250 * @entity: scheduler entity
254 * waiting, removes the entity from the runqueue and returns an error when the
259 long drm_sched_entity_flush(struct drm_sched_entity *entity, long timeout)
265 if (!entity->rq)
268 sched = entity->rq->sched;
277 drm_sched_entity_is_idle(entity),
281 drm_sched_entity_is_idle(entity));
285 last_user = cmpxchg(&entity->last_user, current->group_leader, NULL);
288 drm_sched_entity_kill(entity);
295 * drm_sched_entity_fini - Destroy a context entity
297 * @entity: scheduler entity
299 * Cleanups up @entity which has been initialized by drm_sched_entity_init().
303 * the entity and signals all jobs with an error code if the process was killed.
305 void drm_sched_entity_fini(struct drm_sched_entity *entity)
309 * them here. Also makes sure that the scheduler won't touch this entity
312 drm_sched_entity_kill(entity);
314 if (entity->dependency) {
315 dma_fence_remove_callback(entity->dependency, &entity->cb);
316 dma_fence_put(entity->dependency);
317 entity->dependency = NULL;
320 dma_fence_put(rcu_dereference_check(entity->last_scheduled, true));
321 RCU_INIT_POINTER(entity->last_scheduled, NULL);
326 * drm_sched_entity_destroy - Destroy a context entity
327 * @entity: scheduler entity
332 void drm_sched_entity_destroy(struct drm_sched_entity *entity)
334 drm_sched_entity_flush(entity, MAX_WAIT_SCHED_ENTITY_Q_EMPTY);
335 drm_sched_entity_fini(entity);
343 struct drm_sched_entity *entity =
346 entity->dependency = NULL;
357 struct drm_sched_entity *entity =
361 drm_sched_wakeup_if_can_queue(entity->rq->sched);
365 * drm_sched_entity_set_priority - Sets priority of the entity
367 * @entity: scheduler entity
370 * Update the priority of runqueus used for the entity.
372 void drm_sched_entity_set_priority(struct drm_sched_entity *entity,
375 spin_lock(&entity->rq_lock);
376 entity->priority = priority;
377 spin_unlock(&entity->rq_lock);
382 * Add a callback to the current dependency of the entity to wake up the
383 * scheduler when the entity becomes available.
385 static bool drm_sched_entity_add_dependency_cb(struct drm_sched_entity *entity)
387 struct drm_gpu_scheduler *sched = entity->rq->sched;
388 struct dma_fence *fence = entity->dependency;
391 if (fence->context == entity->fence_context ||
392 fence->context == entity->fence_context + 1) {
395 * which belongs to the same entity, we can ignore
398 dma_fence_put(entity->dependency);
411 dma_fence_put(entity->dependency);
412 entity->dependency = fence;
413 if (!dma_fence_add_callback(fence, &entity->cb,
422 if (!dma_fence_add_callback(entity->dependency, &entity->cb,
426 dma_fence_put(entity->dependency);
432 struct drm_sched_entity *entity)
447 return job->sched->ops->prepare_job(job, entity);
452 struct drm_sched_job *drm_sched_entity_pop_job(struct drm_sched_entity *entity)
456 sched_job = to_drm_sched_job(spsc_queue_peek(&entity->job_queue));
460 while ((entity->dependency =
461 drm_sched_job_dependency(sched_job, entity))) {
462 trace_drm_sched_job_wait_dep(sched_job, entity->dependency);
464 if (drm_sched_entity_add_dependency_cb(entity))
468 /* skip jobs from entity that marked guilty */
469 if (entity->guilty && atomic_read(entity->guilty))
472 dma_fence_put(rcu_dereference_check(entity->last_scheduled, true));
473 rcu_assign_pointer(entity->last_scheduled,
483 spsc_queue_pop(&entity->job_queue);
486 * Update the entity's location in the min heap according to
492 next = to_drm_sched_job(spsc_queue_peek(&entity->job_queue));
494 drm_sched_rq_update_fifo(entity, next->submit_ts);
498 * removing the job from the entities queue, set the jobs entity pointer
499 * to NULL to prevent any future access of the entity through this job.
501 sched_job->entity = NULL;
506 void drm_sched_entity_select_rq(struct drm_sched_entity *entity)
513 if (!entity->sched_list)
517 if (spsc_queue_count(&entity->job_queue))
528 fence = rcu_dereference_check(entity->last_scheduled, true);
534 spin_lock(&entity->rq_lock);
535 sched = drm_sched_pick_best(entity->sched_list, entity->num_sched_list);
536 rq = sched ? &sched->sched_rq[entity->priority] : NULL;
537 if (rq != entity->rq) {
538 drm_sched_rq_remove_entity(entity->rq, entity);
539 entity->rq = rq;
541 spin_unlock(&entity->rq_lock);
543 if (entity->num_sched_list == 1)
544 entity->sched_list = NULL;
548 * drm_sched_entity_push_job - Submit a job to the entity's job queue
560 struct drm_sched_entity *entity = sched_job->entity;
564 trace_drm_sched_job(sched_job, entity);
565 atomic_inc(entity->rq->sched->score);
566 WRITE_ONCE(entity->last_user, current->group_leader);
569 * After the sched_job is pushed into the entity queue, it may be
574 first = spsc_queue_push(&entity->job_queue, &sched_job->queue_node);
578 /* Add the entity to the run queue */
579 spin_lock(&entity->rq_lock);
580 if (entity->stopped) {
581 spin_unlock(&entity->rq_lock);
583 DRM_ERROR("Trying to push to a killed entity\n");
587 drm_sched_rq_add_entity(entity->rq, entity);
588 spin_unlock(&entity->rq_lock);
591 drm_sched_rq_update_fifo(entity, submit_ts);
593 drm_sched_wakeup_if_can_queue(entity->rq->sched);