habanalabs: refactor razwi/page-fault information structures
authorKoby Elbaz <kelbaz@habana.ai>
Sun, 25 Dec 2022 10:43:04 +0000 (12:43 +0200)
committerOded Gabbay <ogabbay@kernel.org>
Thu, 26 Jan 2023 09:52:11 +0000 (11:52 +0200)
This refactor makes the code clearer and the new variables' names
better describe their roles.

Signed-off-by: Koby Elbaz <kelbaz@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
drivers/accel/habanalabs/common/device.c
drivers/accel/habanalabs/common/habanalabs.h
drivers/accel/habanalabs/common/habanalabs_drv.c
drivers/accel/habanalabs/common/habanalabs_ioctl.c

index fe3540ed60d74a20ca43aaca623e8391e5d414d9..e1b5a2c3498603d3e8415e3515ad09f5e4a13c6c 100644 (file)
@@ -2362,7 +2362,7 @@ void hl_device_fini(struct hl_device *hdev)
 
        hl_mmu_fini(hdev);
 
-       vfree(hdev->captured_err_info.pgf_info.user_mappings);
+       vfree(hdev->captured_err_info.page_fault_info.user_mappings);
 
        hl_eq_fini(hdev, &hdev->event_queue);
 
@@ -2422,6 +2422,8 @@ inline void hl_wreg(struct hl_device *hdev, u32 reg, u32 val)
 void hl_capture_razwi(struct hl_device *hdev, u64 addr, u16 *engine_id, u16 num_of_engines,
                        u8 flags)
 {
+       struct razwi_info *razwi_info = &hdev->captured_err_info.razwi_info;
+
        if (num_of_engines > HL_RAZWI_MAX_NUM_OF_ENGINES_PER_RTR) {
                dev_err(hdev->dev,
                                "Number of possible razwi initiators (%u) exceeded limit (%u)\n",
@@ -2430,15 +2432,15 @@ void hl_capture_razwi(struct hl_device *hdev, u64 addr, u16 *engine_id, u16 num_
        }
 
        /* In case it's the first razwi since the device was opened, capture its parameters */
-       if (atomic_cmpxchg(&hdev->captured_err_info.razwi_info_recorded, 0, 1))
+       if (atomic_cmpxchg(&hdev->captured_err_info.razwi_info.razwi_detected, 0, 1))
                return;
 
-       hdev->captured_err_info.razwi.timestamp = ktime_to_ns(ktime_get());
-       hdev->captured_err_info.razwi.addr = addr;
-       hdev->captured_err_info.razwi.num_of_possible_engines = num_of_engines;
-       memcpy(&hdev->captured_err_info.razwi.engine_id[0], &engine_id[0],
+       razwi_info->razwi.timestamp = ktime_to_ns(ktime_get());
+       razwi_info->razwi.addr = addr;
+       razwi_info->razwi.num_of_possible_engines = num_of_engines;
+       memcpy(&razwi_info->razwi.engine_id[0], &engine_id[0],
                        num_of_engines * sizeof(u16));
-       hdev->captured_err_info.razwi.flags = flags;
+       razwi_info->razwi.flags = flags;
 }
 
 void hl_handle_razwi(struct hl_device *hdev, u64 addr, u16 *engine_id, u16 num_of_engines,
@@ -2452,7 +2454,7 @@ void hl_handle_razwi(struct hl_device *hdev, u64 addr, u16 *engine_id, u16 num_o
 
 static void hl_capture_user_mappings(struct hl_device *hdev, bool is_pmmu)
 {
-       struct page_fault_info *pgf_info = &hdev->captured_err_info.pgf_info;
+       struct page_fault_info *pgf_info = &hdev->captured_err_info.page_fault_info;
        struct hl_vm_phys_pg_pack *phys_pg_pack = NULL;
        struct hl_vm_hash_node *hnode;
        struct hl_userptr *userptr;
@@ -2514,13 +2516,15 @@ finish:
 
 void hl_capture_page_fault(struct hl_device *hdev, u64 addr, u16 eng_id, bool is_pmmu)
 {
+       struct page_fault_info *pgf_info = &hdev->captured_err_info.page_fault_info;
+
        /* Capture only the first page fault */
-       if (atomic_cmpxchg(&hdev->captured_err_info.pgf_info_recorded, 0, 1))
+       if (atomic_cmpxchg(&pgf_info->page_fault_detected, 0, 1))
                return;
 
-       hdev->captured_err_info.pgf_info.pgf.timestamp = ktime_to_ns(ktime_get());
-       hdev->captured_err_info.pgf_info.pgf.addr = addr;
-       hdev->captured_err_info.pgf_info.pgf.engine_id = eng_id;
+       pgf_info->page_fault.timestamp = ktime_to_ns(ktime_get());
+       pgf_info->page_fault.addr = addr;
+       pgf_info->page_fault.engine_id = eng_id;
        hl_capture_user_mappings(hdev, is_pmmu);
 }
 
index 9bcefbef5ad78fce613cb7b696d1cb8a811101f0..e578645acba96465a91316da35b374bec1c4e962 100644 (file)
@@ -2975,37 +2975,49 @@ struct undefined_opcode_info {
 };
 
 /**
- * struct page_fault_info - info about page fault
- * @pgf_info: page fault information.
+ * struct page_fault_info - page fault information.
+ * @page_fault: holds information collected during a page fault.
  * @user_mappings: buffer containing user mappings.
  * @num_of_user_mappings: number of user mappings.
+ * @page_fault_detected: if set as 1, then a page-fault was discovered for the
+ *                       first time after the driver has finished booting-up.
+ *                       Since we're looking for the page-fault's root cause,
+ *                       we don't care of the others that might follow it-
+ *                       so once changed to 1, it will remain that way.
  */
 struct page_fault_info {
-       struct hl_page_fault_info       pgf;
+       struct hl_page_fault_info       page_fault;
        struct hl_user_mapping          *user_mappings;
        u64                             num_of_user_mappings;
+       atomic_t                        page_fault_detected;
+};
+
+/**
+ * struct razwi_info - RAZWI information.
+ * @razwi: holds information collected during a RAZWI
+ * @razwi_detected: if set as 1, then a RAZWI was discovered for the
+ *                  first time after the driver has finished booting-up.
+ *                  Since we're looking for the RAZWI's root cause,
+ *                  we don't care of the others that might follow it-
+ *                  so once changed to 1, it will remain that way.
+ */
+struct razwi_info {
+       struct hl_info_razwi_event      razwi;
+       atomic_t                        razwi_detected;
 };
 
 /**
  * struct hl_error_info - holds information collected during an error.
  * @cs_timeout: CS timeout error information.
- * @razwi: razwi information.
- * @razwi_info_recorded: if set writing to razwi information is enabled.
- *                       otherwise - disabled, so the first (root cause) razwi will not be
- *                       overwritten.
- * @undef_opcode: undefined opcode information
- * @pgf_info: page fault information.
- * @pgf_info_recorded: if set writing to page fault information is enabled.
- *                     otherwise - disabled, so the first (root cause) page fault will not be
- *                     overwritten.
+ * @razwi_info: RAZWI information.
+ * @undef_opcode: undefined opcode information.
+ * @page_fault_info: page fault information.
  */
 struct hl_error_info {
        struct cs_timeout_info          cs_timeout;
-       struct hl_info_razwi_event      razwi;
-       atomic_t                        razwi_info_recorded;
+       struct razwi_info               razwi_info;
        struct undefined_opcode_info    undef_opcode;
-       struct page_fault_info          pgf_info;
-       atomic_t                        pgf_info_recorded;
+       struct page_fault_info          page_fault_info;
 };
 
 /**
index 7815c60df54e23bcf141bc6cf9d40b2675bf758c..d7fe0af33bca3a77cea9109db1c574603dd6cc1d 100644 (file)
@@ -222,8 +222,8 @@ int hl_device_open(struct inode *inode, struct file *filp)
        hl_debugfs_add_file(hpriv);
 
        atomic_set(&hdev->captured_err_info.cs_timeout.write_enable, 1);
-       atomic_set(&hdev->captured_err_info.razwi_info_recorded, 0);
-       atomic_set(&hdev->captured_err_info.pgf_info_recorded, 0);
+       atomic_set(&hdev->captured_err_info.razwi_info.razwi_detected, 0);
+       atomic_set(&hdev->captured_err_info.page_fault_info.page_fault_detected, 0);
        hdev->captured_err_info.undef_opcode.write_enable = true;
 
        hdev->open_counter++;
index 0d9750006629c6c3a1d738f2e293f03532b666e6..619d56c40b3038ed61bdcc5648c7125d67b72791 100644 (file)
@@ -609,7 +609,7 @@ static int razwi_info(struct hl_fpriv *hpriv, struct hl_info_args *args)
 {
        struct hl_device *hdev = hpriv->hdev;
        u32 max_size = args->return_size;
-       struct hl_info_razwi_event *info = &hdev->captured_err_info.razwi;
+       struct hl_info_razwi_event *info = &hdev->captured_err_info.razwi_info.razwi;
        void __user *out = (void __user *) (uintptr_t) args->return_pointer;
 
        if ((!max_size) || (!out))
@@ -788,7 +788,7 @@ static int page_fault_info(struct hl_fpriv *hpriv, struct hl_info_args *args)
 {
        struct hl_device *hdev = hpriv->hdev;
        u32 max_size = args->return_size;
-       struct hl_page_fault_info *info = &hdev->captured_err_info.pgf_info.pgf;
+       struct hl_page_fault_info *info = &hdev->captured_err_info.page_fault_info.page_fault;
        void __user *out = (void __user *) (uintptr_t) args->return_pointer;
 
        if ((!max_size) || (!out))
@@ -806,7 +806,7 @@ static int user_mappings_info(struct hl_fpriv *hpriv, struct hl_info_args *args)
        struct page_fault_info *pgf_info;
        u64 actual_size;
 
-       pgf_info = &hdev->captured_err_info.pgf_info;
+       pgf_info = &hdev->captured_err_info.page_fault_info;
        args->array_size = pgf_info->num_of_user_mappings;
 
        if (!out)