Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions homa_incoming.c
Original file line number Diff line number Diff line change
Expand Up @@ -512,14 +512,11 @@ void homa_dispatch_pkts(struct sk_buff *skb)
if (!homa_is_client(id)) {
/* We are the server for this RPC. */
if (h->common.type == DATA) {
int created;

/* Create a new RPC if one doesn't
* already exist.
*/
rpc = homa_rpc_alloc_server(hsk, &saddr,
h,
&created);
h);
if (IS_ERR(rpc)) {
INC_METRIC(server_cant_create_rpcs, 1);
rpc = NULL;
Expand Down
6 changes: 1 addition & 5 deletions homa_rpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,14 @@ struct homa_rpc *homa_rpc_alloc_client(struct homa_sock *hsk,
* @source: IP address (network byte order) of the RPC's client.
* @h: Header for the first data packet received for this RPC; used
* to initialize the RPC.
* @created: Will be set to 1 if a new RPC was created and 0 if an
* existing RPC was found.
*
* Return: A pointer to a new RPC, which is locked, or a negative errno
* if an error occurred. If there is already an RPC corresponding
* to h, then it is returned instead of creating a new RPC.
*/
struct homa_rpc *homa_rpc_alloc_server(struct homa_sock *hsk,
const struct in6_addr *source,
struct homa_data_hdr *h, int *created)
struct homa_data_hdr *h)
__cond_acquires(srpc->bucket->lock)
{
u64 id = homa_local_id(h->common.sender_id);
Expand All @@ -140,7 +138,6 @@ struct homa_rpc *homa_rpc_alloc_server(struct homa_sock *hsk,
/* RPC already exists; just return it instead
* of creating a new RPC.
*/
*created = 0;
return srpc;
}
}
Expand Down Expand Up @@ -204,7 +201,6 @@ struct homa_rpc *homa_rpc_alloc_server(struct homa_sock *hsk,
homa_rpc_handoff(srpc);
}
INC_METRIC(requests_received, 1);
*created = 1;
return srpc;

error:
Expand Down
2 changes: 1 addition & 1 deletion homa_rpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ struct homa_rpc
struct homa_rpc
*homa_rpc_alloc_server(struct homa_sock *hsk,
const struct in6_addr *source,
struct homa_data_hdr *h, int *created);
struct homa_data_hdr *h);
void homa_rpc_end(struct homa_rpc *rpc);
struct homa_rpc
*homa_rpc_find_client(struct homa_sock *hsk, u64 id);
Expand Down
4 changes: 1 addition & 3 deletions test/unit_homa_incoming.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,9 @@ TEST_F(homa_incoming, homa_message_in_init__basics)
TEST_F(homa_incoming, homa_message_in_init__message_too_long)
{
struct homa_rpc *srpc;
int created;

self->data.message_length = htonl(HOMA_MAX_MESSAGE_LENGTH+1);
srpc = homa_rpc_alloc_server(&self->hsk, self->client_ip, &self->data,
&created);
srpc = homa_rpc_alloc_server(&self->hsk, self->client_ip, &self->data);
ASSERT_TRUE(IS_ERR(srpc));
EXPECT_EQ(EINVAL, -PTR_ERR(srpc));
}
Expand Down
57 changes: 14 additions & 43 deletions test/unit_homa_rpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,91 +132,74 @@ TEST_F(homa_rpc, homa_rpc_alloc_client__socket_shutdown)
TEST_F(homa_rpc, homa_rpc_alloc_server__normal)
{
struct homa_rpc *srpc;
int created;

srpc = homa_rpc_alloc_server(&self->hsk, self->client_ip, &self->data,
&created);
srpc = homa_rpc_alloc_server(&self->hsk, self->client_ip, &self->data);
ASSERT_FALSE(IS_ERR(srpc));
homa_rpc_unlock(srpc);
self->data.message_length = N(1600);
homa_data_pkt(mock_skb_alloc(self->client_ip, &self->data.common,
1400, 0), srpc);
EXPECT_EQ(RPC_INCOMING, srpc->state);
EXPECT_EQ(1, unit_list_length(&self->hsk.active_rpcs));
EXPECT_EQ(1, created);
homa_rpc_end(srpc);
}
TEST_F(homa_rpc, homa_rpc_alloc_server__no_buffer_pool)
{
struct homa_rpc *srpc;
int created;

homa_pool_free(self->hsk.buffer_pool);
self->hsk.buffer_pool = NULL;
srpc = homa_rpc_alloc_server(&self->hsk, self->client_ip, &self->data,
&created);
srpc = homa_rpc_alloc_server(&self->hsk, self->client_ip, &self->data);
EXPECT_TRUE(IS_ERR(srpc));
EXPECT_EQ(ENOMEM, -PTR_ERR(srpc));
EXPECT_EQ(0, unit_list_length(&self->hsk.active_rpcs));
}
TEST_F(homa_rpc, homa_rpc_alloc_server__already_exists)
{
struct homa_rpc *srpc1, *srpc2, *srpc3;
int created;

srpc1 = homa_rpc_alloc_server(&self->hsk, self->client_ip, &self->data,
&created);
srpc1 = homa_rpc_alloc_server(&self->hsk, self->client_ip, &self->data);
ASSERT_FALSE(IS_ERR(srpc1));
homa_rpc_unlock(srpc1);
self->data.common.sender_id = cpu_to_be64(
be64_to_cpu(self->data.common.sender_id)
+ 2*HOMA_SERVER_RPC_BUCKETS);
srpc2 = homa_rpc_alloc_server(&self->hsk, self->client_ip, &self->data,
&created);
srpc2 = homa_rpc_alloc_server(&self->hsk, self->client_ip, &self->data);
ASSERT_FALSE(IS_ERR(srpc2));
EXPECT_EQ(1, created);
homa_rpc_unlock(srpc2);
EXPECT_NE(srpc2, srpc1);
self->data.common.sender_id = cpu_to_be64(
be64_to_cpu(self->data.common.sender_id)
- 2*HOMA_SERVER_RPC_BUCKETS);
srpc3 = homa_rpc_alloc_server(&self->hsk, self->client_ip, &self->data,
&created);
srpc3 = homa_rpc_alloc_server(&self->hsk, self->client_ip, &self->data);
ASSERT_FALSE(IS_ERR(srpc3));
EXPECT_EQ(0, created);
homa_rpc_unlock(srpc3);
EXPECT_EQ(srpc3, srpc1);
}
TEST_F(homa_rpc, homa_rpc_alloc_server__malloc_error)
{
struct homa_rpc *srpc;
int created;

mock_kmalloc_errors = 1;
srpc = homa_rpc_alloc_server(&self->hsk, self->client_ip, &self->data,
&created);
srpc = homa_rpc_alloc_server(&self->hsk, self->client_ip, &self->data);
EXPECT_TRUE(IS_ERR(srpc));
EXPECT_EQ(ENOMEM, -PTR_ERR(srpc));
}
TEST_F(homa_rpc, homa_rpc_alloc_server__addr_error)
{
struct homa_rpc *srpc;
int created;

mock_route_errors = 1;
srpc = homa_rpc_alloc_server(&self->hsk, self->client_ip, &self->data,
&created);
srpc = homa_rpc_alloc_server(&self->hsk, self->client_ip, &self->data);
EXPECT_TRUE(IS_ERR(srpc));
EXPECT_EQ(EHOSTUNREACH, -PTR_ERR(srpc));
}
TEST_F(homa_rpc, homa_rpc_alloc_server__socket_shutdown)
{
struct homa_rpc *srpc;
int created;

self->hsk.shutdown = 1;
srpc = homa_rpc_alloc_server(&self->hsk, self->client_ip, &self->data,
&created);
srpc = homa_rpc_alloc_server(&self->hsk, self->client_ip, &self->data);
EXPECT_TRUE(IS_ERR(srpc));
EXPECT_EQ(ESHUTDOWN, -PTR_ERR(srpc));
EXPECT_EQ(0, unit_list_length(&self->hsk.active_rpcs));
Expand All @@ -225,11 +208,9 @@ TEST_F(homa_rpc, homa_rpc_alloc_server__socket_shutdown)
TEST_F(homa_rpc, homa_rpc_alloc_server__allocate_buffers)
{
struct homa_rpc *srpc;
int created;

self->data.message_length = N(3*HOMA_BPAGE_SIZE);
srpc = homa_rpc_alloc_server(&self->hsk, self->client_ip, &self->data,
&created);
srpc = homa_rpc_alloc_server(&self->hsk, self->client_ip, &self->data);
ASSERT_FALSE(IS_ERR(srpc));
homa_rpc_unlock(srpc);
EXPECT_EQ(3, srpc->msgin.num_bpages);
Expand All @@ -238,24 +219,20 @@ TEST_F(homa_rpc, homa_rpc_alloc_server__allocate_buffers)
TEST_F(homa_rpc, homa_rpc_alloc_server__cant_allocate_buffers)
{
struct homa_rpc *srpc;
int created;

self->data.message_length = N(1400);
homa_pool_free(self->hsk.buffer_pool);
self->hsk.buffer_pool = homa_pool_alloc(&self->hsk);
srpc = homa_rpc_alloc_server(&self->hsk, self->client_ip, &self->data,
&created);
srpc = homa_rpc_alloc_server(&self->hsk, self->client_ip, &self->data);
ASSERT_TRUE(IS_ERR(srpc));
EXPECT_EQ(ENOMEM, -PTR_ERR(srpc));
}
TEST_F(homa_rpc, homa_rpc_alloc_server__handoff_rpc)
{
struct homa_rpc *srpc;
int created;

self->data.message_length = N(1400);
srpc = homa_rpc_alloc_server(&self->hsk, self->client_ip, &self->data,
&created);
srpc = homa_rpc_alloc_server(&self->hsk, self->client_ip, &self->data);
ASSERT_FALSE(IS_ERR(srpc));
homa_rpc_unlock(srpc);
EXPECT_EQ(RPC_INCOMING, srpc->state);
Expand All @@ -266,12 +243,10 @@ TEST_F(homa_rpc, homa_rpc_alloc_server__handoff_rpc)
TEST_F(homa_rpc, homa_rpc_alloc_server__dont_handoff_no_buffers)
{
struct homa_rpc *srpc;
int created;

self->data.message_length = N(1400);
atomic_set(&self->hsk.buffer_pool->free_bpages, 0);
srpc = homa_rpc_alloc_server(&self->hsk, self->client_ip, &self->data,
&created);
srpc = homa_rpc_alloc_server(&self->hsk, self->client_ip, &self->data);
ASSERT_FALSE(IS_ERR(srpc));
homa_rpc_unlock(srpc);
EXPECT_EQ(0, unit_list_length(&self->hsk.ready_rpcs));
Expand All @@ -280,12 +255,10 @@ TEST_F(homa_rpc, homa_rpc_alloc_server__dont_handoff_no_buffers)
TEST_F(homa_rpc, homa_rpc_alloc_server__dont_handoff_rpc)
{
struct homa_rpc *srpc;
int created;

self->data.message_length = N(2800);
self->data.seg.offset = N(1400);
srpc = homa_rpc_alloc_server(&self->hsk, self->client_ip, &self->data,
&created);
srpc = homa_rpc_alloc_server(&self->hsk, self->client_ip, &self->data);
ASSERT_FALSE(IS_ERR(srpc));
homa_rpc_unlock(srpc);
EXPECT_EQ(RPC_INCOMING, srpc->state);
Expand All @@ -298,15 +271,13 @@ TEST_F(homa_rpc, homa_rpc_alloc_server__dont_handoff_rpc)
TEST_F(homa_rpc, homa_bucket_lock_slow)
{
struct homa_rpc *crpc, *srpc;
int created;

mock_clock_tick = 10;
crpc = homa_rpc_alloc_client(&self->hsk, &self->server_addr);
ASSERT_FALSE(IS_ERR(crpc));
homa_rpc_end(crpc);
homa_rpc_unlock(crpc);
srpc = homa_rpc_alloc_server(&self->hsk, self->client_ip, &self->data,
&created);
srpc = homa_rpc_alloc_server(&self->hsk, self->client_ip, &self->data);
ASSERT_FALSE(IS_ERR(srpc));
homa_rpc_unlock(srpc);

Expand Down
5 changes: 2 additions & 3 deletions test/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ struct homa_rpc *unit_server_rpc(struct homa_sock *hsk,
struct in6_addr *server_ip, int client_port, int id,
int req_length, int resp_length)
{
int bytes_received, created;
int bytes_received;
struct homa_data_hdr h;
int status;

Expand All @@ -397,8 +397,7 @@ struct homa_rpc *unit_server_rpc(struct homa_sock *hsk,
#ifndef __STRIP__ /* See strip.py */
h.incoming = htonl(10000);
#endif /* See strip.py */
struct homa_rpc *srpc = homa_rpc_alloc_server(hsk, client_ip, &h,
&created);
struct homa_rpc *srpc = homa_rpc_alloc_server(hsk, client_ip, &h);

if (IS_ERR(srpc))
return NULL;
Expand Down