4 * Copyright (c) 2003-2008 Fabrice Bellard
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:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
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
25 /* Needed early for CONFIG_BSD etc. */
26 #include "config-host.h"
39 #define SIG_IPI (SIGRTMIN+4)
41 #define SIG_IPI SIGUSR1
46 #include <sys/prctl.h>
49 #define PR_MCE_KILL 33
52 #ifndef PR_MCE_KILL_SET
53 #define PR_MCE_KILL_SET 1
56 #ifndef PR_MCE_KILL_EARLY
57 #define PR_MCE_KILL_EARLY 1
60 #endif /* CONFIG_LINUX */
62 static CPUState
*next_cpu
;
64 /***********************************************************/
65 void hw_error(const char *fmt
, ...)
71 fprintf(stderr
, "qemu: hardware error: ");
72 vfprintf(stderr
, fmt
, ap
);
73 fprintf(stderr
, "\n");
74 for(env
= first_cpu
; env
!= NULL
; env
= env
->next_cpu
) {
75 fprintf(stderr
, "CPU #%d:\n", env
->cpu_index
);
77 cpu_dump_state(env
, stderr
, fprintf
, X86_DUMP_FPU
);
79 cpu_dump_state(env
, stderr
, fprintf
, 0);
86 void cpu_synchronize_all_states(void)
90 for (cpu
= first_cpu
; cpu
; cpu
= cpu
->next_cpu
) {
91 cpu_synchronize_state(cpu
);
95 void cpu_synchronize_all_post_reset(void)
99 for (cpu
= first_cpu
; cpu
; cpu
= cpu
->next_cpu
) {
100 cpu_synchronize_post_reset(cpu
);
104 void cpu_synchronize_all_post_init(void)
108 for (cpu
= first_cpu
; cpu
; cpu
= cpu
->next_cpu
) {
109 cpu_synchronize_post_init(cpu
);
113 int cpu_is_stopped(CPUState
*env
)
115 return !vm_running
|| env
->stopped
;
118 static void do_vm_stop(int reason
)
124 vm_state_notify(0, reason
);
127 monitor_protocol_event(QEVENT_STOP
, NULL
);
131 static int cpu_can_run(CPUState
*env
)
136 if (env
->stopped
|| !vm_running
) {
142 static bool cpu_thread_is_idle(CPUState
*env
)
144 if (env
->stop
|| env
->queued_work_first
) {
147 if (env
->stopped
|| !vm_running
) {
150 if (!env
->halted
|| qemu_cpu_has_work(env
)) {
156 static bool all_cpu_threads_idle(void)
160 for (env
= first_cpu
; env
!= NULL
; env
= env
->next_cpu
) {
161 if (!cpu_thread_is_idle(env
)) {
168 static void cpu_debug_handler(CPUState
*env
)
170 gdb_set_stop_cpu(env
);
171 debug_requested
= EXCP_DEBUG
;
176 static void sigbus_reraise(void)
179 struct sigaction action
;
181 memset(&action
, 0, sizeof(action
));
182 action
.sa_handler
= SIG_DFL
;
183 if (!sigaction(SIGBUS
, &action
, NULL
)) {
186 sigaddset(&set
, SIGBUS
);
187 sigprocmask(SIG_UNBLOCK
, &set
, NULL
);
189 perror("Failed to re-raise SIGBUS!\n");
193 static void sigbus_handler(int n
, struct qemu_signalfd_siginfo
*siginfo
,
196 if (kvm_on_sigbus(siginfo
->ssi_code
,
197 (void *)(intptr_t)siginfo
->ssi_addr
)) {
202 static void qemu_init_sigbus(void)
204 struct sigaction action
;
206 memset(&action
, 0, sizeof(action
));
207 action
.sa_flags
= SA_SIGINFO
;
208 action
.sa_sigaction
= (void (*)(int, siginfo_t
*, void*))sigbus_handler
;
209 sigaction(SIGBUS
, &action
, NULL
);
211 prctl(PR_MCE_KILL
, PR_MCE_KILL_SET
, PR_MCE_KILL_EARLY
, 0, 0);
214 #else /* !CONFIG_LINUX */
216 static void qemu_init_sigbus(void)
219 #endif /* !CONFIG_LINUX */
222 static int io_thread_fd
= -1;
224 static void qemu_event_increment(void)
226 /* Write 8 bytes to be compatible with eventfd. */
227 static const uint64_t val
= 1;
230 if (io_thread_fd
== -1) {
234 ret
= write(io_thread_fd
, &val
, sizeof(val
));
235 } while (ret
< 0 && errno
== EINTR
);
237 /* EAGAIN is fine, a read must be pending. */
238 if (ret
< 0 && errno
!= EAGAIN
) {
239 fprintf(stderr
, "qemu_event_increment: write() filed: %s\n",
245 static void qemu_event_read(void *opaque
)
247 int fd
= (unsigned long)opaque
;
251 /* Drain the notify pipe. For eventfd, only 8 bytes will be read. */
253 len
= read(fd
, buffer
, sizeof(buffer
));
254 } while ((len
== -1 && errno
== EINTR
) || len
== sizeof(buffer
));
257 static int qemu_event_init(void)
262 err
= qemu_eventfd(fds
);
266 err
= fcntl_setfl(fds
[0], O_NONBLOCK
);
270 err
= fcntl_setfl(fds
[1], O_NONBLOCK
);
274 qemu_set_fd_handler2(fds
[0], NULL
, qemu_event_read
, NULL
,
275 (void *)(unsigned long)fds
[0]);
277 io_thread_fd
= fds
[1];
286 static void dummy_signal(int sig
)
290 /* If we have signalfd, we mask out the signals we want to handle and then
291 * use signalfd to listen for them. We rely on whatever the current signal
292 * handler is to dispatch the signals when we receive them.
294 static void sigfd_handler(void *opaque
)
296 int fd
= (unsigned long) opaque
;
297 struct qemu_signalfd_siginfo info
;
298 struct sigaction action
;
303 len
= read(fd
, &info
, sizeof(info
));
304 } while (len
== -1 && errno
== EINTR
);
306 if (len
== -1 && errno
== EAGAIN
) {
310 if (len
!= sizeof(info
)) {
311 printf("read from sigfd returned %zd: %m\n", len
);
315 sigaction(info
.ssi_signo
, NULL
, &action
);
316 if ((action
.sa_flags
& SA_SIGINFO
) && action
.sa_sigaction
) {
317 action
.sa_sigaction(info
.ssi_signo
,
318 (siginfo_t
*)&info
, NULL
);
319 } else if (action
.sa_handler
) {
320 action
.sa_handler(info
.ssi_signo
);
325 static int qemu_signalfd_init(sigset_t mask
)
329 sigfd
= qemu_signalfd(&mask
);
331 fprintf(stderr
, "failed to create signalfd\n");
335 fcntl_setfl(sigfd
, O_NONBLOCK
);
337 qemu_set_fd_handler2(sigfd
, NULL
, sigfd_handler
, NULL
,
338 (void *)(unsigned long) sigfd
);
343 static void qemu_kvm_eat_signals(CPUState
*env
)
345 struct timespec ts
= { 0, 0 };
351 sigemptyset(&waitset
);
352 sigaddset(&waitset
, SIG_IPI
);
353 sigaddset(&waitset
, SIGBUS
);
356 r
= sigtimedwait(&waitset
, &siginfo
, &ts
);
357 if (r
== -1 && !(errno
== EAGAIN
|| errno
== EINTR
)) {
358 perror("sigtimedwait");
364 if (kvm_on_sigbus_vcpu(env
, siginfo
.si_code
, siginfo
.si_addr
)) {
372 r
= sigpending(&chkset
);
374 perror("sigpending");
377 } while (sigismember(&chkset
, SIG_IPI
) || sigismember(&chkset
, SIGBUS
));
379 #ifndef CONFIG_IOTHREAD
380 if (sigismember(&chkset
, SIGIO
) || sigismember(&chkset
, SIGALRM
)) {
388 HANDLE qemu_event_handle
;
390 static void dummy_event_handler(void *opaque
)
394 static int qemu_event_init(void)
396 qemu_event_handle
= CreateEvent(NULL
, FALSE
, FALSE
, NULL
);
397 if (!qemu_event_handle
) {
398 fprintf(stderr
, "Failed CreateEvent: %ld\n", GetLastError());
401 qemu_add_wait_object(qemu_event_handle
, dummy_event_handler
, NULL
);
405 static void qemu_event_increment(void)
407 if (!SetEvent(qemu_event_handle
)) {
408 fprintf(stderr
, "qemu_event_increment: SetEvent failed: %ld\n",
414 static void qemu_kvm_eat_signals(CPUState
*env
)
419 #ifndef CONFIG_IOTHREAD
420 static void qemu_kvm_init_cpu_signals(CPUState
*env
)
425 struct sigaction sigact
;
427 memset(&sigact
, 0, sizeof(sigact
));
428 sigact
.sa_handler
= dummy_signal
;
429 sigaction(SIG_IPI
, &sigact
, NULL
);
432 sigaddset(&set
, SIG_IPI
);
433 sigaddset(&set
, SIGIO
);
434 sigaddset(&set
, SIGALRM
);
435 pthread_sigmask(SIG_BLOCK
, &set
, NULL
);
437 pthread_sigmask(SIG_BLOCK
, NULL
, &set
);
438 sigdelset(&set
, SIG_IPI
);
439 sigdelset(&set
, SIGBUS
);
440 sigdelset(&set
, SIGIO
);
441 sigdelset(&set
, SIGALRM
);
442 r
= kvm_set_signal_mask(env
, &set
);
444 fprintf(stderr
, "kvm_set_signal_mask: %s\n", strerror(-r
));
451 static sigset_t
block_synchronous_signals(void)
456 sigaddset(&set
, SIGBUS
);
459 * We need to process timer signals synchronously to avoid a race
460 * between exit_request check and KVM vcpu entry.
462 sigaddset(&set
, SIGIO
);
463 sigaddset(&set
, SIGALRM
);
470 int qemu_init_main_loop(void)
473 sigset_t blocked_signals
;
476 blocked_signals
= block_synchronous_signals();
478 ret
= qemu_signalfd_init(blocked_signals
);
483 cpu_set_debug_excp_handler(cpu_debug_handler
);
487 return qemu_event_init();
490 void qemu_main_loop_start(void)
494 void qemu_init_vcpu(void *_env
)
496 CPUState
*env
= _env
;
499 env
->nr_cores
= smp_cores
;
500 env
->nr_threads
= smp_threads
;
503 r
= kvm_init_vcpu(env
);
505 fprintf(stderr
, "kvm_init_vcpu failed: %s\n", strerror(-r
));
508 qemu_kvm_init_cpu_signals(env
);
512 int qemu_cpu_self(void *env
)
517 void run_on_cpu(CPUState
*env
, void (*func
)(void *data
), void *data
)
522 void resume_all_vcpus(void)
526 void pause_all_vcpus(void)
530 void qemu_cpu_kick(void *env
)
534 void qemu_cpu_kick_self(void)
537 assert(cpu_single_env
);
545 void qemu_notify_event(void)
547 CPUState
*env
= cpu_single_env
;
549 qemu_event_increment ();
553 if (next_cpu
&& env
!= next_cpu
) {
559 void qemu_mutex_lock_iothread(void) {}
560 void qemu_mutex_unlock_iothread(void) {}
562 void cpu_stop_current(void)
566 void vm_stop(int reason
)
571 #else /* CONFIG_IOTHREAD */
573 #include "qemu-thread.h"
575 QemuMutex qemu_global_mutex
;
576 static QemuMutex qemu_fair_mutex
;
578 static QemuThread io_thread
;
580 static QemuThread
*tcg_cpu_thread
;
581 static QemuCond
*tcg_halt_cond
;
583 static int qemu_system_ready
;
585 static QemuCond qemu_cpu_cond
;
587 static QemuCond qemu_system_cond
;
588 static QemuCond qemu_pause_cond
;
589 static QemuCond qemu_work_cond
;
591 static void cpu_signal(int sig
)
593 if (cpu_single_env
) {
594 cpu_exit(cpu_single_env
);
599 static void qemu_kvm_init_cpu_signals(CPUState
*env
)
603 struct sigaction sigact
;
605 memset(&sigact
, 0, sizeof(sigact
));
606 sigact
.sa_handler
= dummy_signal
;
607 sigaction(SIG_IPI
, &sigact
, NULL
);
609 pthread_sigmask(SIG_BLOCK
, NULL
, &set
);
610 sigdelset(&set
, SIG_IPI
);
611 sigdelset(&set
, SIGBUS
);
612 r
= kvm_set_signal_mask(env
, &set
);
614 fprintf(stderr
, "kvm_set_signal_mask: %s\n", strerror(-r
));
619 static void qemu_tcg_init_cpu_signals(void)
622 struct sigaction sigact
;
624 memset(&sigact
, 0, sizeof(sigact
));
625 sigact
.sa_handler
= cpu_signal
;
626 sigaction(SIG_IPI
, &sigact
, NULL
);
629 sigaddset(&set
, SIG_IPI
);
630 pthread_sigmask(SIG_UNBLOCK
, &set
, NULL
);
633 static sigset_t
block_io_signals(void)
637 /* SIGUSR2 used by posix-aio-compat.c */
639 sigaddset(&set
, SIGUSR2
);
640 pthread_sigmask(SIG_UNBLOCK
, &set
, NULL
);
643 sigaddset(&set
, SIGIO
);
644 sigaddset(&set
, SIGALRM
);
645 sigaddset(&set
, SIG_IPI
);
646 sigaddset(&set
, SIGBUS
);
647 pthread_sigmask(SIG_BLOCK
, &set
, NULL
);
652 int qemu_init_main_loop(void)
655 sigset_t blocked_signals
;
657 cpu_set_debug_excp_handler(cpu_debug_handler
);
661 blocked_signals
= block_io_signals();
663 ret
= qemu_signalfd_init(blocked_signals
);
668 /* Note eventfd must be drained before signalfd handlers run */
669 ret
= qemu_event_init();
674 qemu_cond_init(&qemu_pause_cond
);
675 qemu_cond_init(&qemu_system_cond
);
676 qemu_mutex_init(&qemu_fair_mutex
);
677 qemu_mutex_init(&qemu_global_mutex
);
678 qemu_mutex_lock(&qemu_global_mutex
);
680 qemu_thread_self(&io_thread
);
685 void qemu_main_loop_start(void)
687 qemu_system_ready
= 1;
688 qemu_cond_broadcast(&qemu_system_cond
);
691 void run_on_cpu(CPUState
*env
, void (*func
)(void *data
), void *data
)
693 struct qemu_work_item wi
;
695 if (qemu_cpu_self(env
)) {
702 if (!env
->queued_work_first
) {
703 env
->queued_work_first
= &wi
;
705 env
->queued_work_last
->next
= &wi
;
707 env
->queued_work_last
= &wi
;
713 CPUState
*self_env
= cpu_single_env
;
715 qemu_cond_wait(&qemu_work_cond
, &qemu_global_mutex
);
716 cpu_single_env
= self_env
;
720 static void flush_queued_work(CPUState
*env
)
722 struct qemu_work_item
*wi
;
724 if (!env
->queued_work_first
) {
728 while ((wi
= env
->queued_work_first
)) {
729 env
->queued_work_first
= wi
->next
;
733 env
->queued_work_last
= NULL
;
734 qemu_cond_broadcast(&qemu_work_cond
);
737 static void qemu_wait_io_event_common(CPUState
*env
)
742 qemu_cond_signal(&qemu_pause_cond
);
744 flush_queued_work(env
);
745 env
->thread_kicked
= false;
748 static void qemu_tcg_wait_io_event(void)
752 while (all_cpu_threads_idle()) {
753 qemu_cond_timedwait(tcg_halt_cond
, &qemu_global_mutex
, 1000);
756 qemu_mutex_unlock(&qemu_global_mutex
);
759 * Users of qemu_global_mutex can be starved, having no chance
760 * to acquire it since this path will get to it first.
761 * So use another lock to provide fairness.
763 qemu_mutex_lock(&qemu_fair_mutex
);
764 qemu_mutex_unlock(&qemu_fair_mutex
);
766 qemu_mutex_lock(&qemu_global_mutex
);
768 for (env
= first_cpu
; env
!= NULL
; env
= env
->next_cpu
) {
769 qemu_wait_io_event_common(env
);
773 static void qemu_kvm_wait_io_event(CPUState
*env
)
775 while (cpu_thread_is_idle(env
)) {
776 qemu_cond_timedwait(env
->halt_cond
, &qemu_global_mutex
, 1000);
779 qemu_kvm_eat_signals(env
);
780 qemu_wait_io_event_common(env
);
783 static int qemu_cpu_exec(CPUState
*env
);
785 static void *qemu_kvm_cpu_thread_fn(void *arg
)
790 qemu_mutex_lock(&qemu_global_mutex
);
791 qemu_thread_self(env
->thread
);
793 r
= kvm_init_vcpu(env
);
795 fprintf(stderr
, "kvm_init_vcpu failed: %s\n", strerror(-r
));
799 qemu_kvm_init_cpu_signals(env
);
801 /* signal CPU creation */
803 qemu_cond_signal(&qemu_cpu_cond
);
805 /* and wait for machine initialization */
806 while (!qemu_system_ready
) {
807 qemu_cond_timedwait(&qemu_system_cond
, &qemu_global_mutex
, 100);
811 if (cpu_can_run(env
)) {
814 qemu_kvm_wait_io_event(env
);
820 static void *qemu_tcg_cpu_thread_fn(void *arg
)
824 qemu_tcg_init_cpu_signals();
825 qemu_thread_self(env
->thread
);
827 /* signal CPU creation */
828 qemu_mutex_lock(&qemu_global_mutex
);
829 for (env
= first_cpu
; env
!= NULL
; env
= env
->next_cpu
) {
832 qemu_cond_signal(&qemu_cpu_cond
);
834 /* and wait for machine initialization */
835 while (!qemu_system_ready
) {
836 qemu_cond_timedwait(&qemu_system_cond
, &qemu_global_mutex
, 100);
841 qemu_tcg_wait_io_event();
847 void qemu_cpu_kick(void *_env
)
849 CPUState
*env
= _env
;
851 qemu_cond_broadcast(env
->halt_cond
);
852 if (!env
->thread_kicked
) {
853 qemu_thread_signal(env
->thread
, SIG_IPI
);
854 env
->thread_kicked
= true;
858 void qemu_cpu_kick_self(void)
860 assert(cpu_single_env
);
862 if (!cpu_single_env
->thread_kicked
) {
863 qemu_thread_signal(cpu_single_env
->thread
, SIG_IPI
);
864 cpu_single_env
->thread_kicked
= true;
868 int qemu_cpu_self(void *_env
)
870 CPUState
*env
= _env
;
873 qemu_thread_self(&this);
875 return qemu_thread_equal(&this, env
->thread
);
878 void qemu_mutex_lock_iothread(void)
881 qemu_mutex_lock(&qemu_global_mutex
);
883 qemu_mutex_lock(&qemu_fair_mutex
);
884 if (qemu_mutex_trylock(&qemu_global_mutex
)) {
885 qemu_thread_signal(tcg_cpu_thread
, SIG_IPI
);
886 qemu_mutex_lock(&qemu_global_mutex
);
888 qemu_mutex_unlock(&qemu_fair_mutex
);
892 void qemu_mutex_unlock_iothread(void)
894 qemu_mutex_unlock(&qemu_global_mutex
);
897 static int all_vcpus_paused(void)
899 CPUState
*penv
= first_cpu
;
902 if (!penv
->stopped
) {
905 penv
= (CPUState
*)penv
->next_cpu
;
911 void pause_all_vcpus(void)
913 CPUState
*penv
= first_cpu
;
918 penv
= (CPUState
*)penv
->next_cpu
;
921 while (!all_vcpus_paused()) {
922 qemu_cond_timedwait(&qemu_pause_cond
, &qemu_global_mutex
, 100);
926 penv
= (CPUState
*)penv
->next_cpu
;
931 void resume_all_vcpus(void)
933 CPUState
*penv
= first_cpu
;
939 penv
= (CPUState
*)penv
->next_cpu
;
943 static void qemu_tcg_init_vcpu(void *_env
)
945 CPUState
*env
= _env
;
947 /* share a single thread for all cpus with TCG */
948 if (!tcg_cpu_thread
) {
949 env
->thread
= qemu_mallocz(sizeof(QemuThread
));
950 env
->halt_cond
= qemu_mallocz(sizeof(QemuCond
));
951 qemu_cond_init(env
->halt_cond
);
952 qemu_thread_create(env
->thread
, qemu_tcg_cpu_thread_fn
, env
);
953 while (env
->created
== 0) {
954 qemu_cond_timedwait(&qemu_cpu_cond
, &qemu_global_mutex
, 100);
956 tcg_cpu_thread
= env
->thread
;
957 tcg_halt_cond
= env
->halt_cond
;
959 env
->thread
= tcg_cpu_thread
;
960 env
->halt_cond
= tcg_halt_cond
;
964 static void qemu_kvm_start_vcpu(CPUState
*env
)
966 env
->thread
= qemu_mallocz(sizeof(QemuThread
));
967 env
->halt_cond
= qemu_mallocz(sizeof(QemuCond
));
968 qemu_cond_init(env
->halt_cond
);
969 qemu_thread_create(env
->thread
, qemu_kvm_cpu_thread_fn
, env
);
970 while (env
->created
== 0) {
971 qemu_cond_timedwait(&qemu_cpu_cond
, &qemu_global_mutex
, 100);
975 void qemu_init_vcpu(void *_env
)
977 CPUState
*env
= _env
;
979 env
->nr_cores
= smp_cores
;
980 env
->nr_threads
= smp_threads
;
982 qemu_kvm_start_vcpu(env
);
984 qemu_tcg_init_vcpu(env
);
988 void qemu_notify_event(void)
990 qemu_event_increment();
993 static void qemu_system_vmstop_request(int reason
)
995 vmstop_requested
= reason
;
999 void cpu_stop_current(void)
1001 if (cpu_single_env
) {
1002 cpu_single_env
->stopped
= 1;
1003 cpu_exit(cpu_single_env
);
1007 void vm_stop(int reason
)
1010 qemu_thread_self(&me
);
1012 if (!qemu_thread_equal(&me
, &io_thread
)) {
1013 qemu_system_vmstop_request(reason
);
1015 * FIXME: should not return to device code in case
1016 * vm_stop() has been requested.
1026 static int qemu_cpu_exec(CPUState
*env
)
1029 #ifdef CONFIG_PROFILER
1033 #ifdef CONFIG_PROFILER
1034 ti
= profile_getclock();
1039 qemu_icount
-= (env
->icount_decr
.u16
.low
+ env
->icount_extra
);
1040 env
->icount_decr
.u16
.low
= 0;
1041 env
->icount_extra
= 0;
1042 count
= qemu_icount_round (qemu_next_deadline());
1043 qemu_icount
+= count
;
1044 decr
= (count
> 0xffff) ? 0xffff : count
;
1046 env
->icount_decr
.u16
.low
= decr
;
1047 env
->icount_extra
= count
;
1049 ret
= cpu_exec(env
);
1050 #ifdef CONFIG_PROFILER
1051 qemu_time
+= profile_getclock() - ti
;
1054 /* Fold pending instructions back into the
1055 instruction counter, and clear the interrupt flag. */
1056 qemu_icount
-= (env
->icount_decr
.u16
.low
1057 + env
->icount_extra
);
1058 env
->icount_decr
.u32
= 0;
1059 env
->icount_extra
= 0;
1064 bool cpu_exec_all(void)
1068 if (next_cpu
== NULL
) {
1069 next_cpu
= first_cpu
;
1071 for (; next_cpu
!= NULL
&& !exit_request
; next_cpu
= next_cpu
->next_cpu
) {
1072 CPUState
*env
= next_cpu
;
1074 qemu_clock_enable(vm_clock
,
1075 (env
->singlestep_enabled
& SSTEP_NOTIMER
) == 0);
1077 if (qemu_alarm_pending()) {
1080 if (cpu_can_run(env
)) {
1081 r
= qemu_cpu_exec(env
);
1082 if (kvm_enabled()) {
1083 qemu_kvm_eat_signals(env
);
1085 if (r
== EXCP_DEBUG
) {
1088 } else if (env
->stop
) {
1093 return !all_cpu_threads_idle();
1096 void set_numa_modes(void)
1101 for (env
= first_cpu
; env
!= NULL
; env
= env
->next_cpu
) {
1102 for (i
= 0; i
< nb_numa_nodes
; i
++) {
1103 if (node_cpumask
[i
] & (1 << env
->cpu_index
)) {
1110 void set_cpu_log(const char *optarg
)
1113 const CPULogItem
*item
;
1115 mask
= cpu_str_to_log_mask(optarg
);
1117 printf("Log items (comma separated):\n");
1118 for (item
= cpu_log_items
; item
->mask
!= 0; item
++) {
1119 printf("%-10s %s\n", item
->name
, item
->help
);
1126 /* Return the virtual CPU time, based on the instruction counter. */
1127 int64_t cpu_get_icount(void)
1130 CPUState
*env
= cpu_single_env
;;
1132 icount
= qemu_icount
;
1134 if (!can_do_io(env
)) {
1135 fprintf(stderr
, "Bad clock read\n");
1137 icount
-= (env
->icount_decr
.u16
.low
+ env
->icount_extra
);
1139 return qemu_icount_bias
+ (icount
<< icount_time_shift
);
1142 void list_cpus(FILE *f
, fprintf_function cpu_fprintf
, const char *optarg
)
1144 /* XXX: implement xxx_cpu_list for targets that still miss it */
1145 #if defined(cpu_list_id)
1146 cpu_list_id(f
, cpu_fprintf
, optarg
);
1147 #elif defined(cpu_list)
1148 cpu_list(f
, cpu_fprintf
); /* deprecated */