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

TCP CCAs in Rust #1062

Draft
wants to merge 13 commits into
base: staging/rust-net
Choose a base branch
from
42 changes: 42 additions & 0 deletions net/ipv4/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,22 @@ config INET_DIAG_DESTROY
had been disconnected.
If unsure, say N.

config RUST_SOCK_ABSTRACTIONS
bool "INET: Rust sock abstractions"
depends on RUST
help
Adds Rust abstractions for working with `struct sock`s.

If unsure, say N.

config RUST_TCP_ABSTRACTIONS
bool "TCP: Rust abstractions"
depends on RUST_SOCK_ABSTRACTIONS
help
Adds support for writing Rust kernel modules that integrate with TCP.

If unsure, say N.

menuconfig TCP_CONG_ADVANCED
bool "TCP: advanced congestion control"
help
Expand Down Expand Up @@ -493,6 +509,15 @@ config TCP_CONG_BIC
increase provides TCP friendliness.
See http://www.csc.ncsu.edu/faculty/rhee/export/bitcp/

config TCP_CONG_BIC_RUST
tristate "Binary Increase Congestion (BIC) control (Rust rewrite)"
depends on RUST_TCP_ABSTRACTIONS
help
Rust rewrite of the original implementation of Binary Increase
Congestion (BIC) control.

If unsure, say N.

config TCP_CONG_CUBIC
tristate "CUBIC TCP"
default y
Expand All @@ -501,6 +526,15 @@ config TCP_CONG_CUBIC
among other techniques.
See http://www.csc.ncsu.edu/faculty/rhee/export/bitcp/cubic-paper.pdf

config TCP_CONG_CUBIC_RUST
tristate "CUBIC TCP (Rust rewrite)"
depends on RUST_TCP_ABSTRACTIONS
help
Rust rewrite of the original implementation of TCP CUBIC congestion
control.

If unsure, say N.

config TCP_CONG_WESTWOOD
tristate "TCP Westwood+"
default m
Expand Down Expand Up @@ -688,9 +722,15 @@ choice
config DEFAULT_BIC
bool "Bic" if TCP_CONG_BIC=y

config DEFAULT_BIC_RUST
bool "Bic (Rust)" if TCP_CONG_BIC_RUST=y

config DEFAULT_CUBIC
bool "Cubic" if TCP_CONG_CUBIC=y

config DEFAULT_CUBIC_RUST
bool "Cubic (Rust)" if TCP_CONG_CUBIC_RUST=y

config DEFAULT_HTCP
bool "Htcp" if TCP_CONG_HTCP=y

Expand Down Expand Up @@ -729,7 +769,9 @@ config TCP_CONG_CUBIC
config DEFAULT_TCP_CONG
string
default "bic" if DEFAULT_BIC
default "bic_rust" if DEFAULT_BIC_RUST
default "cubic" if DEFAULT_CUBIC
default "cubic_rust" if DEFAULT_CUBIC_RUST
default "htcp" if DEFAULT_HTCP
default "hybla" if DEFAULT_HYBLA
default "vegas" if DEFAULT_VEGAS
Expand Down
2 changes: 2 additions & 0 deletions net/ipv4/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ obj-$(CONFIG_INET_UDP_DIAG) += udp_diag.o
obj-$(CONFIG_INET_RAW_DIAG) += raw_diag.o
obj-$(CONFIG_TCP_CONG_BBR) += tcp_bbr.o
obj-$(CONFIG_TCP_CONG_BIC) += tcp_bic.o
obj-$(CONFIG_TCP_CONG_BIC_RUST) += tcp_bic_rust.o
obj-$(CONFIG_TCP_CONG_CDG) += tcp_cdg.o
obj-$(CONFIG_TCP_CONG_CUBIC) += tcp_cubic.o
obj-$(CONFIG_TCP_CONG_CUBIC_RUST) += tcp_cubic_rust.o
obj-$(CONFIG_TCP_CONG_DCTCP) += tcp_dctcp.o
obj-$(CONFIG_TCP_CONG_WESTWOOD) += tcp_westwood.o
obj-$(CONFIG_TCP_CONG_HSTCP) += tcp_highspeed.o
Expand Down
51 changes: 49 additions & 2 deletions net/ipv4/tcp_bic.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include <linux/mm.h>
#include <linux/module.h>
#include <linux/time.h>
#include <net/tcp.h>

