]> git.proxmox.com Git - mirror_qemu.git/blame - accel/dummy-cpus.c
disas: add G_GNUC_PRINTF to gstring_printf
[mirror_qemu.git] / accel / dummy-cpus.c
CommitLineData
1583a389 1/*
9ce84a0d 2 * Dummy cpu thread code
1583a389
CF
3 *
4 * Copyright IBM, Corp. 2011
5 *
6 * Authors:
7 * Anthony Liguori <aliguori@us.ibm.com>
8 *
9 * This work is licensed under the terms of the GNU GPL, version 2 or later.
10 * See the COPYING file in the top-level directory.
11 *
12 */
13
14#include "qemu/osdep.h"
15#include "qemu/rcu.h"
1583a389 16#include "sysemu/cpus.h"
1583a389
CF
17#include "qemu/guest-random.h"
18#include "qemu/main-loop.h"
19#include "hw/core/cpu.h"
20
9ce84a0d 21static void *dummy_cpu_thread_fn(void *arg)
1583a389 22{
1583a389 23 CPUState *cpu = arg;
1583a389
CF
24
25 rcu_register_thread();
26
27 qemu_mutex_lock_iothread();
28 qemu_thread_get_self(cpu->thread);
29 cpu->thread_id = qemu_get_thread_id();
30 cpu->can_do_io = 1;
31 current_cpu = cpu;
32
c9923550
XC
33#ifndef _WIN32
34 sigset_t waitset;
35 int r;
36
1583a389
CF
37 sigemptyset(&waitset);
38 sigaddset(&waitset, SIG_IPI);
c9923550 39#endif
1583a389
CF
40
41 /* signal CPU creation */
42 cpu_thread_signal_created(cpu);
43 qemu_guest_random_seed_thread_part2(cpu->random_seed);
44
45 do {
46 qemu_mutex_unlock_iothread();
c9923550 47#ifndef _WIN32
1583a389
CF
48 do {
49 int sig;
50 r = sigwait(&waitset, &sig);
51 } while (r == -1 && (errno == EAGAIN || errno == EINTR));
52 if (r == -1) {
53 perror("sigwait");
54 exit(1);
55 }
c9923550
XC
56#else
57 qemu_sem_wait(&cpu->sem);
58#endif
1583a389
CF
59 qemu_mutex_lock_iothread();
60 qemu_wait_io_event(cpu);
61 } while (!cpu->unplug);
62
63 qemu_mutex_unlock_iothread();
64 rcu_unregister_thread();
65 return NULL;
1583a389
CF
66}
67
9ce84a0d 68void dummy_start_vcpu_thread(CPUState *cpu)
1583a389
CF
69{
70 char thread_name[VCPU_THREAD_NAME_SIZE];
71
72 cpu->thread = g_malloc0(sizeof(QemuThread));
73 cpu->halt_cond = g_malloc0(sizeof(QemuCond));
74 qemu_cond_init(cpu->halt_cond);
75 snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/DUMMY",
76 cpu->cpu_index);
9ce84a0d 77 qemu_thread_create(cpu->thread, thread_name, dummy_cpu_thread_fn, cpu,
1583a389 78 QEMU_THREAD_JOINABLE);
c9923550
XC
79#ifdef _WIN32
80 qemu_sem_init(&cpu->sem, 0);
81#endif
1583a389 82}