Lines Matching refs: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;
75 * It's perfectly valid to initialize an entity without having a valid
79 entity->sched_list = num_sched_list > 1 ? sched_list : NULL;
80 RCU_INIT_POINTER(entity->last_scheduled, NULL);
81 RB_CLEAR_NODE(&entity->rb_tree_node);
90 /* The "priority" of an entity cannot exceed the number of run-queues of a
94 if (entity->priority >= sched_list[0]->num_rqs) {
95 drm_err(sched_list[0], "entity with out-of-bounds priority:%u num_rqs:%u\n",
96 entity->priority, sched_list[0]->num_rqs);
97 entity->priority = max_t(s32, (s32) sched_list[0]->num_rqs - 1,
100 entity->rq = sched_list[0]->sched_rq[entity->priority];
103 init_completion(&entity->entity_idle);
106 complete_all(&entity->entity_idle);
108 spin_lock_init(&entity->rq_lock);
109 spsc_queue_init(&entity->job_queue);
111 atomic_set(&entity->fence_seq, 0);
112 entity->fence_context = dma_fence_context_alloc(2);
119 * drm_sched_entity_modify_sched - Modify sched of an entity
120 * @entity: scheduler entity to init
122 * existing entity->sched_list
125 * Note that this must be called under the same common lock for @entity as
128 * can be pushed to @entity.
130 void drm_sched_entity_modify_sched(struct drm_sched_entity *entity,
136 entity->sched_list = sched_list;
137 entity->num_sched_list = num_sched_list;
141 static bool drm_sched_entity_is_idle(struct drm_sched_entity *entity)
145 if (list_empty(&entity->list) ||
146 spsc_queue_count(&entity->job_queue) == 0 ||
147 entity->stopped)
153 /* Return true if entity could provide a job. */
154 bool drm_sched_entity_is_ready(struct drm_sched_entity *entity)
156 if (spsc_queue_peek(&entity->job_queue) == NULL)
159 if (READ_ONCE(entity->dependency))
167 * @entity: scheduler entity to check
172 int drm_sched_entity_error(struct drm_sched_entity *entity)
178 fence = rcu_dereference(entity->last_scheduled);
195 /* Signal the scheduler finished fence when the entity in question is killed. */
236 /* Remove the entity from the scheduler and kill all pending jobs */
237 static void drm_sched_entity_kill(struct drm_sched_entity *entity)
242 if (!entity->rq)
245 spin_lock(&entity->rq_lock);
246 entity->stopped = true;
247 drm_sched_rq_remove_entity(entity->rq, entity);
248 spin_unlock(&entity->rq_lock);
250 /* Make sure this entity is not used by the scheduler at the moment */
251 wait_for_completion(&entity->entity_idle);
253 /* The entity is guaranteed to not be used by the scheduler */
254 prev = rcu_dereference_check(entity->last_scheduled, true);
256 while ((job = to_drm_sched_job(spsc_queue_pop(&entity->job_queue)))) {
270 * drm_sched_entity_flush - Flush a context entity
272 * @entity: scheduler entity
276 * waiting, removes the entity from the runqueue and returns an error when the
281 long drm_sched_entity_flush(struct drm_sched_entity *entity, long timeout)
287 if (!entity->rq)
290 sched = entity->rq->sched;
299 drm_sched_entity_is_idle(entity),
303 drm_sched_entity_is_idle(entity));
307 last_user = cmpxchg(&entity->last_user, current->group_leader, NULL);
310 drm_sched_entity_kill(entity);
317 * drm_sched_entity_fini - Destroy a context entity
319 * @entity: scheduler entity
321 * Cleanups up @entity which has been initialized by drm_sched_entity_init().
325 * the entity and signals all jobs with an error code if the process was killed.
327 void drm_sched_entity_fini(struct drm_sched_entity *entity)
331 * them here. Also makes sure that the scheduler won't touch this entity
334 drm_sched_entity_kill(entity);
336 if (entity->dependency) {
337 dma_fence_remove_callback(entity->dependency, &entity->cb);
338 dma_fence_put(entity->dependency);
339 entity->dependency = NULL;
342 dma_fence_put(rcu_dereference_check(entity->last_scheduled, true));
343 RCU_INIT_POINTER(entity->last_scheduled, NULL);
348 * drm_sched_entity_destroy - Destroy a context entity
349 * @entity: scheduler entity
354 void drm_sched_entity_destroy(struct drm_sched_entity *entity)
356 drm_sched_entity_flush(entity, MAX_WAIT_SCHED_ENTITY_Q_EMPTY);
357 drm_sched_entity_fini(entity);
365 struct drm_sched_entity *entity =
368 entity->dependency = NULL;
379 struct drm_sched_entity *entity =
383 drm_sched_wakeup(entity->rq->sched, entity);
387 * drm_sched_entity_set_priority - Sets priority of the entity
389 * @entity: scheduler entity
392 * Update the priority of runqueus used for the entity.
394 void drm_sched_entity_set_priority(struct drm_sched_entity *entity,
397 spin_lock(&entity->rq_lock);
398 entity->priority = priority;
399 spin_unlock(&entity->rq_lock);
404 * Add a callback to the current dependency of the entity to wake up the
405 * scheduler when the entity becomes available.
407 static bool drm_sched_entity_add_dependency_cb(struct drm_sched_entity *entity)
409 struct drm_gpu_scheduler *sched = entity->rq->sched;
410 struct dma_fence *fence = entity->dependency;
413 if (fence->context == entity->fence_context ||
414 fence->context == entity->fence_context + 1) {
417 * which belongs to the same entity, we can ignore
420 dma_fence_put(entity->dependency);
433 dma_fence_put(entity->dependency);
434 entity->dependency = fence;
435 if (!dma_fence_add_callback(fence, &entity->cb,
444 if (!dma_fence_add_callback(entity->dependency, &entity->cb,
448 dma_fence_put(entity->dependency);
454 struct drm_sched_entity *entity)
469 return job->sched->ops->prepare_job(job, entity);
474 struct drm_sched_job *drm_sched_entity_pop_job(struct drm_sched_entity *entity)
478 sched_job = to_drm_sched_job(spsc_queue_peek(&entity->job_queue));
482 while ((entity->dependency =
483 drm_sched_job_dependency(sched_job, entity))) {
484 trace_drm_sched_job_wait_dep(sched_job, entity->dependency);
486 if (drm_sched_entity_add_dependency_cb(entity))
490 /* skip jobs from entity that marked guilty */
491 if (entity->guilty && atomic_read(entity->guilty))
494 dma_fence_put(rcu_dereference_check(entity->last_scheduled, true));
495 rcu_assign_pointer(entity->last_scheduled,
505 spsc_queue_pop(&entity->job_queue);
508 * Update the entity's location in the min heap according to
514 next = to_drm_sched_job(spsc_queue_peek(&entity->job_queue));
516 drm_sched_rq_update_fifo(entity, next->submit_ts);
520 * removing the job from the entities queue, set the jobs entity pointer
521 * to NULL to prevent any future access of the entity through this job.
523 sched_job->entity = NULL;
528 void drm_sched_entity_select_rq(struct drm_sched_entity *entity)
535 if (!entity->sched_list)
539 if (spsc_queue_count(&entity->job_queue))
550 fence = rcu_dereference_check(entity->last_scheduled, true);
556 spin_lock(&entity->rq_lock);
557 sched = drm_sched_pick_best(entity->sched_list, entity->num_sched_list);
558 rq = sched ? sched->sched_rq[entity->priority] : NULL;
559 if (rq != entity->rq) {
560 drm_sched_rq_remove_entity(entity->rq, entity);
561 entity->rq = rq;
563 spin_unlock(&entity->rq_lock);
565 if (entity->num_sched_list == 1)
566 entity->sched_list = NULL;
570 * drm_sched_entity_push_job - Submit a job to the entity's job queue
582 struct drm_sched_entity *entity = sched_job->entity;
586 trace_drm_sched_job(sched_job, entity);
587 atomic_inc(entity->rq->sched->score);
588 WRITE_ONCE(entity->last_user, current->group_leader);
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(entity->rq->sched, entity);