Commit 78baccbd authored by Koby Elbaz's avatar Koby Elbaz Committed by Oded Gabbay

habanalabs: refactor razwi/page-fault information structures

This refactor makes the code clearer and the new variables' names
better describe their roles.
Signed-off-by: default avatarKoby Elbaz <kelbaz@habana.ai>
Reviewed-by: default avatarOded Gabbay <ogabbay@kernel.org>
Signed-off-by: default avatarOded Gabbay <ogabbay@kernel.org>
parent 6cfb0013
...@@ -2362,7 +2362,7 @@ void hl_device_fini(struct hl_device *hdev) ...@@ -2362,7 +2362,7 @@ void hl_device_fini(struct hl_device *hdev)
hl_mmu_fini(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); hl_eq_fini(hdev, &hdev->event_queue);
...@@ -2422,6 +2422,8 @@ inline void hl_wreg(struct hl_device *hdev, u32 reg, u32 val) ...@@ -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, void hl_capture_razwi(struct hl_device *hdev, u64 addr, u16 *engine_id, u16 num_of_engines,
u8 flags) 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) { if (num_of_engines > HL_RAZWI_MAX_NUM_OF_ENGINES_PER_RTR) {
dev_err(hdev->dev, dev_err(hdev->dev,
"Number of possible razwi initiators (%u) exceeded limit (%u)\n", "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_ ...@@ -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 */ /* 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; return;
hdev->captured_err_info.razwi.timestamp = ktime_to_ns(ktime_get()); razwi_info->razwi.timestamp = ktime_to_ns(ktime_get());
hdev->captured_err_info.razwi.addr = addr; razwi_info->razwi.addr = addr;
hdev->captured_err_info.razwi.num_of_possible_engines = num_of_engines; razwi_info->razwi.num_of_possible_engines = num_of_engines;
memcpy(&hdev->captured_err_info.razwi.engine_id[0], &engine_id[0], memcpy(&razwi_info->razwi.engine_id[0], &engine_id[0],
num_of_engines * sizeof(u16)); 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, 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 ...@@ -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) 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_phys_pg_pack *phys_pg_pack = NULL;
struct hl_vm_hash_node *hnode; struct hl_vm_hash_node *hnode;
struct hl_userptr *userptr; struct hl_userptr *userptr;
...@@ -2514,13 +2516,15 @@ static void hl_capture_user_mappings(struct hl_device *hdev, bool is_pmmu) ...@@ -2514,13 +2516,15 @@ static void hl_capture_user_mappings(struct hl_device *hdev, bool is_pmmu)
void hl_capture_page_fault(struct hl_device *hdev, u64 addr, u16 eng_id, bool is_pmmu) 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 */ /* 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; return;
hdev->captured_err_info.pgf_info.pgf.timestamp = ktime_to_ns(ktime_get()); pgf_info->page_fault.timestamp = ktime_to_ns(ktime_get());
hdev->captured_err_info.pgf_info.pgf.addr = addr; pgf_info->page_fault.addr = addr;
hdev->captured_err_info.pgf_info.pgf.engine_id = eng_id; pgf_info->page_fault.engine_id = eng_id;
hl_capture_user_mappings(hdev, is_pmmu); hl_capture_user_mappings(hdev, is_pmmu);
} }
......
...@@ -2975,37 +2975,49 @@ struct undefined_opcode_info { ...@@ -2975,37 +2975,49 @@ struct undefined_opcode_info {
}; };
/** /**
* struct page_fault_info - info about page fault * struct page_fault_info - page fault information.
* @pgf_info: page fault information. * @page_fault: holds information collected during a page fault.
* @user_mappings: buffer containing user mappings. * @user_mappings: buffer containing user mappings.
* @num_of_user_mappings: number of 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 page_fault_info {
struct hl_page_fault_info pgf; struct hl_page_fault_info page_fault;
struct hl_user_mapping *user_mappings; struct hl_user_mapping *user_mappings;
u64 num_of_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. * struct hl_error_info - holds information collected during an error.
* @cs_timeout: CS timeout error information. * @cs_timeout: CS timeout error information.
* @razwi: razwi information. * @razwi_info: RAZWI information.
* @razwi_info_recorded: if set writing to razwi information is enabled. * @undef_opcode: undefined opcode information.
* otherwise - disabled, so the first (root cause) razwi will not be * @page_fault_info: page fault information.
* 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.
*/ */
struct hl_error_info { struct hl_error_info {
struct cs_timeout_info cs_timeout; struct cs_timeout_info cs_timeout;
struct hl_info_razwi_event razwi; struct razwi_info razwi_info;
atomic_t razwi_info_recorded;
struct undefined_opcode_info undef_opcode; struct undefined_opcode_info undef_opcode;
struct page_fault_info pgf_info; struct page_fault_info page_fault_info;
atomic_t pgf_info_recorded;
}; };
/** /**
......
...@@ -222,8 +222,8 @@ int hl_device_open(struct inode *inode, struct file *filp) ...@@ -222,8 +222,8 @@ int hl_device_open(struct inode *inode, struct file *filp)
hl_debugfs_add_file(hpriv); hl_debugfs_add_file(hpriv);
atomic_set(&hdev->captured_err_info.cs_timeout.write_enable, 1); 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.razwi_info.razwi_detected, 0);
atomic_set(&hdev->captured_err_info.pgf_info_recorded, 0); atomic_set(&hdev->captured_err_info.page_fault_info.page_fault_detected, 0);
hdev->captured_err_info.undef_opcode.write_enable = true; hdev->captured_err_info.undef_opcode.write_enable = true;
hdev->open_counter++; hdev->open_counter++;
......
...@@ -609,7 +609,7 @@ static int razwi_info(struct hl_fpriv *hpriv, struct hl_info_args *args) ...@@ -609,7 +609,7 @@ static int razwi_info(struct hl_fpriv *hpriv, struct hl_info_args *args)
{ {
struct hl_device *hdev = hpriv->hdev; struct hl_device *hdev = hpriv->hdev;
u32 max_size = args->return_size; 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; void __user *out = (void __user *) (uintptr_t) args->return_pointer;
if ((!max_size) || (!out)) if ((!max_size) || (!out))
...@@ -788,7 +788,7 @@ static int page_fault_info(struct hl_fpriv *hpriv, struct hl_info_args *args) ...@@ -788,7 +788,7 @@ static int page_fault_info(struct hl_fpriv *hpriv, struct hl_info_args *args)
{ {
struct hl_device *hdev = hpriv->hdev; struct hl_device *hdev = hpriv->hdev;
u32 max_size = args->return_size; 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; void __user *out = (void __user *) (uintptr_t) args->return_pointer;
if ((!max_size) || (!out)) if ((!max_size) || (!out))
...@@ -806,7 +806,7 @@ static int user_mappings_info(struct hl_fpriv *hpriv, struct hl_info_args *args) ...@@ -806,7 +806,7 @@ static int user_mappings_info(struct hl_fpriv *hpriv, struct hl_info_args *args)
struct page_fault_info *pgf_info; struct page_fault_info *pgf_info;
u64 actual_size; 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; args->array_size = pgf_info->num_of_user_mappings;
if (!out) if (!out)
......
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