From patchwork Wed Apr 24 23:02:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 791568 Delivered-To: patch@linaro.org Received: by 2002:a5d:4884:0:b0:346:15ad:a2a with SMTP id g4csp1096529wrq; Wed, 24 Apr 2024 16:04:44 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUjFNg5+9F9PXOz+Yeo+jTwhl45ggNT/8quGU0ySGEVuiP7ABOk+f9IC5ylSj9gcH8cu45uYtE2jSM6iSHmPUob X-Google-Smtp-Source: AGHT+IGvnkWCtsVB2LdJud+WFwJ+UPAfziFVO2jHnf1SQPAc0+0N+W9eoQv+3/PLb+eSwgC4kxEo X-Received: by 2002:a05:6122:1d9f:b0:4c9:f704:38c with SMTP id gg31-20020a0561221d9f00b004c9f704038cmr4432490vkb.11.1713999883811; Wed, 24 Apr 2024 16:04:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1713999883; cv=none; d=google.com; s=arc-20160816; b=ftLJhEUFlPzyCn3e5G2X7zzK9HlJvoWao1DO0L4e0OIQ4jGTHX6U5lplxvD257EAsA urWIDm5MCdE3XXzQYdVMhWCeRvgTGh+6FKQK4NIjEnUBFHuIo3nj1gJ/SG/pAa5nzUrf 2g4m7FpXnJvhqPDFI04RdYTBLxl9GZPHeBSEwJzeer3x0OPclPS8hRxXzFrDDP68luCZ pRu6klRwyS1HTUXlU9FqhXTNq+44uc040Rnu8LTAsmBd2M4f9OtVdnslha1cV89bcjzn gclAXy7Qs9dhV3uFYXQW5A+D5q7FtotL21Dzhl8C/c+qt8XEolI3Iw/QwwE+60dzdnNO zijg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=2G4bfhkGtHkTpReC7gmCGCR5um+WwFsm5xLqETkyRYk=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=p5J1vUMlyM4ma/ourdn/yN75D4dwP7HLEKwZ7TCZJr7m2zFL9py+/qd1kQTZA6aobn s5m8C+RSZLyLZGixMDw7kch5aNX6+mdGkVS0I4HvEZKY/GfrAi1zYCrWAScu/JQ2M5IA HLc1eVEIHOypme3xTBgfzDfNuaofRRCR0gNxjACIXMzPZ34JWyaMVr86SFWhB/6ZOMpY 5EzFmxTxD0GdgutE61L4UhqZY0yaY7a+H1BN+ORg34zuWmNYsJ4qor8NCbzUJjceIpdq n3WhkkOn2rbmJLYH616mXoLtofEdRlZiCkY796Em6Lbm2uZ8wRPExG0f1faq3YUpo3/4 wTuQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MS+I9jIk; 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=pass (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 bi32-20020a05612218a000b004deb85efc31si638176vkb.257.2024.04.24.16.04.43 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 24 Apr 2024 16:04:43 -0700 (PDT) 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=pass header.i=@linaro.org header.s=google header.b=MS+I9jIk; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rzldO-0003jv-Gw; Wed, 24 Apr 2024 19:02:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rzldM-0003hw-Mg for qemu-devel@nongnu.org; Wed, 24 Apr 2024 19:02:36 -0400 Received: from mail-pg1-x535.google.com ([2607:f8b0:4864:20::535]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rzldK-0002d1-VR for qemu-devel@nongnu.org; Wed, 24 Apr 2024 19:02:36 -0400 Received: by mail-pg1-x535.google.com with SMTP id 41be03b00d2f7-5dbcfa0eb5dso322302a12.3 for ; Wed, 24 Apr 2024 16:02:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1713999754; x=1714604554; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=2G4bfhkGtHkTpReC7gmCGCR5um+WwFsm5xLqETkyRYk=; b=MS+I9jIk0xXiKX8hk8xvKBNSzgSuRwkC9ZaIjTtxlLob8eS3Am97ZlimqbmjsmI7aT YWonRnwtLTpJ/+tD1erKzIZ1TQPegrDsrbrhAqVw3JkXZ45YEyenGSlYeHL0TXT/BKtk SKJ8nqoswHIGH5ZmEEtSMZRclOFwMwkaHOc7+EuknE8MMG77604b07YQgyyxrj98gzQn tFm2wDySM4h2B6CYda05uCHJ1oNpA4FMizCCBeV5KN7GsG7wE0S/7cK/NThkDn6GgXkc o/DKxjyuK0AsGQp+QM2yurVwRHFBxnvsa/xNA/8P/9O4bg3szMK5JvJfPxbaU0788gNB pAhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713999754; x=1714604554; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2G4bfhkGtHkTpReC7gmCGCR5um+WwFsm5xLqETkyRYk=; b=CwCvrGxBOj9b3HKjnAPBqoypRAc9QWUs9skbKpE9CnfwVxb8/V6pfKqxckk64KoXbq x8bKPFBEsu8DEPsotbALWwvyb4Edz/SYI0w1OCODFpI+luOrGtV6HVYYYZRCSfXx6ZN8 8fQB0ha0042urk6DKnvi1yrkqMFQliKl3f8SjRyr95FUj3mSGHDuG9Z/ta1enUutUXj7 ENueJaSFxKOuQXjDOnsDrBalmmS56//dL5eCSm9OFA8qSL/VJ4tIwTEgwLhNJPv+AaBN e7aijKs8f4kjBJr/EcDWEsWzXoktdekIffWbDrEy2Ez8tfh9P9XXwhAqBQ+pSh7gI7S1 cQsQ== X-Gm-Message-State: AOJu0YxO/9/fuNqSCj+wnMGplOQ8NLHWtyGvu1Xc9j3CiIMXmR/hVU1i TGukkZwBljU8Nr1jOse6cyYastmKgojJSqj/MBSmM/Xa1xFELXtM7fZjwtdHRzjo1qbmM0RDOGg 0 X-Received: by 2002:a05:6a20:3252:b0:1a9:5e1f:8485 with SMTP id hm18-20020a056a20325200b001a95e1f8485mr3885592pzc.31.1713999753608; Wed, 24 Apr 2024 16:02:33 -0700 (PDT) Received: from stoup.. ([156.19.246.23]) by smtp.gmail.com with ESMTPSA id h5-20020a056a00000500b006ed4aa9d5c0sm11981405pfk.188.2024.04.24.16.02.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Apr 2024 16:02:33 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v3 06/20] plugins: Use emit_before_op for PLUGIN_GEN_AFTER_INSN Date: Wed, 24 Apr 2024 16:02:10 -0700 Message-Id: <20240424230224.941028-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240424230224.941028-1-richard.henderson@linaro.org> References: <20240424230224.941028-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::535; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x535.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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Introduce a new plugin_cb op and migrate one operation. By using emit_before_op, we do not need to emit opcodes early and modify them later -- we can simply emit the final set of opcodes once. Signed-off-by: Richard Henderson Reviewed-by: Pierrick Bouvier --- include/tcg/tcg-op-common.h | 1 + include/tcg/tcg-opc.h | 1 + accel/tcg/plugin-gen.c | 74 +++++++++++++++++++++---------------- tcg/tcg-op.c | 5 +++ 4 files changed, 50 insertions(+), 31 deletions(-) diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h index 2d932a515e..9de5a7f280 100644 --- a/include/tcg/tcg-op-common.h +++ b/include/tcg/tcg-op-common.h @@ -74,6 +74,7 @@ void tcg_gen_goto_tb(unsigned idx); */ void tcg_gen_lookup_and_goto_ptr(void); +void tcg_gen_plugin_cb(unsigned from); void tcg_gen_plugin_cb_start(unsigned from, unsigned type, unsigned wr); void tcg_gen_plugin_cb_end(void); diff --git a/include/tcg/tcg-opc.h b/include/tcg/tcg-opc.h index b80227fa1c..3b7cb2bce1 100644 --- a/include/tcg/tcg-opc.h +++ b/include/tcg/tcg-opc.h @@ -197,6 +197,7 @@ DEF(exit_tb, 0, 0, 1, TCG_OPF_BB_EXIT | TCG_OPF_BB_END) DEF(goto_tb, 0, 0, 1, TCG_OPF_BB_EXIT | TCG_OPF_BB_END) DEF(goto_ptr, 0, 1, 0, TCG_OPF_BB_EXIT | TCG_OPF_BB_END) +DEF(plugin_cb, 0, 0, 1, TCG_OPF_NOT_PRESENT) DEF(plugin_cb_start, 0, 0, 3, TCG_OPF_NOT_PRESENT) DEF(plugin_cb_end, 0, 0, 0, TCG_OPF_NOT_PRESENT) diff --git a/accel/tcg/plugin-gen.c b/accel/tcg/plugin-gen.c index 4b488943ff..4b02c0bfbf 100644 --- a/accel/tcg/plugin-gen.c +++ b/accel/tcg/plugin-gen.c @@ -201,8 +201,7 @@ static void plugin_gen_empty_callback(enum plugin_gen_from from) { switch (from) { case PLUGIN_GEN_AFTER_INSN: - gen_wrapped(from, PLUGIN_GEN_DISABLE_MEM_HELPER, - gen_empty_mem_helper); + tcg_gen_plugin_cb(from); break; case PLUGIN_GEN_FROM_INSN: /* @@ -608,16 +607,6 @@ static void inject_mem_enable_helper(struct qemu_plugin_tb *ptb, inject_mem_helper(begin_op, arr); } -static void inject_mem_disable_helper(struct qemu_plugin_insn *plugin_insn, - TCGOp *begin_op) -{ - if (likely(!plugin_insn->mem_helper)) { - rm_ops(begin_op); - return; - } - inject_mem_helper(begin_op, NULL); -} - /* called before finishing a TB with exit_tb, goto_tb or goto_ptr */ void plugin_gen_disable_mem_helpers(void) { @@ -703,11 +692,14 @@ static void plugin_gen_enable_mem_helper(struct qemu_plugin_tb *ptb, inject_mem_enable_helper(ptb, insn, begin_op); } -static void plugin_gen_disable_mem_helper(struct qemu_plugin_tb *ptb, - TCGOp *begin_op, int insn_idx) +static void gen_disable_mem_helper(struct qemu_plugin_tb *ptb, + struct qemu_plugin_insn *insn) { - struct qemu_plugin_insn *insn = g_ptr_array_index(ptb->insns, insn_idx); - inject_mem_disable_helper(insn, begin_op); + if (insn->mem_helper) { + tcg_gen_st_ptr(tcg_constant_ptr(0), tcg_env, + offsetof(CPUState, plugin_mem_cbs) - + offsetof(ArchCPU, env)); + } } /* #define DEBUG_PLUGIN_GEN_OPS */ @@ -766,16 +758,49 @@ static void pr_ops(void) static void plugin_gen_inject(struct qemu_plugin_tb *plugin_tb) { - TCGOp *op; + TCGOp *op, *next; int insn_idx = -1; pr_ops(); - QTAILQ_FOREACH(op, &tcg_ctx->ops, link) { + /* + * While injecting code, we cannot afford to reuse any ebb temps + * that might be live within the existing opcode stream. + * The simplest solution is to release them all and create new. + */ + memset(tcg_ctx->free_temps, 0, sizeof(tcg_ctx->free_temps)); + + QTAILQ_FOREACH_SAFE(op, &tcg_ctx->ops, link, next) { switch (op->opc) { case INDEX_op_insn_start: insn_idx++; break; + + case INDEX_op_plugin_cb: + { + enum plugin_gen_from from = op->args[0]; + struct qemu_plugin_insn *insn = NULL; + + if (insn_idx >= 0) { + insn = g_ptr_array_index(plugin_tb->insns, insn_idx); + } + + tcg_ctx->emit_before_op = op; + + switch (from) { + case PLUGIN_GEN_AFTER_INSN: + assert(insn != NULL); + gen_disable_mem_helper(plugin_tb, insn); + break; + default: + g_assert_not_reached(); + } + + tcg_ctx->emit_before_op = NULL; + tcg_op_remove(tcg_ctx, op); + break; + } + case INDEX_op_plugin_cb_start: { enum plugin_gen_from from = op->args[0]; @@ -840,19 +865,6 @@ static void plugin_gen_inject(struct qemu_plugin_tb *plugin_tb) break; } - case PLUGIN_GEN_AFTER_INSN: - { - g_assert(insn_idx >= 0); - - switch (type) { - case PLUGIN_GEN_DISABLE_MEM_HELPER: - plugin_gen_disable_mem_helper(plugin_tb, op, insn_idx); - break; - default: - g_assert_not_reached(); - } - break; - } default: g_assert_not_reached(); } diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c index aa6bc6f57d..0f2026c91c 100644 --- a/tcg/tcg-op.c +++ b/tcg/tcg-op.c @@ -312,6 +312,11 @@ void tcg_gen_mb(TCGBar mb_type) } } +void tcg_gen_plugin_cb(unsigned from) +{ + tcg_gen_op1(INDEX_op_plugin_cb, from); +} + void tcg_gen_plugin_cb_start(unsigned from, unsigned type, unsigned wr) { tcg_gen_op3(INDEX_op_plugin_cb_start, from, type, wr);