From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37975) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agxZU-00048x-Hg for qemu-devel@nongnu.org; Fri, 18 Mar 2016 12:48:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1agxZR-0004hM-85 for qemu-devel@nongnu.org; Fri, 18 Mar 2016 12:48:20 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39618) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agxZR-0004hH-0H for qemu-devel@nongnu.org; Fri, 18 Mar 2016 12:48:17 -0400 References: <1458317932-1875-1-git-send-email-alex.bennee@linaro.org> <1458317932-1875-11-git-send-email-alex.bennee@linaro.org> From: Paolo Bonzini Message-ID: <56EC314B.2030903@redhat.com> Date: Fri, 18 Mar 2016 17:48:11 +0100 MIME-Version: 1.0 In-Reply-To: <1458317932-1875-11-git-send-email-alex.bennee@linaro.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [RFC v1 10/11] tcg: grab iothread lock in cpu-exec interrupt handling List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?UTF-8?Q?Alex_Benn=c3=a9e?= , mttcg@greensocs.com, fred.konrad@greensocs.com, a.rigo@virtualopensystems.com, serge.fdrv@gmail.com, cota@braap.org Cc: Richard Henderson , mark.burton@greensocs.com, qemu-devel@nongnu.org, =?UTF-8?Q?Andreas_F=c3=a4rber?= , Peter Crosthwaite On 18/03/2016 17:18, Alex Benn=C3=A9e wrote: > From: "Emilio G. Cota" >=20 > Signed-off-by: Emilio G. Cota > Signed-off-by: Alex Benn=C3=A9e >=20 > --- > v1 (ajb) > - pulled from emilio/mttcg series > --- > cpu-exec.c | 33 +++++++++++++++++++++++++++------ > include/qom/cpu.h | 1 + > 2 files changed, 28 insertions(+), 6 deletions(-) >=20 > diff --git a/cpu-exec.c b/cpu-exec.c > index 76891fd..6acaf25 100644 > --- a/cpu-exec.c > +++ b/cpu-exec.c > @@ -351,6 +351,29 @@ static void cpu_handle_debug_exception(CPUState *c= pu) > cc->debug_excp_handler(cpu); > } > =20 > +#ifdef CONFIG_SOFTMMU > +static inline void cpu_exit_loop_lock(CPUState *cpu) > +{ > + qemu_mutex_lock_iothread(); > + cpu->cpu_loop_exit_locked =3D true; > +} > + > +static inline void cpu_exit_loop_lock_reset(CPUState *cpu) > +{ > + if (cpu->cpu_loop_exit_locked) { > + cpu->cpu_loop_exit_locked =3D false; > + qemu_mutex_unlock_iothread(); > + } > +} In the meanwhile we got qemu_mutex_iothread_locked(), so these two inlines are not necessary anymore. 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 */ > =20 > int cpu_exec(CPUState *cpu) > @@ -450,12 +473,7 @@ int cpu_exec(CPUState *cpu) > for(;;) { > interrupt_request =3D 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_e= xit, > - * and call qemu_unlock_iothread_mutex() there. E= lse, > - * add a flag telling cpu_loop_exit() to unlock it= . > - */ > + cpu_exit_loop_lock(cpu); > =20 > if (unlikely(cpu->singlestep_enabled & SSTEP_NOIRQ= )) { > /* Mask out external interrupts for this step.= */ > @@ -510,6 +528,8 @@ int cpu_exec(CPUState *cpu) > next_tb =3D 0; > } > =20 > + cpu_exit_loop_lock_reset(cpu); > + > } > if (unlikely(cpu->exit_request > || replay_has_interrupt())) { > @@ -630,6 +650,7 @@ int cpu_exec(CPUState *cpu) > =20 > cpu->can_do_io =3D 1; > tb_lock_reset(); > + cpu_exit_loop_lock_reset(cpu); > } > } /* for(;;) */ > =20 > diff --git a/include/qom/cpu.h b/include/qom/cpu.h > index d6cb7b8..954d97d 100644 > --- a/include/qom/cpu.h > +++ b/include/qom/cpu.h > @@ -295,6 +295,7 @@ struct CPUState { > bool crash_occurred; > bool exit_request; > bool tb_invalidated_flag; > + bool cpu_loop_exit_locked; > uint32_t interrupt_request; > int singlestep_enabled; > int64_t icount_extra; >=20