1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * Types used by the library side routines that do not need to be
7 * exposed to the user application
13 #include "build_check.h"
15 #include <portals/types.h>
16 #include <portals/nal.h>
18 # include <linux/uio.h>
19 # include <linux/smp_lock.h>
20 # include <linux/types.h>
22 # define PTL_USE_LIB_FREELIST
23 # include <sys/types.h>
26 typedef char *user_ptr;
27 typedef struct lib_msg_t lib_msg_t;
28 typedef struct lib_ptl_t lib_ptl_t;
29 typedef struct lib_ac_t lib_ac_t;
30 typedef struct lib_me_t lib_me_t;
31 typedef struct lib_md_t lib_md_t;
32 typedef struct lib_eq_t lib_eq_t;
34 #define WIRE_ATTR __attribute__((packed))
36 /* The wire handle's interface cookie only matches one network interface in
37 * one epoch (i.e. new cookie when the interface restarts or the node
38 * reboots). The object cookie only matches one object on that interface
39 * during that object's lifetime (i.e. no cookie re-use). */
41 __u64 wh_interface_cookie;
42 __u64 wh_object_cookie;
43 } WIRE_ATTR ptl_handle_wire_t;
45 /* byte-flip insensitive! */
46 #define PTL_WIRE_HANDLE_NONE \
47 ((const ptl_handle_wire_t) {.wh_interface_cookie = -1, .wh_object_cookie = -1})
57 /* The variant fields of the portals message header are aligned on an 8
58 * byte boundary in the message header. Note that all types used in these
59 * wire structs MUST be fixed size and the smaller types are placed at the
61 typedef struct ptl_ack {
62 ptl_handle_wire_t dst_wmd;
63 ptl_match_bits_t match_bits;
65 } WIRE_ATTR ptl_ack_t;
67 typedef struct ptl_put {
68 ptl_handle_wire_t ack_wmd;
69 ptl_match_bits_t match_bits;
70 ptl_hdr_data_t hdr_data;
71 ptl_pt_index_t ptl_index;
73 } WIRE_ATTR ptl_put_t;
75 typedef struct ptl_get {
76 ptl_handle_wire_t return_wmd;
77 ptl_match_bits_t match_bits;
78 ptl_pt_index_t ptl_index;
79 ptl_size_t src_offset;
80 ptl_size_t sink_length;
81 } WIRE_ATTR ptl_get_t;
83 typedef struct ptl_reply {
84 ptl_handle_wire_t dst_wmd;
85 } WIRE_ATTR ptl_reply_t;
87 typedef struct ptl_hello {
90 } WIRE_ATTR ptl_hello_t;
97 __u32 type; /* ptl_msg_type_t */
98 __u32 payload_length; /* payload data to follow */
99 /*<------__u64 aligned------->*/
107 } WIRE_ATTR ptl_hdr_t;
109 /* A HELLO message contains the portals magic number and protocol version
110 * code in the header's dest_nid, the peer's NID in the src_nid, and
111 * PTL_MSG_HELLO in the type field. All other common fields are zero
112 * (including payload_size; i.e. no payload).
113 * This is for use by byte-stream NALs (e.g. TCP/IP) to check the peer is
114 * running the same protocol and to find out its NID, so that hosts with
115 * multiple IP interfaces can have a single NID. These NALs should exchange
116 * HELLO messages when a connection is first established.
117 * Individual NALs can put whatever else they fancy in ptl_hdr_t::msg.
120 __u32 magic; /* PORTALS_PROTO_MAGIC */
121 __u16 version_major; /* increment on incompatible change */
122 __u16 version_minor; /* increment on compatible change */
123 } WIRE_ATTR ptl_magicversion_t;
125 #define PORTALS_PROTO_MAGIC 0xeebc0ded
127 #define PORTALS_PROTO_VERSION_MAJOR 1
128 #define PORTALS_PROTO_VERSION_MINOR 0
131 long recv_count, recv_length, send_count, send_length, drop_count,
132 drop_length, msgs_alloc, msgs_max;
135 /* temporary expedient: limit number of entries in discontiguous MDs */
136 #define PTL_MTU (1<<20)
137 #define PTL_MD_MAX_IOV 256
140 struct list_head msg_list;
142 ptl_handle_wire_t ack_wmd;
148 struct list_head *tbl;
156 struct list_head lh_hash_chain;
160 #define lh_entry(ptr, type, member) \
161 ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
164 struct list_head eq_list;
166 ptl_seq_t eq_enq_seq;
167 ptl_seq_t eq_deq_seq;
169 ptl_event_t *eq_events;
171 ptl_eq_handler_t eq_callback;
176 struct list_head me_list;
178 ptl_process_id_t match_id;
179 ptl_match_bits_t match_bits, ignore_bits;
185 struct list_head md_list;
194 unsigned int options;
195 unsigned int md_flags;
199 unsigned int md_niov; /* # frags */
201 struct iovec iov[PTL_MD_MAX_IOV];
202 ptl_kiov_t kiov[PTL_MD_MAX_IOV];
206 #define PTL_MD_FLAG_ZOMBIE (1 << 0)
207 #define PTL_MD_FLAG_AUTO_UNLINK (1 << 1)
209 static inline int lib_md_exhausted (lib_md_t *md)
211 return (md->threshold == 0 ||
212 ((md->options & PTL_MD_MAX_SIZE) != 0 &&
213 md->offset + md->max_size > md->length));
216 #ifdef PTL_USE_LIB_FREELIST
219 void *fl_objs; /* single contiguous array of objects */
220 int fl_nobjs; /* the number of them */
221 int fl_objsize; /* the size (including overhead) of each of them */
222 struct list_head fl_list; /* where they are enqueued */
227 struct list_head fo_list; /* enqueue on fl_list */
228 void *fo_contents; /* aligned contents */
233 /* info about peers we are trying to fail */
234 struct list_head tp_list; /* stash in ni.ni_test_peers */
235 ptl_nid_t tp_nid; /* matching nid */
236 unsigned int tp_threshold; /* # failures to simulate */
239 #define PTL_COOKIE_TYPE_MD 1
240 #define PTL_COOKIE_TYPE_ME 2
241 #define PTL_COOKIE_TYPE_EQ 3
242 #define PTL_COOKIE_TYPES 4
243 /* PTL_COOKIE_TYPES must be a power of 2, so the cookie type can be
244 * extracted by masking with (PTL_COOKIE_TYPES - 1) */
246 typedef struct lib_ni
249 ptl_process_id_t ni_pid;
250 lib_ptl_t ni_portals;
251 lib_counters_t ni_counters;
252 ptl_ni_limits_t ni_actual_limits;
254 int ni_lh_hash_size; /* size of lib handle hash table */
255 struct list_head *ni_lh_hash_table; /* all extant lib handles, this interface */
256 __u64 ni_next_object_cookie; /* cookie generator */
257 __u64 ni_interface_cookie; /* uniquely identifies this ni in this epoch */
259 struct list_head ni_test_peers;
261 #ifdef PTL_USE_LIB_FREELIST
262 lib_freelist_t ni_free_mes;
263 lib_freelist_t ni_free_msgs;
264 lib_freelist_t ni_free_mds;
265 lib_freelist_t ni_free_eqs;
268 struct list_head ni_active_msgs;
269 struct list_head ni_active_mds;
270 struct list_head ni_active_eqs;
274 wait_queue_head_t ni_waitq;
276 pthread_mutex_t ni_mutex;
277 pthread_cond_t ni_cond;
282 typedef struct lib_nal
284 /* lib-level interface state */
287 /* NAL-private data */
291 * send: Sends a preformatted header and payload data to a
292 * specified remote process. The payload is scattered over 'niov'
293 * fragments described by iov, starting at 'offset' for 'mlen'
295 * NB the NAL may NOT overwrite iov.
296 * PTL_OK on success => NAL has committed to send and will call
297 * lib_finalize on completion
299 ptl_err_t (*libnal_send)
300 (struct lib_nal *nal, void *private, lib_msg_t *cookie,
301 ptl_hdr_t *hdr, int type, ptl_nid_t nid, ptl_pid_t pid,
302 unsigned int niov, struct iovec *iov,
303 size_t offset, size_t mlen);
305 /* as send, but with a set of page fragments (NULL if not supported) */
306 ptl_err_t (*libnal_send_pages)
307 (struct lib_nal *nal, void *private, lib_msg_t * cookie,
308 ptl_hdr_t * hdr, int type, ptl_nid_t nid, ptl_pid_t pid,
309 unsigned int niov, ptl_kiov_t *iov,
310 size_t offset, size_t mlen);
312 * recv: Receives an incoming message from a remote process. The
313 * payload is to be received into the scattered buffer of 'niov'
314 * fragments described by iov, starting at 'offset' for 'mlen'
315 * bytes. Payload bytes after 'mlen' up to 'rlen' are to be
317 * NB the NAL may NOT overwrite iov.
318 * PTL_OK on success => NAL has committed to receive and will call
319 * lib_finalize on completion
321 ptl_err_t (*libnal_recv)
322 (struct lib_nal *nal, void *private, lib_msg_t * cookie,
323 unsigned int niov, struct iovec *iov,
324 size_t offset, size_t mlen, size_t rlen);
326 /* as recv, but with a set of page fragments (NULL if not supported) */
327 ptl_err_t (*libnal_recv_pages)
328 (struct lib_nal *nal, void *private, lib_msg_t * cookie,
329 unsigned int niov, ptl_kiov_t *iov,
330 size_t offset, size_t mlen, size_t rlen);
333 * (un)map: Tell the NAL about some memory it will access.
334 * *addrkey passed to libnal_unmap() is what libnal_map() set it to.
335 * type of *iov depends on options.
336 * Set to NULL if not required.
338 ptl_err_t (*libnal_map)
339 (struct lib_nal *nal, unsigned int niov, struct iovec *iov,
342 (struct lib_nal *nal, unsigned int niov, struct iovec *iov,
345 /* as (un)map, but with a set of page fragments */
346 ptl_err_t (*libnal_map_pages)
347 (struct lib_nal *nal, unsigned int niov, ptl_kiov_t *iov,
349 void (*libnal_unmap_pages)
350 (struct lib_nal *nal, unsigned int niov, ptl_kiov_t *iov,
353 void (*libnal_printf)(struct lib_nal *nal, const char *fmt, ...);
355 /* Calculate a network "distance" to given node */
356 int (*libnal_dist) (struct lib_nal *nal, ptl_nid_t nid, unsigned long *dist);