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 663343890EE for ; Tue, 28 Apr 2026 23:15:48 +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=1777418151; cv=none; b=GimaP+bEMWUnT+7vwd6qH0r15NqxLX+x26mY3HHQeyY29fnZzxubmwAYO66J3CXQQq+OCPjuCFWohFPBxWIZ9ach9YVeRXm55JH2GemGWabKgXejCNmJQ60JjBh2sVDMQK9+ZzWL3H+pf+dnf5nLgDLU1ZS5zdRWoe5j4JCyMEU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777418151; c=relaxed/simple; bh=7AaFrcIfI7q/SJMniOdc44UyuVT49gFFRf09II3YAVg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kkfhlIGmb5GCP1AcJHJ+eXOKY3BocsCB8DpuDBMSNNa7Tfx4+JoSuWS7UVtlfWhLdSA45GSMYA18U8DHwg3zN5wl/SmvQpOCbTaVHtSllHx1PpreA83BFu8BIO0vrUyhcLwKgQGvCVAPtkIF4eixyQGV49O6qmJE1USHGFEVRyA= 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=Mr2Dwgwx; 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="Mr2Dwgwx" 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=u8rOoN8HAK36VrdCISGIhH9LjB3S3qHI+2kaQJBQPz0=; t=1777418148; x=1778282148; b=Mr2DwgwxBeFcgCFdsgeZ+TRLM4+AoGaSEXezb/1oVqXq0M+p5jDPy7HEncV+8C6j38EfX14plYj VNzS53trU/+0HpRkVi0fk7ck6RGHsQpjZNe+BGn9NHj4fv6Vi6w/eXe+3FhpJvooo9Zd3kT16TRtP Wn1UFZKqFZdFZYlAMjUynZzLsPRHczTLSUBy24H5Iyz/kLRgyk1AU5JiyYjjj/Pf+HSmlq0bZko/+ jemavj9FLRpdynvu8SO/FzCU+5YV716v9wetIN7MmR1x/l39oH872OM4dydLQ3KUY5Slw+fjGgb3h 8++tidXi5Mg7hIT5C4qW5Mu7JHfrInszKGbw==; Received: from ouster448.stanford.edu ([172.24.72.71]:54475 helo=ouster2022) 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 1wHred-0005UM-2u; Tue, 28 Apr 2026 16:15:48 -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 v19 10/15] net: homa: create homa_utils.c Date: Tue, 28 Apr 2026 16:15:13 -0700 Message-ID: <20260428231520.1857-11-ouster@cs.stanford.edu> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260428231520.1857-1-ouster@cs.stanford.edu> References: <20260428231520.1857-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.1 X-Scan-Signature: d9e551a77958145a553edd5d6e40717d This file contains functions for constructing and destructing homa structs. Signed-off-by: John Ousterhout --- Changes for v16: * Use cpu_relax when spinning Changes for v11: * Move link_mbps variable from struct homa_pacer back to struct homa Changes for v10: * Remove log messages after alloc errors Changes for v9: * Add support for homa_net objects * Use new homa_clock abstraction layer * Various name improvements (e.g. use "alloc" instead of "new" for functions that allocate memory) Changes for v8: * Accommodate homa_pacer refactoring Changes for v7: * Make Homa a pernet subsystem * Add support for tx memory accounting * Remove "lock_slow" functions, which don't add functionality in this patch series * Use u64 and __u64 properly --- net/homa/homa_impl.h | 6 +++ net/homa/homa_utils.c | 110 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 116 insertions(+) create mode 100644 net/homa/homa_utils.c diff --git a/net/homa/homa_impl.h b/net/homa/homa_impl.h index 2446e152227c..dfd62b018315 100644 --- a/net/homa/homa_impl.h +++ b/net/homa/homa_impl.h @@ -361,13 +361,19 @@ static inline bool homa_make_header_avl(struct sk_buff *skb) extern unsigned int homa_net_id; +void homa_destroy(struct homa *homa); int homa_fill_data_interleaved(struct homa_rpc *rpc, struct sk_buff *skb, struct iov_iter *iter); +int homa_init(struct homa *homa); int homa_message_out_fill(struct homa_rpc *rpc, struct iov_iter *iter, int xmit); void homa_message_out_init(struct homa_rpc *rpc, int length); +void homa_net_destroy(struct homa_net *hnet); +int homa_net_init(struct homa_net *hnet, struct net *net, + struct homa *homa); void homa_rpc_handoff(struct homa_rpc *rpc); int homa_rpc_tx_end(struct homa_rpc *rpc); +void homa_spin(int ns); 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_utils.c b/net/homa/homa_utils.c new file mode 100644 index 000000000000..df3845fb9417 --- /dev/null +++ b/net/homa/homa_utils.c @@ -0,0 +1,110 @@ +// SPDX-License-Identifier: BSD-2-Clause or GPL-2.0+ + +/* This file contains miscellaneous utility functions for Homa, such + * as initializing and destroying homa structs. + */ + +#include "homa_impl.h" +#include "homa_peer.h" +#include "homa_rpc.h" + +#include "homa_stub.h" + +/** + * homa_init() - Constructor for homa objects. + * @homa: Object to initialize. + * + * Return: 0 on success, or a negative errno if there was an error. Even + * if an error occurs, it is safe (and necessary) to call + * homa_destroy at some point. + */ +int homa_init(struct homa *homa) +{ + int err; + + memset(homa, 0, sizeof(*homa)); + + atomic64_set(&homa->next_outgoing_id, 2); + homa->link_mbps = 25000; + homa->peertab = homa_peer_alloc_peertab(); + if (IS_ERR(homa->peertab)) { + err = PTR_ERR(homa->peertab); + homa->peertab = NULL; + return err; + } + homa->socktab = kmalloc(sizeof(*homa->socktab), GFP_KERNEL); + if (!homa->socktab) + return -ENOMEM; + homa_socktab_init(homa->socktab); + + /* Wild guesses to initialize configuration values... */ + homa->resend_ticks = 5; + homa->resend_interval = 5; + homa->timeout_ticks = 100; + homa->timeout_resends = 5; + homa->request_ack_ticks = 2; + homa->reap_limit = 10; + homa->dead_buffs_limit = 5000; + homa->max_gso_size = 10000; + homa->wmem_max = 100000000; + homa->bpage_lease_usecs = 10000; + return 0; +} + +/** + * homa_destroy() - Destructor for homa objects. + * @homa: Object to destroy. It is safe if this object has already + * been previously destroyed. + */ +void homa_destroy(struct homa *homa) +{ + /* The order of the following cleanups matters! */ + if (homa->socktab) { + homa_socktab_destroy(homa->socktab, NULL); + kfree(homa->socktab); + homa->socktab = NULL; + } + if (homa->peertab) { + homa_peer_free_peertab(homa->peertab); + homa->peertab = NULL; + } +} + +/** + * homa_net_init() - Initialize a new struct homa_net as a per-net subsystem. + * @hnet: Struct to initialzie. + * @net: The network namespace the struct will be associated with. + * @homa: The main Homa data structure to use for the net. + * Return: 0 on success, otherwise a negative errno. + */ +int homa_net_init(struct homa_net *hnet, struct net *net, struct homa *homa) +{ + memset(hnet, 0, sizeof(*hnet)); + hnet->homa = homa; + hnet->prev_default_port = HOMA_MIN_DEFAULT_PORT - 1; + return 0; +} + +/** + * homa_net_destroy() - Release any resources associated with a homa_net. + * @hnet: Object to destroy; must not be used again after this function + * returns. + */ +void homa_net_destroy(struct homa_net *hnet) +{ + homa_socktab_destroy(hnet->homa->socktab, hnet); + homa_peer_free_net(hnet); +} + +/** + * homa_spin() - Delay (without sleeping) for a given time interval. + * @ns: How long to delay (in nanoseconds) + */ +void homa_spin(int ns) +{ + u64 end; + + end = homa_clock() + homa_ns_to_cycles(ns); + while (homa_clock() < end) + cpu_relax(); +} -- 2.43.0