1 /*
2 * Copyright (c) 2014 Mellanox Technologies, Inc.
3 * All rights reserved.
4 * $COPYRIGHT$
5 *
6 * Additional copyrights may follow
7 *
8 * $HEADER$
9 */
10
11 /**
12 * @file
13 *
14 * shmem (shared memory backing facility) framework types, convenience macros,
15 * etc.
16 */
17
18 #ifndef MCA_SSHMEM_TYPES_H
19 #define MCA_SSHMEM_TYPES_H
20
21 #include "oshmem_config.h"
22
23 BEGIN_C_DECLS
24
25 /**
26 * flag indicating the state (valid/invalid) of the sshmem data structure
27 * 0x0* - reserved for non-internal flags
28 */
29 #define MAP_SEGMENT_FLAGS_VALID 0x01
30
31 /**
32 * invalid id value
33 */
34 #define MAP_SEGMENT_SHM_INVALID (-1)
35
36 /**
37 * macro that sets all bits in flags to 0
38 */
39 #define MAP_SEGMENT_RESET_FLAGS(ds_buf) \
40 do { \
41 (ds_buf)->flags = 0x00; \
42 } while (0)
43
44 /**
45 * sets valid bit in flags to 1
46 */
47 #define MAP_SEGMENT_SET_VALID(ds_buf) \
48 do { \
49 (ds_buf)->flags |= MAP_SEGMENT_FLAGS_VALID; \
50 } while (0)
51
52 /**
53 * sets valid bit in flags to 0
54 */
55 #define MAP_SEGMENT_INVALIDATE(ds_buf) \
56 do { \
57 (ds_buf)->flags &= ~MAP_SEGMENT_FLAGS_VALID; \
58 } while (0)
59
60 /**
61 * evaluates to 1 if the valid bit in flags is set to 1. evaluates to 0
62 * otherwise.
63 */
64 #define MAP_SEGMENT_IS_VALID(ds_buf) \
65 ( (ds_buf)->flags & MAP_SEGMENT_FLAGS_VALID )
66
67 typedef uint8_t segment_flag_t;
68
69 typedef enum {
70 MAP_SEGMENT_STATIC = 0,
71 MAP_SEGMENT_ALLOC_MMAP,
72 MAP_SEGMENT_ALLOC_SHM,
73 MAP_SEGMENT_ALLOC_IBV,
74 MAP_SEGMENT_ALLOC_IBV_NOSHMR,
75 MAP_SEGMENT_ALLOC_UCX,
76 MAP_SEGMENT_UNKNOWN
77 } segment_type_t;
78
79 /**
80 * memory key
81 * There are following types of keys:
82 * 1. 'shared memory' keys. Memory segment must be attached before access
83 * such keys use va_base = 0, len = 0 and key != MAP_SEGMENT_SHM_INVALID
84 * va_base will be set once segment is attached.
85 * 2. empty key: len = 0, key == MAP_SEGMENT_SHM_INVALID
86 * 3. generic key: Key is passed with each put/get op.
87 * use va_base = <remote vaddr>, key is stored in mkey struct:
88 * len > 0, data = &<key_blob>
89 */
90 typedef struct sshmem_mkey {
91 void* va_base;
92 uint16_t len;
93 union {
94 void *data;
95 uint64_t key;
96 } u;
97 void *spml_context; /* spml module can attach internal structures here */
98 } sshmem_mkey_t;
99
100 typedef struct map_base_segment {
101 void *va_base; /* base address of the segment */
102 void *va_end; /* final address of the segment */
103 } map_base_segment_t;
104
105 typedef struct mkey_segment {
106 map_base_segment_t super;
107 void *rva_base; /* base va on remote pe */
108 } mkey_segment_t;
109
110 typedef struct segment_allocator segment_allocator_t;
111
112 typedef struct map_segment {
113 map_base_segment_t super;
114 sshmem_mkey_t **mkeys_cache; /* includes remote segment bases in va_base */
115 sshmem_mkey_t *mkeys; /* includes local segment bases in va_base */
116 segment_flag_t flags; /* enable/disable flag */
117 int seg_id;
118 size_t seg_size; /* length of the segment */
119 segment_type_t type; /* type of the segment */
120 long alloc_hints; /* allocation hints this segment supports */
121 void *context; /* allocator can use this field to store
122 its own private data */
123 segment_allocator_t *allocator; /* segment-specific allocator */
124 } map_segment_t;
125
126 struct segment_allocator {
127 int (*realloc)(map_segment_t*, size_t newsize, void *, void **);
128 int (*free)(map_segment_t*, void*);
129 };
130
131 END_C_DECLS
132
133 #endif /* MCA_SSHMEM_TYPES_H */