From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=quarantine dis=none) header.from=asahilina.net Authentication-Results: passt.top; dkim=pass (2048-bit key; secure) header.d=asahilina.net header.i=@asahilina.net header.a=rsa-sha256 header.s=default header.b=qeLjIstg; dkim-atps=neutral Received: from mail.marcansoft.com (marcansoft.com [212.63.210.85]) by passt.top (Postfix) with ESMTPS id 7737D5A026F for ; Sat, 28 Dec 2024 12:43:43 +0100 (CET) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: sendonly@marcansoft.com) by mail.marcansoft.com (Postfix) with ESMTPSA id 4FDDF3FB17; Sat, 28 Dec 2024 11:43:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=asahilina.net; s=default; t=1735386222; bh=qt8KAwRSlS9ZqQlRo2WMRPO5w3rTSkNkejfg5nDHd8s=; h=From:Date:Subject:To:Cc; b=qeLjIstgzrpRX4VTkMD+618hiiakFIMx9JtLIG1a6A2gfxQk2jMdSE0nC+f/3+3B2 HalbU2bMkDWpfzp1CYhcIP7amf9Fmo0w8B2NLSOShcurb3i05QRxrHD7Eyn/DBUtmh 10RM+jI7RZg24CMprsmA5CO3qz95SWGnzsyERkjJKRFpEaC3m2muHStNG5GzmcM4UV pxaB7jUhSpQaqQeICYR0u+1ASyy0efUSPnb2MCFIScBOSgwf3l/3dV0gHn0f8lxBhX I7G21q3iSBYzrFBQz+5oZk8tveIb7Dsm3b/knhI4TdMzj3S+AahMDBahEcxENO0gJ2 RVAJsemfHZWVQ== From: Asahi Lina Date: Sat, 28 Dec 2024 20:43:15 +0900 Subject: [PATCH] tcp: Add missing EPOLLET flag for established sockets MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20241228-tcp-epollet-fix-v1-1-0ff63e0dff63@asahilina.net> X-B4-Tracking: v=1; b=H4sIAFLkb2cC/x2MQQqAIBAAvyJ7biE1yvpKdAhba0FKVCII/550n IGZFxJFpgSTeCHSzYmvs4JsBNhjPXdC3iqDalUnlTKYbUAKl/eU0fGD2hka7aB7u0moVYhU9X+ cl1I+DAIRymEAAAA= X-Change-ID: 20241228-tcp-epollet-fix-3f8e9c736cd1 To: passt-dev@passt.top X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1735386222; l=1998; i=lina@asahilina.net; s=20240902; h=from:subject:message-id; bh=qt8KAwRSlS9ZqQlRo2WMRPO5w3rTSkNkejfg5nDHd8s=; b=bB4XBwWzUbjyrJlPHWnXESkrcQwcOruww6cMOZOImY3nI67HMIu03fpObkj5sAG4INRwarTrZ KLv0YpGxXZiAhdd9UWWkqqz1MKlcftA3eVYJCTvUTTZE62C8ujjPiHT X-Developer-Key: i=lina@asahilina.net; a=ed25519; pk=tpv7cWfUnHNw5jwf6h4t0gGgglt3/xcwlfs0+A/uUu8= Message-ID-Hash: EA6E5YUZZUWXAJIY4JWN3JOUU6IWUAHY X-Message-ID-Hash: EA6E5YUZZUWXAJIY4JWN3JOUU6IWUAHY X-MailFrom: lina@asahilina.net X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Sergio Lopez , Asahi Lina X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: When there is unacknowledged data in the inbound socket buffer, passt leaves the socket in the epoll instance to accept new data from the server. Since there is already data in the socket buffer, an epoll without EPOLLET will repeatedly fire while no data is processed, busy-looping the CPU: epoll_pwait(3, [...], 8, 1000, NULL, 8) = 4 recvmsg(25, {msg_namelen=0}, MSG_PEEK) = -1 EAGAIN (Resource temporarily unavailable) recvmsg(169, {msg_namelen=0}, MSG_PEEK) = -1 EAGAIN (Resource temporarily unavailable) recvmsg(111, {msg_namelen=0}, MSG_PEEK) = -1 EAGAIN (Resource temporarily unavailable) recvmsg(180, {msg_namelen=0}, MSG_PEEK) = -1 EAGAIN (Resource temporarily unavailable) epoll_pwait(3, [...], 8, 1000, NULL, 8) = 4 recvmsg(25, {msg_namelen=0}, MSG_PEEK) = -1 EAGAIN (Resource temporarily unavailable) recvmsg(169, {msg_namelen=0}, MSG_PEEK) = -1 EAGAIN (Resource temporarily unavailable) recvmsg(111, {msg_namelen=0}, MSG_PEEK) = -1 EAGAIN (Resource temporarily unavailable) recvmsg(180, {msg_namelen=0}, MSG_PEEK) = -1 EAGAIN (Resource temporarily unavailable) Add in the missing EPOLLET flag for this case. This brings CPU usage down from around ~80% when downloading over TCP, to ~5% (use case: passt as network transport for muvm, downloading Steam games). Signed-off-by: Asahi Lina --- tcp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tcp.c b/tcp.c index ec433f7d54bcccc4f1ba33e7add10c1e61807bc8..38042264a83570145d7fe9577d9fe1928435ff4d 100644 --- a/tcp.c +++ b/tcp.c @@ -439,7 +439,7 @@ static uint32_t tcp_conn_epoll_events(uint8_t events, uint8_t conn_flags) if (conn_flags & STALLED) return EPOLLIN | EPOLLOUT | EPOLLRDHUP | EPOLLET; - return EPOLLIN | EPOLLRDHUP; + return EPOLLIN | EPOLLRDHUP | EPOLLET; } if (events == TAP_SYN_RCVD) --- base-commit: e5ba8adef71ec53e192373ed1267dc338719dda0 change-id: 20241228-tcp-epollet-fix-3f8e9c736cd1 Cheers, ~~ Lina