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 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
|
/*
* Copyright (c) 2013-2017 Intel Corporation. All rights reserved.
* Copyright (c) 2017, Cisco Systems, Inc. All rights reserved.
*
* This software is available to you under a choice of one of two
* licenses. You may choose to be licensed under the terms of the GNU
* General Public License (GPL) Version 2, available from the file
* COPYING in the main directory of this source tree, or 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 <rdma/fabric.h>
#include <rdma/fi_errno.h>
#include <rdma/fi_endpoint.h>
#include <rdma/fi_rma.h>
#include <rdma/fi_cm.h>
#include "shared.h"
struct test_mr {
uint8_t *buf;
struct fid_cntr *rcntr;
uint64_t rcntr_next;
struct fid_mr *mr;
struct fi_rma_iov *remote;
};
struct test_mr *mr_res_array;
uint8_t *mr_buf_array;
struct fi_rma_iov *remote_array;
uint64_t mr_count;
int verbose;
static int wait_cntr(struct fid_cntr *cntr, uint64_t *cntr_next)
{
/* 30 second wait timeout */
int ret = fi_cntr_wait(cntr, *cntr_next, 30 * 1000);
if (ret < 0)
return ret;
*cntr_next += 1;
return 0;
}
static int free_mr_res()
{
int i;
if (!mr_res_array)
return 0;
for (i = 0; i < mr_count; i++) {
FT_CLOSE_FID(mr_res_array[i].mr);
FT_CLOSE_FID(mr_res_array[i].rcntr);
}
free(mr_res_array);
free(remote_array);
free(mr_buf_array);
return 0;
}
static int alloc_multi_mr_res()
{
int i = 0;
mr_res_array = calloc(mr_count, sizeof(*mr_res_array));
if (!mr_res_array)
return -FI_ENOMEM;
remote_array = calloc(mr_count, sizeof(*remote_array));
if (!remote_array)
return -FI_ENOMEM;
mr_buf_array = calloc(mr_count, opts.transfer_size);
if (!mr_buf_array)
return -FI_ENOMEM;
for (i = 0; i < mr_count; i++) {
mr_res_array[i].remote = &remote_array[i];
mr_res_array[i].buf = &mr_buf_array[i];
}
return 0;
}
static int init_multi_mr_res(void)
{
int ret = 0, i;
if ((1ULL << fi->domain_attr->mr_key_size) < mr_count) {
fprintf(stderr, "ERROR: too many memory regions for unique mr keys");
return -FI_EINVAL;
}
ret = alloc_multi_mr_res();
if (ret)
return ret;
for (i = 0; i < mr_count; i++) {
ret = fi_cntr_open(domain,
&cntr_attr,
&mr_res_array[i].rcntr,
NULL);
if (ret) {
FT_PRINTERR("fi_cntr_open", ret);
return ret;
}
mr_res_array[i].remote->len = opts.transfer_size;
mr_res_array[i].remote->addr = 0;
memset(mr_res_array[i].buf, 0, opts.transfer_size);
mr_res_array[i].rcntr_next = 1;
mr_res_array[i].remote->key = i + 1;
ret = fi_mr_reg(domain, mr_res_array[i].buf,
opts.transfer_size, FI_REMOTE_WRITE,
0, mr_res_array[i].remote->key,
0, &mr_res_array[i].mr, NULL);
if (ret) {
FT_PRINTERR("fi_mr_reg", ret);
return ret;
}
if (verbose) {
printf("MR_REG:domain_ptr, buf_ptr, mr_size, mr_ptr, mr_key)\n");
printf("%p, %p, %zu, %p, %lu)\n",
domain,
mr_res_array[i].buf,
opts.transfer_size,
&mr_res_array[i].mr,
(unsigned long)fi_mr_key(mr_res_array[i].mr));
}
ret = fi_mr_bind(mr_res_array[i].mr,
&mr_res_array[i].rcntr->fid,
FI_REMOTE_WRITE);
if (ret) {
FT_PRINTERR("fi_mr_bind", ret);
return ret;
}
}
return ret;
}
static int mr_key_test()
{
int i, ret = 0;
struct fi_context2 rma_ctx;
for (i = 0; i < mr_count; i++) {
tx_buf = (char *)mr_res_array[i].buf;
if (opts.dst_addr) {
ret = ft_fill_buf(mr_res_array[i].buf,
opts.transfer_size);
if (ret)
return ret;
if (verbose)
printf("write to host's key %lx\n",
(unsigned long)fi_mr_key(mr_res_array[i].mr));
ft_post_rma(FT_RMA_WRITE, tx_buf, opts.transfer_size,
mr_res_array[i].remote, &rma_ctx);
if (verbose)
printf("sent successfully\n");
ret = wait_cntr(mr_res_array[i].rcntr,
&mr_res_array[i].rcntr_next);
if (ret)
return ret;
if (ft_check_opts(FT_OPT_VERIFY_DATA)) {
if (verbose)
printf("checking result in buffer %p, key %lx\n",
mr_res_array[i].buf,
(unsigned long)fi_mr_key(mr_res_array[i].mr));
ret = ft_check_buf(mr_res_array[i].buf,
opts.transfer_size);
if (ret)
return ret;
}
} else {
ret = wait_cntr(mr_res_array[i].rcntr,
&mr_res_array[i].rcntr_next);
if (ret)
return ret;
if (ft_check_opts(FT_OPT_VERIFY_DATA)) {
if (verbose)
printf("checking result in buffer %p, key %lx\n",
mr_res_array[i].buf,
(unsigned long)fi_mr_key(mr_res_array[i].mr));
ret = ft_check_buf(mr_res_array[i].buf,
opts.transfer_size);
if (ret)
return ret;
}
ret = ft_fill_buf(mr_res_array[i].buf,
opts.transfer_size);
if (ret)
return ret;
if (verbose)
printf("write to client's key %lx\n",
(unsigned long)fi_mr_key(mr_res_array[i].mr));
ft_post_rma(FT_RMA_WRITE, tx_buf, opts.transfer_size,
mr_res_array[i].remote, &rma_ctx);
if (verbose)
printf("sent successfully\n");
}
}
printf("GOOD, multi mr key test complete\n");
return ret;
}
static int run_test(void)
{
int ret = 0;
ft_mr_alloc_func = init_multi_mr_res;
if (hints->ep_attr->type == FI_EP_MSG)
ret = ft_init_fabric_cm();
else
ret = ft_init_fabric();
if (ret)
return ret;
ret = mr_key_test();
ft_sync();
ft_finalize();
return ret;
}
int main(int argc, char **argv)
{
int op;
int ret = 0;
opts = INIT_OPTS;
opts.transfer_size = 4096;
mr_count = 2;
verbose = 0;
hints = fi_allocinfo();
if (!hints)
return EXIT_FAILURE;
while ((op = getopt(argc, argv, "c:Vvh" ADDR_OPTS INFO_OPTS)) != -1) {
switch (op) {
default:
ft_parse_addr_opts(op, optarg, &opts);
ft_parseinfo(op, optarg, hints, &opts);
break;
case 'c':
mr_count = strtoull(optarg, NULL, 10);
break;
case 'V':
verbose = 1;
break;
case 'v':
opts.options |= FT_OPT_VERIFY_DATA;
break;
case '?':
case 'h':
ft_usage(argv[0], "Ping-pong multi memory region test");
FT_PRINT_OPTS_USAGE("-c <int>",
"number of memory regions to create and test");
FT_PRINT_OPTS_USAGE("-V", "Enable verbose printing");
FT_PRINT_OPTS_USAGE("-v", "Enable data verification");
return EXIT_FAILURE;
}
}
if (optind < argc)
opts.dst_addr = argv[optind];
hints->caps = FI_RMA | FI_RMA_EVENT | FI_MSG;
hints->mode = FI_CONTEXT | FI_CONTEXT2;
hints->domain_attr->mr_mode = opts.mr_mode;
hints->addr_format = opts.address_format;
ret = run_test();
free_mr_res();
ft_free_res();
return ft_exit_code(ret);
}
|