netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Jason A. Donenfeld" <Jason@zx2c4.com>
To: davem@davemloft.net, netdev@vger.kernel.org
Cc: "Jason A. Donenfeld" <Jason@zx2c4.com>,
	Matt Dunwoodie <ncon@noconroy.net>
Subject: [PATCH v2 net 2/3] wireguard: receive: reset last_under_load to zero
Date: Fri, 14 Feb 2020 18:34:06 +0100	[thread overview]
Message-ID: <20200214173407.52521-3-Jason@zx2c4.com> (raw)
In-Reply-To: <20200214173407.52521-1-Jason@zx2c4.com>

This is a small optimization that prevents more expensive comparisons
from happening when they are no longer necessary, by clearing the
last_under_load variable whenever we wind up in a state where we were
under load but we no longer are.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Suggested-by: Matt Dunwoodie <ncon@noconroy.net>
---
 drivers/net/wireguard/receive.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/net/wireguard/receive.c b/drivers/net/wireguard/receive.c
index 9c6bab9c981f..4a153894cee2 100644
--- a/drivers/net/wireguard/receive.c
+++ b/drivers/net/wireguard/receive.c
@@ -118,10 +118,13 @@ static void wg_receive_handshake_packet(struct wg_device *wg,
 
 	under_load = skb_queue_len(&wg->incoming_handshakes) >=
 		     MAX_QUEUED_INCOMING_HANDSHAKES / 8;
-	if (under_load)
+	if (under_load) {
 		last_under_load = ktime_get_coarse_boottime_ns();
-	else if (last_under_load)
+	} else if (last_under_load) {
 		under_load = !wg_birthdate_has_expired(last_under_load, 1);
+		if (!under_load)
+			last_under_load = 0;
+	}
 	mac_state = wg_cookie_validate_packet(&wg->cookie_checker, skb,
 					      under_load);
 	if ((under_load && mac_state == VALID_MAC_WITH_COOKIE) ||
-- 
2.25.0


  parent reply	other threads:[~2020-02-14 17:34 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-14 17:34 [PATCH v2 net 0/3] wireguard fixes for 5.6-rc2 Jason A. Donenfeld
2020-02-14 17:34 ` [PATCH v2 net 1/3] wireguard: selftests: reduce complexity and fix make races Jason A. Donenfeld
2020-02-14 17:34 ` Jason A. Donenfeld [this message]
2020-02-14 17:34 ` [PATCH v2 net 3/3] wireguard: send: account for mtu=0 devices Jason A. Donenfeld
2020-02-14 17:56   ` Eric Dumazet
2020-02-14 18:15     ` Jason A. Donenfeld
2020-02-14 18:22       ` Eric Dumazet
2020-02-14 18:37         ` Jason A. Donenfeld
2020-02-14 18:53           ` Eric Dumazet
2020-02-14 21:57             ` Jason A. Donenfeld
2020-02-14 22:30               ` Eric Dumazet
2020-02-14 22:53                 ` Jason A. Donenfeld

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200214173407.52521-3-Jason@zx2c4.com \
    --to=jason@zx2c4.com \
    --cc=davem@davemloft.net \
    --cc=ncon@noconroy.net \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).