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