Skip to content

Commit

Permalink
Basic functionality work
Browse files Browse the repository at this point in the history
  • Loading branch information
ccanel committed Apr 30, 2024
1 parent 008da48 commit b08c8c9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
29 changes: 22 additions & 7 deletions ratemon/runtime/libratemon_interp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
#include "ratemon.h"
#include "ratemon_maps.skel.h"

//
bool setup = false;
volatile bool setup = false;
volatile bool skipped_first = false;

// BPF things.
struct ratemon_maps_bpf *skel = NULL;
Expand Down Expand Up @@ -103,7 +103,10 @@ void thread_func() {
continue;
}

// RM_PRINTF("Performing scheduling\n");
RM_PRINTF("Performing scheduling\n");

prev_active_fds.clear();
new_active_fds.clear();

// Make a copy of the currently (soon-to-be previously) active flows.
active_fds.visit_all([&](const int &fd) { prev_active_fds.push_back(fd); });
Expand Down Expand Up @@ -136,7 +139,8 @@ void thread_func() {
RM_PRINTF("\n");

// For each fo the previously active flows, add it to the paused set, remove
// it from the active set, and install an RWND mapping to actually pause it.
// it from the active set, install an RWND mapping to actually pause it, and
// trigger an ACK to communicate the new RWND value.
RM_PRINTF("Pausing %lu flows: ", prev_active_fds.size());
for (const auto &fd : prev_active_fds) {
RM_PRINTF("%d ", fd);
Expand All @@ -145,6 +149,8 @@ void thread_func() {
fd_to_flow.visit(fd, [](const auto &p) {
bpf_map_update_elem(flow_to_rwnd_fd, &p.second, &zero, BPF_ANY);
});
// TODO: Do we need to send an ACK to immediately pause the flow?
trigger_ack(fd);
}
RM_PRINTF("\n");

Expand Down Expand Up @@ -209,6 +215,15 @@ int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen) {
setup = true;
}

// Hack for iperf3. The first flow is a control flow that should not be
// scheduled. Note that for this hack to work, libratemon_interp must be
// restarted between tests.
if (fd_to_flow.size() == 0 && !skipped_first) {
RM_PRINTF("WARNING skipping first flow\n");
skipped_first = true;
return new_fd;
}

// Set the CCA and make sure it was set correctly.
if (setsockopt(new_fd, SOL_TCP, TCP_CONGESTION, RM_BPF_CUBIC,
strlen(RM_BPF_CUBIC)) == -1) {
Expand Down Expand Up @@ -289,9 +304,9 @@ int close(int sockfd) {
// To get the flow struct for this FD, we must use visit() to look it up
// in the concurrent_flat_map. Obviously, do this before removing the FD
// from fd_to_flow.
// fd_to_flow.visit(sockfd, [](const auto &p) {
// bpf_map_delete_elem(flow_to_rwnd_fd, &p.second);
// });
fd_to_flow.visit(sockfd, [](const auto &p) {
bpf_map_delete_elem(flow_to_rwnd_fd, &p.second);
});
fd_to_flow.erase(sockfd);

RM_PRINTF("Successful 'close' for FD=%d\n", sockfd);
Expand Down
2 changes: 1 addition & 1 deletion ratemon/runtime/ratemon.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#define __RATEMON_H

// Comment out the below line to disable verbose logging.
#define RM_VERBOSE
// #define RM_VERBOSE

#ifdef RM_VERBOSE
#define RM_PRINTF(...) printf(__VA_ARGS__)
Expand Down

0 comments on commit b08c8c9

Please sign in to comment.