All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] util/oslib-posix: Have qemu_get_thread_id return the thread id on macOS
@ 2026-11-26 22:00 Philippe Mathieu-Daudé
  2026-11-26 22:34 ` Mohamed Mediouni
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-11-26 22:00 UTC (permalink / raw)
  To: qemu-devel
  Cc: Paolo Bonzini, Pierrick Bouvier, Mohamed Mediouni,
	Philippe Mathieu-Daudé

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



^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-11-27 17:17 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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é
2026-11-27 17:17   ` Philippe Mathieu-Daudé

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.