From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49428) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ar4fB-0000Wx-Og for qemu-devel@nongnu.org; Fri, 15 Apr 2016 10:24:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ar4fA-0007fM-NX for qemu-devel@nongnu.org; Fri, 15 Apr 2016 10:24:01 -0400 Received: from mail-wm0-x234.google.com ([2a00:1450:400c:c09::234]:35633) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ar4fA-0007fD-HU for qemu-devel@nongnu.org; Fri, 15 Apr 2016 10:24:00 -0400 Received: by mail-wm0-x234.google.com with SMTP id a140so33785101wma.0 for ; Fri, 15 Apr 2016 07:24:00 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= Date: Fri, 15 Apr 2016 15:23:48 +0100 Message-Id: <1460730231-1184-11-git-send-email-alex.bennee@linaro.org> In-Reply-To: <1460730231-1184-1-git-send-email-alex.bennee@linaro.org> References: <1460730231-1184-1-git-send-email-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: [Qemu-devel] [RFC v1 09/12] translate-all: introduces tb_flush_safe. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: mttcg@listserver.greensocs.com, fred.konrad@greensocs.com, a.rigo@virtualopensystems.com, serge.fdrv@gmail.com, cota@braap.org Cc: qemu-devel@nongnu.org, mark.burton@greensocs.com, pbonzini@redhat.com, jan.kiszka@siemens.com, rth@twiddle.net, peter.maydell@linaro.org, claudio.fontana@huawei.com, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Peter Crosthwaite From: KONRAD Frederic tb_flush is not thread safe we definitely need to exit VCPUs to do that. This introduces tb_flush_safe which just creates an async safe work which will do a tb_flush later. This is called when we run out of space. Signed-off-by: KONRAD Frederic [AJB: merge the various tb_flush commits] Signed-off-by: Alex Bennée --- v1: - add more comments - fix build for linux-user - add log warning on linux-user --- include/exec/exec-all.h | 1 + translate-all.c | 34 +++++++++++++++++++++++++++------- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h index f695577..858055b 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -307,6 +307,7 @@ struct TBContext { void tb_free(TranslationBlock *tb); void tb_flush(CPUState *cpu); +void tb_flush_safe(CPUState *cpu); void tb_phys_invalidate(TranslationBlock *tb, tb_page_addr_t page_addr); #if defined(USE_DIRECT_JUMP) diff --git a/translate-all.c b/translate-all.c index 8e70583..874dc56 100644 --- a/translate-all.c +++ b/translate-all.c @@ -825,9 +825,30 @@ static void page_flush_tb(void) } } -/* flush all the translation blocks */ -/* XXX: tb_flush is currently not thread safe. System emulation calls it only - * with tb_lock taken or from safe_work, so no need to take tb_lock here. +#ifdef CONFIG_SOFTMMU +static void tb_flush_work(CPUState *cpu, void *opaque) +{ + tb_flush(cpu); +} +#endif + +void tb_flush_safe(CPUState *cpu) +{ +#ifdef CONFIG_SOFTMMU + async_safe_run_on_cpu(cpu, tb_flush_work, NULL); +#else + qemu_log("Safe flushing of TBs not implemented for linux-user\n"); + tb_flush(cpu); +#endif +} + +/* Flush *all* translations + * + * This invalidates all translations, lookups and caches. + * + * This is not thread save for linux-user. For softmmu targets the + * flushing is done when all vCPUs are quiescent via the + * async_safe_work mechanism */ void tb_flush(CPUState *cpu) { @@ -1183,10 +1204,9 @@ TranslationBlock *tb_gen_code(CPUState *cpu, if (unlikely(!tb)) { buffer_overflow: /* flush must be done */ - tb_flush(cpu); - /* cannot fail at this point */ - tb = tb_alloc(pc); - assert(tb != NULL); + tb_flush_safe(cpu); + tb_unlock(); + cpu_loop_exit(cpu); } gen_code_buf = tcg_ctx.code_gen_ptr; -- 2.7.4