File: btl_usnic_frag.c

package info (click to toggle)
openmpi 5.0.7-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 202,312 kB
  • sloc: ansic: 612,441; makefile: 42,495; sh: 11,230; javascript: 9,244; f90: 7,052; java: 6,404; perl: 5,154; python: 1,856; lex: 740; fortran: 61; cpp: 20; tcl: 12
file content (267 lines) | stat: -rw-r--r-- 9,637 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
/*
 * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
 *                         University Research and Technology
 *                         Corporation.  All rights reserved.
 * Copyright (c) 2004-2005 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      Sandia National Laboratories. All rights
 *                         reserved.
 * Copyright (c) 2013-2017 Cisco Systems, Inc.  All rights reserved.
 * $COPYRIGHT$
 *
 * Additional copyrights may follow
 *
 * $HEADER$
 */

#include "opal_config.h"

#include <string.h>

#include "btl_usnic.h"
#include "btl_usnic_ack.h"
#include "btl_usnic_endpoint.h"
#include "btl_usnic_frag.h"
#include "btl_usnic_module.h"

static void common_send_seg_helper(opal_btl_usnic_send_segment_t *seg)
{
    opal_btl_usnic_segment_t *bseg;

    /* send ptr for fi_send().  ss_len will be filled in right before
       the actual send. */
    seg->ss_ptr = (uint8_t *) seg->ss_base.us_list.ptr;
    seg->ss_send_posted = 0;
    seg->ss_ack_pending = false;

    /* Offset the BTL header by (prefix_send_offset) bytes into the
       raw buffer */
    bseg = &seg->ss_base;
    bseg->us_btl_header = (opal_btl_usnic_btl_header_t
                               *) (seg->ss_ptr + mca_btl_usnic_component.prefix_send_offset);
    bseg->us_btl_header->sender = mca_btl_usnic_component.my_hashed_rte_name;
}

static void chunk_seg_constructor(opal_btl_usnic_chunk_segment_t *cseg)
{
    opal_btl_usnic_segment_t *bseg;

    bseg = &cseg->ss_base;
    bseg->us_type = OPAL_BTL_USNIC_SEG_CHUNK;

    /* some more common initialization */
    common_send_seg_helper(cseg);

    /* payload starts next byte beyond BTL chunk header */
    bseg->us_payload.raw = (uint8_t *) (bseg->us_btl_chunk_header + 1);

    bseg->us_btl_header->payload_type = OPAL_BTL_USNIC_PAYLOAD_TYPE_CHUNK;
}

static void frag_seg_constructor(opal_btl_usnic_frag_segment_t *fseg)
{
    opal_btl_usnic_segment_t *bseg;

    bseg = &fseg->ss_base;
    bseg->us_type = OPAL_BTL_USNIC_SEG_FRAG;

    /* some more common initialization */
    common_send_seg_helper(fseg);

    /* payload starts next byte beyond BTL header */
    bseg->us_payload.raw = (uint8_t *) (bseg->us_btl_header + 1);

    bseg->us_btl_header->payload_type = OPAL_BTL_USNIC_PAYLOAD_TYPE_FRAG;
}

static void ack_seg_constructor(opal_btl_usnic_ack_segment_t *ack)
{
    opal_btl_usnic_segment_t *bseg;

    bseg = &ack->ss_base;
    bseg->us_type = OPAL_BTL_USNIC_SEG_ACK;

    /* some more common initialization */
    common_send_seg_helper(ack);

    /* ACK value embedded in BTL header */
    bseg->us_btl_header->payload_type = OPAL_BTL_USNIC_PAYLOAD_TYPE_ACK;
    bseg->us_btl_header->payload_len = 0;
    bseg->us_btl_header->ack_present = 1;

    ack->ss_len = sizeof(bseg->us_btl_header);
}

