Skip to content

Commit 0ef69e7

Browse files
GuangguanWangdavem330
authored andcommitted
net/smc: optimize for smc_sndbuf_sync_sg_for_device and smc_rmb_sync_sg_for_cpu
Some CPU, such as Xeon, can guarantee DMA cache coherency. So it is no need to use dma sync APIs to flush cache on such CPUs. In order to avoid calling dma sync APIs on the IO path, use the dma_need_sync to check whether smc_buf_desc needs dma sync when creating smc_buf_desc. Signed-off-by: Guangguan Wang <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 6d52e2d commit 0ef69e7

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed

net/smc/smc_core.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2016,6 +2016,9 @@ static int smcr_buf_map_link(struct smc_buf_desc *buf_desc, bool is_rmb,
20162016
goto free_table;
20172017
}
20182018

2019+
buf_desc->is_dma_need_sync |=
2020+
smc_ib_is_sg_need_sync(lnk, buf_desc) << lnk->link_idx;
2021+
20192022
/* create a new memory region for the RMB */
20202023
if (is_rmb) {
20212024
rc = smc_ib_get_memory_region(lnk->roce_pd,
@@ -2234,6 +2237,7 @@ static int __smc_buf_create(struct smc_sock *smc, bool is_smcd, bool is_rmb)
22342237
/* check for reusable slot in the link group */
22352238
buf_desc = smc_buf_get_slot(bufsize_short, lock, buf_list);
22362239
if (buf_desc) {
2240+
buf_desc->is_dma_need_sync = 0;
22372241
SMC_STAT_RMB_SIZE(smc, is_smcd, is_rmb, bufsize);
22382242
SMC_STAT_BUF_REUSE(smc, is_smcd, is_rmb);
22392243
break; /* found reusable slot */
@@ -2292,6 +2296,8 @@ static int __smc_buf_create(struct smc_sock *smc, bool is_smcd, bool is_rmb)
22922296

22932297
void smc_sndbuf_sync_sg_for_device(struct smc_connection *conn)
22942298
{
2299+
if (!conn->sndbuf_desc->is_dma_need_sync)
2300+
return;
22952301
if (!smc_conn_lgr_valid(conn) || conn->lgr->is_smcd ||
22962302
!smc_link_active(conn->lnk))
22972303
return;
@@ -2302,6 +2308,8 @@ void smc_rmb_sync_sg_for_cpu(struct smc_connection *conn)
23022308
{
23032309
int i;
23042310

2311+
if (!conn->rmb_desc->is_dma_need_sync)
2312+
return;
23052313
if (!smc_conn_lgr_valid(conn) || conn->lgr->is_smcd)
23062314
return;
23072315
for (i = 0; i < SMC_LINKS_PER_LGR_MAX; i++) {

net/smc/smc_core.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ struct smc_buf_desc {
180180
/* mem region registered */
181181
u8 is_map_ib[SMC_LINKS_PER_LGR_MAX];
182182
/* mem region mapped to lnk */
183+
u8 is_dma_need_sync;
183184
u8 is_reg_err;
184185
/* buffer registration err */
185186
};

net/smc/smc_ib.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,29 @@ int smc_ib_get_memory_region(struct ib_pd *pd, int access_flags,
729729
return 0;
730730
}
731731

732+
bool smc_ib_is_sg_need_sync(struct smc_link *lnk,
733+
struct smc_buf_desc *buf_slot)
734+
{
735+
struct scatterlist *sg;
736+
unsigned int i;
737+
bool ret = false;
738+
739+
/* for now there is just one DMA address */
740+
for_each_sg(buf_slot->sgt[lnk->link_idx].sgl, sg,
741+
buf_slot->sgt[lnk->link_idx].nents, i) {
742+
if (!sg_dma_len(sg))
743+
break;
744+
if (dma_need_sync(lnk->smcibdev->ibdev->dma_device,
745+
sg_dma_address(sg))) {
746+
ret = true;
747+
goto out;
748+
}
749+
}
750+
751+
out:
752+
return ret;
753+
}
754+
732755
/* synchronize buffer usage for cpu access */
733756
void smc_ib_sync_sg_for_cpu(struct smc_link *lnk,
734757
struct smc_buf_desc *buf_slot,
@@ -737,6 +760,9 @@ void smc_ib_sync_sg_for_cpu(struct smc_link *lnk,
737760
struct scatterlist *sg;
738761
unsigned int i;
739762

763+
if (!(buf_slot->is_dma_need_sync & (1U << lnk->link_idx)))
764+
return;
765+
740766
/* for now there is just one DMA address */
741767
for_each_sg(buf_slot->sgt[lnk->link_idx].sgl, sg,
742768
buf_slot->sgt[lnk->link_idx].nents, i) {
@@ -757,6 +783,9 @@ void smc_ib_sync_sg_for_device(struct smc_link *lnk,
757783
struct scatterlist *sg;
758784
unsigned int i;
759785

786+
if (!(buf_slot->is_dma_need_sync & (1U << lnk->link_idx)))
787+
return;
788+
760789
/* for now there is just one DMA address */
761790
for_each_sg(buf_slot->sgt[lnk->link_idx].sgl, sg,
762791
buf_slot->sgt[lnk->link_idx].nents, i) {

net/smc/smc_ib.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ long smc_ib_setup_per_ibdev(struct smc_ib_device *smcibdev);
102102
int smc_ib_get_memory_region(struct ib_pd *pd, int access_flags,
103103
struct smc_buf_desc *buf_slot, u8 link_idx);
104104
void smc_ib_put_memory_region(struct ib_mr *mr);
105+
bool smc_ib_is_sg_need_sync(struct smc_link *lnk,
106+
struct smc_buf_desc *buf_slot);
105107
void smc_ib_sync_sg_for_cpu(struct smc_link *lnk,
106108
struct smc_buf_desc *buf_slot,
107109
enum dma_data_direction data_direction);

0 commit comments

Comments
 (0)