public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: Laurent Vivier <lvivier@redhat.com>
Cc: passt-dev@passt.top
Subject: Re: [PATCH 3/7] passt: Integrate main event loop with threading infrastructure
Date: Fri, 14 Aug 2026 16:25:50 +1000	[thread overview]
Message-ID: <an605sjO_rdbYI0M@zatzit> (raw)
In-Reply-To: <20260731164628.3556997-4-lvivier@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 3479 bytes --]

On Fri, Jul 31, 2026 at 06:46:24PM +0200, Laurent Vivier wrote:
> 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);

Invoking this through threading_start_thread(), which then special
cases thread 0 seems a bit odd.  Could you just directly call
threading_worker()?

>  }
> 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
> 

-- 
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 --]

  reply	other threads:[~2026-08-14  6:52 UTC|newest]

Thread overview: 14+ 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-08-12  4:15   ` David Gibson
2026-07-31 16:46 ` [PATCH 2/7] threading: Add basic threading infrastructure Laurent Vivier
2026-08-14  6:23   ` David Gibson
2026-07-31 16:46 ` [PATCH 3/7] passt: Integrate main event loop with " Laurent Vivier
2026-08-14  6:25   ` David Gibson [this message]
2026-07-31 16:46 ` [PATCH 4/7] flow: Delegate epoll file descriptor management to threading subsystem Laurent Vivier
2026-08-14  6:33   ` David Gibson
2026-07-31 16:46 ` [PATCH 5/7] ctx: Remove epollfd from context structure Laurent Vivier
2026-08-14  6:34   ` David Gibson
2026-07-31 16:46 ` [PATCH 6/7] vhost-user: Add per-qpair worker threads Laurent Vivier
2026-08-14  6:51   ` David Gibson
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=an605sjO_rdbYI0M@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).