2 * QEMU TCG vCPU common functionality
4 * Functionality common to all TCG vCPU variants: mttcg, rr and icount.
6 * Copyright (c) 2003-2008 Fabrice Bellard
7 * Copyright (c) 2014 Red Hat Inc.
9 * Permission is hereby granted, free of charge, to any person obtaining a copy
10 * of this software and associated documentation files (the "Software"), to deal
11 * in the Software without restriction, including without limitation the rights
12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 * copies of the Software, and to permit persons to whom the Software is
14 * furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28 #include "qemu/osdep.h"
29 #include "qemu-common.h"
30 #include "sysemu/tcg.h"
31 #include "sysemu/replay.h"
32 #include "qemu/main-loop.h"
33 #include "qemu/guest-random.h"
34 #include "exec/exec-all.h"
35 #include "hw/boards.h"
39 /* common functionality among all TCG variants */
41 void tcg_cpus_destroy(CPUState
*cpu
)
43 cpu_thread_signal_destroyed(cpu
);
46 int tcg_cpus_exec(CPUState
*cpu
)
49 #ifdef CONFIG_PROFILER
52 assert(tcg_enabled());
53 #ifdef CONFIG_PROFILER
54 ti
= profile_getclock();
59 #ifdef CONFIG_PROFILER
60 qatomic_set(&tcg_ctx
->prof
.cpu_exec_time
,
61 tcg_ctx
->prof
.cpu_exec_time
+ profile_getclock() - ti
);
66 /* mask must never be zero, except for A20 change call */
67 void tcg_cpus_handle_interrupt(CPUState
*cpu
, int mask
)
69 g_assert(qemu_mutex_iothread_locked());
71 cpu
->interrupt_request
|= mask
;
74 * If called from iothread context, wake the target cpu in
77 if (!qemu_cpu_is_self(cpu
)) {
80 qatomic_set(&cpu_neg(cpu
)->icount_decr
.u16
.high
, -1);