Lines Matching full:cs
23 * enum hl_cs_wait_status - cs wait status
24 * @CS_WAIT_STATUS_BUSY: cs was not completed yet
25 * @CS_WAIT_STATUS_COMPLETED: cs completed
26 * @CS_WAIT_STATUS_GONE: cs completed but fence is already gone
47 * CS outcome store supports the following operations: in hl_push_cs_outcome()
48 * push outcome - store a recent CS outcome in the store in hl_push_cs_outcome()
49 * pop outcome - retrieve a SPECIFIC (by seq) CS outcome from the store in hl_push_cs_outcome()
52 * a single CS outcome. in hl_push_cs_outcome()
72 dev_dbg(hdev->dev, "CS %llu outcome was lost\n", node->seq); in hl_push_cs_outcome()
232 void cs_get(struct hl_cs *cs) in cs_get() argument
234 kref_get(&cs->refcount); in cs_get()
237 static int cs_get_unless_zero(struct hl_cs *cs) in cs_get_unless_zero() argument
239 return kref_get_unless_zero(&cs->refcount); in cs_get_unless_zero()
242 static void cs_put(struct hl_cs *cs) in cs_put() argument
244 kref_put(&cs->refcount, cs_do_release); in cs_put()
259 bool cs_needs_completion(struct hl_cs *cs) in cs_needs_completion() argument
261 /* In case this is a staged CS, only the last CS in sequence should in cs_needs_completion()
262 * get a completion, any non staged CS will always get a completion in cs_needs_completion()
264 if (cs->staged_cs && !cs->staged_last) in cs_needs_completion()
270 bool cs_needs_timeout(struct hl_cs *cs) in cs_needs_timeout() argument
272 /* In case this is a staged CS, only the first CS in sequence should in cs_needs_timeout()
273 * get a timeout, any non staged CS will always get a timeout in cs_needs_timeout()
275 if (cs->staged_cs && !cs->staged_first) in cs_needs_timeout()
304 parser.ctx_id = job->cs->ctx->asid; in cs_parser()
305 parser.cs_sequence = job->cs->sequence; in cs_parser()
316 parser.completion = cs_needs_completion(job->cs); in cs_parser()
331 * won't be accessed again for this CS in cs_parser()
345 struct hl_cs *cs = job->cs; in hl_complete_job() local
375 spin_lock(&cs->job_lock); in hl_complete_job()
377 spin_unlock(&cs->job_lock); in hl_complete_job()
381 /* We decrement reference only for a CS that gets completion in hl_complete_job()
382 * because the reference was incremented only for this kind of CS in hl_complete_job()
385 * In staged submission, only the last CS marked as 'staged_last' in hl_complete_job()
387 * As for all the rest CS's in the staged submission which do not get in hl_complete_job()
388 * completion, their CS reference will be decremented by the in hl_complete_job()
389 * 'staged_last' CS during the CS release flow. in hl_complete_job()
390 * All relevant PQ CI counters will be incremented during the CS release in hl_complete_job()
393 if (cs_needs_completion(cs) && in hl_complete_job()
396 /* In CS based completions, the timestamp is already available, in hl_complete_job()
400 cs->completion_timestamp = job->timestamp; in hl_complete_job()
402 cs_put(cs); in hl_complete_job()
409 * hl_staged_cs_find_first - locate the first CS in this staged submission
416 * Find and return a CS pointer with the given sequence
420 struct hl_cs *cs; in hl_staged_cs_find_first() local
422 list_for_each_entry_reverse(cs, &hdev->cs_mirror_list, mirror_node) in hl_staged_cs_find_first()
423 if (cs->staged_cs && cs->staged_first && in hl_staged_cs_find_first()
424 cs->sequence == cs_seq) in hl_staged_cs_find_first()
425 return cs; in hl_staged_cs_find_first()
431 * is_staged_cs_last_exists - returns true if the last CS in sequence exists
434 * @cs: staged submission member
437 bool is_staged_cs_last_exists(struct hl_device *hdev, struct hl_cs *cs) in is_staged_cs_last_exists() argument
441 last_entry = list_last_entry(&cs->staged_cs_node, struct hl_cs, in is_staged_cs_last_exists()
451 * staged_cs_get - get CS reference if this CS is a part of a staged CS
454 * @cs: current CS
457 * Increment CS reference for every CS in this staged submission except for
458 * the CS which get completion.
460 static void staged_cs_get(struct hl_device *hdev, struct hl_cs *cs) in staged_cs_get() argument
462 /* Only the last CS in this staged submission will get a completion. in staged_cs_get()
463 * We must increment the reference for all other CS's in this in staged_cs_get()
467 if (!cs->staged_last) in staged_cs_get()
468 cs_get(cs); in staged_cs_get()
472 * staged_cs_put - put a CS in case it is part of staged submission
475 * @cs: CS to put
477 * This function decrements a CS reference (for a non completion CS)
479 static void staged_cs_put(struct hl_device *hdev, struct hl_cs *cs) in staged_cs_put() argument
481 /* We release all CS's in a staged submission except the last in staged_cs_put()
482 * CS which we have never incremented its reference. in staged_cs_put()
484 if (!cs_needs_completion(cs)) in staged_cs_put()
485 cs_put(cs); in staged_cs_put()
488 static void cs_handle_tdr(struct hl_device *hdev, struct hl_cs *cs) in cs_handle_tdr() argument
492 if (!cs_needs_timeout(cs)) in cs_handle_tdr()
498 * Hence, we choose the CS that reaches this function first which is in cs_handle_tdr()
499 * the CS marked as 'staged_last'. in cs_handle_tdr()
500 * In case single staged cs was submitted which has both first and last in cs_handle_tdr()
502 * removed the cs node from the list before getting here, in cs_handle_tdr()
503 * in such cases just continue with the cs to cancel it's TDR work. in cs_handle_tdr()
505 if (cs->staged_cs && cs->staged_last) { in cs_handle_tdr()
506 first_cs = hl_staged_cs_find_first(hdev, cs->staged_sequence); in cs_handle_tdr()
508 cs = first_cs; in cs_handle_tdr()
513 /* Don't cancel TDR in case this CS was timedout because we might be in cs_handle_tdr()
516 if (cs->timedout || hdev->timeout_jiffies == MAX_SCHEDULE_TIMEOUT) in cs_handle_tdr()
519 if (cs->tdr_active) in cs_handle_tdr()
520 cancel_delayed_work_sync(&cs->work_tdr); in cs_handle_tdr()
524 /* queue TDR for next CS */ in cs_handle_tdr()
540 * force_complete_multi_cs - complete all contexts that wait on multi-CS
561 * multi-cS. in force_complete_multi_cs()
566 "multi-CS completion context %d still waiting when calling force completion\n", in force_complete_multi_cs()
574 * complete_multi_cs - complete all waiting entities on multi-CS
577 * @cs: CS structure
579 * with the completed CS.
581 * - a completed CS worked on stream master QID 4, multi CS completion
584 * - a completed CS worked on stream master QID 4, multi CS completion
588 static void complete_multi_cs(struct hl_device *hdev, struct hl_cs *cs) in complete_multi_cs() argument
590 struct hl_fence *fence = cs->fence; in complete_multi_cs()
593 /* in case of multi CS check for completion only for the first CS */ in complete_multi_cs()
594 if (cs->staged_cs && !cs->staged_first) in complete_multi_cs()
609 * 2. the completed CS has at least one overlapping stream in complete_multi_cs()
615 /* extract the timestamp only of first completed CS */ in complete_multi_cs()
625 * least one CS will be set as completed when polling in complete_multi_cs()
633 /* In case CS completed without mcs completion initialized */ in complete_multi_cs()
638 struct hl_cs *cs, in cs_release_sob_reset_handler() argument
641 /* Skip this handler if the cs wasn't submitted, to avoid putting in cs_release_sob_reset_handler()
645 if (!hl_cs_cmpl->hw_sob || !cs->submitted) in cs_release_sob_reset_handler()
651 * we get refcount upon reservation of signals or signal/wait cs for the in cs_release_sob_reset_handler()
652 * hw_sob object, and need to put it when the first staged cs in cs_release_sob_reset_handler()
653 * (which contains the encaps signals) or cs signal/wait is completed. in cs_release_sob_reset_handler()
660 "CS 0x%llx type %d finished, sob_id: %d, sob_val: %u\n", in cs_release_sob_reset_handler()
678 struct hl_cs *cs = container_of(ref, struct hl_cs, refcount); in cs_do_release() local
679 struct hl_device *hdev = cs->ctx->hdev; in cs_do_release()
682 container_of(cs->fence, struct hl_cs_compl, base_fence); in cs_do_release()
684 cs->completed = true; in cs_do_release()
688 * finished, because each one of them took refcnt to CS, we still in cs_do_release()
690 * will have leaked memory and what's worse, the CS object (and in cs_do_release()
694 list_for_each_entry_safe(job, tmp, &cs->job_list, cs_node) in cs_do_release()
697 if (!cs->submitted) { in cs_do_release()
699 * In case the wait for signal CS was submitted, the fence put in cs_do_release()
703 if (cs->type == CS_TYPE_WAIT || in cs_do_release()
704 cs->type == CS_TYPE_COLLECTIVE_WAIT) in cs_do_release()
705 hl_fence_put(cs->signal_fence); in cs_do_release()
711 hl_hw_queue_update_ci(cs); in cs_do_release()
713 /* remove CS from CS mirror list */ in cs_do_release()
715 list_del_init(&cs->mirror_node); in cs_do_release()
718 cs_handle_tdr(hdev, cs); in cs_do_release()
720 if (cs->staged_cs) { in cs_do_release()
721 /* the completion CS decrements reference for the entire in cs_do_release()
724 if (cs->staged_last) { in cs_do_release()
728 &cs->staged_cs_node, staged_cs_node) in cs_do_release()
732 /* A staged CS will be a member in the list only after it in cs_do_release()
736 if (cs->submitted) { in cs_do_release()
738 list_del(&cs->staged_cs_node); in cs_do_release()
742 /* decrement refcount to handle when first staged cs in cs_do_release()
750 if ((cs->type == CS_TYPE_WAIT || cs->type == CS_TYPE_COLLECTIVE_WAIT) && cs->encaps_signals) in cs_do_release()
751 kref_put(&cs->encaps_sig_hdl->refcount, hl_encaps_release_handle_and_put_ctx); in cs_do_release()
757 hl_debugfs_remove_cs(cs); in cs_do_release()
759 hdev->shadow_cs_queue[cs->sequence & (hdev->asic_prop.max_pending_cs - 1)] = NULL; in cs_do_release()
765 if (cs->timedout) in cs_do_release()
766 cs->fence->error = -ETIMEDOUT; in cs_do_release()
767 else if (cs->aborted) in cs_do_release()
768 cs->fence->error = -EIO; in cs_do_release()
769 else if (!cs->submitted) in cs_do_release()
770 cs->fence->error = -EBUSY; in cs_do_release()
772 if (unlikely(cs->skip_reset_on_timeout)) { in cs_do_release()
775 cs->sequence, in cs_do_release()
776 div_u64(jiffies - cs->submission_time_jiffies, HZ)); in cs_do_release()
779 if (cs->timestamp) { in cs_do_release()
780 cs->fence->timestamp = cs->completion_timestamp; in cs_do_release()
781 hl_push_cs_outcome(hdev, &cs->ctx->outcome_store, cs->sequence, in cs_do_release()
782 cs->fence->timestamp, cs->fence->error); in cs_do_release()
785 hl_ctx_put(cs->ctx); in cs_do_release()
787 complete_all(&cs->fence->completion); in cs_do_release()
788 complete_multi_cs(hdev, cs); in cs_do_release()
790 cs_release_sob_reset_handler(hdev, cs, hl_cs_cmpl); in cs_do_release()
792 hl_fence_put(cs->fence); in cs_do_release()
794 kfree(cs->jobs_in_queue_cnt); in cs_do_release()
795 kfree(cs); in cs_do_release()
800 struct hl_cs *cs = container_of(work, struct hl_cs, work_tdr.work); in cs_timedout() local
807 skip_reset_on_timeout = cs->skip_reset_on_timeout; in cs_timedout()
809 rc = cs_get_unless_zero(cs); in cs_timedout()
813 if ((!cs->submitted) || (cs->completed)) { in cs_timedout()
814 cs_put(cs); in cs_timedout()
818 hdev = cs->ctx->hdev; in cs_timedout()
826 /* Mark the CS is timed out so we won't try to cancel its TDR */ in cs_timedout()
827 cs->timedout = true; in cs_timedout()
830 /* Save only the first CS timeout parameters */ in cs_timedout()
834 hdev->captured_err_info.cs_timeout.seq = cs->sequence; in cs_timedout()
840 switch (cs->type) { in cs_timedout()
844 cs->sequence, timeout_sec); in cs_timedout()
850 cs->sequence, timeout_sec); in cs_timedout()
856 cs->sequence, timeout_sec); in cs_timedout()
862 cs->sequence, timeout_sec); in cs_timedout()
870 cs_put(cs); in cs_timedout()
887 struct hl_cs *cs; in allocate_cs() local
892 cs = kzalloc(sizeof(*cs), GFP_ATOMIC); in allocate_cs()
893 if (!cs) in allocate_cs()
894 cs = kzalloc(sizeof(*cs), GFP_KERNEL); in allocate_cs()
896 if (!cs) { in allocate_cs()
905 cs->ctx = ctx; in allocate_cs()
906 cs->submitted = false; in allocate_cs()
907 cs->completed = false; in allocate_cs()
908 cs->type = cs_type; in allocate_cs()
909 cs->timestamp = !!(flags & HL_CS_FLAGS_TIMESTAMP); in allocate_cs()
910 cs->encaps_signals = !!(flags & HL_CS_FLAGS_ENCAP_SIGNALS); in allocate_cs()
911 cs->timeout_jiffies = timeout; in allocate_cs()
912 cs->skip_reset_on_timeout = in allocate_cs()
915 cs->submission_time_jiffies = jiffies; in allocate_cs()
916 INIT_LIST_HEAD(&cs->job_list); in allocate_cs()
917 INIT_DELAYED_WORK(&cs->work_tdr, cs_timedout); in allocate_cs()
918 kref_init(&cs->refcount); in allocate_cs()
919 spin_lock_init(&cs->job_lock); in allocate_cs()
932 cs->jobs_in_queue_cnt = kcalloc(hdev->asic_prop.max_queues, in allocate_cs()
933 sizeof(*cs->jobs_in_queue_cnt), GFP_ATOMIC); in allocate_cs()
934 if (!cs->jobs_in_queue_cnt) in allocate_cs()
935 cs->jobs_in_queue_cnt = kcalloc(hdev->asic_prop.max_queues, in allocate_cs()
936 sizeof(*cs->jobs_in_queue_cnt), GFP_KERNEL); in allocate_cs()
938 if (!cs->jobs_in_queue_cnt) { in allocate_cs()
946 cs_cmpl->type = cs->type; in allocate_cs()
948 cs->fence = &cs_cmpl->base_fence; in allocate_cs()
961 * This causes a deadlock because this CS will never be in allocate_cs()
962 * completed as it depends on future CS's for completion. in allocate_cs()
966 "Staged CS %llu deadlock due to lack of resources", in allocate_cs()
970 "Rejecting CS because of too many in-flights CS\n"); in allocate_cs()
980 cs->sequence = cs_cmpl->cs_seq; in allocate_cs()
993 *cs_new = cs; in allocate_cs()
999 kfree(cs->jobs_in_queue_cnt); in allocate_cs()
1003 kfree(cs); in allocate_cs()
1008 static void cs_rollback(struct hl_device *hdev, struct hl_cs *cs) in cs_rollback() argument
1012 staged_cs_put(hdev, cs); in cs_rollback()
1014 list_for_each_entry_safe(job, tmp, &cs->job_list, cs_node) in cs_rollback()
1022 * Release reserved encapsulated signals which weren't un-reserved, or for which a CS with
1023 * encapsulated signals wasn't submitted and thus weren't released as part of CS roll-back.
1049 struct hl_cs *cs, *tmp; in hl_cs_rollback_all() local
1054 /* flush all completions before iterating over the CS mirror list in in hl_cs_rollback_all()
1063 /* Make sure we don't have leftovers in the CS mirror list */ in hl_cs_rollback_all()
1064 list_for_each_entry_safe(cs, tmp, &hdev->cs_mirror_list, mirror_node) { in hl_cs_rollback_all()
1065 cs_get(cs); in hl_cs_rollback_all()
1066 cs->aborted = true; in hl_cs_rollback_all()
1067 dev_warn_ratelimited(hdev->dev, "Killing CS %d.%llu\n", in hl_cs_rollback_all()
1068 cs->ctx->asid, cs->sequence); in hl_cs_rollback_all()
1069 cs_rollback(hdev, cs); in hl_cs_rollback_all()
1070 cs_put(cs); in hl_cs_rollback_all()
1127 struct hl_cs *cs; in force_complete_cs() local
1131 list_for_each_entry(cs, &hdev->cs_mirror_list, mirror_node) { in force_complete_cs()
1132 cs->fence->error = -EIO; in force_complete_cs()
1133 complete_all(&cs->fence->completion); in force_complete_cs()
1149 struct hl_cs *cs = job->cs; in job_wq_completion() local
1150 struct hl_device *hdev = cs->ctx->hdev; in job_wq_completion()
1158 struct hl_cs *cs = container_of(work, struct hl_cs, finish_work); in cs_completion() local
1159 struct hl_device *hdev = cs->ctx->hdev; in cs_completion()
1162 list_for_each_entry_safe(job, tmp, &cs->job_list, cs_node) in cs_completion()
1169 struct hl_cs *cs; in hl_get_active_cs_num() local
1173 list_for_each_entry(cs, &hdev->cs_mirror_list, mirror_node) in hl_get_active_cs_num()
1174 if (!cs->completed) in hl_get_active_cs_num()
1356 "CS type flags are mutually exclusive, context %d\n", in hl_cs_sanity_checks()
1368 dev_err(hdev->dev, "Sync stream CS is not supported\n"); in hl_cs_sanity_checks()
1374 dev_err(hdev->dev, "Got execute CS with 0 chunks, context %d\n", ctx->asid); in hl_cs_sanity_checks()
1379 "Sync stream CS mandates one chunk only, context %d\n", in hl_cs_sanity_checks()
1418 dev_err(hdev->dev, "Failed to copy cs chunk array from user\n"); in hl_cs_copy_chunk_array()
1426 static int cs_staged_submission(struct hl_device *hdev, struct hl_cs *cs, in cs_staged_submission() argument
1433 cs->staged_last = !!(flags & HL_CS_FLAGS_STAGED_SUBMISSION_LAST); in cs_staged_submission()
1434 cs->staged_first = !!(flags & HL_CS_FLAGS_STAGED_SUBMISSION_FIRST); in cs_staged_submission()
1436 if (cs->staged_first) { in cs_staged_submission()
1437 /* Staged CS sequence is the first CS sequence */ in cs_staged_submission()
1438 INIT_LIST_HEAD(&cs->staged_cs_node); in cs_staged_submission()
1439 cs->staged_sequence = cs->sequence; in cs_staged_submission()
1441 if (cs->encaps_signals) in cs_staged_submission()
1442 cs->encaps_sig_hdl_id = encaps_signal_handle; in cs_staged_submission()
1447 cs->staged_sequence = sequence; in cs_staged_submission()
1450 /* Increment CS reference if needed */ in cs_staged_submission()
1451 staged_cs_get(hdev, cs); in cs_staged_submission()
1453 cs->staged_cs = true; in cs_staged_submission()
1480 struct hl_cs *cs; in cs_ioctl_default() local
1502 staged_mid ? user_sequence : ULLONG_MAX, &cs, flags, in cs_ioctl_default()
1507 *cs_seq = cs->sequence; in cs_ioctl_default()
1509 hl_debugfs_add_cs(cs); in cs_ioctl_default()
1511 rc = cs_staged_submission(hdev, cs, user_sequence, flags, in cs_ioctl_default()
1517 * rather than the internal CS sequence in cs_ioctl_default()
1519 if (cs->staged_cs) in cs_ioctl_default()
1520 *cs_seq = cs->staged_sequence; in cs_ioctl_default()
1522 /* Validate ALL the CS chunks before submitting the CS */ in cs_ioctl_default()
1555 * queues of this CS in cs_ioctl_default()
1580 job->cs = cs; in cs_ioctl_default()
1585 cs->jobs_in_queue_cnt[job->hw_queue_id]++; in cs_ioctl_default()
1586 cs->jobs_cnt++; in cs_ioctl_default()
1588 list_add_tail(&job->cs_node, &cs->job_list); in cs_ioctl_default()
1591 * Increment CS reference. When CS reference is 0, CS is in cs_ioctl_default()
1596 if (cs_needs_completion(cs) && in cs_ioctl_default()
1599 cs_get(cs); in cs_ioctl_default()
1608 "Failed to parse JOB %d.%llu.%d, err %d, rejecting the CS\n", in cs_ioctl_default()
1609 cs->ctx->asid, cs->sequence, job->id, rc); in cs_ioctl_default()
1614 /* We allow a CS with any queue type combination as long as it does in cs_ioctl_default()
1617 if (int_queues_only && cs_needs_completion(cs)) { in cs_ioctl_default()
1621 "Reject CS %d.%llu since it contains only internal queues jobs and needs completion\n", in cs_ioctl_default()
1622 cs->ctx->asid, cs->sequence); in cs_ioctl_default()
1628 INIT_WORK(&cs->finish_work, cs_completion); in cs_ioctl_default()
1631 * store the (external/HW queues) streams used by the CS in the in cs_ioctl_default()
1632 * fence object for multi-CS completion in cs_ioctl_default()
1635 cs->fence->stream_master_qid_map = stream_master_qid_map; in cs_ioctl_default()
1637 rc = hl_hw_queue_schedule_cs(cs); in cs_ioctl_default()
1641 "Failed to submit CS %d.%llu to H/W queues, error %d\n", in cs_ioctl_default()
1642 cs->ctx->asid, cs->sequence, rc); in cs_ioctl_default()
1646 *signal_initial_sob_count = cs->initial_sob_count; in cs_ioctl_default()
1655 cs_rollback(hdev, cs); in cs_ioctl_default()
1659 /* We finished with the CS in this function, so put the ref */ in cs_ioctl_default()
1660 cs_put(cs); in cs_ioctl_default()
1689 "Failed to switch to context %d, rejecting CS! %d\n", in hl_cs_ctx_switch()
1714 "Need to run restore phase but restore CS is empty\n"); in hl_cs_ctx_switch()
1725 "Failed to submit restore CS for context %d (%d)\n", in hl_cs_ctx_switch()
1744 "Restore CS for context %d failed to complete %d\n", in hl_cs_ctx_switch()
1779 * @hw_sob: the H/W SOB used in this signal CS.
1836 * for the reservation or the next signal cs. in hl_cs_signal_sob_wraparound_handler()
1837 * we do it here, and for both encaps and regular signal cs in hl_cs_signal_sob_wraparound_handler()
1841 * in addition, if we have combination of cs signal and in hl_cs_signal_sob_wraparound_handler()
1843 * no more reservations and only signal cs keep coming, in hl_cs_signal_sob_wraparound_handler()
1885 "Wait for signal CS supports only one signal CS seq\n"); in cs_ioctl_extract_signal_seq()
1924 struct hl_ctx *ctx, struct hl_cs *cs, in cs_ioctl_signal_wait_create_jobs() argument
1942 if (cs->type == CS_TYPE_WAIT) in cs_ioctl_signal_wait_create_jobs()
1956 job->cs = cs; in cs_ioctl_signal_wait_create_jobs()
1962 if ((cs->type == CS_TYPE_WAIT || cs->type == CS_TYPE_COLLECTIVE_WAIT) in cs_ioctl_signal_wait_create_jobs()
1963 && cs->encaps_signals) in cs_ioctl_signal_wait_create_jobs()
1976 cs_get(cs); in cs_ioctl_signal_wait_create_jobs()
1978 cs->jobs_in_queue_cnt[job->hw_queue_id]++; in cs_ioctl_signal_wait_create_jobs()
1979 cs->jobs_cnt++; in cs_ioctl_signal_wait_create_jobs()
1981 list_add_tail(&job->cs_node, &cs->job_list); in cs_ioctl_signal_wait_create_jobs()
2202 struct hl_cs *cs; in cs_ioctl_signal_wait() local
2274 /* check if cs sequence has encapsulated in cs_ioctl_signal_wait()
2285 * needed when multiple wait cs are used with offset in cs_ioctl_signal_wait()
2300 /* treat as signal CS already finished */ in cs_ioctl_signal_wait()
2323 "Failed to get signal CS with seq 0x%llx\n", in cs_ioctl_signal_wait()
2330 /* signal CS already finished */ in cs_ioctl_signal_wait()
2347 "CS seq 0x%llx is not of a signal/encaps-signal CS\n", in cs_ioctl_signal_wait()
2355 /* signal CS already finished */ in cs_ioctl_signal_wait()
2362 rc = allocate_cs(hdev, ctx, cs_type, ULLONG_MAX, &cs, flags, timeout); in cs_ioctl_signal_wait()
2371 * Save the signal CS fence for later initialization right before in cs_ioctl_signal_wait()
2372 * hanging the wait CS on the queue. in cs_ioctl_signal_wait()
2373 * for encaps signals case, we save the cs sequence and handle pointer in cs_ioctl_signal_wait()
2377 cs->signal_fence = sig_fence; in cs_ioctl_signal_wait()
2382 if (cs->encaps_signals) in cs_ioctl_signal_wait()
2383 cs->encaps_sig_hdl = encaps_sig_hdl; in cs_ioctl_signal_wait()
2386 hl_debugfs_add_cs(cs); in cs_ioctl_signal_wait()
2388 *cs_seq = cs->sequence; in cs_ioctl_signal_wait()
2391 rc = cs_ioctl_signal_wait_create_jobs(hdev, ctx, cs, q_type, in cs_ioctl_signal_wait()
2395 cs, q_idx, collective_engine_id, in cs_ioctl_signal_wait()
2407 INIT_WORK(&cs->finish_work, cs_completion); in cs_ioctl_signal_wait()
2409 rc = hl_hw_queue_schedule_cs(cs); in cs_ioctl_signal_wait()
2411 /* In case wait cs failed here, it means the signal cs in cs_ioctl_signal_wait()
2419 "Failed to submit CS %d.%llu to H/W queues, error %d\n", in cs_ioctl_signal_wait()
2420 ctx->asid, cs->sequence, rc); in cs_ioctl_signal_wait()
2424 *signal_sob_addr_offset = cs->sob_addr_offset; in cs_ioctl_signal_wait()
2425 *signal_initial_sob_count = cs->initial_sob_count; in cs_ioctl_signal_wait()
2433 cs_rollback(hdev, cs); in cs_ioctl_signal_wait()
2437 /* We finished with the CS in this function, so put the ref */ in cs_ioctl_signal_wait()
2438 cs_put(cs); in cs_ioctl_signal_wait()
2567 /* In case this is a staged CS, user should supply the CS sequence */ in hl_cs_ioctl()
2654 "Can't wait on CS %llu because current CS is at seq %llu\n", in hl_wait_for_fence()
2662 "Can't wait on seq %llu because current CS is at seq %llu (Fence is gone)\n", in hl_wait_for_fence()
2705 * hl_cs_poll_fences - iterate CS fences to check for CS completion
2707 * @mcs_data: multi-CS internal data
2708 * @mcs_compl: multi-CS completion structure
2712 * The function iterates on all CS sequence in the list and set bit in
2713 * completion_bitmap for each completed CS.
2716 * completion to the multi-CS context.
2737 * 1. CS will complete the multi-CS prior clearing the completion. in which in hl_cs_poll_fences()
2738 * case the fence iteration is guaranteed to catch the CS completion. in hl_cs_poll_fences()
2755 * In order to prevent case where we wait until timeout even though a CS associated in hl_cs_poll_fences()
2756 * with the multi-CS actually completed we do things in the below order: in hl_cs_poll_fences()
2757 * 1. for each fence set it's QID map in the multi-CS completion QID map. This way in hl_cs_poll_fences()
2758 * any CS can, potentially, complete the multi CS for the specific QID (note in hl_cs_poll_fences()
2761 * 2. only after allowing multi-CS completion for the specific QID we check whether in hl_cs_poll_fences()
2762 * the specific CS already completed (and thus the wait for completion part will in hl_cs_poll_fences()
2763 * be skipped). if the CS not completed it is guaranteed that completing CS will in hl_cs_poll_fences()
2776 "wait_for_fence error :%d for CS seq %llu\n", in hl_cs_poll_fences()
2783 /* CS did not finished, QID to wait on already stored */ in hl_cs_poll_fences()
2788 * returns to user indicating CS completed before it finished in hl_cs_poll_fences()
2796 * in case multi CS is completed but MCS handling not done in hl_cs_poll_fences()
2797 * we "complete" the multi CS to prevent it from waiting in hl_cs_poll_fences()
2798 * until time-out and the "multi-CS handling done" will have in hl_cs_poll_fences()
2821 * already gone. In this case, CS set as completed but in hl_cs_poll_fences()
2905 * to multi-CS CSs will be set incrementally at a later stage in hl_wait_multi_cs_completion_init()
2915 dev_err(hdev->dev, "no available multi-CS completion structure\n"); in hl_wait_multi_cs_completion_init()
2940 * hl_wait_multi_cs_completion - wait for first CS to complete
2942 * @mcs_data: multi-CS internal data
2967 * hl_multi_cs_completion_init - init array of multi-CS completion structures
2985 * hl_multi_cs_wait_ioctl - implementation of the multi-CS wait ioctl
2988 * @data: pointer to multi-CS wait ioctl in/out args
3012 dev_err(hdev->dev, "Wait for multi CS is not supported\n"); in hl_multi_cs_wait_ioctl()
3030 /* copy CS sequence array from user */ in hl_multi_cs_wait_ioctl()
3034 dev_err(hdev->dev, "Failed to copy multi-cs sequence array from user\n"); in hl_multi_cs_wait_ioctl()
3046 /* initialize the multi-CS internal data */ in hl_multi_cs_wait_ioctl()
3054 /* wait (with timeout) for the first CS to be completed */ in hl_multi_cs_wait_ioctl()
3062 /* poll all CS fences, extract timestamp */ in hl_multi_cs_wait_ioctl()
3066 * skip wait for CS completion when one of the below is true: in hl_multi_cs_wait_ioctl()
3068 * - one or more CS in the list completed in hl_multi_cs_wait_ioctl()
3080 * poll fences once again to update the CS map. in hl_multi_cs_wait_ioctl()
3091 * it got a completion) it either got completed by CS in the multi CS list in hl_multi_cs_wait_ioctl()
3093 * got completed by CS submitted to one of the shared stream master but in hl_multi_cs_wait_ioctl()
3094 * not in the multi CS list (in which case we should wait again but modify in hl_multi_cs_wait_ioctl()
3095 * the timeout and set timestamp as zero to let a CS related to the current in hl_multi_cs_wait_ioctl()
3096 * multi-CS set a new, relevant, timestamp) in hl_multi_cs_wait_ioctl()
3114 "user process got signal while waiting for Multi-CS\n"); in hl_multi_cs_wait_ioctl()
3134 /* update if some CS was gone */ in hl_multi_cs_wait_ioctl()
3157 "user process got signal while waiting for CS handle %llu\n", in hl_cs_wait_ioctl()
3167 "CS %llu has timed-out while user process is waiting for it\n", in hl_cs_wait_ioctl()
3172 "CS %llu has been aborted while user process is waiting for it\n", in hl_cs_wait_ioctl()