From patchwork Thu Mar 17 13:46:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: sergey.fedorov@linaro.org X-Patchwork-Id: 8611941 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 0FF739F44D for ; Thu, 17 Mar 2016 14:47:02 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3C9182026C for ; Thu, 17 Mar 2016 14:47:01 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5E5BD201F2 for ; Thu, 17 Mar 2016 14:47:00 +0000 (UTC) Received: from localhost ([::1]:35434 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agZCV-00018i-Qd for patchwork-qemu-devel@patchwork.kernel.org; Thu, 17 Mar 2016 10:46:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53110) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agYIW-0004H9-3n for qemu-devel@nongnu.org; Thu, 17 Mar 2016 09:49:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1agYIS-0008Q8-U4 for qemu-devel@nongnu.org; Thu, 17 Mar 2016 09:49:08 -0400 Received: from mail-lb0-x232.google.com ([2a00:1450:4010:c04::232]:34448) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agYIS-0008Pd-Hu for qemu-devel@nongnu.org; Thu, 17 Mar 2016 09:49:04 -0400 Received: by mail-lb0-x232.google.com with SMTP id k12so68763202lbb.1 for ; Thu, 17 Mar 2016 06:49:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=LZv/GCGnuz5iAczaAzeiP0qGPXBT7dJqU0djEevz4Wg=; b=b2Z4Mee8uhddW5f5J+vsvyb7ZVZfyjeFZ4t6YUVbxdO+U+EZ4nlYULs2HTUG7JYRYn TybWrBf/6J2C/3DdUWF9qvwIy3H8bU9/qFaweAWG4MfkAe9kuku/mUL4OgdErrX1C+si qlBq5Qj+9mVmr4Bffjawm33bBtVgsoWeDrzFU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=LZv/GCGnuz5iAczaAzeiP0qGPXBT7dJqU0djEevz4Wg=; b=DAfjiqK78TQ/39k4gJWEmDwu6Qp0aKZVNyNLLjvnYWgdsv9abiFA2c8Is69GcGDugF I5iNpeV0dTTDGVY9/inQMtKSYnk0rIECGFf0qfcqcbMV1Wz1+FwpTTJlG63i/I2SjZok 4PQdFcrk+Fv7d1thGstzdoukyGMm9oDuzbvj6x//fWTwBtGWmFct7iLYEhmqO6PQz+e4 KyMf3uTAmwivc98bOgQBVzdmfsoOVyvg3waCqko0Vkn1+LHeFnCXhpM1Qdpr446I/K0J +aM7HDK+CSwyJkG2wcfDLiZUntlrBz9jwSFP4QLNLhbdoGtoCQ3cRHYRO6uOBMcBdMFm TbjQ== X-Gm-Message-State: AD7BkJKUABmmmrA92HJtDlDbAPBaqYOeXI2pLMvscA4CLOUToNQOrmVZg4MdPGGLbQDtPd3m X-Received: by 10.112.190.4 with SMTP id gm4mr3684381lbc.74.1458222543726; Thu, 17 Mar 2016 06:49:03 -0700 (PDT) Received: from localhost.localdomain ([89.208.20.115]) by smtp.gmail.com with ESMTPSA id wj2sm1371399lbb.5.2016.03.17.06.48.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 17 Mar 2016 06:49:02 -0700 (PDT) From: sergey.fedorov@linaro.org To: qemu-devel@nongnu.org Date: Thu, 17 Mar 2016 16:46:22 +0300 Message-Id: <1458222382-6498-6-git-send-email-sergey.fedorov@linaro.org> X-Mailer: git-send-email 2.7.3 In-Reply-To: <1458222382-6498-1-git-send-email-sergey.fedorov@linaro.org> References: <1458222382-6498-1-git-send-email-sergey.fedorov@linaro.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:4010:c04::232 X-Mailman-Approved-At: Thu, 17 Mar 2016 10:44:16 -0400 Cc: Sergey Fedorov , Peter Crosthwaite , Paolo Bonzini , Sergey Fedorov , =?UTF-8?q?Andreas=20F=C3=A4rber?= , Richard Henderson Subject: [Qemu-devel] [PATCH 5/5] tcg: move tb_invalidated_flag to CPUState X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Paolo Bonzini This is a baby step towards making tb_flush thread safe. Signed-off-by: Paolo Bonzini Signed-off-by: Sergey Fedorov --- cpu-exec.c | 11 +++++------ include/exec/exec-all.h | 2 -- include/qom/cpu.h | 2 ++ translate-all.c | 3 +-- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/cpu-exec.c b/cpu-exec.c index f90482eff778..07545aa91082 100644 --- a/cpu-exec.c +++ b/cpu-exec.c @@ -195,10 +195,11 @@ static void cpu_exec_nocache(CPUState *cpu, int max_cycles, if (max_cycles > CF_COUNT_MASK) max_cycles = CF_COUNT_MASK; + cpu->tb_invalidated_flag = 0; tb = tb_gen_code(cpu, orig_tb->pc, orig_tb->cs_base, orig_tb->flags, max_cycles | CF_NOCACHE | (ignore_icount ? CF_IGNORE_ICOUNT : 0)); - tb->orig_tb = tcg_ctx.tb_ctx.tb_invalidated_flag ? NULL : orig_tb; + tb->orig_tb = cpu->tb_invalidated_flag ? NULL : orig_tb; cpu->current_tb = tb; /* execute the generated code */ trace_exec_tb_nocache(tb, tb->pc); @@ -219,8 +220,6 @@ static TranslationBlock *tb_find_physical(CPUState *cpu, tb_page_addr_t phys_pc, phys_page1; target_ulong virt_page2; - tcg_ctx.tb_ctx.tb_invalidated_flag = 0; - /* find translated block using physical mappings */ phys_pc = get_page_addr_code(env, pc); phys_page1 = phys_pc & TARGET_PAGE_MASK; @@ -288,6 +287,7 @@ static TranslationBlock *tb_find_slow(CPUState *cpu, #endif /* if no translated code available, then translate it now */ + cpu->tb_invalidated_flag = 0; tb = tb_gen_code(cpu, pc, cs_base, flags, 0); #ifdef CONFIG_USER_ONLY @@ -493,12 +493,11 @@ int cpu_exec(CPUState *cpu) tb = tb_find_fast(cpu); /* Note: we do it here to avoid a gcc bug on Mac OS X when doing it in tb_find_slow */ - if (tcg_ctx.tb_ctx.tb_invalidated_flag) { + if (cpu->tb_invalidated_flag) { /* as some TB could have been invalidated because - of memory exceptions while generating the code, we + of a tb_flush while generating the code, we must recompute the hash index here */ next_tb = 0; - tcg_ctx.tb_ctx.tb_invalidated_flag = 0; } if (qemu_loglevel_mask(CPU_LOG_EXEC)) { qemu_log("Trace %p [" TARGET_FMT_lx "] %s\n", diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h index 05a151da4a54..0ef6ea5cf6dc 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -288,8 +288,6 @@ struct TBContext { /* statistics */ int tb_flush_count; int tb_phys_invalidate_count; - - int tb_invalidated_flag; }; void tb_free(TranslationBlock *tb); diff --git a/include/qom/cpu.h b/include/qom/cpu.h index 7052eee7b78a..9538f9cc2af3 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -240,6 +240,7 @@ struct kvm_run; * @crash_occurred: Indicates the OS reported a crash (panic) for this CPU * @tcg_exit_req: Set to force TCG to stop executing linked TBs for this * CPU and return to its top level loop. + * @tb_invalidated_flag: Set to tell TCG that tb_flush has been called. * @singlestep_enabled: Flags for single-stepping. * @icount_extra: Instructions until next timer event. * @icount_decr: Number of cycles left, with interrupt flag in high bit. @@ -291,6 +292,7 @@ struct CPUState { bool stopped; bool crash_occurred; bool exit_request; + bool tb_invalidated_flag; uint32_t interrupt_request; int singlestep_enabled; int64_t icount_extra; diff --git a/translate-all.c b/translate-all.c index 1db5a914d9a3..8e1edd6bb633 100644 --- a/translate-all.c +++ b/translate-all.c @@ -843,6 +843,7 @@ void tb_flush(CPUState *cpu) tcg_ctx.tb_ctx.nb_tbs = 0; CPU_FOREACH(cpu) { + cpu->tb_invalidated_flag = 1; memset(cpu->tb_jmp_cache, 0, sizeof(cpu->tb_jmp_cache)); } @@ -1079,8 +1080,6 @@ TranslationBlock *tb_gen_code(CPUState *cpu, /* cannot fail at this point */ tb = tb_alloc(pc); assert(tb != NULL); - /* Don't forget to invalidate previous TB info. */ - tcg_ctx.tb_ctx.tb_invalidated_flag = 1; } gen_code_buf = tcg_ctx.code_gen_ptr;