File: btl_gm.c

package info (click to toggle)
openmpi 1.4.5-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 60,812 kB
  • sloc: ansic: 307,904; sh: 39,104; cpp: 19,228; makefile: 8,573; asm: 3,627; lex: 901; perl: 362; yacc: 275; csh: 188; fortran: 175; f90: 126; tcl: 12
file content (987 lines) | stat: -rw-r--r-- 30,187 bytes parent folder | download | duplicates (2)
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
/*
 * Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
 *                         University Research and Technology
 *                         Corporation.  All rights reserved.
 * Copyright (c) 2004-2008 The University of Tennessee and The University
 *                         of Tennessee Research Foundation.  All rights
 *                         reserved.
 * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, 
 *                         University of Stuttgart.  All rights reserved.
 * Copyright (c) 2004-2005 The Regents of the University of California.
 *                         All rights reserved.
 * Copyright (c) 2006-2009 Myricom, Inc.  All rights reserved.
 * $COPYRIGHT$
 * 
 * Additional copyrights may follow
 * 
 * $HEADER$
 */

#include "ompi_config.h"
#include <string.h>
#include "orte/util/show_help.h"
#include "opal/util/if.h"
#include "ompi/mca/pml/pml.h"
#include "ompi/mca/btl/btl.h"

#include "btl_gm.h"
#include "btl_gm_frag.h" 
#include "btl_gm_proc.h"
#include "btl_gm_endpoint.h"
#include "ompi/datatype/convertor.h" 
#include "ompi/datatype/datatype.h" 
#include "ompi/mca/mpool/base/base.h" 
#include "ompi/mca/mpool/mpool.h" 
#include "ompi/proc/proc.h"


/**
 * Non-locking versions of public interfaces.
 */

static int mca_btl_gm_send_nl( 
    struct mca_btl_base_module_t* btl,
    struct mca_btl_base_endpoint_t* endpoint,
    struct mca_btl_base_descriptor_t* des, 
    mca_btl_base_tag_t tag);

static int mca_btl_gm_get_nl( 
    mca_btl_base_module_t* btl,
    mca_btl_base_endpoint_t* endpoint,
    mca_btl_base_descriptor_t* des);

static int mca_btl_gm_put_nl( 
    mca_btl_base_module_t* btl,
    mca_btl_base_endpoint_t* endpoint,
    mca_btl_base_descriptor_t* des);


mca_btl_gm_module_t mca_btl_gm_module = {
    {
        &mca_btl_gm_component.super,
        0, /* max size of first fragment */
        0, /* min send fragment size */
        0, /* max send fragment size */
        0, /* btl_rdma_pipeline_send_length */
        0, /* btl_rdma_pipeline_frag_size */
        0, /* btl_min_rdma_pipeline_size */
        0, /* exclusivity */
        0, /* latency */
        0, /* bandwidth */
        0, /* flags */
        mca_btl_gm_add_procs,
        mca_btl_gm_del_procs,
        NULL, 
        mca_btl_gm_finalize,
        mca_btl_gm_alloc, 
        mca_btl_gm_free, 
        mca_btl_gm_prepare_src,
        mca_btl_gm_prepare_dst,
#if OMPI_ENABLE_MPI_THREADS || OMPI_ENABLE_PROGRESS_THREADS
        mca_btl_gm_send,
        NULL, /* send immediate */
        mca_btl_gm_put,
        mca_btl_gm_get,
#else
        mca_btl_gm_send_nl,
        NULL, /* send immediate */
        mca_btl_gm_put_nl,
        mca_btl_gm_get_nl,
#endif
        mca_btl_base_dump,
        NULL, /* mpool */
        mca_btl_gm_register_error_cb,
        mca_btl_gm_ft_event
    }
};


/**
 *
 */

