Skip to content

Commit

Permalink
Rename global homa variable to global_homa
Browse files Browse the repository at this point in the history
(Avoid confusion over name)
  • Loading branch information
johnousterhout committed Dec 3, 2024
1 parent f2ab056 commit 995e0af
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 41 deletions.
2 changes: 2 additions & 0 deletions homa_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions homa_metrics.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down
14 changes: 8 additions & 6 deletions homa_offload.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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),
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions homa_offload.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
26 changes: 18 additions & 8 deletions homa_plumbing.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand 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");
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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))
Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 2 additions & 4 deletions test/unit_homa_metrics.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
22 changes: 10 additions & 12 deletions test/unit_homa_offload.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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);
Expand All @@ -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();
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
6 changes: 2 additions & 4 deletions test/unit_homa_plumbing.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 995e0af

Please sign in to comment.