habanalabs: removed seq_file parameter from is_idle asic functions
PATCH 1/1 habanalabs: removed seq_file parameter from is_idle asic functions
From: Dani Liberman <[email protected]>
Change is_idle functions so it would be more usable outside debugfs.
Do this by replacing seq_file parameter with regular string.
Signed-off-by Dani Liberman <[email protected]>
Reviewed-by Oded Gabbay <[email protected]>
Signed-off-by Oded Gabbay <[email protected]>
--- drivers/misc/habanalabs/common/debugfs.c | 47 +++++++++- drivers/misc/habanalabs/common/habanalabs.h | 17 +++- drivers/misc/habanalabs/gaudi/gaudi.c | 47 +++++----- drivers/misc/habanalabs/gaudi2/gaudi2.c | 97 +++++++++++---------- drivers/misc/habanalabs/goya/goya.c | 32 +++---- 5 files changed, 151 insertions(+), 89 deletions(-)
drivers/misc/habanalabs/common/debugfs.c +46 -1
@@ -17,6 +17,7 @@#define MMU_ASID_BUF_SIZE 10#define MMU_KBUF_SIZE (MMU_ADDR_BUF_SIZE + MMU_ASID_BUF_SIZE)#define I2C_MAX_TRANSACTION_LEN 8 +#define ENGINES_DATA_MAX_SIZE SZ_16Kstatic struct dentry *hl_debug_root;
@@ -586,11 +587,37 @@ static ssize_t mmu_ack_error_value_write(struct file *file,return -EINVAL ; } +void hl_engine_data_sprintf (struct engines_data *e,const char *fmt, ...) +{ +va_list args; +int str_size; + +va_start (args, fmt); +/* Calculate formatted string length. Assuming each string is null terminated, hence +* increment result by 1 +*/ + str_size =vsnprintf (NULL ,0 , fmt, args) +1 ; +va_end (args); + +if ((e->actual_size + str_size) < e->allocated_buf_size) { +va_start (args, fmt); +vsnprintf (e->buf + e->actual_size, str_size, fmt, args); +va_end (args); + } + +/* Need to update the size even when not updating destination buffer to get the exact size +* of all input strings +*/ + e->actual_size += str_size; + +} +static int engines_show (struct seq_file *s,void *data) {struct hl_debugfs_entry *entry = s->private;struct hl_dbg_device_entry *dev_entry = entry->dev_entry;struct hl_device *hdev = dev_entry->hdev; +struct engines_data eng_data;if (hdev->reset_info.in_reset) { dev_warn_ratelimited(hdev->dev,
@@ -598,7 +625,25 @@ static int engines_show(struct seq_file *s, void *data)return 0 ; } - hdev->asic_funcs->is_device_idle (hdev,NULL ,0 , s); + eng_data.actual_size =0 ; + eng_data.allocated_buf_size =ENGINES_DATA_MAX_SIZE ; + eng_data.buf =vmalloc (eng_data.allocated_buf_size); +if (!eng_data.buf) +return -ENOMEM ; + + hdev->asic_funcs->is_device_idle (hdev,NULL ,0 , &eng_data); + +if (eng_data.actual_size > eng_data.allocated_buf_size) { +dev_err (hdev->dev, +"Engines data size (%d Bytes) is bigger than allocated size (%u Bytes)\n" , + eng_data.actual_size, eng_data.allocated_buf_size); +vfree (eng_data.buf); +return -ENOMEM ; + } + +seq_write (s, eng_data.buf, eng_data.actual_size); + +vfree (eng_data.buf);return 0 ; }
drivers/misc/habanalabs/common/habanalabs.h +15 -2
@@ -1371,6 +1371,18 @@ struct fw_load_mgr {struct hl_cs ; +/** +* struct engines_data - asic engines data +* @buf: buffer for engines data in ascii +* @actual_size: actual size of data that was written by the driver to the allocated buffer +* @allocated_buf_size: total size of allocated buffer +*/ +struct engines_data { +char *buf; +int actual_size; +u32 allocated_buf_size; +}; +/** * struct hl_asic_funcs - ASIC specific functions that are can be called from * common code.
@@ -1570,8 +1582,8 @@ struct hl_asic_funcs {int (*mmu_prefetch_cache_range)(struct hl_ctx *ctx,u32 flags,u32 asid,u64 va,u64 size);int (*send_heartbeat)(struct hl_device *hdev);int (*debug_coresight)(struct hl_device *hdev,struct hl_ctx *ctx,void *data); -bool (*is_device_idle)(struct hl_device *hdev,u64 *mask_arr, -u8 mask_len,struct seq_file *s); +bool (*is_device_idle)(struct hl_device *hdev,u64 *mask_arr,u8 mask_len, +struct engines_data *e);int (*non_hard_reset_late_init)(struct hl_device *hdev);void (*hw_queues_lock)(struct hl_device *hdev);void (*hw_queues_unlock)(struct hl_device *hdev);
@@ -3743,6 +3755,7 @@ struct hl_mmap_mem_buf * hl_mmap_mem_buf_alloc(struct hl_mem_mgr *mmg, struct hl_mmap_mem_buf_behavior *behavior, gfp_t gfp, void *args); +void hl_engine_data_sprintf (struct engines_data *e,const char *fmt, ...);#ifdef CONFIG_DEBUG_FS
drivers/misc/habanalabs/gaudi/gaudi.c +24 -23
111 lines not on this page · raw message
drivers/misc/habanalabs/gaudi2/gaudi2.c +50 -47
193 lines not on this page · raw message
drivers/misc/habanalabs/goya/goya.c +16 -16
@@ -5137,8 +5137,8 @@ int goya_cpucp_info_get(struct hl_device *hdev)return 0 ; } -static bool goya_is_device_idle (struct hl_device *hdev,u64 *mask_arr, -u8 mask_len,struct seq_file *s) +static bool goya_is_device_idle (struct hl_device *hdev,u64 *mask_arr,u8 mask_len, +struct engines_data *e) {const char *fmt ="%-5d%-9s%#-14x%#-16x%#x\n" ;const char *dma_fmt ="%-5d%-9s%#-14x%#x\n" ;
@@ -5149,9 +5149,9 @@ static bool goya_is_device_idle(struct hl_device *hdev, u64 *mask_arr,u64 offset;int i; -if (s) -seq_puts (s,"\nDMA is_idle QM_GLBL_STS0 DMA_CORE_STS0\n" -"--- ------- ------------ -------------\n" ); +if (e) +hl_engine_data_sprintf (e,"\nDMA is_idle QM_GLBL_STS0 DMA_CORE_STS0\n" +"--- ------- ------------ -------------\n" ); offset = mmDMA_QM_1_GLBL_STS0 - mmDMA_QM_0_GLBL_STS0;
@@ -5164,13 +5164,13 @@ static bool goya_is_device_idle(struct hl_device *hdev, u64 *mask_arr,if (mask && !is_eng_idle)set_bit (GOYA_ENGINE_ID_DMA_0 + i, mask); -if (s) -seq_printf (s, dma_fmt, i, is_eng_idle ?"Y" :"N" , +if (e) +hl_engine_data_sprintf (e, dma_fmt, i, is_eng_idle ?"Y" :"N" , qm_glbl_sts0, dma_core_sts0); } -if (s) -seq_puts (s, +if (e) +hl_engine_data_sprintf (e,"\nTPC is_idle QM_GLBL_STS0 CMDQ_GLBL_STS0 CFG_STATUS\n" "--- ------- ------------ -------------- ----------\n" );
@@ -5187,13 +5187,13 @@ static bool goya_is_device_idle(struct hl_device *hdev, u64 *mask_arr,if (mask && !is_eng_idle)set_bit (GOYA_ENGINE_ID_TPC_0 + i, mask); -if (s) -seq_printf (s, fmt, i, is_eng_idle ?"Y" :"N" , +if (e) +hl_engine_data_sprintf (e, fmt, i, is_eng_idle ?"Y" :"N" , qm_glbl_sts0, cmdq_glbl_sts0, tpc_cfg_sts); } -if (s) -seq_puts (s, +if (e) +hl_engine_data_sprintf (e,"\nMME is_idle QM_GLBL_STS0 CMDQ_GLBL_STS0 ARCH_STATUS\n" "--- ------- ------------ -------------- -----------\n" );
@@ -5207,10 +5207,10 @@ static bool goya_is_device_idle(struct hl_device *hdev, u64 *mask_arr,if (mask && !is_eng_idle)set_bit (GOYA_ENGINE_ID_MME_0 , mask); -if (s) { -seq_printf (s, fmt,0 , is_eng_idle ?"Y" :"N" , qm_glbl_sts0, +if (e) { +hl_engine_data_sprintf (e, fmt,0 , is_eng_idle ?"Y" :"N" , qm_glbl_sts0, cmdq_glbl_sts0, mme_arch_sts); -seq_puts (s,"\n" ); +hl_engine_data_sprintf (e,"\n" ); }return is_idle;
Signature · 1 line
2.25.1