Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify core 2 #13

Draft
wants to merge 33 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
234e2ab
Fixed compilation erros in src/Perf.h
yilongli Oct 6, 2020
9d4e95e
Changes to the Driver interface to get Homa ready for Shenango integr…
yilongli Jul 17, 2020
a305d46
Update DpdkDriver to use the new API introduced in the previous commit
yilongli Jul 21, 2020
23e6c28
Improvements based on code review discussions with Collin
yilongli Aug 7, 2020
c1308dc
fixed copyrights and formatting issues
yilongli Oct 6, 2020
a75e59c
Include additional Perf microbenchmarks
cstlee Aug 12, 2020
1c5e460
Introduce incremental timeout checking
cstlee Aug 15, 2020
679e483
Clean up comments
cstlee Aug 16, 2020
05a84b5
Change default behavior to ensure message is sent
cstlee Aug 21, 2020
dd631fe
Add Perf benchmark atomicIncUnsafe
cstlee Aug 21, 2020
3ce5233
Remove unneeded Perf::Counters:Stat thread-safety
cstlee Aug 21, 2020
ffab71e
Clean up Perf::Timer usage
cstlee Aug 22, 2020
020468e
Add more Perf microbenchmarks
cstlee Aug 28, 2020
2cd326c
Remove Sender::trySend() restriction
cstlee Aug 28, 2020
793de5a
Simplify DpdkDriver Packet allocation
cstlee Sep 4, 2020
e5d45bd
Change Sender to not PING when blocked on itself
cstlee Sep 4, 2020
c78f1d9
Drop message from sendQueue on Message timeout
cstlee Sep 4, 2020
610b27a
Add Message statistics
cstlee Sep 7, 2020
3c6b2e1
DpdkDriver bug fixes and improvements
cstlee Sep 7, 2020
429db01
Prevent DpdkDriver loopback starvation
cstlee Sep 14, 2020
55c3e34
Bump version to 0.2.0.0
cstlee Oct 6, 2020
e143c27
Add missing DpdkDriverImpl member init
cstlee Oct 7, 2020
b617c47
Expose Receiver::checkTimeouts() as public method
cstlee Oct 7, 2020
40345af
Expose Sender::checkTimeouts() as public method.
cstlee Oct 7, 2020
062fa25
Minor cleanups in Sender.h
yilongli Oct 14, 2020
e788958
wip: complete cleanups for Sender
yilongli Oct 14, 2020
8859e05
completed the first draft of new Sender
yilongli Oct 15, 2020
ee3db75
final cleanup on Sender
yilongli Oct 15, 2020
c382ea3
similar cleanups for Receiver
yilongli Oct 17, 2020
1973fdd
pulled in the changes that simplify Homa::InMessage + improvements ba…
yilongli Oct 27, 2020
6969f25
fixed some trivial issues raised in the code reviews
yilongli Nov 10, 2020
ca0a7cb
fixed the race conditions in Receiver due to reduced coverage of the …
yilongli Nov 11, 2020
f3799b9
fixed race conditions on the Sender side
yilongli Nov 12, 2020
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
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required (VERSION 3.11)

project(Homa VERSION 0.1.1.0 LANGUAGES CXX)
project(Homa VERSION 0.2.0.0 LANGUAGES CXX)

