-
Notifications
You must be signed in to change notification settings - Fork 407
/
ucp_ep.c
3113 lines (2630 loc) · 113 KB
/
ucp_ep.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) Mellanox Technologies Ltd. 2001-2020. ALL RIGHTS RESERVED.
* Copyright (C) Los Alamos National Security, LLC. 2019 ALL RIGHTS RESERVED.
*
* See file LICENSE for terms.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "ucp_ep.h"
#include "ucp_worker.h"
#include "ucp_am.h"
#include "ucp_rkey.h"
#include "ucp_ep.inl"
#include "ucp_request.inl"
#include <ucp/wireup/wireup_ep.h>
#include <ucp/wireup/wireup.h>
#include <ucp/wireup/wireup_cm.h>
#include <ucp/tag/eager.h>
#include <ucp/tag/offload.h>
#include <ucp/proto/proto_select.h>
#include <ucp/rndv/rndv.h>
#include <ucp/stream/stream.h>
#include <ucp/core/ucp_listener.h>
#include <ucp/rma/rma.inl>
#include <ucp/rma/rma.h>
#include <ucs/datastruct/queue.h>
#include <ucs/debug/memtrack_int.h>
#include <ucs/debug/log.h>
#include <ucs/debug/debug_int.h>
#include <ucs/sys/string.h>
#include <ucs/sys/sock.h>
#include <ucs/vfs/base/vfs_cb.h>
#include <ucs/vfs/base/vfs_obj.h>
#include <string.h>
typedef struct {
double reg_growth;
double reg_overhead;
double overhead;
double latency;
size_t bw;
} ucp_ep_thresh_params_t;
/**
* Argument for the setting UCP endpoint as failed
*/
typedef struct ucp_ep_set_failed_arg {
ucp_ep_h ucp_ep; /* UCP endpoint which is failed */
ucp_lane_index_t lane; /* UCP endpoint lane which is failed */
ucs_status_t status; /* Failure status */
} ucp_ep_set_failed_arg_t;
extern const ucp_request_send_proto_t ucp_stream_am_proto;
extern const ucp_request_send_proto_t ucp_am_proto;
extern const ucp_request_send_proto_t ucp_am_reply_proto;
#ifdef ENABLE_STATS
static ucs_stats_class_t ucp_ep_stats_class = {
.name = "ucp_ep",
.num_counters = UCP_EP_STAT_LAST,
.class_id = UCS_STATS_CLASS_ID_INVALID,
.counter_names = {
[UCP_EP_STAT_TAG_TX_EAGER] = "tx_eager",
[UCP_EP_STAT_TAG_TX_EAGER_SYNC] = "tx_eager_sync",
[UCP_EP_STAT_TAG_TX_RNDV] = "tx_rndv"
}
};
#endif
static uct_iface_t ucp_failed_tl_iface = {
.ops = {
.ep_put_short = (uct_ep_put_short_func_t)ucs_empty_function_return_ep_timeout,
.ep_put_bcopy = (uct_ep_put_bcopy_func_t)ucs_empty_function_return_bc_ep_timeout,
.ep_put_zcopy = (uct_ep_put_zcopy_func_t)ucs_empty_function_return_ep_timeout,
.ep_get_short = (uct_ep_get_short_func_t)ucs_empty_function_return_ep_timeout,
.ep_get_bcopy = (uct_ep_get_bcopy_func_t)ucs_empty_function_return_ep_timeout,
.ep_get_zcopy = (uct_ep_get_zcopy_func_t)ucs_empty_function_return_ep_timeout,
.ep_am_short = (uct_ep_am_short_func_t)ucs_empty_function_return_ep_timeout,
.ep_am_short_iov = (uct_ep_am_short_iov_func_t)ucs_empty_function_return_ep_timeout,
.ep_am_bcopy = (uct_ep_am_bcopy_func_t)ucs_empty_function_return_bc_ep_timeout,
.ep_am_zcopy = (uct_ep_am_zcopy_func_t)ucs_empty_function_return_ep_timeout,
.ep_atomic_cswap64 = (uct_ep_atomic_cswap64_func_t)ucs_empty_function_return_ep_timeout,
.ep_atomic_cswap32 = (uct_ep_atomic_cswap32_func_t)ucs_empty_function_return_ep_timeout,
.ep_atomic64_post = (uct_ep_atomic64_post_func_t)ucs_empty_function_return_ep_timeout,
.ep_atomic32_post = (uct_ep_atomic32_post_func_t)ucs_empty_function_return_ep_timeout,
.ep_atomic64_fetch = (uct_ep_atomic64_fetch_func_t)ucs_empty_function_return_ep_timeout,
.ep_atomic32_fetch = (uct_ep_atomic32_fetch_func_t)ucs_empty_function_return_ep_timeout,
.ep_tag_eager_short = (uct_ep_tag_eager_short_func_t)ucs_empty_function_return_ep_timeout,
.ep_tag_eager_bcopy = (uct_ep_tag_eager_bcopy_func_t)ucs_empty_function_return_ep_timeout,
.ep_tag_eager_zcopy = (uct_ep_tag_eager_zcopy_func_t)ucs_empty_function_return_ep_timeout,
.ep_tag_rndv_zcopy = (uct_ep_tag_rndv_zcopy_func_t)ucs_empty_function_return_ep_timeout,
.ep_tag_rndv_cancel = (uct_ep_tag_rndv_cancel_func_t)ucs_empty_function_return_ep_timeout,
.ep_tag_rndv_request = (uct_ep_tag_rndv_request_func_t)ucs_empty_function_return_ep_timeout,
.ep_pending_add = (uct_ep_pending_add_func_t)ucs_empty_function_return_busy,
.ep_pending_purge = (uct_ep_pending_purge_func_t)ucs_empty_function_return_success,
.ep_flush = (uct_ep_flush_func_t)ucs_empty_function_return_ep_timeout,
.ep_fence = (uct_ep_fence_func_t)ucs_empty_function_return_ep_timeout,
.ep_check = (uct_ep_check_func_t)ucs_empty_function_return_success,
.ep_connect_to_ep = (uct_ep_connect_to_ep_func_t)ucs_empty_function_return_ep_timeout,
.ep_destroy = (uct_ep_destroy_func_t)ucs_empty_function,
.ep_get_address = (uct_ep_get_address_func_t)ucs_empty_function_return_ep_timeout
}
};
static uct_ep_t ucp_failed_tl_ep = {
.iface = &ucp_failed_tl_iface
};
static const char *ucp_err_handling_mode_names[] = {
[UCP_ERR_HANDLING_MODE_NONE] = "none",
[UCP_ERR_HANDLING_MODE_PEER] = "peer"
};
int ucp_is_uct_ep_failed(uct_ep_h uct_ep)
{
return uct_ep == &ucp_failed_tl_ep;
}
void ucp_ep_config_key_reset(ucp_ep_config_key_t *key)
{
ucp_lane_index_t i;
memset(key, 0, sizeof(*key));
key->num_lanes = 0;
for (i = 0; i < UCP_MAX_LANES; ++i) {
key->lanes[i].rsc_index = UCP_NULL_RESOURCE;
key->lanes[i].dst_md_index = UCP_NULL_RESOURCE;
key->lanes[i].dst_sys_dev = UCS_SYS_DEVICE_ID_UNKNOWN;
key->lanes[i].path_index = 0;
key->lanes[i].lane_types = 0;
}
key->am_lane = UCP_NULL_LANE;
key->wireup_msg_lane = UCP_NULL_LANE;
key->cm_lane = UCP_NULL_LANE;
key->rkey_ptr_lane = UCP_NULL_LANE;
key->tag_lane = UCP_NULL_LANE;
key->rma_bw_md_map = 0;
key->reachable_md_map = 0;
key->dst_md_cmpts = NULL;
key->ep_check_map = 0;
key->err_mode = UCP_ERR_HANDLING_MODE_NONE;
memset(key->am_bw_lanes, UCP_NULL_LANE, sizeof(key->am_bw_lanes));
memset(key->rma_lanes, UCP_NULL_LANE, sizeof(key->rma_lanes));
memset(key->rma_bw_lanes, UCP_NULL_LANE, sizeof(key->rma_bw_lanes));
memset(key->amo_lanes, UCP_NULL_LANE, sizeof(key->amo_lanes));
}
ucs_status_t ucp_ep_create_base(ucp_worker_h worker, const char *peer_name,
const char *message, ucp_ep_h *ep_p)
{
ucp_lane_index_t lane;
ucs_status_t status;
ucp_ep_h ep;
ep = ucs_strided_alloc_get(&worker->ep_alloc, "ucp_ep");
if (ep == NULL) {
ucs_error("Failed to allocate ep");
status = UCS_ERR_NO_MEMORY;
goto err;
}
ucp_ep_ext_gen(ep)->control_ext = ucs_calloc(1,
sizeof(ucp_ep_ext_control_t),
"ep_control_ext");
if (ucp_ep_ext_gen(ep)->control_ext == NULL) {
ucs_error("Failed to allocate ep control extension");
status = UCS_ERR_NO_MEMORY;
goto err_free_ep;
}
ep->refcount = 1;
ep->cfg_index = UCP_WORKER_CFG_INDEX_NULL;
ep->worker = worker;
ep->am_lane = UCP_NULL_LANE;
ep->flags = 0;
ep->conn_sn = UCP_EP_MATCH_CONN_SN_MAX;
#if UCS_ENABLE_ASSERT
ep->flush_iter_refcount = 0;
ep->discard_refcount = 0;
#endif
ucp_ep_ext_gen(ep)->user_data = NULL;
ucp_ep_ext_control(ep)->cm_idx = UCP_NULL_RESOURCE;
ucp_ep_ext_control(ep)->err_cb = NULL;
ucp_ep_ext_control(ep)->local_ep_id = UCS_PTR_MAP_KEY_INVALID;
ucp_ep_ext_control(ep)->remote_ep_id = UCS_PTR_MAP_KEY_INVALID;
#if UCS_ENABLE_ASSERT
ucp_ep_ext_control(ep)->ka_last_round = 0;
#endif
UCS_STATIC_ASSERT(sizeof(ucp_ep_ext_gen(ep)->ep_match) >=
sizeof(ucp_ep_ext_gen(ep)->flush_state));
memset(&ucp_ep_ext_gen(ep)->ep_match, 0,
sizeof(ucp_ep_ext_gen(ep)->ep_match));
ucs_hlist_head_init(&ucp_ep_ext_gen(ep)->proto_reqs);
ucp_stream_ep_init(ep);
ucp_am_ep_init(ep);
for (lane = 0; lane < UCP_MAX_LANES; ++lane) {
ep->uct_eps[lane] = NULL;
}
#if ENABLE_DEBUG_DATA
ucs_snprintf_zero(ep->peer_name, UCP_WORKER_ADDRESS_NAME_MAX, "%s",
peer_name);
#endif
/* Create statistics */
status = UCS_STATS_NODE_ALLOC(&ep->stats, &ucp_ep_stats_class,
worker->stats, "-%p", ep);
if (status != UCS_OK) {
goto err_free_ep_control_ext;
}
/* Create endpoint VFS node on demand to avoid memory bloat */
ucs_vfs_obj_set_dirty(worker, ucp_worker_vfs_refresh);
*ep_p = ep;
ucs_debug("created ep %p to %s %s", ep, ucp_ep_peer_name(ep), message);
return UCS_OK;
err_free_ep_control_ext:
ucs_free(ucp_ep_ext_control(ep));
err_free_ep:
ucs_strided_alloc_put(&worker->ep_alloc, ep);
err:
return status;
}
static int
ucp_ep_local_disconnect_progress_remove_filter(const ucs_callbackq_elem_t *elem,
void *arg)
{
ucp_ep_h ep = (ucp_ep_h)arg;
ucp_request_t *req;
if (elem->cb != ucp_ep_local_disconnect_progress) {
return 0;
}
req = (ucp_request_t*)elem->arg;
if (ep != req->send.ep) {
return 0;
}
/* Expect that only EP flush request can be remained in the callback queue,
* because reply UCP EP created for sending WIREUP_MSG/EP_REMOVED message is
* not exposed to a user */
ucs_assert(req->flags & UCP_REQUEST_FLAG_RELEASED);
ucs_assert(req->send.uct.func == ucp_ep_flush_progress_pending);
ucp_request_complete_send(req, UCS_OK);
return 1;
}
static unsigned ucp_ep_set_failed_progress(void *arg)
{
ucp_ep_set_failed_arg_t *set_ep_failed_arg = arg;
ucp_ep_h ucp_ep = set_ep_failed_arg->ucp_ep;
ucp_worker_h worker = ucp_ep->worker;
UCS_ASYNC_BLOCK(&worker->async);
ucp_ep_set_failed(ucp_ep, set_ep_failed_arg->lane,
set_ep_failed_arg->status);
UCS_ASYNC_UNBLOCK(&worker->async);
ucs_free(set_ep_failed_arg);
return 1;
}
static int ucp_ep_set_failed_remove_filter(const ucs_callbackq_elem_t *elem,
void *arg)
{
ucp_ep_set_failed_arg_t *set_ep_failed_arg = elem->arg;
if ((elem->cb == ucp_ep_set_failed_progress) &&
(set_ep_failed_arg->ucp_ep == arg)) {
ucs_free(set_ep_failed_arg);
return 1;
}
return 0;
}
static int ucp_ep_remove_filter(const ucs_callbackq_elem_t *elem, void *arg)
{
if (ucp_wireup_msg_ack_cb_pred(elem, arg) ||
ucp_listener_accept_cb_remove_filter(elem, arg) ||
ucp_ep_local_disconnect_progress_remove_filter(elem, arg) ||
ucp_ep_set_failed_remove_filter(elem, arg)) {
return 1;
}
return 0;
}
static void ucp_ep_destroy_base(ucp_ep_h ep)
{
ucs_assert(ep->refcount == 0);
ucs_assert(ep->flush_iter_refcount == 0);
ucs_assert(ep->discard_refcount == 0);
ucs_assert(ucs_hlist_is_empty(&ucp_ep_ext_gen(ep)->proto_reqs));
ucs_vfs_obj_remove(ep);
ucs_callbackq_remove_if(&ep->worker->uct->progress_q, ucp_ep_remove_filter,
ep);
UCS_STATS_NODE_FREE(ep->stats);
ucs_free(ucp_ep_ext_control(ep));
ucs_strided_alloc_put(&ep->worker->ep_alloc, ep);
}
void ucp_ep_add_ref(ucp_ep_h ep)
{
ucs_assert(ep->refcount < UINT8_MAX);
++ep->refcount;
}
/* Return 1 if the endpoint was destroyed, 0 if not */
int ucp_ep_remove_ref(ucp_ep_h ep)
{
ucs_assert(ep->refcount > 0);
if (--ep->refcount == 0) {
ucp_ep_destroy_base(ep);
return 1;
}
return 0;
}
ucs_status_t ucp_worker_create_ep(ucp_worker_h worker, unsigned ep_init_flags,
const char *peer_name, const char *message,
ucp_ep_h *ep_p)
{
ucp_context_h context = worker->context;
ucs_status_t status;
ucp_ep_h ep;
status = ucp_ep_create_base(worker, peer_name, message, &ep);
if (status != UCS_OK) {
goto err;
}
if (!(ep_init_flags & UCP_EP_INIT_FLAG_INTERNAL) &&
((context->config.ext.proto_indirect_id == UCS_CONFIG_ON) ||
((context->config.ext.proto_indirect_id == UCS_CONFIG_AUTO) &&
(ep_init_flags & UCP_EP_INIT_ERR_MODE_PEER_FAILURE)))) {
ucp_ep_update_flags(ep, UCP_EP_FLAG_INDIRECT_ID, 0);
}
status = ucs_ptr_map_put(&worker->ep_map, ep,
!!(ep->flags & UCP_EP_FLAG_INDIRECT_ID),
&ucp_ep_ext_control(ep)->local_ep_id);
if ((status != UCS_OK) && (status != UCS_ERR_NO_PROGRESS)) {
ucs_error("ep %p: failed to allocate ID: %s", ep,
ucs_status_string(status));
goto err_destroy_ep_base;
}
if (ep_init_flags & UCP_EP_INIT_FLAG_INTERNAL) {
ucp_ep_update_flags(ep, UCP_EP_FLAG_INTERNAL, 0);
ucs_list_add_tail(&worker->internal_eps, &ucp_ep_ext_gen(ep)->ep_list);
} else {
ucs_list_add_tail(&worker->all_eps, &ucp_ep_ext_gen(ep)->ep_list);
ucs_assert(ep->worker->num_all_eps < UINT_MAX);
++ep->worker->num_all_eps;
}
*ep_p = ep;
return UCS_OK;
err_destroy_ep_base:
ucp_ep_remove_ref(ep);
err:
return status;
}
void ucp_ep_delete(ucp_ep_h ep)
{
if (!(ep->flags & UCP_EP_FLAG_INTERNAL)) {
ucs_assert(ep->worker->num_all_eps > 0);
--ep->worker->num_all_eps;
ucp_worker_keepalive_remove_ep(ep);
}
ucp_ep_release_id(ep);
ucs_list_del(&ucp_ep_ext_gen(ep)->ep_list);
ucp_ep_remove_ref(ep);
}
/* Since release function resets EP ID to @ref UCS_PTR_MAP_KEY_INVALID and PTR
* MAP considers @ref UCS_PTR_MAP_KEY_INVALID as direct key, release EP ID is
* re-entrant function */
void ucp_ep_release_id(ucp_ep_h ep)
{
ucs_status_t status;
/* Don't use ucp_ep_local_id() function here to avoid assertion failure,
* because local_ep_id can be set to @ref UCS_PTR_MAP_KEY_INVALID */
status = ucs_ptr_map_del(&ep->worker->ep_map,
ucp_ep_ext_control(ep)->local_ep_id);
if ((status != UCS_OK) && (status != UCS_ERR_NO_PROGRESS)) {
ucs_warn("ep %p local id 0x%" PRIxPTR ": ucs_ptr_map_del failed: %s",
ep, ucp_ep_local_id(ep), ucs_status_string(status));
}
ucp_ep_ext_control(ep)->local_ep_id = UCS_PTR_MAP_KEY_INVALID;
}
void ucp_ep_config_key_set_err_mode(ucp_ep_config_key_t *key,
unsigned ep_init_flags)
{
key->err_mode = (ep_init_flags & UCP_EP_INIT_ERR_MODE_PEER_FAILURE) ?
UCP_ERR_HANDLING_MODE_PEER : UCP_ERR_HANDLING_MODE_NONE;
}
static ucs_status_t
ucp_ep_adjust_params(ucp_ep_h ep, const ucp_ep_params_t *params)
{
/* handle a case where the existing endpoint is incomplete */
if (params->field_mask & UCP_EP_PARAM_FIELD_ERR_HANDLING_MODE) {
if (ucp_ep_config(ep)->key.err_mode != params->err_mode) {
ucs_error("asymmetric endpoint configuration is not supported, "
"error handling level mismatch");
return UCS_ERR_UNSUPPORTED;
}
}
if (params->field_mask & UCP_EP_PARAM_FIELD_ERR_HANDLER) {
ucp_ep_ext_gen(ep)->user_data = params->err_handler.arg;
ucp_ep_ext_control(ep)->err_cb = params->err_handler.cb;
}
if (params->field_mask & UCP_EP_PARAM_FIELD_USER_DATA) {
/* user_data overrides err_handler.arg */
ucp_ep_ext_gen(ep)->user_data = params->user_data;
}
return UCS_OK;
}
ucs_status_t ucp_ep_evaluate_perf(ucp_ep_h ep,
const ucp_ep_evaluate_perf_param_t *param,
ucp_ep_evaluate_perf_attr_t *attr)
{
const ucp_worker_h worker = ep->worker;
const ucp_context_h context = worker->context;
const ucp_ep_config_key_t *key = &ucp_ep_config(ep)->key;
double max_bandwidth = 0;
ucp_rsc_index_t max_bandwidth_rsc_index = 0;
ucp_rsc_index_t rsc_index;
double bandwidth;
ucp_lane_index_t lane;
ucp_worker_iface_t *wiface;
uct_iface_attr_t *iface_attr;
ucs_linear_func_t estimated_time;
if (!ucs_test_all_flags(attr->field_mask,
UCP_EP_PERF_ATTR_FIELD_ESTIMATED_TIME &
UCP_EP_PERF_PARAM_FIELD_MESSAGE_SIZE)) {
return UCS_ERR_INVALID_PARAM;
}
for (lane = 0; lane < ucp_ep_num_lanes(ep); ++lane) {
if (lane == key->cm_lane) {
/* Skip CM lanes for bandwidth calculation */
continue;
}
rsc_index = key->lanes[lane].rsc_index;
wiface = worker->ifaces[rsc_index];
bandwidth = ucp_tl_iface_bandwidth(context,
&wiface->attr.bandwidth);
if (bandwidth > max_bandwidth) {
max_bandwidth = bandwidth;
max_bandwidth_rsc_index = rsc_index;
}
}
iface_attr = ucp_worker_iface_get_attr(worker,
max_bandwidth_rsc_index);
estimated_time.c = ucp_tl_iface_latency(context, &iface_attr->latency);
estimated_time.m = param->message_size / max_bandwidth;
attr->estimated_time = estimated_time.c + estimated_time.m;
return UCS_OK;
}
ucs_status_t ucp_worker_mem_type_eps_create(ucp_worker_h worker)
{
ucp_context_h context = worker->context;
unsigned pack_flags = ucp_worker_default_address_pack_flags(worker);
ucp_unpacked_address_t local_address;
ucs_memory_type_t mem_type;
ucs_status_t status;
void *address_buffer;
size_t address_length;
char ep_name[UCP_WORKER_ADDRESS_NAME_MAX];
ucs_memory_type_for_each(mem_type) {
if (UCP_MEM_IS_HOST(mem_type) ||
UCS_BITMAP_IS_ZERO_INPLACE(
&context->mem_type_access_tls[mem_type])) {
continue;
}
status = ucp_address_pack(worker, NULL,
&context->mem_type_access_tls[mem_type],
pack_flags, NULL, &address_length,
&address_buffer);
if (status != UCS_OK) {
goto err_cleanup_eps;
}
status = ucp_address_unpack(worker, address_buffer, pack_flags,
&local_address);
if (status != UCS_OK) {
goto err_free_address_buffer;
}
ucs_snprintf_zero(ep_name, UCP_WORKER_ADDRESS_NAME_MAX,
"mem_type_ep:%s", ucs_memory_type_names[mem_type]);
/* create memtype UCP EPs after blocking async context, because they set
* INTERNAL flag (setting EP flags is expected to be guarded) */
UCS_ASYNC_BLOCK(&worker->async);
status = ucp_ep_create_to_worker_addr(worker, &ucp_tl_bitmap_max,
&local_address,
UCP_EP_INIT_FLAG_MEM_TYPE |
UCP_EP_INIT_FLAG_INTERNAL,
ep_name,
&worker->mem_type_ep[mem_type]);
if (status != UCS_OK) {
UCS_ASYNC_UNBLOCK(&worker->async);
goto err_free_address_list;
}
ucp_ep_flush_state_reset(worker->mem_type_ep[mem_type]);
UCS_ASYNC_UNBLOCK(&worker->async);
ucs_free(local_address.address_list);
ucs_free(address_buffer);
}
return UCS_OK;
err_free_address_list:
ucs_free(local_address.address_list);
err_free_address_buffer:
ucs_free(address_buffer);
err_cleanup_eps:
ucp_worker_mem_type_eps_destroy(worker);
return status;
}
void ucp_worker_mem_type_eps_destroy(ucp_worker_h worker)
{
ucs_memory_type_t mem_type;
ucp_ep_h ep;
/* Destroy memtype UCP EPs after blocking async context, because cleanup
* lanes set FAILED flag (setting EP flags is expected to be guarded) */
UCS_ASYNC_BLOCK(&worker->async);
ucs_memory_type_for_each(mem_type) {
ep = worker->mem_type_ep[mem_type];
if (ep == NULL) {
continue;
}
ucs_debug("memtype ep %p: destroy", ep);
ucs_assert(ep->flags & UCP_EP_FLAG_INTERNAL);
ucp_ep_destroy_internal(ep);
worker->mem_type_ep[mem_type] = NULL;
}
UCS_ASYNC_UNBLOCK(&worker->async);
}
ucs_status_t ucp_ep_init_create_wireup(ucp_ep_h ep, unsigned ep_init_flags,
ucp_wireup_ep_t **wireup_ep)
{
ucp_ep_config_key_t key;
ucs_status_t status;
ucs_assert(ep_init_flags & UCP_EP_INIT_CM_WIREUP_CLIENT);
ucs_assert(ucp_worker_num_cm_cmpts(ep->worker) != 0);
ucp_ep_config_key_reset(&key);
ucp_ep_config_key_set_err_mode(&key, ep_init_flags);
key.num_lanes = 1;
/* all operations will use the first lane, which is a stub endpoint before
* reconfiguration */
key.am_lane = 0;
if (ucp_ep_init_flags_has_cm(ep_init_flags)) {
key.cm_lane = 0;
/* Send keepalive on wireup_ep (which will send on aux_ep) */
if (ep_init_flags & UCP_EP_INIT_ERR_MODE_PEER_FAILURE) {
key.ep_check_map |= UCS_BIT(key.cm_lane);
}
} else {
key.wireup_msg_lane = 0;
}
status = ucp_worker_get_ep_config(ep->worker, &key, 0, &ep->cfg_index);
if (status != UCS_OK) {
return status;
}
ep->am_lane = key.am_lane;
if (!ucp_ep_has_cm_lane(ep)) {
ucp_ep_update_flags(ep, UCP_EP_FLAG_CONNECT_REQ_QUEUED, 0);
}
status = ucp_wireup_ep_create(ep, &ep->uct_eps[0]);
if (status != UCS_OK) {
return status;
}
*wireup_ep = ucs_derived_of(ep->uct_eps[0], ucp_wireup_ep_t);
return UCS_OK;
}
ucs_status_t
ucp_ep_create_to_worker_addr(ucp_worker_h worker,
const ucp_tl_bitmap_t *local_tl_bitmap,
const ucp_unpacked_address_t *remote_address,
unsigned ep_init_flags, const char *message,
ucp_ep_h *ep_p)
{
unsigned addr_indices[UCP_MAX_LANES];
ucp_tl_bitmap_t ep_tl_bitmap;
ucs_status_t status;
ucp_ep_h ep;
/* allocate endpoint */
status = ucp_worker_create_ep(worker, ep_init_flags, remote_address->name,
message, &ep);
if (status != UCS_OK) {
goto err;
}
/* initialize transport endpoints */
status = ucp_wireup_init_lanes(ep, ep_init_flags, local_tl_bitmap,
remote_address, addr_indices);
if (status != UCS_OK) {
goto err_delete;
}
ucp_ep_get_tl_bitmap(ep, &ep_tl_bitmap);
ucp_tl_bitmap_validate(&ep_tl_bitmap, local_tl_bitmap);
*ep_p = ep;
return UCS_OK;
err_delete:
ucp_ep_delete(ep);
err:
return status;
}
static ucs_status_t ucp_ep_create_to_sock_addr(ucp_worker_h worker,
const ucp_ep_params_t *params,
ucp_ep_h *ep_p)
{
char peer_name[UCS_SOCKADDR_STRING_LEN];
ucp_wireup_ep_t *wireup_ep;
ucs_status_t status;
ucp_ep_h ep;
unsigned ep_init_flags;
if (!(params->field_mask & UCP_EP_PARAM_FIELD_SOCK_ADDR)) {
ucs_error("destination socket address is missing");
status = UCS_ERR_INVALID_PARAM;
goto err;
}
UCP_CHECK_PARAM_NON_NULL(params->sockaddr.addr, status, goto err);
/* allocate endpoint */
ucs_sockaddr_str(params->sockaddr.addr, peer_name, sizeof(peer_name));
ep_init_flags = ucp_ep_init_flags(worker, params) |
ucp_cm_ep_init_flags(params);
status = ucp_worker_create_ep(worker, ep_init_flags, peer_name,
"from api call", &ep);
if (status != UCS_OK) {
goto err;
}
status = ucp_ep_init_create_wireup(ep, ep_init_flags, &wireup_ep);
if (status != UCS_OK) {
goto err_delete;
}
status = ucp_ep_adjust_params(ep, params);
if (status != UCS_OK) {
goto err_cleanup_lanes;
}
status = ucp_ep_client_cm_connect_start(ep, params);
if (status != UCS_OK) {
goto err_cleanup_lanes;
}
ucp_ep_flush_state_reset(ep);
*ep_p = ep;
return UCS_OK;
err_cleanup_lanes:
ucp_ep_cleanup_lanes(ep);
err_delete:
ucp_ep_delete(ep);
err:
return status;
}
/**
* Create an endpoint on the server side connected to the client endpoint.
*/
ucs_status_t ucp_ep_create_server_accept(ucp_worker_h worker,
const ucp_conn_request_h conn_request,
ucp_ep_h *ep_p)
{
const ucp_wireup_sockaddr_data_t *sa_data = &conn_request->sa_data;
unsigned ep_init_flags = 0;
ucp_unpacked_address_t remote_addr;
uint64_t addr_flags;
unsigned i;
ucs_status_t status;
if (sa_data->err_mode == UCP_ERR_HANDLING_MODE_PEER) {
ep_init_flags |= UCP_EP_INIT_ERR_MODE_PEER_FAILURE;
}
if (sa_data->addr_mode != UCP_WIREUP_SA_DATA_CM_ADDR) {
ucs_fatal("client sockaddr data contains invalid address mode %d",
sa_data->addr_mode);
}
addr_flags = ucp_worker_common_address_pack_flags(worker) |
UCP_ADDRESS_PACK_FLAGS_CM_DEFAULT;
/* coverity[overrun-local] */
status = ucp_address_unpack(worker, sa_data + 1, addr_flags, &remote_addr);
if (status != UCS_OK) {
ucp_listener_reject(conn_request->listener, conn_request);
return status;
}
for (i = 0; i < remote_addr.address_count; ++i) {
remote_addr.address_list[i].dev_addr = conn_request->remote_dev_addr;
remote_addr.address_list[i].dev_index = conn_request->sa_data.dev_index;
}
status = ucp_ep_cm_server_create_connected(worker, ep_init_flags,
&remote_addr, conn_request,
ep_p);
ucs_free(remote_addr.address_list);
return status;
}
static ucs_status_t
ucp_ep_create_api_conn_request(ucp_worker_h worker,
const ucp_ep_params_t *params, ucp_ep_h *ep_p)
{
ucp_conn_request_h conn_request = params->conn_request;
ucp_ep_h ep;
ucs_status_t status;
status = ucp_ep_create_server_accept(worker, conn_request, &ep);
if (status != UCS_OK) {
return status;
}
status = ucp_ep_adjust_params(ep, params);
if (status == UCS_OK) {
*ep_p = ep;
} else {
ucp_ep_destroy_internal(ep);
}
return status;
}
static ucs_status_t
ucp_ep_create_api_to_worker_addr(ucp_worker_h worker,
const ucp_ep_params_t *params, ucp_ep_h *ep_p)
{
ucp_unpacked_address_t remote_address;
ucp_ep_match_conn_sn_t conn_sn;
ucs_status_t status;
unsigned flags;
ucp_ep_h ep;
if (!(params->field_mask & UCP_EP_PARAM_FIELD_REMOTE_ADDRESS)) {
status = UCS_ERR_INVALID_PARAM;
ucs_error("remote worker address is missing");
goto out;
}
UCP_CHECK_PARAM_NON_NULL(params->address, status, goto out);
status = ucp_address_unpack(worker, params->address,
ucp_worker_default_address_pack_flags(worker),
&remote_address);
if (status != UCS_OK) {
goto out;
}
/* Check if there is already an unconnected internal endpoint to the same
* destination address.
* In case of loopback connection, search the hash table for an endpoint with
* even/odd matching, so that every 2 endpoints connected to the local worker
* with be paired to each other.
* Note that if a loopback endpoint had the UCP_EP_PARAMS_FLAGS_NO_LOOPBACK
* flag set, it will not be added to ep_match as an unexpected ep. Because
* dest_ep_ptr will be initialized, a WIREUP_REQUEST (if sent) will have
* dst_ep != 0. So, ucp_wireup_request() will not create an unexpected ep
* in ep_match.
*/
conn_sn = ucp_ep_match_get_sn(worker, remote_address.uuid);
ep = ucp_ep_match_retrieve(worker, remote_address.uuid,
conn_sn ^
(remote_address.uuid == worker->uuid),
UCS_CONN_MATCH_QUEUE_UNEXP);
if (ep != NULL) {
status = ucp_ep_adjust_params(ep, params);
if (status != UCS_OK) {
ucp_ep_destroy_internal(ep);
}
ucp_ep_flush_state_reset(ep);
ucp_stream_ep_activate(ep);
goto out_free_address;
}
status = ucp_ep_create_to_worker_addr(worker, &ucp_tl_bitmap_max,
&remote_address,
ucp_ep_init_flags(worker, params),
"from api call", &ep);
if (status != UCS_OK) {
goto out_free_address;
}
status = ucp_ep_adjust_params(ep, params);
if (status != UCS_OK) {
ucp_ep_destroy_internal(ep);
goto out_free_address;
}
ep->conn_sn = conn_sn;
/*
* If we are connecting to our own worker, and loopback is allowed, connect
* the endpoint to itself by updating dest_ep_ptr.
* Otherwise, add the new ep to the matching context as an expected endpoint,
* waiting for connection request from the peer endpoint
*/
flags = UCP_PARAM_VALUE(EP, params, flags, FLAGS, 0);
if ((remote_address.uuid == worker->uuid) &&
!(flags & UCP_EP_PARAMS_FLAGS_NO_LOOPBACK)) {
ucp_ep_update_remote_id(ep, ucp_ep_local_id(ep));
ucp_ep_flush_state_reset(ep);
} else {
ucp_ep_match_insert(worker, ep, remote_address.uuid, conn_sn,
UCS_CONN_MATCH_QUEUE_EXP);
}
/* if needed, send initial wireup message */
if (!(ep->flags & UCP_EP_FLAG_LOCAL_CONNECTED)) {
ucs_assert(!(ep->flags & UCP_EP_FLAG_CONNECT_REQ_QUEUED));
status = ucp_wireup_send_request(ep);
if (status != UCS_OK) {
goto out_free_address;
}
}
status = UCS_OK;
out_free_address:
ucs_free(remote_address.address_list);
out:
if (status == UCS_OK) {
*ep_p = ep;
}
return status;
}
ucs_status_t ucp_ep_create(ucp_worker_h worker, const ucp_ep_params_t *params,
ucp_ep_h *ep_p)
{
ucs_status_t status;
unsigned flags;
ucp_ep_h ep = NULL;
UCS_ASYNC_BLOCK(&worker->async);
flags = UCP_PARAM_VALUE(EP, params, flags, FLAGS, 0);
if (flags & UCP_EP_PARAMS_FLAGS_CLIENT_SERVER) {
status = ucp_ep_create_to_sock_addr(worker, params, &ep);
} else if (params->field_mask & UCP_EP_PARAM_FIELD_CONN_REQUEST) {
status = ucp_ep_create_api_conn_request(worker, params, &ep);
} else if (params->field_mask & UCP_EP_PARAM_FIELD_REMOTE_ADDRESS) {
status = ucp_ep_create_api_to_worker_addr(worker, params, &ep);
} else {
status = UCS_ERR_INVALID_PARAM;
}
if (status == UCS_OK) {
#if ENABLE_DEBUG_DATA
if ((params->field_mask & UCP_EP_PARAM_FIELD_NAME) &&
(params->name != NULL)) {
ucs_snprintf_zero(ep->name, UCP_ENTITY_NAME_MAX, "%s",
params->name);
} else {
ucs_snprintf_zero(ep->name, UCP_ENTITY_NAME_MAX, "%p", ep);
}
#endif
ucp_ep_update_flags(ep, UCP_EP_FLAG_USED, 0);
*ep_p = ep;
}
UCS_ASYNC_UNBLOCK(&worker->async);
return status;
}
ucs_status_ptr_t ucp_ep_modify_nb(ucp_ep_h ep, const ucp_ep_params_t *params)
{
ucp_worker_h worker = ep->worker;
ucs_status_t status;
if (params->field_mask & (UCP_EP_PARAM_FIELD_REMOTE_ADDRESS |
UCP_EP_PARAM_FIELD_SOCK_ADDR |
UCP_EP_PARAM_FIELD_ERR_HANDLING_MODE)) {
return UCS_STATUS_PTR(UCS_ERR_INVALID_PARAM);
}
UCS_ASYNC_BLOCK(&worker->async);
status = ucp_ep_adjust_params(ep, params);
UCS_ASYNC_UNBLOCK(&worker->async);
return UCS_STATUS_PTR(status);
}
void ucp_ep_err_pending_purge(uct_pending_req_t *self, void *arg)
{
ucp_request_t *req = ucs_container_of(self, ucp_request_t, send.uct);
ucs_status_t status = UCS_PTR_STATUS(arg);
ucp_request_send_state_ff(req, status);
}
void ucp_destroyed_ep_pending_purge(uct_pending_req_t *self, void *arg)
{
ucs_bug("pending request %p (%s) on ep %p should have been flushed",
self, ucs_debug_get_symbol_name(self->func), arg);
}
void
ucp_ep_purge_lanes(ucp_ep_h ep, uct_pending_purge_callback_t purge_cb,
void *purge_arg)
{
ucp_lane_index_t lane;
uct_ep_h uct_ep;
for (lane = 0; lane < ucp_ep_num_lanes(ep); ++lane) {
uct_ep = ep->uct_eps[lane];
if ((lane == ucp_ep_get_cm_lane(ep)) || (uct_ep == NULL)) {
continue;
}
ucs_debug("ep %p: purge uct_ep[%d]=%p", ep, lane, uct_ep);
uct_ep_pending_purge(uct_ep, purge_cb, purge_arg);
}
}
void ucp_ep_destroy_internal(ucp_ep_h ep)
{
ucs_debug("ep %p: destroy", ep);
ucp_ep_cleanup_lanes(ep);
ucp_ep_delete(ep);
}
static void ucp_ep_check_lanes(ucp_ep_h ep)