int mca_btl_gm_add_procs(
    struct mca_btl_base_module_t* btl, 
    size_t nprocs, 
    struct ompi_proc_t **ompi_procs, 
    struct mca_btl_base_endpoint_t** peers, 
    ompi_bitmap_t* reachable)
{
    mca_btl_gm_module_t* gm_btl = (mca_btl_gm_module_t*)btl;
    int i, rc;

    for(i = 0; i < (int) nprocs; i++) {

        struct ompi_proc_t* ompi_proc = ompi_procs[i];
        mca_btl_gm_proc_t* gm_proc;
        mca_btl_base_endpoint_t* gm_endpoint;

        if(ompi_proc == ompi_proc_local()) 
            continue;

        if(NULL == (gm_proc = mca_btl_gm_proc_create(ompi_proc))) {
            continue;
        }

        /*
         * Check to make sure that the peer has at least as many interface 
         * addresses exported as we are trying to use. If not, then 
         * don't bind this PTL instance to the proc.
         */

        OPAL_THREAD_LOCK(&gm_proc->proc_lock);

        /* The btl_proc datastructure is shared by all GM PTL
         * instances that are trying to reach this destination. 
         * Cache the peer instance on the btl_proc.
         */
        gm_endpoint = OBJ_NEW(mca_btl_gm_endpoint_t);
        if(NULL == gm_endpoint) {
            OPAL_THREAD_UNLOCK(&gm_proc->proc_lock);
            return OMPI_ERR_OUT_OF_RESOURCE;
        }

        gm_endpoint->endpoint_btl = gm_btl;
        rc = mca_btl_gm_proc_insert(gm_proc, gm_endpoint);
        if(rc != OMPI_SUCCESS) {
            OBJ_RELEASE(gm_endpoint);
            OPAL_THREAD_UNLOCK(&gm_proc->proc_lock);
            continue;
        }
        ompi_bitmap_set_bit(reachable, i);
        OPAL_THREAD_UNLOCK(&gm_proc->proc_lock);
        peers[i] = gm_endpoint;
    }
    return OMPI_SUCCESS;
}

int mca_btl_gm_del_procs(struct mca_btl_base_module_t* btl, 
        size_t nprocs, 
        struct ompi_proc_t **procs, 
        struct mca_btl_base_endpoint_t ** peers)
{
    /* TODO */
    return OMPI_SUCCESS;
}

/* 
 *Register callback function for error handling..
 */ 
int mca_btl_gm_register_error_cb(
                        struct mca_btl_base_module_t* btl, 
                        mca_btl_base_module_error_cb_fn_t cbfunc)
{
    
    mca_btl_gm_module_t* gm_btl = (mca_btl_gm_module_t*) btl; 
    gm_btl->error_cb = cbfunc; /* stash for later */
    return OMPI_SUCCESS;
}

/**
 * Allocate a segment.
 *
 * @param btl (IN)      BTL module
 * @param size (IN)     Request segment size.
 */

mca_btl_base_descriptor_t* mca_btl_gm_alloc(
    struct mca_btl_base_module_t* btl,
    struct mca_btl_base_endpoint_t* endpoint,
    uint8_t order,
    size_t size,
    uint32_t flags)
{
    mca_btl_gm_module_t* gm_btl = (mca_btl_gm_module_t*) btl; 
    mca_btl_gm_frag_t* frag;
    int rc;
    
    if(size <= btl->btl_eager_limit) { 
        MCA_BTL_GM_FRAG_ALLOC_EAGER(gm_btl, frag, rc); 
        if(NULL == frag) { 
            return NULL;
        }
        frag->type=MCA_BTL_GM_EAGER;
        frag->segment.seg_len = size;
        
    } else if(size <=  btl->btl_max_send_size) { 
        MCA_BTL_GM_FRAG_ALLOC_MAX(gm_btl, frag, rc); 
        if(NULL == frag) { 
            return NULL;
        }
        frag->type=MCA_BTL_GM_SEND;
        frag->segment.seg_len = size; 
    } else { 
        return NULL;
    }
    
    frag->base.des_src = &frag->segment;
    frag->base.des_src_cnt = 1;
    frag->base.des_dst = NULL;
    frag->base.des_dst_cnt = 0;
    frag->base.des_flags = flags; 
    frag->base.order = MCA_BTL_NO_ORDER;
    return &frag->base;
}


/**
 * Return a segment
 */

int mca_btl_gm_free( struct mca_btl_base_module_t* btl, 
		     mca_btl_base_descriptor_t* des )
{
    mca_btl_gm_frag_t* frag = (mca_btl_gm_frag_t*)des;

    if( NULL != frag->registration ) {
        btl->btl_mpool->mpool_deregister(btl->btl_mpool, (mca_mpool_base_registration_t*) frag->registration);
        frag->registration = NULL;
    }

    MCA_BTL_GM_FRAG_RETURN(btl, frag); 
    return OMPI_SUCCESS; 
}

/**
 * Pack data and return a descriptor that can be
 * used for send/put.
 *
 * @param btl (IN)      BTL module
 * @param peer (IN)     BTL peer addressing
 */
