wireguard: testing alternative timer dispatch
Change-Id: I645bb0a31b333a6160c74987dddb3fb50ff154d8
Type: improvement
Signed-off-by: Mohammed Hawari <mohammed@hawari.fr>
diff --git a/src/plugins/wireguard/wireguard_peer.c b/src/plugins/wireguard/wireguard_peer.c
index c4f06be..f47019b 100644
--- a/src/plugins/wireguard/wireguard_peer.c
+++ b/src/plugins/wireguard/wireguard_peer.c
@@ -81,6 +81,7 @@
for (int i = 0; i < WG_N_TIMERS; i++)
{
peer->timers[i] = ~0;
+ peer->timers_dispatched[i] = 0;
}
peer->last_sent_handshake = vlib_time_now (vm) - (REKEY_TIMEOUT + 1);
diff --git a/src/plugins/wireguard/wireguard_peer.h b/src/plugins/wireguard/wireguard_peer.h
old mode 100755
new mode 100644
index 50c0a01..b60c669
--- a/src/plugins/wireguard/wireguard_peer.h
+++ b/src/plugins/wireguard/wireguard_peer.h
@@ -71,6 +71,7 @@
/* Timers */
tw_timer_wheel_16t_2w_512sl_t *timer_wheel;
u32 timers[WG_N_TIMERS];
+ u8 timers_dispatched[WG_N_TIMERS];
u32 timer_handshake_attempts;
u16 persistent_keepalive_interval;
diff --git a/src/plugins/wireguard/wireguard_timer.c b/src/plugins/wireguard/wireguard_timer.c
old mode 100755
new mode 100644
index 7c09617..b245b85
--- a/src/plugins/wireguard/wireguard_timer.c
+++ b/src/plugins/wireguard/wireguard_timer.c
@@ -62,7 +62,6 @@
{
wg_timers_args *a = arg;
wg_peer_t *peer = wg_peer_get (a->peer_idx);
-
start_timer (peer, a->timer_id, a->interval_ticks);
return 0;
}
@@ -75,8 +74,11 @@
.timer_id = timer_id,
.interval_ticks = interval_ticks,
};
-
- vl_api_rpc_call_main_thread (start_timer_thread_fn, (u8 *) & a, sizeof (a));
+ wg_peer_t *peer = wg_peer_get (peer_idx);
+ if (PREDICT_FALSE (!peer->timers_dispatched[timer_id]))
+ if (!clib_atomic_cmp_and_swap (&peer->timers_dispatched[timer_id], 0, 1))
+ vl_api_rpc_call_main_thread (start_timer_thread_fn, (u8 *) &a,
+ sizeof (a));
}
static inline u32
@@ -295,6 +297,9 @@
peer = wg_peer_get (pool_index);
peer->timers[timer_id] = ~0;
+
+ /* Under barrier, no sync needed */
+ peer->timers_dispatched[timer_id] = 0;
}
for (i = 0; i < vec_len (expired_timers); i++)