habanalabs: add SOB information to signal submission uAPI
authorDani Liberman <dliberman@habana.ai>
Tue, 9 Nov 2021 09:33:28 +0000 (11:33 +0200)
committerOded Gabbay <ogabbay@kernel.org>
Sun, 26 Dec 2021 06:59:07 +0000 (08:59 +0200)
For debug purpose, add SOB address and SOB initial counter value
before current submission to uAPI output.

Using SOB address and initial counter, user can calculate how much of
the submmision has been completed.

Signed-off-by: Dani Liberman <dliberman@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/common/hw_queue.c
include/uapi/misc/habanalabs.h

index 4e89336..7a277f4 100644 (file)
@@ -1277,7 +1277,8 @@ static u32 get_stream_master_qid_mask(struct hl_device *hdev, u32 qid)
 
 static int cs_ioctl_default(struct hl_fpriv *hpriv, void __user *chunks,
                                u32 num_chunks, u64 *cs_seq, u32 flags,
-                               u32 encaps_signals_handle, u32 timeout)
+                               u32 encaps_signals_handle, u32 timeout,
+                               u16 *signal_initial_sob_count)
 {
        bool staged_mid, int_queues_only = true;
        struct hl_device *hdev = hpriv->hdev;
@@ -1444,6 +1445,8 @@ static int cs_ioctl_default(struct hl_fpriv *hpriv, void __user *chunks,
                goto free_cs_object;
        }
 
+       *signal_initial_sob_count = cs->initial_sob_count;
+
        rc = HL_CS_STATUS_SUCCESS;
        goto put_cs;
 
@@ -1472,6 +1475,7 @@ static int hl_cs_ctx_switch(struct hl_fpriv *hpriv, union hl_cs_args *args,
        int rc = 0, do_ctx_switch;
        void __user *chunks;
        u32 num_chunks, tmp;
+       u16 sob_count;
        int ret;
 
        do_ctx_switch = atomic_cmpxchg(&ctx->thread_ctx_switch_token, 1, 0);
@@ -1512,7 +1516,7 @@ static int hl_cs_ctx_switch(struct hl_fpriv *hpriv, union hl_cs_args *args,
                        rc = 0;
                } else {
                        rc = cs_ioctl_default(hpriv, chunks, num_chunks,
-                                       cs_seq, 0, 0, hdev->timeout_jiffies);
+                                       cs_seq, 0, 0, hdev->timeout_jiffies, &sob_count);
                }
 
                mutex_unlock(&hpriv->restore_phase_mutex);
@@ -1963,7 +1967,8 @@ out:
 
 static int cs_ioctl_signal_wait(struct hl_fpriv *hpriv, enum hl_cs_type cs_type,
                                void __user *chunks, u32 num_chunks,
-                               u64 *cs_seq, u32 flags, u32 timeout)
+                               u64 *cs_seq, u32 flags, u32 timeout,
+                               u32 *signal_sob_addr_offset, u16 *signal_initial_sob_count)
 {
        struct hl_cs_encaps_sig_handle *encaps_sig_hdl = NULL;
        bool handle_found = false, is_wait_cs = false,
@@ -2195,6 +2200,9 @@ static int cs_ioctl_signal_wait(struct hl_fpriv *hpriv, enum hl_cs_type cs_type,
                goto free_cs_object;
        }
 
+       *signal_sob_addr_offset = cs->sob_addr_offset;
+       *signal_initial_sob_count = cs->initial_sob_count;
+
        rc = HL_CS_STATUS_SUCCESS;
        if (is_wait_cs)
                wait_cs_submitted = true;
@@ -2225,6 +2233,7 @@ int hl_cs_ioctl(struct hl_fpriv *hpriv, void *data)
        void __user *chunks;
        u32 num_chunks, flags, timeout,
                signals_count = 0, sob_addr = 0, handle_id = 0;
+       u16 sob_initial_count = 0;
        int rc;
 
        rc = hl_cs_sanity_checks(hpriv, args);
@@ -2255,7 +2264,8 @@ int hl_cs_ioctl(struct hl_fpriv *hpriv, void *data)
        case CS_TYPE_WAIT:
        case CS_TYPE_COLLECTIVE_WAIT:
                rc = cs_ioctl_signal_wait(hpriv, cs_type, chunks, num_chunks,
-                                       &cs_seq, args->in.cs_flags, timeout);
+                                       &cs_seq, args->in.cs_flags, timeout,
+                                       &sob_addr, &sob_initial_count);
                break;
        case CS_RESERVE_SIGNALS:
                rc = cs_ioctl_reserve_signals(hpriv,
@@ -2271,20 +2281,33 @@ int hl_cs_ioctl(struct hl_fpriv *hpriv, void *data)
                rc = cs_ioctl_default(hpriv, chunks, num_chunks, &cs_seq,
                                                args->in.cs_flags,
                                                args->in.encaps_sig_handle_id,
-                                               timeout);
+                                               timeout, &sob_initial_count);
                break;
        }
 out:
        if (rc != -EAGAIN) {
                memset(args, 0, sizeof(*args));
 
-               if (cs_type == CS_RESERVE_SIGNALS) {
+               switch (cs_type) {
+               case CS_RESERVE_SIGNALS:
                        args->out.handle_id = handle_id;
                        args->out.sob_base_addr_offset = sob_addr;
                        args->out.count = signals_count;
-               } else {
+                       break;
+               case CS_TYPE_SIGNAL:
+                       args->out.sob_base_addr_offset = sob_addr;
+                       args->out.sob_count_before_submission = sob_initial_count;
+                       args->out.seq = cs_seq;
+                       break;
+               case CS_TYPE_DEFAULT:
+                       args->out.sob_count_before_submission = sob_initial_count;
+                       args->out.seq = cs_seq;
+                       break;
+               default:
                        args->out.seq = cs_seq;
+                       break;
                }
+
                args->out.status = rc;
        }
 
index 77ac4bb..93d0a85 100644 (file)
@@ -1545,6 +1545,9 @@ struct hl_userptr {
  * @submission_time_jiffies: submission time of the cs
  * @type: CS_TYPE_*.
  * @encaps_sig_hdl_id: encaps signals handle id, set for the first staged cs.
+ * @sob_addr_offset: sob offset from the configuration base address.
+ * @initial_sob_count: count of completed signals in SOB before current submission of signal or
+ *                     cs with encaps signals.
  * @submitted: true if CS was submitted to H/W.
  * @completed: true if CS was completed by device.
  * @timedout : true if CS was timedout.
@@ -1580,6 +1583,8 @@ struct hl_cs {
        u64                     submission_time_jiffies;
        enum hl_cs_type         type;
        u32                     encaps_sig_hdl_id;
+       u32                     sob_addr_offset;
+       u16                     initial_sob_count;
        u8                      submitted;
        u8                      completed;
        u8                      timedout;
index 0743319..fc841d6 100644 (file)
@@ -429,6 +429,9 @@ static int init_signal_cs(struct hl_device *hdev,
        rc = hl_cs_signal_sob_wraparound_handler(hdev, q_idx, &hw_sob, 1,
                                                                false);
 
+       job->cs->sob_addr_offset = hw_sob->sob_addr;
+       job->cs->initial_sob_count = prop->next_sob_val - 1;
+
        return rc;
 }
 
index cd86937..648850b 100644 (file)
@@ -929,9 +929,17 @@ struct hl_cs_out {
 
        /*
         * SOB base address offset
-        * Valid only when HL_CS_FLAGS_RESERVE_SIGNALS_ONLY is set
+        * Valid only when HL_CS_FLAGS_RESERVE_SIGNALS_ONLY or HL_CS_FLAGS_SIGNAL is set
         */
        __u32 sob_base_addr_offset;
+
+       /*
+        * Count of completed signals in SOB before current signal submission.
+        * Valid only when (HL_CS_FLAGS_ENCAP_SIGNALS & HL_CS_FLAGS_STAGED_SUBMISSION)
+        * or HL_CS_FLAGS_SIGNAL is set
+        */
+       __u16 sob_count_before_submission;
+       __u16 pad[3];
 };
 
 union hl_cs_args {