Skip to content

Commit cb65dfb

Browse files
MaochenWang1kartben
authored andcommitted
net: lib: zperf: improve UDP RX throughput
The original flow of socket_service thread handling the Zperf UDP RX packets is: zsock_poll() polls all sockets for events, if ctx->recv_q of Zperf is not empty, it will call trigger_work() -> udp_recv_data() -> zsock_recvfrom() to read only one UDP packet from ctx->recv_q, then go back to zsock_poll() and run the same process again, which is inefficient. The alternative solution is, in udp_recv_data(), it should exhaust all the packets in the current ctx->recv_q, and then go back to zsock_poll() to run the same process again. In our Wi-Fi test case, for WPA3 security mode of 5GHz, the STA UDP RX throughput can be improved from 91.48 Mbps to 99.87 Mbps, the SAP UDP RX throughput can be improved from 85.97 Mbps to 96.00 Mbps. Signed-off-by: Maochen Wang <maochen.wang@nxp.com>
1 parent 1ba9e4d commit cb65dfb

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

subsys/net/lib/zperf/zperf_udp_receiver.c

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ static void udp_receiver_cleanup(void)
315315
static int udp_recv_data(struct net_socket_service_event *pev)
316316
{
317317
static uint8_t buf[UDP_RECEIVER_BUF_SIZE];
318-
int ret = 0;
318+
int ret = 1;
319319
int family, sock_error;
320320
struct sockaddr addr;
321321
socklen_t optlen = sizeof(int);
@@ -341,19 +341,25 @@ static int udp_recv_data(struct net_socket_service_event *pev)
341341
return 0;
342342
}
343343

344-
ret = zsock_recvfrom(pev->event.fd, buf, sizeof(buf), 0,
345-
&addr, &addrlen);
346-
if (ret < 0) {
347-
ret = -errno;
348-
(void)zsock_getsockopt(pev->event.fd, SOL_SOCKET,
349-
SO_DOMAIN, &family, &optlen);
350-
NET_ERR("recv failed on IPv%d socket (%d)",
351-
family == AF_INET ? 4 : 6, -ret);
352-
goto error;
353-
}
344+
while (ret > 0) {
345+
ret = zsock_recvfrom(pev->event.fd, buf, sizeof(buf), ZSOCK_MSG_DONTWAIT,
346+
&addr, &addrlen);
347+
if ((ret < 0) && (errno == EAGAIN)) {
348+
ret = 0;
349+
break;
350+
}
354351

355-
udp_received(pev->event.fd, &addr, buf, ret);
352+
if (ret < 0) {
353+
ret = -errno;
354+
(void)zsock_getsockopt(pev->event.fd, SOL_SOCKET,
355+
SO_DOMAIN, &family, &optlen);
356+
NET_ERR("recv failed on IPv%d socket (%d)",
357+
family == AF_INET ? 4 : 6, -ret);
358+
goto error;
359+
}
356360

361+
udp_received(pev->event.fd, &addr, buf, ret);
362+
}
357363
return ret;
358364

359365
error:

0 commit comments

Comments
 (0)