habanalabs: allow user to pass a staged submission seq
authorOfir Bitton <obitton@habana.ai>
Thu, 3 Dec 2020 15:12:09 +0000 (17:12 +0200)
committerOded Gabbay <ogabbay@kernel.org>
Wed, 27 Jan 2021 19:03:48 +0000 (21:03 +0200)
In order to support the staged submission feature, user must be
allowed to use the same CS sequence for all submissions in the
same staged submission.

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
include/uapi/misc/habanalabs.h

index ccb4972..348b0ec 100644 (file)
@@ -807,7 +807,7 @@ static int hl_cs_copy_chunk_array(struct hl_device *hdev,
 }
 
 static int cs_ioctl_default(struct hl_fpriv *hpriv, void __user *chunks,
-                               u32 num_chunks, u64 *cs_seq, bool timestamp)
+                               u32 num_chunks, u64 *cs_seq, u32 flags)
 {
        bool int_queues_only = true;
        struct hl_device *hdev = hpriv->hdev;
@@ -836,7 +836,7 @@ static int cs_ioctl_default(struct hl_fpriv *hpriv, void __user *chunks,
                goto free_cs_chunk_array;
        }
 
-       cs->timestamp = !!timestamp;
+       cs->timestamp = !!(flags & HL_CS_FLAGS_TIMESTAMP);
        *cs_seq = cs->sequence;
 
        hl_debugfs_add_cs(cs);
@@ -1004,7 +1004,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, false);
+                                                               cs_seq, 0);
                }
 
                mutex_unlock(&hpriv->restore_phase_mutex);
@@ -1347,7 +1347,7 @@ int hl_cs_ioctl(struct hl_fpriv *hpriv, void *data)
        enum hl_cs_type cs_type;
        u64 cs_seq = ULONG_MAX;
        void __user *chunks;
-       u32 num_chunks;
+       u32 num_chunks, flags;
        int rc;
 
        rc = hl_cs_sanity_checks(hpriv, args);
@@ -1362,6 +1362,12 @@ int hl_cs_ioctl(struct hl_fpriv *hpriv, void *data)
                                        ~HL_CS_FLAGS_FORCE_RESTORE);
        chunks = (void __user *) (uintptr_t) args->in.chunks_execute;
        num_chunks = args->in.num_chunks_execute;
+       flags = args->in.cs_flags;
+
+       /* In case this is a staged CS, user should supply the CS sequence */
+       if ((flags & HL_CS_FLAGS_STAGED_SUBMISSION) &&
+                       !(flags & HL_CS_FLAGS_STAGED_SUBMISSION_FIRST))
+               cs_seq = args->in.seq;
 
        switch (cs_type) {
        case CS_TYPE_SIGNAL:
@@ -1372,7 +1378,7 @@ int hl_cs_ioctl(struct hl_fpriv *hpriv, void *data)
                break;
        default:
                rc = cs_ioctl_default(hpriv, chunks, num_chunks, &cs_seq,
-                               args->in.cs_flags & HL_CS_FLAGS_TIMESTAMP);
+                                                       args->in.cs_flags);
                break;
        }
 
index dba3827..b9afe1c 100644 (file)
@@ -604,11 +604,14 @@ struct hl_cs_chunk {
 };
 
 /* SIGNAL and WAIT/COLLECTIVE_WAIT flags are mutually exclusive */
-#define HL_CS_FLAGS_FORCE_RESTORE      0x1
-#define HL_CS_FLAGS_SIGNAL             0x2
-#define HL_CS_FLAGS_WAIT               0x4
-#define HL_CS_FLAGS_COLLECTIVE_WAIT    0x8
-#define HL_CS_FLAGS_TIMESTAMP          0x20
+#define HL_CS_FLAGS_FORCE_RESTORE              0x1
+#define HL_CS_FLAGS_SIGNAL                     0x2
+#define HL_CS_FLAGS_WAIT                       0x4
+#define HL_CS_FLAGS_COLLECTIVE_WAIT            0x8
+#define HL_CS_FLAGS_TIMESTAMP                  0x20
+#define HL_CS_FLAGS_STAGED_SUBMISSION          0x40
+#define HL_CS_FLAGS_STAGED_SUBMISSION_FIRST    0x80
+#define HL_CS_FLAGS_STAGED_SUBMISSION_LAST     0x100
 
 #define HL_CS_STATUS_SUCCESS           0
 
@@ -622,10 +625,17 @@ struct hl_cs_in {
        /* holds address of array of hl_cs_chunk for execution phase */
        __u64 chunks_execute;
 
-       /* this holds address of array of hl_cs_chunk for store phase -
-        * Currently not in use
-        */
-       __u64 chunks_store;
+       union {
+               /* this holds address of array of hl_cs_chunk for store phase -
+                * Currently not in use
+                */
+               __u64 chunks_store;
+
+               /* Sequence number of a staged submission CS
+                * valid only if HL_CS_FLAGS_STAGED_SUBMISSION is set
+                */
+               __u64 seq;
+       };
 
        /* Number of chunks in restore phase array. Maximum number is
         * HL_MAX_JOBS_PER_CS