Revision 0ab07c62 cpus.c
b/cpus.c | ||
---|---|---|
130 | 130 |
|
131 | 131 |
static int cpu_can_run(CPUState *env) |
132 | 132 |
{ |
133 |
if (env->stop) |
|
133 |
if (env->stop) {
|
|
134 | 134 |
return 0; |
135 |
if (env->stopped || !vm_running) |
|
135 |
} |
|
136 |
if (env->stopped || !vm_running) { |
|
136 | 137 |
return 0; |
138 |
} |
|
137 | 139 |
return 1; |
138 | 140 |
} |
139 | 141 |
|
... | ... | |
225 | 227 |
static const uint64_t val = 1; |
226 | 228 |
ssize_t ret; |
227 | 229 |
|
228 |
if (io_thread_fd == -1) |
|
230 |
if (io_thread_fd == -1) {
|
|
229 | 231 |
return; |
230 |
|
|
232 |
} |
|
231 | 233 |
do { |
232 | 234 |
ret = write(io_thread_fd, &val, sizeof(val)); |
233 | 235 |
} while (ret < 0 && errno == EINTR); |
... | ... | |
258 | 260 |
int fds[2]; |
259 | 261 |
|
260 | 262 |
err = qemu_eventfd(fds); |
261 |
if (err == -1) |
|
263 |
if (err == -1) {
|
|
262 | 264 |
return -errno; |
263 |
|
|
265 |
} |
|
264 | 266 |
err = fcntl_setfl(fds[0], O_NONBLOCK); |
265 |
if (err < 0) |
|
267 |
if (err < 0) {
|
|
266 | 268 |
goto fail; |
267 |
|
|
269 |
} |
|
268 | 270 |
err = fcntl_setfl(fds[1], O_NONBLOCK); |
269 |
if (err < 0) |
|
271 |
if (err < 0) {
|
|
270 | 272 |
goto fail; |
271 |
|
|
273 |
} |
|
272 | 274 |
qemu_set_fd_handler2(fds[0], NULL, qemu_event_read, NULL, |
273 | 275 |
(void *)(unsigned long)fds[0]); |
274 | 276 |
|
... | ... | |
527 | 529 |
|
528 | 530 |
void qemu_cpu_kick(void *env) |
529 | 531 |
{ |
530 |
return; |
|
531 | 532 |
} |
532 | 533 |
|
533 | 534 |
void qemu_cpu_kick_self(void) |
... | ... | |
660 | 661 |
blocked_signals = block_io_signals(); |
661 | 662 |
|
662 | 663 |
ret = qemu_signalfd_init(blocked_signals); |
663 |
if (ret) |
|
664 |
if (ret) {
|
|
664 | 665 |
return ret; |
666 |
} |
|
665 | 667 |
|
666 | 668 |
/* Note eventfd must be drained before signalfd handlers run */ |
667 | 669 |
ret = qemu_event_init(); |
668 |
if (ret) |
|
670 |
if (ret) {
|
|
669 | 671 |
return ret; |
672 |
} |
|
670 | 673 |
|
671 | 674 |
qemu_cond_init(&qemu_pause_cond); |
672 | 675 |
qemu_cond_init(&qemu_system_cond); |
... | ... | |
696 | 699 |
|
697 | 700 |
wi.func = func; |
698 | 701 |
wi.data = data; |
699 |
if (!env->queued_work_first) |
|
702 |
if (!env->queued_work_first) {
|
|
700 | 703 |
env->queued_work_first = &wi; |
701 |
else
|
|
704 |
} else {
|
|
702 | 705 |
env->queued_work_last->next = &wi; |
706 |
} |
|
703 | 707 |
env->queued_work_last = &wi; |
704 | 708 |
wi.next = NULL; |
705 | 709 |
wi.done = false; |
... | ... | |
717 | 721 |
{ |
718 | 722 |
struct qemu_work_item *wi; |
719 | 723 |
|
720 |
if (!env->queued_work_first) |
|
724 |
if (!env->queued_work_first) {
|
|
721 | 725 |
return; |
726 |
} |
|
722 | 727 |
|
723 | 728 |
while ((wi = env->queued_work_first)) { |
724 | 729 |
env->queued_work_first = wi->next; |
... | ... | |
798 | 803 |
qemu_cond_signal(&qemu_cpu_cond); |
799 | 804 |
|
800 | 805 |
/* and wait for machine initialization */ |
801 |
while (!qemu_system_ready) |
|
806 |
while (!qemu_system_ready) {
|
|
802 | 807 |
qemu_cond_timedwait(&qemu_system_cond, &qemu_global_mutex, 100); |
808 |
} |
|
803 | 809 |
|
804 | 810 |
while (1) { |
805 |
if (cpu_can_run(env)) |
|
811 |
if (cpu_can_run(env)) {
|
|
806 | 812 |
qemu_cpu_exec(env); |
813 |
} |
|
807 | 814 |
qemu_kvm_wait_io_event(env); |
808 | 815 |
} |
809 | 816 |
|
... | ... | |
819 | 826 |
|
820 | 827 |
/* signal CPU creation */ |
821 | 828 |
qemu_mutex_lock(&qemu_global_mutex); |
822 |
for (env = first_cpu; env != NULL; env = env->next_cpu) |
|
829 |
for (env = first_cpu; env != NULL; env = env->next_cpu) {
|
|
823 | 830 |
env->created = 1; |
831 |
} |
|
824 | 832 |
qemu_cond_signal(&qemu_cpu_cond); |
825 | 833 |
|
826 | 834 |
/* and wait for machine initialization */ |
827 |
while (!qemu_system_ready) |
|
835 |
while (!qemu_system_ready) {
|
|
828 | 836 |
qemu_cond_timedwait(&qemu_system_cond, &qemu_global_mutex, 100); |
837 |
} |
|
829 | 838 |
|
830 | 839 |
while (1) { |
831 | 840 |
cpu_exec_all(); |
... | ... | |
838 | 847 |
void qemu_cpu_kick(void *_env) |
839 | 848 |
{ |
840 | 849 |
CPUState *env = _env; |
850 |
|
|
841 | 851 |
qemu_cond_broadcast(env->halt_cond); |
842 | 852 |
if (!env->thread_kicked) { |
843 | 853 |
qemu_thread_signal(env->thread, SIG_IPI); |
... | ... | |
889 | 899 |
CPUState *penv = first_cpu; |
890 | 900 |
|
891 | 901 |
while (penv) { |
892 |
if (!penv->stopped) |
|
902 |
if (!penv->stopped) {
|
|
893 | 903 |
return 0; |
904 |
} |
|
894 | 905 |
penv = (CPUState *)penv->next_cpu; |
895 | 906 |
} |
896 | 907 |
|
... | ... | |
932 | 943 |
static void qemu_tcg_init_vcpu(void *_env) |
933 | 944 |
{ |
934 | 945 |
CPUState *env = _env; |
946 |
|
|
935 | 947 |
/* share a single thread for all cpus with TCG */ |
936 | 948 |
if (!tcg_cpu_thread) { |
937 | 949 |
env->thread = qemu_mallocz(sizeof(QemuThread)); |
938 | 950 |
env->halt_cond = qemu_mallocz(sizeof(QemuCond)); |
939 | 951 |
qemu_cond_init(env->halt_cond); |
940 | 952 |
qemu_thread_create(env->thread, qemu_tcg_cpu_thread_fn, env); |
941 |
while (env->created == 0) |
|
953 |
while (env->created == 0) {
|
|
942 | 954 |
qemu_cond_timedwait(&qemu_cpu_cond, &qemu_global_mutex, 100); |
955 |
} |
|
943 | 956 |
tcg_cpu_thread = env->thread; |
944 | 957 |
tcg_halt_cond = env->halt_cond; |
945 | 958 |
} else { |
... | ... | |
954 | 967 |
env->halt_cond = qemu_mallocz(sizeof(QemuCond)); |
955 | 968 |
qemu_cond_init(env->halt_cond); |
956 | 969 |
qemu_thread_create(env->thread, qemu_kvm_cpu_thread_fn, env); |
957 |
while (env->created == 0) |
|
970 |
while (env->created == 0) {
|
|
958 | 971 |
qemu_cond_timedwait(&qemu_cpu_cond, &qemu_global_mutex, 100); |
972 |
} |
|
959 | 973 |
} |
960 | 974 |
|
961 | 975 |
void qemu_init_vcpu(void *_env) |
... | ... | |
964 | 978 |
|
965 | 979 |
env->nr_cores = smp_cores; |
966 | 980 |
env->nr_threads = smp_threads; |
967 |
if (kvm_enabled()) |
|
981 |
if (kvm_enabled()) {
|
|
968 | 982 |
qemu_kvm_start_vcpu(env); |
969 |
else
|
|
983 |
} else {
|
|
970 | 984 |
qemu_tcg_init_vcpu(env); |
985 |
} |
|
971 | 986 |
} |
972 | 987 |
|
973 | 988 |
void qemu_notify_event(void) |
... | ... | |
1050 | 1065 |
{ |
1051 | 1066 |
int r; |
1052 | 1067 |
|
1053 |
if (next_cpu == NULL) |
|
1068 |
if (next_cpu == NULL) {
|
|
1054 | 1069 |
next_cpu = first_cpu; |
1070 |
} |
|
1055 | 1071 |
for (; next_cpu != NULL && !exit_request; next_cpu = next_cpu->next_cpu) { |
1056 | 1072 |
CPUState *env = next_cpu; |
1057 | 1073 |
|
1058 | 1074 |
qemu_clock_enable(vm_clock, |
1059 | 1075 |
(env->singlestep_enabled & SSTEP_NOTIMER) == 0); |
1060 | 1076 |
|
1061 |
if (qemu_alarm_pending()) |
|
1077 |
if (qemu_alarm_pending()) {
|
|
1062 | 1078 |
break; |
1079 |
} |
|
1063 | 1080 |
if (cpu_can_run(env)) { |
1064 | 1081 |
r = qemu_cpu_exec(env); |
1065 | 1082 |
if (kvm_enabled()) { |
Also available in: Unified diff