Print this page
8368 remove warlock leftovers from usr/src/uts
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/io/ib/clients/rdsv3/threads.c
+++ new/usr/src/uts/common/io/ib/clients/rdsv3/threads.c
1 1 /*
2 2 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
3 3 */
4 4
5 5 /*
6 6 * This file contains code imported from the OFED rds source file threads.c
7 7 * Oracle elects to have and use the contents of threads.c under and governed
8 8 * by the OpenIB.org BSD license (see below for full license text). However,
9 9 * the following notice accompanied the original version of this file:
10 10 */
11 11
12 12 /*
13 13 * Copyright (c) 2006 Oracle. All rights reserved.
14 14 *
15 15 * This software is available to you under a choice of one of two
16 16 * licenses. You may choose to be licensed under the terms of the GNU
17 17 * General Public License (GPL) Version 2, available from the file
18 18 * COPYING in the main directory of this source tree, or the
19 19 * OpenIB.org BSD license below:
20 20 *
21 21 * Redistribution and use in source and binary forms, with or
22 22 * without modification, are permitted provided that the following
23 23 * conditions are met:
24 24 *
25 25 * - Redistributions of source code must retain the above
26 26 * copyright notice, this list of conditions and the following
27 27 * disclaimer.
28 28 *
29 29 * - Redistributions in binary form must reproduce the above
30 30 * copyright notice, this list of conditions and the following
31 31 * disclaimer in the documentation and/or other materials
32 32 * provided with the distribution.
33 33 *
34 34 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
35 35 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
36 36 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
37 37 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
38 38 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
39 39 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
40 40 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
41 41 * SOFTWARE.
42 42 *
43 43 */
44 44 #include <sys/rds.h>
45 45 #include <sys/sunddi.h>
46 46
47 47 #include <sys/ib/clients/rdsv3/rdsv3.h>
48 48 #include <sys/ib/clients/rdsv3/rdsv3_debug.h>
49 49
50 50 /*
51 51 * All of connection management is simplified by serializing it through
52 52 * work queues that execute in a connection managing thread.
53 53 *
54 54 * TCP wants to send acks through sendpage() in response to data_ready(),
55 55 * but it needs a process context to do so.
56 56 *
57 57 * The receive paths need to allocate but can't drop packets (!) so we have
58 58 * a thread around to block allocating if the receive fast path sees an
59 59 * allocation failure.
60 60 */
61 61
62 62 /*
63 63 * Grand Unified Theory of connection life cycle:
64 64 * At any point in time, the connection can be in one of these states:
65 65 * DOWN, CONNECTING, UP, DISCONNECTING, ERROR
66 66 *
67 67 * The following transitions are possible:
68 68 * ANY -> ERROR
69 69 * UP -> DISCONNECTING
70 70 * ERROR -> DISCONNECTING
71 71 * DISCONNECTING -> DOWN
72 72 * DOWN -> CONNECTING
73 73 * CONNECTING -> UP
74 74 *
75 75 * Transition to state DISCONNECTING/DOWN:
76 76 * - Inside the shutdown worker; synchronizes with xmit path
77 77 * through c_send_lock, and with connection management callbacks
78 78 * via c_cm_lock.
79 79 *
80 80 * For receive callbacks, we rely on the underlying transport
81 81 * (TCP, IB/RDMA) to provide the necessary synchronisation.
↓ open down ↓ |
81 lines elided |
↑ open up ↑ |
82 82 */
83 83 struct rdsv3_workqueue_struct_s *rdsv3_wq;
84 84
85 85 void
86 86 rdsv3_connect_complete(struct rdsv3_connection *conn)
87 87 {
88 88 RDSV3_DPRINTF4("rdsv3_connect_complete", "Enter(conn: %p)", conn);
89 89
90 90 if (!rdsv3_conn_transition(conn, RDSV3_CONN_CONNECTING,
91 91 RDSV3_CONN_UP)) {
92 -#ifndef __lock_lint
93 92 RDSV3_DPRINTF2("rdsv3_connect_complete",
94 93 "%s: Cannot transition to state UP, "
95 94 "current state is %d",
96 95 __func__,
97 96 atomic_get(&conn->c_state));
98 -#endif
99 97 conn->c_state = RDSV3_CONN_ERROR;
100 98 rdsv3_queue_work(rdsv3_wq, &conn->c_down_w);
101 99 return;
102 100 }
103 101
104 102 RDSV3_DPRINTF2("rdsv3_connect_complete",
105 103 "conn %p for %u.%u.%u.%u to %u.%u.%u.%u complete",
106 104 conn, NIPQUAD(conn->c_laddr), NIPQUAD(conn->c_faddr));
107 105
108 106 conn->c_reconnect_jiffies = 0;
109 107 conn->c_last_connect_jiffies = ddi_get_lbolt();
110 108
111 109 set_bit(0, &conn->c_map_queued);
112 110 rdsv3_queue_delayed_work(rdsv3_wq, &conn->c_send_w, 0);
113 111 rdsv3_queue_delayed_work(rdsv3_wq, &conn->c_recv_w, 0);
114 112
115 113 RDSV3_DPRINTF4("rdsv3_connect_complete", "Return(conn: %p)", conn);
116 114 }
117 115
118 116 /*
119 117 * This random exponential backoff is relied on to eventually resolve racing
120 118 * connects.
121 119 *
122 120 * If connect attempts race then both parties drop both connections and come
123 121 * here to wait for a random amount of time before trying again. Eventually
124 122 * the backoff range will be so much greater than the time it takes to
125 123 * establish a connection that one of the pair will establish the connection
126 124 * before the other's random delay fires.
127 125 *
128 126 * Connection attempts that arrive while a connection is already established
129 127 * are also considered to be racing connects. This lets a connection from
130 128 * a rebooted machine replace an existing stale connection before the transport
131 129 * notices that the connection has failed.
132 130 *
133 131 * We should *always* start with a random backoff; otherwise a broken connection
134 132 * will always take several iterations to be re-established.
135 133 */
136 134 void
137 135 rdsv3_queue_reconnect(struct rdsv3_connection *conn)
138 136 {
139 137 unsigned long rand;
140 138
141 139 RDSV3_DPRINTF2("rdsv3_queue_reconnect",
142 140 "conn %p for %u.%u.%u.%u to %u.%u.%u.%u reconnect jiffies %lu",
143 141 conn, NIPQUAD(conn->c_laddr), NIPQUAD(conn->c_faddr),
144 142 conn->c_reconnect_jiffies);
145 143
146 144 set_bit(RDSV3_RECONNECT_PENDING, &conn->c_flags);
147 145 if (conn->c_reconnect_jiffies == 0) {
148 146 conn->c_reconnect_jiffies = rdsv3_sysctl_reconnect_min_jiffies;
149 147 rdsv3_queue_delayed_work(rdsv3_wq, &conn->c_conn_w, 0);
150 148 return;
151 149 }
152 150
153 151 (void) random_get_pseudo_bytes((uint8_t *)&rand, sizeof (rand));
154 152
155 153 RDSV3_DPRINTF5("rdsv3",
156 154 "%lu delay %lu ceil conn %p for %u.%u.%u.%u -> %u.%u.%u.%u",
157 155 rand % conn->c_reconnect_jiffies, conn->c_reconnect_jiffies,
158 156 conn, NIPQUAD(conn->c_laddr), NIPQUAD(conn->c_faddr));
159 157
160 158 rdsv3_queue_delayed_work(rdsv3_wq, &conn->c_conn_w,
161 159 rand % conn->c_reconnect_jiffies);
162 160
163 161 conn->c_reconnect_jiffies = min(conn->c_reconnect_jiffies * 2,
164 162 rdsv3_sysctl_reconnect_max_jiffies);
165 163 }
166 164
167 165 void
168 166 rdsv3_connect_worker(struct rdsv3_work_s *work)
169 167 {
170 168 struct rdsv3_connection *conn = container_of(work,
171 169 struct rdsv3_connection, c_conn_w.work);
172 170 int ret;
173 171
174 172 RDSV3_DPRINTF2("rdsv3_connect_worker", "Enter(work: %p)", work);
175 173
176 174 clear_bit(RDSV3_RECONNECT_PENDING, &conn->c_flags);
177 175 if (rdsv3_conn_transition(conn, RDSV3_CONN_DOWN,
178 176 RDSV3_CONN_CONNECTING)) {
179 177 ret = conn->c_trans->conn_connect(conn);
180 178
181 179 RDSV3_DPRINTF5("rdsv3",
182 180 "connect conn %p for %u.%u.%u.%u -> %u.%u.%u.%u "
183 181 "ret %d", conn, NIPQUAD(conn->c_laddr),
184 182 NIPQUAD(conn->c_faddr), ret);
185 183
186 184 RDSV3_DPRINTF2("rdsv3_connect_worker",
187 185 "conn %p for %u.%u.%u.%u to %u.%u.%u.%u dispatched, ret %d",
188 186 conn, NIPQUAD(conn->c_laddr), NIPQUAD(conn->c_faddr), ret);
189 187
190 188 if (ret) {
191 189 if (rdsv3_conn_transition(conn, RDSV3_CONN_CONNECTING,
192 190 RDSV3_CONN_DOWN))
193 191 rdsv3_queue_reconnect(conn);
194 192 else {
195 193 RDSV3_DPRINTF2("rdsv3_connect_worker",
196 194 "RDS: connect failed: %p", conn);
197 195 rdsv3_conn_drop(conn);
198 196 }
199 197 }
200 198 }
201 199
202 200 RDSV3_DPRINTF2("rdsv3_connect_worker", "Return(work: %p)", work);
203 201 }
204 202
205 203 void
206 204 rdsv3_send_worker(struct rdsv3_work_s *work)
207 205 {
208 206 struct rdsv3_connection *conn = container_of(work,
209 207 struct rdsv3_connection, c_send_w.work);
210 208 int ret;
211 209
212 210 RDSV3_DPRINTF4("rdsv3_send_worker", "Enter(work: %p)", work);
213 211
214 212 if (rdsv3_conn_state(conn) == RDSV3_CONN_UP) {
215 213 ret = rdsv3_send_xmit(conn);
216 214 RDSV3_DPRINTF5("rdsv3", "conn %p ret %d", conn, ret);
217 215 switch (ret) {
218 216 case -EAGAIN:
219 217 rdsv3_stats_inc(s_send_immediate_retry);
220 218 rdsv3_queue_delayed_work(rdsv3_wq, &conn->c_send_w, 0);
221 219 break;
222 220 case -ENOMEM:
223 221 rdsv3_stats_inc(s_send_delayed_retry);
224 222 rdsv3_queue_delayed_work(rdsv3_wq, &conn->c_send_w, 2);
225 223 default:
226 224 break;
227 225 }
228 226 }
229 227
230 228 RDSV3_DPRINTF4("rdsv3_send_worker", "Return(work: %p)", work);
231 229 }
232 230
233 231 void
234 232 rdsv3_recv_worker(struct rdsv3_work_s *work)
235 233 {
236 234 struct rdsv3_connection *conn = container_of(work,
237 235 struct rdsv3_connection, c_recv_w.work);
238 236 int ret;
239 237
240 238 RDSV3_DPRINTF4("rdsv3_recv_worker", "Enter(work: %p)", work);
241 239
242 240 if (rdsv3_conn_state(conn) == RDSV3_CONN_UP) {
243 241 ret = conn->c_trans->recv(conn);
244 242 RDSV3_DPRINTF5("rdsv3", "conn %p ret %d", conn, ret);
245 243 switch (ret) {
246 244 case -EAGAIN:
247 245 rdsv3_stats_inc(s_recv_immediate_retry);
248 246 rdsv3_queue_delayed_work(rdsv3_wq, &conn->c_recv_w, 0);
249 247 break;
250 248 case -ENOMEM:
251 249 rdsv3_stats_inc(s_recv_delayed_retry);
252 250 rdsv3_queue_delayed_work(rdsv3_wq, &conn->c_recv_w, 2);
253 251 default:
254 252 break;
255 253 }
256 254 }
257 255
258 256 RDSV3_DPRINTF4("rdsv3_recv_worker", "Return(work: %p)", work);
259 257 }
260 258
261 259 void
262 260 rdsv3_shutdown_worker(struct rdsv3_work_s *work)
263 261 {
264 262 struct rdsv3_connection *conn = container_of(work,
265 263 struct rdsv3_connection, c_down_w);
266 264 rdsv3_conn_shutdown(conn);
267 265 }
268 266
269 267 #define time_after(a, b) ((long)(b) - (long)(a) < 0)
270 268
271 269 void
272 270 rdsv3_reaper_worker(struct rdsv3_work_s *work)
273 271 {
274 272 struct rdsv3_connection *conn = container_of(work,
275 273 struct rdsv3_connection, c_reap_w.work);
276 274
277 275 if (rdsv3_conn_state(conn) != RDSV3_CONN_UP &&
278 276 !time_after(conn->c_last_connect_jiffies,
279 277 ddi_get_lbolt() - RDSV3_REAPER_WAIT_JIFFIES)) {
280 278 rdsv3_conn_destroy(conn);
281 279 } else {
282 280 rdsv3_queue_delayed_work(rdsv3_wq, &conn->c_reap_w,
283 281 RDSV3_REAPER_WAIT_JIFFIES);
284 282 }
285 283 }
286 284
287 285 void
288 286 rdsv3_threads_exit(void)
289 287 {
290 288 rdsv3_destroy_task_workqueue(rdsv3_wq);
291 289 }
292 290
293 291 int
294 292 rdsv3_threads_init(void)
295 293 {
296 294 rdsv3_wq = rdsv3_create_task_workqueue("krdsd");
297 295 if (!rdsv3_wq)
298 296 return (-ENOMEM);
299 297
300 298 return (0);
301 299 }
↓ open down ↓ |
193 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX