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 qemu_system_debug_request();
175 static void sigbus_reraise(void)
178 struct sigaction action
;
180 memset(&action
, 0, sizeof(action
));
181 action
.sa_handler
= SIG_DFL
;
182 if (!sigaction(SIGBUS
, &action
, NULL
)) {
185 sigaddset(&set
, SIGBUS
);
186 sigprocmask(SIG_UNBLOCK
, &set
, NULL
);
188 perror("Failed to re-raise SIGBUS!\n");
192 static void sigbus_handler(int n
, struct qemu_signalfd_siginfo
*siginfo
,
195 if (kvm_on_sigbus(siginfo
->ssi_code
,
196 (void *)(intptr_t)siginfo
->ssi_addr
)) {
201 static void qemu_init_sigbus(void)
203 struct sigaction action
;
205 memset(&action
, 0, sizeof(action
));
206 action
.sa_flags
= SA_SIGINFO
;
207 action
.sa_sigaction
= (void (*)(int, siginfo_t
*, void*))sigbus_handler
;
208 sigaction(SIGBUS
, &action
, NULL
);
210 prctl(PR_MCE_KILL
, PR_MCE_KILL_SET
, PR_MCE_KILL_EARLY
, 0, 0);
213 #else /* !CONFIG_LINUX */
215 static void qemu_init_sigbus(void)
218 #endif /* !CONFIG_LINUX */
221 static int io_thread_fd
= -1;
223 static void qemu_event_increment(void)
225 /* Write 8 bytes to be compatible with eventfd. */
226 static const uint64_t val
= 1;
229 if (io_thread_fd
== -1) {
233 ret
= write(io_thread_fd
, &val
, sizeof(val
));
234 } while (ret
< 0 && errno
== EINTR
);
236 /* EAGAIN is fine, a read must be pending. */
237 if (ret
< 0 && errno
!= EAGAIN
) {
238 fprintf(stderr
, "qemu_event_increment: write() filed: %s\n",
244 static void qemu_event_read(void *opaque
)
246 int fd
= (unsigned long)opaque
;
250 /* Drain the notify pipe. For eventfd, only 8 bytes will be read. */
252 len
= read(fd
, buffer
, sizeof(buffer
));
253 } while ((len
== -1 && errno
== EINTR
) || len
== sizeof(buffer
));
256 static int qemu_event_init(void)
261 err
= qemu_eventfd(fds
);
265 err
= fcntl_setfl(fds
[0], O_NONBLOCK
);
269 err
= fcntl_setfl(fds
[1], O_NONBLOCK
);
273 qemu_set_fd_handler2(fds
[0], NULL
, qemu_event_read
, NULL
,
274 (void *)(unsigned long)fds
[0]);
276 io_thread_fd
= fds
[1];
285 static void dummy_signal(int sig
)
289 /* If we have signalfd, we mask out the signals we want to handle and then
290 * use signalfd to listen for them. We rely on whatever the current signal
291 * handler is to dispatch the signals when we receive them.
293 static void sigfd_handler(void *opaque
)
295 int fd
= (unsigned long) opaque
;
296 struct qemu_signalfd_siginfo info
;
297 struct sigaction action
;
302 len
= read(fd
, &info
, sizeof(info
));
303 } while (len
== -1 && errno
== EINTR
);
305 if (len
== -1 && errno
== EAGAIN
) {
309 if (len
!= sizeof(info
)) {
310 printf("read from sigfd returned %zd: %m\n", len
);
314 sigaction(info
.ssi_signo
, NULL
, &action
);
315 if ((action
.sa_flags
& SA_SIGINFO
) && action
.sa_sigaction
) {
316 action
.sa_sigaction(info
.ssi_signo
,
317 (siginfo_t
*)&info
, NULL
);
318 } else if (action
.sa_handler
) {
319 action
.sa_handler(info
.ssi_signo
);
324 static int qemu_signalfd_init(sigset_t mask
)
328 sigfd
= qemu_signalfd(&mask
);
330 fprintf(stderr
, "failed to create signalfd\n");
334 fcntl_setfl(sigfd
, O_NONBLOCK
);
336 qemu_set_fd_handler2(sigfd
, NULL
, sigfd_handler
, NULL
,
337 (void *)(unsigned long) sigfd
);
342 static void qemu_kvm_eat_signals(CPUState
*env
)
344 struct timespec ts
= { 0, 0 };
350 sigemptyset(&waitset
);
351 sigaddset(&waitset
, SIG_IPI
);
352 sigaddset(&waitset
, SIGBUS
);
355 r
= sigtimedwait(&waitset
, &siginfo
, &ts
);
356 if (r
== -1 && !(errno
== EAGAIN
|| errno
== EINTR
)) {
357 perror("sigtimedwait");
363 if (kvm_on_sigbus_vcpu(env
, siginfo
.si_code
, siginfo
.si_addr
)) {
371 r
= sigpending(&chkset
);
373 perror("sigpending");
376 } while (sigismember(&chkset
, SIG_IPI
) || sigismember(&chkset
, SIGBUS
));
378 #ifndef CONFIG_IOTHREAD
379 if (sigismember(&chkset
, SIGIO
) || sigismember(&chkset
, SIGALRM
)) {
387 HANDLE qemu_event_handle
;
389 static void dummy_event_handler(void *opaque
)
393 static int qemu_event_init(void)
395 qemu_event_handle
= CreateEvent(NULL
, FALSE
, FALSE
, NULL
);
396 if (!qemu_event_handle
) {
397 fprintf(stderr
, "Failed CreateEvent: %ld\n", GetLastError());
400 qemu_add_wait_object(qemu_event_handle
, dummy_event_handler
, NULL
);
404 static void qemu_event_increment(void)
406 if (!SetEvent(qemu_event_handle
)) {
407 fprintf(stderr
, "qemu_event_increment: SetEvent failed: %ld\n",
413 static void qemu_kvm_eat_signals(CPUState
*env
)
418 #ifndef CONFIG_IOTHREAD
419 static void qemu_kvm_init_cpu_signals(CPUState
*env
)
424 struct sigaction sigact
;
426 memset(&sigact
, 0, sizeof(sigact
));
427 sigact
.sa_handler
= dummy_signal
;
428 sigaction(SIG_IPI
, &sigact
, NULL
);
431 sigaddset(&set
, SIG_IPI
);
432 sigaddset(&set
, SIGIO
);
433 sigaddset(&set
, SIGALRM
);
434 pthread_sigmask(SIG_BLOCK
, &set
, NULL
);
436 pthread_sigmask(SIG_BLOCK
, NULL
, &set
);
437 sigdelset(&set
, SIG_IPI
);
438 sigdelset(&set
, SIGBUS
);
439 sigdelset(&set
, SIGIO
);
440 sigdelset(&set
, SIGALRM
);
441 r
= kvm_set_signal_mask(env
, &set
);
443 fprintf(stderr
, "kvm_set_signal_mask: %s\n", strerror(-r
));
450 static sigset_t
block_synchronous_signals(void)
455 sigaddset(&set
, SIGBUS
);
458 * We need to process timer signals synchronously to avoid a race
459 * between exit_request check and KVM vcpu entry.
461 sigaddset(&set
, SIGIO
);
462 sigaddset(&set
, SIGALRM
);
469 int qemu_init_main_loop(void)
472 sigset_t blocked_signals
;
475 blocked_signals
= block_synchronous_signals();
477 ret
= qemu_signalfd_init(blocked_signals
);
482 cpu_set_debug_excp_handler(cpu_debug_handler
);
486 return qemu_event_init();
489 void qemu_main_loop_start(void)
493 void qemu_init_vcpu(void *_env
)
495 CPUState
*env
= _env
;
498 env
->nr_cores
= smp_cores
;
499 env
->nr_threads
= smp_threads
;
502 r
= kvm_init_vcpu(env
);
504 fprintf(stderr
, "kvm_init_vcpu failed: %s\n", strerror(-r
));
507 qemu_kvm_init_cpu_signals(env
);
511 int qemu_cpu_self(void *env
)
516 void run_on_cpu(CPUState
*env
, void (*func
)(void *data
), void *data
)
521 void resume_all_vcpus(void)
525 void pause_all_vcpus(void)
529 void qemu_cpu_kick(void *env
)
533 void qemu_cpu_kick_self(void)
536 assert(cpu_single_env
);
544 void qemu_notify_event(void)
546 CPUState
*env
= cpu_single_env
;
548 qemu_event_increment ();
552 if (next_cpu
&& env
!= next_cpu
) {
558 void qemu_mutex_lock_iothread(void) {}
559 void qemu_mutex_unlock_iothread(void) {}
561 void cpu_stop_current(void)
565 void vm_stop(int reason
)
570 #else /* CONFIG_IOTHREAD */
572 #include "qemu-thread.h"
574 QemuMutex qemu_global_mutex
;
575 static QemuMutex qemu_fair_mutex
;
577 static QemuThread io_thread
;
579 static QemuThread
*tcg_cpu_thread
;
580 static QemuCond
*tcg_halt_cond
;
582 static int qemu_system_ready
;
584 static QemuCond qemu_cpu_cond
;
586 static QemuCond qemu_system_cond
;
587 static QemuCond qemu_pause_cond
;
588 static QemuCond qemu_work_cond
;
590 static void cpu_signal(int sig
)
592 if (cpu_single_env
) {
593 cpu_exit(cpu_single_env
);
598 static void qemu_kvm_init_cpu_signals(CPUState
*env
)
602 struct sigaction sigact
;
604 memset(&sigact
, 0, sizeof(sigact
));
605 sigact
.sa_handler
= dummy_signal
;
606 sigaction(SIG_IPI
, &sigact
, NULL
);
608 pthread_sigmask(SIG_BLOCK
, NULL
, &set
);
609 sigdelset(&set
, SIG_IPI
);
610 sigdelset(&set
, SIGBUS
);
611 r
= kvm_set_signal_mask(env
, &set
);
613 fprintf(stderr
, "kvm_set_signal_mask: %s\n", strerror(-r
));
618 static void qemu_tcg_init_cpu_signals(void)
621 struct sigaction sigact
;
623 memset(&sigact
, 0, sizeof(sigact
));
624 sigact
.sa_handler
= cpu_signal
;
625 sigaction(SIG_IPI
, &sigact
, NULL
);
628 sigaddset(&set
, SIG_IPI
);
629 pthread_sigmask(SIG_UNBLOCK
, &set
, NULL
);
632 static sigset_t
block_io_signals(void)
636 /* SIGUSR2 used by posix-aio-compat.c */
638 sigaddset(&set
, SIGUSR2
);
639 pthread_sigmask(SIG_UNBLOCK
, &set
, NULL
);
642 sigaddset(&set
, SIGIO
);
643 sigaddset(&set
, SIGALRM
);
644 sigaddset(&set
, SIG_IPI
);
645 sigaddset(&set
, SIGBUS
);
646 pthread_sigmask(SIG_BLOCK
, &set
, NULL
);
651 int qemu_init_main_loop(void)
654 sigset_t blocked_signals
;
656 cpu_set_debug_excp_handler(cpu_debug_handler
);
660 blocked_signals
= block_io_signals();
662 ret
= qemu_signalfd_init(blocked_signals
);
667 /* Note eventfd must be drained before signalfd handlers run */
668 ret
= qemu_event_init();
673 qemu_cond_init(&qemu_pause_cond
);
674 qemu_cond_init(&qemu_system_cond
);
675 qemu_mutex_init(&qemu_fair_mutex
);
676 qemu_mutex_init(&qemu_global_mutex
);
677 qemu_mutex_lock(&qemu_global_mutex
);
679 qemu_thread_self(&io_thread
);
684 void qemu_main_loop_start(void)
686 qemu_system_ready
= 1;
687 qemu_cond_broadcast(&qemu_system_cond
);
690 void run_on_cpu(CPUState
*env
, void (*func
)(void *data
), void *data
)
692 struct qemu_work_item wi
;
694 if (qemu_cpu_self(env
)) {
701 if (!env
->queued_work_first
) {
702 env
->queued_work_first
= &wi
;
704 env
->queued_work_last
->next
= &wi
;
706 env
->queued_work_last
= &wi
;
712 CPUState
*self_env
= cpu_single_env
;
714 qemu_cond_wait(&qemu_work_cond
, &qemu_global_mutex
);
715 cpu_single_env
= self_env
;
719 static void flush_queued_work(CPUState
*env
)
721 struct qemu_work_item
*wi
;
723 if (!env
->queued_work_first
) {
727 while ((wi
= env
->queued_work_first
)) {
728 env
->queued_work_first
= wi
->next
;
732 env
->queued_work_last
= NULL
;
733 qemu_cond_broadcast(&qemu_work_cond
);
736 static void qemu_wait_io_event_common(CPUState
*env
)
741 qemu_cond_signal(&qemu_pause_cond
);
743 flush_queued_work(env
);
744 env
->thread_kicked
= false;
747 static void qemu_tcg_wait_io_event(void)
751 while (all_cpu_threads_idle()) {
752 qemu_cond_timedwait(tcg_halt_cond
, &qemu_global_mutex
, 1000);
755 qemu_mutex_unlock(&qemu_global_mutex
);
758 * Users of qemu_global_mutex can be starved, having no chance
759 * to acquire it since this path will get to it first.
760 * So use another lock to provide fairness.
762 qemu_mutex_lock(&qemu_fair_mutex
);
763 qemu_mutex_unlock(&qemu_fair_mutex
);
765 qemu_mutex_lock(&qemu_global_mutex
);
767 for (env
= first_cpu
; env
!= NULL
; env
= env
->next_cpu
) {
768 qemu_wait_io_event_common(env
);
772 static void qemu_kvm_wait_io_event(CPUState
*env
)
774 while (cpu_thread_is_idle(env
)) {
775 qemu_cond_timedwait(env
->halt_cond
, &qemu_global_mutex
, 1000);
778 qemu_kvm_eat_signals(env
);
779 qemu_wait_io_event_common(env
);
782 static int qemu_cpu_exec(CPUState
*env
);
784 static void *qemu_kvm_cpu_thread_fn(void *arg
)
789 qemu_mutex_lock(&qemu_global_mutex
);
790 qemu_thread_self(env
->thread
);
792 r
= kvm_init_vcpu(env
);
794 fprintf(stderr
, "kvm_init_vcpu failed: %s\n", strerror(-r
));
798 qemu_kvm_init_cpu_signals(env
);
800 /* signal CPU creation */
802 qemu_cond_signal(&qemu_cpu_cond
);
804 /* and wait for machine initialization */
805 while (!qemu_system_ready
) {
806 qemu_cond_timedwait(&qemu_system_cond
, &qemu_global_mutex
, 100);
810 if (cpu_can_run(env
)) {
813 qemu_kvm_wait_io_event(env
);
819 static void *qemu_tcg_cpu_thread_fn(void *arg
)
823 qemu_tcg_init_cpu_signals();
824 qemu_thread_self(env
->thread
);
826 /* signal CPU creation */
827 qemu_mutex_lock(&qemu_global_mutex
);
828 for (env
= first_cpu
; env
!= NULL
; env
= env
->next_cpu
) {
831 qemu_cond_signal(&qemu_cpu_cond
);
833 /* and wait for machine initialization */
834 while (!qemu_system_ready
) {
835 qemu_cond_timedwait(&qemu_system_cond
, &qemu_global_mutex
, 100);
840 qemu_tcg_wait_io_event();
846 void qemu_cpu_kick(void *_env
)
848 CPUState
*env
= _env
;
850 qemu_cond_broadcast(env
->halt_cond
);
851 if (!env
->thread_kicked
) {
852 qemu_thread_signal(env
->thread
, SIG_IPI
);
853 env
->thread_kicked
= true;
857 void qemu_cpu_kick_self(void)
859 assert(cpu_single_env
);
861 if (!cpu_single_env
->thread_kicked
) {
862 qemu_thread_signal(cpu_single_env
->thread
, SIG_IPI
);
863 cpu_single_env
->thread_kicked
= true;
867 int qemu_cpu_self(void *_env
)
869 CPUState
*env
= _env
;
872 qemu_thread_self(&this);
874 return qemu_thread_equal(&this, env
->thread
);
877 void qemu_mutex_lock_iothread(void)
880 qemu_mutex_lock(&qemu_global_mutex
);
882 qemu_mutex_lock(&qemu_fair_mutex
);
883 if (qemu_mutex_trylock(&qemu_global_mutex
)) {
884 qemu_thread_signal(tcg_cpu_thread
, SIG_IPI
);
885 qemu_mutex_lock(&qemu_global_mutex
);
887 qemu_mutex_unlock(&qemu_fair_mutex
);
891 void qemu_mutex_unlock_iothread(void)
893 qemu_mutex_unlock(&qemu_global_mutex
);
896 static int all_vcpus_paused(void)
898 CPUState
*penv
= first_cpu
;
901 if (!penv
->stopped
) {
904 penv
= (CPUState
*)penv
->next_cpu
;
910 void pause_all_vcpus(void)
912 CPUState
*penv
= first_cpu
;
917 penv
= (CPUState
*)penv
->next_cpu
;
920 while (!all_vcpus_paused()) {
921 qemu_cond_timedwait(&qemu_pause_cond
, &qemu_global_mutex
, 100);
925 penv
= (CPUState
*)penv
->next_cpu
;
930 void resume_all_vcpus(void)
932 CPUState
*penv
= first_cpu
;
938 penv
= (CPUState
*)penv
->next_cpu
;
942 static void qemu_tcg_init_vcpu(void *_env
)
944 CPUState
*env
= _env
;
946 /* share a single thread for all cpus with TCG */
947 if (!tcg_cpu_thread
) {
948 env
->thread
= qemu_mallocz(sizeof(QemuThread
));
949 env
->halt_cond
= qemu_mallocz(sizeof(QemuCond
));
950 qemu_cond_init(env
->halt_cond
);
951 qemu_thread_create(env
->thread
, qemu_tcg_cpu_thread_fn
, env
);
952 while (env
->created
== 0) {
953 qemu_cond_timedwait(&qemu_cpu_cond
, &qemu_global_mutex
, 100);
955 tcg_cpu_thread
= env
->thread
;
956 tcg_halt_cond
= env
->halt_cond
;
958 env
->thread
= tcg_cpu_thread
;
959 env
->halt_cond
= tcg_halt_cond
;
963 static void qemu_kvm_start_vcpu(CPUState
*env
)
965 env
->thread
= qemu_mallocz(sizeof(QemuThread
));
966 env
->halt_cond
= qemu_mallocz(sizeof(QemuCond
));
967 qemu_cond_init(env
->halt_cond
);
968 qemu_thread_create(env
->thread
, qemu_kvm_cpu_thread_fn
, env
);
969 while (env
->created
== 0) {
970 qemu_cond_timedwait(&qemu_cpu_cond
, &qemu_global_mutex
, 100);
974 void qemu_init_vcpu(void *_env
)
976 CPUState
*env
= _env
;
978 env
->nr_cores
= smp_cores
;
979 env
->nr_threads
= smp_threads
;
981 qemu_kvm_start_vcpu(env
);
983 qemu_tcg_init_vcpu(env
);
987 void qemu_notify_event(void)
989 qemu_event_increment();
992 void cpu_stop_current(void)
994 if (cpu_single_env
) {
995 cpu_single_env
->stopped
= 1;
996 cpu_exit(cpu_single_env
);
1000 void vm_stop(int reason
)
1003 qemu_thread_self(&me
);
1005 if (!qemu_thread_equal(&me
, &io_thread
)) {
1006 qemu_system_vmstop_request(reason
);
1008 * FIXME: should not return to device code in case
1009 * vm_stop() has been requested.
1019 static int qemu_cpu_exec(CPUState
*env
)
1022 #ifdef CONFIG_PROFILER
1026 #ifdef CONFIG_PROFILER
1027 ti
= profile_getclock();
1032 qemu_icount
-= (env
->icount_decr
.u16
.low
+ env
->icount_extra
);
1033 env
->icount_decr
.u16
.low
= 0;
1034 env
->icount_extra
= 0;
1035 count
= qemu_icount_round (qemu_next_deadline());
1036 qemu_icount
+= count
;
1037 decr
= (count
> 0xffff) ? 0xffff : count
;
1039 env
->icount_decr
.u16
.low
= decr
;
1040 env
->icount_extra
= count
;
1042 ret
= cpu_exec(env
);
1043 #ifdef CONFIG_PROFILER
1044 qemu_time
+= profile_getclock() - ti
;
1047 /* Fold pending instructions back into the
1048 instruction counter, and clear the interrupt flag. */
1049 qemu_icount
-= (env
->icount_decr
.u16
.low
1050 + env
->icount_extra
);
1051 env
->icount_decr
.u32
= 0;
1052 env
->icount_extra
= 0;
1057 bool cpu_exec_all(void)
1061 if (next_cpu
== NULL
) {
1062 next_cpu
= first_cpu
;
1064 for (; next_cpu
!= NULL
&& !exit_request
; next_cpu
= next_cpu
->next_cpu
) {
1065 CPUState
*env
= next_cpu
;
1067 qemu_clock_enable(vm_clock
,
1068 (env
->singlestep_enabled
& SSTEP_NOTIMER
) == 0);
1070 if (qemu_alarm_pending()) {
1073 if (cpu_can_run(env
)) {
1074 r
= qemu_cpu_exec(env
);
1075 if (kvm_enabled()) {
1076 qemu_kvm_eat_signals(env
);
1078 if (r
== EXCP_DEBUG
) {
1081 } else if (env
->stop
) {
1086 return !all_cpu_threads_idle();
1089 void set_numa_modes(void)
1094 for (env
= first_cpu
; env
!= NULL
; env
= env
->next_cpu
) {
1095 for (i
= 0; i
< nb_numa_nodes
; i
++) {
1096 if (node_cpumask
[i
] & (1 << env
->cpu_index
)) {
1103 void set_cpu_log(const char *optarg
)
1106 const CPULogItem
*item
;
1108 mask
= cpu_str_to_log_mask(optarg
);
1110 printf("Log items (comma separated):\n");
1111 for (item
= cpu_log_items
; item
->mask
!= 0; item
++) {
1112 printf("%-10s %s\n", item
->name
, item
->help
);
1119 /* Return the virtual CPU time, based on the instruction counter. */
1120 int64_t cpu_get_icount(void)
1123 CPUState
*env
= cpu_single_env
;;
1125 icount
= qemu_icount
;
1127 if (!can_do_io(env
)) {
1128 fprintf(stderr
, "Bad clock read\n");
1130 icount
-= (env
->icount_decr
.u16
.low
+ env
->icount_extra
);
1132 return qemu_icount_bias
+ (icount
<< icount_time_shift
);
1135 void list_cpus(FILE *f
, fprintf_function cpu_fprintf
, const char *optarg
)
1137 /* XXX: implement xxx_cpu_list for targets that still miss it */
1138 #if defined(cpu_list_id)
1139 cpu_list_id(f
, cpu_fprintf
, optarg
);
1140 #elif defined(cpu_list)
1141 cpu_list(f
, cpu_fprintf
); /* deprecated */