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>
23 #include "hw/qdev-core.h"
24 #include "disas/bfd.h"
25 #include "exec/hwaddr.h"
26 #include "exec/memattrs.h"
27 #include "qemu/bitmap.h"
28 #include "qemu/queue.h"
29 #include "qemu/thread.h"
31 typedef int (*WriteCoreDumpFunction
)(const void *buf
, size_t size
,
36 * Type wide enough to contain any #target_ulong virtual address.
38 typedef uint64_t vaddr
;
39 #define VADDR_PRId PRId64
40 #define VADDR_PRIu PRIu64
41 #define VADDR_PRIo PRIo64
42 #define VADDR_PRIx PRIx64
43 #define VADDR_PRIX PRIX64
44 #define VADDR_MAX UINT64_MAX
48 * @section_id: QEMU-cpu
50 * @short_description: Base class for all CPUs
53 #define TYPE_CPU "cpu"
55 /* Since this macro is used a lot in hot code paths and in conjunction with
56 * FooCPU *foo_env_get_cpu(), we deviate from usual QOM practice by using
59 #define CPU(obj) ((CPUState *)(obj))
61 #define CPU_CLASS(class) OBJECT_CLASS_CHECK(CPUClass, (class), TYPE_CPU)
62 #define CPU_GET_CLASS(obj) OBJECT_GET_CLASS(CPUClass, (obj), TYPE_CPU)
64 typedef enum MMUAccessType
{
70 typedef struct CPUWatchpoint CPUWatchpoint
;
72 typedef void (*CPUUnassignedAccess
)(CPUState
*cpu
, hwaddr addr
,
73 bool is_write
, bool is_exec
, int opaque
,
76 struct TranslationBlock
;
80 * @class_by_name: Callback to map -cpu command line model name to an
81 * instantiatable CPU type.
82 * @parse_features: Callback to parse command line arguments.
83 * @reset: Callback to reset the #CPUState to its initial state.
84 * @reset_dump_flags: #CPUDumpFlags to use for reset logging.
85 * @has_work: Callback for checking if there is work to do.
86 * @do_interrupt: Callback for interrupt handling.
87 * @do_unassigned_access: Callback for unassigned access handling.
88 * @do_unaligned_access: Callback for unaligned access handling, if
89 * the target defines #ALIGNED_ONLY.
90 * @virtio_is_big_endian: Callback to return %true if a CPU which supports
91 * runtime configurable endianness is currently big-endian. Non-configurable
92 * CPUs can use the default implementation of this method. This method should
93 * not be used by any callers other than the pre-1.0 virtio devices.
94 * @memory_rw_debug: Callback for GDB memory access.
95 * @dump_state: Callback for dumping state.
96 * @dump_statistics: Callback for dumping statistics.
97 * @get_arch_id: Callback for getting architecture-dependent CPU ID.
98 * @get_paging_enabled: Callback for inquiring whether paging is enabled.
99 * @get_memory_mapping: Callback for obtaining the memory mappings.
100 * @set_pc: Callback for setting the Program Counter register.
101 * @synchronize_from_tb: Callback for synchronizing state from a TCG
103 * @handle_mmu_fault: Callback for handling an MMU fault.
104 * @get_phys_page_debug: Callback for obtaining a physical address.
105 * @get_phys_page_attrs_debug: Callback for obtaining a physical address and the
106 * associated memory transaction attributes to use for the access.
107 * CPUs which use memory transaction attributes should implement this
108 * instead of get_phys_page_debug.
109 * @asidx_from_attrs: Callback to return the CPU AddressSpace to use for
110 * a memory access with the specified memory transaction attributes.
111 * @gdb_read_register: Callback for letting GDB read a register.
112 * @gdb_write_register: Callback for letting GDB write a register.
113 * @debug_check_watchpoint: Callback: return true if the architectural
114 * watchpoint whose address has matched should really fire.
115 * @debug_excp_handler: Callback for handling debug exceptions.
116 * @write_elf64_note: Callback for writing a CPU-specific ELF note to a
117 * 64-bit VM coredump.
118 * @write_elf32_qemunote: Callback for writing a CPU- and QEMU-specific ELF
119 * note to a 32-bit VM coredump.
120 * @write_elf32_note: Callback for writing a CPU-specific ELF note to a
121 * 32-bit VM coredump.
122 * @write_elf32_qemunote: Callback for writing a CPU- and QEMU-specific ELF
123 * note to a 32-bit VM coredump.
124 * @vmsd: State description for migration.
125 * @gdb_num_core_regs: Number of core registers accessible to GDB.
126 * @gdb_core_xml_file: File name for core registers GDB XML description.
127 * @gdb_stop_before_watchpoint: Indicates whether GDB expects the CPU to stop
128 * before the insn which triggers a watchpoint rather than after it.
129 * @gdb_arch_name: Optional callback that returns the architecture name known
130 * to GDB. The caller must free the returned string with g_free.
131 * @cpu_exec_enter: Callback for cpu_exec preparation.
132 * @cpu_exec_exit: Callback for cpu_exec cleanup.
133 * @cpu_exec_interrupt: Callback for processing interrupts in cpu_exec.
134 * @disas_set_info: Setup architecture specific components of disassembly info
136 * Represents a CPU family or model.
138 typedef struct CPUClass
{
140 DeviceClass parent_class
;
143 ObjectClass
*(*class_by_name
)(const char *cpu_model
);
144 void (*parse_features
)(const char *typename
, char *str
, Error
**errp
);
146 void (*reset
)(CPUState
*cpu
);
147 int reset_dump_flags
;
148 bool (*has_work
)(CPUState
*cpu
);
149 void (*do_interrupt
)(CPUState
*cpu
);
150 CPUUnassignedAccess do_unassigned_access
;
151 void (*do_unaligned_access
)(CPUState
*cpu
, vaddr addr
,
152 MMUAccessType access_type
,
153 int mmu_idx
, uintptr_t retaddr
);
154 bool (*virtio_is_big_endian
)(CPUState
*cpu
);
155 int (*memory_rw_debug
)(CPUState
*cpu
, vaddr addr
,
156 uint8_t *buf
, int len
, bool is_write
);
157 void (*dump_state
)(CPUState
*cpu
, FILE *f
, fprintf_function cpu_fprintf
,
159 void (*dump_statistics
)(CPUState
*cpu
, FILE *f
,
160 fprintf_function cpu_fprintf
, int flags
);
161 int64_t (*get_arch_id
)(CPUState
*cpu
);
162 bool (*get_paging_enabled
)(const CPUState
*cpu
);
163 void (*get_memory_mapping
)(CPUState
*cpu
, MemoryMappingList
*list
,
165 void (*set_pc
)(CPUState
*cpu
, vaddr value
);
166 void (*synchronize_from_tb
)(CPUState
*cpu
, struct TranslationBlock
*tb
);
167 int (*handle_mmu_fault
)(CPUState
*cpu
, vaddr address
, int rw
,
169 hwaddr (*get_phys_page_debug
)(CPUState
*cpu
, vaddr addr
);
170 hwaddr (*get_phys_page_attrs_debug
)(CPUState
*cpu
, vaddr addr
,
172 int (*asidx_from_attrs
)(CPUState
*cpu
, MemTxAttrs attrs
);
173 int (*gdb_read_register
)(CPUState
*cpu
, uint8_t *buf
, int reg
);
174 int (*gdb_write_register
)(CPUState
*cpu
, uint8_t *buf
, int reg
);
175 bool (*debug_check_watchpoint
)(CPUState
*cpu
, CPUWatchpoint
*wp
);
176 void (*debug_excp_handler
)(CPUState
*cpu
);
178 int (*write_elf64_note
)(WriteCoreDumpFunction f
, CPUState
*cpu
,
179 int cpuid
, void *opaque
);
180 int (*write_elf64_qemunote
)(WriteCoreDumpFunction f
, CPUState
*cpu
,
182 int (*write_elf32_note
)(WriteCoreDumpFunction f
, CPUState
*cpu
,
183 int cpuid
, void *opaque
);
184 int (*write_elf32_qemunote
)(WriteCoreDumpFunction f
, CPUState
*cpu
,
187 const struct VMStateDescription
*vmsd
;
188 int gdb_num_core_regs
;
189 const char *gdb_core_xml_file
;
190 gchar
* (*gdb_arch_name
)(CPUState
*cpu
);
191 bool gdb_stop_before_watchpoint
;
193 void (*cpu_exec_enter
)(CPUState
*cpu
);
194 void (*cpu_exec_exit
)(CPUState
*cpu
);
195 bool (*cpu_exec_interrupt
)(CPUState
*cpu
, int interrupt_request
);
197 void (*disas_set_info
)(CPUState
*cpu
, disassemble_info
*info
);
200 #ifdef HOST_WORDS_BIGENDIAN
201 typedef struct icount_decr_u16
{
206 typedef struct icount_decr_u16
{
212 typedef struct CPUBreakpoint
{
214 int flags
; /* BP_* */
215 QTAILQ_ENTRY(CPUBreakpoint
) entry
;
218 struct CPUWatchpoint
{
223 int flags
; /* BP_* */
224 QTAILQ_ENTRY(CPUWatchpoint
) entry
;
230 #define TB_JMP_CACHE_BITS 12
231 #define TB_JMP_CACHE_SIZE (1 << TB_JMP_CACHE_BITS)
234 typedef void (*run_on_cpu_func
)(CPUState
*cpu
, void *data
);
235 struct qemu_work_item
;
239 * @cpu_index: CPU index (informative).
240 * @nr_cores: Number of cores within this CPU package.
241 * @nr_threads: Number of threads within this CPU.
242 * @numa_node: NUMA node this CPU is belonging to.
243 * @host_tid: Host thread ID.
244 * @running: #true if CPU is currently running (lockless).
245 * @has_waiter: #true if a CPU is currently waiting for the cpu_exec_end;
246 * valid under cpu_list_lock.
247 * @created: Indicates whether the CPU thread has been successfully created.
248 * @interrupt_request: Indicates a pending interrupt request.
249 * @halted: Nonzero if the CPU is in suspended state.
250 * @stop: Indicates a pending stop request.
251 * @stopped: Indicates the CPU has been artificially stopped.
252 * @unplug: Indicates a pending CPU unplug request.
253 * @crash_occurred: Indicates the OS reported a crash (panic) for this CPU
254 * @tcg_exit_req: Set to force TCG to stop executing linked TBs for this
255 * CPU and return to its top level loop.
256 * @singlestep_enabled: Flags for single-stepping.
257 * @icount_extra: Instructions until next timer event.
258 * @icount_decr: Number of cycles left, with interrupt flag in high bit.
259 * This allows a single read-compare-cbranch-write sequence to test
260 * for both decrementer underflow and exceptions.
261 * @can_do_io: Nonzero if memory-mapped IO is safe. Deterministic execution
262 * requires that IO only be performed on the last instruction of a TB
263 * so that interrupts take effect immediately.
264 * @cpu_ases: Pointer to array of CPUAddressSpaces (which define the
265 * AddressSpaces this CPU has)
266 * @num_ases: number of CPUAddressSpaces in @cpu_ases
267 * @as: Pointer to the first AddressSpace, for the convenience of targets which
268 * only have a single AddressSpace
269 * @env_ptr: Pointer to subclass-specific CPUArchState field.
270 * @gdb_regs: Additional GDB registers.
271 * @gdb_num_regs: Number of total registers accessible to GDB.
272 * @gdb_num_g_regs: Number of registers in GDB 'g' packets.
273 * @next_cpu: Next CPU sharing TB cache.
274 * @opaque: User data.
275 * @mem_io_pc: Host Program Counter at which the memory was accessed.
276 * @mem_io_vaddr: Target virtual address at which the memory was accessed.
277 * @kvm_fd: vCPU file descriptor for KVM.
278 * @work_mutex: Lock to prevent multiple access to queued_work_*.
279 * @queued_work_first: First asynchronous work pending.
280 * @trace_dstate: Dynamic tracing state of events for this vCPU (bitmask).
282 * State of one CPU core or thread.
286 DeviceState parent_obj
;
293 struct QemuThread
*thread
;
299 bool running
, has_waiter
;
300 struct QemuCond
*halt_cond
;
308 uint32_t interrupt_request
;
309 int singlestep_enabled
;
310 int64_t icount_extra
;
313 QemuMutex work_mutex
;
314 struct qemu_work_item
*queued_work_first
, *queued_work_last
;
316 CPUAddressSpace
*cpu_ases
;
319 MemoryRegion
*memory
;
321 void *env_ptr
; /* CPUArchState */
322 struct TranslationBlock
*tb_jmp_cache
[TB_JMP_CACHE_SIZE
];
323 struct GDBRegisterState
*gdb_regs
;
326 QTAILQ_ENTRY(CPUState
) node
;
328 /* ice debug support */
329 QTAILQ_HEAD(breakpoints_head
, CPUBreakpoint
) breakpoints
;
331 QTAILQ_HEAD(watchpoints_head
, CPUWatchpoint
) watchpoints
;
332 CPUWatchpoint
*watchpoint_hit
;
336 /* In order to avoid passing too many arguments to the MMIO helpers,
337 * we store some rarely used information in the CPU context.
344 struct KVMState
*kvm_state
;
345 struct kvm_run
*kvm_run
;
348 * Used for events with 'vcpu' and *without* the 'disabled' properties.
349 * Dynamically allocated based on bitmap requried to hold up to
350 * trace_get_vcpu_event_count() entries.
352 unsigned long *trace_dstate
;
354 /* TODO Move common fields from CPUArchState here. */
355 int cpu_index
; /* used by alpha TCG */
356 uint32_t halted
; /* used by alpha, cris, ppc TCG */
362 int32_t exception_index
; /* used by m68k TCG */
364 /* Used to keep track of an outstanding cpu throttle thread for migration
367 bool throttle_thread_scheduled
;
369 /* Note that this is accessed at the start of every TB via a negative
370 offset from AREG0. Leave this field at the end so as to make the
371 (absolute value) offset as small as possible. This reduces code
372 size, especially for hosts without large memory offsets. */
373 uint32_t tcg_exit_req
;
376 QTAILQ_HEAD(CPUTailQ
, CPUState
);
377 extern struct CPUTailQ cpus
;
378 #define CPU_NEXT(cpu) QTAILQ_NEXT(cpu, node)
379 #define CPU_FOREACH(cpu) QTAILQ_FOREACH(cpu, &cpus, node)
380 #define CPU_FOREACH_SAFE(cpu, next_cpu) \
381 QTAILQ_FOREACH_SAFE(cpu, &cpus, node, next_cpu)
382 #define CPU_FOREACH_REVERSE(cpu) \
383 QTAILQ_FOREACH_REVERSE(cpu, &cpus, CPUTailQ, node)
384 #define first_cpu QTAILQ_FIRST(&cpus)
386 extern __thread CPUState
*current_cpu
;
389 * cpu_paging_enabled:
390 * @cpu: The CPU whose state is to be inspected.
392 * Returns: %true if paging is enabled, %false otherwise.
394 bool cpu_paging_enabled(const CPUState
*cpu
);
397 * cpu_get_memory_mapping:
398 * @cpu: The CPU whose memory mappings are to be obtained.
399 * @list: Where to write the memory mappings to.
400 * @errp: Pointer for reporting an #Error.
402 void cpu_get_memory_mapping(CPUState
*cpu
, MemoryMappingList
*list
,
406 * cpu_write_elf64_note:
407 * @f: pointer to a function that writes memory to a file
408 * @cpu: The CPU whose memory is to be dumped
409 * @cpuid: ID number of the CPU
410 * @opaque: pointer to the CPUState struct
412 int cpu_write_elf64_note(WriteCoreDumpFunction f
, CPUState
*cpu
,
413 int cpuid
, void *opaque
);
416 * cpu_write_elf64_qemunote:
417 * @f: pointer to a function that writes memory to a file
418 * @cpu: The CPU whose memory is to be dumped
419 * @cpuid: ID number of the CPU
420 * @opaque: pointer to the CPUState struct
422 int cpu_write_elf64_qemunote(WriteCoreDumpFunction f
, CPUState
*cpu
,
426 * cpu_write_elf32_note:
427 * @f: pointer to a function that writes memory to a file
428 * @cpu: The CPU whose memory is to be dumped
429 * @cpuid: ID number of the CPU
430 * @opaque: pointer to the CPUState struct
432 int cpu_write_elf32_note(WriteCoreDumpFunction f
, CPUState
*cpu
,
433 int cpuid
, void *opaque
);
436 * cpu_write_elf32_qemunote:
437 * @f: pointer to a function that writes memory to a file
438 * @cpu: The CPU whose memory is to be dumped
439 * @cpuid: ID number of the CPU
440 * @opaque: pointer to the CPUState struct
442 int cpu_write_elf32_qemunote(WriteCoreDumpFunction f
, CPUState
*cpu
,
448 * @CPU_DUMP_FPU: dump FPU register state, not just integer
449 * @CPU_DUMP_CCOP: dump info about TCG QEMU's condition code optimization state
452 CPU_DUMP_CODE
= 0x00010000,
453 CPU_DUMP_FPU
= 0x00020000,
454 CPU_DUMP_CCOP
= 0x00040000,
459 * @cpu: The CPU whose state is to be dumped.
460 * @f: File to dump to.
461 * @cpu_fprintf: Function to dump with.
462 * @flags: Flags what to dump.
466 void cpu_dump_state(CPUState
*cpu
, FILE *f
, fprintf_function cpu_fprintf
,
470 * cpu_dump_statistics:
471 * @cpu: The CPU whose state is to be dumped.
472 * @f: File to dump to.
473 * @cpu_fprintf: Function to dump with.
474 * @flags: Flags what to dump.
476 * Dumps CPU statistics.
478 void cpu_dump_statistics(CPUState
*cpu
, FILE *f
, fprintf_function cpu_fprintf
,
481 #ifndef CONFIG_USER_ONLY
483 * cpu_get_phys_page_attrs_debug:
484 * @cpu: The CPU to obtain the physical page address for.
485 * @addr: The virtual address.
486 * @attrs: Updated on return with the memory transaction attributes to use
489 * Obtains the physical page corresponding to a virtual one, together
490 * with the corresponding memory transaction attributes to use for the access.
491 * Use it only for debugging because no protection checks are done.
493 * Returns: Corresponding physical page address or -1 if no page found.
495 static inline hwaddr
cpu_get_phys_page_attrs_debug(CPUState
*cpu
, vaddr addr
,
498 CPUClass
*cc
= CPU_GET_CLASS(cpu
);
500 if (cc
->get_phys_page_attrs_debug
) {
501 return cc
->get_phys_page_attrs_debug(cpu
, addr
, attrs
);
503 /* Fallback for CPUs which don't implement the _attrs_ hook */
504 *attrs
= MEMTXATTRS_UNSPECIFIED
;
505 return cc
->get_phys_page_debug(cpu
, addr
);
509 * cpu_get_phys_page_debug:
510 * @cpu: The CPU to obtain the physical page address for.
511 * @addr: The virtual address.
513 * Obtains the physical page corresponding to a virtual one.
514 * Use it only for debugging because no protection checks are done.
516 * Returns: Corresponding physical page address or -1 if no page found.
518 static inline hwaddr
cpu_get_phys_page_debug(CPUState
*cpu
, vaddr addr
)
520 MemTxAttrs attrs
= {};
522 return cpu_get_phys_page_attrs_debug(cpu
, addr
, &attrs
);
525 /** cpu_asidx_from_attrs:
527 * @attrs: memory transaction attributes
529 * Returns the address space index specifying the CPU AddressSpace
530 * to use for a memory access with the given transaction attributes.
532 static inline int cpu_asidx_from_attrs(CPUState
*cpu
, MemTxAttrs attrs
)
534 CPUClass
*cc
= CPU_GET_CLASS(cpu
);
536 if (cc
->asidx_from_attrs
) {
537 return cc
->asidx_from_attrs(cpu
, attrs
);
545 * @cpu: The CPU to be added to the list of CPUs.
547 void cpu_list_add(CPUState
*cpu
);
551 * @cpu: The CPU to be removed from the list of CPUs.
553 void cpu_list_remove(CPUState
*cpu
);
557 * @cpu: The CPU whose state is to be reset.
559 void cpu_reset(CPUState
*cpu
);
563 * @typename: The CPU base type.
564 * @cpu_model: The model string without any parameters.
566 * Looks up a CPU #ObjectClass matching name @cpu_model.
568 * Returns: A #CPUClass or %NULL if not matching class is found.
570 ObjectClass
*cpu_class_by_name(const char *typename
, const char *cpu_model
);
574 * @typename: The CPU base type.
575 * @cpu_model: The model string including optional parameters.
577 * Instantiates a CPU, processes optional parameters and realizes the CPU.
579 * Returns: A #CPUState or %NULL if an error occurred.
581 CPUState
*cpu_generic_init(const char *typename
, const char *cpu_model
);
585 * @cpu: The vCPU to check.
587 * Checks whether the CPU has work to do.
589 * Returns: %true if the CPU has work, %false otherwise.
591 static inline bool cpu_has_work(CPUState
*cpu
)
593 CPUClass
*cc
= CPU_GET_CLASS(cpu
);
595 g_assert(cc
->has_work
);
596 return cc
->has_work(cpu
);
601 * @cpu: The vCPU to check against.
603 * Checks whether the caller is executing on the vCPU thread.
605 * Returns: %true if called from @cpu's thread, %false otherwise.
607 bool qemu_cpu_is_self(CPUState
*cpu
);
611 * @cpu: The vCPU to kick.
613 * Kicks @cpu's thread.
615 void qemu_cpu_kick(CPUState
*cpu
);
619 * @cpu: The CPU to check.
621 * Checks whether the CPU is stopped.
623 * Returns: %true if run state is not running or if artificially stopped;
626 bool cpu_is_stopped(CPUState
*cpu
);
630 * @cpu: The vCPU to run on.
631 * @func: The function to be executed.
632 * @data: Data to pass to the function.
633 * @mutex: Mutex to release while waiting for @func to run.
635 * Used internally in the implementation of run_on_cpu.
637 void do_run_on_cpu(CPUState
*cpu
, run_on_cpu_func func
, void *data
,
642 * @cpu: The vCPU to run on.
643 * @func: The function to be executed.
644 * @data: Data to pass to the function.
646 * Schedules the function @func for execution on the vCPU @cpu.
648 void run_on_cpu(CPUState
*cpu
, run_on_cpu_func func
, void *data
);
652 * @cpu: The vCPU to run on.
653 * @func: The function to be executed.
654 * @data: Data to pass to the function.
656 * Schedules the function @func for execution on the vCPU @cpu asynchronously.
658 void async_run_on_cpu(CPUState
*cpu
, run_on_cpu_func func
, void *data
);
661 * async_safe_run_on_cpu:
662 * @cpu: The vCPU to run on.
663 * @func: The function to be executed.
664 * @data: Data to pass to the function.
666 * Schedules the function @func for execution on the vCPU @cpu asynchronously,
667 * while all other vCPUs are sleeping.
669 * Unlike run_on_cpu and async_run_on_cpu, the function is run outside the
672 void async_safe_run_on_cpu(CPUState
*cpu
, run_on_cpu_func func
, void *data
);
676 * @index: The CPUState@cpu_index value of the CPU to obtain.
678 * Gets a CPU matching @index.
680 * Returns: The CPU or %NULL if there is no matching CPU.
682 CPUState
*qemu_get_cpu(int index
);
686 * @id: Guest-exposed CPU ID to lookup.
688 * Search for CPU with specified ID.
690 * Returns: %true - CPU is found, %false - CPU isn't found.
692 bool cpu_exists(int64_t id
);
696 * @new_throttle_pct: Percent of sleep time. Valid range is 1 to 99.
698 * Throttles all vcpus by forcing them to sleep for the given percentage of
699 * time. A throttle_percentage of 25 corresponds to a 75% duty cycle roughly.
700 * (example: 10ms sleep for every 30ms awake).
702 * cpu_throttle_set can be called as needed to adjust new_throttle_pct.
703 * Once the throttling starts, it will remain in effect until cpu_throttle_stop
706 void cpu_throttle_set(int new_throttle_pct
);
711 * Stops the vcpu throttling started by cpu_throttle_set.
713 void cpu_throttle_stop(void);
716 * cpu_throttle_active:
718 * Returns: %true if the vcpus are currently being throttled, %false otherwise.
720 bool cpu_throttle_active(void);
723 * cpu_throttle_get_percentage:
725 * Returns the vcpu throttle percentage. See cpu_throttle_set for details.
727 * Returns: The throttle percentage in range 1 to 99.
729 int cpu_throttle_get_percentage(void);
731 #ifndef CONFIG_USER_ONLY
733 typedef void (*CPUInterruptHandler
)(CPUState
*, int);
735 extern CPUInterruptHandler cpu_interrupt_handler
;
739 * @cpu: The CPU to set an interrupt on.
740 * @mask: The interupts to set.
742 * Invokes the interrupt handler.
744 static inline void cpu_interrupt(CPUState
*cpu
, int mask
)
746 cpu_interrupt_handler(cpu
, mask
);
749 #else /* USER_ONLY */
751 void cpu_interrupt(CPUState
*cpu
, int mask
);
753 #endif /* USER_ONLY */
755 #ifdef CONFIG_SOFTMMU
756 static inline void cpu_unassigned_access(CPUState
*cpu
, hwaddr addr
,
757 bool is_write
, bool is_exec
,
758 int opaque
, unsigned size
)
760 CPUClass
*cc
= CPU_GET_CLASS(cpu
);
762 if (cc
->do_unassigned_access
) {
763 cc
->do_unassigned_access(cpu
, addr
, is_write
, is_exec
, opaque
, size
);
767 static inline void cpu_unaligned_access(CPUState
*cpu
, vaddr addr
,
768 MMUAccessType access_type
,
769 int mmu_idx
, uintptr_t retaddr
)
771 CPUClass
*cc
= CPU_GET_CLASS(cpu
);
773 cc
->do_unaligned_access(cpu
, addr
, access_type
, mmu_idx
, retaddr
);
779 * @cpu: The CPU to set the program counter for.
780 * @addr: Program counter value.
782 * Sets the program counter for a CPU.
784 static inline void cpu_set_pc(CPUState
*cpu
, vaddr addr
)
786 CPUClass
*cc
= CPU_GET_CLASS(cpu
);
788 cc
->set_pc(cpu
, addr
);
792 * cpu_reset_interrupt:
793 * @cpu: The CPU to clear the interrupt on.
794 * @mask: The interrupt mask to clear.
796 * Resets interrupts on the vCPU @cpu.
798 void cpu_reset_interrupt(CPUState
*cpu
, int mask
);
802 * @cpu: The CPU to exit.
804 * Requests the CPU @cpu to exit execution.
806 void cpu_exit(CPUState
*cpu
);
810 * @cpu: The CPU to resume.
812 * Resumes CPU, i.e. puts CPU into runnable state.
814 void cpu_resume(CPUState
*cpu
);
818 * @cpu: The CPU to remove.
820 * Requests the CPU to be removed.
822 void cpu_remove(CPUState
*cpu
);
826 * @cpu: The CPU to remove.
828 * Requests the CPU to be removed and waits till it is removed.
830 void cpu_remove_sync(CPUState
*cpu
);
833 * process_queued_cpu_work() - process all items on CPU work queue
834 * @cpu: The CPU which work queue to process.
836 void process_queued_cpu_work(CPUState
*cpu
);
840 * @cpu: The CPU for the current thread.
842 * Record that a CPU has started execution and can be interrupted with
845 void cpu_exec_start(CPUState
*cpu
);
849 * @cpu: The CPU for the current thread.
851 * Record that a CPU has stopped execution and exclusive sections
852 * can be executed without interrupting it.
854 void cpu_exec_end(CPUState
*cpu
);
859 * Wait for a concurrent exclusive section to end, and then start
860 * a section of work that is run while other CPUs are not running
861 * between cpu_exec_start and cpu_exec_end. CPUs that are running
862 * cpu_exec are exited immediately. CPUs that call cpu_exec_start
863 * during the exclusive section go to sleep until this CPU calls
866 void start_exclusive(void);
871 * Concludes an exclusive execution section started by start_exclusive.
873 void end_exclusive(void);
877 * @cpu: The vCPU to initialize.
879 * Initializes a vCPU.
881 void qemu_init_vcpu(CPUState
*cpu
);
883 #define SSTEP_ENABLE 0x1 /* Enable simulated HW single stepping */
884 #define SSTEP_NOIRQ 0x2 /* Do not use IRQ while single stepping */
885 #define SSTEP_NOTIMER 0x4 /* Do not Timers while single stepping */
889 * @cpu: CPU to the flags for.
890 * @enabled: Flags to enable.
892 * Enables or disables single-stepping for @cpu.
894 void cpu_single_step(CPUState
*cpu
, int enabled
);
896 /* Breakpoint/watchpoint flags */
897 #define BP_MEM_READ 0x01
898 #define BP_MEM_WRITE 0x02
899 #define BP_MEM_ACCESS (BP_MEM_READ | BP_MEM_WRITE)
900 #define BP_STOP_BEFORE_ACCESS 0x04
901 /* 0x08 currently unused */
904 #define BP_ANY (BP_GDB | BP_CPU)
905 #define BP_WATCHPOINT_HIT_READ 0x40
906 #define BP_WATCHPOINT_HIT_WRITE 0x80
907 #define BP_WATCHPOINT_HIT (BP_WATCHPOINT_HIT_READ | BP_WATCHPOINT_HIT_WRITE)
909 int cpu_breakpoint_insert(CPUState
*cpu
, vaddr pc
, int flags
,
910 CPUBreakpoint
**breakpoint
);
911 int cpu_breakpoint_remove(CPUState
*cpu
, vaddr pc
, int flags
);
912 void cpu_breakpoint_remove_by_ref(CPUState
*cpu
, CPUBreakpoint
*breakpoint
);
913 void cpu_breakpoint_remove_all(CPUState
*cpu
, int mask
);
915 /* Return true if PC matches an installed breakpoint. */
916 static inline bool cpu_breakpoint_test(CPUState
*cpu
, vaddr pc
, int mask
)
920 if (unlikely(!QTAILQ_EMPTY(&cpu
->breakpoints
))) {
921 QTAILQ_FOREACH(bp
, &cpu
->breakpoints
, entry
) {
922 if (bp
->pc
== pc
&& (bp
->flags
& mask
)) {
930 int cpu_watchpoint_insert(CPUState
*cpu
, vaddr addr
, vaddr len
,
931 int flags
, CPUWatchpoint
**watchpoint
);
932 int cpu_watchpoint_remove(CPUState
*cpu
, vaddr addr
,
933 vaddr len
, int flags
);
934 void cpu_watchpoint_remove_by_ref(CPUState
*cpu
, CPUWatchpoint
*watchpoint
);
935 void cpu_watchpoint_remove_all(CPUState
*cpu
, int mask
);
938 * cpu_get_address_space:
939 * @cpu: CPU to get address space from
940 * @asidx: index identifying which address space to get
942 * Return the requested address space of this CPU. @asidx
943 * specifies which address space to read.
945 AddressSpace
*cpu_get_address_space(CPUState
*cpu
, int asidx
);
947 void QEMU_NORETURN
cpu_abort(CPUState
*cpu
, const char *fmt
, ...)
949 void cpu_exec_exit(CPUState
*cpu
);
951 #ifdef CONFIG_SOFTMMU
952 extern const struct VMStateDescription vmstate_cpu_common
;
954 #define vmstate_cpu_common vmstate_dummy
957 #define VMSTATE_CPU() { \
958 .name = "parent_obj", \
959 .size = sizeof(CPUState), \
960 .vmsd = &vmstate_cpu_common, \
961 .flags = VMS_STRUCT, \
965 #define UNASSIGNED_CPU_INDEX -1