mca_btl_base_descriptor_t* mca_btl_gm_prepare_src(
    struct mca_btl_base_module_t* btl,
    struct mca_btl_base_endpoint_t* endpoint,
    struct mca_mpool_base_registration_t* registration,
    struct ompi_convertor_t* convertor,
    uint8_t order,
    size_t reserve,
    size_t* size,
    uint32_t flags
)
{
    mca_btl_gm_frag_t *frag = NULL;
    struct iovec iov;
    uint32_t iov_count = 1;
    size_t max_data = *size;
    int rc;

#if (OMPI_MCA_BTL_GM_HAVE_RDMA_GET || OMPI_MCA_BTL_GM_HAVE_RDMA_PUT)
    if(ompi_convertor_need_buffers(convertor) == false && 0 == reserve) {
        if(registration != NULL || max_data > btl->btl_max_send_size) {
            MCA_BTL_GM_FRAG_ALLOC_USER(btl, frag, rc);
            if(NULL == frag) {
                return NULL;
            }

            /*
             * just assign it something..
             * we will assign the real value in put/get
             */
            frag->type = MCA_BTL_GM_PUT;
            iov.iov_len = max_data;
            iov.iov_base = NULL;


            ompi_convertor_pack(convertor, &iov, &iov_count, &max_data);

            *size = max_data;

            if(NULL == registration) {
                rc = btl->btl_mpool->mpool_register(btl->btl_mpool,
                        iov.iov_base, max_data, 0, &registration);
                if(OMPI_SUCCESS != rc || NULL == registration) {
                    MCA_BTL_GM_FRAG_RETURN(btl, frag);
                    return NULL;
                }
                /* keep track of the registration we did */
                frag->registration = registration;
            }

            frag->segment.seg_len = max_data;
            frag->segment.seg_addr.pval = iov.iov_base;

            frag->base.des_src     = &frag->segment;
            frag->base.des_src_cnt = 1;
            frag->base.des_dst     = NULL;
            frag->base.des_dst_cnt = 0;
            frag->base.des_flags   = flags;
            frag->base.order       = MCA_BTL_NO_ORDER;

            return &frag->base;
        }
    }
#endif

    if (max_data + reserve <= btl->btl_eager_limit) {
        /* the data is small enough to fit in the eager frag and
         * memory is not prepinned */
        MCA_BTL_GM_FRAG_ALLOC_EAGER(btl, frag, rc);
        if(frag != NULL) {
            frag->type = MCA_BTL_GM_EAGER;
        }
    }

    if(NULL == frag) {
        /* the data doesn't fit into eager frag or eger frag is
         * not available */
        MCA_BTL_GM_FRAG_ALLOC_MAX(btl, frag, rc);
        if(NULL == frag) {
            return NULL;
        }
        frag->type = MCA_BTL_GM_SEND;
        if(max_data + reserve > btl->btl_max_send_size) {
            max_data = btl->btl_max_send_size - reserve;
        }
    }

    iov.iov_len = max_data;
    iov.iov_base = (unsigned char*) frag->segment.seg_addr.pval + reserve;
    rc = ompi_convertor_pack(convertor, &iov, &iov_count, &max_data);
    if(rc < 0) {
        MCA_BTL_GM_FRAG_RETURN(btl, frag);
        return NULL;
    }
    *size  = max_data;
    frag->segment.seg_len  = max_data + reserve;
    frag->base.des_src     = &frag->segment;
    frag->base.des_src_cnt = 1;
    frag->base.des_dst     = NULL;
    frag->base.des_dst_cnt = 0;
    frag->base.des_flags   = flags;
    frag->base.order       = MCA_BTL_NO_ORDER;

    return &frag->base;
}


/**
 * Prepare a descriptor for send/rdma using the supplied
 * convertor. If the convertor references data that is contigous,
 * the descriptor may simply point to the user buffer. Otherwise,
 * this routine is responsible for allocating buffer space and
 * packing if required.
 *
 * @param btl (IN)          BTL module
 * @param endpoint (IN)     BTL peer addressing
 * @param convertor (IN)    Data type convertor
 * @param reserve (IN)      Additional bytes requested by upper layer to precede user data
 * @param size (IN/OUT)     Number of bytes to prepare (IN), number of bytes actually prepared (OUT)
 */

