From patchwork Tue Feb 9 18:27:47 2021 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: 379370 Delivered-To: patch@linaro.org Received: by 2002:a02:b18a:0:0:0:0:0 with SMTP id t10csp485434jah; Tue, 9 Feb 2021 10:31:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJwx+1H0pB2nHWfWsvYbaWNhwafuv/xNxeNdlpP+jk4KvfUPm0K8zQJhR0/BFx+nkLIuYSFC X-Received: by 2002:a25:81c7:: with SMTP id n7mr34166105ybm.171.1612895483464; Tue, 09 Feb 2021 10:31:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612895483; cv=none; d=google.com; s=arc-20160816; b=LQHnzpEKuyl0gUm2xwwcGFPfn+q89Yb2KtOlPxDwO2c1yW3FeF01PCQiXFkuX1AuOR GwmM4fT2b0JbjIDnByUk+51ZH1/McKftUJ9khZxzQ8eAs2WPUBEpjZSTPQAPnphF2BOR 2nBfSMyPU6YezfX7t5vnhbpy+9MOTTY0XSGVPdxf8hH8sdFZG3H7908d/C+Zy8nTFojx 7MvjHocaCP3Re0CjWAuSz/T+7MqEZO4u/rGis6z1chrJDUZ8Rx3UoQNyneUvsW+5d2ER bdHM9lgVRrTE2vGKquMadXoAW/81TSbUYHuTgYjSpocMBjHKlz8JzIU6bIcDZI0tIlbh xkmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=ejLSBmEQiH4mLxCrVBrlwMdu2X7JBwiJC91YTaurGZo=; b=RnCsI8IgVT9/cHGg1nBN4KjX71YKX0oaaffKDEUNTkIj+430iyjp4tS4JdJ5z8+bdP ybqe3VVvWjcRYavRutcEYP6Yt6EfOZBtFUMe+Fd/sAv2qIxG7kIweriAfMMi612319Rk 4Gv6wFe4j58JqFbO/yVXHiK9tmKYhjP2b/aEEp+82tXrqz+JDQ1bJduaaYaXj0MiRBAI oLmK/UrMJGhUY/aVrqA1CPgf00NBh/cHnxNOpMShthKQzWRv2RKC7jVNBMUzKMfuOfFF cAa4lP3Wk2XvXAxPNBvKr8rt/Ccxkb1SHTq2OR0K7677zImfPhtFfBsV0Ckn3mDcSRPu B9nw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=v4Xmtq1g; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id x3si21871540ybn.333.2021.02.09.10.31.23 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 09 Feb 2021 10:31:23 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=v4Xmtq1g; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:38690 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9XnG-0006np-UT for patch@linaro.org; Tue, 09 Feb 2021 13:31:22 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:43384) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l9Xk6-00038l-Vl for qemu-devel@nongnu.org; Tue, 09 Feb 2021 13:28:07 -0500 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]:39818) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l9Xk4-0007qk-MM for qemu-devel@nongnu.org; Tue, 09 Feb 2021 13:28:06 -0500 Received: by mail-wr1-x431.google.com with SMTP id h12so6941456wrw.6 for ; Tue, 09 Feb 2021 10:28:04 -0800 (PST) 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=ejLSBmEQiH4mLxCrVBrlwMdu2X7JBwiJC91YTaurGZo=; b=v4Xmtq1gJdLVt3rca/xSQKRIVOBb3Y3fQ2RPC5hYgNysb+D7mDKuL5cbb8EHSSHwC6 i8L4E/XO7bD8NHpCVwg1I91wukMQItLHncmQ1je4LfmVfnP4ajENSenjBvkglcGQrGyS L9h1WUXgaoI9tSHHnNEp2DbKu75C3YK9Nnx+aFzyXD4N9mcn6OkLjD4O+NLbFMUCMaMI 3We6TVc/KDr0K/mZn9LecgsyqCMswqShvT5G3Sc2aES16qItEkjCh17wssHX/RxVB5Wc OGmI6yfxKjp1cc5/abLt8o/BMJjbB4xG5czwWoUlV4QImiHJdYi+LZVErrC1bqB1wExq ZO3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ejLSBmEQiH4mLxCrVBrlwMdu2X7JBwiJC91YTaurGZo=; b=UaNZy0F1EzBeni0mPk9h1F923CFmIuPk+AHyWyxnjeiZbzcZg5Gzr06KvvUZX3cLyM ejKisHVAHDt6v0zdE9LGUS9OytB+JAmIhX5xgJHD4pveRNDN+kFgTJ/s+txTZAusbMRc qRQFs3IeYDi0KXI8HRSjkEMo8IvlN3d5ZdnP+Q6fPqpAZkBpSC/7qrInn3XO1SkwUEVg Rz3FPlX3YETHzTt/81W7msHMh3Sw5b0KavFzkiwgmiYwFDmE9h3qkdgqmukUn6yiXtqc B0uE03isHzJ/dHyoiRm5EkEH+7yaujqOIGX4XPhhxvemWfugaMjnISq4IgPhw9BMS4qy SD6w== X-Gm-Message-State: AOAM533Pwt0fcd00FVKlos6lSqi9a/7SjIXV5m7ffD+3oeVWAb96P4z+ 5+T0Z1NnRpA8AHc7m50Urd0ZPQ== X-Received: by 2002:adf:f68e:: with SMTP id v14mr26750428wrp.273.1612895283368; Tue, 09 Feb 2021 10:28:03 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id c22sm180528wrb.91.2021.02.09.10.27.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Feb 2021 10:27:57 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id D236A1FF99; Tue, 9 Feb 2021 18:27:51 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v1 11/12] accel/tcg: allow plugin instrumentation to be disable via cflags Date: Tue, 9 Feb 2021 18:27:47 +0000 Message-Id: <20210209182749.31323-12-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210209182749.31323-1-alex.bennee@linaro.org> References: <20210209182749.31323-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::431; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x431.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Henderson , robhenry@microsoft.com, aaron@os.amperecomputing.com, cota@braap.org, Paolo Bonzini , kuhn.chenqun@huawei.com, =?utf-8?q?Alex_Benn?= =?utf-8?b?w6ll?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" When icount is enabled and we recompile an MMIO access we end up double counting the instruction execution. To avoid this we introduce the CF_NOINSTR cflag which disables instrumentation for the next TB. As this is part of the hashed compile flags we will only execute the generated TB while coming out of a cpu_io_recompile. While we are at it delete the old TODO. We might as well keep the translation handy as it's likely you will repeatedly hit it on each MMIO access. Reported-by: Aaron Lindsay Signed-off-by: Alex Bennée --- include/exec/exec-all.h | 3 ++- accel/tcg/translate-all.c | 17 ++++++++--------- accel/tcg/translator.c | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) -- 2.20.1 Reviewed-by: Richard Henderson diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h index e08179de34..ebf015e22d 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -454,6 +454,7 @@ struct TranslationBlock { uint32_t cflags; /* compile flags */ #define CF_COUNT_MASK 0x00007fff #define CF_LAST_IO 0x00008000 /* Last insn may be an IO access. */ +#define CF_NOINSTR 0x00010000 /* Disable instrumentation of TB */ #define CF_USE_ICOUNT 0x00020000 #define CF_INVALID 0x00040000 /* TB is stale. Set with @jmp_lock held */ #define CF_PARALLEL 0x00080000 /* Generate code for a parallel context */ @@ -461,7 +462,7 @@ struct TranslationBlock { #define CF_CLUSTER_SHIFT 24 /* cflags' mask for hashing/comparison */ #define CF_HASH_MASK \ - (CF_COUNT_MASK | CF_LAST_IO | CF_USE_ICOUNT | CF_PARALLEL | CF_CLUSTER_MASK) + (CF_COUNT_MASK | CF_LAST_IO | CF_NOINSTR | CF_USE_ICOUNT | CF_PARALLEL | CF_CLUSTER_MASK) /* Per-vCPU dynamic tracing state used to generate this TB */ uint32_t trace_vcpu_dstate; diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 27b3042f1d..3dee698457 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -2398,7 +2398,8 @@ void tb_check_watchpoint(CPUState *cpu, uintptr_t retaddr) } #ifndef CONFIG_USER_ONLY -/* in deterministic execution mode, instructions doing device I/Os +/* + * In deterministic execution mode, instructions doing device I/Os * must be at the end of the TB. * * Called by softmmu_template.h, with iothread mutex not held. @@ -2429,19 +2430,17 @@ void cpu_io_recompile(CPUState *cpu, uintptr_t retaddr) n = 2; } - /* Generate a new TB executing the I/O insn. */ - cpu->cflags_next_tb = curr_cflags() | CF_LAST_IO | n; + /* + * Exit the loop and potentially generate a new TB executing the + * just the I/O insns. We also disable instrumentation so we don't + * double count the instruction. + */ + cpu->cflags_next_tb = curr_cflags() | CF_NOINSTR | CF_LAST_IO | n; qemu_log_mask_and_addr(CPU_LOG_EXEC, tb->pc, "cpu_io_recompile: rewound execution of TB to " TARGET_FMT_lx "\n", tb->pc); - /* TODO: If env->pc != tb->pc (i.e. the faulting instruction was not - * the first in the TB) then we end up generating a whole new TB and - * repeating the fault, which is horribly inefficient. - * Better would be to execute just this insn uncached, or generate a - * second new TB. - */ cpu_loop_exit_noexc(cpu); } diff --git a/accel/tcg/translator.c b/accel/tcg/translator.c index a49a794065..14d1ea795d 100644 --- a/accel/tcg/translator.c +++ b/accel/tcg/translator.c @@ -58,7 +58,7 @@ void translator_loop(const TranslatorOps *ops, DisasContextBase *db, ops->tb_start(db, cpu); tcg_debug_assert(db->is_jmp == DISAS_NEXT); /* no early exit */ - plugin_enabled = plugin_gen_tb_start(cpu, tb); + plugin_enabled = !(tb_cflags(db->tb) & CF_NOINSTR) && plugin_gen_tb_start(cpu, tb); while (true) { db->num_insns++;