From 45092f8fb277fc45d7dcfa49bd549fbed10d44e7 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Sun, 10 Jul 2016 03:58:40 +0200 Subject: timers: move timer calls out of hot loop We sacrifice a little bit of precision here, but this avoids jockeying around the timers for every packet, when we're sending in bundles anyway to minimize cache misses. Signed-off-by: Jason A. Donenfeld --- src/send.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/send.c b/src/send.c index 6992fd4..b9a95ac 100644 --- a/src/send.c +++ b/src/send.c @@ -132,16 +132,19 @@ struct packet_bundle { static inline void send_off_bundle(struct packet_bundle *bundle, struct wireguard_peer *peer) { struct sk_buff *skb, *next; - bool is_keepalive; + bool is_keepalive, data_sent = false; + if (likely(bundle->first)) + timers_any_authenticated_packet_traversal(peer); for (skb = bundle->first; skb; skb = next) { /* We store the next pointer locally because socket_send_skb_to_peer * consumes the packet before the top of the loop comes again. */ next = skb->next; is_keepalive = skb->len == message_data_len(0); - timers_any_authenticated_packet_traversal(peer); if (likely(!socket_send_skb_to_peer(peer, skb, 0 /* TODO: Should we copy the DSCP value from the enclosed packet? */) && !is_keepalive)) - timers_data_sent(peer); + data_sent = true; } + if (likely(data_sent)) + timers_data_sent(peer); } static void message_create_data_done(struct sk_buff *skb, struct wireguard_peer *peer) -- cgit v1.2.3