File: osc_rdma_frag.h

package info (click to toggle)
openmpi 5.0.7-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, 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 (103 lines) | stat: -rw-r--r-- 3,411 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
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
/*
 * Copyright (c) 2012      Sandia National Laboratories.  All rights reserved.
 * Copyright (c) 2014-2018 Los Alamos National Security, LLC. All rights
 *                         reserved.
 * Copyright (c) 2020      IBM Corporation.  All rights reserved.
 * Copyright (c) 2021      Google, LLC. All rights reserved.
 * $COPYRIGHT$
 *
 * Additional copyrights may follow
 *
 * $HEADER$
 */

#ifndef OSC_RDMA_FRAG_H
#define OSC_RDMA_FRAG_H

#include "osc_rdma.h"
#include "opal/align.h"

static inline void ompi_osc_rdma_frag_complete (ompi_osc_rdma_frag_t *frag)
{
    OSC_RDMA_VERBOSE(MCA_BASE_VERBOSE_INFO, "returning frag. pending = %d", frag->pending);
    if (0 == OPAL_THREAD_ADD_FETCH32(&frag->pending, -1)) {
        opal_atomic_rmb ();

        (void) opal_atomic_swap_32 (&frag->pending, 1);
        (void) opal_atomic_swap_64 (&frag->curr_index, 0);
    }
}

/*
 * Note: module lock must be held during this operation
 */
static inline int ompi_osc_rdma_frag_alloc (ompi_osc_rdma_module_t *module, size_t request_len,
                                            ompi_osc_rdma_frag_t **buffer, char **ptr)
{
    ompi_osc_rdma_frag_t *curr = module->rdma_frag;
    int64_t my_index;
    int ret;

    /* ensure all buffers are 8-byte aligned */
    request_len = OPAL_ALIGN(request_len, 8, size_t);

    if (request_len > (mca_osc_rdma_component.buffer_size >> 1)) {
        return OMPI_ERR_VALUE_OUT_OF_BOUNDS;
    }

    if (NULL == curr) {
        opal_free_list_item_t *item = NULL;
        void *_tmp_ptr = NULL;

        item = opal_free_list_get (&mca_osc_rdma_component.frags);
        if (OPAL_UNLIKELY(NULL == item)) {
            OPAL_THREAD_UNLOCK(&module->lock);
            return OMPI_ERR_OUT_OF_RESOURCE;
        }

        curr = (ompi_osc_rdma_frag_t *) item;

        curr->handle = NULL;
        curr->pending = 1;
        curr->module = module;
        curr->curr_index = 0;

        if (module->use_memory_registration) {
            ret = ompi_osc_rdma_register (module, MCA_BTL_ENDPOINT_ANY, curr->super.ptr, mca_osc_rdma_component.buffer_size,
                                          MCA_BTL_REG_FLAG_ACCESS_ANY, &curr->handle);
            if (OPAL_UNLIKELY(OMPI_SUCCESS != ret)) {
                return OMPI_ERR_OUT_OF_RESOURCE;
            }
        }

        if (!opal_atomic_compare_exchange_strong_ptr ((opal_atomic_intptr_t *) &module->rdma_frag, (intptr_t *) &_tmp_ptr, (intptr_t) curr)) {
            ompi_osc_rdma_deregister (module, curr->handle);
            curr->handle = NULL;

            opal_free_list_return (&mca_osc_rdma_component.frags, &curr->super);

            curr = module->rdma_frag;
        }
    }

    OSC_RDMA_VERBOSE(MCA_BASE_VERBOSE_INFO, "allocating frag. pending = %d", curr->pending);
    OPAL_THREAD_ADD_FETCH32(&curr->pending, 1);

    my_index = opal_atomic_fetch_add_64 (&curr->curr_index, request_len);
    if (my_index + request_len > mca_osc_rdma_component.buffer_size) {
        if (my_index <= mca_osc_rdma_component.buffer_size) {
            /* this thread caused the buffer to spill over */
            ompi_osc_rdma_frag_complete (curr);
        }
        ompi_osc_rdma_frag_complete (curr);
        return OPAL_ERR_OUT_OF_RESOURCE;
    }

    *ptr = (void *) ((intptr_t) curr->super.ptr + my_index);
    *buffer = curr;

    return OMPI_SUCCESS;
}

#endif