LCOV - code coverage report
Current view: top level - plugins/http - http_timer.c (source / functions) Hit Total Coverage
Test: coverage-filtered.info Lines: 21 28 75.0 %
Date: 2023-07-05 22:20:52 Functions: 4 5 80.0 %

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2022 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             : 
      16             : #include <http/http_timer.h>
      17             : #include <vnet/session/session.h>
      18             : 
      19             : http_tw_ctx_t http_tw_ctx;
      20             : 
      21             : static void
      22           0 : http_timer_process_expired_cb (u32 *expired_timers)
      23             : {
      24           0 :   http_tw_ctx_t *twc = &http_tw_ctx;
      25             :   u32 hs_handle;
      26             :   int i;
      27             : 
      28           0 :   for (i = 0; i < vec_len (expired_timers); i++)
      29             :     {
      30             :       /* Get session handle. The first bit is the timer id */
      31           0 :       hs_handle = expired_timers[i] & 0x7FFFFFFF;
      32           0 :       session_send_rpc_evt_to_thread (hs_handle >> 24, twc->cb_fn,
      33           0 :                                       uword_to_pointer (hs_handle, void *));
      34             :     }
      35           0 : }
      36             : 
      37             : static uword
      38          49 : http_timer_process (vlib_main_t *vm, vlib_node_runtime_t *rt, vlib_frame_t *f)
      39             : {
      40          49 :   http_tw_ctx_t *twc = &http_tw_ctx;
      41          49 :   f64 now, timeout = 1.0;
      42          49 :   uword *event_data = 0;
      43             :   uword __clib_unused event_type;
      44             : 
      45             :   while (1)
      46             :     {
      47         124 :       vlib_process_wait_for_event_or_clock (vm, timeout);
      48          75 :       now = vlib_time_now (vm);
      49          75 :       event_type = vlib_process_get_events (vm, (uword **) &event_data);
      50             : 
      51             :       /* expire timers */
      52          75 :       clib_spinlock_lock (&twc->tw_lock);
      53          75 :       tw_timer_expire_timers_2t_1w_2048sl (&twc->tw, now);
      54          75 :       clib_spinlock_unlock (&twc->tw_lock);
      55             : 
      56          75 :       vec_reset_length (event_data);
      57             :     }
      58             :   return 0;
      59             : }
      60             : 
      61      126600 : VLIB_REGISTER_NODE (http_timer_process_node) = {
      62             :   .function = http_timer_process,
      63             :   .type = VLIB_NODE_TYPE_PROCESS,
      64             :   .name = "http-timer-process",
      65             :   .state = VLIB_NODE_STATE_DISABLED,
      66             : };
      67             : 
      68             : void
      69          49 : http_timers_init (vlib_main_t *vm, http_conn_timeout_fn *cb_fn)
      70             : {
      71          49 :   http_tw_ctx_t *twc = &http_tw_ctx;
      72             :   vlib_node_t *n;
      73             : 
      74          49 :   tw_timer_wheel_init_2t_1w_2048sl (&twc->tw, http_timer_process_expired_cb,
      75             :                                     1.0 /* timer interval */, ~0);
      76          49 :   clib_spinlock_init (&twc->tw_lock);
      77          49 :   twc->cb_fn = cb_fn;
      78             : 
      79          49 :   vlib_node_set_state (vm, http_timer_process_node.index,
      80             :                        VLIB_NODE_STATE_POLLING);
      81          49 :   n = vlib_get_node (vm, http_timer_process_node.index);
      82          49 :   vlib_start_process (vm, n->runtime_index);
      83          49 : }
      84             : 
      85             : /*
      86             :  * fd.io coding-style-patch-verification: ON
      87             :  *
      88             :  * Local Variables:
      89             :  * eval: (c-set-style "gnu")
      90             :  * End:
      91             :  */

Generated by: LCOV version 1.14