Skip to content

Commit

Permalink
tcp:add sociopath
Browse files Browse the repository at this point in the history
original source: @mlucy
https://github.com/mlucy/tcp_sociopath

Signed-off-by: HolyAngel <slverwolf@gmail.com>
  • Loading branch information
mlucy authored and acuicultor committed Aug 30, 2021
1 parent 020baed commit e464278
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
11 changes: 11 additions & 0 deletions net/ipv4/Kconfig
Expand Up @@ -680,6 +680,13 @@ config TCP_CONG_BBR
bufferbloat, policers, or AQM schemes that do not provide a delay
signal. It requires the fq ("Fair Queue") pacing packet scheduler.

config TCP_CONG_SOCIOPATH
tristate "TCP Sociopath"
default n
---help---
This is basically TCP Reno with no slow start and a much more
aggressive ssthresh recalculation (lowers it by 5% instead of 50%).

choice
prompt "Default TCP congestion control"
default DEFAULT_CUBIC
Expand Down Expand Up @@ -717,6 +724,9 @@ choice
config DEFAULT_BBR
bool "BBR" if TCP_CONG_BBR=y

config DEFAULT_SOCIOPATH
bool "Sociopath" if TCP_CONG_SOCIOPATH=y

config DEFAULT_RENO
bool "Reno"
endchoice
Expand All @@ -741,6 +751,7 @@ config DEFAULT_TCP_CONG
default "dctcp" if DEFAULT_DCTCP
default "cdg" if DEFAULT_CDG
default "bbr" if DEFAULT_BBR
default "sociopath" if DEFAULT_SOCIOPATH
default "cubic"

config TCP_MD5SIG
Expand Down
1 change: 1 addition & 0 deletions net/ipv4/Makefile
Expand Up @@ -64,6 +64,7 @@ obj-$(CONFIG_TCP_CONG_SCALABLE) += tcp_scalable.o
obj-$(CONFIG_TCP_CONG_LP) += tcp_lp.o
obj-$(CONFIG_TCP_CONG_YEAH) += tcp_yeah.o
obj-$(CONFIG_TCP_CONG_ILLINOIS) += tcp_illinois.o
obj-$(CONFIG_TCP_CONG_SOCIOPATH) += tcp_sociopath.o
obj-$(CONFIG_NETLABEL) += cipso_ipv4.o

obj-$(CONFIG_XFRM) += xfrm4_policy.o xfrm4_state.o xfrm4_input.o \
Expand Down
48 changes: 48 additions & 0 deletions net/ipv4/tcp_sociopath.c
@@ -0,0 +1,48 @@
#include <linux/mm.h>
#include <linux/module.h>
#include <linux/skbuff.h>
#include <linux/inet_diag.h>
#include <net/tcp.h>

static int lambda = 20;
module_param(lambda, int, 0644);
MODULE_PARM_DESC(lambda, "degree of sociopathy");

static u32 tcp_sociopath_ssthresh(struct sock *sk) {
u32 cwnd = tcp_sk(sk)->snd_cwnd;
return max(cwnd-(cwnd/lambda), 2U);
}

static void tcp_sociopath_cong_avoid(struct sock *sk, u32 ack, u32 in_flight) {
struct tcp_sock *tp = tcp_sk(sk);
if (tp->snd_cwnd <= tp->snd_ssthresh) {
if (tp->snd_cwnd < lambda*10) tp->snd_cwnd = lambda*10;
tcp_reno_cong_avoid(sk, ack, in_flight);
} else {
tcp_reno_cong_avoid(sk, ack, in_flight);
}
}

static struct tcp_congestion_ops tcp_sociopath = {
.owner = THIS_MODULE,
.name = "sociopath",

.ssthresh = tcp_sociopath_ssthresh,
.cong_avoid = tcp_sociopath_cong_avoid
};

static int __init tcp_sociopath_register(void) {
tcp_register_congestion_control(&tcp_sociopath);
return 0;
}

static void __exit tcp_sociopath_unregister(void) {
tcp_unregister_congestion_control(&tcp_sociopath);
}

module_init(tcp_sociopath_register);
module_exit(tcp_sociopath_unregister);

MODULE_AUTHOR("Michael Lucy");
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("TCP Sociopath");

0 comments on commit e464278

Please sign in to comment.