################################################################################
## Dependency Configuration ####################################################
Expand Down Expand Up @@ -74,6 +74,7 @@ endif()
add_library(Homa
src/CodeLocation.cc
src/Debug.cc
src/Driver.cc
src/Homa.cc
src/Perf.cc
src/Policy.cc
Expand Down
198 changes: 77 additions & 121 deletions include/Homa/Driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,141 +23,85 @@
namespace Homa {

/**
* Used by Homa::Transport to send and receive unreliable datagrams. Provides
* the interface to which all Driver implementations must conform.
* A simple wrapper struct around an IP address in binary format.
*
* Implementations of this class should be thread-safe.
* This struct is meant to provide some type-safety when manipulating IP
* addresses. In order to avoid any runtime overhead, this struct contains
* nothing more than the IP address, so it is trivially copyable.
*/
class Driver {
public:
struct IpAddress final {
/// IPv4 address in host byte order.
uint32_t addr;

/**
* Represents a Network address.
*
* Each Address representation is specific to the Driver instance that
* returned the it; they cannot be use interchangeably between different
* Driver instances.
* Unbox the IP address in binary format.
*/
using Address = uint64_t;
explicit operator uint32_t()
{
return addr;
}

/**
* Used to hold a driver's serialized byte-format for a network address.
*
* Each driver may define its own byte-format so long as fits within the
* bytes array.
* Equality function for IpAddress, for use in std::unordered_maps etc.
*/
struct WireFormatAddress {
uint8_t type; ///< Can be used to distinguish between different wire
///< address formats.
uint8_t bytes[19]; ///< Holds an Address's serialized byte-format.
} __attribute__((packed));
bool operator==(const IpAddress& other) const
{
return addr == other.addr;
}

/**
* Represents a packet of data that can be send or is received over the
* network. A Packet logically contains only the payload and not any Driver
* specific headers.
*
* A Packet may be Driver specific and should not used interchangeably
* between Driver instances or implementations.
*
* This class is NOT thread-safe but the Transport and Driver's use of
* Packet objects should be allow the Transport and the Driver to execute on
* different threads.
* This class computes a hash of an IpAddress, so that IpAddress can be used
* as keys in unordered_maps.
*/
class Packet {
public:
/// Packet's source or destination. When sending a Packet, the address
/// field will contain the destination Address. When receiving a Packet,
/// address field will contain the source Address.
Address address;

/// Packet's network priority (send only); the lowest possible priority
/// is 0. The highest priority is positive number defined by the
/// Driver; the highest priority can be queried by calling the method
/// getHighestPacketPriority().
int priority;

/// Pointer to an array of bytes containing the payload of this Packet.
/// This array is valid until the Packet is released back to the Driver.
void* const payload;
struct Hasher {
/// Return a "hash" of the given IpAddress.
std::size_t operator()(const IpAddress& address) const
{
return std::hash<typeof(addr)>{}(address.addr);
}
};

/// Number of bytes in the payload.
int length;
static std::string toString(IpAddress address);
static IpAddress fromString(const char* addressStr);
};
static_assert(std::is_trivially_copyable<IpAddress>());

/// Return the maximum number of bytes the payload can hold.
virtual int getMaxPayloadSize() = 0;
/**
* Represents a packet of data that can be send or is received over the network.
* A Packet logically contains only the transport-layer (L4) Homa header in
* addition to application data.
*
* This struct specifies the minimal object layout of a packet that the core
* Homa protocol depends on (e.g., Homa::Core::{Sender, Receiver}); this is
* useful for applications that only want to use the transport layer of this
* library and have their own infrastructures for sending and receiving packets.
*/
struct PacketSpec {
/// Pointer to an array of bytes containing the payload of this Packet.
/// This array is valid until the Packet is released back to the Driver.
void* payload;

protected:
/**
* Construct a Packet.
*/
explicit Packet(void* payload, int length = 0)
: address()
, priority(0)
, payload(payload)
, length(length)
{}
/// Number of bytes in the payload.
int32_t length;
} __attribute__((packed));
static_assert(std::is_trivial<PacketSpec>());

// DISALLOW_COPY_AND_ASSIGN
Packet(const Packet&) = delete;
Packet& operator=(const Packet&) = delete;
};
/**
* Used by Homa::Transport to send and receive unreliable datagrams. Provides
* the interface to which all Driver implementations must conform.
*
* Implementations of this class should be thread-safe.
*/
class Driver {
public:
/// Import PacketSpec into the Driver namespace.
using Packet = PacketSpec;

/**
* Driver destructor.
*/
virtual ~Driver() = default;

/**
* Return a Driver specific network address for the given string
* representation of the address.
*
* @param addressString
* The string representation of the address to return. The address
* string format can be Driver specific.
*
* @return
* Address that can be the source or destination of a Packet.
*
* @throw BadAddress
* _addressString_ is malformed.
*/
virtual Address getAddress(std::string const* const addressString) = 0;

/**
* Return a Driver specific network address for the given serialized
* byte-format of the address.
*
* @param wireAddress
* The serialized byte-format of the address to be returned. The
* format can be Driver specific.
*
* @return
* Address that can be the source or destination of a Packet.
*
* @throw BadAddress
* _rawAddress_ is malformed.
*/
virtual Address getAddress(WireFormatAddress const* const wireAddress) = 0;

/**
* Return the string representation of a network address.
*
* @param address
* Address whose string representation should be returned.
*/
virtual std::string addressToString(const Address address) = 0;

/**
* Serialize a network address into its Raw byte format.
*
* @param address
* Address to be serialized.
* @param[out] wireAddress
* WireFormatAddress object to which the Address is serialized.
*/
virtual void addressToWireFormat(const Address address,
WireFormatAddress* wireAddress) = 0;

/**
* Allocate a new Packet object from the Driver's pool of resources. The
* caller must eventually release the packet by passing it to a call to
Expand Down Expand Up @@ -187,8 +131,16 @@ class Driver {
*
* @param packet
* Packet to be sent over the network.
* @param destination
* IP address of the packet destination.
* @param priority
* Packet's network priority; the lowest possible priority is 0.
* The highest priority is positive number defined by the Driver;
* the highest priority can be queried by calling the method
* getHighestPacketPriority().
*/
virtual void sendPacket(Packet* packet) = 0;
virtual void sendPacket(Packet* packet, IpAddress destination,
int priority) = 0;

/**
* Request that the Driver enter the "corked" mode where outbound packets
Expand Down Expand Up @@ -218,17 +170,21 @@ class Driver {
*
* @param maxPackets
* The maximum number of Packet objects that should be returned by
* this method.
* this method.
* @param[out] receivedPackets
* Received packets are appended to this array in order of arrival.
* @param[out] sourceAddresses
* Source IP addresses of the received packets are appended to this
* array in order of arrival.
*
* @return
* Number of Packet objects being returned.
*
* @sa Driver::releasePackets()
*/
virtual uint32_t receivePackets(uint32_t maxPackets,
Packet* receivedPackets[]) = 0;
Packet* receivedPackets[],
IpAddress sourceAddresses[]) = 0;

/**
* Release a collection of Packet objects back to the Driver. Every
Expand Down Expand Up @@ -273,10 +229,10 @@ class Driver {
virtual uint32_t getBandwidth() = 0;

/**
* Return this Driver's local network Address which it uses as the source
* Address for outgoing packets.
* Return this Driver's local IP address which it uses as the source
* address for outgoing packets.
*/
virtual Address getLocalAddress() = 0;
virtual IpAddress getLocalAddress() = 0;

/**
* Return the number of bytes that have been passed to the Driver through
Expand Down
34 changes: 13 additions & 21 deletions include/Homa/Drivers/DPDK/DpdkDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ class DpdkDriver : public Driver {
* has exclusive access to DPDK. Note: This call will initialize the DPDK
* EAL with default values.
*
* @param port
* Selects which physical port to use for communication.
* @param ifname
* Selects which network interface to use for communication.
* @param config
* Optional configuration parameters (see Config).
* @throw DriverInitFailure
* Thrown if DpdkDriver fails to initialize for any reason.
*/
DpdkDriver(int port, const Config* const config = nullptr);
DpdkDriver(const char* ifname, const Config* const config = nullptr);

/**
* Construct a DpdkDriver and initialize the DPDK EAL using the provided
Expand All @@ -75,7 +75,7 @@ class DpdkDriver : public Driver {
* overriding the default affinity set by rte_eal_init().
*
* @param port
* Selects which physical port to use for communication.
* Selects which network interface to use for communication.
* @param argc
* Parameter passed to rte_eal_init().
* @param argv
Expand All @@ -85,7 +85,7 @@ class DpdkDriver : public Driver {
* @throw DriverInitFailure
* Thrown if DpdkDriver fails to initialize for any reason.
*/
DpdkDriver(int port, int argc, char* argv[],
DpdkDriver(const char* ifname, int argc, char* argv[],
const Config* const config = nullptr);

/// Used to signal to the DpdkDriver constructor that the DPDK EAL should
Expand All @@ -101,7 +101,7 @@ class DpdkDriver : public Driver {
* called before calling this constructor.
*
* @param port
* Selects which physical port to use for communication.
* Selects which network interface to use for communication.
* @param _
* Parameter is used only to define this constructors alternate
* signature.
Expand All @@ -110,29 +110,20 @@ class DpdkDriver : public Driver {
* @throw DriverInitFailure
* Thrown if DpdkDriver fails to initialize for any reason.
*/
DpdkDriver(int port, NoEalInit _, const Config* const config = nullptr);
DpdkDriver(const char* ifname, NoEalInit _,
const Config* const config = nullptr);

/**
* DpdkDriver Destructor.
*/
virtual ~DpdkDriver();

/// See Driver::getAddress()
virtual Address getAddress(std::string const* const addressString);
virtual Address getAddress(WireFormatAddress const* const wireAddress);

/// See Driver::addressToString()
virtual std::string addressToString(const Address address);

/// See Driver::addressToWireFormat()
virtual void addressToWireFormat(const Address address,
WireFormatAddress* wireAddress);

/// See Driver::allocPacket()
virtual Packet* allocPacket();

/// See Driver::sendPacket()
virtual void sendPacket(Packet* packet);
virtual void sendPacket(Packet* packet, IpAddress destination,
int priority);

/// See Driver::cork()
virtual void cork();
Expand All @@ -142,7 +133,8 @@ class DpdkDriver : public Driver {

/// See Driver::receivePackets()
virtual uint32_t receivePackets(uint32_t maxPackets,
Packet* receivedPackets[]);
Packet* receivedPackets[],
IpAddress sourceAddresses[]);

/// See Driver::releasePackets()
virtual void releasePackets(Packet* packets[], uint16_t numPackets);
Expand All @@ -157,7 +149,7 @@ class DpdkDriver : public Driver {
virtual uint32_t getBandwidth();

/// See Driver::getLocalAddress()
virtual Driver::Address getLocalAddress();
virtual IpAddress getLocalAddress();

/// See Driver::getQueuedBytes();
virtual uint32_t getQueuedBytes();
Expand Down
Loading