tcp: custom geometry for timer wheel

Type: refactor

Signed-off-by: Florin Coras <fcoras@cisco.com>
Change-Id: I04f992e5d91d21f1e5bbafef070478cfe268d94a
This commit is contained in:
Florin Coras
2020-10-08 09:28:32 -07:00
committed by Dave Barach
parent 1046b1a631
commit 49036a5e82
5 changed files with 83 additions and 25 deletions
+1
View File
@@ -623,6 +623,7 @@ list(APPEND VNET_SOURCES
tcp/tcp_cubic.c
tcp/tcp_debug.c
tcp/tcp_sack.c
tcp/tcp_timer.c
tcp/tcp.c
)
+5 -17
View File
@@ -1146,7 +1146,7 @@ tcp_update_time (f64 now, u8 thread_index)
tcp_set_time_now (wrk);
tcp_handle_cleanups (wrk, now);
tw_timer_expire_timers_16t_2w_512sl (&wrk->timer_wheel, now);
tcp_timer_expire_timers (&wrk->timer_wheel, now);
tcp_dispatch_pending_timers (wrk);
}
@@ -1267,21 +1267,6 @@ tcp_expired_timers_dispatch (u32 * expired_timers)
session_queue_run_on_main_thread (wrk->vm);
}
static void
tcp_initialize_timer_wheels (tcp_main_t * tm)
{
vlib_main_t *vm = vlib_get_main ();
tw_timer_wheel_16t_2w_512sl_t *tw;
/* *INDENT-OFF* */
foreach_vlib_main (({
tw = &tm->wrk_ctx[ii].timer_wheel;
tw_timer_wheel_init_16t_2w_512sl (tw, tcp_expired_timers_dispatch,
TCP_TIMER_TICK, ~0);
tw->last_run_time = vlib_time_now (vm);
}));
/* *INDENT-ON* */
}
static void
tcp_initialize_iss_seed (tcp_main_t * tm)
{
@@ -1357,6 +1342,10 @@ tcp_main_enable (vlib_main_t * vm)
*/
if ((thread > 0 || num_threads == 1) && prealloc_conn_per_wrk)
pool_init_fixed (wrk->connections, prealloc_conn_per_wrk);
tcp_timer_initialize_wheel (&wrk->timer_wheel,
tcp_expired_timers_dispatch,
vlib_time_now (vm));
}
/*
@@ -1371,7 +1360,6 @@ tcp_main_enable (vlib_main_t * vm)
clib_spinlock_init (&tm->half_open_lock);
}
tcp_initialize_timer_wheels (tm);
tcp_initialize_iss_seed (tm);
tm->bytes_per_buffer = vlib_buffer_get_default_data_size (vm);
+33
View File
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2020 Cisco and/or its affiliates.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <vnet/tcp/tcp_timer.h>
#include <vppinfra/tw_timer_template.c>
void
tcp_timer_initialize_wheel (tcp_timer_wheel_t * tw,
void (*expired_timer_cb) (u32 *), f64 now)
{
tw_timer_wheel_init_tcp_twsl (tw, expired_timer_cb, TCP_TIMER_TICK, ~0);
tw->last_run_time = now;
}
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/
+15 -6
View File
@@ -23,8 +23,8 @@ tcp_timer_set (tcp_timer_wheel_t * tw, tcp_connection_t * tc, u8 timer_id,
{
ASSERT (tc->c_thread_index == vlib_get_thread_index ());
ASSERT (tc->timers[timer_id] == TCP_TIMER_HANDLE_INVALID);
tc->timers[timer_id] = tw_timer_start_16t_2w_512sl (tw, tc->c_c_index,
timer_id, interval);
tc->timers[timer_id] = tw_timer_start_tcp_twsl (tw, tc->c_c_index,
timer_id, interval);
}
always_inline void
@@ -35,7 +35,7 @@ tcp_timer_reset (tcp_timer_wheel_t * tw, tcp_connection_t * tc, u8 timer_id)
if (tc->timers[timer_id] == TCP_TIMER_HANDLE_INVALID)
return;
tw_timer_stop_16t_2w_512sl (tw, tc->timers[timer_id]);
tw_timer_stop_tcp_twsl (tw, tc->timers[timer_id]);
tc->timers[timer_id] = TCP_TIMER_HANDLE_INVALID;
}
@@ -45,10 +45,10 @@ tcp_timer_update (tcp_timer_wheel_t * tw, tcp_connection_t * tc, u8 timer_id,
{
ASSERT (tc->c_thread_index == vlib_get_thread_index ());
if (tc->timers[timer_id] != TCP_TIMER_HANDLE_INVALID)
tw_timer_update_16t_2w_512sl (tw, tc->timers[timer_id], interval);
tw_timer_update_tcp_twsl (tw, tc->timers[timer_id], interval);
else
tc->timers[timer_id] = tw_timer_start_16t_2w_512sl (tw, tc->c_c_index,
timer_id, interval);
tc->timers[timer_id] = tw_timer_start_tcp_twsl (tw, tc->c_c_index,
timer_id, interval);
}
always_inline void
@@ -120,6 +120,15 @@ tcp_timer_is_active (tcp_connection_t * tc, tcp_timers_e timer)
return tc->timers[timer] != TCP_TIMER_HANDLE_INVALID;
}
always_inline void
tcp_timer_expire_timers (tcp_timer_wheel_t * tw, f64 now)
{
tw_timer_expire_timers_tcp_twsl (tw, now);
}
void tcp_timer_initialize_wheel (tcp_timer_wheel_t * tw,
void (*expired_timer_cb) (u32 *), f64 now);
#endif /* __included_tcp_timer_h__ */
/*
+29 -2
View File
@@ -20,7 +20,6 @@
#include <vppinfra/rbtree.h>
#include <vnet/tcp/tcp_packet.h>
#include <vnet/session/transport.h>
#include <vppinfra/tw_timer_16t_2w_512sl.h>
#define TCP_TICK 0.000001 /**< TCP tick period (s) */
#define THZ (u32) (1/TCP_TICK) /**< TCP tick frequency */
@@ -447,7 +446,35 @@ tcp_get_connection_from_transport (transport_connection_t * tconn)
return (tcp_connection_t *) tconn;
}
typedef tw_timer_wheel_16t_2w_512sl_t tcp_timer_wheel_t;
/*
* Define custom timer wheel geometry
*/
#undef TW_TIMER_WHEELS
#undef TW_SLOTS_PER_RING
#undef TW_RING_SHIFT
#undef TW_RING_MASK
#undef TW_TIMERS_PER_OBJECT
#undef LOG2_TW_TIMERS_PER_OBJECT
#undef TW_SUFFIX
#undef TW_OVERFLOW_VECTOR
#undef TW_FAST_WHEEL_BITMAP
#undef TW_TIMER_ALLOW_DUPLICATE_STOP
#undef TW_START_STOP_TRACE_SIZE
#define TW_TIMER_WHEELS 2
#define TW_SLOTS_PER_RING 512
#define TW_RING_SHIFT 9
#define TW_RING_MASK (TW_SLOTS_PER_RING -1)
#define TW_TIMERS_PER_OBJECT 16
#define LOG2_TW_TIMERS_PER_OBJECT 4
#define TW_SUFFIX _tcp_twsl
#define TW_FAST_WHEEL_BITMAP 0
#define TW_TIMER_ALLOW_DUPLICATE_STOP 1
#include <vppinfra/tw_timer_template.h>
typedef tw_timer_wheel_tcp_twsl_t tcp_timer_wheel_t;
#endif /* SRC_VNET_TCP_TCP_TYPES_H_ */