static void recv_seg_constructor(opal_btl_usnic_recv_segment_t *seg)
{
    opal_btl_usnic_segment_t *bseg;

    bseg = &seg->rs_base;
    bseg->us_type = OPAL_BTL_USNIC_SEG_RECV;

    /* on receive, BTL header starts after protocol header */
    seg->rs_protocol_header = bseg->us_list.ptr;
    bseg->us_btl_header = (opal_btl_usnic_btl_header_t *) (((char *) seg->rs_protocol_header)
                                                           + mca_btl_usnic_component
                                                                 .transport_header_len);

    /* initialize descriptor */
    /* JMS Initializing RECV_REMOTE for receive frags is unnecessary
       with BTL 3.0.  The only reason to keep this here would be for
       compatibility with the BTL 2.0 usnic-v1.8 git branch (i.e.,
       it's harmless to do this assignment first, before the
       RECV_LOCAL assignments -- the compiler will likely compile out
       this dead code, anyway). */
    seg->rs_desc.USNIC_RECV_REMOTE = NULL;
    seg->rs_desc.USNIC_RECV_REMOTE_COUNT = 0;

    seg->rs_desc.USNIC_RECV_LOCAL = &seg->rs_segment;
    seg->rs_desc.USNIC_RECV_LOCAL_COUNT = 1;

    /*
     * This pointer is only correct for incoming segments of type
     * OPAL_BTL_USNIC_PAYLOAD_TYPE_FRAG, but that's the only time
     * we ever give segment directly to upper layer, so its OK
     */
    bseg->us_payload.ompi_header = (mca_btl_base_header_t *) (bseg->us_btl_header + 1);
    seg->rs_segment.seg_addr.pval = bseg->us_payload.ompi_header;
}

static void send_frag_constructor(opal_btl_usnic_send_frag_t *frag)
{
    mca_btl_base_descriptor_t *desc;

    /* Fill in source descriptor */
    desc = &frag->sf_base.uf_base;

    /* JMS Initializing SEND_REMOTE for receive frags is unnecessary
       with BTL 3.0.  The only reason to keep this here would be for
       compatibility with the BTL 2.0 usnic-v1.8 git branch (i.e.,
       it's harmless to do this assignment first, before the
       SEND_LOCAL assignments -- the compiler will likely compile out
       this dead code, anyway). */
    desc->USNIC_SEND_REMOTE = frag->sf_base.uf_remote_seg;
    desc->USNIC_SEND_REMOTE_COUNT = 0;

    desc->USNIC_SEND_LOCAL = frag->sf_base.uf_local_seg;
    frag->sf_base.uf_local_seg[0].seg_len = 0;
    frag->sf_base.uf_local_seg[1].seg_len = 0;
    desc->USNIC_SEND_LOCAL_COUNT = 2;

    desc->order = MCA_BTL_NO_ORDER;
    desc->des_flags = 0;

    OBJ_CONSTRUCT(&frag->sf_convertor, opal_convertor_t);
    frag->sf_seg_post_cnt = 0;
}

static void send_frag_destructor(opal_btl_usnic_send_frag_t *frag)
{
#if OPAL_ENABLE_DEBUG
    /* make sure nobody twiddled these values after the constructor */
    mca_btl_base_descriptor_t *desc;
    desc = &frag->sf_base.uf_base;
    assert(desc->USNIC_SEND_LOCAL == frag->sf_base.uf_local_seg);
    assert(0 == frag->sf_base.uf_local_seg[0].seg_len);
#endif

    /* PML may change desc->des_remote to point elsewhere, cannot assert that it
     * still points to our embedded segment */

    OBJ_DESTRUCT(&frag->sf_convertor);
}

static void small_send_frag_constructor(opal_btl_usnic_small_send_frag_t *frag)
{
    opal_btl_usnic_frag_segment_t *fseg;

    /* construct the embedded segment */
    fseg = &frag->ssf_segment;
    /* us_list.ptr is "input" to the constructor, must come before ctor */
    fseg->ss_base.us_list.ptr = frag->ssf_base.sf_base.uf_base.super.ptr;
    OBJ_CONSTRUCT(fseg, opal_btl_usnic_frag_segment_t);

    /* set us as parent in dedicated frag */
    fseg->ss_parent_frag = (struct opal_btl_usnic_send_frag_t *) frag;

    frag->ssf_base.sf_base.uf_type = OPAL_BTL_USNIC_FRAG_SMALL_SEND;

    /* save data pointer for PML */
    frag->ssf_base.sf_base.uf_local_seg[0].seg_addr.pval = fseg->ss_base.us_payload.raw;
}

