From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=pass (2048-bit key; secure) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202606 header.b=YOITfgg8; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 27DAB5A0265 for ; Thu, 02 Jul 2026 04:55:31 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202606; t=1782960928; bh=cSh5twKxaA3lqIKuHfREAuA+i0ehAAE8ZOSCCTeR/q8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=YOITfgg8B85Z/LVy6CSXj2aivPRn5QYeVfPLOb/gxIrJQbOTra6vd1No3XpA5+DD7 hDljHkSDA1Onmwyhb/unudBerGQXwjVrXSdD8Bk/DnaT/qgv7+eFWxVqxGZH/Zjldm ab0Bs+kkA35cf9AWQGb2u11ep2+fa0EEmduz8yE9XFcG2LE38qimtHDb63BAPIuhEs 4JE+cAx9/xczlwiRpxeNzRMszLkQNeXTCb7Bjq177JahcUn14XDUq8Ywj55TBxWGCi Jqv1pm9OftLwSMayk2JcPe0G3dH5UPcwJHsdNxs2E7L3TRT6OvDohvVpCFjSRX2bt4 xkXuXxRLLHZuQ== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4grM280g4mz58lv; Thu, 02 Jul 2026 12:55:28 +1000 (AEST) Date: Thu, 2 Jul 2026 12:49:24 +1000 From: David Gibson To: Laurent Vivier Subject: Re: [PATCH 5/8] flow: Make flow timer per-caller for thread safety Message-ID: References: <20260616171052.3785909-1-lvivier@redhat.com> <20260616171052.3785909-6-lvivier@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="ZLYo+mpHK5bbVEVo" Content-Disposition: inline In-Reply-To: <20260616171052.3785909-6-lvivier@redhat.com> Message-ID-Hash: BXXLGK7GY4CRMNH3UCDE2LPRWKHZN4IS X-Message-ID-Hash: BXXLGK7GY4CRMNH3UCDE2LPRWKHZN4IS X-MailFrom: dgibson@gandalf.ozlabs.org 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: passt-dev@passt.top 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: --ZLYo+mpHK5bbVEVo Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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. >=20 > Signed-off-by: Laurent Vivier LGTM > --- > flow.c | 11 +++++------ > flow.h | 2 +- > passt.c | 8 +++++--- > 3 files changed, 11 insertions(+), 10 deletions(-) >=20 > 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) >=3D 2 * FLOW_MAX, > "Safe linear probing requires hash table with more entries than the numb= er of sides in the flow table"); > =20 > -/* 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, uint= 8_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 =3D NULL; > unsigned *last_next =3D &flow_first_free; > @@ -908,9 +907,9 @@ void flow_defer_handler(const struct ctx *c, const st= ruct timespec *now, > bool timer =3D false; > union flow *flow; > =20 > - if (timespec_diff_ms(now, &flow_timer_run) >=3D FLOW_TIMER_INTERVAL) { > + if (timespec_diff_ms(now, timer_run) >=3D FLOW_TIMER_INTERVAL) { > timer =3D true; > - flow_timer_run =3D *now; > + *timer_run =3D *now; > } > =20 > 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_)) > =20 > 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 *s= tage, > 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 hand= lers > * @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); > =20 > - flow_defer_handler(c, now, qpair); > + flow_defer_handler(c, now, timer_run, qpair); > fwd_scan_ports_timer(c, now); > =20 > if (!c->no_ndp) > @@ -221,6 +222,7 @@ static void print_stats(const struct ctx *c, const st= ruct passt_stats *stats, > static void passt_worker(void *opaque, int nfds, struct epoll_event *eve= nts) > { > static struct passt_stats stats =3D { 0 }; > + static struct timespec flow_timer_run; > struct ctx *c =3D opaque; > struct timespec now; > int i; > @@ -304,7 +306,7 @@ static void passt_worker(void *opaque, int nfds, stru= ct epoll_event *events) > print_stats(c, &stats, &now); > } > =20 > - post_handler(c, &now, QPAIR_DEFAULT); > + post_handler(c, &now, &flow_timer_run, QPAIR_DEFAULT); > =20 > migrate_handler(c); > } > --=20 > 2.54.0 >=20 --=20 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 --ZLYo+mpHK5bbVEVo Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmpF0aoACgkQzQJF27ox 2Gdb5Q/9EwzK8ExGm1j2feGZNelTm2zn7QTejt1aV36ln7CjyRx4P3/Jed6EqjEM iBwoLHKziCxl2HHkywQM5WZ737IcD+A0zTaZb4GQ4MukmYwFAN5QzmkY1IFdmVJK zzxnaXYI42j3XsDvtyWf9svMi/yYvtjmOdgWEnw08VEBlE3tbg7vJLUg/BLNVZeh al0TdurQHgqjbTsc6GsdTluQkQhgGO9VfVYshYkNlALtFu/+GmBtd9adH3ZaFfeE FTHu8x/Lg7JsNKsp6f7zH0Zq5IHN++FKhqmct3M4/MKrTs5GCeAcUBwRk8d+HDOQ hnQUpesH5Z4I8Iu/iJX1/5o/dhheTofL8dJ4/5CSH3KSu0ddG4pyQkkcTtuhZ4qf L7dEerWcEGZ9HdOK6t6M4NAzI5NT3ARnpP/a9i6qBUmcGuSnl6wXsdsIYapExp7P mScvBH7dMPYYK2dj7qijAgPTG3hkVdKN/+/2QtwuiHq82VWR3J6ugcvq2JK6RVWQ 6lADSJ/sESJnzldvej+/JoOJo2lt4O1GLBu46jolr2N+IujHZoX9/kpDVEzUbktY li8/VuDvYlkn+F0qgdY8yjLRyBpxUlKT39BasC3VHZdtBOta0kE7jmWCJX6xaCRW uSs7Tyfiuy7U+Aqup8a5RhescLpcXutDB5+ql0F8f7Qlayrj+mA= =DX1Y -----END PGP SIGNATURE----- --ZLYo+mpHK5bbVEVo--