forked from MarkZhang81/dvpingpong
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.dv.c
119 lines (95 loc) · 2.69 KB
/
client.dv.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include "pp_common.h"
#include "pp_dv.h"
#define SERVER_IP "10.237.1.205"
static char ibv_devname[100] = "ibp59s0f0";
static int client_sgid_idx = 3;
//#define PP_DV_OPCODE_CLIENT IBV_WR_RDMA_WRITE_WITH_IMM /* IBV_WR_SEND_WITH_IMM */
#define PP_SEND_WRID_CLIENT 0x1000
#define PP_RECV_WRID_CLIENT 0x4000
static struct pp_dv_ctx ppdv;
static struct pp_exchange_info server = {};
static int client_traffic_dv(struct pp_dv_ctx *ppdv)
{
int num_post = PP_MAX_WR, num_comp, i, ret;
//int opcode = MLX5_OPCODE_RDMA_WRITE_IMM;
int opcode = MLX5_OPCODE_SEND_IMM;
DBG("Pause 1sec before post send, opcode %d num_post %d length 0x%lx..\n",
opcode, num_post, ppdv->ppc.mrbuflen);
sleep(1);
for (i = 0; i < num_post; i++) {
mem_string(ppdv->ppc.mrbuf[i], ppdv->ppc.mrbuflen);
*ppdv->ppc.mrbuf[i] = i % ('z' - '0') + '0';
}
ret = pp_dv_post_send(&ppdv->ppc, &ppdv->qp, &server, num_post,
opcode, IBV_SEND_SIGNALED);
if (ret) {
ERR("pp_dv_post_send failed\n");
return ret;
}
num_comp = 0;
while (num_comp < num_post) {
ret = pp_dv_poll_cq(&ppdv->cq, 1);
if (ret == CQ_POLL_ERR) {
ERR("poll_cq(send) failed %d, %d/%d\n", ret, num_comp, num_post);
return ret;
}
if (ret > 0)
num_comp++;
}
/* Reset the buffer so that we can check it the received data is expected */
for (i = 0; i < num_post; i++)
memset(ppdv->ppc.mrbuf[i], 0, ppdv->ppc.mrbuflen);
INFO("Send done (num_post %d), now recving reply...\n", num_post);
ret = pp_dv_post_recv(&ppdv->ppc, &ppdv->qp, num_post);
if (ret) {
ERR("pp_dv_post_recv failed\n");
return ret;
}
num_comp = 0;
while (num_comp < num_post) {
ret = pp_dv_poll_cq(&ppdv->cq, 1);
if (ret == CQ_POLL_ERR) {
ERR("poll_cq(recv) failed %d, %d/%d\n", ret, num_comp, num_post);
return ret;
}
if (ret > 0) {
dump_msg_short(num_comp, &ppdv->ppc);
num_comp++;
}
}
INFO("Client(dv) traffic test done\n");
return 0;
}
int main(int argc, char *argv[])
{
int ret;
if (argv[1]) {
memset(ibv_devname, 0, sizeof(ibv_devname));
strcpy(ibv_devname, argv[1]);
}
ret = pp_ctx_init(&ppdv.ppc, ibv_devname, 0, NULL);
if (ret)
return ret;
ret = pp_create_cq_dv(&ppdv.ppc, &ppdv.cq);
if (ret)
goto out_create_cq;
ret = pp_create_qp_dv(&ppdv.ppc, &ppdv.cq, &ppdv.qp);
if (ret)
goto out_create_qp;
ret = pp_exchange_info(&ppdv.ppc, client_sgid_idx, ppdv.qp.qpn,
CLIENT_PSN, &server, SERVER_IP);
if (ret)
goto out_exchange;
ret = pp_move2rts_dv(&ppdv.ppc, &ppdv.qp, client_sgid_idx,
CLIENT_PSN, &server);
if (ret)
goto out_exchange;
ret = client_traffic_dv(&ppdv);
out_exchange:
pp_destroy_qp_dv(&ppdv.qp);
out_create_qp:
pp_destroy_cq_dv(&ppdv.cq);
out_create_cq:
pp_ctx_cleanup(&ppdv.ppc);
return ret;
}