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=LbLq6CTA; 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 8144C5A0619 for ; Fri, 31 Jul 2026 18:46:38 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1785516397; 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=WwPkAatt6N6+8CuVGKvaX822fFkTeAUF45ctIPgP4gY=; b=LbLq6CTAha/KSKNNtCVdNu2FVB+rRDQDmd5q6RXmyczysn0zkbl9k/uwNNRv+TEroh+LDG cfCihAmaEnSQz5rH3728A495GHrAin+8iimEK4xzQ0wOvTZKllJZjh0qKN1bRT2o0PkXFt Bb919hIRZzEmXCRdLoVpTuRLBZ2YaeU= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-255-UkBxJYOJN52emq1_Zn-2kA-1; Fri, 31 Jul 2026 12:46:35 -0400 X-MC-Unique: UkBxJYOJN52emq1_Zn-2kA-1 X-Mimecast-MFC-AGG-ID: UkBxJYOJN52emq1_Zn-2kA_1785516395 Received: from mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.95]) (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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 21390180047F for ; Fri, 31 Jul 2026 16:46:35 +0000 (UTC) Received: from lenovo-t14s.redhat.corp (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4925141C; Fri, 31 Jul 2026 16:46:34 +0000 (UTC) From: Laurent Vivier To: passt-dev@passt.top Subject: [PATCH 4/7] flow: Delegate epoll file descriptor management to threading subsystem Date: Fri, 31 Jul 2026 18:46:25 +0200 Message-ID: <20260731164628.3556997-5-lvivier@redhat.com> In-Reply-To: <20260731164628.3556997-1-lvivier@redhat.com> References: <20260731164628.3556997-1-lvivier@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.6 on 10.30.177.95 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: wcSJphWp5LpvpKNVqCFhrccdzgIG8Z6H8OzGccHkuCI_1785516395 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true Message-ID-Hash: A6E3QZDNJPGX5B35ZHSCEANSXMQDG7FR X-Message-ID-Hash: A6E3QZDNJPGX5B35ZHSCEANSXMQDG7FR 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: 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 --- 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); } /** @@ -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