diff --git a/include/bpftune/libbpftune.h b/include/bpftune/libbpftune.h index b88280b..c434bc5 100644 --- a/include/bpftune/libbpftune.h +++ b/include/bpftune/libbpftune.h @@ -127,6 +127,11 @@ int bpftuner_tunable_update(struct bpftuner *tuner, int netns_fd, const char *fmt, ...); +void bpftuner_tunable_stats_update(struct bpftuner *tuner, + unsigned int tunable, + unsigned int scenario, bool global_ns, + unsigned long val); + struct bpftuner *bpftune_tuner(unsigned int index); unsigned int bpftune_tuner_num(void); #define bpftune_for_each_tuner(tuner) \ diff --git a/src/libbpftune.c b/src/libbpftune.c index ef239d8..47e5dcb 100644 --- a/src/libbpftune.c +++ b/src/libbpftune.c @@ -701,13 +701,13 @@ struct bpftuner *bpftuner_init(const char *path) return tuner; } +static unsigned long global_netns_cookie; + static void bpftuner_scenario_log(struct bpftuner *tuner, unsigned int tunable, unsigned int scenario, int netns_fd, bool summary, const char *fmt, va_list args); -static unsigned long global_netns_cookie; - void bpftuner_fini(struct bpftuner *tuner, enum bpftune_state state) { unsigned int i, j; @@ -717,6 +717,8 @@ void bpftuner_fini(struct bpftuner *tuner, enum bpftune_state state) bpftune_log(LOG_DEBUG, "cleaning up tuner %s with %d tunables, %d scenarios\n", tuner->name, tuner->num_tunables, tuner->num_scenarios); + if (tuner->fini) + tuner->fini(tuner); /* report summary of events for tuner */ for (i = 0; i < tuner->num_tunables; i++) { for (j = 0; j < tuner->num_scenarios; j++) { @@ -727,9 +729,6 @@ void bpftuner_fini(struct bpftuner *tuner, enum bpftune_state state) bpftuner_scenario_log(tuner, i, j, 1, true, NULL, args); } } - if (tuner->fini) - tuner->fini(tuner); - tuner->state = state; } @@ -1008,13 +1007,14 @@ struct bpftunable *bpftuner_tunable(struct bpftuner *tuner, unsigned int index) return NULL; } -static void bpftuner_tunable_stats_update(struct bpftunable *tunable, - unsigned int scenario, bool global_ns) +static void __bpftuner_tunable_stats_update(struct bpftunable *tunable, + unsigned int scenario, bool global_ns, + unsigned long val) { if (global_ns) - (tunable->stats.global_ns[scenario])++; + (tunable->stats.global_ns[scenario]) += val; else - (tunable->stats.nonglobal_ns[scenario])++; + (tunable->stats.nonglobal_ns[scenario]) += val; bpftune_log(LOG_DEBUG," updated stat for tunable %s, scenario %d: %lu\n", tunable->desc.name, scenario, global_ns ? tunable->stats.global_ns[scenario] : @@ -1022,6 +1022,18 @@ static void bpftuner_tunable_stats_update(struct bpftunable *tunable, } +void bpftuner_tunable_stats_update(struct bpftuner *tuner, + unsigned int tunable, + unsigned int scenario, bool global_ns, + unsigned long val) +{ + struct bpftunable *t = bpftuner_tunable(tuner, tunable); + + if (!t) + return; + __bpftuner_tunable_stats_update(t, scenario, global_ns, val); +} + static void bpftuner_scenario_log(struct bpftuner *tuner, unsigned int tunable, unsigned int scenario, int netns_fd, bool summary, @@ -1078,7 +1090,7 @@ static void bpftuner_scenario_log(struct bpftuner *tuner, unsigned int tunable, global_ns ? "" : "non-", tuner->scenarios[scenario].description); __bpftune_log(BPFTUNE_LOG_LEVEL, fmt, args); - bpftuner_tunable_stats_update(t, scenario, global_ns); + __bpftuner_tunable_stats_update(t, scenario, global_ns, 1); } } diff --git a/src/libbpftune.map b/src/libbpftune.map index ecbc582..fcc7c43 100644 --- a/src/libbpftune.map +++ b/src/libbpftune.map @@ -29,6 +29,7 @@ LIBBPFTUNE_0.1.1 { bpftuner_num_tunables; bpftuner_tunable_sysctl_write; bpftuner_tunable_update; + bpftuner_tunable_stats_update; bpftuner_fini; bpftuner_bpf_fini; bpftuner_bpf_set_autoload; diff --git a/src/tcp_conn_tuner.c b/src/tcp_conn_tuner.c index f6d3f43..0eba2f7 100644 --- a/src/tcp_conn_tuner.c +++ b/src/tcp_conn_tuner.c @@ -38,8 +38,8 @@ static struct bpftunable_desc descs[] = { }; static struct bpftunable_scenario scenarios[] = { -{ TCP_CONG_BBR, "specify bbr congestion control", - "Because loss rate has exceeded 1 percent for a connection, use bbr congestion control algorithm instead of default" }, +{ TCP_CONG_SET, "specify TCP congestion control algorithm", + "To optimize TCP performance, a TCP congestion control algorithm was chosen to mimimize round-trip time and maximize delivery rate." }, }; struct tcp_conn_tuner_bpf *skel; @@ -89,6 +89,7 @@ static void summarize_conn_choices(struct bpftuner *tuner) struct bpf_map *map = bpftuner_bpf_map_get(tcp_conn, tuner, remote_host_map); struct in6_addr key, *prev_key = NULL; int map_fd = bpf_map__fd(map); + unsigned long greedy_count = 0; while (!bpf_map_get_next_key(map_fd, prev_key, &key)) { char buf[INET6_ADDRSTRLEN]; @@ -113,6 +114,10 @@ static void summarize_conn_choices(struct bpftuner *tuner) r.metrics[i].greedy_count, r.metrics[i].min_rtt, r.metrics[i].max_rate_delivered); + bpftuner_tunable_stats_update(tuner, TCP_CONG, + TCP_CONG_SET, true, + r.metrics[i].metric_count); + greedy_count += r.metrics[i].greedy_count; } } } @@ -135,7 +140,8 @@ void event_handler(struct bpftuner *tuner, struct bpftune_event *event, inet_ntop(AF_INET6, &event_data->raddr, buf, sizeof(buf)); bpftune_log(LOG_DEBUG, -"%s: cong alg '%s': got rate_delivered %lld, rtt %lld, metric %lld\n", +"%s: %s: cong alg '%s': got rate_delivered %lld, rtt %lld, metric %lld\n", + tuner->name, buf, congs[state], event_data->rate_delivered, event_data->min_rtt, diff --git a/src/tcp_conn_tuner.h b/src/tcp_conn_tuner.h index cbc4c67..b2e7857 100644 --- a/src/tcp_conn_tuner.h +++ b/src/tcp_conn_tuner.h @@ -24,8 +24,7 @@ enum tcp_cong_tunables { }; enum tcp_cong_scenarios { - TCP_CONG_BBR, - TCP_CONG_HTCP, + TCP_CONG_SET }; #define CONG_MAXNAME 16