]>
Commit | Line | Data |
---|---|---|
dd83b06a AF |
1 | /* |
2 | * QEMU CPU model | |
3 | * | |
4 | * Copyright (c) 2012 SUSE LINUX Products GmbH | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or | |
7 | * modify it under the terms of the GNU General Public License | |
8 | * as published by the Free Software Foundation; either version 2 | |
9 | * of the License, or (at your option) any later version. | |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | * GNU General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with this program; if not, see | |
18 | * <http://www.gnu.org/licenses/gpl-2.0.html> | |
19 | */ | |
20 | #ifndef QEMU_CPU_H | |
21 | #define QEMU_CPU_H | |
22 | ||
fcd7d003 | 23 | #include <signal.h> |
961f8395 | 24 | #include "hw/qdev-core.h" |
1de7afc9 | 25 | #include "qemu/thread.h" |
dd83b06a AF |
26 | |
27 | /** | |
28 | * SECTION:cpu | |
29 | * @section_id: QEMU-cpu | |
30 | * @title: CPU Class | |
31 | * @short_description: Base class for all CPUs | |
32 | */ | |
33 | ||
34 | #define TYPE_CPU "cpu" | |
35 | ||
36 | #define CPU(obj) OBJECT_CHECK(CPUState, (obj), TYPE_CPU) | |
37 | #define CPU_CLASS(class) OBJECT_CLASS_CHECK(CPUClass, (class), TYPE_CPU) | |
38 | #define CPU_GET_CLASS(obj) OBJECT_GET_CLASS(CPUClass, (obj), TYPE_CPU) | |
39 | ||
40 | typedef struct CPUState CPUState; | |
41 | ||
42 | /** | |
43 | * CPUClass: | |
2b8c2754 AF |
44 | * @class_by_name: Callback to map -cpu command line model name to an |
45 | * instantiatable CPU type. | |
f5df5baf | 46 | * @reset: Callback to reset the #CPUState to its initial state. |
b170fce3 | 47 | * @vmsd: State description for migration. |
dd83b06a AF |
48 | * |
49 | * Represents a CPU family or model. | |
50 | */ | |
51 | typedef struct CPUClass { | |
52 | /*< private >*/ | |
961f8395 | 53 | DeviceClass parent_class; |
dd83b06a AF |
54 | /*< public >*/ |
55 | ||
2b8c2754 AF |
56 | ObjectClass *(*class_by_name)(const char *cpu_model); |
57 | ||
dd83b06a | 58 | void (*reset)(CPUState *cpu); |
b170fce3 AF |
59 | |
60 | const struct VMStateDescription *vmsd; | |
dd83b06a AF |
61 | } CPUClass; |
62 | ||
a60f24b5 | 63 | struct KVMState; |
f7575c96 | 64 | struct kvm_run; |
a60f24b5 | 65 | |
dd83b06a AF |
66 | /** |
67 | * CPUState: | |
55e5c285 | 68 | * @cpu_index: CPU index (informative). |
ce3960eb AF |
69 | * @nr_cores: Number of cores within this CPU package. |
70 | * @nr_threads: Number of threads within this CPU. | |
1b1ed8dc | 71 | * @numa_node: NUMA node this CPU is belonging to. |
0d34282f | 72 | * @host_tid: Host thread ID. |
0315c31c | 73 | * @running: #true if CPU is currently running (usermode). |
61a46217 | 74 | * @created: Indicates whether the CPU thread has been successfully created. |
259186a7 AF |
75 | * @interrupt_request: Indicates a pending interrupt request. |
76 | * @halted: Nonzero if the CPU is in suspended state. | |
4fdeee7c | 77 | * @stop: Indicates a pending stop request. |
f324e766 | 78 | * @stopped: Indicates the CPU has been artificially stopped. |
378df4b2 PM |
79 | * @tcg_exit_req: Set to force TCG to stop executing linked TBs for this |
80 | * CPU and return to its top level loop. | |
c05efcb1 | 81 | * @env_ptr: Pointer to subclass-specific CPUArchState field. |
d77953b9 | 82 | * @current_tb: Currently executing TB. |
8737c51c | 83 | * @kvm_fd: vCPU file descriptor for KVM. |
dd83b06a AF |
84 | * |
85 | * State of one CPU core or thread. | |
86 | */ | |
87 | struct CPUState { | |
88 | /*< private >*/ | |
961f8395 | 89 | DeviceState parent_obj; |
dd83b06a AF |
90 | /*< public >*/ |
91 | ||
ce3960eb AF |
92 | int nr_cores; |
93 | int nr_threads; | |
1b1ed8dc | 94 | int numa_node; |
ce3960eb | 95 | |
814e612e | 96 | struct QemuThread *thread; |
bcba2a72 AF |
97 | #ifdef _WIN32 |
98 | HANDLE hThread; | |
99 | #endif | |
9f09e18a | 100 | int thread_id; |
0d34282f | 101 | uint32_t host_tid; |
0315c31c | 102 | bool running; |
f5c121b8 | 103 | struct QemuCond *halt_cond; |
c64ca814 | 104 | struct qemu_work_item *queued_work_first, *queued_work_last; |
216fc9a4 | 105 | bool thread_kicked; |
61a46217 | 106 | bool created; |
4fdeee7c | 107 | bool stop; |
f324e766 | 108 | bool stopped; |
fcd7d003 | 109 | volatile sig_atomic_t exit_request; |
378df4b2 | 110 | volatile sig_atomic_t tcg_exit_req; |
259186a7 | 111 | uint32_t interrupt_request; |
bcba2a72 | 112 | |
c05efcb1 | 113 | void *env_ptr; /* CPUArchState */ |
d77953b9 AF |
114 | struct TranslationBlock *current_tb; |
115 | ||
8737c51c | 116 | int kvm_fd; |
20d695a9 | 117 | bool kvm_vcpu_dirty; |
a60f24b5 | 118 | struct KVMState *kvm_state; |
f7575c96 | 119 | struct kvm_run *kvm_run; |
8737c51c | 120 | |
f5df5baf | 121 | /* TODO Move common fields from CPUArchState here. */ |
55e5c285 | 122 | int cpu_index; /* used by alpha TCG */ |
259186a7 | 123 | uint32_t halted; /* used by alpha, cris, ppc TCG */ |
dd83b06a AF |
124 | }; |
125 | ||
126 | ||
127 | /** | |
128 | * cpu_reset: | |
129 | * @cpu: The CPU whose state is to be reset. | |
130 | */ | |
131 | void cpu_reset(CPUState *cpu); | |
132 | ||
2b8c2754 AF |
133 | /** |
134 | * cpu_class_by_name: | |
135 | * @typename: The CPU base type. | |
136 | * @cpu_model: The model string without any parameters. | |
137 | * | |
138 | * Looks up a CPU #ObjectClass matching name @cpu_model. | |
139 | * | |
140 | * Returns: A #CPUClass or %NULL if not matching class is found. | |
141 | */ | |
142 | ObjectClass *cpu_class_by_name(const char *typename, const char *cpu_model); | |
143 | ||
ca91b15f AF |
144 | /** |
145 | * cpu_class_set_vmsd: | |
146 | * @cc: CPU class | |
147 | * @value: Value to set. Unused for %CONFIG_USER_ONLY. | |
148 | * | |
149 | * Sets #VMStateDescription for @cc. | |
150 | * | |
151 | * The @value argument is intentionally discarded for the non-softmmu targets | |
152 | * to avoid linker errors or excessive preprocessor usage. If this behavior | |
153 | * is undesired, you should assign #CPUState.vmsd directly instead. | |
154 | */ | |
155 | #ifndef CONFIG_USER_ONLY | |
156 | static inline void cpu_class_set_vmsd(CPUClass *cc, | |
157 | const struct VMStateDescription *value) | |
158 | { | |
159 | cc->vmsd = value; | |
160 | } | |
161 | #else | |
162 | #define cpu_class_set_vmsd(cc, value) ((cc)->vmsd = NULL) | |
163 | #endif | |
164 | ||
3993c6bd AF |
165 | /** |
166 | * qemu_cpu_has_work: | |
167 | * @cpu: The vCPU to check. | |
168 | * | |
169 | * Checks whether the CPU has work to do. | |
170 | * | |
171 | * Returns: %true if the CPU has work, %false otherwise. | |
172 | */ | |
173 | bool qemu_cpu_has_work(CPUState *cpu); | |
174 | ||
60e82579 AF |
175 | /** |
176 | * qemu_cpu_is_self: | |
177 | * @cpu: The vCPU to check against. | |
178 | * | |
179 | * Checks whether the caller is executing on the vCPU thread. | |
180 | * | |
181 | * Returns: %true if called from @cpu's thread, %false otherwise. | |
182 | */ | |
183 | bool qemu_cpu_is_self(CPUState *cpu); | |
184 | ||
c08d7424 AF |
185 | /** |
186 | * qemu_cpu_kick: | |
187 | * @cpu: The vCPU to kick. | |
188 | * | |
189 | * Kicks @cpu's thread. | |
190 | */ | |
191 | void qemu_cpu_kick(CPUState *cpu); | |
192 | ||
2fa45344 AF |
193 | /** |
194 | * cpu_is_stopped: | |
195 | * @cpu: The CPU to check. | |
196 | * | |
197 | * Checks whether the CPU is stopped. | |
198 | * | |
199 | * Returns: %true if run state is not running or if artificially stopped; | |
200 | * %false otherwise. | |
201 | */ | |
202 | bool cpu_is_stopped(CPUState *cpu); | |
203 | ||
f100f0b3 AF |
204 | /** |
205 | * run_on_cpu: | |
206 | * @cpu: The vCPU to run on. | |
207 | * @func: The function to be executed. | |
208 | * @data: Data to pass to the function. | |
209 | * | |
210 | * Schedules the function @func for execution on the vCPU @cpu. | |
211 | */ | |
212 | void run_on_cpu(CPUState *cpu, void (*func)(void *data), void *data); | |
213 | ||
38d8f5c8 AF |
214 | /** |
215 | * qemu_get_cpu: | |
216 | * @index: The CPUState@cpu_index value of the CPU to obtain. | |
217 | * | |
218 | * Gets a CPU matching @index. | |
219 | * | |
220 | * Returns: The CPU or %NULL if there is no matching CPU. | |
221 | */ | |
222 | CPUState *qemu_get_cpu(int index); | |
223 | ||
dd83b06a AF |
224 | |
225 | #endif |