public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
* [PATCH v3 0/6] Refactor epoll handling in preparation for multithreading
@ 2025-10-09 13:04 Laurent Vivier
  2025-10-09 13:04 ` [PATCH v3 1/6] util: Simplify epoll_del() interface to take epollfd directly Laurent Vivier
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Laurent Vivier @ 2025-10-09 13:04 UTC (permalink / raw)
  To: passt-dev; +Cc: Laurent Vivier

This series refactors how epoll file descriptors are managed throughout
the codebase in preparation for introducing multithreading support.
Currently, passt uses a single global epollfd accessed through the
context structure. With multithreading, each thread will need its own
epollfd managing its subset of flows.

The key changes are:

1. Centralize epoll management by extracting helper functions into a new
   epoll_ctl.c/h module and moving union epoll_ref from passt.h to its
   more logical location in epoll_ctl.h.

2. Simplify epoll_del() to take the epollfd directly rather than
   extracting it from the context structure, reducing coupling between
   epoll operations and the global context.

3. Move epoll registration out of sock_l4_sa() into protocol-specific
   code, giving callers explicit control over which epoll instance
   manages each socket.

4. Replace the boolean in_epoll flag in TCP connections with a threadnb
   (thread number) field in flow_common. This serves dual purposes:
   tracking registration status (FLOW_THREADNB_INVALID = not registered)
   and identifying the owning thread. A thread-to-epollfd mapping allows
   retrieving the actual epoll file descriptor. The threadnb field is 8
   bits, limiting values to 0-254 (255 = FLOW_THREADNB_INVALID).

5. Apply this pattern consistently across all protocol handlers (TCP,
   ICMP, UDP), storing the managing thread number in each flow's common
   structure.

These changes make thread ownership explicit in the flow tracking system,
enabling flows to be managed by different threads (and their epoll
instances), a prerequisite for per-thread epollfd design in upcoming
multithreading work.

Changes since v1:
- New patch: "epoll_ctl: Extract epoll operations" - centralizes epoll
  helpers into a dedicated module and relocates union epoll_ref from
  passt.h to epoll_ctl.h
- Changed epollfd type in flow_common from int to 8-bit bitfield to avoid
  exceeding cacheline size threshold
- Added flow_epollfd_valid() helper to check epoll registration status
- Added flow_set_epollfd() helper to set the epoll instance for a flow

Changes since v2:
- Renamed field in flow_common from epollfd to threadnb (thread number)
  to better reflect that flows are now associated with threads rather
  than directly with epoll file descriptors
- Introduced thread-to-epollfd mapping via threadnb_to_epollfd[] array
  in flow.c, providing an indirection layer between threads and their
  epoll instances
- Renamed/refactored helper functions:
  - flow_set_epollfd() -> flow_epollfd_set() - now takes thread number
    and epollfd parameters
  - Added flow_epollfd_get() - retrieves the epoll fd for a flow's thread
  - flow_epollfd_valid() - now checks threadnb instead of epollfd
- Updated constants: replaced EPOLLFD_* with FLOW_THREADNB_* equivalents
  (e.g., EPOLLFD_INVALID -> FLOW_THREADNB_INVALID)
- Applied thread-based pattern consistently across TCP, ICMP, and UDP

Laurent Vivier (6):
  util: Simplify epoll_del() interface to take epollfd directly
  epoll_ctl: Extract epoll operations
  util: Move epoll registration out of sock_l4_sa()
  tcp, flow: Replace per-connection in_epoll flag with threadnb in
    flow_common
  icmp: Use thread-based epoll management for ICMP flows
  udp: Use thread-based epoll management for UDP flows

 Makefile     | 22 +++++++++++-----------
 epoll_ctl.c  | 45 ++++++++++++++++++++++++++++++++++++++++++++
 epoll_ctl.h  | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++
 flow.c       | 53 +++++++++++++++++++++++++++++++++++++++++++++-------
 flow.h       | 13 ++++++++++++-
 icmp.c       | 23 +++++++++++++++--------
 passt.c      |  2 +-
 passt.h      | 34 ---------------------------------
 pasta.c      |  7 +++----
 pif.c        | 32 ++++++++++++++++++++++++-------
 repair.c     | 14 +++++---------
 tap.c        | 15 +++++----------
 tcp.c        | 41 +++++++++++++++++++++-------------------
 tcp_conn.h   |  8 +-------
 tcp_splice.c | 26 +++++++++++++-------------
 udp.c        |  2 +-
 udp_flow.c   | 23 +++++++++++++++++++----
 util.c       | 28 ++-------------------------
 util.h       |  6 ++++--
 vhost_user.c | 14 +++++---------
 vu_common.c  |  2 +-
 21 files changed, 287 insertions(+), 174 deletions(-)
 create mode 100644 epoll_ctl.c
 create mode 100644 epoll_ctl.h

-- 
2.50.1



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2025-10-09 13:04 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-10-09 13:04 [PATCH v3 0/6] Refactor epoll handling in preparation for multithreading Laurent Vivier
2025-10-09 13:04 ` [PATCH v3 1/6] util: Simplify epoll_del() interface to take epollfd directly Laurent Vivier
2025-10-09 13:04 ` [PATCH v3 2/6] epoll_ctl: Extract epoll operations Laurent Vivier
2025-10-09 13:04 ` [PATCH v3 3/6] util: Move epoll registration out of sock_l4_sa() Laurent Vivier
2025-10-09 13:04 ` [PATCH v3 4/6] tcp, flow: Replace per-connection in_epoll flag with threadnb in flow_common Laurent Vivier
2025-10-09 13:04 ` [PATCH v3 5/6] icmp: Use thread-based epoll management for ICMP flows Laurent Vivier
2025-10-09 13:04 ` [PATCH v3 6/6] udp: Use thread-based epoll management for UDP flows Laurent Vivier

Code repositories for project(s) associated with this public inbox

	https://passt.top/passt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).