Skip to content

Commit cfbc3c6

Browse files
cotastsquad
authored andcommitted
cpu: introduce cpu_in_exclusive_context()
Suggested-by: Alex Bennée <[email protected]> Reviewed-by: Alex Bennée <[email protected]> Signed-off-by: Emilio G. Cota <[email protected]> [AJB: moved inside start/end_exclusive fns + cleanup] Signed-off-by: Alex Bennée <[email protected]> Reviewed-by: Richard Henderson <[email protected]>
1 parent 504f73f commit cfbc3c6

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

accel/tcg/cpu-exec.c

+1-4
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,6 @@ void cpu_exec_step_atomic(CPUState *cpu)
238238
uint32_t flags;
239239
uint32_t cflags = 1;
240240
uint32_t cf_mask = cflags & CF_HASH_MASK;
241-
/* volatile because we modify it between setjmp and longjmp */
242-
volatile bool in_exclusive_region = false;
243241

244242
if (sigsetjmp(cpu->jmp_env, 0) == 0) {
245243
tb = tb_lookup__cpu_state(cpu, &pc, &cs_base, &flags, cf_mask);
@@ -253,7 +251,6 @@ void cpu_exec_step_atomic(CPUState *cpu)
253251

254252
/* Since we got here, we know that parallel_cpus must be true. */
255253
parallel_cpus = false;
256-
in_exclusive_region = true;
257254
cc->cpu_exec_enter(cpu);
258255
/* execute the generated code */
259256
trace_exec_tb(tb, pc);
@@ -273,7 +270,7 @@ void cpu_exec_step_atomic(CPUState *cpu)
273270
assert_no_pages_locked();
274271
}
275272

276-
if (in_exclusive_region) {
273+
if (cpu_in_exclusive_context(cpu)) {
277274
/* We might longjump out of either the codegen or the
278275
* execution, so must make sure we only end the exclusive
279276
* region if we started it.

cpus-common.c

+4
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,15 @@ void start_exclusive(void)
200200
* section until end_exclusive resets pending_cpus to 0.
201201
*/
202202
qemu_mutex_unlock(&qemu_cpu_list_lock);
203+
204+
current_cpu->in_exclusive_context = true;
203205
}
204206

205207
/* Finish an exclusive operation. */
206208
void end_exclusive(void)
207209
{
210+
current_cpu->in_exclusive_context = false;
211+
208212
qemu_mutex_lock(&qemu_cpu_list_lock);
209213
atomic_set(&pending_cpus, 0);
210214
qemu_cond_broadcast(&exclusive_resume);

include/hw/core/cpu.h

+13
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ struct CPUState {
372372
bool unplug;
373373
bool crash_occurred;
374374
bool exit_request;
375+
bool in_exclusive_context;
375376
uint32_t cflags_next_tb;
376377
/* updates protected by BQL */
377378
uint32_t interrupt_request;
@@ -783,6 +784,18 @@ void async_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data)
783784
*/
784785
void async_safe_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data);
785786

787+
/**
788+
* cpu_in_exclusive_context()
789+
* @cpu: The vCPU to check
790+
*
791+
* Returns true if @cpu is an exclusive context, for example running
792+
* something which has previously been queued via async_safe_run_on_cpu().
793+
*/
794+
static inline bool cpu_in_exclusive_context(const CPUState *cpu)
795+
{
796+
return cpu->in_exclusive_context;
797+
}
798+
786799
/**
787800
* qemu_get_cpu:
788801
* @index: The CPUState@cpu_index value of the CPU to obtain.

0 commit comments

Comments
 (0)