From patchwork Sat Mar 16 01:57:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 780755 Delivered-To: patch@linaro.org Received: by 2002:a5d:46c1:0:b0:33e:7753:30bd with SMTP id g1csp489623wrs; Fri, 15 Mar 2024 18:59:57 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVGXEda0fFirDiGaxbXt3lf+CtFS8uYHdWTEIW+defaXKZ6wionBOGezbb1ZcHxXzzvmWrvb3U1dK0JfGX7HoTt X-Google-Smtp-Source: AGHT+IFwPBwg2nE/msTMwY700vQSx7SWG5/onwH0UicV3jPZIcYycAMqoBd/abQ02p5tUln+YuAr X-Received: by 2002:a05:622a:90:b0:42e:58c6:bc9e with SMTP id o16-20020a05622a009000b0042e58c6bc9emr6196118qtw.60.1710554396752; Fri, 15 Mar 2024 18:59:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1710554396; cv=none; d=google.com; s=arc-20160816; b=Y0wIbDqJA5us0TLImA+x/IbANR+9PiCCQ4M0veqwNiwt7UE87Jd6wkBd0qavkTGoSw 9dVtePGoksxQNYvfOrlLN8QlMvlbPDaVB+xCXnJAZ3oIWGFJOWv+HlrYlzpLl9PN/wAO FSATYrU5X658Hf+FivHo0ImjD9FLfLcu31heXm7Kg73pQ/jkIRVP5zURwBjl5UOmvXBe A52RAXk733TVZ8fQUrQkbVX0nT9FnNdhuXArxMhpKltYD7JoPo/sp7cuyO20z4XMMs7r WyodmGlfgjq7ZEl8mwmOmiozOu8PdADbv+ltqq2/CN4fp0Wj/fMAEjLy1y8nBRk1KB+7 PoOQ== 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=aXNCxUw+xNH5pFREtrweHMcItwOMy2358ghWL5eYh0A=; fh=DfUxOGz7MnM49MBgqH5VPROGi+97fYtPWhcEZCG1Y5Q=; b=XFjELszCV3IqwkcVzmb8mV9AAY1QepQ4Fb+MbaScW5U9Fy/8Xk7+6bRvE1EjBFDZs4 3oU0pzFwNXQnz8AMSJ6mIQoXtxyVkGQUuBwpw5HOs0jQKGPLX0lgNIQw/zSGLQ3tfOml rn0S/152wMLFelWmk1eeM83jQ9UXi0QxRFgRgKL6ZF+DcmyWA7DW5LVc/ewYD/zTed2k /FyuFlRNwdbmJstqFAFvV+nSjyR+qAkNQupqhrCDnVP7Qt3BP7L2YLBm1Rgqk2saFP/U XK5ruG0ozJ8mB4t7q0ejBJvsYsLXEPA6l96qn5OS3RFRYel4m+05eYP1ss2wf/A+jqb6 YCOw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VWyWNssJ; 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 j7-20020a05622a038700b0042dff81e402si4912937qtx.471.2024.03.15.18.59.56 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 15 Mar 2024 18:59:56 -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=VWyWNssJ; 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 1rlJJQ-00032Q-TD; Fri, 15 Mar 2024 21:58:16 -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 1rlJJE-0002xO-7W for qemu-devel@nongnu.org; Fri, 15 Mar 2024 21:58:05 -0400 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rlJJ9-0000md-Rb for qemu-devel@nongnu.org; Fri, 15 Mar 2024 21:58:03 -0400 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1def59b537cso8376075ad.2 for ; Fri, 15 Mar 2024 18:57:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1710554278; x=1711159078; 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=aXNCxUw+xNH5pFREtrweHMcItwOMy2358ghWL5eYh0A=; b=VWyWNssJ4rLZ6EAcfD2JJO6Rrc+YuJA6pYt9il/iy3rtihEEeR+96ecZ5VMc/ih49W 3yHGrIox1ox1NpdsrhrmdXpzzlHsQX8nhFzkg9dIQ2Kguj8C2Feyoc+aAVRvUTUMdtmA oDRwf9RPQmJQchdTH6lFccbKBlL4c020a5rI2o53VBrg500guxg9wJCWJ8V03diV1yDA 2AkOPI8FTl7IYfkT/ZRsQuGDnd2Sq5ircz0Rmxjufwx3m/90nFpqf2CGlIC5irjrZHJ6 uz4yO1JX14/dD5I80U/nr13PwwBYf0KhFIhrJx8xtt+Xe32sYSK0VNVuXgXvYHIRfiMG a3jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710554278; x=1711159078; 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=aXNCxUw+xNH5pFREtrweHMcItwOMy2358ghWL5eYh0A=; b=p0bfvRvfhoRyFWACeoE6svKNeChk+Ucwn/SjsZG3BF1PQLLmlIqqaNGZznrY8UcJCl 2r0//0vAVMd6AbJart7SkD2zNkLVg/3rnVT4WYZTdjGNb3sOVX1YiM7XmAzyvJSgWhin CFx3IBXTCQ+K5MnlDQTdMQolEwcLtnTfS6YMcAq2X1CvyP4PSoSIRr2TkmS+MKoM98o3 fqCAAght16zuYh+AIRw5AruNlq1HJm5T8Ur113Wer/+ZKQSL498S9OvGvkwCSEXK2iOl aSJ3OknuzA+9oby475Ay4jncujtqZApASUr4kP3D/1a2B0MF3FX+bneT6j8LilckpZQs 32kw== X-Gm-Message-State: AOJu0YyDHeyo7lO5HiiRnqNVz9i6KYOgy+9Hf96DA+eJ9USF/vtVXD/P 7YXaAaRo5wrhz6PzL7UoKyadq6jXVnyMq4idevilgOmgoOiKhbVCqQhlz+KkyL+bCSJtqGNUqca W X-Received: by 2002:a17:902:e54c:b0:1dd:a33f:5916 with SMTP id n12-20020a170902e54c00b001dda33f5916mr5630078plf.4.1710554278476; Fri, 15 Mar 2024 18:57:58 -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.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Mar 2024 18:57:57 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org, alex.bennee@linaro.org Subject: [PATCH 17/22] plugins: Replace pr_ops with a proper debug dump flag Date: Fri, 15 Mar 2024 15:57:15 -1000 Message-Id: <20240316015720.3661236-18-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::634; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x634.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 The DEBUG_PLUGIN_GEN_OPS ifdef is replaced with "-d op_plugin". The second pr_ops call can be obtained with "-d op". Signed-off-by: Richard Henderson Reviewed-by: Pierrick Bouvier --- include/qemu/log.h | 1 + include/tcg/tcg.h | 1 + accel/tcg/plugin-gen.c | 68 ++++++++---------------------------------- tcg/tcg.c | 29 +++++++++++++++++- util/log.c | 4 +++ 5 files changed, 46 insertions(+), 57 deletions(-) diff --git a/include/qemu/log.h b/include/qemu/log.h index df59bfabcd..e10e24cd4f 100644 --- a/include/qemu/log.h +++ b/include/qemu/log.h @@ -36,6 +36,7 @@ bool qemu_log_separate(void); #define LOG_STRACE (1 << 19) #define LOG_PER_THREAD (1 << 20) #define CPU_LOG_TB_VPU (1 << 21) +#define LOG_TB_OP_PLUGIN (1 << 22) /* Lock/unlock output. */ diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h index df66e8f012..753d7ca3e0 100644 --- a/include/tcg/tcg.h +++ b/include/tcg/tcg.h @@ -1065,5 +1065,6 @@ static inline const TCGOpcode *tcg_swap_vecop_list(const TCGOpcode *n) } bool tcg_can_emit_vecop_list(const TCGOpcode *, TCGType, unsigned); +void tcg_dump_ops(TCGContext *s, FILE *f, bool have_prefs); #endif /* TCG_H */ diff --git a/accel/tcg/plugin-gen.c b/accel/tcg/plugin-gen.c index 6f0731b479..10d917abd3 100644 --- a/accel/tcg/plugin-gen.c +++ b/accel/tcg/plugin-gen.c @@ -44,6 +44,7 @@ */ #include "qemu/osdep.h" #include "qemu/plugin.h" +#include "qemu/log.h" #include "cpu.h" #include "tcg/tcg.h" #include "tcg/tcg-temp-internal.h" @@ -58,6 +59,7 @@ # define CONFIG_SOFTMMU_GATE 0 #endif +/* Update plugin_from_name in tcg.c. */ enum plugin_gen_from { PLUGIN_GEN_FROM_TB, PLUGIN_GEN_FROM_INSN, @@ -192,66 +194,21 @@ static void gen_mem_cb(struct qemu_plugin_dyn_cb *cb, tcg_temp_free_i32(cpu_index); } -/* #define DEBUG_PLUGIN_GEN_OPS */ -static void pr_ops(void) -{ -#ifdef DEBUG_PLUGIN_GEN_OPS - TCGOp *op; - int i = 0; - - QTAILQ_FOREACH(op, &tcg_ctx->ops, link) { - const char *name = ""; - const char *type = ""; - - if (op->opc == INDEX_op_plugin_cb_start) { - switch (op->args[0]) { - case PLUGIN_GEN_FROM_TB: - name = "tb"; - break; - case PLUGIN_GEN_FROM_INSN: - name = "insn"; - break; - case PLUGIN_GEN_FROM_MEM: - name = "mem"; - break; - case PLUGIN_GEN_AFTER_INSN: - name = "after insn"; - break; - default: - break; - } - switch (op->args[1]) { - case PLUGIN_GEN_CB_UDATA: - type = "udata"; - break; - case PLUGIN_GEN_CB_INLINE: - type = "inline"; - break; - case PLUGIN_GEN_CB_MEM: - type = "mem"; - break; - case PLUGIN_GEN_ENABLE_MEM_HELPER: - type = "enable mem helper"; - break; - case PLUGIN_GEN_DISABLE_MEM_HELPER: - type = "disable mem helper"; - break; - default: - break; - } - } - printf("op[%2i]: %s %s %s\n", i, tcg_op_defs[op->opc].name, name, type); - i++; - } -#endif -} - static void plugin_gen_inject(struct qemu_plugin_tb *plugin_tb) { TCGOp *op, *next; int insn_idx = -1; - pr_ops(); + if (unlikely(qemu_loglevel_mask(LOG_TB_OP_PLUGIN) + && qemu_log_in_addr_range(plugin_tb->vaddr))) { + FILE *logfile = qemu_log_trylock(); + if (logfile) { + fprintf(logfile, "OP before plugin injection:\n"); + tcg_dump_ops(tcg_ctx, logfile, false); + fprintf(logfile, "\n"); + qemu_log_unlock(logfile); + } + } /* * While injecting code, we cannot afford to reuse any ebb temps @@ -389,7 +346,6 @@ static void plugin_gen_inject(struct qemu_plugin_tb *plugin_tb) break; } } - pr_ops(); } bool plugin_gen_tb_start(CPUState *cpu, const DisasContextBase *db, diff --git a/tcg/tcg.c b/tcg/tcg.c index 363a065e28..d248c52e96 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -2540,6 +2540,15 @@ static const char bswap_flag_name[][6] = { [TCG_BSWAP_IZ | TCG_BSWAP_OS] = "iz,os", }; +#ifdef CONFIG_PLUGIN +static const char * const plugin_from_name[] = { + "from-tb", + "from-insn", + "after-insn", + "after-tb", +}; +#endif + static inline bool tcg_regset_single(TCGRegSet d) { return (d & (d - 1)) == 0; @@ -2558,7 +2567,7 @@ static inline TCGReg tcg_regset_first(TCGRegSet d) #define ne_fprintf(...) \ ({ int ret_ = fprintf(__VA_ARGS__); ret_ >= 0 ? ret_ : 0; }) -static void tcg_dump_ops(TCGContext *s, FILE *f, bool have_prefs) +void tcg_dump_ops(TCGContext *s, FILE *f, bool have_prefs) { char buf[128]; TCGOp *op; @@ -2714,6 +2723,24 @@ static void tcg_dump_ops(TCGContext *s, FILE *f, bool have_prefs) i = k = 1; } break; +#ifdef CONFIG_PLUGIN + case INDEX_op_plugin_cb: + { + TCGArg from = op->args[k++]; + const char *name = NULL; + + if (from < ARRAY_SIZE(plugin_from_name)) { + name = plugin_from_name[from]; + } + if (name) { + col += ne_fprintf(f, "%s", name); + } else { + col += ne_fprintf(f, "$0x%" TCG_PRIlx, from); + } + i = 1; + } + break; +#endif default: i = 0; break; diff --git a/util/log.c b/util/log.c index d36c98da0b..6219819855 100644 --- a/util/log.c +++ b/util/log.c @@ -466,6 +466,10 @@ const QEMULogItem qemu_log_items[] = { "show micro ops after optimization" }, { CPU_LOG_TB_OP_IND, "op_ind", "show micro ops before indirect lowering" }, +#ifdef CONFIG_PLUGIN + { LOG_TB_OP_PLUGIN, "op_plugin", + "show micro ops before plugin injection" }, +#endif { CPU_LOG_INT, "int", "show interrupts/exceptions in short format" }, { CPU_LOG_EXEC, "exec",