habanalabs: perform accounting for active CS
PATCH 1/3 habanalabs: perform accounting for active CS
This patch adds accounting for active CS. Active means that the CS was submitted to the H/W queues and was not completed yet.
This is necessary to support suspend operation. Because the device will be reset upon suspend, we can only suspend after all active CS have been completed. Hence, we need to perform accounting on their number.
--- drivers/misc/habanalabs/command_submission.c | 6 ++++++ drivers/misc/habanalabs/device.c | 1 + drivers/misc/habanalabs/habanalabs.h | 13 ++++++++----- drivers/misc/habanalabs/hw_queue.c | 5 +++-- 4 files changed, 18 insertions(+), 7 deletions(-)
drivers/misc/habanalabs/command_submission.c +6 -0
@@ -179,6 +179,12 @@ static void cs_do_release(struct kref *ref)/* We also need to update CI for internal queues */ if (cs->submitted) { +int cs_cnt =atomic_dec_return (&hdev->cs_active_cnt); + +WARN_ONCE ((cs_cnt <0 ), +"hl%d: error in CS active cnt %d\n" , + hdev->id, cs_cnt); +hl_int_hw_queue_update_ci (cs);spin_lock (&hdev->hw_queues_mirror_lock);
drivers/misc/habanalabs/device.c +1 -0
@@ -218,6 +218,7 @@ static int device_early_init(struct hl_device *hdev)spin_lock_init (&hdev->hw_queues_mirror_lock);atomic_set (&hdev->in_reset,0 );atomic_set (&hdev->fd_open_cnt,0 ); +atomic_set (&hdev->cs_active_cnt,0 );return 0 ;
drivers/misc/habanalabs/habanalabs.h +8 -5
@@ -1056,13 +1056,15 @@ struct hl_device_reset_work {* @cb_pool_lock: protects the CB pool. * @user_ctx: current user context executing. * @dram_used_mem: current DRAM memory consumption. -* @in_reset: is device in reset flow. -* @curr_pll_profile: current PLL profile. -* @fd_open_cnt: number of open user processes. * @timeout_jiffies: device CS timeout value. * @max_power: the max power of the device, as configured by the sysadmin. This * value is saved so in case of hard-reset, KMD will restore this * value and update the F/W after the re-initialization +* @in_reset: is device in reset flow. +* @curr_pll_profile: current PLL profile. +* @fd_open_cnt: number of open user processes. +* @cs_active_cnt: number of active command submissions on this device (active +* means already in H/W queues) * @major: habanalabs KMD major. * @high_pll: high PLL profile frequency. * @soft_reset_cnt: number of soft reset since KMD loading.
@@ -1128,11 +1130,12 @@ struct hl_device {struct hl_ctx *user_ctx;atomic64_t dram_used_mem; +u64 timeout_jiffies; +u64 max_power;atomic_t in_reset;atomic_t curr_pll_profile;atomic_t fd_open_cnt; -u64 timeout_jiffies; -u64 max_power; +atomic_t cs_active_cnt;u32 major;u32 high_pll;u32 soft_reset_cnt;
drivers/misc/habanalabs/hw_queue.c +3 -2
@@ -370,12 +370,13 @@ int hl_hw_queue_schedule_cs(struct hl_cs *cs)spin_unlock (&hdev->hw_queues_mirror_lock); } -list_for_each_entry_safe (job, tmp, &cs->job_list, cs_node) { +atomic_inc (&hdev->cs_active_cnt); + +list_for_each_entry_safe (job, tmp, &cs->job_list, cs_node)if (job->ext_queue)ext_hw_queue_schedule_job (job);else int_hw_queue_schedule_job (job); - } cs->submitted = true;
Signature · 1 line
2.17.1
PATCH 2/3 habanalabs: prevent host crash during suspend/resume
This patch fixes the implementation of suspend/resume of the device so that upon resume of the device, the host won't crash due to PCI completion timeout.
Upon suspend, the device is being reset due to PERST. Therefore, upon resume, the driver must initialize the PCI controller as if the driver was loaded. If the controller is not initialized and the device tries to access the device through the PCI bars, the host will crash with PCI completion timeout error.
--- drivers/misc/habanalabs/device.c | 46 +++++++++++++++++++-- drivers/misc/habanalabs/goya/goya.c | 63 +---------------------------- 2 files changed, 43 insertions(+), 66 deletions(-)
drivers/misc/habanalabs/device.c +42 -4
@@ -416,6 +416,27 @@ int hl_device_suspend(struct hl_device *hdev)pci_save_state (hdev->pdev); +/* Block future CS/VM/JOB completion operations */ + rc =atomic_cmpxchg (&hdev->in_reset,0 ,1 ); +if (rc) { +dev_err (hdev->dev,"Can't suspend while in reset\n" ); +return -EIO ; + } + +/* This blocks all other stuff that is not blocked by in_reset */ + hdev->disabled = true; + +/* +* Flush anyone that is inside the critical section of enqueue +* jobs to the H/W +*/ + hdev->asic_funcs->hw_queues_lock (hdev); + hdev->asic_funcs->hw_queues_unlock (hdev); + +/* Flush processes that are sending message to CPU */ +mutex_lock (&hdev->send_cpu_message_lock); +mutex_unlock (&hdev->send_cpu_message_lock); + rc = hdev->asic_funcs->suspend (hdev);if (rc) dev_err(hdev->dev,
@@ -443,21 +464,38 @@ int hl_device_resume(struct hl_device *hdev)pci_set_power_state (hdev->pdev,PCI_D0 );pci_restore_state (hdev->pdev); - rc =pci_enable_device (hdev->pdev); + rc =pci_enable_device_mem (hdev->pdev);if (rc) {dev_err (hdev->dev,"Failed to enable PCI device in resume\n" );return rc; } +pci_set_master (hdev->pdev); + rc = hdev->asic_funcs->resume (hdev);if (rc) { -dev_err (hdev->dev, -"Failed to enable PCI access from device CPU\n" ); -return rc; +dev_err (hdev->dev,"Failed to resume device after suspend\n" ); + goto disable_device; + } + + + hdev->disabled = false; +atomic_set (&hdev->in_reset,0 ); + + rc =hl_device_reset (hdev, true, false); +if (rc) { +dev_err (hdev->dev,"Failed to reset device during resume\n" ); + goto disable_device; }return 0 ; + +disable_device: +pci_clear_master (hdev->pdev); +pci_disable_device (hdev->pdev); + +return rc; }static void hl_device_hard_reset_pending (struct work_struct *work)
drivers/misc/habanalabs/goya/goya.c +1 -62
87 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH 3/3 habanalabs: cast to expected type
In reply to Oded GabbayThis patch fix the following sparse warning:
drivers/misc/habanalabs/goya/goya.c:3646:14: warning: incorrect type in assignment (different address spaces)drivers/misc/habanalabs/goya/goya.c:3646:14: expected void *basedrivers/misc/habanalabs/goya/goya.c:3646:14: got void [noderef] <asn:2> *
--- drivers/misc/habanalabs/goya/goya.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/misc/habanalabs/goya/goya.c +1 -1
@@ -3009,7 +3009,7 @@ void *goya_get_int_queue_base(struct hl_device *hdev, u32 queue_id, *dma_handle = hdev->asic_prop.sram_base_address; - base = hdev->pcie_bar[SRAM_CFG_BAR_ID ]; + base = (void *) hdev->pcie_bar[SRAM_CFG_BAR_ID ];switch (queue_id) {case GOYA_QUEUE_ID_MME :
Signature · 1 line
2.17.1