From: David Gibson <david@gibson.dropbear.id.au>
To: Laurent Vivier <lvivier@redhat.com>
Cc: passt-dev@passt.top
Subject: Re: [PATCH 4/7] flow: Delegate epoll file descriptor management to threading subsystem
Date: Fri, 14 Aug 2026 16:33:18 +1000 [thread overview]
Message-ID: <an62n4J2Y_h70KM4@zatzit> (raw)
In-Reply-To: <20260731164628.3556997-5-lvivier@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 4686 bytes --]
On Fri, Jul 31, 2026 at 06:46:25PM +0200, Laurent Vivier wrote:
> Remove the flow-local epoll_id_to_fd mapping array and instead
> rely on the threading subsystem to provide the epoll file descriptor
> for a given thread number.
>
> Update all protocol handlers (ICMP, TCP, TCP splice, UDP).
>
> Signed-off-by: Laurent Vivier <lvivier@redhat.com>
> ---
> flow.c | 17 +++++++++--------
> flow.h | 4 +---
> passt.c | 2 +-
> tcp.c | 3 ++-
> 4 files changed, 13 insertions(+), 13 deletions(-)
>
> diff --git a/flow.c b/flow.c
> index 3012a07ed680..7821b3f91285 100644
> --- a/flow.c
> +++ b/flow.c
> @@ -24,6 +24,7 @@
> #include "repair.h"
> #include "epoll_ctl.h"
> #include "serialise.h"
> +#include "threading.h"
>
> const char *flow_state_str[] = {
> [FLOW_STATE_FREE] = "FREE",
> @@ -221,7 +222,6 @@ static_assert(ARRAY_SIZE(flow_epoll) == FLOW_NUM_TYPES,
> unsigned flow_first_free;
> union flow flowtab[FLOW_MAX];
> static _Thread_local const union flow *flow_new_entry; /* = NULL */
> -int qpair_to_fd[FLOW_QPAIR_SIZE];
>
> /* Hash table to index it */
> #define FLOW_HASH_LOAD 70 /* % */
> @@ -457,7 +457,12 @@ static void flow_set_state(struct flow_common *f, enum flow_state state)
> */
> int flow_epollfd(const struct flow_common *f)
> {
> - return qpair_to_fd[f->qpair];
> + /* mapping 1:1 between qpair and threadid
> + * return threading_epollfd(f->qpair);
> + * but for the moment we have only one thread
> + */
> + (void)f;
> + return threading_epollfd(THREADING_ID_DEFAULT);
This seems like it's going backwards, always using thread 0's epollfd,
rather than choosing the right thread based on the qpair.
> }
>
> /**
> @@ -525,7 +530,7 @@ bool flow_migrate_epollfd(struct flow_common *f, unsigned int qpair,
> flow_trace((union flow *)f,
> "migrating from qpair %d to %d", qpair, target);
>
> - epoll_del(qpair_to_fd[qpair], ref.fd);
> + epoll_del(threading_epollfd(qpair), ref.fd);
> flow_setqp(f, target);
> flow_epoll_set(f, EPOLL_CTL_ADD, events, ref.fd, ref.flowside.sidei);
> ret = true;
> @@ -1444,9 +1449,8 @@ int flow_migrate_target(struct ctx *c, const struct migrate_stage *stage,
>
> /**
> * flow_init() - Initialise flow related data structures
> - * @c: Execution context
> */
> -void flow_init(const struct ctx *c)
> +void flow_init(void)
> {
> unsigned b;
>
> @@ -1456,7 +1460,4 @@ void flow_init(const struct ctx *c)
>
> for (b = 0; b < FLOW_HASH_SIZE; b++)
> flow_hashtab[b] = FLOW_SIDX_NONE;
> -
> - for (b = 0; b < FLOW_QPAIR_SIZE; b++)
> - qpair_to_fd[b] = c->epollfd;
> }
> diff --git a/flow.h b/flow.h
> index c31a51a9cc96..e2693efd0f70 100644
> --- a/flow.h
> +++ b/flow.h
> @@ -157,8 +157,6 @@ struct flowside {
> in_port_t eport;
> };
>
> -extern int qpair_to_fd[];
> -
> /**
> * flowside_eq() - Check if two flowsides are equal
> * @left, @right: Flowsides to compare
> @@ -266,7 +264,7 @@ flow_sidx_t flow_lookup_sa(const struct ctx *c, uint8_t proto, uint8_t pif,
>
> union flow;
>
> -void flow_init(const struct ctx *c);
> +void flow_init(void);
> int flow_epollfd(const struct flow_common *f);
> int flow_epoll_set(const struct flow_common *f, int command, uint32_t events,
> int fd, unsigned int sidei);
> diff --git a/passt.c b/passt.c
> index 2cedb7ba0756..57290a5a7c6e 100644
> --- a/passt.c
> +++ b/passt.c
> @@ -399,7 +399,7 @@ int main(int argc, char **argv)
> if (clock_gettime(CLOCK_MONOTONIC, &now))
> die_perror("Failed to get CLOCK_MONOTONIC time");
>
> - flow_init(c);
> + flow_init();
> fwd_scan_ports_init(c);
>
> if ((!c->no_udp && udp_init(c)) || (!c->no_tcp && tcp_init(c)))
> diff --git a/tcp.c b/tcp.c
> index 2767a8494107..e8da65410bcf 100644
> --- a/tcp.c
> +++ b/tcp.c
> @@ -317,6 +317,7 @@
> #include "tcp_buf.h"
> #include "tcp_vu.h"
> #include "epoll_ctl.h"
> +#include "threading.h"
>
> /*
> * The size of TCP header (including options) is given by doff (Data Offset)
> @@ -2721,7 +2722,7 @@ void tcp_timer_handler(const struct ctx *c, union epoll_ref ref,
> assert(conn->f.type == FLOW_TCP);
>
> if (conn->f.qpair != qpair) {
> - int old_epollfd = qpair_to_fd[qpair];
> + int old_epollfd = threading_epollfd(qpair);
>
> epoll_del(old_epollfd, conn->timer);
> if (tcp_timer_epoll_add(conn, conn->timer, now) < 0) {
> --
> 2.54.0
>
--
David Gibson (he or they) | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you, not the other way
| around.
http://www.ozlabs.org/~dgibson
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2026-08-14 6:52 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-31 16:46 [PATCH 0/7] multithreading: Add worker threads for queue pair processing Laurent Vivier
2026-07-31 16:46 ` [PATCH 1/7] vhost_user: Reset vq enable flag in vu_cleanup() Laurent Vivier
2026-08-12 4:15 ` David Gibson
2026-07-31 16:46 ` [PATCH 2/7] threading: Add basic threading infrastructure Laurent Vivier
2026-08-14 6:23 ` David Gibson
2026-07-31 16:46 ` [PATCH 3/7] passt: Integrate main event loop with " Laurent Vivier
2026-08-14 6:25 ` David Gibson
2026-07-31 16:46 ` [PATCH 4/7] flow: Delegate epoll file descriptor management to threading subsystem Laurent Vivier
2026-08-14 6:33 ` David Gibson [this message]
2026-07-31 16:46 ` [PATCH 5/7] ctx: Remove epollfd from context structure Laurent Vivier
2026-08-14 6:34 ` David Gibson
2026-07-31 16:46 ` [PATCH 6/7] vhost-user: Add per-qpair worker threads Laurent Vivier
2026-08-14 6:51 ` David Gibson
2026-07-31 16:46 ` [PATCH 7/7] virtio: Prevent crash on virtqueue exhaustion with temporary workaround 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=an62n4J2Y_h70KM4@zatzit \
--to=david@gibson.dropbear.id.au \
--cc=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).