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=c79FigtO; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTPS id D0D625A026F for ; Fri, 17 Oct 2025 12:31:35 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1760697094; 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=qDNChbY7PzhkjQRrzEZm+gz0+fcNQCmZI6Qy+TmfAME=; b=c79FigtO4TchRIKhx3pSIFlIfPX5BBadNUVn8KxD7xFn7FVwNtL6r76dpLRA5HIPx2fS2O USS73awBvCSCJitMxY+sRiNoEWEmv21JnF7B3vz7+qPR7iyGrvVJHZNa8iN4T4ATe4YBUv OgML2XjL7XPJ1t7TlOnHhVhHkF8wlHo= Received: from mx-prod-mc-08.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-136-xw12U32aNVi9tr3HxQfcxA-1; Fri, 17 Oct 2025 06:31:33 -0400 X-MC-Unique: xw12U32aNVi9tr3HxQfcxA-1 X-Mimecast-MFC-AGG-ID: xw12U32aNVi9tr3HxQfcxA_1760697092 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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4F50318002C1 for ; Fri, 17 Oct 2025 10:31:32 +0000 (UTC) Received: from lenovo-t14s.redhat.com (unknown [10.44.32.230]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 54DD31800452; Fri, 17 Oct 2025 10:31:31 +0000 (UTC) From: Laurent Vivier To: passt-dev@passt.top Subject: [PATCH v4 0/7] Refactor epoll handling in preparation for multithreading Date: Fri, 17 Oct 2025 12:31:22 +0200 Message-ID: <20251017103129.229412-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: CONCHbB3ah6HHRGffUtLDJFpxqP2U1LxjxUTLE1FIPM_1760697092 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 4SYU7PDNFTNHLXNRWUYWDY4IZ6UMNC35 X-Message-ID-Hash: 4SYU7PDNFTNHLXNRWUYWDY4IZ6UMNC35 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 Changes since v3:=0D - Change warn() by err() in epoll_add()=0D - Renamed flow_epollfd_valid() to flow_in_epoll(), flow_epollfd_get() to=0D flow_epollfd().=0D - Added flow_thread_register() to register an epollfd to a thread number,= =0D and called it from main() to register c->epollfd for thread 0 (main loop)= =0D - Replaced flow_epollfd_set() by flow_thread_set() to set the thread=0D number of a flow.=0D - Added new patch:=0D "passt: Move main event loop processing into passt_worker()"=0D =0D Laurent Vivier (7):=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 passt: Move main event loop processing into passt_worker()=0D =0D Makefile | 22 +++----=0D epoll_ctl.c | 45 ++++++++++++++=0D epoll_ctl.h | 51 ++++++++++++++++=0D flow.c | 63 +++++++++++++++++---=0D flow.h | 14 ++++-=0D icmp.c | 23 +++++---=0D passt.c | 163 ++++++++++++++++++++++++++++-----------------------=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, 387 insertions(+), 246 deletions(-)=0D create mode 100644 epoll_ctl.c=0D create mode 100644 epoll_ctl.h=0D =0D --=20=0D 2.51.0=0D =0D