diff options
author | David Gibson <david@gibson.dropbear.id.au> | 2023-01-05 15:26:21 +1100 |
---|---|---|
committer | Stefano Brivio <sbrivio@redhat.com> | 2023-01-13 01:07:01 +0100 |
commit | c9e193b5ae0d785f9d77adf2ce196393a1ab205c (patch) | |
tree | 4e9cd01a3c8c388d5ef9be874fa308d52d836ed6 /udp.c | |
parent | 4eb54fd2e792e2c168588c2789e8d5d5977db75d (diff) | |
download | passt-c9e193b5ae0d785f9d77adf2ce196393a1ab205c.tar passt-c9e193b5ae0d785f9d77adf2ce196393a1ab205c.tar.gz passt-c9e193b5ae0d785f9d77adf2ce196393a1ab205c.tar.bz2 passt-c9e193b5ae0d785f9d77adf2ce196393a1ab205c.tar.lz passt-c9e193b5ae0d785f9d77adf2ce196393a1ab205c.tar.xz passt-c9e193b5ae0d785f9d77adf2ce196393a1ab205c.tar.zst passt-c9e193b5ae0d785f9d77adf2ce196393a1ab205c.zip |
udp: Don't handle tap receive batch size calculation within a #define
UDP_MAX_FRAMES gives the maximum number of datagrams we'll ever handle as a
batch for sizing our buffers and control structures. The subtly different
UDP_TAP_FRAMES gives the maximum number of datagrams we'll actually try to
receive at once for tap packets in the current configuration.
This depends on the mode, meaning that the macro has a non-obvious
dependency on the usual 'c' context variable being available. We only use
it in one place, so it makes more sense to open code this. Add an
explanatory comment while we're there.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'udp.c')
-rw-r--r-- | udp.c | 9 |
1 files changed, 6 insertions, 3 deletions
@@ -119,7 +119,6 @@ #define UDP_CONN_TIMEOUT 180 /* s, timeout for ephemeral or local bind */ #define UDP_MAX_FRAMES 32 /* max # of frames to receive at once */ -#define UDP_TAP_FRAMES (c->mode == MODE_PASST ? UDP_MAX_FRAMES : 1) /** * struct udp_tap_port - Port tracking based on tap-facing source port @@ -950,10 +949,14 @@ static void udp_tap_send(const struct ctx *c, void udp_sock_handler(const struct ctx *c, union epoll_ref ref, uint32_t events, const struct timespec *now) { + /* For not entirely clear reasons (data locality?) pasta gets + * better throughput if we receive the datagrams one at a + * time. + */ + ssize_t n = (c->mode == MODE_PASST ? UDP_MAX_FRAMES : 1); in_port_t dstport = ref.r.p.udp.udp.port; bool v6 = ref.r.p.udp.udp.v6; struct mmsghdr *sock_mmh; - ssize_t n; if (events == EPOLLERR) return; @@ -968,7 +971,7 @@ void udp_sock_handler(const struct ctx *c, union epoll_ref ref, uint32_t events, else sock_mmh = udp4_l2_mh_sock; - n = recvmmsg(ref.r.s, sock_mmh, UDP_TAP_FRAMES, 0, NULL); + n = recvmmsg(ref.r.s, sock_mmh, n, 0, NULL); if (n <= 0) return; |