net-af_xdp: use correct number of channels from ethtool
Subsystems (4)
PATCH 1/1 net-af_xdp: use correct number of channels from ethtool
Drivers use different fields to report the number of channels, so take the maximum of all fields (rx, tx, other, combined) when determining the size of the xsk map. The current code used only 'combined' which was set to 0 in some drivers e.g. mlx4.
Tested: compiled and run xdpsock -q 3 -r -S on mlx4
--- tools/lib/bpf/xsk.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
tools/lib/bpf/xsk.c +13 -3
@@ -412,6 +412,11 @@ static int xsk_load_xdp_prog(struct xsk_socket *xsk)return 0 ; } +static inline int max_i (int a,int b) +{ +return a > b ? a : b; +} +static int xsk_get_max_queues (struct xsk_socket *xsk) {struct ethtool_channels channels = { .cmd =ETHTOOL_GCHANNELS };
@@ -431,13 +436,18 @@ static int xsk_get_max_queues(struct xsk_socket *xsk) goto out; } -if (err || channels.max_combined ==0 ) +if (err) {/* If the device says it has no channels, then all traffic * is sent to a single stream, so max queues = 1. */ ret =1 ; -else - ret = channels.max_combined; + }else { +/* Take the max of rx, tx, other, combined. Drivers return +* the number of channels in different ways. +*/ + ret =max_i (max_i (channels.max_rx, channels.max_tx), +max_i (channels.max_other, channels.max_combined)); + } out:close (fd);
Signature · 1 line
2.24.0.432.g9d3f5f5b63-goog
Quoted 7 lines · Luigi Rizzo
Drivers use different fields to report the number of channels, so take the maximum of all fields (rx, tx, other, combined) when determining the size of the xsk map. The current code used only 'combined' which was set to 0 in some drivers e.g. mlx4.
Tested: compiled and run xdpsock -q 3 -r -S on mlx4
Signed-off-by Luigi Rizzo <[email protected]>
thanks, this seems mostly correct
tools/lib/bpf/xsk.c static int xsk_load_xdp_prog(struct xsk_socket *xsk) · line 418
Quoted 12 lines
tools/lib/bpf/xsk.c +4
-0@@ -412,6 +412,11 @@ static int xsk_load_xdp_prog(struct xsk_socket *xsk)return 0 ; } +static inline int max_i (int a,int b) +{ +return a > b ? a : b; +}
There's already a max in tools/lib/bpf/libbpf_internal.h, could you possible just use that?
Quoted 11 lines
tools/lib/bpf/xsk.c +1
-1static int xsk_get_max_queues (struct xsk_socket *xsk) {struct ethtool_channels channels = { .cmd =ETHTOOL_GCHANNELS };@@ -431,13 +436,18 @@ static int xsk_get_max_queues(struct xsk_socket *xsk) goto out; } -if (err || channels.max_combined ==0 ) +if (err) {/* If the device says it has no channels, then all traffic * is sent to a single stream, so max queues = 1.
tools/lib/bpf/xsk.c static int xsk_get_max_queues(struct xsk_socket *xsk) · line 449
Quoted 10 lines
tools/lib/bpf/xsk.c +6
-2*/ ret =1 ; - else - ret = channels.max_combined; + }else { +/* Take the max of rx, tx, other, combined. Drivers return +* the number of channels in different ways. +*/ + ret =max_i (max_i (channels.max_rx, channels.max_tx), +max_i (channels.max_other, channels.max_combined));
The continuation line should be aligned to the opening bracket.
I don't think we need to care about other, other is for non-traffic interrupts.
Quoted 4 lines
tools/lib/bpf/xsk.c +1
-0+ } out:close (fd);
Quoted 20 lines · Jakub Kicinski
Quoted 7 lines · Luigi Rizzo
Drivers use different fields to report the number of channels, so take the maximum of all fields (rx, tx, other, combined) when determining the size of the xsk map. The current code used only 'combined' which was set to 0 in some drivers e.g. mlx4.
Tested: compiled and run xdpsock -q 3 -r -S on mlx4
Signed-off-by Luigi Rizzo <[email protected]>thanks, this seems mostly correct
Quoted 8 lines
tools/lib/bpf/xsk.c +0
-0@@ -412,6 +412,11 @@ static int xsk_load_xdp_prog(struct xsk_socket *xsk)return 0 ; }
Quoted 7 lines
tools/lib/bpf/xsk.c static int xsk_load_xdp_prog(struct xsk_socket *xsk) · line 418
Quoted 4 lines
tools/lib/bpf/xsk.c +4
-0+static inline int max_i (int a,int b) +{ +return a > b ? a : b; +}There's already a max in
tools/lib/bpf/libbpf_internal.h, could you possible just use that?
Sure, will send an updated patch. Note that the compiler is actually picking the max()
macro from tools/include/linux/kernel,h which does not lend to nesting due to shadowing (it also requires a cast due to stricter type checking):
make: Entering directory 'upstream/tools/lib/bpf'
CC staticobjs/xsk.o
In file included from upstream/tools/include/uapi/linux/ethtool.h:17,
from xsk.c:18:
xsk.c: In function ‘xsk_get_max_queues’:
upstream/tools/include/linux/kernel.h:43:12: error: declaration of
‘_max1’ shadows a previous local [-Werror=shadow]
typeof(x) _max1 = (x); \
^~~~~xsk.c:443:9: note: in expansion of macro ‘max’
ret = max(max(channels.max_rx, channels.max_tx),
cheers
luigi