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"
29 #include "hax-accel-ops.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_new0(QemuThread
, 1);
65 cpu
->halt_cond
= g_new0(QemuCond
, 1);
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 static void hax_accel_ops_class_init(ObjectClass
*oc
, void *data
)
79 AccelOpsClass
*ops
= ACCEL_OPS_CLASS(oc
);
81 ops
->create_vcpu_thread
= hax_start_vcpu_thread
;
82 ops
->kick_vcpu_thread
= hax_kick_vcpu_thread
;
84 ops
->synchronize_post_reset
= hax_cpu_synchronize_post_reset
;
85 ops
->synchronize_post_init
= hax_cpu_synchronize_post_init
;
86 ops
->synchronize_state
= hax_cpu_synchronize_state
;
87 ops
->synchronize_pre_loadvm
= hax_cpu_synchronize_pre_loadvm
;
90 static const TypeInfo hax_accel_ops_type
= {
91 .name
= ACCEL_OPS_NAME("hax"),
93 .parent
= TYPE_ACCEL_OPS
,
94 .class_init
= hax_accel_ops_class_init
,
98 static void hax_accel_ops_register_types(void)
100 type_register_static(&hax_accel_ops_type
);
102 type_init(hax_accel_ops_register_types
);