diff --git a/src/tcp_conn_tuner.bpf.c b/src/tcp_conn_tuner.bpf.c index bb21d84..6f2991c 100644 --- a/src/tcp_conn_tuner.bpf.c +++ b/src/tcp_conn_tuner.bpf.c @@ -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: @@ -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; } @@ -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) { diff --git a/test/cong_legacy_test.sh b/test/cong_legacy_test.sh index d9e23de..34feb34 100644 --- a/test/cong_legacy_test.sh +++ b/test/cong_legacy_test.sh @@ -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 diff --git a/test/cong_test.sh b/test/cong_test.sh index 67532ef..2792de9 100644 --- a/test/cong_test.sh +++ b/test/cong_test.sh @@ -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