From patchwork Sat Mar 16 01:57:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 780745 Delivered-To: patch@linaro.org Received: by 2002:a5d:46c1:0:b0:33e:7753:30bd with SMTP id g1csp489470wrs; Fri, 15 Mar 2024 18:59:17 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXCXGBNztStgmO7g72/TGyz6oTL8XvYDF0GnF6PGAT/x8NyEj/HRwCaRgWroAg44b8O84PXSXFfoJP6MObr+5y2 X-Google-Smtp-Source: AGHT+IFJL7nBQQt7vZvYnfgy/5BBrKIszBlq6twEOxaihaLTVYHzw9Larj1yFKU/bAkYGyeKtNXc X-Received: by 2002:a05:620a:55af:b0:789:ecac:7163 with SMTP id vr15-20020a05620a55af00b00789ecac7163mr920903qkn.57.1710554357001; Fri, 15 Mar 2024 18:59:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1710554356; cv=none; d=google.com; s=arc-20160816; b=oQZu4HSZtxQLKgMqRkoBajcJpUMa34eI6FKqrLlxw8+Akmo/A68fyOxcD2vd+8E6p/ M625irMEcZAaRSW1jV9peYFa6OUD+of9Wyw0cenoVxonTnZukBc4FzhZi7Ij1SUjLJyc HYyFvyYxYlxygxGAVEaFLrLeUp/NjfD7QQoOON+/oskjsO7Xxr1k6tBGlUtCSqqz7RRd 8rDkR0wpJpzygjT4tHnUSYw7urmNOxKMmV+cHQTh4LrMa7KjP8Ud5rRK70a0V8xQdZwE BGW0UWKByW79okuAev7BWXarrQg4wBsqNmZb4AHtU4VuIzvaRaa/E9Grq+vZj7VpqdBO tIyw== 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:cc:to :from:dkim-signature; bh=5GryAJXFnUj11zs8uoNqYE1HevxmAcx5O0dvpjg9Kdo=; fh=DfUxOGz7MnM49MBgqH5VPROGi+97fYtPWhcEZCG1Y5Q=; b=RFuI3nhpvDpBu4OBoGGi70eAkiiUXBuL1TbKWSgqe4VkD5Ns2JYBj2Gi6e1Yy89aEL xmCszgOXaTAK5YiDKLReRZthZfkYWj0vtOfFj8f4goDyRXyP/eNhODjZInYu368kKpMv EKqwldUQkcFMuP+pHdXlC1uIZmrPcdOXfw1YbGauTP0wabBLREwB3s0fbGdJv/AFIbTo m+XJ6jPV2Mc0J6vbYzWgE8rlPbER8Vmv+NHKWnDHDQPf5FSjfaw7cI15rIKj+XOSLinu U07ivrUMB4wXaAdOa8/f2OpHEXApMl5v21a4mYbw7EutOZvI2ljjkLDdrN88hTymnx+x wYtw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fr5Rd8qi; 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 y12-20020a05620a09cc00b00789d602d4b9si2140605qky.568.2024.03.15.18.59.16 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 15 Mar 2024 18:59:16 -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=fr5Rd8qi; 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 1rlJIv-0002o0-Fc; Fri, 15 Mar 2024 21:57:45 -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 1rlJIt-0002mU-Ck for qemu-devel@nongnu.org; Fri, 15 Mar 2024 21:57:43 -0400 Received: from mail-pg1-x530.google.com ([2607:f8b0:4864:20::530]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rlJIr-0000ij-6o for qemu-devel@nongnu.org; Fri, 15 Mar 2024 21:57:43 -0400 Received: by mail-pg1-x530.google.com with SMTP id 41be03b00d2f7-5cdbc4334edso1627687a12.3 for ; Fri, 15 Mar 2024 18:57:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1710554260; x=1711159060; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5GryAJXFnUj11zs8uoNqYE1HevxmAcx5O0dvpjg9Kdo=; b=fr5Rd8qizMkRpHiKVKSDyTvDZ5N5xCH0fnImn6PdBwpoCHQVTLQ419I5reLDU6gsdv 3Bjw2bcNjv+EI2M4Ksfiw3LOqW3xj4qVYAsSg5xVf7Yr4PBZN1TkQpBW4O6nDuxx5Zhi zuIuFTokXJGapIqYiCuWs1pChPYrT7KM/2Ub+bOMLgPRnRZ8AGW418Lufh5K9yst4MOK U6e+vumKfog98FepOaI3txXLvK6WJ6PIzpwPTgqtisd2j2PYhiPJoUisWXDU/WxubnCw 3nuPwIn3tifD6v5GlZbB6LNIG77M5DytM9vrthjtZyXUHLAtI4KEvdad94fLCZGCdS4B KE7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710554260; x=1711159060; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5GryAJXFnUj11zs8uoNqYE1HevxmAcx5O0dvpjg9Kdo=; b=YFWEcmR9N0MKMgomnkX4ncvTsO7WgcL8F1qy+WHfs57PPXGnHFcFCHH/1rLr0xHNgk kDUAt+6ZEnhXrmDJhKNNhTj7VDrSbZiKSogyF6eytxKD5IYs23RY+67S/jdk1Y+Xo8p3 WKLiwnk4wndhHFQZhspQN+1uaY5E+qfjrR5FVCrbh9gyc190S4cCCVg510Y0iGDhGAr+ X/r6XdPwFGjB5/hVHyXciASr62ybU1R58I8ON92ejxqRtJDCUxBIOrrFKRAqaWeLdtO5 tWo37FQ01nSdW1ZPucsojdpAb8PjEJGQ2MRDdMMzMQclcxcVCi+Q3onNX+0i4cIYl7MN LzxA== X-Gm-Message-State: AOJu0Yy0V/gHqUVoA9T0hJvxjqnGAqe+p1BI5lCZQXqBVGZm0xjBK2XK TjnSB43P/8q7OJOTrw9uRahBc2aOISXXUlm3RNz6Tlro7nXKatVXhXW2fC/i37grlrFp9DQTOS9 Y X-Received: by 2002:a17:902:7d98:b0:1dd:de0f:c01e with SMTP id a24-20020a1709027d9800b001ddde0fc01emr4439010plm.37.1710554259849; Fri, 15 Mar 2024 18:57:39 -0700 (PDT) Received: from stoup.. (173-197-098-125.biz.spectrum.com. [173.197.98.125]) by smtp.gmail.com with ESMTPSA id b3-20020a170903228300b001dd42bbb08asm4592985plh.253.2024.03.15.18.57.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Mar 2024 18:57:39 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org, alex.bennee@linaro.org Subject: [PATCH 07/22] plugins: Use emit_before_op for PLUGIN_GEN_AFTER_INSN Date: Fri, 15 Mar 2024 15:57:05 -1000 Message-Id: <20240316015720.3661236-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240316015720.3661236-1-richard.henderson@linaro.org> References: <20240316015720.3661236-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::530; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x530.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, T_SCC_BODY_TEXT_LINE=-0.01 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 --- 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 c56f104aee..8fa342b425 100644 --- a/accel/tcg/plugin-gen.c +++ b/accel/tcg/plugin-gen.c @@ -207,8 +207,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: /* @@ -614,16 +613,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) { @@ -709,11 +698,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 */ @@ -772,16 +764,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]; @@ -846,19 +871,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);