static void small_send_frag_destructor(opal_btl_usnic_small_send_frag_t *frag)
{
    opal_btl_usnic_frag_segment_t *fseg;

    fseg = &frag->ssf_segment;
    assert(fseg->ss_parent_frag == (struct opal_btl_usnic_send_frag_t *) frag);
    assert(frag->ssf_base.sf_base.uf_type == OPAL_BTL_USNIC_FRAG_SMALL_SEND);
    assert(frag->ssf_base.sf_base.uf_local_seg[0].seg_addr.pval == fseg->ss_base.us_payload.raw);
    OBJ_DESTRUCT(fseg);
}

static void large_send_frag_constructor(opal_btl_usnic_large_send_frag_t *lfrag)
{
    lfrag->lsf_base.sf_base.uf_type = OPAL_BTL_USNIC_FRAG_LARGE_SEND;

    /* save data pointer for upper layer */
    lfrag->lsf_base.sf_base.uf_local_seg[0].seg_addr.pval = &lfrag->lsf_ompi_header;

    lfrag->lsf_buffer = NULL;
    OBJ_CONSTRUCT(&lfrag->lsf_seg_chain, opal_list_t);
    lfrag->lsf_pack_on_the_fly = false;
}

static void put_dest_frag_constructor(opal_btl_usnic_put_dest_frag_t *pfrag)
{
    pfrag->uf_type = OPAL_BTL_USNIC_FRAG_PUT_DEST;

    /* point dest to our utility segment */
    pfrag->uf_base.USNIC_PUT_LOCAL = pfrag->uf_remote_seg;
    pfrag->uf_base.USNIC_PUT_LOCAL_COUNT = 1;
}

static void put_dest_frag_destructor(opal_btl_usnic_put_dest_frag_t *pfrag)
{
    assert(pfrag->uf_base.USNIC_PUT_LOCAL == pfrag->uf_remote_seg);
    assert(1 == pfrag->uf_base.USNIC_PUT_LOCAL_COUNT);
}

OBJ_CLASS_INSTANCE(opal_btl_usnic_segment_t, opal_free_list_item_t, NULL, NULL);

OBJ_CLASS_INSTANCE(opal_btl_usnic_frag_segment_t, opal_btl_usnic_segment_t, frag_seg_constructor,
                   NULL);

OBJ_CLASS_INSTANCE(opal_btl_usnic_chunk_segment_t, opal_btl_usnic_segment_t, chunk_seg_constructor,
                   NULL);

OBJ_CLASS_INSTANCE(opal_btl_usnic_recv_segment_t, opal_btl_usnic_segment_t, recv_seg_constructor,
                   NULL);

OBJ_CLASS_INSTANCE(opal_btl_usnic_ack_segment_t, opal_btl_usnic_segment_t, ack_seg_constructor,
                   NULL);

/*
 * Fragments
 */
OBJ_CLASS_INSTANCE(opal_btl_usnic_frag_t, mca_btl_base_descriptor_t, NULL, NULL);

OBJ_CLASS_INSTANCE(opal_btl_usnic_send_frag_t, opal_btl_usnic_frag_t, send_frag_constructor,
                   send_frag_destructor);

OBJ_CLASS_INSTANCE(opal_btl_usnic_large_send_frag_t, opal_btl_usnic_send_frag_t,
                   large_send_frag_constructor, NULL);

OBJ_CLASS_INSTANCE(opal_btl_usnic_small_send_frag_t, opal_btl_usnic_send_frag_t,
                   small_send_frag_constructor, small_send_frag_destructor);

OBJ_CLASS_INSTANCE(opal_btl_usnic_put_dest_frag_t, opal_btl_usnic_frag_t, put_dest_frag_constructor,
                   put_dest_frag_destructor);

OBJ_CLASS_INSTANCE(opal_btl_usnic_rx_buf_t, opal_free_list_item_t, NULL, NULL);