Lines Matching full:cpu

2  * CPU thread main loop - common bits for user and system mode emulation
22 #include "exec/cpu-common.h"
23 #include "hw/core/cpu.h"
81 void cpu_list_add(CPUState *cpu) in cpu_list_add() argument
86 if (cpu->cpu_index == UNASSIGNED_CPU_INDEX) { in cpu_list_add()
88 cpu->cpu_index = cpu_get_free_index(); in cpu_list_add()
89 assert(cpu->cpu_index != UNASSIGNED_CPU_INDEX); in cpu_list_add()
93 QTAILQ_INSERT_TAIL_RCU(&cpus_queue, cpu, node); in cpu_list_add()
97 void cpu_list_remove(CPUState *cpu) in cpu_list_remove() argument
100 if (!QTAILQ_IN_USE(cpu, node)) { in cpu_list_remove()
105 QTAILQ_REMOVE_RCU(&cpus_queue, cpu, node); in cpu_list_remove()
106 cpu->cpu_index = UNASSIGNED_CPU_INDEX; in cpu_list_remove()
112 CPUState *cpu; in qemu_get_cpu() local
114 CPU_FOREACH(cpu) { in qemu_get_cpu()
115 if (cpu->cpu_index == index) { in qemu_get_cpu()
116 return cpu; in qemu_get_cpu()
123 /* current CPU in the current thread. It is only valid inside cpu_exec() */
133 static void queue_work_on_cpu(CPUState *cpu, struct qemu_work_item *wi) in queue_work_on_cpu() argument
135 qemu_mutex_lock(&cpu->work_mutex); in queue_work_on_cpu()
136 QSIMPLEQ_INSERT_TAIL(&cpu->work_list, wi, node); in queue_work_on_cpu()
138 qemu_mutex_unlock(&cpu->work_mutex); in queue_work_on_cpu()
140 qemu_cpu_kick(cpu); in queue_work_on_cpu()
143 void do_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data, in do_run_on_cpu() argument
148 if (qemu_cpu_is_self(cpu)) { in do_run_on_cpu()
149 func(cpu, data); in do_run_on_cpu()
159 queue_work_on_cpu(cpu, &wi); in do_run_on_cpu()
168 void async_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data) in async_run_on_cpu() argument
177 queue_work_on_cpu(cpu, wi); in async_run_on_cpu()
180 /* Wait for pending exclusive operations to complete. The CPU list lock
248 /* Wait for exclusive ops to finish, and begin cpu execution. */
249 void cpu_exec_start(CPUState *cpu) in cpu_exec_start() argument
251 qatomic_set(&cpu->running, true); in cpu_exec_start()
253 /* Write cpu->running before reading pending_cpus. */ in cpu_exec_start()
256 /* 1. start_exclusive saw cpu->running == true and pending_cpus >= 1. in cpu_exec_start()
257 * After taking the lock we'll see cpu->has_waiter == true and run---not in cpu_exec_start()
261 * 2. start_exclusive saw cpu->running == false but pending_cpus >= 1. in cpu_exec_start()
263 * Then we'll see cpu->has_waiter == false and wait for the item to in cpu_exec_start()
267 * see cpu->running == true, and it will kick the CPU. in cpu_exec_start()
271 if (!cpu->has_waiter) { in cpu_exec_start()
273 * run. Since we have the lock, just set cpu->running to true in cpu_exec_start()
276 qatomic_set(&cpu->running, false); in cpu_exec_start()
279 qatomic_set(&cpu->running, true); in cpu_exec_start()
288 /* Mark cpu as not executing, and release pending exclusive ops. */
289 void cpu_exec_end(CPUState *cpu) in cpu_exec_end() argument
291 qatomic_set(&cpu->running, false); in cpu_exec_end()
293 /* Write cpu->running before reading pending_cpus. */ in cpu_exec_end()
296 /* 1. start_exclusive saw cpu->running == true. Then it will increment in cpu_exec_end()
298 * we'll see cpu->has_waiter == true. in cpu_exec_end()
300 * 2. start_exclusive saw cpu->running == false but here pending_cpus >= 1. in cpu_exec_end()
302 * cpu->running to false and before we read pending_cpus. Then we'll see in cpu_exec_end()
303 * cpu->has_waiter == false and not touch pending_cpus. The next call to in cpu_exec_end()
308 * see cpu->running == false, and it can ignore this CPU until the in cpu_exec_end()
313 if (cpu->has_waiter) { in cpu_exec_end()
314 cpu->has_waiter = false; in cpu_exec_end()
323 void async_safe_run_on_cpu(CPUState *cpu, run_on_cpu_func func, in async_safe_run_on_cpu() argument
334 queue_work_on_cpu(cpu, wi); in async_safe_run_on_cpu()
337 void free_queued_cpu_work(CPUState *cpu) in free_queued_cpu_work() argument
339 while (!QSIMPLEQ_EMPTY(&cpu->work_list)) { in free_queued_cpu_work()
340 struct qemu_work_item *wi = QSIMPLEQ_FIRST(&cpu->work_list); in free_queued_cpu_work()
341 QSIMPLEQ_REMOVE_HEAD(&cpu->work_list, node); in free_queued_cpu_work()
348 void process_queued_cpu_work(CPUState *cpu) in process_queued_cpu_work() argument
352 qemu_mutex_lock(&cpu->work_mutex); in process_queued_cpu_work()
353 if (QSIMPLEQ_EMPTY(&cpu->work_list)) { in process_queued_cpu_work()
354 qemu_mutex_unlock(&cpu->work_mutex); in process_queued_cpu_work()
357 while (!QSIMPLEQ_EMPTY(&cpu->work_list)) { in process_queued_cpu_work()
358 wi = QSIMPLEQ_FIRST(&cpu->work_list); in process_queued_cpu_work()
359 QSIMPLEQ_REMOVE_HEAD(&cpu->work_list, node); in process_queued_cpu_work()
360 qemu_mutex_unlock(&cpu->work_mutex); in process_queued_cpu_work()
364 * CPU is running; 2) cpu_exec in the other CPU tries to takes the in process_queued_cpu_work()
366 * neither CPU can proceed. in process_queued_cpu_work()
370 wi->func(cpu, wi->data); in process_queued_cpu_work()
374 wi->func(cpu, wi->data); in process_queued_cpu_work()
376 qemu_mutex_lock(&cpu->work_mutex); in process_queued_cpu_work()
383 qemu_mutex_unlock(&cpu->work_mutex); in process_queued_cpu_work()
388 int cpu_breakpoint_insert(CPUState *cpu, vaddr pc, int flags, in cpu_breakpoint_insert() argument
393 if (cpu->cc->gdb_adjust_breakpoint) { in cpu_breakpoint_insert()
394 pc = cpu->cc->gdb_adjust_breakpoint(cpu, pc); in cpu_breakpoint_insert()
404 QTAILQ_INSERT_HEAD(&cpu->breakpoints, bp, entry); in cpu_breakpoint_insert()
406 QTAILQ_INSERT_TAIL(&cpu->breakpoints, bp, entry); in cpu_breakpoint_insert()
413 trace_breakpoint_insert(cpu->cpu_index, pc, flags); in cpu_breakpoint_insert()
418 int cpu_breakpoint_remove(CPUState *cpu, vaddr pc, int flags) in cpu_breakpoint_remove() argument
422 if (cpu->cc->gdb_adjust_breakpoint) { in cpu_breakpoint_remove()
423 pc = cpu->cc->gdb_adjust_breakpoint(cpu, pc); in cpu_breakpoint_remove()
426 QTAILQ_FOREACH(bp, &cpu->breakpoints, entry) { in cpu_breakpoint_remove()
428 cpu_breakpoint_remove_by_ref(cpu, bp); in cpu_breakpoint_remove()
436 void cpu_breakpoint_remove_by_ref(CPUState *cpu, CPUBreakpoint *bp) in cpu_breakpoint_remove_by_ref() argument
438 QTAILQ_REMOVE(&cpu->breakpoints, bp, entry); in cpu_breakpoint_remove_by_ref()
440 trace_breakpoint_remove(cpu->cpu_index, bp->pc, bp->flags); in cpu_breakpoint_remove_by_ref()
445 void cpu_breakpoint_remove_all(CPUState *cpu, int mask) in cpu_breakpoint_remove_all() argument
449 QTAILQ_FOREACH_SAFE(bp, &cpu->breakpoints, entry, next) { in cpu_breakpoint_remove_all()
451 cpu_breakpoint_remove_by_ref(cpu, bp); in cpu_breakpoint_remove_all()