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
)
135 if (env
->stopped
|| !vm_running
)
140 static int cpu_has_work(CPUState
*env
)
144 if (env
->queued_work_first
)
146 if (env
->stopped
|| !vm_running
)
150 if (qemu_cpu_has_work(env
))
155 static int any_cpu_has_work(void)
159 for (env
= first_cpu
; env
!= NULL
; env
= env
->next_cpu
)
160 if (cpu_has_work(env
))
165 static void cpu_debug_handler(CPUState
*env
)
167 gdb_set_stop_cpu(env
);
168 debug_requested
= EXCP_DEBUG
;
173 static void sigbus_reraise(void)
176 struct sigaction action
;
178 memset(&action
, 0, sizeof(action
));
179 action
.sa_handler
= SIG_DFL
;
180 if (!sigaction(SIGBUS
, &action
, NULL
)) {
183 sigaddset(&set
, SIGBUS
);
184 sigprocmask(SIG_UNBLOCK
, &set
, NULL
);
186 perror("Failed to re-raise SIGBUS!\n");
190 static void sigbus_handler(int n
, struct qemu_signalfd_siginfo
*siginfo
,
193 if (kvm_on_sigbus(siginfo
->ssi_code
,
194 (void *)(intptr_t)siginfo
->ssi_addr
)) {
199 static void qemu_init_sigbus(void)
201 struct sigaction action
;
203 memset(&action
, 0, sizeof(action
));
204 action
.sa_flags
= SA_SIGINFO
;
205 action
.sa_sigaction
= (void (*)(int, siginfo_t
*, void*))sigbus_handler
;
206 sigaction(SIGBUS
, &action
, NULL
);
208 prctl(PR_MCE_KILL
, PR_MCE_KILL_SET
, PR_MCE_KILL_EARLY
, 0, 0);
211 #else /* !CONFIG_LINUX */
213 static void qemu_init_sigbus(void)
216 #endif /* !CONFIG_LINUX */
219 static int io_thread_fd
= -1;
221 static void qemu_event_increment(void)
223 /* Write 8 bytes to be compatible with eventfd. */
224 static const uint64_t val
= 1;
227 if (io_thread_fd
== -1)
231 ret
= write(io_thread_fd
, &val
, sizeof(val
));
232 } while (ret
< 0 && errno
== EINTR
);
234 /* EAGAIN is fine, a read must be pending. */
235 if (ret
< 0 && errno
!= EAGAIN
) {
236 fprintf(stderr
, "qemu_event_increment: write() filed: %s\n",
242 static void qemu_event_read(void *opaque
)
244 int fd
= (unsigned long)opaque
;
248 /* Drain the notify pipe. For eventfd, only 8 bytes will be read. */
250 len
= read(fd
, buffer
, sizeof(buffer
));
251 } while ((len
== -1 && errno
== EINTR
) || len
== sizeof(buffer
));
254 static int qemu_event_init(void)
259 err
= qemu_eventfd(fds
);
263 err
= fcntl_setfl(fds
[0], O_NONBLOCK
);
267 err
= fcntl_setfl(fds
[1], O_NONBLOCK
);
271 qemu_set_fd_handler2(fds
[0], NULL
, qemu_event_read
, NULL
,
272 (void *)(unsigned long)fds
[0]);
274 io_thread_fd
= fds
[1];
283 static void dummy_signal(int sig
)
287 /* If we have signalfd, we mask out the signals we want to handle and then
288 * use signalfd to listen for them. We rely on whatever the current signal
289 * handler is to dispatch the signals when we receive them.
291 static void sigfd_handler(void *opaque
)
293 int fd
= (unsigned long) opaque
;
294 struct qemu_signalfd_siginfo info
;
295 struct sigaction action
;
300 len
= read(fd
, &info
, sizeof(info
));
301 } while (len
== -1 && errno
== EINTR
);
303 if (len
== -1 && errno
== EAGAIN
) {
307 if (len
!= sizeof(info
)) {
308 printf("read from sigfd returned %zd: %m\n", len
);
312 sigaction(info
.ssi_signo
, NULL
, &action
);
313 if ((action
.sa_flags
& SA_SIGINFO
) && action
.sa_sigaction
) {
314 action
.sa_sigaction(info
.ssi_signo
,
315 (siginfo_t
*)&info
, NULL
);
316 } else if (action
.sa_handler
) {
317 action
.sa_handler(info
.ssi_signo
);
322 static int qemu_signalfd_init(sigset_t mask
)
326 sigfd
= qemu_signalfd(&mask
);
328 fprintf(stderr
, "failed to create signalfd\n");
332 fcntl_setfl(sigfd
, O_NONBLOCK
);
334 qemu_set_fd_handler2(sigfd
, NULL
, sigfd_handler
, NULL
,
335 (void *)(unsigned long) sigfd
);
340 static void qemu_kvm_eat_signals(CPUState
*env
)
342 struct timespec ts
= { 0, 0 };
348 sigemptyset(&waitset
);
349 sigaddset(&waitset
, SIG_IPI
);
350 sigaddset(&waitset
, SIGBUS
);
353 r
= sigtimedwait(&waitset
, &siginfo
, &ts
);
354 if (r
== -1 && !(errno
== EAGAIN
|| errno
== EINTR
)) {
355 perror("sigtimedwait");
361 if (kvm_on_sigbus_vcpu(env
, siginfo
.si_code
, siginfo
.si_addr
)) {
369 r
= sigpending(&chkset
);
371 perror("sigpending");
374 } while (sigismember(&chkset
, SIG_IPI
) || sigismember(&chkset
, SIGBUS
));
376 #ifndef CONFIG_IOTHREAD
377 if (sigismember(&chkset
, SIGIO
) || sigismember(&chkset
, SIGALRM
)) {
385 HANDLE qemu_event_handle
;
387 static void dummy_event_handler(void *opaque
)
391 static int qemu_event_init(void)
393 qemu_event_handle
= CreateEvent(NULL
, FALSE
, FALSE
, NULL
);
394 if (!qemu_event_handle
) {
395 fprintf(stderr
, "Failed CreateEvent: %ld\n", GetLastError());
398 qemu_add_wait_object(qemu_event_handle
, dummy_event_handler
, NULL
);
402 static void qemu_event_increment(void)
404 if (!SetEvent(qemu_event_handle
)) {
405 fprintf(stderr
, "qemu_event_increment: SetEvent failed: %ld\n",
411 static void qemu_kvm_eat_signals(CPUState
*env
)
416 #ifndef CONFIG_IOTHREAD
417 static void qemu_kvm_init_cpu_signals(CPUState
*env
)
422 struct sigaction sigact
;
424 memset(&sigact
, 0, sizeof(sigact
));
425 sigact
.sa_handler
= dummy_signal
;
426 sigaction(SIG_IPI
, &sigact
, NULL
);
429 sigaddset(&set
, SIG_IPI
);
430 sigaddset(&set
, SIGIO
);
431 sigaddset(&set
, SIGALRM
);
432 pthread_sigmask(SIG_BLOCK
, &set
, NULL
);
434 pthread_sigmask(SIG_BLOCK
, NULL
, &set
);
435 sigdelset(&set
, SIG_IPI
);
436 sigdelset(&set
, SIGBUS
);
437 sigdelset(&set
, SIGIO
);
438 sigdelset(&set
, SIGALRM
);
439 r
= kvm_set_signal_mask(env
, &set
);
441 fprintf(stderr
, "kvm_set_signal_mask: %s\n", strerror(-r
));
448 static sigset_t
block_synchronous_signals(void)
453 sigaddset(&set
, SIGBUS
);
456 * We need to process timer signals synchronously to avoid a race
457 * between exit_request check and KVM vcpu entry.
459 sigaddset(&set
, SIGIO
);
460 sigaddset(&set
, SIGALRM
);
467 int qemu_init_main_loop(void)
470 sigset_t blocked_signals
;
473 blocked_signals
= block_synchronous_signals();
475 ret
= qemu_signalfd_init(blocked_signals
);
480 cpu_set_debug_excp_handler(cpu_debug_handler
);
484 return qemu_event_init();
487 void qemu_main_loop_start(void)
491 void qemu_init_vcpu(void *_env
)
493 CPUState
*env
= _env
;
496 env
->nr_cores
= smp_cores
;
497 env
->nr_threads
= smp_threads
;
500 r
= kvm_init_vcpu(env
);
502 fprintf(stderr
, "kvm_init_vcpu failed: %s\n", strerror(-r
));
505 qemu_kvm_init_cpu_signals(env
);
509 int qemu_cpu_self(void *env
)
514 void run_on_cpu(CPUState
*env
, void (*func
)(void *data
), void *data
)
519 void resume_all_vcpus(void)
523 void pause_all_vcpus(void)
527 void qemu_cpu_kick(void *env
)
532 void qemu_cpu_kick_self(void)
535 assert(cpu_single_env
);
543 void qemu_notify_event(void)
545 CPUState
*env
= cpu_single_env
;
547 qemu_event_increment ();
551 if (next_cpu
&& env
!= next_cpu
) {
557 void qemu_mutex_lock_iothread(void) {}
558 void qemu_mutex_unlock_iothread(void) {}
560 void cpu_stop_current(void)
564 void vm_stop(int reason
)
569 #else /* CONFIG_IOTHREAD */
571 #include "qemu-thread.h"
573 QemuMutex qemu_global_mutex
;
574 static QemuMutex qemu_fair_mutex
;
576 static QemuThread io_thread
;
578 static QemuThread
*tcg_cpu_thread
;
579 static QemuCond
*tcg_halt_cond
;
581 static int qemu_system_ready
;
583 static QemuCond qemu_cpu_cond
;
585 static QemuCond qemu_system_cond
;
586 static QemuCond qemu_pause_cond
;
587 static QemuCond qemu_work_cond
;
589 static void cpu_signal(int sig
)
591 if (cpu_single_env
) {
592 cpu_exit(cpu_single_env
);
597 static void qemu_kvm_init_cpu_signals(CPUState
*env
)
601 struct sigaction sigact
;
603 memset(&sigact
, 0, sizeof(sigact
));
604 sigact
.sa_handler
= dummy_signal
;
605 sigaction(SIG_IPI
, &sigact
, NULL
);
607 pthread_sigmask(SIG_BLOCK
, NULL
, &set
);
608 sigdelset(&set
, SIG_IPI
);
609 sigdelset(&set
, SIGBUS
);
610 r
= kvm_set_signal_mask(env
, &set
);
612 fprintf(stderr
, "kvm_set_signal_mask: %s\n", strerror(-r
));
617 static void qemu_tcg_init_cpu_signals(void)
620 struct sigaction sigact
;
622 memset(&sigact
, 0, sizeof(sigact
));
623 sigact
.sa_handler
= cpu_signal
;
624 sigaction(SIG_IPI
, &sigact
, NULL
);
627 sigaddset(&set
, SIG_IPI
);
628 pthread_sigmask(SIG_UNBLOCK
, &set
, NULL
);
631 static sigset_t
block_io_signals(void)
635 /* SIGUSR2 used by posix-aio-compat.c */
637 sigaddset(&set
, SIGUSR2
);
638 pthread_sigmask(SIG_UNBLOCK
, &set
, NULL
);
641 sigaddset(&set
, SIGIO
);
642 sigaddset(&set
, SIGALRM
);
643 sigaddset(&set
, SIG_IPI
);
644 sigaddset(&set
, SIGBUS
);
645 pthread_sigmask(SIG_BLOCK
, &set
, NULL
);
650 int qemu_init_main_loop(void)
653 sigset_t blocked_signals
;
655 cpu_set_debug_excp_handler(cpu_debug_handler
);
659 blocked_signals
= block_io_signals();
661 ret
= qemu_signalfd_init(blocked_signals
);
665 /* Note eventfd must be drained before signalfd handlers run */
666 ret
= qemu_event_init();
670 qemu_cond_init(&qemu_pause_cond
);
671 qemu_cond_init(&qemu_system_cond
);
672 qemu_mutex_init(&qemu_fair_mutex
);
673 qemu_mutex_init(&qemu_global_mutex
);
674 qemu_mutex_lock(&qemu_global_mutex
);
676 qemu_thread_self(&io_thread
);
681 void qemu_main_loop_start(void)
683 qemu_system_ready
= 1;
684 qemu_cond_broadcast(&qemu_system_cond
);
687 void run_on_cpu(CPUState
*env
, void (*func
)(void *data
), void *data
)
689 struct qemu_work_item wi
;
691 if (qemu_cpu_self(env
)) {
698 if (!env
->queued_work_first
)
699 env
->queued_work_first
= &wi
;
701 env
->queued_work_last
->next
= &wi
;
702 env
->queued_work_last
= &wi
;
708 CPUState
*self_env
= cpu_single_env
;
710 qemu_cond_wait(&qemu_work_cond
, &qemu_global_mutex
);
711 cpu_single_env
= self_env
;
715 static void flush_queued_work(CPUState
*env
)
717 struct qemu_work_item
*wi
;
719 if (!env
->queued_work_first
)
722 while ((wi
= env
->queued_work_first
)) {
723 env
->queued_work_first
= wi
->next
;
727 env
->queued_work_last
= NULL
;
728 qemu_cond_broadcast(&qemu_work_cond
);
731 static void qemu_wait_io_event_common(CPUState
*env
)
736 qemu_cond_signal(&qemu_pause_cond
);
738 flush_queued_work(env
);
739 env
->thread_kicked
= false;
742 static void qemu_tcg_wait_io_event(void)
746 while (!any_cpu_has_work())
747 qemu_cond_timedwait(tcg_halt_cond
, &qemu_global_mutex
, 1000);
749 qemu_mutex_unlock(&qemu_global_mutex
);
752 * Users of qemu_global_mutex can be starved, having no chance
753 * to acquire it since this path will get to it first.
754 * So use another lock to provide fairness.
756 qemu_mutex_lock(&qemu_fair_mutex
);
757 qemu_mutex_unlock(&qemu_fair_mutex
);
759 qemu_mutex_lock(&qemu_global_mutex
);
761 for (env
= first_cpu
; env
!= NULL
; env
= env
->next_cpu
) {
762 qemu_wait_io_event_common(env
);
766 static void qemu_kvm_wait_io_event(CPUState
*env
)
768 while (!cpu_has_work(env
))
769 qemu_cond_timedwait(env
->halt_cond
, &qemu_global_mutex
, 1000);
771 qemu_kvm_eat_signals(env
);
772 qemu_wait_io_event_common(env
);
775 static int qemu_cpu_exec(CPUState
*env
);
777 static void *kvm_cpu_thread_fn(void *arg
)
782 qemu_mutex_lock(&qemu_global_mutex
);
783 qemu_thread_self(env
->thread
);
785 r
= kvm_init_vcpu(env
);
787 fprintf(stderr
, "kvm_init_vcpu failed: %s\n", strerror(-r
));
791 qemu_kvm_init_cpu_signals(env
);
793 /* signal CPU creation */
795 qemu_cond_signal(&qemu_cpu_cond
);
797 /* and wait for machine initialization */
798 while (!qemu_system_ready
)
799 qemu_cond_timedwait(&qemu_system_cond
, &qemu_global_mutex
, 100);
802 if (cpu_can_run(env
))
804 qemu_kvm_wait_io_event(env
);
810 static void *tcg_cpu_thread_fn(void *arg
)
814 qemu_tcg_init_cpu_signals();
815 qemu_thread_self(env
->thread
);
817 /* signal CPU creation */
818 qemu_mutex_lock(&qemu_global_mutex
);
819 for (env
= first_cpu
; env
!= NULL
; env
= env
->next_cpu
)
821 qemu_cond_signal(&qemu_cpu_cond
);
823 /* and wait for machine initialization */
824 while (!qemu_system_ready
)
825 qemu_cond_timedwait(&qemu_system_cond
, &qemu_global_mutex
, 100);
829 qemu_tcg_wait_io_event();
835 void qemu_cpu_kick(void *_env
)
837 CPUState
*env
= _env
;
838 qemu_cond_broadcast(env
->halt_cond
);
839 if (!env
->thread_kicked
) {
840 qemu_thread_signal(env
->thread
, SIG_IPI
);
841 env
->thread_kicked
= true;
845 void qemu_cpu_kick_self(void)
847 assert(cpu_single_env
);
849 if (!cpu_single_env
->thread_kicked
) {
850 qemu_thread_signal(cpu_single_env
->thread
, SIG_IPI
);
851 cpu_single_env
->thread_kicked
= true;
855 int qemu_cpu_self(void *_env
)
857 CPUState
*env
= _env
;
860 qemu_thread_self(&this);
862 return qemu_thread_equal(&this, env
->thread
);
865 void qemu_mutex_lock_iothread(void)
868 qemu_mutex_lock(&qemu_global_mutex
);
870 qemu_mutex_lock(&qemu_fair_mutex
);
871 if (qemu_mutex_trylock(&qemu_global_mutex
)) {
872 qemu_thread_signal(tcg_cpu_thread
, SIG_IPI
);
873 qemu_mutex_lock(&qemu_global_mutex
);
875 qemu_mutex_unlock(&qemu_fair_mutex
);
879 void qemu_mutex_unlock_iothread(void)
881 qemu_mutex_unlock(&qemu_global_mutex
);
884 static int all_vcpus_paused(void)
886 CPUState
*penv
= first_cpu
;
891 penv
= (CPUState
*)penv
->next_cpu
;
897 void pause_all_vcpus(void)
899 CPUState
*penv
= first_cpu
;
904 penv
= (CPUState
*)penv
->next_cpu
;
907 while (!all_vcpus_paused()) {
908 qemu_cond_timedwait(&qemu_pause_cond
, &qemu_global_mutex
, 100);
912 penv
= (CPUState
*)penv
->next_cpu
;
917 void resume_all_vcpus(void)
919 CPUState
*penv
= first_cpu
;
925 penv
= (CPUState
*)penv
->next_cpu
;
929 static void tcg_init_vcpu(void *_env
)
931 CPUState
*env
= _env
;
932 /* share a single thread for all cpus with TCG */
933 if (!tcg_cpu_thread
) {
934 env
->thread
= qemu_mallocz(sizeof(QemuThread
));
935 env
->halt_cond
= qemu_mallocz(sizeof(QemuCond
));
936 qemu_cond_init(env
->halt_cond
);
937 qemu_thread_create(env
->thread
, tcg_cpu_thread_fn
, env
);
938 while (env
->created
== 0)
939 qemu_cond_timedwait(&qemu_cpu_cond
, &qemu_global_mutex
, 100);
940 tcg_cpu_thread
= env
->thread
;
941 tcg_halt_cond
= env
->halt_cond
;
943 env
->thread
= tcg_cpu_thread
;
944 env
->halt_cond
= tcg_halt_cond
;
948 static void kvm_start_vcpu(CPUState
*env
)
950 env
->thread
= qemu_mallocz(sizeof(QemuThread
));
951 env
->halt_cond
= qemu_mallocz(sizeof(QemuCond
));
952 qemu_cond_init(env
->halt_cond
);
953 qemu_thread_create(env
->thread
, kvm_cpu_thread_fn
, env
);
954 while (env
->created
== 0)
955 qemu_cond_timedwait(&qemu_cpu_cond
, &qemu_global_mutex
, 100);
958 void qemu_init_vcpu(void *_env
)
960 CPUState
*env
= _env
;
962 env
->nr_cores
= smp_cores
;
963 env
->nr_threads
= smp_threads
;
970 void qemu_notify_event(void)
972 qemu_event_increment();
975 static void qemu_system_vmstop_request(int reason
)
977 vmstop_requested
= reason
;
981 void cpu_stop_current(void)
983 if (cpu_single_env
) {
984 cpu_single_env
->stopped
= 1;
985 cpu_exit(cpu_single_env
);
989 void vm_stop(int reason
)
992 qemu_thread_self(&me
);
994 if (!qemu_thread_equal(&me
, &io_thread
)) {
995 qemu_system_vmstop_request(reason
);
997 * FIXME: should not return to device code in case
998 * vm_stop() has been requested.
1008 static int qemu_cpu_exec(CPUState
*env
)
1011 #ifdef CONFIG_PROFILER
1015 #ifdef CONFIG_PROFILER
1016 ti
= profile_getclock();
1021 qemu_icount
-= (env
->icount_decr
.u16
.low
+ env
->icount_extra
);
1022 env
->icount_decr
.u16
.low
= 0;
1023 env
->icount_extra
= 0;
1024 count
= qemu_icount_round (qemu_next_deadline());
1025 qemu_icount
+= count
;
1026 decr
= (count
> 0xffff) ? 0xffff : count
;
1028 env
->icount_decr
.u16
.low
= decr
;
1029 env
->icount_extra
= count
;
1031 ret
= cpu_exec(env
);
1032 #ifdef CONFIG_PROFILER
1033 qemu_time
+= profile_getclock() - ti
;
1036 /* Fold pending instructions back into the
1037 instruction counter, and clear the interrupt flag. */
1038 qemu_icount
-= (env
->icount_decr
.u16
.low
1039 + env
->icount_extra
);
1040 env
->icount_decr
.u32
= 0;
1041 env
->icount_extra
= 0;
1046 bool cpu_exec_all(void)
1050 if (next_cpu
== NULL
)
1051 next_cpu
= first_cpu
;
1052 for (; next_cpu
!= NULL
&& !exit_request
; next_cpu
= next_cpu
->next_cpu
) {
1053 CPUState
*env
= next_cpu
;
1055 qemu_clock_enable(vm_clock
,
1056 (env
->singlestep_enabled
& SSTEP_NOTIMER
) == 0);
1058 if (qemu_alarm_pending())
1060 if (cpu_can_run(env
)) {
1061 r
= qemu_cpu_exec(env
);
1062 if (kvm_enabled()) {
1063 qemu_kvm_eat_signals(env
);
1065 if (r
== EXCP_DEBUG
) {
1068 } else if (env
->stop
) {
1073 return any_cpu_has_work();
1076 void set_numa_modes(void)
1081 for (env
= first_cpu
; env
!= NULL
; env
= env
->next_cpu
) {
1082 for (i
= 0; i
< nb_numa_nodes
; i
++) {
1083 if (node_cpumask
[i
] & (1 << env
->cpu_index
)) {
1090 void set_cpu_log(const char *optarg
)
1093 const CPULogItem
*item
;
1095 mask
= cpu_str_to_log_mask(optarg
);
1097 printf("Log items (comma separated):\n");
1098 for (item
= cpu_log_items
; item
->mask
!= 0; item
++) {
1099 printf("%-10s %s\n", item
->name
, item
->help
);
1106 /* Return the virtual CPU time, based on the instruction counter. */
1107 int64_t cpu_get_icount(void)
1110 CPUState
*env
= cpu_single_env
;;
1112 icount
= qemu_icount
;
1114 if (!can_do_io(env
)) {
1115 fprintf(stderr
, "Bad clock read\n");
1117 icount
-= (env
->icount_decr
.u16
.low
+ env
->icount_extra
);
1119 return qemu_icount_bias
+ (icount
<< icount_time_shift
);
1122 void list_cpus(FILE *f
, fprintf_function cpu_fprintf
, const char *optarg
)
1124 /* XXX: implement xxx_cpu_list for targets that still miss it */
1125 #if defined(cpu_list_id)
1126 cpu_list_id(f
, cpu_fprintf
, optarg
);
1127 #elif defined(cpu_list)
1128 cpu_list(f
, cpu_fprintf
); /* deprecated */