Skip to content

Commit a5fc925

Browse files
committed
More changes to enable Shenango integration.
The biggest challenge is to move away from the poll-based execution model previously embedded in the implementation. For example, Shenango can't afford to drive the execution of the transport by calling Transport::poll in a busy loop. Also, Shenango needs to allow users to block on a socket waiting for incoming messages. Another refactoring that results in small code changes all over the place is the Driver::Packet interface. The old interface cannot prevent the driver from modifying the payload (e.g., prepend L3 headers). This will lead to corrupted message when the packet needs to be retransmitted. List of major changes: - CHoma: provide C-bindings of the Homa APIs (Shenango is written in C) - Shenango: implement Shenango Driver, MailboxDir, and Mailbox - TransportPoller: extract poll-based execution model out of the Transport - SimpleMailboxDir: a simple reference implementation for Homa::MailboxDir - Driver::Packet: a new packet interface to eliminate the awkward PacketSpec; this is used to provide an immutable view of the packet to the transport (driver can prepend headers to the payload w/o affecting the transport) - Sender: add a couple of user-defined callbacks (Shenango currently relies on them to wake up blocking threads) - Finally, bring unit tests up-to-date.
1 parent c1308dc commit a5fc925

36 files changed

+2605
-842
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,20 @@ endif()
7373
## lib Homa ####################################################################
7474
add_library(Homa
7575
src/CodeLocation.cc
76+
src/CHoma.cc
7677
src/Debug.cc
7778
src/Driver.cc
7879
src/Homa.cc
7980
src/Perf.cc
8081
src/Policy.cc
8182
src/Receiver.cc
8283
src/Sender.cc
84+
src/Shenango.cc
85+
src/SimpleMailboxDir.cc
8386
src/StringUtil.cc
8487
src/ThreadId.cc
8588
src/TransportImpl.cc
89+
src/TransportPoller.cc
8690
src/Util.cc
8791
)
8892
add_library(Homa::Homa ALIAS Homa)

include/Homa/Bindings/CHoma.h

