From patchwork Tue Apr 5 15:32:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 8753091 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 E82369F3D1 for ; Tue, 5 Apr 2016 15:35:02 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 11FFC20390 for ; Tue, 5 Apr 2016 15:35:02 +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 33B232011D for ; Tue, 5 Apr 2016 15:35:01 +0000 (UTC) Received: from localhost ([::1]:37803 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1anT0O-0002Bf-9B for patchwork-qemu-devel@patchwork.kernel.org; Tue, 05 Apr 2016 11:35:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54808) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1anSy8-0006kO-5W for qemu-devel@nongnu.org; Tue, 05 Apr 2016 11:32:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1anSy6-0007EE-Sn for qemu-devel@nongnu.org; Tue, 05 Apr 2016 11:32:40 -0400 Received: from mail-wm0-x231.google.com ([2a00:1450:400c:c09::231]:34392) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1anSy6-0007E1-IQ for qemu-devel@nongnu.org; Tue, 05 Apr 2016 11:32:38 -0400 Received: by mail-wm0-x231.google.com with SMTP id l6so28820271wml.1 for ; Tue, 05 Apr 2016 08:32:38 -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 :mime-version:content-transfer-encoding; bh=6LSCzHLtgJWEzpw67p2ilRyur1ZOggdbpyYdGCqI3BA=; b=iVUkAIET8JLaHzXwuAgnJt4VMZe6x/UdC3skbJQxXUhlMNiugWvhJ4p44YBcQDrOlc +BejqomKUNwBXJWl0H10XvEUK9vyTLKbNBurHTi9xre62ikrc210KSAfQ7qkEFutUOJu YieSLsNJBTpJ0Wyv3XUqA33X5b1FKTFTDj9+g= 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:mime-version:content-transfer-encoding; bh=6LSCzHLtgJWEzpw67p2ilRyur1ZOggdbpyYdGCqI3BA=; b=aMQjfR4ZPQr4Tan4QO6121Y0CQd9pYUhlE9Dut9fU3Br//ntdrq19eYvUkZv3SAdV5 hEoftdErrTmXfb0B5dbU2cXSCu8pa696WxFsca2E08dez2Agcc5cAZDqgg+L2xFM7PbU Euv3U1UFdZOW5KcMCGZAK+L9vm6Oxu9cZZZlWr6YQEMwfDriTl7iYk1fMpLVCp3rF3Er raMXHphWeTYCX5JUVCWUSMBj9qhLXOF0rYI88ZG7Zsjun8QqHpi1s3Be28NbMZkvJV8b PB/NsWwOmE08vyO9Ae4lyGCSBXkb/f1KNKWUmtQiFj7fr0JLaTYrLNmrJRMqhKhvk/mo Mdyg== X-Gm-Message-State: AD7BkJKEom3jf5art2jswNb+XklrmXkwZrXeIw5FxO5wcvsSvOGw+k+jXOFB9zPCyupm5i67 X-Received: by 10.194.134.227 with SMTP id pn3mr15920023wjb.129.1459870353441; Tue, 05 Apr 2016 08:32:33 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id t7sm35301279wjf.39.2016.04.05.08.32.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 05 Apr 2016 08:32:31 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id E8F763E03D7; Tue, 5 Apr 2016 16:32:32 +0100 (BST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: mttcg@listserver.greensocs.com, fred.konrad@greensocs.com, a.rigo@virtualopensystems.com, serge.fdrv@gmail.com, cota@braap.org Date: Tue, 5 Apr 2016 16:32:14 +0100 Message-Id: <1459870344-16773-2-git-send-email-alex.bennee@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1459870344-16773-1-git-send-email-alex.bennee@linaro.org> References: <1459870344-16773-1-git-send-email-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::231 Cc: peter.maydell@linaro.org, claudio.fontana@huawei.com, Sergey Fedorov , Peter Crosthwaite , jan.kiszka@siemens.com, mark.burton@greensocs.com, qemu-devel@nongnu.org, pbonzini@redhat.com, =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Andreas=20F=C3=A4rber?= , rth@twiddle.net Subject: [Qemu-devel] [RFC v2 01/11] 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 [AJB: use bool] Signed-off-by: Alex Bennée --- v2 - use bool properly --- cpu-exec.c | 11 +++++------ include/exec/exec-all.h | 2 -- include/qom/cpu.h | 2 ++ translate-all.c | 6 ++---- 4 files changed, 9 insertions(+), 12 deletions(-) diff --git a/cpu-exec.c b/cpu-exec.c index 3694234..74065d9 100644 --- a/cpu-exec.c +++ b/cpu-exec.c @@ -205,10 +205,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 = false; 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); @@ -229,8 +230,6 @@ static TranslationBlock *tb_find_physical(CPUState *cpu, unsigned int h; tb_page_addr_t phys_pc, phys_page1; - 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; @@ -303,6 +302,7 @@ static TranslationBlock *tb_find_slow(CPUState *cpu, #endif /* if no translated code available, then translate it now */ + cpu->tb_invalidated_flag = false; tb = tb_gen_code(cpu, pc, cs_base, flags, 0); #ifdef CONFIG_USER_ONLY @@ -509,12 +509,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; } /* see if we can patch the calling TB. When the TB spans two pages, we cannot safely do a direct diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h index 6151a62..bbd9807 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -302,8 +302,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 b7a10f7..6931db9 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -238,6 +238,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. @@ -289,6 +290,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 56498e0..d923008 100644 --- a/translate-all.c +++ b/translate-all.c @@ -841,6 +841,7 @@ void tb_flush(CPUState *cpu) tcg_ctx.tb_ctx.nb_tbs = 0; CPU_FOREACH(cpu) { + cpu->tb_invalidated_flag = true; memset(cpu->tb_jmp_cache, 0, sizeof(cpu->tb_jmp_cache)); } @@ -1009,12 +1010,11 @@ void tb_phys_invalidate(TranslationBlock *tb, tb_page_addr_t page_addr) invalidate_page_bitmap(p); } - tcg_ctx.tb_ctx.tb_invalidated_flag = 1; - /* remove the TB from the hash list */ h = tb_jmp_cache_hash_func(tb->pc); CPU_FOREACH(cpu) { if (cpu->tb_jmp_cache[h] == tb) { + cpu->tb_invalidated_flag = true; cpu->tb_jmp_cache[h] = NULL; } } @@ -1176,8 +1176,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;