Debian Codegraph @

ptl_am/psm_am_internal.h

raw symbols SCIP
1 /*
2 * Copyright (c) 2013. Intel Corporation. All rights reserved.
3 * Copyright (c) 2006-2012. QLogic Corporation. All rights reserved.
4 * Copyright (c) 2003-2006, PathScale, Inc. All rights reserved.
5 *
6 * This software is available to you under a choice of one of two
7 * licenses. You may choose to be licensed under the terms of the GNU
8 * General Public License (GPL) Version 2, available from the file
9 * COPYING in the main directory of this source tree, or the
10 * OpenIB.org BSD license below:
11 *
12 * Redistribution and use in source and binary forms, with or
13 * without modification, are permitted provided that the following
14 * conditions are met:
15 *
16 * - Redistributions of source code must retain the above
17 * copyright notice, this list of conditions and the following
18 * disclaimer.
19 *
20 * - Redistributions in binary form must reproduce the above
21 * copyright notice, this list of conditions and the following
22 * disclaimer in the documentation and/or other materials
23 * provided with the distribution.
24 *
25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32 * SOFTWARE.
33 */
34
35 #ifndef PSMI_AM_H
36 #define PSMI_AM_H
37
38 #include "../psm_am_internal.h"
39
40 #define NSHORT_ARGS 6
41 typedef
42 struct amsh_am_token
43 {
44 struct psmi_am_token tok;
45
46
47 ptl_t *ptl; /**> What PTL was it received on */
48 psm_mq_t mq; /**> What matched queue is this for ? */
49 int shmidx; /**> what shmidx sent this */
50 int loopback; /**> Whether to reply as loopback */
51 }
52 amsh_am_token_t;
53
54 typedef void (*psmi_handler_fn_t)(void *token, psm_amarg_t *args, int nargs, void *src, size_t len);
55
56 typedef struct psmi_handlertab {
57 psmi_handler_fn_t fn;
58 } psmi_handlertab_t;
59
60 /*
61 * Can change the rendezvous threshold based on usage of kcopy (or not)
62 */
63 #define PSMI_MQ_RV_THRESH_KCOPY 16000
64
65 /*
66 * Can change the rendezvous threshold based on usage of knem (or not)
67 */
68 #define PSMI_MQ_RV_THRESH_KNEM 16000
69
70 /* If no kernel assisted copy is available this is the rendezvous threshold */
71 #define PSMI_MQ_RV_THRESH_NO_KASSIST 16000
72
73 /* Threshold for using SCIF DMA to do data transfers */
74 #define PSMI_MQ_RV_THRESH_SCIF_DMA (150000)
75
76 #define PSMI_AM_CONN_REQ 1
77 #define PSMI_AM_CONN_REP 2
78 #define PSMI_AM_DISC_REQ 3
79 #define PSMI_AM_DISC_REP 4
80
81 #define PSMI_KASSIST_OFF 0x0
82 #define PSMI_KASSIST_KCOPY_GET 0x1
83 #define PSMI_KASSIST_KCOPY_PUT 0x2
84 #define PSMI_KASSIST_KNEM_GET 0x4
85 #define PSMI_KASSIST_KNEM_PUT 0x8
86
87 #define PSMI_KASSIST_KCOPY 0x3
88 #define PSMI_KASSIST_KNEM 0xC
89 #define PSMI_KASSIST_GET 0x15
90 #define PSMI_KASSIST_PUT 0x2A
91 #define PSMI_KASSIST_MASK 0x3F
92
93 #define PSMI_KASSIST_MODE_DEFAULT PSMI_KASSIST_KNEM_PUT
94 #define PSMI_KASSIST_MODE_DEFAULT_STRING "knem-put"
95
96 int psmi_epaddr_kcopy_pid(psm_epaddr_t epaddr);
97
98 #define PSMI_SCIF_DMA_OFF 0x0
99 #define PSMI_SCIF_DMA_GET 0x1
100 #define PSMI_SCIF_DMA_PUT 0x2
101
102 #define PSMI_SCIF_DMA_MODE_DEFAULT PSMI_SCIF_DMA_GET
103 #define PSMI_SCIF_DMA_MODE_DEFAULT_STRING "scif-get"
104
105 /*
106 * Eventually, we will allow users to register handlers as "don't reply", which
107 * may save on some of the buffering requirements
108 */
109 #define PSMI_HANDLER_NEEDS_REPLY(handler) 1
110 #define PSMI_VALIDATE_REPLY(handler) assert(PSMI_HANDLER_NEEDS_REPLY(handler))
111
112 int psmi_amsh_poll(ptl_t *ptl, int replyonly);
113
114 /* Shared memory AM, forward decls */
115 int
116 psmi_amsh_short_request(ptl_t *ptl, psm_epaddr_t epaddr,
117 psm_handler_t handler, psm_amarg_t *args, int nargs,
118 const void *src, size_t len, int flags);
119
120 void
121 psmi_amsh_short_reply(amsh_am_token_t *tok,
122 psm_handler_t handler, psm_amarg_t *args, int nargs,
123 const void *src, size_t len, int flags);
124
125 int
126 psmi_amsh_long_request(ptl_t *ptl, psm_epaddr_t epaddr,
127 psm_handler_t handler, psm_amarg_t *args, int nargs,
128 const void *src, size_t len, void *dest, int flags);
129
130 void
131 psmi_amsh_long_reply(amsh_am_token_t *tok,
132 psm_handler_t handler, psm_amarg_t *args, int nargs,
133 const void *src, size_t len, void *dest, int flags);
134
135 void psmi_am_mq_handler(void *toki, psm_amarg_t *args, int narg, void *buf, size_t len);
136
137 void psmi_am_mq_handler(void *toki, psm_amarg_t *args, int narg, void *buf, size_t len);
138 void psmi_am_mq_handler_data(void *toki, psm_amarg_t *args, int narg, void *buf, size_t len);
139 void psmi_am_mq_handler_complete(void *toki, psm_amarg_t *args, int narg, void *buf, size_t len);
140 void psmi_am_mq_handler_rtsmatch(void *toki, psm_amarg_t *args, int narg, void *buf, size_t len);
141 void psmi_am_mq_handler_rtsdone(void *toki, psm_amarg_t *args, int narg, void *buf, size_t len);
142 void psmi_am_handler(void *toki, psm_amarg_t *args, int narg, void *buf, size_t len);
143
144 /* AM over shared memory (forward decls) */
145 psm_error_t
146 psmi_amsh_am_short_request(psm_epaddr_t epaddr,
147 psm_handler_t handler, psm_amarg_t *args, int nargs,
148 void *src, size_t len, int flags,
149 psm_am_completion_fn_t completion_fn,
150 void *completion_ctxt);
151 psm_error_t
152 psmi_amsh_am_short_reply(psm_am_token_t tok,
153 psm_handler_t handler, psm_amarg_t *args, int nargs,
154 void *src, size_t len, int flags,
155 psm_am_completion_fn_t completion_fn,
156 void *completion_ctxt);
157
158 #define amsh_conn_handler_hidx 1
159 #define mq_handler_hidx 2
160 #define mq_handler_data_hidx 3
161 #define mq_handler_rtsmatch_hidx 4
162 #define mq_handler_rtsdone_hidx 5
163 #define am_handler_hidx 6
164
165 #define AMREQUEST_SHORT 0
166 #define AMREQUEST_LONG 1
167 #define AMREPLY_SHORT 2
168 #define AMREPLY_LONG 3
169 #define AM_IS_REPLY(x) ((x)&0x2)
170 #define AM_IS_REQUEST(x) (!AM_IS_REPLY(x))
171 #define AM_IS_LONG(x) ((x)&0x1)
172 #define AM_IS_SHORT(x) (!AM_IS_LONG(x))
173
174 #define AM_FLAG_SRC_ASYNC 0x1
175 #define AM_FLAG_SRC_TEMP 0x2
176
177 /*
178 * Request Fifo.
179 */
180 typedef
181 struct am_reqq {
182 struct am_reqq *next;
183 int amtype;
184
185 ptl_t *ptl;
186 psm_epaddr_t epaddr;
187 psm_handler_t handler;
188 psm_amarg_t args[8];
189 int nargs;
190 void *src;
191 uint32_t len;
192 void *dest;
193 int amflags;
194 int flags;
195 }
196 am_reqq_t;
197
198 struct am_reqq_fifo_t {
199 am_reqq_t *first;
200 am_reqq_t **lastp;
201 };
202
203 psm_error_t psmi_am_reqq_drain(ptl_t *ptl);
204 void psmi_am_reqq_add(int amtype, ptl_t *ptl, psm_epaddr_t epaddr,
205 psm_handler_t handler, psm_amarg_t *args, int nargs,
206 void *src, size_t len, void *dest, int flags);
207
208 /*
209 * Shared memory Active Messages, implementation derived from
210 * Lumetta, Mainwaring, Culler. Multi-Protocol Active Messages on a Cluster of
211 * SMP's. Supercomputing 1997.
212 *
213 * We support multiple endpoints in shared memory, but we only support one
214 * shared memory context with up to AMSH_MAX_LOCAL_PROCS local endpoints. Some
215 * structures are endpoint specific (as denoted * with amsh_ep_) and others are
216 * specific to the single shared memory context * (amsh_ global variables).
217 *
218 * Each endpoint maintains a shared request block and a shared reply block.
219 * Each block is composed of queues for small, medium and large messages.
220 */
221
222 #define QFREE 0
223 #define QUSED 1
224 #define QREADY 2
225 #define QREADYMED 3
226 #define QREADYLONG 4
227
228 #define QISEMPTY(flag) (flag<QREADY)
229 #ifdef __powerpc__
230 # define _QMARK_FLAG_FENCE() asm volatile("lwsync" : : : "memory")
231 #elif defined(__x86_64__) || defined(__i386__)
232 #ifdef __MIC__
233 # define _QMARK_FLAG_FENCE() asm volatile("lock; addl $0,0(%%rsp)" ::: "memory");
234 #else
235 # define _QMARK_FLAG_FENCE() asm volatile("sfence" : : : "memory");
236 //# define _QMARK_FLAG_FENCE() asm volatile("" : : : "memory") /* compilerfence */
237 #endif
238 #else
239 # error No _QMARK_FLAG_FENCE() defined for this platform
240 #endif
241
242 #define _QMARK_FLAG(pkt_ptr, _flag) do { \
243 _QMARK_FLAG_FENCE(); \
244 (pkt_ptr)->flag = (_flag); \
245 _QMARK_FLAG_FENCE(); \
246 } while (0)
247
248 #define QMARKFREE(pkt_ptr) _QMARK_FLAG(pkt_ptr, QFREE)
249 #define QMARKREADY(pkt_ptr) _QMARK_FLAG(pkt_ptr, QREADY)
250 #define QMARKUSED(pkt_ptr) _QMARK_FLAG(pkt_ptr, QUSED)
251
252 #define AMFMT_SYSTEM 1
253 #define AMFMT_SHORT_INLINE 2
254 #define AMFMT_SHORT 3
255 #define AMFMT_LONG 4
256 #define AMFMT_LONG_END 5
257 #define AMFMT_HUGE 6
258 #define AMFMT_HUGE_END 7
259
260 #define _shmidx _ptladdr_u32[0]
261 #define _cstate _ptladdr_u32[1]
262
263 #define AMSH_CMASK_NONE 0
264 #define AMSH_CMASK_PREREQ 1
265 #define AMSH_CMASK_POSTREQ 2
266 #define AMSH_CMASK_DONE 3
267
268 #define AMSH_CSTATE_TO_MASK 0x0f
269 #define AMSH_CSTATE_TO_NONE 0x01
270 #define AMSH_CSTATE_TO_REPLIED 0x02
271 #define AMSH_CSTATE_TO_ESTABLISHED 0x03
272 #define AMSH_CSTATE_TO_DISC_REPLIED 0x04
273 #define AMSH_CSTATE_TO_GET(epaddr) ((epaddr)->_cstate & AMSH_CSTATE_TO_MASK)
274 #define AMSH_CSTATE_TO_SET(epaddr,state) \
275 (epaddr)->_cstate = (((epaddr)->_cstate & ~AMSH_CSTATE_TO_MASK) | \
276 ((AMSH_CSTATE_TO_ ## state) & AMSH_CSTATE_TO_MASK))
277
278 #define AMSH_CSTATE_FROM_MASK 0xf0
279 #define AMSH_CSTATE_FROM_NONE 0x10
280 #define AMSH_CSTATE_FROM_DISC_REQ 0x40
281 #define AMSH_CSTATE_FROM_ESTABLISHED 0x50
282 #define AMSH_CSTATE_FROM_GET(epaddr) ((epaddr)->_cstate & AMSH_CSTATE_FROM_MASK)
283 #define AMSH_CSTATE_FROM_SET(epaddr,state) \
284 (epaddr)->_cstate = (((epaddr)->_cstate & ~AMSH_CSTATE_FROM_MASK) | \
285 ((AMSH_CSTATE_FROM_ ## state) & AMSH_CSTATE_FROM_MASK))
286
287 /**********************************
288 * Shared memory packet formats
289 **********************************/
290 typedef
291 struct am_pkt_short {
292 uint32_t flag; /**> Packet state */
293 union {
294 uint32_t bulkidx; /**> index in bulk packet queue */
295 uint32_t length; /**> length when no bulkidx used */
296 };
297 uint16_t shmidx; /**> index in shared segment */
298 uint16_t type;
299 uint16_t nargs;
300 uint16_t handleridx;
301
302 psm_amarg_t args[NSHORT_ARGS]; /* AM arguments */
303
304 /* We eventually will expose up to 8 arguments, but this isn't implemented
305 * For now. >6 args will probably require a medium instead of a short */
306 }
307 am_pkt_short_t PSMI_CACHEALIGN;
308 PSMI_STRICT_SIZE_DECL(am_pkt_short_t,64);
309
310 typedef struct am_pkt_bulk {
311 uint32_t flag;
312 uint32_t idx;
313 uintptr_t dest; /* Destination pointer in "longs" */
314 uint32_t dest_off; /* Destination pointer offset */
315 uint32_t len; /* Destination length within offset */
316 psm_amarg_t args[2]; /* Additional "spillover" for >6 args */
317 uint8_t payload[0];
318 }
319 am_pkt_bulk_t;
320 /* No strict size decl, used for mediums and longs */
321
322 /****************************************************
323 * Shared memory header and block control structures
324 ***************************************************/
325
326 /* Each pkt queue has the same header format, although the queue
327 * consumers don't use the 'head' index in the same manner. */
328 typedef struct am_ctl_qhdr {
329 uint32_t head; /* Touched only by 1 consumer */
330 uint8_t _pad0[64-4];
331
332 /* tail is now located on the dirpage. */
333 uint32_t elem_cnt;
334 uint32_t elem_sz;
335 uint8_t _pad1[64-2*sizeof(uint32_t)];
336 }
337 am_ctl_qhdr_t;
338 PSMI_STRICT_SIZE_DECL(am_ctl_qhdr_t,128);
339
340 /* Each block reserves some space at the beginning to store auxiliary data */
341 #define AMSH_BLOCK_HEADER_SIZE 4096
342
343 /* Each process has a reply qhdr and a request qhdr */
344 typedef struct am_ctl_blockhdr {
345 volatile am_ctl_qhdr_t shortq;
346 volatile am_ctl_qhdr_t medbulkq;
347 volatile am_ctl_qhdr_t longbulkq;
348 volatile am_ctl_qhdr_t hugebulkq;
349 }
350 am_ctl_blockhdr_t;
351 PSMI_STRICT_SIZE_DECL(am_ctl_blockhdr_t,128*3);
352
353 /* We cache the "shorts" because that's what we poll on in the critical path.
354 * We take care to always update these pointers whenever the segment is remapped.
355 */
356 typedef struct am_ctl_qshort_cache {
357 volatile am_pkt_short_t *base;
358 volatile am_pkt_short_t *head;
359 volatile am_pkt_short_t *end;
360 }
361 am_ctl_qshort_cache_t;
362
363 struct amsh_qptrs {
364 am_ctl_blockhdr_t *qreqH;
365 am_pkt_short_t *qreqFifoShort;
366 am_pkt_bulk_t *qreqFifoMed;
367 am_pkt_bulk_t *qreqFifoLong;
368 am_pkt_bulk_t *qreqFifoHuge;
369
370 am_ctl_blockhdr_t *qrepH;
371 am_pkt_short_t *qrepFifoShort;
372 am_pkt_bulk_t *qrepFifoMed;
373 am_pkt_bulk_t *qrepFifoLong;
374 am_pkt_bulk_t *qrepFifoHuge;
375 };
376
377 /******************************************
378 * Shared segment local directory (global)
379 ******************************************
380 *
381 * Each process keeps a directory for where request and reply structures are
382 * located at its peers.
383 */
384 struct amsh_qdirectory {
385 /* These pointers are convenience aliases for the local node queues
386 also found in the qptrs array. */
387 am_ctl_blockhdr_t *qreqH;
388 am_pkt_short_t *qreqFifoShort;
389 am_pkt_bulk_t *qreqFifoMed;
390 am_pkt_bulk_t *qreqFifoLong;
391 am_pkt_bulk_t *qreqFifoHuge;
392
393 am_ctl_blockhdr_t *qrepH;
394 am_pkt_short_t *qrepFifoShort;
395 am_pkt_bulk_t *qrepFifoMed;
396 am_pkt_bulk_t *qrepFifoLong;
397 am_pkt_bulk_t *qrepFifoHuge;
398
399 struct amsh_qptrs qptrs[PTL_AMSH_MAX_LOCAL_NODES];
400
401 int kassist_pid;
402
403 /*
404 * Peer view of my index. for initial node, it is the same as ep->amsh_shmidx,
405 * for other remote nodes, it is calculated by circular offset of
406 * PTL_AMSH_MAX_LOCAL_PROCS, node-ID, and ep->amsh_shmidx.
407 */
408 int amsh_shmidx;
409 psm_epid_t amsh_epid;
410 uint16_t amsh_verno;
411 #ifdef PSM_HAVE_SCIF
412 scif_epd_t amsh_epd[2];
413 #endif
414 off_t amsh_offset;
415 void *amsh_base;
416 psm_epaddr_t amsh_epaddr;
417 } __attribute__ ((aligned(8)));
418
419 typedef struct amsh_qtail_info
420 {
421 volatile uint32_t tail;
422 volatile pthread_spinlock_t lock;
423 uint8_t _pad0[64-1*4-sizeof(pthread_spinlock_t)];
424 } amsh_qtail_info_t;
425 PSMI_STRICT_SIZE_DECL(amsh_qtail_info_t,64);
426
427 struct amsh_qtail
428 {
429 amsh_qtail_info_t reqFifoShort;
430 amsh_qtail_info_t reqFifoMed;
431 amsh_qtail_info_t reqFifoLong;
432 amsh_qtail_info_t reqFifoHuge;
433
434 amsh_qtail_info_t repFifoShort;
435 amsh_qtail_info_t repFifoMed;
436 amsh_qtail_info_t repFifoLong;
437 amsh_qtail_info_t repFifoHuge;
438 } __attribute__ ((aligned(64)));
439
440 /* The first shared memory page is a control page to support each endpoint
441 * independently adding themselves to the shared memory segment. */
442 struct am_ctl_dirpage {
443 pthread_mutex_t lock;
444 char _pad0[64-sizeof(pthread_mutex_t)];
445 volatile int is_init;
446 char _pad1[64-sizeof(int)];
447
448 uint16_t psm_verno[PTL_AMSH_MAX_LOCAL_PROCS];
449 uint32_t amsh_features[PTL_AMSH_MAX_LOCAL_PROCS];
450 int num_attached; /* 0..MAX_LOCAL_PROCS-1 */
451 int max_idx;
452
453 psm_epid_t shmidx_map_epid[PTL_AMSH_MAX_LOCAL_PROCS];
454 int kcopy_minor;
455 int kassist_pids[PTL_AMSH_MAX_LOCAL_PROCS];
456
457 /* A set of tail queue data for each remote domain. Each domain has
458 a reserved set of queues for each other domain. The queues are located
459 in shared memory on the target domain, while the tail pointer is
460 located on the source domain. */
461 /* The tail pointers are located in the dirpage because each peer in this
462 domain will be sharing them (atomically). The dirpage is mapped by
463 all processes already, so just use it. */
464 struct amsh_qtail qtails[PTL_AMSH_MAX_LOCAL_PROCS*PTL_AMSH_MAX_LOCAL_NODES];
465 };
466
467 #define AMSH_HAVE_KCOPY 0x01
468 #define AMSH_HAVE_KNEM 0x02
469 #define AMSH_HAVE_SCIF 0x04
470 #define AMSH_HAVE_KASSIST 0x7
471
472 /******************************************
473 * Shared fifo element counts and sizes
474 ******************************************
475 * These values are context-wide, they can only be set early on and can't be *
476 * modified at runtime. All endpoints are expected to use the same values.
477 */
478 typedef
479 struct amsh_qinfo {
480 int qreqFifoShort;
481 int qreqFifoMed;
482 int qreqFifoLong;
483 int qreqFifoHuge;
484
485 int qrepFifoShort;
486 int qrepFifoMed;
487 int qrepFifoLong;
488 int qrepFifoHuge;
489 }
490 amsh_qinfo_t;
491
492 /******************************************
493 * Per-endpoint structures (ep-local)
494 ******************************************
495 * Each endpoint keeps its own information as to where it resides in the
496 * directory, and maintains its own cached copies of where the short header
497 * resides in shared memory.
498 *
499 * NOTE: All changes must be reflected in PSMI_AMSH_EP_SIZE
500 */
501 struct ptl {
502 psm_ep_t ep;
503 psm_epid_t epid;
504 psm_epaddr_t epaddr;
505 ptl_ctl_t *ctl;
506 int shmidx;
507 am_ctl_qshort_cache_t reqH[PTL_AMSH_MAX_LOCAL_NODES];
508 am_ctl_qshort_cache_t repH[PTL_AMSH_MAX_LOCAL_NODES];
509 int zero_polls;
510 int amsh_only_polls;
511
512 pthread_mutex_t connect_lock;
513 int connect_phase;
514 int connect_to;
515 int connect_from;
516
517 /* List of context-specific shared variables */
518 amsh_qinfo_t amsh_qsizes;
519 am_pkt_short_t amsh_empty_shortpkt;
520 struct am_reqq_fifo_t psmi_am_reqq_fifo;
521
522 };
523
524 #endif