From: David Gibson <david@gibson.dropbear.id.au>
To: Laurent Vivier <lvivier@redhat.com>
Cc: passt-dev@passt.top
Subject: Re: [PATCH 5/8] flow: Make flow timer per-caller for thread safety
Date: Thu, 2 Jul 2026 12:49:24 +1000 [thread overview]
Message-ID: <akXRtEirfZ41_3mp@zatzit> (raw)
In-Reply-To: <20260616171052.3785909-6-lvivier@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 4386 bytes --]
On Tue, Jun 16, 2026 at 07:10:49PM +0200, Laurent Vivier wrote:
> Move the static flow_timer_run variable out of flow.c and pass it as a
> parameter to flow_defer_handler(). This allows each caller to maintain
> its own timer state: each vhost-user queue pair worker uses the per-qpair
> context.
>
> Signed-off-by: Laurent Vivier <lvivier@redhat.com>
LGTM
> ---
> flow.c | 11 +++++------
> flow.h | 2 +-
> passt.c | 8 +++++---
> 3 files changed, 11 insertions(+), 10 deletions(-)
>
> diff --git a/flow.c b/flow.c
> index 787a7139cfc1..08c7620c7b0f 100644
> --- a/flow.c
> +++ b/flow.c
> @@ -142,9 +142,6 @@ static flow_sidx_t flow_hashtab[FLOW_HASH_SIZE];
> static_assert(ARRAY_SIZE(flow_hashtab) >= 2 * FLOW_MAX,
> "Safe linear probing requires hash table with more entries than the number of sides in the flow table");
>
> -/* Last time the flow timers ran */
> -static struct timespec flow_timer_run;
> -
> /** flowside_from_af() - Initialise flowside from addresses
> * @side: flowside to initialise
> * @af: Address family (AF_INET or AF_INET6)
> @@ -898,9 +895,11 @@ flow_sidx_t flow_lookup_sa(const struct ctx *c, uint8_t proto, uint8_t pif,
> * flow_defer_handler() - Handler for per-flow deferred and timed tasks
> * @c: Execution context
> * @now: Current timestamp
> + * @timer_run: Last time the flow timers ran
> + * @qpair: Queue pair to process
> */
> void flow_defer_handler(const struct ctx *c, const struct timespec *now,
> - unsigned int qpair)
> + struct timespec *timer_run, unsigned int qpair)
> {
> struct flow_free_cluster *free_head = NULL;
> unsigned *last_next = &flow_first_free;
> @@ -908,9 +907,9 @@ void flow_defer_handler(const struct ctx *c, const struct timespec *now,
> bool timer = false;
> union flow *flow;
>
> - if (timespec_diff_ms(now, &flow_timer_run) >= FLOW_TIMER_INTERVAL) {
> + if (timespec_diff_ms(now, timer_run) >= FLOW_TIMER_INTERVAL) {
> timer = true;
> - flow_timer_run = *now;
> + *timer_run = *now;
> }
>
> assert(!flow_new_entry); /* Incomplete flow at end of cycle */
> diff --git a/flow.h b/flow.h
> index 53e0408a9ee5..10634e64a7fc 100644
> --- a/flow.h
> +++ b/flow.h
> @@ -280,7 +280,7 @@ void flow_migrate(struct flow_common *f, unsigned int qpair, uint32_t events,
> (flow_migrate(&(flow_)->f, qpair_, events_, fd_, sidei_))
>
> void flow_defer_handler(const struct ctx *c, const struct timespec *now,
> - unsigned int qpair);
> + struct timespec *timer_run, unsigned int qpair);
> int flow_migrate_source_early(struct ctx *c, const struct migrate_stage *stage,
> int fd);
> int flow_migrate_source_pre(struct ctx *c, const struct migrate_stage *stage,
> diff --git a/passt.c b/passt.c
> index 3afc59b19120..bebc2b99f523 100644
> --- a/passt.c
> +++ b/passt.c
> @@ -98,15 +98,16 @@ struct passt_stats {
> * post_handler() - Run periodic and deferred tasks for L4 protocol handlers
> * @c: Execution context
> * @now: Current timestamp
> + * @timer_run: Last time the flow timers ran
> * @qpair: Queue pair to process
> */
> static void post_handler(struct ctx *c, const struct timespec *now,
> - unsigned int qpair)
> + struct timespec *timer_run, unsigned int qpair)
> {
> if (!c->no_tcp)
> tcp_defer_handler(c, now, qpair);
>
> - flow_defer_handler(c, now, qpair);
> + flow_defer_handler(c, now, timer_run, qpair);
> fwd_scan_ports_timer(c, now);
>
> if (!c->no_ndp)
> @@ -221,6 +222,7 @@ static void print_stats(const struct ctx *c, const struct passt_stats *stats,
> static void passt_worker(void *opaque, int nfds, struct epoll_event *events)
> {
> static struct passt_stats stats = { 0 };
> + static struct timespec flow_timer_run;
> struct ctx *c = opaque;
> struct timespec now;
> int i;
> @@ -304,7 +306,7 @@ static void passt_worker(void *opaque, int nfds, struct epoll_event *events)
> print_stats(c, &stats, &now);
> }
>
> - post_handler(c, &now, QPAIR_DEFAULT);
> + post_handler(c, &now, &flow_timer_run, QPAIR_DEFAULT);
>
> migrate_handler(c);
> }
> --
> 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-07-02 2:55 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-16 17:10 [PATCH 0/8] multithreading: Prepare data structures for concurrent queue pair workers Laurent Vivier
2026-06-16 17:10 ` [PATCH 1/8] tap: Convert packet pools to per-queue-pair arrays for multiqueue Laurent Vivier
2026-06-29 9:59 ` David Gibson
2026-06-16 17:10 ` [PATCH 2/8] tap: Make L4 sequence pools per-qpair for thread safety Laurent Vivier
2026-07-02 2:27 ` David Gibson
2026-06-16 17:10 ` [PATCH 3/8] tcp: Make static buffers stack-local " Laurent Vivier
2026-07-02 2:32 ` David Gibson
2026-06-16 17:10 ` [PATCH 4/8] udp_vu: Make virtqueue " Laurent Vivier
2026-07-02 2:37 ` David Gibson
2026-06-16 17:10 ` [PATCH 5/8] flow: Make flow timer per-caller " Laurent Vivier
2026-07-02 2:49 ` David Gibson [this message]
2026-06-16 17:10 ` [PATCH 6/8] tcp: Make TCP timer state per-caller and guard global tasks Laurent Vivier
2026-07-02 2:55 ` David Gibson
2026-06-16 17:10 ` [PATCH 7/8] tcp: Protect init socket pools with mutex for thread safety Laurent Vivier
2026-07-02 2:59 ` David Gibson
2026-06-16 17:10 ` [PATCH 8/8] flow: Add mutex and per-qpair filtering to flow table operations Laurent Vivier
2026-07-02 3:03 ` David Gibson
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=akXRtEirfZ41_3mp@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).