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
65 * CS outcome store supports the following operations: in hl_push_cs_outcome()
66 * push outcome - store a recent CS outcome in the store in hl_push_cs_outcome()
67 * pop outcome - retrieve a SPECIFIC (by seq) CS outcome from the store in hl_push_cs_outcome()
70 * a single CS outcome. in hl_push_cs_outcome()
90 dev_dbg(hdev->dev, "CS %llu outcome was lost\n", node->seq); in hl_push_cs_outcome()
250 void cs_get(struct hl_cs *cs) in cs_get() argument
252 kref_get(&cs->refcount); in cs_get()
255 static int cs_get_unless_zero(struct hl_cs *cs) in cs_get_unless_zero() argument
257 return kref_get_unless_zero(&cs->refcount); in cs_get_unless_zero()
260 static void cs_put(struct hl_cs *cs) in cs_put() argument
262 kref_put(&cs->refcount, cs_do_release); in cs_put()
277 bool cs_needs_completion(struct hl_cs *cs) in cs_needs_completion() argument
279 /* In case this is a staged CS, only the last CS in sequence should in cs_needs_completion()
280 * get a completion, any non staged CS will always get a completion in cs_needs_completion()
282 if (cs->staged_cs && !cs->staged_last) in cs_needs_completion()
288 bool cs_needs_timeout(struct hl_cs *cs) in cs_needs_timeout() argument
290 /* In case this is a staged CS, only the first CS in sequence should in cs_needs_timeout()
291 * get a timeout, any non staged CS will always get a timeout in cs_needs_timeout()
293 if (cs->staged_cs && !cs->staged_first) in cs_needs_timeout()
322 parser.ctx_id = job->cs->ctx->asid; in cs_parser()
323 parser.cs_sequence = job->cs->sequence; in cs_parser()
334 parser.completion = cs_needs_completion(job->cs); in cs_parser()
349 * won't be accessed again for this CS in cs_parser()
363 struct hl_cs *cs = job->cs; in hl_complete_job() local
393 spin_lock(&cs->job_lock); in hl_complete_job()
395 spin_unlock(&cs->job_lock); in hl_complete_job()
399 /* We decrement reference only for a CS that gets completion in hl_complete_job()
400 * because the reference was incremented only for this kind of CS in hl_complete_job()
403 * In staged submission, only the last CS marked as 'staged_last' in hl_complete_job()
405 * As for all the rest CS's in the staged submission which do not get in hl_complete_job()
406 * completion, their CS reference will be decremented by the in hl_complete_job()
407 * 'staged_last' CS during the CS release flow. in hl_complete_job()
408 * All relevant PQ CI counters will be incremented during the CS release in hl_complete_job()
411 if (cs_needs_completion(cs) && in hl_complete_job()
414 /* In CS based completions, the timestamp is already available, in hl_complete_job()
418 cs->completion_timestamp = job->timestamp; in hl_complete_job()
420 cs_put(cs); in hl_complete_job()
427 * hl_staged_cs_find_first - locate the first CS in this staged submission
434 * Find and return a CS pointer with the given sequence
438 struct hl_cs *cs; in hl_staged_cs_find_first() local
440 list_for_each_entry_reverse(cs, &hdev->cs_mirror_list, mirror_node) in hl_staged_cs_find_first()
441 if (cs->staged_cs && cs->staged_first && in hl_staged_cs_find_first()
442 cs->sequence == cs_seq) in hl_staged_cs_find_first()
443 return cs; in hl_staged_cs_find_first()
449 * is_staged_cs_last_exists - returns true if the last CS in sequence exists
452 * @cs: staged submission member
455 bool is_staged_cs_last_exists(struct hl_device *hdev, struct hl_cs *cs) in is_staged_cs_last_exists() argument
459 last_entry = list_last_entry(&cs->staged_cs_node, struct hl_cs, in is_staged_cs_last_exists()
469 * staged_cs_get - get CS reference if this CS is a part of a staged CS
472 * @cs: current CS
475 * Increment CS reference for every CS in this staged submission except for
476 * the CS which get completion.
478 static void staged_cs_get(struct hl_device *hdev, struct hl_cs *cs) in staged_cs_get() argument
480 /* Only the last CS in this staged submission will get a completion. in staged_cs_get()
481 * We must increment the reference for all other CS's in this in staged_cs_get()
485 if (!cs->staged_last) in staged_cs_get()
486 cs_get(cs); in staged_cs_get()
490 * staged_cs_put - put a CS in case it is part of staged submission
493 * @cs: CS to put
495 * This function decrements a CS reference (for a non completion CS)
497 static void staged_cs_put(struct hl_device *hdev, struct hl_cs *cs) in staged_cs_put() argument
499 /* We release all CS's in a staged submission except the last in staged_cs_put()
500 * CS which we have never incremented its reference. in staged_cs_put()
502 if (!cs_needs_completion(cs)) in staged_cs_put()
503 cs_put(cs); in staged_cs_put()
506 static void cs_handle_tdr(struct hl_device *hdev, struct hl_cs *cs) in cs_handle_tdr() argument
510 if (!cs_needs_timeout(cs)) in cs_handle_tdr()
516 * Hence, we choose the CS that reaches this function first which is in cs_handle_tdr()
517 * the CS marked as 'staged_last'. in cs_handle_tdr()
518 * In case single staged cs was submitted which has both first and last in cs_handle_tdr()
520 * removed the cs node from the list before getting here, in cs_handle_tdr()
521 * in such cases just continue with the cs to cancel it's TDR work. in cs_handle_tdr()
523 if (cs->staged_cs && cs->staged_last) { in cs_handle_tdr()
524 first_cs = hl_staged_cs_find_first(hdev, cs->staged_sequence); in cs_handle_tdr()
526 cs = first_cs; in cs_handle_tdr()
531 /* Don't cancel TDR in case this CS was timedout because we might be in cs_handle_tdr()
534 if (cs->timedout || hdev->timeout_jiffies == MAX_SCHEDULE_TIMEOUT) in cs_handle_tdr()
537 if (cs->tdr_active) in cs_handle_tdr()
538 cancel_delayed_work_sync(&cs->work_tdr); in cs_handle_tdr()
542 /* queue TDR for next CS */ in cs_handle_tdr()
558 * force_complete_multi_cs - complete all contexts that wait on multi-CS
579 * multi-cS. in force_complete_multi_cs()
584 "multi-CS completion context %d still waiting when calling force completion\n", in force_complete_multi_cs()
592 * complete_multi_cs - complete all waiting entities on multi-CS
595 * @cs: CS structure
597 * with the completed CS.
599 * - a completed CS worked on stream master QID 4, multi CS completion
602 * - a completed CS worked on stream master QID 4, multi CS completion
606 static void complete_multi_cs(struct hl_device *hdev, struct hl_cs *cs) in complete_multi_cs() argument
608 struct hl_fence *fence = cs->fence; in complete_multi_cs()
611 /* in case of multi CS check for completion only for the first CS */ in complete_multi_cs()
612 if (cs->staged_cs && !cs->staged_first) in complete_multi_cs()
627 * 2. the completed CS has at least one overlapping stream in complete_multi_cs()
633 /* extract the timestamp only of first completed CS */ in complete_multi_cs()
643 * least one CS will be set as completed when polling in complete_multi_cs()
651 /* In case CS completed without mcs completion initialized */ in complete_multi_cs()
656 struct hl_cs *cs, in cs_release_sob_reset_handler() argument
659 /* Skip this handler if the cs wasn't submitted, to avoid putting in cs_release_sob_reset_handler()
663 if (!hl_cs_cmpl->hw_sob || !cs->submitted) in cs_release_sob_reset_handler()
669 * we get refcount upon reservation of signals or signal/wait cs for the in cs_release_sob_reset_handler()
670 * hw_sob object, and need to put it when the first staged cs in cs_release_sob_reset_handler()
671 * (which contains the encaps signals) or cs signal/wait is completed. in cs_release_sob_reset_handler()
678 "CS 0x%llx type %d finished, sob_id: %d, sob_val: %u\n", in cs_release_sob_reset_handler()
696 struct hl_cs *cs = container_of(ref, struct hl_cs, refcount); in cs_do_release() local
697 struct hl_device *hdev = cs->ctx->hdev; in cs_do_release()
700 container_of(cs->fence, struct hl_cs_compl, base_fence); in cs_do_release()
702 cs->completed = true; in cs_do_release()
706 * finished, because each one of them took refcnt to CS, we still in cs_do_release()
708 * will have leaked memory and what's worse, the CS object (and in cs_do_release()
712 list_for_each_entry_safe(job, tmp, &cs->job_list, cs_node) in cs_do_release()
715 if (!cs->submitted) { in cs_do_release()
717 * In case the wait for signal CS was submitted, the fence put in cs_do_release()
721 if (cs->type == CS_TYPE_WAIT || in cs_do_release()
722 cs->type == CS_TYPE_COLLECTIVE_WAIT) in cs_do_release()
723 hl_fence_put(cs->signal_fence); in cs_do_release()
729 hl_hw_queue_update_ci(cs); in cs_do_release()
731 /* remove CS from CS mirror list */ in cs_do_release()
733 list_del_init(&cs->mirror_node); in cs_do_release()
736 cs_handle_tdr(hdev, cs); in cs_do_release()
738 if (cs->staged_cs) { in cs_do_release()
739 /* the completion CS decrements reference for the entire in cs_do_release()
742 if (cs->staged_last) { in cs_do_release()
746 &cs->staged_cs_node, staged_cs_node) in cs_do_release()
750 /* A staged CS will be a member in the list only after it in cs_do_release()
754 if (cs->submitted) { in cs_do_release()
756 list_del(&cs->staged_cs_node); in cs_do_release()
760 /* decrement refcount to handle when first staged cs in cs_do_release()
768 if ((cs->type == CS_TYPE_WAIT || cs->type == CS_TYPE_COLLECTIVE_WAIT) && cs->encaps_signals) in cs_do_release()
769 kref_put(&cs->encaps_sig_hdl->refcount, hl_encaps_release_handle_and_put_ctx); in cs_do_release()
775 hl_debugfs_remove_cs(cs); in cs_do_release()
777 hdev->shadow_cs_queue[cs->sequence & (hdev->asic_prop.max_pending_cs - 1)] = NULL; in cs_do_release()
783 if (cs->timedout) in cs_do_release()
784 cs->fence->error = -ETIMEDOUT; in cs_do_release()
785 else if (cs->aborted) in cs_do_release()
786 cs->fence->error = -EIO; in cs_do_release()
787 else if (!cs->submitted) in cs_do_release()
788 cs->fence->error = -EBUSY; in cs_do_release()
790 if (unlikely(cs->skip_reset_on_timeout)) { in cs_do_release()
793 cs->sequence, in cs_do_release()
794 div_u64(jiffies - cs->submission_time_jiffies, HZ)); in cs_do_release()
797 if (cs->timestamp) { in cs_do_release()
798 cs->fence->timestamp = cs->completion_timestamp; in cs_do_release()
799 hl_push_cs_outcome(hdev, &cs->ctx->outcome_store, cs->sequence, in cs_do_release()
800 cs->fence->timestamp, cs->fence->error); in cs_do_release()
803 hl_ctx_put(cs->ctx); in cs_do_release()
805 complete_all(&cs->fence->completion); in cs_do_release()
806 complete_multi_cs(hdev, cs); in cs_do_release()
808 cs_release_sob_reset_handler(hdev, cs, hl_cs_cmpl); in cs_do_release()
810 hl_fence_put(cs->fence); in cs_do_release()
812 kfree(cs->jobs_in_queue_cnt); in cs_do_release()
813 kfree(cs); in cs_do_release()
818 struct hl_cs *cs = container_of(work, struct hl_cs, work_tdr.work); in cs_timedout() local
825 skip_reset_on_timeout = cs->skip_reset_on_timeout; in cs_timedout()
827 rc = cs_get_unless_zero(cs); in cs_timedout()
831 if ((!cs->submitted) || (cs->completed)) { in cs_timedout()
832 cs_put(cs); in cs_timedout()
836 hdev = cs->ctx->hdev; in cs_timedout()
844 /* Mark the CS is timed out so we won't try to cancel its TDR */ in cs_timedout()
845 cs->timedout = true; in cs_timedout()
848 /* Save only the first CS timeout parameters */ in cs_timedout()
852 hdev->captured_err_info.cs_timeout.seq = cs->sequence; in cs_timedout()
858 switch (cs->type) { in cs_timedout()
862 cs->sequence, timeout_sec); in cs_timedout()
868 cs->sequence, timeout_sec); in cs_timedout()
874 cs->sequence, timeout_sec); in cs_timedout()
880 cs->sequence, timeout_sec); in cs_timedout()
888 cs_put(cs); in cs_timedout()
905 struct hl_cs *cs; in allocate_cs() local
910 cs = kzalloc(sizeof(*cs), GFP_ATOMIC); in allocate_cs()
911 if (!cs) in allocate_cs()
912 cs = kzalloc(sizeof(*cs), GFP_KERNEL); in allocate_cs()
914 if (!cs) { in allocate_cs()
923 cs->ctx = ctx; in allocate_cs()
924 cs->submitted = false; in allocate_cs()
925 cs->completed = false; in allocate_cs()
926 cs->type = cs_type; in allocate_cs()
927 cs->timestamp = !!(flags & HL_CS_FLAGS_TIMESTAMP); in allocate_cs()
928 cs->encaps_signals = !!(flags & HL_CS_FLAGS_ENCAP_SIGNALS); in allocate_cs()
929 cs->timeout_jiffies = timeout; in allocate_cs()
930 cs->skip_reset_on_timeout = in allocate_cs()
933 cs->submission_time_jiffies = jiffies; in allocate_cs()
934 INIT_LIST_HEAD(&cs->job_list); in allocate_cs()
935 INIT_DELAYED_WORK(&cs->work_tdr, cs_timedout); in allocate_cs()
936 kref_init(&cs->refcount); in allocate_cs()
937 spin_lock_init(&cs->job_lock); in allocate_cs()
950 cs->jobs_in_queue_cnt = kcalloc(hdev->asic_prop.max_queues, in allocate_cs()
951 sizeof(*cs->jobs_in_queue_cnt), GFP_ATOMIC); in allocate_cs()
952 if (!cs->jobs_in_queue_cnt) in allocate_cs()
953 cs->jobs_in_queue_cnt = kcalloc(hdev->asic_prop.max_queues, in allocate_cs()
954 sizeof(*cs->jobs_in_queue_cnt), GFP_KERNEL); in allocate_cs()
956 if (!cs->jobs_in_queue_cnt) { in allocate_cs()
964 cs_cmpl->type = cs->type; in allocate_cs()
966 cs->fence = &cs_cmpl->base_fence; in allocate_cs()
979 * This causes a deadlock because this CS will never be in allocate_cs()
980 * completed as it depends on future CS's for completion. in allocate_cs()
984 "Staged CS %llu deadlock due to lack of resources", in allocate_cs()
988 "Rejecting CS because of too many in-flights CS\n"); in allocate_cs()
998 cs->sequence = cs_cmpl->cs_seq; in allocate_cs()
1011 *cs_new = cs; in allocate_cs()
1017 kfree(cs->jobs_in_queue_cnt); in allocate_cs()
1021 kfree(cs); in allocate_cs()
1026 static void cs_rollback(struct hl_device *hdev, struct hl_cs *cs) in cs_rollback() argument
1030 staged_cs_put(hdev, cs); in cs_rollback()
1032 list_for_each_entry_safe(job, tmp, &cs->job_list, cs_node) in cs_rollback()
1040 * Release reserved encapsulated signals which weren't un-reserved, or for which a CS with
1041 * encapsulated signals wasn't submitted and thus weren't released as part of CS roll-back.
1067 struct hl_cs *cs, *tmp; in hl_cs_rollback_all() local
1072 /* flush all completions before iterating over the CS mirror list in in hl_cs_rollback_all()
1081 /* Make sure we don't have leftovers in the CS mirror list */ in hl_cs_rollback_all()
1082 list_for_each_entry_safe(cs, tmp, &hdev->cs_mirror_list, mirror_node) { in hl_cs_rollback_all()
1083 cs_get(cs); in hl_cs_rollback_all()
1084 cs->aborted = true; in hl_cs_rollback_all()
1085 dev_warn_ratelimited(hdev->dev, "Killing CS %d.%llu\n", in hl_cs_rollback_all()
1086 cs->ctx->asid, cs->sequence); in hl_cs_rollback_all()
1087 cs_rollback(hdev, cs); in hl_cs_rollback_all()
1088 cs_put(cs); in hl_cs_rollback_all()
1148 struct hl_cs *cs; in force_complete_cs() local
1152 list_for_each_entry(cs, &hdev->cs_mirror_list, mirror_node) { in force_complete_cs()
1153 cs->fence->error = -EIO; in force_complete_cs()
1154 complete_all(&cs->fence->completion); in force_complete_cs()
1170 struct hl_cs *cs = job->cs; in job_wq_completion() local
1171 struct hl_device *hdev = cs->ctx->hdev; in job_wq_completion()
1179 struct hl_cs *cs = container_of(work, struct hl_cs, finish_work); in cs_completion() local
1180 struct hl_device *hdev = cs->ctx->hdev; in cs_completion()
1183 list_for_each_entry_safe(job, tmp, &cs->job_list, cs_node) in cs_completion()
1190 struct hl_cs *cs; in hl_get_active_cs_num() local
1194 list_for_each_entry(cs, &hdev->cs_mirror_list, mirror_node) in hl_get_active_cs_num()
1195 if (!cs->completed) in hl_get_active_cs_num()
1376 "CS type flags are mutually exclusive, context %d\n", in hl_cs_sanity_checks()
1388 dev_err(hdev->dev, "Sync stream CS is not supported\n"); in hl_cs_sanity_checks()
1394 dev_err(hdev->dev, "Got execute CS with 0 chunks, context %d\n", ctx->asid); in hl_cs_sanity_checks()
1399 "Sync stream CS mandates one chunk only, context %d\n", in hl_cs_sanity_checks()
1438 dev_err(hdev->dev, "Failed to copy cs chunk array from user\n"); in hl_cs_copy_chunk_array()
1446 static int cs_staged_submission(struct hl_device *hdev, struct hl_cs *cs, in cs_staged_submission() argument
1453 cs->staged_last = !!(flags & HL_CS_FLAGS_STAGED_SUBMISSION_LAST); in cs_staged_submission()
1454 cs->staged_first = !!(flags & HL_CS_FLAGS_STAGED_SUBMISSION_FIRST); in cs_staged_submission()
1456 if (cs->staged_first) { in cs_staged_submission()
1457 /* Staged CS sequence is the first CS sequence */ in cs_staged_submission()
1458 INIT_LIST_HEAD(&cs->staged_cs_node); in cs_staged_submission()
1459 cs->staged_sequence = cs->sequence; in cs_staged_submission()
1461 if (cs->encaps_signals) in cs_staged_submission()
1462 cs->encaps_sig_hdl_id = encaps_signal_handle; in cs_staged_submission()
1467 cs->staged_sequence = sequence; in cs_staged_submission()
1470 /* Increment CS reference if needed */ in cs_staged_submission()
1471 staged_cs_get(hdev, cs); in cs_staged_submission()
1473 cs->staged_cs = true; in cs_staged_submission()
1500 struct hl_cs *cs; in cs_ioctl_default() local
1522 staged_mid ? user_sequence : ULLONG_MAX, &cs, flags, in cs_ioctl_default()
1527 *cs_seq = cs->sequence; in cs_ioctl_default()
1529 hl_debugfs_add_cs(cs); in cs_ioctl_default()
1531 rc = cs_staged_submission(hdev, cs, user_sequence, flags, in cs_ioctl_default()
1537 * rather than the internal CS sequence in cs_ioctl_default()
1539 if (cs->staged_cs) in cs_ioctl_default()
1540 *cs_seq = cs->staged_sequence; in cs_ioctl_default()
1542 /* Validate ALL the CS chunks before submitting the CS */ in cs_ioctl_default()
1575 * queues of this CS in cs_ioctl_default()
1600 job->cs = cs; in cs_ioctl_default()
1605 cs->jobs_in_queue_cnt[job->hw_queue_id]++; in cs_ioctl_default()
1606 cs->jobs_cnt++; in cs_ioctl_default()
1608 list_add_tail(&job->cs_node, &cs->job_list); in cs_ioctl_default()
1611 * Increment CS reference. When CS reference is 0, CS is in cs_ioctl_default()
1616 if (cs_needs_completion(cs) && in cs_ioctl_default()
1619 cs_get(cs); in cs_ioctl_default()
1628 "Failed to parse JOB %d.%llu.%d, err %d, rejecting the CS\n", in cs_ioctl_default()
1629 cs->ctx->asid, cs->sequence, job->id, rc); in cs_ioctl_default()
1634 /* We allow a CS with any queue type combination as long as it does in cs_ioctl_default()
1637 if (int_queues_only && cs_needs_completion(cs)) { in cs_ioctl_default()
1641 "Reject CS %d.%llu since it contains only internal queues jobs and needs completion\n", in cs_ioctl_default()
1642 cs->ctx->asid, cs->sequence); in cs_ioctl_default()
1648 INIT_WORK(&cs->finish_work, cs_completion); in cs_ioctl_default()
1651 * store the (external/HW queues) streams used by the CS in the in cs_ioctl_default()
1652 * fence object for multi-CS completion in cs_ioctl_default()
1655 cs->fence->stream_master_qid_map = stream_master_qid_map; in cs_ioctl_default()
1657 rc = hl_hw_queue_schedule_cs(cs); in cs_ioctl_default()
1661 "Failed to submit CS %d.%llu to H/W queues, error %d\n", in cs_ioctl_default()
1662 cs->ctx->asid, cs->sequence, rc); in cs_ioctl_default()
1666 *signal_initial_sob_count = cs->initial_sob_count; in cs_ioctl_default()
1675 cs_rollback(hdev, cs); in cs_ioctl_default()
1679 /* We finished with the CS in this function, so put the ref */ in cs_ioctl_default()
1680 cs_put(cs); in cs_ioctl_default()
1709 "Failed to switch to context %d, rejecting CS! %d\n", in hl_cs_ctx_switch()
1734 "Need to run restore phase but restore CS is empty\n"); in hl_cs_ctx_switch()
1745 "Failed to submit restore CS for context %d (%d)\n", in hl_cs_ctx_switch()
1759 "Restore CS for context %d failed to complete %d\n", in hl_cs_ctx_switch()
1794 * @hw_sob: the H/W SOB used in this signal CS.
1851 * for the reservation or the next signal cs. in hl_cs_signal_sob_wraparound_handler()
1852 * we do it here, and for both encaps and regular signal cs in hl_cs_signal_sob_wraparound_handler()
1856 * in addition, if we have combination of cs signal and in hl_cs_signal_sob_wraparound_handler()
1858 * no more reservations and only signal cs keep coming, in hl_cs_signal_sob_wraparound_handler()
1900 "Wait for signal CS supports only one signal CS seq\n"); in cs_ioctl_extract_signal_seq()
1939 struct hl_ctx *ctx, struct hl_cs *cs, in cs_ioctl_signal_wait_create_jobs() argument
1957 if (cs->type == CS_TYPE_WAIT) in cs_ioctl_signal_wait_create_jobs()
1971 job->cs = cs; in cs_ioctl_signal_wait_create_jobs()
1977 if ((cs->type == CS_TYPE_WAIT || cs->type == CS_TYPE_COLLECTIVE_WAIT) in cs_ioctl_signal_wait_create_jobs()
1978 && cs->encaps_signals) in cs_ioctl_signal_wait_create_jobs()
1991 cs_get(cs); in cs_ioctl_signal_wait_create_jobs()
1993 cs->jobs_in_queue_cnt[job->hw_queue_id]++; in cs_ioctl_signal_wait_create_jobs()
1994 cs->jobs_cnt++; in cs_ioctl_signal_wait_create_jobs()
1996 list_add_tail(&job->cs_node, &cs->job_list); in cs_ioctl_signal_wait_create_jobs()
2217 struct hl_cs *cs; in cs_ioctl_signal_wait() local
2289 /* check if cs sequence has encapsulated in cs_ioctl_signal_wait()
2300 * needed when multiple wait cs are used with offset in cs_ioctl_signal_wait()
2315 /* treat as signal CS already finished */ in cs_ioctl_signal_wait()
2338 "Failed to get signal CS with seq 0x%llx\n", in cs_ioctl_signal_wait()
2345 /* signal CS already finished */ in cs_ioctl_signal_wait()
2362 "CS seq 0x%llx is not of a signal/encaps-signal CS\n", in cs_ioctl_signal_wait()
2370 /* signal CS already finished */ in cs_ioctl_signal_wait()
2377 rc = allocate_cs(hdev, ctx, cs_type, ULLONG_MAX, &cs, flags, timeout); in cs_ioctl_signal_wait()
2386 * Save the signal CS fence for later initialization right before in cs_ioctl_signal_wait()
2387 * hanging the wait CS on the queue. in cs_ioctl_signal_wait()
2388 * for encaps signals case, we save the cs sequence and handle pointer in cs_ioctl_signal_wait()
2392 cs->signal_fence = sig_fence; in cs_ioctl_signal_wait()
2397 if (cs->encaps_signals) in cs_ioctl_signal_wait()
2398 cs->encaps_sig_hdl = encaps_sig_hdl; in cs_ioctl_signal_wait()
2401 hl_debugfs_add_cs(cs); in cs_ioctl_signal_wait()
2403 *cs_seq = cs->sequence; in cs_ioctl_signal_wait()
2406 rc = cs_ioctl_signal_wait_create_jobs(hdev, ctx, cs, q_type, in cs_ioctl_signal_wait()
2410 cs, q_idx, collective_engine_id, in cs_ioctl_signal_wait()
2422 INIT_WORK(&cs->finish_work, cs_completion); in cs_ioctl_signal_wait()
2424 rc = hl_hw_queue_schedule_cs(cs); in cs_ioctl_signal_wait()
2426 /* In case wait cs failed here, it means the signal cs in cs_ioctl_signal_wait()
2434 "Failed to submit CS %d.%llu to H/W queues, error %d\n", in cs_ioctl_signal_wait()
2435 ctx->asid, cs->sequence, rc); in cs_ioctl_signal_wait()
2439 *signal_sob_addr_offset = cs->sob_addr_offset; in cs_ioctl_signal_wait()
2440 *signal_initial_sob_count = cs->initial_sob_count; in cs_ioctl_signal_wait()
2448 cs_rollback(hdev, cs); in cs_ioctl_signal_wait()
2452 /* We finished with the CS in this function, so put the ref */ in cs_ioctl_signal_wait()
2453 cs_put(cs); in cs_ioctl_signal_wait()
2583 /* In case this is a staged CS, user should supply the CS sequence */ in hl_cs_ioctl()
2670 "Can't wait on CS %llu because current CS is at seq %llu\n", in hl_wait_for_fence()
2678 "Can't wait on seq %llu because current CS is at seq %llu (Fence is gone)\n", in hl_wait_for_fence()
2721 * hl_cs_poll_fences - iterate CS fences to check for CS completion
2723 * @mcs_data: multi-CS internal data
2724 * @mcs_compl: multi-CS completion structure
2728 * The function iterates on all CS sequence in the list and set bit in
2729 * completion_bitmap for each completed CS.
2732 * completion to the multi-CS context.
2753 * 1. CS will complete the multi-CS prior clearing the completion. in which in hl_cs_poll_fences()
2754 * case the fence iteration is guaranteed to catch the CS completion. in hl_cs_poll_fences()
2771 * In order to prevent case where we wait until timeout even though a CS associated in hl_cs_poll_fences()
2772 * with the multi-CS actually completed we do things in the below order: in hl_cs_poll_fences()
2773 * 1. for each fence set it's QID map in the multi-CS completion QID map. This way in hl_cs_poll_fences()
2774 * any CS can, potentially, complete the multi CS for the specific QID (note in hl_cs_poll_fences()
2777 * 2. only after allowing multi-CS completion for the specific QID we check whether in hl_cs_poll_fences()
2778 * the specific CS already completed (and thus the wait for completion part will in hl_cs_poll_fences()
2779 * be skipped). if the CS not completed it is guaranteed that completing CS will in hl_cs_poll_fences()
2792 "wait_for_fence error :%d for CS seq %llu\n", in hl_cs_poll_fences()
2799 /* CS did not finished, QID to wait on already stored */ in hl_cs_poll_fences()
2804 * returns to user indicating CS completed before it finished in hl_cs_poll_fences()
2812 * in case multi CS is completed but MCS handling not done in hl_cs_poll_fences()
2813 * we "complete" the multi CS to prevent it from waiting in hl_cs_poll_fences()
2814 * until time-out and the "multi-CS handling done" will have in hl_cs_poll_fences()
2837 * already gone. In this case, CS set as completed but in hl_cs_poll_fences()
2921 * to multi-CS CSs will be set incrementally at a later stage in hl_wait_multi_cs_completion_init()
2931 dev_err(hdev->dev, "no available multi-CS completion structure\n"); in hl_wait_multi_cs_completion_init()
2956 * hl_wait_multi_cs_completion - wait for first CS to complete
2958 * @mcs_data: multi-CS internal data
2983 * hl_multi_cs_completion_init - init array of multi-CS completion structures
3001 * hl_multi_cs_wait_ioctl - implementation of the multi-CS wait ioctl
3004 * @data: pointer to multi-CS wait ioctl in/out args
3028 dev_err(hdev->dev, "Wait for multi CS is not supported\n"); in hl_multi_cs_wait_ioctl()
3046 /* copy CS sequence array from user */ in hl_multi_cs_wait_ioctl()
3050 dev_err(hdev->dev, "Failed to copy multi-cs sequence array from user\n"); in hl_multi_cs_wait_ioctl()
3062 /* initialize the multi-CS internal data */ in hl_multi_cs_wait_ioctl()
3070 /* wait (with timeout) for the first CS to be completed */ in hl_multi_cs_wait_ioctl()
3078 /* poll all CS fences, extract timestamp */ in hl_multi_cs_wait_ioctl()
3082 * skip wait for CS completion when one of the below is true: in hl_multi_cs_wait_ioctl()
3084 * - one or more CS in the list completed in hl_multi_cs_wait_ioctl()
3096 * poll fences once again to update the CS map. in hl_multi_cs_wait_ioctl()
3107 * it got a completion) it either got completed by CS in the multi CS list in hl_multi_cs_wait_ioctl()
3109 * got completed by CS submitted to one of the shared stream master but in hl_multi_cs_wait_ioctl()
3110 * not in the multi CS list (in which case we should wait again but modify in hl_multi_cs_wait_ioctl()
3111 * the timeout and set timestamp as zero to let a CS related to the current in hl_multi_cs_wait_ioctl()
3112 * multi-CS set a new, relevant, timestamp) in hl_multi_cs_wait_ioctl()
3130 "user process got signal while waiting for Multi-CS\n"); in hl_multi_cs_wait_ioctl()
3150 /* update if some CS was gone */ in hl_multi_cs_wait_ioctl()
3173 "user process got signal while waiting for CS handle %llu\n", in hl_cs_wait_ioctl()
3183 "CS %llu has timed-out while user process is waiting for it\n", in hl_cs_wait_ioctl()
3188 "CS %llu has been aborted while user process is waiting for it\n", in hl_cs_wait_ioctl()