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 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614
|
/*
* Copyright (c) 2015-2017 Los Alamos National Security, LLC. All rights reserved.
* Copyright (c) 2015-2017 Cray Inc. All rights reserved.
* Copyright (c) 2020 Triad National Security, LLC. 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 <errno.h>
#include <getopt.h>
#include <poll.h>
#include <time.h>
#include <string.h>
#include <pthread.h>
#include <unistd.h>
#include <limits.h>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <criterion/criterion.h>
#include "gnix_rdma_headers.h"
#include "fi_ext_gni.h"
#include "common.h"
#if 1
#define dbg_printf(...)
#else
#define dbg_printf(...) \
do { \
printf(__VA_ARGS__); \
fflush(stdout); \
} while (0)
#endif
#define NUMEPS 2
/* Note: Set to ~FI_NOTIFY_FLAGS_ONLY since this was written before api 1.5 */
static uint64_t mode_bits = ~FI_NOTIFY_FLAGS_ONLY;
static struct fid_fabric *fab;
static struct fid_domain *dom[NUMEPS];
static struct fi_gni_ops_domain *gni_domain_ops[NUMEPS];
static struct fid_ep *ep[NUMEPS];
static struct fid_av *av[NUMEPS];
static void *ep_name[NUMEPS];
static fi_addr_t gni_addr[NUMEPS];
static struct fid_cq *msg_cq[NUMEPS];
static struct fi_info *fi[NUMEPS];
static struct fi_cq_attr cq_attr;
static struct fi_info *hints[NUMEPS];
#define BUF_SZ (1<<20)
static char *target, *target_base;
static char *source, *source_base;
static char *uc_target;
static char *uc_source;
static struct fid_mr *rem_mr[NUMEPS], *loc_mr[NUMEPS];
static uint64_t mr_key[NUMEPS];
static uint64_t cq_bind_flags;
void api_cq_bind(uint64_t flags)
{
int ret, i;
for (i = 0; i < NUMEPS; i++) {
ret = fi_ep_bind(ep[i], &msg_cq[i]->fid, flags);
cr_assert(!ret, "fi_ep_bind");
ret = fi_enable(ep[i]);
cr_assert(!ret, "fi_enable");
}
}
static inline void __api_cq_setup(uint32_t version, int mr_mode)
{
int ret, i, j;
struct fi_av_attr attr;
size_t addrlen = 0;
for (i = 0; i < NUMEPS; i++) {
hints[i] = fi_allocinfo();
cr_assert(hints[i], "fi_allocinfo");
hints[i]->domain_attr->cq_data_size = NUMEPS * 2;
hints[i]->domain_attr->data_progress = FI_PROGRESS_AUTO;
hints[i]->domain_attr->mr_mode = mr_mode;
hints[i]->mode = mode_bits;
hints[i]->fabric_attr->prov_name = strdup("gni");
}
/* Get info about fabric services with the provided hints */
for (i = 0; i < NUMEPS; i++) {
ret = fi_getinfo(version, NULL, 0, 0, hints[i],
&fi[i]);
cr_assert(!ret, "fi_getinfo");
}
memset(&attr, 0, sizeof(attr));
attr.type = FI_AV_MAP;
attr.count = NUMEPS;
cq_attr.format = FI_CQ_FORMAT_TAGGED;
cq_attr.size = 1024;
cq_attr.wait_obj = 0;
/* 3x BUF_SZ for multi recv testing */
target_base = malloc(GNIT_ALIGN_LEN(BUF_SZ * 3));
assert(target_base);
target = GNIT_ALIGN_BUFFER(char *, target_base);
source_base = malloc(GNIT_ALIGN_LEN(BUF_SZ));
assert(source_base);
source = GNIT_ALIGN_BUFFER(char *, source_base);
uc_target = malloc(BUF_SZ);
assert(uc_target);
uc_source = malloc(BUF_SZ);
assert(uc_source);
ret = fi_fabric(fi[0]->fabric_attr, &fab, NULL);
cr_assert(!ret, "fi_fabric");
for (i = 0; i < NUMEPS; i++) {
ret = fi_domain(fab, fi[i], dom + i, NULL);
cr_assert(!ret, "fi_domain");
ret = fi_open_ops(&dom[i]->fid, FI_GNI_DOMAIN_OPS_1,
0, (void **) (gni_domain_ops + i), NULL);
ret = fi_av_open(dom[i], &attr, av + i, NULL);
cr_assert(!ret, "fi_av_open");
ret = fi_endpoint(dom[i], fi[i], ep + i, NULL);
cr_assert(!ret, "fi_endpoint");
ret = fi_cq_open(dom[i], &cq_attr, msg_cq + i, 0);
cr_assert(!ret, "fi_cq_open");
ret = fi_getname(&ep[i]->fid, NULL, &addrlen);
cr_assert(addrlen > 0);
ep_name[i] = malloc(addrlen);
cr_assert(ep_name[i] != NULL);
ret = fi_getname(&ep[i]->fid, ep_name[i], &addrlen);
cr_assert(ret == FI_SUCCESS);
}
for (i = 0; i < NUMEPS; i++) {
/* Insert all gni addresses into each av */
for (j = 0; j < NUMEPS; j++) {
ret = fi_av_insert(av[i], ep_name[j], 1, &gni_addr[j],
0, NULL);
cr_assert(ret == 1);
}
ret = fi_ep_bind(ep[i], &av[i]->fid, 0);
cr_assert(!ret, "fi_ep_bind");
}
for (i = 0; i < NUMEPS; i++) {
int target_requested_key =
USING_SCALABLE(fi[i]) ? (i * 2) : 0;
int source_requested_key =
USING_SCALABLE(fi[i]) ? (i * 2) + 1 : 0;
ret = fi_mr_reg(dom[i],
target,
3 * BUF_SZ,
FI_REMOTE_WRITE,
0,
target_requested_key,
0,
rem_mr + i,
&target);
cr_assert_eq(ret, 0);
ret = fi_mr_reg(dom[i],
source,
BUF_SZ,
FI_REMOTE_WRITE,
0,
source_requested_key,
0,
loc_mr + i,
&source);
cr_assert_eq(ret, 0);
if (USING_SCALABLE(fi[i])) {
MR_ENABLE(rem_mr[i], target, 3 * BUF_SZ);
MR_ENABLE(loc_mr[i], source, BUF_SZ);
}
mr_key[i] = fi_mr_key(rem_mr[i]);
}
}
static void api_cq_setup_basic(void)
{
__api_cq_setup(fi_version(), GNIX_MR_BASIC);
}
static void api_cq_setup_scalable(void)
{
__api_cq_setup(fi_version(), GNIX_MR_SCALABLE);
}
static void api_cq_teardown_common(bool unreg)
{
int ret = 0, i = 0;
for (; i < NUMEPS; i++) {
if (unreg) {
fi_close(&loc_mr[i]->fid);
fi_close(&rem_mr[i]->fid);
}
ret = fi_close(&ep[i]->fid);
cr_assert(!ret, "failure in closing ep.");
ret = fi_close(&msg_cq[i]->fid);
cr_assert(!ret, "failure in send cq.");
ret = fi_close(&av[i]->fid);
cr_assert(!ret, "failure in closing av.");
ret = fi_close(&dom[i]->fid);
cr_assert(!ret, "failure in closing domain.");
fi_freeinfo(fi[i]);
free(ep_name[i]);
fi_freeinfo(hints[i]);
}
free(uc_source);
free(uc_target);
free(target_base);
free(source_base);
ret = fi_close(&fab->fid);
cr_assert(!ret, "failure in closing fabric.");
}
static void api_cq_teardown(void)
{
api_cq_teardown_common(true);
}
void api_cq_init_data(char *buf, int len, char seed)
{
int i;
for (i = 0; i < len; i++)
buf[i] = seed++;
}
int api_cq_check_data(char *buf1, char *buf2, int len)
{
int i;
for (i = 0; i < len; i++) {
if (buf1[i] != buf2[i]) {
printf("data mismatch, elem: %d, exp: %hhx, act: %hhx\n"
, i, buf1[i], buf2[i]);
return 0;
}
}
return 1;
}
#define MSG_SEND_ALLOWED(flags) \
(flags & FI_SEND)
#define MSG_RECV_ALLOWED(flags) \
(flags & FI_RECV)
void api_cq_send_allowed(ssize_t sz, uint64_t flags, char *fn)
{
if (MSG_SEND_ALLOWED(flags)) {
cr_assert(sz == 0, "%s failed flags:0x%lx sz:%ld",
fn, flags, sz);
} else {
cr_assert(sz < 0, "%s should fail flags:0x%lx sz:%ld",
fn, flags, sz);
}
}
void api_cq_recv_allowed(ssize_t sz, uint64_t flags, char *fn)
{
if (MSG_RECV_ALLOWED(cq_bind_flags)) {
cr_assert(sz == 0, "%s failed flags:0x%lx sz:%ld",
fn, flags, sz);
} else {
cr_assert(sz < 0, "%s should fail flags:0x%lx sz:%ld",
fn, flags, sz);
}
}
TestSuite(api_cq_basic,
.init = api_cq_setup_basic,
.fini = api_cq_teardown,
.disabled = false);
TestSuite(api_cq_scalable,
.init = api_cq_setup_scalable,
.fini = api_cq_teardown,
.disabled = false);
void api_cq_wait1(struct fid_cq *cq0, uint64_t cq_bind_flags)
{
int ret;
struct fi_cq_tagged_entry cqe;
if (!cq_bind_flags)
return;
while ((ret = fi_cq_read(msg_cq[0], &cqe, 1)) == -FI_EAGAIN);
cr_assert(ret > 0, "ret=%d", ret);
}
void api_cq_wait2(struct fid_cq *cq0, struct fid_cq *cq1,
uint64_t check_send, uint64_t check_rcv)
{
int ret;
int source_done = 0, dest_done = 0;
struct fi_cq_tagged_entry s_cqe, d_cqe;
if (!check_send)
source_done = 1;
if (!check_rcv)
dest_done = 1;
do {
ret = fi_cq_read(cq0, &s_cqe, 1);
if (ret == 1) {
source_done = 1;
}
ret = fi_cq_read(cq1, &d_cqe, 1);
if (ret == 1) {
dest_done = 1;
}
} while (!(source_done && dest_done));
}
void api_cq_send_recv(int len)
{
ssize_t sz;
struct iovec iov;
struct fi_msg_rma rma_msg;
struct fi_rma_iov rma_iov;
iov.iov_base = NULL;
iov.iov_len = 0;
api_cq_init_data(source, len, 0xab);
api_cq_init_data(target, len, 0);
sz = fi_send(ep[0], source, len, loc_mr[0], gni_addr[1], target);
api_cq_send_allowed(sz, cq_bind_flags, "fi_send");
sz = fi_recv(ep[1], target, len, rem_mr[1], gni_addr[0], source);
api_cq_recv_allowed(sz, cq_bind_flags, "fi_recv");
/* don't expect a recv cq if we can't send and vice versa */
api_cq_wait2(msg_cq[0], msg_cq[1],
(cq_bind_flags & FI_SEND) && (cq_bind_flags & FI_RECV),
(cq_bind_flags & FI_SEND) && (cq_bind_flags & FI_RECV));
sz = fi_write(ep[0], source, len,
loc_mr[0], gni_addr[1],
_REM_ADDR(fi[0], target, target), mr_key[1],
target);
api_cq_send_allowed(sz, cq_bind_flags, "fi_write");
api_cq_wait1(msg_cq[0], cq_bind_flags & FI_SEND);
sz = fi_writev(ep[0], &iov, (void **)loc_mr, 1,
gni_addr[1],
_REM_ADDR(fi[0], target, target), mr_key[1],
target);
api_cq_send_allowed(sz, cq_bind_flags, "fi_writev");
api_cq_wait1(msg_cq[0], cq_bind_flags & FI_SEND);
iov.iov_len = len;
iov.iov_base = source;
rma_iov.addr = _REM_ADDR(fi[0], target, target);
rma_iov.len = len;
rma_iov.key = mr_key[1];
rma_msg.msg_iov = &iov;
rma_msg.desc = (void **)loc_mr;
rma_msg.iov_count = 1;
rma_msg.addr = gni_addr[1];
rma_msg.rma_iov = &rma_iov;
rma_msg.rma_iov_count = 1;
rma_msg.context = target;
rma_msg.data = (uint64_t)target;
sz = fi_writemsg(ep[0], &rma_msg, 0);
api_cq_send_allowed(sz, cq_bind_flags, "fi_writemsg");
api_cq_wait1(msg_cq[0], cq_bind_flags & FI_SEND);
#define WRITE_DATA 0x5123da1a145
sz = fi_writedata(ep[0], source, len, loc_mr[0], WRITE_DATA,
gni_addr[1],
_REM_ADDR(fi[0], target, target), mr_key[1],
target);
api_cq_send_allowed(sz, cq_bind_flags, "fi_writedata");
#define READ_CTX 0x4e3dda1aULL
sz = fi_read(ep[0], source, len,
loc_mr[0], gni_addr[1],
_REM_ADDR(fi[0], target, target), mr_key[1],
(void *)READ_CTX);
api_cq_send_allowed(sz, cq_bind_flags, "fi_read");
sz = fi_readv(ep[0], &iov, (void **)loc_mr, 1,
gni_addr[1],
_REM_ADDR(fi[0], target, target), mr_key[1],
target);
api_cq_send_allowed(sz, cq_bind_flags, "fi_readv");
sz = fi_readmsg(ep[0], &rma_msg, 0);
api_cq_send_allowed(sz, cq_bind_flags, "fi_readmsg");
sz = fi_inject_write(ep[0], source, 64,
gni_addr[1],
_REM_ADDR(fi[0], target, target), mr_key[1]);
cr_assert_eq(sz, 0);
api_cq_wait1(msg_cq[0], cq_bind_flags & FI_SEND);
}
static inline void __msg(void)
{
cq_bind_flags = FI_SEND | FI_RECV;
api_cq_bind(cq_bind_flags);
api_cq_send_recv(BUF_SZ);
}
Test(api_cq_basic, msg)
{
__msg();
}
Test(api_cq_scalable, msg)
{
__msg();
}
static inline void __msg_send_only(void)
{
cq_bind_flags = FI_SEND;
api_cq_bind(cq_bind_flags);
api_cq_send_recv(BUF_SZ);
}
Test(api_cq_basic, msg_send_only)
{
__msg_send_only();
}
Test(api_cq_scalable, msg_send_only)
{
__msg_send_only();
}
static inline void __msg_recv_only(void)
{
cq_bind_flags = FI_RECV;
api_cq_bind(cq_bind_flags);
api_cq_send_recv(BUF_SZ);
}
Test(api_cq_basic, msg_recv_only)
{
__msg_recv_only();
}
Test(api_cq_scalable, msg_recv_only)
{
__msg_recv_only();
}
static inline void __msg_no_cq(void)
{
cq_bind_flags = 0;
api_cq_bind(cq_bind_flags);
api_cq_send_recv(BUF_SZ);
}
Test(api_cq_basic, msg_no_cq)
{
__msg_no_cq();
}
Test(api_cq_scalable, msg_no_cq)
{
__msg_no_cq();
}
#define SOURCE_DATA 0xBBBB0000CCCCULL
#define TARGET_DATA 0xAAAA0000DDDDULL
#define FETCH_SOURCE_DATA 0xACEDACEDULL
void api_cq_atomic(void)
{
ssize_t sz;
/* u64 */
*((uint64_t *)source) = SOURCE_DATA;
*((uint64_t *)target) = TARGET_DATA;
sz = fi_atomic(ep[0], source, 1,
loc_mr[0], gni_addr[1],
_REM_ADDR(fi[0], target, target), mr_key[1],
FI_UINT64, FI_ATOMIC_WRITE, target);
api_cq_send_allowed(sz, cq_bind_flags, "fi_atomic");
sz = fi_inject_atomic(ep[0], source, 1,
gni_addr[1],
_REM_ADDR(fi[0], target, target), mr_key[1],
FI_INT64, FI_MIN);
cr_assert_eq(sz, 0);
api_cq_wait1(msg_cq[0], cq_bind_flags & FI_SEND);
}
static inline void __atomic(void)
{
cq_bind_flags = FI_SEND | FI_RECV;
api_cq_bind(cq_bind_flags);
api_cq_atomic();
}
Test(api_cq_basic, atomic)
{
__atomic();
}
Test(api_cq_scalable, atomic)
{
__atomic();
}
static inline void __atomic_send_only(void)
{
cq_bind_flags = FI_SEND;
api_cq_bind(cq_bind_flags);
api_cq_atomic();
}
Test(api_cq_basic, atomic_send_only)
{
__atomic_send_only();
}
Test(api_cq_scalable, atomic_send_only)
{
__atomic_send_only();
}
static inline void __atomic_recv_only(void)
{
cq_bind_flags = FI_RECV;
api_cq_bind(cq_bind_flags);
api_cq_atomic();
}
Test(api_cq_basic, atomic_recv_only)
{
__atomic_recv_only();
}
Test(api_cq_scalable, atomic_recv_only)
{
__atomic_recv_only();
}
|