mca_btl_base_descriptor_t* mca_btl_gm_prepare_dst(
    struct mca_btl_base_module_t* btl,
    struct mca_btl_base_endpoint_t* endpoint,
    struct mca_mpool_base_registration_t* registration,
    struct ompi_convertor_t* convertor,
    uint8_t order,
    size_t reserve,
    size_t* size,
    uint32_t flags)
{
#if (OMPI_MCA_BTL_GM_HAVE_RDMA_GET || OMPI_MCA_BTL_GM_HAVE_RDMA_PUT)
    mca_btl_gm_frag_t* frag;
    mca_mpool_base_module_t* mpool = btl->btl_mpool;
    int rc;

    MCA_BTL_GM_FRAG_ALLOC_USER(btl, frag, rc);
    if(NULL == frag) {
        return NULL;
    }
    
    /* 
     *  we don't know that this is for a PUT,
     *  but it doesn't matter.. they belong 
     *  on the same list eventually anyway
     */      
    frag->type = MCA_BTL_GM_PUT; 
    
    frag->segment.seg_len = *size;
    ompi_convertor_get_current_pointer( convertor, (void**)&(frag->segment.seg_addr.pval) );

    frag->base.des_src = NULL;
    frag->base.des_src_cnt = 0;
    frag->base.des_dst = &frag->segment;
    frag->base.des_dst_cnt = 1;
    frag->base.des_flags = flags;
    frag->base.order = MCA_BTL_NO_ORDER;

    if(NULL == registration) {
        rc = mpool->mpool_register( mpool,
				    frag->segment.seg_addr.pval,
				    frag->segment.seg_len,
				    0,
				    &registration );
        if(rc != OMPI_SUCCESS) {
            MCA_BTL_GM_FRAG_RETURN(btl,frag);
            return NULL;
        }
        frag->registration = registration;
    }
    return &frag->base;
#else
    return NULL;
#endif
}


/**
 *
 */

static void mca_btl_gm_drop_callback( struct gm_port* port, void* context, gm_status_t status )
{
    mca_btl_gm_module_t* btl = (mca_btl_gm_module_t*)context;
    OPAL_THREAD_ADD32( &btl->gm_num_send_tokens, 1 );
}

/**
 * Callback on send completion and/or error.
 * Called with mca_btl_gm_component.gm_lock held.
 */

static void mca_btl_gm_send_callback( struct gm_port* port, void* context, gm_status_t status )
{
    mca_btl_gm_frag_t* frag = (mca_btl_gm_frag_t*)context;
    mca_btl_gm_module_t* btl = frag->btl;
    int btl_ownership = frag->base.des_flags & MCA_BTL_DES_FLAGS_BTL_OWNERSHIP;

    switch(status) {
        case GM_TRY_AGAIN:
        case GM_SEND_TIMED_OUT:
#if GM_API_VERSION > 0x200
        case GM_TIMED_OUT:
#endif
            /* drop all sends to this destination port */
            gm_drop_sends(
                btl->port,
                (frag->base.des_flags & MCA_BTL_DES_FLAGS_PRIORITY) ? GM_HIGH_PRIORITY : GM_LOW_PRIORITY,
                frag->endpoint->endpoint_addr.node_id,
                frag->endpoint->endpoint_addr.port_id,
                mca_btl_gm_drop_callback,
                btl
            );

            /* retry the failed fragment */
            mca_btl_gm_send_nl(&btl->super, frag->endpoint, &frag->base, frag->hdr->tag);
            break;
        case GM_SEND_DROPPED:
            /* release the send token */
            OPAL_THREAD_ADD32(&btl->gm_num_send_tokens, 1);

            /* retry the dropped fragment */
            mca_btl_gm_send_nl(&btl->super, frag->endpoint, &frag->base, frag->hdr->tag);
            break;
        case GM_SUCCESS:
            /* call the completion callback */
            OPAL_THREAD_UNLOCK(&mca_btl_gm_component.gm_lock);
            frag->base.des_cbfunc(&btl->super, frag->endpoint, &frag->base, OMPI_SUCCESS);
            OPAL_THREAD_LOCK(&mca_btl_gm_component.gm_lock);
            if( btl_ownership ) {
                mca_btl_gm_free(&btl->super, &frag->base);
            }
            /* return the send token and deque pending fragments */
            MCA_BTL_GM_RETURN_TOKEN(btl);
            break;
 
        default:
            /* error condition can't deal with */
            opal_output(0, "[%s:%d] send completed with unhandled gm error %d\n", __FILE__,__LINE__,status);

            /* release the send token */
            OPAL_THREAD_ADD32( &btl->gm_num_send_tokens, 1 );

            /* call the completion callback */
            OPAL_THREAD_UNLOCK(&mca_btl_gm_component.gm_lock);
            frag->base.des_cbfunc(&btl->super, frag->endpoint, &frag->base, OMPI_ERROR);
            OPAL_THREAD_LOCK(&mca_btl_gm_component.gm_lock);
            if( btl_ownership ) {
                mca_btl_gm_free(&btl->super, &frag->base);
            }
            break;
    }
}


/**
 * Initiate an asynchronous send. Do NOT acquire gm lock, must already be held,
 * or in an unthreaded environment.
 *
 * @param btl (IN)         BTL module
 * @param endpoint (IN)    BTL addressing information
 * @param descriptor (IN)  Description of the data to be transfered
 * @param tag (IN)         The tag value used to notify the peer.
 */