Lines changed: 238 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
1+
/* Copyright (c) 2020 Stanford University
2+
*
3+
* Permission to use, copy, modify, and distribute this software for any
4+
* purpose with or without fee is hereby granted, provided that the above
5+
* copyright notice and this permission notice appear in all copies.
6+
*
7+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR(S) DISCLAIM ALL WARRANTIES
8+
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9+
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL AUTHORS BE LIABLE FOR
10+
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11+
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12+
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13+
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14+
*/
15+
16+
/**
17+
* @file CHoma.h
18+
*
19+
* Contains C-bindings for the Homa Transport API.
20+
*/
21+
22+
#pragma once
23+
24+
#include "Homa/OutMessageStatus.h"
25+
26+
#ifdef __cplusplus
27+
#include <cstddef>
28+
#include <cstdint>
29+
extern "C" {
30+
#else
31+
#include <stddef.h>
32+
#include <stdint.h>
33+
#endif
34+
35+
/**
36+
* Define handle types for various Homa objects.
37+
*
38+
* A handle type is essentially a thin wrapper around an opaque pointer.
39+
* Compared to generic pointers, using handle types in the C API enables
40+
* some type safety.
41+
*/
42+
#define DEFINE_HOMA_OBJ_HANDLE(x) \
43+
typedef struct { \
44+
void* p; \
45+
} homa_##x;
46+
47+
DEFINE_HOMA_OBJ_HANDLE(driver) /* Homa::Driver */
48+
DEFINE_HOMA_OBJ_HANDLE(inmsg) /* Homa::InMessage */
49+
DEFINE_HOMA_OBJ_HANDLE(outmsg) /* Homa::OutMessage */
50+
DEFINE_HOMA_OBJ_HANDLE(mailbox) /* Homa::Mailbox */
51+
DEFINE_HOMA_OBJ_HANDLE(mailbox_dir) /* Homa::MailboxDir */
52+
DEFINE_HOMA_OBJ_HANDLE(sk) /* Homa::Socket */
53+
DEFINE_HOMA_OBJ_HANDLE(trans) /* Homa::Transport */
54+
55+
/* ============================ */
56+
/* Homa::InMessage API */
57+
/* ============================ */
58+
59+
/**
60+
* homa_inmsg_ack - C-binding for Homa::InMessage::acknowledge
61+
*/
62+
extern void homa_inmsg_ack(homa_inmsg in_msg);
63+
64+
/**
65+
* homa_inmsg_dropped - C-binding for Homa::InMessage::dropped
66+
*/
67+
extern bool homa_inmsg_dropped(homa_inmsg in_msg);
68+
69+
/**
70+
* homa_inmsg_fail - C-binding for Homa::InMessage::fail
71+
*/
72+
extern void homa_inmsg_fail(homa_inmsg in_msg);
73+
74+
/**
75+
* homa_inmsg_get - C-binding for Homa::InMessage::get
76+
*/
77+
extern size_t homa_inmsg_get(homa_inmsg in_msg, size_t ofs, void* dst,
78+
size_t len);
79+
80+
/**
81+
* homa_inmsg_src_addr - C-binding for Homa::InMessage::getSourceAddress
82+
*/
83+
extern void homa_inmsg_src_addr(homa_inmsg in_msg, uint32_t* ip,
84+
uint16_t* port);
85+
86+
/**
87+
* homa_inmsg_len - C-binding for Homa::InMessage::length
88+
*/
89+
extern size_t homa_inmsg_len(homa_inmsg in_msg);
90+
91+
/**
92+
* homa_inmsg_release - C-binding for Homa::InMessage::release
93+
*/
94+
extern void homa_inmsg_release(homa_inmsg in_msg);
95+
96+
/**
97+
* homa_inmsg_strip - C-binding for Homa::InMessage::strip
98+
*/
99+
extern void homa_inmsg_strip(homa_inmsg in_msg, size_t n);
100+
101+
/* ============================ */
102+
/* Homa::OutMessage API */
103+
/* ============================ */
104+
105+
/**
106+
* homa_outmsg_append - C-binding for Homa::OutMessage::append
107+
*/
108+
extern void homa_outmsg_append(homa_outmsg out_msg, const void* buf,
109+
size_t len);
110+
111+
/**
112+
* homa_outmsg_cancel - C-binding for Homa::OutMessage::cancel
113+
*/
114+
extern void homa_outmsg_cancel(homa_outmsg out_msg);
115+
116+
/**
117+
* homa_outmsg_status - C-binding for Homa::OutMessage::getStatus
118+
*/
119+
extern int homa_outmsg_status(homa_outmsg out_msg);
120+
121+
/**
122+
* homa_outmsg_prepend - C-binding for Homa::OutMessage::prepend
123+
*/
124+
extern void homa_outmsg_prepend(homa_outmsg out_msg, const void* buf,
125+
size_t len);
126+
127+
/**
128+
* homa_outmsg_reserve - C-binding for Homa::OutMessage::reserve
129+
*/
130+
extern void homa_outmsg_reserve(homa_outmsg out_msg, size_t n);
131+
132+
/**
133+
* homa_outmsg_send - C-binding for Homa::OutMessage::send
134+
*/
135+
extern void homa_outmsg_send(homa_outmsg out_msg, uint32_t ip, uint16_t port);
136+
137+
/**
138+
* homa_outmsg_register_cb - C-binding for
139+
* Homa::OutMessage::registerCallbackEndState
140+
*/
141+
extern void homa_outmsg_register_cb_end_state(homa_outmsg out_msg,
142+
void (*cb)(void*), void* data);
143+
144+
/**
145+
* homa_outmsg_release - C-binding for Homa::OutMessage::release
146+
*/
147+
extern void homa_outmsg_release(homa_outmsg out_msg);
148+
149+
/* ============================ */
150+
/* Homa::Socket API */
151+
/* ============================ */
152+
153+
/**
154+
* homa_sk_alloc - C-binding for Homa::Socket::alloc
155+
*/
156+
extern homa_outmsg homa_sk_alloc(homa_sk sk);
157+
158+
/**
159+
* homa_sk_receive - C-binding for Homa::Socket::receive
160+
*/
161+
extern homa_inmsg homa_sk_receive(homa_sk sk, bool blocking);
162+
163+
/**
164+
* homa_sk_shutdown - C-binding for Homa::Socket::shutdown
165+
*/
166+
extern void homa_sk_shutdown(homa_sk sk);
167+
168+
/**
169+
* homa_sk_is_shutdown - C-binding for Homa::Socket::isShutdown
170+
*/
171+
extern bool homa_sk_is_shutdown(homa_sk sk);
172+
173+
/**
174+
* homa_sk_local_addr - C-binding for Homa::Socket::getLocalAddress
175+
*/
176+
extern void homa_sk_local_addr(homa_sk sk, uint32_t* ip, uint16_t* port);
177+
178+
/**
179+
* homa_sk_close - C-binding for Homa::Socket::close
180+
*/
181+
extern void homa_sk_close(homa_sk sk);
182+
183+
/* ============================ */
184+
/* Homa::Transport API */
185+
/* ============================ */
186+
187+
/**
188+
* homa_trans_create - C-binding for Homa::Transport::create
189+
*/
190+
extern homa_trans homa_trans_create(homa_driver drv, homa_mailbox_dir dir,
191+
uint64_t id);
192+
193+
/**
194+
* homa_trans_free - C-binding for Homa::Transport::free
195+
*/
196+
extern void homa_trans_free(homa_trans trans);
197+
198+
/**
199+
* homa_trans_open - C-binding for Homa::Transport::open
200+
*/
201+
extern homa_sk homa_trans_open(homa_trans trans, uint16_t port);
202+
203+
/**
204+
* homa_trans_check_timeouts - C-binding for Homa::Transport::checkTimeouts
205+
*/
206+
extern uint64_t homa_trans_check_timeouts(homa_trans trans);
207+
208+
/**
209+
* homa_trans_id - C-binding for Homa::Transport::getId
210+
*/
211+
extern uint64_t homa_trans_id(homa_trans trans);
212+
213+
/**
214+
* homa_trans_proc - C-binding for Homa::Transport::processPacket
215+
*/
216+
extern void homa_trans_proc(homa_trans trans, uintptr_t desc, void* payload,
217+
int32_t len, uint32_t src_ip);
218+
219+
/**
220+
* homa_trans_try_send - C-binding for
221+
* Homa::Transport::registerCallbackSendReady
222+
*/
223+
extern void homa_trans_register_cb_send_ready(homa_trans trans,
224+
void (*cb)(void*), void* data);
225+
226+
/**
227+
* homa_trans_try_send - C-binding for Homa::Transport::trySend
228+
*/
229+
extern bool homa_trans_try_send(homa_trans trans, uint64_t* wait_until);
230+
231+
/**
232+
* homa_trans_try_grant - C-binding for Homa::Transport::trySendGrants
233+
*/
234+
extern bool homa_trans_try_grant(homa_trans trans);
235+
236+
#ifdef __cplusplus
237+
}
238+
#endif

