forked from ofiwg/libfabric
-
Notifications
You must be signed in to change notification settings - Fork 1
/
fabric.c
1506 lines (1279 loc) · 37.6 KB
/
fabric.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) 2004, 2005 Topspin Communications. All rights reserved.
* Copyright (c) 2006-2016 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2013-2017 Intel Corp., Inc. All rights reserved.
* (C) Copyright 2020 Hewlett Packard Enterprise Development LP
* Copyright (c) 2022 Intel Corporation. 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 "config.h"
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dirent.h>
#include <ctype.h>
#include <rdma/fi_errno.h>
#include "ofi_util.h"
#include "ofi.h"
#include "shared/ofi_str.h"
#include "ofi_prov.h"
#include "ofi_perf.h"
#include "ofi_hmem.h"
#include "rdma/fi_ext.h"
#ifdef HAVE_LIBDL
#include <dlfcn.h>
#endif
struct ofi_prov {
struct ofi_prov *next;
char *prov_name;
struct fi_provider *provider;
void *dlhandle;
bool hidden;
};
enum ofi_prov_order {
OFI_PROV_ORDER_VERSION,
OFI_PROV_ORDER_REGISTER,
};
struct ofi_info_match {
const char *prov_name;
enum fi_ep_type ep_type;
};
static struct ofi_prov *prov_head, *prov_tail;
static enum ofi_prov_order prov_order = OFI_PROV_ORDER_VERSION;
int ofi_init = 0;
extern struct ofi_common_locks common_locks;
static struct ofi_filter prov_filter;
static struct ofi_prov *
ofi_alloc_prov(const char *prov_name)
{
struct ofi_prov *prov;
prov = calloc(sizeof *prov, 1);
if (!prov)
return NULL;
prov->prov_name = strdup(prov_name);
if (!prov->prov_name) {
free(prov);
return NULL;
}
return prov;
}
static void
ofi_init_prov(struct ofi_prov *prov, struct fi_provider *provider,
void *dlhandle)
{
prov->provider = provider;
prov->dlhandle = dlhandle;
}
static void ofi_cleanup_prov(struct fi_provider *provider, void *dlhandle)
{
if (provider) {
fi_param_undefine(provider);
if (provider->cleanup)
provider->cleanup();
}
#ifdef HAVE_LIBDL
if (dlhandle)
dlclose(dlhandle);
#else
OFI_UNUSED(dlhandle);
#endif
}
static void ofi_free_prov(struct ofi_prov *prov)
{
ofi_cleanup_prov(prov->provider, prov->dlhandle);
free(prov->prov_name);
free(prov);
}
static void ofi_insert_prov(struct ofi_prov *prov)
{
struct ofi_prov *cur, *prev;
for (prev = NULL, cur = prov_head; cur; prev = cur, cur = cur->next) {
if ((strlen(prov->prov_name) == strlen(cur->prov_name)) &&
!strcasecmp(prov->prov_name, cur->prov_name)) {
if ((prov_order == OFI_PROV_ORDER_VERSION) &&
FI_VERSION_LT(cur->provider->version,
prov->provider->version)) {
cur->hidden = true;
prov->next = cur;
if (prev)
prev->next = prov;
else
prov_head = prov;
} else {
prov->hidden = true;
prov->next = cur->next;
cur->next = prov;
if (prov_tail == cur)
prov_tail = prov;
}
return;
}
}
if (prov_tail)
prov_tail->next = prov;
else
prov_head = prov;
prov_tail = prov;
}
static int ofi_find_name(char **names, const char *name)
{
int i;
for (i = 0; names[i]; i++) {
if (!strcasecmp(name, names[i]))
return i;
}
return -1;
}
/* matches if names[i] == "xxx;yyy" and name == "xxx" */
static int ofi_find_layered_name(char **names, const char *name)
{
int i;
size_t len;
len = strlen(name);
for (i = 0; names[i]; i++) {
if (!strncasecmp(name, names[i], len) && names[i][len] == ';' )
return i;
}
return -1;
}
/* matches if names[i] == "xxx" and name == "xxx;yyy" */
static int ofi_find_core_name(char **names, const char *name)
{
int i;
size_t len;
for (i = 0; names[i]; i++) {
len = strlen(names[i]);
if (!strncasecmp(name, names[i], len) && name[len] == ';' )
return i;
}
return -1;
}
static void ofi_closest_prov_names(char *prov_name, char* miss_prov_name, int n)
{
if (strncasecmp( prov_name, miss_prov_name, n ) == 0 ) {
FI_WARN(&core_prov, FI_LOG_CORE,
"Instead misspelled provider: %s, you may want: %s?\n",
miss_prov_name, prov_name);
}
}
static void ofi_suggest_prov_names(char *name_to_match)
{
struct ofi_prov *prov;
for (prov = prov_head; prov; prov = prov->next) {
if (strlen(prov->prov_name) != strlen(name_to_match)
&& !strncasecmp(prov->prov_name, name_to_match,
strlen(name_to_match))) {
if (strlen(name_to_match) > 5)
ofi_closest_prov_names(prov->prov_name,
name_to_match, 5);
else
ofi_closest_prov_names(prov->prov_name,
name_to_match, 2);
}
}
}
static int ofi_is_util_prov(const struct fi_provider *provider)
{
return ofi_prov_ctx(provider)->type == OFI_PROV_UTIL;
}
static int ofi_is_core_prov(const struct fi_provider *provider)
{
return ofi_prov_ctx(provider)->type == OFI_PROV_CORE;
}
static int ofi_is_hook_prov(const struct fi_provider *provider)
{
return ofi_prov_ctx(provider)->type == OFI_PROV_HOOK;
}
int ofi_apply_filter(struct ofi_filter *filter, const char *name)
{
if (!filter->names)
return 0;
if (ofi_find_name(filter->names, name) >= 0)
return filter->negated;
return !filter->negated;
}
/*
* The provider init filter is used to filter out unnecessary core providers
* at the initialization time. Utility providers are not concerned.
*
* Special handling is needed for layered provider names:
*
* If the filter is not negated, a name "xxx;yyy" in the filter should match
* input "xxx" to ensure that the core provider "xxx" is included.
*
* If the filter is negated, a name "xxx;yyy" in the filter should not match
* input "xxx" otherwise the core provider "xxx" may be incorrectly filtered
* out.
*/
static bool
ofi_apply_prov_init_filter(struct ofi_filter *filter, const char *name)
{
if (!filter->names)
return false;
if (ofi_find_name(filter->names, name) >= 0)
return filter->negated;
if (filter->negated)
return false;
if (ofi_find_layered_name(filter->names, name) >= 0)
return false;
return true;
}
/*
* The provider post filter is used to remove unwanted entries from the fi_info
* list before returning from fi_getinfo().
*
* Layered provider names are handled in the same way as non-layered provider
* names -- requiring full match.
*
* In addition, a name "xxx" in the filter should be able to match an input
* "xxx;yyy" to allow extra layering on top of what is requested by the user.
*/
static bool
ofi_apply_prov_post_filter(struct ofi_filter *filter, const char *name)
{
if (!filter->names)
return false;
if (ofi_find_name(filter->names, name) >= 0 ||
ofi_find_core_name(filter->names, name) >= 0)
return filter->negated;
return !filter->negated;
}
static bool ofi_getinfo_filter(const struct fi_provider *provider)
{
/* Positive filters only apply to core providers. They must be
* explicitly enabled by the filter. Other providers (i.e. utility)
* are automatically enabled in this case, so that they can work
* over any enabled core filter. Negative filters may be used
* to disable any provider.
*/
if (!prov_filter.negated && !ofi_is_core_prov(provider))
return false;
return ofi_apply_prov_init_filter(&prov_filter, provider->name);
}
static void ofi_filter_info(struct fi_info **info)
{
struct fi_info *cur, *prev, *tmp;
if (!prov_filter.names)
return;
prev = NULL;
cur = *info;
while (cur) {
assert(cur->fabric_attr && cur->fabric_attr->prov_name);
if (ofi_apply_prov_post_filter(&prov_filter,
cur->fabric_attr->prov_name)) {
tmp = cur;
cur = cur->next;
if (prev)
prev->next = cur;
else
*info = cur;
tmp->next = NULL;
fi_freeinfo(tmp);
} else {
prev = cur;
cur = cur->next;
}
}
}
static struct ofi_prov *ofi_getprov(const char *prov_name, size_t len)
{
struct ofi_prov *prov;
for (prov = prov_head; prov; prov = prov->next) {
if ((strlen(prov->prov_name) == len) &&
!strncasecmp(prov->prov_name, prov_name, len))
return prov;
}
return NULL;
}
static struct fi_provider *ofi_get_hook(const char *name)
{
struct ofi_prov *prov;
struct fi_provider *provider = NULL;
char *try_name = NULL;
int ret;
prov = ofi_getprov(name, strlen(name));
if (!prov) {
ret = asprintf(&try_name, "ofi_hook_%s", name);
if (ret > 0)
prov = ofi_getprov(try_name, ret);
else
try_name = NULL;
}
if (prov) {
if (prov->provider && ofi_is_hook_prov(prov->provider)) {
provider = prov->provider;
} else {
FI_WARN(&core_prov, FI_LOG_CORE,
"Specified provider is not a hook: %s\n", name);
}
} else {
FI_WARN(&core_prov, FI_LOG_CORE,
"No hook found for: %s\n", name);
}
free(try_name);
return provider;
}
/* This is the default order that providers will be accessed when available.
* This, in turn, sets the default ordering of fi_info's reported to the user.
* However, ofi_reorder_info() may re-arrange the list based on hard-coded
* criteria.
*/
static void ofi_ordered_provs_init(void)
{
char *ordered_prov_names[] = {
"efa", "psm2", "opx", "psm", "usnic", "gni", "bgq", "verbs",
"netdir", "psm3", "ofi_rxm", "ofi_rxd", "shm",
/* Initialize the socket based providers last of the
* standard providers. This will result in them being
* the least preferred providers.
*/
/* Before you add ANYTHING here, read the comment above!!! */
"udp", "tcp", "sockets", "net", /* NOTHING GOES HERE! */
/* Seriously, read it! */
/* These are hooking providers only. Their order
* doesn't matter
*/
"ofi_hook_perf", "ofi_hook_debug", "ofi_hook_noop", "ofi_hook_hmem",
"ofi_hook_dmabuf_peer_mem",
/* So do the offload providers. */
"off_coll",
};
struct ofi_prov *prov;
int num_provs, i;
num_provs = sizeof(ordered_prov_names) / sizeof(ordered_prov_names[0]);
for (i = 0; i < num_provs; i++) {
prov = ofi_alloc_prov(ordered_prov_names[i]);
if (prov)
ofi_insert_prov(prov);
}
}
static void ofi_set_prov_type(struct fi_provider *provider)
{
if (!provider->getinfo)
ofi_prov_ctx(provider)->type = OFI_PROV_HOOK;
else if (ofi_has_util_prefix(provider->name))
ofi_prov_ctx(provider)->type = OFI_PROV_UTIL;
else if (ofi_has_offload_prefix(provider->name))
ofi_prov_ctx(provider)->type = OFI_PROV_OFFLOAD;
else
ofi_prov_ctx(provider)->type = OFI_PROV_CORE;
}
static void ofi_register_provider(struct fi_provider *provider, void *dlhandle)
{
struct ofi_prov *prov = NULL;
bool hidden = false;
if (!provider || !provider->name) {
FI_DBG(&core_prov, FI_LOG_CORE,
"no provider structure or name\n");
goto cleanup;
}
FI_INFO(&core_prov, FI_LOG_CORE,
"registering provider: %s (%d.%d)\n", provider->name,
FI_MAJOR(provider->version), FI_MINOR(provider->version));
if (!provider->fabric) {
FI_WARN(&core_prov, FI_LOG_CORE,
"provider missing mandatory entry points\n");
goto cleanup;
}
/* The current core implementation is not backward compatible
* with providers that support a release earlier than v1.3.
* See commit 0f4b6651.
*/
if (provider->fi_version < FI_VERSION(1, 3)) {
FI_INFO(&core_prov, FI_LOG_CORE,
"provider has unsupported FI version "
"(provider %d.%d != libfabric %d.%d); ignoring\n",
FI_MAJOR(provider->fi_version),
FI_MINOR(provider->fi_version), FI_MAJOR_VERSION,
FI_MINOR_VERSION);
goto cleanup;
}
ofi_set_prov_type(provider);
if (ofi_getinfo_filter(provider)) {
FI_INFO(&core_prov, FI_LOG_CORE,
"\"%s\" filtered by provider include/exclude "
"list, skipping\n", provider->name);
hidden = true;
}
if (ofi_apply_filter(&prov_log_filter, provider->name))
ofi_prov_ctx(provider)->disable_logging = true;
/* Prevent utility providers from layering on these core providers
* unless explicitly requested.
*/
if (!strcasecmp(provider->name, "sockets") ||
!strcasecmp(provider->name, "shm") ||
!strcasecmp(provider->name, "efa") ||
!strcasecmp(provider->name, "psm3") ||
ofi_is_util_prov(provider))
ofi_prov_ctx(provider)->disable_layering = true;
prov = ofi_getprov(provider->name, strlen(provider->name));
if (prov && !prov->provider) {
ofi_init_prov(prov, provider, dlhandle);
} else {
prov = ofi_alloc_prov(provider->name);
if (!prov)
goto cleanup;
ofi_init_prov(prov, provider, dlhandle);
ofi_insert_prov(prov);
}
if (hidden)
prov->hidden = true;
return;
cleanup:
ofi_cleanup_prov(provider, dlhandle);
}
#ifdef HAVE_LIBDL
static int lib_filter(const struct dirent *entry)
{
size_t l = strlen(entry->d_name);
size_t sfx = sizeof (FI_LIB_SUFFIX) - 1;
if (l > sfx)
return !strcmp(&(entry->d_name[l-sfx]), FI_LIB_SUFFIX);
else
return 0;
}
#endif
static int verify_filter_names(char **names)
{
int i, j;
char** split_names;
for (i = 0; names[i]; i++) {
split_names = ofi_split_and_alloc(names[i], ";", NULL);
if (!split_names) {
FI_WARN(&core_prov, FI_LOG_CORE,
"unable to parse given filter string\n");
return -FI_ENODATA;
}
for(j = 0; split_names[j]; j++) {
if(!ofi_getprov(split_names[j], strlen(split_names[j]))) {
FI_WARN(&core_prov, FI_LOG_CORE,
"provider %s is unknown, misspelled"
" or DL provider?\n", split_names[j]);
ofi_suggest_prov_names(split_names[j]);
}
}
ofi_free_string_array(split_names);
}
return FI_SUCCESS;
}
void ofi_free_filter(struct ofi_filter *filter)
{
ofi_free_string_array(filter->names);
}
void ofi_create_filter(struct ofi_filter *filter, const char *raw_filter)
{
memset(filter, 0, sizeof *filter);
if (raw_filter == NULL)
return;
if (*raw_filter == '^') {
filter->negated = true;
++raw_filter;
}
filter->names = ofi_split_and_alloc(raw_filter, ",", NULL);
if (!filter->names) {
FI_WARN(&core_prov, FI_LOG_CORE,
"unable to parse filter from: %s\n", raw_filter);
return;
}
if (verify_filter_names(filter->names))
FI_WARN(&core_prov, FI_LOG_CORE,
"unable to verify filter name\n");
}
#ifdef HAVE_LIBDL
static void ofi_reg_dl_prov(const char *lib)
{
void *dlhandle;
struct fi_provider* (*inif)(void);
FI_DBG(&core_prov, FI_LOG_CORE, "opening provider lib %s\n", lib);
dlhandle = dlopen(lib, RTLD_NOW);
if (dlhandle == NULL) {
FI_DBG(&core_prov, FI_LOG_CORE,
"dlopen(%s): %s\n", lib, dlerror());
return;
}
inif = dlsym(dlhandle, "fi_prov_ini");
if (inif == NULL) {
FI_WARN(&core_prov, FI_LOG_CORE, "dlsym: %s\n", dlerror());
dlclose(dlhandle);
} else {
ofi_register_provider((inif)(), dlhandle);
}
}
static void ofi_ini_dir(const char *dir)
{
int n;
char *lib;
struct dirent **liblist = NULL;
n = scandir(dir, &liblist, lib_filter, alphasort);
if (n < 0)
goto libdl_done;
while (n--) {
if (asprintf(&lib, "%s/%s", dir, liblist[n]->d_name) < 0) {
FI_WARN(&core_prov, FI_LOG_CORE,
"asprintf failed to allocate memory\n");
goto libdl_done;
}
ofi_reg_dl_prov(lib);
free(liblist[n]);
free(lib);
}
libdl_done:
while (n-- > 0)
free(liblist[n]);
free(liblist);
}
/* Search standard system library paths (i.e. LD_LIBRARY_PATH) for DLLs for
* known providers.
*/
static void ofi_find_prov_libs(void)
{
const char* lib_prefix = "lib";
struct ofi_prov *prov;
char* lib;
char* short_prov_name;
for (prov = prov_head; prov; prov = prov->next) {
if (!prov->prov_name)
continue;
if (ofi_has_util_prefix(prov->prov_name)) {
short_prov_name = prov->prov_name + strlen(OFI_UTIL_PREFIX);
} else if (ofi_has_offload_prefix(prov->prov_name)) {
short_prov_name = prov->prov_name + strlen(OFI_OFFLOAD_PREFIX);
} else {
short_prov_name = prov->prov_name;
}
if (asprintf(&lib, "%s%s%s%s", lib_prefix,
short_prov_name, "-", FI_LIB_SUFFIX) < 0) {
FI_WARN(&core_prov, FI_LOG_CORE,
"asprintf failed to allocate memory\n");
continue;
}
ofi_reg_dl_prov(lib);
free(lib);
}
}
static void ofi_load_dl_prov(void)
{
char **dirs;
char *provdir = NULL;
void *dlhandle;
int i;
/* If dlopen fails, assume static linking and return */
dlhandle = dlopen(NULL, RTLD_NOW);
if (!dlhandle)
return;
dlclose(dlhandle);
fi_param_define(NULL, "provider_path", FI_PARAM_STRING,
"Search for providers in specific path. Path is "
"specified similar to dir1:dir2:dir3. If the path "
"starts with @, loaded providers are given preference "
"based on discovery order, rather than version. "
"(default: " PROVDLDIR ")");
fi_param_get_str(NULL, "provider_path", &provdir);
if (!provdir || !strlen(provdir)) {
ofi_find_prov_libs();
dirs = ofi_split_and_alloc(PROVDLDIR, ":", NULL);
} else if (provdir[0] == '@') {
prov_order = OFI_PROV_ORDER_REGISTER;
if (strlen(provdir) == 1)
dirs = ofi_split_and_alloc(PROVDLDIR, ":", NULL);
else
dirs = ofi_split_and_alloc(&provdir[1], ":", NULL);
} else {
dirs = ofi_split_and_alloc(provdir, ":", NULL);
}
if (dirs) {
for (i = 0; dirs[i]; i++)
ofi_ini_dir(dirs[i]);
ofi_free_string_array(dirs);
}
}
#else /* HAVE_LIBDL */
static void ofi_load_dl_prov(void)
{
}
#endif
static char **hooks;
static size_t hook_cnt;
/*
* Call the fabric() interface of the hooking provider. We pass in the
* fabric being hooked via the fabric attributes and the corresponding
* fi_provider structure as the context.
*/
static void ofi_hook_install(struct fid_fabric *hfabric,
struct fid_fabric **fabric,
struct fi_provider *prov)
{
struct fi_provider *hook_prov;
struct fi_fabric_attr attr;
int i, ret;
*fabric = hfabric;
if (!hook_cnt || !hooks)
return;
memset(&attr, 0, sizeof attr);
for (i = 0; i < hook_cnt; i++) {
hook_prov = ofi_get_hook(hooks[i]);
if (!hook_prov)
continue;
attr.fabric = hfabric;
ret = hook_prov->fabric(&attr, fabric, prov);
if (ret)
continue;
hfabric = *fabric;
}
}
static void ofi_hook_init(void)
{
char *param_val = NULL;
fi_param_define(NULL, "hook", FI_PARAM_STRING,
"Intercept calls to underlying provider and apply "
"the specified functionality to them. Hook option: "
"perf (gather performance data)");
fi_param_get_str(NULL, "hook", ¶m_val);
if (!param_val)
return;
hooks = ofi_split_and_alloc(param_val, ";", &hook_cnt);
}
static void ofi_hook_fini(void)
{
if (hooks)
ofi_free_string_array(hooks);
}
void fi_ini(void)
{
char *param_val = NULL;
pthread_mutex_lock(&common_locks.ini_lock);
if (ofi_init)
goto unlock;
ofi_ordered_provs_init();
fi_param_init();
fi_log_init();
ofi_osd_init();
ofi_mem_init();
ofi_pmem_init();
ofi_perf_init();
ofi_hook_init();
ofi_hmem_init();
ofi_monitors_init();
fi_param_define(NULL, "provider", FI_PARAM_STRING,
"Only use specified provider (default: all available)");
fi_param_get_str(NULL, "provider", ¶m_val);
ofi_create_filter(&prov_filter, param_val);
fi_param_define(NULL, "fork_unsafe", FI_PARAM_BOOL,
"Whether use of fork() may be unsafe for some providers "
"(default: no). Setting this to yes could improve "
"performance at the expense of making fork() potentially "
"unsafe");
fi_param_define(NULL, "universe_size", FI_PARAM_SIZE_T,
"Defines the maximum number of processes that will be "
"used by distribute OFI application. The provider uses "
"this to optimize resource allocations "
"(default: provider specific)");
fi_param_get_size_t(NULL, "universe_size", &ofi_universe_size);
fi_param_define(NULL, "av_remove_cleanup", FI_PARAM_BOOL,
"When true, release any underlying resources, such as "
"hidden connections when removing an entry from an "
"AV. This can help save resources on AV entries "
"that reference a peer which is no longer active. "
"However, it may abruptly terminate data transfers "
"from peers that are active at the time their "
"address is removed from the local AV. "
"(default: false)");
fi_param_get_bool(NULL, "av_remove_cleanup", &ofi_av_remove_cleanup);
fi_param_define(NULL, "offload_coll_provider", FI_PARAM_STRING,
"The name of colective offload provider (default: empty - no provider)");
ofi_load_dl_prov();
ofi_register_provider(PSM3_INIT, NULL);
ofi_register_provider(PSM2_INIT, NULL);
ofi_register_provider(PSM_INIT, NULL);
ofi_register_provider(USNIC_INIT, NULL);
ofi_register_provider(GNI_INIT, NULL);
ofi_register_provider(BGQ_INIT, NULL);
ofi_register_provider(NETDIR_INIT, NULL);
ofi_register_provider(SHM_INIT, NULL);
ofi_register_provider(RXM_INIT, NULL);
ofi_register_provider(VERBS_INIT, NULL);
/* ofi_register_provider(RSTREAM_INIT, NULL); - no support */
ofi_register_provider(MRAIL_INIT, NULL);
ofi_register_provider(RXD_INIT, NULL);
ofi_register_provider(EFA_INIT, NULL);
ofi_register_provider(OPX_INIT, NULL);
ofi_register_provider(UDP_INIT, NULL);
ofi_register_provider(SOCKETS_INIT, NULL);
ofi_register_provider(TCP_INIT, NULL);
ofi_register_provider(XNET_INIT, NULL);
ofi_register_provider(HOOK_PERF_INIT, NULL);
ofi_register_provider(HOOK_DEBUG_INIT, NULL);
ofi_register_provider(HOOK_HMEM_INIT, NULL);
ofi_register_provider(HOOK_DMABUF_PEER_MEM_INIT, NULL);
ofi_register_provider(HOOK_NOOP_INIT, NULL);
ofi_register_provider(COLL_INIT, NULL);
ofi_init = 1;
unlock:
pthread_mutex_unlock(&common_locks.ini_lock);
}
FI_DESTRUCTOR(fi_fini(void))
{
struct ofi_prov *prov;
pthread_mutex_lock(&common_locks.ini_lock);
if (!ofi_init)
goto unlock;
while (prov_head) {
prov = prov_head;
prov_head = prov->next;
ofi_free_prov(prov);
}
ofi_free_filter(&prov_filter);
ofi_monitors_cleanup();
ofi_hmem_cleanup();
ofi_hook_fini();
ofi_mem_fini();
fi_log_fini();
fi_param_fini();
ofi_osd_fini();
ofi_init = 0;
unlock:
pthread_mutex_unlock(&common_locks.ini_lock);
}
__attribute__((visibility ("default"),EXTERNALLY_VISIBLE))
void DEFAULT_SYMVER_PRE(fi_freeinfo)(struct fi_info *info)
{
struct fi_info *next;
for (; info; info = next) {
next = info->next;
free(info->src_addr);
free(info->dest_addr);
free(info->tx_attr);
free(info->rx_attr);
if (info->ep_attr) {
free(info->ep_attr->auth_key);
free(info->ep_attr);
}
if (info->domain_attr) {
free(info->domain_attr->auth_key);
free(info->domain_attr->name);
free(info->domain_attr);
}
if (info->fabric_attr) {
free(info->fabric_attr->name);
free(info->fabric_attr->prov_name);
free(info->fabric_attr);
}
if (info->nic &&
FI_CHECK_OP(info->nic->fid.ops, struct fi_ops, close)) {
fi_close(&info->nic->fid);
}
free(info);
}
}
DEFAULT_SYMVER(fi_freeinfo_, fi_freeinfo, FABRIC_1.3);
static bool
ofi_info_match_prov(struct fi_info *info, struct ofi_info_match *match)
{
assert(match && match->prov_name);
assert(info && info->fabric_attr && info->ep_attr);
return !strcasecmp(info->fabric_attr->prov_name, match->prov_name) &&
(info->ep_attr->type == match->ep_type);
}
static bool
ofi_info_split(struct fi_info **info, struct fi_info **new_list,
struct fi_info **new_tail, struct ofi_info_match *match)
{
struct fi_info *cur, *prev, *next;
*new_list = NULL;
*new_tail = NULL;
prev = NULL;
for (cur = *info; cur; cur = next) {
next = cur->next;
if (!ofi_info_match_prov(cur, match)) {
prev = cur;
continue;
}
if (prev)
prev->next = next;
else
*info = next;
if (*new_list)
(*new_tail)->next = cur;
else
*new_list = cur;
*new_tail = cur;
(*new_tail)->next = NULL;
}
return *new_list != NULL;
}
static void
ofi_info_insert(struct fi_info **info, struct fi_info *head,
struct fi_info *tail, struct ofi_info_match *match)
{
struct fi_info *cur, *prev;
for (prev = NULL, cur = *info; cur; prev = cur, cur = cur->next) {
if (ofi_info_match_prov(cur, match))
break;
}
if (prev) {