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=PSlLF2aR; 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 633205A026F for ; Tue, 21 Oct 2025 23:01:22 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1761080481; 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=REx52ePzY9Q9MLPIaFOr3K+5NcfZOIHOTUgKJ+q1WOs=; b=PSlLF2aRntydB6UWiwki8sJAjLabbRz5fIuAT29PEmUS2FjK8Hd9s/0Rqu+kbOfE278cAT u9radnGn/bjo0D/jq+88SMKMSKToJe5eERD5A7QEWr5KFvGgcISJHcLeuWGnQXtfD1KMAz TFfnISXjjCeFx5eq8FBZlEu1ylCaqMY= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-307-1qm-tDUBNwif0ZCfi4M-Yw-1; Tue, 21 Oct 2025 17:01:20 -0400 X-MC-Unique: 1qm-tDUBNwif0ZCfi4M-Yw-1 X-Mimecast-MFC-AGG-ID: 1qm-tDUBNwif0ZCfi4M-Yw_1761080479 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2B8351956096 for ; Tue, 21 Oct 2025 21:01:19 +0000 (UTC) Received: from lenovo-t14s.redhat.com (unknown [10.44.33.101]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1727719560A2; Tue, 21 Oct 2025 21:01:17 +0000 (UTC) From: Laurent Vivier To: passt-dev@passt.top Subject: [PATCH v5 0/7] Refactor epoll handling in preparation for multithreading Date: Tue, 21 Oct 2025 23:01:09 +0200 Message-ID: <20251021210116.314674-1-lvivier@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: Mr1SrPHA8lVIsJ7rDFux3WcCbzXWgXxZkmBC8fSN8X0_1761080479 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 62N5LNPTOSXUSJA2KLWY2PR26AUUTB7V X-Message-ID-Hash: 62N5LNPTOSXUSJA2KLWY2PR26AUUTB7V 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 an epollid=0D (epoll identifier) field in flow_common. This serves dual purposes:=0D tracking registration status (EPOLLFD_ID_INVALID =3D not registered)=0D and identifying which epoll instance manages the flow. An epoll ID to=0D epoll fd mapping allows retrieving the actual epoll file descriptor.=0D The epollid field is 8 bits, limiting values to 0-254 (255 =3D=0D EPOLLFD_ID_INVALID).=0D =0D 5. Apply this pattern consistently across all protocol handlers (TCP,=0D ICMP, UDP), storing the managing epoll ID in each flow's common=0D structure.=0D =0D 6. Extract the event loop processing logic into a separate passt_worker()= =0D function, preparing the structure for future threading where this will= =0D become a worker thread callback.=0D =0D These changes make epoll instance ownership explicit in the flow tracking= =0D system, enabling flows to be managed by different epoll instances, a=0D prerequisite for per-thread epollfd design in upcoming multithreading=0D 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 Changes since v4:=0D - Renamed field in flow_common from threadnb to epollid (epoll identifier)= =0D to better reflect the abstraction - flows are associated with an epoll=0D instance identifier rather than specifically a thread number=0D - Renamed mapping array from threadnb_to_epollfd[] to epoll_id_to_fd[]=0D - Renamed/refactored helper functions:=0D - flow_thread_set() -> flow_epollid_set() - sets the epoll ID=0D - flow_thread_register() -> flow_epollid_register() - registers the=0D epollfd for a given epoll ID=0D - Added flow_epollid_clear() - explicitly clears the epoll ID=0D - Updated constants: replaced FLOW_THREADNB_* with EPOLLFD_ID_* equivalents= =0D (e.g., FLOW_THREADNB_INVALID -> EPOLLFD_ID_INVALID, FLOW_THREADNB_MAX ->= =0D EPOLLFD_ID_MAX)=0D - Added EPOLLFD_ID_DEFAULT constant for the default (main loop) epoll insta= nce=0D - Clarified that EPOLLFD_ID_BITS limits the number of epoll instances, not= =0D threads (though initially there will be one epoll instance per thread)=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 an epollid in=0D flow_common=0D icmp: Use epoll instance management for ICMP flows=0D udp: Use epoll instance 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 | 71 +++++++++++++++++++---=0D flow.h | 15 ++++-=0D icmp.c | 23 +++++---=0D passt.c | 163 ++++++++++++++++++++++++++++-----------------------=0D passt.h | 34 -----------=0D pasta.c | 7 +--=0D pif.c | 32 +++++++---=0D repair.c | 18 +++---=0D tap.c | 15 ++---=0D tcp.c | 46 +++++++++------=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, 403 insertions(+), 248 deletions(-)=0D create mode 100644 epoll_ctl.c=0D create mode 100644 epoll_ctl.h=0D =0D --=20=0D 2.51.0=0D =0D