summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorFlorin Coras <fcoras@cisco.com>2020-02-12 01:24:29 +0000
committerDave Barach <openvpp@barachs.net>2020-02-12 20:43:45 +0000
commit0426185e65f4f1e001e62375c819fc8ed49a544d (patch)
tree6bd2ff0fb0fb79b99220701ac17f787e6875e2dc /src
parent8727acdd92ca67ae4ee6c7681dd9e862c0d6d000 (diff)
tcp: move connections to wrk ctx
Type: refactor Signed-off-by: Florin Coras <fcoras@cisco.com> Change-Id: I06cc3f032a72eacc716eed8d6fe8856a2839def1
Diffstat (limited to 'src')
-rw-r--r--src/plugins/unittest/tcp_test.c14
-rw-r--r--src/vnet/tcp/tcp.c46
-rw-r--r--src/vnet/tcp/tcp.h48
3 files changed, 50 insertions, 58 deletions
diff --git a/src/plugins/unittest/tcp_test.c b/src/plugins/unittest/tcp_test.c
index bdd74c8bc0a..a485823ffc7 100644
--- a/src/plugins/unittest/tcp_test.c
+++ b/src/plugins/unittest/tcp_test.c
@@ -815,7 +815,6 @@ static int
tcp_test_lookup (vlib_main_t * vm, unformat_input_t * input)
{
session_main_t *smm = &session_main;
- tcp_main_t *tm = &tcp_main;
transport_connection_t _tc1, *tc1 = &_tc1, _tc2, *tc2 = &_tc2, *tconn;
tcp_connection_t *tc;
session_t *s, *s1;
@@ -829,9 +828,7 @@ tcp_test_lookup (vlib_main_t * vm, unformat_input_t * input)
clib_memset (s, 0, sizeof (*s));
s->session_index = sidx = s - smm->wrk[0].sessions;
- pool_get (tm->connections[0], tc);
- clib_memset (tc, 0, sizeof (*tc));
- tc->connection.c_index = tc - tm->connections[0];
+ tc = tcp_connection_alloc (0);
tc->connection.s_index = s->session_index;
s->connection_index = tc->connection.c_index;
@@ -850,9 +847,7 @@ tcp_test_lookup (vlib_main_t * vm, unformat_input_t * input)
clib_memset (s, 0, sizeof (*s));
s->session_index = s - smm->wrk[0].sessions;
- pool_get (tm->connections[0], tc);
- clib_memset (tc, 0, sizeof (*tc));
- tc->connection.c_index = tc - tm->connections[0];
+ tc = tcp_connection_alloc (0);
tc->connection.s_index = s->session_index;
s->connection_index = tc->connection.c_index;
@@ -926,7 +921,6 @@ tcp_test_session (vlib_main_t * vm, unformat_input_t * input)
tcp_connection_t *tc0;
ip4_address_t local, remote;
u16 local_port, remote_port;
- tcp_main_t *tm = vnet_get_tcp_main ();
int is_add = 1;
@@ -947,12 +941,10 @@ tcp_test_session (vlib_main_t * vm, unformat_input_t * input)
local_port = clib_host_to_net_u16 (1234);
remote_port = clib_host_to_net_u16 (11234);
- pool_get (tm->connections[0], tc0);
- clib_memset (tc0, 0, sizeof (*tc0));
+ tc0 = tcp_connection_alloc (0);
tc0->state = TCP_STATE_ESTABLISHED;
tc0->rcv_las = 1;
- tc0->c_c_index = tc0 - tm->connections[0];
tc0->c_lcl_port = local_port;
tc0->c_rmt_port = remote_port;
tc0->c_is_ip4 = 1;
diff --git a/src/vnet/tcp/tcp.c b/src/vnet/tcp/tcp.c
index c3fa6d49da5..ec24082347f 100644
--- a/src/vnet/tcp/tcp.c
+++ b/src/vnet/tcp/tcp.c
@@ -237,8 +237,6 @@ tcp_half_open_connection_new (void)
void
tcp_connection_cleanup (tcp_connection_t * tc)
{
- tcp_main_t *tm = &tcp_main;
-
TCP_EVT (TCP_EVT_DELETE, tc);
/* Cleanup local endpoint if this was an active connect */
@@ -257,8 +255,6 @@ tcp_connection_cleanup (tcp_connection_t * tc)
}
else
{
- int thread_index = tc->c_thread_index;
-
/* Make sure all timers are cleared */
tcp_connection_timers_reset (tc);
@@ -274,10 +270,7 @@ tcp_connection_cleanup (tcp_connection_t * tc)
if (tc->cfg_flags & TCP_CFG_F_RATE_SAMPLE)
tcp_bt_cleanup (tc);
- /* Poison the entry */
- if (CLIB_DEBUG > 0)
- clib_memset (tc, 0xFA, sizeof (*tc));
- pool_put (tm->connections[thread_index], tc);
+ tcp_connection_free (tc);
}
}
@@ -298,12 +291,12 @@ tcp_connection_del (tcp_connection_t * tc)
tcp_connection_t *
tcp_connection_alloc (u8 thread_index)
{
- tcp_main_t *tm = vnet_get_tcp_main ();
+ tcp_worker_ctx_t *wrk = tcp_get_worker (thread_index);
tcp_connection_t *tc;
- pool_get (tm->connections[thread_index], tc);
+ pool_get (wrk->connections, tc);
clib_memset (tc, 0, sizeof (*tc));
- tc->c_c_index = tc - tm->connections[thread_index];
+ tc->c_c_index = tc - wrk->connections;
tc->c_thread_index = thread_index;
return tc;
}
@@ -311,12 +304,12 @@ tcp_connection_alloc (u8 thread_index)
tcp_connection_t *
tcp_connection_alloc_w_base (u8 thread_index, tcp_connection_t * base)
{
- tcp_main_t *tm = vnet_get_tcp_main ();
+ tcp_worker_ctx_t *wrk = tcp_get_worker (thread_index);
tcp_connection_t *tc;
- pool_get (tm->connections[thread_index], tc);
+ pool_get (wrk->connections, tc);
clib_memcpy_fast (tc, base, sizeof (*tc));
- tc->c_c_index = tc - tm->connections[thread_index];
+ tc->c_c_index = tc - wrk->connections;
tc->c_thread_index = thread_index;
return tc;
}
@@ -324,15 +317,14 @@ tcp_connection_alloc_w_base (u8 thread_index, tcp_connection_t * base)
void
tcp_connection_free (tcp_connection_t * tc)
{
- tcp_main_t *tm = &tcp_main;
+ tcp_worker_ctx_t *wrk = tcp_get_worker (tc->c_thread_index);
if (CLIB_DEBUG)
{
- u8 thread_index = tc->c_thread_index;
clib_memset (tc, 0xFA, sizeof (*tc));
- pool_put (tm->connections[thread_index], tc);
+ pool_put (wrk->connections, tc);
return;
}
- pool_put (tm->connections[tc->c_thread_index], tc);
+ pool_put (wrk->connections, tc);
}
/**
@@ -1514,6 +1506,7 @@ tcp_main_enable (vlib_main_t * vm)
u32 num_threads, n_workers, prealloc_conn_per_wrk;
tcp_connection_t *tc __attribute__ ((unused));
tcp_main_t *tm = vnet_get_tcp_main ();
+ tcp_worker_ctx_t *wrk;
clib_error_t *error = 0;
int thread;
@@ -1536,25 +1529,28 @@ tcp_main_enable (vlib_main_t * vm)
*/
num_threads = 1 /* main thread */ + vtm->n_threads;
- vec_validate (tm->connections, num_threads - 1);
vec_validate (tm->wrk_ctx, num_threads - 1);
n_workers = num_threads == 1 ? 1 : vtm->n_threads;
prealloc_conn_per_wrk = tcp_cfg.preallocated_connections / n_workers;
for (thread = 0; thread < num_threads; thread++)
{
- vec_validate (tm->wrk_ctx[thread].pending_deq_acked, 255);
- vec_validate (tm->wrk_ctx[thread].pending_disconnects, 255);
- vec_reset_length (tm->wrk_ctx[thread].pending_deq_acked);
- vec_reset_length (tm->wrk_ctx[thread].pending_disconnects);
- tm->wrk_ctx[thread].vm = vlib_mains[thread];
+ wrk = &tm->wrk_ctx[thread];
+
+ vec_validate (wrk->pending_deq_acked, 255);
+ vec_validate (wrk->pending_disconnects, 255);
+ vec_validate (wrk->pending_resets, 255);
+ vec_reset_length (wrk->pending_deq_acked);
+ vec_reset_length (wrk->pending_disconnects);
+ vec_reset_length (wrk->pending_resets);
+ wrk->vm = vlib_mains[thread];
/*
* Preallocate connections. Assume that thread 0 won't
* use preallocated threads when running multi-core
*/
if ((thread > 0 || num_threads == 1) && prealloc_conn_per_wrk)
- pool_init_fixed (tm->connections[thread], prealloc_conn_per_wrk);
+ pool_init_fixed (wrk->connections, prealloc_conn_per_wrk);
}
/*
diff --git a/src/vnet/tcp/tcp.h b/src/vnet/tcp/tcp.h
index 36e98a98dd6..59ccf8f1a73 100644
--- a/src/vnet/tcp/tcp.h
+++ b/src/vnet/tcp/tcp.h
@@ -506,11 +506,8 @@ typedef struct tcp_worker_ctx_
{
CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
- /** tx buffer free list */
- u32 *tx_buffers;
-
- /** tx frames for ip 4/6 lookup nodes */
- vlib_frame_t *ip_lookup_tx_frames[2];
+ /** worker's pool of connections */
+ tcp_connection_t *connections;
/** vector of pending ack dequeues */
u32 *pending_deq_acked;
@@ -518,6 +515,7 @@ typedef struct tcp_worker_ctx_
/** vector of pending disconnect notifications */
u32 *pending_disconnects;
+ /** vector of pending reset notifications */
u32 *pending_resets;
/** convenience pointer to this thread's vlib main */
@@ -526,11 +524,17 @@ typedef struct tcp_worker_ctx_
/** worker time */
u32 time_now;
+ /** tx frames for ip 4/6 lookup nodes */
+ vlib_frame_t *ip_lookup_tx_frames[2];
+
CLIB_CACHE_LINE_ALIGN_MARK (cacheline1);
/** cached 'on the wire' options for bursts */
u8 cached_opts[40];
+ /** tx buffer free list */
+ u32 *tx_buffers;
+
/** worker timer wheel */
tw_timer_wheel_16t_2w_512sl_t timer_wheel;
@@ -614,27 +618,24 @@ typedef struct tcp_configuration_
typedef struct _tcp_main
{
- /* Per-worker thread tcp connection pools */
- tcp_connection_t **connections;
+ /** per-worker context */
+ tcp_worker_ctx_t *wrk_ctx;
/* Pool of listeners. */
tcp_connection_t *listener_pool;
+ f64 tstamp_ticks_per_clock;
+
+ /** vlib buffer size */
+ u32 bytes_per_buffer;
+
/** Dispatch table by state and flags */
tcp_lookup_dispatch_t dispatch_table[TCP_N_STATES][64];
- u8 log2_tstamp_clocks_per_tick;
- f64 tstamp_ticks_per_clock;
-
- /** per-worker context */
- tcp_worker_ctx_t *wrk_ctx;
+ clib_spinlock_t half_open_lock;
/** Pool of half-open connections on which we've sent a SYN */
tcp_connection_t *half_open_connections;
- clib_spinlock_t half_open_lock;
-
- /** vlib buffer size */
- u32 bytes_per_buffer;
/** Seed used to generate random iss */
tcp_iss_seed_t iss_seed;
@@ -694,6 +695,7 @@ vnet_get_tcp_main ()
always_inline tcp_worker_ctx_t *
tcp_get_worker (u32 thread_index)
{
+ ASSERT (thread_index < vec_len (tcp_main.wrk_ctx));
return &tcp_main.wrk_ctx[thread_index];
}
@@ -721,20 +723,22 @@ void tcp_punt_unknown (vlib_main_t * vm, u8 is_ip4, u8 is_add);
always_inline tcp_connection_t *
tcp_connection_get (u32 conn_index, u32 thread_index)
{
- if (PREDICT_FALSE
- (pool_is_free_index (tcp_main.connections[thread_index], conn_index)))
+ tcp_worker_ctx_t *wrk = tcp_get_worker (thread_index);
+ if (PREDICT_FALSE (pool_is_free_index (wrk->connections, conn_index)))
return 0;
- return pool_elt_at_index (tcp_main.connections[thread_index], conn_index);
+ return pool_elt_at_index (wrk->connections, conn_index);
}
always_inline tcp_connection_t *
tcp_connection_get_if_valid (u32 conn_index, u32 thread_index)
{
- if (tcp_main.connections[thread_index] == 0)
+ tcp_worker_ctx_t *wrk;
+ if (thread_index >= vec_len (tcp_main.wrk_ctx))
return 0;
- if (pool_is_free_index (tcp_main.connections[thread_index], conn_index))
+ wrk = tcp_get_worker (thread_index);
+ if (pool_is_free_index (wrk->connections, conn_index))
return 0;
- return pool_elt_at_index (tcp_main.connections[thread_index], conn_index);
+ return pool_elt_at_index (wrk->connections, conn_index);
}
always_inline tcp_connection_t *