static int mca_btl_gm_send_nl( 
    struct mca_btl_base_module_t* btl,
    struct mca_btl_base_endpoint_t* endpoint,
    struct mca_btl_base_descriptor_t* des, 
    mca_btl_base_tag_t tag)
{
    mca_btl_gm_module_t* gm_btl = (mca_btl_gm_module_t*) btl;
    mca_btl_gm_frag_t* frag = (mca_btl_gm_frag_t*)des; 

    frag->btl = gm_btl;
    frag->endpoint = endpoint; 
    frag->hdr->tag = tag;

    /* queue the descriptor if there are no send tokens */
    MCA_BTL_GM_ACQUIRE_TOKEN_NL(gm_btl, frag);

    /* post the send descriptor */
    if(frag->base.des_flags & MCA_BTL_DES_FLAGS_PRIORITY &&  
       frag->size == mca_btl_gm_component.gm_eager_frag_size) {
        gm_send_with_callback( gm_btl->port,
			       frag->hdr,
			       mca_btl_gm_component.gm_eager_frag_size,
			       frag->segment.seg_len + sizeof(mca_btl_base_header_t),
			       GM_HIGH_PRIORITY,
			       endpoint->endpoint_addr.node_id,
			       endpoint->endpoint_addr.port_id,
			       mca_btl_gm_send_callback,
			       frag );
    } else {
        gm_send_with_callback( gm_btl->port,
			       frag->hdr,
			       mca_btl_gm_component.gm_max_frag_size,
			       frag->segment.seg_len + sizeof(mca_btl_base_header_t),
			       GM_LOW_PRIORITY,
			       endpoint->endpoint_addr.node_id,
			       endpoint->endpoint_addr.port_id,
			       mca_btl_gm_send_callback,
			       frag );
    }
    if(opal_list_get_size(&gm_btl->gm_repost)) {
        mca_btl_gm_frag_t* frag;
        while(NULL != (frag = (mca_btl_gm_frag_t*)opal_list_remove_first(&gm_btl->gm_repost))) {
            gm_provide_receive_buffer(gm_btl->port, frag->hdr, frag->size, frag->priority);
        }
    }

    return OMPI_SUCCESS;
}


/**
 * Initiate an asynchronous send.
 *
 * @param btl (IN)         BTL module
 * @param endpoint (IN)    BTL addressing information
 * @param descriptor (IN)  Description of the data to be transfered
 * @param tag (IN)         The tag value used to notify the peer.
 */

int mca_btl_gm_send( 
    struct mca_btl_base_module_t* btl,
    struct mca_btl_base_endpoint_t* endpoint,
    struct mca_btl_base_descriptor_t* des, 
    mca_btl_base_tag_t tag)
   
{
    mca_btl_gm_module_t* gm_btl = (mca_btl_gm_module_t*) btl;
    mca_btl_gm_frag_t* frag = (mca_btl_gm_frag_t*)des; 

    frag->btl = gm_btl;
    frag->endpoint = endpoint; 
    frag->hdr->tag = tag;
    
    /* queue the descriptor if there are no send tokens */
    OPAL_THREAD_LOCK(&mca_btl_gm_component.gm_lock);
    MCA_BTL_GM_ACQUIRE_TOKEN(gm_btl, frag);
    
    /* post the send descriptor */
    if(frag->base.des_flags & MCA_BTL_DES_FLAGS_PRIORITY &&  
       frag->size == mca_btl_gm_component.gm_eager_frag_size) {
        gm_send_with_callback( gm_btl->port,
			       frag->hdr,
			       mca_btl_gm_component.gm_eager_frag_size,
			       frag->segment.seg_len + sizeof(mca_btl_base_header_t),
			       GM_HIGH_PRIORITY,
			       endpoint->endpoint_addr.node_id,
			       endpoint->endpoint_addr.port_id,
			       mca_btl_gm_send_callback,
			       frag );
    } else {
        gm_send_with_callback( gm_btl->port,
			       frag->hdr,
			       mca_btl_gm_component.gm_max_frag_size,
			       frag->segment.seg_len + sizeof(mca_btl_base_header_t),
			       GM_LOW_PRIORITY,
			       endpoint->endpoint_addr.node_id,
			       endpoint->endpoint_addr.port_id,
			       mca_btl_gm_send_callback,
			       frag );
    }

    if(opal_list_get_size(&gm_btl->gm_repost)) {
        mca_btl_gm_frag_t* frag;
        while(NULL != (frag = (mca_btl_gm_frag_t*)opal_list_remove_first(&gm_btl->gm_repost))) {
            gm_provide_receive_buffer(gm_btl->port, frag->hdr, frag->size, frag->priority);
        }
    }
    OPAL_THREAD_UNLOCK(&mca_btl_gm_component.gm_lock);
    return OMPI_SUCCESS;
}



