Skip to content

Commit e8163b9

Browse files
netoptimizerAlexei Starovoitov
authored andcommitted
selftests/bpf: xdp_hw_metadata remove bpf_printk and add counters
The tool xdp_hw_metadata can be used by driver developers implementing XDP-hints metadata kfuncs. Remove all bpf_printk calls, as the tool already transfers all the XDP-hints related information via metadata area to AF_XDP userspace process. Add counters for providing remaining information about failure and skipped packet events. Signed-off-by: Jesper Dangaard Brouer <[email protected]> Acked-by: Stanislav Fomichev <[email protected]> Link: https://lore.kernel.org/r/168132891533.340624.7313781245316405141.stgit@firesoul Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 0646dc3 commit e8163b9

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed

tools/testing/selftests/bpf/progs/xdp_hw_metadata.c

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ struct {
1212
__type(value, __u32);
1313
} xsk SEC(".maps");
1414

15+
__u64 pkts_skip = 0;
16+
__u64 pkts_fail = 0;
17+
__u64 pkts_redir = 0;
18+
1519
extern int bpf_xdp_metadata_rx_timestamp(const struct xdp_md *ctx,
1620
__u64 *timestamp) __ksym;
1721
extern int bpf_xdp_metadata_rx_hash(const struct xdp_md *ctx,
@@ -26,7 +30,7 @@ int rx(struct xdp_md *ctx)
2630
struct udphdr *udp = NULL;
2731
struct iphdr *iph = NULL;
2832
struct xdp_meta *meta;
29-
int ret;
33+
int err;
3034

3135
data = (void *)(long)ctx->data;
3236
data_end = (void *)(long)ctx->data_end;
@@ -46,17 +50,20 @@ int rx(struct xdp_md *ctx)
4650
udp = NULL;
4751
}
4852

49-
if (!udp)
53+
if (!udp) {
54+
__sync_add_and_fetch(&pkts_skip, 1);
5055
return XDP_PASS;
56+
}
5157

52-
if (udp->dest != bpf_htons(9091))
58+
/* Forwarding UDP:9091 to AF_XDP */
59+
if (udp->dest != bpf_htons(9091)) {
60+
__sync_add_and_fetch(&pkts_skip, 1);
5361
return XDP_PASS;
62+
}
5463

55-
bpf_printk("forwarding UDP:9091 to AF_XDP");
56-
57-
ret = bpf_xdp_adjust_meta(ctx, -(int)sizeof(struct xdp_meta));
58-
if (ret != 0) {
59-
bpf_printk("bpf_xdp_adjust_meta returned %d", ret);
64+
err = bpf_xdp_adjust_meta(ctx, -(int)sizeof(struct xdp_meta));
65+
if (err) {
66+
__sync_add_and_fetch(&pkts_fail, 1);
6067
return XDP_PASS;
6168
}
6269

@@ -65,20 +72,19 @@ int rx(struct xdp_md *ctx)
6572
meta = data_meta;
6673

6774
if (meta + 1 > data) {
68-
bpf_printk("bpf_xdp_adjust_meta doesn't appear to work");
75+
__sync_add_and_fetch(&pkts_fail, 1);
6976
return XDP_PASS;
7077
}
7178

72-
if (!bpf_xdp_metadata_rx_timestamp(ctx, &meta->rx_timestamp))
73-
bpf_printk("populated rx_timestamp with %llu", meta->rx_timestamp);
74-
else
79+
err = bpf_xdp_metadata_rx_timestamp(ctx, &meta->rx_timestamp);
80+
if (err)
7581
meta->rx_timestamp = 0; /* Used by AF_XDP as not avail signal */
7682

77-
if (!bpf_xdp_metadata_rx_hash(ctx, &meta->rx_hash))
78-
bpf_printk("populated rx_hash with %u", meta->rx_hash);
79-
else
83+
err = bpf_xdp_metadata_rx_hash(ctx, &meta->rx_hash);
84+
if (err)
8085
meta->rx_hash = 0; /* Used by AF_XDP as not avail signal */
8186

87+
__sync_add_and_fetch(&pkts_redir, 1);
8288
return bpf_redirect_map(&xsk, ctx->rx_queue_index, XDP_PASS);
8389
}
8490

tools/testing/selftests/bpf/xdp_hw_metadata.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,9 @@ static int verify_metadata(struct xsk *rx_xsk, int rxq, int server_fd)
212212
while (true) {
213213
errno = 0;
214214
ret = poll(fds, rxq + 1, 1000);
215-
printf("poll: %d (%d)\n", ret, errno);
215+
printf("poll: %d (%d) skip=%llu fail=%llu redir=%llu\n",
216+
ret, errno, bpf_obj->bss->pkts_skip,
217+
bpf_obj->bss->pkts_fail, bpf_obj->bss->pkts_redir);
216218
if (ret < 0)
217219
break;
218220
if (ret == 0)

0 commit comments

Comments
 (0)