From: "Daniel P. Berrangé" <berrange@redhat.com>
To: "Philippe Mathieu-Daudé" <philmd@oss.qualcomm.com>
Cc: qemu-devel@nongnu.org, Paolo Bonzini <pbonzini@redhat.com>,
Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>,
Mohamed Mediouni <mohamed@unpredictable.fr>
Subject: Re: [PATCH] util/oslib-posix: Have qemu_get_thread_id return the thread id on macOS
Date: Fri, 27 Nov 2026 09:25:26 +0000 [thread overview]
Message-ID: <awlMhnDkT04Z-AeM@redhat.com> (raw)
In-Reply-To: <20261126220001.58932-1-philmd@oss.qualcomm.com>
On Thu, Nov 26, 2026 at 11:00:01PM +0100, Philippe Mathieu-Daudé wrote:
> qemu_get_thread_id() fell back to getpid() on macOS, so
> every thread, including each vCPU reported by query-cpus-fast,
> shared the process id. Use pthread_threadid_np(), keeping the
> value positive.
>
> For example running '-M virt -smp 2 -accel tcg,thread=multi',
> QMP 'query-cpus-fast' returned before:
>
> {"return": [{"thread-id": 58412, "cpu-index": 0, ...},
> {"thread-id": 58412, "cpu-index": 1, ...}]}
>
> and now:
>
> {"return": [{"thread-id": 75188616, "cpu-index": 0, ...},
> {"thread-id": 75188617, "cpu-index": 1, ...}]}
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
> ---
> util/oslib-posix.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/util/oslib-posix.c b/util/oslib-posix.c
> index dc001da66dd4..71fd369e42f1 100644
> --- a/util/oslib-posix.c
> +++ b/util/oslib-posix.c
> @@ -107,6 +107,10 @@ int qemu_get_thread_id(void)
> return _lwp_self();
> #elif defined(__OpenBSD__)
> return getthrid();
> +#elif defined(__APPLE__)
> + uint64_t tid;
> + pthread_threadid_np(NULL, &tid);
> + return tid & INT_MAX;
> #else
I wonder how likely it is that a thread ID would exceed 'int' ?
IOW, do we need to consider changing return type to uint64_t
> return getpid();
Separately, it is probably worth also adding
warn_report_once("No qemu_get_thread_id() impl on this platform")
so that we nag people to fix remaining platform gaps they
might care about.
With regards,
Daniel
--
|: https://berrange.com ~~ https://hachyderm.io/@berrange :|
|: https://libvirt.org ~~ https://entangle-photo.org :|
|: https://pixelfed.art/berrange ~~ https://fstop138.berrange.com :|
next prev parent reply other threads:[~2026-11-27 9:25 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 22:00 [PATCH] util/oslib-posix: Have qemu_get_thread_id return the thread id on macOS Philippe Mathieu-Daudé
2026-11-26 22:34 ` Mohamed Mediouni
2026-11-26 23:16 ` Pierrick Bouvier
2026-11-27 9:25 ` Daniel P. Berrangé [this message]
2026-11-27 17:17 ` Philippe Mathieu-Daudé
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=awlMhnDkT04Z-AeM@redhat.com \
--to=berrange@redhat.com \
--cc=mohamed@unpredictable.fr \
--cc=pbonzini@redhat.com \
--cc=philmd@oss.qualcomm.com \
--cc=pierrick.bouvier@oss.qualcomm.com \
--cc=qemu-devel@nongnu.org \
/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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.