Skip to content

Commit 2975e7f

Browse files
p-shah256facebook-github-bot
authored andcommitted
Add XDP-level counters for improved visibility
Summary: Add dedicated XDP-level statistics counters to improve observability of packet processing at the XDP layer. introduces new counters: `XDP_TOTAL_CNTR`, `XDP_TX_CNTR`, `XDP_DROP_CNTR`, and `XDP_PASS_CNTR` Reviewed By: nikhildl12 Differential Revision: D82544156 fbshipit-source-id: 7045912a5ec4bd9fda1e30b7cf8ca0f6b1d60eaa
1 parent 9248941 commit 2975e7f

2 files changed

Lines changed: 39 additions & 3 deletions

File tree

katran/lib/bpf/balancer.bpf.c

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,22 +1077,50 @@ int balancer_ingress(struct xdp_md* ctx) {
10771077
__u32 eth_proto;
10781078
__u32 nh_off;
10791079
nh_off = sizeof(struct ethhdr);
1080+
__u64 data_len = data_end - data;
1081+
struct lb_stats* data_stats;
1082+
__u32 stats_key;
10801083

10811084
if (data + nh_off > data_end) {
10821085
// bogus packet, len less than minimum ethernet frame size
10831086
return XDP_DROP;
10841087
}
10851088

1089+
stats_key = MAX_VIPS + XDP_TOTAL_CNTR;
1090+
data_stats = bpf_map_lookup_elem(&stats, &stats_key);
1091+
if (!data_stats) {
1092+
return XDP_DROP;
1093+
}
1094+
data_stats->v1 += 1;
1095+
data_stats->v2 += data_len;
1096+
10861097
eth_proto = eth->h_proto;
10871098

1099+
int action;
10881100
if (eth_proto == BE_ETH_P_IP) {
1089-
return process_packet(ctx, nh_off, false);
1101+
action = process_packet(ctx, nh_off, false);
10901102
} else if (eth_proto == BE_ETH_P_IPV6) {
1091-
return process_packet(ctx, nh_off, true);
1103+
action = process_packet(ctx, nh_off, true);
10921104
} else {
10931105
// pass to tcp/ip stack
1094-
return XDP_PASS;
1106+
action = XDP_PASS;
10951107
}
1108+
1109+
if (action == XDP_PASS) {
1110+
stats_key = MAX_VIPS + XDP_PASS_CNTR;
1111+
} else if (action == XDP_DROP) {
1112+
stats_key = MAX_VIPS + XDP_DROP_CNTR;
1113+
} else if (action == XDP_TX) {
1114+
stats_key = MAX_VIPS + XDP_TX_CNTR;
1115+
}
1116+
1117+
data_stats = bpf_map_lookup_elem(&stats, &stats_key);
1118+
if (!data_stats) {
1119+
return XDP_DROP;
1120+
}
1121+
data_stats->v1 += 1;
1122+
data_stats->v2 += data_len;
1123+
return action;
10961124
}
10971125

10981126
char _license[] SEC("license") = "GPL";

katran/lib/bpf/balancer_consts.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,11 @@
254254
#define NO_FLAGS 0
255255

256256
// offset of the lru cache hit related counters
257+
/* v1 tracks total vip packets (no longer used for lru calculations)
258+
v2 tracks lru misses */
257259
#define LRU_CNTRS 0
260+
/* v1 tracks misses for TCP syns
261+
v2 tracks misses for TCP non syns */
258262
#define LRU_MISS_CNTR 1
259263
#define NEW_CONN_RATE_CNTR 2
260264
#define FALLBACK_LRU_CNTR 3
@@ -281,6 +285,10 @@
281285
#define XPOP_DECAP_SUCCESSFUL 14
282286
// Tracks packets dst invalidated due to UDP flow migration
283287
#define UDP_FLOW_MIGRATION_STATS 15
288+
#define XDP_TOTAL_CNTR 16 // total packets "touched" by katran
289+
#define XDP_TX_CNTR 17 // total packets sent to backend
290+
#define XDP_DROP_CNTR 18 // total packets dropped by katran
291+
#define XDP_PASS_CNTR 19 // packets passed up to the kernel
284292

285293
// indice for all stats maps defined above correspond to entries in the map
286294
// stats starting from the index MAX_VIPS. The max_entries of stats is

0 commit comments

Comments
 (0)