Skip to content

Commit a2dcc16

Browse files
committed
af_xdp: Resize the XSPMAP to num of rxq in xdp_onload_prepare
xdp_tstamp.c currectly hardcodes the XSKMAP size to 4, but it redirects to XSKs based on ctx->rx_queue_index. We can look up the number of queues with an ethtool ioctl and resize the XSKMAP before loading the map into the kernel. The non-xdp_tstamp path works fine because xdp_map_create in efhw/af_xdp.c creates max_entries = nic->vi_lim. Signed-off-by: YiFei Zhu <zhuyifei@google.com>
1 parent d4269ef commit a2dcc16

1 file changed

Lines changed: 34 additions & 1 deletion

File tree

src/tools/bpf_link_helper/xdp_onload_prepare.c

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,55 @@
88

99
#include <errno.h>
1010
#include <error.h>
11+
#include <linux/ethtool.h>
1112
#include <linux/if_link.h>
13+
#include <linux/sockios.h>
1214
#include <net/if.h>
1315
#include <stdlib.h>
16+
#include <sys/ioctl.h>
17+
#include <unistd.h>
1418

1519
#include <bpf/bpf.h>
1620
#include <bpf/libbpf.h>
1721

22+
static int get_num_rxq(char *ifname)
23+
{
24+
struct ethtool_channels ch = {
25+
.cmd = ETHTOOL_GCHANNELS,
26+
};
27+
struct ifreq ifr = {
28+
.ifr_data = (void *)&ch,
29+
};
30+
int fd, ret;
31+
32+
strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
33+
34+
fd = socket(AF_UNIX, SOCK_DGRAM, 0);
35+
if (fd < 0)
36+
error(1, errno, "socket");
37+
38+
ret = ioctl(fd, SIOCETHTOOL, &ifr);
39+
if (ret < 0)
40+
error(1, errno, "ioctl SIOCETHTOOL");
41+
42+
close(fd);
43+
44+
return ch.rx_count + ch.combined_count;
45+
}
46+
1847
int main(int argc, char **argv)
1948
{
2049
struct bpf_object *obj;
2150
struct bpf_program *prog;
2251
struct bpf_map *map_xsk;
2352
int prog_fd, ifindex;
53+
char *ifname;
2454

2555
if (argc != 3)
2656
error(1, 0, "Usage: %s [ifname] [bpf_file]\n", argv[0]);
2757

28-
ifindex = if_nametoindex(argv[1]);
58+
ifname = argv[1];
59+
ifindex = if_nametoindex(ifname);
2960
if (!ifindex)
3061
error(1, errno, "if_nametoindex %s", argv[1]);
3162

@@ -37,6 +68,8 @@ int main(int argc, char **argv)
3768
if (!map_xsk)
3869
error(1, 0, "bpf_object__find_map_by_name onload_xdp_xsk");
3970

71+
bpf_map__set_max_entries(map_xsk, get_num_rxq(ifname));
72+
4073
prog = bpf_object__find_program_by_name(obj, "xdp_onload_prog");
4174
if (!prog)
4275
error(1, 0, "bpf_object__find_program_by_name");

0 commit comments

Comments
 (0)