AF_XDP-interaction: Update ethtool_utils

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
This commit is contained in:
Jesper Dangaard Brouer
2021-11-16 15:24:31 +01:00
parent 9bca7ea4ff
commit ca9ef962de
3 changed files with 39 additions and 9 deletions

View File

@@ -748,8 +748,8 @@ static void rx_and_process(struct config *cfg,
for (i = 0; i < n_fds; i++) {
struct xsk_socket_info *xsk_info = xsks->sockets[i];
printf("XXX i[%d] queue:%d xsk_info:%p \n",
i, xsk_info->queue_id, xsk_info);
//printf("XXX i[%d] queue:%d xsk_info:%p \n",
// i, xsk_info->queue_id, xsk_info);
handle_receive_packets(xsk_info);
}
@@ -878,6 +878,7 @@ int main(int argc, char **argv)
pthread_t stats_poll_thread;
struct xsk_umem_info *umem;
struct xsk_container xsks;
int queues_max, queues_set;
int i;
/* Default to AF_XDP copy mode.
@@ -897,9 +898,6 @@ int main(int argc, char **argv)
*/
cfg.xsk_bind_flags = XDP_COPY;
xsks.num = 2;
//xsks.num = 1;
struct bpf_object *bpf_obj = NULL;
struct bpf_map *map;
@@ -941,6 +939,15 @@ int main(int argc, char **argv)
}
}
queues_max = ethtool_get_max_channels(cfg.ifname);
queues_set = ethtool_get_channels(cfg.ifname);
if (verbose || debug_meta)
printf("Interface: %s - queues max:%d set:%d\n",
cfg.ifname, queues_max, queues_set);
xsks.num = 2;
//xsks.num = 1;
err = init_btf_info_via_bpf_object(bpf_obj);
if (err) {
fprintf(stderr, "ERROR(%d): Invalid BTF info: errno:%s\n",

View File

@@ -16,15 +16,17 @@
# define max(x, y) ((x) < (y) ? (y) : (x))
#endif
#define GET_CHAN_MAX 1
#define GET_CHAN_CURR 2
/* Based on xsk_get_max_queues(), but needed info on max_queues before
* xsk objects are created.
*/
int ethtool_get_max_queues(const char *ifname)
int __ethtool_get_channels(const char *ifname, int type)
{
struct ethtool_channels channels = { .cmd = ETHTOOL_GCHANNELS };
struct ifreq ifr = {};
int fd, err, ret;
int fd, err, ret = -1;
fd = socket(AF_LOCAL, SOCK_DGRAM | SOCK_CLOEXEC, 0);
if (fd < 0)
@@ -44,15 +46,35 @@ int ethtool_get_max_queues(const char *ifname)
* is sent to a single stream, so max queues = 1.
*/
ret = 1;
} else {
goto out;
}
if (type == GET_CHAN_MAX) {
/* Take the max of rx, tx, combined. Drivers return
* the number of channels in different ways.
*/
ret = max(channels.max_rx, channels.max_tx);
ret = max(ret, (int)channels.max_combined);
goto out;
}
if (type == GET_CHAN_CURR) {
ret = max(channels.rx_count, channels.tx_count);
ret = max(ret, (int)channels.combined_count);
goto out;
}
out:
close(fd);
return ret;
}
int ethtool_get_max_channels(const char *ifname)
{
return __ethtool_get_channels(ifname, GET_CHAN_MAX);
}
int ethtool_get_channels(const char *ifname)
{
return __ethtool_get_channels(ifname, GET_CHAN_CURR);
}

View File

@@ -3,6 +3,7 @@
#ifndef __ETHTOOL_UTILS_H
#define __ETHTOOL_UTILS_H
int ethtool_get_max_queues(const char *ifname);
int ethtool_get_max_channels(const char *ifname);
int ethtool_get_channels(const char *ifname);
#endif /* __ETHTOOL_UTILS_H */