From: "Philippe Mathieu-Daudé" <philmd@oss.qualcomm.com>
To: qemu-devel@nongnu.org
Cc: "Paolo Bonzini" <pbonzini@redhat.com>,
"Pierrick Bouvier" <pierrick.bouvier@oss.qualcomm.com>,
"Mohamed Mediouni" <mohamed@unpredictable.fr>,
"Philippe Mathieu-Daudé" <philmd@oss.qualcomm.com>
Subject: [PATCH] util/oslib-posix: Have qemu_get_thread_id return the thread id on macOS
Date: Thu, 26 Nov 2026 23:00:01 +0100 [thread overview]
Message-ID: <20261126220001.58932-1-philmd@oss.qualcomm.com> (raw)
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
return getpid();
#endif
--
2.55.0
next reply other threads:[~2026-11-26 22:00 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 22:00 Philippe Mathieu-Daudé [this message]
2026-11-26 22:34 ` [PATCH] util/oslib-posix: Have qemu_get_thread_id return the thread id on macOS Mohamed Mediouni
2026-11-26 23:16 ` Pierrick Bouvier
2026-11-27 9:25 ` Daniel P. Berrangé
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=20261126220001.58932-1-philmd@oss.qualcomm.com \
--to=philmd@oss.qualcomm.com \
--cc=mohamed@unpredictable.fr \
--cc=pbonzini@redhat.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.