habanalabs: don't init vm module if no MMU
PATCH 1/1 habanalabs: don't init vm module if no MMU
In case we are running without MMU enabled (debug mode), no need to initialize the VM module in the driver.
--- drivers/misc/habanalabs/common/memory.c | 33 +++++++++++-------------- 1 file changed, 14 insertions(+), 19 deletions(-)
drivers/misc/habanalabs/common/memory.c +14 -19
@@ -1685,27 +1685,19 @@ int hl_vm_ctx_init(struct hl_ctx *ctx)* In case of DRAM mapping, the returned address is the physical * address of the memory related to the given handle. */ -if (ctx->hdev->mmu_enable) { - dram_range_start = prop->dmmu.start_addr; - dram_range_end = prop->dmmu.end_addr; - host_range_start = prop->pmmu.start_addr; - host_range_end = prop->pmmu.end_addr; - host_huge_range_start = prop->pmmu_huge.start_addr; - host_huge_range_end = prop->pmmu_huge.end_addr; - }else { - dram_range_start = prop->dram_user_base_address; - dram_range_end = prop->dram_end_address; - host_range_start = prop->dram_user_base_address; - host_range_end = prop->dram_end_address; - host_huge_range_start = prop->dram_user_base_address; - host_huge_range_end = prop->dram_end_address; - } +if (!ctx->hdev->mmu_enable) +return 0 ; + + dram_range_start = prop->dmmu.start_addr; + dram_range_end = prop->dmmu.end_addr; + host_range_start = prop->pmmu.start_addr; + host_range_end = prop->pmmu.end_addr; + host_huge_range_start = prop->pmmu_huge.start_addr; + host_huge_range_end = prop->pmmu_huge.end_addr;return vm_ctx_init_with_ranges (ctx, host_range_start, host_range_end, - host_huge_range_start, - host_huge_range_end, - dram_range_start, - dram_range_end); + host_huge_range_start, host_huge_range_end, + dram_range_start, dram_range_end); }/*
@@ -1737,6 +1729,9 @@ void hl_vm_ctx_fini(struct hl_ctx *ctx)struct hlist_node *tmp_node;int i; +if (!ctx->hdev->mmu_enable) +return ; +hl_debugfs_remove_ctx_mem_hash (hdev, ctx);/*
Signature · 1 line
2.17.1
PATCH 1/1 habanalabs: minimize prints when everything is fine
No need to print when the driver starts to initialize the H/W. Drivers should be silent when everything is OK.
--- drivers/misc/habanalabs/gaudi/gaudi.c | 2 -- drivers/misc/habanalabs/goya/goya.c | 2 -- 2 files changed, 4 deletions(-)
drivers/misc/habanalabs/gaudi/gaudi.c +0 -2
@@ -2947,8 +2947,6 @@ static int gaudi_hw_init(struct hl_device *hdev) {int rc; -dev_info (hdev->dev,"Starting initialization of H/W\n" ); -gaudi_pre_hw_init (hdev);gaudi_init_pci_dma_qmans (hdev);
drivers/misc/habanalabs/goya/goya.c +0 -2
@@ -2505,8 +2505,6 @@ static int goya_hw_init(struct hl_device *hdev)struct asic_fixed_properties *prop = &hdev->asic_prop;int rc; -dev_info (hdev->dev,"Starting initialization of H/W\n" ); -/* Perform read from the device to make sure device is up */ RREG32 (mmPCIE_DBI_DEVICE_ID_VENDOR_ID_REG);
Signature · 1 line
2.17.1
PATCH 1/4 habanalabs: sync stream structures refactor
In reply to Oded GabbayFrom: Ofir Bitton <[email protected]>
Refactor sync stream implementation by adding more structures for better readability. In addition reducing allocated resources.
--- drivers/misc/habanalabs/common/habanalabs.h | 78 +++++--- drivers/misc/habanalabs/common/hw_queue.c | 197 +++++++++++--------- drivers/misc/habanalabs/gaudi/gaudi.c | 37 ++-- drivers/misc/habanalabs/goya/goya.c | 4 +- 4 files changed, 180 insertions(+), 136 deletions(-)
drivers/misc/habanalabs/common/habanalabs.h +50 -28
@@ -68,9 +68,6 @@#define HL_RSVD_SOBS 4#define HL_RSVD_MONS 2 -#define HL_RSVD_SOBS_IN_USE 2 -#define HL_RSVD_MONS_IN_USE 1 -#define HL_MAX_SOB_VAL (1 << 15)#define IS_POWER_OF_2 (n) (n != 0 && ((n & (n - 1)) == 0))
@@ -80,6 +77,22 @@#define HL_MAX_DCORES 4 +/** +* struct hl_gen_wait_properties - properties for generating a wait CB +* @data: command buffer +* @q_idx: queue id is used to extract fence register address +* @sob_id: SOB id to use in this wait CB +* @sob_val: SOB value to wait for +* @mon_id: monitor to use in this wait CB +*/ +struct hl_gen_wait_properties { +void *data; +u32 q_idx; +u16 sob_id; +u16 sob_val; +u16 mon_id; +}; +/** * struct pgt_info - MMU hop page info. * @node: hash linked-list node for the pgts shadow hash of pgts.
@@ -502,9 +515,27 @@ struct hl_cs_job;#define HL_CPU_ACCESSIBLE_MEM_SIZE SZ_2M/** -* struct hl_hw_queue - describes a H/W transport queue. +* struct hl_sync_stream_properties - +* describes a H/W queue sync stream properties * @hw_sob: array of the used H/W SOBs by this H/W queue. +* @next_sob_val: the next value to use for the currently used SOB. +* @base_sob_id: the base SOB id of the SOBs used by this queue. +* @base_mon_id: the base MON id of the MONs used by this queue. +* @curr_sob_offset: the id offset to the currently used SOB from the +* HL_RSVD_SOBS that are being used by this queue. +*/ +struct hl_sync_stream_properties { +struct hl_hw_sob hw_sob[HL_RSVD_SOBS ]; +u16 next_sob_val; +u16 base_sob_id; +u16 base_mon_id; +u8 curr_sob_offset; +}; + +/** +* struct hl_hw_queue - describes a H/W transport queue. * @shadow_queue: pointer to a shadow queue that holds pointers to jobs. +* @sync_stream_prop: sync stream queue properties * @queue_type: type of queue. * @kernel_address: holds the queue's kernel virtual address. * @bus_address: holds the queue's DMA address.
@@ -514,33 +545,24 @@ struct hl_cs_job;* @cq_id: the id for the corresponding CQ for this H/W queue. * @msi_vec: the IRQ number of the H/W queue. * @int_queue_len: length of internal queue (number of entries). -* @next_sob_val: the next value to use for the currently used SOB. -* @base_sob_id: the base SOB id of the SOBs used by this queue. -* @base_mon_id: the base MON id of the MONs used by this queue. * @valid: is the queue valid (we have array of 32 queues, not all of them * exist). -* @curr_sob_offset: the id offset to the currently used SOB from the -* HL_RSVD_SOBS that are being used by this queue. * @supports_sync_stream: True if queue supports sync stream */ struct hl_hw_queue { -struct hl_hw_sob hw_sob[HL_RSVD_SOBS ]; -struct hl_cs_job **shadow_queue; -enum hl_queue_type queue_type; -u64 kernel_address; -dma_addr_t bus_address; -u32 pi; -atomic_t ci; -u32 hw_queue_id; -u32 cq_id; -u32 msi_vec; -u16 int_queue_len; -u16 next_sob_val; -u16 base_sob_id; -u16 base_mon_id; -u8 valid; -u8 curr_sob_offset; -u8 supports_sync_stream; +struct hl_cs_job **shadow_queue; +struct hl_sync_stream_properties sync_stream_prop; +enum hl_queue_type queue_type; +u64 kernel_address; +dma_addr_t bus_address; +u32 pi; +atomic_t ci; +u32 hw_queue_id; +u32 cq_id; +u32 msi_vec; +u16 int_queue_len; +u8 valid; +u8 supports_sync_stream; };/**
@@ -823,8 +845,8 @@ struct hl_asic_funcs {u32 (*get_signal_cb_size)(struct hl_device *hdev);u32 (*get_wait_cb_size)(struct hl_device *hdev);void (*gen_signal_cb)(struct hl_device *hdev,void *data,u16 sob_id); -void (*gen_wait_cb)(struct hl_device *hdev,void *data,u16 sob_id, -u16 sob_val,u16 mon_id,u32 q_idx); +void (*gen_wait_cb)(struct hl_device *hdev, +struct hl_gen_wait_properties *prop);void (*reset_sob)(struct hl_device *hdev,void *data);void (*set_dma_mask_from_fw)(struct hl_device *hdev);u64 (*get_device_time)(struct hl_device *hdev);
drivers/misc/habanalabs/common/hw_queue.c +110 -87
245 lines not on this page · raw message
drivers/misc/habanalabs/gaudi/gaudi.c +18 -19
@@ -472,9 +472,11 @@ static int gaudi_get_fixed_properties(struct hl_device *hdev) prop->max_pending_cs =GAUDI_MAX_PENDING_CS ; prop->first_available_user_sob[HL_GAUDI_WS_DCORE ] = - num_sync_stream_queues *HL_RSVD_SOBS ; + prop->sync_stream_first_sob + + (num_sync_stream_queues *HL_RSVD_SOBS ); prop->first_available_user_mon[HL_GAUDI_WS_DCORE ] = - num_sync_stream_queues *HL_RSVD_MONS ; + prop->sync_stream_first_mon + + (num_sync_stream_queues *HL_RSVD_MONS );return 0 ; }
@@ -6472,16 +6474,16 @@ static u32 gaudi_add_fence_pkt(struct packet_fence *pkt)return pkt_size; } -static void gaudi_gen_wait_cb (struct hl_device *hdev,void *data,u16 sob_id, -u16 sob_val,u16 mon_id,u32 q_idx) +static void gaudi_gen_wait_cb (struct hl_device *hdev, +struct hl_gen_wait_properties *prop) { -struct hl_cb *cb = (struct hl_cb *) data; +struct hl_cb *cb = (struct hl_cb *) prop->data;void *buf = (void *) (uintptr_t ) cb->kernel_address;u64 monitor_base, fence_addr =0 ;u32 size =0 ;u16 msg_addr_offset; -switch (q_idx) { +switch (prop->q_idx) {case GAUDI_QUEUE_ID_DMA_0_0 : fence_addr = mmDMA0_QM_CP_FENCE2_RDATA_0;break ;
@@ -6521,7 +6523,7 @@ static void gaudi_gen_wait_cb(struct hl_device *hdev, void *data, u16 sob_id,default :/* queue index should be valid here */ dev_crit (hdev->dev,"wrong queue id %d for wait packet\n" , - q_idx); + prop->q_idx);return ; }
@@ -6534,17 +6536,15 @@ static void gaudi_gen_wait_cb(struct hl_device *hdev, void *data, u16 sob_id, monitor_base = mmSYNC_MNGR_W_S_SYNC_MNGR_OBJS_MON_PAY_ADDRL_0;/* First monitor config packet: low address of the sync */ - msg_addr_offset = - (mmSYNC_MNGR_W_S_SYNC_MNGR_OBJS_MON_PAY_ADDRL_0 + mon_id *4 ) - - monitor_base; + msg_addr_offset = (mmSYNC_MNGR_W_S_SYNC_MNGR_OBJS_MON_PAY_ADDRL_0 + + prop->mon_id *4 ) - monitor_base; size +=gaudi_add_mon_msg_short (buf + size, (u32 ) fence_addr, msg_addr_offset);/* Second monitor config packet: high address of the sync */ - msg_addr_offset = - (mmSYNC_MNGR_W_S_SYNC_MNGR_OBJS_MON_PAY_ADDRH_0 + mon_id *4 ) - - monitor_base; + msg_addr_offset = (mmSYNC_MNGR_W_S_SYNC_MNGR_OBJS_MON_PAY_ADDRH_0 + + prop->mon_id *4 ) - monitor_base; size +=gaudi_add_mon_msg_short (buf + size, (u32) (fence_addr >>32 ), msg_addr_offset);
@@ -6553,18 +6553,17 @@ static void gaudi_gen_wait_cb(struct hl_device *hdev, void *data, u16 sob_id,* Third monitor config packet: the payload, i.e. what to write when the * sync triggers */ - msg_addr_offset = - (mmSYNC_MNGR_W_S_SYNC_MNGR_OBJS_MON_PAY_DATA_0 + mon_id *4 ) - - monitor_base; + msg_addr_offset = (mmSYNC_MNGR_W_S_SYNC_MNGR_OBJS_MON_PAY_DATA_0 + + prop->mon_id *4 ) - monitor_base; size +=gaudi_add_mon_msg_short (buf + size,1 , msg_addr_offset);/* Fourth monitor config packet: bind the monitor to a sync object */ msg_addr_offset = - (mmSYNC_MNGR_W_S_SYNC_MNGR_OBJS_MON_ARM_0 + mon_id *4 ) - + (mmSYNC_MNGR_W_S_SYNC_MNGR_OBJS_MON_ARM_0 + prop->mon_id *4 ) - monitor_base; - size +=gaudi_add_arm_monitor_pkt (buf + size, sob_id, sob_val, - msg_addr_offset); + size +=gaudi_add_arm_monitor_pkt (buf + size, prop->sob_id, + prop->sob_val, msg_addr_offset);/* Fence packet */ size +=gaudi_add_fence_pkt (buf + size);
drivers/misc/habanalabs/goya/goya.c +2 -2
@@ -5297,8 +5297,8 @@ static void goya_gen_signal_cb(struct hl_device *hdev, void *data, u16 sob_id) } -static void goya_gen_wait_cb (struct hl_device *hdev,void *data,u16 sob_id, -u16 sob_val,u16 mon_id,u32 q_idx) +static void goya_gen_wait_cb (struct hl_device *hdev, +struct hl_gen_wait_properties *prop) { }
Signature · 1 line
2.17.1
PATCH 2/4 habanalabs: add support for multiple SOBs per monitor
In reply to Oded GabbayFrom: Ofir Bitton <[email protected]>
Support advanced monitor functionality to monitor more than a single SOB. In addition expand all CB generation functions with buffer offset in order to put in them multiple packets that are generated by different functions.
--- .../habanalabs/common/command_submission.c | 32 ++++ drivers/misc/habanalabs/common/habanalabs.h | 16 +- drivers/misc/habanalabs/common/hw_queue.c | 6 +- drivers/misc/habanalabs/gaudi/gaudi.c | 137 ++++++++++++------ drivers/misc/habanalabs/goya/goya.c | 9 +- 5 files changed, 143 insertions(+), 57 deletions(-)
drivers/misc/habanalabs/common/command_submission.c +32 -0
@@ -38,6 +38,38 @@ void hl_sob_reset_error(struct kref *ref) hw_sob->q_idx, hw_sob->sob_id); } +/** +* hl_gen_sob_mask() - Generates a sob mask to be used in a monitor arm packet +* @sob_base: sob base id +* @sob_mask: sob user mask, each bit represents a sob offset from sob base +* @mask: generated mask +* +* Return: 0 if given parameters are valid +*/ +int hl_gen_sob_mask (u16 sob_base,u8 sob_mask,u8 *mask) +{ +int i; + +if (sob_mask ==0 ) +return -EINVAL ; + +if (sob_mask ==0x1 ) { + *mask = ~(1 << (sob_base &0x7 )); + }else { +/* find msb in order to verify sob range is valid */ +for (i =BITS_PER_BYTE -1 ; i >=0 ; i--) +if (BIT (i) & sob_mask) +break ; + +if (i > (HL_MAX_SOBS_PER_MONITOR - (sob_base &0x7 ) -1 )) +return -EINVAL ; + + *mask = ~sob_mask; + } + +return 0 ; +} +static void hl_fence_release (struct kref *kref) { struct hl_fence *fence =
drivers/misc/habanalabs/common/habanalabs.h +12 -4
@@ -77,20 +77,26 @@#define HL_MAX_DCORES 4 +#define HL_MAX_SOBS_PER_MONITOR 8 +/** * struct hl_gen_wait_properties - properties for generating a wait CB * @data: command buffer * @q_idx: queue id is used to extract fence register address -* @sob_id: SOB id to use in this wait CB +* @size: offset in command buffer +* @sob_base: SOB base to use in this wait CB * @sob_val: SOB value to wait for * @mon_id: monitor to use in this wait CB +* @sob_mask: each bit represents a SOB offset from sob_base to be used */ struct hl_gen_wait_properties {void *data;u32 q_idx; -u16 sob_id; +u32 size; +u16 sob_base;u16 sob_val;u16 mon_id; +u8 sob_mask; };/**
@@ -844,8 +850,9 @@ struct hl_asic_funcs {int (*load_boot_fit_to_device)(struct hl_device *hdev);u32 (*get_signal_cb_size)(struct hl_device *hdev);u32 (*get_wait_cb_size)(struct hl_device *hdev); -void (*gen_signal_cb)(struct hl_device *hdev,void *data,u16 sob_id); -void (*gen_wait_cb)(struct hl_device *hdev, +u32 (*gen_signal_cb)(struct hl_device *hdev,void *data,u16 sob_id, +u32 size); +u32 (*gen_wait_cb)(struct hl_device *hdev,struct hl_gen_wait_properties *prop);void (*reset_sob)(struct hl_device *hdev,void *data);void (*set_dma_mask_from_fw)(struct hl_device *hdev);
@@ -1927,6 +1934,7 @@ void hl_cs_rollback_all(struct hl_device *hdev);struct hl_cs_job *hl_cs_allocate_job (struct hl_device *hdev,enum hl_queue_type queue_type,bool is_kernel_allocated_cb);void hl_sob_reset_error (struct kref *ref); +int hl_gen_sob_mask (u16 sob_base,u8 sob_mask,u8 *mask);void hl_fence_put (struct hl_fence *fence);void hl_fence_get (struct hl_fence *fence);
drivers/misc/habanalabs/common/hw_queue.c +4 -2
@@ -408,7 +408,7 @@ static void init_signal_cs(struct hl_device *hdev, cs_cmpl->hw_sob->sob_id, cs_cmpl->sob_val, q_idx); hdev->asic_funcs->gen_signal_cb (hdev, job->patched_cb, - cs_cmpl->hw_sob->sob_id); + cs_cmpl->hw_sob->sob_id,0 );kref_get (&hw_sob->kref);
@@ -455,10 +455,12 @@ static void init_wait_cs(struct hl_device *hdev, struct hl_cs *cs, prop->base_mon_id, q_idx); wait_prop.data = (void *) job->patched_cb; - wait_prop.sob_id = cs_cmpl->hw_sob->sob_id; + wait_prop.sob_base = cs_cmpl->hw_sob->sob_id; + wait_prop.sob_mask =0x1 ; wait_prop.sob_val = cs_cmpl->sob_val; wait_prop.mon_id = prop->base_mon_id; wait_prop.q_idx = q_idx; + wait_prop.size =0 ; hdev->asic_funcs->gen_wait_cb (hdev, &wait_prop);kref_get (&cs_cmpl->hw_sob->kref);
drivers/misc/habanalabs/gaudi/gaudi.c +90 -47
226 lines not on this page · raw message
drivers/misc/habanalabs/goya/goya.c +5 -4
@@ -5292,15 +5292,16 @@ static u32 goya_get_wait_cb_size(struct hl_device *hdev)return 0 ; } -static void goya_gen_signal_cb (struct hl_device *hdev,void *data,u16 sob_id) +static u32 goya_gen_signal_cb (struct hl_device *hdev,void *data,u16 sob_id, +u32 size) { - +return 0 ; } -static void goya_gen_wait_cb (struct hl_device *hdev, +static u32 goya_gen_wait_cb (struct hl_device *hdev,struct hl_gen_wait_properties *prop) { - +return 0 ; }static void goya_reset_sob (struct hl_device *hdev,void *data)
Signature · 1 line
2.17.1
PATCH 3/4 habanalabs: sync stream refactor functions
In reply to Oded GabbayFrom: Ofir Bitton <[email protected]>
Refactor sync stream implementation by reducing function length for better readability.
--- .../habanalabs/common/command_submission.c | 210 ++++++++++-------- 1 file changed, 119 insertions(+), 91 deletions(-)
drivers/misc/habanalabs/common/command_submission.c +119 -91
@@ -792,22 +792,121 @@ static int cs_ioctl_default(struct hl_fpriv *hpriv, void __user *chunks,return rc; } +static int cs_ioctl_extract_signal_seq (struct hl_device *hdev, +struct hl_cs_chunk *chunk,u64 *signal_seq) +{ +u64 *signal_seq_arr =NULL ; +u32 size_to_copy, signal_seq_arr_len; +int rc =0 ; + + signal_seq_arr_len = chunk->num_signal_seq_arr; + +/* currently only one signal seq is supported */ +if (signal_seq_arr_len !=1 ) { +dev_err (hdev->dev, +"Wait for signal CS supports only one signal CS seq\n" ); +return -EINVAL ; + } + + signal_seq_arr =kmalloc_array (signal_seq_arr_len, +sizeof (*signal_seq_arr), +GFP_ATOMIC ); +if (!signal_seq_arr) +return -ENOMEM ; + + size_to_copy = chunk->num_signal_seq_arr *sizeof (*signal_seq_arr); +if (copy_from_user (signal_seq_arr, +u64_to_user_ptr (chunk->signal_seq_arr), + size_to_copy)) { +dev_err (hdev->dev, +"Failed to copy signal seq array from user\n" ); + rc = -EFAULT ; + goto out; + } + +/* currently it is guaranteed to have only one signal seq */ + *signal_seq = signal_seq_arr[0 ]; + +out: +kfree (signal_seq_arr); + +return rc; +} + +static int cs_ioctl_signal_wait_create_jobs (struct hl_device *hdev, +struct hl_ctx *ctx,struct hl_cs *cs,enum hl_queue_type q_type, +u32 q_idx) +{ +struct hl_cs_counters_atomic *cntr; +struct hl_cs_job *job; +struct hl_cb *cb; +u32 cb_size; + + cntr = &hdev->aggregated_cs_counters; + + job =hl_cs_allocate_job (hdev, q_type, true); +if (!job) { + ctx->cs_counters.out_of_mem_drop_cnt++; +atomic64_inc (&cntr->out_of_mem_drop_cnt); +dev_err (hdev->dev,"Failed to allocate a new job\n" ); +return -ENOMEM ; + } + +if (cs->type ==CS_TYPE_WAIT ) + cb_size = hdev->asic_funcs->get_wait_cb_size (hdev); +else + cb_size = hdev->asic_funcs->get_signal_cb_size (hdev); + + cb =hl_cb_kernel_create (hdev, cb_size, + q_type ==QUEUE_TYPE_HW && hdev->mmu_enable); +if (!cb) { + ctx->cs_counters.out_of_mem_drop_cnt++; +atomic64_inc (&cntr->out_of_mem_drop_cnt); +kfree (job); +return -EFAULT ; + } + + job->id =0 ; + job->cs = cs; + job->user_cb = cb; + job->user_cb->cs_cnt++; + job->user_cb_size = cb_size; + job->hw_queue_id = q_idx; + +/* +* No need in parsing, user CB is the patched CB. +* We call hl_cb_destroy() out of two reasons - we don't need the CB in +* the CB idr anymore and to decrement its refcount as it was +* incremented inside hl_cb_kernel_create(). +*/ + job->patched_cb = job->user_cb; + job->job_cb_size = job->user_cb_size; +hl_cb_destroy (hdev, &hdev->kernel_cb_mgr, cb->id <<PAGE_SHIFT ); + + cs->jobs_in_queue_cnt[job->hw_queue_id]++; + +list_add_tail (&job->cs_node, &cs->job_list); + +hl_debugfs_add_job (hdev, job); + +return 0 ; +} +static int cs_ioctl_signal_wait (struct hl_fpriv *hpriv,enum hl_cs_type cs_type,void __user *chunks,u32 num_chunks,u64 *cs_seq) { -u32 size_to_copy, q_idx, signal_seq_arr_len, cb_size; +struct hl_device *hdev = hpriv->hdev; +struct hl_ctx *ctx = hpriv->ctx;struct hl_cs_chunk *cs_chunk_array, *chunk;struct hw_queue_properties *hw_queue_prop; -u64 *signal_seq_arr =NULL , signal_seq; -struct hl_device *hdev = hpriv->hdev; -struct hl_cs_counters_atomic *cntr;struct hl_fence *sig_fence =NULL ; -struct hl_ctx *ctx = hpriv->ctx; -enum hl_queue_type q_type; -struct hl_cs_job *job; +struct hl_cs_counters_atomic *cntr; +struct hl_cs_compl *sig_waitcs_cmpl;struct hl_cs *cs; -struct hl_cb *cb; +enum hl_queue_type q_type; +u32 size_to_copy, q_idx; +u64 signal_seq;int rc; *cs_seq =ULLONG_MAX ;
@@ -857,52 +956,23 @@ static int cs_ioctl_signal_wait(struct hl_fpriv *hpriv, enum hl_cs_type cs_type, }if (cs_type ==CS_TYPE_WAIT ) { -struct hl_cs_compl *sig_waitcs_cmpl; - - signal_seq_arr_len = chunk->num_signal_seq_arr; - -/* currently only one signal seq is supported */ -if (signal_seq_arr_len !=1 ) { -dev_err (hdev->dev, -"Wait for signal CS supports only one signal CS seq\n" ); - rc = -EINVAL ; + rc =cs_ioctl_extract_signal_seq (hdev, chunk, &signal_seq); +if (rc) goto free_cs_chunk_array; - } - signal_seq_arr =kmalloc_array (signal_seq_arr_len, -sizeof (*signal_seq_arr), -GFP_ATOMIC ); -if (!signal_seq_arr) { - rc = -ENOMEM ; - goto free_cs_chunk_array; - } - - size_to_copy = chunk->num_signal_seq_arr * -sizeof (*signal_seq_arr); -if (copy_from_user (signal_seq_arr, -u64_to_user_ptr (chunk->signal_seq_arr), - size_to_copy)) { -dev_err (hdev->dev, -"Failed to copy signal seq array from user\n" ); - rc = -EFAULT ; - goto free_signal_seq_array; - } - -/* currently it is guaranteed to have only one signal seq */ - signal_seq = signal_seq_arr[0 ]; sig_fence =hl_ctx_get_fence (ctx, signal_seq);if (IS_ERR (sig_fence)) {dev_err (hdev->dev,"Failed to get signal CS with seq 0x%llx\n" , signal_seq); rc =PTR_ERR (sig_fence); - goto free_signal_seq_array; + goto free_cs_chunk_array; }if (!sig_fence) {/* signal CS already finished */ rc =0 ; - goto free_signal_seq_array; + goto free_cs_chunk_array; } sig_waitcs_cmpl =
@@ -914,14 +984,14 @@ static int cs_ioctl_signal_wait(struct hl_fpriv *hpriv, enum hl_cs_type cs_type, signal_seq);hl_fence_put (sig_fence); rc = -EINVAL ; - goto free_signal_seq_array; + goto free_cs_chunk_array; }if (completion_done (&sig_fence->completion)) {/* signal CS already finished */ hl_fence_put (sig_fence); rc =0 ; - goto free_signal_seq_array; + goto free_cs_chunk_array; } }
@@ -933,70 +1003,31 @@ static int cs_ioctl_signal_wait(struct hl_fpriv *hpriv, enum hl_cs_type cs_type,if (cs_type ==CS_TYPE_WAIT )hl_fence_put (sig_fence);hl_ctx_put (ctx); - goto free_signal_seq_array; + goto free_cs_chunk_array; }/* * Save the signal CS fence for later initialization right before * hanging the wait CS on the queue. */ -if (cs->type ==CS_TYPE_WAIT ) +if (cs_type ==CS_TYPE_WAIT ) cs->signal_fence = sig_fence;hl_debugfs_add_cs (cs); *cs_seq = cs->sequence; - job =hl_cs_allocate_job (hdev, q_type, true); -if (!job) { - ctx->cs_counters.out_of_mem_drop_cnt++; -atomic64_inc (&cntr->out_of_mem_drop_cnt); -dev_err (hdev->dev,"Failed to allocate a new job\n" ); - rc = -ENOMEM ; - goto put_cs; - } - -if (cs->type ==CS_TYPE_WAIT ) - cb_size = hdev->asic_funcs->get_wait_cb_size (hdev); -else - cb_size = hdev->asic_funcs->get_signal_cb_size (hdev); +if (cs_type ==CS_TYPE_WAIT || cs_type ==CS_TYPE_SIGNAL ) + rc =cs_ioctl_signal_wait_create_jobs (hdev, ctx, cs, q_type, + q_idx); - cb =hl_cb_kernel_create (hdev, cb_size, - q_type ==QUEUE_TYPE_HW && hdev->mmu_enable); -if (!cb) { - ctx->cs_counters.out_of_mem_drop_cnt++; -atomic64_inc (&cntr->out_of_mem_drop_cnt); -kfree (job); - rc = -EFAULT ; +if (rc) goto put_cs; - } - job->id =0 ; - job->cs = cs; - job->user_cb = cb; - job->user_cb->cs_cnt++; - job->user_cb_size = cb_size; - job->hw_queue_id = q_idx; - -/* -* No need in parsing, user CB is the patched CB. -* We call hl_cb_destroy() out of two reasons - we don't need the CB in -* the CB idr anymore and to decrement its refcount as it was -* incremented inside hl_cb_kernel_create(). -*/ - job->patched_cb = job->user_cb; - job->job_cb_size = job->user_cb_size; -hl_cb_destroy (hdev, &hdev->kernel_cb_mgr, cb->id <<PAGE_SHIFT ); - - cs->jobs_in_queue_cnt[job->hw_queue_id]++; - -list_add_tail (&job->cs_node, &cs->job_list);/* increment refcount as for external queues we get completion */ cs_get (cs); -hl_debugfs_add_job (hdev, job); - rc =hl_hw_queue_schedule_cs (cs);if (rc) {if (rc != -EAGAIN )
@@ -1016,9 +1047,6 @@ static int cs_ioctl_signal_wait(struct hl_fpriv *hpriv, enum hl_cs_type cs_type, put_cs:/* We finished with the CS in this function, so put the ref */ cs_put (cs); -free_signal_seq_array: -if (cs_type ==CS_TYPE_WAIT ) -kfree (signal_seq_arr); free_cs_chunk_array:kfree (cs_chunk_array); out:
Signature · 1 line
2.17.1
PATCH 4/4 habanalabs: remove duplicate check
In reply to Oded GabbayWe already check if queue index is smaller than max queues a few lines above this check so no need to check this again.
--- drivers/misc/habanalabs/common/command_submission.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/misc/habanalabs/common/command_submission.c +4 -3
@@ -948,9 +948,10 @@ static int cs_ioctl_signal_wait(struct hl_fpriv *hpriv, enum hl_cs_type cs_type, hw_queue_prop = &hdev->asic_prop.hw_queues_props[q_idx]; q_type = hw_queue_prop->type; -if ((q_idx >= hdev->asic_prop.max_queues) || - (!hw_queue_prop->supports_sync_stream)) { -dev_err (hdev->dev,"Queue index %d is invalid\n" , q_idx); +if (!hw_queue_prop->supports_sync_stream) { +dev_err (hdev->dev, +"Queue index %d does not support sync stream operations\n" , + q_idx); rc = -EINVAL ; goto free_cs_chunk_array; }
Signature · 1 line
2.17.1