Lines Matching refs:cs
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
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
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()
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()
393 if (cs_needs_completion(cs) && in hl_complete_job()
400 cs->completion_timestamp = job->timestamp; in hl_complete_job()
402 cs_put(cs); in hl_complete_job()
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()
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()
460 static void staged_cs_get(struct hl_device *hdev, struct hl_cs *cs) in staged_cs_get() argument
467 if (!cs->staged_last) in staged_cs_get()
468 cs_get(cs); in staged_cs_get()
479 static void staged_cs_put(struct hl_device *hdev, struct hl_cs *cs) in staged_cs_put() argument
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()
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()
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()
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()
594 if (cs->staged_cs && !cs->staged_first) in complete_multi_cs()
638 struct hl_cs *cs, in cs_release_sob_reset_handler() argument
645 if (!hl_cs_cmpl->hw_sob || !cs->submitted) 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()
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()
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()
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()
724 if (cs->staged_last) { in cs_do_release()
728 &cs->staged_cs_node, staged_cs_node) in cs_do_release()
736 if (cs->submitted) { in cs_do_release()
738 list_del(&cs->staged_cs_node); 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()
827 cs->timedout = true; 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()
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()
1049 struct hl_cs *cs, *tmp; in hl_cs_rollback_all() local
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()
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()
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()
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()
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()
1519 if (cs->staged_cs) in cs_ioctl_default()
1520 *cs_seq = cs->staged_sequence; 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()
1596 if (cs_needs_completion(cs) && in cs_ioctl_default()
1599 cs_get(cs); in cs_ioctl_default()
1609 cs->ctx->asid, cs->sequence, job->id, rc); in cs_ioctl_default()
1617 if (int_queues_only && cs_needs_completion(cs)) { 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()
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()
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()
1660 cs_put(cs); in cs_ioctl_default()
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
2362 rc = allocate_cs(hdev, ctx, cs_type, ULLONG_MAX, &cs, flags, timeout); 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()
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()
2438 cs_put(cs); in cs_ioctl_signal_wait()