Lines Matching +full:- +full:affinity
10 * See the COPYING file in the top-level directory.
14 #include "qemu/thread-context.h"
16 #include "qapi/qapi-builtin-visit.h"
18 #include "qemu/config-file.h"
19 #include "qapi/qapi-builtin-visit.h"
46 tc->thread_id = qemu_get_thread_id(); in thread_context_run()
47 qemu_sem_post(&tc->sem); in thread_context_run()
51 * Threads inherit the CPU affinity of the creating thread. For this in thread_context_run()
52 * reason, we create new (especially short-lived) threads from our in thread_context_run()
55 * Especially when QEMU is not allowed to set the affinity itself, in thread_context_run()
56 * management tools can simply set the affinity of the context thread in thread_context_run()
58 * the context inherit the CPU affinity automatically. in thread_context_run()
60 switch (tc->thread_cmd) { in thread_context_run()
64 tc->thread_cmd = TC_CMD_NONE; in thread_context_run()
65 qemu_sem_post(&tc->sem); in thread_context_run()
68 ThreadContextCmdNew *cmd_new = tc->thread_cmd_data; in thread_context_run()
70 qemu_thread_create(cmd_new->thread, cmd_new->name, in thread_context_run()
71 cmd_new->start_routine, cmd_new->arg, in thread_context_run()
72 cmd_new->mode); in thread_context_run()
73 tc->thread_cmd = TC_CMD_NONE; in thread_context_run()
74 tc->thread_cmd_data = NULL; in thread_context_run()
75 qemu_sem_post(&tc->sem); in thread_context_run()
81 qemu_sem_wait(&tc->sem_thread); in thread_context_run()
94 if (tc->init_cpu_bitmap) { in thread_context_set_cpu_affinity()
95 error_setg(errp, "Mixing CPU and node affinity not supported"); in thread_context_set_cpu_affinity()
108 for (l = host_cpus; l; l = l->next) { in thread_context_set_cpu_affinity()
109 nbits = MAX(nbits, l->value + 1); in thread_context_set_cpu_affinity()
112 for (l = host_cpus; l; l = l->next) { in thread_context_set_cpu_affinity()
113 set_bit(l->value, bitmap); in thread_context_set_cpu_affinity()
116 if (tc->thread_id != -1) { in thread_context_set_cpu_affinity()
118 * Note: we won't be adjusting the affinity of any thread that is still in thread_context_set_cpu_affinity()
119 * around, but only the affinity of the context thread. in thread_context_set_cpu_affinity()
121 ret = qemu_thread_set_affinity(&tc->thread, bitmap, nbits); in thread_context_set_cpu_affinity()
123 error_setg(errp, "Setting CPU affinity failed: %s", strerror(ret)); in thread_context_set_cpu_affinity()
126 tc->init_cpu_bitmap = bitmap; in thread_context_set_cpu_affinity()
128 tc->init_cpu_nbits = nbits; in thread_context_set_cpu_affinity()
145 if (tc->thread_id == -1) { in thread_context_get_cpu_affinity()
150 ret = qemu_thread_get_affinity(&tc->thread, &bitmap, &nbits); in thread_context_get_cpu_affinity()
152 error_setg(errp, "Getting CPU affinity failed: %s", strerror(ret)); in thread_context_get_cpu_affinity()
180 if (tc->init_cpu_bitmap) { in thread_context_set_node_affinity()
181 error_setg(errp, "Mixing CPU and node affinity not supported"); in thread_context_set_node_affinity()
196 for (l = host_nodes; l; l = l->next) { in thread_context_set_node_affinity()
198 ret = numa_node_to_cpus(l->value, tmp_cpus); in thread_context_set_node_affinity()
216 if (tc->thread_id != -1) { in thread_context_set_node_affinity()
218 * Note: we won't be adjusting the affinity of any thread that is still in thread_context_set_node_affinity()
219 * around for now, but only the affinity of the context thread. in thread_context_set_node_affinity()
221 ret = qemu_thread_set_affinity(&tc->thread, bitmap, nbits); in thread_context_set_node_affinity()
223 error_setg(errp, "Setting CPU affinity failed: %s", strerror(ret)); in thread_context_set_node_affinity()
226 tc->init_cpu_bitmap = bitmap; in thread_context_set_node_affinity()
228 tc->init_cpu_nbits = nbits; in thread_context_set_node_affinity()
234 error_setg(errp, "NUMA node affinity is not supported by this QEMU"); in thread_context_set_node_affinity()
243 uint64_t value = tc->thread_id; in thread_context_get_thread_id()
256 qemu_thread_create(&tc->thread, thread_name, thread_context_run, tc, in thread_context_instance_complete()
261 while (tc->thread_id == -1) { in thread_context_instance_complete()
262 qemu_sem_wait(&tc->sem); in thread_context_instance_complete()
265 if (tc->init_cpu_bitmap) { in thread_context_instance_complete()
266 ret = qemu_thread_set_affinity(&tc->thread, tc->init_cpu_bitmap, in thread_context_instance_complete()
267 tc->init_cpu_nbits); in thread_context_instance_complete()
269 error_setg(errp, "Setting CPU affinity failed: %s", strerror(ret)); in thread_context_instance_complete()
271 g_free(tc->init_cpu_bitmap); in thread_context_instance_complete()
272 tc->init_cpu_bitmap = NULL; in thread_context_instance_complete()
280 ucc->complete = thread_context_instance_complete; in thread_context_class_init()
281 object_class_property_add(oc, "thread-id", "int", in thread_context_class_init()
284 object_class_property_add(oc, "cpu-affinity", "int", in thread_context_class_init()
287 object_class_property_add(oc, "node-affinity", "int", NULL, in thread_context_class_init()
295 tc->thread_id = -1; in thread_context_instance_init()
296 qemu_sem_init(&tc->sem, 0); in thread_context_instance_init()
297 qemu_sem_init(&tc->sem_thread, 0); in thread_context_instance_init()
298 qemu_mutex_init(&tc->mutex); in thread_context_instance_init()
305 if (tc->thread_id != -1) { in thread_context_instance_finalize()
306 tc->thread_cmd = TC_CMD_STOP; in thread_context_instance_finalize()
307 qemu_sem_post(&tc->sem_thread); in thread_context_instance_finalize()
308 qemu_thread_join(&tc->thread); in thread_context_instance_finalize()
310 qemu_sem_destroy(&tc->sem); in thread_context_instance_finalize()
311 qemu_sem_destroy(&tc->sem_thread); in thread_context_instance_finalize()
312 qemu_mutex_destroy(&tc->mutex); in thread_context_instance_finalize()
347 qemu_mutex_lock(&tc->mutex); in type_init()
348 tc->thread_cmd = TC_CMD_NEW; in type_init()
349 tc->thread_cmd_data = &data; in type_init()
350 qemu_sem_post(&tc->sem_thread); in type_init()
352 while (tc->thread_cmd != TC_CMD_NONE) { in type_init()
353 qemu_sem_wait(&tc->sem); in type_init()
355 qemu_mutex_unlock(&tc->mutex); in type_init()