From: Laurent Vivier <lvivier@redhat.com>
To: passt-dev@passt.top
Cc: Laurent Vivier <lvivier@redhat.com>
Subject: [PATCH 3/7] passt: Integrate main event loop with threading infrastructure
Date: Fri, 31 Jul 2026 18:46:24 +0200 [thread overview]
Message-ID: <20260731164628.3556997-4-lvivier@redhat.com> (raw)
In-Reply-To: <20260731164628.3556997-1-lvivier@redhat.com>
Convert the main event loop to use the threading subsystem. The main
process now registers passt_worker() as thread #0 and starts it through
the threading infrastructure instead of running a manual epoll_wait loop.
Signed-off-by: Laurent Vivier <lvivier@redhat.com>
---
passt.c | 20 ++++----------------
threading.c | 3 ---
2 files changed, 4 insertions(+), 19 deletions(-)
diff --git a/passt.c b/passt.c
index 8a06838c5ed8..2cedb7ba0756 100644
--- a/passt.c
+++ b/passt.c
@@ -333,8 +333,7 @@ static void passt_worker(void *opaque, int nfds, struct epoll_event *events)
*/
int main(int argc, char **argv)
{
- struct epoll_event events[NUM_EPOLL_EVENTS];
- int nfds, devnull_fd = -1, fd;
+ int devnull_fd = -1, fd;
struct ctx *c = &passt_ctx;
struct rlimit limit;
struct timespec now;
@@ -377,9 +376,7 @@ int main(int argc, char **argv)
madvise(pkt_buf, sizeof(pkt_buf), MADV_HUGEPAGE);
threading_init();
- c->epollfd = epoll_create1(EPOLL_CLOEXEC);
- if (c->epollfd == -1)
- die_perror("Failed to create epoll file descriptor");
+ c->epollfd = threading_epollfd(THREADING_ID_DEFAULT);
if (getrlimit(RLIMIT_NOFILE, &limit))
die_perror("Failed to get maximum value of open files limit");
@@ -449,15 +446,6 @@ int main(int argc, char **argv)
isolate_postfork(c);
-loop:
- /* NOLINTBEGIN(bugprone-branch-clone): intervals can be the same */
- /* cppcheck-suppress [duplicateValueTernary, unmatchedSuppression] */
- nfds = epoll_wait(c->epollfd, events, NUM_EPOLL_EVENTS, TIMER_INTERVAL);
- /* NOLINTEND(bugprone-branch-clone) */
- if (nfds == -1 && errno != EINTR)
- die_perror("epoll_wait() failed in main loop");
-
- passt_worker(c, nfds, events);
-
- goto loop;
+ threading_worker_set(THREADING_ID_DEFAULT, passt_worker, c);
+ threading_start_thread(THREADING_ID_DEFAULT);
}
diff --git a/threading.c b/threading.c
index fd5b30ed7ff6..e1ed644f5864 100644
--- a/threading.c
+++ b/threading.c
@@ -66,7 +66,6 @@ void threading_init(void)
*
* Return: 0 on success, -1 if thread index is invalid
*/
-/* cppcheck-suppress unusedFunction */
int threading_worker_set(unsigned int threadid,
void (*worker)(void *, int, struct epoll_event *),
void *opaque)
@@ -90,7 +89,6 @@ int threading_worker_set(unsigned int threadid,
*
* Return: epoll file descriptor for the specified thread, -1 if index invalid
*/
-/* cppcheck-suppress unusedFunction */
int threading_epollfd(unsigned int threadid)
{
if (threadid >= ARRAY_SIZE(threads))
@@ -135,7 +133,6 @@ static void *threading_worker(void *opaque)
*
* #syscalls rt_sigaction rt_sigprocmask mprotect getrandom brk clone3 rseq set_robust_list clock_nanosleep
*/
-/* cppcheck-suppress unusedFunction */
void threading_start_thread(unsigned int threadid)
{
struct threading_context *tc;
--
2.54.0
next prev parent reply other threads:[~2026-07-31 16:46 UTC|newest]
Thread overview: 8+ 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-07-31 16:46 ` [PATCH 2/7] threading: Add basic threading infrastructure Laurent Vivier
2026-07-31 16:46 ` Laurent Vivier [this message]
2026-07-31 16:46 ` [PATCH 4/7] flow: Delegate epoll file descriptor management to threading subsystem Laurent Vivier
2026-07-31 16:46 ` [PATCH 5/7] ctx: Remove epollfd from context structure Laurent Vivier
2026-07-31 16:46 ` [PATCH 6/7] vhost-user: Add per-qpair worker threads Laurent Vivier
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=20260731164628.3556997-4-lvivier@redhat.com \
--to=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).