Skip to content

Commit ff92d01

Browse files
osharabiogabbay
authored andcommitted
accel/habanalabs: trace dma map sgtable
Traces the DMA [un]map_sgtable using the new traces we added. Signed-off-by: Ohad Sharabi <[email protected]> Reviewed-by: Oded Gabbay <[email protected]> Signed-off-by: Oded Gabbay <[email protected]>
1 parent 309ed96 commit ff92d01

File tree

6 files changed

+81
-20
lines changed

6 files changed

+81
-20
lines changed

drivers/accel/habanalabs/common/device.c

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,36 @@ void hl_cpu_accessible_dma_pool_free(struct hl_device *hdev, size_t size, void *
188188
hdev->asic_funcs->cpu_accessible_dma_pool_free(hdev, size, vaddr);
189189
}
190190

191-
int hl_dma_map_sgtable(struct hl_device *hdev, struct sg_table *sgt, enum dma_data_direction dir)
191+
int hl_dma_map_sgtable_caller(struct hl_device *hdev, struct sg_table *sgt,
192+
enum dma_data_direction dir, const char *caller)
193+
{
194+
struct asic_fixed_properties *prop = &hdev->asic_prop;
195+
struct scatterlist *sg;
196+
int rc, i;
197+
198+
rc = hdev->asic_funcs->dma_map_sgtable(hdev, sgt, dir);
199+
if (rc)
200+
return rc;
201+
202+
if (!trace_habanalabs_dma_map_page_enabled())
203+
return 0;
204+
205+
for_each_sgtable_dma_sg(sgt, sg, i)
206+
trace_habanalabs_dma_map_page(hdev->dev,
207+
page_to_phys(sg_page(sg)),
208+
sg->dma_address - prop->device_dma_offset_for_host_access,
209+
#ifdef CONFIG_NEED_SG_DMA_LENGTH
210+
sg->dma_length,
211+
#else
212+
sg->length,
213+
#endif
214+
dir, caller);
215+
216+
return 0;
217+
}
218+
219+
int hl_asic_dma_map_sgtable(struct hl_device *hdev, struct sg_table *sgt,
220+
enum dma_data_direction dir)
192221
{
193222
struct asic_fixed_properties *prop = &hdev->asic_prop;
194223
struct scatterlist *sg;
@@ -206,7 +235,30 @@ int hl_dma_map_sgtable(struct hl_device *hdev, struct sg_table *sgt, enum dma_da
206235
return 0;
207236
}
208237

209-
void hl_dma_unmap_sgtable(struct hl_device *hdev, struct sg_table *sgt, enum dma_data_direction dir)
238+
void hl_dma_unmap_sgtable_caller(struct hl_device *hdev, struct sg_table *sgt,
239+
enum dma_data_direction dir, const char *caller)
240+
{
241+
struct asic_fixed_properties *prop = &hdev->asic_prop;
242+
struct scatterlist *sg;
243+
int i;
244+
245+
hdev->asic_funcs->dma_unmap_sgtable(hdev, sgt, dir);
246+
247+
if (trace_habanalabs_dma_unmap_page_enabled()) {
248+
for_each_sgtable_dma_sg(sgt, sg, i)
249+
trace_habanalabs_dma_unmap_page(hdev->dev, page_to_phys(sg_page(sg)),
250+
sg->dma_address - prop->device_dma_offset_for_host_access,
251+
#ifdef CONFIG_NEED_SG_DMA_LENGTH
252+
sg->dma_length,
253+
#else
254+
sg->length,
255+
#endif
256+
dir, caller);
257+
}
258+
}
259+
260+
void hl_asic_dma_unmap_sgtable(struct hl_device *hdev, struct sg_table *sgt,
261+
enum dma_data_direction dir)
210262
{
211263
struct asic_fixed_properties *prop = &hdev->asic_prop;
212264
struct scatterlist *sg;

drivers/accel/habanalabs/common/habanalabs.h

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,11 @@ enum hl_mmu_page_table_location {
159159
#define hl_asic_dma_pool_free(hdev, vaddr, dma_addr) \
160160
hl_asic_dma_pool_free_caller(hdev, vaddr, dma_addr, __func__)
161161

162+
#define hl_dma_map_sgtable(hdev, sgt, dir) \
163+
hl_dma_map_sgtable_caller(hdev, sgt, dir, __func__)
164+
#define hl_dma_unmap_sgtable(hdev, sgt, dir) \
165+
hl_dma_unmap_sgtable_caller(hdev, sgt, dir, __func__)
166+
162167
/*
163168
* Reset Flags
164169
*
@@ -1520,9 +1525,9 @@ struct engines_data {
15201525
* @asic_dma_pool_free: free small DMA allocation from pool.
15211526
* @cpu_accessible_dma_pool_alloc: allocate CPU PQ packet from DMA pool.
15221527
* @cpu_accessible_dma_pool_free: free CPU PQ packet from DMA pool.
1523-
* @hl_dma_unmap_sgtable: DMA unmap scatter-gather table.
1528+
* @dma_unmap_sgtable: DMA unmap scatter-gather table.
1529+
* @dma_map_sgtable: DMA map scatter-gather table.
15241530
* @cs_parser: parse Command Submission.
1525-
* @asic_dma_map_sgtable: DMA map scatter-gather table.
15261531
* @add_end_of_cb_packets: Add packets to the end of CB, if device requires it.
15271532
* @update_eq_ci: update event queue CI.
15281533
* @context_switch: called upon ASID context switch.
@@ -1643,12 +1648,11 @@ struct hl_asic_funcs {
16431648
size_t size, dma_addr_t *dma_handle);
16441649
void (*cpu_accessible_dma_pool_free)(struct hl_device *hdev,
16451650
size_t size, void *vaddr);
1646-
void (*hl_dma_unmap_sgtable)(struct hl_device *hdev,
1647-
struct sg_table *sgt,
1651+
void (*dma_unmap_sgtable)(struct hl_device *hdev, struct sg_table *sgt,
16481652
enum dma_data_direction dir);
1649-
int (*cs_parser)(struct hl_device *hdev, struct hl_cs_parser *parser);
1650-
int (*asic_dma_map_sgtable)(struct hl_device *hdev, struct sg_table *sgt,
1653+
int (*dma_map_sgtable)(struct hl_device *hdev, struct sg_table *sgt,
16511654
enum dma_data_direction dir);
1655+
int (*cs_parser)(struct hl_device *hdev, struct hl_cs_parser *parser);
16521656
void (*add_end_of_cb_packets)(struct hl_device *hdev,
16531657
void *kernel_address, u32 len,
16541658
u32 original_len,
@@ -3670,8 +3674,13 @@ void *hl_asic_dma_pool_zalloc_caller(struct hl_device *hdev, size_t size, gfp_t
36703674
dma_addr_t *dma_handle, const char *caller);
36713675
void hl_asic_dma_pool_free_caller(struct hl_device *hdev, void *vaddr, dma_addr_t dma_addr,
36723676
const char *caller);
3673-
int hl_dma_map_sgtable(struct hl_device *hdev, struct sg_table *sgt, enum dma_data_direction dir);
3674-
void hl_dma_unmap_sgtable(struct hl_device *hdev, struct sg_table *sgt,
3677+
int hl_dma_map_sgtable_caller(struct hl_device *hdev, struct sg_table *sgt,
3678+
enum dma_data_direction dir, const char *caller);
3679+
void hl_dma_unmap_sgtable_caller(struct hl_device *hdev, struct sg_table *sgt,
3680+
enum dma_data_direction dir, const char *caller);
3681+
int hl_asic_dma_map_sgtable(struct hl_device *hdev, struct sg_table *sgt,
3682+
enum dma_data_direction dir);
3683+
void hl_asic_dma_unmap_sgtable(struct hl_device *hdev, struct sg_table *sgt,
36753684
enum dma_data_direction dir);
36763685
int hl_access_sram_dram_region(struct hl_device *hdev, u64 addr, u64 *val,
36773686
enum debugfs_access_type acc_type, enum pci_region region_type, bool set_dram_bar);

drivers/accel/habanalabs/common/memory.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ static int dma_map_host_va(struct hl_device *hdev, u64 addr, u64 size,
244244

245245
*p_userptr = userptr;
246246

247-
rc = hdev->asic_funcs->asic_dma_map_sgtable(hdev, userptr->sgt, DMA_BIDIRECTIONAL);
247+
rc = hl_dma_map_sgtable(hdev, userptr->sgt, DMA_BIDIRECTIONAL);
248248
if (rc) {
249249
dev_err(hdev->dev, "failed to map sgt with DMA region\n");
250250
goto dma_map_err;
@@ -2445,7 +2445,7 @@ void hl_unpin_host_memory(struct hl_device *hdev, struct hl_userptr *userptr)
24452445
hl_debugfs_remove_userptr(hdev, userptr);
24462446

24472447
if (userptr->dma_mapped)
2448-
hdev->asic_funcs->hl_dma_unmap_sgtable(hdev, userptr->sgt, userptr->dir);
2448+
hl_dma_unmap_sgtable(hdev, userptr->sgt, userptr->dir);
24492449

24502450
unpin_user_pages_dirty_lock(userptr->pages, userptr->npages, true);
24512451
kvfree(userptr->pages);

drivers/accel/habanalabs/gaudi/gaudi.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4908,7 +4908,7 @@ static int gaudi_pin_memory_before_cs(struct hl_device *hdev,
49084908

49094909
list_add_tail(&userptr->job_node, parser->job_userptr_list);
49104910

4911-
rc = hdev->asic_funcs->asic_dma_map_sgtable(hdev, userptr->sgt, dir);
4911+
rc = hl_dma_map_sgtable(hdev, userptr->sgt, dir);
49124912
if (rc) {
49134913
dev_err(hdev->dev, "failed to map sgt with DMA region\n");
49144914
goto unpin_memory;
@@ -9144,9 +9144,9 @@ static const struct hl_asic_funcs gaudi_funcs = {
91449144
.asic_dma_pool_free = gaudi_dma_pool_free,
91459145
.cpu_accessible_dma_pool_alloc = gaudi_cpu_accessible_dma_pool_alloc,
91469146
.cpu_accessible_dma_pool_free = gaudi_cpu_accessible_dma_pool_free,
9147-
.hl_dma_unmap_sgtable = hl_dma_unmap_sgtable,
9147+
.dma_unmap_sgtable = hl_asic_dma_unmap_sgtable,
91489148
.cs_parser = gaudi_cs_parser,
9149-
.asic_dma_map_sgtable = hl_dma_map_sgtable,
9149+
.dma_map_sgtable = hl_asic_dma_map_sgtable,
91509150
.add_end_of_cb_packets = gaudi_add_end_of_cb_packets,
91519151
.update_eq_ci = gaudi_update_eq_ci,
91529152
.context_switch = gaudi_context_switch,

drivers/accel/habanalabs/gaudi2/gaudi2.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11497,9 +11497,9 @@ static const struct hl_asic_funcs gaudi2_funcs = {
1149711497
.asic_dma_pool_free = gaudi2_dma_pool_free,
1149811498
.cpu_accessible_dma_pool_alloc = gaudi2_cpu_accessible_dma_pool_alloc,
1149911499
.cpu_accessible_dma_pool_free = gaudi2_cpu_accessible_dma_pool_free,
11500-
.hl_dma_unmap_sgtable = hl_dma_unmap_sgtable,
11500+
.dma_unmap_sgtable = hl_asic_dma_unmap_sgtable,
1150111501
.cs_parser = gaudi2_cs_parser,
11502-
.asic_dma_map_sgtable = hl_dma_map_sgtable,
11502+
.dma_map_sgtable = hl_asic_dma_map_sgtable,
1150311503
.add_end_of_cb_packets = NULL,
1150411504
.update_eq_ci = gaudi2_update_eq_ci,
1150511505
.context_switch = gaudi2_context_switch,

drivers/accel/habanalabs/goya/goya.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3358,7 +3358,7 @@ static int goya_pin_memory_before_cs(struct hl_device *hdev,
33583358

33593359
list_add_tail(&userptr->job_node, parser->job_userptr_list);
33603360

3361-
rc = hdev->asic_funcs->asic_dma_map_sgtable(hdev, userptr->sgt, dir);
3361+
rc = hl_dma_map_sgtable(hdev, userptr->sgt, dir);
33623362
if (rc) {
33633363
dev_err(hdev->dev, "failed to map sgt with DMA region\n");
33643364
goto unpin_memory;
@@ -5465,9 +5465,9 @@ static const struct hl_asic_funcs goya_funcs = {
54655465
.asic_dma_pool_free = goya_dma_pool_free,
54665466
.cpu_accessible_dma_pool_alloc = goya_cpu_accessible_dma_pool_alloc,
54675467
.cpu_accessible_dma_pool_free = goya_cpu_accessible_dma_pool_free,
5468-
.hl_dma_unmap_sgtable = hl_dma_unmap_sgtable,
5468+
.dma_unmap_sgtable = hl_asic_dma_unmap_sgtable,
54695469
.cs_parser = goya_cs_parser,
5470-
.asic_dma_map_sgtable = hl_dma_map_sgtable,
5470+
.dma_map_sgtable = hl_asic_dma_map_sgtable,
54715471
.add_end_of_cb_packets = goya_add_end_of_cb_packets,
54725472
.update_eq_ci = goya_update_eq_ci,
54735473
.context_switch = goya_context_switch,

0 commit comments

Comments
 (0)