From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48300) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bIH26-0006VY-Ss for qemu-devel@nongnu.org; Wed, 29 Jun 2016 11:04:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bIH21-0000ML-Mh for qemu-devel@nongnu.org; Wed, 29 Jun 2016 11:04:05 -0400 Received: from mail-lf0-x243.google.com ([2a00:1450:4010:c07::243]:33998) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bIH21-0000Lt-ET for qemu-devel@nongnu.org; Wed, 29 Jun 2016 11:04:01 -0400 Received: by mail-lf0-x243.google.com with SMTP id l184so5370393lfl.1 for ; Wed, 29 Jun 2016 08:04:01 -0700 (PDT) References: <87a8i5e18d.fsf@linaro.org> From: Sergey Fedorov Message-ID: <5773E35F.5030806@gmail.com> Date: Wed, 29 Jun 2016 18:03:59 +0300 MIME-Version: 1.0 In-Reply-To: <87a8i5e18d.fsf@linaro.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Subject: Re: [Qemu-devel] [RFC 8/8] tcg: Make tb_flush() thread safe List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?UTF-8?Q?Alex_Benn=c3=a9e?= , Sergey Fedorov Cc: qemu-devel@nongnu.org, Peter Crosthwaite , patches@linaro.org, Paolo Bonzini , Richard Henderson On 28/06/16 19:18, Alex Bennée wrote: > Sergey Fedorov writes: > >> From: Sergey Fedorov >> >> Use async_safe_run_on_cpu() to make tb_flush() thread safe. >> >> Signed-off-by: Sergey Fedorov >> Signed-off-by: Sergey Fedorov >> --- >> translate-all.c | 12 ++++++++---- >> 1 file changed, 8 insertions(+), 4 deletions(-) >> >> diff --git a/translate-all.c b/translate-all.c >> index 3f402dfe04f5..09b1d0b0efc3 100644 >> --- a/translate-all.c >> +++ b/translate-all.c >> @@ -832,7 +832,7 @@ static void page_flush_tb(void) >> >> /* flush all the translation blocks */ >> /* XXX: tb_flush is currently not thread safe */ > ^^^ > > The comment belies a lack of confidence ;-) Nice catch! Thanks, Sergey > >> -void tb_flush(CPUState *cpu) >> +static void do_tb_flush(CPUState *cpu, void *data) >> { >> #if defined(DEBUG_FLUSH) >> printf("qemu: flush code_size=%ld nb_tbs=%d avg_tb_size=%ld\n", >> @@ -861,6 +861,11 @@ void tb_flush(CPUState *cpu) >> tcg_ctx.tb_ctx.tb_flush_count++; >> } >> >> +void tb_flush(CPUState *cpu) >> +{ >> + async_safe_run_on_cpu(cpu, do_tb_flush, NULL); >> +} >> + >> #ifdef DEBUG_TB_CHECK >> >> static void >> @@ -1163,9 +1168,8 @@ TranslationBlock *tb_gen_code(CPUState *cpu, >> buffer_overflow: >> /* flush must be done */ >> tb_flush(cpu); >> - /* cannot fail at this point */ >> - tb = tb_alloc(pc); >> - assert(tb != NULL); >> + mmap_unlock(); >> + cpu_loop_exit(cpu); >> } >> >> gen_code_buf = tcg_ctx.code_gen_ptr; > > -- > Alex Bennée