aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorDavid Hildenbrand <david@redhat.com>2022-10-14 15:47:15 +0200
committerDavid Hildenbrand <david@redhat.com>2022-10-27 11:00:36 +0200
commit7730f32c281f6005b5d35e0ba4b537a47d2dbf32 (patch)
tree62fddec16ce613751820744b83fff623d3cfd5ce /include
parent6556aadc18c560e493b29dd99cae2cbf86d214cb (diff)
downloadqemu-7730f32c281f6005b5d35e0ba4b537a47d2dbf32.zip
qemu-7730f32c281f6005b5d35e0ba4b537a47d2dbf32.tar.gz
qemu-7730f32c281f6005b5d35e0ba4b537a47d2dbf32.tar.bz2
util: Introduce qemu_thread_set_affinity() and qemu_thread_get_affinity()
Usually, we let upper layers handle CPU pinning, because pthread_setaffinity_np() (-> sched_setaffinity()) is blocked via seccomp when starting QEMU with -sandbox enable=on,resourcecontrol=deny However, we want to configure and observe the CPU affinity of threads from QEMU directly in some cases when the sandbox option is either not enabled or not active yet. So let's add a way to configure CPU pinning via qemu_thread_set_affinity() and obtain CPU affinity via qemu_thread_get_affinity() and implement them under POSIX using pthread_setaffinity_np() + pthread_getaffinity_np(). Implementation under Windows is possible using SetProcessAffinityMask() + GetProcessAffinityMask(), however, that is left as future work. Reviewed-by: Michal Privoznik <mprivozn@redhat.com> Message-Id: <20221014134720.168738-3-david@redhat.com> Signed-off-by: David Hildenbrand <david@redhat.com>
Diffstat (limited to 'include')
-rw-r--r--include/qemu/thread.h4
1 files changed, 4 insertions, 0 deletions
diff --git a/include/qemu/thread.h b/include/qemu/thread.h
index af19f2b..79e507c 100644
--- a/include/qemu/thread.h
+++ b/include/qemu/thread.h
@@ -185,6 +185,10 @@ void qemu_event_destroy(QemuEvent *ev);
void qemu_thread_create(QemuThread *thread, const char *name,
void *(*start_routine)(void *),
void *arg, int mode);
+int qemu_thread_set_affinity(QemuThread *thread, unsigned long *host_cpus,
+ unsigned long nbits);
+int qemu_thread_get_affinity(QemuThread *thread, unsigned long **host_cpus,
+ unsigned long *nbits);
void *qemu_thread_join(QemuThread *thread);
void qemu_thread_get_self(QemuThread *thread);
bool qemu_thread_is_self(QemuThread *thread);