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 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
|
/*
* Copyright (c) 2013-2015 Intel Corporation. All rights reserved.
* Copyright (c) 2015 Cisco Systems, Inc. All rights reserved.
*
* This software is available to you under the BSD license below:
*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
*
* - Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer.
*
* - Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
#include <unistd.h>
#include <rdma/fi_errno.h>
#include <rdma/fi_cm.h>
#include <shared.h>
#define MAX_POLL_CNT 10
static int alloc_ep_res(struct fi_info *fi)
{
struct fi_poll_attr poll_attr;
int ret;
ret = ft_alloc_active_res(fi);
if (ret)
return ret;
memset(&poll_attr, 0, sizeof poll_attr);
ret = fi_poll_open(domain, &poll_attr, &pollset);
if (ret) {
FT_PRINTERR("fi_poll_open", ret);
return ret;
}
if (txcq) {
ret = fi_poll_add(pollset, &txcq->fid, 0);
if (ret)
goto err;
}
if (rxcq) {
ret = fi_poll_add(pollset, &rxcq->fid, 0);
if (ret)
goto err;
}
if (txcntr) {
ret = fi_poll_add(pollset, &txcntr->fid, 0);
if (ret)
goto err;
}
if (rxcntr) {
ret = fi_poll_add(pollset, &rxcntr->fid, 0);
if (ret)
goto err;
}
return 0;
err:
FT_PRINTERR("fi_poll_add", ret);
return ret;
}
static int free_poll_res(void)
{
int ret;
if (!pollset)
return 0;
if (txcq) {
ret = fi_poll_del(pollset, &txcq->fid, 0);
if (ret)
goto err;
}
if (rxcq) {
ret = fi_poll_del(pollset, &rxcq->fid, 0);
if (ret)
goto err;
}
if (txcntr) {
ret = fi_poll_del(pollset, &txcntr->fid, 0);
if (ret)
goto err;
}
if (rxcntr) {
ret = fi_poll_del(pollset, &rxcntr->fid, 0);
if (ret)
goto err;
}
return 0;
err:
FT_PRINTERR("fi_poll_del", ret);
return ret;
}
static int init_fabric(void)
{
int ret;
ret = ft_init();
if (ret)
return ret;
ret = ft_init_oob();
if (ret)
return ret;
ret = ft_getinfo(hints, &fi);
if (ret)
return ret;
ret = ft_open_fabric_res();
if (ret)
return ret;
ret = alloc_ep_res(fi);
if (ret)
return ret;
ret = ft_enable_ep_recv();
if (ret)
return ret;
return 0;
}
static int send_recv()
{
struct fid_cq *cq;
void *context[MAX_POLL_CNT];
struct fi_cq_entry comp;
int ret;
int ret_count = 0;
int i, tx_cntr_val = 0, rx_cntr_val = 0;
fprintf(stdout, "Posting a send...\n");
ret = ft_post_tx(ep, remote_fi_addr, tx_size, NO_CQ_DATA, &tx_ctx);
if (ret)
return ret;
while (((opts.options & FT_OPT_TX_CQ) && (tx_cq_cntr < tx_seq)) ||
((opts.options & FT_OPT_TX_CNTR) && (tx_cntr_val < tx_seq)) ||
((opts.options & FT_OPT_RX_CQ) && (rx_cq_cntr < rx_seq)) ||
((opts.options & FT_OPT_RX_CNTR) && (rx_cntr_val < rx_seq))) {
/* Poll send and recv CQs/Cntrs */
do {
ret_count = fi_poll(pollset, context, MAX_POLL_CNT);
if (ret_count < 0) {
FT_PRINTERR("fi_poll", ret_count);
return ret_count;
}
} while (!ret_count);
fprintf(stdout, "Retrieved %d event(s)\n", ret_count);
for (i = 0; i < ret_count; i++) {
if (context[i] == &txcq) {
printf("Send completion received\n");
cq = txcq;
tx_cq_cntr++;
} else if (context[i] == &rxcq) {
printf("Recv completion received\n");
cq = rxcq;
rx_cq_cntr++;
} else if (context[i] == &txcntr) {
printf("Send counter poll-event\n");
tx_cntr_val = fi_cntr_read(txcntr);
if (tx_cntr_val > tx_seq) {
FT_ERR("Invalid tx counter event\n");
FT_ERR("expected: %" PRIu64 ", found: "
"%d\n", tx_seq, tx_cntr_val);
return -1;
}
continue;
} else if (context[i] == &rxcntr) {
printf("Recv counter poll-event\n");
rx_cntr_val = fi_cntr_read(rxcntr);
if (rx_cntr_val > rx_seq) {
FT_ERR("Invalid rx counter event\n");
FT_ERR("expected: %" PRIu64 ", found: "
"%d\n", rx_seq, rx_cntr_val);
return -1;
}
continue;
} else {
FT_ERR("Unknown completion received\n");
return -1;
}
/* Read the completion entry */
ret = fi_cq_read(cq, &comp, 1);
if (ret < 0) {
if (ret == -FI_EAVAIL) {
ret = ft_cq_readerr(cq);
} else {
FT_PRINTERR("fi_cq_read", ret);
}
return ret;
}
}
}
return 0;
}
static int run(void)
{
int ret;
ret = init_fabric();
if (ret)
return ret;
ret = ft_init_av();
if (ret)
return ret;
return send_recv();
}
int main(int argc, char **argv)
{
int op, ret = 0;
opts = INIT_OPTS;
opts.options |= FT_OPT_SIZE;
hints = fi_allocinfo();
if (!hints)
return EXIT_FAILURE;
while ((op = getopt(argc, argv, "h" CS_OPTS INFO_OPTS)) != -1) {
switch (op) {
default:
ft_parse_addr_opts(op, optarg, &opts);
ft_parseinfo(op, optarg, hints, &opts);
ft_parsecsopts(op, optarg, &opts);
break;
case '?':
case 'h':
ft_usage(argv[0], "A client-server example that uses poll.\n");
FT_PRINT_OPTS_USAGE("-t <type>", "completion type [queue, counter]");
return EXIT_FAILURE;
}
}
if (optind < argc)
opts.dst_addr = argv[optind];
hints->ep_attr->type = FI_EP_RDM;
hints->caps = FI_MSG;
hints->mode = FI_CONTEXT;
hints->domain_attr->mr_mode = opts.mr_mode;
hints->addr_format = opts.address_format;
ret = run();
free_poll_res();
ft_free_res();
return ft_exit_code(ret);
}
|