Skip to content

Commit eb97e5f

Browse files
florincorasDave Barach
authored andcommitted
tls: fix multi threaded medium scale test (VPP-1457)
- ensure session enqueue epoch does not wrap between two enqueues - use 3 states for echo clients app, to distinguish between starting and closing phases - force tcp fin retransmit if out of buffers while sending a fin Change-Id: I6f2cab46affd1148aba2a33fb6d58bcc54f32805 Signed-off-by: Florin Coras <[email protected]>
1 parent f47e9b6 commit eb97e5f

File tree

7 files changed

+52
-11
lines changed

7 files changed

+52
-11
lines changed

src/vnet/session-apps/echo_client.c

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ echo_client_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node,
208208
connections_this_batch =
209209
ecm->connections_this_batch_by_thread[my_thread_index];
210210

211-
if ((ecm->run_test == 0) ||
211+
if ((ecm->run_test != ECHO_CLIENTS_RUNNING) ||
212212
((vec_len (connection_indices) == 0)
213213
&& vec_len (connections_this_batch) == 0))
214214
return 0;
@@ -352,6 +352,16 @@ echo_clients_init (vlib_main_t * vm)
352352
return 0;
353353
}
354354

355+
static void
356+
echo_clients_session_disconnect (stream_session_t * s)
357+
{
358+
echo_client_main_t *ecm = &echo_client_main;
359+
vnet_disconnect_args_t _a, *a = &_a;
360+
a->handle = session_handle (s);
361+
a->app_index = ecm->app_index;
362+
vnet_disconnect_session (a);
363+
}
364+
355365
static int
356366
echo_clients_session_connected_callback (u32 app_index, u32 api_context,
357367
stream_session_t * s, u8 is_fail)
@@ -361,6 +371,9 @@ echo_clients_session_connected_callback (u32 app_index, u32 api_context,
361371
u32 session_index;
362372
u8 thread_index;
363373

374+
if (PREDICT_FALSE (ecm->run_test != ECHO_CLIENTS_STARTING))
375+
return -1;
376+
364377
if (is_fail)
365378
{
366379
clib_warning ("connection %d failed!", api_context);
@@ -407,7 +420,7 @@ echo_clients_session_connected_callback (u32 app_index, u32 api_context,
407420
__sync_fetch_and_add (&ecm->ready_connections, 1);
408421
if (ecm->ready_connections == ecm->expected_connections)
409422
{
410-
ecm->run_test = 1;
423+
ecm->run_test = ECHO_CLIENTS_RUNNING;
411424
/* Signal the CLI process that the action is starting... */
412425
signal_evt_to_cli (1);
413426
}
@@ -447,6 +460,12 @@ echo_clients_rx_callback (stream_session_t * s)
447460
echo_client_main_t *ecm = &echo_client_main;
448461
eclient_session_t *sp;
449462

463+
if (PREDICT_FALSE (ecm->run_test != ECHO_CLIENTS_RUNNING))
464+
{
465+
echo_clients_session_disconnect (s);
466+
return -1;
467+
}
468+
450469
sp = pool_elt_at_index (ecm->sessions,
451470
s->server_rx_fifo->client_session_index);
452471
receive_data_chunk (ecm, sp);
@@ -624,6 +643,7 @@ echo_clients_command_fn (vlib_main_t * vm,
624643
ecm->vlib_main = vm;
625644
ecm->tls_engine = TLS_ENGINE_OPENSSL;
626645
ecm->no_copy = 0;
646+
ecm->run_test = ECHO_CLIENTS_STARTING;
627647

628648
if (thread_main->n_vlib_mains > 1)
629649
clib_spinlock_init (&ecm->sessions_lock);
@@ -825,7 +845,7 @@ echo_clients_command_fn (vlib_main_t * vm,
825845
error = clib_error_return (0, "failed: test bytes");
826846

827847
cleanup:
828-
ecm->run_test = 0;
848+
ecm->run_test = ECHO_CLIENTS_EXITING;
829849
vlib_process_wait_for_event_or_clock (vm, 10e-3);
830850
for (i = 0; i < vec_len (ecm->connection_index_by_thread); i++)
831851
{

src/vnet/session-apps/echo_client.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@ typedef struct
105105
vlib_main_t *vlib_main;
106106
} echo_client_main_t;
107107

108+
enum
109+
{
110+
ECHO_CLIENTS_STARTING,
111+
ECHO_CLIENTS_RUNNING,
112+
ECHO_CLIENTS_EXITING
113+
} echo_clients_test_state_e;
108114
extern echo_client_main_t echo_client_main;
109115

110116
vlib_node_registration_t echo_clients_node;

src/vnet/session/session.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ session_free (stream_session_t * s)
153153
memset (s, 0xFA, sizeof (*s));
154154
}
155155

156-
static void
156+
void
157157
session_free_w_fifos (stream_session_t * s)
158158
{
159159
segment_manager_dealloc_fifos (s->svm_segment_index, s->server_rx_fifo,
@@ -197,7 +197,7 @@ session_alloc_for_connection (transport_connection_t * tc)
197197
s = session_alloc (thread_index);
198198
s->session_type = session_type_from_proto_and_ip (tc->proto, tc->is_ip4);
199199
s->session_state = SESSION_STATE_CONNECTING;
200-
s->enqueue_epoch = ~0;
200+
s->enqueue_epoch = (u64) ~ 0;
201201

202202
/* Attach transport to session and vice versa */
203203
s->connection_index = tc->c_index;
@@ -393,7 +393,7 @@ session_enqueue_stream_connection (transport_connection_t * tc,
393393
* by calling stream_server_flush_enqueue_events () */
394394
session_manager_main_t *smm = vnet_get_session_manager_main ();
395395
u32 thread_index = s->thread_index;
396-
u32 enqueue_epoch = smm->current_enqueue_epoch[tc->proto][thread_index];
396+
u64 enqueue_epoch = smm->current_enqueue_epoch[tc->proto][thread_index];
397397

398398
if (s->enqueue_epoch != enqueue_epoch)
399399
{
@@ -434,7 +434,7 @@ session_enqueue_dgram_connection (stream_session_t * s,
434434
* by calling stream_server_flush_enqueue_events () */
435435
session_manager_main_t *smm = vnet_get_session_manager_main ();
436436
u32 thread_index = s->thread_index;
437-
u32 enqueue_epoch = smm->current_enqueue_epoch[proto][thread_index];
437+
u64 enqueue_epoch = smm->current_enqueue_epoch[proto][thread_index];
438438

439439
if (s->enqueue_epoch != enqueue_epoch)
440440
{

src/vnet/session/session.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ struct _session_manager_main
195195
clib_rwlock_t *peekers_rw_locks;
196196

197197
/** Per-proto, per-worker enqueue epoch counters */
198-
u32 *current_enqueue_epoch[TRANSPORT_N_PROTO];
198+
u64 *current_enqueue_epoch[TRANSPORT_N_PROTO];
199199

200200
/** Per-proto, per-worker thread vector of sessions to enqueue */
201201
u32 **session_to_enqueue[TRANSPORT_N_PROTO];
@@ -308,6 +308,7 @@ stream_session_is_valid (u32 si, u8 thread_index)
308308
stream_session_t *session_alloc (u32 thread_index);
309309
int session_alloc_fifos (segment_manager_t * sm, stream_session_t * s);
310310
void session_free (stream_session_t * s);
311+
void session_free_w_fifos (stream_session_t * s);
311312

312313
always_inline stream_session_t *
313314
session_get (u32 si, u32 thread_index)

src/vnet/session/stream_session.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ typedef struct _stream_session_t
6767
u8 thread_index;
6868

6969
/** To avoid n**2 "one event per frame" check */
70-
u8 enqueue_epoch;
70+
u64 enqueue_epoch;
7171

7272
/** svm segment index where fifos were allocated */
7373
u32 svm_segment_index;
@@ -120,6 +120,9 @@ typedef struct local_session_
120120
/** Port for connection. Overlaps thread_index/enqueue_epoch */
121121
u16 port;
122122

123+
/** Partly overlaps enqueue_epoch */
124+
u8 pad_epoch[7];
125+
123126
/** Segment index where fifos were allocated */
124127
u32 svm_segment_index;
125128

src/vnet/tcp/tcp_output.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1078,7 +1078,15 @@ tcp_send_fin (tcp_connection_t * tc)
10781078

10791079
tcp_retransmit_timer_force_update (tc);
10801080
if (PREDICT_FALSE (tcp_get_free_buffer_index (tm, &bi)))
1081-
return;
1081+
{
1082+
/* Out of buffers so program fin retransmit ASAP */
1083+
tcp_timer_update (tc, TCP_TIMER_RETRANSMIT, 1);
1084+
tc->flags |= TCP_CONN_FINSNT;
1085+
tc->snd_una_max += 1;
1086+
tc->snd_nxt = tc->snd_una_max;
1087+
return;
1088+
}
1089+
10821090
b = vlib_get_buffer (vm, bi);
10831091
tcp_init_buffer (vm, b);
10841092
fin_snt = tc->flags & TCP_CONN_FINSNT;

src/vnet/tls/tls.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,17 +119,18 @@ tls_ctx_half_open_alloc (void)
119119
{
120120
clib_rwlock_writer_lock (&tm->half_open_rwlock);
121121
pool_get (tm->half_open_ctx_pool, ctx);
122+
ctx_index = ctx - tm->half_open_ctx_pool;
122123
clib_rwlock_writer_unlock (&tm->half_open_rwlock);
123124
}
124125
else
125126
{
126127
/* reader lock assumption: only main thread will call pool_get */
127128
clib_rwlock_reader_lock (&tm->half_open_rwlock);
128129
pool_get (tm->half_open_ctx_pool, ctx);
130+
ctx_index = ctx - tm->half_open_ctx_pool;
129131
clib_rwlock_reader_unlock (&tm->half_open_rwlock);
130132
}
131133
memset (ctx, 0, sizeof (*ctx));
132-
ctx_index = ctx - tm->half_open_ctx_pool;
133134
return ctx_index;
134135
}
135136

@@ -254,6 +255,8 @@ tls_notify_app_connected (tls_ctx_t * ctx, u8 is_failed)
254255
{
255256
TLS_DBG (1, "failed to notify app");
256257
tls_disconnect (ctx->tls_ctx_handle, vlib_get_thread_index ());
258+
session_free_w_fifos (app_session);
259+
return -1;
257260
}
258261

259262
session_lookup_add_connection (&ctx->connection,

0 commit comments

Comments
 (0)