LCOV - code coverage report
Current view: top level - vnet/tcp - tcp_timer.h (source / functions) Hit Total Coverage
Test: coverage-filtered.info Lines: 41 51 80.4 %
Date: 2023-07-05 22:20:52 Functions: 9 11 81.8 %

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2016-2019 Cisco and/or its affiliates.
       3             :  * Licensed under the Apache License, Version 2.0 (the "License");
       4             :  * you may not use this file except in compliance with the License.
       5             :  * You may obtain a copy of the License at:
       6             :  *
       7             :  *     http://www.apache.org/licenses/LICENSE-2.0
       8             :  *
       9             :  * Unless required by applicable law or agreed to in writing, software
      10             :  * distributed under the License is distributed on an "AS IS" BASIS,
      11             :  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      12             :  * See the License for the specific language governing permissions and
      13             :  * limitations under the License.
      14             :  */
      15             : #ifndef __included_tcp_timer_h__
      16             : #define __included_tcp_timer_h__
      17             : 
      18             : #include <vnet/tcp/tcp_types.h>
      19             : 
      20             : static inline u8
      21       46790 : tcp_timer_thread_is_valid (tcp_connection_t *tc)
      22             : {
      23       46790 :   return ((tc->c_thread_index == vlib_get_thread_index ()) ||
      24           0 :           vlib_thread_is_main_w_barrier ());
      25             : }
      26             : 
      27             : always_inline void
      28        2324 : tcp_timer_set (tcp_timer_wheel_t *tw, tcp_connection_t *tc, u8 timer_id,
      29             :                u32 interval)
      30             : {
      31        2324 :   ASSERT (tcp_timer_thread_is_valid (tc));
      32        2324 :   ASSERT (tc->timers[timer_id] == TCP_TIMER_HANDLE_INVALID);
      33        2324 :   tc->timers[timer_id] = tw_timer_start_tcp_twsl (tw, tc->c_c_index,
      34             :                                                   timer_id, interval);
      35        2324 : }
      36             : 
      37             : always_inline void
      38        4803 : tcp_timer_reset (tcp_timer_wheel_t * tw, tcp_connection_t * tc, u8 timer_id)
      39             : {
      40        4803 :   ASSERT (tcp_timer_thread_is_valid (tc));
      41        4803 :   tc->pending_timers &= ~(1 << timer_id);
      42        4803 :   if (tc->timers[timer_id] == TCP_TIMER_HANDLE_INVALID)
      43        1838 :     return;
      44             : 
      45        2965 :   tw_timer_stop_tcp_twsl (tw, tc->timers[timer_id]);
      46        2965 :   tc->timers[timer_id] = TCP_TIMER_HANDLE_INVALID;
      47             : }
      48             : 
      49             : always_inline void
      50       39663 : tcp_timer_update (tcp_timer_wheel_t * tw, tcp_connection_t * tc, u8 timer_id,
      51             :                   u32 interval)
      52             : {
      53       39663 :   ASSERT (tcp_timer_thread_is_valid (tc));
      54       39663 :   if (tc->timers[timer_id] != TCP_TIMER_HANDLE_INVALID)
      55       38878 :     tw_timer_update_tcp_twsl (tw, tc->timers[timer_id], interval);
      56             :   else
      57         785 :     tc->timers[timer_id] = tw_timer_start_tcp_twsl (tw, tc->c_c_index,
      58             :                                                     timer_id, interval);
      59       39663 : }
      60             : 
      61             : always_inline u8
      62     1062303 : tcp_timer_is_active (tcp_connection_t *tc, tcp_timers_e timer)
      63             : {
      64     2084400 :   return tc->timers[timer] != TCP_TIMER_HANDLE_INVALID ||
      65     1022087 :          (tc->pending_timers & (1 << timer));
      66             : }
      67             : 
      68             : always_inline void
      69        1937 : tcp_retransmit_timer_set (tcp_timer_wheel_t * tw, tcp_connection_t * tc)
      70             : {
      71        1937 :   ASSERT (tc->snd_una != tc->snd_nxt);
      72        1937 :   tcp_timer_set (tw, tc, TCP_TIMER_RETRANSMIT,
      73        1937 :                  clib_max ((u32) tc->rto * TCP_TO_TIMER_TICK, 1));
      74        1937 : }
      75             : 
      76             : always_inline void
      77        2063 : tcp_retransmit_timer_reset (tcp_timer_wheel_t * tw, tcp_connection_t * tc)
      78             : {
      79        2063 :   tcp_timer_reset (tw, tc, TCP_TIMER_RETRANSMIT);
      80        2063 : }
      81             : 
      82             : always_inline void
      83           0 : tcp_persist_timer_set (tcp_timer_wheel_t * tw, tcp_connection_t * tc)
      84             : {
      85             :   /* Reuse RTO. It's backed off in handler */
      86           0 :   tcp_timer_set (tw, tc, TCP_TIMER_PERSIST,
      87           0 :                  clib_max ((u32) tc->rto * TCP_TO_TIMER_TICK, 1));
      88           0 : }
      89             : 
      90             : always_inline void
      91           0 : tcp_persist_timer_reset (tcp_timer_wheel_t * tw, tcp_connection_t * tc)
      92             : {
      93           0 :   tcp_timer_reset (tw, tc, TCP_TIMER_PERSIST);
      94           0 : }
      95             : 
      96             : always_inline void
      97       41208 : tcp_retransmit_timer_update (tcp_timer_wheel_t * tw, tcp_connection_t * tc)
      98             : {
      99       41208 :   if (tc->snd_una == tc->snd_nxt)
     100             :     {
     101        1931 :       tcp_retransmit_timer_reset (tw, tc);
     102        1931 :       if (tc->snd_wnd < tc->snd_mss &&
     103           0 :           !tcp_timer_is_active (tc, TCP_TIMER_PERSIST))
     104           0 :         tcp_persist_timer_set (tw, tc);
     105             :     }
     106             :   else
     107       39277 :     tcp_timer_update (tw, tc, TCP_TIMER_RETRANSMIT,
     108       39277 :                       clib_max ((u32) tc->rto * TCP_TO_TIMER_TICK, 1));
     109       41208 : }
     110             : 
     111             : always_inline void
     112    74947900 : tcp_timer_expire_timers (tcp_timer_wheel_t * tw, f64 now)
     113             : {
     114    74947900 :   tw_timer_expire_timers_tcp_twsl (tw, now);
     115    74949600 : }
     116             : 
     117             : void tcp_timer_initialize_wheel (tcp_timer_wheel_t * tw,
     118             :                                  void (*expired_timer_cb) (u32 *), f64 now);
     119             : 
     120             : #endif /* __included_tcp_timer_h__ */
     121             : 
     122             : /*
     123             :  * fd.io coding-style-patch-verification: ON
     124             :  *
     125             :  * Local Variables:
     126             :  * eval: (c-set-style "gnu")
     127             :  * End:
     128             :  */

Generated by: LCOV version 1.14