Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 1 | /* |
| 2 | * QEMU System Emulator |
| 3 | * |
| 4 | * Copyright (c) 2003-2008 Fabrice Bellard |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to deal |
| 8 | * in the Software without restriction, including without limitation the rights |
| 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | * copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in |
| 14 | * all copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 22 | * THE SOFTWARE. |
| 23 | */ |
| 24 | |
| 25 | /* Needed early for CONFIG_BSD etc. */ |
| 26 | #include "config-host.h" |
| 27 | |
| 28 | #include "monitor.h" |
| 29 | #include "sysemu.h" |
| 30 | #include "gdbstub.h" |
| 31 | #include "dma.h" |
| 32 | #include "kvm.h" |
| 33 | |
Paolo Bonzini | 96284e8 | 2011-03-12 17:43:53 +0100 | [diff] [blame] | 34 | #include "qemu-thread.h" |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 35 | #include "cpus.h" |
Jan Kiszka | 0ff0fc1 | 2011-06-23 10:15:55 +0200 | [diff] [blame] | 36 | |
| 37 | #ifndef _WIN32 |
Marcelo Tosatti | a8486bc | 2010-10-11 15:31:16 -0300 | [diff] [blame] | 38 | #include "compatfd.h" |
Jan Kiszka | 0ff0fc1 | 2011-06-23 10:15:55 +0200 | [diff] [blame] | 39 | #endif |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 40 | |
Blue Swirl | 7277e02 | 2010-04-12 17:19:06 +0000 | [diff] [blame] | 41 | #ifdef SIGRTMIN |
| 42 | #define SIG_IPI (SIGRTMIN+4) |
| 43 | #else |
| 44 | #define SIG_IPI SIGUSR1 |
| 45 | #endif |
| 46 | |
Jan Kiszka | 6d9cb73 | 2011-02-01 22:15:58 +0100 | [diff] [blame] | 47 | #ifdef CONFIG_LINUX |
| 48 | |
| 49 | #include <sys/prctl.h> |
| 50 | |
Marcelo Tosatti | c0532a7 | 2010-10-11 15:31:21 -0300 | [diff] [blame] | 51 | #ifndef PR_MCE_KILL |
| 52 | #define PR_MCE_KILL 33 |
| 53 | #endif |
| 54 | |
Jan Kiszka | 6d9cb73 | 2011-02-01 22:15:58 +0100 | [diff] [blame] | 55 | #ifndef PR_MCE_KILL_SET |
| 56 | #define PR_MCE_KILL_SET 1 |
| 57 | #endif |
| 58 | |
| 59 | #ifndef PR_MCE_KILL_EARLY |
| 60 | #define PR_MCE_KILL_EARLY 1 |
| 61 | #endif |
| 62 | |
| 63 | #endif /* CONFIG_LINUX */ |
| 64 | |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 65 | static CPUState *next_cpu; |
| 66 | |
| 67 | /***********************************************************/ |
| 68 | void hw_error(const char *fmt, ...) |
| 69 | { |
| 70 | va_list ap; |
| 71 | CPUState *env; |
| 72 | |
| 73 | va_start(ap, fmt); |
| 74 | fprintf(stderr, "qemu: hardware error: "); |
| 75 | vfprintf(stderr, fmt, ap); |
| 76 | fprintf(stderr, "\n"); |
| 77 | for(env = first_cpu; env != NULL; env = env->next_cpu) { |
| 78 | fprintf(stderr, "CPU #%d:\n", env->cpu_index); |
| 79 | #ifdef TARGET_I386 |
| 80 | cpu_dump_state(env, stderr, fprintf, X86_DUMP_FPU); |
| 81 | #else |
| 82 | cpu_dump_state(env, stderr, fprintf, 0); |
| 83 | #endif |
| 84 | } |
| 85 | va_end(ap); |
| 86 | abort(); |
| 87 | } |
| 88 | |
| 89 | void cpu_synchronize_all_states(void) |
| 90 | { |
| 91 | CPUState *cpu; |
| 92 | |
| 93 | for (cpu = first_cpu; cpu; cpu = cpu->next_cpu) { |
| 94 | cpu_synchronize_state(cpu); |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | void cpu_synchronize_all_post_reset(void) |
| 99 | { |
| 100 | CPUState *cpu; |
| 101 | |
| 102 | for (cpu = first_cpu; cpu; cpu = cpu->next_cpu) { |
| 103 | cpu_synchronize_post_reset(cpu); |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | void cpu_synchronize_all_post_init(void) |
| 108 | { |
| 109 | CPUState *cpu; |
| 110 | |
| 111 | for (cpu = first_cpu; cpu; cpu = cpu->next_cpu) { |
| 112 | cpu_synchronize_post_init(cpu); |
| 113 | } |
| 114 | } |
| 115 | |
Marcelo Tosatti | 3ae9501 | 2010-05-04 09:45:24 -0300 | [diff] [blame] | 116 | int cpu_is_stopped(CPUState *env) |
| 117 | { |
| 118 | return !vm_running || env->stopped; |
| 119 | } |
| 120 | |
Luiz Capitulino | 1dfb4dd | 2011-07-29 14:26:33 -0300 | [diff] [blame] | 121 | static void do_vm_stop(RunState state) |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 122 | { |
| 123 | if (vm_running) { |
| 124 | cpu_disable_ticks(); |
| 125 | vm_running = 0; |
| 126 | pause_all_vcpus(); |
Luiz Capitulino | f5bbfba | 2011-07-29 15:04:45 -0300 | [diff] [blame] | 127 | runstate_set(state); |
Luiz Capitulino | 1dfb4dd | 2011-07-29 14:26:33 -0300 | [diff] [blame] | 128 | vm_state_notify(0, state); |
Michael S. Tsirkin | 55df6f3 | 2010-11-22 19:52:22 +0200 | [diff] [blame] | 129 | qemu_aio_flush(); |
| 130 | bdrv_flush_all(); |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 131 | monitor_protocol_event(QEVENT_STOP, NULL); |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | static int cpu_can_run(CPUState *env) |
| 136 | { |
Jan Kiszka | 0ab07c6 | 2011-02-07 12:19:14 +0100 | [diff] [blame] | 137 | if (env->stop) { |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 138 | return 0; |
Jan Kiszka | 0ab07c6 | 2011-02-07 12:19:14 +0100 | [diff] [blame] | 139 | } |
| 140 | if (env->stopped || !vm_running) { |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 141 | return 0; |
Jan Kiszka | 0ab07c6 | 2011-02-07 12:19:14 +0100 | [diff] [blame] | 142 | } |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 143 | return 1; |
| 144 | } |
| 145 | |
Jan Kiszka | 1640032 | 2011-02-09 16:29:37 +0100 | [diff] [blame] | 146 | static bool cpu_thread_is_idle(CPUState *env) |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 147 | { |
Jan Kiszka | 1640032 | 2011-02-09 16:29:37 +0100 | [diff] [blame] | 148 | if (env->stop || env->queued_work_first) { |
| 149 | return false; |
| 150 | } |
| 151 | if (env->stopped || !vm_running) { |
| 152 | return true; |
| 153 | } |
Jan Kiszka | f2c1cc8 | 2011-03-15 12:26:18 +0100 | [diff] [blame] | 154 | if (!env->halted || qemu_cpu_has_work(env) || |
| 155 | (kvm_enabled() && kvm_irqchip_in_kernel())) { |
Jan Kiszka | 1640032 | 2011-02-09 16:29:37 +0100 | [diff] [blame] | 156 | return false; |
| 157 | } |
| 158 | return true; |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 159 | } |
| 160 | |
Paolo Bonzini | ab33fcd | 2011-04-13 10:03:44 +0200 | [diff] [blame] | 161 | bool all_cpu_threads_idle(void) |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 162 | { |
| 163 | CPUState *env; |
| 164 | |
Jan Kiszka | 1640032 | 2011-02-09 16:29:37 +0100 | [diff] [blame] | 165 | for (env = first_cpu; env != NULL; env = env->next_cpu) { |
| 166 | if (!cpu_thread_is_idle(env)) { |
| 167 | return false; |
| 168 | } |
| 169 | } |
| 170 | return true; |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 171 | } |
| 172 | |
Jan Kiszka | 1009d2e | 2011-03-15 12:26:13 +0100 | [diff] [blame] | 173 | static void cpu_handle_guest_debug(CPUState *env) |
Jan Kiszka | 3c638d0 | 2010-06-25 16:56:56 +0200 | [diff] [blame] | 174 | { |
| 175 | gdb_set_stop_cpu(env); |
Jan Kiszka | 8cf7171 | 2011-02-07 12:19:16 +0100 | [diff] [blame] | 176 | qemu_system_debug_request(); |
Jan Kiszka | 83f338f | 2011-02-07 12:19:17 +0100 | [diff] [blame] | 177 | env->stopped = 1; |
Jan Kiszka | 3c638d0 | 2010-06-25 16:56:56 +0200 | [diff] [blame] | 178 | } |
| 179 | |
Paolo Bonzini | 714bd04 | 2011-03-12 17:44:06 +0100 | [diff] [blame] | 180 | static void cpu_signal(int sig) |
| 181 | { |
| 182 | if (cpu_single_env) { |
| 183 | cpu_exit(cpu_single_env); |
| 184 | } |
| 185 | exit_request = 1; |
| 186 | } |
Paolo Bonzini | 714bd04 | 2011-03-12 17:44:06 +0100 | [diff] [blame] | 187 | |
Jan Kiszka | 6d9cb73 | 2011-02-01 22:15:58 +0100 | [diff] [blame] | 188 | #ifdef CONFIG_LINUX |
| 189 | static void sigbus_reraise(void) |
| 190 | { |
| 191 | sigset_t set; |
| 192 | struct sigaction action; |
| 193 | |
| 194 | memset(&action, 0, sizeof(action)); |
| 195 | action.sa_handler = SIG_DFL; |
| 196 | if (!sigaction(SIGBUS, &action, NULL)) { |
| 197 | raise(SIGBUS); |
| 198 | sigemptyset(&set); |
| 199 | sigaddset(&set, SIGBUS); |
| 200 | sigprocmask(SIG_UNBLOCK, &set, NULL); |
| 201 | } |
| 202 | perror("Failed to re-raise SIGBUS!\n"); |
| 203 | abort(); |
| 204 | } |
| 205 | |
| 206 | static void sigbus_handler(int n, struct qemu_signalfd_siginfo *siginfo, |
| 207 | void *ctx) |
| 208 | { |
| 209 | if (kvm_on_sigbus(siginfo->ssi_code, |
| 210 | (void *)(intptr_t)siginfo->ssi_addr)) { |
| 211 | sigbus_reraise(); |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | static void qemu_init_sigbus(void) |
| 216 | { |
| 217 | struct sigaction action; |
| 218 | |
| 219 | memset(&action, 0, sizeof(action)); |
| 220 | action.sa_flags = SA_SIGINFO; |
| 221 | action.sa_sigaction = (void (*)(int, siginfo_t*, void*))sigbus_handler; |
| 222 | sigaction(SIGBUS, &action, NULL); |
| 223 | |
| 224 | prctl(PR_MCE_KILL, PR_MCE_KILL_SET, PR_MCE_KILL_EARLY, 0, 0); |
| 225 | } |
| 226 | |
Jan Kiszka | 1ab3c6c | 2011-03-15 12:26:12 +0100 | [diff] [blame] | 227 | static void qemu_kvm_eat_signals(CPUState *env) |
| 228 | { |
| 229 | struct timespec ts = { 0, 0 }; |
| 230 | siginfo_t siginfo; |
| 231 | sigset_t waitset; |
| 232 | sigset_t chkset; |
| 233 | int r; |
| 234 | |
| 235 | sigemptyset(&waitset); |
| 236 | sigaddset(&waitset, SIG_IPI); |
| 237 | sigaddset(&waitset, SIGBUS); |
| 238 | |
| 239 | do { |
| 240 | r = sigtimedwait(&waitset, &siginfo, &ts); |
| 241 | if (r == -1 && !(errno == EAGAIN || errno == EINTR)) { |
| 242 | perror("sigtimedwait"); |
| 243 | exit(1); |
| 244 | } |
| 245 | |
| 246 | switch (r) { |
| 247 | case SIGBUS: |
| 248 | if (kvm_on_sigbus_vcpu(env, siginfo.si_code, siginfo.si_addr)) { |
| 249 | sigbus_reraise(); |
| 250 | } |
| 251 | break; |
| 252 | default: |
| 253 | break; |
| 254 | } |
| 255 | |
| 256 | r = sigpending(&chkset); |
| 257 | if (r == -1) { |
| 258 | perror("sigpending"); |
| 259 | exit(1); |
| 260 | } |
| 261 | } while (sigismember(&chkset, SIG_IPI) || sigismember(&chkset, SIGBUS)); |
Jan Kiszka | 1ab3c6c | 2011-03-15 12:26:12 +0100 | [diff] [blame] | 262 | } |
| 263 | |
Jan Kiszka | 6d9cb73 | 2011-02-01 22:15:58 +0100 | [diff] [blame] | 264 | #else /* !CONFIG_LINUX */ |
| 265 | |
| 266 | static void qemu_init_sigbus(void) |
| 267 | { |
| 268 | } |
Jan Kiszka | 1ab3c6c | 2011-03-15 12:26:12 +0100 | [diff] [blame] | 269 | |
| 270 | static void qemu_kvm_eat_signals(CPUState *env) |
| 271 | { |
| 272 | } |
Jan Kiszka | 6d9cb73 | 2011-02-01 22:15:58 +0100 | [diff] [blame] | 273 | #endif /* !CONFIG_LINUX */ |
| 274 | |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 275 | #ifndef _WIN32 |
| 276 | static int io_thread_fd = -1; |
| 277 | |
| 278 | static void qemu_event_increment(void) |
| 279 | { |
| 280 | /* Write 8 bytes to be compatible with eventfd. */ |
Blue Swirl | 26a8233 | 2010-05-14 19:32:21 +0000 | [diff] [blame] | 281 | static const uint64_t val = 1; |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 282 | ssize_t ret; |
| 283 | |
Jan Kiszka | 0ab07c6 | 2011-02-07 12:19:14 +0100 | [diff] [blame] | 284 | if (io_thread_fd == -1) { |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 285 | return; |
Jan Kiszka | 0ab07c6 | 2011-02-07 12:19:14 +0100 | [diff] [blame] | 286 | } |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 287 | do { |
| 288 | ret = write(io_thread_fd, &val, sizeof(val)); |
| 289 | } while (ret < 0 && errno == EINTR); |
| 290 | |
| 291 | /* EAGAIN is fine, a read must be pending. */ |
| 292 | if (ret < 0 && errno != EAGAIN) { |
Alexandre Raymond | 77bec68 | 2011-06-13 22:16:36 -0400 | [diff] [blame] | 293 | fprintf(stderr, "qemu_event_increment: write() failed: %s\n", |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 294 | strerror(errno)); |
| 295 | exit (1); |
| 296 | } |
| 297 | } |
| 298 | |
| 299 | static void qemu_event_read(void *opaque) |
| 300 | { |
Stefan Weil | e0efb99 | 2011-02-23 19:09:16 +0100 | [diff] [blame] | 301 | int fd = (intptr_t)opaque; |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 302 | ssize_t len; |
| 303 | char buffer[512]; |
| 304 | |
| 305 | /* Drain the notify pipe. For eventfd, only 8 bytes will be read. */ |
| 306 | do { |
| 307 | len = read(fd, buffer, sizeof(buffer)); |
| 308 | } while ((len == -1 && errno == EINTR) || len == sizeof(buffer)); |
| 309 | } |
| 310 | |
| 311 | static int qemu_event_init(void) |
| 312 | { |
| 313 | int err; |
| 314 | int fds[2]; |
| 315 | |
| 316 | err = qemu_eventfd(fds); |
Jan Kiszka | 0ab07c6 | 2011-02-07 12:19:14 +0100 | [diff] [blame] | 317 | if (err == -1) { |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 318 | return -errno; |
Jan Kiszka | 0ab07c6 | 2011-02-07 12:19:14 +0100 | [diff] [blame] | 319 | } |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 320 | err = fcntl_setfl(fds[0], O_NONBLOCK); |
Jan Kiszka | 0ab07c6 | 2011-02-07 12:19:14 +0100 | [diff] [blame] | 321 | if (err < 0) { |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 322 | goto fail; |
Jan Kiszka | 0ab07c6 | 2011-02-07 12:19:14 +0100 | [diff] [blame] | 323 | } |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 324 | err = fcntl_setfl(fds[1], O_NONBLOCK); |
Jan Kiszka | 0ab07c6 | 2011-02-07 12:19:14 +0100 | [diff] [blame] | 325 | if (err < 0) { |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 326 | goto fail; |
Jan Kiszka | 0ab07c6 | 2011-02-07 12:19:14 +0100 | [diff] [blame] | 327 | } |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 328 | qemu_set_fd_handler2(fds[0], NULL, qemu_event_read, NULL, |
Stefan Weil | e0efb99 | 2011-02-23 19:09:16 +0100 | [diff] [blame] | 329 | (void *)(intptr_t)fds[0]); |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 330 | |
| 331 | io_thread_fd = fds[1]; |
| 332 | return 0; |
| 333 | |
| 334 | fail: |
| 335 | close(fds[0]); |
| 336 | close(fds[1]); |
| 337 | return err; |
| 338 | } |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 339 | |
Jan Kiszka | 55f8d6a | 2011-02-01 22:15:52 +0100 | [diff] [blame] | 340 | static void dummy_signal(int sig) |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 341 | { |
| 342 | } |
| 343 | |
Marcelo Tosatti | a8486bc | 2010-10-11 15:31:16 -0300 | [diff] [blame] | 344 | /* If we have signalfd, we mask out the signals we want to handle and then |
| 345 | * use signalfd to listen for them. We rely on whatever the current signal |
| 346 | * handler is to dispatch the signals when we receive them. |
| 347 | */ |
| 348 | static void sigfd_handler(void *opaque) |
| 349 | { |
Stefan Weil | e0efb99 | 2011-02-23 19:09:16 +0100 | [diff] [blame] | 350 | int fd = (intptr_t)opaque; |
Marcelo Tosatti | a8486bc | 2010-10-11 15:31:16 -0300 | [diff] [blame] | 351 | struct qemu_signalfd_siginfo info; |
| 352 | struct sigaction action; |
| 353 | ssize_t len; |
| 354 | |
| 355 | while (1) { |
| 356 | do { |
| 357 | len = read(fd, &info, sizeof(info)); |
| 358 | } while (len == -1 && errno == EINTR); |
| 359 | |
| 360 | if (len == -1 && errno == EAGAIN) { |
| 361 | break; |
| 362 | } |
| 363 | |
| 364 | if (len != sizeof(info)) { |
| 365 | printf("read from sigfd returned %zd: %m\n", len); |
| 366 | return; |
| 367 | } |
| 368 | |
| 369 | sigaction(info.ssi_signo, NULL, &action); |
| 370 | if ((action.sa_flags & SA_SIGINFO) && action.sa_sigaction) { |
| 371 | action.sa_sigaction(info.ssi_signo, |
| 372 | (siginfo_t *)&info, NULL); |
| 373 | } else if (action.sa_handler) { |
| 374 | action.sa_handler(info.ssi_signo); |
| 375 | } |
| 376 | } |
| 377 | } |
| 378 | |
Paolo Bonzini | 712ae48 | 2011-03-12 17:44:05 +0100 | [diff] [blame] | 379 | static int qemu_signal_init(void) |
Marcelo Tosatti | a8486bc | 2010-10-11 15:31:16 -0300 | [diff] [blame] | 380 | { |
| 381 | int sigfd; |
Paolo Bonzini | 712ae48 | 2011-03-12 17:44:05 +0100 | [diff] [blame] | 382 | sigset_t set; |
Marcelo Tosatti | a8486bc | 2010-10-11 15:31:16 -0300 | [diff] [blame] | 383 | |
Paolo Bonzini | 712ae48 | 2011-03-12 17:44:05 +0100 | [diff] [blame] | 384 | /* SIGUSR2 used by posix-aio-compat.c */ |
| 385 | sigemptyset(&set); |
| 386 | sigaddset(&set, SIGUSR2); |
| 387 | pthread_sigmask(SIG_UNBLOCK, &set, NULL); |
| 388 | |
Alexandre Raymond | 89b9ba6 | 2011-06-15 01:20:31 -0400 | [diff] [blame] | 389 | /* |
| 390 | * SIG_IPI must be blocked in the main thread and must not be caught |
| 391 | * by sigwait() in the signal thread. Otherwise, the cpu thread will |
| 392 | * not catch it reliably. |
| 393 | */ |
| 394 | sigemptyset(&set); |
| 395 | sigaddset(&set, SIG_IPI); |
| 396 | pthread_sigmask(SIG_BLOCK, &set, NULL); |
| 397 | |
Paolo Bonzini | 712ae48 | 2011-03-12 17:44:05 +0100 | [diff] [blame] | 398 | sigemptyset(&set); |
| 399 | sigaddset(&set, SIGIO); |
| 400 | sigaddset(&set, SIGALRM); |
Paolo Bonzini | 712ae48 | 2011-03-12 17:44:05 +0100 | [diff] [blame] | 401 | sigaddset(&set, SIGBUS); |
Alexandre Raymond | 5664aed | 2011-06-14 10:05:36 -0400 | [diff] [blame] | 402 | pthread_sigmask(SIG_BLOCK, &set, NULL); |
Paolo Bonzini | 712ae48 | 2011-03-12 17:44:05 +0100 | [diff] [blame] | 403 | |
| 404 | sigfd = qemu_signalfd(&set); |
Marcelo Tosatti | a8486bc | 2010-10-11 15:31:16 -0300 | [diff] [blame] | 405 | if (sigfd == -1) { |
| 406 | fprintf(stderr, "failed to create signalfd\n"); |
| 407 | return -errno; |
| 408 | } |
| 409 | |
| 410 | fcntl_setfl(sigfd, O_NONBLOCK); |
| 411 | |
| 412 | qemu_set_fd_handler2(sigfd, NULL, sigfd_handler, NULL, |
Stefan Weil | e0efb99 | 2011-02-23 19:09:16 +0100 | [diff] [blame] | 413 | (void *)(intptr_t)sigfd); |
Marcelo Tosatti | a8486bc | 2010-10-11 15:31:16 -0300 | [diff] [blame] | 414 | |
| 415 | return 0; |
| 416 | } |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 417 | |
Paolo Bonzini | 714bd04 | 2011-03-12 17:44:06 +0100 | [diff] [blame] | 418 | static void qemu_kvm_init_cpu_signals(CPUState *env) |
| 419 | { |
| 420 | int r; |
| 421 | sigset_t set; |
| 422 | struct sigaction sigact; |
| 423 | |
| 424 | memset(&sigact, 0, sizeof(sigact)); |
| 425 | sigact.sa_handler = dummy_signal; |
| 426 | sigaction(SIG_IPI, &sigact, NULL); |
| 427 | |
Paolo Bonzini | 714bd04 | 2011-03-12 17:44:06 +0100 | [diff] [blame] | 428 | pthread_sigmask(SIG_BLOCK, NULL, &set); |
| 429 | sigdelset(&set, SIG_IPI); |
| 430 | sigdelset(&set, SIGBUS); |
| 431 | r = kvm_set_signal_mask(env, &set); |
| 432 | if (r) { |
| 433 | fprintf(stderr, "kvm_set_signal_mask: %s\n", strerror(-r)); |
| 434 | exit(1); |
| 435 | } |
Paolo Bonzini | 714bd04 | 2011-03-12 17:44:06 +0100 | [diff] [blame] | 436 | |
Paolo Bonzini | 714bd04 | 2011-03-12 17:44:06 +0100 | [diff] [blame] | 437 | sigdelset(&set, SIG_IPI); |
| 438 | sigdelset(&set, SIGBUS); |
| 439 | r = kvm_set_signal_mask(env, &set); |
| 440 | if (r) { |
| 441 | fprintf(stderr, "kvm_set_signal_mask: %s\n", strerror(-r)); |
| 442 | exit(1); |
| 443 | } |
| 444 | } |
| 445 | |
| 446 | static void qemu_tcg_init_cpu_signals(void) |
| 447 | { |
Paolo Bonzini | 714bd04 | 2011-03-12 17:44:06 +0100 | [diff] [blame] | 448 | sigset_t set; |
| 449 | struct sigaction sigact; |
| 450 | |
| 451 | memset(&sigact, 0, sizeof(sigact)); |
| 452 | sigact.sa_handler = cpu_signal; |
| 453 | sigaction(SIG_IPI, &sigact, NULL); |
| 454 | |
| 455 | sigemptyset(&set); |
| 456 | sigaddset(&set, SIG_IPI); |
| 457 | pthread_sigmask(SIG_UNBLOCK, &set, NULL); |
Paolo Bonzini | 714bd04 | 2011-03-12 17:44:06 +0100 | [diff] [blame] | 458 | } |
| 459 | |
Jan Kiszka | 55f8d6a | 2011-02-01 22:15:52 +0100 | [diff] [blame] | 460 | #else /* _WIN32 */ |
| 461 | |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 462 | HANDLE qemu_event_handle; |
| 463 | |
| 464 | static void dummy_event_handler(void *opaque) |
| 465 | { |
| 466 | } |
| 467 | |
| 468 | static int qemu_event_init(void) |
| 469 | { |
| 470 | qemu_event_handle = CreateEvent(NULL, FALSE, FALSE, NULL); |
| 471 | if (!qemu_event_handle) { |
| 472 | fprintf(stderr, "Failed CreateEvent: %ld\n", GetLastError()); |
| 473 | return -1; |
| 474 | } |
| 475 | qemu_add_wait_object(qemu_event_handle, dummy_event_handler, NULL); |
| 476 | return 0; |
| 477 | } |
| 478 | |
| 479 | static void qemu_event_increment(void) |
| 480 | { |
| 481 | if (!SetEvent(qemu_event_handle)) { |
| 482 | fprintf(stderr, "qemu_event_increment: SetEvent failed: %ld\n", |
| 483 | GetLastError()); |
| 484 | exit (1); |
| 485 | } |
| 486 | } |
Jan Kiszka | 9a36085 | 2011-02-01 22:15:55 +0100 | [diff] [blame] | 487 | |
Paolo Bonzini | 712ae48 | 2011-03-12 17:44:05 +0100 | [diff] [blame] | 488 | static int qemu_signal_init(void) |
| 489 | { |
| 490 | return 0; |
| 491 | } |
| 492 | |
Paolo Bonzini | 714bd04 | 2011-03-12 17:44:06 +0100 | [diff] [blame] | 493 | static void qemu_kvm_init_cpu_signals(CPUState *env) |
| 494 | { |
| 495 | abort(); |
| 496 | } |
| 497 | |
| 498 | static void qemu_tcg_init_cpu_signals(void) |
| 499 | { |
| 500 | } |
Jan Kiszka | 55f8d6a | 2011-02-01 22:15:52 +0100 | [diff] [blame] | 501 | #endif /* _WIN32 */ |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 502 | |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 503 | QemuMutex qemu_global_mutex; |
Paolo Bonzini | 46daff1 | 2011-06-09 13:10:24 +0200 | [diff] [blame] | 504 | static QemuCond qemu_io_proceeded_cond; |
| 505 | static bool iothread_requesting_mutex; |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 506 | |
| 507 | static QemuThread io_thread; |
| 508 | |
| 509 | static QemuThread *tcg_cpu_thread; |
| 510 | static QemuCond *tcg_halt_cond; |
| 511 | |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 512 | /* cpu creation */ |
| 513 | static QemuCond qemu_cpu_cond; |
| 514 | /* system init */ |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 515 | static QemuCond qemu_pause_cond; |
| 516 | static QemuCond qemu_work_cond; |
| 517 | |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 518 | int qemu_init_main_loop(void) |
| 519 | { |
| 520 | int ret; |
| 521 | |
Jan Kiszka | 6d9cb73 | 2011-02-01 22:15:58 +0100 | [diff] [blame] | 522 | qemu_init_sigbus(); |
Jan Kiszka | 3c638d0 | 2010-06-25 16:56:56 +0200 | [diff] [blame] | 523 | |
Paolo Bonzini | 712ae48 | 2011-03-12 17:44:05 +0100 | [diff] [blame] | 524 | ret = qemu_signal_init(); |
Jan Kiszka | 0ab07c6 | 2011-02-07 12:19:14 +0100 | [diff] [blame] | 525 | if (ret) { |
Marcelo Tosatti | a8486bc | 2010-10-11 15:31:16 -0300 | [diff] [blame] | 526 | return ret; |
Jan Kiszka | 0ab07c6 | 2011-02-07 12:19:14 +0100 | [diff] [blame] | 527 | } |
Marcelo Tosatti | a8486bc | 2010-10-11 15:31:16 -0300 | [diff] [blame] | 528 | |
| 529 | /* Note eventfd must be drained before signalfd handlers run */ |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 530 | ret = qemu_event_init(); |
Jan Kiszka | 0ab07c6 | 2011-02-07 12:19:14 +0100 | [diff] [blame] | 531 | if (ret) { |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 532 | return ret; |
Jan Kiszka | 0ab07c6 | 2011-02-07 12:19:14 +0100 | [diff] [blame] | 533 | } |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 534 | |
Anthony Liguori | ed94592 | 2011-02-08 18:18:18 +0100 | [diff] [blame] | 535 | qemu_cond_init(&qemu_cpu_cond); |
Anthony Liguori | ed94592 | 2011-02-08 18:18:18 +0100 | [diff] [blame] | 536 | qemu_cond_init(&qemu_pause_cond); |
| 537 | qemu_cond_init(&qemu_work_cond); |
Paolo Bonzini | 46daff1 | 2011-06-09 13:10:24 +0200 | [diff] [blame] | 538 | qemu_cond_init(&qemu_io_proceeded_cond); |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 539 | qemu_mutex_init(&qemu_global_mutex); |
| 540 | qemu_mutex_lock(&qemu_global_mutex); |
| 541 | |
Jan Kiszka | b7680cb | 2011-03-12 17:43:51 +0100 | [diff] [blame] | 542 | qemu_thread_get_self(&io_thread); |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 543 | |
| 544 | return 0; |
| 545 | } |
| 546 | |
Blue Swirl | 7277e02 | 2010-04-12 17:19:06 +0000 | [diff] [blame] | 547 | void qemu_main_loop_start(void) |
| 548 | { |
Jan Kiszka | fa7d186 | 2011-08-22 18:35:25 +0200 | [diff] [blame] | 549 | resume_all_vcpus(); |
Blue Swirl | 7277e02 | 2010-04-12 17:19:06 +0000 | [diff] [blame] | 550 | } |
| 551 | |
Marcelo Tosatti | e82bcec | 2010-05-04 09:45:22 -0300 | [diff] [blame] | 552 | void run_on_cpu(CPUState *env, void (*func)(void *data), void *data) |
| 553 | { |
| 554 | struct qemu_work_item wi; |
| 555 | |
Jan Kiszka | b7680cb | 2011-03-12 17:43:51 +0100 | [diff] [blame] | 556 | if (qemu_cpu_is_self(env)) { |
Marcelo Tosatti | e82bcec | 2010-05-04 09:45:22 -0300 | [diff] [blame] | 557 | func(data); |
| 558 | return; |
| 559 | } |
| 560 | |
| 561 | wi.func = func; |
| 562 | wi.data = data; |
Jan Kiszka | 0ab07c6 | 2011-02-07 12:19:14 +0100 | [diff] [blame] | 563 | if (!env->queued_work_first) { |
Marcelo Tosatti | e82bcec | 2010-05-04 09:45:22 -0300 | [diff] [blame] | 564 | env->queued_work_first = &wi; |
Jan Kiszka | 0ab07c6 | 2011-02-07 12:19:14 +0100 | [diff] [blame] | 565 | } else { |
Marcelo Tosatti | e82bcec | 2010-05-04 09:45:22 -0300 | [diff] [blame] | 566 | env->queued_work_last->next = &wi; |
Jan Kiszka | 0ab07c6 | 2011-02-07 12:19:14 +0100 | [diff] [blame] | 567 | } |
Marcelo Tosatti | e82bcec | 2010-05-04 09:45:22 -0300 | [diff] [blame] | 568 | env->queued_work_last = &wi; |
| 569 | wi.next = NULL; |
| 570 | wi.done = false; |
| 571 | |
| 572 | qemu_cpu_kick(env); |
| 573 | while (!wi.done) { |
| 574 | CPUState *self_env = cpu_single_env; |
| 575 | |
| 576 | qemu_cond_wait(&qemu_work_cond, &qemu_global_mutex); |
| 577 | cpu_single_env = self_env; |
| 578 | } |
| 579 | } |
| 580 | |
| 581 | static void flush_queued_work(CPUState *env) |
| 582 | { |
| 583 | struct qemu_work_item *wi; |
| 584 | |
Jan Kiszka | 0ab07c6 | 2011-02-07 12:19:14 +0100 | [diff] [blame] | 585 | if (!env->queued_work_first) { |
Marcelo Tosatti | e82bcec | 2010-05-04 09:45:22 -0300 | [diff] [blame] | 586 | return; |
Jan Kiszka | 0ab07c6 | 2011-02-07 12:19:14 +0100 | [diff] [blame] | 587 | } |
Marcelo Tosatti | e82bcec | 2010-05-04 09:45:22 -0300 | [diff] [blame] | 588 | |
| 589 | while ((wi = env->queued_work_first)) { |
| 590 | env->queued_work_first = wi->next; |
| 591 | wi->func(wi->data); |
| 592 | wi->done = true; |
| 593 | } |
| 594 | env->queued_work_last = NULL; |
| 595 | qemu_cond_broadcast(&qemu_work_cond); |
| 596 | } |
| 597 | |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 598 | static void qemu_wait_io_event_common(CPUState *env) |
| 599 | { |
| 600 | if (env->stop) { |
| 601 | env->stop = 0; |
| 602 | env->stopped = 1; |
| 603 | qemu_cond_signal(&qemu_pause_cond); |
| 604 | } |
Marcelo Tosatti | e82bcec | 2010-05-04 09:45:22 -0300 | [diff] [blame] | 605 | flush_queued_work(env); |
Jan Kiszka | aa2c364 | 2011-02-01 22:15:42 +0100 | [diff] [blame] | 606 | env->thread_kicked = false; |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 607 | } |
| 608 | |
Jan Kiszka | 6cabe1f | 2010-06-25 16:56:53 +0200 | [diff] [blame] | 609 | static void qemu_tcg_wait_io_event(void) |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 610 | { |
Jan Kiszka | 6cabe1f | 2010-06-25 16:56:53 +0200 | [diff] [blame] | 611 | CPUState *env; |
| 612 | |
Jan Kiszka | 1640032 | 2011-02-09 16:29:37 +0100 | [diff] [blame] | 613 | while (all_cpu_threads_idle()) { |
Paolo Bonzini | ab33fcd | 2011-04-13 10:03:44 +0200 | [diff] [blame] | 614 | /* Start accounting real time to the virtual clock if the CPUs |
| 615 | are idle. */ |
| 616 | qemu_clock_warp(vm_clock); |
Paolo Bonzini | 9705fbb | 2011-03-12 17:44:00 +0100 | [diff] [blame] | 617 | qemu_cond_wait(tcg_halt_cond, &qemu_global_mutex); |
Jan Kiszka | 1640032 | 2011-02-09 16:29:37 +0100 | [diff] [blame] | 618 | } |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 619 | |
Paolo Bonzini | 46daff1 | 2011-06-09 13:10:24 +0200 | [diff] [blame] | 620 | while (iothread_requesting_mutex) { |
| 621 | qemu_cond_wait(&qemu_io_proceeded_cond, &qemu_global_mutex); |
| 622 | } |
Jan Kiszka | 6cabe1f | 2010-06-25 16:56:53 +0200 | [diff] [blame] | 623 | |
| 624 | for (env = first_cpu; env != NULL; env = env->next_cpu) { |
| 625 | qemu_wait_io_event_common(env); |
| 626 | } |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 627 | } |
| 628 | |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 629 | static void qemu_kvm_wait_io_event(CPUState *env) |
| 630 | { |
Jan Kiszka | 1640032 | 2011-02-09 16:29:37 +0100 | [diff] [blame] | 631 | while (cpu_thread_is_idle(env)) { |
Paolo Bonzini | 9705fbb | 2011-03-12 17:44:00 +0100 | [diff] [blame] | 632 | qemu_cond_wait(env->halt_cond, &qemu_global_mutex); |
Jan Kiszka | 1640032 | 2011-02-09 16:29:37 +0100 | [diff] [blame] | 633 | } |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 634 | |
Jan Kiszka | 5db5bda | 2011-02-01 22:15:54 +0100 | [diff] [blame] | 635 | qemu_kvm_eat_signals(env); |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 636 | qemu_wait_io_event_common(env); |
| 637 | } |
| 638 | |
Jan Kiszka | 7e97cd8 | 2011-02-07 12:19:12 +0100 | [diff] [blame] | 639 | static void *qemu_kvm_cpu_thread_fn(void *arg) |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 640 | { |
| 641 | CPUState *env = arg; |
Jan Kiszka | 84b4915 | 2011-02-01 22:15:50 +0100 | [diff] [blame] | 642 | int r; |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 643 | |
Marcelo Tosatti | 6164e6d | 2010-03-23 13:37:13 -0300 | [diff] [blame] | 644 | qemu_mutex_lock(&qemu_global_mutex); |
Jan Kiszka | b7680cb | 2011-03-12 17:43:51 +0100 | [diff] [blame] | 645 | qemu_thread_get_self(env->thread); |
Jan Kiszka | dc7a09c | 2011-03-15 12:26:31 +0100 | [diff] [blame] | 646 | env->thread_id = qemu_get_thread_id(); |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 647 | |
Jan Kiszka | 84b4915 | 2011-02-01 22:15:50 +0100 | [diff] [blame] | 648 | r = kvm_init_vcpu(env); |
| 649 | if (r < 0) { |
| 650 | fprintf(stderr, "kvm_init_vcpu failed: %s\n", strerror(-r)); |
| 651 | exit(1); |
| 652 | } |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 653 | |
Jan Kiszka | 55f8d6a | 2011-02-01 22:15:52 +0100 | [diff] [blame] | 654 | qemu_kvm_init_cpu_signals(env); |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 655 | |
| 656 | /* signal CPU creation */ |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 657 | env->created = 1; |
| 658 | qemu_cond_signal(&qemu_cpu_cond); |
| 659 | |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 660 | while (1) { |
Jan Kiszka | 0ab07c6 | 2011-02-07 12:19:14 +0100 | [diff] [blame] | 661 | if (cpu_can_run(env)) { |
Jan Kiszka | 6792a57 | 2011-02-07 12:19:18 +0100 | [diff] [blame] | 662 | r = kvm_cpu_exec(env); |
Jan Kiszka | 83f338f | 2011-02-07 12:19:17 +0100 | [diff] [blame] | 663 | if (r == EXCP_DEBUG) { |
Jan Kiszka | 1009d2e | 2011-03-15 12:26:13 +0100 | [diff] [blame] | 664 | cpu_handle_guest_debug(env); |
Jan Kiszka | 83f338f | 2011-02-07 12:19:17 +0100 | [diff] [blame] | 665 | } |
Jan Kiszka | 0ab07c6 | 2011-02-07 12:19:14 +0100 | [diff] [blame] | 666 | } |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 667 | qemu_kvm_wait_io_event(env); |
| 668 | } |
| 669 | |
| 670 | return NULL; |
| 671 | } |
| 672 | |
Jan Kiszka | 7e97cd8 | 2011-02-07 12:19:12 +0100 | [diff] [blame] | 673 | static void *qemu_tcg_cpu_thread_fn(void *arg) |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 674 | { |
| 675 | CPUState *env = arg; |
| 676 | |
Jan Kiszka | 55f8d6a | 2011-02-01 22:15:52 +0100 | [diff] [blame] | 677 | qemu_tcg_init_cpu_signals(); |
Jan Kiszka | b7680cb | 2011-03-12 17:43:51 +0100 | [diff] [blame] | 678 | qemu_thread_get_self(env->thread); |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 679 | |
| 680 | /* signal CPU creation */ |
| 681 | qemu_mutex_lock(&qemu_global_mutex); |
Jan Kiszka | 0ab07c6 | 2011-02-07 12:19:14 +0100 | [diff] [blame] | 682 | for (env = first_cpu; env != NULL; env = env->next_cpu) { |
Jan Kiszka | dc7a09c | 2011-03-15 12:26:31 +0100 | [diff] [blame] | 683 | env->thread_id = qemu_get_thread_id(); |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 684 | env->created = 1; |
Jan Kiszka | 0ab07c6 | 2011-02-07 12:19:14 +0100 | [diff] [blame] | 685 | } |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 686 | qemu_cond_signal(&qemu_cpu_cond); |
| 687 | |
Jan Kiszka | fa7d186 | 2011-08-22 18:35:25 +0200 | [diff] [blame] | 688 | /* wait for initial kick-off after machine start */ |
| 689 | while (first_cpu->stopped) { |
| 690 | qemu_cond_wait(tcg_halt_cond, &qemu_global_mutex); |
Jan Kiszka | 0ab07c6 | 2011-02-07 12:19:14 +0100 | [diff] [blame] | 691 | } |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 692 | |
| 693 | while (1) { |
Jan Kiszka | 472fb0c | 2010-06-25 16:56:55 +0200 | [diff] [blame] | 694 | cpu_exec_all(); |
Paolo Bonzini | cb842c9 | 2011-04-13 10:03:46 +0200 | [diff] [blame] | 695 | if (use_icount && qemu_next_icount_deadline() <= 0) { |
Paolo Bonzini | 3b2319a | 2011-04-13 10:03:43 +0200 | [diff] [blame] | 696 | qemu_notify_event(); |
| 697 | } |
Jan Kiszka | 6cabe1f | 2010-06-25 16:56:53 +0200 | [diff] [blame] | 698 | qemu_tcg_wait_io_event(); |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 699 | } |
| 700 | |
| 701 | return NULL; |
| 702 | } |
| 703 | |
Paolo Bonzini | cc015e9 | 2011-03-12 17:44:08 +0100 | [diff] [blame] | 704 | static void qemu_cpu_kick_thread(CPUState *env) |
| 705 | { |
| 706 | #ifndef _WIN32 |
| 707 | int err; |
| 708 | |
| 709 | err = pthread_kill(env->thread->thread, SIG_IPI); |
| 710 | if (err) { |
| 711 | fprintf(stderr, "qemu:%s: %s", __func__, strerror(err)); |
| 712 | exit(1); |
| 713 | } |
| 714 | #else /* _WIN32 */ |
| 715 | if (!qemu_cpu_is_self(env)) { |
| 716 | SuspendThread(env->thread->thread); |
| 717 | cpu_signal(0); |
| 718 | ResumeThread(env->thread->thread); |
| 719 | } |
| 720 | #endif |
| 721 | } |
| 722 | |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 723 | void qemu_cpu_kick(void *_env) |
| 724 | { |
| 725 | CPUState *env = _env; |
Jan Kiszka | 0ab07c6 | 2011-02-07 12:19:14 +0100 | [diff] [blame] | 726 | |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 727 | qemu_cond_broadcast(env->halt_cond); |
Jan Kiszka | eae74cf | 2011-08-22 17:46:03 +0200 | [diff] [blame] | 728 | if (kvm_enabled() && !env->thread_kicked) { |
Paolo Bonzini | cc015e9 | 2011-03-12 17:44:08 +0100 | [diff] [blame] | 729 | qemu_cpu_kick_thread(env); |
Jan Kiszka | aa2c364 | 2011-02-01 22:15:42 +0100 | [diff] [blame] | 730 | env->thread_kicked = true; |
| 731 | } |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 732 | } |
| 733 | |
Jan Kiszka | 46d62fa | 2011-02-01 22:15:59 +0100 | [diff] [blame] | 734 | void qemu_cpu_kick_self(void) |
| 735 | { |
Paolo Bonzini | b55c22c | 2011-03-12 17:44:07 +0100 | [diff] [blame] | 736 | #ifndef _WIN32 |
Jan Kiszka | 46d62fa | 2011-02-01 22:15:59 +0100 | [diff] [blame] | 737 | assert(cpu_single_env); |
| 738 | |
| 739 | if (!cpu_single_env->thread_kicked) { |
Paolo Bonzini | cc015e9 | 2011-03-12 17:44:08 +0100 | [diff] [blame] | 740 | qemu_cpu_kick_thread(cpu_single_env); |
Jan Kiszka | 46d62fa | 2011-02-01 22:15:59 +0100 | [diff] [blame] | 741 | cpu_single_env->thread_kicked = true; |
| 742 | } |
Paolo Bonzini | b55c22c | 2011-03-12 17:44:07 +0100 | [diff] [blame] | 743 | #else |
| 744 | abort(); |
| 745 | #endif |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 746 | } |
| 747 | |
Jan Kiszka | b7680cb | 2011-03-12 17:43:51 +0100 | [diff] [blame] | 748 | int qemu_cpu_is_self(void *_env) |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 749 | { |
| 750 | CPUState *env = _env; |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 751 | |
Jan Kiszka | b7680cb | 2011-03-12 17:43:51 +0100 | [diff] [blame] | 752 | return qemu_thread_is_self(env->thread); |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 753 | } |
| 754 | |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 755 | void qemu_mutex_lock_iothread(void) |
| 756 | { |
| 757 | if (kvm_enabled()) { |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 758 | qemu_mutex_lock(&qemu_global_mutex); |
Marcelo Tosatti | 1a28cac | 2010-05-04 09:45:20 -0300 | [diff] [blame] | 759 | } else { |
Paolo Bonzini | 46daff1 | 2011-06-09 13:10:24 +0200 | [diff] [blame] | 760 | iothread_requesting_mutex = true; |
Marcelo Tosatti | 1a28cac | 2010-05-04 09:45:20 -0300 | [diff] [blame] | 761 | if (qemu_mutex_trylock(&qemu_global_mutex)) { |
Paolo Bonzini | cc015e9 | 2011-03-12 17:44:08 +0100 | [diff] [blame] | 762 | qemu_cpu_kick_thread(first_cpu); |
Marcelo Tosatti | 1a28cac | 2010-05-04 09:45:20 -0300 | [diff] [blame] | 763 | qemu_mutex_lock(&qemu_global_mutex); |
| 764 | } |
Paolo Bonzini | 46daff1 | 2011-06-09 13:10:24 +0200 | [diff] [blame] | 765 | iothread_requesting_mutex = false; |
| 766 | qemu_cond_broadcast(&qemu_io_proceeded_cond); |
Marcelo Tosatti | 1a28cac | 2010-05-04 09:45:20 -0300 | [diff] [blame] | 767 | } |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 768 | } |
| 769 | |
| 770 | void qemu_mutex_unlock_iothread(void) |
| 771 | { |
| 772 | qemu_mutex_unlock(&qemu_global_mutex); |
| 773 | } |
| 774 | |
| 775 | static int all_vcpus_paused(void) |
| 776 | { |
| 777 | CPUState *penv = first_cpu; |
| 778 | |
| 779 | while (penv) { |
Jan Kiszka | 0ab07c6 | 2011-02-07 12:19:14 +0100 | [diff] [blame] | 780 | if (!penv->stopped) { |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 781 | return 0; |
Jan Kiszka | 0ab07c6 | 2011-02-07 12:19:14 +0100 | [diff] [blame] | 782 | } |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 783 | penv = (CPUState *)penv->next_cpu; |
| 784 | } |
| 785 | |
| 786 | return 1; |
| 787 | } |
| 788 | |
| 789 | void pause_all_vcpus(void) |
| 790 | { |
| 791 | CPUState *penv = first_cpu; |
| 792 | |
| 793 | while (penv) { |
| 794 | penv->stop = 1; |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 795 | qemu_cpu_kick(penv); |
| 796 | penv = (CPUState *)penv->next_cpu; |
| 797 | } |
| 798 | |
| 799 | while (!all_vcpus_paused()) { |
Paolo Bonzini | be7d6c5 | 2011-03-12 17:44:02 +0100 | [diff] [blame] | 800 | qemu_cond_wait(&qemu_pause_cond, &qemu_global_mutex); |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 801 | penv = first_cpu; |
| 802 | while (penv) { |
Marcelo Tosatti | 1fbb22e | 2010-05-04 09:45:21 -0300 | [diff] [blame] | 803 | qemu_cpu_kick(penv); |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 804 | penv = (CPUState *)penv->next_cpu; |
| 805 | } |
| 806 | } |
| 807 | } |
| 808 | |
| 809 | void resume_all_vcpus(void) |
| 810 | { |
| 811 | CPUState *penv = first_cpu; |
| 812 | |
| 813 | while (penv) { |
| 814 | penv->stop = 0; |
| 815 | penv->stopped = 0; |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 816 | qemu_cpu_kick(penv); |
| 817 | penv = (CPUState *)penv->next_cpu; |
| 818 | } |
| 819 | } |
| 820 | |
Jan Kiszka | 7e97cd8 | 2011-02-07 12:19:12 +0100 | [diff] [blame] | 821 | static void qemu_tcg_init_vcpu(void *_env) |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 822 | { |
| 823 | CPUState *env = _env; |
Jan Kiszka | 0ab07c6 | 2011-02-07 12:19:14 +0100 | [diff] [blame] | 824 | |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 825 | /* share a single thread for all cpus with TCG */ |
| 826 | if (!tcg_cpu_thread) { |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 827 | env->thread = g_malloc0(sizeof(QemuThread)); |
| 828 | env->halt_cond = g_malloc0(sizeof(QemuCond)); |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 829 | qemu_cond_init(env->halt_cond); |
Jan Kiszka | fa7d186 | 2011-08-22 18:35:25 +0200 | [diff] [blame] | 830 | tcg_halt_cond = env->halt_cond; |
Jan Kiszka | 7e97cd8 | 2011-02-07 12:19:12 +0100 | [diff] [blame] | 831 | qemu_thread_create(env->thread, qemu_tcg_cpu_thread_fn, env); |
Jan Kiszka | 0ab07c6 | 2011-02-07 12:19:14 +0100 | [diff] [blame] | 832 | while (env->created == 0) { |
Paolo Bonzini | 18a8572 | 2011-03-12 17:44:03 +0100 | [diff] [blame] | 833 | qemu_cond_wait(&qemu_cpu_cond, &qemu_global_mutex); |
Jan Kiszka | 0ab07c6 | 2011-02-07 12:19:14 +0100 | [diff] [blame] | 834 | } |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 835 | tcg_cpu_thread = env->thread; |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 836 | } else { |
| 837 | env->thread = tcg_cpu_thread; |
| 838 | env->halt_cond = tcg_halt_cond; |
| 839 | } |
| 840 | } |
| 841 | |
Jan Kiszka | 7e97cd8 | 2011-02-07 12:19:12 +0100 | [diff] [blame] | 842 | static void qemu_kvm_start_vcpu(CPUState *env) |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 843 | { |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 844 | env->thread = g_malloc0(sizeof(QemuThread)); |
| 845 | env->halt_cond = g_malloc0(sizeof(QemuCond)); |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 846 | qemu_cond_init(env->halt_cond); |
Jan Kiszka | 7e97cd8 | 2011-02-07 12:19:12 +0100 | [diff] [blame] | 847 | qemu_thread_create(env->thread, qemu_kvm_cpu_thread_fn, env); |
Jan Kiszka | 0ab07c6 | 2011-02-07 12:19:14 +0100 | [diff] [blame] | 848 | while (env->created == 0) { |
Paolo Bonzini | 18a8572 | 2011-03-12 17:44:03 +0100 | [diff] [blame] | 849 | qemu_cond_wait(&qemu_cpu_cond, &qemu_global_mutex); |
Jan Kiszka | 0ab07c6 | 2011-02-07 12:19:14 +0100 | [diff] [blame] | 850 | } |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 851 | } |
| 852 | |
| 853 | void qemu_init_vcpu(void *_env) |
| 854 | { |
| 855 | CPUState *env = _env; |
| 856 | |
| 857 | env->nr_cores = smp_cores; |
| 858 | env->nr_threads = smp_threads; |
Jan Kiszka | fa7d186 | 2011-08-22 18:35:25 +0200 | [diff] [blame] | 859 | env->stopped = 1; |
Jan Kiszka | 0ab07c6 | 2011-02-07 12:19:14 +0100 | [diff] [blame] | 860 | if (kvm_enabled()) { |
Jan Kiszka | 7e97cd8 | 2011-02-07 12:19:12 +0100 | [diff] [blame] | 861 | qemu_kvm_start_vcpu(env); |
Jan Kiszka | 0ab07c6 | 2011-02-07 12:19:14 +0100 | [diff] [blame] | 862 | } else { |
Jan Kiszka | 7e97cd8 | 2011-02-07 12:19:12 +0100 | [diff] [blame] | 863 | qemu_tcg_init_vcpu(env); |
Jan Kiszka | 0ab07c6 | 2011-02-07 12:19:14 +0100 | [diff] [blame] | 864 | } |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 865 | } |
| 866 | |
| 867 | void qemu_notify_event(void) |
| 868 | { |
| 869 | qemu_event_increment(); |
| 870 | } |
| 871 | |
Jan Kiszka | b4a3d96 | 2011-02-01 22:15:43 +0100 | [diff] [blame] | 872 | void cpu_stop_current(void) |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 873 | { |
Jan Kiszka | b4a3d96 | 2011-02-01 22:15:43 +0100 | [diff] [blame] | 874 | if (cpu_single_env) { |
Paolo Bonzini | 67bb172 | 2011-03-12 17:43:59 +0100 | [diff] [blame] | 875 | cpu_single_env->stop = 0; |
Jan Kiszka | b4a3d96 | 2011-02-01 22:15:43 +0100 | [diff] [blame] | 876 | cpu_single_env->stopped = 1; |
| 877 | cpu_exit(cpu_single_env); |
Paolo Bonzini | 67bb172 | 2011-03-12 17:43:59 +0100 | [diff] [blame] | 878 | qemu_cond_signal(&qemu_pause_cond); |
Jan Kiszka | b4a3d96 | 2011-02-01 22:15:43 +0100 | [diff] [blame] | 879 | } |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 880 | } |
| 881 | |
Luiz Capitulino | 1dfb4dd | 2011-07-29 14:26:33 -0300 | [diff] [blame] | 882 | void vm_stop(RunState state) |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 883 | { |
Jan Kiszka | b7680cb | 2011-03-12 17:43:51 +0100 | [diff] [blame] | 884 | if (!qemu_thread_is_self(&io_thread)) { |
Luiz Capitulino | 1dfb4dd | 2011-07-29 14:26:33 -0300 | [diff] [blame] | 885 | qemu_system_vmstop_request(state); |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 886 | /* |
| 887 | * FIXME: should not return to device code in case |
| 888 | * vm_stop() has been requested. |
| 889 | */ |
Jan Kiszka | b4a3d96 | 2011-02-01 22:15:43 +0100 | [diff] [blame] | 890 | cpu_stop_current(); |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 891 | return; |
| 892 | } |
Luiz Capitulino | 1dfb4dd | 2011-07-29 14:26:33 -0300 | [diff] [blame] | 893 | do_vm_stop(state); |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 894 | } |
| 895 | |
Jan Kiszka | 6792a57 | 2011-02-07 12:19:18 +0100 | [diff] [blame] | 896 | static int tcg_cpu_exec(CPUState *env) |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 897 | { |
| 898 | int ret; |
| 899 | #ifdef CONFIG_PROFILER |
| 900 | int64_t ti; |
| 901 | #endif |
| 902 | |
| 903 | #ifdef CONFIG_PROFILER |
| 904 | ti = profile_getclock(); |
| 905 | #endif |
| 906 | if (use_icount) { |
| 907 | int64_t count; |
| 908 | int decr; |
| 909 | qemu_icount -= (env->icount_decr.u16.low + env->icount_extra); |
| 910 | env->icount_decr.u16.low = 0; |
| 911 | env->icount_extra = 0; |
Paolo Bonzini | cb842c9 | 2011-04-13 10:03:46 +0200 | [diff] [blame] | 912 | count = qemu_icount_round(qemu_next_icount_deadline()); |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 913 | qemu_icount += count; |
| 914 | decr = (count > 0xffff) ? 0xffff : count; |
| 915 | count -= decr; |
| 916 | env->icount_decr.u16.low = decr; |
| 917 | env->icount_extra = count; |
| 918 | } |
| 919 | ret = cpu_exec(env); |
| 920 | #ifdef CONFIG_PROFILER |
| 921 | qemu_time += profile_getclock() - ti; |
| 922 | #endif |
| 923 | if (use_icount) { |
| 924 | /* Fold pending instructions back into the |
| 925 | instruction counter, and clear the interrupt flag. */ |
| 926 | qemu_icount -= (env->icount_decr.u16.low |
| 927 | + env->icount_extra); |
| 928 | env->icount_decr.u32 = 0; |
| 929 | env->icount_extra = 0; |
| 930 | } |
| 931 | return ret; |
| 932 | } |
| 933 | |
Jan Kiszka | 472fb0c | 2010-06-25 16:56:55 +0200 | [diff] [blame] | 934 | bool cpu_exec_all(void) |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 935 | { |
Jan Kiszka | 9a36085 | 2011-02-01 22:15:55 +0100 | [diff] [blame] | 936 | int r; |
| 937 | |
Paolo Bonzini | ab33fcd | 2011-04-13 10:03:44 +0200 | [diff] [blame] | 938 | /* Account partial waits to the vm_clock. */ |
| 939 | qemu_clock_warp(vm_clock); |
| 940 | |
Jan Kiszka | 0ab07c6 | 2011-02-07 12:19:14 +0100 | [diff] [blame] | 941 | if (next_cpu == NULL) { |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 942 | next_cpu = first_cpu; |
Jan Kiszka | 0ab07c6 | 2011-02-07 12:19:14 +0100 | [diff] [blame] | 943 | } |
Jan Kiszka | c629a4b | 2010-06-25 16:56:52 +0200 | [diff] [blame] | 944 | for (; next_cpu != NULL && !exit_request; next_cpu = next_cpu->next_cpu) { |
Jan Kiszka | 345f442 | 2010-06-25 16:56:54 +0200 | [diff] [blame] | 945 | CPUState *env = next_cpu; |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 946 | |
| 947 | qemu_clock_enable(vm_clock, |
Jan Kiszka | 345f442 | 2010-06-25 16:56:54 +0200 | [diff] [blame] | 948 | (env->singlestep_enabled & SSTEP_NOTIMER) == 0); |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 949 | |
Jan Kiszka | 3c638d0 | 2010-06-25 16:56:56 +0200 | [diff] [blame] | 950 | if (cpu_can_run(env)) { |
Jan Kiszka | 9a36085 | 2011-02-01 22:15:55 +0100 | [diff] [blame] | 951 | if (kvm_enabled()) { |
Jan Kiszka | 6792a57 | 2011-02-07 12:19:18 +0100 | [diff] [blame] | 952 | r = kvm_cpu_exec(env); |
Jan Kiszka | 9a36085 | 2011-02-01 22:15:55 +0100 | [diff] [blame] | 953 | qemu_kvm_eat_signals(env); |
Jan Kiszka | 6792a57 | 2011-02-07 12:19:18 +0100 | [diff] [blame] | 954 | } else { |
| 955 | r = tcg_cpu_exec(env); |
Jan Kiszka | 9a36085 | 2011-02-01 22:15:55 +0100 | [diff] [blame] | 956 | } |
| 957 | if (r == EXCP_DEBUG) { |
Jan Kiszka | 1009d2e | 2011-03-15 12:26:13 +0100 | [diff] [blame] | 958 | cpu_handle_guest_debug(env); |
Jan Kiszka | 3c638d0 | 2010-06-25 16:56:56 +0200 | [diff] [blame] | 959 | break; |
| 960 | } |
Paolo Bonzini | df646df | 2011-03-12 17:43:58 +0100 | [diff] [blame] | 961 | } else if (env->stop || env->stopped) { |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 962 | break; |
| 963 | } |
| 964 | } |
Jan Kiszka | c629a4b | 2010-06-25 16:56:52 +0200 | [diff] [blame] | 965 | exit_request = 0; |
Jan Kiszka | 1640032 | 2011-02-09 16:29:37 +0100 | [diff] [blame] | 966 | return !all_cpu_threads_idle(); |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 967 | } |
| 968 | |
| 969 | void set_numa_modes(void) |
| 970 | { |
| 971 | CPUState *env; |
| 972 | int i; |
| 973 | |
| 974 | for (env = first_cpu; env != NULL; env = env->next_cpu) { |
| 975 | for (i = 0; i < nb_numa_nodes; i++) { |
| 976 | if (node_cpumask[i] & (1 << env->cpu_index)) { |
| 977 | env->numa_node = i; |
| 978 | } |
| 979 | } |
| 980 | } |
| 981 | } |
| 982 | |
| 983 | void set_cpu_log(const char *optarg) |
| 984 | { |
| 985 | int mask; |
| 986 | const CPULogItem *item; |
| 987 | |
| 988 | mask = cpu_str_to_log_mask(optarg); |
| 989 | if (!mask) { |
| 990 | printf("Log items (comma separated):\n"); |
| 991 | for (item = cpu_log_items; item->mask != 0; item++) { |
| 992 | printf("%-10s %s\n", item->name, item->help); |
| 993 | } |
| 994 | exit(1); |
| 995 | } |
| 996 | cpu_set_log(mask); |
| 997 | } |
Blue Swirl | 29e922b | 2010-03-29 19:24:00 +0000 | [diff] [blame] | 998 | |
Matthew Fernandez | c235d73 | 2011-06-07 16:32:40 +0000 | [diff] [blame] | 999 | void set_cpu_log_filename(const char *optarg) |
| 1000 | { |
| 1001 | cpu_set_log_filename(optarg); |
| 1002 | } |
| 1003 | |
Blue Swirl | 29e922b | 2010-03-29 19:24:00 +0000 | [diff] [blame] | 1004 | /* Return the virtual CPU time, based on the instruction counter. */ |
| 1005 | int64_t cpu_get_icount(void) |
| 1006 | { |
| 1007 | int64_t icount; |
| 1008 | CPUState *env = cpu_single_env;; |
| 1009 | |
| 1010 | icount = qemu_icount; |
| 1011 | if (env) { |
| 1012 | if (!can_do_io(env)) { |
| 1013 | fprintf(stderr, "Bad clock read\n"); |
| 1014 | } |
| 1015 | icount -= (env->icount_decr.u16.low + env->icount_extra); |
| 1016 | } |
| 1017 | return qemu_icount_bias + (icount << icount_time_shift); |
| 1018 | } |
Blue Swirl | 262353c | 2010-05-04 19:55:35 +0000 | [diff] [blame] | 1019 | |
Stefan Weil | 9a78eea | 2010-10-22 23:03:33 +0200 | [diff] [blame] | 1020 | void list_cpus(FILE *f, fprintf_function cpu_fprintf, const char *optarg) |
Blue Swirl | 262353c | 2010-05-04 19:55:35 +0000 | [diff] [blame] | 1021 | { |
| 1022 | /* XXX: implement xxx_cpu_list for targets that still miss it */ |
| 1023 | #if defined(cpu_list_id) |
| 1024 | cpu_list_id(f, cpu_fprintf, optarg); |
| 1025 | #elif defined(cpu_list) |
| 1026 | cpu_list(f, cpu_fprintf); /* deprecated */ |
| 1027 | #endif |
| 1028 | } |