1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2005 Cluster File Systems, Inc. All rights reserved.
5 * Author: Eric Barton <eeb@bartonsoftware.com>
7 * This file is part of the Lustre file system, http://www.lustre.org
8 * Lustre is a trademark of Cluster File Systems, Inc.
10 * This file is confidential source code owned by Cluster File Systems.
11 * No viewing, modification, compilation, redistribution, or any other
12 * form of use is permitted except through a signed license agreement.
14 * If you have not signed such an agreement, then you have no rights to
15 * this file. Please destroy it immediately and contact CFS.
20 #define DEBUG_SUBSYSTEM S_LND
22 #include <lnet/lib-lnet.h>
23 #include <lnet/ptllnd_wire.h>
25 #include <portals/p30.h>
26 #include <lnet/ptllnd.h> /* Depends on portals/p30.h */
28 #define PTLLND_DEBUG_TIMING 0
30 #define PTLLND_MSGS_PER_BUFFER 64
31 #define PTLLND_MSGS_SPARE 256
32 #define PTLLND_PEER_HASH_SIZE 101
33 #define PTLLND_EQ_SIZE 1024
34 #if PTLLND_DEBUG_TIMING
35 # define PTLLND_TX_HISTORY 1024
37 # define PTLLND_TX_HISTORY 0
39 #define PTLLND_WARN_LONG_WAIT 5 /* seconds */
40 #define PTLLND_ABORT_ON_NAK 1 /* abort app on protocol version mismatch */
42 #define PTLLND_MD_OPTIONS (PTL_MD_LUSTRE_COMPLETION_SEMANTICS |\
43 PTL_MD_EVENT_START_DISABLE)
47 ptl_pid_t plni_ptllnd_pid; /* Portals PID of peers I may connect to */
48 int plni_peer_credits;
49 int plni_max_msg_size;
52 int plni_peer_hash_size;
55 int plni_max_tx_history;
56 int plni_abort_on_nak;
59 struct list_head plni_active_txs;
60 struct list_head plni_zombie_txs;
64 ptl_handle_ni_t plni_nih;
65 ptl_handle_eq_t plni_eqh;
66 ptl_process_id_t plni_portals_id; /* Portals ID of interface */
68 struct list_head *plni_peer_hash;
71 struct list_head plni_tx_history;
74 struct list_head plni_buffers;
76 int plni_nposted_buffers;
79 #define PTLLND_CREDIT_HIGHWATER(plni) ((plni)->plni_peer_credits - 1)
83 struct list_head plp_list;
85 lnet_process_id_t plp_id;
86 ptl_process_id_t plp_ptlid;
89 int plp_outstanding_credits;
92 int plp_recvd_hello:1;
96 struct list_head plp_txq;
97 struct list_head plp_activeq;
102 struct list_head plb_list;
105 ptl_handle_md_t plb_md;
111 ptllnd_peer_t *rx_peer;
118 struct list_head tx_list;
121 ptllnd_peer_t *tx_peer;
122 lnet_msg_t *tx_lnetmsg;
123 lnet_msg_t *tx_lnetreplymsg;
124 unsigned int tx_niov;
125 ptl_md_iovec_t *tx_iov;
126 ptl_handle_md_t tx_bulkmdh;
127 ptl_handle_md_t tx_reqmdh;
128 #if PTLLND_DEBUG_TIMING
129 struct timeval tx_bulk_posted;
130 struct timeval tx_bulk_done;
131 struct timeval tx_req_posted;
132 struct timeval tx_req_done;
134 int tx_completing; /* someone already completing */
135 int tx_msgsize; /* # bytes in tx_msg */
136 kptl_msg_t tx_msg; /* message to send */
139 #define PTLLND_RDMA_WRITE 0x100 /* pseudo message type */
140 #define PTLLND_RDMA_READ 0x101 /* (no msg actually sent) */
142 /* Hack to extract object type from event's user_ptr relies on (and checks)
143 * that structs are somewhat aligned. */
144 #define PTLLND_EVENTARG_TYPE_TX 0x1
145 #define PTLLND_EVENTARG_TYPE_BUF 0x2
146 #define PTLLND_EVENTARG_TYPE_MASK 0x3
149 ptllnd_obj2eventarg (void *obj, int type)
151 unsigned long ptr = (unsigned long)obj;
153 LASSERT ((ptr & PTLLND_EVENTARG_TYPE_MASK) == 0);
154 LASSERT ((type & ~PTLLND_EVENTARG_TYPE_MASK) == 0);
156 return (void *)(ptr | type);
160 ptllnd_eventarg2type (void *arg)
162 unsigned long ptr = (unsigned long)arg;
164 return (ptr & PTLLND_EVENTARG_TYPE_MASK);
168 ptllnd_eventarg2obj (void *arg)
170 unsigned long ptr = (unsigned long)arg;
172 return (void *)(ptr & ~PTLLND_EVENTARG_TYPE_MASK);
175 #if PTLLND_DEBUG_TIMING
176 # define PTLLND_DBGT_INIT(tv) memset(&(tv), 0, sizeof(tv))
177 # define PTLLND_DBGT_STAMP(tv) gettimeofday(&(tv), NULL)
178 # define DBGT_FMT "%ld.%06ld"
179 # define DBGT_ARGS(tv) , (long)((tv).tv_sec), (long)((tv).tv_usec)
181 # define PTLLND_DBGT_INIT(tv)
182 # define PTLLND_DBGT_STAMP(tv)
183 # define DBGT_FMT "-"
184 # define DBGT_ARGS(tv)
187 void ptllnd_cull_tx_history(ptllnd_ni_t *plni);
188 int ptllnd_startup(lnet_ni_t *ni);
189 void ptllnd_shutdown(lnet_ni_t *ni);
190 int ptllnd_ctl(lnet_ni_t *ni, unsigned int cmd, void *arg);
191 int ptllnd_send(lnet_ni_t *ni, void *private, lnet_msg_t *msg);
192 int ptllnd_recv(lnet_ni_t *ni, void *private, lnet_msg_t *msg,
193 int delayed, unsigned int niov,
194 struct iovec *iov, lnet_kiov_t *kiov,
195 unsigned int offset, unsigned int mlen, unsigned int rlen);
196 int ptllnd_eager_recv(lnet_ni_t *ni, void *private, lnet_msg_t *msg,
197 void **new_privatep);
199 ptllnd_tx_t *ptllnd_new_tx(ptllnd_peer_t *peer, int type, int payload_nob);
200 void ptllnd_notify(lnet_ni_t *ni, lnet_nid_t nid, int alive);
201 void ptllnd_wait(lnet_ni_t *ni, int milliseconds);
202 void ptllnd_check_sends(ptllnd_peer_t *peer);
203 void ptllnd_debug_peer(lnet_ni_t *ni, lnet_process_id_t id);
204 void ptllnd_destroy_peer(ptllnd_peer_t *peer);
205 void ptllnd_close_peer(ptllnd_peer_t *peer, int error);
206 int ptllnd_post_buffer(ptllnd_buffer_t *buf);
207 int ptllnd_grow_buffers (lnet_ni_t *ni);
208 const char *ptllnd_evtype2str(int type);
209 const char *ptllnd_msgtype2str(int type);
210 char *ptllnd_ptlid2str(ptl_process_id_t id);
213 ptllnd_peer_addref (ptllnd_peer_t *peer)
215 LASSERT (peer->plp_refcount > 0);
216 peer->plp_refcount++;
220 ptllnd_peer_decref (ptllnd_peer_t *peer)
222 LASSERT (peer->plp_refcount > 0);
223 peer->plp_refcount--;
224 if (peer->plp_refcount == 0)
225 ptllnd_destroy_peer(peer);
229 ptllnd_post_tx(ptllnd_tx_t *tx)
231 ptllnd_peer_t *peer = tx->tx_peer;
232 LASSERT(tx->tx_peer != NULL);
233 list_add_tail(&tx->tx_list, &peer->plp_txq);
234 ptllnd_check_sends(peer);
237 static inline lnet_nid_t
238 ptllnd_ptl2lnetnid(lnet_ni_t *ni, ptl_nid_t portals_nid)
240 return LNET_MKNID(LNET_NIDNET(ni->ni_nid), portals_nid);
243 static inline ptl_nid_t
244 ptllnd_lnet2ptlnid(lnet_nid_t lnet_nid)
246 return LNET_NIDADDR(lnet_nid);
250 * A note about lprintf():
251 * Normally printf() is redirected to stdout of the console
252 * from which yod launched the catamount application. However
253 * there is a lot of initilziation code that runs before this
254 * redirection is hooked up, and printf() seems to go to the bit bucket
256 * To get any kind of debug output and init time lprintf() can
257 * be used to output to the console from which bookqk was used to
258 * boot the catamount node. This works for debugging some simple