photon  1.1
photon_backend.h
Go to the documentation of this file.
1 // =============================================================================
2 // Photon RDMA Library (libphoton)
3 //
4 // Copyright (c) 2016, Trustees of Indiana University,
5 // All rights reserved.
6 //
7 // This software may be modified and distributed under the terms of the BSD
8 // license. See the COPYING file for details.
9 //
10 // This software was created at the Indiana University Center for Research in
11 // Extreme Scale Technologies (CREST).
12 // =============================================================================
13 
14 #ifndef PHOTON_BACKEND_H
15 #define PHOTON_BACKEND_H
16 
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20 
21 #include "libphoton.h"
22 #include "photon_buffer.h"
23 #include "photon_request.h"
24 #include "photon_msgbuffer.h"
25 #include "photon_rdma_ledger.h"
27 #include "photon_rdma_EAGER_buf.h"
28 
29 #include "htable.h"
30 #include "logging.h"
31 #include "squeue.h"
32 #include "libsync/sync.h"
33 #include "libsync/queues.h"
34 
35 #ifdef HAVE_XSP
36 #include "photon_xsp_forwarder.h"
37 #endif
38 
39 #define PHOTON_GET_CQ_IND(n, i) ((n > 1) ? (i % n) : 0)
40 
41 #define DEF_EAGER_BUF_SIZE (1024*8) // 8K bytes of space per rank
42 #define DEF_PWC_BUF_SIZE (1024*8) // 8K bytes of space per rank
43 #define DEF_PWC_CID_SIZE (8) // Default to 64 bit completion IDs
44 #define DEF_SMALL_MSG_SIZE (1024)
45 #define DEF_LEDGER_SIZE (64)
46 #define DEF_SP_SIZE (128)
47 #define DEF_NUM_CQ 1
48 #define DEF_USE_RCQ 0
49 
50 #define MAX_LEDGER_SIZE (1<<13) // Only 13 bits available in RCQ
51 #define MAX_PWC_BUF_SIZE (1<<13) // Only 13 bits available in RCQ
52 #define MIN_PWC_BUF_SIZE (1024) // PWC requires some internal buffer
53 
54 #define UD_MASK_SIZE (1<<6)
55 
56 #define EVENT_NIL 0x00
57 #define LEDGER 0x01
58 #define EVQUEUE 0x02
59 #define SENDRECV 0x03
60 
61 #define RDMA_FLAG_NIL 0x00
62 #define RDMA_FLAG_NO_CQE (1<<1)
63 #define RDMA_FLAG_WITH_IMM (1<<2)
64 
65 #define LEDGER_ALL 0xff
66 #define LEDGER_INFO (1<<1)
67 #define LEDGER_EAGER (1<<2)
68 #define LEDGER_FIN (1<<3)
69 #define LEDGER_PWC (1<<4)
70 #define LEDGER_BUF (1<<5)
71 #define LEDGER_PBUF (1<<6)
72 
73 #define PH_BE_NIL 0x00
74 #define PH_BE_IN_ORDER (1<<1)
75 
77 
78 typedef struct proc_info_t {
89 
94  photonMsgBuf smsgbuf;
95 
97  photonBackend backend;
98 
99 #ifdef HAVE_SHMEM
100  pid_t pid;
101  unsigned long host;
102 #endif
103 
104 #ifdef HAVE_XSP
105  libxspSess *sess;
106  PhotonIOInfo *io_info;
107 #endif
108 } ProcessInfo;
109 
110 // photon memory registration requests
112  SLIST_ENTRY(photon_mem_register_req) list;
113  void *buffer;
114  uint64_t buffer_size;
115 };
116 
117 // header for UD message
118 typedef struct photon_ud_hdr_t {
119  uint32_t request;
120  uint32_t src_addr;
121  uint32_t length;
122  uint16_t msn;
123  uint16_t nmsg;
124 } photon_ud_hdr;
125 
126 typedef struct photon_backend_attr_t {
131 
134  void *context;
135  int (*initialized)(void);
136  int (*init)(photonConfig cfg, ProcessInfo *info);
137  int (*finalize)(void);
138  int (*connect)(void *local_ci, void *remote_ci, int pindex, void **ret_ci, int *ret_len,
140  int (*get_info)(ProcessInfo *pi, int proc, void **info, int *size, photon_info_t type);
141  int (*set_info)(ProcessInfo *pi, int proc, void *info, int size, photon_info_t type);
142  int (*get_dev_addr)(int af, photonAddr addr);
143  int (*get_dev_name)(char **ib_dev);
144  int (*register_addr)(photonAddr addr, int af);
145  int (*unregister_addr)(photonAddr addr, int af);
146  int (*rdma_put)(int proc, uintptr_t laddr, uintptr_t raddr, uint64_t size,
147  photonBuffer lbuf, photonBuffer rbuf, uint64_t id, uint64_t imm, int flags);
148  int (*rdma_get)(int proc, uintptr_t laddr, uintptr_t raddr, uint64_t size,
149  photonBuffer lbuf, photonBuffer rbuf, uint64_t id, int flags);
150  int (*rdma_send)(photonAddr addr, uintptr_t laddr, uint64_t size,
151  photonBuffer lbuf, uint64_t id, uint64_t imm, int flags);
152  int (*rdma_recv)(photonAddr addr, uintptr_t laddr, uint64_t size,
153  photonBuffer lbuf, uint64_t id, int flags);
154  int (*tx_size_left)(int proc);
155  int (*rx_size_left)(int proc);
156  int (*get_event)(int proc, int max, photon_rid *ids, int *n);
157  int (*get_revent)(int proc, int max, photon_rid *ids, uint64_t *imms, int *n);
158 };
159 
161 
164 
165 #ifdef HAVE_XSP
166 int photon_xsp_lookup_proc(libxspSess *sess, ProcessInfo **ret_pi, int *index);
167 int photon_xsp_unused_proc(ProcessInfo **ret_pi, int *index);
168 #endif
169 
170 // Photon API methods
172 PHOTON_INTERNAL int _photon_init(photonConfig cfg, ProcessInfo *info, photonBufferHandle ss);
173 PHOTON_INTERNAL int _photon_cancel(photon_rid request, int flags);
175 PHOTON_INTERNAL int _photon_register_buffer(void *buffer, uint64_t size);
176 PHOTON_INTERNAL int _photon_unregister_buffer(void *buffer, uint64_t size);
177 PHOTON_INTERNAL int _photon_test(photon_rid request, int *flag, int *type, photonStatus status);
179 PHOTON_INTERNAL int _photon_send(photonAddr addr, void *ptr, uint64_t size, int flags, photon_rid *request);
180 PHOTON_INTERNAL int _photon_recv(uint64_t request, void *ptr, uint64_t size, int flags);
181 PHOTON_INTERNAL int _photon_post_recv_buffer_rdma(int proc, void *ptr, uint64_t size, int tag, photon_rid *request);
182 PHOTON_INTERNAL int _photon_post_send_buffer_rdma(int proc, void *ptr, uint64_t size, int tag, photon_rid *request);
183 PHOTON_INTERNAL int _photon_post_send_request_rdma(int proc, uint64_t size, int tag, photon_rid *request);
184 PHOTON_INTERNAL int _photon_wait_recv_buffer_rdma(int proc, uint64_t size, int tag, photon_rid *request);
185 PHOTON_INTERNAL int _photon_wait_send_buffer_rdma(int proc, uint64_t size, int tag, photon_rid *request);
187 PHOTON_INTERNAL int _photon_post_os_put(photon_rid request, int proc, void *ptr, uint64_t size, int tag, uint64_t r_offset);
188 PHOTON_INTERNAL int _photon_post_os_get(photon_rid request, int proc, void *ptr, uint64_t size, int tag, uint64_t r_offset);
189 PHOTON_INTERNAL int _photon_post_os_put_direct(int proc, void *ptr, uint64_t size, photonBuffer rbuf, int flags, photon_rid *request);
190 PHOTON_INTERNAL int _photon_post_os_get_direct(int proc, void *ptr, uint64_t size, photonBuffer rbuf, int flags, photon_rid *request);
191 PHOTON_INTERNAL int _photon_send_FIN(photon_rid request, int proc, int flags);
192 PHOTON_INTERNAL int _photon_wait_any(int *ret_proc, photon_rid *ret_req);
193 PHOTON_INTERNAL int _photon_wait_any_ledger(int *ret_proc, photon_rid *ret_req);
194 PHOTON_INTERNAL int _photon_probe_ledger(int proc, int *flag, int type, photonStatus status);
195 PHOTON_INTERNAL int _photon_probe(photonAddr addr, int *flag, photonStatus status);
196 PHOTON_INTERNAL int _photon_io_init(char *file, int amode, void *view, int niter);
198 
199 // util
200 int _photon_get_buffer_private(void *buf, uint64_t size, const struct photon_buffer_priv_t **pptr);
201 int _photon_get_buffer_remote(photon_rid request, photonBuffer ret_buf);
202 int _photon_handle_addr(photonAddr addr, photonAddr ret_addr);
203 
204 #ifdef __cplusplus
205 }
206 #endif
207 
208 #endif
photonLedger remote_pwc_ledger
PHOTON_INTERNAL int _photon_unregister_buffer(void *buffer, uint64_t size)
photonLedger local_pwc_ledger
PHOTON_INTERNAL int _photon_initialized(void)
PHOTON_INTERNAL int _photon_io_init(char *file, int amode, void *view, int niter)
photon_connect_mode_t
PHOTON_INTERNAL int _photon_post_os_get(photon_rid request, int proc, void *ptr, uint64_t size, int tag, uint64_t r_offset)
struct photon_buffer_handle_t * photonBufferHandle
PHOTON_INTERNAL int _photon_cancel(photon_rid request, int flags)
photonLedger remote_eager_ledger
PHOTON_INTERNAL int _photon_send(photonAddr addr, void *ptr, uint64_t size, int flags, photon_rid *request)
uint32_t request
PHOTON_INTERNAL int _photon_test(photon_rid request, int *flag, int *type, photonStatus status)
PHOTON_INTERNAL int _photon_register_buffer(void *buffer, uint64_t size)
photonRequestTable request_table
PHOTON_INTERNAL int _photon_wait_any_ledger(int *ret_proc, photon_rid *ret_req)
struct photon_req_table_t * photonRequestTable
uint64_t photon_rid
The Photon request ID.
Definition: photon.h:75
uint32_t src_addr
photon_info_t
Definition: photon_io.h:21
photonRILedger remote_rcv_info_ledger
photonEagerBuf local_pwc_buf
PHOTON_INTERNAL int _photon_post_recv_buffer_rdma(int proc, void *ptr, uint64_t size, int tag, photon_rid *request)
PHOTON_INTERNAL int _photon_wait_any(int *ret_proc, photon_rid *ret_req)
PHOTON_INTERNAL int _photon_wait_recv_buffer_rdma(int proc, uint64_t size, int tag, photon_rid *request)
struct photon_ri_ledger_t * photonRILedger
PHOTON_INTERNAL int _photon_post_send_request_rdma(int proc, uint64_t size, int tag, photon_rid *request)
struct photon_backend_t photon_default_backend
photonMsgBuf smsgbuf
union photon_addr_t * photonAddr
Convenience pointer type for the address union.
Definition: photon.h:112
PHOTON_INTERNAL int _photon_wait(photon_rid request)
photonBackend backend
PHOTON_INTERNAL int _photon_post_os_put(photon_rid request, int proc, void *ptr, uint64_t size, int tag, uint64_t r_offset)
photonLedger remote_fin_ledger
PHOTON_INTERNAL int _photon_init(photonConfig cfg, ProcessInfo *info, photonBufferHandle ss)
PHOTON_INTERNAL int _photon_probe_ledger(int proc, int *flag, int type, photonStatus status)
#define PHOTON_INTERNAL
photonLedger local_eager_ledger
int _photon_get_buffer_private(void *buf, uint64_t size, const struct photon_buffer_priv_t **pptr)
PHOTON_INTERNAL int _photon_io_finalize()
int _photon_get_buffer_remote(photon_rid request, photonBuffer ret_buf)
PHOTON_INTERNAL int _photon_wait_send_buffer_rdma(int proc, uint64_t size, int tag, photon_rid *request)
int _photon_handle_addr(photonAddr addr, photonAddr ret_addr)
photonRILedger local_snd_info_ledger
photon_backend_attr * attr
photonEagerBuf remote_pwc_buf
PHOTON_INTERNAL int _photon_post_send_buffer_rdma(int proc, void *ptr, uint64_t size, int tag, photon_rid *request)
PHOTON_INTERNAL int _photon_wait_send_request_rdma(int tag)
photonRILedger local_rcv_info_ledger
PHOTON_INTERNAL int _photon_finalize(void)
photonEagerBuf local_eager_buf
photonEagerBuf remote_eager_buf
struct photon_rdma_ledger_t * photonLedger
Convenience pointer type for the private buffer structure.
Definition: photon.h:98
photonRILedger remote_snd_info_ledger
PHOTON_INTERNAL int _photon_probe(photonAddr addr, int *flag, photonStatus status)
PHOTON_INTERNAL int _photon_recv(uint64_t request, void *ptr, uint64_t size, int flags)
PHOTON_INTERNAL int _photon_post_os_put_direct(int proc, void *ptr, uint64_t size, photonBuffer rbuf, int flags, photon_rid *request)
ProcessInfo * photon_processes
PHOTON_INTERNAL int _photon_post_os_get_direct(int proc, void *ptr, uint64_t size, photonBuffer rbuf, int flags, photon_rid *request)
PHOTON_INTERNAL int _photon_send_FIN(photon_rid request, int proc, int flags)
photonLedger local_fin_ledger
struct photon_rdma_eager_buf_t * photonEagerBuf
photonBufferHandle shared_storage