Fix tcp tx buffer allocation

- Make tcp output buffer allocation macro an inline function
- Use per ip version per thread tx frames for retransmits and timer
  events
- Fix / parameterize tcp data structure preallocation
- Add a couple of gdb-callable show commands
- Fix local endpoint cleanup

Change-Id: I67b47b7570aa14cb4634b6fd93c57cd2eacbfa29
Signed-off-by: Florin Coras <fcoras@cisco.com>
Signed-off-by: Dave Barach <dave@barachs.net>
This commit is contained in:
Florin Coras
2017-07-31 17:18:03 -07:00
parent fdbc38249a
commit 66b11318a1
15 changed files with 376 additions and 121 deletions
+1
View File
@@ -357,6 +357,7 @@ show_dpdk_buffer (vlib_main_t * vm, unformat_input_t * input,
"name=\"%s\" available = %7d allocated = %7d total = %7d\n",
rmp->name, (u32) count, (u32) free_count,
(u32) (count + free_count));
rte_mempool_dump (stderr, rmp);
}
else
{
+1 -1
View File
@@ -280,7 +280,7 @@ show_errors (vlib_main_t * vm,
}
/* *INDENT-OFF* */
VLIB_CLI_COMMAND (cli_show_errors, static) = {
VLIB_CLI_COMMAND (vlib_cli_show_errors) = {
.path = "show errors",
.short_help = "Show error counts",
.function = show_errors,
+9 -7
View File
@@ -410,19 +410,21 @@ vlib_frame_t *vlib_get_frame_to_node (vlib_main_t * vm, u32 to_node_index);
void vlib_put_frame_to_node (vlib_main_t * vm, u32 to_node_index,
vlib_frame_t * f);
always_inline vlib_process_t *
vlib_get_current_process (vlib_main_t * vm)
{
vlib_node_main_t *nm = &vm->node_main;
return vec_elt (nm->processes, nm->current_process_index);
}
always_inline uword
vlib_in_process_context (vlib_main_t * vm)
{
return vm->node_main.current_process_index != ~0;
}
always_inline vlib_process_t *
vlib_get_current_process (vlib_main_t * vm)
{
vlib_node_main_t *nm = &vm->node_main;
if (vlib_in_process_context (vm))
return vec_elt (nm->processes, nm->current_process_index);
return 0;
}
always_inline uword
vlib_current_process (vlib_main_t * vm)
{
-2
View File
@@ -354,8 +354,6 @@ vlib_buffer_push_ip4 (vlib_main_t * vm, vlib_buffer_t * b,
ih->checksum = 0;
b->flags |= VNET_BUFFER_F_OFFLOAD_IP_CKSUM | VNET_BUFFER_F_IS_IP4;
vnet_buffer (b)->l3_hdr_offset = (u8 *) ih - b->data;
vnet_buffer (b)->l4_hdr_offset = vnet_buffer (b)->l3_hdr_offset +
sizeof (*ih);
}
else
ih->checksum = ip4_header_checksum (ih);
+75 -9
View File
@@ -759,6 +759,7 @@ session_manager_main_enable (vlib_main_t * vm)
session_manager_main_t *smm = &session_manager_main;
vlib_thread_main_t *vtm = vlib_get_thread_main ();
u32 num_threads;
u32 preallocated_sessions_per_worker;
int i;
num_threads = 1 /* main thread */ + vtm->n_threads;
@@ -795,15 +796,35 @@ session_manager_main_enable (vlib_main_t * vm)
for (i = 0; i < vec_len (smm->vpp_event_queues); i++)
session_vpp_event_queue_allocate (smm, i);
/* $$$$ preallocate hack config parameter */
for (i = 0; i < smm->preallocated_sessions; i++)
/* Preallocate sessions */
if (num_threads == 1)
{
stream_session_t *ss __attribute__ ((unused));
pool_get_aligned (smm->sessions[0], ss, CLIB_CACHE_LINE_BYTES);
}
for (i = 0; i < smm->preallocated_sessions; i++)
{
stream_session_t *ss __attribute__ ((unused));
pool_get_aligned (smm->sessions[0], ss, CLIB_CACHE_LINE_BYTES);
}
for (i = 0; i < smm->preallocated_sessions; i++)
pool_put_index (smm->sessions[0], i);
for (i = 0; i < smm->preallocated_sessions; i++)
pool_put_index (smm->sessions[0], i);
}
else
{
int j;
preallocated_sessions_per_worker = smm->preallocated_sessions /
(num_threads - 1);
for (j = 1; j < num_threads; j++)
{
for (i = 0; i < preallocated_sessions_per_worker; i++)
{
stream_session_t *ss __attribute__ ((unused));
pool_get_aligned (smm->sessions[j], ss, CLIB_CACHE_LINE_BYTES);
}
for (i = 0; i < preallocated_sessions_per_worker; i++)
pool_put_index (smm->sessions[j], i);
}
}
session_lookup_init ();
@@ -863,6 +884,7 @@ session_config_fn (vlib_main_t * vm, unformat_input_t * input)
{
session_manager_main_t *smm = &session_manager_main;
u32 nitems;
uword tmp;
while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
{
@@ -873,9 +895,53 @@ session_config_fn (vlib_main_t * vm, unformat_input_t * input)
else
clib_warning ("event queue length %d too small, ignored", nitems);
}
if (unformat (input, "preallocated-sessions %d",
&smm->preallocated_sessions))
else if (unformat (input, "preallocated-sessions %d",
&smm->preallocated_sessions))
;
else if (unformat (input, "v4-session-table-buckets %d",
&smm->configured_v4_session_table_buckets))
;
else if (unformat (input, "v4-halfopen-table-buckets %d",
&smm->configured_v4_halfopen_table_buckets))
;
else if (unformat (input, "v6-session-table-buckets %d",
&smm->configured_v6_session_table_buckets))
;
else if (unformat (input, "v6-halfopen-table-buckets %d",
&smm->configured_v6_halfopen_table_buckets))
;
else if (unformat (input, "v4-session-table-memory %U",
unformat_memory_size, &tmp))
{
if (tmp >= 0x100000000)
return clib_error_return (0, "memory size %llx (%lld) too large",
tmp, tmp);
smm->configured_v4_session_table_memory = tmp;
}
else if (unformat (input, "v4-halfopen-table-memory %U",
unformat_memory_size, &tmp))
{
if (tmp >= 0x100000000)
return clib_error_return (0, "memory size %llx (%lld) too large",
tmp, tmp);
smm->configured_v4_halfopen_table_memory = tmp;
}
else if (unformat (input, "v6-session-table-memory %U",
unformat_memory_size, &tmp))
{
if (tmp >= 0x100000000)
return clib_error_return (0, "memory size %llx (%lld) too large",
tmp, tmp);
smm->configured_v6_session_table_memory = tmp;
}
else if (unformat (input, "v6-halfopen-table-memory %U",
unformat_memory_size, &tmp))
{
if (tmp >= 0x100000000)
return clib_error_return (0, "memory size %llx (%lld) too large",
tmp, tmp);
smm->configured_v6_halfopen_table_memory = tmp;
}
else
return clib_error_return (0, "unknown input `%U'",
format_unformat_error, input);
+10
View File
@@ -133,6 +133,16 @@ struct _session_manager_main
/** vpp fifo event queue configured length */
u32 configured_event_queue_length;
/** session table size parameters */
u32 configured_v4_session_table_buckets;
u32 configured_v4_session_table_memory;
u32 configured_v4_halfopen_table_buckets;
u32 configured_v4_halfopen_table_memory;
u32 configured_v6_session_table_buckets;
u32 configured_v6_session_table_memory;
u32 configured_v6_halfopen_table_buckets;
u32 configured_v6_halfopen_table_memory;
/** Unique segment name counter */
u32 unique_segment_name_counter;
+1 -1
View File
@@ -312,7 +312,7 @@ show_session_command_fn (vlib_main_t * vm, unformat_input_t * input,
}
/* *INDENT-OFF* */
VLIB_CLI_COMMAND (show_session_command, static) =
VLIB_CLI_COMMAND (vlib_cli_show_session_command) =
{
.path = "show session",
.short_help = "show session [verbose]",
+32 -10
View File
@@ -569,23 +569,45 @@ stream_session_lookup_transport6 (ip6_address_t * lcl, ip6_address_t * rmt,
return 0;
}
#define foreach_hash_table_parameter \
_(v4,session,buckets,20000) \
_(v4,session,memory,(64<<20)) \
_(v6,session,buckets,20000) \
_(v6,session,memory,(64<<20)) \
_(v4,halfopen,buckets,20000) \
_(v4,halfopen,memory,(64<<20)) \
_(v6,halfopen,buckets,20000) \
_(v6,halfopen,memory,(64<<20))
void
session_lookup_init (void)
{
session_lookup_t *sl = &session_lookup;
clib_bihash_init_16_8 (&sl->v4_session_hash, "v4 session table",
200000 /* $$$$ config parameter nbuckets */ ,
(64 << 20) /*$$$ config parameter table size */ );
clib_bihash_init_48_8 (&sl->v6_session_hash, "v6 session table",
200000 /* $$$$ config parameter nbuckets */ ,
(64 << 20) /*$$$ config parameter table size */ );
#define _(af,table,parm,value) \
u32 configured_##af##_##table##_table_##parm = value;
foreach_hash_table_parameter;
#undef _
#define _(af,table,parm,value) \
if (session_manager_main.configured_##af##_##table##_table_##parm) \
configured_##af##_##table##_table_##parm = \
session_manager_main.configured_##af##_##table##_table_##parm;
foreach_hash_table_parameter;
#undef _
clib_bihash_init_16_8 (&sl->v4_session_hash, "v4 session table",
configured_v4_session_table_buckets,
configured_v4_session_table_memory);
clib_bihash_init_48_8 (&sl->v6_session_hash, "v6 session table",
configured_v6_session_table_buckets,
configured_v6_session_table_memory);
clib_bihash_init_16_8 (&sl->v4_half_open_hash, "v4 half-open table",
200000 /* $$$$ config parameter nbuckets */ ,
(64 << 20) /*$$$ config parameter table size */ );
configured_v4_halfopen_table_buckets,
configured_v4_halfopen_table_memory);
clib_bihash_init_48_8 (&sl->v6_half_open_hash, "v6 half-open table",
200000 /* $$$$ config parameter nbuckets */ ,
(64 << 20) /*$$$ config parameter table size */ );
configured_v6_halfopen_table_buckets,
configured_v6_halfopen_table_memory);
}
/*
+33 -6
View File
@@ -597,8 +597,9 @@ clients_connect (vlib_main_t * vm, u8 * uri, u32 n_clients)
a->mp = 0;
vnet_connect_uri (a);
/* Crude pacing for call setups, 100k/sec */
vlib_process_suspend (vm, 10e-6);
/* Crude pacing for call setups */
if ((i % 4) == 0)
vlib_process_suspend (vm, 10e-6);
}
}
@@ -612,8 +613,10 @@ test_tcp_clients_command_fn (vlib_main_t * vm,
uword *event_data = 0, event_type;
u8 *default_connect_uri = (u8 *) "tcp://6.0.1.1/1234", *uri;
u64 tmp, total_bytes;
f64 cli_timeout = 20.0, delta;
f64 test_timeout = 20.0, syn_timeout = 20.0, delta;
f64 time_before_connects;
u32 n_clients = 1;
int preallocate_sessions = 0;
char *transfer_type;
int i;
@@ -640,7 +643,9 @@ test_tcp_clients_command_fn (vlib_main_t * vm,
;
else if (unformat (input, "uri %s", &tm->connect_uri))
;
else if (unformat (input, "cli-timeout %f", &cli_timeout))
else if (unformat (input, "test-timeout %f", &test_timeout))
;
else if (unformat (input, "syn-timeout %f", &syn_timeout))
;
else if (unformat (input, "no-return"))
tm->no_return = 1;
@@ -657,6 +662,8 @@ test_tcp_clients_command_fn (vlib_main_t * vm,
tm->private_segment_size = tmp;
else if (unformat (input, "preallocate-fifos"))
tm->prealloc_fifos = 1;
else if (unformat (input, "preallocate-sessions"))
preallocate_sessions = 1;
else
if (unformat (input, "client-batch %d", &tm->connections_per_batch))
;
@@ -674,6 +681,7 @@ test_tcp_clients_command_fn (vlib_main_t * vm,
return clib_error_return (0, "failed init");
}
tm->ready_connections = 0;
tm->expected_connections = n_clients;
tm->rx_total = 0;
@@ -705,11 +713,21 @@ test_tcp_clients_command_fn (vlib_main_t * vm,
vlib_node_set_state (vlib_mains[i], builtin_client_node.index,
VLIB_NODE_STATE_POLLING);
if (preallocate_sessions)
{
session_t *sp __attribute__ ((unused));
for (i = 0; i < n_clients; i++)
pool_get (tm->sessions, sp);
for (i = 0; i < n_clients; i++)
pool_put_index (tm->sessions, i);
}
/* Fire off connect requests */
time_before_connects = vlib_time_now (vm);
clients_connect (vm, uri, n_clients);
/* Park until the sessions come up, or ten seconds elapse... */
vlib_process_wait_for_event_or_clock (vm, 10 /* timeout, seconds */ );
vlib_process_wait_for_event_or_clock (vm, syn_timeout);
event_type = vlib_process_get_events (vm, &event_data);
switch (event_type)
{
@@ -719,6 +737,15 @@ test_tcp_clients_command_fn (vlib_main_t * vm,
goto cleanup;
case 1:
delta = vlib_time_now (vm) - time_before_connects;
if (delta != 0.0)
{
vlib_cli_output
(vm, "%d three-way handshakes in %.2f seconds, %.2f/sec",
n_clients, delta, ((f64) n_clients) / delta);
}
tm->test_start_time = vlib_time_now (tm->vlib_main);
vlib_cli_output (vm, "Test started at %.6f", tm->test_start_time);
break;
@@ -729,7 +756,7 @@ test_tcp_clients_command_fn (vlib_main_t * vm,
}
/* Now wait for the sessions to finish... */
vlib_process_wait_for_event_or_clock (vm, cli_timeout);
vlib_process_wait_for_event_or_clock (vm, test_timeout);
event_type = vlib_process_get_events (vm, &event_data);
switch (event_type)
{
+34 -18
View File
@@ -173,7 +173,7 @@ tcp_connection_cleanup (tcp_connection_t * tc)
/* Cleanup local endpoint if this was an active connect */
tepi = transport_endpoint_lookup (&tm->local_endpoints_table, &tc->c_lcl_ip,
tc->c_lcl_port);
clib_net_to_host_u16 (tc->c_lcl_port));
if (tepi != TRANSPORT_ENDPOINT_INVALID_INDEX)
{
tep = pool_elt_at_index (tm->local_endpoints, tepi);
@@ -367,25 +367,24 @@ tcp_allocate_local_port (ip46_address_t * ip)
{
tcp_main_t *tm = vnet_get_tcp_main ();
transport_endpoint_t *tep;
u32 time_now, tei;
u32 tei;
u16 min = 1024, max = 65535; /* XXX configurable ? */
int tries;
int tries, limit;
tries = max - min;
time_now = tcp_time_now ();
limit = max - min;
/* Only support active opens from thread 0 */
ASSERT (vlib_get_thread_index () == 0);
/* Search for first free slot */
for (; tries >= 0; tries--)
for (tries = 0; tries < limit; tries++)
{
u16 port = 0;
/* Find a port in the specified range */
while (1)
{
port = random_u32 (&time_now) & PORT_MASK;
port = random_u32 (&tm->port_allocator_seed) & PORT_MASK;
if (PREDICT_TRUE (port >= min && port < max))
break;
}
@@ -1189,8 +1188,9 @@ tcp_main_enable (vlib_main_t * vm)
vlib_thread_main_t *vtm = vlib_get_thread_main ();
clib_error_t *error = 0;
u32 num_threads;
int thread, i;
int i, thread;
tcp_connection_t *tc __attribute__ ((unused));
u32 preallocated_connections_per_thread;
if ((error = vlib_call_init_function (vm, ip_main_init)))
return error;
@@ -1224,14 +1224,26 @@ tcp_main_enable (vlib_main_t * vm)
vec_validate (tm->connections, num_threads - 1);
/*
* Preallocate connections
* Preallocate connections. Assume that thread 0 won't
* use preallocated threads when running multi-core
*/
for (thread = 0; thread < num_threads; thread++)
if (num_threads == 1)
{
for (i = 0; i < tm->preallocated_connections; i++)
thread = 0;
preallocated_connections_per_thread = tm->preallocated_connections;
}
else
{
thread = 1;
preallocated_connections_per_thread =
tm->preallocated_connections / (num_threads - 1);
}
for (; thread < num_threads; thread++)
{
for (i = 0; i < preallocated_connections_per_thread; i++)
pool_get (tm->connections[thread], tc);
for (i = 0; i < tm->preallocated_connections; i++)
for (i = 0; i < preallocated_connections_per_thread; i++)
pool_put_index (tm->connections[thread], i);
}
@@ -1257,13 +1269,21 @@ tcp_main_enable (vlib_main_t * vm)
/ TCP_TSTAMP_RESOLUTION;
clib_bihash_init_24_8 (&tm->local_endpoints_table, "local endpoint table",
200000 /* $$$$ config parameter nbuckets */ ,
(64 << 20) /*$$$ config parameter table size */ );
1000000 /* $$$$ config parameter nbuckets */ ,
(512 << 20) /*$$$ config parameter table size */ );
/* Initialize [port-allocator] random number seed */
tm->port_allocator_seed = (u32) clib_cpu_time_now ();
if (num_threads > 1)
{
clib_spinlock_init (&tm->half_open_lock);
clib_spinlock_init (&tm->local_endpoints_lock);
}
vec_validate (tm->tx_frames[0], num_threads - 1);
vec_validate (tm->tx_frames[1], num_threads - 1);
return error;
}
@@ -1289,16 +1309,12 @@ clib_error_t *
tcp_init (vlib_main_t * vm)
{
tcp_main_t *tm = vnet_get_tcp_main ();
tm->vnet_main = vnet_get_main ();
tm->is_enabled = 0;
return 0;
}
VLIB_INIT_FUNCTION (tcp_init);
static clib_error_t *
tcp_config_fn (vlib_main_t * vm, unformat_input_t * input)
{
+7 -5
View File
@@ -369,6 +369,8 @@ typedef struct _tcp_main
/** per-worker tx buffer free lists */
u32 **tx_buffers;
/** per-worker tx frames to 4/6 output nodes */
vlib_frame_t **tx_frames[2];
/* Per worker-thread timer wheel for connections timers */
tw_timer_wheel_16t_2w_512sl_t *timer_wheels;
@@ -400,11 +402,8 @@ typedef struct _tcp_main
u32 last_v6_address_rotor;
ip6_address_t *ip6_src_addresses;
/* convenience */
vlib_main_t *vlib_main;
vnet_main_t *vnet_main;
ip4_main_t *ip4_main;
ip6_main_t *ip6_main;
/** Port allocator random number generator seed */
u32 port_allocator_seed;
} tcp_main_t;
extern tcp_main_t tcp_main;
@@ -493,6 +492,8 @@ void tcp_send_fin (tcp_connection_t * tc);
void tcp_init_mss (tcp_connection_t * tc);
void tcp_update_snd_mss (tcp_connection_t * tc);
void tcp_update_rto (tcp_connection_t * tc);
void tcp_flush_frame_to_output (vlib_main_t * vm, u8 thread_index, u8 is_ip4);
void tcp_flush_frames_to_output (u8 thread_index);
always_inline u32
tcp_end_seq (tcp_header_t * th, u32 len)
@@ -614,6 +615,7 @@ tcp_update_time (f64 now, u32 thread_index)
{
tw_timer_expire_timers_16t_2w_512sl (&tcp_main.timer_wheels[thread_index],
now);
tcp_flush_frames_to_output (thread_index);
}
u32 tcp_push_header (transport_connection_t * tconn, vlib_buffer_t * b);
+2
View File
@@ -1751,6 +1751,8 @@ tcp46_established_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
errors = session_manager_flush_enqueue_events (my_thread_index);
tcp_established_inc_counter (vm, is_ip4, TCP_ERROR_EVENT_FIFO_FULL, errors);
tcp_flush_frame_to_output (vm, my_thread_index, is_ip4);
return from_frame->n_vectors;
}
+126 -60
View File
File diff suppressed because it is too large Load Diff
+44 -1
View File
@@ -21,7 +21,7 @@
#include <vlib/threads.h>
#include <vnet/vnet.h>
#include <vppinfra/format.h>
/**
* @brief GDB callable function: vl - Return vector length of vector
@@ -135,6 +135,47 @@ void vlib_runtime_index_to_node_name (u32 index)
fformat(stderr, "node runtime index %d name %s\n", index, nm->nodes[index]->name);
}
void gdb_show_errors (int verbose)
{
extern vlib_cli_command_t vlib_cli_show_errors;
unformat_input_t input;
vlib_main_t * vm = vlib_get_main();
if (verbose == 0)
unformat_init_string (&input, "verbose 0", 9);
else if (verbose == 1)
unformat_init_string (&input, "verbose 1", 9);
else
{
fformat(stderr, "verbose not 0 or 1\n");
return;
}
vlib_cli_show_errors.function (vm, &input, 0 /* cmd */);
unformat_free (&input);
}
void gdb_show_session (int verbose)
{
extern vlib_cli_command_t vlib_cli_show_session_command;
unformat_input_t input;
vlib_main_t * vm = vlib_get_main();
if (verbose == 0)
unformat_init_string (&input, "verbose 0", 9);
else if (verbose == 1)
unformat_init_string (&input, "verbose 1", 9);
else if (verbose == 2)
unformat_init_string (&input, "verbose 2", 9);
else
{
fformat(stderr, "verbose not 0 - 2\n");
return;
}
vlib_cli_show_session_command.function (vm, &input, 0 /* cmd */);
unformat_free (&input);
}
/**
* @brief GDB callable function: show_gdb_command_fn - show gdb
@@ -151,6 +192,8 @@ show_gdb_command_fn (vlib_main_t * vm,
vlib_cli_output (vm, "vl(p) returns vec_len(p)");
vlib_cli_output (vm, "pe(p) returns pool_elts(p)");
vlib_cli_output (vm, "pifi(p, i) returns pool_is_free_index(p, i)");
vlib_cli_output (vm, "gdb_show_errors(0|1) dumps error counters");
vlib_cli_output (vm, "gdb_show_session dumps session counters");
vlib_cli_output (vm, "debug_hex_bytes (ptr, n_bytes) dumps n_bytes in hex");
vlib_cli_output (vm, "vlib_dump_frame_ownership() does what it says");
vlib_cli_output (vm, "vlib_runtime_index_to_node_name (index) prints NN");
+1 -1
View File
@@ -200,7 +200,7 @@ do { \
#define pool_get(P,E) pool_get_aligned(P,E,0)
/** See if pool_get will expand the pool or not */
#define pool_get_aligned_will_expand (P,YESNO,A) \
#define pool_get_aligned_will_expand(P,YESNO,A) \
do { \
pool_header_t * _pool_var (p) = pool_header (P); \
uword _pool_var (l); \