#define BICTCP_BETA_SCALE 1024 /* Scale factor beta calculation
Expand Down Expand Up @@ -55,6 +56,7 @@ struct bictcp {
u32 epoch_start; /* beginning of an epoch */
#define ACK_RATIO_SHIFT 4
u32 delayed_ack; /* estimate the ratio of Packets/ACKs << 4 */
u64 start_time;
};

static inline void bictcp_reset(struct bictcp *ca)
Expand All @@ -65,6 +67,7 @@ static inline void bictcp_reset(struct bictcp *ca)
ca->last_time = 0;
ca->epoch_start = 0;
ca->delayed_ack = 2 << ACK_RATIO_SHIFT;
ca->start_time = ktime_get_boot_fast_ns();
}

static void bictcp_init(struct sock *sk)
Expand All @@ -75,6 +78,19 @@ static void bictcp_init(struct sock *sk)

if (initial_ssthresh)
tcp_sk(sk)->snd_ssthresh = initial_ssthresh;

pr_info("Socket created: start %llu\n", ca->start_time);
}

static void bictcp_release(struct sock* sk)
{
struct bictcp *ca = inet_csk_ca(sk);

pr_info(
"Socket destroyed: start %llu, end %llu\n",
ca->start_time,
ktime_get_boot_fast_ns()
);
}

/*
Expand Down Expand Up @@ -147,11 +163,23 @@ static void bictcp_cong_avoid(struct sock *sk, u32 ack, u32 acked)

if (tcp_in_slow_start(tp)) {
acked = tcp_slow_start(tp, acked);
if (!acked)
if (!acked) {
pr_info(
"New cwnd: %u, time %llu, ssthresh %u, start %llu, ss 1\n",
tp->snd_cwnd, ktime_get_boot_fast_ns(),
tp->snd_ssthresh, ca->start_time
);
return;
}
}
bictcp_update(ca, tcp_snd_cwnd(tp));
tcp_cong_avoid_ai(tp, ca->cnt, acked);

pr_info(
"New cwnd: %u, time %llu, ssthresh %u, start %llu, ss 1\n",
tp->snd_cwnd, ktime_get_boot_fast_ns(),
tp->snd_ssthresh, ca->start_time
);
}

/*
Expand All @@ -163,6 +191,12 @@ static u32 bictcp_recalc_ssthresh(struct sock *sk)
const struct tcp_sock *tp = tcp_sk(sk);
struct bictcp *ca = inet_csk_ca(sk);

pr_info(
"Enter fast retransmit: time %llu, start %llu\n",
ktime_get_boot_fast_ns(),
ca->start_time
);

ca->epoch_start = 0; /* end of epoch */

/* Wmax and fast convergence */
Expand All @@ -180,8 +214,20 @@ static u32 bictcp_recalc_ssthresh(struct sock *sk)

static void bictcp_state(struct sock *sk, u8 new_state)
{
if (new_state == TCP_CA_Loss)
if (new_state == TCP_CA_Loss) {
struct bictcp *ca = inet_csk_ca(sk);
u64 tmp = ca->start_time;

pr_info(
"Retransmission timeout fired: time %llu, start %llu\n",
ktime_get_boot_fast_ns(),
ca->start_time
);

bictcp_reset(inet_csk_ca(sk));

ca->start_time = tmp;
}
}

/* Track delayed acknowledgment ratio using sliding window
Expand All @@ -201,6 +247,7 @@ static void bictcp_acked(struct sock *sk, const struct ack_sample *sample)

static struct tcp_congestion_ops bictcp __read_mostly = {
.init = bictcp_init,
.release = bictcp_release,
.ssthresh = bictcp_recalc_ssthresh,
.cong_avoid = bictcp_cong_avoid,
.set_state = bictcp_state,
Expand Down
Loading