/**
 * Callback on put completion and/or error.
 * Called with mca_btl_gm_component.gm_lock held.
 */

static void mca_btl_gm_put_callback( struct gm_port* port, void* context, gm_status_t status )
{
    mca_btl_gm_frag_t* frag = (mca_btl_gm_frag_t*)context;
    mca_btl_gm_module_t* btl = frag->btl;
    int btl_ownership = frag->base.des_flags & MCA_BTL_DES_FLAGS_BTL_OWNERSHIP;

    /* call the completion callback */
    switch(status) {
        case GM_TRY_AGAIN:
        case GM_SEND_TIMED_OUT:
#if GM_API_VERSION > 0x200
        case GM_TIMED_OUT:
#endif
            /* drop all sends to this destination port */

            gm_drop_sends(
                btl->port,
                (frag->base.des_flags & MCA_BTL_DES_FLAGS_PRIORITY) ? GM_HIGH_PRIORITY : GM_LOW_PRIORITY,
                frag->endpoint->endpoint_addr.node_id,
                frag->endpoint->endpoint_addr.port_id,
                mca_btl_gm_drop_callback,
                btl
            );

            /* retry the failed fragment */
            mca_btl_gm_put_nl(&btl->super, frag->endpoint, &frag->base);
            break;
        case GM_SEND_DROPPED:
            /* release the send token */
            OPAL_THREAD_ADD32(&btl->gm_num_send_tokens, 1);

            /* retry the dropped fragment */
            mca_btl_gm_put_nl(&btl->super, frag->endpoint, &frag->base);
            break;
        case GM_SUCCESS:
            /* call completion callback */
            OPAL_THREAD_UNLOCK(&mca_btl_gm_component.gm_lock);
            frag->base.des_cbfunc(&btl->super, frag->endpoint, &frag->base, OMPI_SUCCESS);
            OPAL_THREAD_LOCK(&mca_btl_gm_component.gm_lock);
            if( btl_ownership ) {
                mca_btl_gm_free(&btl->super, &frag->base);
            }

            /* return the send token and deque pending fragments */
            MCA_BTL_GM_RETURN_TOKEN(btl);
            break;
        default:
            /* error condition can't deal with */
            opal_output(0, "[%s:%d] gm_put operation failed with status %d\n", __FILE__, __LINE__, status);

            /* release the send token */
            OPAL_THREAD_ADD32( &btl->gm_num_send_tokens, 1 );

            /* call the completion callback */
            OPAL_THREAD_UNLOCK(&mca_btl_gm_component.gm_lock);
            frag->base.des_cbfunc(&btl->super, frag->endpoint, &frag->base, OMPI_ERROR);
            OPAL_THREAD_LOCK(&mca_btl_gm_component.gm_lock);
            if( btl_ownership ) {
                mca_btl_gm_free(&btl->super, &frag->base);
            }
            break;
    }
}


/**
 * Initiate an asynchronous put. Do not acquire lock.
 *
 * @param btl (IN)         BTL module
 * @param endpoint (IN)    BTL addressing information
 * @param descriptor (IN)  Description of the data to be transferred
 */

static int mca_btl_gm_put_nl( 
    mca_btl_base_module_t* btl,
    mca_btl_base_endpoint_t* endpoint,
    mca_btl_base_descriptor_t* des)
{
#if OMPI_MCA_BTL_GM_HAVE_RDMA_PUT
    mca_btl_gm_module_t* gm_btl = (mca_btl_gm_module_t*) btl;
    mca_btl_gm_frag_t* frag = (mca_btl_gm_frag_t*) des; 

    frag->btl = gm_btl;
    frag->endpoint = endpoint;
    frag->type = MCA_BTL_GM_PUT;

    /* queue the descriptor if there are no send tokens */
    MCA_BTL_GM_ACQUIRE_TOKEN_NL(gm_btl, frag);

    /* post the put descriptor */
    gm_put(gm_btl->port,
        des->des_src->seg_addr.pval,
        des->des_dst->seg_addr.lval,
        des->des_src->seg_len,
        GM_LOW_PRIORITY,
        endpoint->endpoint_addr.node_id,
        endpoint->endpoint_addr.port_id,
        mca_btl_gm_put_callback,
        frag);
    return OMPI_SUCCESS; 
#else
    return OMPI_ERR_NOT_IMPLEMENTED;
#endif
}


