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
5 changes: 5 additions & 0 deletions include/bpftune/libbpftune.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand Down
32 changes: 22 additions & 10 deletions src/libbpftune.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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++) {
Expand All @@ -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;
}

Expand Down Expand Up @@ -1008,20 +1007,33 @@ 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] :
tunable->stats.nonglobal_ns[scenario]);

}

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,
Expand Down Expand Up @@ -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);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/libbpftune.map
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 9 additions & 3 deletions src/tcp_conn_tuner.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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];
Expand All @@ -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;
}
}
}
Expand All @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions src/tcp_conn_tuner.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down