From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: passt.top; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ddLB5TyT; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTPS id AD52C5A026F for ; Thu, 09 Oct 2025 15:04:16 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1760015055; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=hIdahkFOYHubRXQ2KLTDjhnWTJEVxf+r1jVsn/Nqx70=; b=ddLB5TyT/kGEICM72tIoEFl7ibQucILcxOhOWTPdbP0fi0HGd7JVitMhqr+JpwNFJbHqgF DGK1xy0dylg4QdEZHEpNvv5kP9o9loeD3PKWmwNY0yfTNg3cVOdM68/ONlVl894GtQVXv9 lahkRBpqQl94iCsctY+hbE2exRh1sJQ= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-417-bw2KmRlBOACh6LuWsrjsdQ-1; Thu, 09 Oct 2025 09:04:13 -0400 X-MC-Unique: bw2KmRlBOACh6LuWsrjsdQ-1 X-Mimecast-MFC-AGG-ID: bw2KmRlBOACh6LuWsrjsdQ_1760015052 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4EB35180057D for ; Thu, 9 Oct 2025 13:04:12 +0000 (UTC) Received: from lenovo-t14s.redhat.com (unknown [10.45.224.166]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 3D5671800578; Thu, 9 Oct 2025 13:04:10 +0000 (UTC) From: Laurent Vivier To: passt-dev@passt.top Subject: [PATCH v3 0/6] Refactor epoll handling in preparation for multithreading Date: Thu, 9 Oct 2025 15:04:03 +0200 Message-ID: <20251009130409.3931795-1-lvivier@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: su7zAm8Z_Iu6zr0tDFAnE1qC-JU-eMLHi5SaeXzTYTk_1760015052 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-ID-Hash: VLGERR6ERSC3462N5MHBALOHHRLNLJYZ X-Message-ID-Hash: VLGERR6ERSC3462N5MHBALOHHRLNLJYZ X-MailFrom: lvivier@redhat.com 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: Laurent Vivier 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: This series refactors how epoll file descriptors are managed throughout=0D the codebase in preparation for introducing multithreading support.=0D Currently, passt uses a single global epollfd accessed through the=0D context structure. With multithreading, each thread will need its own=0D epollfd managing its subset of flows.=0D =0D The key changes are:=0D =0D 1. Centralize epoll management by extracting helper functions into a new=0D epoll_ctl.c/h module and moving union epoll_ref from passt.h to its=0D more logical location in epoll_ctl.h.=0D =0D 2. Simplify epoll_del() to take the epollfd directly rather than=0D extracting it from the context structure, reducing coupling between=0D epoll operations and the global context.=0D =0D 3. Move epoll registration out of sock_l4_sa() into protocol-specific=0D code, giving callers explicit control over which epoll instance=0D manages each socket.=0D =0D 4. Replace the boolean in_epoll flag in TCP connections with a threadnb=0D (thread number) field in flow_common. This serves dual purposes:=0D tracking registration status (FLOW_THREADNB_INVALID =3D not registered)= =0D and identifying the owning thread. A thread-to-epollfd mapping allows=0D retrieving the actual epoll file descriptor. The threadnb field is 8=0D bits, limiting values to 0-254 (255 =3D FLOW_THREADNB_INVALID).=0D =0D 5. Apply this pattern consistently across all protocol handlers (TCP,=0D ICMP, UDP), storing the managing thread number in each flow's common=0D structure.=0D =0D These changes make thread ownership explicit in the flow tracking system,= =0D enabling flows to be managed by different threads (and their epoll=0D instances), a prerequisite for per-thread epollfd design in upcoming=0D multithreading work.=0D =0D Changes since v1:=0D - New patch: "epoll_ctl: Extract epoll operations" - centralizes epoll=0D helpers into a dedicated module and relocates union epoll_ref from=0D passt.h to epoll_ctl.h=0D - Changed epollfd type in flow_common from int to 8-bit bitfield to avoid= =0D exceeding cacheline size threshold=0D - Added flow_epollfd_valid() helper to check epoll registration status=0D - Added flow_set_epollfd() helper to set the epoll instance for a flow=0D =0D Changes since v2:=0D - Renamed field in flow_common from epollfd to threadnb (thread number)=0D to better reflect that flows are now associated with threads rather=0D than directly with epoll file descriptors=0D - Introduced thread-to-epollfd mapping via threadnb_to_epollfd[] array=0D in flow.c, providing an indirection layer between threads and their=0D epoll instances=0D - Renamed/refactored helper functions:=0D - flow_set_epollfd() -> flow_epollfd_set() - now takes thread number=0D and epollfd parameters=0D - Added flow_epollfd_get() - retrieves the epoll fd for a flow's thread= =0D - flow_epollfd_valid() - now checks threadnb instead of epollfd=0D - Updated constants: replaced EPOLLFD_* with FLOW_THREADNB_* equivalents=0D (e.g., EPOLLFD_INVALID -> FLOW_THREADNB_INVALID)=0D - Applied thread-based pattern consistently across TCP, ICMP, and UDP=0D =0D Laurent Vivier (6):=0D util: Simplify epoll_del() interface to take epollfd directly=0D epoll_ctl: Extract epoll operations=0D util: Move epoll registration out of sock_l4_sa()=0D tcp, flow: Replace per-connection in_epoll flag with threadnb in=0D flow_common=0D icmp: Use thread-based epoll management for ICMP flows=0D udp: Use thread-based epoll management for UDP flows=0D =0D Makefile | 22 +++++++++++-----------=0D epoll_ctl.c | 45 ++++++++++++++++++++++++++++++++++++++++++++=0D epoll_ctl.h | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++=0D flow.c | 53 +++++++++++++++++++++++++++++++++++++++++++++-------=0D flow.h | 13 ++++++++++++-=0D icmp.c | 23 +++++++++++++++--------=0D passt.c | 2 +-=0D passt.h | 34 ---------------------------------=0D pasta.c | 7 +++----=0D pif.c | 32 ++++++++++++++++++++++++-------=0D repair.c | 14 +++++---------=0D tap.c | 15 +++++----------=0D tcp.c | 41 +++++++++++++++++++++-------------------=0D tcp_conn.h | 8 +-------=0D tcp_splice.c | 26 +++++++++++++-------------=0D udp.c | 2 +-=0D udp_flow.c | 23 +++++++++++++++++++----=0D util.c | 28 ++-------------------------=0D util.h | 6 ++++--=0D vhost_user.c | 14 +++++---------=0D vu_common.c | 2 +-=0D 21 files changed, 287 insertions(+), 174 deletions(-)=0D create mode 100644 epoll_ctl.c=0D create mode 100644 epoll_ctl.h=0D =0D --=20=0D 2.50.1=0D =0D