From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: passt.top; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=bD3Z9iNm; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTPS id 5AA7D5A0274 for ; Tue, 16 Jun 2026 19:11:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1781629863; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AnbQv81waRM24XmJG4Yi1Q6U/OGSO+b5I+qBCLifxuc=; b=bD3Z9iNmEmLxL9mXwv6oqy3e2wP7h4g2MTOTjiLF/2OccqMa3r9ciibf/9Uq7OQgqdZN7g 3HTj+6+PIhyvMjBuivXejFSkxw4hQvl0L/fHZHZ7qvwm7XsEg1jfKEPIddiBPKDQRjG1Jq akaIaeRuQ9qFVLATmSxi5F1ZanX54/Y= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-379-0pdEdKW2PQ2BrRYFFn5bkg-1; Tue, 16 Jun 2026 13:11:01 -0400 X-MC-Unique: 0pdEdKW2PQ2BrRYFFn5bkg-1 X-Mimecast-MFC-AGG-ID: 0pdEdKW2PQ2BrRYFFn5bkg_1781629860 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 9B5A519560B1 for ; Tue, 16 Jun 2026 17:11:00 +0000 (UTC) Received: from lenovo-t14s.redhat.corp (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id CA272195419F; Tue, 16 Jun 2026 17:10:59 +0000 (UTC) From: Laurent Vivier To: passt-dev@passt.top Subject: [PATCH 5/8] flow: Make flow timer per-caller for thread safety Date: Tue, 16 Jun 2026 19:10:49 +0200 Message-ID: <20260616171052.3785909-6-lvivier@redhat.com> In-Reply-To: <20260616171052.3785909-1-lvivier@redhat.com> References: <20260616171052.3785909-1-lvivier@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: kwYIPTbWIOAsByLEPHeOAM907J4VAKES9XcmEykuJs8_1781629860 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true Message-ID-Hash: UDDJU5GCBBTMMOKPZKLRCV3OOMLR6GIQ X-Message-ID-Hash: UDDJU5GCBBTMMOKPZKLRCV3OOMLR6GIQ X-MailFrom: lvivier@redhat.com 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: Laurent Vivier 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: 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 --- 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