Skip to content

Commit 61cfada

Browse files
isilenceaxboe
authored andcommitted
io_uring/zcrx: consolidate dma syncing
Split refilling into two steps, first allocate niovs, and then do DMA sync for them. This way dma synchronisation code can be better optimised. E.g. we don't need to call dma_dev_need_sync() for each every niov, and maybe we can coalesce sync for adjacent netmems in the future as well. Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Link: https://patch.msgid.link/19f2d50baa62ff2e0c6cd56dd7c394cab728c567.1774261953.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent c098913 commit 61cfada

1 file changed

Lines changed: 12 additions & 11 deletions

File tree

io_uring/zcrx.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -300,21 +300,23 @@ static void io_zcrx_unmap_area(struct io_zcrx_ifq *ifq,
300300
}
301301
}
302302

303-
static void io_zcrx_sync_for_device(struct page_pool *pool,
304-
struct net_iov *niov)
303+
static void zcrx_sync_for_device(struct page_pool *pp, struct io_zcrx_ifq *zcrx,
304+
netmem_ref *netmems, unsigned nr)
305305
{
306306
#if defined(CONFIG_HAS_DMA) && defined(CONFIG_DMA_NEED_SYNC)
307+
struct device *dev = pp->p.dev;
308+
unsigned i, niov_size;
307309
dma_addr_t dma_addr;
308310

309-
unsigned niov_size;
310-
311-
if (!dma_dev_need_sync(pool->p.dev))
311+
if (!dma_dev_need_sync(dev))
312312
return;
313+
niov_size = 1U << zcrx->niov_shift;
313314

314-
niov_size = 1U << io_pp_to_ifq(pool)->niov_shift;
315-
dma_addr = page_pool_get_dma_addr_netmem(net_iov_to_netmem(niov));
316-
__dma_sync_single_for_device(pool->p.dev, dma_addr + pool->p.offset,
317-
niov_size, pool->p.dma_dir);
315+
for (i = 0; i < nr; i++) {
316+
dma_addr = page_pool_get_dma_addr_netmem(netmems[i]);
317+
__dma_sync_single_for_device(dev, dma_addr + pp->p.offset,
318+
niov_size, pp->p.dma_dir);
319+
}
318320
#endif
319321
}
320322

@@ -1046,7 +1048,6 @@ static unsigned io_zcrx_ring_refill(struct page_pool *pp,
10461048
continue;
10471049
}
10481050

1049-
io_zcrx_sync_for_device(pp, niov);
10501051
netmems[allocated] = netmem;
10511052
allocated++;
10521053
} while (--entries);
@@ -1069,7 +1070,6 @@ static unsigned io_zcrx_refill_slow(struct page_pool *pp, struct io_zcrx_ifq *if
10691070
if (!niov)
10701071
break;
10711072
net_mp_niov_set_page_pool(pp, niov);
1072-
io_zcrx_sync_for_device(pp, niov);
10731073
netmems[allocated] = net_iov_to_netmem(niov);
10741074
}
10751075
return allocated;
@@ -1094,6 +1094,7 @@ static netmem_ref io_pp_zc_alloc_netmems(struct page_pool *pp, gfp_t gfp)
10941094
if (!allocated)
10951095
return 0;
10961096
out_return:
1097+
zcrx_sync_for_device(pp, ifq, netmems, allocated);
10971098
allocated--;
10981099
pp->alloc.count += allocated;
10991100
return netmems[allocated];

0 commit comments

Comments
 (0)