File: btl_usnic_util.h

package info (click to toggle)
openmpi 5.0.8-4
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 201,684 kB
  • sloc: ansic: 613,078; makefile: 42,353; sh: 11,194; javascript: 9,244; f90: 7,052; java: 6,404; perl: 5,179; python: 1,859; lex: 740; fortran: 61; cpp: 20; tcl: 12
file content (114 lines) | stat: -rw-r--r-- 2,821 bytes parent folder | download | duplicates (4)
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
/*
 * Copyright (c) 2013-2019 Cisco Systems, Inc.  All rights reserved
 * $COPYRIGHT$
 *
 * Additional copyrights may follow
 *
 * $HEADER$
 */

#ifndef BTL_USNIC_UTIL_H
#define BTL_USNIC_UTIL_H

#include "opal/datatype/opal_convertor.h"

#include "btl_usnic.h"

#ifndef MIN
#    define MIN(a, b) ((a) < (b) ? (a) : (b))
#endif

/*
 * Safely (but abnornmally) exit this process without abort()'ing (and
 * leaving a corefile).
 */
struct opal_btl_usnic_module_t;
void opal_btl_usnic_exit(struct opal_btl_usnic_module_t *module);

/*
 * Print a show_help message and then call opal_btl_usnic_exit().
 */
void opal_btl_usnic_util_abort(const char *msg, const char *file, int line);

/*
 * Long enough to hold "xxx.xxx.xxx.xxx/xx"
 */
#define IPV4STRADDRLEN 20

/*
 * If netmask==0, it is not included in the output string.  addr is
 * expected to be in network byte order.
 */
void opal_btl_usnic_snprintf_ipv4_addr(char *out, size_t maxlen, uint32_t addr_be,
                                       uint32_t netmask_be);

void opal_btl_usnic_snprintf_bool_array(char *s, size_t slen, bool a[], size_t alen);

void opal_btl_usnic_dump_hex(int verbose_level, int output_id, void *vaddr, int len);

size_t opal_btl_usnic_convertor_pack_peek(const opal_convertor_t *conv, size_t max_len);

/* avoid "defined but not used" warnings */
static inline int __opal_attribute_always_inline__ usnic_fls(int x) __opal_attribute_unused__;

static inline int __opal_attribute_always_inline__ usnic_fls(int x)
{
    int r = 32;

    if (!x) {
        return 0;
    }
    if (!(x & 0xffff0000u)) {
        x <<= 16;
        r -= 16;
    }
    if (!(x & 0xff000000u)) {
        x <<= 8;
        r -= 8;
    }
    if (!(x & 0xf0000000u)) {
        x <<= 4;
        r -= 4;
    }
    if (!(x & 0xc0000000u)) {
        x <<= 2;
        r -= 2;
    }
    if (!(x & 0x80000000u)) {
        r -= 1;
    }
    return r;
}

/* a helper function that just declutters convertor packing */
static inline void usnic_convertor_pack_simple(opal_convertor_t *convertor, void *dest,
                                               size_t max_bytes_to_pack, size_t *bytes_packed)
{
    int rc;
    struct iovec iov;
    uint32_t iov_count;

    iov.iov_base = (IOVBASE_TYPE *) dest;
    iov.iov_len = max_bytes_to_pack;
    iov_count = 1;
    *bytes_packed = max_bytes_to_pack;
    rc = opal_convertor_pack(convertor, &iov, &iov_count, bytes_packed);
    if (OPAL_UNLIKELY(rc < 0)) {
        opal_btl_usnic_util_abort("opal_convertor_pack error", __FILE__, __LINE__);
    }
}

static inline int usnic_netmask_to_cidrlen(uint32_t netmask_be)
{
    return 33 - ffs(ntohl(netmask_be));
}

static inline uint32_t usnic_cidrlen_to_netmask(int cidrlen)
{
    uint32_t mask;

    mask = ~0 << (32 - cidrlen);
    return htonl(mask);
}

#endif /* BTL_USNIC_UTIL_H */