public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: Laurent Vivier <lvivier@redhat.com>
To: passt-dev@passt.top
Cc: Laurent Vivier <lvivier@redhat.com>
Subject: [PATCH v2 00/10] multithreading: Prepare data structures for concurrent queue pair workers
Date: Fri, 31 Jul 2026 18:23:19 +0200	[thread overview]
Message-ID: <20260731162329.3552800-1-lvivier@redhat.com> (raw)

This series makes the passt data structures safe for concurrent access
by multiple worker threads, each handling a different queue pair.  It
builds on the multiqueue series which threads the queue pair parameter
through the network stack.

The changes fall into four categories:

1. Per-queue-pair data isolation:
   - Convert packet pools (pool_tap4, pool_tap6) to per-queue-pair arrays
   - Convert L4 sequence batching arrays (tap4_l4, tap6_l4) similarly
   - Move flow and TCP timer state out of global/context structures into
     per-caller parameters

2. Stack-local buffers:
   - Move static iovec and virtqueue buffers onto the stack in tcp.c,
     tcp_vu.c, and udp_vu.c so each thread operates on its own copy

3. Locking for remaining shared state:
   - pthread_mutex on pre-opened socket pools (init_sock_pool4/6)
   - pthread_rwlock on the flow table, hash table, and free list, with
     read locks for lookups and write locks for mutations
   - _Thread_local for flow_new_entry so each thread independently
     tracks its in-progress allocation
   - Per-qpair filtering in flow_defer_handler() so each worker only
     processes its own flows

4. Lock-free flow migration between queue pairs:
   - When guest steers traffic to a different TX queue, flows migrate
     lazily using a to_migrate[] array
   - flow_migrate_mark() records target qpair from tap path (write-once,
     no lock needed)
   - flow_migrate_epollfd() completes migration on next socket/timer
     event by moving fd and updating qpair on the old thread
   - TCP timers migrate the same way using new tcp_timer_epoll_add()
     helper

Global operations that don't need per-queue-pair handling
(tcp_payload_flush, socket pool refills) are guarded to run only on
queue pair 0.

v2:
- Rebase on latest master and multiqueue v6
- Split v1's "flow: Add mutex and per-qpair filtering..." into two patches:
  - "flow: Add locking, per-qpair filtering, and intermediate state handling"
    (locking only)
  - "flow: Add lazy, lock-free flow migration between queue pairs" (migration
    logic separated)
- Changed from simple mutex to pthread_rwlock for flow table (read locks for
  lookups, write locks for mutations and free-list rebuild)
- Updated flow_foreach() and flow_defer_handler() to handle intermediate flow
  states (NEW, INI, TGT, TYPED) that can be observed between flow_alloc() and
  FLOW_ACTIVATE() when lock is released
- New patch: "tcp: Extract tcp_timer_epoll_add() helper" - factors out epoll
  registration for timer migration support
- flow_migrate_epollfd() now uses tcp_timer_epoll_add() for timer migration

v1:
- Initial submission

Based-on: 20260616125130.1324274-1-lvivier@redhat.com

Laurent Vivier (10):
  tap: Convert packet pools to per-queue-pair arrays for multiqueue
  tap: Make L4 sequence pools per-qpair for thread safety
  tcp: Make static buffers stack-local for thread safety
  udp_vu: Make virtqueue buffers stack-local for thread safety
  flow: Make flow timer per-caller for thread safety
  tcp: Make TCP timer state per-caller and guard global tasks
  tcp: Protect init socket pools with mutex for thread safety
  tcp: Extract tcp_timer_epoll_add() helper
  flow: Add locking, per-qpair filtering, and intermediate state
    handling
  flow: Add lazy, lock-free flow migration between queue pairs

 flow.c       | 222 ++++++++++++++++++++++++++++++++++++++++++++++-----
 flow.h       |   5 +-
 flow_table.h |   2 +-
 icmp.c       |  10 ++-
 passt.c      |  37 +++++----
 tap.c        | 109 ++++++++++++++-----------
 tap.h        |   2 +-
 tcp.c        | 108 ++++++++++++++++++-------
 tcp.h        |   9 +--
 tcp_vu.c     |  33 +++++---
 udp.c        |   3 +
 udp_flow.c   |   4 +
 udp_vu.c     |   4 +-
 vu_common.c  |   2 +-
 14 files changed, 409 insertions(+), 141 deletions(-)

-- 
2.54.0


             reply	other threads:[~2026-07-31 16:23 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-31 16:23 Laurent Vivier [this message]
2026-07-31 16:23 ` [PATCH v2 01/10] tap: Convert packet pools to per-queue-pair arrays for multiqueue Laurent Vivier
2026-07-31 16:23 ` [PATCH v2 02/10] tap: Make L4 sequence pools per-qpair for thread safety Laurent Vivier
2026-07-31 16:23 ` [PATCH v2 03/10] tcp: Make static buffers stack-local " Laurent Vivier
2026-07-31 16:23 ` [PATCH v2 04/10] udp_vu: Make virtqueue " Laurent Vivier
2026-07-31 16:23 ` [PATCH v2 05/10] flow: Make flow timer per-caller " Laurent Vivier
2026-07-31 16:23 ` [PATCH v2 06/10] tcp: Make TCP timer state per-caller and guard global tasks Laurent Vivier
2026-07-31 16:23 ` [PATCH v2 07/10] tcp: Protect init socket pools with mutex for thread safety Laurent Vivier
2026-07-31 16:23 ` [PATCH v2 08/10] tcp: Extract tcp_timer_epoll_add() helper Laurent Vivier
2026-07-31 16:23 ` [PATCH v2 09/10] flow: Add locking, per-qpair filtering, and intermediate state handling Laurent Vivier
2026-07-31 16:23 ` [PATCH v2 10/10] flow: Add lazy, lock-free flow migration between queue pairs Laurent Vivier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260731162329.3552800-1-lvivier@redhat.com \
    --to=lvivier@redhat.com \
    --cc=passt-dev@passt.top \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).