habanalabs: perform context switch flow only if needed
authorOfir Bitton <obitton@habana.ai>
Mon, 22 Aug 2022 07:59:34 +0000 (10:59 +0300)
committerOded Gabbay <ogabbay@kernel.org>
Sun, 18 Sep 2022 10:29:53 +0000 (13:29 +0300)
Except Goya, none of our ASICs require context switch flow, hence we
enable this flow only where it is needed.

Signed-off-by: Ofir Bitton <obitton@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
drivers/misc/habanalabs/common/command_submission.c
drivers/misc/habanalabs/common/habanalabs.h
drivers/misc/habanalabs/goya/goya.c

index cf41185..746b688 100644 (file)
@@ -1590,13 +1590,14 @@ static int hl_cs_ctx_switch(struct hl_fpriv *hpriv, union hl_cs_args *args,
        struct hl_device *hdev = hpriv->hdev;
        struct hl_ctx *ctx = hpriv->ctx;
        bool need_soft_reset = false;
-       int rc = 0, do_ctx_switch;
+       int rc = 0, do_ctx_switch = 0;
        void __user *chunks;
        u32 num_chunks, tmp;
        u16 sob_count;
        int ret;
 
-       do_ctx_switch = atomic_cmpxchg(&ctx->thread_ctx_switch_token, 1, 0);
+       if (hdev->supports_ctx_switch)
+               do_ctx_switch = atomic_cmpxchg(&ctx->thread_ctx_switch_token, 1, 0);
 
        if (do_ctx_switch || (args->in.cs_flags & HL_CS_FLAGS_FORCE_RESTORE)) {
                mutex_lock(&hpriv->restore_phase_mutex);
@@ -1667,9 +1668,10 @@ wait_again:
                        }
                }
 
-               ctx->thread_ctx_switch_wait_token = 1;
+               if (hdev->supports_ctx_switch)
+                       ctx->thread_ctx_switch_wait_token = 1;
 
-       } else if (!ctx->thread_ctx_switch_wait_token) {
+       } else if (hdev->supports_ctx_switch && !ctx->thread_ctx_switch_wait_token) {
                rc = hl_poll_timeout_memory(hdev,
                        &ctx->thread_ctx_switch_wait_token, tmp, (tmp == 1),
                        100, jiffies_to_usecs(hdev->timeout_jiffies), false);
index d7fd4f5..33c6476 100644 (file)
@@ -3199,6 +3199,7 @@ struct hl_reset_info {
  *                         Used only for testing.
  * @heartbeat: Controls if we want to enable the heartbeat mechanism vs. the f/w, which verifies
  *             that the f/w is always alive. Used only for testing.
+ * @supports_ctx_switch: true if a ctx switch is required upon first submission.
  */
 struct hl_device {
        struct pci_dev                  *pdev;
@@ -3335,6 +3336,7 @@ struct hl_device {
        u8                              compute_ctx_in_release;
        u8                              supports_mmu_prefetch;
        u8                              reset_upon_device_release;
+       u8                              supports_ctx_switch;
 
        /* Parameters for bring-up */
        u64                             nic_ports_mask;
index 87465a2..d8fb91d 100644 (file)
@@ -1025,6 +1025,7 @@ static int goya_sw_init(struct hl_device *hdev)
        hdev->asic_prop.supports_compute_reset = true;
        hdev->asic_prop.allow_inference_soft_reset = true;
        hdev->supports_wait_for_multi_cs = false;
+       hdev->supports_ctx_switch = true;
 
        hdev->asic_funcs->set_pci_memory_regions(hdev);