include/Homa/Driver.h

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <string>
2020

2121
#include "Homa/Exception.h"
22+
#include "Homa/OutMessageStatus.h"
2223

2324
namespace Homa {
2425

@@ -66,26 +67,6 @@ struct IpAddress final {
6667
};
6768
static_assert(std::is_trivially_copyable<IpAddress>());
6869

69-
/**
70-
* Represents a packet of data that can be send or is received over the network.
71-
* A Packet logically contains only the transport-layer (L4) Homa header in
72-
* addition to application data.
73-
*
74-
* This struct specifies the minimal object layout of a packet that the core
75-
* Homa protocol depends on (e.g., Homa::Core::{Sender, Receiver}); this is
76-
* useful for applications that only want to use the transport layer of this
77-
* library and have their own infrastructures for sending and receiving packets.
78-
*/
79-
struct PacketSpec {
80-
/// Pointer to an array of bytes containing the payload of this Packet.
81-
/// This array is valid until the Packet is released back to the Driver.
82-
void* payload;
83-
84-
/// Number of bytes in the payload.
85-
int32_t length;
86-
} __attribute__((packed));
87-
static_assert(std::is_trivial<PacketSpec>());
88-
8970
/**
9071
* Used by Homa::Transport to send and receive unreliable datagrams. Provides
9172
* the interface to which all Driver implementations must conform.
@@ -94,8 +75,23 @@ static_assert(std::is_trivial<PacketSpec>());
9475
*/
9576
class Driver {
9677
public:
97-
/// Import PacketSpec into the Driver namespace.
98-
using Packet = PacketSpec;
78+
/**
79+
* Describes a packet of data that can be send or is received over the
80+
* network. A Packet logically contains only the transport-layer (L4) Homa
81+
* header in addition to application data.
82+
*/
83+
struct Packet {
84+
/// Unique identifier of this Packet within the Driver. This descriptor
85+
/// is entirely opaque to the transport.
86+
uintptr_t descriptor;
87+
88+
/// Pointer to an array of bytes containing the payload of this Packet.
89+
/// This array is valid until the Packet is released back to the Driver.
90+
void* payload;
91+
92+
/// Number of bytes in the payload.
93+
int32_t length;
94+
};
9995

10096
/**
10197
* Driver destructor.
@@ -107,7 +103,7 @@ class Driver {
107103
* caller must eventually release the packet by passing it to a call to
108104
* releasePacket().
109105
*/
110-
virtual Packet* allocPacket() = 0;
106+
virtual Packet allocPacket() = 0;
111107

112108
/**
113109
* Send a packet over the network.
@@ -183,7 +179,7 @@ class Driver {
183179
* @sa Driver::releasePackets()
184180
*/
185181
virtual uint32_t receivePackets(uint32_t maxPackets,
186-
Packet* receivedPackets[],
182+
Packet receivedPackets[],
187183
IpAddress sourceAddresses[]) = 0;
188184

189185
/**
@@ -201,7 +197,7 @@ class Driver {
201197
* @param numPackets
202198
* Number of Packet objects in _packets_.
203199
*/
204-
virtual void releasePackets(Packet* packets[], uint16_t numPackets) = 0;
200+
virtual void releasePackets(Packet packets[], uint16_t numPackets) = 0;
205201

206202
/**
207203
* Returns the highest packet priority level this Driver supports (0 is

include/Homa/Drivers/DPDK/DpdkDriver.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class DpdkDriver : public Driver {
119119
virtual ~DpdkDriver();
120120

121121
/// See Driver::allocPacket()
122-
virtual Packet* allocPacket();
122+
virtual Packet allocPacket();
123123

124124
/// See Driver::sendPacket()
125125
virtual void sendPacket(Packet* packet, IpAddress destination,
@@ -133,11 +133,11 @@ class DpdkDriver : public Driver {
133133

134134
/// See Driver::receivePackets()
135135
virtual uint32_t receivePackets(uint32_t maxPackets,
136-
Packet* receivedPackets[],
136+
Packet receivedPackets[],
137137
IpAddress sourceAddresses[]);
138138

139139
/// See Driver::releasePackets()
140-
virtual void releasePackets(Packet* packets[], uint16_t numPackets);
140+
virtual void releasePackets(Packet packets[], uint16_t numPackets);
141141

142142
/// See Driver::getHighestPacketPriority()
143143
virtual int getHighestPacketPriority();

0 commit comments

Comments
 (0)