From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp1.cs.Stanford.EDU (smtp1.cs.stanford.edu [171.64.64.25]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 96FF727701C for ; Mon, 18 Aug 2025 20:56:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=171.64.64.25 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755550604; cv=none; b=fVhPfxbP6KkizqEzgD6cQok/uyk9KtEkJIdHB9zFDLYiqY6AFopyH8r2uedK+R3RokPiBFxfCfc2IURE2UJCrBGpKuXTRUezDs0tNKX3MEoBbMZ/WKcXGqwrCbi0991sUn5SNZsiwIPj78jptZo7zHFZ2TR4eA60jG9CLQl7xdk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755550604; c=relaxed/simple; bh=kIESrb+oGWQ1OYTD8HCnR78L9UDyXNQo0zVmF2JAWXw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=O11i5tfSt/HLUUv6MlPQiwfZro9FJmrAuPs0IXH6weNVMAid2j6Wix7XG7ny8yVDYcs8roeeahIF8huMnyAmlJmNxZoam4gYffyDvwkCUIrqz2ZJNwK8S+hkWUoaYTlyF7KpmnZQcwdHM1X6fVYWvn+6IqxAFx5iPFbwtVfyvtY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=cs.stanford.edu; spf=pass smtp.mailfrom=cs.stanford.edu; dkim=pass (2048-bit key) header.d=cs.stanford.edu header.i=@cs.stanford.edu header.b=tL6nDzAG; arc=none smtp.client-ip=171.64.64.25 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=cs.stanford.edu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cs.stanford.edu Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=cs.stanford.edu header.i=@cs.stanford.edu header.b="tL6nDzAG" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=cs.stanford.edu; s=cs2308; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=Ebq4fAVswntCZgWHVtr2u7V0AFlOuUDtGAhdgwOI6Kg=; t=1755550602; x=1756414602; b=tL6nDzAGNqzROhLZLQdrNCoaf6u/xcCTVfzC/wYtti7OYiWbqO/Cn02XWQbbh6vVdkX8bxnxgun eE/MoEorN3g/2sCzukSGomYSLuVj+kpemhEATzQ9S1AuVf/aC+dBuiY7OrZ84tJcdSeR6+YwYAo3n ChdePQECKPHMI8ixj/xI7DS+RgokFqlPVgIDdxSFu+yEPlUi6Uji/i2ZzYQR4ai/qH+wfwJG8aByp b7qkN+vUEwEPczbDfaDEAuZ8mrzRevDKgr8lfJ8412mEmJ/RiE76T96GDEO2IbBHMRFOSujsBAi7i F+Qv9yI7UHWgUHSYp4Cb0qcn3GFuJ5eDQMLg==; Received: from ouster448.stanford.edu ([172.24.72.71]:50368 helo=localhost.localdomain) by smtp1.cs.Stanford.EDU with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uo6uH-0001f9-Kd; Mon, 18 Aug 2025 13:56:42 -0700 From: John Ousterhout To: netdev@vger.kernel.org Cc: pabeni@redhat.com, edumazet@google.com, horms@kernel.org, kuba@kernel.org, John Ousterhout Subject: [PATCH net-next v15 13/15] net: homa: create homa_timer.c Date: Mon, 18 Aug 2025 13:55:48 -0700 Message-ID: <20250818205551.2082-14-ouster@cs.stanford.edu> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20250818205551.2082-1-ouster@cs.stanford.edu> References: <20250818205551.2082-1-ouster@cs.stanford.edu> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Score: -101.0 X-Scan-Signature: 0ecaf295db8a04c0f692789316a3d0cf 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 --- Changes for v14: * Use new homa_rpc_tx_end function Changes for v11: * Cleanup sparse annotations. Changes for v10: * Refactor resend mechanism Changes for v9: * Reflect changes in socket and peer management * Minor name changes for clarity Changes for v7: * Interface changes to homa_sock_start_scan etc. * Remove locker argument from locking functions * Use u64 and __u64 properly --- net/homa/homa_impl.h | 3 + net/homa/homa_timer.c | 136 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 139 insertions(+) create mode 100644 net/homa/homa_timer.c diff --git a/net/homa/homa_impl.h b/net/homa/homa_impl.h index 3d91b7f44de9..f28302cb1061 100644 --- a/net/homa/homa_impl.h +++ b/net/homa/homa_impl.h @@ -446,6 +446,9 @@ void homa_resend_pkt(struct sk_buff *skb, struct homa_rpc *rpc, void homa_rpc_handoff(struct homa_rpc *rpc); int homa_rpc_tx_end(struct homa_rpc *rpc); void homa_spin(int ns); +void homa_timer(struct homa *homa); +void homa_timer_check_rpc(struct homa_rpc *rpc); +int homa_timer_main(void *transport); struct sk_buff *homa_tx_data_pkt_alloc(struct homa_rpc *rpc, struct iov_iter *iter, int offset, int length, int max_seg_data); diff --git a/net/homa/homa_timer.c b/net/homa/homa_timer.c new file mode 100644 index 000000000000..dcfdcc06c8ab --- /dev/null +++ b/net/homa/homa_timer.c @@ -0,0 +1,136 @@ +// SPDX-License-Identifier: BSD-2-Clause or GPL-2.0+ + +/* 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" +#include "homa_stub.h" + +/** + * homa_timer_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_timer_check_rpc(struct homa_rpc *rpc) + __must_hold(rpc->bucket->lock) +{ + struct homa *homa = rpc->hsk->homa; + int tx_end = homa_rpc_tx_end(rpc); + + /* See if we need to request an ack for this RPC. */ + if (!homa_is_client(rpc->id) && rpc->state == RPC_OUTGOING && + tx_end == 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 homa_need_ack_hdr 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 (tx_end < rpc->msgout.length) { + /* There are granted 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) + homa_request_retrans(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 rpc_count = 0; + + homa->timer_ticks++; + + /* Scan all existing RPCs in all sockets. */ + for (hsk = homa_socktab_start_scan(homa->socktab, &scan); + hsk; hsk = homa_socktab_next(&scan)) { + while (hsk->dead_skbs >= homa->dead_buffs_limit) + /* If we get here, it means that Homa isn't keeping + * up with RPC reaping, so we'll help out. See + * "RPC Reaping Strategy" in homa_rpc_reap code for + * details. + */ + if (homa_rpc_reap(hsk, false) == 0) + break; + + if (list_empty(&hsk->active_rpcs) || hsk->shutdown) + continue; + + if (!homa_protect_rpcs(hsk)) + continue; + rcu_read_lock(); + list_for_each_entry_rcu(rpc, &hsk->active_rpcs, active_links) { + homa_rpc_lock(rpc); + if (rpc->state == RPC_IN_SERVICE) { + rpc->silent_ticks = 0; + homa_rpc_unlock(rpc); + continue; + } + rpc->silent_ticks++; + homa_timer_check_rpc(rpc); + homa_rpc_unlock(rpc); + rpc_count++; + if (rpc_count >= 10) { + /* Give other kernel threads a chance to run + * on this core. + */ + rcu_read_unlock(); + schedule(); + rcu_read_lock(); + rpc_count = 0; + } + } + rcu_read_unlock(); + homa_unprotect_rpcs(hsk); + } + homa_socktab_end_scan(&scan); + homa_skb_release_pages(homa); + homa_peer_gc(homa->peertab); +} -- 2.43.0