forked from ofiwg/libfabric
/
gnix_ep.c
3214 lines (2688 loc) · 79.3 KB
/
gnix_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) 2015-2017 Cray Inc. All rights reserved.
* Copyright (c) 2015-2017 Los Alamos 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.
*/
/*
* Endpoint common code
*/
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "gnix.h"
#include "gnix_cm_nic.h"
#include "gnix_nic.h"
#include "gnix_util.h"
#include "gnix_ep.h"
#include "gnix_hashtable.h"
#include "gnix_vc.h"
#include "gnix_vector.h"
#include "gnix_msg.h"
#include "gnix_rma.h"
#include "gnix_atomic.h"
#include "gnix_cntr.h"
#include "gnix_xpmem.h"
#include "gnix_eq.h"
#include "gnix_cm.h"
#include "gnix_auth_key.h"
/*******************************************************************************
* gnix_fab_req freelist functions
*
* These are wrappers around the gnix_freelist
*
******************************************************************************/
#define GNIX_FAB_REQ_FL_MIN_SIZE 100
#define GNIX_FAB_REQ_FL_REFILL_SIZE 10
int _gnix_ep_int_tx_pool_grow(struct gnix_fid_ep *ep)
{
int ret, i;
uint8_t *tx_bufs;
struct fid_mr *auto_mr = NULL;
struct gnix_fid_mem_desc *md = NULL;
struct gnix_int_tx_buf *tx_buf_list;
struct gnix_int_tx_ptrs *tx_ptrs;
assert(ep);
if (ep->int_tx_pool.nbufs >= GNIX_INT_TX_POOL_COUNT) {
GNIX_WARN(FI_LOG_EP_DATA, "int_tx_pool is at max size\n");
return -FI_ENOSPC;
}
tx_bufs = malloc(GNIX_INT_TX_POOL_SIZE * GNIX_INT_TX_BUF_SZ);
if (tx_bufs == NULL) {
GNIX_WARN(FI_LOG_EP_DATA, "tx_bufs allocation failed\n");
goto tx_buf_err;
}
tx_buf_list = malloc(GNIX_INT_TX_POOL_SIZE *
sizeof(struct gnix_int_tx_buf));
if (tx_buf_list == NULL) {
GNIX_WARN(FI_LOG_EP_DATA, "tx_bufs_list allocation failed\n");
goto tx_buf_list_err;
}
tx_ptrs = malloc(sizeof(struct gnix_int_tx_ptrs));
if (tx_buf_list == NULL) {
GNIX_WARN(FI_LOG_EP_DATA, "tx_ptrs allocation failed\n");
goto tx_ptrs_err;
}
ret = gnix_mr_reg(&ep->domain->domain_fid.fid, tx_bufs,
GNIX_INT_TX_BUF_SZ * GNIX_INT_TX_POOL_SIZE,
FI_READ | FI_WRITE, 0, 0, 0, &auto_mr, NULL);
if (unlikely(ret != FI_SUCCESS)) {
GNIX_WARN(FI_LOG_EP_DATA, "gnix_mr_req returned: %s\n",
fi_strerror(-ret));
goto reg_err;
}
md = container_of(auto_mr, struct gnix_fid_mem_desc, mr_fid);
fastlock_acquire(&ep->int_tx_pool.lock);
for (i = 0; i < GNIX_INT_TX_POOL_SIZE; i++) {
GNIX_DEBUG(FI_LOG_EP_DATA,
"tx_bufs + (%d * GNIX_INT_TX_BUF_SZ) = %p\n",
i, tx_bufs + (i * GNIX_INT_TX_BUF_SZ));
tx_buf_list[i].buf = tx_bufs + (i * GNIX_INT_TX_BUF_SZ);
tx_buf_list[i].md = md;
slist_insert_tail(&tx_buf_list[i].e, &ep->int_tx_pool.sl);
}
tx_ptrs->md = md;
tx_ptrs->buf_ptr = (void *) tx_bufs;
tx_ptrs->sl_ptr = (void *) tx_buf_list;
slist_insert_tail(&tx_ptrs->e, &ep->int_tx_pool.bl);
ep->int_tx_pool.nbufs++;
fastlock_release(&ep->int_tx_pool.lock);
return FI_SUCCESS;
reg_err:
free(tx_ptrs);
tx_ptrs_err:
free(tx_buf_list);
tx_buf_list_err:
free(tx_bufs);
tx_buf_err:
return -FI_ENOSPC;
}
int _gnix_ep_int_tx_pool_init(struct gnix_fid_ep *ep)
{
int ret;
assert(ep);
ep->int_tx_pool.nbufs = 0;
slist_init(&ep->int_tx_pool.sl);
slist_init(&ep->int_tx_pool.bl);
fastlock_init(&ep->int_tx_pool.lock);
ret = _gnix_ep_int_tx_pool_grow(ep);
if (ret != FI_SUCCESS)
return ret;
ep->int_tx_pool.enabled = true;
return FI_SUCCESS;
}
void _gnix_ep_int_tx_pool_fini(struct gnix_fid_ep *ep)
{
int ret;
struct slist_entry *e;
struct gnix_int_tx_ptrs *tx_ptrs;
assert(ep);
if (ep->int_tx_pool.enabled == false)
return;
fastlock_acquire(&ep->int_tx_pool.lock);
while (!slist_empty(&ep->int_tx_pool.bl)) {
e = slist_remove_head(&ep->int_tx_pool.bl);
tx_ptrs = (struct gnix_int_tx_ptrs *)e;
ret = fi_close(&tx_ptrs->md->mr_fid.fid);
if (ret != FI_SUCCESS) {
GNIX_WARN(FI_LOG_EP_DATA, "fi_close returned: %s\n",
fi_strerror(-ret));
}
if (tx_ptrs->buf_ptr != NULL) {
free(tx_ptrs->buf_ptr);
tx_ptrs->buf_ptr = NULL;
}
if (tx_ptrs->sl_ptr != NULL) {
free(tx_ptrs->sl_ptr);
tx_ptrs->sl_ptr = NULL;
}
free(tx_ptrs);
ep->int_tx_pool.nbufs--;
}
ep->int_tx_pool.enabled = false;
fastlock_release(&ep->int_tx_pool.lock);
}
static int __fr_freelist_init(struct gnix_fid_ep *ep)
{
int ret;
assert(ep);
ret = _gnix_fl_init_ts(sizeof(struct gnix_fab_req),
offsetof(struct gnix_fab_req, dlist),
GNIX_FAB_REQ_FL_MIN_SIZE,
GNIX_FAB_REQ_FL_REFILL_SIZE,
0, 0, &ep->fr_freelist);
if (ret != FI_SUCCESS) {
GNIX_DEBUG(FI_LOG_EP_DATA, "_gnix_fl_init_ts returned: %s\n",
fi_strerror(-ret));
return ret;
}
return ret;
}
static void __fr_freelist_destroy(struct gnix_fid_ep *ep)
{
assert(ep);
_gnix_fl_destroy(&ep->fr_freelist);
}
int _gnix_ep_enable(struct gnix_fid_ep *ep)
{
/*
* set enable flags and add nic to poll lists
*/
if (ep->send_cq) {
_gnix_cq_poll_obj_add(ep->send_cq, ep->nic,
_gnix_nic_progress);
if (ep->cm_nic) /* No CM NIC for MSG EPs */
_gnix_cq_poll_obj_add(ep->send_cq, ep->cm_nic,
_gnix_cm_nic_progress);
ep->tx_enabled = true;
}
if (ep->recv_cq) {
_gnix_cq_poll_obj_add(ep->recv_cq, ep->nic,
_gnix_nic_progress);
if (ep->cm_nic) /* No CM NIC for MSG EPs */
_gnix_cq_poll_obj_add(ep->recv_cq, ep->cm_nic,
_gnix_cm_nic_progress);
ep->rx_enabled = true;
}
if (ep->send_cntr) {
_gnix_cntr_poll_obj_add(ep->send_cntr, ep->nic,
_gnix_nic_progress);
if (ep->cm_nic) /* No CM NIC for MSG EPs */
_gnix_cntr_poll_obj_add(ep->send_cntr, ep->cm_nic,
_gnix_cm_nic_progress);
}
if (ep->recv_cntr) {
_gnix_cntr_poll_obj_add(ep->recv_cntr, ep->nic,
_gnix_nic_progress);
if (ep->cm_nic) /* No CM NIC for MSG EPs */
_gnix_cntr_poll_obj_add(ep->recv_cntr, ep->cm_nic,
_gnix_cm_nic_progress);
}
if (ep->write_cntr) {
_gnix_cntr_poll_obj_add(ep->write_cntr, ep->nic,
_gnix_nic_progress);
if (ep->cm_nic) /* No CM NIC for MSG EPs */
_gnix_cntr_poll_obj_add(ep->write_cntr, ep->cm_nic,
_gnix_cm_nic_progress);
}
if (ep->read_cntr) {
_gnix_cntr_poll_obj_add(ep->read_cntr, ep->nic,
_gnix_nic_progress);
if (ep->cm_nic) /* No CM NIC for MSG EPs */
_gnix_cntr_poll_obj_add(ep->read_cntr, ep->cm_nic,
_gnix_cm_nic_progress);
}
if (ep->rwrite_cntr) {
_gnix_cntr_poll_obj_add(ep->rwrite_cntr, ep->nic,
_gnix_nic_progress);
if (ep->cm_nic) /* No CM NIC for MSG EPs */
_gnix_cntr_poll_obj_add(ep->rwrite_cntr, ep->cm_nic,
_gnix_cm_nic_progress);
}
if (ep->rread_cntr) {
_gnix_cntr_poll_obj_add(ep->rread_cntr, ep->nic,
_gnix_nic_progress);
if (ep->cm_nic) /* No CM NIC for MSG EPs */
_gnix_cntr_poll_obj_add(ep->rread_cntr, ep->cm_nic,
_gnix_cm_nic_progress);
}
return FI_SUCCESS;
}
/*******************************************************************************
* Forward declaration for ops structures
******************************************************************************/
static struct fi_ops gnix_ep_fi_ops;
static struct fi_ops_ep gnix_ep_ops;
static struct fi_ops_msg gnix_ep_msg_ops;
static struct fi_ops_rma gnix_ep_rma_ops;
struct fi_ops_tagged gnix_ep_tagged_ops;
struct fi_ops_atomic gnix_ep_atomic_ops;
/*******************************************************************************
* EP common messaging wrappers.
******************************************************************************/
ssize_t _ep_recv(struct fid_ep *ep, void *buf, size_t len,
void *desc, fi_addr_t src_addr, void *context,
uint64_t flags, uint64_t tag, uint64_t ignore)
{
struct gnix_fid_ep *ep_priv;
if (!ep) {
return -FI_EINVAL;
}
ep_priv = container_of(ep, struct gnix_fid_ep, ep_fid);
assert(GNIX_EP_RDM_DGM_MSG(ep_priv->type));
if (!(ep_priv->op_flags & FI_MULTI_RECV)) {
return _gnix_recv(ep_priv,
(uint64_t)buf,
len, desc,
src_addr,
context,
ep_priv->op_flags | flags,
tag,
ignore,
NULL);
} else {
return _gnix_recv_mr(ep_priv,
(uint64_t)buf,
len,
desc,
src_addr,
context,
ep_priv->op_flags | flags,
tag,
ignore);
}
}
ssize_t _ep_recvv(struct fid_ep *ep, const struct iovec *iov,
void **desc, size_t count, fi_addr_t src_addr,
void *context, uint64_t flags, uint64_t tag,
uint64_t ignore)
{
struct gnix_fid_ep *ep_priv;
if (!ep || !iov || count > GNIX_MAX_MSG_IOV_LIMIT) {
return -FI_EINVAL;
}
ep_priv = container_of(ep, struct gnix_fid_ep, ep_fid);
assert(GNIX_EP_RDM_DGM_MSG(ep_priv->type));
if (count <= 1) {
if (!(ep_priv->op_flags & FI_MULTI_RECV)) {
return _gnix_recv(ep_priv,
(uint64_t)iov[0].iov_base,
iov[0].iov_len,
desc ? desc[0] : NULL,
src_addr,
context,
ep_priv->op_flags | flags,
tag,
ignore,
NULL);
} else {
return _gnix_recv_mr(ep_priv,
(uint64_t)iov[0].iov_base,
iov[0].iov_len,
desc ? desc[0] : NULL,
src_addr,
context,
ep_priv->op_flags | flags,
tag,
ignore);
}
}
return _gnix_recvv(ep_priv, iov, desc, count, src_addr,
context, ep_priv->op_flags | flags, ignore, tag);
}
ssize_t _ep_recvmsg(struct fid_ep *ep, const struct fi_msg *msg,
uint64_t flags, uint64_t tag,
uint64_t ignore)
{
struct iovec iov;
struct gnix_fid_ep *ep_priv = container_of(ep, struct gnix_fid_ep, ep_fid);
ep_priv = container_of(ep, struct gnix_fid_ep, ep_fid);
assert(GNIX_EP_RDM_DGM_MSG(ep_priv->type));
iov.iov_base = NULL;
iov.iov_len = 0;
if (!msg) {
return -FI_EINVAL;
}
if (flags & FI_MULTI_RECV) {
return _gnix_recv_mr(ep_priv,
(uint64_t)msg->msg_iov[0].iov_base,
msg->msg_iov[0].iov_len,
msg->desc ? msg->desc[0] : NULL,
msg->addr,
msg->context,
ep_priv->op_flags | flags,
tag,
ignore);
}
/* msg_iov can be undefined when using FI_PEEK, etc. */
return _ep_recvv(ep, msg->msg_iov ? msg->msg_iov : &iov, msg->desc,
msg->iov_count, msg->addr, msg->context, flags, tag,
ignore);
}
ssize_t _ep_send(struct fid_ep *ep, const void *buf, size_t len,
void *desc, fi_addr_t dest_addr, void *context,
uint64_t flags, uint64_t tag)
{
struct gnix_fid_ep *gnix_ep;
if (!ep) {
return -FI_EINVAL;
}
gnix_ep = container_of(ep, struct gnix_fid_ep, ep_fid);
assert(GNIX_EP_RDM_DGM_MSG(gnix_ep->type));
return _gnix_send(gnix_ep, (uint64_t)buf, len, desc, dest_addr, context,
gnix_ep->op_flags | flags, 0, tag);
}
ssize_t _ep_sendv(struct fid_ep *ep, const struct iovec *iov,
void **desc, size_t count, fi_addr_t dest_addr,
void *context, uint64_t flags, uint64_t tag)
{
struct gnix_fid_ep *gnix_ep;
if (!ep || !iov || !count || count > GNIX_MAX_MSG_IOV_LIMIT) {
return -FI_EINVAL;
}
gnix_ep = container_of(ep, struct gnix_fid_ep, ep_fid);
assert(GNIX_EP_RDM_DGM_MSG(gnix_ep->type));
if (count == 1) {
return _gnix_send(gnix_ep, (uint64_t)iov[0].iov_base,
iov[0].iov_len, desc ? desc[0] : NULL,
dest_addr, context, gnix_ep->op_flags | flags,
0, tag);
}
return _gnix_sendv(gnix_ep, iov, desc, count, dest_addr, context,
gnix_ep->op_flags | flags, tag);
}
ssize_t _ep_sendmsg(struct fid_ep *ep, const struct fi_msg *msg,
uint64_t flags, uint64_t tag)
{
struct gnix_fid_ep *gnix_ep;
if (!ep || !msg || !msg->msg_iov || !msg->iov_count) {
return -FI_EINVAL;
}
/* Must check the iov count here, can't send msg->data to sendv */
if (msg->iov_count > 1) {
return _ep_sendv(ep, msg->msg_iov, msg->desc, msg->iov_count,
msg->addr, msg->context, flags, tag);
}
gnix_ep = container_of(ep, struct gnix_fid_ep, ep_fid);
assert(GNIX_EP_RDM_DGM_MSG(gnix_ep->type));
return _gnix_send(gnix_ep, (uint64_t)msg->msg_iov[0].iov_base,
msg->msg_iov[0].iov_len,
msg->desc ? msg->desc[0] : NULL, msg->addr,
msg->context, flags, msg->data, tag);
}
ssize_t _ep_inject(struct fid_ep *ep, const void *buf,
size_t len, uint64_t data, fi_addr_t dest_addr,
uint64_t flags, uint64_t tag)
{
struct gnix_fid_ep *gnix_ep;
uint64_t inject_flags;
if (!ep) {
return -FI_EINVAL;
}
gnix_ep = container_of(ep, struct gnix_fid_ep, ep_fid);
assert(GNIX_EP_RDM_DGM_MSG(gnix_ep->type));
inject_flags = (gnix_ep->op_flags | FI_INJECT |
GNIX_SUPPRESS_COMPLETION | flags);
return _gnix_send(gnix_ep, (uint64_t)buf, len, NULL, dest_addr,
NULL, inject_flags, data, tag);
}
ssize_t _ep_senddata(struct fid_ep *ep, const void *buf,
size_t len, void *desc, uint64_t data,
fi_addr_t dest_addr, void *context,
uint64_t flags, uint64_t tag)
{
struct gnix_fid_ep *gnix_ep;
uint64_t sd_flags;
if (!ep) {
return -FI_EINVAL;
}
gnix_ep = container_of(ep, struct gnix_fid_ep, ep_fid);
assert(GNIX_EP_RDM_DGM_MSG(gnix_ep->type));
sd_flags = gnix_ep->op_flags | FI_REMOTE_CQ_DATA | flags;
return _gnix_send(gnix_ep, (uint64_t)buf, len, desc, dest_addr,
context, sd_flags, data, tag);
}
static void __gnix_vc_destroy_ht_entry(void *val)
{
struct gnix_vc *vc = (struct gnix_vc *) val;
_gnix_vc_destroy(vc);
}
/*******************************************************************************
* EP vc initialization helper
******************************************************************************/
int _gnix_ep_init_vc(struct gnix_fid_ep *ep_priv)
{
int ret;
gnix_hashtable_attr_t gnix_ht_attr;
gnix_vec_attr_t gnix_vec_attr;
if (ep_priv->av == NULL) {
GNIX_FATAL(FI_LOG_EP_CTRL,
"_gnix_ep_init_vc av field NULL\n");
}
if (ep_priv->av->type == FI_AV_TABLE) {
/* Use array to store EP VCs when using FI_AV_TABLE. */
ep_priv->vc_table = calloc(1, sizeof(struct gnix_vector));
if(ep_priv->vc_table == NULL)
return -FI_ENOMEM;
gnix_vec_attr.vec_initial_size =
ep_priv->domain->params.ct_init_size;
/* TODO: ep_priv->domain->params.ct_max_size; */
gnix_vec_attr.vec_maximum_size = 1024*1024;
gnix_vec_attr.vec_increase_step = ep_priv->domain->params.ct_step;
gnix_vec_attr.vec_increase_type = GNIX_VEC_INCREASE_MULT;
gnix_vec_attr.vec_internal_locking = GNIX_VEC_UNLOCKED;
ret = _gnix_vec_init(ep_priv->vc_table, &gnix_vec_attr);
GNIX_DEBUG(FI_LOG_EP_CTRL,
"ep_priv->vc_table = %p, ep_priv->vc_table->vector = %p\n",
ep_priv->vc_table, ep_priv->vc_table->vector);
if (ret != FI_SUCCESS) {
GNIX_WARN(FI_LOG_EP_CTRL, "_gnix_vec_init returned %s\n",
fi_strerror(ret));
goto err;
}
} else {
/* Use hash table to store EP VCs when using FI_AV_MAP. */
ep_priv->vc_ht = calloc(1, sizeof(struct gnix_hashtable));
if (ep_priv->vc_ht == NULL)
return -FI_ENOMEM;
gnix_ht_attr.ht_initial_size =
ep_priv->domain->params.ct_init_size;
gnix_ht_attr.ht_maximum_size =
ep_priv->domain->params.ct_max_size;
gnix_ht_attr.ht_increase_step = ep_priv->domain->params.ct_step;
gnix_ht_attr.ht_increase_type = GNIX_HT_INCREASE_MULT;
gnix_ht_attr.ht_collision_thresh = 500;
gnix_ht_attr.ht_hash_seed = 0xdeadbeefbeefdead;
gnix_ht_attr.ht_internal_locking = 0;
gnix_ht_attr.destructor = __gnix_vc_destroy_ht_entry;
ret = _gnix_ht_init(ep_priv->vc_ht, &gnix_ht_attr);
if (ret != FI_SUCCESS) {
GNIX_WARN(FI_LOG_EP_CTRL,
"_gnix_ht_init returned %s\n",
fi_strerror(-ret));
goto err;
}
}
dlist_init(&ep_priv->unmapped_vcs);
return FI_SUCCESS;
err:
if (ep_priv->av->type == FI_AV_TABLE) {
free(ep_priv->vc_table);
ep_priv->vc_table = NULL;
} else {
free(ep_priv->vc_ht);
ep_priv->vc_ht = NULL;
}
return ret;
}
static inline int __gnix_ep_fini_vc(struct gnix_fid_ep *ep)
{
int ret;
GNIX_VECTOR_ITERATOR(ep->vc_table, iter);
struct gnix_vc *vc;
/* Free unmapped VCs. */
dlist_for_each(&ep->unmapped_vcs, vc, list) {
_gnix_vc_destroy(vc);
}
if (!ep->av) {
/* No AV bound, no mapped VCs clean up. */
return FI_SUCCESS;
}
if (ep->av->type == FI_AV_TABLE) {
/* Destroy all VCs */
while ((vc = (struct gnix_vc *)
_gnix_vec_iterator_next(&iter))) {
_gnix_vec_remove_at(ep->vc_table,
GNIX_VECTOR_ITERATOR_IDX(iter));
_gnix_vc_destroy(vc);
}
/* Destroy vector storage */
ret = _gnix_vec_close(ep->vc_table);
if (ret == FI_SUCCESS) {
free(ep->vc_table);
ep->vc_table = NULL;
} else {
GNIX_WARN(FI_LOG_EP_CTRL,
"_gnix_vec_close returned %s\n",
fi_strerror(-ret));
}
} else {
/* Destroy VC storage, it automatically tears down VCs */
ret = _gnix_ht_destroy(ep->vc_ht);
if (ret == FI_SUCCESS) {
free(ep->vc_ht);
ep->vc_ht = NULL;
} else {
GNIX_WARN(FI_LOG_EP_CTRL,
"_gnix_ht_destroy returned %s\n",
fi_strerror(-ret));
}
}
return FI_SUCCESS;
}
/*******************************************************************************
* EP messaging API function implementations.
******************************************************************************/
DIRECT_FN STATIC ssize_t gnix_ep_recv(struct fid_ep *ep, void *buf, size_t len,
void *desc, fi_addr_t src_addr,
void *context)
{
return _ep_recv(ep, buf, len, desc, src_addr, context, 0, 0, 0);
}
DIRECT_FN STATIC ssize_t gnix_ep_recvv(struct fid_ep *ep,
const struct iovec *iov,
void **desc, size_t count,
fi_addr_t src_addr,
void *context)
{
return _ep_recvv(ep, iov, desc, count, src_addr, context, 0, 0, 0);
}
DIRECT_FN STATIC ssize_t gnix_ep_recvmsg(struct fid_ep *ep,
const struct fi_msg *msg,
uint64_t flags)
{
return _ep_recvmsg(ep, msg, flags & GNIX_RECVMSG_FLAGS, 0, 0);
}
DIRECT_FN STATIC ssize_t gnix_ep_send(struct fid_ep *ep, const void *buf,
size_t len, void *desc,
fi_addr_t dest_addr, void *context)
{
return _ep_send(ep, buf, len, desc, dest_addr, context, 0, 0);
}
DIRECT_FN STATIC ssize_t gnix_ep_sendv(struct fid_ep *ep,
const struct iovec *iov,
void **desc, size_t count,
fi_addr_t dest_addr,
void *context)
{
return _ep_sendv(ep, iov, desc, count, dest_addr, context, 0, 0);
}
DIRECT_FN STATIC ssize_t gnix_ep_sendmsg(struct fid_ep *ep,
const struct fi_msg *msg,
uint64_t flags)
{
return _ep_sendmsg(ep, msg, flags & GNIX_SENDMSG_FLAGS, 0);
}
DIRECT_FN STATIC ssize_t gnix_ep_msg_inject(struct fid_ep *ep, const void *buf,
size_t len, fi_addr_t dest_addr)
{
return _ep_inject(ep, buf, len, 0, dest_addr, 0, 0);
}
DIRECT_FN STATIC ssize_t gnix_ep_senddata(struct fid_ep *ep, const void *buf,
size_t len, void *desc, uint64_t data,
fi_addr_t dest_addr, void *context)
{
return _ep_senddata(ep, buf, len, desc, data, dest_addr, context, 0, 0);
}
DIRECT_FN STATIC ssize_t
gnix_ep_msg_injectdata(struct fid_ep *ep, const void *buf, size_t len,
uint64_t data, fi_addr_t dest_addr)
{
struct gnix_fid_ep *gnix_ep;
uint64_t flags;
if (!ep) {
return -FI_EINVAL;
}
gnix_ep = container_of(ep, struct gnix_fid_ep, ep_fid);
assert(GNIX_EP_RDM_DGM_MSG(gnix_ep->type));
flags = gnix_ep->op_flags | FI_INJECT | FI_REMOTE_CQ_DATA |
GNIX_SUPPRESS_COMPLETION;
return _gnix_send(gnix_ep, (uint64_t)buf, len, NULL, dest_addr,
NULL, flags, data, 0);
}
/*******************************************************************************
* EP RMA API function implementations.
******************************************************************************/
DIRECT_FN STATIC ssize_t gnix_ep_read(struct fid_ep *ep, void *buf, size_t len,
void *desc, fi_addr_t src_addr, uint64_t addr,
uint64_t key, void *context)
{
struct gnix_fid_ep *gnix_ep;
uint64_t flags;
if (!ep) {
return -FI_EINVAL;
}
gnix_ep = container_of(ep, struct gnix_fid_ep, ep_fid);
assert(GNIX_EP_RDM_DGM_MSG(gnix_ep->type));
flags = gnix_ep->op_flags | GNIX_RMA_READ_FLAGS_DEF;
return _gnix_rma(gnix_ep, GNIX_FAB_RQ_RDMA_READ,
(uint64_t)buf, len, desc,
src_addr, addr, key,
context, flags, 0);
}
DIRECT_FN STATIC ssize_t
gnix_ep_readv(struct fid_ep *ep, const struct iovec *iov, void **desc,
size_t count, fi_addr_t src_addr, uint64_t addr, uint64_t key,
void *context)
{
struct gnix_fid_ep *gnix_ep;
uint64_t flags;
if (!ep || !iov || !desc || count > GNIX_MAX_RMA_IOV_LIMIT) {
return -FI_EINVAL;
}
gnix_ep = container_of(ep, struct gnix_fid_ep, ep_fid);
assert(GNIX_EP_RDM_DGM_MSG(gnix_ep->type));
flags = gnix_ep->op_flags | GNIX_RMA_READ_FLAGS_DEF;
return _gnix_rma(gnix_ep, GNIX_FAB_RQ_RDMA_READ,
(uint64_t)iov[0].iov_base, iov[0].iov_len, desc[0],
src_addr, addr, key,
context, flags, 0);
}
DIRECT_FN STATIC ssize_t
gnix_ep_readmsg(struct fid_ep *ep, const struct fi_msg_rma *msg, uint64_t flags)
{
struct gnix_fid_ep *gnix_ep;
if (!ep || !msg || !msg->msg_iov || !msg->rma_iov || !msg->desc ||
msg->iov_count != 1 || msg->rma_iov_count != 1 ||
msg->rma_iov[0].len > msg->msg_iov[0].iov_len) {
return -FI_EINVAL;
}
gnix_ep = container_of(ep, struct gnix_fid_ep, ep_fid);
assert(GNIX_EP_RDM_DGM_MSG(gnix_ep->type));
flags = (flags & GNIX_READMSG_FLAGS) | GNIX_RMA_READ_FLAGS_DEF;
return _gnix_rma(gnix_ep, GNIX_FAB_RQ_RDMA_READ,
(uint64_t)msg->msg_iov[0].iov_base,
msg->msg_iov[0].iov_len, msg->desc[0],
msg->addr, msg->rma_iov[0].addr, msg->rma_iov[0].key,
msg->context, flags, msg->data);
}
DIRECT_FN STATIC ssize_t
gnix_ep_write(struct fid_ep *ep, const void *buf, size_t len, void *desc,
fi_addr_t dest_addr, uint64_t addr, uint64_t key, void *context)
{
struct gnix_fid_ep *gnix_ep;
uint64_t flags;
if (!ep) {
return -FI_EINVAL;
}
gnix_ep = container_of(ep, struct gnix_fid_ep, ep_fid);
assert(GNIX_EP_RDM_DGM_MSG(gnix_ep->type));
flags = gnix_ep->op_flags | GNIX_RMA_WRITE_FLAGS_DEF;
return _gnix_rma(gnix_ep, GNIX_FAB_RQ_RDMA_WRITE,
(uint64_t)buf, len, desc, dest_addr, addr, key,
context, flags, 0);
}
DIRECT_FN STATIC ssize_t
gnix_ep_writev(struct fid_ep *ep, const struct iovec *iov, void **desc,
size_t count, fi_addr_t dest_addr, uint64_t addr, uint64_t key,
void *context)
{
struct gnix_fid_ep *gnix_ep;
uint64_t flags;
if (!ep || !iov || !desc || count > GNIX_MAX_RMA_IOV_LIMIT) {
return -FI_EINVAL;
}
gnix_ep = container_of(ep, struct gnix_fid_ep, ep_fid);
assert(GNIX_EP_RDM_DGM_MSG(gnix_ep->type));
flags = gnix_ep->op_flags | GNIX_RMA_WRITE_FLAGS_DEF;
return _gnix_rma(gnix_ep, GNIX_FAB_RQ_RDMA_WRITE,
(uint64_t)iov[0].iov_base, iov[0].iov_len, desc[0],
dest_addr, addr, key, context, flags, 0);
}
DIRECT_FN STATIC ssize_t gnix_ep_writemsg(struct fid_ep *ep, const struct fi_msg_rma *msg,
uint64_t flags)
{
struct gnix_fid_ep *gnix_ep;
if (!ep || !msg || !msg->msg_iov || !msg->rma_iov ||
msg->iov_count != 1 ||
msg->rma_iov_count > GNIX_MAX_RMA_IOV_LIMIT ||
msg->rma_iov[0].len > msg->msg_iov[0].iov_len) {
return -FI_EINVAL;
}
gnix_ep = container_of(ep, struct gnix_fid_ep, ep_fid);
assert(GNIX_EP_RDM_DGM_MSG(gnix_ep->type));
flags = (flags & GNIX_WRITEMSG_FLAGS) | GNIX_RMA_WRITE_FLAGS_DEF;
return _gnix_rma(gnix_ep, GNIX_FAB_RQ_RDMA_WRITE,
(uint64_t)msg->msg_iov[0].iov_base,
msg->msg_iov[0].iov_len, msg->desc ? msg->desc[0] : NULL,
msg->addr, msg->rma_iov[0].addr, msg->rma_iov[0].key,
msg->context, flags, msg->data);
}
DIRECT_FN STATIC ssize_t gnix_ep_rma_inject(struct fid_ep *ep, const void *buf,
size_t len, fi_addr_t dest_addr,
uint64_t addr, uint64_t key)
{
struct gnix_fid_ep *gnix_ep;
uint64_t flags;
if (!ep) {
return -FI_EINVAL;
}
gnix_ep = container_of(ep, struct gnix_fid_ep, ep_fid);
assert(GNIX_EP_RDM_DGM_MSG(gnix_ep->type));
flags = gnix_ep->op_flags | FI_INJECT | GNIX_SUPPRESS_COMPLETION |
GNIX_RMA_WRITE_FLAGS_DEF;
return _gnix_rma(gnix_ep, GNIX_FAB_RQ_RDMA_WRITE,
(uint64_t)buf, len, NULL,
dest_addr, addr, key,
NULL, flags, 0);
}
DIRECT_FN STATIC ssize_t
gnix_ep_writedata(struct fid_ep *ep, const void *buf, size_t len, void *desc,
uint64_t data, fi_addr_t dest_addr, uint64_t addr,
uint64_t key, void *context)
{
struct gnix_fid_ep *gnix_ep;
uint64_t flags;
if (!ep) {
return -FI_EINVAL;
}
gnix_ep = container_of(ep, struct gnix_fid_ep, ep_fid);
assert(GNIX_EP_RDM_DGM_MSG(gnix_ep->type));
flags = gnix_ep->op_flags | FI_REMOTE_CQ_DATA |
GNIX_RMA_WRITE_FLAGS_DEF;
return _gnix_rma(gnix_ep, GNIX_FAB_RQ_RDMA_WRITE,
(uint64_t)buf, len, desc,
dest_addr, addr, key,
context, flags, data);
}
DIRECT_FN STATIC ssize_t
gnix_ep_rma_injectdata(struct fid_ep *ep, const void *buf, size_t len,
uint64_t data, fi_addr_t dest_addr, uint64_t addr,
uint64_t key)
{
struct gnix_fid_ep *gnix_ep;
uint64_t flags;
if (!ep) {
return -FI_EINVAL;
}
gnix_ep = container_of(ep, struct gnix_fid_ep, ep_fid);
assert(GNIX_EP_RDM_DGM_MSG(gnix_ep->type));
flags = gnix_ep->op_flags | FI_INJECT | FI_REMOTE_CQ_DATA |
GNIX_SUPPRESS_COMPLETION | GNIX_RMA_WRITE_FLAGS_DEF;
return _gnix_rma(gnix_ep, GNIX_FAB_RQ_RDMA_WRITE,
(uint64_t)buf, len, NULL,
dest_addr, addr, key,
NULL, flags, data);
}
/*******************************************************************************
* EP Tag matching API function implementations.
******************************************************************************/
DIRECT_FN STATIC ssize_t gnix_ep_trecv(struct fid_ep *ep, void *buf, size_t len,
void *desc, fi_addr_t src_addr,
uint64_t tag, uint64_t ignore,
void *context)
{
return _ep_recv(ep, buf, len, desc, src_addr, context,
FI_TAGGED, tag, ignore);
}
DIRECT_FN STATIC ssize_t gnix_ep_trecvv(struct fid_ep *ep,
const struct iovec *iov,
void **desc, size_t count,
fi_addr_t src_addr,
uint64_t tag, uint64_t ignore,
void *context)
{