Debian Codegraph @

armci/src/devices/openib/cbuf.h

raw symbols SCIP
1 /*
2 * Copyright (C) 1999-2001 The Regents of the University of California
3 * (through E.O. Lawrence Berkeley National Laboratory), subject to
4 * approval by the U.S. Department of Energy.
5 *
6 * Use of this software is under license. The license agreement is included
7 * in the file MVICH_LICENSE.TXT.
8 *
9 * Developed at Berkeley Lab as part of MVICH.
10 *
11 * Authors: Bill Saphir <[email protected]>
12 * Michael Welcome <[email protected]>
13 */
14
15 /* Copyright (c) 2002-2008, The Ohio State University. All rights
16 * reserved.
17 *
18 * This file is part of the MVAPICH software package developed by the
19 * team members of The Ohio State University's Network-Based Computing
20 * Laboratory (NBCL), headed by Professor Dhabaleswar K. (DK) Panda.
21 *
22 * For detailed copyright and licensing information, please refer to the
23 * copyright file COPYRIGHT_MVAPICH in the top level MPICH directory.
24 *
25 */
26
27
28 #ifndef _CBUF_H
29 #define _CBUF_H
30
31 #include <stdio.h>
32 #include <pthread.h>
33 #include <infiniband/verbs.h>
34 #include <malloc.h>
35 #include <string.h>
36
37 #define CBUF_FLAG_TYPE uint32_t
38
39 #if (defined(RDMA_FAST_PATH) || defined(ADAPTIVE_RDMA_FAST_PATH))
40
41 #define CBUF_BUFFER_SIZE (viadev_cbuf_total_size - \
42 2*sizeof(CBUF_FLAG_TYPE))
43
44 #else
45
46 #define CBUF_BUFFER_SIZE (viadev_cbuf_total_size)
47
48 #endif
49
50 /*
51 * brief justification for cbuf format:
52 * descriptor must be aligned (64 bytes).
53 * cbuf size must be multiple of this alignment to allow contiguous allocation
54 * descriptor and buffer should be contiguous to allow via implementations that
55 * optimize contiguous descriptor/data (? how likely ?)
56 * need to be able to store send handle in cbuf so that we can mark sends
57 * complete when communication completes. don't want to store
58 * it in packet header because we don't always need to send over the network.
59 * don't want to store at beginning or between desc and buffer (see above) so
60 * store at end.
61 */
62
63 #define QP_CON_REQ 1
64 #define QP_CON_ACK 2
65 #define QP_CON_BREAK_FROM_CLIENT 3
66 #define QP_CON_BREAK_FROM_SERVER 4
67
68 typedef struct {
69 uint32_t src_rank;
70 uint16_t lid;
71 uint32_t qpnum;
72 int msg_type;
73 } armci_ud_rank;
74
75 struct ibv_descriptor {
76 union {
77 struct ibv_recv_wr rr;
78 struct ibv_send_wr sr;
79 } u;
80 struct ibv_sge sg_entry;
81 void *next;
82 };
83
84 typedef struct ibv_descriptor IBV_DESCRIPTOR;
85
86 typedef struct cbuf {
87
88 #if (defined(RDMA_FAST_PATH) || defined(ADAPTIVE_RDMA_FAST_PATH))
89 CBUF_FLAG_TYPE *head_flag;
90 #endif
91
92 unsigned char *buffer;
93
94 #if (defined(RDMA_FAST_PATH) || defined(ADAPTIVE_RDMA_FAST_PATH))
95 int padding;
96 #endif
97
98 IBV_DESCRIPTOR desc;
99
100 /* NULL shandle means not send or not complete. Non-null
101 * means pointer to send handle that is now complete. Used
102 * by viadev_process_send
103 */
104 void *shandle;
105 struct cbuf_region *region;
106 int grank;
107
108 uint16_t bytes_remaining;
109 uint16_t len;
110 unsigned char *data_start;
111 uint16_t ref_count;
112
113 } cbuf;
114 /* one for head and one for tail */
115 #define CBUF_FAST_RDMA_EXTRA_BYTES (2*sizeof(CBUF_FLAG_TYPE))
116
117 #define FAST_RDMA_ALT_TAG 0x8000
118 #define FAST_RDMA_SIZE_MASK 0x7fff
119
120 /*
121 * Vbufs are allocated in blocks and threaded on a single free list.
122 *
123 * These data structures record information on all the cbuf
124 * regions that have been allocated. They can be used for
125 * error checking and to un-register and deallocate the regions
126 * at program termination.
127 *
128 */
129 typedef struct cbuf_region {
130 struct ibv_mr *mem_handle; /* memory handle for entire region */
131
132 void *malloc_start; /* used to free region later */
133 void *malloc_end; /* to bracket mem region */
134 void *malloc_buf_start; /* used to free DMA region later */
135 void *malloc_buf_end; /* bracket DMA region */
136 int count; /* number of cbufs in region */
137 struct cbuf *cbuf_head; /* first cbuf in region */
138 struct cbuf_region *next; /* thread cbuf regions */
139 } cbuf_region;
140
141 /* ack. needed here after cbuf is defined. need to clean up header files
142 * and dependencies.
143 */
144
145 typedef unsigned long aint_t;
146
147 extern int viadev_cbuf_max;
148 extern int viadev_cbuf_total_size;
149 extern int viadev_cbuf_secondary_pool_size;
150
151
152 void dump_cbuf_regions(void);
153 void dump_cbuf_region(cbuf_region * r);
154
155
156 void allocate_cbufs(int ncbufs);
157 void deallocate_cbufs(void);
158
159 cbuf *get_cbuf(void);
160 void release_cbuf(cbuf * v);
161 void cbuf_init_send(cbuf * v, unsigned long len);
162 void cbuf_init_recv(cbuf * v, unsigned long len);
163 void cbuf_init_sendrecv(cbuf * v, unsigned long len);
164
165 void cbuf_init_rput(cbuf * v,
166 void *local_address,
167 uint32_t local_memhandle,
168 void *remote_address,
169 uint32_t remote_memhandle_rkey, int nbytes);
170 void cbuf_init_rget(cbuf * v,
171 void *local_address,
172 uint32_t local_memhandle,
173 void *remote_address,
174 uint32_t remote_memhandle_rkey, int nbytes);
175
176 void init_cbuf_lock();
177
178 void dump_cbuf(char *msg, cbuf * v);
179
180 struct ibv_mr * armci_register_memory(void *, int);
181
182 /*
183 * Macros for working with cbufs
184 */
185
186 #define CBUF_BUFFER_START(v) (v->buffer)
187
188 #define CBUF_DATA_SIZE(type) (CBUF_BUFFER_SIZE - sizeof(type))
189
190 #endif /* _CBUF_H */