4 * Copyright IBM, Corp. 2008
8 * Anthony Liguori <aliguori@us.ibm.com>
9 * Glauber Costa <gcosta@redhat.com>
11 * Copyright (c) 2011 Intel Corporation
13 * Jiang Yunhong<yunhong.jiang@intel.com>
14 * Xin Xiaohui<xiaohui.xin@intel.com>
15 * Zhang Xiantao<xiantao.zhang@intel.com>
17 * This work is licensed under the terms of the GNU GPL, version 2 or later.
18 * See the COPYING file in the top-level directory.
22 #include "qemu/osdep.h"
23 #include "qemu/error-report.h"
24 #include "qemu/main-loop.h"
25 #include "sysemu/runstate.h"
26 #include "sysemu/cpus.h"
27 #include "qemu/guest-random.h"
31 static void *hax_cpu_thread_fn(void *arg
)
36 rcu_register_thread();
37 qemu_mutex_lock_iothread();
38 qemu_thread_get_self(cpu
->thread
);
40 cpu
->thread_id
= qemu_get_thread_id();
43 cpu_thread_signal_created(cpu
);
44 qemu_guest_random_seed_thread_part2(cpu
->random_seed
);
47 if (cpu_can_run(cpu
)) {
48 r
= hax_smp_cpu_exec(cpu
);
49 if (r
== EXCP_DEBUG
) {
50 cpu_handle_guest_debug(cpu
);
54 qemu_wait_io_event(cpu
);
55 } while (!cpu
->unplug
|| cpu_can_run(cpu
));
56 rcu_unregister_thread();
60 static void hax_start_vcpu_thread(CPUState
*cpu
)
62 char thread_name
[VCPU_THREAD_NAME_SIZE
];
64 cpu
->thread
= g_malloc0(sizeof(QemuThread
));
65 cpu
->halt_cond
= g_malloc0(sizeof(QemuCond
));
66 qemu_cond_init(cpu
->halt_cond
);
68 snprintf(thread_name
, VCPU_THREAD_NAME_SIZE
, "CPU %d/HAX",
70 qemu_thread_create(cpu
->thread
, thread_name
, hax_cpu_thread_fn
,
71 cpu
, QEMU_THREAD_JOINABLE
);
73 cpu
->hThread
= qemu_thread_get_handle(cpu
->thread
);
77 const CpusAccel hax_cpus
= {
78 .create_vcpu_thread
= hax_start_vcpu_thread
,
79 .kick_vcpu_thread
= hax_kick_vcpu_thread
,
81 .synchronize_post_reset
= hax_cpu_synchronize_post_reset
,
82 .synchronize_post_init
= hax_cpu_synchronize_post_init
,
83 .synchronize_state
= hax_cpu_synchronize_state
,
84 .synchronize_pre_loadvm
= hax_cpu_synchronize_pre_loadvm
,