habanalabs: flush only at the end of the map/unmap
PATCH 1/1 habanalabs: flush only at the end of the map/unmap
From: Pawel Piskorski <[email protected]>
Optimize hl_mmu_map and hl_mmu_unmap by not calling flush(ctx) within per-page loop.
Signed-off-by Pawel Piskorski <[email protected]>
Reviewed-by Oded Gabbay <[email protected]>
Signed-off-by Oded Gabbay <[email protected]>
--- drivers/misc/habanalabs/goya/goya.c | 20 +++++++------ drivers/misc/habanalabs/habanalabs.h | 6 ++-- drivers/misc/habanalabs/memory.c | 9 ++++-- drivers/misc/habanalabs/mmu.c | 42 ++++++++++++++++++---------- 4 files changed, 50 insertions(+), 27 deletions(-)
drivers/misc/habanalabs/goya/goya.c +12 -8
@@ -4737,7 +4737,8 @@ static int goya_mmu_add_mappings_for_device_cpu(struct hl_device *hdev)for (off =0 ; off <CPU_FW_IMAGE_SIZE ; off +=PAGE_SIZE_2MB ) { rc =hl_mmu_map (hdev->kernel_ctx, prop->dram_base_address + off, - prop->dram_base_address + off,PAGE_SIZE_2MB ); + prop->dram_base_address + off,PAGE_SIZE_2MB , + (off +PAGE_SIZE_2MB ) ==CPU_FW_IMAGE_SIZE );if (rc) {dev_err (hdev->dev,"Map failed for address 0x%llx\n" , prop->dram_base_address + off);
@@ -4747,7 +4748,7 @@ static int goya_mmu_add_mappings_for_device_cpu(struct hl_device *hdev)if (!(hdev->cpu_accessible_dma_address & (PAGE_SIZE_2MB -1 ))) { rc =hl_mmu_map (hdev->kernel_ctx,VA_CPU_ACCESSIBLE_MEM_ADDR , - hdev->cpu_accessible_dma_address,PAGE_SIZE_2MB ); + hdev->cpu_accessible_dma_address,PAGE_SIZE_2MB , true);if (rc) { dev_err(hdev->dev,
@@ -4760,7 +4761,7 @@ static int goya_mmu_add_mappings_for_device_cpu(struct hl_device *hdev) rc =hl_mmu_map (hdev->kernel_ctx,VA_CPU_ACCESSIBLE_MEM_ADDR + cpu_off, hdev->cpu_accessible_dma_address + cpu_off, -PAGE_SIZE_4KB ); +PAGE_SIZE_4KB , true);if (rc) {dev_err (hdev->dev,"Map failed for CPU accessible memory\n" );
@@ -4786,14 +4787,15 @@ static int goya_mmu_add_mappings_for_device_cpu(struct hl_device *hdev)for (; cpu_off >=0 ; cpu_off -=PAGE_SIZE_4KB )if (hl_mmu_unmap (hdev->kernel_ctx,VA_CPU_ACCESSIBLE_MEM_ADDR + cpu_off, -PAGE_SIZE_4KB )) +PAGE_SIZE_4KB , true))dev_warn_ratelimited (hdev->dev,"failed to unmap address 0x%llx\n" ,VA_CPU_ACCESSIBLE_MEM_ADDR + cpu_off); unmap:for (; off >=0 ; off -=PAGE_SIZE_2MB )if (hl_mmu_unmap (hdev->kernel_ctx, - prop->dram_base_address + off,PAGE_SIZE_2MB )) + prop->dram_base_address + off,PAGE_SIZE_2MB , + true))dev_warn_ratelimited (hdev->dev,"failed to unmap address 0x%llx\n" , prop->dram_base_address + off);
@@ -4818,14 +4820,15 @@ void goya_mmu_remove_device_cpu_mappings(struct hl_device *hdev)if (!(hdev->cpu_accessible_dma_address & (PAGE_SIZE_2MB -1 ))) {if (hl_mmu_unmap (hdev->kernel_ctx,VA_CPU_ACCESSIBLE_MEM_ADDR , -PAGE_SIZE_2MB )) +PAGE_SIZE_2MB , true))dev_warn (hdev->dev,"Failed to unmap CPU accessible memory\n" ); }else {for (cpu_off =0 ; cpu_off <SZ_2M ; cpu_off +=PAGE_SIZE_4KB )if (hl_mmu_unmap (hdev->kernel_ctx,VA_CPU_ACCESSIBLE_MEM_ADDR + cpu_off, -PAGE_SIZE_4KB )) +PAGE_SIZE_4KB , + (cpu_off +PAGE_SIZE_4KB ) >=SZ_2M ))dev_warn_ratelimited (hdev->dev,"failed to unmap address 0x%llx\n" ,VA_CPU_ACCESSIBLE_MEM_ADDR + cpu_off);
@@ -4833,7 +4836,8 @@ void goya_mmu_remove_device_cpu_mappings(struct hl_device *hdev)for (off =0 ; off <CPU_FW_IMAGE_SIZE ; off +=PAGE_SIZE_2MB )if (hl_mmu_unmap (hdev->kernel_ctx, - prop->dram_base_address + off,PAGE_SIZE_2MB )) + prop->dram_base_address + off,PAGE_SIZE_2MB , + (off +PAGE_SIZE_2MB ) >=CPU_FW_IMAGE_SIZE ))dev_warn_ratelimited (hdev->dev,"Failed to unmap address 0x%llx\n" , prop->dram_base_address + off);
drivers/misc/habanalabs/habanalabs.h +4 -2
@@ -1573,8 +1573,10 @@ int hl_mmu_init(struct hl_device *hdev);void hl_mmu_fini (struct hl_device *hdev);int hl_mmu_ctx_init (struct hl_ctx *ctx);void hl_mmu_ctx_fini (struct hl_ctx *ctx); -int hl_mmu_map (struct hl_ctx *ctx,u64 virt_addr,u64 phys_addr,u32 page_size); -int hl_mmu_unmap (struct hl_ctx *ctx,u64 virt_addr,u32 page_size); +int hl_mmu_map (struct hl_ctx *ctx,u64 virt_addr,u64 phys_addr, +u32 page_size,bool flush_pte); +int hl_mmu_unmap (struct hl_ctx *ctx,u64 virt_addr,u32 page_size, +bool flush_pte);void hl_mmu_swap_out (struct hl_ctx *ctx);void hl_mmu_swap_in (struct hl_ctx *ctx);
drivers/misc/habanalabs/memory.c +6 -3
@@ -747,7 +747,8 @@ static int map_phys_pg_pack(struct hl_ctx *ctx, u64 vaddr,for (i =0 ; i < phys_pg_pack->npages ; i++) { paddr = phys_pg_pack->pages[i]; - rc =hl_mmu_map (ctx, next_vaddr, paddr, page_size); + rc =hl_mmu_map (ctx, next_vaddr, paddr, page_size, + (i +1 ) == phys_pg_pack->npages);if (rc) { dev_err(hdev->dev, "map failed for handle %u, npages: %llu, mapped: %llu",
@@ -765,7 +766,8 @@ static int map_phys_pg_pack(struct hl_ctx *ctx, u64 vaddr, err: next_vaddr = vaddr;for (i =0 ; i < mapped_pg_cnt ; i++) { -if (hl_mmu_unmap (ctx, next_vaddr, page_size)) +if (hl_mmu_unmap (ctx, next_vaddr, page_size, + (i +1 ) == mapped_pg_cnt)) dev_warn_ratelimited(hdev->dev, "failed to unmap handle %u, va: 0x%llx, pa: 0x%llx, page size: %u\n", phys_pg_pack->handle, next_vaddr,
@@ -794,7 +796,8 @@ static void unmap_phys_pg_pack(struct hl_ctx *ctx, u64 vaddr, next_vaddr = vaddr;for (i =0 ; i < phys_pg_pack->npages ; i++, next_vaddr += page_size) { -if (hl_mmu_unmap (ctx, next_vaddr, page_size)) +if (hl_mmu_unmap (ctx, next_vaddr, page_size, + (i +1 ) == phys_pg_pack->npages))dev_warn_ratelimited (hdev->dev,"unmap failed for vaddr: 0x%llx\n" , next_vaddr);
drivers/misc/habanalabs/mmu.c +28 -14
124 lines not on this page · raw message
Signature · 1 line
2.17.1