-
Notifications
You must be signed in to change notification settings - Fork 60
/
na_ofi.c
9171 lines (7843 loc) · 317 KB
/
na_ofi.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
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
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* Copyright (c) 2013-2022 UChicago Argonne, LLC and The HDF Group.
* Copyright (c) 2017-2023 Intel Corporation.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#define _GNU_SOURCE
#include "na_plugin.h"
#ifndef _WIN32
# include "na_ip.h"
# include "na_loc.h"
#endif
#include "mercury_hash_string.h"
#include "mercury_hash_table.h"
#include "mercury_inet.h"
#include "mercury_mem.h"
#include "mercury_mem_pool.h"
#include "mercury_thread.h"
#include "mercury_thread_mutex.h"
#include "mercury_thread_rwlock.h"
#include "mercury_thread_spin.h"
#include "mercury_time.h"
#include <rdma/fabric.h>
#include <rdma/fi_cm.h>
#include <rdma/fi_domain.h>
#include <rdma/fi_endpoint.h>
#include <rdma/fi_errno.h>
#include <rdma/fi_ext.h>
#include <rdma/fi_rma.h>
#include <rdma/fi_tagged.h>
#ifdef NA_OFI_HAS_EXT_GNI_H
# include <rdma/fi_ext_gni.h>
#endif
#ifdef NA_OFI_HAS_EXT_CXI_H
# include <rdma/fi_cxi_ext.h>
#endif
#ifdef _WIN32
# include <WS2tcpip.h>
# include <WinSock2.h>
# include <Windows.h>
#else
# include <netdb.h>
# include <sys/socket.h>
# include <sys/uio.h> /* for struct iovec */
# include <unistd.h>
#endif
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/****************/
/* Local Macros */
/****************/
/* Name of this class */
#define NA_OFI_CLASS_NAME "ofi"
/**
* FI VERSION provides binary backward and forward compatibility support.
* Specify the version of OFI is coded to, the provider will select struct
* layouts that are compatible with this version.
*/
#ifndef FI_COMPILE_VERSION
# define FI_COMPILE_VERSION FI_VERSION(FI_MAJOR_VERSION, FI_MINOR_VERSION)
#endif
#if FI_VERSION_LT(FI_COMPILE_VERSION, FI_VERSION(1, 16))
# define NA_OFI_VERSION FI_VERSION(1, 9)
#elif FI_VERSION_LT(FI_COMPILE_VERSION, FI_VERSION(1, 20))
/* Bump to 1.13 to support redefinition of OFI log callbacks */
# define NA_OFI_VERSION FI_VERSION(1, 13)
#else
/* Bump to 1.20 to support av auth keys */
# define NA_OFI_VERSION FI_VERSION(1, 20)
#endif
/* Fallback for undefined OPX values */
#if FI_VERSION_LT(FI_COMPILE_VERSION, FI_VERSION(1, 15))
# define FI_ADDR_OPX -1
# define FI_PROTO_OPX -1
#endif
/* Fallback for undefined CXI values */
#if FI_VERSION_LT(FI_COMPILE_VERSION, FI_VERSION(1, 14)) /* < 1.14 */
# define FI_ADDR_CXI -2
# define FI_PROTO_CXI -2
#elif (FI_MAJOR_VERSION == 1 && FI_MINOR_VERSION == 14) /* = 1.14 */
# define FI_ADDR_CXI (FI_ADDR_PSMX3 + 1)
# define FI_PROTO_CXI (FI_PROTO_PSMX3 + 1)
#elif (FI_MAJOR_VERSION == 1 && FI_MINOR_VERSION == 15 && \
FI_REVISION_VERSION < 2) /* 1.15 */
# define FI_ADDR_CXI (FI_ADDR_OPX + 1)
# define FI_PROTO_CXI (FI_PROTO_OPX + 1)
#endif
#ifndef NA_OFI_HAS_EXT_CXI_H
# define FI_CXI_DOM_OPS_6 "dom_ops_v6"
#endif
/* Fallback for undefined XNET values */
#if FI_VERSION_LT(FI_COMPILE_VERSION, FI_VERSION(1, 17))
# define FI_PROTO_XNET -3
#endif
/* Default basic bits */
#define NA_OFI_MR_BASIC_REQ (FI_MR_VIRT_ADDR | FI_MR_ALLOCATED | FI_MR_PROV_KEY)
/* flags that control na_ofi behavior (in the X macro below for each
* provider)
*/
#define NA_OFI_DOM_IFACE (1 << 0) /* domain name is interface name */
#define NA_OFI_WAIT_SET (1 << 1) /* supports FI_WAIT_SET */
#define NA_OFI_WAIT_FD (1 << 2) /* supports FI_WAIT_FD */
#define NA_OFI_SIGNAL (1 << 3) /* supports fi_signal() */
#define NA_OFI_SEP (1 << 4) /* supports SEPs */
#define NA_OFI_LOC_INFO (1 << 5) /* supports locality info */
#define NA_OFI_CONTEXT2 (1 << 6) /* requires FI_CONTEXT2 */
#define NA_OFI_HMEM (1 << 7) /* supports FI_HMEM */
#define NA_OFI_AV_AUTH_KEY (1 << 8) /* support FI_AV_AUTH_KEY */
/* X-macro to define the following for each supported provider:
* - enum type
* - name
* - alternate (alias) names for convenience
* - preferred address format if unspecified
* - native address format
* - progress mode
* - endpoint protocol
* - additional capabilities used (beyond the base set required by NA)
* - misc flags to control na_ofi behavior and workarounds with this provider
*
* The purpose of this is to aggregate settings for all providers into a
* single location so that it is easier to alter them.
*/
/* clang-format off */
#define NA_OFI_PROV_TYPES \
X(NA_OFI_PROV_NULL, "", "", 0, 0, 0, 0, 0, 0) \
X(NA_OFI_PROV_SHM, \
"shm", \
"sm", \
FI_ADDR_STR, \
FI_ADDR_STR, \
FI_PROGRESS_MANUAL, \
FI_PROTO_SHM, \
0, \
NA_OFI_HMEM \
) \
X(NA_OFI_PROV_SOCKETS, \
"sockets", \
"", \
FI_SOCKADDR_IN, \
FI_SOCKADDR_IN, \
FI_PROGRESS_AUTO, \
FI_PROTO_SOCK_TCP, \
FI_MULTI_RECV, \
NA_OFI_DOM_IFACE | NA_OFI_WAIT_FD | NA_OFI_SEP \
) \
X(NA_OFI_PROV_TCP, \
"tcp", \
"tcp_exp", \
FI_SOCKADDR_IN, \
FI_SOCKADDR_IN, \
FI_PROGRESS_MANUAL, \
FI_PROTO_XNET, \
FI_MULTI_RECV, \
NA_OFI_DOM_IFACE | NA_OFI_WAIT_FD \
) \
X(NA_OFI_PROV_TCP_RXM, \
"tcp;ofi_rxm", \
"tcp_rxm", \
FI_SOCKADDR_IN, \
FI_SOCKADDR_IN, \
FI_PROGRESS_MANUAL, \
FI_PROTO_RXM, \
FI_MULTI_RECV, \
NA_OFI_DOM_IFACE | NA_OFI_WAIT_FD \
) \
X(NA_OFI_PROV_PSM2, \
"psm2", \
"", \
FI_ADDR_PSMX2, \
FI_ADDR_PSMX2, \
FI_PROGRESS_MANUAL, \
FI_PROTO_PSMX2, \
FI_SOURCE | FI_SOURCE_ERR | FI_MULTI_RECV, \
NA_OFI_SIGNAL | NA_OFI_SEP | NA_OFI_LOC_INFO \
) \
X(NA_OFI_PROV_OPX, \
"opx", \
"", \
FI_ADDR_OPX, \
FI_ADDR_OPX, \
FI_PROGRESS_MANUAL, \
FI_PROTO_OPX, \
0, \
NA_OFI_SIGNAL | NA_OFI_SEP | NA_OFI_CONTEXT2 \
) \
X(NA_OFI_PROV_VERBS_RXM, \
"verbs;ofi_rxm", \
"verbs", \
FI_SOCKADDR_IN, \
FI_SOCKADDR_IB, \
FI_PROGRESS_MANUAL, \
FI_PROTO_RXM, \
FI_MULTI_RECV, \
NA_OFI_WAIT_FD | NA_OFI_LOC_INFO | NA_OFI_HMEM \
) \
X(NA_OFI_PROV_GNI, \
"gni", \
"", \
FI_ADDR_GNI, \
FI_ADDR_GNI, \
FI_PROGRESS_AUTO, \
FI_PROTO_GNI, \
FI_SOURCE | FI_SOURCE_ERR | FI_MULTI_RECV, \
NA_OFI_WAIT_SET | NA_OFI_SIGNAL | NA_OFI_SEP \
) \
X(NA_OFI_PROV_CXI, \
"cxi", \
"", \
FI_ADDR_CXI, \
FI_ADDR_CXI, \
FI_PROGRESS_MANUAL, \
FI_PROTO_CXI, \
FI_SOURCE | FI_SOURCE_ERR | FI_MULTI_RECV, \
NA_OFI_WAIT_FD | NA_OFI_LOC_INFO | NA_OFI_HMEM | NA_OFI_AV_AUTH_KEY \
) \
X(NA_OFI_PROV_MAX, "", "", 0, 0, 0, 0, 0, 0)
/* clang-format on */
#define X(a, b, c, d, e, f, g, h, i) a,
enum na_ofi_prov_type { NA_OFI_PROV_TYPES };
#undef X
#define X(a, b, c, d, e, f, g, h, i) b,
static const char *const na_ofi_prov_name[] = {NA_OFI_PROV_TYPES};
#undef X
#define X(a, b, c, d, e, f, g, h, i) c,
static const char *const na_ofi_prov_alt_name[] = {NA_OFI_PROV_TYPES};
#undef X
#define X(a, b, c, d, e, f, g, h, i) d,
static int const na_ofi_prov_addr_format_pref[] = {NA_OFI_PROV_TYPES};
#undef X
#define X(a, b, c, d, e, f, g, h, i) e,
static int const na_ofi_prov_addr_format_native[] = {NA_OFI_PROV_TYPES};
#undef X
#define X(a, b, c, d, e, f, g, h, i) f,
static enum fi_progress const na_ofi_prov_progress[] = {NA_OFI_PROV_TYPES};
#undef X
#define X(a, b, c, d, e, f, g, h, i) g,
static int const na_ofi_prov_ep_proto[] = {NA_OFI_PROV_TYPES};
#undef X
#define X(a, b, c, d, e, f, g, h, i) h,
static uint64_t const na_ofi_prov_extra_caps[] = {NA_OFI_PROV_TYPES};
#undef X
#define X(a, b, c, d, e, f, g, h, i) i,
static unsigned long const na_ofi_prov_flags[] = {NA_OFI_PROV_TYPES};
#undef X
/* Prov info array init count */
#define NA_OFI_PROV_INFO_COUNT (32)
/* Address / URI max len */
#define NA_OFI_MAX_URI_LEN (128)
/* Address key hash */
#define NA_OFI_HASH64(x) \
((((uint32_t) (x >> 32)) & 0xFFFF0000U) | ((x & 0xFFFFFFFFU) & 0xFFFFU))
/* Address serialization optimization */
/* Don't enable for now to prevent backward compatibility issues */
// #define NA_OFI_ADDR_OPT
/* OPX */
#define NA_OFI_OPX_NODE_PREFIX "ib"
/* IB */
#ifndef AF_IB
# define AF_IB 27
#endif
/* Values taken from librdmacm/rdma_cma.h */
#define NA_OFI_IB_IP_PS_MASK 0xFFFFFFFFFFFF0000ULL
#define NA_OFI_IB_IP_PORT_MASK 0x000000000000FFFFULL
/* GNI */
#define NA_OFI_GNI_AV_STR_ADDR_VERSION (1)
#define NA_OFI_GNI_UDREG_REG_LIMIT (2048)
/* CXI */
#define NA_OFI_CXI_NODE_PREFIX "cxi"
#ifndef C_DFA_PID_BITS_MAX
# define C_DFA_PID_BITS_MAX 9
#endif
#ifndef C_DFA_NIC_BITS
# define C_DFA_NIC_BITS 20
#endif
/* Address pool (enabled by default, comment out to disable) */
#define NA_OFI_HAS_ADDR_POOL
#define NA_OFI_ADDR_POOL_COUNT (64)
/* Memory pool (enabled by default, comment out to disable) */
#define NA_OFI_HAS_MEM_POOL
#define NA_OFI_MEM_CHUNK_COUNT (256)
#define NA_OFI_MEM_BLOCK_COUNT (2)
/* Allocation using hugepages */
#define NA_OFI_ALLOC_HUGE (NA_ALLOC_MAX)
/* Unexpected size */
#define NA_OFI_MSG_SIZE (4096)
#define NA_OFI_TAG_MASK ((uint64_t) 0x0FFFFFFFF)
#define NA_OFI_UNEXPECTED_TAG (NA_OFI_TAG_MASK + 1)
/* Number of CQ event provided for fi_cq_read() */
#define NA_OFI_CQ_EVENT_NUM (16)
/**
* CQ default provider sizes:
* - tcp: 1024
* - verbs: 1024
* - opx: 8192
* - socket: 256
* - gni: 256
* Override default to 128k
*/
#define NA_OFI_CQ_DEPTH (131072)
/* Default OP multi CQ size */
#define NA_OFI_OP_MULTI_CQ_SIZE (NA_OFI_CQ_EVENT_NUM * 4)
/* Uncomment to register SGL regions */
// #define NA_OFI_USE_REGV
/* Maximum number of pre-allocated IOV entries */
#define NA_OFI_IOV_STATIC_MAX (8)
/* Receive context bits for SEP */
#define NA_OFI_SEP_RX_CTX_BITS (8)
/* Op ID status bits */
#define NA_OFI_OP_COMPLETED (1 << 0)
#define NA_OFI_OP_CANCELING (1 << 1)
#define NA_OFI_OP_CANCELED (1 << 2)
#define NA_OFI_OP_QUEUED (1 << 3)
#define NA_OFI_OP_ERRORED (1 << 4)
/* Timeout (ms) until we give up on retry */
#define NA_OFI_OP_RETRY_TIMEOUT (120 * 1000)
/* Private data access */
#define NA_OFI_CLASS(x) ((struct na_ofi_class *) ((x)->plugin_class))
#define NA_OFI_CONTEXT(x) ((struct na_ofi_context *) ((x)->plugin_context))
/* Init info */
#define NA_OFI_INFO_INITIALIZER \
((struct na_ofi_info){.addr_format = FI_FORMAT_UNSPEC, \
.thread_mode = FI_THREAD_UNSPEC, \
.node = NULL, \
.service = NULL, \
.src_addr = NULL, \
.src_addrlen = 0, \
.num_auth_keys = 0, \
.use_hmem = false})
/* Get IOV */
#define NA_OFI_IOV(iov, iovcnt) (iovcnt > NA_OFI_IOV_STATIC_MAX) ? iov.d : iov.s
/* Reset op ID */
#define NA_OFI_OP_RESET( \
_op, _context, _fi_op_flags, _cb_type, _cb, _arg, _addr) \
do { \
*_op->completion_data = \
(struct na_cb_completion_data){ \
.callback_info = \
(struct na_cb_info){ \
.info.multi_recv_unexpected = \
(struct na_cb_info_multi_recv_unexpected){ \
.actual_buf_size = 0, \
.source = NULL, \
.tag = 0, \
.actual_buf = NULL, \
.last = false}, \
.arg = NULL, \
.type = _cb_type, \
.ret = NA_SUCCESS}, \
.callback = NULL, \
.plugin_callback = NULL, \
.plugin_callback_args = NULL}, \
_op->context = _context; \
_op->addr = _addr; \
if (_addr) \
na_ofi_addr_ref_incr(_addr); \
_op->retry_op.msg = NULL; \
_op->fi_op_flags = _fi_op_flags; \
_op->callback = _cb; \
_op->arg = _arg; \
_op->type = _cb_type; \
hg_atomic_set32(&_op->status, 0); \
} while (0)
#define NA_OFI_OP_RELEASE(_op) \
do { \
if (_op->addr) \
na_ofi_addr_ref_decr(_op->addr); \
hg_atomic_set32(&_op->status, NA_OFI_OP_COMPLETED); \
} while (0)
#ifdef _WIN32
# define strtok_r strtok_s
# undef strdup
# define strdup _strdup
#endif
/************************************/
/* Local Type and Struct Definition */
/************************************/
#ifdef _WIN32
typedef USHORT in_port_t;
#endif
/* IB address */
struct na_ofi_sockaddr_ib {
unsigned short int sib_family; /* AF_IB */
uint16_t sib_pkey;
uint32_t sib_flowinfo;
uint8_t sib_addr[16];
uint64_t sib_sid;
uint64_t sib_sid_mask;
uint64_t sib_scope_id;
};
/* PSM address */
struct na_ofi_psm_addr {
uint64_t addr0;
};
/* PSM2 address */
struct na_ofi_psm2_addr {
uint64_t addr0;
uint64_t addr1;
};
/* OPX address */
typedef uint32_t na_ofi_opx_uid_t;
NA_PACKED(union na_ofi_opx_uid {
na_ofi_opx_uid_t fi;
NA_PACKED(struct {
uint16_t endpoint_id;
uint16_t lid;
});
});
NA_PACKED(union na_ofi_opx_address {
uint64_t raw;
NA_PACKED(struct {
uint8_t hfi1_rx;
uint8_t hfi1_unit;
uint8_t reliability_rx;
union na_ofi_opx_uid uid;
uint8_t rx_index;
});
});
NA_PACKED(struct na_ofi_opx_addr {
union na_ofi_opx_address addr;
uint32_t key;
uint32_t key_inst;
});
/* GNI address */
struct na_ofi_gni_addr {
struct {
uint32_t device_addr; /* physical NIC address */
uint32_t cdm_id; /* user supplied id */
};
struct {
uint32_t name_type : 8; /* bound, unbound */
uint32_t cm_nic_cdm_id : 24; /* CM nic ID */
uint32_t cookie; /* CDM identifier */
};
struct {
uint32_t rx_ctx_cnt : 8; /* number of contexts */
uint32_t key_offset : 12; /* auth key offset */
uint32_t unused1 : 12;
uint32_t unused2;
};
uint64_t reserved[3];
};
/* CXI address */
#if FI_VERSION_LT(FI_COMPILE_VERSION, FI_VERSION(1, 20))
struct na_ofi_cxi_addr {
uint32_t pid : C_DFA_PID_BITS_MAX;
uint32_t nic : C_DFA_NIC_BITS;
/* ignore other bits */
};
#else
struct na_ofi_cxi_addr {
uint32_t pid : C_DFA_PID_BITS_MAX;
uint32_t nic : C_DFA_NIC_BITS;
uint16_t vni;
};
#endif
/* String address */
struct na_ofi_str_addr {
char buf[NA_OFI_MAX_URI_LEN];
};
/* Raw address */
union na_ofi_raw_addr {
struct sockaddr_in sin;
struct sockaddr_in6 sin6;
struct na_ofi_sockaddr_ib sib;
struct na_ofi_psm_addr psm;
struct na_ofi_psm2_addr psm2;
struct na_ofi_opx_addr opx;
struct na_ofi_gni_addr gni;
struct na_ofi_cxi_addr cxi;
struct na_ofi_str_addr str;
};
/* Address key */
struct na_ofi_addr_key {
union na_ofi_raw_addr addr;
uint64_t val; /* Keep a 64-bit value for now to simplify hashing */
};
/* Address */
struct na_ofi_addr {
struct na_ofi_addr_key addr_key; /* Address key */
STAILQ_ENTRY(na_ofi_addr) entry; /* Entry in addr pool */
struct na_ofi_class *class; /* Class */
fi_addr_t fi_addr; /* FI address */
fi_addr_t fi_auth_key; /* FI auth key */
hg_atomic_int32_t refcount; /* Reference counter */
};
/* Error address info */
struct na_ofi_src_err {
union na_ofi_raw_addr addr; /* Source address */
size_t addrlen; /* Address size */
fi_addr_t fi_auth_key; /* Auth key if configured with FI_AV_AUTH_KEY */
};
/* Message buffer info */
struct na_ofi_msg_buf_handle {
size_t alloc_size; /* Buf alloc size */
unsigned long flags; /* Buf alloc flags */
struct fid_mr *fi_mr; /* FI MR handle */
};
/* Memory descriptor info */
struct na_ofi_mem_desc_info {
uint64_t fi_mr_key; /* FI MR key */
uint64_t len; /* Size of region */
uint64_t iovcnt; /* Segment count */
uint8_t flags; /* Flag of operation access */
};
/* Memory descriptor */
struct na_ofi_mem_desc {
struct na_ofi_mem_desc_info info; /* Segment info */
union {
struct iovec s[NA_OFI_IOV_STATIC_MAX]; /* Single segment */
struct iovec *d; /* Multiple segments */
} iov; /* Remain last */
};
/* Memory handle */
struct na_ofi_mem_handle {
struct na_ofi_mem_desc desc; /* Memory descriptor */
struct fid_mr *fi_mr; /* FI MR handle */
};
/* Msg info */
struct na_ofi_msg_info {
union {
const void *const_ptr;
void *ptr;
} buf;
void *desc;
size_t buf_size;
fi_addr_t fi_addr;
uint64_t tag;
uint64_t tag_mask;
};
/* OFI RMA op (put/get) */
typedef ssize_t (*na_ofi_rma_op_t)(
struct fid_ep *ep, const struct fi_msg_rma *msg, uint64_t flags);
/* RMA info */
struct na_ofi_rma_info {
na_ofi_rma_op_t fi_rma_op;
const char *fi_rma_op_string;
uint64_t fi_rma_flags;
union {
struct iovec s[NA_OFI_IOV_STATIC_MAX]; /* Single segment */
struct iovec *d; /* Multiple segments */
} local_iov_storage;
struct iovec *local_iov;
union {
void *s[NA_OFI_IOV_STATIC_MAX]; /* Single segment */
void **d; /* Multiple segments */
} local_desc_storage;
void **local_desc;
size_t local_iovcnt;
fi_addr_t fi_addr;
union {
struct fi_rma_iov s[NA_OFI_IOV_STATIC_MAX]; /* Single segment */
struct fi_rma_iov *d; /* Multiple segments */
} remote_iov_storage;
struct fi_rma_iov *remote_iov;
size_t remote_iovcnt;
};
struct na_ofi_completion_multi {
struct na_cb_completion_data *data;
hg_atomic_int32_t head;
hg_atomic_int32_t tail;
int32_t mask;
uint32_t size;
uint32_t completion_count; /* Total completion count */
};
/* Operation ID */
struct na_ofi_op_id {
union {
struct na_cb_completion_data single; /* Single completion */
struct na_ofi_completion_multi multi; /* Multiple completions */
} completion_data_storage; /* Completion data storage */
union {
struct na_ofi_msg_info msg; /* Msg info (tagged and non-tagged) */
struct na_ofi_rma_info rma; /* RMA info */
} info; /* Op info */
TAILQ_ENTRY(na_ofi_op_id) multi; /* Entry in multi queue */
TAILQ_ENTRY(na_ofi_op_id) retry; /* Entry in retry queue */
struct fi_context fi_ctx[2]; /* Context handle */
hg_time_t retry_deadline; /* Retry deadline */
hg_time_t retry_last; /* Last retry time */
struct na_ofi_class *na_ofi_class; /* NA class associated */
na_context_t *context; /* NA context associated */
struct na_ofi_addr *addr; /* Address associated */
union {
na_return_t (*msg)(
struct fid_ep *, const struct na_ofi_msg_info *, void *);
na_return_t (*rma)(
struct fid_ep *, const struct na_ofi_rma_info *, void *);
} retry_op; /* Operation used for retries */
void (*complete)(struct na_ofi_op_id *, bool, na_return_t); /* Complete */
struct na_cb_completion_data *completion_data; /* Completion data */
uint64_t fi_op_flags; /* Operation flags */
na_cb_t callback; /* Operation callback */
void *arg; /* Callback args */
na_cb_type_t type; /* Operation type */
hg_atomic_int32_t status; /* Operation status */
bool multi_event; /* Triggers multiple events */
};
/* Op ID queue */
struct na_ofi_op_queue {
TAILQ_HEAD(, na_ofi_op_id) queue;
hg_thread_spin_t lock;
};
/* Event queue */
struct na_ofi_eq {
struct fid_cq *fi_cq; /* CQ handle */
struct na_ofi_op_queue *retry_op_queue; /* Retry op queue */
struct fid_wait *fi_wait; /* Optional wait set handle */
};
/* Context */
struct na_ofi_context {
struct na_ofi_op_queue multi_op_queue; /* To keep track of multi-events */
struct fid_ep *fi_tx; /* Transmit context handle */
struct fid_ep *fi_rx; /* Receive context handle */
struct na_ofi_eq *eq; /* Event queues */
hg_atomic_int32_t multi_op_count; /* Number of multi-events ops */
uint8_t idx; /* Context index */
};
/* Endpoint */
struct na_ofi_endpoint {
struct fid_ep *fi_ep; /* Endpoint handle */
struct na_ofi_eq *eq; /* Event queues */
struct na_ofi_addr *src_addr; /* Endpoint address */
size_t unexpected_msg_size_max; /* Max unexpected msg size */
size_t expected_msg_size_max; /* Max expected msg size */
};
/* Map (used to cache addresses) */
struct na_ofi_map {
hg_thread_rwlock_t lock;
hg_hash_table_t *key_map; /* Primary */
hg_hash_table_t *fi_map; /* Secondary */
};
#ifndef NA_OFI_HAS_EXT_GNI_H
/* GNI Authorization Key */
struct fi_gni_raw_auth_key {
uint32_t protection_key;
};
struct fi_gni_auth_key {
uint32_t type;
union {
struct fi_gni_raw_auth_key raw;
};
};
#endif
#ifndef NA_OFI_HAS_EXT_CXI_H
/* CXI domain ops (v6) */
struct fi_cxi_dom_ops {
int (*cntr_read)(struct fid *fid, unsigned int cntr, uint64_t *value,
struct timespec *ts);
int (*topology)(struct fid *fid, unsigned int *group_id,
unsigned int *switch_id, unsigned int *port_id);
int (*enable_hybrid_mr_desc)(struct fid *fid, bool enable);
size_t (*ep_get_unexp_msgs)(struct fid_ep *fid_ep,
struct fi_cq_tagged_entry *entry, size_t count, fi_addr_t *src_addr,
size_t *ux_count);
int (*get_dwq_depth)(struct fid *fid, size_t *depth);
int (*enable_mr_match_events)(struct fid *fid, bool enable);
int (*enable_optimized_mrs)(struct fid *fid, bool enable);
};
/* CXI Authorization Key */
struct cxi_auth_key {
uint32_t svc_id;
uint16_t vni;
};
#endif
/* Authorization Key */
union na_ofi_auth_key {
struct fi_gni_auth_key gni_auth_key; /* GNI auth key */
struct cxi_auth_key cxi_auth_key; /* CXI auth key */
};
/* Domain */
struct na_ofi_domain {
const struct na_ofi_fabric *fabric; /* Associated fabric */
struct na_ofi_map addr_map; /* Address map */
hg_hash_table_t *auth_key_map; /* Auth key map (FI_AV_AUTH_KEY) */
struct fid_domain *fi_domain; /* Domain handle */
struct fid_av *fi_av; /* Address vector handle */
char *name; /* Domain name */
size_t context_max; /* Max contexts available */
hg_atomic_int64_t requested_key; /* Requested key if not FI_MR_PROV_KEY */
int64_t max_key; /* Max key if not FI_MR_PROV_KEY */
uint64_t max_tag; /* Max tag from CQ data size */
hg_atomic_int32_t *mr_reg_count; /* Number of MR registered */
bool no_wait; /* Wait disabled on domain */
bool av_auth_key; /* Use FI_AV_AUTH_KEY */
bool av_user_id; /* Use FI_AV_USER_ID */
} HG_LOCK_CAPABILITY("domain");
/* Addr pool */
struct na_ofi_addr_pool {
STAILQ_HEAD(, na_ofi_addr) queue;
hg_thread_spin_t lock;
};
/* Fabric */
struct na_ofi_fabric {
SLIST_ENTRY(na_ofi_fabric) entry; /* Entry in fabric list */
struct fid_fabric *fi_fabric; /* Fabric handle */
char *name; /* Fabric name */
char *prov_name; /* Provider name */
enum na_ofi_prov_type prov_type; /* Provider type */
int32_t refcount; /* Refcount of this fabric */
} HG_LOCK_CAPABILITY("fabric");
/* Get info */
struct na_ofi_info {
char *node; /* Node/host IP info */
char *service; /* Service/port info */
enum fi_threading thread_mode; /* Thread mode */
int addr_format; /* Address format */
void *src_addr; /* Native src addr */
size_t src_addrlen; /* Native src addr len */
size_t num_auth_keys; /* Requested number of auth keys */
bool use_hmem; /* Use FI_HMEM */
};
/* Verify info */
struct na_ofi_verify_info {
const struct na_loc_info *loc_info; /* Loc info */
const char *domain_name; /* Domain name */
int addr_format; /* Addr format */
enum na_ofi_prov_type prov_type; /* Provider type */
};
/* OFI class */
struct na_ofi_class {
struct na_ofi_addr_pool addr_pool; /* Addr pool */
struct fi_info *fi_info; /* OFI info */
struct na_ofi_fabric *fabric; /* Fabric pointer */
struct na_ofi_domain *domain; /* Domain pointer */
struct na_ofi_endpoint *endpoint; /* Endpoint pointer */
struct hg_mem_pool *send_pool; /* Msg send buf pool */
struct hg_mem_pool *recv_pool; /* Msg recv buf pool */
na_return_t (*msg_send_unexpected)(
struct fid_ep *, const struct na_ofi_msg_info *, void *);
na_return_t (*msg_recv_unexpected)(
struct fid_ep *, const struct na_ofi_msg_info *, void *);
na_return_t (*cq_poll)(
struct na_ofi_class *, struct na_ofi_context *, unsigned int *);
unsigned long opt_features; /* Optional feature flags */
hg_atomic_int32_t n_contexts; /* Number of context */
unsigned int op_retry_timeout; /* Retry timeout */
unsigned int op_retry_period; /* Time elapsed until next retry */
uint8_t context_max; /* Max number of contexts */
bool no_wait; /* Ignore wait object */
bool use_sep; /* Use scalable endpoints */
bool finalizing; /* Class being destroyed */
};
/********************/
/* Local Prototypes */
/********************/
#if !defined(_WIN32) && FI_VERSION_GE(FI_COMPILE_VERSION, FI_VERSION(1, 16))
/**
* Check if OFI log is enabled.
*/
static int
na_ofi_log_enabled(const struct fi_provider *prov, enum fi_log_level level,
enum fi_log_subsys subsys, uint64_t flags);
/**
* Print OFI log.
*/
static void
na_ofi_log(const struct fi_provider *prov, enum fi_log_level level,
enum fi_log_subsys subsys, const char *func, int line, const char *msg);
/**
* Check if OFI log is ready.
*/
static int
na_ofi_log_ready(const struct fi_provider *prov, enum fi_log_level level,
enum fi_log_subsys subsys, uint64_t flags, uint64_t *showtime);
/**
* Convert FI log level to HG log level.
*/
static enum hg_log_level
na_ofi_log_level_to_hg(enum fi_log_level level);
#endif
/**
* Convert FI errno to NA return values.
*/
static na_return_t
na_ofi_errno_to_na(int rc);
/**
* Convert provider name to enum type.
*/
static NA_INLINE enum na_ofi_prov_type
na_ofi_prov_name_to_type(const char *prov_name);
/**
* Convert NA traffic class to tclass.
*/
static NA_INLINE uint32_t
na_ofi_tclass(enum na_traffic_class traffic_class);
/**
* Determine addr format to use based on preferences.
*/
static NA_INLINE int
na_ofi_prov_addr_format(
enum na_ofi_prov_type prov_type, enum na_addr_format na_init_format);
/**
* Get provider encoded address size.
*/
static NA_INLINE size_t
na_ofi_prov_addr_size(int addr_format);
/**
* Get provider type encoded in string.
*/
static NA_INLINE enum na_ofi_prov_type
na_ofi_addr_prov(const char *str);
/**
* Get native address from string.
*/
static NA_INLINE na_return_t
na_ofi_str_to_raw_addr(
const char *str, int addr_format, union na_ofi_raw_addr *addr);
static na_return_t
na_ofi_str_to_sin(const char *str, struct sockaddr_in *sin_addr);
static na_return_t
na_ofi_str_to_sin6(const char *str, struct sockaddr_in6 *sin6_addr);
static na_return_t
na_ofi_str_to_sib(const char *str, struct na_ofi_sockaddr_ib *sib_addr);
static na_return_t
na_ofi_str_to_psm(const char *str, struct na_ofi_psm_addr *psm_addr);
static na_return_t
na_ofi_str_to_psm2(const char *str, struct na_ofi_psm2_addr *psm2_addr);
static na_return_t
na_ofi_str_to_opx(const char *str, struct na_ofi_opx_addr *opx_addr);
static na_return_t
na_ofi_str_to_gni(const char *str, struct na_ofi_gni_addr *gni_addr);
static na_return_t
na_ofi_str_to_cxi(const char *str, struct na_ofi_cxi_addr *cxi_addr);
static na_return_t
na_ofi_str_to_str(const char *str, struct na_ofi_str_addr *str_addr);
/**
* Convert the address to a 64-bit key to search corresponding FI addr.
*/
static NA_INLINE uint64_t
na_ofi_raw_addr_to_key(int addr_format, const union na_ofi_raw_addr *addr);
static NA_INLINE uint64_t
na_ofi_sin_to_key(const struct sockaddr_in *addr);
static NA_INLINE uint64_t
na_ofi_sin6_to_key(const struct sockaddr_in6 *addr);
static NA_INLINE uint64_t
na_ofi_sib_to_key(const struct na_ofi_sockaddr_ib *addr);
static NA_INLINE uint64_t
na_ofi_psm_to_key(const struct na_ofi_psm_addr *addr);
static NA_INLINE uint64_t
na_ofi_psm2_to_key(const struct na_ofi_psm2_addr *addr);
static NA_INLINE uint64_t
na_ofi_opx_to_key(const struct na_ofi_opx_addr *addr);
static NA_INLINE uint64_t
na_ofi_gni_to_key(const struct na_ofi_gni_addr *addr);
static NA_INLINE uint64_t
na_ofi_cxi_to_key(const struct na_ofi_cxi_addr *addr);
static NA_INLINE uint64_t
na_ofi_str_to_key(const struct na_ofi_str_addr *addr);
/**
* Convert a key back to an address. (only for sin serialization)
*/
#ifdef NA_OFI_ADDR_OPT
static NA_INLINE void
na_ofi_key_to_sin(struct sockaddr_in *addr, uint64_t key);
#endif
/**
* Size required to serialize raw addr.
*/
static NA_INLINE size_t
na_ofi_raw_addr_serialize_size(int addr_format);
/**
* Serialize addr key.
*/
static na_return_t
na_ofi_raw_addr_serialize(int addr_format, void *buf, size_t buf_size,
const union na_ofi_raw_addr *addr);
/**
* Deserialize addr key.
*/
static na_return_t
na_ofi_raw_addr_deserialize(int addr_format, union na_ofi_raw_addr *addr,
union na_ofi_auth_key *auth_key, const void *buf, size_t buf_size);
/**
* Lookup addr and insert key if not present.
*/
static na_return_t
na_ofi_addr_key_lookup(struct na_ofi_class *na_ofi_class,
struct na_ofi_addr_key *addr_key, fi_addr_t fi_auth_key,
struct na_ofi_addr **na_ofi_addr_p);
/**
* Key hash for hash table.
*/
static NA_INLINE unsigned int
na_ofi_addr_key_hash(hg_hash_table_key_t key);
/**
* Compare key.
*/
static NA_INLINE int
na_ofi_addr_key_equal_default(
hg_hash_table_key_t key1, hg_hash_table_key_t key2);
/**
* Compare IPv6 address keys.
*/
static NA_INLINE int
na_ofi_addr_key_equal_sin6(hg_hash_table_key_t key1, hg_hash_table_key_t key2);