From 995e0af5b5b05d15a7003d3f30fa3ff76ffc12eb Mon Sep 17 00:00:00 2001 From: John Ousterhout Date: Tue, 3 Dec 2024 10:04:09 -0800 Subject: [PATCH] Rename global homa variable to global_homa (Avoid confusion over name) --- homa_impl.h | 2 ++ homa_metrics.c | 10 +++++----- homa_offload.c | 14 ++++++++------ homa_offload.h | 4 ++-- homa_plumbing.c | 26 ++++++++++++++++++-------- test/unit_homa_metrics.c | 6 ++---- test/unit_homa_offload.c | 22 ++++++++++------------ test/unit_homa_plumbing.c | 6 ++---- 8 files changed, 49 insertions(+), 41 deletions(-) diff --git a/homa_impl.h b/homa_impl.h index 728d632..668c13e 100644 --- a/homa_impl.h +++ b/homa_impl.h @@ -1073,6 +1073,8 @@ void unit_hook(char *id); #endif /* __UNIT_TEST__ */ #endif /* See strip.py */ +extern struct homa *global_homa; + void homa_abort_rpcs(struct homa *homa, const struct in6_addr *addr, int port, int error); void homa_abort_sock_rpcs(struct homa_sock *hsk, int error); diff --git a/homa_metrics.c b/homa_metrics.c index 853898b..0800d48 100644 --- a/homa_metrics.c +++ b/homa_metrics.c @@ -8,11 +8,6 @@ DEFINE_PER_CPU(struct homa_metrics, homa_metrics); -/* For functions that are invoked directly by Linux, so they can't be - * passed a struct homa arguments. - */ -extern struct homa *homa; - /** * homa_metric_append() - Formats a new metric and appends it to homa->metrics. * @homa: The new data will appended to the @metrics field of @@ -351,6 +346,8 @@ char *homa_metrics_print(struct homa *homa) */ int homa_metrics_open(struct inode *inode, struct file *file) { + struct homa *homa = global_homa; + /* Collect all of the metrics when the file is opened, and save * these for use by subsequent reads (don't want the metrics to * change between reads). If there are concurrent opens on the @@ -381,6 +378,7 @@ int homa_metrics_open(struct inode *inode, struct file *file) ssize_t homa_metrics_read(struct file *file, char __user *buffer, size_t length, loff_t *offset) { + struct homa *homa = global_homa; size_t copied; if (*offset >= homa->metrics_length) @@ -417,6 +415,8 @@ loff_t homa_metrics_lseek(struct file *file, loff_t offset, int whence) */ int homa_metrics_release(struct inode *inode, struct file *file) { + struct homa *homa = global_homa; + spin_lock(&homa->metrics_lock); homa->metrics_active_opens--; spin_unlock(&homa->metrics_lock); diff --git a/homa_offload.c b/homa_offload.c index d9db318..e4d7ea6 100644 --- a/homa_offload.c +++ b/homa_offload.c @@ -19,8 +19,6 @@ static const struct net_offload homa_offload = { }, }; -extern struct homa *homa; - /* Pointers to TCP's net_offload structures. NULL means homa_gro_hook_tcp * hasn't been called yet. */ @@ -284,6 +282,7 @@ struct sk_buff *homa_gro_receive(struct list_head *held_list, */ __u64 saved_softirq_metric, softirq_ns; struct homa_offload_core *offload_core; + struct homa *homa = global_homa; struct sk_buff *result = NULL; __u64 *softirq_ns_metric; struct data_header *h_new; @@ -461,11 +460,12 @@ struct sk_buff *homa_gro_receive(struct list_head *held_list, * homa_gro_gen2() - When the Gen2 load balancer is being used this function * is invoked by homa_gro_complete to choose a core to handle SoftIRQ for a * batch of packets + * @homa: Overall information about the Homa transport. * @skb: First in a group of packets that are ready to be passed to SoftIRQ. * Information will be updated in the packet so that Linux will * direct it to the chosen core. */ -void homa_gro_gen2(struct sk_buff *skb) +void homa_gro_gen2(struct homa *homa, struct sk_buff *skb) { /* Scan the next several cores in order after the current core, * trying to find one that is not already busy with SoftIRQ processing, @@ -520,11 +520,12 @@ void homa_gro_gen2(struct sk_buff *skb) * homa_gro_gen3() - When the Gen3 load balancer is being used this function * is invoked by homa_gro_complete to choose a core to handle SoftIRQ for a * batch of packets + * @homa: Overall information about the Homa transport. * @skb: First in a group of packets that are ready to be passed to SoftIRQ. * Information will be updated in the packet so that Linux will * direct it to the chosen core. */ -void homa_gro_gen3(struct sk_buff *skb) +void homa_gro_gen3(struct homa *homa, struct sk_buff *skb) { /* See balance.txt for overall design information on the Gen3 * load balancer. @@ -575,6 +576,7 @@ void homa_gro_gen3(struct sk_buff *skb) int homa_gro_complete(struct sk_buff *skb, int hoffset) { struct data_header *h = (struct data_header *)skb_transport_header(skb); + struct homa *homa = global_homa; // tt_record4("homa_gro_complete type %d, id %d, offset %d, count %d", // h->common.type, homa_local_id(h->common.sender_id), @@ -583,9 +585,9 @@ int homa_gro_complete(struct sk_buff *skb, int hoffset) per_cpu(homa_offload_core, raw_smp_processor_id()).held_skb = NULL; if (homa->gro_policy & HOMA_GRO_GEN3) { - homa_gro_gen3(skb); + homa_gro_gen3(homa, skb); } else if (homa->gro_policy & HOMA_GRO_GEN2) { - homa_gro_gen2(skb); + homa_gro_gen2(homa, skb); } else if (homa->gro_policy & HOMA_GRO_IDLE) { int i, core, best; __u64 best_time = ~0; diff --git a/homa_offload.h b/homa_offload.h index 2162891..cdc7b79 100644 --- a/homa_offload.h +++ b/homa_offload.h @@ -74,8 +74,8 @@ struct homa_offload_core { DECLARE_PER_CPU(struct homa_offload_core, homa_offload_core); int homa_gro_complete(struct sk_buff *skb, int thoff); -void homa_gro_gen2(struct sk_buff *skb); -void homa_gro_gen3(struct sk_buff *skb); +void homa_gro_gen2(struct homa *homa, struct sk_buff *skb); +void homa_gro_gen3(struct homa *homa, struct sk_buff *skb); void homa_gro_hook_tcp(void); void homa_gro_unhook_tcp(void); struct sk_buff *homa_gro_receive(struct list_head *gro_list, diff --git a/homa_plumbing.c b/homa_plumbing.c index d30a1dc..049959e 100644 --- a/homa_plumbing.c +++ b/homa_plumbing.c @@ -21,16 +21,18 @@ static long sysctl_homa_mem[3] __read_mostly; static int sysctl_homa_rmem_min __read_mostly; static int sysctl_homa_wmem_min __read_mostly; -/* Global data for Homa. Never reference homa_data directory. Always use - * the homa variable instead; this allows overriding during unit tests. +/* Global data for Homa. Never reference homa_data directly. Always use + * the global_homa variable instead; this allows overriding during unit tests. */ static struct homa homa_data; -/* This variable should almost never be used directly; it is normally - * passed as a parameter to functions that need it. Thus it is not declared - * in a header file. +/* This variable contains the address of the statically-allocated struct homa + * used throughout Homa. This variable should almost never be used directly: + * it should be passed as a parameter to functions that need it. This + * variable is used only by functions called from Linux (so they can't pass + * in a pointer). */ -struct homa *homa = &homa_data; +struct homa *global_homa = &homa_data; /* True means that the Homa module is in the process of unloading itself, * so everyone should clean up. @@ -523,6 +525,7 @@ static DECLARE_COMPLETION(timer_thread_done); */ static int __init homa_load(void) { + struct homa *homa = global_homa; int status; pr_notice("Homa module loading\n"); @@ -632,6 +635,8 @@ static int __init homa_load(void) */ static void __exit homa_unload(void) { + struct homa *homa = global_homa; + pr_notice("Homa module unloading\n"); exiting = true; @@ -671,8 +676,8 @@ module_exit(homa_unload); */ int homa_bind(struct socket *sock, struct sockaddr *addr, int addr_len) { - struct homa_sock *hsk = homa_sk(sock->sk); union sockaddr_in_union *addr_in = (union sockaddr_in_union *)addr; + struct homa_sock *hsk = homa_sk(sock->sk); int port = 0; if (unlikely(addr->sa_family != sock->sk->sk_family)) @@ -686,7 +691,7 @@ int homa_bind(struct socket *sock, struct sockaddr *addr, int addr_len) return -EINVAL; port = ntohs(addr_in->in6.sin6_port); } - return homa_sock_bind(homa->port_map, hsk, port); + return homa_sock_bind(hsk->homa->port_map, hsk, port); } /** @@ -814,6 +819,7 @@ int homa_ioctl(struct sock *sk, int cmd, int *karg) int homa_socket(struct sock *sk) { struct homa_sock *hsk = homa_sk(sk); + struct homa *homa = global_homa; homa_sock_init(hsk, homa); return 0; @@ -1194,6 +1200,7 @@ int homa_softirq(struct sk_buff *skb) { struct sk_buff *packets, *other_pkts, *next; struct sk_buff **prev_link, **other_link; + struct homa *homa = global_homa; struct common_header *h; int first_packet = 1; int header_offset; @@ -1371,6 +1378,7 @@ int homa_err_handler_v4(struct sk_buff *skb, u32 info) { const struct in6_addr saddr = skb_canonical_ipv6_saddr(skb); const struct iphdr *iph = ip_hdr(skb); + struct homa *homa = global_homa; int type = icmp_hdr(skb)->type; int code = icmp_hdr(skb)->code; @@ -1415,6 +1423,7 @@ int homa_err_handler_v6(struct sk_buff *skb, struct inet6_skb_parm *opt, u8 type, u8 code, int offset, __be32 info) { const struct ipv6hdr *iph = (const struct ipv6hdr *)skb->data; + struct homa *homa = global_homa; if (type == ICMPV6_DEST_UNREACH && code == ICMPV6_PORT_UNREACH) { char *icmp = (char *)icmp_hdr(skb); @@ -1493,6 +1502,7 @@ int homa_dointvec(const struct ctl_table *table, int write, void *buffer, size_t *lenp, loff_t *ppos) #endif { + struct homa *homa = global_homa; int result; result = proc_dointvec(table, write, buffer, lenp, ppos); diff --git a/test/unit_homa_metrics.c b/test/unit_homa_metrics.c index e4a7df0..0c02f42 100644 --- a/test/unit_homa_metrics.c +++ b/test/unit_homa_metrics.c @@ -7,19 +7,17 @@ #include "mock.h" #include "utils.h" -extern struct homa *homa; - FIXTURE(homa_metrics) { struct homa homa; }; FIXTURE_SETUP(homa_metrics) { homa_init(&self->homa); - homa = &self->homa; + global_homa = &self->homa; } FIXTURE_TEARDOWN(homa_metrics) { - homa = NULL; + global_homa = NULL; homa_destroy(&self->homa); unit_teardown(); } diff --git a/test/unit_homa_offload.c b/test/unit_homa_offload.c index b889782..921e709 100644 --- a/test/unit_homa_offload.c +++ b/test/unit_homa_offload.c @@ -11,8 +11,6 @@ #define cur_offload_core (&per_cpu(homa_offload_core, raw_smp_processor_id())) -extern struct homa *homa; - static struct sk_buff *tcp_gro_receive(struct list_head *held_list, struct sk_buff *skb) { @@ -44,7 +42,7 @@ FIXTURE_SETUP(homa_offload) homa_init(&self->homa); self->homa.flags |= HOMA_FLAG_DONT_THROTTLE; - homa = &self->homa; + global_homa = &self->homa; mock_sock_init(&self->hsk, &self->homa, 99); self->ip = unit_get_in_addr("196.168.0.1"); self->header = (struct data_header){.common = { @@ -101,7 +99,7 @@ FIXTURE_TEARDOWN(homa_offload) list_for_each_entry_safe(skb, tmp, &self->napi.gro_hash[2].list, list) kfree_skb(skb); homa_destroy(&self->homa); - homa = NULL; + global_homa = NULL; unit_teardown(); } @@ -479,7 +477,7 @@ TEST_F(homa_offload, homa_gro_receive__max_gro_skbs) struct sk_buff *skb; // First packet: fits below the limit. - homa->max_gro_skbs = 3; + self->homa.max_gro_skbs = 3; cur_offload_core->held_skb = self->skb2; cur_offload_core->held_bucket = 2; self->header.seg.offset = htonl(6000); @@ -504,7 +502,7 @@ TEST_F(homa_offload, homa_gro_receive__max_gro_skbs) // Third packet also hits the limit for skb, causing the bucket // to become empty. - homa->max_gro_skbs = 2; + self->homa.max_gro_skbs = 2; cur_offload_core->held_skb = self->skb; skb = mock_skb_new(&self->ip, &self->header.common, 1400, 0); unit_log_clear(); @@ -520,9 +518,9 @@ TEST_F(homa_offload, homa_gro_receive__max_gro_skbs) TEST_F(homa_offload, homa_gro_gen2) { - homa->gro_policy = HOMA_GRO_GEN2; + self->homa.gro_policy = HOMA_GRO_GEN2; mock_ns = 1000; - homa->busy_ns = 100; + self->homa.busy_ns = 100; mock_set_core(5); atomic_set(&per_cpu(homa_offload_core, 6).softirq_backlog, 1); per_cpu(homa_offload_core, 6).last_gro = 0; @@ -562,7 +560,7 @@ TEST_F(homa_offload, homa_gro_gen3__basics) struct homa_offload_core *offload5 = &per_cpu(homa_offload_core, 5); struct homa_offload_core *offload7 = &per_cpu(homa_offload_core, 7); - homa->gro_policy = HOMA_GRO_GEN3; + self->homa.gro_policy = HOMA_GRO_GEN3; offload_core->gen3_softirq_cores[0] = 3; offload_core->gen3_softirq_cores[1] = 7; offload_core->gen3_softirq_cores[2] = 5; @@ -581,7 +579,7 @@ TEST_F(homa_offload, homa_gro_gen3__stop_on_negative_core_id) { struct homa_offload_core *offload_core = cur_offload_core; - homa->gro_policy = HOMA_GRO_GEN3; + self->homa.gro_policy = HOMA_GRO_GEN3; offload_core->gen3_softirq_cores[0] = 3; offload_core->gen3_softirq_cores[1] = -1; offload_core->gen3_softirq_cores[2] = 5; @@ -598,7 +596,7 @@ TEST_F(homa_offload, homa_gro_gen3__all_cores_busy_so_pick_first) { struct homa_offload_core *offload_core = cur_offload_core; - homa->gro_policy = HOMA_GRO_GEN3; + self->homa.gro_policy = HOMA_GRO_GEN3; offload_core->gen3_softirq_cores[0] = 3; offload_core->gen3_softirq_cores[1] = 7; offload_core->gen3_softirq_cores[2] = 5; @@ -625,7 +623,7 @@ TEST_F(homa_offload, homa_gro_complete__clear_held_skb) } TEST_F(homa_offload, homa_gro_complete__GRO_IDLE) { - homa->gro_policy = HOMA_GRO_IDLE; + self->homa.gro_policy = HOMA_GRO_IDLE; per_cpu(homa_offload_core, 6).last_active = 30; per_cpu(homa_offload_core, 7).last_active = 25; per_cpu(homa_offload_core, 0).last_active = 20; diff --git a/test/unit_homa_plumbing.c b/test/unit_homa_plumbing.c index 8cb5183..fb748da 100644 --- a/test/unit_homa_plumbing.c +++ b/test/unit_homa_plumbing.c @@ -9,8 +9,6 @@ #include "mock.h" #include "utils.h" -extern struct homa *homa; - /* The following hook function frees hook_rpc. */ static struct homa_rpc *hook_rpc; static void unlock_hook(char *id) @@ -57,7 +55,7 @@ FIXTURE_SETUP(homa_plumbing) self->client_addr.in6.sin6_port = htons(self->client_port); self->server_addr.in6.sin6_addr = self->server_ip[0]; self->server_addr.in6.sin6_port = htons(self->server_port); - homa = &self->homa; + global_homa = &self->homa; homa_init(&self->homa); mock_sock_init(&self->hsk, &self->homa, 0); self->client_addr.in6.sin6_family = self->hsk.inet.sk.sk_family; @@ -107,7 +105,7 @@ FIXTURE_TEARDOWN(homa_plumbing) { homa_destroy(&self->homa); unit_teardown(); - homa = NULL; + global_homa = NULL; } TEST_F(homa_plumbing, homa_bind__version_mismatch)