From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55072) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZZcOF-0007VD-7y for qemu-devel@nongnu.org; Wed, 09 Sep 2015 06:14:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZZcOB-0005u8-5E for qemu-devel@nongnu.org; Wed, 09 Sep 2015 06:14:07 -0400 Received: from mail-wi0-x22a.google.com ([2a00:1450:400c:c05::22a]:37906) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZZcOA-0005tu-UW for qemu-devel@nongnu.org; Wed, 09 Sep 2015 06:14:03 -0400 Received: by wiclk2 with SMTP id lk2so15735245wic.1 for ; Wed, 09 Sep 2015 03:14:02 -0700 (PDT) Sender: Paolo Bonzini References: <1440375847-17603-1-git-send-email-cota@braap.org> <1440375847-17603-24-git-send-email-cota@braap.org> From: Paolo Bonzini Message-ID: <55F00667.1070901@redhat.com> Date: Wed, 9 Sep 2015 12:13:59 +0200 MIME-Version: 1.0 In-Reply-To: <1440375847-17603-24-git-send-email-cota@braap.org> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [RFC 23/38] cpu-exec: grab iothread lock during interrupt handling List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Emilio G. Cota" , qemu-devel@nongnu.org, mttcg@listserver.greensocs.com Cc: alex.bennee@linaro.org, Frederic Konrad , mark.burton@greensocs.com, a.rigo@virtualopensystems.com, guillaume.delbergue@greensocs.com On 24/08/2015 02:23, Emilio G. Cota wrote: > Signed-off-by: Emilio G. Cota > --- > cpu-exec.c | 34 ++++++++++++++++++++++++++++------ > include/qom/cpu.h | 1 + > 2 files changed, 29 insertions(+), 6 deletions(-) > > diff --git a/cpu-exec.c b/cpu-exec.c > index fd57b9c..a1700ac 100644 > --- a/cpu-exec.c > +++ b/cpu-exec.c > @@ -371,6 +371,29 @@ static void cpu_handle_debug_exception(CPUState *cpu) > cc->debug_excp_handler(cpu); > } > > +#ifdef CONFIG_SOFTMMU > +static inline void cpu_exit_loop_lock(CPUState *cpu) > +{ > + qemu_mutex_lock_iothread(); > + cpu->cpu_loop_exit_locked = true; > +} > + > +static inline void cpu_exit_loop_lock_reset(CPUState *cpu) > +{ > + if (cpu->cpu_loop_exit_locked) { > + cpu->cpu_loop_exit_locked = false; > + qemu_mutex_unlock_iothread(); > + } This can use qemu_mutex_iothread_locked, avoiding the introduction of a new CPUState member. Paolo > +} > + > +#else > +static inline void cpu_exit_loop_lock(CPUState *cpu) > +{ } > + > +static inline void cpu_exit_loop_lock_reset(CPUState *cpu) > +{ } > +#endif > + > /* main execution loop */ > > int cpu_exec(CPUState *cpu) > @@ -452,12 +475,8 @@ int cpu_exec(CPUState *cpu) > for(;;) { > interrupt_request = cpu->interrupt_request; > if (unlikely(interrupt_request)) { > - /* FIXME: this needs to take the iothread lock. > - * For this we need to find all places in > - * cc->cpu_exec_interrupt that can call cpu_loop_exit, > - * and call qemu_unlock_iothread_mutex() there. Else, > - * add a flag telling cpu_loop_exit() to unlock it. > - */ > + cpu_exit_loop_lock(cpu); > + > if (unlikely(cpu->singlestep_enabled & SSTEP_NOIRQ)) { > /* Mask out external interrupts for this step. */ > interrupt_request &= ~CPU_INTERRUPT_SSTEP_MASK; > @@ -503,6 +522,8 @@ int cpu_exec(CPUState *cpu) > the program flow was changed */ > next_tb = 0; > } > + > + cpu_exit_loop_lock_reset(cpu); > } > if (unlikely(cpu->exit_request)) { > cpu->exception_index = EXCP_INTERRUPT; > @@ -609,6 +630,7 @@ int cpu_exec(CPUState *cpu) > env = &x86_cpu->env; > #endif > tb_lock_reset(); > + cpu_exit_loop_lock_reset(cpu); > } > } /* for(;;) */ > > diff --git a/include/qom/cpu.h b/include/qom/cpu.h > index 1d97b63..dbe0438 100644 > --- a/include/qom/cpu.h > +++ b/include/qom/cpu.h > @@ -270,6 +270,7 @@ struct CPUState { > bool created; > bool stop; > bool stopped; > + bool cpu_loop_exit_locked; > volatile sig_atomic_t exit_request; > uint32_t interrupt_request; > int singlestep_enabled; >