[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [RFC v4 30/71] cpu: define cpu_interrupt_request helper
From: |
Alex Bennée |
Subject: |
Re: [Qemu-devel] [RFC v4 30/71] cpu: define cpu_interrupt_request helpers |
Date: |
Wed, 31 Oct 2018 16:21:11 +0000 |
User-agent: |
mu4e 1.1.0; emacs 26.1.50 |
Emilio G. Cota <address@hidden> writes:
> Add a comment about how atomic_read works here. The comment refers to
> a "BQL-less CPU loop", which will materialize toward the end
> of this series.
>
> Note that the modifications to cpu_reset_interrupt are there to
> avoid deadlock during the CPU lock transition; once that is complete,
> cpu_interrupt_request will be simple again.
>
<snip>
> --- a/qom/cpu.c
> +++ b/qom/cpu.c
> @@ -98,14 +98,29 @@ static void cpu_common_get_memory_mapping(CPUState *cpu,
> * BQL here if we need to. cpu_interrupt assumes it is held.*/
> void cpu_reset_interrupt(CPUState *cpu, int mask)
> {
> - bool need_lock = !qemu_mutex_iothread_locked();
> + bool has_bql = qemu_mutex_iothread_locked();
> + bool has_cpu_lock = cpu_mutex_locked(cpu);
>
> - if (need_lock) {
> - qemu_mutex_lock_iothread();
> + if (has_bql) {
> + if (has_cpu_lock) {
> + atomic_set(&cpu->interrupt_request, cpu->interrupt_request &
> ~mask);
> + } else {
> + cpu_mutex_lock(cpu);
> + atomic_set(&cpu->interrupt_request, cpu->interrupt_request &
> ~mask);
> + cpu_mutex_unlock(cpu);
> + }
> + return;
> + }
> +
> + if (has_cpu_lock) {
> + cpu_mutex_unlock(cpu);
> }
> - cpu->interrupt_request &= ~mask;
> - if (need_lock) {
> - qemu_mutex_unlock_iothread();
> + qemu_mutex_lock_iothread();
> + cpu_mutex_lock(cpu);
> + atomic_set(&cpu->interrupt_request, cpu->interrupt_request & ~mask);
> + qemu_mutex_unlock_iothread();
> + if (!has_cpu_lock) {
> + cpu_mutex_unlock(cpu);
> }
> }
Yeah I can see this is pretty ugly but cleaned up by the end of the
series. If it's the same sequence as the previous patch I wonder if it's
possible to hide the ugliness in a common helper while we transition?
Otherwise:
Reviewed-by: Alex Bennée <address@hidden>
--
Alex Bennée
- Re: [Qemu-devel] [RFC v4 18/71] sh4: convert to cpu_halted, (continued)
- [Qemu-devel] [RFC v4 32/71] exec: use cpu_reset_interrupt, Emilio G. Cota, 2018/10/25
- [Qemu-devel] [RFC v4 21/71] m68k: convert to cpu_halted, Emilio G. Cota, 2018/10/25
- [Qemu-devel] [RFC v4 28/71] openrisc: convert to cpu_halted, Emilio G. Cota, 2018/10/25
- [Qemu-devel] [RFC v4 30/71] cpu: define cpu_interrupt_request helpers, Emilio G. Cota, 2018/10/25
- [Qemu-devel] [RFC v4 25/71] sparc: convert to cpu_halted, Emilio G. Cota, 2018/10/25
- [Qemu-devel] [RFC v4 26/71] xtensa: convert to cpu_halted, Emilio G. Cota, 2018/10/25
- [Qemu-devel] [RFC v4 29/71] cpu-exec: convert to cpu_halted, Emilio G. Cota, 2018/10/25
- [Qemu-devel] [RFC v4 27/71] gdbstub: convert to cpu_halted, Emilio G. Cota, 2018/10/25
- [Qemu-devel] [RFC v4 19/71] i386: convert to cpu_halted, Emilio G. Cota, 2018/10/25