Commit ea6ee260 authored by Tomer Tayar's avatar Tomer Tayar Committed by Oded Gabbay

habanalabs: Small refactoring of cs_do_release()

Slightly refactor the cs_do_release() function, to reduce nesting level
and to ease the handling of future CS types.
Signed-off-by: default avatarTomer Tayar <ttayar@habana.ai>
Reviewed-by: default avatarOded Gabbay <ogabbay@kernel.org>
Signed-off-by: default avatarOded Gabbay <ogabbay@kernel.org>
parent 6de3d769
...@@ -281,8 +281,7 @@ static void free_job(struct hl_device *hdev, struct hl_cs_job *job) ...@@ -281,8 +281,7 @@ static void free_job(struct hl_device *hdev, struct hl_cs_job *job)
static void cs_do_release(struct kref *ref) static void cs_do_release(struct kref *ref)
{ {
struct hl_cs *cs = container_of(ref, struct hl_cs, struct hl_cs *cs = container_of(ref, struct hl_cs, refcount);
refcount);
struct hl_device *hdev = cs->ctx->hdev; struct hl_device *hdev = cs->ctx->hdev;
struct hl_cs_job *job, *tmp; struct hl_cs_job *job, *tmp;
...@@ -299,8 +298,16 @@ static void cs_do_release(struct kref *ref) ...@@ -299,8 +298,16 @@ static void cs_do_release(struct kref *ref)
list_for_each_entry_safe(job, tmp, &cs->job_list, cs_node) list_for_each_entry_safe(job, tmp, &cs->job_list, cs_node)
free_job(hdev, job); free_job(hdev, job);
/* We also need to update CI for internal queues */ if (!cs->submitted) {
if (cs->submitted) { /* In case the wait for signal CS was submitted, the put occurs
* in init_signal_wait_cs() right before hanging on the PQ.
*/
if (cs->type == CS_TYPE_WAIT)
hl_fence_put(cs->signal_fence);
goto out;
}
hdev->asic_funcs->hw_queues_lock(hdev); hdev->asic_funcs->hw_queues_lock(hdev);
hdev->cs_active_cnt--; hdev->cs_active_cnt--;
...@@ -319,6 +326,7 @@ static void cs_do_release(struct kref *ref) ...@@ -319,6 +326,7 @@ static void cs_do_release(struct kref *ref)
hdev->asic_funcs->hw_queues_unlock(hdev); hdev->asic_funcs->hw_queues_unlock(hdev);
/* Need to update CI for internal queues */
hl_int_hw_queue_update_ci(cs); hl_int_hw_queue_update_ci(cs);
spin_lock(&hdev->hw_queues_mirror_lock); spin_lock(&hdev->hw_queues_mirror_lock);
...@@ -326,12 +334,11 @@ static void cs_do_release(struct kref *ref) ...@@ -326,12 +334,11 @@ static void cs_do_release(struct kref *ref)
list_del_init(&cs->mirror_node); list_del_init(&cs->mirror_node);
spin_unlock(&hdev->hw_queues_mirror_lock); spin_unlock(&hdev->hw_queues_mirror_lock);
/* /* Don't cancel TDR in case this CS was timedout because we might be
* Don't cancel TDR in case this CS was timedout because we * running from the TDR context
* might be running from the TDR context
*/ */
if ((!cs->timedout) && if (!cs->timedout &&
(hdev->timeout_jiffies != MAX_SCHEDULE_TIMEOUT)) { hdev->timeout_jiffies != MAX_SCHEDULE_TIMEOUT) {
struct hl_cs *next; struct hl_cs *next;
if (cs->tdr_active) if (cs->tdr_active)
...@@ -340,11 +347,10 @@ static void cs_do_release(struct kref *ref) ...@@ -340,11 +347,10 @@ static void cs_do_release(struct kref *ref)
spin_lock(&hdev->hw_queues_mirror_lock); spin_lock(&hdev->hw_queues_mirror_lock);
/* queue TDR for next CS */ /* queue TDR for next CS */
next = list_first_entry_or_null( next = list_first_entry_or_null(&hdev->hw_queues_mirror_list,
&hdev->hw_queues_mirror_list,
struct hl_cs, mirror_node); struct hl_cs, mirror_node);
if ((next) && (!next->tdr_active)) { if (next && !next->tdr_active) {
next->tdr_active = true; next->tdr_active = true;
schedule_delayed_work(&next->work_tdr, schedule_delayed_work(&next->work_tdr,
hdev->timeout_jiffies); hdev->timeout_jiffies);
...@@ -352,16 +358,9 @@ static void cs_do_release(struct kref *ref) ...@@ -352,16 +358,9 @@ static void cs_do_release(struct kref *ref)
spin_unlock(&hdev->hw_queues_mirror_lock); spin_unlock(&hdev->hw_queues_mirror_lock);
} }
} else if (cs->type == CS_TYPE_WAIT) {
/*
* In case the wait for signal CS was submitted, the put occurs
* in init_signal_wait_cs() right before hanging on the PQ.
*/
hl_fence_put(cs->signal_fence);
}
/* out:
* Must be called before hl_ctx_put because inside we use ctx to get /* Must be called before hl_ctx_put because inside we use ctx to get
* the device * the device
*/ */
hl_debugfs_remove_cs(cs); hl_debugfs_remove_cs(cs);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment