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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #include <http/http_timer.h>
17 #include <vnet/session/session.h>
19 http_tw_ctx_t http_tw_ctx;
22 http_timer_process_expired_cb (u32 *expired_timers)
24 http_tw_ctx_t *twc = &http_tw_ctx;
28 for (i = 0; i < vec_len (expired_timers); i++)
30 /* Get session handle. The first bit is the timer id */
31 hs_handle = expired_timers[i] & 0x7FFFFFFF;
32 session_send_rpc_evt_to_thread (hs_handle >> 24, twc->cb_fn,
33 uword_to_pointer (hs_handle, void *));
38 http_timer_process (vlib_main_t *vm, vlib_node_runtime_t *rt, vlib_frame_t *f)
40 http_tw_ctx_t *twc = &http_tw_ctx;
41 f64 now, timeout = 1.0;
42 uword *event_data = 0;
43 uword __clib_unused event_type;
47 vlib_process_wait_for_event_or_clock (vm, timeout);
48 now = vlib_time_now (vm);
49 event_type = vlib_process_get_events (vm, (uword **) &event_data);
52 clib_spinlock_lock (&twc->tw_lock);
53 tw_timer_expire_timers_2t_1w_2048sl (&twc->tw, now);
54 clib_spinlock_unlock (&twc->tw_lock);
56 vec_reset_length (event_data);
61 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,
69 http_timers_init (vlib_main_t *vm, http_conn_timeout_fn *cb_fn)
71 http_tw_ctx_t *twc = &http_tw_ctx;
74 tw_timer_wheel_init_2t_1w_2048sl (&twc->tw, http_timer_process_expired_cb,
75 1.0 /* timer interval */, ~0);
76 clib_spinlock_init (&twc->tw_lock);
79 vlib_node_set_state (vm, http_timer_process_node.index,
80 VLIB_NODE_STATE_POLLING);
81 n = vlib_get_node (vm, http_timer_process_node.index);
82 vlib_start_process (vm, n->runtime_index);
86 * fd.io coding-style-patch-verification: ON
89 * eval: (c-set-style "gnu")