linux-api.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: John Ousterhout <ouster@cs.stanford.edu>
To: netdev@vger.kernel.org, linux-api@vger.kernel.org
Cc: John Ousterhout <ouster@cs.stanford.edu>
Subject: [PATCH net-next v2 10/12] net: homa: create homa_timer.c
Date: Mon, 11 Nov 2024 15:40:03 -0800	[thread overview]
Message-ID: <20241111234006.5942-11-ouster@cs.stanford.edu> (raw)
In-Reply-To: <20241111234006.5942-1-ouster@cs.stanford.edu>

This file contains code that wakes up periodically to check for
missing data, initiate retransmissions, and declare peer nodes
"dead".

Signed-off-by: John Ousterhout <ouster@cs.stanford.edu>
---
 net/homa/homa_timer.c | 156 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 156 insertions(+)
 create mode 100644 net/homa/homa_timer.c

diff --git a/net/homa/homa_timer.c b/net/homa/homa_timer.c
new file mode 100644
index 000000000000..a650d0c5a14f
--- /dev/null
+++ b/net/homa/homa_timer.c
@@ -0,0 +1,156 @@
+// SPDX-License-Identifier: BSD-2-Clause
+
+/* This file handles timing-related functions for Homa, such as retries
+ * and timeouts.
+ */
+
+#include "homa_impl.h"
+#include "homa_peer.h"
+#include "homa_rpc.h"
+
+/**
+ * homa_check_rpc() -  Invoked for each RPC during each timer pass; does
+ * most of the work of checking for time-related actions such as sending
+ * resends, aborting RPCs for which there is no response, and sending
+ * requests for acks. It is separate from homa_timer because homa_timer
+ * got too long and deeply indented.
+ * @rpc:     RPC to check; must be locked by the caller.
+ */
+void homa_check_rpc(struct homa_rpc *rpc)
+{
+	struct homa *homa = rpc->hsk->homa;
+	struct resend_header resend;
+
+	/* See if we need to request an ack for this RPC. */
+	if (!homa_is_client(rpc->id) && rpc->state == RPC_OUTGOING &&
+	    rpc->msgout.next_xmit_offset >= rpc->msgout.length) {
+		if (rpc->done_timer_ticks == 0) {
+			rpc->done_timer_ticks = homa->timer_ticks;
+		} else {
+			/* >= comparison that handles tick wrap-around. */
+			if ((rpc->done_timer_ticks + homa->request_ack_ticks
+					- 1 - homa->timer_ticks) & 1 << 31) {
+				struct need_ack_header h;
+
+				homa_xmit_control(NEED_ACK, &h, sizeof(h), rpc);
+			}
+		}
+	}
+
+	if (rpc->state == RPC_INCOMING) {
+		if (rpc->msgin.num_bpages == 0) {
+			/* Waiting for buffer space, so no problem. */
+			rpc->silent_ticks = 0;
+			return;
+		}
+	} else if (!homa_is_client(rpc->id)) {
+		/* We're the server and we've received the input message;
+		 * no need to worry about retries.
+		 */
+		rpc->silent_ticks = 0;
+		return;
+	}
+
+	if (rpc->state == RPC_OUTGOING) {
+		if (rpc->msgout.next_xmit_offset < rpc->msgout.length) {
+			/* There are bytes that we haven't transmitted,
+			 * so no need to be concerned; the ball is in our court.
+			 */
+			rpc->silent_ticks = 0;
+			return;
+		}
+	}
+
+	if (rpc->silent_ticks < homa->resend_ticks)
+		return;
+	if (rpc->silent_ticks >= homa->timeout_ticks) {
+		homa_rpc_abort(rpc, -ETIMEDOUT);
+		return;
+	}
+	if (((rpc->silent_ticks - homa->resend_ticks) % homa->resend_interval)
+			!= 0)
+		return;
+
+	/* Issue a resend for the bytes just after the last ones received
+	 * (gaps in the middle were already handled by homa_gap_retry above).
+	 */
+	if (rpc->msgin.length < 0) {
+		/* Haven't received any data for this message; request
+		 * retransmission of just the first packet (the sender
+		 * will send at least one full packet, regardless of
+		 * the length below).
+		 */
+		resend.offset = htonl(0);
+		resend.length = htonl(100);
+	} else {
+		homa_gap_retry(rpc);
+		resend.offset = htonl(rpc->msgin.recv_end);
+		resend.length = htonl(rpc->msgin.length - rpc->msgin.recv_end);
+		if (resend.length == 0)
+			return;
+	}
+	homa_xmit_control(RESEND, &resend, sizeof(resend), rpc);
+}
+
+/**
+ * homa_timer() - This function is invoked at regular intervals ("ticks")
+ * to implement retries and aborts for Homa.
+ * @homa:    Overall data about the Homa protocol implementation.
+ */
+void homa_timer(struct homa *homa)
+{
+	struct homa_socktab_scan scan;
+	struct homa_sock *hsk;
+	struct homa_rpc *rpc;
+	int total_rpcs = 0;
+	int rpc_count = 0;
+
+	homa->timer_ticks++;
+
+	/* Scan all existing RPCs in all sockets.  The rcu_read_lock
+	 * below prevents sockets from being deleted during the scan.
+	 */
+	rcu_read_lock();
+	for (hsk = homa_socktab_start_scan(homa->port_map, &scan);
+			hsk; hsk = homa_socktab_next(&scan)) {
+		while (hsk->dead_skbs >= homa->dead_buffs_limit)
+			/* If we get here, it means that homa_wait_for_message
+			 * isn't keeping up with RPC reaping, so we'll help
+			 * out.  See reap.txt for more info.
+			 */
+			if (homa_rpc_reap(hsk, hsk->homa->reap_limit) == 0)
+				break;
+
+		if (list_empty(&hsk->active_rpcs) || hsk->shutdown)
+			continue;
+
+		if (!homa_protect_rpcs(hsk))
+			continue;
+		list_for_each_entry_rcu(rpc, &hsk->active_rpcs, active_links) {
+			total_rpcs++;
+			homa_rpc_lock(rpc, "homa_timer");
+			if (rpc->state == RPC_IN_SERVICE) {
+				rpc->silent_ticks = 0;
+				homa_rpc_unlock(rpc);
+				continue;
+			}
+			rpc->silent_ticks++;
+			homa_check_rpc(rpc);
+			homa_rpc_unlock(rpc);
+			rpc_count++;
+			if (rpc_count >= 10) {
+				/* Give other kernel threads a chance to run
+				 * on this core. Must release the RCU read lock
+				 * while doing this.
+				 */
+				rcu_read_unlock();
+				schedule();
+				rcu_read_lock();
+				rpc_count = 0;
+			}
+		}
+		homa_unprotect_rpcs(hsk);
+	}
+	homa_socktab_end_scan(&scan);
+	rcu_read_unlock();
+}
-- 
2.34.1


  parent reply	other threads:[~2024-11-11 23:40 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-11 23:39 [PATCH net-next v2 00/12] Begin upstreaming Homa transport protocol John Ousterhout
2024-11-11 23:39 ` [PATCH net-next v2 01/12] net: homa: define user-visible API for Homa John Ousterhout
2024-11-11 23:39 ` [PATCH net-next v2 02/12] net: homa: define Homa packet formats John Ousterhout
2024-11-11 23:39 ` [PATCH net-next v2 03/12] net: homa: create shared Homa header files John Ousterhout
2024-11-11 23:39 ` [PATCH net-next v2 04/12] net: homa: create homa_pool.h and homa_pool.c John Ousterhout
2024-11-11 23:39 ` [PATCH net-next v2 05/12] net: homa: create homa_rpc.h and homa_rpc.c John Ousterhout
2024-11-11 23:39 ` [PATCH net-next v2 06/12] net: homa: create homa_peer.h and homa_peer.c John Ousterhout
2024-11-11 23:40 ` [PATCH net-next v2 07/12] net: homa: create homa_sock.h and homa_sock.c John Ousterhout
2024-11-11 23:40 ` [PATCH net-next v2 08/12] net: homa: create homa_incoming.c John Ousterhout
2024-11-11 23:40 ` [PATCH net-next v2 09/12] net: homa: create homa_outgoing.c John Ousterhout
2024-11-11 23:40 ` John Ousterhout [this message]
2024-11-11 23:40 ` [PATCH net-next v2 11/12] net: homa: create homa_plumbing.c homa_utils.c John Ousterhout
2024-11-26  5:32   ` D. Wythe
2024-12-04 19:54     ` John Ousterhout
2024-12-02  3:51   ` D. Wythe
2024-12-03  1:51     ` Andrew Lunn
2024-12-09  6:45       ` D. Wythe
2024-12-05 19:49     ` John Ousterhout
2024-12-09  6:56       ` D. Wythe
2024-12-09 16:53         ` John Ousterhout
2024-12-09 17:03           ` John Ousterhout
2024-12-10  5:14             ` D. Wythe
2024-12-10  5:50               ` John Ousterhout
2024-12-10  6:13                 ` D. Wythe
2024-11-11 23:40 ` [PATCH net-next v2 12/12] net: homa: create Makefile and Kconfig John Ousterhout
2024-11-11 23:52   ` Randy Dunlap
2024-11-12  0:11     ` John Ousterhout
2024-11-12  9:36   ` kernel test robot
2024-11-12  9:36   ` kernel test robot
2024-11-12 11:32   ` kernel test robot
2024-11-13 13:52   ` kernel test robot
2024-11-18 21:23     ` John Ousterhout
2024-11-26  4:13       ` D. Wythe
2024-11-26  4:27   ` D. Wythe
2024-12-02 23:27     ` John Ousterhout
2024-11-12  0:15 ` [PATCH net-next v2 00/12] Begin upstreaming Homa transport protocol Joe Damato
2024-11-12  6:06   ` John Ousterhout
2024-11-13  1:48 ` Jakub Kicinski
2024-11-13 18:18   ` John Ousterhout
2024-11-13 17:07 ` Cong Wang
2024-11-14 16:59   ` John Ousterhout
2024-11-14 19:36     ` Randy Dunlap
2024-11-19 21:13     ` John Ousterhout
2024-11-22 21:42       ` Cong Wang

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=20241111234006.5942-11-ouster@cs.stanford.edu \
    --to=ouster@cs.stanford.edu \
    --cc=linux-api@vger.kernel.org \
    --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).