/**
 * Initiate an asynchronous put.
 *
 * @param btl (IN)         BTL module
 * @param endpoint (IN)    BTL addressing information
 * @param descriptor (IN)  Description of the data to be transferred
 */

int mca_btl_gm_put( 
    mca_btl_base_module_t* btl,
    mca_btl_base_endpoint_t* endpoint,
    mca_btl_base_descriptor_t* des)
{
#if OMPI_MCA_BTL_GM_HAVE_RDMA_PUT
    mca_btl_gm_module_t* gm_btl = (mca_btl_gm_module_t*) btl;
    mca_btl_gm_frag_t* frag = (mca_btl_gm_frag_t*) des; 

    frag->btl = gm_btl;
    frag->endpoint = endpoint;
    frag->type = MCA_BTL_GM_PUT;

    /* queue the descriptor if there are no send tokens */
    OPAL_THREAD_LOCK(&mca_btl_gm_component.gm_lock);
    MCA_BTL_GM_ACQUIRE_TOKEN(gm_btl, frag);

    /* post the put descriptor */
    gm_put(gm_btl->port,
        des->des_src->seg_addr.pval,
        des->des_dst->seg_addr.lval,
        des->des_src->seg_len,
        GM_LOW_PRIORITY,
        endpoint->endpoint_addr.node_id,
        endpoint->endpoint_addr.port_id,
        mca_btl_gm_put_callback,
        frag);
    OPAL_THREAD_UNLOCK(&mca_btl_gm_component.gm_lock);
    return OMPI_SUCCESS; 
#else
    return OMPI_ERR_NOT_IMPLEMENTED;
#endif
}



/**
 * Callback on get completion and/or error. 
 * Called with mca_btl_gm_component.gm_lock held.
 */

static void mca_btl_gm_get_callback( struct gm_port* port, void* context, gm_status_t status )
{
    mca_btl_gm_frag_t* frag = (mca_btl_gm_frag_t*)context;
    mca_btl_gm_module_t* btl = frag->btl;
    int btl_ownership = frag->base.des_flags & MCA_BTL_DES_FLAGS_BTL_OWNERSHIP;

    /* call the completion callback */
    switch(status) {
        case GM_TRY_AGAIN:
        case GM_SEND_TIMED_OUT:
#if GM_API_VERSION > 0x200
        case GM_TIMED_OUT:
#endif
            /* drop all sends to this destination port */
            gm_drop_sends(
                btl->port,
                (frag->base.des_flags & MCA_BTL_DES_FLAGS_PRIORITY) ? GM_HIGH_PRIORITY : GM_LOW_PRIORITY,
                frag->endpoint->endpoint_addr.node_id,
                frag->endpoint->endpoint_addr.port_id,
                mca_btl_gm_drop_callback,
                btl
            );

            /* retry the failed fragment */
            mca_btl_gm_get_nl(&btl->super, frag->endpoint, &frag->base);
            break;
        case GM_SEND_DROPPED:
            /* release the send token */
            OPAL_THREAD_ADD32(&btl->gm_num_send_tokens, 1);

            /* retry the dropped fragment */
            mca_btl_gm_get_nl(&btl->super, frag->endpoint, &frag->base);
            break;
        case GM_SUCCESS:
            /* call completion callback */
            OPAL_THREAD_UNLOCK(&mca_btl_gm_component.gm_lock);
            frag->base.des_cbfunc(&btl->super, frag->endpoint, &frag->base, OMPI_SUCCESS);
            OPAL_THREAD_LOCK(&mca_btl_gm_component.gm_lock);
            if( btl_ownership ) {
                mca_btl_gm_free(&btl->super, &frag->base);
            }

            /* return the send token and deque pending fragments */
            MCA_BTL_GM_RETURN_TOKEN(btl);
            break;
        default:
            /* error condition can't deal with */
            opal_output(0, "[%s:%d] gm_get operation failed with status %d\n", __FILE__, __LINE__, status);

            /* release the send token */
            OPAL_THREAD_ADD32( &btl->gm_num_send_tokens, 1 );

            /* call the completion callback */
            OPAL_THREAD_UNLOCK(&mca_btl_gm_component.gm_lock);
            frag->base.des_cbfunc(&btl->super, frag->endpoint, &frag->base, OMPI_ERROR);
            OPAL_THREAD_LOCK(&mca_btl_gm_component.gm_lock);
            if( btl_ownership ) {
                mca_btl_gm_free(&btl->super, &frag->base);
            }
            break;
    }
}


/**
 * Initiate an asynchronous get. No locking.
 *
 * @param btl (IN)         BTL module
 * @param endpoint (IN)    BTL addressing information
 * @param descriptor (IN)  Description of the data to be transferred
 *
 */

