Whamcloud - gitweb
LU-1576 llite: correct page usage count
[fs/lustre-release.git] / lnet / ulnds / ptllnd / ptllnd.h
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  */
30 /*
31  * This file is part of Lustre, http://www.lustre.org/
32  * Lustre is a trademark of Sun Microsystems, Inc.
33  *
34  * lnet/ulnds/ptllnd/ptllnd.h
35  *
36  * Author: Eric Barton <eeb@bartonsoftware.com>
37  */
38
39
40 #define DEBUG_SUBSYSTEM S_LND
41
42 #include <lnet/lib-lnet.h>
43 #include <lnet/ptllnd_wire.h>
44
45 #include <portals/p30.h>
46 #include <lnet/ptllnd.h>           /* Depends on portals/p30.h */
47 #include <stdarg.h>
48
49 /* Hack to record history
50  * This should really be done by CDEBUG(D_NETTRACE...  */
51
52 typedef struct {
53         cfs_list_t                he_list;
54         struct timeval            he_time;
55         const char               *he_fn;
56         const char               *he_file;
57         int                       he_seq;
58         int                       he_line;
59         char                      he_msg[80];
60 } ptllnd_he_t;
61
62 void ptllnd_dump_history();
63 void ptllnd_history(const char *fn, const char *file, const int line,
64                     const char *fmt, ...);
65 #define PTLLND_HISTORY(fmt, a...) \
66         ptllnd_history(__FUNCTION__, __FILE__, __LINE__, fmt, ## a)
67
68
69 #define PTLLND_MD_OPTIONS        (PTL_MD_LUSTRE_COMPLETION_SEMANTICS |\
70                                   PTL_MD_EVENT_START_DISABLE)
71 typedef struct
72 {
73         int                        plni_portal;
74         ptl_pid_t                  plni_ptllnd_pid; /* Portals PID of peers I may connect to */
75         int                        plni_peer_credits;
76         int                        plni_max_msg_size;
77         int                        plni_buffer_size;
78         int                        plni_msgs_spare;
79         int                        plni_peer_hash_size;
80         int                        plni_eq_size;
81         int                        plni_checksum;
82         int                        plni_max_tx_history;
83         int                        plni_abort_on_protocol_mismatch;
84         int                        plni_abort_on_nak;
85         int                        plni_dump_on_nak;
86         int                        plni_debug;
87         int                        plni_long_wait;
88         int                        plni_watchdog_interval;
89         int                        plni_timeout;
90
91         __u64                      plni_stamp;
92         cfs_list_t                 plni_active_txs;
93         cfs_list_t                 plni_zombie_txs;
94         int                        plni_ntxs;
95         int                        plni_nrxs;
96
97         ptl_handle_ni_t            plni_nih;
98         ptl_handle_eq_t            plni_eqh;
99         ptl_process_id_t           plni_portals_id;   /* Portals ID of interface */
100
101         cfs_list_t                *plni_peer_hash;
102         int                        plni_npeers;
103
104         int                        plni_watchdog_nextt;
105         int                        plni_watchdog_peeridx;
106
107         cfs_list_t                 plni_tx_history;
108         int                        plni_ntx_history;
109
110         cfs_list_t                 plni_buffers;
111         int                        plni_nbuffers;
112         int                        plni_nposted_buffers;
113         int                        plni_nmsgs;
114 } ptllnd_ni_t;
115
116 #define PTLLND_CREDIT_HIGHWATER(plni) ((plni)->plni_peer_credits - 1)
117
118 typedef struct
119 {
120         cfs_list_t                 plp_list;
121         lnet_ni_t                 *plp_ni;
122         lnet_process_id_t          plp_id;
123         ptl_process_id_t           plp_ptlid;
124         int                        plp_credits; /* # msg buffers reserved for me at peer */
125
126         /* credits for msg buffers I've posted for this peer...
127          * outstanding - free buffers I've still to inform my peer about
128          * sent        - free buffers I've told my peer about
129          * lazy        - additional buffers (over and above plni_peer_credits)
130          *               posted to prevent peer blocking on sending a non-RDMA
131          *               messages to me when LNET isn't eagerly responsive to
132          *               the network (i.e. liblustre doesn't have control). 
133          * extra_lazy  - lazy credits not required any more. */
134         int                        plp_outstanding_credits;
135         int                        plp_sent_credits;
136         int                        plp_lazy_credits;
137         int                        plp_extra_lazy_credits;
138
139         int                        plp_max_msg_size;
140         int                        plp_refcount;
141         int                        plp_sent_hello:1;
142         int                        plp_recvd_hello:1;
143         int                        plp_closing:1;
144         __u64                      plp_match;
145         __u64                      plp_stamp;
146         cfs_list_t                 plp_txq;
147         cfs_list_t                 plp_noopq;
148         cfs_list_t                 plp_activeq;
149 } ptllnd_peer_t;
150
151 typedef struct
152 {
153         cfs_list_t                 plb_list;
154         lnet_ni_t                 *plb_ni;
155         int                        plb_posted;
156         ptl_handle_md_t            plb_md;
157         char                      *plb_buffer;
158 } ptllnd_buffer_t;
159
160 typedef struct
161 {
162         ptllnd_peer_t             *rx_peer;
163         kptl_msg_t                *rx_msg;
164         int                        rx_nob;
165 } ptllnd_rx_t;
166
167 typedef struct
168 {
169         cfs_list_t                 tx_list;
170         int                        tx_type;
171         int                        tx_status;
172         ptllnd_peer_t             *tx_peer;
173         lnet_msg_t                *tx_lnetmsg;
174         lnet_msg_t                *tx_lnetreplymsg;
175         unsigned int               tx_niov;
176         ptl_md_iovec_t            *tx_iov;
177         ptl_handle_md_t            tx_bulkmdh;
178         ptl_handle_md_t            tx_reqmdh;
179         struct timeval             tx_bulk_posted;
180         struct timeval             tx_bulk_done;
181         struct timeval             tx_req_posted;
182         struct timeval             tx_req_done;
183         int                        tx_completing; /* someone already completing */
184         int                        tx_msgsize;  /* # bytes in tx_msg */
185         time_t                     tx_deadline; /* time to complete by */
186         kptl_msg_t                 tx_msg;      /* message to send */
187 } ptllnd_tx_t;
188
189 #define PTLLND_RDMA_WRITE           0x100       /* pseudo message type */
190 #define PTLLND_RDMA_READ            0x101       /* (no msg actually sent) */
191
192 /* Hack to extract object type from event's user_ptr relies on (and checks)
193  * that structs are somewhat aligned. */
194 #define PTLLND_EVENTARG_TYPE_TX     0x1
195 #define PTLLND_EVENTARG_TYPE_BUF    0x2
196 #define PTLLND_EVENTARG_TYPE_MASK   0x3
197
198 static inline void *
199 ptllnd_obj2eventarg (void *obj, int type)
200 {
201         unsigned long ptr = (unsigned long)obj;
202
203         LASSERT ((ptr & PTLLND_EVENTARG_TYPE_MASK) == 0);
204         LASSERT ((type & ~PTLLND_EVENTARG_TYPE_MASK) == 0);
205
206         return (void *)(ptr | type);
207 }
208
209 static inline int
210 ptllnd_eventarg2type (void *arg)
211 {
212         unsigned long ptr = (unsigned long)arg;
213
214         return (ptr & PTLLND_EVENTARG_TYPE_MASK);
215 }
216
217 static inline void *
218 ptllnd_eventarg2obj (void *arg)
219 {
220         unsigned long ptr = (unsigned long)arg;
221
222         return (void *)(ptr & ~PTLLND_EVENTARG_TYPE_MASK);
223 }
224
225 int ptllnd_parse_int_tunable(int *value, char *name, int dflt);
226 void ptllnd_cull_tx_history(ptllnd_ni_t *plni);
227 int ptllnd_startup(lnet_ni_t *ni);
228 void ptllnd_shutdown(lnet_ni_t *ni);
229 int ptllnd_ctl(lnet_ni_t *ni, unsigned int cmd, void *arg);
230 int ptllnd_send(lnet_ni_t *ni, void *private, lnet_msg_t *msg);
231 int ptllnd_recv(lnet_ni_t *ni, void *private, lnet_msg_t *msg,
232                 int delayed, unsigned int niov,
233                 struct iovec *iov, lnet_kiov_t *kiov,
234                 unsigned int offset, unsigned int mlen, unsigned int rlen);
235 int ptllnd_eager_recv(lnet_ni_t *ni, void *private, lnet_msg_t *msg,
236                       void **new_privatep);
237
238 ptllnd_tx_t *ptllnd_new_tx(ptllnd_peer_t *peer, int type, int payload_nob);
239 int  ptllnd_setasync(lnet_ni_t *ni, lnet_process_id_t id, int n);
240 void ptllnd_wait(lnet_ni_t *ni, int milliseconds);
241 void ptllnd_check_sends(ptllnd_peer_t *peer);
242 void ptllnd_debug_peer(lnet_ni_t *ni, lnet_process_id_t id);
243 void ptllnd_destroy_peer(ptllnd_peer_t *peer);
244 void ptllnd_close_peer(ptllnd_peer_t *peer, int error);
245 int ptllnd_post_buffer(ptllnd_buffer_t *buf);
246 int ptllnd_size_buffers (lnet_ni_t *ni, int delta);
247 const char *ptllnd_evtype2str(int type);
248 const char *ptllnd_msgtype2str(int type);
249 const char *ptllnd_errtype2str(int type);
250 char *ptllnd_ptlid2str(ptl_process_id_t id);
251 void ptllnd_dump_debug(lnet_ni_t *ni, lnet_process_id_t id);
252
253
254 static inline void
255 ptllnd_peer_addref (ptllnd_peer_t *peer)
256 {
257         LASSERT (peer->plp_refcount > 0);
258         peer->plp_refcount++;
259 }
260
261 static inline void
262 ptllnd_peer_decref (ptllnd_peer_t *peer)
263 {
264         LASSERT (peer->plp_refcount > 0);
265         peer->plp_refcount--;
266         if (peer->plp_refcount == 0)
267                 ptllnd_destroy_peer(peer);
268 }
269
270 static inline lnet_nid_t
271 ptllnd_ptl2lnetnid(lnet_ni_t *ni, ptl_nid_t portals_nid)
272 {
273         return LNET_MKNID(LNET_NIDNET(ni->ni_nid), portals_nid);
274 }
275
276 static inline ptl_nid_t
277 ptllnd_lnet2ptlnid(lnet_nid_t lnet_nid)
278 {
279         return LNET_NIDADDR(lnet_nid);
280 }
281
282 /*
283  * A note about lprintf():
284  *  Normally printf() is redirected to stdout of the console
285  *  from which yod launched the catamount application.  However
286  *  there is a lot of initilziation code that runs before this
287  *  redirection is hooked up, and printf() seems to go to the bit bucket
288  *
289  *  To get any kind of debug output and init time lprintf() can
290  *  be used to output to the console from which bookqk was used to
291  *  boot the catamount node.  This works for debugging some simple
292  *  cases.
293  */