Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
33 changes: 14 additions & 19 deletions src/tcp_conn_tuner.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ int conn_tuner_sockops(struct bpf_sock_ops *ops)
switch (ops->op) {
case BPF_SOCK_OPS_ACTIVE_ESTABLISHED_CB:
case BPF_SOCK_OPS_PASSIVE_ESTABLISHED_CB:
/* enable retransmission events */
/* enable other needed events */
bpf_sock_ops_cb_flags_set(ops, cb_flags);
break;
case BPF_SOCK_OPS_STATE_CB:
Expand Down Expand Up @@ -128,43 +128,38 @@ int conn_tuner_sockops(struct bpf_sock_ops *ops)
__u8 i, ncands = 0, minindex = 0, s;
__u8 cands[NUM_TCP_CONN_METRICS];

/* find highest metric and use cong alg based on it. */
/* find best (minimum) metric and use cong alg based on it. */
for (i = 0; i < NUM_TCP_CONN_METRICS; i++) {
cands[i] = 0;
metric_value = remote_host->metrics[i].metric_value;
bpftune_debug("conn_tuner: addr 0x%x cong '%s' metric_value %lld\n",
ops->remote_ip4, congs[i], metric_value);

if (metric_value > metric_min)
continue;
if (metric_value < metric_min) {
else if (metric_value < metric_min) {
cands[0] = i;
ncands = 1;
} else if (metric_value == metric_min) {
cands[ncands++] = i;
cands[ncands] = i;
ncands++;
}
metric_min = metric_value;
}
/* if multiple min values, choose randomly. */
if (ncands > 1) {
int choice = bpf_get_prandom_u32() % ncands;
if (ncands > 1 && ncands <= NUM_TCP_CONN_METRICS) {
__u32 choice = bpf_get_prandom_u32() % ncands;

/* verifier refused to believe the index used was valid, so
* unroll the mapping from chice to cands[] index to keep
* verification happy.
*/
/* verifier complains about variable stack offset */
switch (choice) {
case 0:
minindex = cands[0];
break;
minindex = cands[0]; break;
case 1:
minindex = cands[1];
break;
minindex = cands[1]; break;
case 2:
minindex = cands[2];
break;
minindex = cands[2]; break;
case 3:
minindex = cands[3];
break;
minindex = cands[3]; break;
default:
return 1;
}
Expand All @@ -173,7 +168,7 @@ int conn_tuner_sockops(struct bpf_sock_ops *ops)
} else {
return 1;
}
minindex &= 0x3;
minindex &= (NUM_TCP_CONN_METRICS - 1);
/* choose random alg 5% of the time (1/20) */
s = epsilon_greedy(minindex, NUM_TCP_CONN_METRICS, 20);
if (s != minindex) {
Expand Down
2 changes: 1 addition & 1 deletion test/cong_legacy_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ for DROP_PERCENT in 0 5 ; do
echo "Running ${MODE}..."
test_run_cmd_local "ip netns exec $NETNS $IPERF3 -p $PORT -s &"
if [[ $MODE != "baseline" ]]; then
test_run_cmd_local "$BPFTUNE -dsL &" true
test_run_cmd_local "$BPFTUNE -dsL -a tcp_conn_tuner.so &" true
sleep $SETUPTIME
# warm up connection...
for i in {1..20}; do
Expand Down
2 changes: 1 addition & 1 deletion test/cong_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ for DROP_PERCENT in 0 5 ; do
echo "Running ${MODE}..."
test_run_cmd_local "ip netns exec $NETNS $IPERF3 -p $PORT -s &"
if [[ $MODE != "baseline" ]]; then
test_run_cmd_local "$BPFTUNE -ds &" true
test_run_cmd_local "$BPFTUNE -ds -a tcp_conn_tuner.so &" true
sleep $SETUPTIME
# warm up connection...
for i in {1..20}; do
Expand Down