]>
git.proxmox.com Git - qemu.git/blob - include/qom/cpu.h
b83ba6f1501f5c2c254b68f1b50de13a6ae140c3
4 * Copyright (c) 2012 SUSE LINUX Products GmbH
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.
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.
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>
24 #include "hw/qdev-core.h"
25 #include "qemu/thread.h"
29 * @section_id: QEMU-cpu
31 * @short_description: Base class for all CPUs
34 #define TYPE_CPU "cpu"
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)
40 typedef struct CPUState CPUState
;
44 * @class_by_name: Callback to map -cpu command line model name to an
45 * instantiatable CPU type.
46 * @reset: Callback to reset the #CPUState to its initial state.
47 * @vmsd: State description for migration.
49 * Represents a CPU family or model.
51 typedef struct CPUClass
{
53 DeviceClass parent_class
;
56 ObjectClass
*(*class_by_name
)(const char *cpu_model
);
58 void (*reset
)(CPUState
*cpu
);
60 const struct VMStateDescription
*vmsd
;
68 * @cpu_index: CPU index (informative).
69 * @nr_cores: Number of cores within this CPU package.
70 * @nr_threads: Number of threads within this CPU.
71 * @numa_node: NUMA node this CPU is belonging to.
72 * @host_tid: Host thread ID.
73 * @running: #true if CPU is currently running (usermode).
74 * @created: Indicates whether the CPU thread has been successfully created.
75 * @interrupt_request: Indicates a pending interrupt request.
76 * @halted: Nonzero if the CPU is in suspended state.
77 * @stop: Indicates a pending stop request.
78 * @stopped: Indicates the CPU has been artificially stopped.
79 * @tcg_exit_req: Set to force TCG to stop executing linked TBs for this
80 * CPU and return to its top level loop.
81 * @env_ptr: Pointer to subclass-specific CPUArchState field.
82 * @current_tb: Currently executing TB.
83 * @kvm_fd: vCPU file descriptor for KVM.
85 * State of one CPU core or thread.
89 DeviceState parent_obj
;
96 struct QemuThread
*thread
;
103 struct QemuCond
*halt_cond
;
104 struct qemu_work_item
*queued_work_first
, *queued_work_last
;
109 volatile sig_atomic_t exit_request
;
110 volatile sig_atomic_t tcg_exit_req
;
111 uint32_t interrupt_request
;
113 void *env_ptr
; /* CPUArchState */
114 struct TranslationBlock
*current_tb
;
118 struct KVMState
*kvm_state
;
119 struct kvm_run
*kvm_run
;
121 /* TODO Move common fields from CPUArchState here. */
122 int cpu_index
; /* used by alpha TCG */
123 uint32_t halted
; /* used by alpha, cris, ppc TCG */
129 * @cpu: The CPU whose state is to be reset.
131 void cpu_reset(CPUState
*cpu
);
135 * @typename: The CPU base type.
136 * @cpu_model: The model string without any parameters.
138 * Looks up a CPU #ObjectClass matching name @cpu_model.
140 * Returns: A #CPUClass or %NULL if not matching class is found.
142 ObjectClass
*cpu_class_by_name(const char *typename
, const char *cpu_model
);
145 * cpu_class_set_vmsd:
147 * @value: Value to set. Unused for %CONFIG_USER_ONLY.
149 * Sets #VMStateDescription for @cc.
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.
155 #ifndef CONFIG_USER_ONLY
156 static inline void cpu_class_set_vmsd(CPUClass
*cc
,
157 const struct VMStateDescription
*value
)
162 #define cpu_class_set_vmsd(cc, value) ((cc)->vmsd = NULL)
167 * @cpu: The vCPU to check.
169 * Checks whether the CPU has work to do.
171 * Returns: %true if the CPU has work, %false otherwise.
173 bool qemu_cpu_has_work(CPUState
*cpu
);
177 * @cpu: The vCPU to check against.
179 * Checks whether the caller is executing on the vCPU thread.
181 * Returns: %true if called from @cpu's thread, %false otherwise.
183 bool qemu_cpu_is_self(CPUState
*cpu
);
187 * @cpu: The vCPU to kick.
189 * Kicks @cpu's thread.
191 void qemu_cpu_kick(CPUState
*cpu
);
195 * @cpu: The CPU to check.
197 * Checks whether the CPU is stopped.
199 * Returns: %true if run state is not running or if artificially stopped;
202 bool cpu_is_stopped(CPUState
*cpu
);
206 * @cpu: The vCPU to run on.
207 * @func: The function to be executed.
208 * @data: Data to pass to the function.
210 * Schedules the function @func for execution on the vCPU @cpu.
212 void run_on_cpu(CPUState
*cpu
, void (*func
)(void *data
), void *data
);
216 * @index: The CPUState@cpu_index value of the CPU to obtain.
218 * Gets a CPU matching @index.
220 * Returns: The CPU or %NULL if there is no matching CPU.
222 CPUState
*qemu_get_cpu(int index
);
225 * cpu_reset_interrupt:
226 * @cpu: The CPU to clear the interrupt on.
227 * @mask: The interrupt mask to clear.
229 * Resets interrupts on the vCPU @cpu.
231 void cpu_reset_interrupt(CPUState
*cpu
, int mask
);