static int mca_btl_gm_get_nl( 
    mca_btl_base_module_t* btl,
    mca_btl_base_endpoint_t* endpoint,
    mca_btl_base_descriptor_t* des)
{
#if OMPI_MCA_BTL_GM_HAVE_RDMA_GET
    mca_btl_gm_module_t* gm_btl = (mca_btl_gm_module_t*) btl;
    mca_btl_gm_frag_t* frag = (mca_btl_gm_frag_t*) des; 

    frag->btl = gm_btl;
    frag->endpoint = endpoint;
    frag->type = MCA_BTL_GM_GET;

    /* queue the descriptor if there are no send tokens */
    MCA_BTL_GM_ACQUIRE_TOKEN_NL(gm_btl, frag);

    /* post get put descriptor */
    gm_get(gm_btl->port,
        des->des_dst->seg_addr.lval,
        des->des_src->seg_addr.pval,
        des->des_src->seg_len,
        GM_LOW_PRIORITY,
        endpoint->endpoint_addr.node_id,
        endpoint->endpoint_addr.port_id,
        mca_btl_gm_get_callback,
        frag);
    return OMPI_SUCCESS; 
#else
    return OMPI_ERR_NOT_IMPLEMENTED;
#endif
}


/**
 * Initiate an asynchronous get.
 *
 * @param btl (IN)         BTL module
 * @param endpoint (IN)    BTL addressing information
 * @param descriptor (IN)  Description of the data to be transferred
 *
 */

int mca_btl_gm_get( 
    mca_btl_base_module_t* btl,
    mca_btl_base_endpoint_t* endpoint,
    mca_btl_base_descriptor_t* des)
{
#if OMPI_MCA_BTL_GM_HAVE_RDMA_GET
    mca_btl_gm_module_t* gm_btl = (mca_btl_gm_module_t*) btl;
    mca_btl_gm_frag_t* frag = (mca_btl_gm_frag_t*) des; 

    frag->btl = gm_btl;
    frag->endpoint = endpoint;
    frag->type = MCA_BTL_GM_GET;

    /* queue the descriptor if there are no send tokens */
    OPAL_THREAD_LOCK(&mca_btl_gm_component.gm_lock);
    MCA_BTL_GM_ACQUIRE_TOKEN(gm_btl, frag);

    /* post get put descriptor */
    gm_get(gm_btl->port,
        des->des_dst->seg_addr.lval,
        des->des_src->seg_addr.pval,
        des->des_src->seg_len,
        GM_LOW_PRIORITY,
        endpoint->endpoint_addr.node_id,
        endpoint->endpoint_addr.port_id,
        mca_btl_gm_get_callback,
        frag);
    OPAL_THREAD_UNLOCK(&mca_btl_gm_component.gm_lock);
    return OMPI_SUCCESS; 
#else
    return OMPI_ERR_NOT_IMPLEMENTED;
#endif
}


/*
 * Cleanup/release module resources.
 */

#if OMPI_ENABLE_PROGRESS_THREADS
static void mca_btl_gm_alarm(void* arg) {}
#endif

int mca_btl_gm_finalize(struct mca_btl_base_module_t* btl)
{
    mca_btl_gm_module_t* gm_btl = (mca_btl_gm_module_t*) btl; 
#if OMPI_ENABLE_PROGRESS_THREADS
    gm_alarm_t alarm;
    OPAL_THREAD_LOCK(&mca_btl_gm_component.gm_lock);
    gm_btl->gm_progress = false;
    gm_initialize_alarm(&alarm);
    gm_set_alarm(gm_btl->port, &alarm, 10, mca_btl_gm_alarm, NULL);
    OPAL_THREAD_UNLOCK(&mca_btl_gm_component.gm_lock);
    opal_thread_join(&gm_btl->gm_thread, NULL);
#endif

    OBJ_DESTRUCT(&gm_btl->gm_frag_eager);
    OBJ_DESTRUCT(&gm_btl->gm_frag_max);
    OBJ_DESTRUCT(&gm_btl->gm_frag_user);
    gm_close(gm_btl->port);
    free(gm_btl);
    return OMPI_SUCCESS;
}

int mca_btl_gm_ft_event(int state) {
    if(OPAL_CRS_CHECKPOINT == state) {
        ;
    }
    else if(OPAL_CRS_CONTINUE == state) {
        ;
    }
    else if(OPAL_CRS_RESTART == state) {
        ;
    }
    else if(OPAL_CRS_TERM == state ) {
        ;
    }
    else {
        ;
    }

    return OMPI_SUCCESS;
}